From 011e36350a1f8f20addaac753f2a4d3b359ab2d6 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 4 Aug 2022 09:03:59 +0200 Subject: [PATCH] merge git log from multiple repositories by date --- git-log-merge.pl | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 git-log-merge.pl diff --git a/git-log-merge.pl b/git-log-merge.pl new file mode 100755 index 0000000..9886fdc --- /dev/null +++ b/git-log-merge.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl +use warnings; +use strict; +use autodie; +use Data::Dump qw(dump); + +my @repos = qw( +/home/dpavlin/dell-switch/running-config/ +/home/dpavlin/mikrotik-switch/backup/ +/home/dpavlin/tilera/backup/ +); + +my $debug = $ENV{DEBUG} || 0; +$| = 1 if $debug; + +open(my $less, '|-', "less -R -S"); + +my $commit; +my $commit_next; + +our $fh; +my $date_commit; + +sub get_commit { + my $repo = shift; + my $r = $fh->{$repo}; + die "ERROR on $repo in ",dump($fh) unless $r; + while(<$r>) { + if ( m/(\e\[\d*m)?commit [0-9a-f]+/ ) { + #if ( m/commit [0-9a-f]+/ ) { + if ( ! defined $commit->{$repo} ) { # first time, read commit + $commit->{$repo} = $_; + warn "## first commit ",dump($_) if $debug; + } else { + $commit_next->{$repo} = $_; + warn "## --------------" if $debug; + last; + } + } elsif (m/Date:\s+([0-9-\+: ]+)/ ) { + $date_commit->{$1} = $repo; + warn "# $repo $1" if $debug; + $commit->{$repo} .= $_; + } else { + $commit->{$repo} .= $_; + warn "## $repo $. ",dump($_) if $debug; + } + } +} + +foreach my $repo ( @repos ) { + $ENV{PAGER} = 'cat'; + open(my $r, '-|', "git -C $repo log --date=iso --color @ARGV"); + $fh->{$repo} = $r; + get_commit $repo; +} + + +while(1) { + #warn "# date_commit = ",dump($date_commit); + my $date = ( sort { $b cmp $a } keys %$date_commit )[0]; + my $repo = $date_commit->{$date}; + print "# $date $repo\n$commit->{$repo}"; + $commit->{$repo} = $commit_next->{$repo}; + delete $date_commit->{$date}; + get_commit $repo; +} -- 2.20.1