Skip to content

Commit 4e7c457

Browse files
iabervongitster
authored andcommitted
Add "skip_unmerged" option to unpack_trees.
This option allows the caller to reset everything that isn't unmerged, leaving the unmerged things to be resolved. If, after a merge of "working" and "HEAD", this is used with "HEAD" (reset, !update), the result will be that all of the changes from "local" are in the working tree but not added to the index (either with the index clean but unchanged, or with the index unmerged, depending on whether there are conflicts). This will be used in checkout -m. Signed-off-by: Daniel Barkalow <[email protected]>
1 parent 33ecf7e commit 4e7c457

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

unpack-trees.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
8585
int any_dirs = 0;
8686
char *cache_name;
8787
int ce_stage;
88+
int skip_entry = 0;
8889

8990
/* Find the first name in the input. */
9091

@@ -153,6 +154,8 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
153154
any_files = 1;
154155
src[0] = active_cache[o->pos];
155156
remove = o->pos;
157+
if (o->skip_unmerged && ce_stage(src[0]))
158+
skip_entry = 1;
156159
}
157160

158161
for (i = 0; i < len; i++) {
@@ -181,6 +184,12 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
181184
continue;
182185
}
183186

187+
if (skip_entry) {
188+
subposns[i] = df_conflict_list;
189+
posns[i] = posns[i]->next;
190+
continue;
191+
}
192+
184193
if (!o->merge)
185194
ce_stage = 0;
186195
else if (i + 1 < o->head_idx)
@@ -205,7 +214,13 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
205214
posns[i] = posns[i]->next;
206215
}
207216
if (any_files) {
208-
if (o->merge) {
217+
if (skip_entry) {
218+
o->pos++;
219+
while (o->pos < active_nr &&
220+
!strcmp(active_cache[o->pos]->name,
221+
src[0]->name))
222+
o->pos++;
223+
} else if (o->merge) {
209224
int ret;
210225

211226
#if DBRT_DEBUG > 1
@@ -730,9 +745,8 @@ int threeway_merge(struct cache_entry **stages,
730745
* If we have an entry in the index cache, then we want to
731746
* make sure that it matches head.
732747
*/
733-
if (index && !same(index, head)) {
748+
if (index && !same(index, head))
734749
return o->gently ? -1 : reject_merge(index);
735-
}
736750

737751
if (head) {
738752
/* #5ALT, #15 */

unpack-trees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct unpack_trees_options {
1616
int trivial_merges_only;
1717
int verbose_update;
1818
int aggressive;
19+
int skip_unmerged;
1920
int gently;
2021
const char *prefix;
2122
int pos;

0 commit comments

Comments
 (0)