How to include more than one file pattern in Mercurial command - mercurial

Mercurial 1.7.5 on Windows.
I have a few files I have modified, and want to split them into two commits. To do so, I'm playing with the -I (or --include) option. Docs state:
-I --include PATTERN [+] include names matching the given patterns
I haven't been able to figure out how to include more than one pattern yet. I've tried:
hg status -I C:\folderToSolution\Project1\**.cs C:\folderToSolution\Project3\**.cs
hg status -I C:\folderToSolution\Project1\**.cs +C:\folderToSolution\Project3\**.cs
(Using status to test my pattern before committing.)
What's the syntax for getting more than one pattern in the option?

Specify -I before each pattern
hg status -I C:\folderToSolution\Project1\**.cs -I C:\folderToSolution\Project3\**.cs
The [+] in the documentation means that the option can be specified more than once.

Related

Mercurial find files that have not been modified since a revision

I am trying to find a list of source files that have not been modified for the past few years.
This is one aspect I am trying to measure to try to help us understand the amount of stability and change in a given project over time.
Is there any way in mercurial to identify the files that have not been modified since a given revision?
There is some ambiguity in the question, but it can probably be answered using the status (st) command. For example, to obtain a listing based on a comparison of the files at revision R with those in the pwd, you could run:
hg st --rev R -cn
The -c option is equivalent to "--clean" (meaning in effect "no change").
To compare the files at revision R with those in the most recent commit:
hg st --rev R:-1 -cn
There are many ways to specify "R", e.g. 0 for the initial commit.
Posting my own answer.
I cloned the repository twice into new directories.
Then updated one to the current version and one to the original baseline revsion
hg update <rev>
Then used the diff command to find files that were identical (excluding whitespace changes)
diff -sqrbwB original current | grep "identical"
The diff flags are as follows:
-s reports identical files (facilitating the grep for "identical")
-q brief report (don't need a detailed report of differences)
-r recursively follow directories
-b ignore space changes
-w ignore all space
-B ignore Blank lines
Not sure if -b -w and -B are all necessary but it worked and output a list of files that have not chaged.

Get rid of "nameless" node in mercurial repository

I found a nameless node in my mercurial repository.
On executing the tag listing command "hg tags" as part of the generated output, I find the same node mentioned twice.
The output of hg tags command contains the following duplicate nodes:
xyz_release_tag daa262c10
daa262c10
In one of the entries, the node has a name but the other entry the node does not have a name.
I am in the process of migrating the mercurial repository to git and I am using fast-export to do the conversion.
The presence of this "nameless" node causes errors during the conversion process. Similar issue has been discussed at: https://github.com/frej/fast-export/issues/1.
As a quick workaround, I made a quick change to my local repository cache file. There is a file by name "tags2-visible" that gets created after I run the hg tags command for listing. Once I modify this file to remove the entry for the nameless node, it disappears and the conversion process succeeds.
I am not very sure if this is the right way to do it or if at all there is any other way.
Any thoughts ?
Resulting quickfix:
hg tags # Creates .hg/cache/tags2-visible
# Fix the nameless tag
sed -rie 's/^([^ ]+) $/\1 \1/' .hg/cache/tags2-visible
How I came to the solution:
$ hg tags | tail -3
PRODUCION_18032010 216:3e0a6415bbde
166:809065c08005
PRODUCION 125:d98f65c06bac
$ # Where is the problem?
$ grep -r 809065c08005
.hg/cache/tags2-visible:809065c08005ef2d261f10f72f17ea5fcd1e7540
$ # Add " test" to the end of this line
$ sed -i .hg/cache/tags2-visible -e 's/809065c08005ef2d261f10f72f17ea5fcd1e7540/809065c08005ef2d261f10f72f17ea5fcd1e7540 test/'
$ # Checking the edition
$ grep -r 809065c08005
.hg/cache/tags2-visible:809065c08005ef2d261f10f72f17ea5fcd1e7540 test
$ # Checking the validity of the hack
$ hg tags | tail -3
PRODUCION_18032010 216:3e0a6415bbde
test 166:809065c08005
PRODUCION 125:d98f65c06bac
After editing .hg/cache/tags2-visible adding a label to the branch fast-export worked for me.
Anyone see any problem in editing .hg/cache/tags2-visible in this way?

Finding first appearance of text in Mercurial repository

I have a Mercurial repository with ~800 changesets and I need to find the first changeset where the word Example appeared. The word appears inside a .php file and not on a commit comment etc.
What is the quickest/easiest way to do that?
try hg grep Example *.php
hg grep [OPTION]... PATTERN [FILE]...
search for a pattern in specified files and revisions
Search revisions of files for a regular expression.
This command behaves differently than Unix grep. It only
accepts Python/Perl regexps. It searches repository
history, not the working directory. It always prints the
revision number in which a match appears.
By default, grep only prints output for the first
revision of a file in which it finds a match. To get it
to print every revision that contains a change in match
status ("-" for a match that becomes a non-match, or "+"
for a non-match that becomes a match), use the --all
flag.
options:
-0 --print0 end fields with NUL
--all print all revisions that match
-f --follow follow changeset history, or file
history across copies and renames
-i --ignore-case ignore case when matching
-l --files-with-matches print only filenames and revisions
that match
-n --line-number print matching line numbers
-r --rev search in given revision range
-u --user list the author (long with -v)
-d --date list the date (short with -q)
-I --include include names matching the given
patterns
-X --exclude exclude names matching the given
patterns
use "hg -v help grep" to show global options
The selected answer is incomplete:
hg grep --all --files-with-matches 'PATTERN' [FILES]
is normally what you want.
You would want to use the --diff (--all is deprecated) flag of hg grep. It searches the diffs rather than file contents itself, what this would result in is, you would get all the changesets/revisions where the word Example appeared or removed.
Now to get the first hit you need to pass this in revlog order via the -r flag. That is the revisions will be searched from 0 to tip. ( -r 0:tip )
And for the .php files you would want to pass -I flag which is for file name patterns.
So your command will be :
hg grep --all -r 0:tip "Example" -I "*.php"
hg help filesets
...
"grep(regex)"
File contains the given regular expression.
hg locate "set:grep(Example) and **.php"
or
hg locate "set:**.php and (**Example*)"

How to stop tracking a file without deleting it on Mercurial

I saw this thread which discusses a solution for git, and found this thread on the mailing list for Mercurial (the thread is four years old though)
The solution proposed in the mailing list is to use hg rm -Af file (and they leave open the possibility of implementing this behavior as a new, more intuitive option). I'm wondering if that option exists now.
Also, if I try the command above:
> hg rm -Af my_file
> hg st
R my_file
there is an R next to my_file, but the file my_file is technically on disk, and I have told Mercurial to stop tracking it, so why am I getting R next to it?
You can just use hg forget or maybe add the file to your .hgignore file
And to answer the last question about the R in my_file. If you see the help for hg rm --help:
hg remove [OPTION]... FILE...
aliases: rm
remove the specified files on the next commit
Schedule the indicated files for removal from the current branch.
This command schedules the files to be removed at the next commit. To undo
a remove before that, see "hg revert". To undo added files, see "hg
forget".
Returns 0 on success, 1 if any warnings encountered.
options:
-A --after record delete for missing files
-f --force remove (and delete) file even if added or modified
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
[+] marked option can be specified multiple times
use "hg -v help remove" to show more info
As you can see you are forcing the deletion of that file and that's why you can see the R (Removed)

How can I get the changeset ID of the base file when merging with mercurial?

I have a couple branches that I need to merge, but I don't know where some of the changes are coming from that are showing up in my merge tool. The change sets of local and other are obvious, but how can I find out which change set the base file came from? I'm working in a repository with dozens of branches, so viewing the graph and tracking it doesn't work very well.
Using revsets (Mercurial 1.6 and later), you can get the common ancestor of two changesets with:
hg log -r ancestor(rev1,rev2)
Try the hg grep command:
hg grep [OPTION]... PATTERN [FILE]...
search for a pattern in specified files and revisions
Search revisions of files for a regular expression.
This command behaves differently than Unix grep. It only accepts
Python/Perl regexps. It searches repository history, not the working
directory. It always prints the revision number in which a match appears.
By default, grep only prints output for the first revision of a file in
which it finds a match. To get it to print every revision that contains a
change in match status ("-" for a match that becomes a non-match, or "+"
for a non-match that becomes a match), use the --all flag.
Returns 0 if a match is found, 1 otherwise.
options:
-0 --print0 end fields with NUL
--all print all revisions that match
-f --follow follow changeset history, or file history across
copies and renames
-i --ignore-case ignore case when matching
-l --files-with-matches print only filenames and revisions that match
-n --line-number print matching line numbers
-r --rev REV [+] only search files changed within revision range
-u --user list the author (long with -v)
-d --date list the date (short with -q)
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
--mq operate on patch repository
[+] marked option can be specified multiple times
use "hg -v help grep" to show global options
You can use it like:
hg grep "a string"
and it will tell you in which revision it was first added.
If you're looking for something less search-y and more overview-y you can use hg log -v to see what files were changes in each changeset and hg log -p to see the actual diffs for each.