head	1.15;
access;
symbols
	RELEASE-1_4:1.14.0.2;
locks; strict;
comment	@# @;


1.15
date	2003.08.15.12.50.15;	author lanius;	state dead;
branches;
next	1.14;

1.14
date	2003.05.26.15.52.02;	author agriffis;	state Exp;
branches;
next	1.13;

1.13
date	2003.05.25.17.36.37;	author agriffis;	state Exp;
branches;
next	1.12;

1.12
date	2003.04.27.19.39.39;	author agriffis;	state Exp;
branches;
next	1.11;

1.11
date	2003.04.22.20.04.57;	author agriffis;	state Exp;
branches;
next	1.10;

1.10
date	2003.03.21.14.45.30;	author agriffis;	state Exp;
branches;
next	1.9;

1.9
date	2003.03.12.16.49.51;	author agriffis;	state Exp;
branches;
next	1.8;

1.8
date	2003.03.08.04.42.29;	author agriffis;	state Exp;
branches;
next	1.7;

1.7
date	2003.02.25.14.39.57;	author agriffis;	state Exp;
branches;
next	1.6;

1.6
date	2003.02.25.14.37.33;	author agriffis;	state Exp;
branches;
next	1.5;

1.5
date	2003.02.23.21.01.47;	author agriffis;	state Exp;
branches;
next	1.4;

1.4
date	2003.02.23.20.54.36;	author agriffis;	state Exp;
branches;
next	1.3;

1.3
date	2003.02.22.04.23.28;	author agriffis;	state Exp;
branches;
next	1.2;

1.2
date	2003.02.12.19.42.11;	author agriffis;	state Exp;
branches;
next	1.1;

1.1
date	2003.02.10.19.42.03;	author agriffis;	state Exp;
branches;
next	;


desc
@@


1.15
log
@moved to app-portage
@
text
@#!/usr/bin/perl -w
#
# echangelog: Update the ChangeLog for an ebuild.  For example:
#
#   $ echangelog 'Add ~alpha to KEYWORDS'
#   4a5,7
#   >   10 Feb 2003; Aron Griffis <agriffis@@gentoo.org> oaf-0.6.8-r1.ebuild :
#   >   Add ~alpha to KEYWORDS
#   >

use strict;
use POSIX qw(strftime getcwd setlocale);

# Fix bug 21022 by restricting to C locale
setlocale(&POSIX::LC_ALL, "C");

use Text::Wrap;
$Text::Wrap::columns = 79;
$Text::Wrap::unexpand = 0;

my @@files = ();
my ($input, $entry, $user, $date, $text, $version);
my %versions = ();

# Read the current ChangeLog
if (-f 'ChangeLog') {
    open I, '<ChangeLog' or die "Can't open ChangeLog for input: $!\n";
    { local $/ = undef; $text = <I>; }
    close I;
} else {
    # No ChangeLog here, maybe we should make one...
    if (<*.ebuild>) {
        open I, '<../../skel.ChangeLog' 
            or die "Can't open ../../skel.ChangeLog for input: $!\n";
        { local $/ = undef; $text = <I>; }
        close I;
        my ($cwd) = getcwd();
        $cwd =~ m|.*/(\w+-\w+)/([^/]+)| 
            or die "Can't figure out category/package.. sorry!\n";
        my ($category, $package_name) = ($1, $2);
        $text =~ s/^\*.*//ms;   # don't need the fake entry
        $text =~ s/<CATEGORY>/$category/;
        $text =~ s/<PACKAGE_NAME>/$package_name/;
        # Okay, now we have a starter ChangeLog to work with.
        # The entry will be added just like with any other ChangeLog.
    } else {
        die "This should be run in a directory with ebuilds...\n";
    }
}

