views:

310

answers:

1

Hi all, I am a mercurial user on windows and I am trying to write a batch file to check for incoming changes to a number of repositories stored in a common folder (i.e. there could be 10 or so small mercurial repos under a main folder). I have the following batch file that successfully iterates through the multiple repositories and runs hg incoming. However I can't seem to get it to execute hg -pull -u when a repository is found that has remote changes.

   FOR /D /r %%G in (".hg*") DO (
    @echo Processing: %%G
    cd /d %%G\.. 
    hg incoming
    IF NOT ERRORLEVEL 0 (
     echo Pulling changes from the server
     hg pull -u
    )
    cd..
    )

I am pretty sure the problem lies with the If statement. hg incoming doesn't seem to have a return value that can be interpreted by the ERRORLEVEL. Is this the right approach or should I be using python instead?

+2  A: 

The exit code for hg incoming and hg outgoing is 1 is there were no incoming/outgoing changesets and 0 otherwise. This is apparently not really documented anywhere, but it means that your test is backwards.

Also, doing both hg incoming and hg pull does the job twice: you should simply use hg pull. The help for hg incoming says:

For remote repository, using --bundle avoids downloading the changesets twice if the incoming is followed by a pull.

So you're actually downloading all changesets twice, using twice the bandwidth.

Martin Geisler
I was under the impression that hg incoming and outgoing were simply previews of what would be pulled/pushed not actually pulling all the changes sets. If I understand correctly hg incoming grabs the changesets and when finished discards them? If that is the case then simply using hg pull -u would be sufficent.
Bluebill
Yeah, I agree, 'hg incoming' ought to just quickly fetch the meta data (authors, commit messages, etc) and not the actual data. I'm not sufficiently familiar with that part of the code to say why it's done this way.
Martin Geisler