App-Git-Workflow

 view release on metacpan or  search on metacpan

lib/App/Git/Workflow/Command/Recent.pm  view on Meta::CPAN

    print Dumper $changed;

    return;
}

sub out_json {
    my ($self, $changed) = @_;

    require JSON;
    print JSON::encode_json($changed), "\n";

    return;
}

sub out_yaml {
    my ($self, $changed) = @_;

    require YAML;
    print YAML::Dump($changed);

    return;
}

sub recent_commits {
    my ($self, $option) = @_;

    my @args = ('--since', $option->{since} );

    if ( !$option->{since} ) {
        my $sec_ago = $option->{month} ? 60 * 60 * 24 * 30
            : $option->{week} ? 60 * 60 * 24 * 7
            :                   60 * 60 * 24;

        my (undef,undef,undef,$day,$month,$year) = localtime( time - $sec_ago );
        $year += 1900;
        $month++;

        @args = ('--since', sprintf "%04d-%02d-%02d", $year, $month, $day );
    }

    unshift @args, $option->{tag} ? '--tags'
        : $option->{all}          ? '--all'
        : $option->{remote}       ? '--remotes'
        :                           '--branches';

    return $workflow->git->rev_list(@args);
}

sub changed_from_shas {
    my ($self, @commits) = @_;
    my %changed;
    my $count = 0;
    print {*STDERR} '.' if $option{verbose};

    for my $sha (@commits) {
        my $changed = $workflow->commit_details($sha, branches => 1, files => 1, user => 1);
        next if $self->ignore($changed);

        for my $type (keys %{ $changed->{files} }) {
            if ( defined $option{depth} ) {
                $type = join '/', grep {defined $_} (split m{/}, $type)[0 .. $option{depth} - 1];
            }
            if ( defined $option{path_depth} ) {
                for my $path (keys %{ $option{path_depth} }) {
                    if ( $type =~ /^$path/ ) {
                        $type = join '/', grep {defined $_} (split m{/}, $type)[0 .. $option{path_depth}{$path} - 1];
                    }
                }
            }
            my %branches;
            if ( $option{remote} ) {
                %branches = map { $_ => 1 } grep {/^origin/} keys %{ $changed->{branches} };
            }
            elsif ( $option{all} ) {
                %branches = %{ $changed->{branches} };
            }
            else {
                %branches = map { $_ => 1 } grep {!/^origin/} keys %{ $changed->{branches} };
            }
            next if !%branches;

            $changed{$type}{users}{$changed->{user}}++;
            $changed{$type}{files} = {
                %{ $changed{$type}{files} || {} },
                %{ $changed->{files} },
            };
            $changed{$type}{branches} = {
                %{ $changed{$type}{branches} || {} },
                %branches,
            };
        }

        print {*STDERR} '.' if $option{verbose} && ++$count % 10 == 0;
    }

    for my $type (keys %changed) {
        $changed{$type}{users   } = [ sort keys %{ $changed{$type}{users   } } ];
        $changed{$type}{files   } = [ sort keys %{ $changed{$type}{files   } } ];
        $changed{$type}{branches} = [ sort keys %{ $changed{$type}{branches} } ];
    }

    return %changed;
}

sub ignore {
    my ($self, $commit) = @_;

    if ($option{ignore_files}) {
        for my $ignore (@{ $option{ignore_files} }) {
            for my $file (keys %{ $commit->{files} }) {
                return 1 if $file =~ /$ignore/;
            }
        }
    }

    if ($option{ignore_user}
        && grep {$commit->{user} =~ /$_/} @{ $option{ignore_user} } ) {
        return 1;
    }

    if ($option{ignore_branch}
        && grep {$commit->{branches} =~ /$_/} @{ $option{ignore_branch} } ) {
        return 1;
    }

    return 0;



( run in 1.059 second using v1.01-cache-2.11-cpan-6aa56a78535 )