Show More
@@ -8,7 +8,6 b'' | |||
|
8 | 8 | |
|
9 | 9 | Inspired by git rebase --interactive. |
|
10 | 10 | """ |
|
11 | from inspect import getargspec | |
|
12 | 11 | try: |
|
13 | 12 | import cPickle as pickle |
|
14 | 13 | except ImportError: |
@@ -25,7 +24,6 b' from mercurial import node' | |||
|
25 | 24 | from mercurial import patch |
|
26 | 25 | from mercurial import repair |
|
27 | 26 | from mercurial import scmutil |
|
28 | from mercurial import url | |
|
29 | 27 | from mercurial import util |
|
30 | 28 | from mercurial.i18n import _ |
|
31 | 29 | |
@@ -44,7 +42,7 b' editcomment = """' | |||
|
44 | 42 | """ |
|
45 | 43 | |
|
46 | 44 | def between(repo, old, new, keep): |
|
47 |
revs = [old |
|
|
45 | revs = [old] | |
|
48 | 46 | current = old |
|
49 | 47 | while current != new: |
|
50 | 48 | ctx = repo[current] |
@@ -89,12 +87,12 b' def pick(ui, repo, ctx, ha, opts):' | |||
|
89 | 87 | return ctx, [], [], [] |
|
90 | 88 | finally: |
|
91 | 89 | os.unlink(patchfile) |
|
92 |
except Exception |
|
|
90 | except Exception: | |
|
93 | 91 | raise util.Abort(_('Fix up the change and run ' |
|
94 | 92 | 'hg histedit --continue')) |
|
95 |
n = repo.commit(text=oldctx.description(), user=oldctx.user(), |
|
|
96 | extra=oldctx.extra()) | |
|
97 |
return repo[n], [n |
|
|
93 | n = repo.commit(text=oldctx.description(), user=oldctx.user(), | |
|
94 | date=oldctx.date(), extra=oldctx.extra()) | |
|
95 | return repo[n], [n], [oldctx.node()], [] | |
|
98 | 96 | |
|
99 | 97 | |
|
100 | 98 | def edit(ui, repo, ctx, ha, opts): |
@@ -117,7 +115,7 b' def edit(ui, repo, ctx, ha, opts):' | |||
|
117 | 115 | patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
|
118 | 116 | finally: |
|
119 | 117 | os.unlink(patchfile) |
|
120 |
except Exception |
|
|
118 | except Exception: | |
|
121 | 119 | pass |
|
122 | 120 | raise util.Abort(_('Make changes as needed, you may commit or record as ' |
|
123 | 121 | 'needed now.\nWhen you are finished, run hg' |
@@ -147,11 +145,11 b' def fold(ui, repo, ctx, ha, opts):' | |||
|
147 | 145 | return ctx, [], [], [] |
|
148 | 146 | finally: |
|
149 | 147 | os.unlink(patchfile) |
|
150 |
except Exception |
|
|
148 | except Exception: | |
|
151 | 149 | raise util.Abort(_('Fix up the change and run ' |
|
152 | 150 | 'hg histedit --continue')) |
|
153 |
n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(), |
|
|
154 | extra=oldctx.extra()) | |
|
151 | n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(), | |
|
152 | date=oldctx.date(), extra=oldctx.extra()) | |
|
155 | 153 | return finishfold(ui, repo, ctx, oldctx, n, opts, []) |
|
156 | 154 | |
|
157 | 155 | def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges): |
@@ -174,21 +172,21 b' def finishfold(ui, repo, ctx, oldctx, ne' | |||
|
174 | 172 | finally: |
|
175 | 173 | os.unlink(patchfile) |
|
176 | 174 | newmessage = '\n***\n'.join( |
|
177 |
[ctx.description() |
|
|
175 | [ctx.description()] + | |
|
178 | 176 | [repo[r].description() for r in internalchanges] + |
|
179 |
[oldctx.description() |
|
|
177 | [oldctx.description()]) | |
|
180 | 178 | # If the changesets are from the same author, keep it. |
|
181 | 179 | if ctx.user() == oldctx.user(): |
|
182 | 180 | username = ctx.user() |
|
183 | 181 | else: |
|
184 | 182 | username = ui.username() |
|
185 | 183 | newmessage = ui.edit(newmessage, username) |
|
186 |
n = repo.commit(text=newmessage, user=username, |
|
|
187 | extra=oldctx.extra()) | |
|
188 |
return repo[n], [n |
|
|
184 | n = repo.commit(text=newmessage, user=username, | |
|
185 | date=max(ctx.date(), oldctx.date()), extra=oldctx.extra()) | |
|
186 | return repo[n], [n], [oldctx.node(), ctx.node()], [newnode] | |
|
189 | 187 | |
|
190 | 188 | def drop(ui, repo, ctx, ha, opts): |
|
191 |
return ctx, [], [repo[ha].node() |
|
|
189 | return ctx, [], [repo[ha].node()], [] | |
|
192 | 190 | |
|
193 | 191 | |
|
194 | 192 | def message(ui, repo, ctx, ha, opts): |
@@ -211,7 +209,7 b' def message(ui, repo, ctx, ha, opts):' | |||
|
211 | 209 | patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
|
212 | 210 | finally: |
|
213 | 211 | os.unlink(patchfile) |
|
214 |
except Exception |
|
|
212 | except Exception: | |
|
215 | 213 | raise util.Abort(_('Fix up the change and run ' |
|
216 | 214 | 'hg histedit --continue')) |
|
217 | 215 | message = oldctx.description() |
@@ -255,7 +253,8 b' def histedit(ui, repo, *parent, **opts):' | |||
|
255 | 253 | parent = list(parent) + opts.get('rev', []) |
|
256 | 254 | if opts.get('outgoing'): |
|
257 | 255 | if len(parent) > 1: |
|
258 | raise util.Abort(_('only one repo argument allowed with --outgoing')) | |
|
256 | raise util.Abort( | |
|
257 | _('only one repo argument allowed with --outgoing')) | |
|
259 | 258 | elif parent: |
|
260 | 259 | parent = parent[0] |
|
261 | 260 | |
@@ -279,7 +278,7 b' def histedit(ui, repo, *parent, **opts):' | |||
|
279 | 278 | if len(parent) != 0: |
|
280 | 279 | raise util.Abort(_('no arguments allowed with --continue')) |
|
281 | 280 | (parentctxnode, created, replaced, |
|
282 |
tmpnodes, existing, rules, keep, tip, replacemap |
|
|
281 | tmpnodes, existing, rules, keep, tip, replacemap) = readstate(repo) | |
|
283 | 282 | currentparent, wantnull = repo.dirstate.parents() |
|
284 | 283 | parentctx = repo[parentctxnode] |
|
285 | 284 | # discover any nodes the user has added in the interim |
@@ -287,7 +286,7 b' def histedit(ui, repo, *parent, **opts):' | |||
|
287 | 286 | if c.node() not in existing] |
|
288 | 287 | action, currentnode = rules.pop(0) |
|
289 | 288 | while newchildren: |
|
290 |
if action in |
|
|
289 | if action in ('f', 'fold'): | |
|
291 | 290 | tmpnodes.extend([n.node() for n in newchildren]) |
|
292 | 291 | else: |
|
293 | 292 | created.extend([n.node() for n in newchildren]) |
@@ -300,22 +299,20 b' def histedit(ui, repo, *parent, **opts):' | |||
|
300 | 299 | message = oldctx.description() |
|
301 | 300 | if action in ('e', 'edit', 'm', 'mess'): |
|
302 | 301 | message = ui.edit(message, ui.username()) |
|
303 |
elif action in ('f', 'fold' |
|
|
302 | elif action in ('f', 'fold'): | |
|
304 | 303 | message = 'fold-temp-revision %s' % currentnode |
|
305 | 304 | new = None |
|
306 | 305 | if m or a or r or d: |
|
307 |
new = repo.commit(text=message, user=oldctx.user(), |
|
|
308 | extra=oldctx.extra()) | |
|
306 | new = repo.commit(text=message, user=oldctx.user(), | |
|
307 | date=oldctx.date(), extra=oldctx.extra()) | |
|
309 | 308 | |
|
310 | 309 | if action in ('f', 'fold'): |
|
311 | 310 | if new: |
|
312 | 311 | tmpnodes.append(new) |
|
313 | 312 | else: |
|
314 | 313 | new = newchildren[-1] |
|
315 | (parentctx, created_, | |
|
316 | replaced_, tmpnodes_, ) = finishfold(ui, repo, | |
|
317 | parentctx, oldctx, new, | |
|
318 | opts, newchildren) | |
|
314 | (parentctx, created_, replaced_, tmpnodes_) = finishfold( | |
|
315 | ui, repo, parentctx, oldctx, new, opts, newchildren) | |
|
319 | 316 | replaced.extend(replaced_) |
|
320 | 317 | created.extend(created_) |
|
321 | 318 | tmpnodes.extend(tmpnodes_) |
@@ -338,7 +335,7 b' def histedit(ui, repo, *parent, **opts):' | |||
|
338 | 335 | ', '.join([node.hex(n)[:12] for n in created])) |
|
339 | 336 | ui.debug('should strip temp nodes %s\n' % |
|
340 | 337 | ', '.join([node.hex(n)[:12] for n in tmpnodes])) |
|
341 |
for nodes in (created, tmpnodes |
|
|
338 | for nodes in (created, tmpnodes): | |
|
342 | 339 | for n in reversed(nodes): |
|
343 | 340 | try: |
|
344 | 341 | repair.strip(ui, repo, n) |
@@ -367,7 +364,7 b' def histedit(ui, repo, *parent, **opts):' | |||
|
367 | 364 | rules = opts.get('commands', '') |
|
368 | 365 | if not rules: |
|
369 | 366 | rules = '\n'.join([makedesc(c) for c in ctxs]) |
|
370 |
rules += editcomment % (node.hex(parent)[:12], node.hex(tip)[:12] |
|
|
367 | rules += editcomment % (node.hex(parent)[:12], node.hex(tip)[:12]) | |
|
371 | 368 | rules = ui.edit(rules, ui.username()) |
|
372 | 369 | # Save edit rules in .hg/histedit-last-edit.txt in case |
|
373 | 370 | # the user needs to ask for help after something |
@@ -392,13 +389,11 b' def histedit(ui, repo, *parent, **opts):' | |||
|
392 | 389 | |
|
393 | 390 | |
|
394 | 391 | while rules: |
|
395 |
writestate(repo, parentctx.node(), created, replaced, |
|
|
396 | rules, keep, tip, replacemap) | |
|
392 | writestate(repo, parentctx.node(), created, replaced, | |
|
393 | tmpnodes, existing, rules, keep, tip, replacemap) | |
|
397 | 394 | action, ha = rules.pop(0) |
|
398 | (parentctx, created_, | |
|
399 | replaced_, tmpnodes_, ) = actiontable[action](ui, repo, | |
|
400 | parentctx, ha, | |
|
401 | opts) | |
|
395 | (parentctx, created_, replaced_, tmpnodes_) = actiontable[action]( | |
|
396 | ui, repo, parentctx, ha, opts) | |
|
402 | 397 | |
|
403 | 398 | hexshort = lambda x: node.hex(x)[:12] |
|
404 | 399 | |
@@ -415,8 +410,8 b' def histedit(ui, repo, *parent, **opts):' | |||
|
415 | 410 | # made more changesets than we're replacing |
|
416 | 411 | # TODO synthesize patch names for created patches |
|
417 | 412 | replacemap[replaced_[0]] = created_[-1] |
|
418 |
ui.debug('histedit: created many, assuming %s replaced by %s' % |
|
|
419 | hexshort(replaced_[0]), hexshort(created_[-1]))) | |
|
413 | ui.debug('histedit: created many, assuming %s replaced by %s' % | |
|
414 | (hexshort(replaced_[0]), hexshort(created_[-1]))) | |
|
420 | 415 | elif rlen > clen: |
|
421 | 416 | if not created_: |
|
422 | 417 | # This must be a drop. Try and put our metadata on |
@@ -451,8 +446,8 b' def histedit(ui, repo, *parent, **opts):' | |||
|
451 | 446 | |
|
452 | 447 | if not keep: |
|
453 | 448 | if replacemap: |
|
454 | ui.note('histedit: Should update metadata for the following ' | |
|
455 | 'changes:\n') | |
|
449 | ui.note(_('histedit: Should update metadata for the following ' | |
|
450 | 'changes:\n')) | |
|
456 | 451 | |
|
457 | 452 | def copybms(old, new): |
|
458 | 453 | if old in tmpnodes or old in created: |
@@ -460,12 +455,13 b' def histedit(ui, repo, *parent, **opts):' | |||
|
460 | 455 | return |
|
461 | 456 | while new in replacemap: |
|
462 | 457 | new = replacemap[new] |
|
463 |
ui.note('histedit: %s to %s\n' % (hexshort(old), |
|
|
458 | ui.note(_('histedit: %s to %s\n') % (hexshort(old), | |
|
459 | hexshort(new))) | |
|
464 | 460 | octx = repo[old] |
|
465 | 461 | marks = octx.bookmarks() |
|
466 | 462 | if marks: |
|
467 | ui.note('histedit: moving bookmarks %s\n' % | |
|
468 | ', '.join(marks)) | |
|
463 | ui.note(_('histedit: moving bookmarks %s\n') % | |
|
464 | ', '.join(marks)) | |
|
469 | 465 | for mark in marks: |
|
470 | 466 | repo._bookmarks[mark] = new |
|
471 | 467 | bookmarks.write(repo) |
@@ -526,7 +522,6 b' def verifyrules(rules, repo, ctxs):' | |||
|
526 | 522 | or a rule on a changeset outside of the user-given range. |
|
527 | 523 | """ |
|
528 | 524 | parsed = [] |
|
529 | first = True | |
|
530 | 525 | if len(rules) != len(ctxs): |
|
531 | 526 | raise util.Abort(_('must specify a rule for each changeset once')) |
|
532 | 527 | for r in rules: |
@@ -539,7 +534,8 b' def verifyrules(rules, repo, ctxs):' | |||
|
539 | 534 | ha = r.strip() |
|
540 | 535 | try: |
|
541 | 536 | if repo[ha] not in ctxs: |
|
542 | raise util.Abort(_('may not use changesets other than the ones listed')) | |
|
537 | raise util.Abort( | |
|
538 | _('may not use changesets other than the ones listed')) | |
|
543 | 539 | except error.RepoError: |
|
544 | 540 | raise util.Abort(_('unknown changeset %s listed') % ha) |
|
545 | 541 | if action not in actiontable: |
@@ -551,12 +547,15 b' def verifyrules(rules, repo, ctxs):' | |||
|
551 | 547 | cmdtable = { |
|
552 | 548 | "histedit": |
|
553 | 549 | (histedit, |
|
554 | [('', 'commands', '', _('Read history edits from the specified file.')), | |
|
550 | [('', 'commands', '', _( | |
|
551 | 'Read history edits from the specified file.')), | |
|
555 | 552 | ('c', 'continue', False, _('continue an edit already in progress')), |
|
556 | ('k', 'keep', False, _("don't strip old nodes after edit is complete")), | |
|
553 | ('k', 'keep', False, _( | |
|
554 | "don't strip old nodes after edit is complete")), | |
|
557 | 555 | ('', 'abort', False, _('abort an edit in progress')), |
|
558 | 556 | ('o', 'outgoing', False, _('changesets not found in destination')), |
|
559 | ('f', 'force', False, _('force outgoing even for unrelated repositories')), | |
|
557 | ('f', 'force', False, _( | |
|
558 | 'force outgoing even for unrelated repositories')), | |
|
560 | 559 | ('r', 'rev', [], _('first revision to be edited')), |
|
561 | 560 | ], |
|
562 | 561 | __doc__, |
General Comments 0
You need to be logged in to leave comments.
Login now