-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-log-merge.pl
executable file
·66 lines (57 loc) · 1.43 KB
/
git-log-merge.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 $less "# $date $repo\n$commit->{$repo}";
$commit->{$repo} = $commit_next->{$repo};
delete $date_commit->{$date};
get_commit $repo;
}