chiark / gitweb /
dgit: Dgit parsing: Refactor into parse_dsc_field
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Jan 2017 18:44:26 +0000 (18:44 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Jan 2017 22:14:48 +0000 (22:14 +0000)
No functional change other than changes to messages.

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

diff --git a/dgit b/dgit
index 54c38c24f534c668b3ecf6e3fccbd62d70cb5c48..54b0e6fc7719237d1d357459edfb6e2a3d360c62 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -2700,6 +2700,18 @@ sub fetch_from_archive_record_2 ($) {
     }
 }
 
     }
 }
 
+sub parse_dsc_field ($$) {
+    my ($f, $what) = @_;
+    if (!defined $f) {
+       progress "$what: NO git hash";
+    } elsif ($f =~ m/^\w+/) {
+       $dsc_hash = $&;
+       progress "$what: specified git hash";
+    } else {
+       fail "$what: invalid Dgit info";
+    }
+}
+
 sub fetch_from_archive () {
     ensure_setup_existing_tree();
 
 sub fetch_from_archive () {
     ensure_setup_existing_tree();
 
@@ -2711,17 +2723,12 @@ sub fetch_from_archive () {
     get_archive_dsc();
 
     if ($dsc) {
     get_archive_dsc();
 
     if ($dsc) {
+       my $f;
        foreach my $field (@ourdscfield) {
        foreach my $field (@ourdscfield) {
-           $dsc_hash = $dsc->{$field};
-           last if defined $dsc_hash;
-       }
-       if (defined $dsc_hash) {
-           $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'";
-           $dsc_hash = $&;
-           progress "last upload to archive specified git hash";
-       } else {
-           progress "last upload to archive has NO git hash";
+           $f = $dsc->{$field};
+           last if defined $f;
        }
        }
+       parse_dsc_field($f, 'last upload to archive');
     } else {
        progress "no version available from the archive";
     }
     } else {
        progress "no version available from the archive";
     }
@@ -5891,31 +5898,31 @@ sub cmd_import_dsc {
 
     parse_dscdata();
 
 
     parse_dscdata();
 
-    my $dgit_commit = $dsc->{$ourdscfield[0]};
-    if (defined $dgit_commit
+    my $dgit_field = $dsc->{$ourdscfield[0]};
+    parse_dsc_field($dgit_field, "$ourdscfield[0] field in .dsc");
+
+    if (defined $dsc_hash
        && !forceing [qw(import-dsc-with-dgit-field)]) {
        && !forceing [qw(import-dsc-with-dgit-field)]) {
-       $dgit_commit =~ m/\w+/ or fail "invalid hash in .dsc";
-       $dgit_commit = $&;
        progress "dgit: import-dsc of .dsc with Dgit field, using git hash";
        my @cmd = (qw(sh -ec),
        progress "dgit: import-dsc of .dsc with Dgit field, using git hash";
        my @cmd = (qw(sh -ec),
-                  "echo $dgit_commit | git cat-file --batch-check");
+                  "echo $dsc_hash | git cat-file --batch-check");
        my $objgot = cmdoutput @cmd;
        if ($objgot =~ m#^\w+ missing\b#) {
            fail <<END
        my $objgot = cmdoutput @cmd;
        if ($objgot =~ m#^\w+ missing\b#) {
            fail <<END
-.dsc contains Dgit field referring to object $dgit_commit
+.dsc contains Dgit field referring to object $dsc_hash
 Your git tree does not have that object.  Try `git fetch' from a
 plausible server (browse.dgit.d.o? alioth?), and try the import-dsc again.
 END
        }
 Your git tree does not have that object.  Try `git fetch' from a
 plausible server (browse.dgit.d.o? alioth?), and try the import-dsc again.
 END
        }
-       if ($oldhash && !is_fast_fwd $oldhash, $dgit_commit) {
+       if ($oldhash && !is_fast_fwd $oldhash, $dsc_hash) {
            if ($force > 0) {
                progress "Not fast forward, forced update.";
            } else {
            if ($force > 0) {
                progress "Not fast forward, forced update.";
            } else {
-               fail "Not fast forward to $dgit_commit";
+               fail "Not fast forward to $dsc_hash";
            }
        }
        @cmd = (@git, qw(update-ref -m), "dgit import-dsc (Dgit): $info",
            }
        }
        @cmd = (@git, qw(update-ref -m), "dgit import-dsc (Dgit): $info",
-               $dstbranch, $dgit_commit);
+               $dstbranch, $dsc_hash);
        runcmd @cmd;
        progress "dgit: import-dsc updated git ref $dstbranch";
        return 0;
        runcmd @cmd;
        progress "dgit: import-dsc updated git ref $dstbranch";
        return 0;