| 919 | } |
| 920 | |
| 921 | static 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 |
no test coverage detected