How to set "hg diff" output shows in gvim? - mercurial

I use mercurial and I want to see modified change in Vim or GVim.
Normally there is hg diff which show the modified changes in diff format.
but I want to see it in Vim as the original version and modified version side-by-side.
I try extdiff in ExtdiffExtension but it doesn't work and gvim open some blank file.
I know there is gvim -d localfile otherfile but I don't know how to config mercurial.

If you're fine with vim, I'm been using this in my ~/.hgrc for months without problems
[extensions]
hgext.extdiff =
[extdiff]
cmd.vimdiff =
[alias]
vi = vimdiff
vim = vimdiff
Then you just use
hg vimdiff somefile
The [alias] section is optional, but it's nice to have.
I'm using v1.4.2, FWIW.

Check this: Using vimdiff to view single diffs
hg cat <filename> | vim - -c ":vert diffsplit <filename>" -c "map q :qa!<CR>";

I can't help you for the vim part, but in mercurial, to get the content of a file in the parent changest, you'll do hg cat path/to/my/file.ext

On OSX when using MacVim (and homebrew):
cd /usr/local/bin
ln -s mvim gvimdiff
edit~/.hgrc
[extdiff]
cmd.gdiff = gvimdiff
opts.gdiff = -f
then to use:
hg gdiff somefile.cpp

Related

Mercurial extension to automatically generate .hgignore file?

