[PATCH 1 of 2] keyword: disable expansion for "hg diff" to avoid distracting output

Christian Ebert blacktrash at gmx.net
Sun Jan 13 14:16:05 CST 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1200250682 -3600
# Node ID 17a1ed371f07310ea4c930e2bbffedc80d6528b0
# Parent  9e2571d12471504fcc332e50937d914118c73725
keyword: disable expansion for "hg diff" to avoid distracting output

Expanded keywords might yield additional differences.
However we need setup of kwrepo to detect expanded keywords in
working dir.

Implementation:
- disable expansion when reading filelog
- shrink expanded keywords when reading from working dir (wread)

At the moment this happens for "diff" only; other commands can be added.

Adjust test output.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -395,20 +395,21 @@ def reposetup(ui, repo):
     This is done for local repos only, and only if there are
     files configured at all for keyword substitution.'''
 
-    def kwbailout():
-        '''Obtains command via simplified cmdline parsing,
-        returns True if keyword expansion not needed.'''
-        nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy',
-                        'export', 'grep', 'identify', 'incoming', 'init',
-                        'log', 'outgoing', 'push', 'remove', 'rename',
-                        'rollback', 'tip',
-                        'convert')
-        args = fancyopts.fancyopts(sys.argv[1:], commands.globalopts, {})
-        if args:
-            aliases, i = cmdutil.findcmd(ui, args[0], commands.table)
-            return aliases[0] in nokwcommands
+    if not repo.local():
+        return
 
-    if not repo.local() or kwbailout():
+    nokwcommands = ('add', 'addremove', 'bundle', 'clone', 'copy', 'export',
+                    'grep', 'identify', 'incoming', 'init', 'log', 'outgoing',
+                    'push', 'remove', 'rename', 'rollback', 'tip',
+                    'convert')
+
+    hgcmd = None
+    args = fancyopts.fancyopts(sys.argv[1:], commands.globalopts, {})
+    if args:
+        aliases, i = cmdutil.findcmd(ui, args[0], commands.table)
+        hgcmd = aliases[0]
+
+    if hgcmd in nokwcommands:
         return
 
     inc, exc = [], ['.hgtags']
@@ -427,9 +428,15 @@ def reposetup(ui, repo):
         def file(self, f, kwmatch=False):
             if f[0] == '/':
                 f = f[1:]
-            if kwmatch or _kwtemplater.matcher(f):
+            if hgcmd != 'diff' and (kwmatch or _kwtemplater.matcher(f)):
                 return kwfilelog(self.sopener, f)
             return filelog.filelog(self.sopener, f)
+
+        def wread(self, filename):
+            data = super(kwrepo, self).wread(filename)
+            if hgcmd == 'diff' and _kwtemplater.matcher(filename):
+                return _kwtemplater.shrink(data)
+            return data
 
         def commit(self, files=None, text='', user=None, date=None,
                    match=util.always, force=False, force_editor=False,
diff --git a/tests/test-keyword.out b/tests/test-keyword.out
--- a/tests/test-keyword.out
+++ b/tests/test-keyword.out
@@ -184,7 +184,7 @@ diff -r f782df5f9602 c
 diff -r f782df5f9602 c
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
 @@ -0,0 +1,3 @@
-+expand $Id: c,v 0ba462c0f077 1970/01/01 00:00:01 user $
++expand $Id$
 +do not process $Id:
 +xxx $
 % rollback


More information about the Mercurial-devel mailing list