|
7 | 7 | #include "ll-merge.h"
|
8 | 8 | #include "attr.h"
|
9 | 9 |
|
| 10 | +#define RESOLVED 0 |
| 11 | +#define PUNTED 1 |
| 12 | +#define THREE_STAGED 2 |
| 13 | +void *RERERE_RESOLVED = &RERERE_RESOLVED; |
| 14 | + |
10 | 15 | /* if rerere_enabled == -1, fall back to detection of .git/rr-cache */
|
11 | 16 | static int rerere_enabled = -1;
|
12 | 17 |
|
@@ -345,21 +350,74 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
|
345 | 350 | return hunk_no;
|
346 | 351 | }
|
347 | 352 |
|
348 |
| -static int find_conflict(struct string_list *conflict) |
| 353 | +static int check_one_conflict(int i, int *type) |
349 | 354 | {
|
350 |
| - int i; |
351 |
| - if (read_cache() < 0) |
352 |
| - return error("Could not read index"); |
353 |
| - for (i = 0; i+1 < active_nr; i++) { |
| 355 | + struct cache_entry *e = active_cache[i]; |
| 356 | + |
| 357 | + if (!ce_stage(e)) { |
| 358 | + *type = RESOLVED; |
| 359 | + return i + 1; |
| 360 | + } |
| 361 | + |
| 362 | + *type = PUNTED; |
| 363 | + if (ce_stage(e) == 1) { |
| 364 | + if (active_nr <= ++i) |
| 365 | + return i + 1; |
| 366 | + } |
| 367 | + |
| 368 | + /* Only handle regular files with both stages #2 and #3 */ |
| 369 | + if (i + 1 < active_nr) { |
354 | 370 | struct cache_entry *e2 = active_cache[i];
|
355 |
| - struct cache_entry *e3 = active_cache[i+1]; |
| 371 | + struct cache_entry *e3 = active_cache[i + 1]; |
356 | 372 | if (ce_stage(e2) == 2 &&
|
357 | 373 | ce_stage(e3) == 3 &&
|
358 |
| - ce_same_name(e2, e3) && |
| 374 | + ce_same_name(e, e3) && |
359 | 375 | S_ISREG(e2->ce_mode) &&
|
360 |
| - S_ISREG(e3->ce_mode)) { |
361 |
| - string_list_insert(conflict, (const char *)e2->name); |
362 |
| - i++; /* skip over both #2 and #3 */ |
| 376 | + S_ISREG(e3->ce_mode)) |
| 377 | + *type = THREE_STAGED; |
| 378 | + } |
| 379 | + |
| 380 | + /* Skip the entries with the same name */ |
| 381 | + while (i < active_nr && ce_same_name(e, active_cache[i])) |
| 382 | + i++; |
| 383 | + return i; |
| 384 | +} |
| 385 | + |
| 386 | +static int find_conflict(struct string_list *conflict) |
| 387 | +{ |
| 388 | + int i; |
| 389 | + if (read_cache() < 0) |
| 390 | + return error("Could not read index"); |
| 391 | + |
| 392 | + for (i = 0; i < active_nr;) { |
| 393 | + int conflict_type; |
| 394 | + struct cache_entry *e = active_cache[i]; |
| 395 | + i = check_one_conflict(i, &conflict_type); |
| 396 | + if (conflict_type == THREE_STAGED) |
| 397 | + string_list_insert(conflict, (const char *)e->name); |
| 398 | + } |
| 399 | + return 0; |
| 400 | +} |
| 401 | + |
| 402 | +int rerere_remaining(struct string_list *merge_rr) |
| 403 | +{ |
| 404 | + int i; |
| 405 | + if (read_cache() < 0) |
| 406 | + return error("Could not read index"); |
| 407 | + |
| 408 | + for (i = 0; i < active_nr;) { |
| 409 | + int conflict_type; |
| 410 | + struct cache_entry *e = active_cache[i]; |
| 411 | + i = check_one_conflict(i, &conflict_type); |
| 412 | + if (conflict_type == PUNTED) |
| 413 | + string_list_insert(merge_rr, (const char *)e->name); |
| 414 | + else if (conflict_type == RESOLVED) { |
| 415 | + struct string_list_item *it; |
| 416 | + it = string_list_lookup(merge_rr, (const char *)e->name); |
| 417 | + if (it != NULL) { |
| 418 | + free(it->util); |
| 419 | + it->util = RERERE_RESOLVED; |
| 420 | + } |
363 | 421 | }
|
364 | 422 | }
|
365 | 423 | return 0;
|
|
0 commit comments