aboutsummaryrefslogtreecommitdiff
path: root/contrib/findMergedChanges.pl
blob: 460424f309a2597fe304226661371d0aa769664a (plain)
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
59
60
61
62
63
64
65
66
#!/usr/bin/perl

use warnings;
use strict;

sub nChanges {
    my ($branches, $fname) = @_;
    local *F;
    # requires perl 5.8.  Avoids shell issues if we ever get a changes
    # file named by the parents of Little Johnny Tables.
    open F, "-|", "git", "log", "--pretty=format:%H", $branches, "--", $fname
	or die "$!";
    my @changes = <F>;
    return scalar @changes
}

my $look_for_type = "merged";

if (! @ARGV) {
    print <<EOF
Usage:
   findMergedChanges.pl [--merged/--unmerged/--weird/--list] changes/*

A change is "merged" if it has ever been merged to release-0.2.2 and it has had
no subsequent changes in master.

A change is "unmerged" if it has never been merged to release-0.2.2 and it
has had changes in master.

A change is "weird" if it has been merged to release-0.2.2 and it *has* had
subsequent changes in master.

Suggested application:
   findMergedChanges.pl --merged changes/* | xargs -n 1 git rm

EOF
}

while (@ARGV and $ARGV[0] =~ /^--/) {
    my $flag = shift @ARGV;
    if ($flag =~ /^--(weird|merged|unmerged|list)/) {
	$look_for_type = $1;
    } else {
	die "Unrecognized flag $flag";
    }
}

for my $changefile (@ARGV) {
    my $n_merged = nChanges("origin/release-0.2.2", $changefile);
    my $n_postmerged = nChanges("origin/release-0.2.2..origin/master", $changefile);
    my $type;

    if ($n_merged != 0 and $n_postmerged == 0) {
	$type = "merged";
    } elsif ($n_merged == 0 and $n_postmerged != 0) {
	$type = "unmerged";
    } else {
	$type = "weird";
    }

    if ($type eq $look_for_type) {
	print "$changefile\n";
    } elsif ($look_for_type eq 'list') {
	printf "% 8s: %s\n", $type, $changefile;
    }
}