findMergedChanges.pl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. sub nChanges {
  5. my ($branches, $fname) = @_;
  6. local *F;
  7. # requires perl 5.8. Avoids shell issues if we ever get a changes
  8. # file named by the parents of Little Johnny Tables.
  9. open F, "-|", "git", "log", "--pretty=format:%H", $branches, "--", $fname
  10. or die "$!";
  11. my @changes = <F>;
  12. return scalar @changes
  13. }
  14. my $look_for_type = "merged";
  15. if (! @ARGV) {
  16. print <<EOF
  17. Usage:
  18. findMergedChanges.pl [--merged/--unmerged/--weird/--list] changes/*
  19. A change is "merged" if it has ever been merged to release-0.2.2 and it has had
  20. no subsequent changes in master.
  21. A change is "unmerged" if it has never been merged to release-0.2.2 and it
  22. has had changes in master.
  23. A change is "weird" if it has been merged to release-0.2.2 and it *has* had
  24. subsequent changes in master.
  25. Suggested application:
  26. findMergedChanges.pl --merged changes/* | xargs -n 1 git rm
  27. EOF
  28. }
  29. while (@ARGV and $ARGV[0] =~ /^--/) {
  30. my $flag = shift @ARGV;
  31. if ($flag =~ /^--(weird|merged|unmerged|list)/) {
  32. $look_for_type = $1;
  33. } else {
  34. die "Unrecognized flag $flag";
  35. }
  36. }
  37. for my $changefile (@ARGV) {
  38. my $n_merged = nChanges("origin/release-0.2.2", $changefile);
  39. my $n_postmerged = nChanges("origin/release-0.2.2..origin/master", $changefile);
  40. my $type;
  41. if ($n_merged != 0 and $n_postmerged == 0) {
  42. $type = "merged";
  43. } elsif ($n_merged == 0 and $n_postmerged != 0) {
  44. $type = "unmerged";
  45. } else {
  46. $type = "weird";
  47. }
  48. if ($type eq $look_for_type) {
  49. print "$changefile\n";
  50. } elsif ($look_for_type eq 'list') {
  51. printf "% 8s: %s\n", $type, $changefile;
  52. }
  53. }