{"thread":{"id":"52516","subject":"[BUG] `git diff` treats an unchanged line as modified","startedAt":"2019-12-24T17:50:46Z","lastAt":"2019-12-25T15:26:23Z","messageCount":3,"participants":["Hao Lee","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"388868","messageId":"CA+PpKPm0_zXr978Mw8h7owHBChx-uqVCdjrtuh45uOS-A_0qrA@mail.gmail.com","threadId":"52516","inReplyTo":null,"subject":"[BUG] `git diff` treats an unchanged line as modified","fromName":"Hao Lee","fromEmail":"haolee.swjtu@gmail.com","sentAt":"2019-12-24T17:50:29Z","receivedAt":"2019-12-24T17:50:46Z","isPatch":false,"sender":{"key":"haolee.swjtu@gmail.com","avatar":null},"body":"Here are two files `old` and `new`.\n\nThe content of `old` file:\n\n```\n\n\n\nkasan_poison_slab(page);//\n\nshuffle = shuffle_freelist(s, page);//\n\nif (!shuffle) {\nfor_each_object_idx(p, idx, s, start, page->objects) {\nsetup_object(s, page, p);\nif (likely(idx < page->objects))\n```\n\nThe content of `new` file:\n\n```\n\n\n\nkasan_poison_slab(page);\n\nshuffle = shuffle_freelist(s, page);\n```\n\nWhen using git to compare these two files, the result is:\n\n```\ndiff --git a/old b/new\nindex 474ab07..d432a67 100644\n--- a/old\n+++ b/new\n@@ -1,11 +1,6 @@\n\n\n\n-       kasan_poison_slab(page);//\n-\n-       shuffle = shuffle_freelist(s, page);//\n-\n-       if (!shuffle) {\n-               for_each_object_idx(p, idx, s, start, page->objects) {\n-                       setup_object(s, page, p);\n-                       if (likely(idx < page->objects))\n+       kasan_poison_slab(page);\n+\n+       shuffle = shuffle_freelist(s, page);\n```\n\nHowever, the Linux diff command gives the following result:\n\n```\n--- old 2019-12-25 00:56:40.000000000 +0800\n+++ new 2019-12-25 01:12:48.000000000 +0800\n@@ -1,11 +1,6 @@\n\n\n\n- kasan_poison_slab(page);//\n+ kasan_poison_slab(page);\n\n- shuffle = shuffle_freelist(s, page);//\n-\n- if (!shuffle) {\n- for_each_object_idx(p, idx, s, start, page->objects) {\n- setup_object(s, page, p);\n- if (likely(idx < page->objects))\n+ shuffle = shuffle_freelist(s, page);\n```\n\nI think the latter is correct because the fifth line is not changed\nand it's still a line which only contains a whitespace.\n\nSteps to Reproduce:\n\ncurl -L https://git.io/JeFNy | base64 -d > file.tgz\ntar -xf file.tgz\ngit diff --no-index old new\n"},{"id":"388874","messageId":"xmqqy2v14iwc.fsf@gitster-ct.c.googlers.com","threadId":"52516","inReplyTo":"CA+PpKPm0_zXr978Mw8h7owHBChx-uqVCdjrtuh45uOS-A_0qrA@mail.gmail.com","subject":"Re: [BUG] `git diff` treats an unchanged line as modified","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-12-24T19:34:43Z","receivedAt":"2019-12-24T19:34:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Hao Lee <haolee.swjtu@gmail.com> writes:\n\n> I think the latter is correct because the fifth line is not changed\n> and it's still a line which only contains a whitespace.\n\nAs long as lines that begin with \"-\" and \" \" match what the 'old'\nfile has, and replacing them with lines that begin with \" \" and\n\"+\" in the 'old' file yields the 'new' file, any patch is \"correct\".\n\nIOW, there is no *single* diff output that is correct.\n\nAmong many \"correct\" diff output, there are ones that readers find\nthem easier to understand and those that look suboptimal.  The\ndifferences are often personal tastes.\n\n\"git diff\" has options to tweak heuristics it uses to choose among\nmany \"correct\" diff outputs, like --patience, --histogram, etc.\nPerhaps using one of them would produce one that match your taste\nbetter?\n\n"},{"id":"388908","messageId":"CA+PpKPnCrSciiNinC9g6BVX7DHXPDq8k2zegK+-9Yg2CPzF_bQ@mail.gmail.com","threadId":"52516","inReplyTo":"xmqqy2v14iwc.fsf@gitster-ct.c.googlers.com","subject":"Re: [BUG] `git diff` treats an unchanged line as modified","fromName":"Hao Lee","fromEmail":"haolee.swjtu@gmail.com","sentAt":"2019-12-25T15:26:05Z","receivedAt":"2019-12-25T15:26:23Z","isPatch":false,"sender":{"key":"haolee.swjtu@gmail.com","avatar":null},"body":"On Wed, 25 Dec 2019 at 03:34, Junio C Hamano <gitster@pobox.com> wrote:\n> IOW, there is no *single* diff output that is correct.\n>\n> Among many \"correct\" diff output, there are ones that readers find\n> them easier to understand and those that look suboptimal.  The\n> differences are often personal tastes.\n\nThanks, this explanation is clear for me.\n\n> \"git diff\" has options to tweak heuristics it uses to choose among\n> many \"correct\" diff outputs, like --patience, --histogram, etc.\n> Perhaps using one of them would produce one that match your taste\n> better?\n>\n\nAfter understanding the correctness of diff algorithm, the default\nalgorithm also suits my needs now, although the patience algorithm is\nmore understandable in some special circumstances.\n\nRegards,\nHao Lee\n"}]}