git-p4: Unset P4DIFF environment variable when using 'p4 -du diff'
[gitweb.git] / git-cvsserver.perl
index 0d55fec04fa7e3e2a02987543a857a26ae1f96cb..7f632af20defd7a3cfd92008c51f7e599be13830 100755 (executable)
@@ -1211,13 +1211,13 @@ sub req_ci
 
     chdir $tmpdir;
 
-    # populate the temporary index based
+    # populate the temporary index
     system("git-read-tree", $parenthash);
     unless ($? == 0)
     {
        die "Error running git-read-tree $state->{module} $file_index $!";
     }
-    $log->info("Created index '$file_index' with for head $state->{module} - exit status $?");
+    $log->info("Created index '$file_index' for head $state->{module} - exit status $?");
 
     my @committedfiles = ();
     my %oldmeta;
@@ -1237,7 +1237,7 @@ sub req_ci
 
         my ( $filepart, $dirpart ) = filenamesplit($filename);
 
-        # do a checkout of the file if it part of this tree
+       # do a checkout of the file if it is part of this tree
         if ($wrev) {
             system('git-checkout-index', '-f', '-u', $filename);
             unless ($? == 0) {
@@ -1324,11 +1324,11 @@ sub req_ci
         exit;
     }
 
-       # Check that this is allowed, just as we would with a receive-pack
-       my @cmd = ( $ENV{GIT_DIR}.'hooks/update', "refs/heads/$state->{module}",
+       ### Emulate git-receive-pack by running hooks/update
+       my @hook = ( $ENV{GIT_DIR}.'hooks/update', "refs/heads/$state->{module}",
                        $parenthash, $commithash );
-       if( -x $cmd[0] ) {
-               unless( system( @cmd ) == 0 )
+       if( -x $hook[0] ) {
+               unless( system( @hook ) == 0 )
                {
                        $log->warn("Commit failed (update hook declined to update ref)");
                        print "error 1 Commit failed (update hook declined)\n";
@@ -1337,6 +1337,7 @@ sub req_ci
                }
        }
 
+       ### Update the ref
        if (system(qw(git update-ref -m), "cvsserver ci",
                        "refs/heads/$state->{module}", $commithash, $parenthash)) {
                $log->warn("update-ref for $state->{module} failed.");
@@ -1344,6 +1345,24 @@ sub req_ci
                exit;
        }
 
+       ### Emulate git-receive-pack by running hooks/post-receive
+       my $hook = $ENV{GIT_DIR}.'hooks/post-receive';
+       if( -x $hook ) {
+               open(my $pipe, "| $hook") || die "can't fork $!";
+
+               local $SIG{PIPE} = sub { die 'pipe broke' };
+
+               print $pipe "$parenthash $commithash refs/heads/$state->{module}\n";
+
+               close $pipe || die "bad pipe: $! $?";
+       }
+
+       ### Then hooks/post-update
+       $hook = $ENV{GIT_DIR}.'hooks/post-update';
+       if (-x $hook) {
+               system($hook, "refs/heads/$state->{module}");
+       }
+
     $updater->update();
 
     # foreach file specified on the command line ...
@@ -2524,13 +2543,20 @@ sub update
                     if ($parent eq $lastpicked) {
                         next;
                     }
-                    my $base = safe_pipe_capture('git-merge-base',
+                   my $base = eval {
+                           safe_pipe_capture('git-merge-base',
                                                 $lastpicked, $parent);
+                   };
+                   # The two branches may not be related at all,
+                   # in which case merge base simply fails to find
+                   # any, but that's Ok.
+                   next if ($@);
+
                     chomp $base;
                     if ($base) {
                         my @merged;
                         # print "want to log between  $base $parent \n";
-                        open(GITLOG, '-|', 'git-log', "$base..$parent")
+                        open(GITLOG, '-|', 'git-log', '--pretty=medium', "$base..$parent")
                          or die "Cannot call git-log: $!";
                         my $mergedhash;
                         while (<GITLOG>) {