diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2023-10-29 15:19:59 +0000 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2023-10-29 17:15:33 +0000 |
commit | ea3af8fd9ddbab3a2e83e712ced23daf5a07625e (patch) | |
tree | ba2df03eee48ef60195b6fb828552c617c84943f /dgit | |
parent | 7980fe62342b7bd95af1497e5eeae41cad25bef2 (diff) |
dgit: Break out import_r1authline and change variable plumbing
Move the dicey parts into their own function.
If there are no origs, or import_r1authline didn't obtain the top
changelog entry, just call parsechangelog.
No overall functional change.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'dgit')
-rwxr-xr-x | dgit | 111 |
1 files changed, 59 insertions, 52 deletions
@@ -2366,6 +2366,55 @@ sub dotdot_bpd_transfer_origs ($$$) { closedir DD; } +sub import_r1authline ($$) { + my ($clogp_r, $upstreamv) = @_; + my $r1clogp; + + my @clogcmd = qw(dpkg-parsechangelog --format rfc822 --all); + + printdebug "import clog search...\n"; + parsechangelog_loop \@clogcmd, (__ "package changelog"), sub { + my ($thisstanza, $desc) = @_; + no warnings qw(exiting); + + $$clogp_r //= $thisstanza; + + printdebug "import clog $thisstanza->{version} $desc...\n"; + + # We look for the first (most recent) changelog entry whose + # version number is lower than the upstream version of this + # package. Then the last (least recent) previous changelog + # entry is treated as the one which introduced this upstream + # version and used for the synthetic commits for the upstream + # tarballs. + + # One might think that a more sophisticated algorithm would be + # necessary. But: we do not want to scan the whole changelog + # file. Stopping when we see an earlier version, which + # necessarily then is an earlier upstream version, is the only + # realistic way to do that. Then, either the earliest + # changelog entry we have seen so far is indeed the earliest + # upload of this upstream version; or there are only changelog + # entries relating to later upstream versions (which is not + # possible unless the changelog and .dsc disagree about the + # version). Then it remains to choose between the physically + # last entry in the file, and the one with the lowest version + # number. If these are not the same, we guess that the + # versions were created in a non-monotonic order rather than + # that the changelog entries have been misordered. + + printdebug "import clog $thisstanza->{version} vs $upstreamv...\n"; + + last if version_compare($thisstanza->{version}, $upstreamv) < 0; + $r1clogp = $thisstanza; + + printdebug "import clog $r1clogp->{version} becomes r1\n"; + }; + + $r1clogp //= $$clogp_r; # maybe there's only one entry; + return clogp_authline $r1clogp; +} + sub import_tarball_tartrees ($$) { my ($upstreamv, $dfi) = @_; # cwd should be the playground @@ -2486,65 +2535,23 @@ sub import_tarball_commits ($$) { my $any_orig = grep { $_->{Orig} } @$tartrees; - my @clogcmd = qw(dpkg-parsechangelog --format rfc822 --all); my $clogp; - my $r1clogp; - - printdebug "import clog search...\n"; - parsechangelog_loop \@clogcmd, (__ "package changelog"), sub { - my ($thisstanza, $desc) = @_; - no warnings qw(exiting); - - $clogp //= $thisstanza; - - printdebug "import clog $thisstanza->{version} $desc...\n"; - - last if !$any_orig; # we don't need $r1clogp - - # We look for the first (most recent) changelog entry whose - # version number is lower than the upstream version of this - # package. Then the last (least recent) previous changelog - # entry is treated as the one which introduced this upstream - # version and used for the synthetic commits for the upstream - # tarballs. - - # One might think that a more sophisticated algorithm would be - # necessary. But: we do not want to scan the whole changelog - # file. Stopping when we see an earlier version, which - # necessarily then is an earlier upstream version, is the only - # realistic way to do that. Then, either the earliest - # changelog entry we have seen so far is indeed the earliest - # upload of this upstream version; or there are only changelog - # entries relating to later upstream versions (which is not - # possible unless the changelog and .dsc disagree about the - # version). Then it remains to choose between the physically - # last entry in the file, and the one with the lowest version - # number. If these are not the same, we guess that the - # versions were created in a non-monotonic order rather than - # that the changelog entries have been misordered. - - printdebug "import clog $thisstanza->{version} vs $upstreamv...\n"; - - last if version_compare($thisstanza->{version}, $upstreamv) < 0; - $r1clogp = $thisstanza; - - printdebug "import clog $r1clogp->{version} becomes r1\n"; - }; - - $clogp or fail __ "package changelog has no entries!"; - + my $r1authline; + if ($any_orig) { + $r1authline = import_r1authline(\$clogp, $upstreamv); + $clogp or fail __ "package changelog has no entries!"; + } + # Runs if $any_orig clause didn't set $clogp + $clogp //= parsechangelog(); my $authline = clogp_authline $clogp; + # Runs if $any_orig clause didn't set $r1authline + $r1authline //= $authline; + my $changes = getfield $clogp, 'Changes'; $changes =~ s/^\n//; # Changes: \n my $cversion = getfield $clogp, 'Version'; - my $r1authline; if (@$tartrees) { - $r1clogp //= $clogp; # maybe there's only one entry; - $r1authline = clogp_authline $r1clogp; - # Strictly, r1authline might now be wrong if it's going to be - # unused because !$any_orig. Whatever. - printdebug "import tartrees authline $authline\n"; printdebug "import tartrees r1authline $r1authline\n"; |