]> thyrsus.com Git - src.git/commitdiff
Faster status check.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 9 Nov 2014 02:54:12 +0000 (21:54 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 9 Nov 2014 02:54:12 +0000 (21:54 -0500)
src

diff --git a/src b/src
index f77e47a2f34d9dc903b309439d80d9f329fd6e94..5dabdab5b27b94e3b12c1d6bcf68cae3776ca8a7 100755 (executable)
--- a/src
+++ b/src
@@ -526,17 +526,13 @@ def status_method(*args):
         masterbase = os.path.basename(backend.master(fn))
         if masterbase not in registered:
             pairs.append((fn, "?"))
-            continue
         elif not os.path.exists(fn):
             pairs.append((fn, "!"))
-            continue
         # Relies on the fact that we touch the file with utimes(2)
         # each time it's checked out.
         elif os.path.getmtime(fn) > os.path.getmtime(backend.master(fn)):
             pairs.append((fn, "M"))
-            continue
-        metadata = History(fn)
-        if len(metadata) == 0:
+        elif not backend.has_revisions(fn):
             pairs.append((fn, "A"))
         else:
             pairs.append((fn, "U"))
@@ -801,6 +797,20 @@ class RCS:
             return os.path.join(os.path.dirname(arg),
                                 repodir,
                                 os.path.basename(arg) + ",v")
+    def has_revisions(self, arg):
+        "Does the master for this file have any revisions"
+        # The magic number 105 is the size of an empty RCS file (no
+        # metadata, no revisions) at 76 bytes, plus 29 bytes. We
+        # assume that this ize has stayed constant or increased since
+        # ancient times. In fact the size of an RCS file with revisions
+        # goes up more - by the 78 bytes for the final, fixed line of the
+        # log display.  This gives us plenty of slack to cope with
+        # minor format differences.
+        #
+        # The motivation here is to make "src status" faster by avoid
+        # the need for an entire log parse when checking for "A"
+        # status.
+        return os.path.getsize(self.master(arg)) > 105
     def workfile(self, arg):
         return arg[:-2]
     def add(self, arg):