11
11
12
12
13
13
class Rebase (GitSimBaseCommand ):
14
- def __init__ (self , branch : str , rebase_merges : bool , onto : bool , oldparent : str ):
14
+ def __init__ (self , branch : str , rebase_merges : bool , onto : bool , oldparent : str , until : str ):
15
15
super ().__init__ ()
16
16
self .branch = branch
17
17
self .rebase_merges = rebase_merges
18
18
self .onto = onto
19
19
self .oldparent = oldparent
20
+ self .until = until
20
21
21
22
try :
22
23
git .repo .fun .rev_parse (self .repo , self .branch )
@@ -34,7 +35,16 @@ def __init__(self, branch: str, rebase_merges: bool, onto: bool, oldparent: str)
34
35
"git-sim error: Please specify the parent of the commit to rebase ('oldparent')"
35
36
)
36
37
sys .exit (1 )
37
- self .n = self .get_mainline_distance (oldparent , "HEAD" )
38
+ self .n = max (self .get_mainline_distance (self .oldparent , "HEAD" ), self .n )
39
+
40
+ if self .until :
41
+ self .until_n = self .get_mainline_distance (self .oldparent , self .until )
42
+ else :
43
+ if self .oldparent or self .until :
44
+ print (
45
+ "git-sim error: Please use --onto flag when specifying <oldparent> and <until>"
46
+ )
47
+ sys .exit (1 )
38
48
39
49
if self .branch in [branch .name for branch in self .repo .heads ]:
40
50
self .selected_branches .append (self .branch )
@@ -44,7 +54,7 @@ def __init__(self, branch: str, rebase_merges: bool, onto: bool, oldparent: str)
44
54
except TypeError :
45
55
pass
46
56
47
- self .cmd += f"{ type (self ).__name__ .lower ()} { ' --rebase-merges' if self .rebase_merges else '' } { ' --onto' if self .onto else '' } { self .branch } { ' ' + self .oldparent if self .onto and self .oldparent else '' } "
57
+ self .cmd += f"{ type (self ).__name__ .lower ()} { ' --rebase-merges' if self .rebase_merges else '' } { ' --onto' if self .onto else '' } { self .branch } { ' ' + self .oldparent if self .onto and self .oldparent else '' } { ' ' + self . until if self . onto and self . until else '' } "
48
58
49
59
self .alt_colors = {
50
60
0 : [m .BLUE_B , m .BLUE_E ],
@@ -98,7 +108,12 @@ def construct(self):
98
108
self .to_rebase = []
99
109
for c in flat_default_commits :
100
110
if self .branch not in self .repo .git .branch ("--contains" , c ):
101
- self .to_rebase .append (c )
111
+ if self .onto and self .until :
112
+ range_commits = list (self .repo .iter_commits (f"{ self .oldparent } ...{ self .until } " ))
113
+ if c in range_commits :
114
+ self .to_rebase .append (c )
115
+ else :
116
+ self .to_rebase .append (c )
102
117
103
118
reached_base = False
104
119
merge_base = self .repo .git .merge_base (self .branch , self .repo .active_branch .name )
@@ -145,7 +160,14 @@ def construct(self):
145
160
self .draw_arrow_between_commits (tr .hexsha , rebased_shas [j - k ], color = arrow_color )
146
161
147
162
if self .rebase_merges :
148
- self .reset_head_branch (rebased_sha_map [default_commits [0 ][0 ].hexsha ])
163
+ if self .onto and self .until :
164
+ until_sha = self .get_commit (self .until ).hexsha
165
+ if until_sha == self .repo .head .commit .hexsha :
166
+ self .reset_head_branch (rebased_sha_map [until_sha ])
167
+ else :
168
+ self .reset_head (rebased_sha_map [until_sha ])
169
+ else :
170
+ self .reset_head_branch (rebased_sha_map [default_commits [0 ][0 ].hexsha ])
149
171
else :
150
172
self .reset_head_branch (parent )
151
173
self .color_by (offset = 2 * len (self .to_rebase ))
@@ -194,21 +216,24 @@ def setup_and_draw_parent(
194
216
)
195
217
circle .shift (shift )
196
218
197
- arrow_start_ends = []
219
+ arrow_start_ends = set ()
198
220
arrows = []
199
- start = circle .get_center ()
221
+ start = tuple ( circle .get_center () )
200
222
if not self .rebase_merges or branch_index == 0 :
201
- end = self .drawnCommits [child ].get_center ()
202
- arrow_start_ends .append ((start , end ))
223
+ end = tuple ( self .drawnCommits [child ].get_center () )
224
+ arrow_start_ends .add ((start , end ))
203
225
if self .rebase_merges :
204
226
for p in self .get_commit (orig ).parents :
205
227
if self .branch in self .repo .git .branch (
206
228
"--contains" , p
207
- ) or p not in self . to_rebase :
229
+ ):
208
230
continue
209
231
try :
210
- end = self .drawnCommits [p .hexsha ].get_center () + m .UP * 4 + (m .LEFT if settings .reverse else m .RIGHT ) * len (default_commits [0 ]) * 2.5 + (m .LEFT * side_offset if settings .reverse else m .RIGHT * side_offset ) * 5
211
- arrow_start_ends .append ((start , end ))
232
+ if p not in self .to_rebase :
233
+ end = tuple (self .drawnCommits [self .get_commit (self .branch ).hexsha ].get_center ())
234
+ else :
235
+ end = tuple (self .drawnCommits [p .hexsha ].get_center () + m .UP * 4 + (m .LEFT if settings .reverse else m .RIGHT ) * len (default_commits [0 ]) * 2.5 + (m .LEFT * side_offset if settings .reverse else m .RIGHT * side_offset ) * 5 )
236
+ arrow_start_ends .add ((start , end ))
212
237
except KeyError :
213
238
pass
214
239
@@ -221,7 +246,7 @@ def setup_and_draw_parent(
221
246
tip_shape = self .arrow_tip_shape ,
222
247
max_stroke_width_to_length_ratio = 1000 ,
223
248
)
224
- length = numpy .linalg .norm (start - end ) - (1.5 if start [1 ] == end [1 ] else 3 )
249
+ length = numpy .linalg .norm (numpy . subtract ( end , start ) ) - (1.5 if start [1 ] == end [1 ] else 3 )
225
250
arrow .set_length (length )
226
251
arrows .append (arrow )
227
252
0 commit comments