##// END OF EJS Templates
histedit: use one editor when multiple folds happen in a row (issue3524) (BC)...
Augie Fackler -
r26246:bf81b696 default
parent child Browse files
Show More
@@ -557,8 +557,21 b' class fold(histeditaction):'
557 middlecommits)
557 middlecommits)
558
558
559 def skipprompt(self):
559 def skipprompt(self):
560 """Returns true if the rule should skip the message editor.
561
562 For example, 'fold' wants to show an editor, but 'rollup'
563 doesn't want to.
564 """
560 return False
565 return False
561
566
567 def mergedescs(self):
568 """Returns true if the rule should merge messages of multiple changes.
569
570 This exists mainly so that 'rollup' rules can be a subclass of
571 'fold'.
572 """
573 return True
574
562 def finishfold(self, ui, repo, ctx, oldctx, newnode, internalchanges):
575 def finishfold(self, ui, repo, ctx, oldctx, newnode, internalchanges):
563 parent = ctx.parents()[0].node()
576 parent = ctx.parents()[0].node()
564 hg.update(repo, parent)
577 hg.update(repo, parent)
@@ -566,7 +579,7 b' class fold(histeditaction):'
566 commitopts = {}
579 commitopts = {}
567 commitopts['user'] = ctx.user()
580 commitopts['user'] = ctx.user()
568 # commit message
581 # commit message
569 if self.skipprompt():
582 if not self.mergedescs():
570 newmessage = ctx.description()
583 newmessage = ctx.description()
571 else:
584 else:
572 newmessage = '\n***\n'.join(
585 newmessage = '\n***\n'.join(
@@ -601,7 +614,22 b' class fold(histeditaction):'
601 replacements.append((ich, (n,)))
614 replacements.append((ich, (n,)))
602 return repo[n], replacements
615 return repo[n], replacements
603
616
617 class _multifold(fold):
618 """fold subclass used for when multiple folds happen in a row
619
620 We only want to fire the editor for the folded message once when
621 (say) four changes are folded down into a single change. This is
622 similar to rollup, but we should preserve both messages so that
623 when the last fold operation runs we can show the user all the
624 commit messages in their editor.
625 """
626 def skipprompt(self):
627 return True
628
604 class rollup(fold):
629 class rollup(fold):
630 def mergedescs(self):
631 return False
632
605 def skipprompt(self):
633 def skipprompt(self):
606 return True
634 return True
607
635
@@ -644,6 +672,7 b" actiontable = {'p': pick,"
644 'edit': edit,
672 'edit': edit,
645 'f': fold,
673 'f': fold,
646 'fold': fold,
674 'fold': fold,
675 '_multifold': _multifold,
647 'r': rollup,
676 'r': rollup,
648 'roll': rollup,
677 'roll': rollup,
649 'd': drop,
678 'd': drop,
@@ -850,6 +879,14 b' def _histedit(ui, repo, state, *freeargs'
850 'histedit')
879 'histedit')
851 state.backupfile = backupfile
880 state.backupfile = backupfile
852
881
882 # preprocess rules so that we can hide inner folds from the user
883 # and only show one editor
884 rules = state.rules[:]
885 for idx, ((action, ha), (nextact, unused)) in enumerate(
886 zip(rules, rules[1:] + [(None, None)])):
887 if action == 'fold' and nextact == 'fold':
888 state.rules[idx] = '_multifold', ha
889
853 while state.rules:
890 while state.rules:
854 state.write()
891 state.write()
855 action, ha = state.rules.pop(0)
892 action, ha = state.rules.pop(0)
@@ -995,7 +1032,7 b' def verifyrules(rules, repo, ctxs):'
995 raise util.Abort(_('duplicated command for changeset %s') %
1032 raise util.Abort(_('duplicated command for changeset %s') %
996 ha[:12])
1033 ha[:12])
997 seen.add(ha)
1034 seen.add(ha)
998 if action not in actiontable:
1035 if action not in actiontable or action.startswith('_'):
999 raise util.Abort(_('unknown action "%s"') % action)
1036 raise util.Abort(_('unknown action "%s"') % action)
1000 parsed.append([action, ha])
1037 parsed.append([action, ha])
1001 missing = sorted(expected - seen) # sort to stabilize output
1038 missing = sorted(expected - seen) # sort to stabilize output
@@ -509,4 +509,64 b' into the hook command.'
509 $ hg add amended.txt
509 $ hg add amended.txt
510 $ hg ci -q --config extensions.largefiles= --amend -I amended.txt
510 $ hg ci -q --config extensions.largefiles= --amend -I amended.txt
511
511
512 Test that folding multiple changes in a row doesn't show multiple
513 editors.
514
515 $ echo foo >> foo
516 $ hg add foo
517 $ hg ci -m foo1
518 $ echo foo >> foo
519 $ hg ci -m foo2
520 $ echo foo >> foo
521 $ hg ci -m foo3
522 $ hg logt
523 4:21679ff7675c foo3
524 3:b7389cc4d66e foo2
525 2:0e01aeef5fa8 foo1
526 1:578c7455730c a
527 0:79b99e9c8e49 b
528 $ cat > $TESTTMP/editor.sh <<EOF
529 > echo ran editor >> $TESTTMP/editorlog.txt
530 > cat \$1 >> $TESTTMP/editorlog.txt
531 > echo END >> $TESTTMP/editorlog.txt
532 > echo merged foos > \$1
533 > EOF
534 $ HGEDITOR="sh $TESTTMP/editor.sh" hg histedit 1 --commands - 2>&1 <<EOF | fixbundle
535 > pick 578c7455730c 1 a
536 > pick 0e01aeef5fa8 2 foo1
537 > fold b7389cc4d66e 3 foo2
538 > fold 21679ff7675c 4 foo3
539 > EOF
540 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
541 reverting foo
542 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
543 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
544 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
545 merging foo
546 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
547 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
548 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
549 $ hg logt
550 2:e8bedbda72c1 merged foos
551 1:578c7455730c a
552 0:79b99e9c8e49 b
553 Editor should have run only once
554 $ cat $TESTTMP/editorlog.txt
555 ran editor
556 foo1
557 ***
558 foo2
559 ***
560 foo3
561
562
563
564 HG: Enter commit message. Lines beginning with 'HG:' are removed.
565 HG: Leave message empty to abort commit.
566 HG: --
567 HG: user: test
568 HG: branch 'default'
569 HG: added foo
570 END
571
512 $ cd ..
572 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now