Get Mercurial to tell you the hgrc files it loads - mercurial

I often have trouble finding the hgrc files loaded by Mercurial.
I know the possible locations are documented at http://linux.die.net/man/5/hgrc, but there are quite a few of them, and they vary from platform to platform, and they depend on things like the "Mercurial installation directory" which is yet another thing to have to track down. And sometimes, it seems like it's loading hgrc files from locations that are not on that list at all!
It would be great if I could get Mercurial to tell me which hgrc files it's loading, so I don't have to spend time searching for them. Basically, I'd like to be able to pass hg an option, like hg -debug-hgrc-paths and have it print the full path to each hgrc file that it loads. Much like how you can get gcc to print the header file search paths it is using with gcc -v -E. Does anyone know of such an option?

It might be more than you actually need but
hg --debug showconfig
will tell you quite a bit about what values are being set from where.

Related

Mercurial tool for high level summary of ignored files

I asked a similar question to summarize the directories of files that are ignored under mercurial and got an appropriate answer Summarize all ignored files/directories in a mercurial repository.
However, with large projects, the information thrown out by hg stats -i is still a lot (even after filtering to directory level). Is there a tool or smart script that will help me get a high level summary of ignored files. Something that draws out a tree like directory structure with icons indicating which top level folders have ignored stuff. It could be exe or pyc files or entire libraries like django or jquery that are sitting in my repo but are part of hgignore.
If that doesn't exist, maybe a simple tool that can cross-verify that I haven't made errors in the glob/regexp patterns of hgignore i.e. accidentally ignored some crucial file.
There is no tool in the Mercurial ecosystem that is going to give you a visual tree of ignored things. You could, however, do something like this:
cd ..
cp -a yourRepo ignoredOnlyRepo # create a copy (not a clone) of the tree
cd ignoredOnlyRepo
hg status -mardcu --no-status --print0 | xargs -0 rm
That creates a copy (not a clone) of your repo and then deletes all non-ignored files from it. At that point you can use any file viewer you like and you're seeing only the ignored stuff because they're all that's left.

How to find out the size of a mercurial repository?

So, for example, if there's a mercurial repository https://code.google.com/p/potentiallyLarge is there a command which would allow me to find out its size before cloning it? Something like
hg size https://code.google.com/p/potentiallyLarge
Also, is there a command for doing this for subversion repositories?
The size used on disk is different from the bandwidth used to make a clone. Some hosting sites (such as Bitbucket) display the size on disk so that you know upfront how much space you'll need on your system before cloning. But I can see that Google Code doesn't, so it wont help you here.
The Mercurial wire protocol doesn't expose any commands that can tell you how big a repository is. When you make a normal clone, the client doesn't know upfront how much data it will receive, it just receives a stream of data. After receiving the changelog, the client knows how many manifests and filelogs to expect, but it doesn't know the size of them.
In fact, it's difficult for the server to compute how much data a clone will use: the network bandwidth used is less than the disk space since the compression used is different (bzip2 vs gzip). However, if you use --uncompressed with your clone (which Google Code doesn't support) then there is a trick, see below.
The only way to know much bandwidth a clone uses is to make one. If you have a clone already you can use hg bundle to simulate a clone:
$ hg bundle --all my-bundle.hg
The size of the bundle will tell you how much data there is in the repository.
A trick: If Google Code had supported hg clone --uncompressed, then you could use that to learn the size of a remote repository! When you use --uncompressed, the client asks the server to send the content of the .hg/ directory as-is — without re-compressing it with bzip2. Conveniently, the server starts the stream by telling the client the size of the repository. So you can start such a clone and then abort it (with Control-C) when your client has printed the line telling you the size of the repo.
Update: My answer below is wrong, but I'm leaving it here since MG provided some good info in response. It looks like the right answer is "no".
Not a great way, but a work-around sort of way. A hg clone URL is really just hg init ; hg pull URL And the command hg incoming tells you what you'd get if you did a pull, so you could do:
hg init theproject
cd theproject
hg incoming --stat URL_TO_THE_PROJECT
and get a pretty decent guess of how much data you'll be pulling down if you follow up with:
hg pull URL_TO_THE_PROJECT
I'm not sure about the network efficiency of hg incoming but I don't think it downloads everything from all the changesets, though I could be wrong about that. It offers a --bundle option that saves whatever incoming pulls down to a file from which you can later pull to avoid double downloading.

