Mercurial bookmark regex search? - mercurial

How to find a bookmark using a regular expression?

The command:
hg log -r bookmark('re:T.+v2')
lists all bookmarks matching the regex T.+v2.
In TortoiseHG:
Press Ctrl+S to show the Filter Toolbar
Write bookmark('re:T.+v2').
This is documented under Patterns and Predicates as part of the revsets query language.

Related

How to search Mercurial for a particular change?

I added a function to file on an a branch I can't remember. I want to port that function to a different branch. How can I search Mercurial to find it?
I know the name of the function and the file I put it in.
I'm using TortoiseHg, and it's got a search bar at the top. I'm not sure which Mecurial command it's using internally..maybe hg log?
But so far I've got
user('me') and file('glob:class/database.php') and ????('myfunctionname')
Not sure what filter I can use to search diff contents.
Also, I don't really know how those filename patterns work, I seem to have to search from the base; can't I do an exact match on filename, excluding directories?
I believe the grep command is what you're looking for:
hg grep 'myfunctionname' -r "user('me') and file('class/database.php')"
You can match a specific file in the file revset query by specifying its full path. Use **file.extension to find any file.extension anywhere in the repository. See the Mercurial docs on file patterns for more information. They are a little unclear on how to match any file with a specific name anywhere in the repo, however, so you'll probably have to do experiment a little.

How to convert Mercurial diff output to HTML?

Is there a way to add the HTML tags to Hg diff output? Currently our team of developers receives diffs over email every day and we would like to improve their readability, for example add line highlight and change title styles. I know it can be done in SVN via the special script, but I can't seem to find the instructions on how to do it in Hg. Thanks in advance.
I've never used it, it's only from a search on Google but you can try this:
http://colorer.sourceforge.net/
hg diff | colorer -h > diff.html
You can combine the output of this command with a hook after a commit. So, after every commit, mercurial can send an email with the diff in HTML. You just need to put the glue between the line above an the examples given for setting hooks in Mercurial.

How to setup hook for "hg branch"?

