##// END OF EJS Templates
Change branches to sort 'active' branches first, and add an option to show only active branches.
Eric Hopper -
r4675:6858a747 default
parent child Browse files
Show More
@@ -0,0 +1,36 b''
1 #!/bin/sh
2
3 hg init a
4 cd a
5 echo 'root' >root
6 hg add root
7 hg commit -d '0 0' -u test -m "Adding root node"
8
9 echo 'a' >a
10 hg add a
11 hg branch a
12 hg commit -d '1 0' -u test -m "Adding a branch"
13
14 hg update -C 0
15 echo 'b' >b
16 hg add b
17 hg branch b
18 hg commit -d '2 0' -u test -m "Adding b branch"
19
20 echo 'bh1' >bh1
21 hg add bh1
22 hg commit -d '3 0' -u test -m "Adding b branch head 1"
23
24 hg update -C 2
25 echo 'bh2' >bh2
26 hg add bh2
27 hg commit -d '4 0' -u test -m "Adding b branch head 2"
28
29 echo 'c' >c
30 hg add c
31 hg branch c
32 hg commit -d '5 0' -u test -m "Adding c branch"
33
34 hg branches
35 echo '-------'
36 hg branches -a
@@ -0,0 +1,12 b''
1 marked working directory as branch a
2 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
3 marked working directory as branch b
4 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
5 marked working directory as branch c
6 c 5:5ca481e59b8c
7 a 1:dd6b440dd85a
8 b 4:22df7444f7c1 (inactive)
9 default 0:19709c5a4e75 (inactive)
10 -------
11 c 5:5ca481e59b8c
12 a 1:dd6b440dd85a
@@ -237,21 +237,34 b' def branch(ui, repo, label=None, **opts)'
237 else:
237 else:
238 ui.write("%s\n" % util.tolocal(repo.dirstate.branch()))
238 ui.write("%s\n" % util.tolocal(repo.dirstate.branch()))
239
239
240 def branches(ui, repo):
240 def branches(ui, repo, active=False):
241 """list repository named branches
241 """list repository named branches
242
242
243 List the repository's named branches.
243 List the repository's named branches, indicating which ones are
244 inactive. If active is specified, only show active branches.
245
246 A branch is considered active if it contains unmerged heads.
244 """
247 """
245 b = repo.branchtags()
248 b = repo.branchtags()
246 l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()]
249 heads = dict.fromkeys(repo.heads(), 1)
250 l = [((n in heads), repo.changelog.rev(n), n, t) for t, n in b.items()]
247 l.sort()
251 l.sort()
248 for r, n, t in l:
252 l.reverse()
249 hexfunc = ui.debugflag and hex or short
253 for ishead, r, n, t in l:
250 if ui.quiet:
254 if active and not ishead:
251 ui.write("%s\n" % t)
255 # If we're only displaying active branches, abort the loop on
256 # encountering the first inactive head
257 break
252 else:
258 else:
253 spaces = " " * (30 - util.locallen(t))
259 hexfunc = ui.debugflag and hex or short
254 ui.write("%s%s %s:%s\n" % (t, spaces, -r, hexfunc(n)))
260 if ui.quiet:
261 ui.write("%s\n" % t)
262 else:
263 spaces = " " * (30 - util.locallen(t))
264 # The code only gets here if inactive branches are being
265 # displayed or the branch is active.
266 isinactive = ((not ishead) and " (inactive)") or ''
267 ui.write("%s%s %s:%s%s\n" % (t, spaces, r, hexfunc(n), isinactive))
255
268
256 def bundle(ui, repo, fname, dest=None, **opts):
269 def bundle(ui, repo, fname, dest=None, **opts):
257 """create a changegroup file
270 """create a changegroup file
@@ -2738,7 +2751,10 b' table = {'
2738 [('f', 'force', None,
2751 [('f', 'force', None,
2739 _('set branch name even if it shadows an existing branch'))],
2752 _('set branch name even if it shadows an existing branch'))],
2740 _('hg branch [NAME]')),
2753 _('hg branch [NAME]')),
2741 "branches": (branches, [], _('hg branches')),
2754 "branches": (branches,
2755 [('a', 'active', False,
2756 _("show only branches that have unmerged heads"))],
2757 _('hg branches [-a]')),
2742 "bundle":
2758 "bundle":
2743 (bundle,
2759 (bundle,
2744 [('f', 'force', None,
2760 [('f', 'force', None,
@@ -127,13 +127,13 b' tip 5:db5'
127 é 3:770b9b11621d
127 é 3:770b9b11621d
128 % ascii
128 % ascii
129 ? 5:db5520b4645f
129 ? 5:db5520b4645f
130 default 4:9cff3c980b58
130 default 4:9cff3c980b58 (inactive)
131 % latin-1
131 % latin-1
132 � 5:db5520b4645f
132 � 5:db5520b4645f
133 default 4:9cff3c980b58
133 default 4:9cff3c980b58 (inactive)
134 % utf-8
134 % utf-8
135 é 5:db5520b4645f
135 é 5:db5520b4645f
136 default 4:9cff3c980b58
136 default 4:9cff3c980b58 (inactive)
137 % utf-8
137 % utf-8
138 changeset: 5:db5520b4645f
138 changeset: 5:db5520b4645f
139 branch: é
139 branch: é
@@ -48,8 +48,8 b' date: Mon Jan 12 13:46:40 1970 +0'
48 summary: initial
48 summary: initial
49
49
50 foo 5:5f8fb06e083e
50 foo 5:5f8fb06e083e
51 default 3:bf1bc2f45e83
51 default 3:bf1bc2f45e83 (inactive)
52 bar 2:67ec16bde7f1
52 bar 2:67ec16bde7f1 (inactive)
53 foo
53 foo
54 default
54 default
55 bar
55 bar
General Comments 0
You need to be logged in to leave comments. Login now