{"thread":{"id":"29350","subject":"[PATCH] diff --no-index: support more than one file pair","startedAt":"2012-01-12T09:09:31Z","lastAt":"2012-01-12T18:26:27Z","messageCount":7,"participants":["Nguyễn Thái Ngọc Duy","Matthieu Moy","Nguyen Thai Ngoc Duy","Neal Kreitzinger"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"182420","messageId":"1326359371-13528-1-git-send-email-pclouds@gmail.com","threadId":"29350","inReplyTo":null,"subject":"[PATCH] diff --no-index: support more than one file pair","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-01-12T09:09:31Z","receivedAt":"2012-01-12T09:09:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This allows you to do\n\ngit diff --no-index file1.old file1.new file2.old file2.new...\n\nIt could be seen as an abuse of \"git --no-index\", but it's very\ntempting considering many bells and whistles git's diff machinery\nprovides.\n\nSigned-off-by: A Clearcase user who has had enough with \"ct diff\"\n---\n Sorry I used git@vger as a personal archive, but this might benefit\n others as well, I think.\n\n diff-no-index.c |   38 +++++++++++++++++++++-----------------\n 1 files changed, 21 insertions(+), 17 deletions(-)\n\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 3a36144..b4f6d06 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -199,12 +199,8 @@ void diff_no_index(struct rev_info *revs,\n \t\t     !path_outside_repo(argv[i+1])))\n \t\t\treturn;\n \t}\n-\tif (argc != i + 2)\n-\t\tusagef(\"git diff %s <path> <path>\",\n-\t\t       no_index ? \"--no-index\" : \"[--no-index]\");\n-\n \tdiff_setup(&revs->diffopt);\n-\tfor (i = 1; i < argc - 2; ) {\n+\tfor (i = 1; i < argc; ) {\n \t\tint j;\n \t\tif (!strcmp(argv[i], \"--no-index\"))\n \t\t\ti++;\n@@ -214,13 +210,19 @@ void diff_no_index(struct rev_info *revs,\n \t\t}\n \t\telse if (!strcmp(argv[i], \"--\"))\n \t\t\ti++;\n-\t\telse {\n+\t\telse if (argv[i][0] == '-') {\n \t\t\tj = diff_opt_parse(&revs->diffopt, argv + i, argc - i);\n \t\t\tif (!j)\n \t\t\t\tdie(\"invalid diff option/value: %s\", argv[i]);\n \t\t\ti += j;\n \t\t}\n+\t\telse\n+\t\t\tbreak;\n \t}\n+\tif ((argc - i) % 2)\n+\t\tusagef(\"git diff %s <path> <path>%s\",\n+\t\t       no_index ? \"--no-index\" : \"[--no-index]\",\n+\t\t       no_index ? \"[ <path> <path>...]\" : \"\");\n \n \t/*\n \t * If the user asked for our exit code then don't start a\n@@ -229,13 +231,15 @@ void diff_no_index(struct rev_info *revs,\n \tif (!DIFF_OPT_TST(&revs->diffopt, EXIT_WITH_STATUS))\n \t\tsetup_pager();\n \n+\t/* argv now only contains paths */\n+\targv += i;\n+\targc -= i;\n+\n \tif (prefix) {\n \t\tint len = strlen(prefix);\n-\t\tconst char *paths[3];\n-\t\tmemset(paths, 0, sizeof(paths));\n \n-\t\tfor (i = 0; i < 2; i++) {\n-\t\t\tconst char *p = argv[argc - 2 + i];\n+\t\tfor (i = 0; i < argc; i++) {\n+\t\t\tconst char *p = argv[i];\n \t\t\t/*\n \t\t\t * stdin should be spelled as '-'; if you have\n \t\t\t * path that is '-', spell it as ./-.\n@@ -243,12 +247,10 @@ void diff_no_index(struct rev_info *revs,\n \t\t\tp = (strcmp(p, \"-\")\n \t\t\t     ? xstrdup(prefix_filename(prefix, len, p))\n \t\t\t     : p);\n-\t\t\tpaths[i] = p;\n+\t\t\targv[i] = p;\n \t\t}\n-\t\tdiff_tree_setup_paths(paths, &revs->diffopt);\n \t}\n-\telse\n-\t\tdiff_tree_setup_paths(argv + argc - 2, &revs->diffopt);\n+\n \trevs->diffopt.skip_stat_unmatch = 1;\n \tif (!revs->diffopt.output_format)\n \t\trevs->diffopt.output_format = DIFF_FORMAT_PATCH;\n@@ -260,9 +262,11 @@ void diff_no_index(struct rev_info *revs,\n \tif (diff_setup_done(&revs->diffopt) < 0)\n \t\tdie(\"diff_setup_done failed\");\n \n-\tif (queue_diff(&revs->diffopt, revs->diffopt.pathspec.raw[0],\n-\t\t       revs->diffopt.pathspec.raw[1]))\n-\t\texit(1);\n+\twhile (argv[0] && argv[1]) {\n+\t\tif (queue_diff(&revs->diffopt, argv[0], argv[1]))\n+\t\t\texit(1);\n+\t\targv += 2;\n+\t}\n \tdiff_set_mnemonic_prefix(&revs->diffopt, \"1/\", \"2/\");\n \tdiffcore_std(&revs->diffopt);\n \tdiff_flush(&revs->diffopt);\n-- \n1.7.3.1.256.g2539c.dirty\n"},{"id":"182422","messageId":"vpq39bll1ua.fsf@bauges.imag.fr","threadId":"29350","inReplyTo":"1326359371-13528-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] diff --no-index: support more than one file pair","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-01-12T09:14:21Z","receivedAt":"2012-01-12T09:14:21Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n\n> This allows you to do\n>\n> git diff --no-index file1.old file1.new file2.old file2.new...\n>\n> It could be seen as an abuse of \"git --no-index\", but it's very\n> tempting considering many bells and whistles git's diff machinery\n> provides.\n\nI find this very, very unintuitive. I tried with GNU diff:\n\ndiff 1 2 3 4\n\nand it complained with \"diff: extra operand `3'\". I find\n\ngit diff --no-index file1.old file1.new\ngit diff --no-index file2.old file2.new\n\nfar more intuitive, less error prone (when you start having a\nnon-trivial list of arguments, it's hard to tell which is the new and\nwhich is the old visually), ... So I'm curious why you prefer your\nsyntax.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"182423","messageId":"CACsJy8BvA_o1+xrOx4hYhmwNWpsRnh5+mftb471h3yFW2b6vhA@mail.gmail.com","threadId":"29350","inReplyTo":"vpq39bll1ua.fsf@bauges.imag.fr","subject":"Re: [PATCH] diff --no-index: support more than one file pair","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-01-12T09:17:57Z","receivedAt":"2012-01-12T09:17:57Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2012/1/12 Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>:\n> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:\n>\n>> This allows you to do\n>>\n>> git diff --no-index file1.old file1.new file2.old file2.new...\n>>\n>> It could be seen as an abuse of \"git --no-index\", but it's very\n>> tempting considering many bells and whistles git's diff machinery\n>> provides.\n>\n> I find this very, very unintuitive. I tried with GNU diff:\n>\n> diff 1 2 3 4\n>\n> and it complained with \"diff: extra operand `3'\". I find\n>\n> git diff --no-index file1.old file1.new\n> git diff --no-index file2.old file2.new\n>\n> far more intuitive, less error prone (when you start having a\n> non-trivial list of arguments, it's hard to tell which is the new and\n> which is the old visually), ... So I'm curious why you prefer your\n> syntax.\n\nSingle operation has its advantages:\n\n - one pager\n - one stat and summary\n - might be easier to script (just throw them all to xargs)\n - hell, i might even benefit from git copy/modify detection\n-- \nDuy\n"},{"id":"182425","messageId":"vpqmx9te08z.fsf@bauges.imag.fr","threadId":"29350","inReplyTo":"CACsJy8BvA_o1+xrOx4hYhmwNWpsRnh5+mftb471h3yFW2b6vhA@mail.gmail.com","subject":"Re: [PATCH] diff --no-index: support more than one file pair","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-01-12T09:30:36Z","receivedAt":"2012-01-12T09:30:36Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> Single operation has its advantages:\n>\n>  - one pager\n>  - one stat and summary\n\nI buy these, and I understand why they apply to \"git diff\" and not GNU\ndiff.\n\n>  - might be easier to script (just throw them all to xargs)\n\nI don't see a use-case where a command produces old1 new1 old2 new2, but\nif there is one, then \"| xargs -n 2 diff\" is the solution. You don't\nneed your patch.\n\n>  - hell, i might even benefit from git copy/modify detection\n\nI don't see how, if you specify explicitely the pairs (old, new). You\nmay have such benefit if you let the command-line express \"here's a\nbunch of old files, and a bunch of new ones\", but not with your proposed\nsyntax.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"182438","messageId":"4F0F0C51.3050706@gmail.com","threadId":"29350","inReplyTo":"1326359371-13528-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] diff --no-index: support more than one file pair","fromName":"Neal Kreitzinger","fromEmail":"nkreitzinger@gmail.com","sentAt":"2012-01-12T16:37:37Z","receivedAt":"2012-01-12T16:37:37Z","isPatch":true,"sender":{"key":"nkreitzinger@gmail.com","avatar":null},"body":"On 1/12/2012 3:09 AM, Nguyễn Thái Ngọc Duy wrote:\n> This allows you to do\n>\n> git diff --no-index file1.old file1.new file2.old file2.new...\n>\n> It could be seen as an abuse of \"git --no-index\", but it's very\n> tempting considering many bells and whistles git's diff machinery\n> provides.\n>\nI see that git-diff can be used in place of linux diff for totally \nuntracked file pairs (which is kind of neat, I guess, if you're partial \nto git like I am and would probably prefer to use it as your primary \nfile-system interface if you could).  I assume this new syntax implies \nmanual usage since scripting this input is less straightforward than \niterating thru a single pair via xargs, etc.  In that context, I also \nsee that git-difftool doesn't bring up kdiff3 (or whatever) but just \ndoes a text diff (git 1.7.1) which is mildly disappointing for mere \nmortals like myself who prefer to read side-by-side gui diffs over text \ndiffS.  This, of course, is also preference for someone like me who \nwouldn't mind prefixing all of my commands with \"git \" ;-)\n\nv/r,\nneal\n"},{"id":"182446","messageId":"CACsJy8B460CwtACV+o0wnwqi1On_oEavLfDAL8f=w6kyfktKcQ@mail.gmail.com","threadId":"29350","inReplyTo":"vpqmx9te08z.fsf@bauges.imag.fr","subject":"Re: [PATCH] diff --no-index: support more than one file pair","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-01-12T17:40:27Z","receivedAt":"2012-01-12T17:40:27Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Jan 12, 2012 at 4:30 PM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n>>  - might be easier to script (just throw them all to xargs)\n>\n> I don't see a use-case where a command produces old1 new1 old2 new2, but\n> if there is one, then \"| xargs -n 2 diff\" is the solution. You don't\n> need your patch.\n\nUnthorough thought. I agree with you.\n\n>>  - hell, i might even benefit from git copy/modify detection\n>\n> I don't see how, if you specify explicitely the pairs (old, new). You\n> may have such benefit if you let the command-line express \"here's a\n> bunch of old files, and a bunch of new ones\", but not with your proposed\n> syntax.\n\nThat's what git gives to diff machinery: a set of file pairs, and the\ndiff machinery has to figure out copy/modify pairs, shuffling them up\nif necessary. I simply cut of tree traversal part out and feed file\npairs directly to diff machinery. I remember long long time ago Junio\nasked for assistance about code moving support within a file. It has\nnot come up (at least in public), but one can hope it'll come someday.\n-- \nDuy\n"},{"id":"182451","messageId":"vpq8vlc93qk.fsf@bauges.imag.fr","threadId":"29350","inReplyTo":"CACsJy8B460CwtACV+o0wnwqi1On_oEavLfDAL8f=w6kyfktKcQ@mail.gmail.com","subject":"Re: [PATCH] diff --no-index: support more than one file pair","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-01-12T18:26:27Z","receivedAt":"2012-01-12T18:26:27Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n>>>  - hell, i might even benefit from git copy/modify detection\n>>\n>> I don't see how, if you specify explicitely the pairs (old, new). You\n>> may have such benefit if you let the command-line express \"here's a\n>> bunch of old files, and a bunch of new ones\", but not with your proposed\n>> syntax.\n>\n> That's what git gives to diff machinery: a set of file pairs, and the\n> diff machinery has to figure out copy/modify pairs, shuffling them up\n> if necessary. I simply cut of tree traversal part out and feed file\n> pairs directly to diff machinery.\n\nIf you want to benefit from copy detection, you cannot hardcode the fact\nthat you have as many source and destination files. And even to benefit\nfrom rename detection, I find the user interface really weird. If I\nprovide files in pairs, I really don't expect Git to shuffle them like\n\ngit diff --no-index A1 B1 A2 B2\n--- A1\n+++ B2\n..\n--- A2\n+++ B1\n..\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}