git-age-report

At work we have some git repos that were converted from CVS originally created back in 2002 or so. A lot of the things in these repos is cruft and could be deleted. I wrote a little git command to report the most recent commit date for each thing in the current directory.

#!/usr/bin/env perl

use strict;
use warnings;

use DateTime;

my %age;
for my $thing ( glob '*' ) {
    next if $thing =~ /^\.\.?$/;

    my $epoch = `git log -1 --format="%at" $thing`;
    chomp $epoch;

    $thing .= '/' if -d $thing;
    push @{ $age{$epoch} }, $thing;
}

for my $epoch ( reverse sort keys %age ) {
    my $dt = DateTime->from_epoch( epoch => $epoch );

    print $dt->date(), "\n";
    print "  - $_\n" for @{ $age{$epoch} };
    print "\n";
}

4 comments

  1. ack -naf|xargs -I {} sh -c ‘echo -n $(git log -1 –format=%ai “{}”); echo ” {}”‘

  2. Nice one anonymous! I golfed it down and replaced ack with find:

    find . -maxdepth 1 -type f |xargs -I {} git log -1 –format=”%ai {}” “{}”

  3. Those one-liners don’t solve the original problem. The entries should be sorted by date and directories should not be skipped.

    ls -p | xargs -I {} git log -1 –format=”%ai {}” “{}” | sort -r

    This one sorts by date and marks directories with a slash (like the original). Note that the original script would have mis-sorted dates earlier than 9th Sep 2001 because of string sort on unix time, but the earliest expected date was after that anyway.

Comments are closed.