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

Christian Ebert blacktrash at gmx.net
Mon Jan 14 02:11:50 CST 2008


* Christian Ebert on Sunday, January 13, 2008 at 21:16:05 +0100
> # 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)

This is an alternative and less radical approach which might make
more sense:

keyword expansion is disabled for "hg diff" only when comparing 2
explicitly specified revisions.

This has the advantage that keywords that haven't been updated
(example: "partial" commits by "hg record") are recognized as
differences.

Opinions on which route to take?

c


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1200298211 -3600
# Node ID b8743764f0ed6da8d98e60ce2b590d27724c51f3
# Parent  8b95f598097c99ccdb25ca18dede3ac97b0ac817
keyword: for diff expand only when comparing against working dir

When comparing 2 explicitly specified revisions the additional
difference caused by keyword expansion is only distracting.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -74,7 +74,7 @@ like CVS' $Log$, are not supported. A ke
 "Log = {desc}" expands to the first line of the changeset description.
 '''
 
-from mercurial import commands, cmdutil, context, fancyopts, filelog
+from mercurial import commands, cmdutil, context, dispatch, filelog
 from mercurial import patch, localrepo, revlog, templater, util
 from mercurial.node import *
 from mercurial.i18n import _
@@ -403,10 +403,12 @@ def reposetup(ui, repo):
                         '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
+        cmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
+        if cmd == 'diff':
+            # only expand if comparing against working dir
+            node1, node2 = cmdutil.revpair(repo, cmdopts.get('rev'))
+            return node2 is not None
+        return cmd in nokwcommands
 
     if not repo.local() or kwbailout():
         return


More information about the Mercurial-devel mailing list