]> thyrsus.com Git - src.git/commitdiff
Resolve relative to each master object.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 7 Nov 2014 05:17:28 +0000 (00:17 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 7 Nov 2014 05:17:28 +0000 (00:17 -0500)
src

diff --git a/src b/src
index 0ec5bfea5dd8766bf500279d775a23754f130bd2..02e6ade5aaca4d51ed2124e8d8d5bb3cc6329d0f 100755 (executable)
--- a/src
+++ b/src
@@ -184,6 +184,22 @@ class RCSLog:
             if item.revno == revno:
                 return item.revision
         croak("{0} has no revno {1}".format(self.name, revno))
+    def resolve(self, revspec):
+        "Resolve a revision spec that may contain tags into revnos."
+        if revspec is None:
+            return None
+        (start, end) = revspec
+        if type(start) == type(""):
+            if start in self.symbols:
+                start = self.symbols[start]
+            else:
+                croak("can't resolve symbol {0} in {1}".format(start,self.name))
+        if type(end) == type(""):
+            if end in self.symbols:
+                end = self.symbols[end]
+            else:
+                croak("can't resolve symbol {0} in {1}".format(end, self.name))
+        return range(start, end+1) 
 
 def help_method(*args):
     "Summarize src commands, or (with argument) show help for a single command."
@@ -254,14 +270,23 @@ def preamble(cmd, args):
         try:
             if "-" in revspec:
                 (start, end) = revspec.split("-")
-                start = int(start)
-                end = int(end)
+                try:
+                    start = int(start)
+                except ValueError:
+                    pass
+                try:
+                    end = int(end)
+                except ValueError:
+                    pass
             else:
-                start = int(revspec)
+                try:
+                    start = int(revspec)
+                except ValueError:
+                    pass
                 end = start
         except ValueError:
             croak("malformed revision spec: %s" % revspec)
-        revspec = range(start, end+1)
+        revspec = (start, end)
     if not args:
         masters = os.listdir(".src")
         if len(masters) == 1:
@@ -322,7 +347,9 @@ def list_method(*args):
     width = screenwidth()
     for arg in args:
         sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
-        for item in RCSLog(arg):
+        master = RCSLog(arg)
+        revspec = master.resolve(revspec)
+        for item in master:
             if not revspec or item.revno in revspec:
                 # Must allow enough room for revno and date
                 summary = item.log.strip()[:width - 34]
@@ -339,7 +366,9 @@ def log_method(*args):
     width = screenwidth()
     for arg in args:
         sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
-        for item in RCSLog(arg):
+        master = RCSLog(arg)
+        revspec = master.resolve(revspec)
+        for item in master:
             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")
@@ -350,16 +379,17 @@ def checkout_method(*args):
     if revspec and len(revspec) > 1:
         croak("checkout needs an empty or singleton revision spec")
     for arg in args:
-        revlist = RCSLog(arg)
+        master = RCSLog(arg)
+        revspec = master.resolve(revspec)
         if revspec is None:
-            revspec = [len(revlist)]
+            revspec = [len(master)]
             revision = ""
         elif len(revspec) != 1:
             croak("checkout cannot take a range")
-        elif revspec[0] > len(revlist):
-            croak("%s has only %d revisions" % (arg, len(revlist)))
+        elif revspec[0] > len(master):
+            croak("%s has only %d revisions" % (arg, len(master)))
         else:
-            revision = revlist[len(revlist) - revspec[0]].revision
+            revision = master[len(master) - revspec[0]].revision
         with lifted(arg):
             do_or_die("rm -f {0} && rcs -q -u {0},v && co -q -l{1} {0}".format(arg, revision))
         announce("%s <- %d" % (arg, revspec[0])) 
@@ -368,11 +398,12 @@ def cat_method(*args):
     "Dump revision content to standard output."
     (revspec, args) = preamble("cat", args)
     for arg in args:
-        revlist = RCSLog(arg)
+        master = RCSLog(arg)
+        revspec = master.resolve(revspec)
         if revspec is None:
-            revspec = range(1, len(revlist)+1)
+            revspec = range(1, len(master)+1)
         with lifted(arg):
-            for item in revlist:
+            for item in master:
                 if item.revno in revspec:
                     do_or_die("co -q -p -r{1} {0}".format(arg, item.revision), loud=True)
 
@@ -385,10 +416,11 @@ def diff_method(*args):
     for arg in args:
         diffspec = ""
         if revspec is not None:
-            state = RCSLog(arg)
-            diffspec += "-r" + state.revno_to_rcs(revspec[0])
+            master = RCSLog(arg)
+            revspec = master.resolve(revspec)
+            diffspec += "-r" + master.revno_to_rcs(revspec[0])
             if len(revspec) > 1:
-                diffspec += " -r" + state.revno_to_rcs(revspec[1])
+                diffspec += " -r" + master.revno_to_rcs(revspec[1])
         with lifted(arg):
             # The || : suppresses the error return from diff(1)
             do_or_die("rcsdiff -q {0} {1} {2} || :".format(diffspec, diffopts, arg),loud=True)
@@ -399,10 +431,10 @@ def list_tags(*args):
         croak("can't accept a revision-spec when deleting tags.")
     width = screenwidth()
     for arg in args:
-        state = RCSLog(arg)
+        master = RCSLog(arg)
         sys.stdout.write("= %s %s\n" % (arg, ((width - len(arg) - 5) * "=")))
-        for (key, value) in state.symbols.items():
-            sys.stdout.write("%4d      %s\n" % (state.rcs_to_revno(value),key))
+        for (key, value) in master.symbols.items():
+            sys.stdout.write("%4d      %s\n" % (master.rcs_to_revno(value),key))
 
 def delete_tags(args):
     if not args:
@@ -419,14 +451,16 @@ def set_tags(args):
     if not args:
         croak("setting tags requires a tagname argument")
     tagname = args.pop(0)
+    if not args:
+        croak("setting tags requires a revision-spec after the tag name")    
     (revspec, args) = preamble("tag", args)
-    print "Foo!", revspec
     for arg in args:
-        state = RCSLog(arg)
+        master = RCSLog(arg)
+        revspec = master.resolve(revspec)
         if revspec is None:
-            revision = state.tip().revision
+            revision = master.tip().revision
         elif len(revspec) == 1:
-            revision = state.revno_to_rcs(revspec[0])
+            revision = master.revno_to_rcs(revspec[0])
         else:
             croak("can't accept a range when setting tags.")
         with lifted(arg):