]> thyrsus.com Git - src.git/commitdiff
Factor out a predicate. Regression test passes.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 23:43:03 +0000 (18:43 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 23:43:03 +0000 (18:43 -0500)
src

diff --git a/src b/src
index ff8638cb0d50223c29e4f387aa55144b0f60c40a..6ffd6a23ea2b494fddb5c08272124c74713eae9e 100755 (executable)
--- a/src
+++ b/src
@@ -167,6 +167,10 @@ class HistoryEntry:
         except (TypeError, ValueError):
             croak("garbled date %s" % self.date)
 
+def registered(fn):
+    "Is this a workfile for a registered history?"
+    return os.path.exists(backend.history(fn))
+
 class History:
     "Encapsulate a revision list and some methods on it"
     def __init__(self, name):
@@ -175,7 +179,7 @@ class History:
         self.symbols = {}
         self.branch = "trunk"
         self.lockrevs = []
-        if not os.path.exists(backend.history(self.name)):
+        if not registered(self.name):
             croak("%s is not registered" % self.name)
         backend.parse(self)
         self.by_revno_d = {}
@@ -644,7 +648,7 @@ def commit_method(*args):
     for arg in ctx.args:
         if not os.path.exists(arg):
             croak("I see no '%s' here." % arg)
-        if os.path.exists(backend.history(arg)):
+        if registered(arg):
             metadata = History(arg)
             ctx.resolve(metadata)
             if ctx.is_empty():
@@ -657,7 +661,7 @@ def commit_method(*args):
         if not comment.edit(content="", trailer=trailer):
             announce("in %s, commit cancelled" % arg)
         else:
-            if not os.path.exists(backend.history(arg)):
+            if not registered(arg):
                 backend.add(arg)
             with backend.lifter(arg):
                 backend.checkin(arg, comment.content())
@@ -676,7 +680,7 @@ def amend_method(*args):
     for arg in ctx.args:
        if not os.path.exists(arg):
            croak("I see no '%s' here." % arg)
-       elif not os.path.exists(backend.history(arg)):
+       elif not registered(arg):
            croak("%s is not registered." % arg)
     for arg in ctx.args:
         metadata = History(arg)
@@ -946,9 +950,9 @@ def filecmd(legend, hook, args):
     (source, target) = args
     if not os.path.exists(source):
         croak("I see no '%s' here." % source)
-    elif not os.path.exists(backend.history(source)):
+    elif not registered(source):
         croak("%s is not registered, skipping" % source)
-    elif os.path.exists(backend.history(target)):
+    elif registered(target):
         croak("%s is registered, I won't step on it" % source)
     elif os.path.exists(target):
         croak("%s exists, please delete manually if you want it gone" % target)
@@ -969,7 +973,7 @@ def release_method(*args):
     for arg in ctx.args:
         if not os.path.exists(arg):
             croak("I see no '%s' here." % arg)
-        elif not os.path.exists(backend.history(arg)):
+        elif not registered(arg):
             croak("%s is not registered, skipping" % arg)
         else:
             with backend.lifter(arg):
@@ -999,7 +1003,7 @@ def fast_export_method(*args):
         useremail = capture_or_die("git config --get user.email").strip()
     attribution = "%s <%s>" % (username, useremail)
     for arg in ctx.args:
-        if not os.path.exists(backend.history(arg)):
+        if not registered(arg):
             croak("%s is not registered" % arg)
         executable = os.stat(arg).st_mode & stat.S_IXUSR
         if executable: