From: Graham Knop Date: Fri, 6 Nov 2015 23:04:47 +0000 (-0500) Subject: fold committing into adding changelog header script X-Git-Tag: v0.003000~43 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDistar.git;a=commitdiff_plain;h=762733d92766c3c78055f19d39c70233fc8b2303 fold committing into adding changelog header script --- diff --git a/helpers/add-changelog-heading b/helpers/add-changelog-heading index 85a0f9d..9d258db 100755 --- a/helpers/add-changelog-heading +++ b/helpers/add-changelog-heading @@ -1,23 +1,33 @@ #!/usr/bin/env perl use strict; use warnings FATAL => 'all'; +use Getopt::Long qw(:config gnu_getopt); +GetOptions( + "git" => \my $git, +) or die("Error in command line arguments\n"); my $version = shift; my @ymd = (gmtime)[5,4,3]; $ymd[0] += 1900; $ymd[1] += 1; -my $changes_line = sprintf "%s - %i-%02i-%02i\n", $version, @ymd; +my $changes_line = sprintf "%s - %i-%02i-%02i", $version, @ymd; foreach my $changes (@ARGV) { print "Adding $version heading to $changes.\n"; - open my $fh, '+<', $changes + open my $fh, '+<:raw', $changes or die "Can't open $changes: $!"; + my $content = ''; - my $done; - local $/ = $/; + my $context; + while (<$fh>) { - if ($done) { - undef $/; + if (defined $context) { + if (/^\S/) { + local $/; + $content .= $_ . <$fh>; + last; + } + $context++; } elsif (/^v?(\d+(?:\.\d+)*)(\s+|$)/) { if ($1 eq $version) { @@ -29,7 +39,8 @@ foreach my $changes (@ARGV) { } elsif (/^\s+[-*+#]/) { $content .= $changes_line; - $done = 1; + $content .= (/(\r?\n)/ || $content =~ /(\r?\n)/) ? $1 : "\n"; + $context = 1; } $content .= $_; } @@ -38,4 +49,9 @@ foreach my $changes (@ARGV) { truncate $fh, 0; print { $fh } $content; close $fh; + + if ($git) { + local $ENV{GIT_DIFF_OPTS} = "-u$context"; + system qw(git add -p), $changes; + } } diff --git a/helpers/changelog-context b/helpers/changelog-context deleted file mode 100755 index 5ab2115..0000000 --- a/helpers/changelog-context +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings FATAL => 'all'; - -my $version = shift or die "no version specified!"; -my $changelog = shift or die "no changelog file specified!"; - -open my $fh, '<', $changelog - or die "can't open $changelog: $!"; -my $context; -my $found_version; -while (my $line = <$fh>) { - if ($found_version) { - last - if $line =~ /^\S/; - $context++; - } - elsif ($line =~ /^v?\Q$version\E/) { - $found_version = 1; - } -} -close $fh; -die "couldn't find heading for $version!" - unless $found_version; - -print "$context\n"; diff --git a/lib/Distar.pm b/lib/Distar.pm index 804f684..62f39c0 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -158,8 +158,7 @@ disttest: distmanicheck distmanicheck: create_distdir cd $(DISTVNAME) && $(ABSPERLRUN) "-MExtUtils::Manifest=manicheck" -e "exit manicheck" nextrelease: - $(ABSPERLRUN) Distar/helpers/add-changelog-heading $(VERSION) Changes - GIT_DIFF_OPTS=-u`$(ABSPERLRUN) Distar/helpers/changelog-context $(VERSION) Changes` git add -p Changes + $(ABSPERLRUN) Distar/helpers/add-changelog-heading --git $(VERSION) Changes refresh: cd Distar && git pull $(RM_F) $(FIRST_MAKEFILE)