From 6df06968cbcb92d2dc9796a137d36cdc873b827a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 7 Jan 2017 18:44:26 +0000 Subject: dgit: Dgit parsing: Refactor into parse_dsc_field No functional change other than changes to messages. Signed-off-by: Ian Jackson --- dgit | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/dgit b/dgit index 54c38c2..54b0e6f 100755 --- 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(); @@ -2711,17 +2723,12 @@ sub fetch_from_archive () { get_archive_dsc(); if ($dsc) { + my $f; 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"; } @@ -5891,31 +5898,31 @@ sub cmd_import_dsc { 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)]) { - $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), - "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 < 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", - $dstbranch, $dgit_commit); + $dstbranch, $dsc_hash); runcmd @cmd; progress "dgit: import-dsc updated git ref $dstbranch"; return 0; -- cgit v1.2.3