1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
#!/usr/bin/perl
=head1 NAME
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, svn, svk, arch, bzr or git
repository. It must be run in a cvs, svn, svk, arch, bzr or git 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, svn, svk, arch or git.
bzr does not yet support symbolic tags, so you will only get a normal
commit.
Note that svn/svk 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;
use File::Basename;
my $progname = basename($0);
sub usage {
print <<"EOT";
Usage: $progname [--release] [--message=text] [--noact] [--help ] [--version]
Generates a commit message based on new text in debian/changelog,
and commit the change to a package\'s repository.
--release Commit a release of the package.
--message=text Specify a commit message
--noact Dry run, no actual commits
--help This message
--version Version information
EOT
}
sub version {
print <<"EOF";
This is $progname, from the Debian devscripts package, version ###VERSION###
This code is copyright by Joey Hess <joeyh\@debian.org>, all rights reserved.
This program comes with ABSOLUTELY NO WARRANTY.
You are free to redistribute this code under the terms of the
GNU General Public License, version 2 or later.
EOF
}
my $release=0;
my $message;
my $noact=0;
if (! GetOptions(
"release" => \$release,
"message=s" => \$message,
"noact" => \$noact,
"help" => sub { usage(); exit 0; },
"version" => sub { version(); exit 0; },
)) {
die "Usage: debcommit [--release] [--message=text] [--noact]\n";
}
my $prog=getprog();
if (! -e "debian/changelog") {
die "debcommit: cannot find debian/changelog\n";
}
if ($release) {
open (C, "<debian/changelog") || die "debcommit: cannot read debian/changelog: $!";
my $top=<C>;
if ($top=~/UNRELEASED/) {
die "debcommit: debian/changelog says it's UNRELEASED\nTry running dch --release first\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";
}
elsif (-d "{arch}") {
# I don't think we can tell just from the working copy
# whether to use tla or baz, so try baz if it's available,
# otherwise fall back to tla.
if (system ("baz --version >/dev/null 2>&1") == 0) {
return "baz";
} else {
return "tla";
}
}
elsif (-d ".bzr") {
return "bzr";
}
elsif (-d ".git") {
return "git";
}
else {
# svk has no useful directories so try to run it.
my $svkpath=`svk info . 2>/dev/null| grep -i '^Depot Path:' | cut -d ' ' -f 2`;
if (length $svkpath) {
return "svk";
}
die "debcommit: not in a cvs, subversion, arch, bzr, git or svk working copy\n";
}
}
sub action {
my $prog=shift;
print $prog, " ",
join(" ", map { if (/[^-A-Za-z0-9]/) { "'$_'" } else { $_ } } @_), "\n";
return 1 if $noact;
return (system($prog, @_) != 0) ? 0 : 1;
}
sub commit {
my $message=shift;
if ($prog eq 'cvs' || $prog eq 'svn' || $prog eq 'svk' || $prog eq 'bzr') {
if (! action($prog, "commit", "-m", $message)) {
die "debcommit: commit failed\n";
}
}
elsif ($prog eq 'git') {
if (! action($prog, "commit", "-a", "-m", $message)) {
die "debcommit: commit failed\n";
}
}
elsif ($prog eq 'tla' || $prog eq 'baz') {
my $summary=$message;
$summary=~s/^((?:\* )?[^\n]{1,72})(?:(?:\s|\n).*|$)/$1/ms;
my @args;
if ($summary eq $message) {
$summary=~s/^\* //s;
@args=("-s", $summary);
} else {
$summary=~s/^\* //s;
@args=("-s", "$summary ...", "-L", $message);
}
if (! action($prog, "commit", @args)) {
die "debcommit: commit failed\n";
}
}
else {
die "debcommit: unknown program $prog";
}
}
sub tag {
my $tag=shift;
if ($prog eq 'svn' || $prog eq 'svk') {
my $svnpath=`svnpath`;
chomp $svnpath;
my $tagpath=`svnpath tags`;
chomp $tagpath;
if (! action($prog, "copy", $svnpath, "$tagpath/$tag",
"-m", "tagging version $tag")) {
if (! action($prog, "mkdir", $tagpath,
"-m", "create tag directory") ||
! action($prog, "copy", $svnpath, "$tagpath/$tag",
"-m", "tagging version $tag")) {
die "debcommit: failed tagging with $tag\n";
}
}
}
elsif ($prog eq 'cvs') {
$tag=~s/^[0-9]+://; # strip epoch
$tag=~tr/./_/; # mangle for cvs
$tag="debian_version_$tag";
if (! action("cvs", "tag", "-f", $tag)) {
die "debcommit: failed tagging with $tag\n";
}
}
elsif ($prog eq 'tla' || $prog eq 'baz') {
my $archpath=`archpath`;
chomp $archpath;
my $tagpath=`archpath releases--\Q$tag\E`;
chomp $tagpath;
my $subcommand;
if ($prog eq 'baz') {
$subcommand="branch";
} else {
$subcommand="tag";
}
if (! action($prog, $subcommand, $archpath, $tagpath)) {
die "debcommit: failed tagging with $tag\n";
}
}
elsif ($prog eq 'bzr') {
warn "No support for symbolic tags in bzr yet.\n";
}
elsif ($prog eq 'git') {
$tag=~s/^[0-9]+://; # strip epoch
$tag="debian_version_$tag";
if (! action($prog, "tag", $tag)) {
die "debcommit: failed tagging with $tag\n";
}
}
}
sub getmessage {
my $ret;
if ($prog eq 'cvs' || $prog eq 'svn' || $prog eq 'svk' ||
$prog eq 'tla' || $prog eq 'baz' || $prog eq 'bzr' || $prog eq 'git') {
$ret='';
my @diffcmd;
if ($prog eq 'tla' || $prog eq 'baz') {
@diffcmd = ($prog, 'file-diff');
} elsif ($prog eq 'git') {
@diffcmd = ('git-diff', '--cached');
} else {
@diffcmd = ($prog, 'diff');
}
open CHLOG, '-|', @diffcmd, 'debian/changelog'
or die "debcommit: cannot run $diffcmd[0]: $!\n";
foreach (<CHLOG>) {
next unless /^\+ /;
s/^\+ //;
next if /^\s*\[.*\]\s*$/; # maintainer name
$ret .= $_;
}
if (! length $ret) {
die "debcommit: unable to determine commit message using $prog\nTry using the -m flag.\n";
}
}
else {
die "debcommit: unknown program $prog";
}
chomp $ret;
return $ret;
}
=head1 LICENSE
GPL
=head1 AUTHOR
Joey Hess <joeyh@debian.org>
=cut
|