chiark / gitweb /
dgit: Break out import_tarball_commits
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 29 Jun 2019 16:27:12 +0000 (17:27 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 30 Jun 2019 20:11:17 +0000 (21:11 +0100)
No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit

diff --git a/dgit b/dgit
index cfd4f7ce2ca0681698d17715a4ee9887c352ac46..4844bfce36e0c3b3343da3fc907b7e4310760609 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -2383,6 +2383,101 @@ sub import_tarball_tartrees ($$) {
     @tartrees;
 }
 
+sub import_tarball_commits ($$) {
+    my ($tartrees, $upstreamv) = @_;
+    # cwd should be a playtree which has a relevant debian/changelog
+    # fills in $tt->{Commit} for each one
+
+    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 $authline = clogp_authline $clogp;
+    my $changes = getfield $clogp, 'Changes';
+    $changes =~ s/^\n//; # Changes: \n
+    my $cversion = getfield $clogp, 'Version';
+
+    if (@$tartrees) {
+       $r1clogp //= $clogp; # maybe there's only one entry;
+       my $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";
+
+       foreach my $tt (@$tartrees) {
+           printdebug "import tartree $tt->{F} $tt->{Tree}\n";
+
+           my $mbody = f_ "Import %s", $tt->{F};
+           $tt->{Commit} = hash_commit_text($tt->{Orig} ? <<END_O : <<END_T);
+tree $tt->{Tree}
+author $r1authline
+committer $r1authline
+
+$mbody
+
+[dgit import orig $tt->{F}]
+END_O
+tree $tt->{Tree}
+author $authline
+committer $authline
+
+$mbody
+
+[dgit import tarball $package $cversion $tt->{F}]
+END_T
+       }
+    }
+
+    return ($authline, $clogp, $changes);
+}
+
 sub generate_commits_from_dsc () {
     # See big comment in fetch_from_archive, below.
     # See also README.dsc-import.
@@ -2442,8 +2537,6 @@ sub generate_commits_from_dsc () {
 
     my @tartrees = import_tarball_tartrees($upstreamv, \@dfi);
 
-    my $any_orig = grep { $_->{Orig} } @tartrees;
-
     my $dscfn = "$package.dsc";
 
     my $treeimporthow = 'package';
@@ -2473,91 +2566,11 @@ sub generate_commits_from_dsc () {
        $dappliedtree = git_add_write_tree();
     }
 
-    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";
-    };
+    my ($authline, $clogp, $changes) =
+       import_tarball_commits(\@tartrees, $upstreamv);
 
-    $clogp or fail __ "package changelog has no entries!";
-
-    my $authline = clogp_authline $clogp;
-    my $changes = getfield $clogp, 'Changes';
-    $changes =~ s/^\n//; # Changes: \n
     my $cversion = getfield $clogp, 'Version';
 
-    if (@tartrees) {
-       $r1clogp //= $clogp; # maybe there's only one entry;
-       my $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";
-
-       foreach my $tt (@tartrees) {
-           printdebug "import tartree $tt->{F} $tt->{Tree}\n";
-
-           my $mbody = f_ "Import %s", $tt->{F};
-           $tt->{Commit} = hash_commit_text($tt->{Orig} ? <<END_O : <<END_T);
-tree $tt->{Tree}
-author $r1authline
-committer $r1authline
-
-$mbody
-
-[dgit import orig $tt->{F}]
-END_O
-tree $tt->{Tree}
-author $authline
-committer $authline
-
-$mbody
-
-[dgit import tarball $package $cversion $tt->{F}]
-END_T
-       }
-    }
-
     printdebug "import main commit\n";
 
     open C, ">../commit.tmp" or confess "$!";