On Wed, Aug 12, 2009 at 03:44:24PM +0200, Daniel Baumann wrote: > please add something like --begin that behaves the opposite of --append, > so that i can insert an entry on the top, instead of at the bottom.
Attached is a patch which implements most of the logic for a --prepend option. In my testing, it handles all of the multi-maintainer scenarios but still appends in the base case of a single-maintainer changelog. Man page updates are also lacking. -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega <[email protected]>
diff --git a/scripts/debchange.pl b/scripts/debchange.pl
index 6dc1793..8a83a4e 100755
--- a/scripts/debchange.pl
+++ b/scripts/debchange.pl
@@ -77,6 +77,8 @@ Usage: $progname [options] [changelog entry]
Options:
-a, --append
Append a new entry to the current changelog
+ -P, --prepend
+ Prepend a new entry to the current changelog
-i, --increment
Increase the Debian release number, adding a new changelog entry
-v <version>, --newversion=<version>
@@ -180,7 +182,7 @@ Options:
Display this help message and exit
--version
Display version information
- At most one of -a, -i, -e, -r, -v, -d, -n, --bin-nmu, -q, --qa, -s, --bpo, -l
+ At most one of -a, -P, -i, -e, -r, -v, -d, -n, --bin-nmu, -q, --qa, -s, --bpo, -l
(or their long equivalents) may be used.
With no options, one of -i or -a is chosen by looking for a .upload
file in the parent directory and checking its contents.
@@ -297,7 +299,7 @@ if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
# We use bundling so that the short option behaviour is the same as
# with older debchange versions.
my ($opt_help, $opt_version);
-my ($opt_i, $opt_a, $opt_e, $opt_r, $opt_v, $opt_b, $opt_d, $opt_D, $opt_u, $opt_force_dist);
+my ($opt_i, $opt_a, $opt_prepend, $opt_e, $opt_r, $opt_v, $opt_b, $opt_d, $opt_D, $opt_u, $opt_force_dist);
my ($opt_n, $opt_bn, $opt_qa, $opt_s, $opt_bpo, $opt_l, $opt_c, $opt_m, $opt_create, $opt_package, @closes);
my ($opt_news);
my ($opt_ignore, $opt_level, $opt_regex, $opt_noconf, $opt_empty);
@@ -307,6 +309,7 @@ GetOptions("help|h" => \$opt_help,
"version" => \$opt_version,
"i|increment" => \$opt_i,
"a|append" => \$opt_a,
+ "P|prepend" => \$opt_prepend,
"e|edit" => \$opt_e,
"r|release" => \$opt_r,
"create" => \$opt_create,
@@ -378,8 +381,8 @@ if (defined $opt_level) {
if (defined $opt_regex) { $check_dirname_regex = $opt_regex; }
# Only allow at most one non-help option
-fatal "Only one of -a, -i, -e, -r, -v, -d, -n/--nmu, --bin-nmu, -q/--qa, -s/--security, --bpo, -l/--local is allowed;\ntry $progname --help for more help"
- if ($opt_i?1:0) + ($opt_a?1:0) + ($opt_e?1:0) + ($opt_r?1:0) + ($opt_v?1:0) + ($opt_d?1:0) + ($opt_n?1:0) + ($opt_bn?1:0) + ($opt_qa?1:0) + ($opt_s?1:0) + ($opt_bpo?1:0) + ($opt_l?1:0) > 1;
+fatal "Only one of -a, -P, -i, -e, -r, -v, -d, -n/--nmu, --bin-nmu, -q/--qa, -s/--security, --bpo, -l/--local is allowed;\ntry $progname --help for more help"
+ if ($opt_i?1:0) + ($opt_a?1:0) + ($opt_prepend?1:0) + ($opt_e?1:0) + ($opt_r?1:0) + ($opt_v?1:0) + ($opt_d?1:0) + ($opt_n?1:0) + ($opt_bn?1:0) + ($opt_qa?1:0) + ($opt_s?1:0) + ($opt_bpo?1:0) + ($opt_l?1:0) > 1;
if ($opt_s) {
$opt_u = "high";
@@ -434,9 +437,10 @@ fatal "--package cannot be used when creating a NEWS file"
if $opt_package && $opt_news;
if ($opt_create) {
- if ($opt_a || $opt_i || $opt_e || $opt_r || $opt_b || $opt_n || $opt_bn ||
- $opt_qa || $opt_s || $opt_bpo || $opt_l || $opt_allow_lower) {
- warn "$progname warning: ignoring -a/-i/-e/-r/-b/--allow-lower-version/-n/--bin-nmu/-q/--qa/-s/--bpo/-l options with --create\n";
+ if ($opt_a || $opt_prepend || $opt_i || $opt_e || $opt_r || $opt_b ||
+ $opt_n || $opt_bn || $opt_qa || $opt_s || $opt_bpo || $opt_l ||
+ $opt_allow_lower) {
+ warn "$progname warning: ignoring -a/-P/-i/-e/-r/-b/--allow-lower-version/-n/--bin-nmu/-q/--qa/-s/--bpo/-l options with --create\n";
$warnings++;
}
if ($opt_package && $opt_d) {
@@ -717,10 +721,11 @@ if (! $opt_m) {
#####
-if ($opt_auto_nmu eq 'yes' and ! $opt_v and ! $opt_l and ! $opt_s and
+if ($opt_auto_nmu eq 'yes' and ! $opt_v and ! $opt_l and ! $opt_s and
! $opt_qa and ! $opt_bpo and ! $opt_bn and ! $opt_n and ! $opt_c and
! (exists $ENV{'CHANGELOG'} and length $ENV{'CHANGELOG'}) and
! $opt_create and ! $opt_a_passed and ! $opt_r and ! $opt_e and
+ ! $opt_prepend and
! ($opt_release_heuristic eq 'changelog' and
$changelog{'Distribution'} eq 'UNRELEASED' and ! $opt_i_passed)) {
@@ -853,7 +858,7 @@ if ($opt_news && !$opt_i && !$opt_a) {
# Are we going to have to figure things out for ourselves?
if (! $opt_i && ! $opt_v && ! $opt_d && ! $opt_a && ! $opt_e && ! $opt_r &&
! $opt_n && ! $opt_bn && ! $opt_qa && ! $opt_s && ! $opt_bpo &&
- ! $opt_l && ! $opt_create) {
+ ! $opt_l && ! $opt_create && ! $opt_prepend) {
# Yes, we are
if ($opt_release_heuristic eq 'log') {
my @UPFILES = glob("../$PACKAGE\_$SVERSION\_*.upload");
@@ -1134,7 +1139,7 @@ if (($opt_i || $opt_n || $opt_bn || $opt_qa || $opt_s || $opt_bpo || $opt_l || $
print O <S>;
}
}
-if (($opt_r || $opt_a || $merge) && ! $opt_create) {
+if (($opt_r || $opt_a || $opt_prepend || $merge) && ! $opt_create) {
# This means we just have to generate a new * entry in changelog
# and if a multi-developer changelog is detected, add developer names.
@@ -1146,8 +1151,8 @@ if (($opt_r || $opt_a || $merge) && ! $opt_create) {
# last entry, and determine whether there are existing
# multi-developer changes by the current maintainer.
$line=-1;
- my ($lastmaint, $nextmaint, $maintline, $count, $lastheader, $lastdist, $dist_indicator);
- my $savedline = $line;;
+ my ($lastmaint, $nextmaint, $maintline, $prependline, $count, $lastheader, $lastdist, $dist_indicator);
+ my $savedline = $line;
while (<S>) {
$line++;
# Start of existing changes by the current maintainer
@@ -1180,9 +1185,15 @@ if (($opt_r || $opt_a || $merge) && ! $opt_create) {
$lastmaint=$1;
# Remember where we are so we can skip back afterwards
$savedline = $line;
+ # No previous blocks for the current maintainer, so start before
+ # the end of the changelog block
+ $prependline ||= $line;
}
if (defined $maintline && !defined $nextmaint) {
+ if (/^ +\* \S/) {
+ $prependline ||= $line;
+ }
$maintline++;
}
}
@@ -1212,6 +1223,7 @@ if (($opt_r || $opt_a || $merge) && ! $opt_create) {
# changelog.
my $newchanges='';
$CHANGES=~s/^( .+)$/ [ $lastmaint ]\n$1/m;
+ $prependline++ if defined $prependline;
}
}
}
@@ -1247,19 +1259,24 @@ if (($opt_r || $opt_a || $merge) && ! $opt_create) {
$warnings++;
}
- if (defined $maintline && defined $nextmaint) {
+ if (defined $maintline && (defined $nextmaint || $opt_prepend)) {
# Output the lines up to the end of the current maintainer block
$count=1;
$line=$maintline;
foreach (split /\n/, $CHANGES) {
print O $_ . "\n";
+ # Stop early if the user requested prepending
+ if ($opt_prepend && $count==$prependline) {
+ $line=$prependline+1;
+ $maintline=$line;
+ }
$count++;
last if $count==$maintline;
}
} else {
# The first lines are as we have already found
print O $CHANGES;
- };
+ }
if (! $opt_r) {
# Add a multi-maintainer header...
@@ -1267,6 +1284,9 @@ if (($opt_r || $opt_a || $merge) && ! $opt_create) {
# ...unless there already is one for this maintainer.
if (!defined $maintline) {
print O "\n [ $MAINTAINER ]\n";
+ if ($opt_prepend) {
+ $line=$prependline;
+ }
$line+=2;
}
}
@@ -1292,7 +1312,7 @@ if (($opt_r || $opt_a || $merge) && ! $opt_create) {
}
}
- if ($opt_t && $opt_a) {
+ if ($opt_t && ($opt_a || $opt_prepend)) {
print O "\n -- $changelog{'Maintainer'} $changelog{'Date'}\n";
} else {
print O "\n -- $MAINTAINER <$EMAIL> $DATE\n";
signature.asc
Description: Digital signature