# Figure out what has changed around here
open C, 'cvs diff --brief 2>&1 |' or die "Can't run cvs diff: $!\n";
while (<C>) {
    /ChangeLog/ and next;
	if (/^cvs.*?: (([^\/]*?)\.ebuild) was removed/) { 
		push @@files, $1;
		$versions{$2} = 0;	# existing ebuild that was removed
	}
    elsif (/^cvs.*?: (\S+) was removed/) {
		push @@files, $1;
		# existing file that has been removed
	}
	elsif (/^Index: (([^\/]*?)\.ebuild)\s*$/) { 
		push @@files, $1;
		$versions{$2} = 0;	# existing ebuild that has changed
	}
	elsif (/^Index: (\S+)/) {
		push @@files, $1;
		# existing file, but not an ebuild, so no %version entry
	}
	elsif (/^cvs.*?: (([^\/]*?)\.ebuild) is a new entry/) { 
		push @@files, $1;
		$versions{$2} = -1;	# new ebuild, will create a new entry
	}
	elsif (/^cvs.*?: (\S+) is a new entry/) {
        push @@files, $1;
		# new file, but not an ebuild, so no %version entry
	}
	# other cvs output is ignored
}
close C;
die "No changed files found (did you forget to cvs add?)\n" unless @@files;

# Get the input from the cmdline or stdin
if ($ARGV[0]) {
    $input = "@@ARGV";
} else {
    local $/ = undef;
    print "Please type the log entry, finish with ctrl-d\n";
    $input = <>;
}
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 each end after adding indentation below).
$input =~ s/^\s*(.*?)\s*\z/$1/s;  # trim whitespace
$input = Text::Wrap::fill('', '', $input) if ($input =~ /^.{80}/m);
$input =~ s/^/  /gm;        # add indentation

# Prepend the user info to the input
$user = $ENV{'ECHANGELOG_USER'} ||
        sprintf("%s <%s\@@gentoo.org>", (getpwuid($<))[6,0]);
# Make sure that we didn't get "root"
die "Please set ECHANGELOG_USER or run as non-root\n" if $user =~ / root@@/;
$date = strftime("%d %b %Y", localtime);
$entry = "$date; $user ";
$entry .= join ', ', grep !/files.digest|Manifest/, @@files;  # don't list digests
$entry .= ':';
$entry = Text::Wrap::fill('  ', '  ', $entry);  # does not append a \n
$entry .= "\n$input";                           # append user input

# Find the version that's highest in the file (or determine if we're
# adding a new version).  Note that existing ebuilds have version=0,
# new ebuilds have version=-1 to make them automatically rise to the
# top.
if (%versions) {
    for (keys %versions) {
        $versions{$_} = index $text, $_ unless $versions{$_};
    }
    $version = (sort { $versions{$a} <=> $versions{$b} } keys %versions)[0];
}

# Each one of these regular expressions will eat the whitespace
# leading up to the next entry (except the two-space leader on the
# front of a dated entry), so it needs to be replaced with a
# double carriage-return.  This helps to normalize the spacing in
# the ChangeLogs.
#
# NOTE: The first two branches here are disabled via '&& 0'
# because they use the new but unsanctioned ChangeLog format.
if (0 && !defined $version) { # <--- NOTE disabled via '0'
	# Changing a patch or something, not an ebuild, so put the entry
	# after the first *version line (really guessing)
	$text =~ s/^( \*.*? )             # find the *version line
				\s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
				/$1\n\n$entry\n\n/mx
		or die "Failed to insert new entry (1)\n";
} elsif (0 && $versions{$version} > -1) { # <--- NOTE disabled via '0'
	# Insert after the *version line
	$text =~ s/^( \*\Q$version\E )    # find the *version line = $1
				(?:\.|\.ebuild)?      # some poorly formed entries
				\s+ ( \(.*\) )        # (date) = $2
				\s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
				/$1 $2\n\n$entry\n\n/mx
		or die "Failed to insert new entry (2)\n";
} elsif (!defined $version || $versions{$version} > -1) {
	# Changing an existing patch or ebuild, no new version marker
	# required
	$text =~ s/^( .*? )				  # grab header
				\s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
				/$1\n\n$entry\n\n/sx
		or die "Failed to insert new entry (3)\n";
} else {
	# Insert at the top with a new version marker
	$text =~ s/^( .*? )				  # grab header
				\s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
				/$1\n\n*$version ($date)\n\n$entry\n\n/sx
		or die "Failed to insert new entry (4)\n";
}

# Write the new ChangeLog
open O, '>ChangeLog.new' or die "Can't open ChangeLog.new for output: $!\n";
print O $text            or die "Can't write ChangeLog.new: $!\n";
close O                  or die "Can't close ChangeLog.new: $!\n";

# Move things around
system 'diff -Nu ChangeLog ChangeLog.new';
rename 'ChangeLog.new', 'ChangeLog' or die "Can't rename: $!\n";
@


