From 3042de8658d532e451ac5ff5f1e0be772ed07770 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 6 Nov 2014 15:36:36 -0500 Subject: [PATCH] src log works. --- src | 60 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/src b/src index db86201..4c67d8c 100755 --- a/src +++ b/src @@ -6,6 +6,11 @@ import sys, os, subprocess, time version = 0.1 +def screenwidth(): + "Return the current width of the terminal window." + with popen_or_die(b'stty size', b"rb") as tp: + return int(tp.read().split()[1]) + def rfc3339(t): "RFC3339 string from Unix time." return time.strftime(b"%Y-%m-%dT%H:%M:%SZ", time.gmtime(t)) @@ -20,7 +25,7 @@ def croak(msg): sys.stderr.write("src: " + msg + "\n") sys.exit(1) -debug = 1 +debug = 0 DEBUG_COMMANDS = 1 # Show commands as they are executed def do_or_die(dcmd, legend=b""): @@ -62,15 +67,42 @@ class popen_or_die: % (self.command, self.legend, oe)) def __exit__(self, extype, value, traceback_unused): if extype: - if verbose: - complain(b"fatal exception in popen_or_die.") + complain(b"fatal exception in popen_or_die.") raise extype(value) if self.fp.close() is not None: complain(b"%s%s returned error." % (self.command, self.legend)) return False def log_capture(fn): - return popen_or_die("cd .src >/dev/null; rlog %s; cd ..>/dev/null" % fn) + "Capture and parse the metadata for a specified file." + with popen_or_die("cd .src >/dev/null; rlog %s; cd ..>/dev/null" % fn) as fp: + revlist = [] + maxrevno = 0 + state = "initial" + for line in fp: + if line.startswith("----------------------------"): + state = "logheader" + revlist.append(RCSRevisionItem(maxrevno)) + maxrevno += 1 + elif state == "logheader" and line.startswith("revision"): + fields = line.split() + revlist[-1].revision = fields[1] + elif state == "logheader" and line.startswith("date"): + fields = line.split() + date = fields[1] + " " + fields[2] + if date.endswith(";"): + date = date[:-1] + date = date.replace("/", "-").replace(" ", "T") + "Z" + revlist[-1].date = date + elif line.startswith("======================="): + if not revlist[-1].log.endswith("\n"): + revlist[-1].log += "\n" + break + elif revlist: + revlist[-1].log += line + for item in revlist: + item.revno = maxrevno - item.revno + return revlist def help_method(*args): "Summarize src commands, or (with argument) show help for a single command." @@ -154,16 +186,22 @@ def commit_method(*args): do_or_die("mv .src/{0},v . && ci -l {0} && mv {0},v .src".format(arg)) announce("%s %d" % (arg, revcount(arg))) +class RCSRevisionItem: + "Capture the state of an RCS revision item in the log." + def __init__(self, revno): + self.revno = revno; + self.revision = None + self.log = "" + self.date = None + def log_method(*args): args = preamble("log", args) + width = screenwidth() for arg in args: - sys.stdout.write("%s:\n" % arg) - with log_capture(arg) as fp: - revno = 0 - for line in fp: - if line.startswith("----------------------------"): - revno += 1 - print "%d\n" % revno + sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "="))) + for item in log_capture(arg): + sys.stdout.write("%d | %s\n%s" % (item.revno, item.date, item.log)) + sys.stdout.write(("-" * (width - 1)) + "\n") dispatch = { "help": help_method, -- 2.43.0