Git users seeking to achieve a workflow involving lightweight branches in Mercurial are often pointed to Mercurial bookmarks. In a nutshell, the recommendation is to maintain multiple heads that would correspond to the git branches, and name them with bookmarks.
A common desire in such a workflow is to see a list of all commits made in the current branch since the point it was branched from the parent branch (commonly master
or another long-lived branch). In git, this can be accomplished with:
git log <master>..HEAD
where <master>
is the name of the parent branch.
I am wondering, what would be the equivalent of this command in Mercurial with bookmarks?
I am looking for a command with the following properties:
master
.Git log man-page (with link to Git revisions man-page) defines range specifications like that as follows:
<rev1>..<rev2>
Include commits that are reachable from <rev2> but exclude those that are reachable from <rev1>.
It also say about order:
By default, the commits are shown in reverse chronological order.
Given this specification, the Mercurial revset
reverse(ancestors(.)-ancestors(<bookmark>))
should be sufficient.
On a closer look, this revset actually follows the specification down to the letter. It shows in reverse order the commits reachable from the current working copy's parent excluding those reachable from the given bookmark ("master" in your case). I consider Git's syntax a shorthand for this specification. You can do the same (creating a shortcut) in Mercurial using the so-called revset aliases.
Putting the following lines into your .hgrc:
[revsetalias]
range($1)=reverse(ancestors(.)-ancestors($1))
will enable you to use this:
hg log -r range(<bookmark>)
If you want to make it more flexible, you can define it like this in the .hgrc:
[revsetalias]
range($1,$2)=reverse(ancestors($2)-ancestors($1))
and use the following to get the HEAD example:
hg log -r range(<bookmark>, .)
If the word "range" is too much to type for you, you can use some special characters, too:
[revsetalias]
_($1)=reverse(ancestors(.)-ancestors($1))
The resulting shorthand
hg log -r_(<bookmark>)
is then even shorter than
git log <bookmark>..HEAD
But of course this is just nitpicking, anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With