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
|
2021-05-25 13:33:58 +02:00
|
|
|
or die "$!";
|
2011-02-21 20:22:56 +01:00
|
|
|
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
|
2021-05-25 13:33:58 +02:00
|
|
|
no subsequent changes in main.
|
2011-04-29 21:26:19 +02:00
|
|
|
|
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
|
2021-05-25 13:33:58 +02:00
|
|
|
has had changes in main.
|
2011-04-29 21:26:19 +02:00
|
|
|
|
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
|
2021-05-25 13:33:58 +02:00
|
|
|
subsequent changes in main.
|
2011-04-29 21:26:19 +02:00
|
|
|
|
|
|
|
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";
|
2021-05-25 13:33:58 +02:00
|
|
|
my $head = "origin/main";
|
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)/) {
|
2021-05-25 13:33:58 +02:00
|
|
|
$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 {
|
2021-05-25 13:33:58 +02:00
|
|
|
die "Unrecognized flag $flag";
|
2011-02-21 20:22:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2021-05-25 13:33:58 +02:00
|
|
|
$type = "merged";
|
2011-02-21 20:22:56 +01:00
|
|
|
} elsif ($n_merged == 0 and $n_postmerged != 0) {
|
2021-05-25 13:33:58 +02:00
|
|
|
$type = "unmerged";
|
2011-02-21 20:22:56 +01:00
|
|
|
} else {
|
2021-05-25 13:33:58 +02:00
|
|
|
$type = "weird";
|
2011-02-21 20:22:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($type eq $look_for_type) {
|
2021-05-25 13:33:58 +02:00
|
|
|
print "$changefile\n";
|
2011-02-21 20:22:56 +01:00
|
|
|
} elsif ($look_for_type eq 'list') {
|
2021-05-25 13:33:58 +02:00
|
|
|
printf "% 8s: %s\n", $type, $changefile;
|
2011-02-21 20:22:56 +01:00
|
|
|
}
|
|
|
|
}
|