Apply a patch from Gisle Vanem to make tor-gencert build under MSVC
[tor/neena.git] / contrib / findMergedChanges.pl
blob46e070f943e8e1f8a1142c511bfb0bcc098a92fb
1 #!/usr/bin/perl
3 use warnings;
4 use strict;
6 sub nChanges {
7 my ($branches, $fname) = @_;
8 local *F;
9 # requires perl 5.8. Avoids shell issues if we ever get a changes
10 # file named by the parents of Little Johnny Tables.
11 open F, "-|", "git", "log", "--pretty=format:%H", $branches, "--", $fname
12 or die "$!";
13 my @changes = <F>;
14 return scalar @changes
17 my $look_for_type = "merged";
19 if (! @ARGV) {
20 print <<EOF
21 Usage:
22 findMergedChanges.pl [--merged/--unmerged/--weird/--list] changes/*
24 A change is "merged" if it has ever been merged to release-0.2.2 and it has had
25 no subsequent changes in master.
27 A change is "unmerged" if it has never been merged to release-0.2.2 and it
28 has had changes in master.
30 A change is "weird" if it has been merged to release-0.2.2 and it *has* had
31 subsequent changes in master.
33 Suggested application:
34 findMergedChanges.pl --merged changes/* | xargs -n 1 git rm
36 EOF
39 my $target_branch = "origin/release-0.2.2";
41 while (@ARGV and $ARGV[0] =~ /^--/) {
42 my $flag = shift @ARGV;
43 if ($flag =~ /^--(weird|merged|unmerged|list)/) {
44 $look_for_type = $1;
45 } elsif ($flag =~ /^--branch=(\S+)/) {
46 $target_branch = $1;
47 } else {
48 die "Unrecognized flag $flag";
52 for my $changefile (@ARGV) {
53 my $n_merged = nChanges($target_branch, $changefile);
54 my $n_postmerged = nChanges("${target_branch}..origin/master", $changefile);
55 my $type;
57 if ($n_merged != 0 and $n_postmerged == 0) {
58 $type = "merged";
59 } elsif ($n_merged == 0 and $n_postmerged != 0) {
60 $type = "unmerged";
61 } else {
62 $type = "weird";
65 if ($type eq $look_for_type) {
66 print "$changefile\n";
67 } elsif ($look_for_type eq 'list') {
68 printf "% 8s: %s\n", $type, $changefile;