| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | # Created on: 2014-03-11 20:58:59 | 
| 3 |  |  |  |  |  |  | # Create by:  Ivan Wills | 
| 4 |  |  |  |  |  |  | # $Id$ | 
| 5 |  |  |  |  |  |  | # $Revision$, $HeadURL$, $Date$ | 
| 6 |  |  |  |  |  |  | # $Revision$, $Source$, $Date$ | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | use strict; | 
| 9 | 2 |  |  | 2 |  | 92069 | use warnings; | 
|  | 2 |  |  |  |  | 14 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 10 | 2 |  |  | 2 |  | 10 | use version; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 59 |  | 
| 11 | 2 |  |  | 2 |  | 409 | use English qw/ -no_match_vars /; | 
|  | 2 |  |  |  |  | 1632 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 12 | 2 |  |  | 2 |  | 644 | use App::Git::Workflow; | 
|  | 2 |  |  |  |  | 3054 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 13 | 2 |  |  | 2 |  | 1173 | use App::Git::Workflow::Command qw/get_options/; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 141 |  | 
| 14 | 2 |  |  | 2 |  | 550 |  | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 1953 |  | 
| 15 |  |  |  |  |  |  | our $VERSION = version->new(1.1.19); | 
| 16 |  |  |  |  |  |  | our $workflow = App::Git::Workflow->new; | 
| 17 |  |  |  |  |  |  | my ($name)   = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs; | 
| 18 |  |  |  |  |  |  | our %option; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | %option = ( | 
| 21 |  |  |  |  |  |  | age => 28, | 
| 22 | 8 |  |  | 8 | 1 | 30 | ); | 
| 23 |  |  |  |  |  |  | get_options( | 
| 24 |  |  |  |  |  |  | \%option, | 
| 25 | 8 | 100 |  |  |  | 44 | 'since|s=s', | 
| 26 |  |  |  |  |  |  | 'age|a=i', | 
| 27 |  |  |  |  |  |  | 'tag|t=s', | 
| 28 |  |  |  |  |  |  | 'branch|b=s', | 
| 29 |  |  |  |  |  |  | 'local|l', | 
| 30 |  |  |  |  |  |  | 'max_history|max-history|m=i', | 
| 31 |  |  |  |  |  |  | ) or return; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # do stuff here | 
| 34 |  |  |  |  |  |  | $workflow->{VERBOSE} = $option{verbose}; | 
| 35 |  |  |  |  |  |  | $workflow->{TEST   } = $option{test}; | 
| 36 | 7 |  |  |  |  | 23 |  | 
| 37 | 7 |  |  |  |  | 20 | my $action = @ARGV && __PACKAGE__->can("do_$ARGV[0]") ? 'do_' . shift @ARGV : 'do_changed'; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 7 | 100 | 100 |  |  | 75 | my ($release) = $workflow->releases(%option); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 7 |  |  |  |  | 43 | return __PACKAGE__->$action($release, @ARGV); | 
| 42 |  |  |  |  |  |  | } | 
| 43 | 7 |  |  |  |  | 40 |  | 
| 44 |  |  |  |  |  |  | my (undef, $release) = @_; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # get local branch changed files vs prod | 
| 47 | 5 |  |  | 5 | 1 | 14 | my @local_files = map {/(.*)$/; $1} $workflow->git->diff('--name-only', $release->{name}); | 
| 48 |  |  |  |  |  |  | my $all_files   = files_changed(); | 
| 49 |  |  |  |  |  |  | my ($type, $name) = $workflow->current(); | 
| 50 | 5 |  |  |  |  | 13 | my %files; | 
|  | 10 |  |  |  |  | 26 |  | 
|  | 10 |  |  |  |  | 73 |  | 
| 51 | 5 |  |  |  |  | 22 |  | 
| 52 | 5 |  |  |  |  | 26 | # iterate over all locally changed files | 
| 53 | 5 |  |  |  |  | 15 | for my $file (@local_files) { | 
| 54 |  |  |  |  |  |  | warn "$file\n" if $option{verbose}; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 5 |  |  |  |  | 13 | # check that it has been modified in recent times | 
| 57 | 10 | 100 |  |  |  | 147 | if ($all_files->{$file}) { | 
| 58 |  |  |  |  |  |  | # iterate over each commit id to eliminate them from the current branch | 
| 59 |  |  |  |  |  |  | for my $sha (@{ $all_files->{$file}{sha} }) { | 
| 60 | 10 | 100 |  |  |  | 39 | warn "    $sha\n" if $option{verbose} && $option{verbose} > 1; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 8 |  |  |  |  | 12 | # get a list of branches that the file changed on (apart from the current) | 
|  | 8 |  |  |  |  | 24 |  | 
| 63 | 16 | 100 | 100 |  |  | 98 | my @branches = | 
| 64 |  |  |  |  |  |  | grep {$_ ne $name} | 
| 65 |  |  |  |  |  |  | map {m{ ([^/\s]*) $}xms; $1} | 
| 66 |  |  |  |  |  |  | $workflow->git->branch(qw/-a --contains/, $sha); | 
| 67 | 30 |  |  |  |  | 64 |  | 
| 68 | 16 |  |  |  |  | 53 | next if !@branches; | 
|  | 30 |  |  |  |  | 108 |  | 
|  | 30 |  |  |  |  | 74 |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | my $show = $workflow->git->show($sha); | 
| 71 | 16 | 100 |  |  |  | 37 | my ($author) = $show =~ /^Author: \s+ (.*?) \s+ </xms; | 
| 72 |  |  |  |  |  |  | push @{ $files{$file}{branches} }, @branches; | 
| 73 | 15 |  |  |  |  | 34 | push @{ $files{$file}{authors} }, $author; | 
| 74 | 15 |  |  |  |  | 77 | } | 
| 75 | 15 |  |  |  |  | 18 | } | 
|  | 15 |  |  |  |  | 45 |  | 
| 76 | 15 |  |  |  |  | 21 | } | 
|  | 15 |  |  |  |  | 46 |  | 
| 77 |  |  |  |  |  |  | for my $file (sort keys %files) { | 
| 78 |  |  |  |  |  |  | my %branches = map { $_ => 1 } @{ $files{$file}{branches} }; | 
| 79 |  |  |  |  |  |  | my %authors = map { $_ => 1 } @{ $files{$file}{authors} }; | 
| 80 | 5 |  |  |  |  | 31 | print "$file\n"; | 
| 81 | 8 |  |  |  |  | 15 | print "    Modified in : " . (join ', ', sort keys %branches) . "\n"; | 
|  | 30 |  |  |  |  | 59 |  | 
|  | 8 |  |  |  |  | 21 |  | 
| 82 | 8 |  |  |  |  | 15 | print "             by : " . (join ', ', sort keys %authors) . "\n"; | 
|  | 15 |  |  |  |  | 29 |  | 
|  | 8 |  |  |  |  | 15 |  | 
| 83 | 8 |  |  |  |  | 226 | } | 
| 84 | 8 |  |  |  |  | 158 | } | 
| 85 | 8 |  |  |  |  | 149 |  | 
| 86 |  |  |  |  |  |  | my $files = files_changed(); | 
| 87 |  |  |  |  |  |  | print | 
| 88 |  |  |  |  |  |  | map  { sprintf "%4d %s\n", $files->{$_}{count}, $_ } | 
| 89 |  |  |  |  |  |  | sort { $files->{$a}{count} <=> $files->{$b}{count} || $a cmp $b } | 
| 90 | 2 |  |  | 2 | 1 | 8 | keys %$files; | 
| 91 |  |  |  |  |  |  | } | 
| 92 | 4 |  |  |  |  | 171 |  | 
| 93 | 2 | 50 |  |  |  | 9 | my $args = $option{since} ? "--since=$option{since}" : "--max-age=" . ( time - 60 * 60 * 24 * $option{age} ); | 
|  | 2 |  |  |  |  | 11 |  | 
| 94 |  |  |  |  |  |  | my @commits = $workflow->git->rev_list('--all', $args); | 
| 95 |  |  |  |  |  |  | my %files; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | for my $id (@commits) { | 
| 98 | 7 | 100 |  | 7 | 1 | 41 | chomp $id; | 
| 99 | 7 |  |  |  |  | 24 | my (undef, @files) = $workflow->git->show(qw/--name-only --oneline/, $id); | 
| 100 | 7 |  |  |  |  | 13 | for my $file (@files) { | 
| 101 |  |  |  |  |  |  | chomp $file; | 
| 102 | 7 |  |  |  |  | 19 | $files{$file}{count}++; | 
| 103 | 23 |  |  |  |  | 37 | push @{ $files{$file}{sha} }, $id; | 
| 104 | 23 |  |  |  |  | 54 | } | 
| 105 | 23 |  |  |  |  | 43 | } | 
| 106 | 23 |  |  |  |  | 30 |  | 
| 107 | 23 |  |  |  |  | 51 | return \%files; | 
| 108 | 23 |  |  |  |  | 28 | } | 
|  | 23 |  |  |  |  | 60 |  | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | 1; | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 7 |  |  |  |  | 25 |  | 
| 113 |  |  |  |  |  |  | =head1 NAME | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | git-files - Get information on files changed across branches. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head1 VERSION | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | This documentation refers to git-files version 1.1.19 | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | git-files [changed] [(-s|--age) days] [(-s|--since) YYYY-MM-DD] [-v|--verbose] | 
| 124 |  |  |  |  |  |  | git-files local [(-s|--age) days] [(-s|--since) YYYY-MM-DD] [-v|--verbose] | 
| 125 |  |  |  |  |  |  | git-files set [-v|--verbose] | 
| 126 |  |  |  |  |  |  | git-files | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | SUB COMMANDS: | 
| 129 |  |  |  |  |  |  | changed       Files that have changed | 
| 130 |  |  |  |  |  |  | local         See if any locally (to the branch) modified files have been | 
| 131 |  |  |  |  |  |  | modified in other branches. | 
| 132 |  |  |  |  |  |  | set           Sets files modified time to the date they were last committed. | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | OPTIONS: | 
| 135 |  |  |  |  |  |  | -a --age[=]days | 
| 136 |  |  |  |  |  |  | Age in days to look changed files | 
| 137 |  |  |  |  |  |  | -s --since[=]YYYY-MM-DDTHH::MM | 
| 138 |  |  |  |  |  |  | Files changed since date | 
| 139 |  |  |  |  |  |  | -t --tag[=]tag | 
| 140 |  |  |  |  |  |  | Tag to use to define a release | 
| 141 |  |  |  |  |  |  | -b --branch[=]branch | 
| 142 |  |  |  |  |  |  | Branch to use to define a release | 
| 143 |  |  |  |  |  |  | -l --local | 
| 144 |  |  |  |  |  |  | Use master as release | 
| 145 |  |  |  |  |  |  | -m --max-history[=]int | 
| 146 |  |  |  |  |  |  | Limit getting release history to this number of commits | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | -v --verbose  Show more detailed option | 
| 149 |  |  |  |  |  |  | --version  Prints the version information | 
| 150 |  |  |  |  |  |  | --help     Prints this help information | 
| 151 |  |  |  |  |  |  | --man      Prints the full documentation for git-files | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | The C<git-files> command helps to find out which files are being actively | 
| 156 |  |  |  |  |  |  | changed by whom and where those files changes are occurring. The aim is to | 
| 157 |  |  |  |  |  |  | help developers see if other developers are working on the same files. This | 
| 158 |  |  |  |  |  |  | should reduce the potential for conflicts later on (or at least start the | 
| 159 |  |  |  |  |  |  | process to resolve those conflicts). | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =head1 SUBROUTINES/METHODS | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =head2 C<run ()> | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | Executes the git workflow command | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =head2 C<do_local ($release)> | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =head2 C<do_changed ()> | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | =head2 C<files_changed ()> | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =head1 DIAGNOSTICS | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =head1 CONFIGURATION AND ENVIRONMENT | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =head1 DEPENDENCIES | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =head1 INCOMPATIBILITIES | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =head1 BUGS AND LIMITATIONS | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | There are no known bugs in this module. | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Please report problems to Ivan Wills (ivan.wills@gmail.com). | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | Patches are welcome. | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =head1 AUTHOR | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | Ivan Wills - (ivan.wills@gmail.com) | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | 
| 196 |  |  |  |  |  |  | All rights reserved. | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | This module is free software; you can redistribute it and/or modify it under | 
| 199 |  |  |  |  |  |  | the same terms as Perl itself. See L<perlartistic>.  This program is | 
| 200 |  |  |  |  |  |  | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | 
| 201 |  |  |  |  |  |  | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | 
| 202 |  |  |  |  |  |  | PARTICULAR PURPOSE. | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | =cut |