hgkw/keyword.py
changeset 213 948500df7c55
parent 211 110c76a94d1c
child 216 f35a0c382168
--- a/hgkw/keyword.py	Tue Jul 24 14:53:39 2007 +0200
+++ b/hgkw/keyword.py	Tue Jul 24 15:04:33 2007 +0200
@@ -83,7 +83,7 @@
 from mercurial import commands, cmdutil, context, fancyopts
 from mercurial import filelog, localrepo, templater, util, hg
 from mercurial.i18n import gettext as _
-import os, re, shutil, sys, tempfile, time
+import re, shutil, sys, tempfile, time
 
 # findcmd, bail_if_changed were in commands until 0c61124ad877
 try:
@@ -253,6 +253,16 @@
         return util.matcher(repo.root, inc=inc, exc=exc)[1]
     return None
 
+def _weedcandidates(man, kwfmatcher, candidates):
+    '''Weeds out files that do not match keyword file matcher,
+    are not tracked, or are links.'''
+    files = man.keys()
+    if candidates:
+        return [f for f in candidates if kwfmatcher(f)
+                and f in files and not man.linkf(f)]
+    # kwexpand w/o args on all files in manifest
+    return [f for f in files if kwfmatcher(f) and not man.linkf(f)]
+
 def _overwrite(ui, repo, files, expand):
     '''Expands/shrinks keywords in working directory.'''
     wlock = lock = None
@@ -267,22 +277,14 @@
         if kwfmatcher is None:
             ui.warn(_('no files configured for keyword expansion\n'))
             return
-        m = ctx.manifest()
-        if files:
-            files = [f for f in files if f in m.keys()]
-        else:
-            files = m.keys()
-        if hasattr(repo, '_link'):
-            files = [f for f in files if kwfmatcher(f) and not repo._link(f)]
-        else:
-            files = [f for f in files if kwfmatcher(f)
-                     and not os.path.islink(repo.wjoin(f))]
+        man = ctx.manifest()
+        files = _weedcandidates(man, kwfmatcher, files)
         if not files:
             ui.warn(_('files not configured for expansion or untracked\n'))
             return
         commit = False
         kwt = kwtemplater(ui, repo, expand, node=ctx.node())
-        kwt.overwrite(files, m, commit)
+        kwt.overwrite(files, man, commit)
     finally:
         del wlock, lock
 
@@ -459,16 +461,9 @@
                                               p1=p1, p2=p2, extra=extra)
                 if node is not None:
                     cl = self.changelog.read(node)
-                    if hasattr(self, '_link'):
-                        candidates = [f for f in cl[3] if kwfmatcher(f)
-                                      and f not in removed
-                                      and not self._link(f)]
-                    else:
-                        candidates = [f for f in cl[3] if kwfmatcher(f)
-                                      and f not in removed
-                                      and not os.path.islink(self.wjoin(f))]
+                    mn = self.manifest.read(cl[0])
+                    candidates = _weedcandidates(mn, kwfmatcher, cl[3])
                     if candidates:
-                        mn = self.manifest.read(cl[0])
                         expand = commit = True
                         kwt = kwtemplater(ui, self, expand, node=node)
                         kwt.overwrite(candidates, mn, commit)
@@ -484,7 +479,7 @@
         (demo,
          [('d', 'default', None, _('show default keyword template maps')),
           ('f', 'rcfile', [], _('read maps from RCFILE'))],
-         _('hg kwdemo [-d || [-f RCFILE] TEMPLATEMAP ...]')),
+         _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP ...]')),
     'kwshrink': (shrink, [], _('hg kwshrink [NAME] ...')),
     'kwexpand': (expand, [], _('hg kwexpand [NAME] ...')),
 }