~ubuntu-branches/ubuntu/utopic/gitolite3/utopic-proposed

« back to all changes in this revision

Viewing changes to src/commands/who-pushed

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2013-05-18 17:59:21 UTC
  • Revision ID: package-import@ubuntu.com-20130518175921-ac4xe6vd0jtxvjot
Tags: upstream-3.5.1+4
ImportĀ upstreamĀ versionĀ 3.5.1+4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
use lib $ENV{GL_LIBDIR};
 
6
use Gitolite::Easy;
 
7
 
 
8
=for usage
 
9
Usage:    ssh git@host who-pushed <repo> <SHA>
 
10
 
 
11
Determine who pushed the given commit.  The first few hex digits of the SHA
 
12
should suffice.
 
13
 
 
14
Each line of the output contains the following fields: timestamp, a
 
15
transaction ID, username, refname, and the old and new SHAs for the ref.
 
16
 
 
17
We assume the logfile names have been left as default, or if changed, in such
 
18
a way that they come up oldest first when sorted.
 
19
 
 
20
The program searches ALL the log files, in reverse sorted order (i.e., newest
 
21
first).  This means it could take a long time if your log directory is large
 
22
and contains lots of old log files.  Patches to limit the search to an
 
23
optional date range are welcome.
 
24
 
 
25
Note on the "transaction ID" field: if looking at the log file doesn't help
 
26
you figure out what its purpose is, please just ignore it.
 
27
=cut
 
28
 
 
29
usage() if not @ARGV or @ARGV < 2 or $ARGV[0] eq '-h';
 
30
usage() if $ARGV[1] !~ /^[0-9a-f]+$/i;
 
31
 
 
32
my $repo = shift;
 
33
my $sha = shift; $sha =~ tr/A-F/a-f/;
 
34
 
 
35
$ENV{GL_USER} and ( can_read($repo) or die "no read permissions on '$repo'" );
 
36
 
 
37
# ----------------------------------------------------------------------
 
38
 
 
39
my $repodir = "$ENV{GL_REPO_BASE}/$repo.git";
 
40
chdir $repodir or die "repo '$repo' missing";
 
41
(my $logdir = $ENV{GL_LOGFILE}) =~ s(/[^/]+$)();
 
42
 
 
43
for my $logfile ( reverse glob("$logdir/*") ) {
 
44
    @ARGV = ($logfile);
 
45
    for my $line ( reverse grep { m(\tupdate\t($repo|$repodir)\t) } <> ) {
 
46
        chomp($line);
 
47
        my @fields = split /\t/, $line;
 
48
        my ($ts, $pid, $who, $ref, $d_old, $new) = @fields[ 0, 1, 4, 6, 7, 8];
 
49
 
 
50
        # d_old is what you display
 
51
        my $old = $d_old;
 
52
        $old = "" if $d_old eq ("0" x 40);
 
53
        $old = "$old.." if $old;
 
54
 
 
55
        system("git rev-list $old$new 2>/dev/null | grep ^$sha >/dev/null && echo '$ts $pid $who $ref $d_old $new'");
 
56
    }
 
57
}