Makefile: Set USE_PIC on x86-64
[gitweb.git] / git-fmt-merge-msg.perl
index c34ddc5d5ec1b14ceb80fd699ad6b7c96e3f6b4c..1b23fa150b7dd8af9850af71382e78c1a21c7321 100755 (executable)
@@ -5,7 +5,12 @@
 # Read .git/FETCH_HEAD and make a human readable merge message
 # by grouping branches and tags together to form a single line.
 
+BEGIN { unshift @INC, '@@INSTLIBDIR@@'; }
 use strict;
+use Git;
+use Error qw(:try);
+
+my $repo = Git->repository();
 
 my @src;
 my %src;
@@ -28,43 +33,38 @@ sub andjoin {
 }
 
 sub repoconfig {
-       my $fh;
        my $val;
-       eval {
-               open $fh, '-|', 'git-repo-config', '--get', 'merge.summary'
-                   or die "$!";
-               ($val) = <$fh>;
-               close $fh;
+       try {
+               $val = $repo->command_oneline('repo-config', '--get', 'merge.summary');
+       } catch Git::Error::Command with {
+               my ($E) = shift;
+               if ($E->value() == 1) {
+                       return undef;
+               } else {
+                       throw $E;
+               }
        };
        return $val;
 }
 
 sub current_branch {
-       my $fh;
-       open $fh, '-|', 'git-symbolic-ref', 'HEAD' or die "$!";
-       my ($bra) = <$fh>;
-       chomp($bra);
+       my ($bra) = $repo->command_oneline('symbolic-ref', 'HEAD');
        $bra =~ s|^refs/heads/||;
        if ($bra ne 'master') {
                $bra = " into $bra";
        } else {
                $bra = "";
        }
-
        return $bra;
 }
 
 sub shortlog {
-       my ($tip, $limit) = @_;
-       my ($fh, @result);
-       open $fh, '-|', ('git-log', "--max-count=$limit", '--topo-order',
-                        '--pretty=oneline', $tip, '^HEAD')
-           or die "$!";
-       while (<$fh>) {
+       my ($tip) = @_;
+       my @result;
+       foreach ($repo->command('log', '--no-merges', '--topo-order', '--pretty=oneline', $tip, '^HEAD')) {
                s/^[0-9a-f]{40}\s+//;
                push @result, $_;
        }
-       close $fh or die "$!";
        return @result;
 }
 
@@ -88,6 +88,7 @@ sub shortlog {
                $src{$src} = {
                        BRANCH => [],
                        TAG => [],
+                       R_BRANCH => [],
                        GENERIC => [],
                        # &1 == has HEAD.
                        # &2 == has others.
@@ -104,6 +105,11 @@ sub shortlog {
                push @{$src{$src}{TAG}}, $1;
                $src{$src}{HEAD_STATUS} |= 2;
        }
+       elsif (/^remote branch (.*)$/) {
+               $origin = $1;
+               push @{$src{$src}{R_BRANCH}}, $1;
+               $src{$src}{HEAD_STATUS} |= 2;
+       }
        elsif (/^HEAD$/) {
                $origin = $src;
                $src{$src}{HEAD_STATUS} |= 1;
@@ -136,6 +142,8 @@ sub shortlog {
        }
        push @this, andjoin("branch ", "branches ",
                           $src{$src}{BRANCH});
+       push @this, andjoin("remote branch ", "remote branches ",
+                          $src{$src}{R_BRANCH});
        push @this, andjoin("tag ", "tags ",
                           $src{$src}{TAG});
        push @this, andjoin("commit ", "commits ",
@@ -160,7 +168,7 @@ sub shortlog {
 
 for (@origin) {
        my ($sha1, $name) = @$_;
-       my @log = shortlog($sha1, $limit + 1);
+       my @log = shortlog($sha1);
        if ($limit + 1 <= @log) {
                print "\n* $name: (" . scalar(@log) . " commits)\n";
        }
@@ -173,6 +181,6 @@ sub shortlog {
                        print "  ...\n";
                        last;
                }
-               print "  $log";
+               print "  $log\n";
        }
 }