I understand that I can print a revision in the terminal with hg cat filename -r, but it is often convuluted and hard to read in the terminal window.
Is there a way I can open a revision with textmate from terminal, similar to using mate filename?
I'd prefer not to have to export the revision, and then open it up in textmate.
Thanks!
You can use mate - to read from stdin. So you can use hg cat filename -r rev | mate -.
However, the TextMate Mercurial bundle is enabled by default, so if you're already viewing the file in TextMate, use Bundles > Mercurial > View Revision (or ⌘Y6) to pick an older revision to view instead.
Related
I'm trying to use mercurial file sets to add all the files in a directory tree, excluding very large files and any binary files. Cribbing from the mercurial documentation, this command should do it:
hg init
hg add 'set: size("<1M") and not binary()'
However this returns a status code of 0, and hasn't added anything to my new, empty repo. I've tried just 'set: not binary()' and that didn't work either.
The frustrating thing is that although I can google for mercurial file sets, and find lots of examples, I can't find anything to help troubleshoot when it doesn't work!
I don't have a .hgignore file, and it's a fresh empty repo. Mercurial 4.2.2.
The directory where I'm testing this has a couple of artificially created files for the purpose of testing. In my real use case, I inherit a multi-gigbyte tarball of assorted sources and binaries from a client, and I want to get all the sources into mercurial before I start hacking to fix their problems, hence the need to exclude the binaries and large files that otherwise choke mercurial.
Here's my little test script:
#!/bin/sh -ex
dd if=/dev/urandom of=binary_1k bs=1 count=1024
dd if=/dev/urandom of=binary_2M bs=1 count=2097152
echo "This. Is, a SMALL text file." > text_small
hexdump binary_1k > text_1k
hexdump binary_2M > text_2M
ls -lh
file binary_1k
file binary_2M
file text_1k
file text_2M
hg init
hg add 'set: size("<1M") and not binary()'
hg status -a
hg add 'set: not binary()'
hg status -a
hg add 'set: size("<1M")'
hg status -a
At the end of this, each status command reports no files in the repo, and the add commands report no errors.
The problem is that file sets do a query of Mercurial's repository data base, which knows only about files that are part of the repository or have been added.
One solution is to add all, and then to get rid of the files that you don't like, e.g.:
hg forget 'set:size(">1M") or binary()'
This works, because the query also requires recently added files, even if they haven't been committed yet.
I've just started using Meld. I'm using its Version Control Diff feature and its working well, except that it doesn't seem to use the .hgignore file.
The tree I'm working in is huge, but I only mercurial-track a small portion, so Meld is taking a loong time to scan the entire tree, 90% of which I could care less about.
I'm using Meld 1.6.0, which doesn't appear to allow the user to manually select the VC type, so I'm forced to start the compare in the directory containing the .hg sub-dir.
Is there a way to get Meld to use the .hgignore file or perhaps override Meld's default VC choice?
I think you should do "the other way around", that is:
configure mercurial to use meld as its "external diff" tool, utilizing "extdiff" extension.
NOTE: All of the above has been tested in UNIX-like environment
in ~/.hgrc enable "extdiff" extension by adding to [extensions] section:
[extensions]
extdiff =
add this below:
[extdiff]
cmd.meld = # if meld is not in your path, you may need to type in here the absolute path to the script
Save ~/.hgrc file.
Now, Then a new hg subcommand shall be available to you.
Enter the hg repo folder, in terminal:
user#machine:~$ cd myrepo
user#machine:~/myrepo$ hg meld
That would spawn meld properly, respectful to .hgignore, mercurial respects itself )
For GUI trickery, you may hook this up to context menus of your favourite file manager:
1. Linux: you may to dance with the Shaman's drum a bit more, but TortoiseHg respects extdiff extension.
1. Windows: TortoiseHg does this automagically
1. Mac: no idea how to do this to Finder :), maybe AppleScripting will be needed here.
Regards.
To somewhat elaborate on the title question, is there a way to have Mercurial search through the repository history for a particular version of a given file, and show all of the revisions (or just the most recent one) that contain that version?
For example, let's say that the current working revision is, say, 300 and a file was reverted to an earlier version (say, revision 200). I don't know this - all I can easily see is "how different" the new file is from the 300 version. How can I find out all of the possible revisions that it could have been reverted to?
And if Mercurial cannot do this natively, is there another tool that can? (TortoiseHG?)
I don't think this is possible with any of hg's built-in functionality, but you can get something like it with judicious xargs and md5sum application:
hg log --template "{rev}\\n" | xargs -I "{}" /bin/bash -c 'echo $(hg cat -r {} <filename> | md5sum) {}'
This will give you a list of md5 checksums with the revision number, which when you sort it will give you the revisions sharing versions of the file.
For a given file in a Mercurial repository, how can you see the revision history?
And how can you diff two revisions of the file?
Ideally doing all this with visual tools (we use ExamDiff to do some other diffs).
I'd say this is basic source control functionality but I can't seem to figure out how to do this with Mercurial.
hg log file
hg diff -r 10 -r 20 file
The hgk extension gives you hg view file command that shows a visual history, from which you can diff/vdiff arbitrary pair of revisions.
TortoiseHg gives you thg log file command that does the same thing but looks better.
For readability
hg diff -r revision1:revision2 file
Where revision1 and revision2 can be a tag, changeset etc.
If you use TortoiseHg:
Windows users can use Windows Explorer and view the revision history by right-clicking on the file.
For Linux users, you can do it within TortoiseHg but it took me a while to figure out how. You need to right-click on the desired file and select "File History". However, for some mysterious reason, the file needs to be unaltered. Furthermore, to find the desired file there are two options:
In ### revision set query### one can type:
file("**<myfile>")
The double ** are necessary to search directories recursively. This gives you immediately an list of all repositories in which the desired file was changed.
Alternatively, next to the ### filter text ### click first on the question mark sign and select "clean" to see all files in the repository. Then inside the ### filter text ### box you can narrow down the number of files shown.
Alternatively, Linux users can do it from a terminal as suggested by Geoffrey Zheng above:
thg log file
I am working on a system that performs continuous integration and I am looking for a method I can use to get the most recent changeset from a Mercurial repository without creating a repository locally.
I have considered using clone but this method will only work if you have set a working directory locally (since this will be occurring on a build server, I would prefer not to do this because of inclusion of the .hg file and the diffs - all I want is essentially an export of the files from the tip revision and nothing more.)
This request may not even be possible, and it's very likely that I just do not understand DVCS very well. However, if I cannot do what I want to do, is there a workaround?
It's possible using 'hg archive' depending how your remote repository is set up.
If it's available over HTTP using hgweb.cgi or hg serve you can hit the archive link programmatically to get the files you want. Example:
wget https://www.mercurial-scm.org/repo/hg/archive/tip.zip --output-document=- | unzip -
or it's available over ssh:
ssh you#there.com hg archive --type=zip - | unzip -
You can use:
$ hg clone http://your_repo
$ hg archive ../export/
$ rm -rf *
$ cd ..
$ cd export
From Mercurial's help files:
$ hg help archive
hg archive [OPTION]... DEST
create an unversioned archive of a
repository revision
You can use:
http://merc/raw-file
to retrieve a list of files in the repository or
http://merc/raw-file/filename
to get a specific file.