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 55 lines (46 sloc) 1.734 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
#!/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;
        $merges{$commit} = \@parents;
        my ( $left_parent, $right_parent ) = @parents;
        # first parent is a merge
        if ( my $left_grandparents = $merges{ $left_parent } ) {
            my $right_grandparent = `git show -s --pretty='format:%P' $right_parent | cut -d' ' -f1`;
            chomp $right_grandparent;
            if ($right_grandparent eq $left_grandparents->[1]) {
                $altered{$commit}++;
                $parents[0] = $left_grandparents->[0];
                delete $merges{ $left_parent };
                delete $altered{ $left_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 } "# Simplified 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.