Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 59 lines (49 sloc) 1.741 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/env perl
use strict;
use warnings;

use Cwd qw(realpath);
use File::Basename;
my $BASE_DIR = dirname realpath __FILE__;
chomp (my $GIT_DIR = `git rev-parse --git-dir`);

my $simplified_merges = do "$BASE_DIR/cache/simplified-merges.pl";

{
    my @merges = `git log --all --merges --pretty=format:'%H %P'`;
    my %altered;
    my %merges;
    for my $merge ( reverse @merges ) {
        chomp $merge;
        my ($commit, @parents) = split / /, $merge;
        my $f;
        $merges{$commit} = \@parents;
        PARENT: for my $p ( 0 .. 1 ) {
            my $parent = $parents[ $p ];
            my $check_ancest = $parents[ 1 - $p ];
            my $ancest = $merges{ $check_ancest } || next;

            ANCEST: for my $c ( 0 .. 1 ) {
                if ($parent eq $ancest->[ $c ]) {
                    $altered{$commit}++;
                    $parents[1 - $p] = $ancest->[1 - $c];
                    delete $merges{ $check_ancest };
                    delete $altered{ $check_ancest };
                    last PARENT;
                }
            }
        }
    }

    my $regex = '(?:' . (join '|', keys %altered) . ')';
    system "perl -i -pe's/^($regex )/# \$1/' $GIT_DIR/info/grafts";

    open my $fh, '>>', "$GIT_DIR/info/grafts";
    print { $fh } "# Redundant merges\n";
    for my $commit ( keys %altered ) {
        print { $fh } join(q{ }, $commit, @{ $merges{$commit} }) . "\n";
    }
    close $fh;

    use Data::Dumper;
    $Data::Dumper::Indent = 1;
    $Data::Dumper::Terse = 1;
    $Data::Dumper::Sortkeys = 1;

    @altered{ keys %$simplified_merges } = values %$simplified_merges;
    open $fh, '>', "$BASE_DIR/cache/simplified-merges.pl";
    print { $fh } Dumper(\%altered);
    close $fh;
}

Something went wrong with that request. Please try again.