I want my "hg h" (an hg log alias's output) to show what my currently working revision is in the context of 开发者_Python百科the history/log.
On my .hgrc I have the following:
[alias]
h = log --template "{rev} {node|short} {date|shortdate} | [{author|user}] {desc|strip|firstline} :: {tags}\n"
Here's a sample output:
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
But if I update to revision 0, the output is still the same:
$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
An example desired output would be:
$ hg h
1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit :: [working]
note: that [working] is NOT a tag, just my working revision, the one I updated-to.
Another example could be:
$ hg h
1 f130b4194c90 2011-07-21 | | [slashfoo] added a comment :: tip
0 f4b4ec3c8c95 2011-07-21 |X| [slashfoo] initial commit ::
I customized my "hg h" output using the hgbook's entry on "Customizing the output of Mercurial" http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html
Alternatives to what I want to do could be:
- using graphlog extension and doing
hg h -G
so that an @ would denote current working revision - using
hg id
to know what revision I am - using
hg parents
to know what revision I am with some extra info
But only alternative #1 shows me the context, but hg log -G and aliases are a bit less "compact" than my desired output.
Here's a sample of the output of alternative #1
$ hg h -G
o 1 f130b4194c90 2011-07-21 | [slashfoo] added a comment :: tip
|
@ 0 f4b4ec3c8c95 2011-07-21 | [slashfoo] initial commit ::
This question is simmilar to How can I find my working revision in mercurial but I want it in context, and in a compact manner (i.e. without -G)
hg log --rev $(hg id -i | sed 's/.$//')
In bash-like environment the following little monster of a bash-alias does the trick:
alias hgh='hg log -G --template "{rev} {node|short} {date|shortdate} | [{author|user}] {desc|strip|firstline} :: {tags}\n" | grep -v "^[|/\\ ]*$" | sed -e "s,^[o|/\\ +-]*,," -e "s,^@ *\(.*\),\1 [working]," | less'
It uses the -G
option and grep
and sed
to strip off all the graph stuff, except the @
marker, which is replaced by a [working]
marker at the end of the line.
Admittedly, this is a working but ugly solution. Using pure Mercurial commands and options would be much better, but it looks like the templating system does not provide what you want.
As a side note, you might want to have a look a the compass extension I wrote -- not what your are looking for specifically but it also helps to see your current context within a repository.
Use a revision set to pick the changesets you want. If you add
-r "limit(.::, 4) + last(::., 4)"
to the end of your alias, then you will see the working copy parent revision plus three changesets before and after for context.
Unfortunately there wont be any indication of where the working copy parent revision is in the output -- it will be at the top when you're at tip, and it will be in the middle when you're somewhere else in the history.
精彩评论