Package: devscripts
Version: 2.8.15
Severity: wishlist
Tags: patch

A while ago I mentioned my commit script and Julian expressed interest
in adding it to devscripts. Attached are two programs, debcommit and
svnpath. debcommit has been used by several people other than me, though
I just rewrote it in perl; svnpath is used by debcommit and is fairly
useful on its own.
-- 
see shy jo
#!/usr/bin/perl

=head1 NAME debcommit

debcommit - commit changes to a package

=head1 SYNOPSIS

debcommit [--release] [--message=text] [--noact]

=head1 DESCRIPTION

debcommit generates a commit message based on new text in debian/changelog,
and commits the change to a package's cvs or svn repository. It must be run
in a cvs or svn working copy for the package.

=head1 OPTIONS

=over 4

=item -r --release

Commit a release of the package. The version number is determined from
debian/changelog, and is used to tag the package in cvs or svn.

Note that svn tagging conventions vary, so debcommit uses
L<svnpath(1)> to determine where the tag should be placed in the
repository.

=item -m text --message test

Specify a commit message to use. Useful if the program cannot determine
a commit message on its own based on debian/changelog, or if you want to
override the default message.

=item -n --noact

Do not actually do anything, but do print the commands that would be run.

=over 4

=back

=cut

use warnings;
use strict;
use Getopt::Long;

my $release=0;
my $message;
my $noact=0;
if (! GetOptions(
        "release" => \$release,
        "message=s" => \$message,
        "noact" => \$noact,
)) {
        die "Usage: debcommit [--release] [--message=text] [--noact]\n";
}

my $prog=getprog();
if (! -e "debian/changelog") {
        die "cannot find debian/changelog\n";
}

if ($release) {
        open (C, "<debian/changelog") || die "cannot read debian/changelog: $!";
        my $top=<C>;
        if ($top=~/UNRELEASED/) {
                die "debian/changelog says it's UNRELEASED\n";
        }
        close C;

        my $version=`dpkg-parsechangelog | grep Version: | cut -f 2 -d ' '`;
        chomp $version;

        $message="releasing version $version" if ! defined $message;
        commit($message);
        tag($version);
}
else {
        $message=getmessage() if ! defined $message;
        commit($message);
}

sub getprog {
        if (-d ".svn") {
                return "svn";
        }
        elsif (-d "CVS") {
                return "CVS";
        }
        else {
                die "not in a cvs or subversion working copy\n";
        }
}

sub action {
        my $prog=shift;
        print $prog." ".join(" ", map { if (/[^-A-Za-z0-9]/) { "'$_'" } else { 
$_ } } @_)."\n";
        return 1 if $noact;
        if (system(@_) != 0) {
                return 0;
        }
        else {
                return 1;
        }
}

sub commit {
        my $message=shift;

        if ($prog eq 'cvs' || $prog eq 'svn') {
                if (! action($prog, "commit", "-m", $message)) {
                        die "commit failed\n";
                }
        }
        else {
                die "unknown program $prog";
        }
}

sub tag {
        my $tag=shift;

        if ($prog eq 'svn') {
                my $svnpath=`svnpath`;
                chomp $svnpath;
                my $tagpath=`svnpath tags`;
                chomp $tagpath;
                
                if (! action("svn", "copy", $svnpath, "$tagpath/$tag", "-m", 
"tagging version $tag") ||
                    ! action("svn", "mkdir", $tagpath) || # make tag subdir
                    ! action("svn", "copy", $svnpath, "$tagpath/$tag", "-m", 
"tagging version $tag")) {
                        die "failed tagging with $tag\n";
                }
        }
        elsif ($prog eq 'cvs') {
                $tag=~s/^[0-9]+://; # strip epoch
                $tag=~tr/./_/;      # mangle for cvs
                if (! action("cvs", "tag", "-f", $tag)) {
                        die "failed tagging with $tag\n";
                }
        }
}

sub getmessage {
        my $ret;

        if ($prog eq 'cvs' || $prog eq 'svn') {
                $ret='';
                foreach my $line (`$prog diff debian/changelog`) {
                        next unless $line=~/^\+  /;
                        $line=~s/^\+  //;
                        next if $line=~/^\s*\[.*\]\s*$/; # maintainer name
                        $ret.=$line;
                }
                
                if (! length $ret) {
                        die "Unable to determine commit message using 
$prog\nTry using the -m flag.\n";
                }
        }
        else {
                die "unknown program $prog";
        }

        chomp $ret;
        return $ret;
}

=head1 LICENSE

GPL

=head1 AUTHOR

Joey Hess <[EMAIL PROTECTED]>

=cut
#!/usr/bin/perl

=head1 NAME svnpath

svnpath - output svn url with support for tags and branches

=head1 SYNOPSIS

svnpath

svnpath tags

svnpath branches

svnpath trunk

=head1 DESCRIPTION

svnpath is intended to be run in a subversion working copy.

In its simplest usage, svnpath with no parameters outputs the svn url for
the repository associated with the working copy.

If a parameter is given, svnpath attempts to instead output the url that
would be used for the tags, branches, or trunk. This will only work if it's
run in the top-level directory that is subject to tagging or branching.

For example, if you want to tag what's checked into subversion as version
1.0, you could use a command like this:

  svn cp $(svnpath) $(svnpath tags)/1.0

That's much easier than using svn info to look up the repository url and
manually modifying it to derive the url to use for the tag, and typing in
something like this:

  svn cp svn+ssh://my.server.example/svn/project/trunk 
svn+ssh://my.server.example/svn/project/tags/1.0

svnpath uses a simple heuristic to convert between the trunk, tags, and
branches paths. It replaes the first occurance of "trunk", "tags", or
"branches" with the name of what you're looking for. This will work ok for
most typical subversion repository layouts.

If you have an atypical layout and it does not work, you can add a
~/.svnpath file. This file is perl code, which can modify the path in $url.
For example, the author uses this file:

 #!/usr/bin/perl
 # svnpath personal override file

 # For d-i I sometimes work from a full d-i tree branch. Remove that from
 # the path to get regular tags or branches directories.
 $url=~s!d-i/(rc|beta)[0-9]+/!!;
 $url=~s!d-i/sarge/!!;
 1

=cut
 
$ENV{LANG}="C";

my $wanted=shift;
my $path=shift;

if (length $path) {
        chdir $path || die "$path: unreadable\n";
}

our $url;
if (-d ".svn") {
        # Get the svn url of the current directory.
        $url = `svn info .| grep -i ^URL: | cut -d ' ' -f 2`;
}
else {
        # Try svk instead.
        $url = `svk info .| grep -i '^Depot Path:' | cut -d ' ' -f 2`;
}

if (! length $url) {
        die "cannot get url";
}

if (length $wanted) {
        # Now jut substitute into it.
        $url=~s!/(?:trunk|branches|tags)($|/)!/$wanted$1!;

        if (-e "$ENV{HOME}/.svnpath") {
                require "$ENV{HOME}/.svnpath";
        }
}

print $url;

=head1 LICENSE

GPL

=head1 AUTHOR

Joey Hess <[EMAIL PROTECTED]>

=cut

Attachment: signature.asc
Description: Digital signature

Reply via email to