5

I want my "hg h" (an hg log alias's output) to show what my currently working revision is in the context of 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:

  1. using graphlog extension and doing hg h -G so that an @ would denote current working revision
  2. using hg id to know what revision I am
  3. 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)

Community
  • 1
  • 1
slashfoo
  • 576
  • 6
  • 7
  • 1
    Are you interested in seeing rev `1`? `hg log --follow` will show the parent of your working directory as the first cset. – Idan K Jul 21 '11 at 19:13
  • hg log -f (or --follow) as you mention is a good one, but I'd like to know the whole context, before and after, more like the output of `git log --pretty=format:"%h %ad | [%an] %s%d" --graph --date=short`, you can Always know where you are because it's marked with "(HEAD)". – slashfoo Jul 21 '11 at 20:24
  • Your *"example desired output"* is exactly the same as shown by `hg h`. Is this a mistake? If not, what's the problem? – Oben Sonne Jul 21 '11 at 20:25
  • Oben: I want some marker like the `[working]` on the desired output. or the `@` on `hg h -G` – slashfoo Jul 21 '11 at 20:30
  • http://www.selenic.com/mercurial/hgrc.5.html#alias try using a shell expansion against hg id. – Paul Nathan Jul 21 '11 at 22:55
  • Paul: how does that give me context? why would I use shell expansion against id when id is already an hg command? please elaborate. – slashfoo Jul 22 '11 at 00:12
  • slashfoo: Okay, right, now I also got you point. – Oben Sonne Jul 22 '11 at 14:12
  • It's more or less the "you are here" dot on the maps at the malls, but for the hg log command. – slashfoo Jul 22 '11 at 14:52

3 Answers3

3

hg log --rev $(hg id -i | sed 's/.$//')

d9k
  • 1,476
  • 3
  • 15
  • 28
1

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.

Oben Sonne
  • 9,893
  • 2
  • 40
  • 61
0

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.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229