[PATCH 3 of 5 V2] revlog: add a callback for when revisions are added
Gregory Szorc
gregory.szorc at gmail.com
Wed Jul 15 17:32:06 CDT 2015
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1436997222 25200
# Wed Jul 15 14:53:42 2015 -0700
# Node ID 3c13ae7f08b610bb5ff0e7aba3a3e35d0369983c
# Parent 8510f2a1d3b2ec3231391dc0cf9a865b696a22cb
revlog: add a callback for when revisions are added
A subsequent patch will add a feature that performs iterative
computation as changesets are added from a changegroup. To facilitate
this type of processing in a generic manner, we add a mechanism for
calling a function whenever a revision is added from a changegroup.
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1235,9 +1235,10 @@ class revlog(object):
return ('u', text)
return ("", bin)
def _addrevision(self, node, text, transaction, link, p1, p2, flags,
- cachedelta, ifh, dfh, returntext=False):
+ cachedelta, ifh, dfh, returntext=False,
+ addrevisioncb=None):
"""internal function to add revisions to the log
see addrevision for argument descriptions.
invariants:
@@ -1364,8 +1365,11 @@ class revlog(object):
if type(text) == str: # only accept immutable objects
self._cache = (node, curr, text)
self._basecache = (curr, chainbase)
+ if addrevisioncb:
+ addrevisioncb(self, node)
+
if returntext:
return node, buildtext()
else:
return node
@@ -1387,15 +1391,19 @@ class revlog(object):
ifh.write(data[0])
ifh.write(data[1])
self.checkinlinesize(transaction, ifh)
- def addgroup(self, bundle, linkmapper, transaction):
+ def addgroup(self, bundle, linkmapper, transaction, addrevisioncb=None):
"""
add a delta group
given a set of deltas, add them to the revision log. the
first delta is against its parent, which should be in our
log, the rest are against the previous delta.
+
+ If ``addrevisioncb`` is specified, it will be called with arguments of
+ this revlog instance and the node that was added. Derived classes may
+ change the arguments.
"""
# track the base of the current delta log
content = []
@@ -1466,9 +1474,10 @@ class revlog(object):
flags |= REVIDX_ISCENSORED
chain = self._addrevision(node, None, transaction, link,
p1, p2, flags, (baserev, delta),
- ifh, dfh)
+ ifh, dfh,
+ addrevisioncb=addrevisioncb)
if not dfh and not self._inline:
# addrevision switched from inline to conventional
# reopen the index
ifh.close()
More information about the Mercurial-devel
mailing list