- handle_file(path, NULL, rerere_path(id, "preimage"));
- if (id->collection->status[variant] & RR_HAS_POSTIMAGE) {
- const char *path = rerere_path(id, "postimage");
- if (unlink(path))
- die_errno("cannot unlink stray '%s'", path);
- id->collection->status[variant] &= ~RR_HAS_POSTIMAGE;
- }
- id->collection->status[variant] |= RR_HAS_PREIMAGE;
- fprintf(stderr, "Recorded preimage for '%s'\n", path);
- return;
- } else if (has_rerere_resolution(id)) {
- /* Is there a recorded resolution we could attempt to apply? */
- if (merge(id, path))
- return; /* failed to replay */
+ }
+
+ /* Does any existing resolution apply cleanly? */
+ for (variant = 0; variant < rr_dir->status_nr; variant++) {
+ const int both = RR_HAS_PREIMAGE | RR_HAS_POSTIMAGE;
+ struct rerere_id vid = *id;
+
+ if ((rr_dir->status[variant] & both) != both)
+ continue;
+
+ vid.variant = variant;
+ if (merge(&vid, path))
+ continue; /* failed to replay */
+
+ /*
+ * If there already is a different variant that applies
+ * cleanly, there is no point maintaining our own variant.
+ */
+ if (0 <= id->variant && id->variant != variant)
+ remove_variant(id);