D2891: uncommit: simplify condition for keeping commit

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sat Mar 17 17:14:07 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We used to keep the commit if it would have become empty and --keep
  was not passed. Since we just changed it so we also keep it if any
  patterns were passed on the command line, the only remaining case
  where we prune the commit is when no arguments were passed and --keep
  was not passed either, we can simplify the "not files and not
  allowempty" to just "not allowempty". Let's also rename "allowempty"
  to "keepcommit" since it's no longer about allowing an empty commit.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/uncommit.py

CHANGE DETAILS

diff --git a/hgext/uncommit.py b/hgext/uncommit.py
--- a/hgext/uncommit.py
+++ b/hgext/uncommit.py
@@ -51,7 +51,7 @@
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
-def _commitfiltered(repo, ctx, match, allowempty):
+def _commitfiltered(repo, ctx, match, keepcommit):
     """Recommit ctx with changed files not in match. Return the new
     node identifier, or None if nothing changed.
     """
@@ -66,7 +66,7 @@
 
     files = (initialfiles - exclude)
     # return the p1 so that we don't create an obsmarker later
-    if not files and not allowempty:
+    if not keepcommit:
         return ctx.parents()[0].node()
 
     # Filter copies
@@ -169,8 +169,8 @@
 
         with repo.transaction('uncommit'):
             match = scmutil.match(old, pats, opts)
-            allowempty = opts.get('keep') or pats
-            newid = _commitfiltered(repo, old, match, allowempty)
+            keepcommit = opts.get('keep') or pats
+            newid = _commitfiltered(repo, old, match, keepcommit)
             if newid is None:
                 ui.status(_("nothing to uncommit\n"))
                 return 1



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list