On Fri, Apr 13, 2018 at 12:02 AM, Elijah Newren wrote: > > I hope you don't mind me barging into your conversation I was getting tired of my own rambling anyway.. > However, it turns out we have this awesome function called > "was_tracked(const char *path)" that was intended for answering this > exact question. So, assuming was_tracked() isn't buggy, the correct > patch for this problem would look like: Apparently that causes problems, for some odd reason. I like the notion of checking the index, but it's not clear that the index is reliable in the presence of renames either. > A big series > including that patch was merged to master two days ago, but > unfortunately that exact patch was the one that caused some > impressively awful fireworks[1]. Yeah, so this code is fragile. How about we take a completely different approach? Instead of relying on fragile (but clever) tests, why not rely on stupid brute force? Yeah, yeah, it's bad to be stupid, but sometimes simple and stupid really does work. See the attached patch. It gets rid of all the subtle "has this been renamed" tests entirely, and just _always_ does that final update_file(). But instead, it makes update_file() a bit smarter, and says "before we write this file out, let's see if it's already there and already has the expected contents"? Now, it really shouldn't be _quite_ as stupid as that: we should probably set a flag in the "hey, the oid matches, maybe it's worth checking", so that it doesn't do the check in the cases where we know the merge has done things. But it's actually *fairly* low cost, because before it reads the file it at least checks that file length matches the expected length (and that the user permission bits match the expected mode). So if the file doesn't match, most of the time the real cost will just be an extra 'open/fstat/close()' sequence. That's pretty cheap. So even the completely stupid approach is probably not too bad, and it could be made smarter. NOTE! I have *NOT* tested this on anything interesting. I tested the patch on my stupid test-case, but that'[s it. I didn't even bother re-doing the kernel merge that started this. Comments? Because considering the problems this code has had, maybe "stupid" really is the right approach... [ Ok, I lied. I just tested this on the kernel merge. It worked fine, and avoided modifying ] Linus