self.log = ""
self.date = None
+class RCSLog:
+ "Encapsulate a revision list and some methods on it"
+ def __init__(self, name):
+ self.name = name
+ self.revlist = []
+ with popen_or_die("cd .src >/dev/null; rlog %s; cd ..>/dev/null" % name) as fp:
+ self.revlist = []
+ maxrevno = 0
+ state = "initial"
+ for line in fp:
+ if line.startswith("----------------------------"):
+ state = "logheader"
+ self.revlist.append(RCSRevisionItem(maxrevno))
+ maxrevno += 1
+ elif state == "logheader" and line.startswith("revision"):
+ fields = line.split()
+ self.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"
+ self.revlist[-1].date = date
+ elif line.startswith("======================="):
+ if not self.revlist[-1].log.endswith("\n"):
+ self.revlist[-1].log += "\n"
+ break
+ elif self.revlist:
+ self.revlist[-1].log += line[1:]
+ for item in self.revlist:
+ item.revno = maxrevno - item.revno
+ def __len__(self):
+ return len(self.revlist)
+ def __getitem__(self, i):
+ "Use 1-origin indices, lowest oldest."
+ return self.revlist[len(self.revlist) - i]
+
def log_capture(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[1:]
- for item in revlist:
- item.revno = maxrevno - item.revno
return revlist
def help_method(*args):
logcomment = open(scratchfile).read()
logcomment = "." + logcomment.replace("\n", "\n.")[:-1]
do_or_die("mv .src/{0},v . && ci -l -m'{1}' {0} && mv {0},v .src".format(arg, logcomment))
- revlist = log_capture(arg)
- announce("%s -> %d" % (arg, len(revlist)))
+ announce("%s -> %d" % (arg, len(RCSLog(arg))))
def list_method(*args):
"Generate a summary listing of commits, one line per commit."
width = screenwidth()
for arg in args:
sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
- for item in log_capture(arg):
+ for item in RCSLog(arg):
if not revspec or item.revno in revspec:
# Must allow enough room for revno and date
summary = item.log.strip()[:width - 32]
width = screenwidth()
for arg in args:
sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
- for item in log_capture(arg):
+ for item in RCSLog(arg):
if not revspec or item.revno in revspec:
sys.stdout.write("%-4d | %s\n%s" % (item.revno, item.date, item.log))
sys.stdout.write(("-" * (width - 1)) + "\n")
if revspec and len(revspec) > 1:
croak("checkout needs an empty or singleton revision spec")
for arg in args:
- revlist = log_capture(arg)
+ revlist = RCSLog(arg)
if revspec is None:
revspec = [len(revlist)]
revision = ""
"Dump revision content to standard output."
(revspec, args) = preamble("cat", args)
for arg in args:
- revlist = log_capture(arg)
+ revlist = RCSLog(arg)
if revspec is None:
revspec = range(1, len(revlist)+1)
do_or_die("mv .src/{0},v .".format(arg))
while args and args[0].startswith("-"):
diffopts += " " + args.pop(0)
for arg in args:
- revlist = log_capture(arg)
+ revlist = RCSLog(arg)
do_or_die("mv .src/{0},v .".format(arg))
if revspec is None:
# The || : suppresses the error return from diff(1)