]> thyrsus.com Git - src.git/commitdiff
Status (no help for this).
authorEric S. Raymond <esr@thyrsus.com>
Thu, 6 Nov 2014 18:48:28 +0000 (13:48 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 6 Nov 2014 18:48:28 +0000 (13:48 -0500)
src

diff --git a/src b/src
index d9ca235f92547e89cd1973c0b1059d86c59962eb..9318a5a54f33ac4c85e91a8beacf91cc96f7a156 100755 (executable)
--- a/src
+++ b/src
@@ -2,10 +2,14 @@
 #
 # src - simple revision control.
 #
-import sys, os, subprocess
+import sys, os, subprocess, time
 
 version = 0.1
 
+def rfc3339(t):
+    "RFC3339 string from Unix time."
+    return time.strftime(b"%Y-%m-%dT%H:%M:%SZ", time.gmtime(t))
+
 def announce(msg):
     sys.stdout.write("src: " + msg + "\n")
 
@@ -46,7 +50,7 @@ class popen_or_die:
         self.fp = None
     def __enter__(self):
         if debug >= DEBUG_COMMANDS:
-            if self.mode == "r":
+            if self.mode == "rb":
                 announce(b"%s: reading from '%s'%s" % (rfc3339(time.time()), self.command, self.legend))
             else:
                 announce(b"%s: writing to '%s'%s" % (rfc3339(time.time()), self.command, self.legend))
@@ -65,6 +69,15 @@ class popen_or_die:
             complain(b"%s%s returned error." % (self.command, self.legend))
         return False
 
+def revcount(fn):
+    "Count revisions in the log output from an RCS file."
+    with popen_or_die("cd .src >/dev/null; rlog %s; cd ..>/dev/null" % fn) as fp:
+        revno = 0
+        for line in fp:
+            if line.startswith("----------------------------"):
+                revno += 1
+    return revno
+
 def help_method(*args):
     "Summarize src commands, or (with argument) show help for a single command."
     print"""
@@ -131,7 +144,7 @@ def add_method(*args):
        elif os.path.exists(".src/%s,v" % arg):
            complain("%s is already registered." % arg)
        else:
-           do_or_die("rcs -q -i %s </dev/null" % arg)
+           do_or_die("rcs -q -kk -i %s </dev/null" % arg)
            do_or_die("ci -l %s && mv %s,v .src" % (arg, arg))
            announce("%s: 1" % arg) 
 
@@ -145,13 +158,19 @@ def commit_method(*args):
            complain("%s is not registered." % arg)
        else:
            do_or_die("mv .src/{0},v . && ci -l {0} && mv {0},v .src".format(arg))
-           #announce("%s: 1" % arg) 
+           announce("%s %d" % (arg, revcount(arg))) 
+
+def status_method(*args):
+    args = preamble("status", args)
+    for arg in args:
+        announce("%s %d" % (arg, revcount(arg))) 
 
 dispatch = {
     "help":   help_method,
     "init":   init_method,
     "add":    add_method,
     "commit": commit_method,
+    "status": status_method,
 }
 
 if __name__ == "__main__":