Patchwork D8729: commit: factor out empty commit check to `committablectx.isempty()`

login
register
mail settings
Submitter phabricator
Date July 10, 2020, 11:17 p.m.
Message ID <differential-rev-PHID-DREV-lo33ynn7gyvcnhuwh7mu-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46694/
State Superseded
Headers show

Comments

phabricator - July 10, 2020, 11:17 p.m.
mjacob created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This enables reuse in other places, e.g. those dealing with `memctx`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/context.py
  mercurial/localrepo.py

CHANGE DETAILS




To: mjacob, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2995,14 +2995,9 @@ 
             mergeutil.checkunresolved(ms)
 
             # internal config: ui.allowemptycommit
-            allowemptycommit = (
-                cctx.branch() != cctx.p1().branch()
-                or extra.get(b'close')
-                or merge
-                or cctx.files()
-                or self.ui.configbool(b'ui', b'allowemptycommit')
-            )
-            if not allowemptycommit:
+            if cctx.isempty() and not self.ui.configbool(
+                b'ui', b'allowemptycommit'
+            ):
                 self.ui.debug(b'nothing to commit, clearing merge state\n')
                 ms.reset()
                 return None
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1502,6 +1502,14 @@ 
     def dirty(self, missing=False, merge=True, branch=True):
         return False
 
+    def isempty(self):
+        return not (
+            len(self.parents()) > 1
+            or self.branch() != self.p1().branch()
+            or self.closesbranch()
+            or self.files()
+        )
+
 
 class workingctx(committablectx):
     """A workingctx object makes access to data related to