MCPcopy Create free account
hub / github.com/git/git / unique_path

Function unique_path

merge-ort.c:921–945  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

919}
920
921static char *unique_path(struct merge_options *opt,
922 const char *path,
923 const char *branch)
924{
925 char *ret = NULL;
926 struct strbuf newpath = STRBUF_INIT;
927 int suffix = 0;
928 size_t base_len;
929 struct strmap *existing_paths = &opt->priv->paths;
930
931 strbuf_addf(&newpath, "%s~", path);
932 add_flattened_path(&newpath, branch);
933
934 base_len = newpath.len;
935 while (strmap_contains(existing_paths, newpath.buf)) {
936 strbuf_setlen(&newpath, base_len);
937 strbuf_addf(&newpath, "_%d", suffix++);
938 }
939
940 /* Track the new path in our memory pool */
941 ret = mem_pool_alloc(&opt->priv->pool, newpath.len + 1);
942 memcpy(ret, newpath.buf, newpath.len + 1);
943 strbuf_release(&newpath);
944 return ret;
945}
946
947/*** Function Grouping: functions related to collect_merge_info() ***/
948

Callers 1

process_entryFunction · 0.85

Calls 6

strbuf_addfFunction · 0.85
add_flattened_pathFunction · 0.85
strmap_containsFunction · 0.85
strbuf_setlenFunction · 0.85
mem_pool_allocFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected