Software Woes

Rants, tips and tricks



Saturday, February 21, 2009



Setting up Git offline work via USB memory stick

I have a home laptop and an office desktop computer. When I leave office, everything is shut down, so there is no way to access the git repository online. Since I didn't want to drag my notebook to work everyday, I got the idea to have a git repository on my USB memory stick.

One of the requirements was that it is a bare repository so it does not take too much space. I had a lot of trouble figuring out this one, and finally I got the right way when I understood how git is meant to be used.

I created a big file on my FAT filesystem, and formatted in in ext2 with something like:

dd if=/dev/null of=/mnt/stick/repos.ext2 bs=1024 count=500000
mkfs.ext2 /mnt/stick/repos.ext2

Then I mounted it and created a bare copy of my repos:

mount -o loop /mnt/stick/repos /mnt/repos
cd /mnt/repos
git clone /home/milanb/repos repos

When I go home, I repeat the mount on my laptop and pull the changes into local development repository:

mount -o loop /mnt/stick/repos /mnt/repos
cd ~/devel/repos
git pull /mnt/repos/repos master

After I commit the changes, just push it back to stick:

git push /mnt/repos/repos

Now, the tricky part, when I go back to the office, I was (stupid) to try to push the changes from the stick to local repository. There are ways to make this work, but quite awkward and error prone. Git is not meant to be used that way. The rules are simple, if you do everything right:

- you should never need to pull/fetch into bare repos
- you should never need to push into non-bare repos

So, what I really needed to do is just to reverse the logic and pull changes from stick into my local repository:

git pull /mnt/repos/repos master

It merges (unless there's confict) and everything is fine. To prevent from typing all those long paths, you can define aliases (remotes) via git-remote command:

git remote add /mnt/repos/repos stick

And later just do these to pull and push:

git pull stick master
git push stick

All that time I used SVN and CVS just got that centralized way of thinking into me. Finally I'm free ;)

All I can say is: Git simply rocks!



Thursday, February 12, 2009



Git statistics

Today I was looking for some tool to analyze my Git repository and show some nice statistics. Pie charts and bars would also be nice, but simple tables with stats also do the job. I'm used to seeing many good tools for the same task against CVS and SVN repositories, but Git is still young so my hopes weren't high.

Google search yields this one:

http://sourceforge.net/projects/gitstat

I used GitStat version 0.5. Now, I am an experienced developer and computer user, but the list of dependencies simply sucks. I mean, such simple tool to need all this is ridiculous:

* PHP 4.3.3 or later
* GD 1.8.x or GD 2.15 or higher
* Mysql 3.x or later
* Perl, Perl-DBD-MySQL, Perl-DBI
* Perl MIME:Lite Module (Lite.pm) copy to .../path_to_gitstat/gstat_pl/lib
* GeSHi( Generic Syntax Highlighter )
* JpGraph 1.21 or JpGraph 2.2(for PHP5)

Both Perl and PHP? Copy stuff around manually? (why isn't it in the package?)

Ok, I can understand MySQL for caching, but you still need to fetch changes from Git repos, so what's the point? I bet it doesn't do deltas and even if it does it probably does not handle rebase. Or maybe someone would prove me wrong. Wouldn't something like SQLite be more appropriate for a tool like this?

Anyway, this seemed too much hassle and I really didn't want the stats THAT bad, so I almost gave up... but then I noticed another tool, with a subtle difference in the name. It almost slipped because of that, so I hope authors of either of these two are going to invent some cool name for their project and create a distinction. Anyway, the other tool is named GitStats.

http://gitstats.sourceforge.net/

It's a simple and dead-easy to use Python script. What can I say: It just simply works. The only dependency (beside obious Git and Python) is GNU Plot, which is installed by default on most Linux systems anyway.

It created the stats for my 1.5 years old, 1.5 million line of code repository in about 3 minutes. That was quite fine for me. No pie charts though, but maybe there will be some in future versions.