]> thyrsus.com Git - src.git/commitdiff
A step towards handling masters with no revisions more smoothly.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 23 Nov 2014 15:48:04 +0000 (10:48 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 23 Nov 2014 15:48:04 +0000 (10:48 -0500)
Regression test passes.

src

diff --git a/src b/src
index 2d9f9c092f526fde71b6e865f41d36d52f0041ce..9ba00aa83d9a37ae938e1a6b20029375e0785d5e 100755 (executable)
--- a/src
+++ b/src
@@ -278,15 +278,16 @@ class History:
             item.child  = self.by_native_d.get(backend.succ(item.native))
             if item.parent and item.parent.child != item:
                 item.parent.branches.add(item)
-        for (name, rev) in self.symbols.items():
-            if backend.isbranch(rev):
-                base = backend.branch_to_base(rev, self)
-                tip = backend.branch_to_tip(rev, self)
-                while True:
-                    self.by_native_d[base].branch = name
-                    if base == tip:
-                        break
-                    base = backend.succ(base)
+        if self.revlist:
+            for (name, rev) in self.symbols.items():
+                if backend.isbranch(rev):
+                    base = backend.branch_to_base(rev, self)
+                    tip = backend.branch_to_tip(rev, self)
+                    while True:
+                        self.by_native_d[base].branch = name
+                        if base == tip:
+                            break
+                        base = backend.succ(base)
         #for item in self.revlist:
         #    print item
         #print self.by_revno_d.keys()
@@ -294,30 +295,36 @@ class History:
         return len(self.revlist)
     def current(self):
         "Return the revision currently checked out."
+        # Yes, this looks weird.  The idea is: Try to return the locked
+        # revision. If that blows up, try to return the tip revision
+        # of the current branch.  If that blows up, return None.
         try:
             return self.by_native_d[self.lockrevs[0]]
+            return self.by_native_d[backend.branch_to_tip(self.symbols[self.branch], self)]
         except IndexError:
-            croak("in %s, no current revision - src checkout to recover" % self,name)
+            return None
     def current_branch(self, backwards=False):
         "Return a list of items that are descendants or ancestors of current."
         if debug >= DEBUG_SEQUENCE:
             print "current_branch(%s)" % self.current()
+        selection = []
         p = self.current()
-        selection = [p]
-        while True:
-            if p.parent is None:
-                break
-            else:
-                p = p.parent
-            selection = [p] + selection
-        s = self.current()
-        while True:
-            s = s.child
-            if s is None:
-                break
-            selection.append(s)
-        if backwards:
-            selection.reverse()
+        if p is not None:
+            selection = [p]
+            while True:
+                if p.parent is None:
+                    break
+                else:
+                    p = p.parent
+                selection = [p] + selection
+            s = self.current()
+            while True:
+                s = s.child
+                if s is None:
+                    break
+                selection.append(s)
+            if backwards:
+                selection.reverse()
         return selection
     def tip(self, rev=None):
         "Return the tip revision of the branch of the given native revision."
@@ -338,7 +345,12 @@ class History:
         try:
             return self.by_revno_d[revno]
         except KeyError:
-            croak("{0} has no revno {1}".format(self.name, revno))
+            if revno == 0:
+                # This case comes up if we try to select the
+                # tip revision of a history without revisions. 
+                croak("{0} has no revisions".format(self.name))
+            else:
+                croak("{0} has no revno {1}".format(self.name, revno))
     def revno_to_native(self, revno):
         "Map a revno to a native ID"
         return self.by_revno(revno).native
@@ -1922,9 +1934,9 @@ if __name__ == "__main__":
         if not commandline:
             help_method()
         else:
-            try:
+            if commandline[0] in dispatch:
                 dispatch[commandline[0]](*commandline[1:])
-            except KeyError:
+            else:
                 sys.stderr.write("src: no such command as '%s'.  Try 'src help'\n" \
                                % commandline[0])
     except KeyboardInterrupt: