changeset 45089:3e40abe0a170

commit: factor out empty commit check to `basectx.isempty()` This enables reuse in other places, e.g. those dealing with `memctx`. Differential Revision: https://phab.mercurial-scm.org/D8729
author Manuel Jacob <me@manueljacob.de>
date Sat, 11 Jul 2020 01:14:00 +0200
parents 83f75f1efdcc
children d085fcb11c56
files mercurial/context.py mercurial/localrepo.py
diffstat 2 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Sat Jul 11 00:53:34 2020 +0200
+++ b/mercurial/context.py	Sat Jul 11 01:14:00 2020 +0200
@@ -481,6 +481,14 @@
             '%s does not implement mergestate()' % self.__class__
         )
 
+    def isempty(self):
+        return not (
+            len(self.parents()) > 1
+            or self.branch() != self.p1().branch()
+            or self.closesbranch()
+            or self.files()
+        )
+
 
 class changectx(basectx):
     """A changecontext object makes access to data related to a particular
--- a/mercurial/localrepo.py	Sat Jul 11 00:53:34 2020 +0200
+++ b/mercurial/localrepo.py	Sat Jul 11 01:14:00 2020 +0200
@@ -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