💾 Archived View for d.moonfire.us › blog › 2012 › 04 › 24 › an-obsession-with-data-git captured on 2022-03-01 at 15:45:32. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-01-08)

➡️ Next capture (2023-01-29)

-=-=-=-=-=-=-

An obsession with data (Git version)

Up a Level

Previous

Next

git log –name-only –pretty=%ai

Setup

Directives

use strict; use warnings;

Directory Parsing

Go through all the files in the command-line arguments.

while (@ARGV) { # If it isn't a directory, we don't care. my $dir = shift @ARGV; $dir =~ s@/$@@sg;

if (! -d $dir)
{
	print STDERR "Ignoring $dir (not a directory)n";
	next;
}

my $git_dir = "$dir/.git";

if (! -d $dir)
{
	print STDERR "Ignoring $dir (no .git inside)n";
	next;
}

# We're processing this directory.
print STDERR "Processing $dirn";

# Set the GIT_DIR and GIT_WORK_TREE so we don't have to move into
# that directory.
$ENV{GIT_WORK_TREE} = $dir;
$ENV{GIT_DIR} = $git_dir;

# We want to build up a log of the entire repository. We want to
# know each of the files and date that they were checked in.
my $last_timestamp;
my %files = ();

open GIT, "git log --name-only --pretty=%ai |"
	or die "Cannot open Git for $dir ($!)";

while ()
{
	# Clean up the line and ignore blanks.
	chomp;
	next if /^s*$/;

	# In general, we will have two types of lines. One is in a
	# timestamp and the other is the name of the file.
	if (/^(d+)-(d+)-(d+) (d+):(d+):(d+)/)
	{
		# We only care about the date of the check-in.
		$last_timestamp = "$1-$2-$3";
	}
	else
	{
		# For everything else, we get a filename. There are a few
		# things that we frequently ignore, such as hidden files
		# (start with a period).
		next if /^./;
		next if m@/.@;

		# We add the file and the current timestamp to the
		# hash. Since we replace with each one, and `git log` goes
		# backwards in time, the last time we see the file is the
		# point it was first added to the repository.

		# Print out the line.
		$files{$_} = $last_timestamp;
	}
}

close GIT;

# Now that we are done parsing, we output the merged results.
open REPORT, ">$dir.files" or die "Cannot write $dir.files ($!)";

foreach my $file (sort(keys(%files)))
{
	# Pull out the date.
	my $date = $files{$file};

	# Keep track if this file exists.
	my $exists = 0;
	$exists = 1 if -f "$dir/$file";

	#print "$filet$daten";
	#print "$datet$existst$filen";
	print REPORT "$filet$existst$daten";
}

close REPORT;

}

Metadata

Categories:

Programming

Writing

Tags:

Perl

Footer

Below are various useful links within this site and to related sites (not all have been converted over to Gemini).

Contact

Biography

Bibliography

Fiction

Fedran

Coding

The Moonfires

Categories

Tags

Privacy

Colophon

Mailing List

https://d.moonfire.us/blog/2012/04/24/an-obsession-with-data-git/