{"thread":{"id":"49241","subject":"Feature request: be able to pass arguments to difftool command","startedAt":"2018-08-28T15:57:26Z","lastAt":"2018-09-17T16:44:37Z","messageCount":5,"participants":["H.Merijn Brand","Junio C Hamano","David Aguilar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"356706","messageId":"20180828175711.3a0aeacc@pc09.procura.nl","threadId":"49241","inReplyTo":null,"subject":"Feature request: be able to pass arguments to difftool command","fromName":"H.Merijn Brand","fromEmail":"h.m.brand@xs4all.nl","sentAt":"2018-08-28T15:57:11Z","receivedAt":"2018-08-28T15:57:26Z","isPatch":false,"sender":{"key":"h.m.brand@xs4all.nl","avatar":"https://gravatar.com/avatar/5b8f83ee35c427a646cbea3b104346e00ab3663b99bbf435cddeb75cd4b3857b?d=mp&s=160"},"body":"In short, I want to be able to do\n\n $ git difftool 5c5a -v2\n\nwhere -v2 is passed to the tool invoked in the end. I'll elaborate on\nwhy ...\n\nBackground.\n\nSome changes are not obvious to spot. One of the best examples I found\nis this one:\nhttps://github.com/hexchat/hexchat/commit/5c5aacd9da7d45dfc1644b87de9e2379a1102d6a\n\n$ git show 5c5a\ncommit 5c5aacd9da7d45dfc1644b87de9e2379a1102d6a\nAuthor: Patrick Griffis <tingping@tingping.se>\nDate:   Wed Apr 4 19:21:53 2018 -0400\n\n    Fix another bad translation\n\ndiff --git a/po/el.po b/po/el.po\nindex 7d47ee1e..e54d62c1 100644\n--- a/po/el.po\n+++ b/po/el.po\n@@ -1072,7 +1072,7 @@ msgstr \"%C22*%O$t%C22$1%O: %C18$2%O κατά συνέχεια %C24$4%O από %C\n\n #: src/common/textevents.h:13\n msgid \"%C22*%O$tCannot join %C22$1 %O(%C20You are banned%O).\"\n-msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%Ο).\"\n+msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%O).\"\n\n #: src/common/textevents.h:19\n msgid \"%C29*%O$tCapabilities acknowledged: %C29$2%O\"\n\n\nI bet none of you is able to spot the change in that line, even if\ncolored. I had a similar problem completely unrelated to git, and I\nwrote the \"ccdiff\" tool, to do horizontally colored diff. As mail (when\nused without HTML, as it ought to be used) is not apt to coloring, I\nadded an option to show markers under the changed text. I then\nintegrated the tool as much as possible into git\n\n $ cpan App::ccdiff\n $ git config --global diff.tool ccdiff\n $ git config --global difftool.prompt false\n $ git config --global difftool.ccdiff.cmd 'ccdiff --utf-8 -u $LOCAL $REMOTE'\n $ git difftool 5c5a~..5c5a\n --- /tmp/CXbTje_el.po   Tue Aug 28 17:38:02 2018\n +++ /tmp/8jrR7d_el.po   Tue Aug 28 17:38:02 2018\n 1075,1075c1075,1075\n\n  #: src/common/textevents.h:13\n  msgid \"%C22*%O$tCannot join %C22$1 %O(%C20You are banned%O).\"\n -msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%Ο).\"\n +msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%O).\"\n\n  #: src/common/textevents.h:19\n  msgid \"%C29*%O$tCapabilities acknowledged: %C29$2%O\"\n\n $ cat >~/bin/git-ccdiff <<EOC\n #!/bin/sh\n\n commit=$1\n shift\n if [ \"$commit\" = \"\" ]; then\n     git difftool\n else\n     git difftool $commit~1..$commit\n     fi\n EOF\n $ chmod 755 ~/bin/git-ccdiff\n $ git ccdiff 5c5a\n --- /tmp/Cw7VDo_el.po   Tue Aug 28 17:41:08 2018\n +++ /tmp/yuTGro_el.po   Tue Aug 28 17:41:08 2018\n 1075,1075c1075,1075\n\n  #: src/common/textevents.h:13\n  msgid \"%C22*%O$tCannot join %C22$1 %O(%C20You are banned%O).\"\n -msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%Ο).\"\n +msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%O).\"\n\n  #: src/common/textevents.h:19\n  msgid \"%C29*%O$tCapabilities acknowledged: %C29$2%O\"\n\nSo, with all parts in place, I want more info\n\n $ git ccdiff 5c5a -m\n\nNo change. When I add -m to the cmd in ~/.gitconfig, like\n\n[difftool \"ccdiff\"]\n\tcmd = ccdiff --utf-8 -u -m $LOCAL $REMOTE\n\n $ git ccdiff 5c5a\n --- /tmp/fXkf4E_el.po   Tue Aug 28 17:44:12 2018\n +++ /tmp/P3mZ1E_el.po   Tue Aug 28 17:44:12 2018\n 1075,1075c1075,1075\n\n  #: src/common/textevents.h:13\n  msgid \"%C22*%O$tCannot join %C22$1 %O(%C20You are banned%O).\"\n -msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%Ο).\"\n -                                                                       ▼\n +msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%O).\"\n +                                                                       ▲\n\n  #: src/common/textevents.h:19\n  msgid \"%C29*%O$tCapabilities acknowledged: %C29$2%O\"\n\nNice, but I still cannot pass it from the command line, and in this\nspecific case I also want -v2 or -v3\n\ncmd = ccdiff --utf-8 -u -m -v2 $LOCAL $REMOTE:\n\n--- /tmp/dp0E5T_el.po   Tue Aug 28 17:45:51 2018\n+++ /tmp/za7m3T_el.po   Tue Aug 28 17:45:51 2018\n1075,1075c1075,1075\n\n  #: src/common/textevents.h:13\n  msgid \"%C22*%O$tCannot join %C22$1 %O(%C20You are banned%O).\"\n -msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%↱Ο↰).\"\n -                                                                        ▼\n - -- verbose : GREEK CAPITAL LETTER OMICRON\n +msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%↱O↰).\"\n +                                                                        ▲\n + -- verbose : LATIN CAPITAL LETTER O\n\n  #: src/common/textevents.h:19\n  msgid \"%C29*%O$tCapabilities acknowledged: %C29$2%O\"\n\ncmd = ccdiff --utf-8 -u -m -v3 $LOCAL $REMOTE\n(a screenshot is added to show the colors)\n\n--- /tmp/4gPKTd_el.po   Tue Aug 28 17:47:57 2018\n+++ /tmp/IreaTe_el.po   Tue Aug 28 17:47:57 2018\n1075,1075c1075,1075\n\n  #: src/common/textevents.h:13\n  msgid \"%C22*%O$tCannot join %C22$1 %O(%C20You are banned%O).\"\n -msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%↱Ο↰).\"\n -                                                                        ▼\n - -- verbose : GREEK CAPITAL LETTER OMICRON (U+00039F)\n +msgstr \"%C22*%O$tΑδυναμία εισαγωγής %C22$1 %O(%C20Είστε μπλοκαρισμένος%↱O↰).\"\n +                                                                        ▲\n + -- verbose : LATIN CAPITAL LETTER O (U+00004F)\n\n  #: src/common/textevents.h:19\n  msgid \"%C29*%O$tCapabilities acknowledged: %C29$2%O\"\n\n\nThe only workaround I could come up with (for now) is both ugly and\nfragile: I keep the extra arguments in an environment variable and add\nthose back to the commandline after the command started. Very easy to\nbreak though.\n\n$ cat ~/bin/git-ccdiff\n#!/pro/bin/perl\n\nuse 5.18.3;\nuse warnings;\n\nmy $commit;\n\nif (@ARGV) {\n    $ARGV[0] =~ m/^-/ or $commit = shift;\n    }\n\n@ARGV and $ENV{CCDIFF_OPTIONS} = \"@ARGV\";\nmy @git = qw( git difftool );\ndefined $commit and push @git, \"$commit~1..$commit\";\nsystem @git;\n\n\nSo, my wish would be to have an option, possibly using -- to pass\nadditional command line arguments to git difftool, so that\n\n $ git difftool $commit~1..$commit -- -m -v2\n\nwould pass the arguments after -- transparantly to ccdiff (in my case)\n\n\n-- \nH.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/\nusing perl5.00307 .. 5.29   porting perl5 on HP-UX, AIX, and openSUSE\nhttp://mirrors.develooper.com/hpux/        http://www.test-smoke.org/\nhttp://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/\n"},{"id":"356723","messageId":"xmqqpny2ffjv.fsf@gitster-ct.c.googlers.com","threadId":"49241","inReplyTo":"20180828175711.3a0aeacc@pc09.procura.nl","subject":"Re: Feature request: be able to pass arguments to difftool command","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-08-28T19:37:40Z","receivedAt":"2018-08-28T19:37:45Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"H.Merijn Brand\" <h.m.brand@xs4all.nl> writes:\n\n> So, my wish would be to have an option, possibly using -- to pass\n> additional command line arguments to git difftool, so that\n>\n>  $ git difftool $commit~1..$commit -- -m -v2\n>\n> would pass the arguments after -- transparantly to ccdiff (in my case)\n\nAt the syntax level passing any option after \"--\" would be a no\nstarter, as I would imagine that \"git difftool $revs -- $paths\"\nshould still be supported.\n\nAt the concept level, however, I can see why such a feature would be\nuseful.  Perhaps\n\n    $ git difftool --backend-option=-m --backend-option=-v2 HEAD\n    $ git mergetool --backend-option=--foo\n\nwith appropriate way(s) [*1*] to make it easier to type (and\nimplement) would be an acceptable avenue to pursue, I wonder?\n\n\n[Footnote]\n\n*1* There are various possible ways, not all of them are mutually\n    incompatible.\n\n    a. Give a short-form synonym, e.g. -X, to \"--backend-option\";\n\n    b. Assume that backend option always begins with a dash and add\n       one when missing, e.g. -Xm becomes --backend-option=-m\n\n    c. Allow giving multiple backend options on a single option and\n       split at whitespace, e.g. --backend-option=\"-m -v2\"\n\n    d. Allow difftool.$toolname.opts configuration variable that is\n       multi-valued, so you can say\n\n\tgit -c difftool.ccdiff.opts=-v2 -c difftool.ccdiff.opts=-m difftool\n\n       (of course, not necessarily from the command line but the\n       point is you could configure it)\n\n    Some of these (e.g. b, c) may not be desirable, though.\n\n"},{"id":"356818","messageId":"20180829091838.2eee8a6a@pc09.procura.nl","threadId":"49241","inReplyTo":"xmqqpny2ffjv.fsf@gitster-ct.c.googlers.com","subject":"Re: Feature request: be able to pass arguments to difftool command","fromName":"H.Merijn Brand","fromEmail":"h.m.brand@xs4all.nl","sentAt":"2018-08-29T07:18:38Z","receivedAt":"2018-08-29T07:18:53Z","isPatch":false,"sender":{"key":"h.m.brand@xs4all.nl","avatar":"https://gravatar.com/avatar/5b8f83ee35c427a646cbea3b104346e00ab3663b99bbf435cddeb75cd4b3857b?d=mp&s=160"},"body":"On Tue, 28 Aug 2018 12:37:40 -0700, Junio C Hamano <gitster@pobox.com>\nwrote:\n\n> \"H.Merijn Brand\" <h.m.brand@xs4all.nl> writes:\n> \n> > So, my wish would be to have an option, possibly using -- to pass\n> > additional command line arguments to git difftool, so that\n> >\n> >  $ git difftool $commit~1..$commit -- -m -v2\n> >\n> > would pass the arguments after -- transparantly to ccdiff (in my case)  \n> \n> At the syntax level passing any option after \"--\" would be a no\n> starter, as I would imagine that \"git difftool $revs -- $paths\"\n> should still be supported.\n> \n> At the concept level, however, I can see why such a feature would be\n> useful.  Perhaps\n> \n>     $ git difftool --backend-option=-m --backend-option=-v2 HEAD\n>     $ git mergetool --backend-option=--foo\n\nThis would mean I can just pass remaining arguments, like this?\n\n--8<--- ~/bin/git-ccdiff\n#!/usr/bin/env perl\nuse 5.18.3;\nuse warnings;\n\nmy $commit;\n\n@ARGV && $ARGV[0] !~ m/^-/ and $commit = shift;\n\nmy @git = qw( git difftool );\ndefined $commit and push @git, \"$commit~1..$commit\";\nsystem @git, @ARGV;\n-->8---\n\n> with appropriate way(s) [*1*] to make it easier to type (and\n> implement) would be an acceptable avenue to pursue, I wonder?\n\nI like it, as long as they are all separate options in the backend and\nnot available in one single variable that needs to be split\n\nI can envision a configure variable like\n\n  backends.options.separator = U+2063\n\nso the backend can safely split on that itself. But I also see this as\noverly complex en over-engineering\n\n> [Footnote]\n> \n> *1* There are various possible ways, not all of them are mutually\n>     incompatible.\n> \n>     a. Give a short-form synonym, e.g. -X, to \"--backend-option\";\n\nI like it\n\n>     b. Assume that backend option always begins with a dash and add\n>        one when missing, e.g. -Xm becomes --backend-option=-m\n\nI guess not: there might be tools that do not work like that, e.g.\nxfreerdp changed all their rememberable and logic options to the weird\nstupid syntax they use now, including mixing -, -- and +\n\n rdesktop -u user -p - -g 1280x1024 -a 16 -r clipboard:CLIPBOARD host\n\n->\n\n xfreerdp -u user --from-stdin -g 1280x1024 -a 16 --plugin clipbrd host\n\n->\n\n xfreerdp /u:user /from-stdin /size:1280x1024 /bpp:16 +clipboard /v:host\n\n>     c. Allow giving multiple backend options on a single option and\n>        split at whitespace, e.g. --backend-option=\"-m -v2\"\n\nThat is the weak part in my workaround, as it will break on options like\n\n  --backend-option='--config=\"/path/to/My Configuration/My Application\"'\n\n>     d. Allow difftool.$toolname.opts configuration variable that is\n>        multi-valued, so you can say\n> \n> \tgit -c difftool.ccdiff.opts=-v2 -c difftool.ccdiff.opts=-m difftool\n\nHmm, maybe harder to explain, but why not\n\n>        (of course, not necessarily from the command line but the\n>        point is you could configure it)\n> \n>     Some of these (e.g. b, c) may not be desirable, though.\n\n\n-- \nH.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/\nusing perl5.00307 .. 5.29   porting perl5 on HP-UX, AIX, and openSUSE\nhttp://mirrors.develooper.com/hpux/        http://www.test-smoke.org/\nhttp://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/\n"},{"id":"358219","messageId":"20180916062800.GA18517@gmail.com","threadId":"49241","inReplyTo":"20180829091838.2eee8a6a@pc09.procura.nl","subject":"Re: Feature request: be able to pass arguments to difftool command","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2018-09-16T06:28:00Z","receivedAt":"2018-09-16T06:34:45Z","isPatch":false,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Wed, Aug 29, 2018 at 09:18:38AM +0200, H.Merijn Brand wrote:\n> On Tue, 28 Aug 2018 12:37:40 -0700, Junio C Hamano <gitster@pobox.com>\n> wrote:\n> \n> > \"H.Merijn Brand\" <h.m.brand@xs4all.nl> writes:\n> > \n> > > So, my wish would be to have an option, possibly using -- to pass\n> > > additional command line arguments to git difftool, so that\n> > >\n> > >  $ git difftool $commit~1..$commit -- -m -v2\n> > >\n> > > would pass the arguments after -- transparantly to ccdiff (in my case)  \n> > \n> > At the syntax level passing any option after \"--\" would be a no\n> > starter, as I would imagine that \"git difftool $revs -- $paths\"\n> > should still be supported.\n> > \n> > At the concept level, however, I can see why such a feature would be\n> > useful.  Perhaps\n> > \n> >     $ git difftool --backend-option=-m --backend-option=-v2 HEAD\n> >     $ git mergetool --backend-option=--foo\n> \n> This would mean I can just pass remaining arguments, like this?\n> \n> --8<--- ~/bin/git-ccdiff\n> #!/usr/bin/env perl\n> use 5.18.3;\n> use warnings;\n> \n> my $commit;\n> \n> @ARGV && $ARGV[0] !~ m/^-/ and $commit = shift;\n> \n> my @git = qw( git difftool );\n> defined $commit and push @git, \"$commit~1..$commit\";\n> system @git, @ARGV;\n> -->8---\n> \n> > with appropriate way(s) [*1*] to make it easier to type (and\n> > implement) would be an acceptable avenue to pursue, I wonder?\n> \n> I like it, as long as they are all separate options in the backend and\n> not available in one single variable that needs to be split\n> \n> I can envision a configure variable like\n> \n>   backends.options.separator = U+2063\n> \n> so the backend can safely split on that itself. But I also see this as\n> overly complex en over-engineering\n\n\nPersonally, I think it'd be better to keep the tool simple.\n\nWhile I do see the utility, it would be just as easy to configure a 2nd\nand 3rd variant of the same difftool and use those as needed instead.\n\n\"git difftool -t ccdiff2\" or \"-t ccdiff3\" is the simplest, and there's\nnothing stopping the user from creating aliases to shorten it further.\n\nWe also already have, \"git difftool -x / --extcmd\"\nfor specifying a full-on external diff command.\n\n> \tgit -c difftool.ccdiff.opts=-v2 -c difftool.ccdiff.opts=-m difftool\n\nFor example, this seems simpler as:\n\n\tgit difftool -x 'ccdiff -v2 -m'\n\nWe already have two mechanisms for controlling the inner command that's\nlaunched by difftool.  IMO we don't need more.\n\nMy primary concerns with --backend-opts are as follows:\n\n1. If we add a mechansim for passing -X/--backend-opts, then we\n   need to specify a new variable that users will need to be aware\n   of when creating custom commands.  (sorry for stating the obvious)\n\n2. All of the built-in commands would need to change to honor that\n   variable.\n\n3. The documentation becomes more complex because someone that wants\n   to configure a bog-standard custom external tool now needs to\n   be aware of this extra external source of arguments.\n\n#1 and #2 are primarily implementation concerns, but #3 suggests\nto me that it's over-complicating things.\n\nFurthermore, #2 is not really that simple.\nWhat would the sciplet look like?\n\n\tdiff_cmd () {\n\t\t\"$merge_tool_path\" $EXTRA_ARGS ...\n\t}\n\nThat implies that we would need to shell quote stuff when\nconstructing $EXTRA_ARGS internally if we were to support multiple -X\narguments.  That just made it a bit more complex.\n\nIMO we should be working to simpliify, not make things more complex for\nrare use cases.  There's no reason the user can't just do:\n\n\tV=2 git difftool\n\tV=3 git difftool\n\n... and let the inner script check for $V (or any other) variable.\nWhile environment variables aren't great, this does seem like the right\nplace to use them.\n\nAnother option -- we already eval the configured command, so if the user\nincludes a variable ($ARGS) in their custom configuration then they can\nspecify extra flags today without needing to change the tool.  ex:\n\n\t[difftool \"ccdiff\"]\n\t\tcmd = ccdiff $ARGS \\\"$LOCAL\\\" \\\"$REMOTE\\\"\n\n\tARGS='-v2 -m' git difftool HEAD~1..HEAD\n\n\nAre these alternatives short and simple enough?\n-- \nDavid\n"},{"id":"358291","messageId":"xmqqfty8845q.fsf@gitster-ct.c.googlers.com","threadId":"49241","inReplyTo":"20180916062800.GA18517@gmail.com","subject":"Re: Feature request: be able to pass arguments to difftool command","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-09-17T16:44:33Z","receivedAt":"2018-09-17T16:44:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> While I do see the utility, it would be just as easy to configure a 2nd\n> and 3rd variant of the same difftool and use those as needed instead.\n>\n> \"git difftool -t ccdiff2\" or \"-t ccdiff3\" is the simplest, and there's\n> nothing stopping the user from creating aliases to shorten it further.\n> ...\n> We already have two mechanisms for controlling the inner command that's\n> launched by difftool.  IMO we don't need more.\n\nOK, fair enough.\n"}]}