code_junkie

Git: Find duplicate blobs (files) in this tree

Nov 11th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # usage: git ls-tree -r HEAD | $PROGRAM_NAME
  4.  
  5. use strict;
  6. use warnings;
  7.  
  8. my $sha1_path = {};
  9.  
  10. while (my $line = <STDIN>) {
  11. chomp $line;
  12.  
  13. if ($line =~ m{ A d+ s+ w+ s+ (w+) s+ (S+) z }xms) {
  14. my $sha1 = $1;
  15. my $path = $2;
  16.  
  17. push @{$sha1_path->{$sha1}}, $path;
  18. }
  19. }
  20.  
  21. foreach my $sha1 (keys %$sha1_path) {
  22. if (scalar @{$sha1_path->{$sha1}} > 1) {
  23. foreach my $path (@{$sha1_path->{$sha1}}) {
  24. print "$sha1 $pathn";
  25. }
  26.  
  27. print '-' x 40, "n";
  28. }
  29. }
  30.  
  31. git ls-tree -r HEAD |
  32. sort -t ' ' -k 3 |
  33. perl -ne '$1 && / $1t/ && print "e[0;31m" ; / ([0-9a-f]{40})t/; print "$_e[0m"'
  34.  
  35. git ls-tree -r HEAD
Add Comment
Please, Sign In to add comment