| 1 |
package Analizo::Command::tree_evolution; |
| 2 |
use Analizo -command; |
| 3 |
use parent qw(Analizo::Command); |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
use Digest::SHA qw(sha1_hex); |
| 7 |
use File::Basename; |
| 8 |
use Analizo::LanguageFilter; |
| 9 |
|
| 10 |
#ABSTRACT: watch the evolution of the source code |
| 11 |
|
| 12 |
=head1 NAME |
| 13 |
|
| 14 |
analizo-tree-evolution - watch the evolution of the source code |
| 15 |
|
| 16 |
=head1 USAGE |
| 17 |
|
| 18 |
analizo tree-evolution [OPTIONS] |
| 19 |
|
| 20 |
=cut |
| 21 |
|
| 22 |
sub command_names { qw/tree-evolution/ } |
| 23 |
|
| 24 |
sub opt_spec { |
| 25 |
return ( |
| 26 |
[ 'language|l=s', 'filters the source tree by language', { default => 'all' } ], |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
sub validate {} |
| 31 |
|
| 32 |
sub execute { |
| 33 |
my ($self, $opt, $args) = @_; |
| 34 |
my $filter = Analizo::LanguageFilter->new($opt->language); |
| 35 |
local $ENV{PATH} = '/usr/local/bin:/usr/bin:/bin'; |
| 36 |
open COMMITS, "git log --reverse --format=%H|"; |
| 37 |
my @commits = <COMMITS>; |
| 38 |
chomp @commits; |
| 39 |
close COMMITS; |
| 40 |
my %trees = (); |
| 41 |
for my $commit (@commits) { |
| 42 |
my @tree = `git ls-tree -r --name-only $commit`; |
| 43 |
chomp(@tree); |
| 44 |
my %dirs = map { dirname($_) => 1 } (grep { $filter->matches($_) } @tree); |
| 45 |
@tree = sort(grep { $_ ne '.' } keys(%dirs)); |
| 46 |
next unless (@tree); |
| 47 |
my $tree = join("\n", @tree); |
| 48 |
my $sha1 = sha1_hex($tree); |
| 49 |
if (!exists($trees{$sha1})) { |
| 50 |
print "# $commit\n"; |
| 51 |
print $tree, "\n"; |
| 52 |
$trees{$sha1} = 1; |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
1; |
| 58 |
|
| 59 |
=head1 DESCRIPTION |
| 60 |
|
| 61 |
Watch the evolution of the source code tree in a Git repository. |
| 62 |
|
| 63 |
When run inside a Git repository, B<analizo tree-evolution> will output all |
| 64 |
different sets of directories found in the project's history. For each commit |
| 65 |
in which a new directory was added or removed, you will have the commit hash |
| 66 |
and a snapshot of the source code tree at that commit. |
| 67 |
|
| 68 |
For example, consider the following sample execution of B<analizo |
| 69 |
tree-evolution> against a sample Git repository: |
| 70 |
|
| 71 |
$ analizo tree-evolution |
| 72 |
# 073290fbad0254793bd3ecfb97654c04368d0039 |
| 73 |
src |
| 74 |
# 85f7db08f7b7b0b62e3c0023b2743d529b0d5b4b |
| 75 |
src |
| 76 |
src/input |
| 77 |
# f41cf7d0351e812285efd60c6d957c330b1f61a1 |
| 78 |
src |
| 79 |
src/input |
| 80 |
src/output |
| 81 |
|
| 82 |
The output shows us the following information: |
| 83 |
|
| 84 |
=over |
| 85 |
|
| 86 |
=item |
| 87 |
|
| 88 |
Commit I<073290fbad0254793bd3ecfb97654c04368d0039> was the first commit in the |
| 89 |
project, and back then the project had a "src" directory. |
| 90 |
|
| 91 |
=item |
| 92 |
|
| 93 |
In commit I<85f7db08f7b7b0b62e3c0023b2743d529b0d5b4b>, a directory called |
| 94 |
src/input was added to the tree. |
| 95 |
|
| 96 |
=item |
| 97 |
|
| 98 |
Finally, commit I<f41cf7d0351e812285efd60c6d957c330b1f61a1> introduced another |
| 99 |
directory called src/output. |
| 100 |
|
| 101 |
=back |
| 102 |
|
| 103 |
analizo tree-evolution is part of the analizo suite. |
| 104 |
|
| 105 |
=head1 OPTIONS |
| 106 |
|
| 107 |
=over |
| 108 |
|
| 109 |
=item --language LANGUAGE, -l LANGUAGE |
| 110 |
|
| 111 |
Filters the source tree by language. When determining the contents of the |
| 112 |
source tree, only consider directories that contain files that match the |
| 113 |
expected file extensions for LANGUAGE. |
| 114 |
|
| 115 |
LANGUAGE can be one of I<c>, I<cpp> and I<java>. The default behaviour is to |
| 116 |
consider all files in the repository. |
| 117 |
|
| 118 |
=back |
| 119 |
|
| 120 |
=head1 COPYRIGHT AND AUTHORS |
| 121 |
|
| 122 |
See B<analizo(1)>. |
| 123 |
|
| 124 |
=cut |