~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to contrib/continuous/post-receive-cinotify

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20070422133105-tkmhz328g2p0epz1
Tags: 1:1.5.1.2-1
* new upstream point release.
* debian/changelog.upstream: upstream changes taken from mailing list
  announcement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
#
 
3
# A hook that notifies its companion cidaemon through a simple
 
4
# queue file that a ref has been updated via a push (actually
 
5
# by a receive-pack running on the server).
 
6
#
 
7
# See cidaemon for per-repository configuration details.
 
8
#
 
9
# To use this hook, add it as the post-receive hook, make it
 
10
# executable, and set its configuration options.
 
11
#
 
12
 
 
13
local $ENV{PATH} = '/opt/git/bin';
 
14
 
 
15
use strict;
 
16
use warnings;
 
17
use File::Spec;
 
18
use Storable qw(retrieve nstore);
 
19
use Fcntl ':flock';
 
20
 
 
21
my $git_dir = File::Spec->rel2abs($ENV{GIT_DIR});
 
22
my $queue_name = `git config --get builder.queue`;chop $queue_name;
 
23
$queue_name =~ m,^([^\s]+)$,; $queue_name = $1; # untaint
 
24
unless ($queue_name) {
 
25
        1 while <STDIN>;
 
26
        print STDERR "\nerror: builder.queue not set.  Not enqueing.\n\n";
 
27
        exit;
 
28
}
 
29
my $queue_lock = "$queue_name.lock";
 
30
 
 
31
my @skip;
 
32
open S, "git config --get-all builder.skip|";
 
33
while (<S>) {
 
34
        chop;
 
35
        push @skip, $_;
 
36
}
 
37
close S;
 
38
 
 
39
my @new_branch_base;
 
40
open S, "git config --get-all builder.newBranchBase|";
 
41
while (<S>) {
 
42
        chop;
 
43
        push @new_branch_base, $_;
 
44
}
 
45
close S;
 
46
 
 
47
sub skip ($)
 
48
{
 
49
        local $_ = shift;
 
50
        foreach my $p (@skip) {
 
51
                return 1 if /^$p/;
 
52
        }
 
53
        0;
 
54
}
 
55
 
 
56
open LOCK, ">$queue_lock" or die "Can't open $queue_lock: $!";
 
57
flock LOCK, LOCK_EX;
 
58
 
 
59
my $queue = -f $queue_name ? retrieve $queue_name : [];
 
60
my %existing;
 
61
foreach my $r (@$queue) {
 
62
        my ($gd, $ref) = @$r;
 
63
        $existing{$gd}{$ref} = $r;
 
64
}
 
65
 
 
66
my @new_branch_commits;
 
67
my $loaded_new_branch_commits = 0;
 
68
 
 
69
while (<STDIN>) {
 
70
        chop;
 
71
        my ($old, $new, $ref) = split / /, $_, 3;
 
72
 
 
73
        next if $old eq $new;
 
74
        next if $new =~ /^0{40}$/;
 
75
        next if skip $ref;
 
76
 
 
77
        my $r = $existing{$git_dir}{$ref};
 
78
        if ($r) {
 
79
                $r->[3] = $new;
 
80
        } else {
 
81
                if ($old =~ /^0{40}$/) {
 
82
                        if (!$loaded_new_branch_commits && @new_branch_base) {
 
83
                                open M,'-|','git','show-ref',@new_branch_base;
 
84
                                while (<M>) {
 
85
                                        ($_) = split / /, $_;
 
86
                                        push @new_branch_commits, $_;
 
87
                                }
 
88
                                close M;
 
89
                                $loaded_new_branch_commits = 1;
 
90
                        }
 
91
                        $old = [@new_branch_commits];
 
92
                } else {
 
93
                        $old = [$old];
 
94
                }
 
95
 
 
96
                $r = [$git_dir, $ref, $old, $new];
 
97
                $existing{$git_dir}{$ref} = $r;
 
98
                push @$queue, $r;
 
99
        }
 
100
}
 
101
nstore $queue, $queue_name;
 
102
 
 
103
flock LOCK, LOCK_UN;
 
104
close LOCK;