Skip to content

Instantly share code, notes, and snippets.

@nikolasco
Created June 11, 2009 23:10
Show Gist options
  • Save nikolasco/128296 to your computer and use it in GitHub Desktop.
Save nikolasco/128296 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
my $NAME = 'Nikolas Coukouma';
my $EMAIL = 'atrus@zmanda.com';
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
open DS, '-|', 'diffstat -l' or die 'failed to run diffstat';
open OCL, '<', 'ChangeLog' or die 'failed to open old ChangeLog';
-f 'ChangeLog~' and die 'new ChangeLog~ already exists';
open NCL, '>', 'ChangeLog~' or die 'failed to open new ChangeLog~';
my @files = ();
my $fn;
while ($fn = <DS>) {
chomp $fn;
push @files, $fn;
}
printf NCL "%04d-%02d-%02d %s <%s>\n", $year+1900, $mon+1, $mday, $NAME, $EMAIL;
my $c_line = "\t* ";
my $some_files = 0;
while (@files) {
$fn = shift @files;
# start a new line before appending?
if ($some_files and
# +7 for tab, possible +2 for ", "
(length($c_line)+7+length($fn)+($some_files? 2 : 0)) > 79) {
print NCL $c_line . ",\n";
$c_line = "\t ";
$some_files = 0;
} else {
unless ($some_files) {
print "will append, so we have at least one file\n";
} else {
printf "will append, line not over 80 chars (%d)\n", (length($c_line)+7+length($fn)+($some_files? 2 : 0));
}
}
$c_line .= ($some_files? ", " : "") . $fn;
$some_files = 1;
}
print NCL "$c_line:\n\n";
close DS;
while (my $l = <OCL>) {
print NCL $l;
}
close OCL;
close NCL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment