Category Archives: mercurial

Changing username in google code mercurial commit

Disclaimer: This kind of trickery can easily break your repository and totally annoy your collaborators. So take backups, butter up your friends, and consider yourself warned.. I take no responsibility for your issues should anything go wrong, and in fact this message will self-destruct in 10 seconds..

Anyway, the main point is just to document this for myself the next time I fail. I committed some stuff to a project in Google Code and noticed after a laptop change I had forgotten to set the username for mercurial. By default it grabs this information from the OS and network, which being paranoid, I did not wish to include in the public history. Next time I should just set the HGUSER environment variable.

But Mercurial does not let me “undo” pushed commits or modify them. And I had done two of them before noticing that I forgot to re-configure the username on the “new” laptop.

Addressing this is discussed here: http://code.google.com/p/support/wiki/MercurialFAQ. But it took me a while to get it figured out and to go ahead and just try it. So here is what worked (for me):

As noted here: http://mercurial.selenic.com/guide/#removing_history, we start with creating a fresh clone of the repository but without the commits we wish to modify. So assume we are at revision 202 and wish to modify the commit information for 201 and 202. Assume our project is named “gummybears” and is located in a directory with this name. We open terminal/command prompt in the directory above “gummybears”. We do this to get ourselves revision 200 in directory “gummybears-fix”:

hg clone -r 200 gummybears gummybears-fix

Then we want to get the changes that were present in revisions 201 and 202 but with a different username.

To do this, we issue the following set of commands (again from http://mercurial.selenic.com/guide/#removing_history):

cd gummybears
hg export 201 > ..\changes201.diff
hg export 202 > ..\changes202.diff

Now we have the revision 201 and 202 changes in the files changes201.diff and changes202.diff. By importing these to the “gummybears-fix” directory we can get a new versions of the repository with the naughty commits re-applied. But if we just do this, they will be re-applied with the bad username as before. So open up your favourite text editor and load the two “.diff” files. On the top is the “Username” field. Edit the value to your liking to not make the same mistake again.

Now we issue the following commands

cd gummybears-fix
hg import ..\changes201.diff
hg import ..\changes202.diff

And then we go for the step 4, profit. Go to Google Code, under project administration reset your repository. This will completely nuke everything so just be sure you understand what you are doing. After this rename “gummybears” to “gummybears-old” and rename “gummybears-fix” to “gummybears”. Probably this is not necessary but paranoia is good. Trust me, I know what I am doing (yeah right, boom). Finally, enter your new “gummybears” directory and type the following command

hg push

And then.. profit! hah, or so we wish. Anyways, your repository should now be fixed, with all the history intact and the usernames changed to protect the innocent. You can probably apply this to do other changes other than username too if you have the courage..

Oh yeah, then your still have to remove the old modified “commits” from your computer where you did the commit if this is not the one where you did these changes. Try this:

hg rollback

This does not actually work for me, but maybe you get a better experience. In any case, I am cloning a fresh set just to be sure..

 

 

moving to eclipse + mercurial errors

ok so i decided to try once again to move to eclipse from my 10 years of intellij. it seems like a better experience not, perhaps due to my numerous attemps before and the added “features” that spam my code in intellij with the latest versions. so i had to integrate with my mercurial repository. the mercurialeclipse plugin actually seems better than most things i have seen, with nice support for commit+push and pull+update. sorta was always painful for me to do those separately. but it gave me a strange error about dotencode not being supported. so changing this in the preferences to point to the tortoisehg executable fixed it as specified in

http://josefbetancourt.wordpress.com/2010/11/21/eclipse-team-hg-dotencode/

Seems a bit strange to leave it broken like that. Well, if it works for me now..

 

BTW, I had real issues finding out how to enable the whole thing after installing the mercurialeclipse plugins. it was right click on project->enable sharing and then select mercurial. nicely enough it did at this point identify that the project was part of the mercurial checkout done on the parent folder (the workspace). but why not document this someplace to say how to enable the whole feature? same goes pretty much for the google windowbuilder toolkit (one of the reasons i wish to try eclipse again). it is great but how about telling how to really apply and enable it? it is right click file->open with->windowbuilder. but no mention on the tool website? basic documentation is obviously too hard for nerds

BTW2: (ok i overuse btw lol) I always struggled with the idea of how to import existing code into eclipse without requiring a new checkout from version control of whatever. now i figure that at least in the latest versions it works if you create a workspace on the parent directory and then “create java project” and name it the same as you directory where the project is checked out. it will then give you the option to use the existing project there, and mostly it works great. whooppee. i also figured out that the workspace should actually match the “project” in intellij and the “project” the “module” in intellij. which in turn leads me to realize this is actually a good tool for modularization if you figure it this way. well, good to learn that after 10 years eh.. 😀

 

 

using mercurial

i wanted to move my stuff from github to a googlecode mercurial hostinrg. github seems to have a nice way to download the code as a .zip file so i take that, unzip it and then what?

cd <projectdir-unzipped>

hg init

hg add

(the add seems to automatically recurse everything)

hg commit

hs push <repository-address>

this push thing requires the username and password for the remote repository

so, stack-overflow to the rescue

http://stackoverflow.com/questions/2584407/how-to-save-username-and-password-with-mercurial

in the Mercurial.ini file we put in

[auth] 
myrepo.prefix = https://foo/bar
myrepo.username = my_uname 
myrepo.password = my_passwd

the point is that when i do a commit to a repository, it looks for the “https://foo/bar&#8221; in the configuration file and if found, uses that to read the username and password, if any are found. thats what i think of it anyway.

now i seem to have managed to create the repo and all.. whooppee.

 

 

 

mercurial install

there is a guide on the mercurial website

http://mercurial.selenic.com/guide/

but it seems a bit vague on topics such as is the mercurial.ini file supposed to be there when i run the installer or should i create it. this one seems to also provide some useful info

http://mercurial.selenic.com/wiki/WindowsInstall

now, i install kdiff3 as instructed from

http://kdiff3.sourceforge.net/

which does not have a 64bit version it seems although the last change note refers to that. well, who cares

then we put kdiff3 on the path, which is in the directory

C:\Program Files (x86)\KDiff3

btw, if you type “system” into the search item in the start menu, it loads something called system configuration which is not the one where you set the environment variables but something completely different.. interesting.

then we create the Mercurial.ini file by copying the stuff from the mercurial wiki example to

C:\Users\<username>\Mercurial.ini

that seems to have done the setup. now how to use it..

git me this, git me that, or mercurial

after trying out git with github for quite a while now, it still confuses me and it also seems that the windows integration is not so nice. probably i just do not apprechiate all the fancy things it has. still, the speed of it and the local repository access are very nice.

 

trying the different hosting site i guess now i will give mercurial a try on google code. maybe this will finally get me something i enjoy with simple for-dummies integration on windows and a reasonable hosting infrastructure speed.