{"thread":{"id":"15180","subject":"[PATCH (BUGFIX)] Respect core.autocrlf in combined diff","startedAt":"2008-08-23T19:21:21Z","lastAt":"2008-08-24T09:21:57Z","messageCount":4,"participants":["Alexander Gavrilov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"88306","messageId":"200808232321.21795.angavrilov@gmail.com","threadId":"15180","inReplyTo":null,"subject":"[PATCH (BUGFIX)] Respect core.autocrlf in combined diff","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-08-23T19:21:21Z","receivedAt":"2008-08-23T19:21:21Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"Fix git-diff to make it produce useful 3-way\ndiffs for merge conflicts in repositories with\nautocrlf enabled. Otherwise it always reports\nthat the whole file was changed.\n\nSigned-off-by: Alexander Gavrilov <angavrilov@gmail.com>\n---\n\n\tI noticed that combined diffs, which are shown by git-diff for files\n\twith conflicts, are unusable on repositories with autocrlf=true. \n\n\tSteps to reproduce:\n\n\t\tgit init\n\t\techo foo > file\n\t\tgit add file\n\t\tgit commit -m init\n\t\tgit checkout -b a\n\t\tgit checkout -b b\n\t\techo bbb >> file\n\t\tgit add file\n\t\tgit commit -m bbb\n\t\tgit checkout a\n\t\techo aaa >> file\n\t\tgit add file\n\t\tgit commit -m aaa\n\t\tgit config core.autocrlf true\n\t\tgit merge b\n\n\tThen look at the output of git diff.\n\n\t-- Alexander\n\n combine-diff.c |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 9f80a1c..da1ca99 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -727,6 +727,18 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\t\tdie(\"early EOF '%s'\", elem->path);\n \n \t\t\tresult[len] = 0;\n+\n+\t\t\t/* If not a fake symlink, apply filters, e.g. autocrlf */\n+\t\t\tif (is_file) {\n+\t\t\t\tstruct strbuf buf;\n+\t\t\t\t\n+\t\t\t\tstrbuf_init(&buf, 0);\n+\t\t\t\tif (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {\n+\t\t\t\t\tfree(result);\n+\t\t\t\t\tresult = strbuf_detach(&buf, &len);\n+\t\t\t\t\tresult_size = len;\n+\t\t\t\t}\n+\t\t\t}\n \t\t}\n \t\telse {\n \t\tdeleted_file:\n-- \n1.6.0.rc2\n"},{"id":"88338","messageId":"7vej4fw7qf.fsf@gitster.siamese.dyndns.org","threadId":"15180","inReplyTo":"200808232321.21795.angavrilov@gmail.com","subject":"Re: [PATCH (BUGFIX)] Respect core.autocrlf in combined diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-24T00:56:56Z","receivedAt":"2008-08-24T00:56:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Gavrilov <angavrilov@gmail.com> writes:\n\n> \tSteps to reproduce:\n>\n> \t\tgit init\n> \t\techo foo > file\n> \t\tgit add file\n> \t\tgit commit -m init\n> \t\tgit checkout -b a\n> \t\tgit checkout -b b\n> \t\techo bbb >> file\n> \t\tgit add file\n> \t\tgit commit -m bbb\n> \t\tgit checkout a\n> \t\techo aaa >> file\n> \t\tgit add file\n> \t\tgit commit -m aaa\n> \t\tgit config core.autocrlf true\n> \t\tgit merge b\n\nPlease add this kind of sequence to test scripts.\n\nThe patch from a cursory look appears correct.  Thanks.\n"},{"id":"88341","messageId":"7vy72nurw0.fsf@gitster.siamese.dyndns.org","threadId":"15180","inReplyTo":"200808232321.21795.angavrilov@gmail.com","subject":"Re: [PATCH (BUGFIX)] Respect core.autocrlf in combined diff","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-24T01:24:31Z","receivedAt":"2008-08-24T01:24:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Gavrilov <angavrilov@gmail.com> writes:\n\n> \t\t...\n> \t\tgit commit -m aaa\n> \t\tgit config core.autocrlf true\n> \t\tgit merge b\n>\n> \tThen look at the output of git diff.\n\nCome to think of it, this test sequence is totally bogus, isn't it?\n\nAfter making the \"aaa\" commit, you change core.autocrlf setting, which\nmeans that at that point your work tree is invalid and needs to be checked\nout with the right crlf.\n\nIOW, shouldn't you need to do something like this:\n\n \t\tgit commit -m aaa\n \t\tgit config core.autocrlf true\n+\t\trm -f .git/index && git reset --hard\n\t\tgit merge b\n\nfor the test sequence to be a valid one that (may or may not) exposes the\nproblem you are trying to solve?\n"},{"id":"88357","messageId":"200808241321.58791.angavrilov@gmail.com","threadId":"15180","inReplyTo":"7vy72nurw0.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH (BUGFIX)] Respect core.autocrlf in combined diff","fromName":"Alexander Gavrilov","fromEmail":"angavrilov@gmail.com","sentAt":"2008-08-24T09:21:57Z","receivedAt":"2008-08-24T09:21:57Z","isPatch":true,"sender":{"key":"angavrilov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42666?v=4"},"body":"On Sunday 24 August 2008 05:24:31 Junio C Hamano wrote:\n> Alexander Gavrilov <angavrilov@gmail.com> writes:\n> \n> > \t\t...\n> > \t\tgit commit -m aaa\n> > \t\tgit config core.autocrlf true\n> > \t\tgit merge b\n> >\n> > \tThen look at the output of git diff.\n> \n> Come to think of it, this test sequence is totally bogus, isn't it?\n> \n> After making the \"aaa\" commit, you change core.autocrlf setting, which\n> means that at that point your work tree is invalid and needs to be checked\n> out with the right crlf.\n> \n\nYes, it is more correct to reset after changing that parameter, but since\nmerge overwrites the file anyway, I took a shortcut. I first noticed the\nproblem on Windows, where autocrlf was turned on from the beginning.\n\n\nBy the way, am I right that currently the only way to get properly CRLFed\nversions of all stages is to do something like this:\n\nmv -f $path \"$path.BACKUP\"\ngit checkout-index -f --stage=1 $path\nmv -f $path \"$path.BASE\"\ngit checkout-index -f --stage=2 $path\nmv -f $path \"$path.LOCAL\"\ngit checkout-index -f --stage=3 $path\nmv -f $path \"$path.REMOTE\"\ncp -f \"$path.BACKUP\" $path\n\n\ngit-mergetool does it like this, but it produces LF files:\n\n    base_present   && git cat-file blob \":1:$prefix$MERGED\" >\"$BASE\" 2>/dev/null\n    local_present  && git cat-file blob \":2:$prefix$MERGED\" >\"$LOCAL\" 2>/dev/null\n    remote_present && git cat-file blob \":3:$prefix$MERGED\" >\"$REMOTE\" 2>/dev/null\n\n\nAlexander\n"}]}