Reg : Keyword expansion

Roger Gammans roger at computer-surgery.co.uk
Tue Aug 31 11:25:23 UTC 2010


On Mon, Aug 30, 2010 at 03:55:00PM +0100, Christian Ebert wrote:
> But the keyword extension /does/ behave like SVN or CVS: it
> expands the keywords to the data of the changeset when the file
> in question was changed, not to working directory parent.
> 
> Roger Gammons would like to have a different behaviour 

Actually I think I want /both/ behaviours, and having given it 
some thought the current kw behaviour is works well for
developers/engineers between release cycles. But I still need the
releases to be marked differently for which added a release build script 
which tags the repo and places the repo wide versioning on all 
the kw expansions  should do the trick . This mix of both practices means 
both release and non-release drawings are meaningfully versioned.

I'm pleased with the broad range of approaches that this discussion has
brought forward, and feel I have enough ideas that I will be able to
implement what I would like in some manner. 

> (can be
> implemented with decode/encode filterpairs I'd think).

There is warning about using on the EncodeDecodeFilter wiki page about
using it for keyword expansion. My almost working patch for the kw
extension is pretty trivial after all, look:-

--- /usr/share/pyshared/hgext/keyword.py	2010-04-01 23:49:36.000000000 +0100
+++ py/keyword.py	2010-08-31 11:56:35.000000000 +0100
@@ -167,7 +167,7 @@
         '''Overwrites selected files expanding/shrinking keywords.'''
         ctx = self.repo[node]
         mf = ctx.manifest()
-        if node is not None:     # commit
+        if files is None:     # commit
             files = [f for f in ctx.files() if f in mf]
             notify = self.ui.debug
         else:                    # kwexpand/kwshrink
@@ -259,7 +259,11 @@
         raise util.Abort(_('[keyword] patterns cannot match'))
     raise util.Abort(_('no [keyword] patterns configured'))
 
-def _kwfwrite(ui, repo, expand, *pats, **opts):
+def update(ui, repo,  *pats, **opts):
+    '''Expands keywords to repo wide versioning.'''
+    _kwfwrite(ui, repo, True, False , *pats, **opts)
+
+def _kwfwrite(ui, repo, expand, filewise ,*pats, **opts):
     '''Selects files and passes them to kwtemplater.overwrite.'''
     if repo.dirstate.parents()[1] != nullid:
         raise util.Abort(_('outstanding uncommitted merge'))
@@ -272,7 +276,9 @@
     try:
         wlock = repo.wlock()
         lock = repo.lock()
-        kwt.overwrite(None, expand, status[6])
+        ctx = None
+        if not filewise: ctx = str(repo['.'])
+        kwt.overwrite(ctx, expand, status[6])
     finally:
         release(lock, wlock)
 
@@ -370,7 +376,7 @@
     kwexpand refuses to run if given files contain local changes.
     '''
     # 3rd argument sets expansion to True
-    _kwfwrite(ui, repo, True, *pats, **opts)
+    _kwfwrite(ui, repo, True ,True, *pats, **opts)
 
 def files(ui, repo, *pats, **opts):
     '''show files configured for keyword expansion
@@ -424,7 +430,7 @@
     kwshrink refuses to run if given files contain local changes.
     '''
     # 3rd argument sets expansion to False
-    _kwfwrite(ui, repo, False, *pats, **opts)
+    _kwfwrite(ui, repo, False ,True, *pats, **opts)
 
 
 def uisetup(ui):
@@ -535,6 +541,8 @@
          _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')),
     'kwexpand': (expand, commands.walkopts,
                  _('hg kwexpand [OPTION]... [FILE]...')),
+    'kwupdate': (update, commands.walkopts,
+                 _('hg kwexpand [OPTION]... [FILE]...')),
     'kwfiles':
         (files,
          [('A', 'all', None, _('show keyword status flags of all files')),


The only problem it has is that it doesn't hide the mods from 
status , diff ,etc. Which the kwexpand does.

TTFN
-- 
Roger. 	                        Home| http://www.sandman.uklinux.net/
Master of Peng Shui.      (Ancient oriental art of Penguin Arranging)
Work|Independent Sys Consultant | http://www.computer-surgery.co.uk/
 New key Fpr: 0F2F E1DF 4CD2 5E7B EF9F  B173 4CFA F143 ADBE 6B00 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20100831/6ae78efb/attachment.asc>


More information about the Mercurial mailing list