MCPcopy Index your code
hub / github.com/git/git / handle_cache

Function handle_cache

rerere.c:972–1041  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

970}
971
972static int handle_cache(struct index_state *istate,
973 const char *path, unsigned char *hash, const char *output)
974{
975 mmfile_t mmfile[3] = {{NULL}};
976 mmbuffer_t result = {NULL, 0};
977 const struct cache_entry *ce;
978 int pos, len, i, has_conflicts;
979 struct rerere_io_mem io;
980 int marker_size = ll_merge_marker_size(istate, path);
981
982 /*
983 * Reproduce the conflicted merge in-core
984 */
985 len = strlen(path);
986 pos = index_name_pos(istate, path, len);
987 if (0 <= pos)
988 return -1;
989 pos = -pos - 1;
990
991 while (pos < istate->cache_nr) {
992 enum object_type type;
993 size_t size;
994
995 ce = istate->cache[pos++];
996 if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
997 break;
998 i = ce_stage(ce) - 1;
999 if (!mmfile[i].ptr) {
1000 mmfile[i].ptr = odb_read_object(the_repository->objects,
1001 &ce->oid, &type, &size);
1002 if (!mmfile[i].ptr)
1003 die(_("unable to read %s"),
1004 oid_to_hex(&ce->oid));
1005 mmfile[i].size = size;
1006 }
1007 }
1008 for (i = 0; i < 3; i++)
1009 if (!mmfile[i].ptr && !mmfile[i].size)
1010 mmfile[i].ptr = xstrdup("");
1011
1012 /*
1013 * NEEDSWORK: handle conflicts from merges with
1014 * merge.renormalize set, too?
1015 */
1016 ll_merge(&result, path, &mmfile[0], NULL,
1017 &mmfile[1], "ours",
1018 &mmfile[2], "theirs",
1019 istate, NULL);
1020 for (i = 0; i < 3; i++)
1021 free(mmfile[i].ptr);
1022
1023 memset(&io, 0, sizeof(io));
1024 io.io.getline = rerere_mem_getline;
1025 if (output)
1026 io.io.output = fopen(output, "w");
1027 else
1028 io.io.output = NULL;
1029 strbuf_init(&io.input, 0);

Callers 1

rerere_forget_one_pathFunction · 0.85

Calls 11

ll_merge_marker_sizeFunction · 0.85
index_name_posFunction · 0.85
odb_read_objectFunction · 0.85
oid_to_hexFunction · 0.85
xstrdupFunction · 0.85
ll_mergeFunction · 0.85
strbuf_initFunction · 0.85
strbuf_attachFunction · 0.85
handle_pathFunction · 0.85
strbuf_releaseFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected