Git Quickie

This is a document I intend to maintain for my own purposes. It serves like a quick reminder to the steps I need to take when creating and working with git repositories.

First setup a bare repository on the server.

$ git --bare init projectX.git
Initialized empty Git repository in /pub/git/projectX.git/

Set one-liner description, visible in gitweb.

$ echo "Secret Project-X use ROT13 to decode all source files" >projectX.git/description

Setup a post-update hook so that the server repo is update automatically when you push to it.

$ cp ~/public_html/programming/post-update projectX.git/hooks/

Change how the "Owner" field in gitweb is displayed to include an obfuscated email address.
$ vi projectX.git/config

[gitweb]
        owner = "Joachim Nilsson <troglobit()vmlinux!org>"

These steps have become so common to me that I've setup a script to create server side git repositories.

You can now push to the server, after having setup remote location on the client.

$ git remote add origin ssh://login@example.com/pub/git/projextX.git
$ git push origin master
$ git push --tags

Tuesday, 13 July 2010 at 20:45 | /programming | permanent link to this entry

Simple Guide to Converting from Bazaar to GIT

You need git, and bazaar obviously. Also install bzr-fastimport, it contains the export plugin as well. The rest is a rip off from the folloing URL: http://fthieme.net/en/drupal6/node/77.

git init project.git
cd project.git
bzr fast-export --export-marks=.git/bzr.mark ~/project.bzr | git fast-import --export-marks=.git/git.mark

That worked for me. The output will likely be something like this:

01:41:19 Calculating the revisions to include ...
01:41:19 Starting export of 33 revisions ...
01:41:20 Exported 33 revisions in 0:00:01
git-fast-import statistics:
---------------------------------------------------------------------
Alloc'd objects:       5000
Total objects:          267 (         0 duplicates                  )
      blobs  :          158 (         0 duplicates         57 deltas)
      trees  :           76 (         0 duplicates         55 deltas)
      commits:           33 (         0 duplicates          0 deltas)
      tags   :            0 (         0 duplicates          0 deltas)
Total branches:          10 (         1 loads     )
      marks:           1024 (        33 unique    )
      atoms:             38
Memory total:          2344 KiB
       pools:          2110 KiB
     objects:           234 KiB
---------------------------------------------------------------------
pack_report: getpagesize()            =       4096
pack_report: core.packedGitWindowSize = 1073741824
pack_report: core.packedGitLimit      = 8589934592
pack_report: pack_used_ctr            =        267
pack_report: pack_mmap_calls          =         73
pack_report: pack_open_windows        =          1 /          1
pack_report: pack_mapped              =     977484 /     977484
---------------------------------------------------------------------

Now just do a simple "git checkout master" to get started working again.

Tuesday, 13 July 2010 at 01:56 | /programming | permanent link to this entry

Best. Programming. Font. Ever.

This is not only a reminder to myself, it is appraisal to the probably best programming font ever: Inconsolata. Thank you Mr Raph Levien!

On the previous laptop I used ProFont quite extensively, but its screen was only 1280x800, on the new laptop I have 1680x1050 and ProFont just got too small for my aging eyes.

For more tips on fonts, see Top-10 Programming Fonts and KeithDevens.com.

Monday, 26 April 2010 at 22:44 | /programming | permanent link to this entry

ANSI Escape Sequences

Here follows a listing of ANSI escape sequences that I use in some of my various projects. Most of the contents of this post is a rip off an original by Will Guaraldi Kahn-Greene.

