diff options
author | fuzzyray <fuzzyray@gentoo.org> | 2009-05-05 16:02:10 +0000 |
---|---|---|
committer | fuzzyray <fuzzyray@gentoo.org> | 2009-05-05 16:02:10 +0000 |
commit | ab5d6784bbb1382b8a48cae001cbd2d075f58d21 (patch) | |
tree | b123d2e675a998d8a28bd108e3dd66592922e89c /src/echangelog | |
parent | Merge changes from trunk to fix issues in 0.2.4 (diff) | |
parent | Add some useful informations when using $EDITOR. (diff) | |
download | gentoolkit-ab5d6784bbb1382b8a48cae001cbd2d075f58d21.tar.gz gentoolkit-ab5d6784bbb1382b8a48cae001cbd2d075f58d21.tar.bz2 gentoolkit-ab5d6784bbb1382b8a48cae001cbd2d075f58d21.zip |
Merge changes from trunk in prep for making trunk ready for version 0.3
svn path=/branches/gentoolkit-0.2.4/; revision=588
Diffstat (limited to 'src/echangelog')
-rw-r--r-- | src/echangelog/Makefile | 17 | ||||
-rwxr-xr-x | src/echangelog/echangelog | 166 | ||||
-rw-r--r-- | src/echangelog/echangelog.pod | 136 | ||||
-rwxr-xr-x | src/echangelog/test/test.sh | 38 |
4 files changed, 153 insertions, 204 deletions
diff --git a/src/echangelog/Makefile b/src/echangelog/Makefile index 61c5e57..4825683 100644 --- a/src/echangelog/Makefile +++ b/src/echangelog/Makefile @@ -6,15 +6,18 @@ include ../../makedefs.mak -%.1 : %.pod - pod2man $< > $@ +.PHONY: all test -.PHONY: all -all: echangelog.1 +all: -dist: echangelog.1 - mkdir -p ../../$(distdir)/src/echangelog/ - cp Makefile AUTHORS README TODO ChangeLog echangelog echangelog.pod echangelog.1 ../../$(distdir)/src/echangelog/ +test: + cd test; sh test.sh + +dist: + mkdir -p ../../$(distdir)/src/echangelog/test/templates + cp Makefile AUTHORS README TODO ChangeLog echangelog echangelog.1 ../../$(distdir)/src/echangelog/ + cp test/TEST.pm test/test.sh ../../$(distdir)/src/echangelog/test/ + cp test/templates/test.patch test/templates/vcstest-0.0.1.ebuild ../../$(distdir)/src/echangelog/test/templates install: all install -m 0755 echangelog $(bindir)/ diff --git a/src/echangelog/echangelog b/src/echangelog/echangelog index fea1af6..551d9b9 100755 --- a/src/echangelog/echangelog +++ b/src/echangelog/echangelog @@ -76,6 +76,74 @@ sub version { exit 0; } +sub getenv($) { + my $key = shift; + + # Ensure our variable exist + if ( defined($ENV{$key}) ) { + # Ensure we don't get empty variables + if ( length($ENV{$key}) > 0 ) { + return $ENV{$key}; + } + } + return undef; +} + +# Bug 264146. +# Copied from Text::Wrap. +# The only modified thing is: +# We trim _just_ tab/space etc. but not \n/\r. +# \s treats even \n/\r as whitespace. +# BUGS: +# ' test' +# ' test' +# Will end up in: +# ' test' +# '' +# 'test' +# See 'my $ps = ($ip eq $xp) ? "\n\n" : "\n";' +sub text_fill { + my ($ip, $xp, @raw) = @_; + my @para; + my $pp; + + for $pp ( split(/\n\s+/, join("\n", @raw)) ) { + $pp =~ s/[\x09|\x0B|\x0C|\x20]+/ /g; + my $x = Text::Wrap::wrap($ip, $xp, $pp); + push(@para, $x); + } + + # if paragraph_indent is the same as line_indent, + # separate paragraphs with blank lines + my $ps = ($ip eq $xp) ? "\n\n" : "\n"; + return join ($ps, @para); +} + +sub changelog_info(%) { + my %changed = @_; + + open(INFO, '>', 'ChangeLog.new'); + + print(INFO "\n"); + print(INFO "# Please enter the ChangeLog message for your changes. Lines starting\n"); + print(INFO "# with '#' will be ignored, and an empty message aborts the ChangeLog.\n"); + print(INFO "#\n# Changes:\n"); + + foreach my $key (keys(%changed)) { + if ($changed{$key} eq "+") { + printf(INFO "# new file:\t%s\n", $key); + } + elsif ($changed{$key} eq "-") { + printf(INFO "# deleted:\t%s\n", $key); + } + else { + printf(INFO "# modified:\t%s\n", $key); + } + } + + close(INFO); +} + GetOptions( 'help' => \$opt_help, 'strict' => \$opt_strict, @@ -91,10 +159,16 @@ if ( -d "CVS" ) { } elsif ( -d '.svn' ) { $vcs = "svn"; } else { - if ( -x '/usr/bin/git' ) { - open(GIT, '-|', "git rev-parse --git-dir 2>/dev/null"); - $vcs = "git" if defined(<GIT>); - close(GIT); + # Respect $PATH while looking for git + if (getenv("PATH")) { + foreach my $path ( split(":", getenv("PATH")) ) { + if ( -X "$path/git" ) { + open(GIT, '-|', "git rev-parse --git-dir 2>/dev/null"); + $vcs = "git" if defined(<GIT>); + close(GIT); + last; + } + } } if ( ! $vcs ) { @@ -115,7 +189,7 @@ if (-f 'ChangeLog') { close C; $new =~ s/\s+$//; - open I, "< $new/skel.ChangeLog" + open I, "< $new/skel.ChangeLog" or die "Can't open $new/skel.ChangeLog for input: $!\n"; { local $/ = undef; $text = <I>; } close I; @@ -140,7 +214,7 @@ while (<C>) { push @conflicts, $1; next; } - + push @conflicts, $1; next; } elsif (/^\?\s+(\S+)/) { @@ -157,18 +231,18 @@ while (<C>) { } else { push @unknown, $1; } - + $actions{$1} = '+'; next; } elsif (/^([ARMD])\s+\+?\s*(\S+)/) { my ($status, $filename) = ($1,$2); - + if($vcs eq "git") { open P, "git rev-parse --sq --show-prefix |"; my $prefix = <P>; $prefix = substr($prefix, 0, -1); close P; - + if ($filename =~ /$prefix(\S*)/) { $filename = $1 ; } @@ -176,11 +250,11 @@ while (<C>) { next; } } - + if( -d $filename ) { next; } - + push @files, $filename; ($actions{$filename} = $status) =~ tr/DARM/-+-/d; } @@ -199,12 +273,12 @@ sub git_unknown_objects { # Ignore empty directories - git doesn't version them and cvs removes them. if ( (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && ! -d _ ) { open C, $vcs." status $_ 2>&1 1>/dev/null |"; - + while (<C>) { $_ = <C>; push @unknown, $object; }; - + close C; }; } @@ -301,7 +375,7 @@ sub sortfunc($$) { # compare suffix number return +5 if defined $sna and !defined $snb; return -5 if defined $snb and !defined $sna; - + if (defined $sna) { # and defined $snb $retval = ($sna <=> $snb); return $retval if $retval; @@ -313,7 +387,7 @@ sub sortfunc($$) { # return +6 if defined $ra and !defined $rb; return -6 if defined $rb and !defined $ra; - + if (defined $ra) { # and defined $rb return ($ra <=> $rb); } @@ -324,8 +398,6 @@ sub sortfunc($$) { return 0; } -@files = sort sortfunc @files; - # Just to ensure we don't get duplicate entries. sub mypush(\@@) { my $aref = shift; @@ -362,7 +434,7 @@ if (@ebuilds) { if ($vcs eq "git") { my $version = $2; - + while (<C>) { last if /^deleted file mode|^index/; if (/^new file mode/) { @@ -412,7 +484,7 @@ if (($vcs eq "svn") and (@ebuilds)) { mypush(@files, $1); mypush(@new_versions, $2); } - + $_ = <C>; } } @@ -439,7 +511,12 @@ unless (@files) { } @files = sort sortfunc @trivial; - @files = qw/ChangeLog/ unless @files; # last resort to put something in the list + + # last resort to put something in the list + unless (@files) { + @files = qw/ChangeLog/; + $actions{'ChangeLog'} = ""; + } } # sort @@ -450,34 +527,39 @@ unless (@files) { if ($ARGV[0]) { $input = "@ARGV"; } else { - # Testing for defined() allows ECHANGELOG_EDITOR='' to cancel EDITOR - $editor = defined($ENV{'ECHANGELOG_EDITOR'}) ? $ENV{'ECHANGELOG_EDITOR'} : - $ENV{'EDITOR'} || undef; - + $editor = getenv('ECHANGELOG_EDITOR') ? getenv('ECHANGELOG_EDITOR') : getenv('EDITOR') || undef; + if ($editor) { + # Append some informations. + changelog_info(%actions); + system("$editor ChangeLog.new"); if ($? != 0) { # This usually happens when the editor got forcefully killed; and # the terminal is probably messed up: so we reset things. - system('/usr/bin/stty sane'); + system('stty sane'); print STDERR "Editor died! Reverting to stdin method.\n"; undef $editor; } else { if (open I, "<ChangeLog.new") { local $/ = undef; $input = <I>; - close I; + close(I); + + # Remove comments from changelog_info(). + local $/ = "\n"; + $input =~ s/^#.*//mg; + local $/ = undef; } else { print STDERR "Error opening ChangeLog.new: $!\n"; print STDERR "Reverting to stdin method.\n"; undef $editor; } - - unlink 'ChangeLog.new'; } + unlink('ChangeLog.new') if -f 'ChangeLog.new'; } - + unless ($editor) { print "Please type the log entry: use Ctrl-d to finish, Ctrl-c to abort...\n"; local $/ = undef; @@ -488,14 +570,28 @@ die "Empty entry; aborting\n" unless $input =~ /\S/; # If there are any long lines, then wrap the input at $columns chars # (leaving 2 chars on left, one char on right, after adding indentation below). -$input =~ s/^\s*(.*?)\s*\z/$1/s; # trim whitespace -$input = Text::Wrap::fill(' ', ' ', $input); +$input = text_fill(' ', ' ', $input); # Prepend the user info to the input -unless ($user = $ENV{'ECHANGELOG_USER'}) { +# Changes related to bug 213374; +# This sequence should be right: +# 1. GENTOO_COMMITTER_NAME && GENTOO_COMMITTER_EMAIL +# 2. GENTOO_AUTHOR_NAME && GENTOO_AUTHOR_EMAIL +# 3. ECHANGELOG_USER (fallback/obsolete?) +# 4. getpwuid().. +if ( getenv("GENTOO_COMMITTER_NAME") && getenv("GENTOO_COMMITTER_EMAIL") ) { + $user = sprintf("%s <%s>", getenv("GENTOO_COMMITTER_NAME"), getenv("GENTOO_COMMITTER_EMAIL")); +} +elsif ( getenv("GENTOO_AUTHOR_NAME") && getenv("GENTOO_AUTHOR_EMAIL") ) { + $user = sprintf("%s <%s>", getenv("GENTOO_AUTHOR_NAME"), getenv("GENTOO_AUTHOR_EMAIL")); +} +elsif ( getenv("ECHANGELOG_USER") ) { + $user = getenv("ECHANGELOG_USER"); +} +else { my ($fullname, $username) = (getpwuid($<))[6,0]; - $fullname =~ s/,.*//; # remove GECOS, bug 80011 - $user = sprintf "%s <%s\@gentoo.org>", $fullname, $username; + $fullname =~ s/,.*//; # remove GECOS, bug 80011 + $user = sprintf('%s <%s@gentoo.org>', $fullname, $username); } # Make sure that we didn't get "root" @@ -516,7 +612,7 @@ $entry .= "\n$input"; # append user input if (@new_versions) { # Insert at the top with a new version marker $text =~ s/^( .*? ) # grab header - \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace + \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace /"$1\n\n" . join("\n", map "*$_ ($date)", reverse @new_versions) . "\n\n$entry\n\n"/sxe diff --git a/src/echangelog/echangelog.pod b/src/echangelog/echangelog.pod deleted file mode 100644 index 192af8d..0000000 --- a/src/echangelog/echangelog.pod +++ /dev/null @@ -1,136 +0,0 @@ -=head1 NAME - -echangelog - Gentoo: update portage ChangeLogs - -=head1 SYNOPSIS - -echangelog [ I<text> ] - -=head1 DESCRIPTION - -This tool provides an easy way to create or update portage ChangeLogs -in Gentoo. The tool scans the current directory, which is assumed to -be a package directory such as /usr/portage/app-editors/vim, finds -what files have been changed or added, and inserts the appropriate -entry to ChangeLog. If I<text> is not provided on the command-line, -echangelog prompts for it. - -All modifications should occur before running echangelog so that it -can include the appropriate file information in the ChangeLog entry. -For example, you should run "cvs add" on your files, otherwise -echangelog won't know those files are part of the update. - -If your text would cause the ChangeLog entry to exceed 80 columns, it -will be rewrapped to keep the ChangeLog neat. If you need special -formatting in the ChangeLog, then you can either (1) run echangelog -with no text on the command-line, and make sure that your text won't -be too wide, (2) edit the ChangeLog manually. If you prefer (2), I'd -recommend something like "echangelog blah" so that the header lines -are computed correctly, then edit and change "blah" to your preferred -text. - -In addition to updating the ChangeLog, echangelog will automatically -update the copyright year of all out-of-date ebuilds, as well as the -ChangeLog itself. These updates are included in the diff displayed by -echangelog when it finishes its work. - -=head1 OPTIONS - -Presently echangelog is simple enough that it supplies no options. -Probably I'll add B<--help> and B<--version> in the future, but for -now it's enough to track the gentoolkit version. - -=head1 EXAMPLES - -To create a ChangeLog for a completely new package. The header is -parsed from skel.ebuild. - - $ cvs add metalog-0.1.ebuild - cvs server: use 'cvs commit' to add this file permanently - - $ echangelog 'New ebuild, thanks to Harvey McGillicuddy' - --- ChangeLog 1969-12-31 19:00:00.000000000 -0500 - +++ ChangeLog.new 2003-02-23 14:04:06.000000000 -0500 - @@ -0,0 +1,9 @@ - +# ChangeLog for app-admin/metalog - +# Copyright 2000-2003 Gentoo Technologies, Inc.; Distributed under the GPL v2 - +# $Header$ - + - +*metalog-0.1 (23 Feb 2003) - + - + 23 Feb 2003; Aron Griffis <agriffis@gentoo.org> metalog-0.1.ebuild : - + New ebuild, thanks to Harvey McGillicuddy - + - -To bump a revision. Note you need to "cvs add" so that echangelog -will notice the new file. - - $ cvs add metalog-0.1-r1.ebuild - cvs server: use 'cvs commit' to add this file permanently - - $ echangelog 'Bump revision to fix bug #999' - --- ChangeLog 2003-02-23 14:04:06.000000000 -0500 - +++ ChangeLog.new 2003-02-23 14:07:48.000000000 -0500 - @@ -2,6 +2,11 @@ - # Copyright 2000-2003 Gentoo Technologies, Inc.; Distributed under the GPL v2 - # $Header$ - - +*metalog-0.1-r1 (23 Feb 2003) - + - + 23 Feb 2003; Aron Griffis <agriffis@gentoo.org> metalog-0.1-r1.ebuild : - + Bump revision to fix bug #999 - + - *metalog-0.1 (23 Feb 2003) - - 23 Feb 2003; Aron Griffis <agriffis@gentoo.org> metalog-0.1.ebuild : - -For a multi-line entry, omit the command-line arg. - - $ echangelog - Please type the log entry, finish with ctrl-d - Bump revision to fix bug #999. Necessary to bump the revision because - the problem appears at run-time, not compile-time. This should also - give users the updated default configuration file. - --- ChangeLog 2003-02-23 14:09:12.000000000 -0500 - +++ ChangeLog.new 2003-02-23 14:12:43.000000000 -0500 - @@ -2,6 +2,13 @@ - # Copyright 2000-2003 Gentoo Technologies, Inc.; Distributed under the GPL v2 - # $Header$ - - +*metalog-0.1-r1 (23 Feb 2003) - + - + 23 Feb 2003; Aron Griffis <agriffis@gentoo.org> metalog-0.1-r1.ebuild : - + Bump revision to fix bug #999. Necessary to bump the revision because - + the problem appears at run-time, not compile-time. This should also - + give users the updated default configuration file. - + - *metalog-0.1 (23 Feb 2003) - - 23 Feb 2003; Aron Griffis <agriffis@gentoo.org> metalog-0.1.ebuild : - -=head1 ENVIRONMENT VARIABLES - -=over - -=item ECHANGELOG_USER - -If echangelog can't figure out your username for the entry, you should -set ECHANGELOG_USER. For example, export ECHANGELOG_USER="Aron -Griffis <agriffis@gentoo.org>" - -=back - -=head1 NOTES - -As of the most recent version of echangelog (when this man-page -appeared), echangelog puts all new entries at the top of the file -instead of finding the appropriate *version line within the file. -This is because that "new" ChangeLog format was never agreed upon by -the Gentoo developers. Unfortunately the existence of both formats -will undoubtedly cause much confusion. - -This also means that the examples above are wrong, since I just copied -them from some old email. However they're not much wrong. ;-) - -This tool was written by Aron Griffis <agriffis@gentoo.org>. Bugs -found should be filed against me at http://bugs.gentoo.org/ diff --git a/src/echangelog/test/test.sh b/src/echangelog/test/test.sh index 374522f..f2052f3 100755 --- a/src/echangelog/test/test.sh +++ b/src/echangelog/test/test.sh @@ -2,22 +2,17 @@ source /etc/init.d/functions.sh +SUPPORTED_VCS=( "cvs" "svn" "git" ) VCSTEST="echangelog-test/vcstest" _ROOT=$(pwd) export ECHANGELOG_USER="Just a test <echangelogtest@gentoo.org>" -#MD5_INIT="34d54bc2ab1a2154b0c7bd5cdd7f6119" MD5_INIT="34d54bc2ab1a2154b0c7bd5cdd7f6119" -#MD5_PATCH="d910ab6b76cfb48b68e11ae1f06612bb" MD5_PATCH="db1ab89bb7374824d0f198078f79a83f" -#MD5_REVBUMP="8e36650a644ba49cc13bcbe93fdb2d2d" MD5_REVBUMP="31ddfa60d2ae4dd1fccd7e3d2bd2c06c" -#MD5_COPYRIGHT="55a6097d8e3913a9feb0dff250649c00" MD5_COPYRIGHT="6f39fa409ea14bb6506347c53f6dee50" -#MD5_OBSOLETE="6c30d84f603f5f0e4b09a88d9cfdaaa8" MD5_OBSOLETE="0aedadf159c6f3add97a3f79fb867221" -#MD5_FINAL="cdd58fea5cfcef5820013d82ccbe0e89" MD5_FINAL="17eb0df69f501cc6fdaffebd118b7764" function md5() { @@ -168,25 +163,16 @@ else exit 1 fi -if [[ -x $(which git) ]]; -then - ebegin "Starting test with git" - make_test $_ROOT "git" || set $? - eend ${1:-0} -fi - -if [[ -x $(which cvs) ]]; -then - ebegin "Starting test with cvs" - make_test $_ROOT "cvs" || set $? - eend ${1:-0} -fi - -if [[ -x $(which svn) ]]; -then - ebegin "Starting test with svn" - make_test $_ROOT "svn" || set $? - eend ${1:-0} -fi +for vcs in ${SUPPORTED_VCS[*]}; +do + if [[ -x "$(which ${vcs} 2>/dev/null)" ]]; + then + ebegin "Starting test with ${vcs}" + make_test $_ROOT "${vcs}" || set $? + eend ${1:-0} + else + ewarn "No ${vcs} executable found, skipping test..." + fi +done rm -rf "${_ROOT}/tmp" |