comparison mercurial/localrepo.py @ 7656:6a24fb994701

branch closing: referencing open and closed branches/heads Treat fully closed branches similarly to "inactive" in the output of 'hg branches'. They will be suffixed with "(closed)" where inactive branches are marked with "(inactive)". If the -a/--active option is given both inactive and closed branches will not be shown. Partially closed branches (multiple heads, at least one not closed) will display the next (tipmost) open head. Add -a/--active option to "hg heads" which will hide closed heads iff the option is specified. In other hg commands, when multiple branch heads exist the branch name will refer to the tipmost open head, and if none exist, then the tipmost closed head.
author John Mulligan <phlogistonjohn@asynchrono.us>
date Wed, 14 Jan 2009 21:47:38 -0500
parents cce37dab7ad6
children e5f445c94226
comparison
equal deleted inserted replaced
7655:cce37dab7ad6 7656:6a24fb994701
396 return self.branchcache 396 return self.branchcache
397 397
398 398
399 def branchtags(self): 399 def branchtags(self):
400 '''return a dict where branch names map to the tipmost head of 400 '''return a dict where branch names map to the tipmost head of
401 the branch''' 401 the branch, open heads come before closed'''
402 return dict([(k, v[-1]) for (k, v) in self._branchheads().iteritems()]) 402 bt = {}
403 for bn, heads in self._branchheads().iteritems():
404 head = None
405 for i in range(len(heads)-1, -1, -1):
406 h = heads[i]
407 if 'close' not in self.changelog.read(h)[5]:
408 head = h
409 break
410 # no open heads were found
411 if head is None:
412 head = heads[-1]
413 bt[bn] = head
414 return bt
415
403 416
404 def _readbranchcache(self): 417 def _readbranchcache(self):
405 partial = {} 418 partial = {}
406 try: 419 try:
407 f = self.opener("branchheads.cache") 420 f = self.opener("branchheads.cache")
1178 self.dirstate.add(dest) 1191 self.dirstate.add(dest)
1179 self.dirstate.copy(source, dest) 1192 self.dirstate.copy(source, dest)
1180 finally: 1193 finally:
1181 del wlock 1194 del wlock
1182 1195
1183 def heads(self, start=None): 1196 def heads(self, start=None, closed=True):
1184 heads = self.changelog.heads(start) 1197 heads = self.changelog.heads(start)
1198 def display(head):
1199 if closed:
1200 return True
1201 extras = self.changelog.read(head)[5]
1202 return ('close' not in extras)
1185 # sort the output in rev descending order 1203 # sort the output in rev descending order
1186 heads = [(-self.changelog.rev(h), h) for h in heads] 1204 heads = [(-self.changelog.rev(h), h) for h in heads if display(h)]
1187 return [n for (r, n) in util.sort(heads)] 1205 return [n for (r, n) in util.sort(heads)]
1188 1206
1189 def branchheads(self, branch=None, start=None): 1207 def branchheads(self, branch=None, start=None, closed=True):
1190 if branch is None: 1208 if branch is None:
1191 branch = self[None].branch() 1209 branch = self[None].branch()
1192 branches = self._branchheads() 1210 branches = self._branchheads()
1193 if branch not in branches: 1211 if branch not in branches:
1194 return [] 1212 return []
1196 # the cache returns heads ordered lowest to highest 1214 # the cache returns heads ordered lowest to highest
1197 bheads.reverse() 1215 bheads.reverse()
1198 if start is not None: 1216 if start is not None:
1199 # filter out the heads that cannot be reached from startrev 1217 # filter out the heads that cannot be reached from startrev
1200 bheads = self.changelog.nodesbetween([start], bheads)[2] 1218 bheads = self.changelog.nodesbetween([start], bheads)[2]
1219 if not closed:
1220 bheads = [h for h in bheads if
1221 ('close' not in self.changelog.read(h)[5])]
1201 return bheads 1222 return bheads
1202 1223
1203 def branches(self, nodes): 1224 def branches(self, nodes):
1204 if not nodes: 1225 if not nodes:
1205 nodes = [self.changelog.tip()] 1226 nodes = [self.changelog.tip()]