summaryrefslogtreecommitdiff
path: root/merge-ort.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-01-01 02:34:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-01-04 18:40:45 (GMT)
commit5a1a1e8ea9fdd4a575c711b91f176838ea502e44 (patch)
tree044e221c821562f97fcb52733815c108991c35f8 /merge-ort.c
parent23366d2aa97544fe76bc86964f4493b7b89e7b22 (diff)
downloadgit-5a1a1e8ea9fdd4a575c711b91f176838ea502e44.zip
git-5a1a1e8ea9fdd4a575c711b91f176838ea502e44.tar.gz
git-5a1a1e8ea9fdd4a575c711b91f176838ea502e44.tar.bz2
merge-ort: implement unique_path() helper
Implement unique_path(), based on the one from merge-recursive.c. It is simplified, however, due to: (1) using strmaps, and (2) the fact that merge-ort lets the checkout codepath handle possible collisions with the working tree means that other code locations don't have to. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-ort.c')
-rw-r--r--merge-ort.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/merge-ort.c b/merge-ort.c
index d300a02..1adc27a 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -343,11 +343,34 @@ static void path_msg(struct merge_options *opt,
strbuf_addch(sb, '\n');
}
+/* add a string to a strbuf, but converting "/" to "_" */
+static void add_flattened_path(struct strbuf *out, const char *s)
+{
+ size_t i = out->len;
+ strbuf_addstr(out, s);
+ for (; i < out->len; i++)
+ if (out->buf[i] == '/')
+ out->buf[i] = '_';
+}
+
static char *unique_path(struct strmap *existing_paths,
const char *path,
const char *branch)
{
- die("Not yet implemented.");
+ struct strbuf newpath = STRBUF_INIT;
+ int suffix = 0;
+ size_t base_len;
+
+ strbuf_addf(&newpath, "%s~", path);
+ add_flattened_path(&newpath, branch);
+
+ base_len = newpath.len;
+ while (strmap_contains(existing_paths, newpath.buf)) {
+ strbuf_setlen(&newpath, base_len);
+ strbuf_addf(&newpath, "_%d", suffix++);
+ }
+
+ return strbuf_detach(&newpath, NULL);
}
/*** Function Grouping: functions related to collect_merge_info() ***/