##// END OF EJS Templates
show: use consistent (and possibly shorter) node lengths...
Gregory Szorc -
r34192:e6b5e732 default
parent child Browse files
Show More
@@ -161,9 +161,10 b' def showbookmarks(ui, repo, fm):'
161 161 ui.write(_('(no bookmarks set)\n'))
162 162 return
163 163
164 revs = [repo[node].rev() for node in marks.values()]
164 165 active = repo._activebookmark
165 166 longestname = max(len(b) for b in marks)
166 # TODO consider exposing longest shortest(node).
167 nodelen = longestshortest(repo, revs)
167 168
168 169 for bm, node in sorted(marks.items()):
169 170 fm.startitem()
@@ -172,7 +173,7 b' def showbookmarks(ui, repo, fm):'
172 173 fm.write('node', fm.hexfunc(node), fm.hexfunc(node))
173 174 fm.data(active=bm == active,
174 175 longestbookmarklen=longestname,
175 nodelen=5)
176 nodelen=nodelen)
176 177
177 178 @showview('stack', csettopic='stack')
178 179 def showstack(ui, repo, displayer):
@@ -236,6 +237,9 b' def showstack(ui, repo, displayer):'
236 237 else:
237 238 newheads = set()
238 239
240 allrevs = set(stackrevs) | newheads | set([baserev])
241 nodelen = longestshortest(repo, allrevs)
242
239 243 try:
240 244 cmdutil.findcmd('rebase', commands.table)
241 245 haverebase = True
@@ -247,7 +251,7 b' def showstack(ui, repo, displayer):'
247 251 # our simplicity and the customizations required.
248 252 # TODO use proper graph symbols from graphmod
249 253
250 shortesttmpl = formatter.maketemplater(ui, '{shortest(node, 5)}')
254 shortesttmpl = formatter.maketemplater(ui, '{shortest(node, %d)}' % nodelen)
251 255 def shortest(ctx):
252 256 return shortesttmpl.render({'ctx': ctx, 'node': ctx.hex()})
253 257
@@ -278,7 +282,7 b' def showstack(ui, repo, displayer):'
278 282 ui.write(' ')
279 283
280 284 ui.write(('o '))
281 displayer.show(ctx, nodelen=5)
285 displayer.show(ctx, nodelen=nodelen)
282 286 displayer.flush(ctx)
283 287 ui.write('\n')
284 288
@@ -318,7 +322,7 b' def showstack(ui, repo, displayer):'
318 322 ui.write(' ')
319 323
320 324 ui.write(symbol, ' ')
321 displayer.show(ctx, nodelen=5)
325 displayer.show(ctx, nodelen=nodelen)
322 326 displayer.flush(ctx)
323 327 ui.write('\n')
324 328
@@ -335,7 +339,7 b' def showstack(ui, repo, displayer):'
335 339 ui.write(_('(stack base)'), '\n', label='stack.label')
336 340 ui.write(('o '))
337 341
338 displayer.show(basectx, nodelen=5)
342 displayer.show(basectx, nodelen=nodelen)
339 343 displayer.flush(basectx)
340 344 ui.write('\n')
341 345
@@ -394,12 +398,13 b' def showwork(ui, repo, displayer):'
394 398 """changesets that aren't finished"""
395 399 # TODO support date-based limiting when calling revset.
396 400 revs = repo.revs('sort(_underway(), topo)')
401 nodelen = longestshortest(repo, revs)
397 402
398 403 revdag = graphmod.dagwalker(repo, revs)
399 404
400 405 ui.setconfig('experimental', 'graphshorten', True)
401 406 cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges,
402 props={'nodelen': 5})
407 props={'nodelen': nodelen})
403 408
404 409 def extsetup(ui):
405 410 # Alias `hg <prefix><view>` to `hg show <view>`.
@@ -420,6 +425,27 b' def extsetup(ui):'
420 425
421 426 ui.setconfig('alias', name, 'show %s' % view, source='show')
422 427
428 def longestshortest(repo, revs, minlen=4):
429 """Return the length of the longest shortest node to identify revisions.
430
431 The result of this function can be used with the ``shortest()`` template
432 function to ensure that a value is unique and unambiguous for a given
433 set of nodes.
434
435 The number of revisions in the repo is taken into account to prevent
436 a numeric node prefix from conflicting with an integer revision number.
437 If we fail to do this, a value of e.g. ``10023`` could mean either
438 revision 10023 or node ``10023abc...``.
439 """
440 tmpl = formatter.maketemplater(repo.ui, '{shortest(node, %d)}' % minlen)
441 lens = [minlen]
442 for rev in revs:
443 ctx = repo[rev]
444 shortest = tmpl.render({'ctx': ctx, 'node': ctx.hex()})
445 lens.append(len(shortest))
446
447 return max(lens)
448
423 449 # Adjust the docstring of the show command so it shows all registered views.
424 450 # This is a bit hacky because it runs at the end of module load. When moved
425 451 # into core or when another extension wants to provide a view, we'll need
@@ -17,7 +17,7 b' Stack displays single draft changeset as'
17 17 $ echo 0 > foo
18 18 $ hg -q commit -A -m 'commit 0'
19 19 $ hg show stack
20 @ 9f171 commit 0
20 @ 9f17 commit 0
21 21
22 22 Stack displays multiple draft changesets
23 23
@@ -30,48 +30,48 b' Stack displays multiple draft changesets'
30 30 $ echo 4 > foo
31 31 $ hg commit -m 'commit 4'
32 32 $ hg show stack
33 @ 2737b commit 4
34 o d1a69 commit 3
35 o 128c8 commit 2
36 o 181cc commit 1
37 o 9f171 commit 0
33 @ 2737 commit 4
34 o d1a6 commit 3
35 o 128c commit 2
36 o 181c commit 1
37 o 9f17 commit 0
38 38
39 39 Public parent of draft base is displayed, separated from stack
40 40
41 41 $ hg phase --public -r 0
42 42 $ hg show stack
43 @ 2737b commit 4
44 o d1a69 commit 3
45 o 128c8 commit 2
46 o 181cc commit 1
43 @ 2737 commit 4
44 o d1a6 commit 3
45 o 128c commit 2
46 o 181c commit 1
47 47 / (stack base)
48 o 9f171 commit 0
48 o 9f17 commit 0
49 49
50 50 $ hg phase --public -r 1
51 51 $ hg show stack
52 @ 2737b commit 4
53 o d1a69 commit 3
54 o 128c8 commit 2
52 @ 2737 commit 4
53 o d1a6 commit 3
54 o 128c commit 2
55 55 / (stack base)
56 o 181cc commit 1
56 o 181c commit 1
57 57
58 58 Draft descendants are shown
59 59
60 60 $ hg -q up 2
61 61 $ hg show stack
62 o 2737b commit 4
63 o d1a69 commit 3
64 @ 128c8 commit 2
62 o 2737 commit 4
63 o d1a6 commit 3
64 @ 128c commit 2
65 65 / (stack base)
66 o 181cc commit 1
66 o 181c commit 1
67 67
68 68 $ hg -q up 3
69 69 $ hg show stack
70 o 2737b commit 4
71 @ d1a69 commit 3
72 o 128c8 commit 2
70 o 2737 commit 4
71 @ d1a6 commit 3
72 o 128c commit 2
73 73 / (stack base)
74 o 181cc commit 1
74 o 181c commit 1
75 75
76 76 working dir on public changeset should display special message
77 77
@@ -89,10 +89,10 b' Branch point in descendants displayed at'
89 89 $ hg show stack
90 90 \ / (multiple children)
91 91 |
92 o d1a69 commit 3
93 @ 128c8 commit 2
92 o d1a6 commit 3
93 @ 128c commit 2
94 94 / (stack base)
95 o 181cc commit 1
95 o 181c commit 1
96 96
97 97 $ cd ..
98 98
@@ -117,9 +117,9 b' Base is stopped at merges'
117 117 TODO doesn't yet handle case where wdir is a draft merge
118 118
119 119 $ hg show stack
120 @ 8ee90 merge heads
120 @ 8ee9 merge heads
121 121 / (stack base)
122 o 59478 head 1
122 o 5947 head 1
123 123
124 124 $ echo d1 > foo
125 125 $ hg commit -m 'draft 1'
@@ -127,10 +127,10 b" TODO doesn't yet handle case where wdir "
127 127 $ hg commit -m 'draft 2'
128 128
129 129 $ hg show stack
130 @ 430d5 draft 2
131 o 787b1 draft 1
130 @ 430d draft 2
131 o 787b draft 1
132 132 / (stack base)
133 o 8ee90 merge heads
133 o 8ee9 merge heads
134 134
135 135 $ cd ..
136 136
@@ -156,36 +156,36 b' Now move on to stacks when there are mor'
156 156 Newer draft heads don't impact output
157 157
158 158 $ hg show stack
159 @ eaffc draft 2
160 o 2b218 draft 1
159 @ eaff draft 2
160 o 2b21 draft 1
161 161 / (stack base)
162 o b66bb base
162 o b66b base
163 163
164 164 Newer public heads are rendered
165 165
166 166 $ hg phase --public -r '::tip'
167 167
168 168 $ hg show stack
169 o baa4b new 2
169 o baa4 new 2
170 170 / (2 commits ahead)
171 171 :
172 172 : (stack head)
173 : @ eaffc draft 2
174 : o 2b218 draft 1
173 : @ eaff draft 2
174 : o 2b21 draft 1
175 175 :/ (stack base)
176 o b66bb base
176 o b66b base
177 177
178 178 If rebase is available, we show a hint how to rebase to that head
179 179
180 180 $ hg --config extensions.rebase= show stack
181 o baa4b new 2
182 / (2 commits ahead; hg rebase --source 2b218 --dest baa4b)
181 o baa4 new 2
182 / (2 commits ahead; hg rebase --source 2b21 --dest baa4)
183 183 :
184 184 : (stack head)
185 : @ eaffc draft 2
186 : o 2b218 draft 1
185 : @ eaff draft 2
186 : o 2b21 draft 1
187 187 :/ (stack base)
188 o b66bb base
188 o b66b base
189 189
190 190 Similar tests but for multiple heads
191 191
@@ -196,25 +196,25 b' Similar tests but for multiple heads'
196 196 $ hg -q up 2
197 197
198 198 $ hg show stack
199 o baa4b new 2
199 o baa4 new 2
200 200 / (2 commits ahead)
201 : o 9a848 new head 2
201 : o 9a84 new head 2
202 202 :/ (1 commits ahead)
203 203 :
204 204 : (stack head)
205 : @ eaffc draft 2
206 : o 2b218 draft 1
205 : @ eaff draft 2
206 : o 2b21 draft 1
207 207 :/ (stack base)
208 o b66bb base
208 o b66b base
209 209
210 210 $ hg --config extensions.rebase= show stack
211 o baa4b new 2
212 / (2 commits ahead; hg rebase --source 2b218 --dest baa4b)
213 : o 9a848 new head 2
214 :/ (1 commits ahead; hg rebase --source 2b218 --dest 9a848)
211 o baa4 new 2
212 / (2 commits ahead; hg rebase --source 2b21 --dest baa4)
213 : o 9a84 new head 2
214 :/ (1 commits ahead; hg rebase --source 2b21 --dest 9a84)
215 215 :
216 216 : (stack head)
217 : @ eaffc draft 2
218 : o 2b218 draft 1
217 : @ eaff draft 2
218 : o 2b21 draft 1
219 219 :/ (stack base)
220 o b66bb base
220 o b66b base
@@ -16,20 +16,20 b' Single draft changeset shown'
16 16 $ hg -q commit -A -m 'commit 0'
17 17
18 18 $ hg show work
19 @ 9f171 commit 0
19 @ 9f17 commit 0
20 20
21 21 Even when it isn't the wdir
22 22
23 23 $ hg -q up null
24 24
25 25 $ hg show work
26 o 9f171 commit 0
26 o 9f17 commit 0
27 27
28 28 Single changeset is still there when public because it is a head
29 29
30 30 $ hg phase --public -r 0
31 31 $ hg show work
32 o 9f171 commit 0
32 o 9f17 commit 0
33 33
34 34 A draft child will show both it and public parent
35 35
@@ -38,8 +38,8 b' A draft child will show both it and publ'
38 38 $ hg commit -m 'commit 1'
39 39
40 40 $ hg show work
41 @ 181cc commit 1
42 o 9f171 commit 0
41 @ 181c commit 1
42 o 9f17 commit 0
43 43
44 44 Multiple draft children will be shown
45 45
@@ -47,16 +47,16 b' Multiple draft children will be shown'
47 47 $ hg commit -m 'commit 2'
48 48
49 49 $ hg show work
50 @ 128c8 commit 2
51 o 181cc commit 1
52 o 9f171 commit 0
50 @ 128c commit 2
51 o 181c commit 1
52 o 9f17 commit 0
53 53
54 54 Bumping first draft changeset to public will hide its parent
55 55
56 56 $ hg phase --public -r 1
57 57 $ hg show work
58 @ 128c8 commit 2
59 o 181cc commit 1
58 @ 128c commit 2
59 o 181c commit 1
60 60 |
61 61 ~
62 62
@@ -68,10 +68,10 b' Multiple DAG heads will be shown'
68 68 created new head
69 69
70 70 $ hg show work
71 @ f0abc commit 3
72 | o 128c8 commit 2
71 @ f0ab commit 3
72 | o 128c commit 2
73 73 |/
74 o 181cc commit 1
74 o 181c commit 1
75 75 |
76 76 ~
77 77
@@ -80,10 +80,10 b' Even when wdir is something else'
80 80 $ hg -q up null
81 81
82 82 $ hg show work
83 o f0abc commit 3
84 | o 128c8 commit 2
83 o f0ab commit 3
84 | o 128c commit 2
85 85 |/
86 o 181cc commit 1
86 o 181c commit 1
87 87 |
88 88 ~
89 89
@@ -95,13 +95,13 b' Draft child shows public head (multiple '
95 95 created new head
96 96
97 97 $ hg show work
98 @ 668ca commit 4
99 | o f0abc commit 3
100 | | o 128c8 commit 2
98 @ 668c commit 4
99 | o f0ab commit 3
100 | | o 128c commit 2
101 101 | |/
102 | o 181cc commit 1
102 | o 181c commit 1
103 103 |/
104 o 9f171 commit 0
104 o 9f17 commit 0
105 105
106 106 $ cd ..
107 107
@@ -126,11 +126,11 b' Branch name appears in output'
126 126 $ hg commit -m 'commit 4'
127 127
128 128 $ hg show work
129 @ f8dd3 (mybranch) commit 4
130 o 90cfc (mybranch) commit 3
131 | o 128c8 commit 2
129 @ f8dd (mybranch) commit 4
130 o 90cf (mybranch) commit 3
131 | o 128c commit 2
132 132 |/
133 o 181cc commit 1
133 o 181c commit 1
134 134 |
135 135 ~
136 136
@@ -157,11 +157,11 b' Bookmark name appears in output'
157 157 $ hg bookmark mybook
158 158
159 159 $ hg show work
160 @ cac82 (mybook) commit 4
161 o f0abc commit 3
162 | o 128c8 (@) commit 2
160 @ cac8 (mybook) commit 4
161 o f0ab commit 3
162 | o 128c (@) commit 2
163 163 |/
164 o 181cc commit 1
164 o 181c commit 1
165 165 |
166 166 ~
167 167
@@ -182,9 +182,9 b' Tags are rendered'
182 182 $ hg tag 0.2
183 183
184 184 $ hg show work
185 @ 37582 Added tag 0.2 for changeset 6379c25b76f1
186 o 6379c (0.2) commit 3
187 o a2ad9 Added tag 0.1 for changeset 6a75536ea0b1
185 @ 3758 Added tag 0.2 for changeset 6379c25b76f1
186 o 6379 (0.2) commit 3
187 o a2ad Added tag 0.1 for changeset 6a75536ea0b1
188 188 |
189 189 ~
190 190
@@ -205,15 +205,15 b' Multiple names on same changeset render '
205 205 $ hg commit -m 'commit 2'
206 206
207 207 $ hg show work
208 @ 34834 (mybook) (mybranch) commit 2
209 o 97fcc commit 1
208 @ 3483 (mybook) (mybranch) commit 2
209 o 97fc commit 1
210 210
211 211 Multiple bookmarks on same changeset render properly
212 212
213 213 $ hg book mybook2
214 214 $ hg show work
215 @ 34834 (mybook mybook2) (mybranch) commit 2
216 o 97fcc commit 1
215 @ 3483 (mybook mybook2) (mybranch) commit 2
216 o 97fc commit 1
217 217
218 218 $ cd ..
219 219
@@ -230,8 +230,38 b' Extra namespaces are rendered'
230 230 $ hg commit -m 'commit 3'
231 231
232 232 $ hg --config extensions.revnames=$TESTDIR/revnamesext.py show work
233 @ 32f3e (r2) commit 3
234 o 6a755 (r1) commit 2
235 o 97fcc (r0) commit 1
233 @ 32f3 (r2) commit 3
234 o 6a75 (r1) commit 2
235 o 97fc (r0) commit 1
236 236
237 237 $ cd ..
238
239 Prefix collision on hashes increases shortest node length
240
241 $ hg init hashcollision
242 $ cd hashcollision
243 $ echo 0 > a
244 $ hg -q commit -Am 0
245 $ for i in 17 1057 2857 4025; do
246 > hg -q up 0
247 > echo $i > a
248 > hg -q commit -m $i
249 > echo 0 > a
250 > hg commit -m "$i commit 2"
251 > done
252
253 $ hg show work
254 @ cfd04 4025 commit 2
255 o c562d 4025
256 | o 08048 2857 commit 2
257 | o c5623 2857
258 |/
259 | o 6a6b6 1057 commit 2
260 | o c5625 1057
261 |/
262 | o 96b4e 17 commit 2
263 | o 11424 17
264 |/
265 o b4e73 0
266
267 $ cd ..
@@ -95,8 +95,8 b' bookmarks view shows bookmarks in an ali'
95 95 $ hg bookmark a-longer-bookmark
96 96
97 97 $ hg show bookmarks
98 * a-longer-bookmark 7b570
99 book1 b757f
98 * a-longer-bookmark 7b57
99 book1 b757
100 100
101 101 A custom bookmarks template works
102 102
@@ -113,14 +113,14 b' bookmarks JSON works'
113 113 "bookmark": "a-longer-bookmark",
114 114 "longestbookmarklen": 17,
115 115 "node": "7b5709ab64cbc34da9b4367b64afff47f2c4ee83",
116 "nodelen": 5
116 "nodelen": 4
117 117 },
118 118 {
119 119 "active": false,
120 120 "bookmark": "book1",
121 121 "longestbookmarklen": 17,
122 122 "node": "b757f780b8ffd71267c6ccb32e0882d9d32a8cc0",
123 "nodelen": 5
123 "nodelen": 4
124 124 }
125 125 ]
126 126
@@ -138,19 +138,19 b' commands.show.aliasprefix aliases values'
138 138 (no bookmarks set)
139 139
140 140 $ hg --config commands.show.aliasprefix=sh shwork
141 @ 7b570 commit for book2
142 o b757f commit for book1
143 o ba592 initial
141 @ 7b57 commit for book2
142 o b757 commit for book1
143 o ba59 initial
144 144
145 145 $ hg --config commands.show.aliasprefix='s sh' swork
146 @ 7b570 commit for book2
147 o b757f commit for book1
148 o ba592 initial
146 @ 7b57 commit for book2
147 o b757 commit for book1
148 o ba59 initial
149 149
150 150 $ hg --config commands.show.aliasprefix='s sh' shwork
151 @ 7b570 commit for book2
152 o b757f commit for book1
153 o ba592 initial
151 @ 7b57 commit for book2
152 o b757 commit for book1
153 o ba59 initial
154 154
155 155 The aliases don't appear in `hg config`
156 156
General Comments 0
You need to be logged in to leave comments. Login now