Cursor Controls
\e[#;#H or \e[#;#f moves cursor to line #, column #
\e[#A moves cursor up # lines
\e[#B moves cursor down # lines
\e[#C moves cursor right # spaces
\e[#D moves cursor left # spaces
\e[#;#R reports current cursor line & column
\e[s save cursor position for recall later
\e[u Return to saved cursor position
Erase Functions
\e[2J clear screen and home cursor
\e[K clear to end of line
Color and Text Formatting
\e[#(;#)m Text formatting sequence numbers are separated by a ; and ends with an m. The # is one of the following.
Attributes
0 normal display
1 bold
4 underline (mono only)
5 blink on
7 reverse video on
8 nondisplayed (invisible)
Foreground Colors
30 black
31 red
32 green
33 yellow
34 blue
35 magenta
36 cyan
37 white
Background Colors
40 black
41 red
42 green
43 yellow
44 blue
45 magenta
46 cyan
47 white
Examples
\e[0;30m Black
\e[0;34m Blue
\e[0;32m Green
\e[0;36m Cyan
\e[0;31m Red
\e[0;35m Purple
\e[0;33m Brown
\e[0;37m Gray
\e[1;30m Dark Gray
\e[1;34m Light Blue
\e[1;32m Light Green
\e[1;36m Light Cyan
\e[1;31m Light Red
\e[1;35m Light Purple
\e[1;33m Yellow
\e[1;37m White
Screen Modes
\e[=#;7h or
\e[=h or
\e[=0h or
\e[?7h
put screen in indicated mode where # is:
0 40 x 25 black & white
1 40 x 25 color
2 80 x 25 b&w
3 80 x 25 color
4 320 x 200 color graphics
5 320 x 200 b & w graphics
6 640 x 200 b & w graphics
7 to wrap at end of line
\e[=#;7l or
\e[=l or
\e[=0l or
\e[?7l
resets mode # set with above command

For more details on VT100 and ANSI see vt100.net or ascii-table.com.

Monday, 06 July 2009 at 13:50 | /programming | permanent link to this entry

HowTo use Git for Collaborative Development

This is mainly some notes for myself so I don't forget. Having worked with GNU Bazaar before much of Git is still alien to me.

This HowTo is divided into two parts, 1) what happens on your laptop, and 2) what you must do on a remote server where you publish your changes.

laptop> mkdir projectX; cd projectX
laptop> git init
laptop> emacs file1.txt
laptop> git add file1.txt
laptop> git commit -m "Initial commit"

Thus far no suprises, right? Now, some nasty git bits:

laptop> emacs file1.txt
laptop> git commit

Yep, doesn't work. You have to add -a to the command line for "all".

laptop> git commit -a

OK, so next item. How to publish this so others can see? Well, I have a shell account on a remote server, so I naturally try:

laptop> git push sftp://login@example.com/pub/git/projectX.git
fatal: I don't handle protocol 'sftp'

Does not work. OK, next obvious choice:

laptop> git push ssh://login@example.com/pub/git/projectX.git
fatal: '/pub/git/projectX.git': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly

Wow, not a clue as to how I should proceed. After some Google-Foo I found this article detail the steps for remote repos. Very messy, compared to Bazaar.

laptop> ssh login@example.com
server> cd /pub/git
server> mkdir projectX.git; cd projectX.git
server> git --bare init
server> logout
laptop> git remote add origin ssh://login@example.com/pub/git/projextX.git
laptop> git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://login@example.com/pub/git/projectX.git'
> git push origin master
Counting objects: 29, done.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (29/29), 9.54 KiB, done.
Total 29 (delta 10), reused 0 (delta 0)
To ssh://login@example.com/pub/git/projectX.git
 * [new branch]      master -> master

Eventually I made it sing. The first "git push" must use the references to origin and master. At least you don't have to care about that later, after the first push command git remembers what you want.

Only one thing left, in the gitweb project overview projectX is listed as having no description. Of course, since I'm starting to get to know git by now, I realised early this is probably not something that is propagated through push — yep, I was right. You have to change that on the server.

laptop> ssh login@example.com
server> cd /pub/git/projectX.git
server> echo "Secret Project-X use ROT13 to decode all source files" >description
server> logout

All done! *phew*

Friday, 12 June 2009 at 23:50 | /programming | permanent link to this entry

More about Bzrweb and some about Git

OK, I admit it. I cannot decide what version control system (VCS) to use. I'm stuck between the speed and massive snow ball effect of Git and the ease of use and emotional attachment I have to Bazaar.

I've been "maintaining" bzrweb for a while now, not doing a very good job of it though. It's lagging behind considerably to the bzr API. After the upgrade of vmlinux.org to the latest Ubuntu server release bzrweb actually didn't work at all. If it hadn't been for the fixes by Rasmus Toftdahl Olesen I would probably have abandoned it entirely. Thank you Rasmus! Anyway, I've been gleaning at other Bazaar web frontends for a while. The only real option is Loggerhead, but even though I consider myself a computer pro I just cannot seem to wrap my head around how to set it up. I just wanted to setup a local browser for my user, without the need for root access. Like bzrweb supports, after having abandoned that, seemingly radical idea, I tried setting up a site wide shared installation ... no luck so far. :-/

In comparison to Loggerhead I easily managed to setup a Git repository browser, using a /pub/git structure, see git.vmlinux.org. The gitweb package in Ubuntu was very easy to setup, the one only thing I had problem with was the Apache VirtualHost setup. Some sleep cured that, but I should post the conf here, in case someone else experiences trouble.

I'll have another go at setting up Loggerhead later, or perhaps try to fixup bzrweb. I'm currently leaning towards fixing up bzrweb. Fix bugs viewing tree files, refactor tarball export and a new project summary page, are some of the most interesting things I can come up with. If only things could settle down at work for a while — oh well, vacation is coming up. Soon, my precious, soon...

First, however, I will publish the micro vt100/ansi tetris version I found last week. It will be the second project where I use Git, the first one was cons, which is a Xen xm wrapper for non privileged users.

Some Git and Bazaar links:

Friday, 12 June 2009 at 19:50 | /programming | permanent link to this entry

Learning about Git

It has been a long time coming, but now I'm seriously starting to look at Git. Git is the content tracker used by the Linux kernel folks, initially developed by Torvalds.

At Westermo R&D we use Subversion for our daily operations and today I started migrating the software to Git. Mainly just to get a comparison of performance, storage size and to explore how we can use Git on top of svn to become more productive when working in parallel in different teams. We've tried this quite extensively before, using Subversion branches and even though it's a heck of a lot easier to use compared to CVS its strength is not in merging.

The new merge tracking feature in Subversion 1.5 and features like detection of tree conflicts in, the recently released, 1.6 helps. However, working in small teams, disconnected from a centralised server is still not possible with svn, OK sure there is svk, but honestly, doesn't that make you think of CVS and bolting on features after the fact, similar to CVSNT or OpenCVS. Intriguingly bizarre projects. :-)

The reasons for trying out Git are not only related to any short comings of Subversion, Git has lot of strong points on its own. See here for instance:

I've started collecting a set of links that seem to be useful:

I'll conclude this post with two YouTube entries, first is the, now classic, presentation by Linus Torvalds on what Git isn't... and then Randal Schwartz on what Git is....

Friday, 10 April 2009 at 16:23 | /programming | permanent link to this entry

Why I like C

I thought I was alone, but it turns out I'm not. Scott James Remnant describes exacytly what I've been feeling the last couple of years. Read his blog entry on the subject. I couldn't agree more.

Friday, 27 March 2009 at 00:37 | /programming | permanent link to this entry