I have been thinking that it sure would be nice to have a command like "hg ignore" that would automatically add all untracked files to the .hgignore file.
Manually editing the .hgignore file is powerful, but when I am frequently creating new repositories it would be nice to be able to add only the files I want and then do an hg ignore to automatically have Mercurial ignore any others.
Does anyone know of any extensions that do this?
Try this once you've added all the files you need:
hg stat --unknown --no-status >> .hgignore
You can create a command to automatically generate your .hgignore using an alias. On a Unix-like system, add the following lines to your .hg/hgrc (or one of Mercurial's other configuration files):
[alias]
ignore = !echo 'syntax: glob' >> $(hg root)/.hgignore && \
$HG status --unknown --no-status >> $(hg root)/.hgignore
This will give you a hg ignore command that will populate the .hgignore file with all currently unknown files, thus turning them into ignored.
On Windows, the syntax for the alias is:
[alias]
ignore = !echo syntax: glob > .hgignore && "%HG%" status --unknown --no-status -X .hgignore >> .hgignore
On Windows, you must run it in the root directory of the repository, otherwise the .hgignore file will be created in the current directory, which is probably not what you want.
The ! syntax in aliases is new in Mercurial 1.7. In earlier versions you can add
[alias]
ignore = status --unknown --no-status
and then redirect the output of this command to the .hgignore file yourself:
hg ignore >> .hgignore
You will then also need to take care of adding a syntax: glob line, if necessary (the default syntax is regular expressions).

hg: unknown command 'extdiff''

I can't figure out why my extdiff extension is not working for Mercurial (on a Mac).
this is what my .hgrc file looks like:
[extensions]
fetch=
hgext.extdiff =
[extdiff]
cmd.kdiff3 =
[ui]
merge=kdiff3
[merge-tools]
kdiff3.executable=/Applications/kdiff3.app/Contents/MacOS/kdiff3
kdiff3.args = $base $local $other -o $output
and yet kdiff3 is recognized as a merge tool.. and can be run from the cmd line like "kdiff3". but what i'd like to do is use kdiff3 as a gui tool for comparing diff files.
like this:
hg extdiff -p kdiff3
this seems like the best way of using kdiff3 as a popup gui when using Mercurial.
I am new to this and am not sure if I am doing it right.
Thanks...!
By the way, when I try to run 'hg extdiff'
I get:
hg: unknown command 'extdiff'
'extdiff' is provided by the following extension:
extdiff command to allow external programs to compare revisions
use "hg help extensions" for information on enabling extensions
(even though it is in .hgrc)
Please note that merge-tool and external diff are different tools for different tasks.
For example you can use fmdiff script to use FileMerge for diff and k3diff for merge-tool:
Your .hgrc should be:
[extensions]
# enable external diff program
extdiff =
[extdiff]
cmd.opendiff = fmdiff
opts.opendiff =
[merge-tools]
# Override stock tool location
kdiff3.executable = /Applications/kdiff3.app/Contents/MacOS/kdiff3
# Specify command line
kdiff3.args = $base $local $other -o $output
# Give higher priority
kdiff3.priority = 1
Now you can use
hg opendiff myfile.ext
Please note that 'opendiff' is a custom wrapper name, so you can change it to your likes but it cannot be one of already reserver names.

How do I make diffmerge do a three-way merge with Mercurial?

I am currently using the commmand hg diffmerge -r 32 -r 30 myfile, but this only displays two windows, not three. How can I make it do a three way merge?
.hgrc
[ui]
merge=diffmerge
[extensions]
collapse=~/.hgext/collapse.py
hgext.purge=
hgext.extdiff=
hgext.graphlog=
[extdiff]
cmd.diffmerge=/usr/bin/diffmerge
[merge-tools]
diffmerge.executable=/usr/bin/diffmerge
diffmerge.args= --result=$output -t1="Local Version" -t2=$output -t3="Other Version" --caption=$output $local $base $other
diffmerge.binary=False
diffmerge.symlinks=False
diffmerge.gui=True
diffmerge.premerge=True
I suppose you mean you're using SourceGear DiffMerge as external merge tool. What's your .hgrc? Is it based on the sample from hg website?
My guess is that your diffmerge.args is problematic. You can try running diffmerge manually with those arguments to make sure it works.
With your .hgrc it's clear now. Your command hg diffmerge -r 32 -r 30 myfile is NOT a merge command, instead you're asking hg to use diffmerge as the external diff tool (specified in [extdiff] section) to compare myfile between version 32 and 30. There's not a 3rd version involved.
For merge you run hg merge [-r<the other head>], and since your .hgrc tells hg to use diffmerge as merge tool (specified in [ui] section) hg will use diffmerge for the 3-way merge. I verified that it works in my Windows setup with identical hgrc.

How to use `hg cat` from an empty working directory?

I have a repo located at x:/projects/repo1. The working directory has been emptied using hg update null. I want to extract the latest version of some files from there to a local directory.
I tried this:
x:\projects\repo1> hg cat -o c:\sql\%s scripts\*.sql -r tip
I get this error:
scripts\*.sql: No such file in rev 14f07c26178b
The same command works fine if the working directory is not empty. Is there a good reason why this does not work? Or do you know another way of extract some files from there to a local directory?
The hg cat command is for single files. If you want multiple files use the hg archive command, which makes zipfiles or directories full of files. Here's your command:
x:\projects\repo1> hg archive --include scripts\*.sql -r tip c:\sql
It seems that hg cat doesn't support wildcard symbols in paths. So you should use the full file name:
hg cat -r tip scripts/foo.sql
When your working copy is up to date with the tip revision, your shell does wildcard substitution for you.
The hg manifest command also might be helpful for getting tracked file listings.
This answer is to your comment on Andrey's answer:
hg manifest takes a --rev argument that you can use to see the list of all files in your repository:
hg manifest --rev tip
To get the list of files matching a pattern at the tip, use:
hg stat --all --include *.sql --rev tip --no-status
hg stat -A -I *.sql --rev tip -n # using abbreviations.
From there you could redirect the output to a file and edit each line into a hg cat command like in your original question. It appears (to me, at least, having done some experimentation) that hg cat uses the contents of the working directory -- rather than the contents of the repository at the revision specified -- for glob-matching, so once you know the exact name of the file, you can hg cat it at any revision.

How to view Mercurial changeset changes using a GUI diff tool

We use both Examdiff and Kdiff3 to view Mercurial changes.
Just add this to .hgrc:
[extdiff]
cmd.kdiff3 =
cmd.examdiff = C:\Program Files\ExamDiff Pro\ExamDiff.exe
And then you can type hg examdiff or hg diff3 to see a complete diff of all your changes.
What I would like is to do the same to see a "before and after" of files for a given changeset that was checked in by someone else.
I know you can type hg log to see all changesets and then hg log -vprXX to see a text diff, but that's too hard for my GUI preferring eyes. Anyone know how to the equivalent with the GUI tools?
Can't use just use the -c option to extdiff?
hg kdiff3 -c XX
or
hg examdiff -c XX
in your example?
-c --change change made by revision
from the hg help extdiff output.