Thread (47 messages) 47 messages, 4 authors, 2017-11-26

Re: [PATCH v3 25/33] merge-recursive: check for file level conflicts then get new name

From: Stefan Beller <hidden>
Date: 2017-11-22 18:56:12

On Tue, Nov 21, 2017 at 12:00 AM, Elijah Newren [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Before trying to apply directory renames to paths within the given
directories, we want to make sure that there aren't conflicts at the
file level either.  If there aren't any, then get the new name from
any directory renames.

Signed-off-by: Elijah Newren <redacted>
---
 merge-recursive.c                   | 192 ++++++++++++++++++++++++++++++++++--
 t/t6043-merge-rename-directories.sh |   2 +-
 2 files changed, 185 insertions(+), 9 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index b8c7d6dce3..5bc207b819 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1496,6 +1496,109 @@ static void get_renamed_dir_portion(const char *old_path, const char *new_path,
        }
 }

+/*
+ * Write:
+ *   element1, element2, element3, ..., elementN
+ * to str.  If only one element, just write "element1" to str.
+ */
+static void comma_separated_list(char *str, struct string_list *slist)
This is quite a low level function, so I wondered if we have such functionality
already, but neither string-list.h nor strbuf.h present a drop-in replacement.
Speaking of strbufs, this might be another "big thing" to use in this series as
strbufs make using strings (and its memory management) easier in git.

This functionality could look like this (in strbuf.c):

/*
 * Adds all strings of a string list to the strbuf, separated by the
given separator.
 * For example a list of ("a", "b") with sep=";" would result in "a;b" added
 * to the strbuf.
 */
void strbuf_add_separated_string_list(struct strbuf *sb, struct
string_list *slist, const char *sep)
{
    int add_sep = 0;
    struct string_list_item *item;

    for_each_string_list_item(item, s_list) {
        if (add_sep)
            strbuf_addstr(sb, sep);
        strbuf_addstr(item->string);
        add_sep = 1;
    }
}

+{
+       int i;
+
+       for (i = 0; i < slist->nr; i++) {
+               str += sprintf(str, "%s", slist->items[i].string);
+               if (i < slist->nr-1)
style nit: blanks before and after '-';
+                       str += sprintf(str, ", ");
+       }
+}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help