Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 22701:cb28d2b3db0b
formatter: add general way to switch hex/short functions
This seems a bit awkward, but it can avoid duplicates in annotate, tags,
branches and bookmarks.
I guess fm.hexfunc can eventually be removed (or redesigned) when it gets
template backend.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 03 Oct 2014 22:20:02 +0900 |
parents | 21d5416b8a8a |
children | 08a4e70ed183 |
comparison
equal
deleted
inserted
replaced
22700:41421bd9c42e | 22701:cb28d2b3db0b |
---|---|
274 # to mimic the behavior of Mercurial before version 1.5 | 274 # to mimic the behavior of Mercurial before version 1.5 |
275 opts['file'] = True | 275 opts['file'] = True |
276 | 276 |
277 fm = ui.formatter('annotate', opts) | 277 fm = ui.formatter('annotate', opts) |
278 datefunc = ui.quiet and util.shortdate or util.datestr | 278 datefunc = ui.quiet and util.shortdate or util.datestr |
279 if fm or ui.debugflag: | 279 hexfn = fm.hexfunc |
280 hexfn = hex | |
281 else: | |
282 hexfn = short | |
283 | 280 |
284 opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser), | 281 opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser), |
285 ('number', ' ', lambda x: x[0].rev(), str), | 282 ('number', ' ', lambda x: x[0].rev(), str), |
286 ('changeset', ' ', lambda x: hexfn(x[0].node()), str), | 283 ('changeset', ' ', lambda x: hexfn(x[0].node()), str), |
287 ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)), | 284 ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)), |
6084 | 6081 |
6085 Returns 0 on success. | 6082 Returns 0 on success. |
6086 """ | 6083 """ |
6087 | 6084 |
6088 fm = ui.formatter('tags', opts) | 6085 fm = ui.formatter('tags', opts) |
6089 if fm or ui.debugflag: | 6086 hexfunc = fm.hexfunc |
6090 hexfunc = hex | |
6091 else: | |
6092 hexfunc = short | |
6093 tagtype = "" | 6087 tagtype = "" |
6094 | 6088 |
6095 for t, n in reversed(repo.tagslist()): | 6089 for t, n in reversed(repo.tagslist()): |
6096 hn = hexfunc(n) | 6090 hn = hexfunc(n) |
6097 label = 'tags.normal' | 6091 label = 'tags.normal' |