[PATCH V2] histedit: delete to drop

Mateusz Kwapich mitrandir at fb.com
Fri Dec 11 23:29:10 UTC 2015


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1449876455 28800
#      Fri Dec 11 15:27:35 2015 -0800
# Node ID cc9f2b9a222d3fb02c3f74edeac9e78a16d1863a
# Parent  94a215551b3f75c81052f6b490ecaf257a344185
histedit: delete to drop

The default behaviour to forbid this makes a lot of sense for novice users
because it's safeguarding them from dangerous behavior but making it
configurable will be apprieciated by power users in at least one big
organization.

It allows an user to look an histedit rules from declarative perspective and
make the rules reflect the state after histedit.  If we can move lines t move
commits why can't we drop lines to drop commits?

Let's put this behind config knob and inform users about this feature the very
moment they are trying to use it so they can choose desired behaviour.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -143,6 +143,9 @@
 repository that Mercurial does not detect to be related to the source
 repo, you can add a ``--force`` option.
 
+Config
+======
+
 Histedit rule lines are truncated to 80 characters by default. You
 can customize this behavior by setting a different length in your
 configuration file::
@@ -156,6 +159,14 @@
 
   [histedit]
   defaultrev = only(.) & draft()
+
+By default each edited revision needs to be present in histedit commands.
+To remove revision you need to use ``drop`` operation. You can configure
+the drop to be implicit for missing commits by adding:
+
+  [histedit]
+  dropmissing = True
+
 """
 
 try:
@@ -1260,10 +1271,17 @@
                         ha[:12])
             seen.add(ha)
     missing = sorted(expected - seen)  # sort to stabilize output
-    if missing:
+
+    if state.repo.ui.configbool('histedit', 'dropmissing'):
+        drops = [drop(state, node.bin(n)) for n in missing]
+        # put the in the beginning so they execute immediately and
+        # don't show in the edit-plan in the future
+        actions[:0] = drops
+    elif missing:
         raise error.Abort(_('missing rules for changeset %s') %
                 missing[0][:12],
-                hint=_('use "drop %s" to discard the change') % missing[0][:12])
+                hint=_('use "drop %s" to discard, '
+                       'see also: "hg help -e histedit.config"' % missing[0][:12]))
 
 def newnodestoabort(state):
     """process the list of replacements to return
diff --git a/tests/test-histedit-drop.t b/tests/test-histedit-drop.t
--- a/tests/test-histedit-drop.t
+++ b/tests/test-histedit-drop.t
@@ -151,4 +151,27 @@
      summary:     a
   
 
-  $ cd ..
+  $ hg histedit cb9a9f314b8b --commands - 2>&1 << EOF | fixbundle
+  > pick cb9a9f314b8b a
+  > pick ee283cb5f2d5 e
+  > EOF
+  abort: missing rules for changeset a4f7421b80f7
+  (use "drop a4f7421b80f7" to discard, see also: "hg help -e histedit.config")
+  $ hg --config histedit.dropmissing=True histedit  cb9a9f314b8b --commands - 2>&1 << EOF | fixbundle
+  > pick cb9a9f314b8b a
+  > pick ee283cb5f2d5 e
+  > EOF
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg log --graph
+  @  changeset:   1:e99c679bf03e
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     e
+  |
+  o  changeset:   0:cb9a9f314b8b
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     a
+  


More information about the Mercurial-devel mailing list