From 464cea28a7c3e3c8e61c61b6963ab9861542f975 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 13 Nov 2014 18:43:03 -0500 Subject: [PATCH] Factor out a predicate. Regression test passes. --- src | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src b/src index ff8638c..6ffd6a2 100755 --- 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: -- 2.43.0