From 60690f11257949161344ac1392b365179dc763de Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 16 Jul 2016 17:50:17 +0100 Subject: quilt innards: Break out quilt_check_splitbrain_cache (nfc) --- dgit | 134 +++++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 75 insertions(+), 59 deletions(-) diff --git a/dgit b/dgit index 97274e9..835366e 100755 --- a/dgit +++ b/dgit @@ -2992,6 +2992,78 @@ END close $fakedsc or die $!; } +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(); + + my $splitbrain_cachekey; + + progress + "dgit: split brain (separate dgit view) may 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); + push @cachekey, $upstreamversion; + push @cachekey, $quilt_mode; + push @cachekey, $headref; + + push @cachekey, hashfile('fake.dsc'); + + my $srcshash = Digest::SHA->new(256); + my %sfs = ( %INC, '$0(dgit)' => $0 ); + foreach my $sfk (sort keys %sfs) { + $srcshash->add($sfk," "); + $srcshash->add(hashfile($sfs{$sfk})); + $srcshash->add("\n"); + } + push @cachekey, $srcshash->hexdigest(); + $splitbrain_cachekey = "@cachekey"; + + my @cmd = (@git, qw(reflog), '--pretty=format:%H %gs', + $splitbraincache); + printdebug "splitbrain cachekey $splitbrain_cachekey\n"; + debugcmd "|(probably)",@cmd; + my $child = open GC, "-|"; defined $child or die $!; + if (!$child) { + chdir '../../..' or die $!; + if (!stat ".git/logs/refs/$splitbraincache") { + $! == ENOENT or die $!; + printdebug ">(no reflog)\n"; + exit 0; + } + exec @cmd; die $!; + } + while () { + chomp; + printdebug ">| ", $_, "\n" if $debuglevel > 1; + next unless m/^(\w+) (\S.*\S)$/ && $2 eq $splitbrain_cachekey; + + my $cachehit = $1; + quilt_fixup_mkwork($headref); + if ($cachehit ne $headref) { + progress "dgit view: found cached (commit id $cachehit)"; + runcmd @git, qw(checkout -q -b dgit-view), $cachehit; + $split_brain = 1; + return ($splitbrain_cachekey, 1); + } + progress "dgit view: found cached, no changes required"; + return ($splitbrain_cachekey, 2); + } + die $! if GC->error; + failedcmd unless close GC; + + printdebug "splitbrain cache miss\n"; + return ($splitbrain_cachekey, 0); +} + sub quilt_fixup_multipatch ($$$) { my ($clogp, $headref, $upstreamversion) = @_; @@ -3066,66 +3138,10 @@ sub quilt_fixup_multipatch ($$$) { # afterwards with dpkg-source --before-build. That lets us save a # tree object corresponding to .origs. - quilt_make_fake_dsc($upstreamversion); + my ($splitbrain_cachekey,$cachehit) = + quilt_check_splitbrain_cache($headref, $upstreamversion); - my $splitbrain_cachekey; - if (quiltmode_splitbrain()) { - progress - "dgit: split brain (separate dgit view) may 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); - push @cachekey, $upstreamversion; - push @cachekey, $quilt_mode; - push @cachekey, $headref; - - push @cachekey, hashfile('fake.dsc'); - - my $srcshash = Digest::SHA->new(256); - my %sfs = ( %INC, '$0(dgit)' => $0 ); - foreach my $sfk (sort keys %sfs) { - $srcshash->add($sfk," "); - $srcshash->add(hashfile($sfs{$sfk})); - $srcshash->add("\n"); - } - push @cachekey, $srcshash->hexdigest(); - $splitbrain_cachekey = "@cachekey"; - - my @cmd = (@git, qw(reflog), '--pretty=format:%H %gs', - $splitbraincache); - printdebug "splitbrain cachekey $splitbrain_cachekey\n"; - debugcmd "|(probably)",@cmd; - my $child = open GC, "-|"; defined $child or die $!; - if (!$child) { - chdir '../../..' or die $!; - if (!stat ".git/logs/refs/$splitbraincache") { - $! == ENOENT or die $!; - printdebug ">(no reflog)\n"; - exit 0; - } - exec @cmd; die $!; - } - while () { - chomp; - printdebug ">| ", $_, "\n" if $debuglevel > 1; - next unless m/^(\w+) (\S.*\S)$/ && $2 eq $splitbrain_cachekey; - - my $cachehit = $1; - quilt_fixup_mkwork($headref); - if ($cachehit ne $headref) { - progress "dgit view: found cached (commit id $cachehit)"; - runcmd @git, qw(checkout -q -b dgit-view), $cachehit; - $split_brain = 1; - return; - } - progress "dgit view: found cached, no changes required"; - return; - } - die $! if GC->error; - failedcmd unless close GC; - - printdebug "splitbrain cache miss\n"; - } + return if $splitbrain_cachekey && $cachehit; runcmd qw(sh -ec), 'exec dpkg-source --no-check --skip-patches -x fake.dsc >/dev/null'; -- cgit v1.2.3