Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
From: Derrick Stolee <stolee@gmail.com>
To: Elijah Newren <newren@gmail.com>
Cc: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 03/10] merge-ort: implement unique_path() helper
Date: Thu, 31 Dec 2020 06:19:55 -0500
Message-ID: <0636b843-5dbd-2855-5c43-8f65a528bbc9@gmail.com> (raw)
In-Reply-To: <CABPp-BF37UeBdF4T68rvOaFRtPyZ2uoUSe48V4K8CUigy77CfA@mail.gmail.com>

On 12/30/2020 10:10 AM, Elijah Newren wrote:
> On Wed, Dec 30, 2020 at 6:16 AM Derrick Stolee <stolee@gmail.com> wrote:
>> On 12/18/2020 12:51 AM, Elijah Newren via GitGitGadget wrote:
>>> From: Elijah Newren <newren@gmail.com>
>>>
>>> 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>
>>> ---
>>>  merge-ort.c | 25 ++++++++++++++++++++++++-
>>>  1 file changed, 24 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/merge-ort.c b/merge-ort.c
>>> index d300a02810e..1adc27a11bc 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] = '_';
>>> +}
>>> +
>>
>> Thank you for pointing out that you based your code on merge-recursive.c.
>> I see that this implementation is identical to the one there. I question
>> whether this causes collisions in a problematic way, when "a/b/c" and
>> "a_b_c" both exist in a tree.
>>
>> To avoid such a problem, we'd likely need to also expand "_" to "__" or
>> similar. This might never actually affect any users because of the
>> strange filename matches _and_ we need to be in a directory/file conflict.
>>
>> And maybe it's not a hole at all? If it is, we can consider patching or
>> at least documenting the problem.
> 
> add_flattened_path() can certainly result in a collision, regardless
> of whether the char *s parameter has any '/' characters in it.  For
> example, if you are trying to get a unique path associated with
> builtin/commit-graph.c due to changes from the 'next' branch side of
> the merge, and builtin/commit-graph.c~next already exists, then you
> have a collision.  It's actually pretty rare that the parameter would
> have any '/' characters at all, since it's pretty rare for me to see
> folks (other than Junio) use hierarchical branch names.  But if the
> branch name were ds/line-log-on-bloom, then the provisional filename
> would be builtin/commit-graph.c~ds_line-log-on-bloom.  The '/' to '_'
> conversion exists just to make sure our new file remains in the same
> directory as where the conflict that caused us to need a new unique
> path occurred.

Ah, I am misinterpreting which '/' characters are getting squashed.
Thank you for fixing my confusion.

> But unique_path() does NOT end immediately after calling
> add_flattened_path() and there is no collision possible in the return
> from unique_path(), because it ends with a
>     while (strmap_contains(existing_paths, newpath.buf)) {
> loop that modifies the resulting path until it finds one that doesn't
> collide with an existing path.

And this extra care here is helpful. Thanks!

-Stolee


  reply index

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-18  5:51 [PATCH 00/10] merge-ort: add more handling of basic conflict types Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 01/10] merge-ort: handle D/F conflict where directory disappears due to merge Elijah Newren via GitGitGadget
2020-12-30 14:06   ` Derrick Stolee
2020-12-30 15:13     ` Elijah Newren
2020-12-31 11:17       ` Derrick Stolee
2020-12-31 17:13         ` Elijah Newren
2020-12-18  5:51 ` [PATCH 02/10] merge-ort: handle directory/file conflicts that remain Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 03/10] merge-ort: implement unique_path() helper Elijah Newren via GitGitGadget
2020-12-30 14:16   ` Derrick Stolee
2020-12-30 15:10     ` Elijah Newren
2020-12-31 11:19       ` Derrick Stolee [this message]
2020-12-18  5:51 ` [PATCH 04/10] merge-ort: handle book-keeping around two- and three-way content merge Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 05/10] merge-ort: flesh out implementation of handle_content_merge() Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 06/10] merge-ort: copy and adapt merge_3way() from merge-recursive.c Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 07/10] merge-ort: copy and adapt merge_submodule() " Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 08/10] merge-ort: implement format_commit() Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 09/10] merge-ort: copy find_first_merges() implementation from merge-recursive.c Elijah Newren via GitGitGadget
2020-12-18  5:51 ` [PATCH 10/10] merge-ort: add handling for different types of files at same path Elijah Newren via GitGitGadget
2020-12-29  0:44 ` [PATCH 00/10] merge-ort: add more handling of basic conflict types Elijah Newren
2021-01-01  2:34 ` [PATCH v2 " Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 01/10] merge-ort: handle D/F conflict where directory disappears due to merge Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 02/10] merge-ort: handle directory/file conflicts that remain Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 03/10] merge-ort: implement unique_path() helper Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 04/10] merge-ort: handle book-keeping around two- and three-way content merge Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 05/10] merge-ort: flesh out implementation of handle_content_merge() Elijah Newren via GitGitGadget
2021-03-04 16:28     ` A merge-ort TODO comment, and how to test merge-ort? Ævar Arnfjörð Bjarmason
2021-03-04 19:43       ` Elijah Newren
2021-03-04 21:29         ` Ævar Arnfjörð Bjarmason
2021-03-04 22:45           ` Elijah Newren
2021-03-08 14:49             ` Ævar Arnfjörð Bjarmason
2021-01-01  2:34   ` [PATCH v2 06/10] merge-ort: copy and adapt merge_3way() from merge-recursive.c Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 07/10] merge-ort: copy and adapt merge_submodule() " Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 08/10] merge-ort: implement format_commit() Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 09/10] merge-ort: copy find_first_merges() implementation from merge-recursive.c Elijah Newren via GitGitGadget
2021-01-01  2:34   ` [PATCH v2 10/10] merge-ort: add handling for different types of files at same path Elijah Newren via GitGitGadget
2021-01-05 14:23   ` [PATCH v2 00/10] merge-ort: add more handling of basic conflict types Derrick Stolee
2021-01-06 19:20     ` Elijah Newren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0636b843-5dbd-2855-5c43-8f65a528bbc9@gmail.com \
    --to=stolee@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git