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()
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."
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
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: