Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use 5.008;
  3. use strict;
  4. use Memoize;
  5.  
  6. # usage:
  7. # git-large-files 500k
  8. # git-large-files 0.5m
  9. # git-large-files 5b
  10.  
  11. sub usage { die "usage: git-large-files <size[b|k|m]> [<git-log arguments ...>]\n" }
  12.  
  13. @ARGV or usage();
  14. my ( $max_size, $unit ) = ( shift =~ /^(\d+)([bkm]?)\z/ ) ? ( $1, $2 ) : usage();
  15.  
  16. my $exp = 10 * ( $unit eq 'b' ? 0 : $unit eq 'k' ? 1 : 2 );
  17. my $cutoff = $max_size * 2**$exp;
  18.  
  19. sub walk_tree {
  20. my ( $tree, @path ) = @_;
  21. my @subtree;
  22. my @r;
  23.  
  24. {
  25. open my $ls_tree, '-|', git => 'ls-tree' => -l => $tree
  26. or die "Couldn't open pipe to git-ls-tree: $!\n";
  27.  
  28. while ( <$ls_tree> ) {
  29. my ( $type, $sha1, $size, $name ) = /\A[0-7]{6} (\S+) (\S+) +(\S+)\t(.*)/;
  30. if ( $type eq 'tree' ) {
  31. push @subtree, [ $sha1, $name ];
  32. }
  33. elsif ( $type eq 'blob' and $size >= $cutoff ) {
  34. push @r, [ $size, @path, $name ];
  35. }
  36. }
  37. }
  38.  
  39. push @r, walk_tree( $_->[0], @path, $_->[1] )
  40. for @subtree;
  41.  
  42. return @r;
  43. }
  44.  
  45. memoize 'walk_tree';
  46.  
  47. open my $log, '-|', git => log => @ARGV, '--pretty=format:%T %h %cr'
  48. or die "Couldn't open pipe to git-log: $!\n";
  49.  
  50. my %seen;
  51. while ( <$log> ) {
  52. chomp;
  53. my ( $tree, $commit, $age ) = split " ", $_, 3;
  54. my $is_header_printed;
  55. for ( walk_tree( $tree ) ) {
  56. my ( $size, @path ) = @$_;
  57. my $path = join '/', @path;
  58. next if $seen{ $path }++;
  59. print "$commit $age\n" if not $is_header_printed++;
  60. print "\t$size\t$path\n";
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement