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

Re: git mv messed up file mapping if folders contain identical files

From
BOBill Okara <billokara@gmail.com>
Date
Feb 26, 2016, 15:48 UTC
Message-ID
<CADsr5c-WztuTM5Tmu9_h_9_uSnGLwqSR1c5ZPa_DDi9yAJBNnw@mail.gmail.com>
In-Reply-To
<1456487400-31174-1-git-send-email-szeder@ira.uka.de>
Hi,
On Fri, Feb 26, 2016 at 4:50 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:
>
> Please don't top-post on this list.
>
Sorry about that. Just learned what that means and why it is bad...
Show 29 quoted lines
> Subject: [PATCH] diffcore: fix iteration order of identical files during rename detection
>
> If the two paths 'dir/A/file' and 'dir/B/file' have identical content
> and the parent directory is renamed, e.g. 'git mv dir other-dir', then
> diffcore reports the following exact renames:
>
>     renamed:    dir/B/file -> other-dir/A/file
>     renamed:    dir/A/file -> other-dir/B/file
>
> While technically not wrong, this is confusing not only for the user,
> but also for git commands that make decisions based on rename
> information, e.g. 'git log --follow'.
>
> This behavior is a side effect of commit v2.0.0-rc4~8^2~14
> (diffcore-rename.c: simplify finding exact renames, 2013-11-14): the
> hashmap storing sources returns entries from the same bucket, i.e.
> sources matching the current destination, in LIFO order.  Thus the
> iteration first examines 'other-dir/A/file' and 'dir/B/file' and, upon
> finding identical content and basename, reports an exact rename.
>
> Restore the original behavior by reversing the order of filling the
> hashmap with source entries.
>
> Reported-by: Bill Okara <billokara@gmail.com>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
>  diffcore-rename.c      |  6 ++++--
>  t/t4001-diff-rename.sh | 11 +++++++++++
>  2 files changed, 15 insertions(+), 2 deletions(-)
Show 25 quoted lines
> diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh
> index 2f327b749588..ed90c6c6f984 100755
> --- a/t/t4001-diff-rename.sh
> +++ b/t/t4001-diff-rename.sh
> @@ -77,6 +77,17 @@ test_expect_success 'favour same basenames even with minor differences' '
>         git show HEAD:path1 | sed "s/15/16/" > subdir/path1 &&
>         git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
>
> +test_expect_success 'two files with same basename and same content' '
> +       git reset --hard &&
> +       mkdir -p dir/A dir/B &&
> +       cp path1 dir/A/file &&
> +       cp path1 dir/B/file &&
> +       git add dir &&
> +       git commit -m 2 &&
> +       git mv dir other-dir &&
> +       git status | test_i18ngrep "renamed: .*dir/A/file -> other-dir/A/file"
> +'
> +
>  test_expect_success 'setup for many rename source candidates' '
>         git reset --hard &&
>         for i in 0 1 2 3 4 5 6 7 8 9;
> --
> 2.7.2.410.g92cb358
>
Thank you very much for the fix and the detailed explanation!
-Bill
Previous: SZEDER Gábor
Message 9 of 9 in “git mv messed up file mapping if folders contain identical files”
  1. Bill OkaraFeb 24, 2016
  2. Junio C HamanoFeb 24, 2016
  3. Bill OkaraFeb 24, 2016
  4. Bill OkaraFeb 25, 2016
  5. Kevin DaudtFeb 25, 2016
  6. Stefan BellerFeb 25, 2016
  7. Bill OkaraFeb 25, 2016
  8. SZEDER GáborFeb 26, 2016
  9. Bill OkaraFeb 26, 2016

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.