hgkw/keyword.py
changeset 273 a283665ad7cd
parent 272 02d012b9dd56
child 274 231b408b1f6b
--- a/hgkw/keyword.py	Wed Oct 17 13:22:48 2007 +0200
+++ b/hgkw/keyword.py	Wed Oct 17 17:03:59 2007 +0200
@@ -308,13 +308,19 @@
             return t2 != text
         return revlog.revlog.cmp(self, node, text)
 
-def _kwbailout(ui):
+def _bail_if_nokwconf(ui):
+    if hasattr(ui, 'kwfmatcher'):
+        return
     if ui.configitems('keyword'):
         raise util.Abort(_('[keyword] patterns cannot match'))
     raise util.Abort(_('no [keyword] patterns configured'))
 
+def _iskwfile(ui, man, f):
+    return not man.linkf(f) and ui.kwfmatcher(f)
+
 def _overwrite(ui, repo, expand, *pats, **opts):
     '''Expands/shrinks keywords in working directory.'''
+    _bail_if_nokwconf(ui)
     bail_if_changed(repo)
     wlock = lock = None
     try:
@@ -328,21 +334,14 @@
         mfiles = man.keys()
         mfiles.sort()
         files = []
-        
-        def iskwfile(f):
-            try:
-                return ui.kwfmatcher(f) and not man.linkf(f)
-            except AttributeError:
-                _kwbailout(ui)
-
         for f in mfiles:
             for ff in fdict:
                 if ff == f or ff.startswith('%s/' % f):
-                    if iskwfile(ff):
+                    if _iskwfile(ui, man, ff):
                         files.append(ff)
                     del fdict[ff]
                     break
-            if not f in files and match(f) and iskwfile(f):
+            if not f in files and match(f) and _iskwfile(ui, man, f):
                 files.append(f)
         if files:
             kwt = kwtemplater(ui, repo, expand, node=ctx.node())
@@ -376,6 +375,7 @@
     keyword expansion.
     That is, files matched by [keyword] config patterns but not symlinks.
     '''
+    _bail_if_nokwconf(ui)
     files, match, anypats = cmdutil.matchpats(repo, pats, opts)
     status = repo.status(files=files, match=match, list_clean=True)
     modified, added, removed, deleted, unknown, ignored, clean = status
@@ -384,12 +384,9 @@
     else:
         files = modified + added + clean
     files.sort()
-    try:
-        # use the full definition of repo._link for backwards compatibility
-        kwfiles = [f for f in files if ui.kwfmatcher(f)
-                   and not os.path.islink(repo.wjoin(f))]
-    except AttributeError:
-        _kwbailout(ui)
+    # use the full definition of repo._link for backwards compatibility
+    kwfiles = [f for f in files if ui.kwfmatcher(f)
+               and not os.path.islink(repo.wjoin(f))]
     cwd = pats and repo.getcwd() or ''
     allf = opts['all']
     ignore = opts['ignore']
@@ -553,8 +550,8 @@
                 if node is not None:
                     cl = self.changelog.read(node)
                     mn = self.manifest.read(cl[0])
-                    candidates = [f for f in cl[3] if ui.kwfmatcher(f)
-                                  and mn.has_key(f) and not mn.linkf(f)]
+                    candidates = [f for f in cl[3] if mn.has_key(f)
+                                  and _iskwfile(ui, mn, f)]
                     if candidates:
                         # 3rd argument sets expansion to True
                         kwt = kwtemplater(ui, self, True, node=node)