Skip to content

Commit c0a4ae7

Browse files
committed
update-index: remove stale fallback code for "--unresolve"
The "update-index --unresolve" is a relatively old feature that was introduced in Git v1.4.1 (June 2006), which predates the resolve-undo extension introduced in Git v1.7.0 (February 2010). The original code that was limited only to work during a merge (and not during a rebase or a cherry-pick) has been kept as the fallback codepath to be used as a transition measure. By now, for more than 10 years we have stored resolve-undo extension in the index file, and the fallback code way outlived its usefulness. Remove it, together with two file-scope static global variables. One of these variables is still used by surviving function, but it does not have to be a global at all, so move it to local to that function. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35901f1 commit c0a4ae7

File tree

1 file changed

+12
-102
lines changed

1 file changed

+12
-102
lines changed

builtin/update-index.c

Lines changed: 12 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,6 @@ static const char * const update_index_usage[] = {
608608
NULL
609609
};
610610

611-
static struct object_id head_oid;
612-
static struct object_id merge_head_oid;
613-
614611
static struct cache_entry *read_one_ent(const char *which,
615612
struct object_id *ent, const char *path,
616613
int namelen, int stage)
@@ -639,107 +636,19 @@ static struct cache_entry *read_one_ent(const char *which,
639636
return ce;
640637
}
641638

642-
static int read_head_pointers(void)
643-
{
644-
static int result = -2; /* unknown yet */
645-
646-
if (result == -2) {
647-
result = -1;
648-
if (read_ref("HEAD", &head_oid))
649-
return error("No HEAD -- no initial commit yet?");
650-
if (read_ref("MERGE_HEAD", &merge_head_oid))
651-
return error("Not in the middle of a merge");
652-
result = 0;
653-
}
654-
return result;
655-
}
656-
657639
static int unresolve_one(const char *path)
658640
{
659-
int namelen = strlen(path);
660-
int pos;
661-
int ret = 0;
662-
struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
663-
struct resolve_undo_info *ru = NULL;
664-
665-
if (the_index.resolve_undo) {
666-
struct string_list_item *item;
667-
item = string_list_lookup(the_index.resolve_undo, path);
668-
if (item) {
669-
ru = item->util;
670-
item->util = NULL;
671-
}
672-
}
673-
674-
/* resolve-undo record exists for the path */
675-
if (ru) {
676-
ret = unmerge_index_entry(&the_index, path, ru);
677-
free(ru);
678-
return ret;
679-
}
680-
681-
/* See if there is such entry in the index. */
682-
pos = index_name_pos(&the_index, path, namelen);
683-
if (0 <= pos) {
684-
; /* resolve-undo record was used already -- fall back */
685-
} else {
686-
/* Is it unmerged? */
687-
pos = -pos - 1;
688-
if (pos < the_index.cache_nr) {
689-
const struct cache_entry *ce = the_index.cache[pos];
690-
if (ce_namelen(ce) == namelen &&
691-
!memcmp(ce->name, path, namelen)) {
692-
fprintf(stderr,
693-
"%s: skipping still unmerged path.\n",
694-
path);
695-
}
696-
goto free_return;
697-
}
698-
/* No, such a path does not exist -- removed */
699-
}
700-
701-
/*
702-
* We are not using resolve-undo information but just
703-
* populating the stages #2 and #3 from HEAD and MERGE_HEAD.
704-
*
705-
* This is a flawed replacement of true "unresolve", as we do
706-
* not have a way to recreate the stage #1 for the common
707-
* ancestor (which may not be a unique merge-base between the
708-
* two).
709-
*/
710-
if (read_head_pointers()) {
711-
ret = -1;
712-
goto free_return;
713-
}
714-
715-
ce_2 = read_one_ent("our", &head_oid, path, namelen, 2);
716-
ce_3 = read_one_ent("their", &merge_head_oid, path, namelen, 3);
717-
718-
if (!ce_2 || !ce_3) {
719-
ret = -1;
720-
goto free_return;
721-
}
722-
if (oideq(&ce_2->oid, &ce_3->oid) &&
723-
ce_2->ce_mode == ce_3->ce_mode) {
724-
fprintf(stderr, "%s: identical in both, skipping.\n",
725-
path);
726-
goto free_return;
727-
}
728-
729-
remove_file_from_index(&the_index, path);
730-
if (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {
731-
error("%s: cannot add our version to the index.", path);
732-
ret = -1;
733-
goto free_return;
734-
}
735-
if (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))
736-
return 0;
737-
error("%s: cannot add their version to the index.", path);
738-
ret = -1;
739-
free_return:
740-
discard_cache_entry(ce_2);
741-
discard_cache_entry(ce_3);
742-
return ret;
641+
struct string_list_item *item;
642+
int res = 0;
643+
644+
if (!the_index.resolve_undo)
645+
return res;
646+
item = string_list_lookup(the_index.resolve_undo, path);
647+
if (!item)
648+
return res; /* no resolve-undo record for the path */
649+
res = unmerge_index_entry(&the_index, path, item->util);
650+
FREE_AND_NULL(item->util);
651+
return res;
743652
}
744653

745654
static int do_unresolve(int ac, const char **av,
@@ -766,6 +675,7 @@ static int do_reupdate(const char **paths,
766675
int pos;
767676
int has_head = 1;
768677
struct pathspec pathspec;
678+
struct object_id head_oid;
769679

770680
parse_pathspec(&pathspec, 0,
771681
PATHSPEC_PREFER_CWD,

0 commit comments

Comments
 (0)