|
1 | 1 | #include "cache.h" |
| 2 | +#include "dir.h" |
2 | 3 | #include "resolve-undo.h" |
3 | 4 | #include "string-list.h" |
4 | 5 |
|
@@ -115,3 +116,61 @@ void resolve_undo_clear_index(struct index_state *istate) |
115 | 116 | istate->resolve_undo = NULL; |
116 | 117 | istate->cache_changed = 1; |
117 | 118 | } |
| 119 | + |
| 120 | +int unmerge_index_entry_at(struct index_state *istate, int pos) |
| 121 | +{ |
| 122 | + struct cache_entry *ce; |
| 123 | + struct string_list_item *item; |
| 124 | + struct resolve_undo_info *ru; |
| 125 | + int i, err = 0; |
| 126 | + |
| 127 | + if (!istate->resolve_undo) |
| 128 | + return pos; |
| 129 | + |
| 130 | + ce = istate->cache[pos]; |
| 131 | + if (ce_stage(ce)) { |
| 132 | + /* already unmerged */ |
| 133 | + while ((pos < istate->cache_nr) && |
| 134 | + ! strcmp(istate->cache[pos]->name, ce->name)) |
| 135 | + pos++; |
| 136 | + return pos - 1; /* return the last entry processed */ |
| 137 | + } |
| 138 | + item = string_list_lookup(ce->name, istate->resolve_undo); |
| 139 | + if (!item) |
| 140 | + return pos; |
| 141 | + ru = item->util; |
| 142 | + if (!ru) |
| 143 | + return pos; |
| 144 | + remove_index_entry_at(istate, pos); |
| 145 | + for (i = 0; i < 3; i++) { |
| 146 | + struct cache_entry *nce; |
| 147 | + if (!ru->mode[i]) |
| 148 | + continue; |
| 149 | + nce = make_cache_entry(ru->mode[i], ru->sha1[i], |
| 150 | + ce->name, i + 1, 0); |
| 151 | + if (add_index_entry(istate, nce, ADD_CACHE_OK_TO_ADD)) { |
| 152 | + err = 1; |
| 153 | + error("cannot unmerge '%s'", ce->name); |
| 154 | + } |
| 155 | + } |
| 156 | + if (err) |
| 157 | + return pos; |
| 158 | + free(ru); |
| 159 | + item->util = NULL; |
| 160 | + return unmerge_index_entry_at(istate, pos); |
| 161 | +} |
| 162 | + |
| 163 | +void unmerge_index(struct index_state *istate, const char **pathspec) |
| 164 | +{ |
| 165 | + int i; |
| 166 | + |
| 167 | + if (!istate->resolve_undo) |
| 168 | + return; |
| 169 | + |
| 170 | + for (i = 0; i < istate->cache_nr; i++) { |
| 171 | + struct cache_entry *ce = istate->cache[i]; |
| 172 | + if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) |
| 173 | + continue; |
| 174 | + i = unmerge_index_entry_at(istate, i); |
| 175 | + } |
| 176 | +} |
0 commit comments