122
return ((id->collection->status & both) == both);
123
}
124
125
+static int has_rerere_preimage(const struct rerere_id *id)
126
+{
127
+ return (id->collection->status & RR_HAS_PREIMAGE);
128
+}
129
+
130
static struct rerere_id *new_rerere_id_hex(char *hex)
131
{
132
struct rerere_id *id = xmalloc(sizeof(*id));
754
const char *path = rr_item->string;
755
const struct rerere_id *id = rr_item->util;
756
752
- /* Is there a recorded resolution we could attempt to apply? */
753
- if (has_rerere_resolution(id)) {
757
+ if (!has_rerere_preimage(id)) {
758
+ /*
759
+ * We are the first to encounter this conflict. Ask
760
+ * handle_file() to write the normalized contents to
761
+ * the "preimage" file.
762
+ */
763
+ handle_file(path, NULL, rerere_path(id, "preimage"));
764
+ if (id->collection->status & RR_HAS_POSTIMAGE) {
765
+ const char *path = rerere_path(id, "postimage");
766
+ if (unlink(path))
767
+ die_errno("cannot unlink stray '%s'", path);
768
+ id->collection->status &= ~RR_HAS_POSTIMAGE;
769
+ }
770
+ id->collection->status |= RR_HAS_PREIMAGE;
771
+ fprintf(stderr, "Recorded preimage for '%s'\n", path);
772
+ return;
773
+ } else if (has_rerere_resolution(id)) {
774
+ /* Is there a recorded resolution we could attempt to apply? */
775
if (merge(id, path))
776
return; /* failed to replay */
777
828
id = new_rerere_id(sha1);
829
string_list_insert(rr, path)->util = id;
830
810
- /*
811
- * Ensure that the directory exists.
812
- * mkdir_in_gitdir() will fail with EEXIST if there
813
- * already is one.
814
- */
815
- if (mkdir_in_gitdir(rerere_path(id, NULL)) &&
816
- errno != EEXIST)
817
- continue; /* NEEDSWORK: perhaps we should die? */
818
-
819
- if (id->collection->status & RR_HAS_PREIMAGE) {
820
- ;
821
- } else {
822
- /*
823
- * We are the first to encounter this
824
- * conflict. Ask handle_file() to write the
825
- * normalized contents to the "preimage" file.
826
- *
827
- * NEEDSWORK: what should happen if we had a
828
- * leftover postimage that is totally
829
- * unrelated? Perhaps we should unlink it?
830
- */
831
- handle_file(path, NULL, rerere_path(id, "preimage"));
832
- id->collection->status |= RR_HAS_PREIMAGE;
833
- fprintf(stderr, "Recorded preimage for '%s'\n", path);
834
- }
831
+ /* Ensure that the directory exists. */
832
+ mkdir_in_gitdir(rerere_path(id, NULL));
833
}
834
835
for (i = 0; i < rr->nr; i++)