#
# 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")
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))
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"""
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)
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__":