[PATCH] transplant: update transplants file when a new changegroup arrives

Georg Brandl georg at python.org
Sat Aug 28 16:51:37 CDT 2010


# HG changeset patch
# User Georg Brandl <georg at python.org>
# Date 1283032261 -7200
# Node ID f1d2beebdbc84232d928ce0aab7754dd2c67ccd2
# Parent  a8b1cb0b0ddb63d32294d4e0edb464c7006275c7
transplant: update transplants file when a new changegroup arrives

While the transplant extension records each transplanted changeset's source in
the "transplant_source" extra item of the changeset, it also maintains a cache
of this information in .hg/transplant, which is consulted when checking for
already transplanted changesets.  When changesets are not transplanted in the
local clone, the cache file becomes outdated.

This change makes transplant update the cache file when receiving changesets,
so that (as long as the extension is enabled) the cache file contents should
be complete.

BTW, I am not sure if this is the right way of adding a hook in an extension,
or even the right way of reacting to a changegroup.

diff -r a8b1cb0b0ddb -r f1d2beebdbc8 hgext/transplant.py
--- a/hgext/transplant.py	Fri Aug 27 22:24:47 2010 -0500
+++ b/hgext/transplant.py	Sat Aug 28 23:51:01 2010 +0200
@@ -16,7 +16,7 @@
 from mercurial.i18n import _
 import os, tempfile
 from mercurial import bundlerepo, changegroup, cmdutil, hg, merge, match
-from mercurial import patch, revlog, util, error, discovery
+from mercurial import patch, revlog, util, error, discovery, extensions, ui
 
 class transplantentry(object):
     def __init__(self, lnode, rnode):
@@ -598,6 +598,35 @@
             source.close()
             os.unlink(bundle)
 
+def updatetransplantfile(ui, repo, hooktype, **kwds):
+    '''installed as a changegroup hook, records pulled transplanted changesets
+    in the repository's transplants file'''
+    newtransplants = []
+    firstrev = repo[kwds['node']].rev()
+    for revno in range(firstrev, len(repo.changelog)):
+        ctx = repo[revno]
+        source = ctx.extra().get('transplant_source')
+        if source:
+            newtransplants.append((ctx.node(), source))
+    if newtransplants:
+        path = repo.join('transplant')
+        tp = transplants(path, 'transplants', opener=util.opener(path))
+        for left, right in newtransplants:
+            tp.set(left, right)
+        tp.write()
+        ui.debug(_('recorded %d transplanted changeset(s)') %
+                 len(newtransplants))
+    else:
+        ui.debug(_('no new transplanted changesets found'))
+
+def configitems(orig, self, section, untrusted=False):
+    items = orig(self, section, untrusted)
+    if section == 'hooks':
+        items.append(('changegroup.__transplant__', updatetransplantfile))
+    return items
+
+extensions.wrapfunction(ui.ui, 'configitems', configitems)
+
 cmdtable = {
     "transplant":
         (transplant,


More information about the Mercurial-devel mailing list