3 # Integration between git and Debian-style archives
5 # Copyright (C)2013 Ian Jackson
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 use Dpkg::Control::Hash;
30 our $isuite = 'unstable';
38 our $existing_package = 'dpkg';
40 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
43 our (@dget) = qw(dget);
44 our (@dput) = qw(dput);
45 our (@debsign) = qw(debsign);
46 our (@sbuild) = qw(sbuild -A);
47 our (@dpkgbuildpackage) = qw(dpkg-buildpackage -i\.git/ -I.git);
48 our (@mergechanges) = qw(mergechanges -f);
51 our %opts_opt_map = ('dget' => \@dget,
53 'debsign' => \@debsign,
55 'dpkg-buildpackage' => \@dpkgbuildpackage,
56 'mergechanges' => \@mergechanges);
61 open DEBUG, ">/dev/null" or die $!;
63 our $remotename = 'dgit';
64 our $ourdscfield = 'Vcs-Dgit-Master';
65 our $branchprefix = 'dgit';
68 sub lbranch () { return "$branchprefix/$csuite"; }
69 my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
70 sub lref () { return "refs/heads/".lbranch(); }
71 sub lrref () { return "refs/remotes/$remotename/$csuite"; }
72 sub rrref () { return "refs/$branchprefix/$csuite"; }
79 sub dscfn ($) { return "${package}_$_[0].dsc"; }
83 sub fail { die "$us: @_\n"; }
85 sub badcfg { print STDERR "$us: invalid configuration: @_\n"; exit 12; }
87 sub no_such_package () {
88 print STDERR "$us: package $package does not exist in suite $isuite\n";
94 return "+".rrref().":".lrref();
101 $ua = LWP::UserAgent->new();
105 print "downloading $what...\n";
106 my $r = $ua->get(@_) or die $!;
107 $r->is_success or fail "failed to fetch $what: ".$r->status_line;
108 return $r->decoded_content();
111 our ($dscdata,$dscurl,$dsc);
115 my $intro = shift @_;
116 print $fh $intro or die $!;
120 if (s{['\\]}{\\$&}g || m{\s} || m{[^-_./0-9a-z]}i) {
121 print $fh " '$_'" or die $!;
123 print $fh " $_" or die $!;
126 print $fh "\n" or die $!;
130 { local ($!); printcmd \*STDERR, "$_[0]: failed command:", @_ or die $!; };
132 fail "failed to fork/exec: $!";
133 } elsif (!($? & 0xff)) {
134 fail "subprocess failed with error exit status ".($?>>8);
136 fail "subprocess crashed (wait status $?)";
138 fail "subprocess produced invalid output";
143 printcmd(\*DEBUG,"+",@_) if $debug>0;
145 failedcmd @_ if system @_;
150 print "dgit ok: @_\n";
152 print "would be ok: @_ (but dry run only)\n";
156 sub cmdoutput_errok {
157 die Dumper(\@_)." ?" if grep { !defined } @_;
158 printcmd(\*DEBUG,"|",@_) if $debug>0;
159 open P, "-|", @_ or die $!;
162 { local $/ = undef; $d = <P>; }
164 if (!close P) { print DEBUG "=>!$?\n" if $debug>0; return undef; }
167 print DEBUG "=> \`$&'",(length $' ? '...' : ''),"\n" if $debug>0; #';
172 my $d = cmdoutput_errok @_;
173 defined $d or failedcmd @_;
178 printcmd(\*STDOUT,"#",@_);
181 sub runcmd_ordryrun {
189 our $helpmsg = <<END;
191 dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
192 dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
193 dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
194 dgit [dgit-opts] push [dgit-opts] [suite]
195 important dgit options:
196 -k<keyid> sign tag and package with <keyid> instead of default
197 --dry-run -n do not change anything, but go through the motions
198 --new -N allow introducing a new package
199 --debug -D increase debug level
200 -c<name>=<value> set git config option (used directly by dgit too)
204 print STDERR "$us: @_\n", $helpmsg or die $!;
209 print $helpmsg or die $!;
213 our %defcfg = ('dgit.default.distro' => 'debian',
214 'dgit.default.username' => '',
215 'dgit.default.archive-query-default-component' => 'main',
216 'dgit.default.ssh' => 'ssh',
217 'dgit-distro.debian.git-host' => 'dgit.debian.net',
218 'dgit-distro.debian.git-proto' => 'git+ssh://',
219 'dgit-distro.debian.git-path' => '/git/dgit-repos',
220 'dgit-distro.debian.git-check' => 'ssh-cmd',
221 'dgit-distro.debian.git-create' => 'ssh-cmd',
222 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org',
223 'dgit-distro.debian.sshdakls-dir' =>
224 '/srv/ftp-master.debian.org/ftp/dists',
225 'dgit-distro.debian.mirror' => 'http://http.debian.net/debian/');
229 return undef if $c =~ /RETURN-UNDEF/;
230 my @cmd = (@git, qw(config --), $c);
233 local ($debug) = $debug-1;
234 $v = cmdoutput_errok @cmd;
241 my $dv = $defcfg{$c};
242 return $dv if defined $dv;
244 badcfg "need value for one of: @_";
247 sub access_distro () {
248 return cfg("dgit-suite.$isuite.distro",
249 "dgit.default.distro");
254 my $distro = $idistro || access_distro();
255 my $value = cfg(map { ("dgit-distro.$distro.$_",
256 "dgit.default.$_") } @keys);
260 sub access_someuserhost ($) {
262 my $user = access_cfg("$some-user",'username');
263 my $host = access_cfg("$some-host");
264 return length($user) ? "$user\@$host" : $host;
267 sub access_gituserhost () {
268 return access_someuserhost('git');
271 sub access_giturl () {
272 my $url = access_cfg('git-url','RETURN-UNDEF');
275 access_cfg('git-proto').
276 access_gituserhost().
277 access_cfg('git-path');
279 return "$url/$package.git";
282 sub parsecontrolfh ($$@) {
283 my ($fh, $desc, @opts) = @_;
284 my %opts = ('name' => $desc, @opts);
285 my $c = Dpkg::Control::Hash->new(%opts);
286 $c->parse($fh) or die "parsing of $desc failed";
291 my ($file, $desc) = @_;
292 my $fh = new IO::Handle;
293 open $fh, '<', $file or die "$file: $!";
294 my $c = parsecontrolfh($fh,$desc);
295 $fh->error and die $!;
301 my ($dctrl,$field) = @_;
302 my $v = $dctrl->{$field};
303 return $v if defined $v;
304 fail "missing field $field in ".$v->get_option('name');
308 my $c = Dpkg::Control::Hash->new();
309 my $p = new IO::Handle;
310 my @cmd = (qw(dpkg-parsechangelog));
311 open $p, '-|', @cmd or die $!;
313 $?=0; $!=0; close $p or failedcmd @cmd;
319 sub archive_query ($) {
321 my $query = access_cfg('archive-query','RETURN-UNDEF');
322 if (!defined $query) {
323 my $distro = access_distro();
324 if ($distro eq 'debian') {
325 $query = "sshdakls:".
326 access_someuserhost('sshdakls').':'.
327 access_cfg('sshdakls-dir');
329 $query = "madison:$distro";
332 $query =~ s/^(\w+):// or badcfg "invalid archive-query method \`$query'";
335 { no strict qw(refs); &{"${method}_${proto}"}($proto,$data); }
338 sub archive_query_madison ($$) {
339 my ($proto,$data) = @_;
340 die unless $proto eq 'madison';
341 $rmad{$package} ||= cmdoutput
342 qw(rmadison -asource),"-s$isuite","-u$data",$package;
343 my $rmad = $rmad{$package};
344 return madison_parse($rmad);
347 sub archive_query_sshdakls ($$) {
348 my ($proto,$data) = @_;
349 $data =~ s/:.*// or badcfg "invalid sshdakls method string \`$data'";
350 my $dakls = cmdoutput
351 access_cfg('ssh'), $data, qw(dak ls -asource),"-s$isuite",$package;
352 return madison_parse($dakls);
355 sub canonicalise_suite_sshdakls ($$) {
356 my ($proto,$data) = @_;
357 $data =~ m/:/ or badcfg "invalid sshdakls method string \`$data'";
359 (access_cfg('ssh'), $`,
361 " if test -h $isuite; then readlink $isuite; exit 0; fi;".
362 " if test -d $isuite; then echo $isuite; exit 0; fi;".
364 my $dakls = cmdoutput @cmd;
365 failedcmd @cmd unless $dakls =~ m/^\w/;
369 sub madison_parse ($) {
374 $rmad =~ m{^ \s*( [^ \t|]+ )\s* \|
375 \s*( [^ \t|]+ )\s* \|
376 \s*( [^ \t|/]+ )(?:/([^ \t|/]+))? \s* \|
377 \s*( [^ \t|]+ )\s* }x or die "$rmad $?";
378 $1 eq $package or die "$rmad $package ?";
385 $component = access_cfg('archive-query-default-component');
387 $5 eq 'source' or die "$rmad ?";
388 my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1);
389 my $subpath = "/pool/$component/$prefix/$package/${package}_$vsn.dsc";
390 return ($vsn,$subpath,$newsuite);
393 sub canonicalise_suite_madison ($$) {
394 my @r = archive_query_madison($_[0],$_[1]);
396 "unable to canonicalise suite using package $package".
397 " which does not appear to exist in suite $isuite;".
398 " --existing-package may help";
402 sub canonicalise_suite () {
403 $csuite = archive_query('canonicalise_suite');
404 if ($isuite ne $csuite) {
405 # madison canonicalises for us
406 print "canonical suite name for $isuite is $csuite\n";
410 sub get_archive_dsc () {
411 my ($vsn,$subpath) = archive_query('archive_query');
412 canonicalise_suite();
413 if (!defined $vsn) { $dsc=undef; return undef; }
414 $dscurl = access_cfg('mirror').$subpath;
415 $dscdata = url_get($dscurl);
416 my $dscfh = new IO::File \$dscdata, '<' or die $!;
417 print DEBUG Dumper($dscdata) if $debug>1;
418 $dsc = parsecontrolfh($dscfh,$dscurl, allow_pgp=>1);
419 print DEBUG Dumper($dsc) if $debug>1;
420 my $fmt = getfield $dsc, 'Format';
421 fail "unsupported source format $fmt, sorry" unless $format_ok{$fmt};
424 sub check_for_git () {
426 my $how = access_cfg('git-check');
427 if ($how eq 'ssh-cmd') {
429 (access_cfg('ssh'),access_gituserhost(),
430 " set -e; cd ".access_cfg('git-path').";".
431 " if test -d $package.git; then echo 1; else echo 0; fi");
432 my $r= cmdoutput @cmd;
433 failedcmd @cmd unless $r =~ m/^[01]$/;
436 badcfg "unknown git-check \`$how'";
440 sub create_remote_git_repo () {
441 my $how = access_cfg('git-create');
442 if ($how eq 'ssh-cmd') {
444 (access_cfg('ssh'),access_gituserhost(),
445 "set -e; cd ".access_cfg('git-path').";".
446 " mkdir -p $package.git;".
448 " if ! test -d objects; then git init --bare; fi");
450 badcfg "unknown git-create \`$how'";
454 our ($dsc_hash,$upload_hash);
456 our $ud = '.git/dgit/unpack';
464 sub mktree_in_ud_from_only_subdir () {
465 # changes into the subdir
468 $dirs[0] =~ m#^([^/]+)/\.$# or die;
470 chdir $dir or die "$dir $!";
472 die $! unless $!==&ENOENT;
473 runcmd qw(git init -q);
474 rmtree('.git/objects');
475 symlink '../../../../objects','.git/objects' or die $!;
476 runcmd @git, qw(add -Af);
477 my $tree = cmdoutput @git, qw(write-tree);
478 $tree =~ m/^\w+$/ or die "$tree ?";
483 my $field = $dsc->{'Checksums-Sha256'} || $dsc->{Files};
485 fail "missing both Checksums-Sha256 and Files in ".
486 $dsc->get_option('name');
488 m/^\w+ \d+ (\S+)$/ or
489 fail "could not parse .dsc Files/Checksums line \`$_'";
491 } grep m/\S/, split /\n/, $field;
494 sub is_orig_file ($) {
496 m/\.orig(?:-\w+)?\.tar\.\w+$/;
499 sub make_commit ($) {
501 return cmdoutput @git, qw(hash-object -w -t commit), $file;
504 sub generate_commit_from_dsc () {
508 foreach my $f (dsc_files()) {
509 die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
511 link "../../../$f", $f
515 runcmd @dget, qw(--), $dscurl;
516 foreach my $f (grep { is_orig_file($_) } @files) {
517 link $f, "../../../../$f"
521 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
522 runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
523 my $clogp = parsecontrol('../changelog.tmp',"commit's changelog");
524 my $date = cmdoutput qw(date), '+%s %z', qw(-d), getfield($clogp,'Date');
525 my $author = getfield $clogp, 'Maintainer';
526 $author =~ s#,.*##ms;
527 my $authline = "$author $date";
528 $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
529 fail "unexpected commit author line format \`$authline'".
530 " (was generated from changelog Maintainer field)";
531 my $changes = getfield $clogp, 'Changes';
532 open C, ">../commit.tmp" or die $!;
533 print C <<END or die $!;
540 # imported from the archive
543 my $outputhash = make_commit qw(../commit.tmp);
544 my $cversion = getfield $clogp, 'Version';
545 print "synthesised git commit from .dsc $cversion\n";
547 runcmd @git, qw(reset --hard), $upload_hash;
548 runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
549 my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
550 my $oversion = getfield $oldclogp, 'Version';
552 version_compare_string($oversion, $cversion);
554 # git upload/ is earlier vsn than archive, use archive
555 open C, ">../commit2.tmp" or die $!;
556 print C <<END or die $!;
563 Record $package ($cversion) in archive suite $csuite
565 $outputhash = make_commit qw(../commit2.tmp);
566 } elsif ($vcmp > 0) {
567 print STDERR <<END or die $!;
568 Version actually in archive: $cversion (older)
569 Last allegedly pushed/uploaded: $oversion (newer or same)
570 Perhaps the upload is stuck in incoming. Using the version from git.
572 $outputhash = $upload_hash;
573 } elsif ($outputhash ne $upload_hash) {
574 fail "version in archive ($cversion)".
575 " is same as version in git".
576 " to-be-uploaded (upload/) branch ($oversion)".
577 " but archive version hash no commit hash?!";
580 chdir '../../../..' or die $!;
581 runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
582 'DGIT_ARCHIVE', $outputhash;
583 cmdoutput @git, qw(log -n2), $outputhash;
584 # ... gives git a chance to complain if our commit is malformed
589 sub ensure_we_have_orig () {
590 foreach my $f (dsc_files()) {
591 next unless is_orig_file($f);
593 die "$f ?" unless -f _;
595 die "$f $!" unless $!==&ENOENT;
597 my $origurl = $dscurl;
598 $origurl =~ s{/[^/]+$}{};
600 die "$f ?" unless $f =~ m/^${package}_/;
601 die "$f ?" if $f =~ m#/#;
602 runcmd_ordryrun qw(sh -ec),'cd ..; exec "$@"','x',
608 return cmdoutput @git, qw(rev-parse), "$_[0]~0";
611 sub is_fast_fwd ($$) {
612 my ($ancestor,$child) = @_;
613 my $mb = cmdoutput @git, qw(merge-base), $ancestor, $child;
614 return rev_parse($mb) eq rev_parse($ancestor);
617 sub git_fetch_us () {
618 badusage "cannot dry run with fetch" if $dryrun;
619 runcmd @git, qw(fetch),access_giturl(),fetchspec();
622 sub fetch_from_archive () {
623 # ensures that lrref() is what is actually in the archive,
625 get_archive_dsc() or return 0;
626 $dsc_hash = $dsc->{$ourdscfield};
627 if (defined $dsc_hash) {
628 $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'";
630 print "last upload to archive specified git hash\n";
632 print "last upload to archive has NO git hash\n";
635 my $lrref_fn = ".git/".lrref();
636 if (open H, $lrref_fn) {
639 die "$lrref_fn $upload_hash ?" unless $upload_hash =~ m/^\w+$/;
640 } elsif ($! == &ENOENT) {
645 print DEBUG "previous reference hash=$upload_hash\n";
647 if (defined $dsc_hash) {
648 fail "missing git history even though dsc has hash -".
649 " could not find commit $dsc_hash".
650 " (should be in ".access_giturl()."#".rref().")"
653 ensure_we_have_orig();
655 $hash = generate_commit_from_dsc();
657 print DEBUG "current hash=$hash\n";
659 fail "not fast forward on last upload branch!".
660 " (archive's version left in DGIT_ARCHIVE)"
661 unless is_fast_fwd($upload_hash, $hash);
663 if ($upload_hash ne $hash) {
664 my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
668 dryrun_report @upd_cmd;
676 canonicalise_suite();
677 badusage "dry run makes no sense with clone" if $dryrun;
678 mkdir $dstdir or die "$dstdir $!";
679 chdir "$dstdir" or die "$dstdir $!";
680 runcmd @git, qw(init -q);
681 runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
682 open H, "> .git/HEAD" or die $!;
683 print H "ref: ".lref()."\n" or die $!;
685 runcmd @git, qw(remote add), 'origin', access_giturl();
686 if (check_for_git()) {
687 print "fetching existing git history\n";
689 runcmd @git, qw(fetch origin);
691 print "starting new git history\n";
693 fetch_from_archive() or no_such_package;
694 runcmd @git, qw(reset --hard), lrref();
695 printdone "ready for work in $dstdir";
699 if (check_for_git()) {
702 fetch_from_archive() or no_such_package();
703 printdone "fetched into ".lrref();
708 runcmd_ordryrun @git, qw(merge -m),"Merge from $csuite [dgit]",
710 printdone "fetched to ".lrref()." and merged into HEAD";
713 sub check_not_dirty () {
714 my @cmd = (@git, qw(diff --quiet HEAD));
715 printcmd(\*DEBUG,"+",@cmd) if $debug>0;
716 $!=0; $?=0; system @cmd;
717 return if !$! && !$?;
718 if (!$! && $?==256) {
719 fail "working tree is dirty (does not match HEAD)";
725 sub commit_quilty_patch ($) {
727 my $output = cmdoutput @git, qw(status --porcelain);
728 my %fixups = map {$_=>1}
729 (".pc/debian-changes-$vsn/","debian/patches/debian-changes-$vsn");
731 foreach my $l (split /\n/, $output) {
732 next unless $l =~ s/^\?\? //;
733 next unless $fixups{$l};
736 print DEBUG "checking for quilty\n", Dumper(\@files);
738 my $m = "Commit Debian 3.0 (quilt) metadata";
740 runcmd_ordryrun @git, qw(add), @files;
741 runcmd_ordryrun @git, qw(commit -m), $m;
746 print DEBUG "actually entering push\n";
747 my $clogp = parsechangelog();
748 $package = getfield $clogp, 'Source';
749 my $cversion = getfield $clogp, 'Version';
750 my $dscfn = dscfn($cversion);
752 fail "looked for .dsc $dscfn, but $!;".
753 " maybe you forgot to build";
754 $dsc = parsecontrol("../$dscfn","$dscfn");
755 my $dscpackage = getfield $dsc, 'Source';
756 my $format = getfield $dsc, 'Format';
757 my $dversion = getfield $dsc, 'Version';
758 ($dscpackage eq $package && $dversion eq $cversion) or
759 fail "$dsc is for $dscpackage $dversion".
760 " but debian/changelog is for $package $cversion";
761 print DEBUG "format $format\n";
762 if ($format eq '3.0 (quilt)') {
763 print "Format \`$format', urgh\n";
764 commit_quilty_patch($dversion);
769 print "checking that $dscfn corresponds to HEAD\n";
770 runcmd qw(dpkg-source -x --), "../../../../$dscfn";
771 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
772 chdir '../../../..' or die $!;
773 printcmd \*DEBUG,"+",@_;
774 my @diffcmd = (@git, qw(diff --exit-code), $tree);
776 if (system @diffcmd) {
778 fail "$dscfn specifies a different tree to your HEAD commit;".
779 " perhaps you forgot to build";
785 #do fast forward check and maybe fake merge
786 # if (!is_fast_fwd(mainbranch
787 # runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
788 # map { lref($_).":".rref($_) }
790 $dsc->{$ourdscfield} = rev_parse('HEAD');
791 $dsc->save("../$dscfn.tmp") or die $!;
793 my $multi = "../${package}_${cversion}_multi.changes";
795 $changesfile = $multi;
797 $!==&ENOENT or die "$multi: $!";
798 my $pat = "${package}_${cversion}_*.changes";
799 my @cs = glob "../$pat";
800 fail "failed to find unique changes file".
801 " (looked for $pat in .., or $multi);".
802 " perhaps you need to use dgit -C"
804 ($changesfile) = @cs;
807 my $tag = debiantag($dversion);
808 if (!check_for_git()) {
809 create_remote_git_repo();
811 runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref();
813 rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
815 print "[new .dsc left in $dscfn.tmp]\n";
818 my @tag_cmd = (@git, qw(tag -s -m),
819 "Release $dversion for $csuite [dgit]");
820 push @tag_cmd, qw(-u),$keyid if defined $keyid;
822 runcmd_ordryrun @tag_cmd;
823 my @debsign_cmd = @debsign;
824 push @debsign_cmd, "-k$keyid" if defined $keyid;
825 push @debsign_cmd, $changesfile;
826 runcmd_ordryrun @debsign_cmd;
828 runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag";
829 my $host = access_cfg('upload-host','RETURN-UNDEF');
830 my @hostarg = defined($host) ? ($host,) : ();
831 runcmd_ordryrun @dput, @hostarg, $changesfile;
832 printdone "pushed and uploaded $dversion";
838 badusage "-p is not allowed with clone; specify as argument instead"
842 } elsif (@ARGV==2 && $ARGV[1] =~ m#^\w#) {
843 ($package,$isuite) = @ARGV;
844 } elsif (@ARGV==2 && $ARGV[1] =~ m#^[./]#) {
845 ($package,$dstdir) = @ARGV;
847 ($package,$isuite,$dstdir) = @ARGV;
849 badusage "incorrect arguments to dgit clone";
851 $dstdir ||= "$package";
856 my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
857 if ($branch =~ m#$lbranch_re#o) {
864 sub fetchpullargs () {
865 if (!defined $package) {
866 my $sourcep = parsecontrol('debian/control','debian/control');
867 $package = getfield $sourcep, 'Source';
870 # $isuite = branchsuite(); # this doesn't work because dak hates canons
872 my $clogp = parsechangelog();
873 $isuite = getfield $clogp, 'Distribution';
875 canonicalise_suite();
876 print "fetching from suite $csuite\n";
879 canonicalise_suite();
881 badusage "incorrect arguments to dgit fetch or dgit pull";
899 badusage "-p is not allowed with dgit push" if defined $package;
900 runcmd @git, qw(diff --quiet HEAD);
901 my $clogp = parsechangelog();
902 $package = getfield $clogp, 'Source';
904 $isuite = getfield $clogp, 'Distribution';
906 local ($package) = $existing_package; # this is a hack
907 canonicalise_suite();
910 badusage "incorrect arguments to dgit push";
912 if (fetch_from_archive()) {
913 is_fast_fwd(lrref(), 'HEAD') or die;
915 fail "package appears to be new in this suite;".
916 " if this is intentional, use --new";
922 # we pass further options and args to git-buildpackage
923 badusage "-p is not allowed with dgit build" if defined $package;
924 my $clogp = parsechangelog();
925 $isuite = getfield $clogp, 'Distribution';
926 $package = getfield $clogp, 'Source';
928 (qw(git-buildpackage -us -uc --git-no-sign-tags),
929 "--git-builder=@dpkgbuildpackage");
930 unless (grep { m/^--git-debian-branch/ } @ARGV) {
931 canonicalise_suite();
932 push @cmd, "--git-debian-branch=".lbranch();
934 runcmd_ordryrun @cmd, @ARGV;
935 printdone "build successful\n";
940 badusage "-p is not allowed with dgit sbuild" if defined $package;
941 my $clogp = parsechangelog();
942 $package = getfield $clogp, 'Source';
943 my $isuite = getfield $clogp, 'Distribution';
944 my $version = getfield $clogp, 'Version';
945 runcmd_ordryrun (@dpkgbuildpackage, qw(-us -uc -S));
946 chdir ".." or die $!;
947 my $sourcechanges = "${package}_${version}_source.changes";
948 my $dscfn = dscfn($version);
949 my $pat = "${package}_${version}_*.changes";
951 stat $dscfn or fail "$dscfn (in parent directory): $!";
952 stat $sourcechanges or fail "$sourcechanges (in parent directory): $!";
953 foreach my $cf (glob $pat) {
954 next if $cf eq $sourcechanges;
955 unlink $cf or fail "remove $cf: $!";
958 runcmd_ordryrun @sbuild, @ARGV, qw(-d), $isuite, $dscfn;
959 runcmd_ordryrun @mergechanges, glob $pat;
960 my $multichanges = "${package}_${version}_multi.changes";
962 stat $multichanges or fail "$multichanges: $!";
964 printdone "build successful, results in $multichanges\n" or die $!;
967 sub cmd_quilt_fixup {
968 badusage "incorrect arguments to dgit quilt-fixup";
969 my $clogp = parsechangelog();
970 commit_quilty_patch((getfield $clogp, 'Version'));
976 last unless $ARGV[0] =~ m/^-/;
980 if (m/^--dry-run$/) {
982 } elsif (m/^--no-sign$/) {
984 } elsif (m/^--help$/) {
986 } elsif (m/^--new$/) {
988 } elsif (m/^--(\w+)=(.*)/s && ($om = $opts_opt_map{$1})) {
990 } elsif (m/^--(\w+):(.*)/s && ($om = $opts_opt_map{$1})) {
992 } elsif (m/^--existing-package=(.*)/s) {
993 $existing_package = $1;
994 } elsif (m/^--distro=(.*)/s) {
997 badusage "unknown long option \`$_'";
1003 } elsif (s/^-h/-/) {
1005 } elsif (s/^-D/-/) {
1006 open DEBUG, ">&STDERR" or die $!;
1008 } elsif (s/^-N/-/) {
1010 } elsif (s/^-c(.*=.*)//s) {
1011 push @git, '-c', $1;
1012 } elsif (s/^-d(.*)//s) {
1014 } elsif (s/^-C(.*)//s) {
1016 } elsif (s/^-k(.*)//s) {
1019 badusage "unknown short option \`$_'";
1027 print STDERR "DRY RUN ONLY\n" if $dryrun;
1029 print STDERR $helpmsg or die $!;
1032 my $cmd = shift @ARGV;
1034 { no strict qw(refs); &{"cmd_$cmd"}(); }