hgkw/keyword.py
changeset 280 2088e409d360
parent 278 232df68a0bcc
child 282 2386cdd2ef2e
--- a/hgkw/keyword.py	Fri Oct 19 12:36:32 2007 +0200
+++ b/hgkw/keyword.py	Fri Oct 19 16:09:56 2007 +0200
@@ -98,12 +98,6 @@
     except AttributeError:
         _parse = commands.parse
 
-try:
-    # bail_if_changed moves from commands to cmdutil in 0c61124ad877
-    bail_if_changed = cmdutil.bail_if_changed
-except AttributeError:
-    bail_if_changed = commands.bail_if_changed
-
 def _pathto(repo, f, cwd=None):
     '''kwfiles behaves similar to status, using pathto since 78b6add1f966.'''
     try:
@@ -310,9 +304,10 @@
             return t2 != text
         return revlog.revlog.cmp(self, node, text)
 
-def _bail_if_nokwconf(ui):
+def _status(ui, repo, *pats, **opts):
     if hasattr(ui, 'kwfmatcher'):
-        return
+        files, match, anypats = cmdutil.matchpats(repo, pats, opts)
+        return repo.status(files=files, match=match, list_clean=True)
     if ui.configitems('keyword'):
         raise util.Abort(_('[keyword] patterns cannot match'))
     raise util.Abort(_('no [keyword] patterns configured'))
@@ -329,35 +324,19 @@
 
 def _kwfwrite(ui, repo, expand, *pats, **opts):
     '''Selects files and passes them to _overwrite.'''
-    _bail_if_nokwconf(ui)
-    bail_if_changed(repo)
+    status = _status(ui, repo, *pats, **opts)
+    modified, added, removed, deleted, unknown, ignored, clean = status
+    if modified or added or removed or deleted:
+        raise util.Abort(_('outstanding uncommitted changes in given files'))
     wlock = lock = None
     try:
         wlock = repo.wlock()
         lock = repo.lock()
-        files, match, anypats = cmdutil.matchpats(repo, pats, opts)
-        fdict = dict.fromkeys(files)
-        fdict.pop('.', None)
         ctx = repo.changectx()
         man = ctx.manifest()
-        mfiles = man.keys()
-        mfiles.sort()
-        files = []
-        for f in mfiles:
-            for ff in fdict:
-                if ff == f or ff.startswith('%s/' % f):
-                    if _iskwfile(ui, man, ff):
-                        files.append(ff)
-                    del fdict[ff]
-                    break
-            if not f in files and match(f) and _iskwfile(ui, man, f):
-                files.append(f)
-        ffiles = fdict.keys()
-        ffiles.sort()
-        for f in ffiles:
-            ui.warn(_('%s: No such file in working copy\n') % _pathto(repo, f))
+        candidates = [f for f in clean if _iskwfile(ui, man, f)]
         # 7th argument sets commit to False
-        _overwrite(ui, repo, files, ctx.node(), man, expand, False)
+        _overwrite(ui, repo, candidates, ctx.node(), man, expand, False)
     finally:
         del wlock, lock
 
@@ -386,9 +365,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)
+    status = _status(ui, repo, *pats, **opts)
     modified, added, removed, deleted, unknown, ignored, clean = status
     if opts['untracked']:
         files = modified + added + unknown + clean