Analizo/Command/tree_evolution.pm

filter: Statementstmt 51.0% 24 / 47 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 75.0% 3 / 4 totaltotal 54.5% 36 / 66 CC 4 SCAR 18.6
CC
4
Cov
47%
execute
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.4
« Analizo/Command.pm ↑ Summary Analizo/Model.pm »
1 package Analizo::Command::tree_evolution;
2 9 ▶use Analizo -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use parent qw(Analizo::Command);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Analizo::LanguageFilter;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 28 ▶sub command_names { qw/tree-evolution/ }
Subroutine command_names: called CC=1 SCAR=0.0
Pod documented
23  
24 2 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
25 return (
26 2 [ 'language|l=s', 'filters the source tree by language', { default => 'all' } ],
27 );
28 }
29  
30 0 ▶sub validate {}
Subroutine validate: not called CC=1 SCAR=0.0
Pod undocumented
31  
32 0 ▶sub execute {
Subroutine execute: not called CC=4 SCAR=30.0
Pod documented
33 0 my ($self, $opt, $args) = @_;
34 0 my $filter = Analizo::LanguageFilter->new($opt->language);
35 0 local $ENV{PATH} = '/usr/local/bin:/usr/bin:/bin';
36 0 open COMMITS, "git log --reverse --format=%H|";
37 0 my @commits = <COMMITS>;
38 0 chomp @commits;
39 0 close COMMITS;
40 0 my %trees = ();
41 0 for my $commit (@commits) {
42 0 my @tree = `git ls-tree -r --name-only $commit`;
43 0 chomp(@tree);
44 0 my %dirs = map { dirname($_) => 1 } (grep { $filter->matches($_) } @tree);
45 0 @tree = sort(grep { $_ ne '.' } keys(%dirs));
46 0 ▶ next unless (@tree);
Branch: 1 branch
BranchTrueFalseTotal
unless @tree 0 0 0
47 0 my $tree = join("\n", @tree);
48 0 my $sha1 = sha1_hex($tree);
49 0 ▶ if (!exists($trees{$sha1})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $trees{$sha1}) 0 0 0
50 0 print "# $commit\n";
51 0 print $tree, "\n";
52 0 $trees{$sha1} = 1;
53 }
54 }
55 }
56  
57 9 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
« Analizo/Command.pm ↑ Summary Analizo/Model.pm »