[PATCH] keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert
blacktrash at gmx.net
Wed Feb 13 21:48:21 UTC 2008
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1202939194 -3600
# Node ID 805afb5c82d819b0bf6bfc4d8f1a83e93a3b190d
# Parent e85deb6dcf9d9265a2a35b5ec6fac36dfed28aee
keyword: monkeypatch patch.diff for non-interactive diffs
Avoid clobbering diffs with expanded keywords eg. for
notify extension.
diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -94,7 +94,7 @@
# hg commands that trigger expansion only when writing to working dir,
# not when reading filelog, and unexpand when reading from working dir
-restricted = 'diff1 record qfold qimport qnew qpush qrefresh qrecord'
+restricted = 'record qfold qimport qnew qpush qrefresh qrecord'
def utcdate(date):
'''Returns hgdate in cvs-like UTC format.'''
@@ -105,6 +105,7 @@
# store originals of monkeypatches
_patchfile_init = patch.patchfile.__init__
+_patch_diff = patch.diff
_dispatch_parse = dispatch._parse
def _kwpatchfile_init(self, ui, fname, missing=False):
@@ -115,6 +116,16 @@
# shrink keywords read from working dir
kwshrunk = _kwtemplater.shrink(''.join(self.lines))
self.lines = kwshrunk.splitlines(True)
+
+def _kw_diff(repo, node1=None, node2=None, files=None, match=util.always,
+ fp=None, changes=None, opts=None):
+ # only expand if comparing against working dir
+ if node2 is not None:
+ _kwtemplater.matcher = util.never
+ if node1 is not None and node1 != repo.changectx().node():
+ _kwtemplater.restrict = True
+ _patch_diff(repo, node1=node1, node2=node2, files=files, match=match,
+ fp=fp, changes=changes, opts=opts)
def _kwweb_changeset(web, req, tmpl):
'''Wraps webcommands.changeset turning off keyword expansion.'''
@@ -453,15 +464,6 @@
if not inc:
return
- if hgcmd == 'diff':
- # only expand if comparing against working dir
- node1, node2 = cmdutil.revpair(repo, hgcmdopts.get('rev'))
- if node2 is not None:
- return
- # shrink if rev is not current node
- if node1 is not None and node1 != repo.changectx().node():
- hgcmd = 'diff1'
-
_kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd)
class kwrepo(repo.__class__):
@@ -523,6 +525,7 @@
repo.__class__ = kwrepo
patch.patchfile.__init__ = _kwpatchfile_init
+ patch.diff = _kw_diff
webcommands.changeset = webcommands.rev = _kwweb_changeset
webcommands.filediff = webcommands.diff = _kwweb_filediff
More information about the Mercurial-devel
mailing list