git/list[1] front-page[2] threads[3] people[4] search[5] about
 

GIT Web Interface

From
KSKay Sievers <kay.sievers@vrfy.org>
Date
Apr 19, 2005, 00:44 UTC
Message-ID
<20050419004415.GA10628@vrfy.org>
I'm hacking on a simple web interface, cause I missed the bkweb too much.
It can't do much more than browse through the source tree and show the
log now, but that should change... :)
  http://ehlo.org/~kay/gitweb.pl?project=linux-2.6

How can I get the files touched with a changeset and the corresponding diffs belonging to it?

Thanks, Kay

-- 
#!/usr/bin/perl

# This file is licensed under the GPL v2, or a later version
# (C) 2005, Kay Sievers <kay.sievers@vrfy.org>


use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $query = new CGI;
my $gitbin = "/home/kay/bin";
my $gitroot = "/home/kay/public_html";

my $project = $query->param("project") || "";
my $action = $query->param("action") || "";
my $hash = $query->param("hash") || "";
my $projectroot = "$gitroot/$project";
$ENV{'SHA1_FILE_DIRECTORY'} = "$projectroot/.git/objects";

sub header {
	print $query->header();
	print $query->start_html("gitweb");
	print $query->h1($project);
}

sub footer {
	print $query->end_html();
}

if ($project eq "") {
	open my $fd, "-|", "ls", "-1", $gitroot;
	my (@path) = map { chomp; $_ } <$fd>;
	close $fd;
	header();
	print "projects:<br/>\n";
	foreach my $line (@path) {
		if (-e "$gitroot/$line/.git/HEAD") {
			print $query->a({-href => "gitweb.pl?project=$line"}, $line) . "<br/>\n";
		}
	}
	footer();
	exit;
}

if ($action eq "") {
	print $query->redirect("gitweb.pl?project=$project&action=show_log");
	exit;
}

if ($action eq "show_file") {
	header();
	print "<pre>\n";
	open my $fd, "-|", "$gitbin/cat-file", "blob", $hash;
	my $nr;
	while (my $line = <$fd>) {
		$nr++;
		print "$nr\t$line";
	}
	close $fd;
	print "</pre>\n";
	footer();
} elsif ($action eq "show_tree") {
	if ($hash eq "") {
		open my $fd, "$projectroot/.git/HEAD";
		my $head = <$fd>;
		chomp $head;
		close $fd;

		open $fd, "-|", "$gitbin/cat-file", "commit", $head;
		my $tree = <$fd>;
		chomp $tree;
		$tree =~ s/tree //;
		close $fd;
		$hash = $tree;
	}
	open my $fd, "-|", "$gitbin/ls-tree", $hash;
	my (@entries) = map { chomp; $_ } <$fd>;
	close $fd;
	header();
	foreach my $line (@entries) {
		$line =~ m/^([0-9]+)\t(.*)\t(.*)\t(.*)$/;
		my $t_type = $2;
		my $t_hash = $3;
		my $t_name = $4;
		if ($t_type eq "blob") {
			print "B\t" . $query->a({-href => "gitweb.pl?project=$project&action=show_file&hash=$3"}, $4) . "<br/>\n";
		} elsif ($t_type eq "tree") {
			print "T\t" . $query->a({-href => "gitweb.pl?project=$project&action=show_tree&hash=$3"}, $4) . "<br/>\n";
		}
	}
	footer();
} elsif ($action eq "show_log") {
	open my $fd, "$projectroot/.git/HEAD";
	my $head = <$fd>;
	chomp $head;
	close $fd;

	open my $fd, "-|", "$gitbin/rev-tree", $head;
	my (@revtree) = map { chomp; $_ } <$fd>;
	close $fd;

	header();
	foreach my $rev (reverse sort @revtree) {
		$rev =~ m/^([0-9]+) ([0-9a-fA-F]+)/;
		my $time = $1;
		my $commit = $2;

		open my $fd, "-|", "$gitbin/cat-file", "commit", $commit;
		print "commit $commit<br/>\n";
		while (my $line = <$fd>) {
			if ($line =~ m/^tree (.*)$/) {
				print $query->a({-href => "gitweb.pl?project=$project&action=show_tree&hash=$1"}, $line) . "<br/>\n";
			} elsif ($line =~ m/^(author|committer) (.*)/) {
				$line =~ m/^(.*) (.*>) ([0-9]+) (.*)$/;
				my $type = $1;
				my $name = $2;
				my $time = $3;
				my $timezone = $4;
				$name =~ s/</&lt;/;
				$name =~ s/>/&gt;/;
				$time = gmtime($time);
				print "$type $name $time $timezone<br/>\n";
			} else {
				$line =~ s/</&lt;/;
				$line =~ s/>/&gt;/;
				print "$line<br/>\n";
			}
		}
		close $fd;
		print "====================================<br/><br/>\n";
	}
	footer();
} else {
	header();
	print "unknown action\n";
	footer();
}
Next: Petr Baudis
Message 1 of 7 in “GIT Web Interface”
  1. Kay SieversApr 19, 2005
  2. Petr BaudisApr 19, 2005
  3. Kay SieversApr 19, 2005
  4. Greg KHApr 19, 2005
  5. Stéphane FillodApr 19, 2005
  6. Kay SieversApr 19, 2005
  7. Greg KHApr 19, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.