Only terminate PT processes that are running.
[tor.git] / scripts / maint / findMergedChanges.pl
blob427f2b111dcdfaa9c3df94e84a632bca7d8530ec
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", "--no-merges", "--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] [--branch=<branchname] [--head=<branchname>] changes/*
24 A change is "merged" if it has ever been merged to release-0.2.4 and it has had
25 no subsequent changes in main.
27 A change is "unmerged" if it has never been merged to release-0.2.4 and it
28 has had changes in main.
30 A change is "weird" if it has been merged to release-0.2.4 and it *has* had
31 subsequent changes in main.
33 Suggested application:
34 findMergedChanges.pl --merged changes/* | xargs -n 1 git rm
36 EOF
39 my $target_branch = "origin/release-0.2.4";
40 my $head = "origin/main";
42 while (@ARGV and $ARGV[0] =~ /^--/) {
43 my $flag = shift @ARGV;
44 if ($flag =~ /^--(weird|merged|unmerged|list)/) {
45 $look_for_type = $1;
46 } elsif ($flag =~ /^--branch=(\S+)/) {
47 $target_branch = $1;
48 } elsif ($flag =~ /^--head=(\S+)/) {
49 $head = $1;
50 } else {
51 die "Unrecognized flag $flag";
55 for my $changefile (@ARGV) {
56 my $n_merged = nChanges($target_branch, $changefile);
57 my $n_postmerged = nChanges("${target_branch}..${head}", $changefile);
58 my $type;
60 if ($n_merged != 0 and $n_postmerged == 0) {
61 $type = "merged";
62 } elsif ($n_merged == 0 and $n_postmerged != 0) {
63 $type = "unmerged";
64 } else {
65 $type = "weird";
68 if ($type eq $look_for_type) {
69 print "$changefile\n";
70 } elsif ($look_for_type eq 'list') {
71 printf "% 8s: %s\n", $type, $changefile;