Gentoo Archives: gentoo-commits

From: "Christian Ruppert (idl0r)" <idl0r@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoolkit r554 - in trunk/src/echangelog: . test test/templates
Date: Wed, 29 Apr 2009 12:35:26
Message-Id: E1Lz90V-0005j5-MD@stork.gentoo.org
1 Author: idl0r
2 Date: 2009-04-29 12:35:23 +0000 (Wed, 29 Apr 2009)
3 New Revision: 554
4
5 Modified:
6 trunk/src/echangelog/echangelog
7 trunk/src/echangelog/test/TEST.pm
8 trunk/src/echangelog/test/templates/test.patch
9 Log:
10 Fixed indent, migrated to tabs and fixed vim modeline. Cleanup.
11
12
13 Modified: trunk/src/echangelog/echangelog
14 ===================================================================
15 --- trunk/src/echangelog/echangelog 2009-04-29 10:54:15 UTC (rev 553)
16 +++ trunk/src/echangelog/echangelog 2009-04-29 12:35:23 UTC (rev 554)
17 @@ -11,6 +11,7 @@
18 use strict;
19 use POSIX qw(strftime getcwd setlocale);
20 use File::Find;
21 +use Getopt::Long;
22
23 # Fix bug 21022 by restricting to C locale
24 setlocale(&POSIX::LC_ALL, "C");
25 @@ -24,30 +25,34 @@
26 my ($input, $editor, $entry, $user, $date, $text, $year, $vcs);
27 my ($opt_help, $opt_strict, $opt_version);
28
29 +$opt_help = 0;
30 +$opt_strict = 0;
31 +$opt_version = 0;
32 +
33 my %vcs = (
34 - cvs => {
35 - diff => "cvs -f diff -U0",
36 - status => "cvs -fn up",
37 - add => "cvs -f add",
38 - skip => 6,
39 - regex => qr/^Index: (([^\/]*?)\.ebuild)\s*$/
40 - },
41 - svn => {
42 - diff => "svn diff -N",
43 - status => "svn status",
44 - add => "svn add",
45 - skip => 4,
46 - regex => qr/^Index: (([^\/]*?)\.ebuild)\s*$/
47 - },
48 - git => {
49 - diff => "git diff",
50 - status => "git diff-index HEAD --name-status",
51 - add => "git add",
52 - # This value should usually be 3 but on new file mode we need skip+1.
53 - # So 4 should be fine anyway.
54 - skip => 4,
55 - regex => qr/^diff \-\-git \S*\/((\S*)\.ebuild)/
56 - },
57 + cvs => {
58 + diff => "cvs -f diff -U0",
59 + status => "cvs -fn up",
60 + add => "cvs -f add",
61 + skip => 6,
62 + regex => qr/^Index: (([^\/]*?)\.ebuild)\s*$/
63 + },
64 + svn => {
65 + diff => "svn diff -N",
66 + status => "svn status",
67 + add => "svn add",
68 + skip => 4,
69 + regex => qr/^Index: (([^\/]*?)\.ebuild)\s*$/
70 + },
71 + git => {
72 + diff => "git diff",
73 + status => "git diff-index HEAD --name-status",
74 + add => "git add",
75 + # This value should usually be 3 but on new file mode we need skip+1.
76 + # So 4 should be fine anyway.
77 + skip => 4,
78 + regex => qr/^diff \-\-git \S*\/((\S*)\.ebuild)/
79 + },
80 );
81
82 sub usage {
83 @@ -62,6 +67,7 @@
84 print $usage;
85 exit 0;
86 }
87 +
88 sub version {
89 my $Revision = "Last svn change rev";
90 my $Date = "Last svn change date";
91 @@ -69,107 +75,114 @@
92 print "echangelog\n$Revision$foo \n$Date$foo\n";
93 exit 0;
94 }
95 -use Getopt::Long;
96 -$opt_help = 0;
97 -$opt_strict = 0;
98 -$opt_version = 0;
99 +
100 GetOptions(
101 'help' => \$opt_help,
102 'strict' => \$opt_strict,
103 - 'version' => \$opt_version
104 + 'version' => \$opt_version,
105 );
106 -usage if $opt_help;
107 -version if $opt_version;
108
109 +usage() if $opt_help;
110 +version() if $opt_version;
111 +
112 # Figure out what kind of repo we are in.
113 -
114 if ( -d "CVS" ) {
115 - $vcs = "cvs";
116 + $vcs = "cvs";
117 } elsif ( -d '.svn' ) {
118 - $vcs = "svn";
119 + $vcs = "svn";
120 } elsif ( -f '/usr/bin/git' and open GIT, "git rev-parse --git-dir |" ) {
121 - $vcs = "git";
122 - close GIT;
123 + $vcs = "git";
124 + close GIT;
125 } else {
126 - die "No CVS, .git, .svn directories found, what kind of repo is this?";
127 + die "No CVS, .git, .svn directories found, what kind of repo is this?";
128 }
129
130 # Read the current ChangeLog
131 if (-f 'ChangeLog') {
132 - open I, '<ChangeLog' or die "Can't open ChangeLog for input: $!\n";
133 - { local $/ = undef; $text = <I>; }
134 - close I;
135 + open I, '<ChangeLog' or die "Can't open ChangeLog for input: $!\n";
136 + { local $/ = undef; $text = <I>; }
137 + close I;
138 } else {
139 - # No ChangeLog here, maybe we should make one...
140 - if (<*.ebuild>) {
141 - open C, "portageq envvar PORTDIR |" or die "Can't find PORTDIR";
142 - my ($new) = <C>;
143 - close C;
144 - $new =~ s/\s+$//;
145 - open I, "< $new/skel.ChangeLog"
146 - or die "Can't open $new/skel.ChangeLog for input: $!\n";
147 - { local $/ = undef; $text = <I>; }
148 - close I;
149 - $text =~ s/^\*.*//ms; # don't need the fake entry
150 - } else {
151 - die "This should be run in a directory with ebuilds...\n";
152 - }
153 + # No ChangeLog here, maybe we should make one...
154 + if (<*.ebuild>) {
155 + open C, "portageq envvar PORTDIR |" or die "Can't find PORTDIR";
156 + my ($new) = <C>;
157 + close C;
158 +
159 + $new =~ s/\s+$//;
160 + open I, "< $new/skel.ChangeLog"
161 + or die "Can't open $new/skel.ChangeLog for input: $!\n";
162 + { local $/ = undef; $text = <I>; }
163 + close I;
164 + $text =~ s/^\*.*//ms; # don't need the fake entry
165 + } else {
166 + die "This should be run in a directory with ebuilds...\n";
167 + }
168 }
169
170 # Figure out what has changed around here
171 open C, $vcs{$vcs}{status}.' 2>&1 |' or die "Can't run ".$vcs{$vcs}{status}.": $!\n";
172 while (<C>) {
173 - if (/^C\s+(\S+)/) {
174 - if($vcs eq "git") {
175 - my $filename = $2;
176 - $filename =~ /\S*\/(\S*)/;
177 - if( -d $1 ) {
178 + if (/^C\s+(\S+)/) {
179 + if($vcs eq "git") {
180 + my $filename = $2;
181 + $filename =~ /\S*\/(\S*)/;
182 +
183 + if( -d $1 ) {
184 + next;
185 + }
186 +
187 + push @conflicts, $1;
188 + next;
189 + }
190 +
191 + push @conflicts, $1;
192 next;
193 - }
194 - push @conflicts, $1;
195 - next;
196 - }
197 - push @conflicts, $1;
198 - next;
199 - } elsif (/^\?\s+(\S+)/) {
200 - if($vcs eq "git") {
201 - my $filename = $2;
202 - $filename =~ /\S*\/(\S*)/;
203 - if( -d $1 ) {
204 + } elsif (/^\?\s+(\S+)/) {
205 + if($vcs eq "git") {
206 + my $filename = $2;
207 + $filename =~ /\S*\/(\S*)/;
208 +
209 + if( -d $1 ) {
210 + next;
211 + }
212 +
213 + push @unknown, $1;
214 + next;
215 + } else {
216 + push @unknown, $1;
217 + }
218 +
219 + $actions{$1} = '+';
220 next;
221 - }
222 - push @unknown, $1;
223 - next;
224 - } else {
225 - push @unknown, $1;
226 - }
227 - $actions{$1} = '+';
228 - next;
229 - } elsif (/^([ARMD])\s+\+?\s*(\S+)/) {
230 - my ($status, $filename) = ($1,$2);
231 - if($vcs eq "git") {
232 - open P, "git rev-parse --sq --show-prefix |";
233 - my $prefix = <P>;
234 - $prefix = substr($prefix, 0, -1);
235 - close P;
236 -
237 - if ($filename =~ /$prefix(\S*)/) {
238 - $filename = $1 ;
239 - }
240 - else {
241 - next;
242 - }
243 - }
244 - if( -d $filename ) {
245 - next;
246 + } elsif (/^([ARMD])\s+\+?\s*(\S+)/) {
247 + my ($status, $filename) = ($1,$2);
248 +
249 + if($vcs eq "git") {
250 + open P, "git rev-parse --sq --show-prefix |";
251 + my $prefix = <P>;
252 + $prefix = substr($prefix, 0, -1);
253 + close P;
254 +
255 + if ($filename =~ /$prefix(\S*)/) {
256 + $filename = $1 ;
257 + }
258 + else {
259 + next;
260 + }
261 + }
262 +
263 + if( -d $filename ) {
264 + next;
265 + }
266 +
267 + push @files, $filename;
268 + ($actions{$filename} = $status) =~ tr/DARM/-+-/d;
269 }
270 - push @files, $filename;
271 - ($actions{$filename} = $status) =~ tr/DARM/-+-/d;
272 - }
273 }
274
275 # git only shows files already added so we need to check for unknown files
276 -# separately here.
277 +# separately here.
278 if($vcs eq "git") {
279 find(\&git_unknown_objects, "./");
280 }
281 @@ -179,138 +192,142 @@
282 my ($dev,$ino,$mode,$nlink,$uid,$gid);
283
284 # Ignore empty directories - git doesn't version them and cvs removes them.
285 - if ((($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && ! -d _) {
286 + if ( (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && ! -d _ ) {
287 open C, $vcs." status $_ 2>&1 1>/dev/null |";
288 -
289 - while (<C>) {
290 +
291 + while (<C>) {
292 $_ = <C>;
293 push @unknown, $object;
294 - };
295 - close C;
296 + };
297 +
298 + close C;
299 };
300 }
301
302 # Separate out the trivial files for now
303 -@files = grep {
304 - !/files.digest|Manifest|ChangeLog/ or do { push @trivial, $_; 0; }
305 +@files = grep {
306 + !/files.digest|Manifest|ChangeLog/ or do { push @trivial, $_; 0; }
307 } @files;
308
309 -@unknown = grep {
310 - !/files.digest|Manifest|ChangeLog/ or do { push @trivial, $_; 0; }
311 +@unknown = grep {
312 + !/files.digest|Manifest|ChangeLog/ or do { push @trivial, $_; 0; }
313 } @unknown;
314
315 # Don't allow any conflicts
316 if (@conflicts) {
317 - print STDERR <<EOT;
318 + print STDERR <<EOT;
319 $vcs reports the following conflicts. Please resolve them before
320 running echangelog.
321 EOT
322 - print STDERR map "C $_\n", @conflicts;
323 - exit 1;
324 + print STDERR map "C $_\n", @conflicts;
325 + exit 1;
326 }
327
328 # Don't allow unknown files (other than the trivial files that were separated
329 # out above)
330 if (@unknown) {
331 - print STDERR <<EOT;
332 + print STDERR <<EOT;
333 $vcs reports the following unknown files. Please use "$vcs add" before
334 running echangelog, or remove the files in question.
335 EOT
336 - print STDERR map "? $_\n", @unknown;
337 - exit 1;
338 + print STDERR map "? $_\n", @unknown;
339 + exit 1;
340 }
341
342 # Sort the list of files as portage does. None of the operations through
343 # the rest of the script should break this sort.
344 sub sortfunc($$) {
345 - my ($a, $b) = @_;
346 - (my $va = $a) =~ s/.*?-(\d.*?)(?:\.ebuild)?$/$1/;
347 - (my $vb = $b) =~ s/.*?-(\d.*?)(?:\.ebuild)?$/$1/;
348 - my ($na, $sa, $sna, $ra) = ($va =~ /^(.*?)(?:_(alpha|beta||pre|rc|p)(\d*))?(?:-r(\d+))?$/);
349 - my ($nb, $sb, $snb, $rb) = ($vb =~ /^(.*?)(?:_(alpha|beta||pre|rc|p)(\d*))?(?:-r(\d+))?$/);
350 - my (@na) = split /\.|(?<=\d)(?=[^\d\.])/, $na;
351 - my (@nb) = split /\.|(?<=\d)(?=[^\d\.])/, $nb;
352 - my $retval;
353 + my ($a, $b) = @_;
354 + (my $va = $a) =~ s/.*?-(\d.*?)(?:\.ebuild)?$/$1/;
355 + (my $vb = $b) =~ s/.*?-(\d.*?)(?:\.ebuild)?$/$1/;
356 + my ($na, $sa, $sna, $ra) = ($va =~ /^(.*?)(?:_(alpha|beta||pre|rc|p)(\d*))?(?:-r(\d+))?$/);
357 + my ($nb, $sb, $snb, $rb) = ($vb =~ /^(.*?)(?:_(alpha|beta||pre|rc|p)(\d*))?(?:-r(\d+))?$/);
358 + my (@na) = split /\.|(?<=\d)(?=[^\d\.])/, $na;
359 + my (@nb) = split /\.|(?<=\d)(?=[^\d\.])/, $nb;
360 + my $retval;
361
362 - #
363 - # compare version numbers first
364 - #
365 - for (my $i = 0; defined $na[$i] or defined $nb[$i]; $i++) {
366 - # def vs. undef
367 - return +1 if defined $na[$i] and !defined $nb[$i];
368 - return -1 if defined $nb[$i] and !defined $na[$i];
369 + #
370 + # compare version numbers first
371 + #
372 + for (my $i = 0; defined $na[$i] or defined $nb[$i]; $i++) {
373 + # def vs. undef
374 + return +1 if defined $na[$i] and !defined $nb[$i];
375 + return -1 if defined $nb[$i] and !defined $na[$i];
376
377 - # num vs. num
378 - if ($na[$i] =~ /^\d/ and $nb[$i] =~ /^\d/) {
379 - $retval = ($na[$i] <=> $nb[$i]);
380 - return $retval if $retval;
381 - next;
382 - }
383 + # num vs. num
384 + if ($na[$i] =~ /^\d/ and $nb[$i] =~ /^\d/) {
385 + $retval = ($na[$i] <=> $nb[$i]);
386 + return $retval if $retval;
387 + next;
388 + }
389
390 - # char vs. char
391 - if ($na[$i] =~ /^\D/ and $nb[$i] =~ /^\D/) {
392 - $retval = ($na[$i] cmp $nb[$i]);
393 - return $retval if $retval;
394 - next;
395 - }
396 + # char vs. char
397 + if ($na[$i] =~ /^\D/ and $nb[$i] =~ /^\D/) {
398 + $retval = ($na[$i] cmp $nb[$i]);
399 + return $retval if $retval;
400 + next;
401 + }
402
403 - # num vs. char
404 - $retval = ($na[$i] =~ /\d/ and -1 or +1);
405 - return $retval;
406 - }
407 + # num vs. char
408 + $retval = ($na[$i] =~ /\d/ and -1 or +1);
409 + return $retval;
410 + }
411
412 - #
413 - # compare suffix second
414 - #
415 - if (defined $sa and !defined $sb) {
416 - return +2 if $sa eq "p";
417 - return -2;
418 - }
419 - if (defined $sb and !defined $sa) {
420 - return -3 if $sb eq "p";
421 - return +3;
422 - }
423 + #
424 + # compare suffix second
425 + #
426 + if (defined $sa and !defined $sb) {
427 + return +2 if $sa eq "p";
428 + return -2;
429 + }
430 + if (defined $sb and !defined $sa) {
431 + return -3 if $sb eq "p";
432 + return +3;
433 + }
434
435 - if (defined $sa) { # and defined $sb
436 - $retval = ($sa cmp $sb);
437 - if ($retval) {
438 - return +4 if $sa eq "p";
439 - return -4 if $sb eq "p";
440 - return $retval; # suffixes happen to be alphabetical order, mostly
441 - }
442 + if (defined $sa) { # and defined $sb
443 + $retval = ($sa cmp $sb);
444 + if ($retval) {
445 + return +4 if $sa eq "p";
446 + return -4 if $sb eq "p";
447 + return $retval; # suffixes happen to be alphabetical order, mostly
448 + }
449
450 - # compare suffix number
451 - return +5 if defined $sna and !defined $snb;
452 - return -5 if defined $snb and !defined $sna;
453 - if (defined $sna) { # and defined $snb
454 - $retval = ($sna <=> $snb);
455 - return $retval if $retval;
456 - }
457 - }
458 + # compare suffix number
459 + return +5 if defined $sna and !defined $snb;
460 + return -5 if defined $snb and !defined $sna;
461 +
462 + if (defined $sna) { # and defined $snb
463 + $retval = ($sna <=> $snb);
464 + return $retval if $retval;
465 + }
466 + }
467
468 - #
469 - # compare rev third
470 - #
471 - return +6 if defined $ra and !defined $rb;
472 - return -6 if defined $rb and !defined $ra;
473 - if (defined $ra) { # and defined $rb
474 - return ($ra <=> $rb);
475 - }
476 + #
477 + # compare rev third
478 + #
479 + return +6 if defined $ra and !defined $rb;
480 + return -6 if defined $rb and !defined $ra;
481 +
482 + if (defined $ra) { # and defined $rb
483 + return ($ra <=> $rb);
484 + }
485
486 - #
487 - # nothing left to compare
488 - #
489 - return 0;
490 + #
491 + # nothing left to compare
492 + #
493 + return 0;
494 }
495 +
496 @files = sort sortfunc @files;
497
498 # Just to ensure we don't get duplicate entries.
499 sub mypush(\@@) {
500 - my $aref = shift;
501 + my $aref = shift;
502
503 - foreach my $value (@_) {
504 - push(@{$aref}, $value) if !grep(/^$value$/, @{$aref});
505 - }
506 + foreach my $value (@_) {
507 + push(@{$aref}, $value) if !grep(/^$value$/, @{$aref});
508 + }
509 }
510
511 # Forget ebuilds that only have changed copyrights, unless that's all
512 @@ -320,79 +337,79 @@
513 @files = grep !/\.ebuild$/, @files;
514
515 if (@ebuilds) {
516 - if ($vcs eq "git") {
517 - open C, $vcs{$vcs}{diff}." HEAD -- @ebuilds 2>&1 |" or die "Can't run: ".$vcs{$vcs}{diff}."$!\n";
518 - } else {
519 - open C, $vcs{$vcs}{diff}." @ebuilds 2>&1 |" or die "Can't run: ".$vcs{$vcs}{diff}."$!\n";
520 - }
521 + if ($vcs eq "git") {
522 + open C, $vcs{$vcs}{diff}." HEAD -- @ebuilds 2>&1 |" or die "Can't run: ".$vcs{$vcs}{diff}."$!\n";
523 + } else {
524 + open C, $vcs{$vcs}{diff}." @ebuilds 2>&1 |" or die "Can't run: ".$vcs{$vcs}{diff}."$!\n";
525 + }
526
527 - $_ = <C>;
528 + $_ = <C>;
529
530 - while (defined $_) {
531 - # only possible with cvs
532 - if (/^$vcs diff: (([^\/]*?)\.ebuild) was removed/) {
533 - mypush(@files, $1);
534 - }
535 + while (defined $_) {
536 + # only possible with cvs
537 + if (/^$vcs diff: (([^\/]*?)\.ebuild) was removed/) {
538 + mypush(@files, $1);
539 + }
540 + # We assume GNU diff output format here.
541 + # git format: diff --git a/app-doc/repodoc/metadata.xml b/app-doc/repodoc/metadata.xml
542 + elsif (/$vcs{$vcs}{regex}/) {
543 + my $f = $1;
544
545 - # We assume GNU diff output format here.
546 - # git format: diff --git a/app-doc/repodoc/metadata.xml b/app-doc/repodoc/metadata.xml
547 - elsif (/$vcs{$vcs}{regex}/) {
548 - my $f = $1;
549 + if ($vcs eq "git") {
550 + my $version = $2;
551 +
552 + while (<C>) {
553 + last if /^deleted file mode|^index/;
554 + if (/^new file mode/) {
555 + mypush(@files, $f);
556 + mypush(@new_versions, $version);
557 + last;
558 + }
559 + }
560 + }
561
562 - if ($vcs eq "git") {
563 - my $version = $2;
564 + # check if more than just copyright date changed.
565 + # skip some lines (vcs dependent)
566 + foreach(1..$vcs{$vcs}{skip}) {
567 + $_ = <C>;
568 + }
569
570 - while (<C>) {
571 - last if /^deleted file mode|^index/;
572 - if (/^new file mode/) {
573 - mypush(@files, $f);
574 - mypush(@new_versions, $version);
575 - last;
576 - }
577 - }
578 - }
579 + while (<C>) {
580 + last if /^[A-Za-z]/;
581 + if (/^[-+](?!# Copyright)/) {
582 + mypush(@files, $f);
583 + last;
584 + }
585 + }
586
587 - # check if more than just copyright date changed.
588 - # skip some lines (vcs dependent)
589 - foreach(1..$vcs{$vcs}{skip}) {
590 - $_ = <C>;
591 - }
592 + # at this point we've either added $f to @files or not,
593 + # and we have the next line in $_ for processing
594 + next;
595 + }
596 + elsif (/^$vcs.*?: (([^\/]*?)\.ebuild) is a new entry/) {
597 + mypush(@files, $1);
598 + mypush(@new_versions, $2);
599 + }
600
601 - while (<C>) {
602 - last if /^[A-Za-z]/;
603 - if (/^[-+](?!# Copyright)/) {
604 - mypush(@files, $f);
605 - last;
606 - }
607 - }
608 -
609 - # at this point we've either added $f to @files or not,
610 - # and we have the next line in $_ for processing
611 - next;
612 - }
613 - elsif (/^$vcs.*?: (([^\/]*?)\.ebuild) is a new entry/) {
614 - mypush(@files, $1);
615 - mypush(@new_versions, $2);
616 - }
617 -
618 - # other cvs output is ignored
619 - $_ = <C>;
620 - }
621 + # other cvs output is ignored
622 + $_ = <C>;
623 + }
624 }
625 close C;
626
627 # Subversion diff doesn't identify new versions. So use the status command
628 if (($vcs eq "svn") and (@ebuilds)) {
629 - open C, $vcs{$vcs}{status}." @ebuilds 2>&1 |" or die "Can't run: ".$vcs{$vcs}{status}."$!\n";
630 - $_ = <C>;
631 + open C, $vcs{$vcs}{status}." @ebuilds 2>&1 |" or die "Can't run: ".$vcs{$vcs}{status}."$!\n";
632 + $_ = <C>;
633
634 - while (defined $_) {
635 - if (/^A\s+\+?\s*(([^\s]*)\.ebuild)/) {
636 - mypush(@files, $1);
637 - mypush(@new_versions, $2);
638 - }
639 - $_ = <C>;
640 - }
641 + while (defined $_) {
642 + if (/^A\s+\+?\s*(([^\s]*)\.ebuild)/) {
643 + mypush(@files, $1);
644 + mypush(@new_versions, $2);
645 + }
646 +
647 + $_ = <C>;
648 + }
649 }
650
651 # When a package move occurs, the versions appear to be new even though they are
652 @@ -405,17 +422,19 @@
653
654 # Allow ChangeLog entries with no changed files, but give a fat warning
655 unless (@files) {
656 - print STDERR "**\n";
657 - print STDERR "** NOTE: No non-trivial changed files found. Normally echangelog\n";
658 - print STDERR "** should be run after all affected files have been added and/or\n";
659 - print STDERR "** modified. Did you forget to $vcs add?\n";
660 - print STDERR "**\n";
661 - if ($opt_strict) {
662 - print STDERR "** In strict mode, exiting\n";
663 - exit 1;
664 - }
665 - @files = sort sortfunc @trivial;
666 - @files = qw/ChangeLog/ unless @files; # last resort to put something in the list
667 + print STDERR "**\n";
668 + print STDERR "** NOTE: No non-trivial changed files found. Normally echangelog\n";
669 + print STDERR "** should be run after all affected files have been added and/or\n";
670 + print STDERR "** modified. Did you forget to $vcs add?\n";
671 + print STDERR "**\n";
672 +
673 + if ($opt_strict) {
674 + print STDERR "** In strict mode, exiting\n";
675 + exit 1;
676 + }
677 +
678 + @files = sort sortfunc @trivial;
679 + @files = qw/ChangeLog/ unless @files; # last resort to put something in the list
680 }
681
682 # sort
683 @@ -424,37 +443,41 @@
684
685 # Get the input from the cmdline, editor or stdin
686 if ($ARGV[0]) {
687 - $input = "@ARGV";
688 + $input = "@ARGV";
689 } else {
690 - # Testing for defined() allows ECHANGELOG_EDITOR='' to cancel EDITOR
691 - $editor = defined($ENV{'ECHANGELOG_EDITOR'}) ? $ENV{'ECHANGELOG_EDITOR'} :
692 - $ENV{'EDITOR'} || undef;
693 - if ($editor) {
694 - system("$editor ChangeLog.new");
695 - if ($? != 0) {
696 - # This usually happens when the editor got forcefully killed; and
697 - # the terminal is probably messed up: so we reset things.
698 - system('/usr/bin/stty sane');
699 - print STDERR "Editor died! Reverting to stdin method.\n";
700 - undef $editor;
701 - } else {
702 - if (open I, "<ChangeLog.new") {
703 - local $/ = undef;
704 - $input = <I>;
705 - close I;
706 - } else {
707 - print STDERR "Error opening ChangeLog.new: $!\n";
708 - print STDERR "Reverting to stdin method.\n";
709 - undef $editor;
710 - }
711 - unlink 'ChangeLog.new';
712 - }
713 - }
714 - unless ($editor) {
715 - print "Please type the log entry: use Ctrl-d to finish, Ctrl-c to abort...\n";
716 - local $/ = undef;
717 - $input = <>;
718 - }
719 + # Testing for defined() allows ECHANGELOG_EDITOR='' to cancel EDITOR
720 + $editor = defined($ENV{'ECHANGELOG_EDITOR'}) ? $ENV{'ECHANGELOG_EDITOR'} :
721 + $ENV{'EDITOR'} || undef;
722 +
723 + if ($editor) {
724 + system("$editor ChangeLog.new");
725 +
726 + if ($? != 0) {
727 + # This usually happens when the editor got forcefully killed; and
728 + # the terminal is probably messed up: so we reset things.
729 + system('/usr/bin/stty sane');
730 + print STDERR "Editor died! Reverting to stdin method.\n";
731 + undef $editor;
732 + } else {
733 + if (open I, "<ChangeLog.new") {
734 + local $/ = undef;
735 + $input = <I>;
736 + close I;
737 + } else {
738 + print STDERR "Error opening ChangeLog.new: $!\n";
739 + print STDERR "Reverting to stdin method.\n";
740 + undef $editor;
741 + }
742 +
743 + unlink 'ChangeLog.new';
744 + }
745 + }
746 +
747 + unless ($editor) {
748 + print "Please type the log entry: use Ctrl-d to finish, Ctrl-c to abort...\n";
749 + local $/ = undef;
750 + $input = <>;
751 + }
752 }
753 die "Empty entry; aborting\n" unless $input =~ /\S/;
754
755 @@ -465,18 +488,20 @@
756
757 # Prepend the user info to the input
758 unless ($user = $ENV{'ECHANGELOG_USER'}) {
759 - my ($fullname, $username) = (getpwuid($<))[6,0];
760 - $fullname =~ s/,.*//; # remove GECOS, bug 80011
761 - $user = sprintf "%s <%s\@gentoo.org>", $fullname, $username;
762 + my ($fullname, $username) = (getpwuid($<))[6,0];
763 + $fullname =~ s/,.*//; # remove GECOS, bug 80011
764 + $user = sprintf "%s <%s\@gentoo.org>", $fullname, $username;
765 }
766 +
767 # Make sure that we didn't get "root"
768 die "Please set ECHANGELOG_USER or run as non-root\n" if $user =~ /<root@/;
769 +
770 $date = strftime("%d %b %Y", gmtime);
771 $entry = "$date; $user ";
772 $entry .= join ', ', map "$actions{$_}$_", @files;
773 $entry .= ':';
774 -$entry = Text::Wrap::fill(' ', ' ', $entry); # does not append a \n
775 -$entry .= "\n$input"; # append user input
776 +$entry = Text::Wrap::fill(' ', ' ', $entry); # does not append a \n
777 +$entry .= "\n$input"; # append user input
778
779 # Each one of these regular expressions will eat the whitespace
780 # leading up to the next entry (except the two-space leader on the
781 @@ -484,45 +509,49 @@
782 # double carriage-return. This helps to normalize the spacing in
783 # the ChangeLogs.
784 if (@new_versions) {
785 - # Insert at the top with a new version marker
786 - $text =~ s/^( .*? ) # grab header
787 - \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
788 - /"$1\n\n" .
789 - join("\n", map "*$_ ($date)", reverse @new_versions) .
790 - "\n\n$entry\n\n"/sxe
791 - or die "Failed to insert new entry (4)\n";
792 + # Insert at the top with a new version marker
793 + $text =~ s/^( .*? ) # grab header
794 + \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
795 + /"$1\n\n" .
796 + join("\n", map "*$_ ($date)", reverse @new_versions) .
797 + "\n\n$entry\n\n"/sxe
798 + or die "Failed to insert new entry (4)\n";
799 } else {
800 - # Changing an existing patch or ebuild, no new version marker
801 - # required
802 - $text =~ s/^( .*? ) # grab header
803 - \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
804 - /$1\n\n$entry\n\n/sx
805 - or die "Failed to insert new entry (3)\n";
806 + # Changing an existing patch or ebuild, no new version marker
807 + # required
808 + $text =~ s/^( .*? ) # grab header
809 + \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
810 + /$1\n\n$entry\n\n/sx
811 + or die "Failed to insert new entry (3)\n";
812 }
813
814 sub update_cat_pn {
815 - my ($t) = @_;
816 - my ($cwd) = getcwd();
817 - $cwd =~ m|.*/(\w+-\w+\|virtual)/([^/]+)|
818 - or die "Can't figure out category/package.. sorry!\n";
819 - my ($category, $package_name) = ($1, $2);
820 - $t =~ s/^(# ChangeLog for).*/$1 $category\/$package_name/;
821 - return $t;
822 + my ($t) = @_;
823 + my ($cwd) = getcwd();
824 +
825 + $cwd =~ m|.*/(\w+-\w+\|virtual)/([^/]+)|
826 + or die "Can't figure out category/package.. sorry!\n";
827 + my ($category, $package_name) = ($1, $2);
828 + $t =~ s/^(# ChangeLog for).*/$1 $category\/$package_name/;
829 +
830 + return $t;
831 }
832
833 # New packages and/or ones that have moved around often have stale data here.
834 # But only do that in places where ebuilds are around (as echangelog can be
835 # used in profiles/ and such places).
836 if (grep(/\.ebuild$/, @files)) {
837 - $text = update_cat_pn($text);
838 + $text = update_cat_pn($text);
839 }
840
841 sub update_copyright {
842 - my ($t) = @_;
843 - (my $year = $date) =~ s/.* //;
844 - $t =~ s/^# Copyright \d+(?= )/$&-$year/m or
845 - $t =~ s/^(# Copyright) \d+-(\d+)/$1 1999-$year/m;
846 - return $t;
847 + my ($t) = @_;
848 + (my $year = $date) =~ s/.* //;
849 +
850 + $t =~ s/^# Copyright \d+(?= )/$&-$year/m or
851 + $t =~ s/^(# Copyright) \d+-(\d+)/$1 1999-$year/m;
852 +
853 + return $t;
854 }
855
856 # Update the copyright year in the ChangeLog
857 @@ -537,25 +566,26 @@
858 # copyright lines on ebuilds that haven't changed. I verified this with an IP
859 # lawyer.
860 for my $e (grep /\.ebuild$/, @files) {
861 - if (-s $e) {
862 - my ($etext, $netext);
863 - open E, "<$e" or warn("Can't read $e to update copyright year\n"), next;
864 - { local $/ = undef; $etext = <E>; }
865 - close E;
866 + if (-s $e) {
867 + my ($etext, $netext);
868
869 - # Attempt the substitution and compare
870 - $netext = update_copyright($etext);
871 - next if $netext eq $etext; # skip this file if no change.
872 + open E, "<$e" or warn("Can't read $e to update copyright year\n"), next;
873 + { local $/ = undef; $etext = <E>; }
874 + close E;
875
876 - # Write the new ebuild
877 - open E, ">$e.new" or warn("Can't open $e.new\n"), next;
878 - print E $netext and
879 - close E or warn("Can't write $e.new\n"), next;
880 + # Attempt the substitution and compare
881 + $netext = update_copyright($etext);
882 + next if $netext eq $etext; # skip this file if no change.
883
884 - # Move things around and show the diff
885 - system "diff -U 0 $e $e.new";
886 - rename "$e.new", $e or warn("Can't rename $e.new: $!\n");
887 - }
888 + # Write the new ebuild
889 + open E, ">$e.new" or warn("Can't open $e.new\n"), next;
890 + print E $netext and
891 + close E or warn("Can't write $e.new\n"), next;
892 +
893 + # Move things around and show the diff
894 + system "diff -U 0 $e $e.new";
895 + rename "$e.new", $e or warn("Can't rename $e.new: $!\n");
896 + }
897 }
898
899 # Move things around and show the ChangeLog diff
900 @@ -563,18 +593,18 @@
901 rename 'ChangeLog.new', 'ChangeLog' or die "Can't rename ChangeLog.new: $!\n";
902
903 # Okay, now we have a starter ChangeLog to work with.
904 -# The text will be added just like with any other ChangeLog below.
905 +# The text will be added just like with any other ChangeLog below.
906 # Add the new ChangeLog to vcs before continuing.
907 if ($vcs eq "cvs") {
908 - if (open F, "CVS/Entries") {
909 - system("cvs -f add ChangeLog") unless (scalar grep /^\/ChangeLog\//, <F>);
910 - }
911 + if (open F, "CVS/Entries") {
912 + system("cvs -f add ChangeLog") unless (scalar grep /^\/ChangeLog\//, <F>);
913 + }
914 } elsif ($vcs eq "svn") {
915 - if (open F, ".svn/entries") {
916 - system("svn add ChangeLog") unless (scalar grep /ChangeLog/, <F>);
917 - }
918 + if (open F, ".svn/entries") {
919 + system("svn add ChangeLog") unless (scalar grep /ChangeLog/, <F>);
920 + }
921 } else {
922 - system("$vcs{$vcs}{add} ChangeLog 2>&1 >> /dev/null");
923 + system("$vcs{$vcs}{add} ChangeLog 2>&1 >> /dev/null");
924 }
925
926 -# vim:sw=4 ts=4 expandtab
927 +# vim: set ts=4 sw=4 tw=0:
928
929 Modified: trunk/src/echangelog/test/TEST.pm
930 ===================================================================
931 --- trunk/src/echangelog/test/TEST.pm 2009-04-29 10:54:15 UTC (rev 553)
932 +++ trunk/src/echangelog/test/TEST.pm 2009-04-29 12:35:23 UTC (rev 554)
933 @@ -1,19 +1,5 @@
934 -#
935 -#===============================================================================
936 -#
937 -# FILE: POSIX.pm
938 -#
939 -# DESCRIPTION:
940 -#
941 -# FILES: ---
942 -# BUGS: ---
943 -# NOTES: ---
944 -# AUTHOR: YOUR NAME (),
945 -# COMPANY:
946 -# VERSION: 1.0
947 -# CREATED: 04/28/2009 01:24:13 PM
948 -# REVISION: ---
949 -#===============================================================================
950 +# We just return a static/predefined date because we're working with
951 +# static md5 checksums.
952
953 package TEST;
954
955
956 Modified: trunk/src/echangelog/test/templates/test.patch
957 ===================================================================
958 --- trunk/src/echangelog/test/templates/test.patch 2009-04-29 10:54:15 UTC (rev 553)
959 +++ trunk/src/echangelog/test/templates/test.patch 2009-04-29 12:35:23 UTC (rev 554)
960 @@ -1,6 +1,6 @@
961 ---- test.patch2 2009-04-28 14:13:26.171225175 +0200
962 +--- test.patch 2009-04-28 14:13:26.171225175 +0200
963 +++ test.patch 2009-04-28 14:12:26.246497830 +0200
964 @@ -0,0 +1,3 @@
965 +This is just an example.
966 -+Its used for serveral echangelog tests.
967 ++Its used for several echangelog tests.
968 +