I want to write a hook that performs some actions each time I run hg branch branch_name (e.g. set "In progress" status for a JIRA ticket), but I can't find anything that runs during branching. Is there a way I can do it?
The is a pre-<command> hook (with a hyphen) for each command. Note that is is distinct from any hook that may exist without a hyphen, sush as precommit.
Thus you can do:
[hooks]
pre-bookmark = /usr/bin/notify_jira.sh ${HG_ARGS#bookmark }
to invoke:
/usr/bin/notify_jira.sh PROJ-415
when you run:
hg bookmark PROJ-415
Full details on the generic pre-<command> (and post-<command>) hooks can be found on the hgrc man page.
It also looks like pushkey hook might do what you want, but pre-bookmark (or better, post-bookmark) is probably more straightforward.

TortoiseHg: How to match a node hash to its revision node in the revision graph?

I gave someone a copy of my code using hg archive a while ago. A lot of commits has happened since then and I cannot remember which was the revision I gave him. There is some information about the version I had given the person in the .hg_archival.txt file. It has the node hash information, for example node: 72f497079285b2c3cf4f8b86950664f84221cd63
Using the information in the .hg_archival.txt file (like the node hash) how do I find the corresponding revision node in the revision graph displayed in TortoiseHg?
This works with TortoiseHg 2.x.y. If the Filter Toolbar is not visible, enable it by choosing View -> Filter Toolbar or pressing Ctrl+S.
In the revision set query textbox of the Filter toolbar paste the node hash and press Enter. If the Filter check box is set, only the revision matching the hash is displayed. If you disable the Filter check box, the revision matching the hash is highlighted in the complete revision graph.
The complete hash is 40 characters long. You only need to paste enough of it to be able to unambiguously match a revision.
hg log -r 72f497079285b2c3cf4f8b86950664f84221cd63 or hg update -r 72f497079285b2c3cf4f8b86950664f84221cd63

How can I label my build with revision number and not the GUID (in TeamCity)?

I am trying to do "continuous integration" with TeamCity. I would like to label my builds in a incremental way and the GUID provided by the VCS is not as usefull as a simple increasing number. I would like the number to actually match the revision in number in Mercurial.
My state of affairs:
Mercurial info:
I would like the build to be labeled 0.0.12 rather than the GUID.
Would someone be so kind and save me hours of trying to figure this out ?
As Lasse V. Karlsen mentioned those numerical revision numbers are local-clone specific and can be different for each clone. They're really not suitable for versioning -- you could reclone the same repo and get different revision numbers.
At the very least include the node id also creating something like 0.0.12-6ec760554f2b then you still get sortable release artifacts but are still firmly identifying your release.
If you're using numeric tags to tag releases there's a particularly nice option:
% hg log -r tip --template '{latesttag}.{latesttagdistance}'
which, if the most recent tag on that clone was called 1.0.1 and was 84 commits ago gives a value like:
1.0.1.84
Since you can have different heads that are 84 commits away from a tag in different repos you should still probably include the node id like:
% hg log -r tip --template '{latesttag}.{latesttagdistance}-{node|short}'
giving:
1.0.1.84-ec760554f2b
which makes a great version string.
The best and easiest way to see rev. number in TeamCity build number is to use Build Script Interaction with TeamCity. Namely, it has a possibility to set Build Number.
So, add to your project a new very first build step Command Line with following Command Executable
for /f %%i in ('c:\tortoisehg\hg id -n') do echo ##teamcity[buildNumber '%%i']
And you will get the Mercurial revision number as a label for your every build.
Of course you can change the command in quotes to anything you wish.
I believe my answer is way more correct than the accepted one.
EDIT:
Also you can do the same via MSBuild task rather than Command Executable. Have a MSBuild project file with following code, setup TeamCity to run it as first step, and it will alter its global variable buildNumber:
<Message Text="##teamcity[buildNumber '$(CurrentVersion)']" Importance="High" />
Where CurrentVersion is a string containing full version (for example "1.0.56.20931").
hg id produces the hash (6ec760554f2b), hg id -n produces the local revision number (12).
(Note this is an answer purely from the hg side, how you then get that into TeamCity, I don't know, as I've never used it.)
I managed to use it in Teamcity using a workaround:
<Exec Command="hg log -r tip --template {latesttag}.{latesttagdistance} > $(BuildAgentTempDir)\version.txt"/>
<ReadLinesFromFile File="$(BuildAgentTempDir)\version.txt">
<Output TaskParameter="Lines" ItemName="versionInfo"/>
</ReadLinesFromFile>
<TeamCitySetBuildNumber BuildNumber="#(versionInfo)-{build.number}" />
If you see the MSBuild task "TeamCitySetBuildNumber" I'm using the "{build.number}" variable because it substitutes this with what you set in the build number originally. I used %build.vcs.number% in my original settings (in the Web UI) and the result is just what Ry4an wrote above!
Hope it works for you!
When I used to use Subversion I used to do something similar in TeamCity. The format was:
{Major}.{Minor}.{TeamCity Build No.}.{Subversion Revision No.}
This allowed me to look at an assembly and see which build it came from on TeamCity and the revision number from subversion.
I have now moved to Git which has put me in the same situation as you. After playing with various ideas I have come to the conclusion that I don't actually need the revision, the build is good enough. Because TeamCity is such a powerful tool, all you need is the build number, given the build number you can look at the build history and determine the revision from that.
{Major}.{Minor}.{Macro}.{TeamCity Build No.}
Additionally you can get TeamCity to label your repository with the build number allowing you to look up a given build in your source control.
When providing your build number with numeral mercurial revision, you must be aware, that those numbers are clone-specific and can differ from clone to clone.
In our project we had the same issue. We're using TeamCity 7.1.1. We solved it in the following way:
Add Command line build step to your configuration.
Make this build step run first.
In the build step properties select "Run: 'Executable with parameters'"
Add the following text to Command Executable:
for /f %%i in ('hg id -n') do echo ##teamcity[buildNumber '%%i']
Save changes.
You can also use previously generated build number when performing step 3.
Example:
for /f %%i in ('hg id -n') do echo ##teamcity[buildNumber '%system.build.number%.%%i']
You can use this to make build counter present in your build number.
Read this to get more information!
Remember that teamcity compiles configurations build number before build starts and the correct build number will appear only after your build step will finish its job. That's why, in some cases (f.e. inserting your mercurial revision into artifact's name) you should define build number's value in preceding configuration and refer to it.
Example:
%dep.bt82.build.number%
Read this to get more information!