Re: More precise tag following

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jan 27, 2007 at 02:39:30PM -0800, Linus Torvalds wrote:

> (For some reason I have never fathomed, gtk apps seem to always like 
> adding about a mile of empty space around lines. I want my text nice and 
> tight - gtk menus and text always look like it's 1½ line spacing to me. 
> Which may be ok when you're writing a paper and want space to add your 
> scribbles and underlining etc, but not when you're looking at the screen, 
> and it just means that there's *less* space for commentary).

Yes, I spent quite a bit of time trying to correct this, but it seems to
be an artifact of the GtkTreeView widget (which maybe I am abusing, but
it seems like the right thing conceptually). As the vertical spacing is
a "style" attribute, I'm not as a developer allowed to change it. You
can try this, which helps a bit (the default is '2'); put it before any
widgets are created:

Gtk2::Rc->parse_string(<<'EOS');
style "treeview_style"
{
  GtkTreeView::vertical-separator = 0
}
class "GtkTreeView" style "treeview_style"
EOS

But it's still pretty ugly. I'm not inclined to hack on it much more --
IMHO, a nice curses interface like tig would be much more sensible.

> Yeah. It needs the logic to coalesce consecutive file-name/line-nr 
> entries, but even after you add a "-C" to the arguments (which really 
> makes 'git-blame' quite a bit more expensive), it doesn't feel "slow". 

Yes, it would ideally color the blobs (try adding
$fileview->set_rules_hint(1) to get alternating line colors!). But I
don't think I can do anything that magical with their widget, which
means I get to write my own widget. Bleh.

> Just ugly ;)

:)

Here's my "final" version that looks up the committer name. It also
takes blame output on the command line:
  git-blame --incremental -C file | perl foo.pl file
I won't be working on it anymore, but if somebody wants to see an
example of some really ugly perl/gtk code, here it is.

-Peff

-- >8 --
#!/usr/bin/perl

use Gtk2 -init;
use Gtk2::SimpleList;

my $fn = shift or die "require filename to blame";

Gtk2::Rc->parse_string(<<'EOS');
style "treeview_style"
{
  GtkTreeView::vertical-separator = 0
}
class "GtkTreeView" style "treeview_style"
EOS

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect(destroy => sub { Gtk2->main_quit });
my $scrolled_window = Gtk2::ScrolledWindow->new;
$window->add($scrolled_window);
my $fileview = Gtk2::SimpleList->new(
    'Commit' => 'text',
    'CommitInfo' => 'text',
    'FileLine' => 'text',
    'Data' => 'text'
);
$scrolled_window->add($fileview);
$fileview->get_column(0)->set_spacing(0);
$fileview->set_size_request(1024, 768);
$fileview->set_rules_hint(1);

open(my $fh, '<', $fn)
  or die "unable to open $fn: $!";
while(<$fh>) {
  chomp;
  $fileview->{data}->[$.] = ['HEAD', '?', "$fn:$.", $_];
}

Glib::IO->add_watch(fileno(STDIN), 'in', \&read_blame_line);

$window->show_all;
Gtk2->main;
exit 0;

my $buf;
sub read_blame_line {
  my $r = sysread(STDIN, $buf, 1024, length($buf));
  return 0 unless $r;
  while($buf =~ s/([^\n]*)\n//) {
    my $line = $1;
    $line =~ /^(\d+) (\d+) ([0-9a-f]+):(.*):(\d+)$/
      or die "bad blame output: $line";
    my $info = commitinfo($3);
    for(my $i = 0; $i < $2; $i++) {
      @{$fileview->{data}->[$1+$i]}[0,1] =
        (substr($3, 0, 8), $info, $4 . ':' . ($5+$i+1));
    }
  }
  return 1;
}

sub commitinfo {
  my $hash = shift;
  open(my $fh, '-|', qw(git rev-list -1 --pretty=raw), $hash)
    or die "unable to open git-rev-list: $!";
  while(<$fh>) {
    chomp;
    next unless /^author (.*) <.*> (\d+) ([+-]\d+)/;
    return $1 . ' ' . format_time($2, $3);
  }
}

sub format_time {
  my $time = shift;
  my $tz = shift;

  my $minutes = $tz < 0 ? 0-$tz : $tz;
  $minutes = ($minutes / 100)*60 + ($minutes % 100);
  $minutes = $tz < 0 ? 0-$minutes : $minutes;
  $time += $minutes * 60;
  my @t = gmtime($time);
  return sprintf('%04d-%02d-%02d %02d:%02d:%02d %s', @t[5,4,3,2,1,0], $tz);
}
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]