From: Ian Jackson Date: Tue, 31 Dec 2019 13:13:25 +0000 (+0000) Subject: catacomb-import-update: Handle deletion X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=19777e64f1b65b077dad9dcdf3f181834f45d20c;p=secnet.git catacomb-import-update: Handle deletion If files are removed from the list to be processed, they should be removed from the import directory, not left lying around stale. (Files that disappear from Catacomb upstream would always produce an error, and will still do so.) This means we key off %changed. If there is no entry in %DONOR_REV_MAP then it means the file is being deleted; if the entry is undef ie means the file is being added. Signed-off-by: Ian Jackson --- diff --git a/catacomb-import-update b/catacomb-import-update index 0371187..de96ca9 100755 --- a/catacomb-import-update +++ b/catacomb-import-update @@ -94,13 +94,15 @@ sub commit_changes () { return if $DOCONVERT; + my $dir = $DONOR_IMPORT_DIR; + runx 'rm', '-rf', $dir; + runx 'mkdir', $dir; + my @paths = sort keys %DONOR_REV_MAP; runx 'rsync', '-Rc', (map { "$DONOR_DIR/./$_" } @paths), $DONOR_IMPORT_DIR; - my $dir = $DONOR_IMPORT_DIR; ## Stage updated files for commit. - runx "git", "update-index", "--add", "--", - map { "$dir/$_" } keys %DONOR_REV_MAP; + runx "git", "add", "-A", $dir; ## Inspect the changed files. Notice whether we've actually changed or ## added files. @@ -120,13 +122,8 @@ sub commit_changes () { $changed{$path} = 1; $new{$path} = ($old !~ /[^0]/); } - ## Files which haven't changed aren't interesting any more. - for my $path (keys %DONOR_REV_MAP) { - if (!$changed{$path}) { - delete $DONOR_REV_MAP{$path}; - } - } - if (!%DONOR_REV_MAP) { moan "no changes to import"; return ""; } + ## Files which haven't changed aren't interesting + if (!%changed) { moan "no changes to import"; return ""; } ## Build the commit preamble. $msg .= "Update crypto code from Catacomb $DONOR_VERSION.\n\n"; @@ -141,7 +138,8 @@ sub commit_changes () { ## Now the detailed list of upstream commits. $msg .= "\nDetailed list of changes:\n"; my @lpaths; my @roots; - for my $path (sort keys %DONOR_REV_MAP) { + for my $path (sort keys %changed) { + if (!exists $DONOR_REV_MAP{$path}) { $msg .= " Deleted $path.\n"; next; } my $rev = $DONOR_REV_MAP{$path}; if (defined $rev) { push @lpaths, $path; push @roots, $rev; } else { $msg .= " Initial import of $path.\n"; } @@ -172,7 +170,7 @@ sub commit_changes () { ## Commit everything. runx "git", "commit", "--edit", "--message", $msg, - map { "$dir/$_" } @paths; + map { "$dir/$_" } keys %changed; } ###--------------------------------------------------------------------------