Subclassing notify
Ulrich Pfeifer
pfeifer at wait.de
Fri Apr 3 12:17:05 CDT 2009
Hello,
I tried to subclass notify to overwrite the part displaying a single
change set in the incoming hook:
else:
count = 1
n.node(node)
- n.diff(node, node)
+ n.diff_single(node)
data = ui.popbuffer()
n.send(node, count, data)
were diff_single differs from diff by this:
- def diff(self, node, ref):
+ def diff_single(self, node):
maxdiff = int(self.ui.config('notify', 'maxdiff', 300))
prev = self.repo.changelog.parents(node)[0]
- chunks = patch.diff(self.repo, prev, ref,
opts=patch.diffopts(self.ui))
+ chunks = patch.diff(self.repo, prev, node,
opts=patch.diffopts(self.ui))
difflines = ''.join(chunks).splitlines()
+ if len(self.repo.changelog.parents(node)) > 1:
+ right = self.repo.changelog.parents(node)[1]
+ chunks = patch.diff(self.repo, right, node,
opts=patch.diffopts(self.ui))
+ difflines_right = ''.join(chunks).splitlines()
+ self.ui.debug(_('\nleft=%s right=%s\nLeft %d lines, right
%d lines\n') % (short(prev), short(right), len(difflines),
len(difflines_right)))
+ if len(difflines_right) < len(difflines):
+ difflines = difflines_right
+
if self.ui.configbool('notify', 'diffstat', True):
s = patch.diffstat(difflines)
# s may be nil, don't include the header if it is
if s:
Basically in the merge case this is emitting the shorter diff. This
is far from perfect - but a start of what I wanted to do.
My problem now is, that with a fairly big repository (manifest has
about 65mb) the hg process bloats to above 750mb main memory.
It does not do that with the original hook.
The suclassing is done like this:
from hgext.notify import notifier
class vzbnotifier(notifier):
and
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
'''send email notifications to interested subscribers.
if used as changegroup hook, send one email for all changesets in
changegroup. else send one email per changeset.'''
- n = notifier(ui, repo, hooktype)
+ n = vzbnotifier(ui, repo, hooktype)
if not n.subs:
I am completely mystified by this. Any suggestions what is wrong with
my approach?
Thanks,
Ulrich
More information about the Mercurial
mailing list