From: Eric S. Raymond Date: Sun, 23 Nov 2014 15:48:04 +0000 (-0500) Subject: A step towards handling masters with no revisions more smoothly. X-Git-Tag: 0.13~4 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=913aa86c26e6fdfbaf7af6431346f2cf2ed95de8;p=src.git A step towards handling masters with no revisions more smoothly. Regression test passes. --- diff --git a/src b/src index 2d9f9c0..9ba00aa 100755 --- 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: