Subject: git rerere is confused with identical conflicts in multiple files

From: Markos Chandras <[email-masked]>
Date: Fri, 10 Jul 2015 09:04:17 +0100

Hi,

(Please keep me on CC as I am not subscribed to the list)

I am having a weird problem when merging a branch which causes some
conflicts

This is the initial status for the rerere cache

$ tree .git/rr-cache
.git/rr-cache [error opening dir]

0 directories, 0 files

I then go ahead and merge the said branch and I end up with the
following conflicts

Auto-merging arch/mips/mm/sc-mips.c
Auto-merging arch/mips/mm/c-r4k.c
CONFLICT (content): Merge conflict in arch/mips/mm/c-r4k.c
Auto-merging arch/mips/kernel/traps.c
CONFLICT (content): Merge conflict in arch/mips/kernel/traps.c
Auto-merging arch/mips/kernel/spram.c
CONFLICT (content): Merge conflict in arch/mips/kernel/spram.c
Auto-merging arch/mips/kernel/idle.c
CONFLICT (content): Merge conflict in arch/mips/kernel/idle.c
Auto-merging arch/mips/kernel/cpu-probe.c
Auto-merging arch/mips/include/asm/mipsregs.h
Auto-merging arch/mips/include/asm/cpu.h
CONFLICT (content): Merge conflict in arch/mips/include/asm/cpu.h
Auto-merging arch/mips/include/asm/cpu-type.h
CONFLICT (content): Merge conflict in arch/mips/include/asm/cpu-type.h
Recorded preimage for 'arch/mips/include/asm/cpu-type.h'
Recorded preimage for 'arch/mips/include/asm/cpu.h'
Automatic merge failed; fix conflicts and then commit the result.

As you see, git only records two preimage files instead of 6.

the rr-cache is like this now

$ tree .git/rr-cache
.git/rr-cache
├── 5563edc0fb427275a0ca5677c93c40def8b53258
│   └── preimage
└── f175ff6228f624296b661664bce4ab4e84d712cc
    └── preimage

2 directories, 2 files

and .git/MERGE_RR

$ cat .git/MERGE_RR
5563edc0fb427275a0ca5677c93c40def8b53258
arch/mips/include/asm/cpu-type.hf175ff6228f624296b661664bce4ab4e84d712cc

arch/mips/include/asm/cpu.h5563edc0fb427275a0ca5677c93c40def8b53258
   arch/mips/kernel/idle.c5563edc0fb427275a0ca5677c93c40def8b53258
arch/mips/kernel/spram.c5563edc0fb427275a0ca5677c93c40def8b53258
arch/mips/kernel/traps.c5563edc0fb427275a0ca5677c93c40def8b53258
arch/mips/mm/c-r4k.c

so as you see, multiple files share the same hash. That's probably
because the "conflicting context ( the part between >>> <<<<)" in every
file but cpu.h is identical and git seems to calculate the hash purely
on the conflicting context. That makes git rerere thinks that it only
has to resolve 2 conflicts instead of 6.

Does anyone have an idea how to resolve that? If my assumption is
correct (I only looked at the git code briefly) I believe it would make
sense to throw the filepath into the sha1 calculation as well in order
to ensure it will not conflict with similar changes across different files.

-- 
markos