Mercurial > hg
comparison hgext/histedit.py @ 18436:b38c10502af9
histedit: factor most commit creation in a function
Later commits add two important items to histedit:
- Obsolescence cycle prevention
- Proper phase conservation
Those logics must be applied to all simple operations (pick, edit, mess) and
will require verbose code.
So we introduce a new function that will provide an entry point for this new.
logic.
The function build a closure to have a clear distinction between commit
arguments and data provided to the function to fulfil its logic.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 16 Jan 2013 19:11:06 +0100 |
parents | c605e12dd622 |
children | 358c23e8f1c6 |
comparison
equal
deleted
inserted
replaced
18435:8c019d2fd7c0 | 18436:b38c10502af9 |
---|---|
173 # f, fold = use commit, but fold into previous commit (combines N and N-1) | 173 # f, fold = use commit, but fold into previous commit (combines N and N-1) |
174 # d, drop = remove commit from history | 174 # d, drop = remove commit from history |
175 # m, mess = edit message without changing commit content | 175 # m, mess = edit message without changing commit content |
176 # | 176 # |
177 """) | 177 """) |
178 | |
179 def commitfuncfor(repo, src): | |
180 """Build a commit function for the replacement of <src> | |
181 | |
182 This function ensure we apply the same treatement to all changesets. | |
183 | |
184 No such treatment is done yet. | |
185 | |
186 Note that fold have its own separated logic because its handling is a bit | |
187 different and not easily factored out of the fold method. | |
188 """ | |
189 def commitfunc(**kwargs): | |
190 return repo.commit(**kwargs) | |
191 return commitfunc | |
192 | |
193 | |
178 | 194 |
179 def applychanges(ui, repo, ctx, opts): | 195 def applychanges(ui, repo, ctx, opts): |
180 """Merge changeset from ctx (only) in the current working directory""" | 196 """Merge changeset from ctx (only) in the current working directory""" |
181 wcpar = repo.dirstate.parents()[0] | 197 wcpar = repo.dirstate.parents()[0] |
182 if ctx.p1().node() == wcpar: | 198 if ctx.p1().node() == wcpar: |
277 stats = applychanges(ui, repo, oldctx, opts) | 293 stats = applychanges(ui, repo, oldctx, opts) |
278 if stats and stats[3] > 0: | 294 if stats and stats[3] > 0: |
279 raise util.Abort(_('Fix up the change and run ' | 295 raise util.Abort(_('Fix up the change and run ' |
280 'hg histedit --continue')) | 296 'hg histedit --continue')) |
281 # drop the second merge parent | 297 # drop the second merge parent |
282 n = repo.commit(text=oldctx.description(), user=oldctx.user(), | 298 commit = commitfuncfor(repo, oldctx) |
283 date=oldctx.date(), extra=oldctx.extra()) | 299 n = commit(text=oldctx.description(), user=oldctx.user(), |
300 date=oldctx.date(), extra=oldctx.extra()) | |
284 if n is None: | 301 if n is None: |
285 ui.warn(_('%s: empty changeset\n') | 302 ui.warn(_('%s: empty changeset\n') |
286 % node.hex(ha)) | 303 % node.hex(ha)) |
287 return ctx, [] | 304 return ctx, [] |
288 new = repo[n] | 305 new = repo[n] |
354 if stats and stats[3] > 0: | 371 if stats and stats[3] > 0: |
355 raise util.Abort(_('Fix up the change and run ' | 372 raise util.Abort(_('Fix up the change and run ' |
356 'hg histedit --continue')) | 373 'hg histedit --continue')) |
357 message = oldctx.description() + '\n' | 374 message = oldctx.description() + '\n' |
358 message = ui.edit(message, ui.username()) | 375 message = ui.edit(message, ui.username()) |
359 new = repo.commit(text=message, user=oldctx.user(), date=oldctx.date(), | 376 commit = commitfuncfor(repo, oldctx) |
360 extra=oldctx.extra()) | 377 new = commit(text=message, user=oldctx.user(), date=oldctx.date(), |
378 extra=oldctx.extra()) | |
361 newctx = repo[new] | 379 newctx = repo[new] |
362 if oldctx.node() != newctx.node(): | 380 if oldctx.node() != newctx.node(): |
363 return newctx, [(oldctx.node(), (new,))] | 381 return newctx, [(oldctx.node(), (new,))] |
364 # We didn't make an edit, so just indicate no replaced nodes | 382 # We didn't make an edit, so just indicate no replaced nodes |
365 return newctx, [] | 383 return newctx, [] |
556 message = ctx.description() + '\n' | 574 message = ctx.description() + '\n' |
557 if action in ('e', 'edit', 'm', 'mess'): | 575 if action in ('e', 'edit', 'm', 'mess'): |
558 editor = cmdutil.commitforceeditor | 576 editor = cmdutil.commitforceeditor |
559 else: | 577 else: |
560 editor = False | 578 editor = False |
561 new = repo.commit(text=message, user=ctx.user(), | 579 commit = commitfuncfor(repo, ctx) |
562 date=ctx.date(), extra=ctx.extra(), | 580 new = commit(text=message, user=ctx.user(), |
563 editor=editor) | 581 date=ctx.date(), extra=ctx.extra(), |
582 editor=editor) | |
564 if new is not None: | 583 if new is not None: |
565 newchildren.append(new) | 584 newchildren.append(new) |
566 | 585 |
567 replacements = [] | 586 replacements = [] |
568 # track replacements | 587 # track replacements |
720 # if nothing got rewritten there is not purpose for this function | 739 # if nothing got rewritten there is not purpose for this function |
721 return | 740 return |
722 moves = [] | 741 moves = [] |
723 for bk, old in sorted(repo._bookmarks.iteritems()): | 742 for bk, old in sorted(repo._bookmarks.iteritems()): |
724 if old == oldtopmost: | 743 if old == oldtopmost: |
725 # special case ensure bookmark stay on tip. | 744 # special case ensure bookmark stay on tip. |
726 # | 745 # |
727 # This is arguably a feature and we may only want that for the | 746 # This is arguably a feature and we may only want that for the |
728 # active bookmark. But the behavior is kept compatible with the old | 747 # active bookmark. But the behavior is kept compatible with the old |
729 # version for now. | 748 # version for now. |
730 moves.append((bk, newtopmost)) | 749 moves.append((bk, newtopmost)) |