{"thread":{"id":"42318","subject":"'git diff-index' doesn't honor the 'diff.algorithm' variable","startedAt":"2016-05-13T23:45:21Z","lastAt":"2016-05-15T20:36:10Z","messageCount":5,"participants":["Dmitry Gutov","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"286520","messageId":"9d15b6c8-ed97-7352-3df1-efab1b4ffadb@yandex.ru","threadId":"42318","inReplyTo":null,"subject":"'git diff-index' doesn't honor the 'diff.algorithm' variable","fromName":"Dmitry Gutov","fromEmail":"dgutov@yandex.ru","sentAt":"2016-05-13T23:45:21Z","receivedAt":"2016-05-13T23:45:21Z","isPatch":false,"sender":{"key":"dgutov@yandex.ru","avatar":"https://gravatar.com/avatar/e29ab2de517e0d4042de95eeaddb4f555bcb3b3c1d3c3f50b8169edb266ec43d?d=mp&s=160"},"body":"Hi all,\n\nSubj. ...even though it's explicitly mentioned in the subcommand's man \npage. Git version 2.7.4 here.\n\nTo elaborate:\n\n- Call 'git config --global diff.algorithm histogram'.\n\n- Try the example from http://stackoverflow.com/a/36551123/615245.\n\n'git diff test.css' gives the expected output using the non-default \nalgorithm.\n\n'git diff-index -p HEAD -- test.css' uses the default one.\n\nBest regards,\nDmitry.\n"},{"id":"286544","messageId":"xmqqshxk7aa8.fsf@gitster.mtv.corp.google.com","threadId":"42318","inReplyTo":"9d15b6c8-ed97-7352-3df1-efab1b4ffadb@yandex.ru","subject":"Re: 'git diff-index' doesn't honor the 'diff.algorithm' variable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-14T18:40:47Z","receivedAt":"2016-05-14T18:40:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dmitry Gutov <dgutov@yandex.ru> writes:\n\n> Hi all,\n>\n> Subj. ...even though it's explicitly mentioned in the subcommand's man\n> page. Git version 2.7.4 here.\n>\n> To elaborate:\n>\n> - Call 'git config --global diff.algorithm histogram'.\n\nThe variable belongs to UI config, meant for Porcelain \"git diff\",\ntogether with things like \"diff.color\", \"diff.context\", etc.\n\nAs the point of lower-level plumbing commands in the diff family,\ni.e. diff-files, diff-index and diff-tree, are about giving stable\noutput, which are _not_ affected by random end-user configuration,\nfor scripted use, it is very much deliberate design decision that\nthey ignore the UI config variables.\n\nA script that calls diff-index, if it wants to honor end-users'\nUI config variables, is allowed to use 'git config' to read them and\nturn them into appropriate command line options.  e.g.\n\n    algo=$(git config diff.algorithm)\n    case \"$algo\" in\n    minimal|histogram|patience) algo=--$algo ;;\n    *) algo= ;;\n    esac\n\n    ...\n    git diff-index $algo ... other args ...\n\nor something like that.\n"},{"id":"286570","messageId":"8e5a7045-77f7-acb0-de7f-3e8f72479ec3@yandex.ru","threadId":"42318","inReplyTo":"xmqqshxk7aa8.fsf@gitster.mtv.corp.google.com","subject":"Re: 'git diff-index' doesn't honor the 'diff.algorithm' variable","fromName":"Dmitry Gutov","fromEmail":"dgutov@yandex.ru","sentAt":"2016-05-15T10:25:24Z","receivedAt":"2016-05-15T10:25:24Z","isPatch":false,"sender":{"key":"dgutov@yandex.ru","avatar":"https://gravatar.com/avatar/e29ab2de517e0d4042de95eeaddb4f555bcb3b3c1d3c3f50b8169edb266ec43d?d=mp&s=160"},"body":"Hi Junio,\n\nOn 05/14/2016 09:40 PM, Junio C Hamano wrote:\n\n> The variable belongs to UI config, meant for Porcelain \"git diff\",\n> together with things like \"diff.color\", \"diff.context\", etc.\n\nOK, that makes sense. You might want to fix the man page, though, it \nsays, like the 'git diff' one, \"For instance, if you configured \ndiff.algorithm variable to a non-default value and want to use the \ndefault one, then you have to use --diff-algorithm=default option.\".\n\n> A script that calls diff-index, if it wants to honor end-users'\n> UI config variables, is allowed to use 'git config' to read them and\n> turn them into appropriate command line options.  e.g.\n>\n>     algo=$(git config diff.algorithm)\n>     case \"$algo\" in\n>     minimal|histogram|patience) algo=--$algo ;;\n>     *) algo= ;;\n>     esac\n>\n>     ...\n>     git diff-index $algo ... other args ...\n>\n> or something like that.\n\nThanks, but we don't distribute any custom Git porcelains with Emacs. We \nusually can't rely on bash being available either. Doing an extra \nprocess call from Emacs for this niche a feature doesn't seem like a \ngreat idea either. To clarify, the problem is that `M-x vc-diff' doesn't \nhonor the diff.algorithm option.\n\nI'll have to see why we using 'git diff-index' there directly. Maybe we \ncould switch to 'git diff'.\n"},{"id":"286598","messageId":"xmqqwpmv5fi3.fsf@gitster.mtv.corp.google.com","threadId":"42318","inReplyTo":"8e5a7045-77f7-acb0-de7f-3e8f72479ec3@yandex.ru","subject":"Re: 'git diff-index' doesn't honor the 'diff.algorithm' variable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-15T18:43:16Z","receivedAt":"2016-05-15T18:43:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dmitry Gutov <dgutov@yandex.ru> writes:\n\n> OK, that makes sense. You might want to fix the man page, though, it\n> says, like the 'git diff' one, \"For instance, if you configured\n> diff.algorithm variable to a non-default value and want to use the\n> default one, then you have to use --diff-algorithm=default option.\".\n\nThanks; I think the paragraph is shared among the \"diff\" family of\ncommands both plumbing and Porcelain, so I'd say \"patches welcome\"\nat this point ;-).\n\n> Thanks, but we don't distribute any custom Git porcelains with\n> Emacs. We usually can't rely on bash being available either.\n\nThe script was an illustration of the logic--I am sure elisp is much\ncore capable scripting environment than POSIX shell.  Perhaps (setq\nvc-diff-git-diff-use-histogram t) in ~/.emacs is not too bad ;-)\n\n> I'll have to see why we using 'git diff-index' there directly. Maybe\n> we could switch to 'git diff'.\n\nI do not think it is a good idea.\n\nDepending on how much understanding vc-diff wants to have on what\nthe diff output is saying, it may want to be read and parse parts of\nthe output; an end user who has diff.color=always can easily ruin\nyour day.\n\nAnd no, running \"git diff --color=never\" is not a solution for that.\n\nThe Porcelain \"git diff\" command is not bound by any promise of\nstable output and reserves the right to change the default to better\nsupport human users.  I think the upcoming version of Git turns the\ndiff.renames setting on by default, for example.  We might even add\na side-by-side diff and make it the default someday.  You do not\nwant to be reading these \"fancy\" output, and you cannot keep\nupdating the invocation of \"git diff\" by vc-diff with unbounded\nnumber options, e.g. --no-side-by-side, that will be added to defeat\nconfiguration variables that will be invented in the future.\n"},{"id":"286606","messageId":"c81e4b71-29f2-6a11-7bf4-769013d34a6d@yandex.ru","threadId":"42318","inReplyTo":"xmqqwpmv5fi3.fsf@gitster.mtv.corp.google.com","subject":"Re: 'git diff-index' doesn't honor the 'diff.algorithm' variable","fromName":"Dmitry Gutov","fromEmail":"dgutov@yandex.ru","sentAt":"2016-05-15T20:36:10Z","receivedAt":"2016-05-15T20:36:10Z","isPatch":false,"sender":{"key":"dgutov@yandex.ru","avatar":"https://gravatar.com/avatar/e29ab2de517e0d4042de95eeaddb4f555bcb3b3c1d3c3f50b8169edb266ec43d?d=mp&s=160"},"body":"On 05/15/2016 09:43 PM, Junio C Hamano wrote:\n\n> I think the paragraph is shared among the \"diff\" family of\n> commands both plumbing and Porcelain, so I'd say \"patches welcome\"\n> at this point ;-).\n\nI think I've done my part here. It's not like this is a feature request.\n\n> The script was an illustration of the logic--I am sure elisp is much\n> core capable scripting environment than POSIX shell.  Perhaps (setq\n> vc-diff-git-diff-use-histogram t) in ~/.emacs is not too bad ;-)\n\nYes, doing it via a user option is already possible in Emacs. I was \nconcerned that the user has to configure it twice (once for console, two \nfor Emacs), but if you think it's fine, let's leave it at that.\n\n> The Porcelain \"git diff\" command is not bound by any promise of\n> stable output and reserves the right to change the default to better\n> support human users.  I think the upcoming version of Git turns the\n> diff.renames setting on by default, for example.  We might even add\n> a side-by-side diff and make it the default someday.  You do not\n> want to be reading these \"fancy\" output, and you cannot keep\n> updating the invocation of \"git diff\" by vc-diff with unbounded\n> number options, e.g. --no-side-by-side, that will be added to defeat\n> configuration variables that will be invented in the future.\n\nFair enough.\n\nThanks,\nDmitry.\n"}]}