Git: how to tag old commit

Another noob git tip. Tagging with git is easy and I won’t duplicate another explanation here. But suppose you want to tag a commit which you already pushed to another repo. When you push, nothing happens. I had tagged before, so I thought the problem was that I wanted to tag a commit which I already pushed.

But the trick to know here is: push simply does not push tags by default. You have to specify an option. So any tag you would want to share, on your last commit or any other commit, you would have to push explicitly:

git push origin <mytag>

or if you’d want to sync all tags in one go:

git push --tags origin

So, the title of this blog post was actually a trick question 😉

Git: set up remote branch tracking post factum

I often have the following scenario:
– create local repository/branch
– create gitorious project/repository
– push branch to gitorious

This way you end up with your local branch not tracking the remote one. You know you’re not tracking when you have to specify the branch every time you push/pull and when you don’t see how much commits you are ahead of the remote. It is a matter of setting up the correct tracking configuration, something like this for the master branch:

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

However, I just discovered that since git 1.7 there is now a command for this:

git branch --set-upstream master origin/master

much easier to remember!

I <3 libpcap

A few years ago, I wrote a small app showing the open network connections (announcement following shortly). I never figured out how to measure transfer rates over the connections since the kernel does not seem to provide this info through the /proc filesystem (only some data queue length which is related to kernel mem usage).

Today we all know and love iftop, but where does it get that info? Simple: pcap! Out of curiosity, I checked out the libpcap docs to see how hard it would be to get started. Turned out to be pretty simple! There are a few excellent tutorials which get you started real fast. In about half an hour I made this very simple sniffer which accumulates the received bytes and packets per second and prints it out when the second changes. Each line contains the timestamp (sec), KB/s and number of packets received in that second. Here you can see me watching a youtube vid 🙂

Opening device eth0
ts = 1285276934, load = 0.7 KB/s (4)
ts = 1285276935, load = 0.3 KB/s (1)
ts = 1285276939, load = 0.9 KB/s (4)
ts = 1285276940, load = 14.4 KB/s (44)
ts = 1285276941, load = 294.9 KB/s (764)
ts = 1285276942, load = 608.9 KB/s (1505)
ts = 1285276943, load = 1164.4 KB/s (2882)
ts = 1285276944, load = 1242.6 KB/s (3064)
ts = 1285276945, load = 1166.6 KB/s (2880)
ts = 1285276946, load = 69.9 KB/s (179)
ts = 1285276947, load = 140.1 KB/s (363)
ts = 1285276948, load = 139.9 KB/s (361)
ts = 1285276949, load = 139.7 KB/s (358)
ts = 1285276950, load = 139.7 KB/s (358)
ts = 1285276951, load = 139.3 KB/s (358)
....

It is a good test to see if the calculated payload is correct. The initial burst of ~1.2MB/s confirms that. 🙂

git through proxy

You’re at work and want to access your git repo who’s residing in the free external world?

create the following config file in your .ssh folder:

Host
ProxyCommand connect -S <proxy host>:<proxy port> %h %p

replace the hosts and port as appropriate.

You can find the connect executable for windows here (contains a lot of other useful socks info as well).
Hat tip to pieter.

Amazing

The 1989 C standard didn’t allow variable argument macros. They were added in the 1999 standard. To use one according to the standard, plug in “__VA_ARGS__” where you want the variable arguments. For example:

#define print(…) real_print( __VA_ARGS__ , 0)

Of course, your compiler may or may not support either this feature or a nonstandard variation.

You might have guessed that, after all those years, the MS compiler still does not support them!!! arghh. crap.