James Bowes

Purveyor of Pre-eminent Programmes

Posts Tagged ‘git

Graphing Git Repository Activity In ASCII

with 3 comments

Here’s a quick little script I wrote up (adapted from this perlmonks post) to show git repository activity as an ascii graph, like so:

git-graph screenshotThe X axis represents a day, with the current day being on the far right. The Y axis is no. of lines added + no. of lines deleted during that day.

EDIT (2009/02/03):

WordPress.com won’t let me attach a .pl file, so here’s the contents:

#!/usr/bin/perl
#
# git-graph.pl - Generate an ascii graph of git repository activity
#
# Copyright (C) 2008 James Bowes <jbowes@dangerouslyinc.com>
#
# Graphing routine Adapted from http://www.perlmonks.org/?node_id=336907

sub get_activity {
    my $day = shift;
    my $git_cmd = 'git diff --shortstat "@{' . ($day + 1) .' day ago}" "@{' .
                  ($day or "0") . ' day ago}"';
    $res = `$git_cmd 2> /dev/null`;

    $res =~ /, (.*?) insertions\(\+\), (.*?) deletions\(-\)/;
    $activity = $1 + $2;

    return $activity;
}

@deltas = ();
foreach $day (0..70) {
    push (@deltas, get_activity ($day));
}

print ("\n");
print graph(@deltas);
print ("\n");

sub graph {
  my( $i, $magic, $m, $p, $top, @g ) = ( 0, 20, 7, 70, 0, () );

  foreach $pad (0..($p - scalar(@_))) {
      push (@_, 0);
  }

  @_ = reverse @_; 

  for (0..($p)) {
      $top = ($top > $_[$_]) ? $top : $_[$_];
  }

  $top = $top - ($top % 100) + 100;

  my $s = $top > $magic ? ( $top / $magic ) : 1;  ### calculate scale

  for (0..$magic) {
    $g[$_] = sprintf("%" . ($m - 1) . "d |", $_ * $s) .
             ($_ % 5 == 0 ? '_' : ' ') x ($p);
    for $i (0..($p)) {
        substr($g[$_], ($i + $m), 1) = '#' if ($_[$i] / $s) > $_;
    }
  }
  join( "\n", reverse( @g ), ' Date:  ' . '^^^^^^|' x ( $p / 7 ));  
}  # end sub graph

__END__
Advertisements

Written by jbowes

May 24, 2008 at 11:15 am

Posted in SCM

Tagged with , , , ,

git bisect: A practical example with yum

leave a comment »

update: This post is now on my new blog.

I used git bisect to track down a bug in yum last night. It was so easy and practical that I figured I should record it here, so that others might want to give git a try.

I was attempting to install mutt, and yum failed (printing a traceback) after the rpms had been downloaded, but before the test transaction finished. So I started git bisect, and marked the current point as bad:

$> git bisect start
$> git bisect bad

The yum 3.1.0 release didn’t have this bug (it was the version I had installed at the time), so I marked it as good:

$> git bisect good yum-3-1-0
Bisecting: 15 revisions left to test after this
[1d0454af41ef6361604cafa8c7a13d80bc183c63] make it so that we see that the local rpm is present and then don't download

Git automatically checks out the next revision for you to test. This one happened to be good, so I marked it as such. I continued to test and mark revisions as either good or bad, until:

$> git bisect bad
832814e6b037621c4f26ee6a47e4b7b6dc7eb073 is first bad commit
commit 832814e6b037621c4f26ee6a47e4b7b6dc7eb073
Author: XXX
Date: XXX
XXXXXXXXXXXXXXXX
:100644 100644 8ea07cda8441687da2f0e3dd794c3a1c50a0f161 567ef25557eacbd932bc5f8c20cd34e49c169f57 M cli.py
:100644 100644 50fb320c9c31a0f394985e244dc35b9766fb28ce 3875b70c4f8a7b6a9cf7d06de6df47e8a0ae5777 M yum-updatesd.py
:040000 040000 28296caad31015e1573b19dd84d12c2e3db2b90b 98048391465ca3da06c210d6f45c3f234dc12e0a M yum

At this point, with the traceback and the diff from the commit, it was easy enough figure out what the problem was, and commit a fix.

Written by jbowes

February 18, 2007 at 8:59 pm

Posted in SCM, tech

Tagged with , , ,

Did I mention that svn sucks?

with 4 comments

$> svn co svn://gcc.gnu.org/svn/gcc/trunk gcc
$> cd gcc
$> du -h
...
1.6G .
$> svn export . ../clean-gcc
$> cd ../clean-gcc
$> du -h
...
638M .
$>

Oh, yes, I did.

Written by jbowes

February 11, 2007 at 12:46 pm

Posted in SCM, tech

Tagged with , ,

Giving back to git

leave a comment »

It must be obvious from previous posts that I love git. Tonight I sent a patch to the mailing list. It’s small and simple; it lets you save options for cvsimport in your config file, rather than supplying them each time you run it.

Hopefully it will be of use to others.

Written by jbowes

February 5, 2007 at 8:38 pm

Posted in life, tech

Tagged with , , , ,

My .gitconfig

with one comment

update: I’ve posted a revised and updated version of my .gitconfig on my new blog.

By default, git does not include aliases for commands. For instance,
‘git status’ works but ‘git st’ does not. This will hurt your noggin if you are
used to using cvs or svn.
Also, the internet is for posting config files on.
So here are the contents of my .gitconfig:


[user]
    name = James Bowes
    email = MY_EMAIL

[alias]
    ci = commit -a
    co = checkout
    st = status -a
    praise = blame

[apply]
    whitespace = strip

[diff]
    color = auto
    rename = copy

[pager]
    color = true

[status]
    color = auto

Just drop that into ~/.gitconfig and you’re all set. Also, use your own name
and email address.

Written by jbowes

December 19, 2006 at 5:16 pm

Posted in tech

Tagged with , , , , , ,