Documentation/git-reset: reorder modes for soft-mixed-hard progression
[git/mjg.git] / contrib / continuous / post-receive-cinotify
blobb8f5a609af464f3af8b624246cc69eb335ce81d1
1 #!/usr/bin/perl
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).
7 # See cidaemon for per-repository configuration details.
9 # To use this hook, add it as the post-receive hook, make it
10 # executable, and set its configuration options.
13 local $ENV{PATH} = '/opt/git/bin';
15 use strict;
16 use warnings;
17 use File::Spec;
18 use Storable qw(retrieve nstore);
19 use Fcntl ':flock';
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;
29 my $queue_lock = "$queue_name.lock";
31 my @skip;
32 open S, "git config --get-all builder.skip|";
33 while (<S>) {
34 chop;
35 push @skip, $_;
37 close S;
39 my @new_branch_base;
40 open S, "git config --get-all builder.newBranchBase|";
41 while (<S>) {
42 chop;
43 push @new_branch_base, $_;
45 close S;
47 sub skip ($)
49 local $_ = shift;
50 foreach my $p (@skip) {
51 return 1 if /^$p/;
56 open LOCK, ">$queue_lock" or die "Can't open $queue_lock: $!";
57 flock LOCK, LOCK_EX;
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;
66 my @new_branch_commits;
67 my $loaded_new_branch_commits = 0;
69 while (<STDIN>) {
70 chop;
71 my ($old, $new, $ref) = split / /, $_, 3;
73 next if $old eq $new;
74 next if $new =~ /^0{40}$/;
75 next if skip $ref;
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, $_;
88 close M;
89 $loaded_new_branch_commits = 1;
91 $old = [@new_branch_commits];
92 } else {
93 $old = [$old];
96 $r = [$git_dir, $ref, $old, $new];
97 $existing{$git_dir}{$ref} = $r;
98 push @$queue, $r;
101 nstore $queue, $queue_name;
103 flock LOCK, LOCK_UN;
104 close LOCK;