diff options
author | Yves Orton <demerphq@gmail.com> | 2009-01-01 18:19:33 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2009-01-04 23:32:40 +0100 |
commit | 29299e4722ac21a0c18f63a307026e12b5b868fb (patch) | |
tree | 72419520cba43697f5c23629d0f06e84c98dc6d4 /make_patchnum.pl | |
parent | b6194a9dbf93238df7e489901287cc0265a05f6c (diff) | |
download | perl-29299e4722ac21a0c18f63a307026e12b5b868fb.tar.gz |
move subs from bottom to top, and add a vim and shebang line
Diffstat (limited to 'make_patchnum.pl')
-rw-r--r-- | make_patchnum.pl | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/make_patchnum.pl b/make_patchnum.pl index 75423af5f2..929c45b595 100644 --- a/make_patchnum.pl +++ b/make_patchnum.pl @@ -1,3 +1,7 @@ +#!/usr/bin/perl +use strict; +use warnings; + =head1 NAME make_patchnum.pl - make patchnum @@ -8,8 +12,42 @@ make_patchnum.pl - make patchnum =cut -use strict; -use warnings; +BEGIN { + my $root="."; + while (!-e "$root/perl.c" and length($root)<100) { + if ($root eq '.') { + $root=".."; + } else { + $root.="/.."; + } + } + die "Can't find toplevel" if !-e "$root/perl.c"; + sub path_to { "$root/$_[0]" } # use $_[0] if this'd be placed in toplevel. +} + +sub read_file { + my $file = path_to(@_); + return "" unless -e $file; + open my $fh, '<', $file + or die "Failed to open for read '$file':$!"; + return do { local $/; <$fh> }; +} + +sub write_file { + my ($file, $content) = @_; + $file= path_to($file); + open my $fh, '>', $file + or die "Failed to open for write '$file':$!"; + print $fh $content; + close $fh; +} + +sub backtick { + my $command = shift; + my $result = `$command`; + chomp $result; + return $result; +} my $existing_patchnum = read_file('.patchnum'); my $existing_config = read_file('lib/Config_git.pl'); @@ -42,7 +80,7 @@ elsif (-d path_to('.git')) { join ",", map { (split /\s/, $_)[1] } grep {/\+/} split /\n/, backtick("git cherry $remote/$branch"); # git cherry $remote/$branch | awk 'BEGIN{ORS="\t\\\\\n"} /\+/ {print ",\"" $2 "\""}' - $unpushed_commits = + $unpushed_commits = join "", map { ',"'.(split /\s/, $_)[1].'"'."\t\\\n" } grep {/\+/} split /\n/, backtick("git cherry $remote/$branch"); if (length $unpushed_commits) { @@ -99,40 +137,4 @@ else { print "Reusing .patchnum and lib/Config_git.pl\n" } -BEGIN { - my $root="."; - while (!-e "$root/perl.c" and length($root)<100) { - if ($root eq '.') { - $root=".."; - } else { - $root.="/.."; - } - } - die "Can't find toplevel" if !-e "$root/perl.c"; - sub path_to { "$root/$_[0]" } # use $_[0] if this'd be placed in toplevel. -} - -sub read_file { - my $file = path_to(@_); - return "" unless -e $file; - open my $fh, '<', $file - or die "Failed to open for read '$file':$!"; - return do { local $/; <$fh> }; -} - -sub write_file { - my ($file, $content) = @_; - $file= path_to($file); - open my $fh, '>', $file - or die "Failed to open for write '$file':$!"; - print $fh $content; - close $fh; -} - -sub backtick { - my $command = shift; - my $result = `$command`; - chomp $result; - return $result; -} -#$ ts=4:et +# ex: set ts=4 sts=4 et ft=perl: |