123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package Gsg::Gather;
- use strict;
- use warnings;
- use Log::Log4perl qw(:easy);
- use Shellex::Shellex qw(shellex findBin);
- use Exporter qw(import);
- our @EXPORT_OK = qw(get_file_tree get_projects);
- sub get_projects($$$) {
- my $git_dir = shift;
- my $ignored_projects_ref = shift;
- my $logger = shift;
- my $ls_cmd = findBin("ls",$logger);
- my @git_project_dirs;
- foreach my $dir ( split("\n", shellex("$ls_cmd -d $git_dir/*/",$logger)) ) {
- if ( $dir !~ m/\.git/ ) {
- next;
- }
- if ( grep( /^$dir$/, @$ignored_projects_ref ) ) {
- $logger->info("Found $dir in ignore list, skipping...");
- next;
- } else {
- push(@git_project_dirs,$dir);
- }
- }
- return \@git_project_dirs;
- }
- sub get_file_tree($$) {
- my $projectDir = shift;
- my $logger = shift;
- my $gitCmd = findBin("git",$logger);
- # Get files
- my %file_tree;
- foreach my $file ( split("\n", shellex("$gitCmd --git-dir=\"$projectDir\" ls-tree --full-tree -r HEAD",$logger)) ) {
- chomp $file;
- $file =~ /([a-z0-9]{40})\t(.*)$/;
- # Name - object id
- $file_tree{$2} = $1;
- }
- # Get file content
- my %file_content;
- foreach my $filename ( keys %file_tree ) {
- my $content = shellex("$gitCmd --git-dir=\"$projectDir\" show $file_tree{$filename}",$logger);
- chomp $content;
- # Name - file content
- $file_content{$filename} = $content;
- }
- # Get logs
- my @commit_ids;
- foreach my $log_line ( split("\n",shellex("$gitCmd --git-dir=\"$projectDir\" log",$logger)) ) {
- if ( $log_line =~ m/commit\ ([a-z0-9]{40})/ ) {
- push(@commit_ids,$1);
- }
- }
- my %commits;
- foreach my $commit_id ( @commit_ids ) {
- my $commit_info = shellex("git --git-dir=\"$projectDir\" show $commit_id",$logger);
- chomp $commit_info;
- $commits{$commit_id} = $commit_info;
- }
- return ( \%file_tree, \%file_content, \%commits );
- }
- 1;
|