{"thread":{"id":"59330","subject":"\"git diff\" surprising default output","startedAt":"2023-03-01T18:25:51Z","lastAt":"2023-03-01T20:28:51Z","messageCount":3,"participants":["Sergey Organov","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"472891","messageId":"871qm849co.fsf@osv.gnss.ru","threadId":"59330","inReplyTo":null,"subject":"\"git diff\" surprising default output","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2023-03-01T18:25:43Z","receivedAt":"2023-03-01T18:25:51Z","isPatch":false,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Hello,\n\nBy default, 'git diff' produces an output that is often rather\nsurprising and difficult to grok, here is a simple example:\n\n$ git diff --no-index -- f0.txt f1.txt\ndiff --git a/f0.txt b/f1.txt\nindex 3af00a929..35478f7bd 100644\n--- a/f0.txt\n+++ b/f1.txt\n@@ -3,9 +3,6 @@\n #endif\n #if CANOPEN > 0\n     IMD_CANOPEN,\n-#endif\n-#if MDL_LASER > 0\n-    IMD_LASER,\n #endif\n     IMD_AUTO,\n     IMD_NONE,\n\nI figured the offender is --indent-heuristic that is described in the\nmanual as:\n\n      Enable the heuristic that shifts diff hunk boundaries to make\n      patches easier to read. This is the default.\n\nbut apparently rather makes patches harder to read, at least at some\nconditions. Turning it off helps to get the expected result:\n\n$ git diff --no-index --no-indent-heuristic -- f0.txt f1.txt\ndiff --git a/f0.txt b/f1.txt\nindex 3af00a929..35478f7bd 100644\n--- a/f0.txt\n+++ b/f1.txt\n@@ -4,9 +4,6 @@\n #if CANOPEN > 0\n     IMD_CANOPEN,\n #endif\n-#if MDL_LASER > 0\n-    IMD_LASER,\n-#endif\n     IMD_AUTO,\n     IMD_NONE,\n     IMD_COUNT\n\n\nChanging --diff-algorithm doesn't change the outcome.\n\nSo the questions are:\n\n- Is there an example of an advantage the option has?\n\n- Is it possible to flip the default?\n\nThanks,\n-- Sergey Organov\n"},{"id":"472895","messageId":"xmqqzg8wmfa6.fsf@gitster.g","threadId":"59330","inReplyTo":"871qm849co.fsf@osv.gnss.ru","subject":"Re: \"git diff\" surprising default output","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-03-01T19:40:17Z","receivedAt":"2023-03-01T19:40:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sergey Organov <sorganov@gmail.com> writes:\n\n> I figured the offender is --indent-heuristic that is described in the\n> manual as:\n>\n>       Enable the heuristic that shifts diff hunk boundaries to make\n>       patches easier to read. This is the default.\n>\n> but apparently rather makes patches harder to read, at least at some\n> conditions. Turning it off helps to get the expected result:\n\nAs a heuristic, it is not surprising that it has some corner cases\nwhere it does not shine.  I think the version that was eventually\nmerged starts here\n\n  https://lore.kernel.org/git/cover.1473068229.git.mhagger@alum.mit.edu/\n\nand we should be able to find a few links to the original\nobservation that motivated the change, e.g.\n\n  https://public-inbox.org/git/cover.1470259583.git.mhagger@alum.mit.edu/\n\n\n\nThanks.\n"},{"id":"472900","messageId":"87sfeo2p38.fsf@osv.gnss.ru","threadId":"59330","inReplyTo":"xmqqzg8wmfa6.fsf@gitster.g","subject":"Re: \"git diff\" surprising default output","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2023-03-01T20:28:43Z","receivedAt":"2023-03-01T20:28:51Z","isPatch":false,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Sergey Organov <sorganov@gmail.com> writes:\n>\n>> I figured the offender is --indent-heuristic that is described in the\n>> manual as:\n>>\n>>       Enable the heuristic that shifts diff hunk boundaries to make\n>>       patches easier to read. This is the default.\n>>\n>> but apparently rather makes patches harder to read, at least at some\n>> conditions. Turning it off helps to get the expected result:\n>\n> As a heuristic, it is not surprising that it has some corner cases\n> where it does not shine.  I think the version that was eventually\n> merged starts here\n>\n>   https://lore.kernel.org/git/cover.1473068229.git.mhagger@alum.mit.edu/\n>\n> and we should be able to find a few links to the original\n> observation that motivated the change, e.g.\n>\n>   https://public-inbox.org/git/cover.1470259583.git.mhagger@alum.mit.edu/\n\nThanks a lot for the references!\n\nFrom what I briefly read there it apparently follows that it'd shine at\nregular C code, yet won't shine at preprocessor directives that are\nusually out of regular alignment.\n\nIt'd be nice to improve this, but I'm not sure it's a simple thing to\nfix, or even at all possible, though maybe it'd help to somehow favoring\nchunks that start and end at the same alignment?\n\nOr maybe it's just plain bug in the implementation?\n\nThanks,\n-- Sergey Organov\n"}]}