How do I list configured urls in Mercurial?

Obviously I can do something like cat .hg/hgrc on *nix to see the paths I have configured, but is there a built-in Mercurial command? A Google search for "hg list configured urls" didn't seem to have any useful results, and neither does hg help urls (that I noticed).
Is there any command that will display the urls I have configured?
hg paths is what you are looking for. hg help paths will give you more information.
The correct answer is indeed hg paths as smooth reggae wrote, but so you know, there's also the showconfig command, which will show you any section(s) of the combined config files.
There's not much point in using hg showconfig paths, which is longer to type, but it's useful for quickly checking the value of other configuration settings.

Mercurial: remote operation with different environments (remotecmd .hgrc)

There are two project in which I collaborate, they live in different servers, A and B.
While A has the hg program in /opt/mercurial/bin/hg, B has it in /usr/local/bin/hg.
When I want to pull/push changes to either remote, I have to manually modify .hgrcfile in order for the option remotecmdto point to the right location of hg.
I would like to know if it is possible to setup different remotecmdpaths for different remotes so that I don't have to manually change the path of the hgprogram everytime I need to do some remote operation.
I saw this question: Setup platform-dependent hgrc but it seemed to me that there should be a more native (something like a built-in setting) way to do this. So far I haven't been able to find it, so any help will be welcome :)
Thanks!
Ideally you just get the hg binary into your $PATH on both servers and you don't have to think about it anymore. That can be done in the system's /etc/profile or in your .ssh/enviironment on that remote server. Most people never even need to think about remotecmd.
If they're separate projects (or even separate clones locally of the same project) you can set the remotecmd in the .hg/hgrc file within each repository -- settings don't just have to be in your ~/hgrc file.
Also be aware that --remotecmd is available as a command line option for push and pull, so you could use that and even combine it with something like:
[alias]
pusha = push --remotecmd /opt/mercurial/bin/hg
and then you can just do hg pusha
Really though, just try to get hg into your path like everyone else does.

Is it possible to checkout a single directory from a Mercurial (HG) repository?

So, I'm trying to checkout just the TestNG plugin from the Netbeans contrib repository. (Or is it module? I'm new to Mercurial, so I don't really know the lingo yet.)
When I run the following command...
hg clone http://hg.netbeans.org/main/contrib/
...I get the entire repository, which contains all of the the contrib plug-ins. Is it possible to just pull this location?
http://hg.netbeans.org/main/contrib/file/tip/testng/
Thanks!
This concept is called "narrow cloning" and no, it's not possible at the moment in Mercurial.
It's on the radar of some of us that contribute to Mercurial but it's a hard problem to solve. For example:
How do you calculate the hash of any new commits you make if you don't have all of the files in the repo?
What happens if you try to view the history of a file in contrib/testng if that file was moved from another folder?
I'm not sure, but I think the answer in the general case is "probably not".
If the repository is local (it doesn't sound like it is in your case), you can do something like:
hg archive -R /path/to/my/repo -I /path/to/my/repo/folder/i/want export-folder-name
(The command would need to be something that exports non-VC'd files, rather than creating a partial repo, since the .hg stuff is stored once at the toplevel, rather than in pieces in each folder as SVN does.)
It doesn't work on remote repositories, though. Neither does "hg log", and the hg folks explained why:
Imagine I send a log -p command to http://www.kernel.org/hg/linux-2.6, which is
approaching 100k changesets. At one diff per second (lots of seeking), this will
take about 3 hours of CPU/disk time on the server, nevermind metric tons of
bandwidth. It would be faster and simpler for everyone just to clone the repo
and do the log locally.
I suspect hg archive can't work remotely for the same reason.