sub runcmd {
debugcmd "+",@_;
- $!=0; $?=0;
+ $!=0; $?=-1;
failedcmd @_ if system @_;
}
my @cmd = (@git, qw(config -z --get-regexp .*));
debugcmd "|",@cmd;
- open GITS, "-|", @cmd or failedcmd @cmd;
+ open GITS, "-|", @cmd or die $!;
while (<GITS>) {
chomp or die;
printdebug "=> ", (messagequote $_), "\n";
" set -e; cd ".access_cfg('git-path').";".
" if test -d $package.git; then echo 1; else echo 0; fi");
my $r= cmdoutput @cmd;
- if ($r =~ m/^divert (\w+)$/) {
+ if (defined $r and $r =~ m/^divert (\w+)$/) {
my $divert=$1;
my ($usedistro,) = access_distros();
# NB that if we are pushing, $usedistro will be $distro/push
progress "diverting to $divert (using config for $instead_distro)";
return check_for_git();
}
- failedcmd @cmd unless $r =~ m/^[01]$/;
+ failedcmd @cmd unless defined $r and $r =~ m/^[01]$/;
return $r+0;
} elsif ($how eq 'url') {
my $prefix = access_cfg('git-check-url','git-url');
sub remove_stray_gits () {
my @gitscmd = qw(find -name .git -prune -print0);
debugcmd "|",@gitscmd;
- open GITS, "-|", @gitscmd or failedcmd @gitscmd;
+ open GITS, "-|", @gitscmd or die $!;
{
local $/="\0";
while (<GITS>) {
my @cmd = (@git, qw(diff --quiet HEAD));
debugcmd "+",@cmd;
- $!=0; $?=0; system @cmd;
- return if !$! && !$?;
- if (!$! && $?==256) {
+ $!=0; $?=-1; system @cmd;
+ return if !$?;
+ if ($?==256) {
fail "working tree is dirty (does not match HEAD)";
} else {
failedcmd @cmd;
my $format = getfield $dsc, 'Format';
printdebug "format $format\n";
+ my $head = git_rev_parse('HEAD');
+
if (madformat($format)) {
# user might have not used dgit build, so maybe do this now:
commit_quilty_patch();
my $diffopt = $debuglevel>0 ? '--exit-code' : '--quiet';
my @diffcmd = (@git, qw(diff), $diffopt, $tree);
debugcmd "+",@diffcmd;
- $!=0; $?=0;
+ $!=0; $?=-1;
my $r = system @diffcmd;
if ($r) {
if ($r==256) {
failedcmd @diffcmd;
}
}
- my $head = git_rev_parse('HEAD');
if (!$changesfile) {
my $pat = changespat $cversion;
my @cs = glob "$buildproductsdir/$pat";
sub quilt_check_splitbrain_cache ($$) {
my ($headref, $upstreamversion) = @_;
- # Checks to see if we are in (potentially) split brain mode.
- # If so, computes the cache key and looks in the cache.
- # If split brain is not applicable, returns (undef,0).
- # Otherwise returns ($cachekey,HIT) where
- # HIT=0: miss; HIT=1: hit, needs different commit; HIT=2: same commit OK
-
- quilt_make_fake_dsc($upstreamversion);
-
- return (undef,0) unless quiltmode_splitbrain();
+ # Called only if we are in (potentially) split brain mode.
+ # Called in $ud.
+ # Computes the cache key and looks in the cache.
+ # Returns ($dgit_view_commitid, $cachekey) or (undef, $cachekey)
my $splitbrain_cachekey;
progress
- "dgit: split brain (separate dgit view) may needed (--quilt=$quilt_mode).";
+ "dgit: split brain (separate dgit view) may be needed (--quilt=$quilt_mode).";
# we look in the reflog of dgit-intern/quilt-cache
# we look for an entry whose message is the key for the cache lookup
my @cachekey = (qw(dgit), $our_version);
my $srcshash = Digest::SHA->new(256);
my %sfs = ( %INC, '$0(dgit)' => $0 );
foreach my $sfk (sort keys %sfs) {
+ next unless m/^\$0\b/ || m{^Debian/Dgit\b};
$srcshash->add($sfk," ");
$srcshash->add(hashfile($sfs{$sfk}));
$srcshash->add("\n");
progress "dgit view: found cached (commit id $cachehit)";
runcmd @git, qw(checkout -q -b dgit-view), $cachehit;
$split_brain = 1;
- return ($splitbrain_cachekey, 1);
+ return ($cachehit, $splitbrain_cachekey);
}
progress "dgit view: found cached, no changes required";
- return ($splitbrain_cachekey, 2);
+ return ($headref, $splitbrain_cachekey);
}
die $! if GC->error;
failedcmd unless close GC;
printdebug "splitbrain cache miss\n";
- return ($splitbrain_cachekey, 0);
+ return (undef, $splitbrain_cachekey);
}
sub quilt_fixup_multipatch ($$$) {
# afterwards with dpkg-source --before-build. That lets us save a
# tree object corresponding to .origs.
- my ($splitbrain_cachekey,$cachehit) =
- quilt_check_splitbrain_cache($headref, $upstreamversion);
+ my $splitbrain_cachekey;
+
+ quilt_make_fake_dsc($upstreamversion);
- return if $splitbrain_cachekey && $cachehit;
+ if (quiltmode_splitbrain()) {
+ my $cachehit;
+ ($cachehit, $splitbrain_cachekey) =
+ quilt_check_splitbrain_cache($headref, $upstreamversion);
+ return if $cachehit;
+ }
runcmd qw(sh -ec),
'exec dpkg-source --no-check --skip-patches -x fake.dsc >/dev/null';