Archive for the ‘Commands’ Category

From Mercurial to Git and from GoogleCode to GitHub

2012/10/10 2 comments

Some time ago we decided to modify the VCS of our code repository at Google Code from SVN to Mercurial, the only DVCS alternative offered in Google Code (at the time). This system has far more power than non distributed systems and allowed us more freedom to develop on different branches and to merge all the work. But, this decision was made mainly to keep the current repository location rather than by choice, since we prefer to work with Git.

Lately, though, we have been having some problems with Mercurial and that, added to the difficulty to export and import this kind of repository in other code hosting sites, led us to change yet again, this time to Git and to GitHub.

Here are the steps we took in order to do so.

First, make some folders to store the tools and the repositories

cd ~
mkdir repository_conversion
cd repository_conversion
mkdir gitprojectname

Next, make a clone of the mercurial repository in your local machine.

hg clone

This will make a folder projectname with the contents of the repository. Then, download Fast-Export, a tool that converts mercurial repositories into git repositories.

git clone

Before going any further, you should know that Git is more restrictive with the username format of the person doing a commit. Mercurial lets you commit using partial or different username information for the same set of credentials. For example, if you have a committer called John Doe you might find Mercurial commits with the following aliases:

John Doe <>

The correct commit format is the last one (User Name <>), so you should map the wrong aliases to a correct format before converting the repository. To do this, you first need to get the list of all the people that has made a commit in your repository. For that purpose, we can either use the hg log command or the churn extension.

hg log --template "{author}\n" | sort | uniq -c | sort -nr

If you want to use the churn extension instead, you must enable it first in the Mercurial configuration file. You can enable it system-wide editing the /etc/mercurial/hgrc file (or just for your repository editing ~/repository_conversion/projectname/.hg/hgrc) and adding the following to it:

hgext.churn =

Then you can call it like this:

hg churn --template "{author}"

These commands output a list of committers sorted by number of commits. You can copy that list to a text file called to do the user mapping. Following our previous example, you would map John Doe’s aliases like this:

johndoe@dcb55125-116f-0410-8251-c326c5fbc55d=John Doe <> Doe <>
johndoe=John Doe <>
John Doe <>=John Doe <>

Once you are done mapping the users, go to the git repository folder, init a git repository and call the conversion script:

cd ~/repository_conversion/gitprojectname
git init
../fast-export/ -r ../projectname/ -A ../

Depending on the number of commits and branches this process may take a while. Once the conversion is finished, you can check if all the committers were correctly mapped typing:

cd ~/repository_conversion/gitprojectname
git shortlog -nse --all

So, with that we have a fully converted git repository. Now we have to upload it to a repository hosting site, like say GitHub. GitHub has very good and detailed guides on how to setup your repositories, so I will just assume I signed up on the site as and tell you the commands you need in order to push the repository without going into much detail.

Create a set of SSH keys to be able to push your changes:

cd ~/.ssh
mkdir key_backup
cp id_rsa* key_backup
rm id_rsa*
ssh-keygen -t rsa -C ""

Copy the contents of your file (exactly as they are, without adding or removing anything) in your SSH Key management area and create a repository named gitprojectname using the web interface.

Before starting to commit and push things in your repository, you should configure the commit user of Git (the user and email that appears in the commit’s metadata). If you haven’t done so by now, you can set your system-wide git user like this:

git config --global ""
git config --global "John Doe"

If you prefer to use this user only for a particular repository:

cd ~/repository_conversion/gitprojectname
git config --local ""
git config --local "John Doe"

Finally, push your local repository to the remote site (you can also do this via SSH using the keyset you generated in the previous step and pointing to an URL that looks like

cd ~/repository_conversion/gitprojectname
git remote add origin
git push -u origin master

If you have several branches and want to upload them all you can try replacing the last step with git push --all.

Hope that was helpful.


Read .gz text files on the fly

Logging systems usually compress old logs into Gzip files. Uncompressing those files to check old logs can be a pain in the neck, specially if you don’t know which file contains the entries of a specific date. The zless command will help you a lot with this task. For example, to read Tomcat’s compressed logs you just have to execute:

zless catalina.out.1.gz

You will see the content of the compressed file as if you were using the less command.

Categories: Commands, Linux Tags: , , , ,

Shutdown your computer, cleaners are lurking

It’s late and you are at work. Is time to take the bus and go home, but your computer is processing a huge amount of ultra-confidential data (of course, this only can be done on Linux :P). You’ll miss the bus if you don’t run now, but you don’t want to shut you computer down and lose a lot of time repeating all the process tomorrow.

The problem is that if you don’t shut down the computer, the cleaners, that are coming at 22:00 to clean the office armed with their brooms and cloths, could access all the data in your computer (as we all know, cleaners are actually high level hackers). So, what can you do?

Don’t worry, just run the next command and your PC will shut down one minute before they come into your office:

shutdown -h 21:59

If you know how long it will take to finish the process (let’s say 60 minutes), run this command instead:

shutdown -h +60

Finally, if you are too paranoid, you can halt your computer immediately by running this one:

shutdown -h now

Hey! And don’t forget to lock the door!

Categories: Commands, Linux Tags: , ,