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

Re: [RFC PATCH] merge-recursive: symlink's descendants not in way

From
Elijah Newren <newren@gmail.com>
Date
Sep 18, 2019, 00:35 UTC
Message-ID
<CABPp-BEXjZCOOuDS4b1bajYvE-T0NVw32YCRMi9Ks8TikPhORg@mail.gmail.com>
In-Reply-To
<20190917215040.132503-1-jonathantanmy@google.com>
Hi Jonathan,
On Tue, Sep 17, 2019 at 2:50 PM Jonathan Tan <jonathantanmy@google.com> wrote:
Show 18 quoted lines
>
> When the working tree has:
>  - foo (symlink)
>  - foo/bar (directory)
>
> and the user merges a commit that deletes the foo symlink and instead
> contains:
>  - foo (directory)
>  - foo/bar (file)
>
> the merge should happen without requiring user intervention. However,
> this does not happen.
>
> In merge_trees(), process_entry() will be invoked first for "foo/bar",
> then "foo" (in reverse lexicographical order). process_entry() correctly
> reaches "Case B: Added in one", but dir_in_way() states that "bar" is
> already present as a directory, causing a directory/file conflict at the
> wrong point.

I don't think the notes about hitting the "Case B: Added in one" codepath help; that's only one codepath that calls dir_in_way(), and I'm pretty sure with a little work we could trigger the same bug with the other ones.

Show 11 quoted lines
> Instead, teach dir_in_way() that directories under symlinks are not "in
> the way", so that symlinks are treated as regular files instead of
> directories containing other directories and files. Thus, the "else"
> branch will be followed instead: "foo/bar" will be added to the working
> tree, make_room_for_path() being indirectly called to unlink the "foo"
> symlink (just like if "foo" were a regular file instead). When
> process_entry() is subsequently invoked for "foo", process_entry() will
> reach "Case A: Deleted in one", and will handle it as "Add/delete" or
> "Modify/delete" appropriately (including reinstatement of the previously
> unlinked symlink with a new unique filename if necessary, again, just
> like if "foo" were a regular file instead).

I was trying to think of a way to summarize it a bit, and then Junio later in the thread came in and provided a different and compatible way to view the issue that summarizes it quite nicely:

"In any case, if the working tree has 'foo' as a symlink, Git should not look at or get affected by what 'foo' points at."

We can probably make the commit message pretty concise using that wording or something similar. Maybe adding something like "In particular, the presence of a symlink should be treated much the same as the presence of a file; since dir_in_way() is only checking to see if there is a directory in the way, we don't want symlinks in leading paths to sometimes cause dir_in_way() to return true."

Show 12 quoted lines
>
> Helped-by: Elijah Newren <newren@gmail.com>
> Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
> ---
> Thanks to Elijah for his help. Some of the commit message is based on
> his explanation [1].
>
> I'm finding this relatively complicated, so I'm sending this as RFC. My
> main concern is that whether all callers of dir_in_way() are OK with its
> behavior change, and if yes, how to explain it. I suspect that this is
> correct because dir_in_way() should behave consistently for all its
> callers, but I might be wrong.

Yes, we want all callers of dir_in_way() to get this change; if they don't, I'm pretty sure with some work we could devise special scenarios that exhibit the same bug.

Thanks for working on this, Elijah

Previous: SZEDER Gábor
Message 13 of 13 in “merge-recursive thinks symlink's child dirs are "real"”
  1. Jonathan TanSep 16, 2019
  2. SZEDER GáborSep 16, 2019
  3. Elijah NewrenSep 17, 2019
  4. Jonathan NiederSep 17, 2019
  5. Elijah NewrenSep 17, 2019
  6. Elijah NewrenSep 17, 2019
  7. merge-recursive: symlink's descendants not in wayJonathan Tan, Sep 17, 2019
  8. Junio C HamanoSep 17, 2019
  9. Jonathan TanSep 17, 2019
  10. Junio C HamanoSep 17, 2019
  11. Jonathan TanSep 17, 2019
  12. SZEDER GáborSep 17, 2019
  13. Elijah NewrenSep 18, 2019

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.