chiark / gitweb /
dgit: dsc Dgit field handling: Break out resolve_dsc_field_commit
[dgit.git] / dgit
diff --git a/dgit b/dgit
index de7b4de625ec4520ff13d552cee200172d76c3b3..933c00824f263b53fd2cebfe18851d6448d93d89 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -1683,6 +1683,7 @@ sub create_remote_git_repo () {
 }
 
 our ($dsc_hash,$lastpush_mergeinput);
+our ($dsc_distro, $dsc_hint_tag, $dsc_hint_url);
 
 our $ud = '.git/dgit/unpack';
 
@@ -2704,17 +2705,48 @@ sub fetch_from_archive_record_2 ($) {
 }
 
 sub parse_dsc_field ($$) {
-    my ($f, $what) = @_;
+    my ($dsc, $what) = @_;
+    my $f;
+    foreach my $field (@ourdscfield) {
+       $f = $dsc->{$field};
+       last if defined $f;
+    }
     if (!defined $f) {
        progress "$what: NO git hash";
-    } elsif ($f =~ m/^\w+/) {
+    } elsif (($dsc_hash, $dsc_distro, $dsc_hint_tag, $dsc_hint_url)
+            = $f =~ m/^(\w+) ($distro_re) ($versiontag_re) (\S+)(?:\s|$)/) {
+       progress "$what: specified git info ($dsc_distro)";
+       $dsc_hint_tag = [ $dsc_hint_tag ];
+    } elsif ($f =~ m/^\w+\s*$/) {
        $dsc_hash = $&;
+       $dsc_distro //= 'debian';
+       $dsc_hint_tag = [ debiantags +(getfield $dsc, 'Version'),
+                         $dsc_distro ];
        progress "$what: specified git hash";
     } else {
        fail "$what: invalid Dgit info";
     }
 }
 
+sub resolve_dsc_field_commit ($$) {
+    my ($already_distro, $already_mapref) = @_;
+
+    return unless defined $dsc_hash;
+
+    my $rewritemapdata = git_cat_file $already_mapref.':map';
+    if (defined $rewritemapdata
+       && $rewritemapdata =~ m/^$dsc_hash(?:[ \t](\w+))/m) {
+       progress "server's git history rewrite map contains a relevant entry!";
+
+       $dsc_hash = $1;
+       if (defined $dsc_hash) {
+           progress "using rewritten git hash in place of .dsc value";
+       } else {
+           progress "server data says .dsc hash is to be disregarded";
+       }
+    }
+}
+
 sub fetch_from_archive () {
     ensure_setup_existing_tree();
 
@@ -2726,28 +2758,13 @@ sub fetch_from_archive () {
     get_archive_dsc();
 
     if ($dsc) {
-       my $f;
-       foreach my $field (@ourdscfield) {
-           $f = $dsc->{$field};
-           last if defined $f;
-       }
-       parse_dsc_field($f, 'last upload to archive');
+       parse_dsc_field($dsc, 'last upload to archive');
+       resolve_dsc_field_commit access_basedistro,
+           lrfetchrefs."/".$rewritemap
     } else {
        progress "no version available from the archive";
     }
 
-    my $rewritemapdata = git_cat_file lrfetchrefs."/".$rewritemap.':map';
-    if (defined $rewritemapdata
-       && $rewritemapdata =~ m/^$dsc_hash(?:[ \t](\w+))/m) {
-       progress "server's git history rewrite map contains a relevant entry!";
-       $dsc_hash = $1;
-       if (defined $dsc_hash) {
-           progress "using rewritten git hash in place of .dsc value";
-       } else {
-           progress "server data says .dsc hash is to be disregarded";
-       }
-    }
-
     # If the archive's .dsc has a Dgit field, there are three
     # relevant git commitids we need to choose between and/or merge
     # together:
@@ -5901,8 +5918,7 @@ sub cmd_import_dsc {
 
     parse_dscdata();
 
-    my $dgit_field = $dsc->{$ourdscfield[0]};
-    parse_dsc_field($dgit_field, "$ourdscfield[0] field in .dsc");
+    parse_dsc_field($dsc, "Dgit metadata in .dsc");
 
     if (defined $dsc_hash
        && !forceing [qw(import-dsc-with-dgit-field)]) {