[PATCH 2 of 8] cmdutil: add "autocommit" to create the hook point for automated committing

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Sep 9 13:18:46 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1410286453 -32400
#      Wed Sep 10 03:14:13 2014 +0900
# Node ID e1ea239437e1eba86dd66d8d78cdacc8076466ba
# Parent  a0d96709737b2fb101d2a937a54e044aefadd7e8
cmdutil: add "autocommit" to create the hook point for automated committing

Before this patch, code paths extending commit behavior (largefiles
extension, for example) does below for automated committing:

  - wrap "commit"/"commitctx" of "localrepository"

    This may not be enough to know about committing. For example, it
    is impossible to know whether an invocation is the 1st commit of
    resuming (e.g. "hg rebase --continue") or not via wrapping.

  - wrap functions implying "commit"/"commitctx" of "localrepository"

    This may not be fine grain. For example, "commands.graft" implies
    multiple committing, and it is impossible to distinguish the 1st
    commit of resuming and others at "commit.localrepository" side.

    In addition to it, wrapper and wrappee are associated tightly by
    this kind of wrapping. This increases maintenace cost at changing
    wrapper and/or wrappee.

This patch adds "autocommit" to create the hook point for automated
committing and avoid problems above.

"autocommit" accepts additional information about committing via
"**props" for extensibility: for example, another property "bypass"
will be added for code paths directly using "commitctx" in the future
(e.g. "hg import --bypass").

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2037,6 +2037,33 @@
     return commitfunc(ui, repo, message,
                       scmutil.match(repo[None], pats, opts), opts)
 
+def autocommit(commandname, repo, commitfunc, **props):
+    """create the hook point for automated committing
+
+    'commitfunc' must be the function to create a new revision (=
+    'localrepository.commit', 'localrepository.commitctx' or the
+    function indirectly using them).  It must not cause to create
+    multiple revisions at once.
+
+    Code paths implying automated committing are expected to use the
+    function returned by 'autocommit' instead of 'commitfunc' itself.
+
+    Then, code paths extending commit behavior can hook automated
+    committing by wrapping 'autocommit'.
+
+    Below properties are allowed for 'props':
+
+    :resuming: whether the returned function is used for the 1st
+    commit of the resuming (like "rebase --continue") or
+    not. Automated committing must not use the function returned by
+    "resuming=True" for revisions other than the 1st commit of the
+    resuming.
+
+    'commandname' may be used to identify the scope of hooking.
+    """
+
+    return commitfunc
+
 def amend(ui, repo, commitfunc, old, extra, pats, opts):
     ui.note(_('amending changeset %s\n') % old)
     base = old.p1()


More information about the Mercurial-devel mailing list