git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 03/10] merge-ort: implement unique_path() helper

From
Elijah Newren <newren@gmail.com>
Date
Dec 30, 2020, 15:10 UTC
Message-ID
<CABPp-BF37UeBdF4T68rvOaFRtPyZ2uoUSe48V4K8CUigy77CfA@mail.gmail.com>
In-Reply-To
<3a07f700-18fc-9f4e-3117-41e534d737b0@gmail.com>
On Wed, Dec 30, 2020 at 6:16 AM Derrick Stolee <stolee@gmail.com> wrote:
Show 44 quoted lines
>
> 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.

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.
Previous: Derrick StoleeNext: Derrick Stolee
Message 9 of 37 in “merge-ort: add more handling of basic conflict types”
  1. 00/10 merge-ort: add more handling of basic conflict typesElijah Newren via GitGitGadget, Dec 18, 2020
  2. 01/10 merge-ort: handle D/F conflict where directory disappears due to mergeElijah Newren via GitGitGadget, Dec 18, 2020
  3. Derrick StoleeDec 30, 2020
  4. Elijah NewrenDec 30, 2020
  5. Derrick StoleeDec 31, 2020
  6. Elijah NewrenDec 31, 2020
  7. 03/10 merge-ort: implement unique_path() helperElijah Newren via GitGitGadget, Dec 18, 2020
  8. Derrick StoleeDec 30, 2020
  9. Elijah NewrenDec 30, 2020
  10. Derrick StoleeDec 31, 2020
  11. 04/10 merge-ort: handle book-keeping around two- and three-way content mergeElijah Newren via GitGitGadget, Dec 18, 2020
  12. 02/10 merge-ort: handle directory/file conflicts that remainElijah Newren via GitGitGadget, Dec 18, 2020
  13. 05/10 merge-ort: flesh out implementation of handle_content_merge()Elijah Newren via GitGitGadget, Dec 18, 2020
  14. 07/10 merge-ort: copy and adapt merge_submodule() from merge-recursive.cElijah Newren via GitGitGadget, Dec 18, 2020
  15. 09/10 merge-ort: copy find_first_merges() implementation from merge-recursive.cElijah Newren via GitGitGadget, Dec 18, 2020
  16. 10/10 merge-ort: add handling for different types of files at same pathElijah Newren via GitGitGadget, Dec 18, 2020
  17. 06/10 merge-ort: copy and adapt merge_3way() from merge-recursive.cElijah Newren via GitGitGadget, Dec 18, 2020
  18. 08/10 merge-ort: implement format_commit()Elijah Newren via GitGitGadget, Dec 18, 2020
  19. Elijah NewrenDec 29, 2020
  20. 00/10 merge-ort: add more handling of basic conflict typesElijah Newren via GitGitGadget, Jan 1, 2021
  21. 01/10 merge-ort: handle D/F conflict where directory disappears due to mergeElijah Newren via GitGitGadget, Jan 1, 2021
  22. 05/10 merge-ort: flesh out implementation of handle_content_merge()Elijah Newren via GitGitGadget, Jan 1, 2021
  23. A merge-ort TODO comment, and how to test merge-ort?Ævar Arnfjörð Bjarmason, Mar 4, 2021
  24. Elijah NewrenMar 4, 2021
  25. Ævar Arnfjörð BjarmasonMar 4, 2021
  26. Elijah NewrenMar 4, 2021
  27. Ævar Arnfjörð BjarmasonMar 8, 2021
  28. 03/10 merge-ort: implement unique_path() helperElijah Newren via GitGitGadget, Jan 1, 2021
  29. 04/10 merge-ort: handle book-keeping around two- and three-way content mergeElijah Newren via GitGitGadget, Jan 1, 2021
  30. 07/10 merge-ort: copy and adapt merge_submodule() from merge-recursive.cElijah Newren via GitGitGadget, Jan 1, 2021
  31. 02/10 merge-ort: handle directory/file conflicts that remainElijah Newren via GitGitGadget, Jan 1, 2021
  32. 09/10 merge-ort: copy find_first_merges() implementation from merge-recursive.cElijah Newren via GitGitGadget, Jan 1, 2021
  33. 08/10 merge-ort: implement format_commit()Elijah Newren via GitGitGadget, Jan 1, 2021
  34. 10/10 merge-ort: add handling for different types of files at same pathElijah Newren via GitGitGadget, Jan 1, 2021
  35. 06/10 merge-ort: copy and adapt merge_3way() from merge-recursive.cElijah Newren via GitGitGadget, Jan 1, 2021
  36. Derrick StoleeJan 5, 2021
  37. Elijah NewrenJan 6, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.