From: Stefan Beller Date: Tue, 29 Mar 2016 18:16:57 GMT Subject: Re: weird diff output? Message-ID: In-Reply-To: On Tue, Mar 29, 2016 at 10:54 AM, Junio C Hamano wrote: > Stefan Beller writes: > >> I thought this is an optimization for C code where you have a diff like: >> >> int existingStuff1(..) { >> ... >> } >> + >> + int foo(..) { >> +... >> +} >> >> int existingStuff2(...) { >> ... >> >> Note that the closing '}' could be taken from the method existingStuff1 instead >> of correctly closing foo. > > That is a less optimal output. Another possible output would be > like so: > > int existingStuff1(..) { > ... > } > > + int foo(..) { > +... > +} > + > int existingStuff2(...) { > > All three are valid output, and ... > >> So the correct heuristic really depends on what kind of text we >> are diffing. > > ... this realization is correct. > > I have a feeling that any heuristic would be correct half of the > time, including the ehuristic implemented in the current code. The > readers of patches have inherent bias. They do not notice when the > hunk is formed to match their expectation, but they will notice and > remember when they see something less optimal. > We have 3 possible diffs: 1) closing brace and newline before the chunk 2) newline before, closing brace after the chunk 3) closing brace and newline after the chunk For C code we may want to conclude that 3) is best. (appeals the bias of most people) 2 is slightly worse, whereas 1) is absolutely worst. Now looking at the code Jacob found strange: > cat > expect < + expected results ... > + EOF > +test_expect_failure ... ' > + ... > + ' > + > +cat > expect < expect < expect < } > > + int foo(..) { > +... > +} > + > int existingStuff2(...) { > test_expect_failure ... ' > existing test ... > ' > > + cat > expect < + expected results ... > + EOF > +test_expect_failure ... ' > + ... > + ' > + > cat > expect <