2011-02-21 20:22:56 +01:00
|
|
|
#!/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.
|
2014-01-20 21:47:54 +01:00
|
|
|
open F, "-|", "git", "log", "--no-merges", "--pretty=format:%H", $branches, "--", $fname
|
2011-02-21 20:22:56 +01:00
|
|
|
or die "$!";
|
|
|
|
my @changes = <F>;
|
|
|
|
return scalar @changes
|
|
|
|
}
|
|
|
|
|
|
|
|
my $look_for_type = "merged";
|
|
|
|
|
2011-04-29 21:26:19 +02:00
|
|
|
if (! @ARGV) {
|
|
|
|
print <<EOF
|
|
|
|
Usage:
|
2014-01-20 21:47:54 +01:00
|
|
|
findMergedChanges.pl [--merged/--unmerged/--weird/--list] [--branch=<branchname] [--head=<branchname>] changes/*
|
2011-04-29 21:26:19 +02:00
|
|
|
|
2013-04-19 17:14:06 +02:00
|
|
|
A change is "merged" if it has ever been merged to release-0.2.4 and it has had
|
2011-04-29 21:26:19 +02:00
|
|
|
no subsequent changes in master.
|
|
|
|
|
2013-04-19 17:14:06 +02:00
|
|
|
A change is "unmerged" if it has never been merged to release-0.2.4 and it
|
2011-04-29 21:26:19 +02:00
|
|
|
has had changes in master.
|
|
|
|
|
2013-04-19 17:14:06 +02:00
|
|
|
A change is "weird" if it has been merged to release-0.2.4 and it *has* had
|
2011-04-29 21:26:19 +02:00
|
|
|
subsequent changes in master.
|
|
|
|
|
|
|
|
Suggested application:
|
|
|
|
findMergedChanges.pl --merged changes/* | xargs -n 1 git rm
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2013-04-19 17:14:06 +02:00
|
|
|
my $target_branch = "origin/release-0.2.4";
|
2014-01-20 21:47:54 +01:00
|
|
|
my $head = "origin/master";
|
2011-07-18 18:43:39 +02:00
|
|
|
|
2011-02-21 20:22:56 +01:00
|
|
|
while (@ARGV and $ARGV[0] =~ /^--/) {
|
|
|
|
my $flag = shift @ARGV;
|
|
|
|
if ($flag =~ /^--(weird|merged|unmerged|list)/) {
|
|
|
|
$look_for_type = $1;
|
2011-07-18 18:43:39 +02:00
|
|
|
} elsif ($flag =~ /^--branch=(\S+)/) {
|
|
|
|
$target_branch = $1;
|
2014-01-20 21:47:54 +01:00
|
|
|
} elsif ($flag =~ /^--head=(\S+)/) {
|
|
|
|
$head = $1;
|
2011-02-21 20:22:56 +01:00
|
|
|
} else {
|
|
|
|
die "Unrecognized flag $flag";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for my $changefile (@ARGV) {
|
2011-07-18 18:43:39 +02:00
|
|
|
my $n_merged = nChanges($target_branch, $changefile);
|
2014-01-20 21:47:54 +01:00
|
|
|
my $n_postmerged = nChanges("${target_branch}..${head}", $changefile);
|
2011-02-21 20:22:56 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|