[PATCH 2 of 3] keyword: avoid extra diffs when not comparing against working dir

Christian Ebert blacktrash at gmx.net
Tue Jan 15 08:47:17 CST 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1200404393 -3600
# Node ID b7304d95fc1547134473d5107dad0bfad3d3c747
# Parent  d82b42d67d7b38f643fda4e115c4ff72478fa850
keyword: avoid extra diffs when not comparing against working dir

When diffing against specified revisions expanded keywords
only get in the way.

Update test output.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -94,7 +94,8 @@ def _kwrestrict(cmd):
     '''Returns True if cmd should trigger restricted expansion.
     Keywords will only expanded when writing to working dir.
     Crucial for mq as expanded keywords should not make it into patches.'''
-    return cmd in ('qimport', 'qnew', 'qpush', 'qrefresh', 'record', 'qrecord')
+    return cmd in ('diff1', 
+                   'qimport', 'qnew', 'qpush', 'qrefresh', 'record', 'qrecord')
 
 
 _kwtemplater = None
@@ -419,6 +420,15 @@ def reposetup(ui, repo):
     if hgcmd in nokwcommands:
         return
 
+    if hgcmd == 'diff':
+        # only expand if comparing against working dir
+        node1, node2 = cmdutil.revpair(repo, cmdopts.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'
+
     inc, exc = [], ['.hgtags']
     for pat, opt in ui.configitems('keyword'):
         if opt != 'ignore':
diff --git a/tests/test-keyword.out b/tests/test-keyword.out
--- a/tests/test-keyword.out
+++ b/tests/test-keyword.out
@@ -188,7 +188,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