1.14
log
@fix bug 21022
@
text
@@


1.13
log
@fix bug 20491
@
text
@d12 4
a15 1
use POSIX qw(strftime getcwd);
@


1.12
log
@update echangelog and add man-page
@
text
@d56 1
a56 1
    if (/^cvs.*?: (\S+) was removed/) {
@


1.11
log
@update echangelog
@
text
@d120 30
a149 22
# Each one of these regular expressions will eat the whitespace 
# leading up to the next entry (excepting the two-space leader on the
# front of a dated entry), so it needs to be replaced with a double
# carriage-return.  This helps to normalize the spacing in the
# ChangeLogs.
if (!defined $version) {
    # Changing a patch or something, not an ebuild, so put the entry
    # after the first *version line (really guessing)
    $text =~ s/^( \*.*? )             # find the *version line
                \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
              /$1\n\n$entry\n\n/mx
        or die "Failed to insert new entry (1)\n";
    #$text =~ s/^(\*.*?)\s*\n(?=  \d|\*|\z)/$1\n\n$entry\n\n/m
} elsif ($versions{$version} > -1) {
    # Insert after the *version line
    $text =~ s/^( \*\Q$version\E )    # find the *version line = $1
                (?:\.|\.ebuild)?      # some poorly formed entries
                \s+ ( \(.*\) )        # (date) = $2
                \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
              /$1 $2\n\n$entry\n\n/mx
        or die "Failed to insert new entry (2)\n";
    #$text =~ s/^\*\Q$version\E\.?(?:ebuild)?\s.*\n/$&\n$entry\n/m 
d151 1
a151 1
    # Insert at the top with a new version marker
d153 3
a155 3
	            \s*\n(?=\ \ \d|\*|\z) # suck up trailing whitespace
			  /$1\n\n*$version ($date)\n\n$entry\n\n/sx
        or die "Failed to insert new entry (3)\n";
@


1.10
log
@echangelog update
@
text
@d104 1
a104 1
$entry .= join ', ', grep !/files.digest/, @@files;  # don't list digests
@


1.9
log
@echangelog update
@
text
@d100 2
@


1.8
log
@minor echangelog fixes
@
text
@d52 1
a52 1
	if (/^cvs server: (([^\/]*?)\.ebuild) was removed/) { 
d56 1
a56 1
    if (/^cvs server: (\S+) was removed/) {
d68 1
a68 1
	elsif (/^cvs server: (([^\/]*?)\.ebuild) is a new entry/) { 
d72 1
a72 1
	elsif (/^cvs server: (\S+) is a new entry/) {
@


1.7
log
@new echangelog
@
text
@d52 21
a72 1
    if (/^cvs server: (\S+) .*new entry/ || /^Index: (\S+)/) {
d74 3
a76 4
        if ($1 =~ /^([^\/]*?)\.ebuild$/) {
            $versions{$1} = -1;
        }
    }
d108 3
a110 1
# adding a new version).
d113 1
a113 1
        $versions{$_} = index $text, $_;
d142 3
a144 2
    # XXX Fix to use a regex similar to above
    $text =~ s/^(.*?)\n(?=\s)/$&\n*$version ($date)\n\n$entry\n/s
@


1.6
log
@fix echangelog bugs
@
text
@d15 1
a15 1
$Text::Wrap::columns = 77;
d75 1
a75 1
$input = Text::Wrap::fill('', '', $input) if ($input =~ /^.{78}/m);
@


1.5
log
@fix tabbing
@
text
@d13 1
d15 2
d19 1
a19 1
my ($entry, $user, $date, $text, $version);
d62 1
a62 1
# Get the entry from the cmdline or stdin
d64 1
a64 1
    $entry = "@@ARGV";
d68 1
a68 1
    $entry = <>;
d70 1
a70 1
die "Empty entry; aborting\n" unless $entry =~ /\S/;
d72 1
a72 1
# If there are any long lines, then wrap the entry at 76 chars
d74 3
a76 5
if ($entry =~ /^.{77}/m) {
    local $Text::Wrap::columns = 76;
    local $Text::Wrap::unexpand = 0;
    $entry = Text::Wrap::fill('', '', $entry);
}
d78 1
a78 1
# Prepend the user info to the entry
d82 5
a86 3
$entry =~ s/^\s*(.*?)\s*\z/$1/s; # trim whitespace
$entry = "$date; $user @@files :\n$entry";
$entry =~ s/^/  /gm;             # add indentation
d97 5
d104 4
a107 2
    # after the first *version line
    $text =~ s/^\*.*\n/$&\n$entry\n/m
d109 1
a109 3
    # If we were putting it at the top of the file, the following
    # regex would work well.
    # $text =~ s/^.*?\n(?=\s)/$&\n$entry\n/s;
d112 5
a116 2
    # Sometimes the version line includes . or even .ebuild
    $text =~ s/^\*\Q$version\E\.?(?:ebuild)?\s.*\n/$&\n$entry\n/m 
d118 1
d121 2
a122 1
    $text =~ s/^.*?\n(?=\s)/$&\n*$version ($date)\n\n$entry\n/s
@


1.4
log
@echangelog patches
@
text
@d97 1
a97 1
	$text =~ s/^\*.*\n/$&\n$entry\n/m
d99 3
a101 3
	# If we were putting it at the top of the file, the following
	# regex would work well.
	# $text =~ s/^.*?\n(?=\s)/$&\n$entry\n/s;
@


1.3
log
@fix a few bugs
@
text
@d13 1
d21 3
a23 3
	open I, '<ChangeLog' or die "Can't open ChangeLog for input: $!\n";
	{ local $/ = undef; $text = <I>; }
	close I;
d25 18
a42 18
	# No ChangeLog here, maybe we should make one...
	if (<*.ebuild>) {
		open I, '<../../skel.ChangeLog' 
			or die "Can't open ../../skel.ChangeLog for input: $!\n";
		{ local $/ = undef; $text = <I>; }
		close I;
		my ($cwd) = getcwd();
		$cwd =~ m|.*/(\w+-\w+)/([^/]+)| 
			or die "Can't figure out category/package.. sorry!\n";
		my ($category, $package_name) = ($1, $2);
		$text =~ s/^\*.*//ms;	# don't need the fake entry
		$text =~ s/<CATEGORY>/$category/;
		$text =~ s/<PACKAGE_NAME>/$package_name/;
		# Okay, now we have a starter ChangeLog to work with.
		# The entry will be added just like with any other ChangeLog.
	} else {
		die "This should be run in a directory with ebuilds...\n";
	}
d69 8
d96 6
a101 3
    # at the top of the file.
    $text =~ s/^.*?\n(?=\s)/$&\n$entry\n/s
        or die "Failed to insert new entry\n";
d104 1
a104 1
	# Sometimes the version line includes . or even .ebuild
d106 1
a106 1
        or die "Failed to insert new entry\n";
d110 1
a110 1
        or die "Failed to insert new entry\n";
@


1.2
log
@updated echangelog and ekeyword
@
text
@d12 1
a12 1
use POSIX qw(strftime);
d19 24
a42 3
open I, '<ChangeLog' or die "Can't open ChangeLog for input: $!\n";
{ local $/ = undef; $text = <I>; }
close I;
d56 1
a56 1
die "No changed files found\n" unless @@files;
d60 1
a60 1
    $entry = $ARGV[0];
d72 1
a72 1
$entry =~ s/^\s*(.*?)\s*\z/$1/;  # trim whitespace
d92 2
a93 1
    $text =~ s/^\*$version\s.*\n/$&\n$entry\n/m 
d107 1
a107 1
system 'diff -u ChangeLog ChangeLog.new';
@


1.1
log
@version 0.1.18: add ekeyword and echangelog
@
text
@d11 1
a11 1

d15 2
a16 1
my ($entry, $user, $date, $text);
d18 4
a21 1
die "No ChangeLog in this directory\n" unless -f 'ChangeLog';
d23 1
d29 3
a34 1

d37 1
a44 1

a45 2
$entry =~ s/^\s*(.*?)\s*$/$1/;  # trim whitespace
$entry =~ s/^/  /gm;            # add indentation
d47 1
a49 1

d51 12
d64 14
a77 3
open I, '<ChangeLog' or die "Can't open ChangeLog for input: $!\n";
{ local $/ = undef; $text = <I>; }
close I;
d79 1
d81 2
a82 3
$text =~ s/^.*?\n(?=\s)/$&\n  $date; $user @@files :\n$entry\n/s;
print O $text;
close O;
d84 2
a85 1
system 'diff ChangeLog ChangeLog.new';
@

