[PATCH 1 of 5] localrepo: add usercommitctx() wrapper

Dan Villiom Podlaski Christiansen danchr at gmail.com
Tue Jul 13 07:16:19 CDT 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1279022291 -7200
# Node ID 84ae201bac7b69c5ea9148cfedb306db19c860f5
# Parent  bb274fd59bf52843e916fa4971a7016c09e62a29
localrepo: add usercommitctx() wrapper.

This wrapper allows extensions to safely wrap commitctx() for
user-initiated commits only.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -890,7 +890,7 @@ class localrepository(repo.repository):
             hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
             try:
                 self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2)
-                ret = self.commitctx(cctx, True)
+                ret = self.usercommitctx(cctx, True)
             except:
                 if edited:
                     msgfn = self.pathto(msgfile.name[len(self.root)+1:])
@@ -911,9 +911,23 @@ class localrepository(repo.repository):
         self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2)
         return ret
 
+    def usercommitctx(self, ctx, error=False):
+        """
+        Wrapper for commitctx() method indicating a user-initiated commit.
+
+        This method is primarily intended for wrapping or specializing.
+        Extensions can safely wrap it, without interfering with other uses of
+        commitctx(), such as for conversion extensions.
+        """
+        return self.commitctx(ctx, error)
+
     def commitctx(self, ctx, error=False):
         """Add a new revision to current repository.
         Revision information is passed via the context argument.
+
+        Please note that this method shouldn't be wrapped or specialized by
+        extensions. This method may be used part of a conversion where it's
+        important that `ctx' is committed to the repository as-is.
         """
 
         tr = lock = None


More information about the Mercurial-devel mailing list