Is it possible to find out the email of a certain user.
I tried:
hg log --user sherman
but that only told me all the changes that sherman made and didn't tell me his email.
It's possible that the user hasn't provided an email at all when committing, but if they have this might help although it'll not give you the result for a single user.
hg churn -c --template "{author|person} - {author|email}"
Should give you a list of all the authors in the format
username - email_address
It'll also give you the number of commits they've made.
Another option that'll give you similar output (in Powershell) without the churn extension is:
hg log --template "{author|person} - {author|email}\n" | Sort-Object -Unique
I believe the Linux equivalent is something like:
hg log --template "{author|person} - {author|email}\n" | sort | uniq
Related
I have lot of tags for the project as it is very old and there are many releases to the
client.
Now when I list all the tags to view it; I ended up with a big list on my terminal.
Is there any command to show the top 5 tags or top 10 tags something like this.
I use
hg tags
command to list.
What exactly do you mean by "top"? Or do you want to only show 5 or 10 from the list?
To accomplish the last thing, use
hg tags | head -n 5
or
hg tags | tail -n 5
(if you're using *nix).
If you want to have Mercurial-only platform-independent soulution (without *Nix-specific), you can use Mercurial's revsets and templating (BTW, hg tags always show unwanted tip in list), something like
hg log -r "last(tag(),5)" --template "{tags}\t{rev}:{node|short}\n"
In order to decrease typing in process, you can write write (parametrized) revset in `[revsetalias] section on config-file like
[revsetalias]
lt = last(tag(),$1)
and use hg log -r "lt(<ANY NUMBER HERE>)" --template "{tags}\t{rev}:{node|short}\n" for getting <ANY NUMBER HERE> chronologically newest tags
or define additionally hg log --template as new command in [alias] section
[alias]
latestags = log -r "lt($1)" --template "{tags}\t{rev}:{node|short}\n"
and use later hg latestags(5) or hg latestags(10)
I need to get the current mercurial changeset to return in a very simple webservice, just the incrementing revision number and not the hash.
I know I can use
hg --cwd C:\repos\MyRepo parent
which will return me
changeset: 730:9d347e4a8d47
tag: tip
user: Simon Martin <simon.martin#mydomain.com>
date: Tue Jun 12 15:39:45 2012 +0100
summary: Fixed defect #244...
What I need though is just the 730 part of the changeset. The goal is to be able to write a very simple web service that will return that value - this will then be picked up by another application and displayed in the footer to give a quick reference as to which local revision is current. The testing process can then refer to that 'build' which can then be used to identify that.
You can show the local revision number of the working copy’s current parent using:
hg identify --num
Note that this outputs a + suffix when there are local changes. Add an -r . option to avoid this.
You can use the -r option to get the local revision number for other revisions too. For example, to retrieve the ID of the last tagged ancestor:
hg id -n -r "ancestors(.) and tag()"
You can use a custom template for the hg parent command.
This should get what you want:
hg parent --template "{rev}"
Using templates, I want to find out how many times a file has been revised across all changesets. So, put another way, how many changesets feature that file.
Is there a way to do it? And can it be done with the Keywords extension?
And yes, I realise it's not really what Mercurial is about. I have sucky requirements:)
hg log -q filename | wc -l will output amount of changesets
It is a normal feature of an VCS to track, when a file was changed, just run hg log THE_FILENAME to see all changesets which affect one specific file.
To count them, run for example hg log THE_FILENAME | grep -c "^changeset".
I thought I'd just add one more option to the list here since grep and wc (word count) may not be available in your console (Windows users especially). There is an equivalent functionality in PowerShell:
hg log -q filename | Measure-Object
This will return the count by default (and as you can see there are other options you can play with using Measure-Object)
Count : 14
Average :
Sum :
Maximum :
Minimum :
Property :
And if you are interested in how many commits you have done for the entire repository you can omit the -q filename parameter:
hg log | Measure-Object
Count : 492
Average :
Sum :
Maximum :
Minimum :
Property :
Is there a way to obtain the number of changed lines of code over a certain time period in a mercurial repository? Something along the lines of what statsvn does would be great, but anything counting the number of changed lines of code within 6 months will do (including a clever combination of arguments to hg log).
The hg churn extension is what you want.
You can get visual results with hg activity or hg chart.
Edit: hg diff and hg log both support a --stat option that can do this for you, only better and quicker.
I made an alias called lines to count changed lines (not necessarily lines of code) for me. Try putting this alias in your .hgrc file:
[alias]
lines = !echo `hg log -pr $# | grep "^+" | wc -l` Additions; echo `hg log -pr $# | grep "^-" | wc -l` Deletions;
Then pass it the revision first, followed by any optional arguments:
hg lines tip or hg lines 123:456 -u brian
Sometimes you want to know the number of lines changed excluding whitespace-only changes. This requires using diff -w underneath instead of log -p. I set up a linesw alias for this:
#ignore whitespace
linesw = ![[ $1 =~ : ]] && r=$1 || r="$1~1:$1"; echo `hg diff -wr $r | grep "^+\([^+]\|$\)" | wc -l` Additions; echo `hg diff -wr $r | grep "^-\([^-]\|$\)" | wc -l` Deletions;
hg linesw tip or hg lines 123:456
Note they behave slightly differently because diff and log behave differently -- for example, log will take a --user parameter while diff will not, and when passing a range, log will show changes commited in the first revision given in the range, while diff will not.
This has only been tested using bash.
I needed to do this, and spent quite a bit of time with the hg churn extension and similar solutions.
In the end, I found that what worked best for me was CLOC (Count Lines of Code): http://cloc.sourceforge.net/
You can give it two folders containing two versions of a project, and it will count all of the lines that are the same, modified, added, removed. It recognises multiple languages and itemises code, comments and blank lines.
To use it, I pulled out the two versions of my code from Hg into two parallel folders, and then used cloc --diff --ignore-whitespace
I wonder whether there is a mercurial command/extension that just tests whether a given changeset is in a branch. The command would be something like:
hg contains [-r branch] changeset_id
and should check whether the given changeset is in the current/given branch, returning just "Yes" or "No".
I know about the "debugancestor" command, but a "Yes/No" answer is way easier to read.
And if there is, is it possible to check for transplanted changesets as well?
EDIT: The scenario is located in a repo where named branches have multiple heads. Lets say a branch is named "dev-X", having more than 1 head and a longer history, too long at least to track it with various graph visualizations.
I want to figure out whether a changeset X in branch "dev-X" was merged into another head of "dev-X". Therefore I cannot use branch names but only changeset numbers/hashes to specify a branch.
And to top it all, I'm trying to find out whether changeset X was transplanted there, possibly taking more than 1 transplantation step. I know that the necessary info is stored in mercurial (I've seen it when tampering with the mercurial internals), it's just not accessible via the command line interface.
How about this:
hg log -r changeset_id -b branchname
That will give some output if changeid_id includes changes on branch branchname, otherwise no output is returned.
You could wrap it in a bash function if you want:
function contains() {
if [ "$(hg log -r $1 -b $2)" == "" ]
then
echo no
else
echo yes
fi
}
which does this:
$ contains 0 default
yes
$ contains 0 other
no
using 1.6 and later with the power of revision sets all you need is
hg log --rev "ancestors(.) and <revNum>"
eg
hg log --rev "ancestors(.) and 1234"
blank means no, output means yes, its in your history. Some of the other solutions posted here wont work if the changeset was created in a named branch, even if it was merged at some point later.
As mentioned in the comment above I gave it a shot, this is what came out:
http://bitbucket.org/resi/hg-contains/
It should be pretty easy to transform the results from debugancestor into a yes or a no (but there's definitely no built-in way to do that; write a script already!). Be aware that the answer might be wrong if the branch has more than one branch head, though.
(Writing an extension to add a command to do this should also be nigh-trivial, BTW.)
You could always just print out the name of the branch for that revision (it'll be empty if it's default) and then test that against whatever you want (in bash or in a scripting language of some sort):
hg log --template '{branches}' -r <revision name/number>
I've tested most of approaches above, did not work. The extension 'contains' somehow takes wrong revision (I think its a bug), the hg log --rev "ancestors(.) and 1234" work, but I found even more simple approach to do this:
hg merge -P <changeset>
Will show you if anything unmerged remains (it will also include changesets which are not merged parents of the changeset in question)