Patchwork D3872: histedit: add --no-backup option (issue5825)

login
register
mail settings
Submitter phabricator
Date July 1, 2018, 4:35 p.m.
Message ID <differential-rev-PHID-DREV-42lq7srkub5bhqst54po-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/32550/
State Superseded
Headers show

Comments

phabricator - July 1, 2018, 4:35 p.m.
khanchi97 created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This option provides a functionality to not store a backup
  while aborting histedit in between. Also added tests for the
  same.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3872

AFFECTED FILES
  hgext/histedit.py
  tests/test-histedit-no-backup.t

CHANGE DETAILS




To: khanchi97, durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - July 4, 2018, 7:30 p.m.
pulkit accepted this revision.
pulkit added inline comments.

INLINE COMMENTS

> histedit.py:927
>       ('o', 'outgoing', False, _('changesets not found in destination')),
> +     ('', 'no-backup', False, _('no backup')),
>       ('f', 'force', False,

We can definitely improve this help text here. Please follow-up.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3872

To: khanchi97, durin42, #hg-reviewers, pulkit
Cc: pulkit, mercurial-devel

Patch

diff --git a/tests/test-histedit-no-backup.t b/tests/test-histedit-no-backup.t
new file mode 100644
--- /dev/null
+++ b/tests/test-histedit-no-backup.t
@@ -0,0 +1,95 @@ 
+  $ . "$TESTDIR/histedit-helpers.sh"
+
+Enable extension used by this test
+  $ cat >>$HGRCPATH <<EOF
+  > [extensions]
+  > histedit=
+  > EOF
+
+Repo setup:
+  $ hg init foo
+  $ cd foo
+  $ echo first>file
+  $ hg ci -qAm one
+  $ echo second>>file
+  $ hg ci -m two
+  $ echo third>>file
+  $ hg ci -m three
+  $ echo forth>>file
+  $ hg ci -m four
+  $ hg log -G --style compact
+  @  3[tip]   7d5187087c79   1970-01-01 00:00 +0000   test
+  |    four
+  |
+  o  2   80d23dfa866d   1970-01-01 00:00 +0000   test
+  |    three
+  |
+  o  1   6153eb23e623   1970-01-01 00:00 +0000   test
+  |    two
+  |
+  o  0   36b4bdd91f5b   1970-01-01 00:00 +0000   test
+       one
+  
+Check when --no-backup is not passed
+  $ hg histedit -r '36b4bdd91f5b' --commands - << EOF
+  > pick 36b4bdd91f5b 0 one
+  > pick 6153eb23e623 1 two
+  > roll 80d23dfa866d 2 three
+  > edit 7d5187087c79 3 four
+  > EOF
+  merging file
+  Editing (7d5187087c79), you may commit or record as needed now.
+  (hg histedit --continue to resume)
+  [1]
+
+  $ hg histedit --abort
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/foo/.hg/strip-backup/1d8f701c7b35-cf7be322-backup.hg
+  saved backup bundle to $TESTTMP/foo/.hg/strip-backup/5c0056670bce-b54b65d0-backup.hg
+
+  $ hg st
+  $ hg diff
+  $ hg log -G --style compact
+  @  3[tip]   7d5187087c79   1970-01-01 00:00 +0000   test
+  |    four
+  |
+  o  2   80d23dfa866d   1970-01-01 00:00 +0000   test
+  |    three
+  |
+  o  1   6153eb23e623   1970-01-01 00:00 +0000   test
+  |    two
+  |
+  o  0   36b4bdd91f5b   1970-01-01 00:00 +0000   test
+       one
+  
+
+Check when --no-backup is passed
+  $ hg histedit -r '36b4bdd91f5b' --commands - << EOF
+  > pick 36b4bdd91f5b 0 one
+  > pick 6153eb23e623 1 two
+  > roll 80d23dfa866d 2 three
+  > edit 7d5187087c79 3 four
+  > EOF
+  merging file
+  Editing (7d5187087c79), you may commit or record as needed now.
+  (hg histedit --continue to resume)
+  [1]
+
+  $ hg histedit --abort --no-backup
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg st
+  $ hg diff
+  $ hg log -G --style compact
+  @  3[tip]   7d5187087c79   1970-01-01 00:00 +0000   test
+  |    four
+  |
+  o  2   80d23dfa866d   1970-01-01 00:00 +0000   test
+  |    three
+  |
+  o  1   6153eb23e623   1970-01-01 00:00 +0000   test
+  |    two
+  |
+  o  0   36b4bdd91f5b   1970-01-01 00:00 +0000   test
+       one
+  
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -924,6 +924,7 @@ 
       _("don't strip old nodes after edit is complete")),
      ('', 'abort', False, _('abort an edit in progress')),
      ('o', 'outgoing', False, _('changesets not found in destination')),
+     ('', 'no-backup', False, _('no backup')),
      ('f', 'force', False,
       _('force outgoing even for unrelated repositories')),
      ('r', 'rev', [], _('first revision to be edited'), _('REV'))] +
@@ -1109,6 +1110,7 @@ 
     fm.startitem()
     goal = _getgoal(opts)
     revs = opts.get('rev', [])
+    nobackup = opts.get('no_backup')
     rules = opts.get('commands', '')
     state.keep = opts.get('keep', False)
 
@@ -1122,7 +1124,7 @@ 
         _edithisteditplan(ui, repo, state, rules)
         return
     elif goal == goalabort:
-        _aborthistedit(ui, repo, state)
+        _aborthistedit(ui, repo, state, nobackup=nobackup)
         return
     else:
         # goal == goalnew
@@ -1222,7 +1224,7 @@ 
     if repo.vfs.exists('histedit-last-edit.txt'):
         repo.vfs.unlink('histedit-last-edit.txt')
 
-def _aborthistedit(ui, repo, state):
+def _aborthistedit(ui, repo, state, nobackup=False):
     try:
         state.read()
         __, leafs, tmpnodes, __ = processreplacement(state)
@@ -1244,8 +1246,8 @@ 
         if repo.unfiltered().revs('parents() and (%n  or %ln::)',
                                 state.parentctxnode, leafs | tmpnodes):
             hg.clean(repo, state.topmost, show_stats=True, quietempty=True)
-        cleanupnode(ui, repo, tmpnodes)
-        cleanupnode(ui, repo, leafs)
+        cleanupnode(ui, repo, tmpnodes, nobackup=nobackup)
+        cleanupnode(ui, repo, leafs, nobackup=nobackup)
     except Exception:
         if state.inprogress():
             ui.warn(_('warning: encountered an exception during histedit '
@@ -1602,7 +1604,7 @@ 
                 changes.append((name, newtopmost))
             marks.applychanges(repo, tr, changes)
 
-def cleanupnode(ui, repo, nodes):
+def cleanupnode(ui, repo, nodes, nobackup=False):
     """strip a group of nodes from the repository
 
     The set of node to strip may contains unknown nodes."""
@@ -1617,7 +1619,8 @@ 
         nodes = sorted(n for n in nodes if n in nm)
         roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
         if roots:
-            repair.strip(ui, repo, roots)
+            backup = not nobackup
+            repair.strip(ui, repo, roots, backup=backup)
 
 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs):
     if isinstance(nodelist, str):