[PATCH] 1321 (partial): run Python pretxnchangegroup hooks before disk flush

Jesse Glick typrase at gmail.com
Wed Jan 14 15:51:04 CST 2009


# HG changeset patch
# User Jesse Glick <jesse.glick at sun.com>
# Date 1231969019 18000
# Node ID fc298a32de5fca6b3275c9323ed358c506c6924a
# Parent  71cb1dc77e7650f427dde0024ae8c789a258c70a
1321 (partial): run Python pretxnchangegroup hooks before disk flush.

Since these hooks are passed an in-memory repository object, it is
unnecessary to have flushed disk changes to 00changelog first. Running
them before the flush means that if one of them aborts the
transaction, other Hg processes pulling from the repo will never see
the rejected changesets even for a moment. That means that there is no
need for the push-gate hack (except perhaps for slow hooks which
should not run synchronously during the push).

Fixing external pretxnchangegroup hooks seems possible but would be
more work, and big sites concerned about this issue are likely to be
using in-process hooks for their power and speed anyway.

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -88,7 +88,7 @@
     global _redirect
     _redirect = state
 
-def hook(ui, repo, name, throw=False, **args):
+def hook(ui, repo, name, throw=False, pythononly=False, extonly=False, **args):
     r = False
 
     if _redirect:
@@ -101,11 +101,14 @@
             if hname.split('.')[0] != name or not cmd:
                 continue
             if callable(cmd):
+                if extonly: continue
                 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
             elif cmd.startswith('python:'):
+                if extonly: continue
                 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(),
                                 args, throw) or r
             else:
+                if pythononly: continue
                 r = _exthook(ui, repo, hname, cmd, args, throw) or r
     finally:
         if _redirect:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2030,6 +2030,11 @@
                 revisions += len(fl) - o
                 files += 1
 
+            if changesets > 0:
+                self.hook('pretxnchangegroup', throw=True,
+                          node=hex(self.changelog.node(cor+1)), source=srctype,
+                          url=url, pythononly=True)
+
             # make changelog see real files again
             cl.finalize(trp)
 
@@ -2045,7 +2050,7 @@
             if changesets > 0:
                 self.hook('pretxnchangegroup', throw=True,
                           node=hex(self.changelog.node(cor+1)), source=srctype,
-                          url=url)
+                          url=url, extonly=True)
 
             tr.close()
         finally:


More information about the Mercurial-devel mailing list