From 7d53ee43f82cc5eda12e7f585e785933b4aa18dc Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Tue, 19 Aug 2025 11:10:10 +0000 Subject: Ratifying Pure Functionality Of Nothing New --- perl/git-construct.pl | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 perl/git-construct.pl (limited to 'perl/git-construct.pl') diff --git a/perl/git-construct.pl b/perl/git-construct.pl new file mode 100755 index 0000000..4024ef1 --- /dev/null +++ b/perl/git-construct.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Git::Repository; +use Cwd 'realpath'; +use File::Basename; + +use Data::Dumper; + +sub new_repository { + my ($path) = @_; + $path = realpath($path); + + my $name = basename($path); + my $repo = Git::Repository->new(work_tree => $path); + + my @raw_branches = $repo->run('branch'); + my @branches; + + for my $b (@raw_branches) { + chomp $b; + my $is_active = 0; + + if ($b =~ /^\* /) { + $b =~ s/^\* //; + $is_active = 1; + } + + my @commits; + my @logs = $repo->run(log => $b, '--pretty=format:%H;%an;%s'); + for my $line (@logs) { + my ($hash, $author, $message) = split /;/, $line, 3; + push @commits, { + hash => $hash, + author => $author, + message => $message, + }; + } + + push @branches, { + name => $b, + is_active => $is_active, + commits => \@commits, + }; + } + + # first commiter as a fallback + my $owner = ($repo->run('log', '--reverse', '--pretty=format:%an'))[0]; + + return { + name => $name, + owner => $owner, + branches => \@branches, + }; +} + +print Dumper( new_repository('./') ); -- cgit v1.2.3