chiark / gitweb /
catacomb-import-update: Handle deletion
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 31 Dec 2019 13:13:25 +0000 (13:13 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 1 Jan 2020 23:48:14 +0000 (23:48 +0000)
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 <ijackson@chiark.greenend.org.uk>
catacomb-import-update

index 03711879d1cf2cbf9fed079e270369b962ea2961..de96ca9625766d088247e62b997128621a513568 100755 (executable)
@@ -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;
 }
 
 ###--------------------------------------------------------------------------