2 #include "resolve-undo.h"
3 #include "string-list.h"
5 /* The only error case is to run out of memory in string-list */
6 void record_resolve_undo(struct index_state
*istate
, struct cache_entry
*ce
)
8 struct string_list_item
*lost
;
9 struct resolve_undo_info
*ui
;
10 struct string_list
*resolve_undo
;
11 int stage
= ce_stage(ce
);
16 if (!istate
->resolve_undo
) {
17 resolve_undo
= xcalloc(1, sizeof(*resolve_undo
));
18 resolve_undo
->strdup_strings
= 1;
19 istate
->resolve_undo
= resolve_undo
;
21 resolve_undo
= istate
->resolve_undo
;
22 lost
= string_list_insert(ce
->name
, resolve_undo
);
24 lost
->util
= xcalloc(1, sizeof(*ui
));
26 hashcpy(ui
->sha1
[stage
- 1], ce
->sha1
);
27 ui
->mode
[stage
- 1] = ce
->ce_mode
;
30 static int write_one(struct string_list_item
*item
, void *cbdata
)
32 struct strbuf
*sb
= cbdata
;
33 struct resolve_undo_info
*ui
= item
->util
;
38 strbuf_addstr(sb
, item
->string
);
40 for (i
= 0; i
< 3; i
++)
41 strbuf_addf(sb
, "%o%c", ui
->mode
[i
], 0);
42 for (i
= 0; i
< 3; i
++) {
45 strbuf_add(sb
, ui
->sha1
[i
], 20);
50 void resolve_undo_write(struct strbuf
*sb
, struct string_list
*resolve_undo
)
52 for_each_string_list(write_one
, resolve_undo
, sb
);
55 struct string_list
*resolve_undo_read(void *data
, unsigned long size
)
57 struct string_list
*resolve_undo
;
62 resolve_undo
= xcalloc(1, sizeof(*resolve_undo
));
63 resolve_undo
->strdup_strings
= 1;
66 struct string_list_item
*lost
;
67 struct resolve_undo_info
*ui
;
69 len
= strlen(data
) + 1;
72 lost
= string_list_insert(data
, resolve_undo
);
74 lost
->util
= xcalloc(1, sizeof(*ui
));
79 for (i
= 0; i
< 3; i
++) {
80 ui
->mode
[i
] = strtoul(data
, &endptr
, 8);
81 if (!endptr
|| endptr
== data
|| *endptr
)
83 len
= (endptr
+ 1) - (char*)data
;
90 for (i
= 0; i
< 3; i
++) {
95 hashcpy(ui
->sha1
[i
], data
);
103 string_list_clear(resolve_undo
, 1);
104 error("Index records invalid resolve-undo information");
108 void resolve_undo_clear_index(struct index_state
*istate
)
110 struct string_list
*resolve_undo
= istate
->resolve_undo
;
113 string_list_clear(resolve_undo
, 1);
115 istate
->resolve_undo
= NULL
;
116 istate
->cache_changed
= 1;