# HG changeset patch # User Manuel Jacob # Date 2020-07-10 23:14:00 # Node ID 3e40abe0a170774a8c4cafa156d747de66580b5f # Parent 83f75f1efdcca90550c11e1a6caa5ec254c6d92f 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 diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -481,6 +481,14 @@ class basectx(object): '%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 diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -2995,14 +2995,9 @@ class localrepository(object): 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