{"thread":{"id":"38919","subject":"[PATCH V2/RFC][GSoC] diff-no-index: transform \"$directory $file\" args to \"$directory/$file $file\"","startedAt":"2015-03-26T20:54:40Z","lastAt":"2015-03-26T22:58:47Z","messageCount":2,"participants":["Yurii Shevtsov","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"258567","messageId":"CAHLaBN+nE9tmGMdJM65V-bONKe8CE9PZ1Ottc1R9D=Pm0X7k_g@mail.gmail.com","threadId":"38919","inReplyTo":null,"subject":"[PATCH V2/RFC][GSoC] diff-no-index: transform \"$directory $file\" args to \"$directory/$file $file\"","fromName":"Yurii Shevtsov","fromEmail":"ungetch@gmail.com","sentAt":"2015-03-26T20:54:40Z","receivedAt":"2015-03-26T20:54:40Z","isPatch":true,"sender":{"key":"ungetch@gmail.com","avatar":null},"body":"git diff --no-index refuses to compare if args are directory and file,\ninstead of usual diff.\n\nNow git diff --no-index modifies args, if they're directory and file,\nand diffs files, as usual diff does.\n\nChanges are done in diff_no_index().\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Yurii Shevtsov <ungetch@gmail.com>\n---\n diff-no-index.c |   31 +++++++++++++++++++++++++++++--\n 1 files changed, 29 insertions(+), 2 deletions(-)\n\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 265709b..ecff15e 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -186,7 +186,7 @@ void diff_no_index(struct rev_info *revs,\n            int argc, const char **argv,\n            const char *prefix)\n {\n-    int i, prefixlen;\n+    int i, prefixlen, mode1 = 0, mode2 = 0;\n     const char *paths[2];\n\n     diff_setup(&revs->diffopt);\n@@ -229,8 +229,35 @@ void diff_no_index(struct rev_info *revs,\n     setup_diff_pager(&revs->diffopt);\n     DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);\n\n-    if (queue_diff(&revs->diffopt, paths[0], paths[1]))\n+    if (get_mode(paths[0], &mode1) || get_mode(paths[1], &mode2))\n+        exit(2);\n+\n+    if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) {\n+        struct strbuf pathtofile;\n+        const char *dir, *file;\n+        char *filename;\n+        int ret;\n+\n+        dir = S_ISDIR(mode1) ? paths[0] : paths[1];\n+        file = (dir == paths[0]) ? paths[1] : paths[0];\n+        strbuf_init(&pathtofile, strlen(paths[0]) + strlen(paths[1]) + 1);\n+        strbuf_addstr(&pathtofile, dir);\n+        if (pathtofile.len && pathtofile.buf[pathtofile.len - 1] != '/')\n+               strbuf_addch(&pathtofile, '/');\n+        filename = strrchr(file, '/');\n+        strbuf_addstr(&pathtofile, filename ? (filename + 1) : file);\n+\n+        if (file == paths[0])\n+            ret = queue_diff(&revs->diffopt, file, pathtofile.buf);\n+        else\n+            ret = queue_diff(&revs->diffopt, pathtofile.buf, file);\n+        strbuf_release(&pathtofile);\n+        if (ret)\n+            exit(1);\n+    }\n+    else if (queue_diff(&revs->diffopt, paths[0], paths[1]))\n         exit(1);\n+\n     diff_set_mnemonic_prefix(&revs->diffopt, \"1/\", \"2/\");\n     diffcore_std(&revs->diffopt);\n     diff_flush(&revs->diffopt);\n-- \n\nAttached patch file because gmail always replaces tabs with spaces and\nrefuses to authorize 'git send-email'\n\n\nFrom 0e160b47960dd436b32e55229184688c0a9da069 Mon Sep 17 00:00:00 2001\nFrom: Yurii Shevtsov <ungetch@gmail.com>\nDate: Thu, 25 Mar 2015 18:43:24 +0200\nSubject: [PATCH]  diff-no-index: transform \"$directory $file\" args to \"$directory/$file $file\"\ngit diff --no-index refuses to compare if args are directory and file, instead of usual diff.\n\nNow git diff --no-index modifies args, if they're directory and file, and\ndiffs files, as usual diff does.\n\nChanges are done in diff_no_index().\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Yurii Shevtsov <ungetch@gmail.com>\n---\n diff-no-index.c |   31 +++++++++++++++++++++++++++++--\n 1 files changed, 29 insertions(+), 2 deletions(-)\n\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 265709b..ecff15e 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -186,7 +186,7 @@ void diff_no_index(struct rev_info *revs,\n \t\t   int argc, const char **argv,\n \t\t   const char *prefix)\n {\n-\tint i, prefixlen;\n+\tint i, prefixlen, mode1 = 0, mode2 = 0;\n \tconst char *paths[2];\n \n \tdiff_setup(&revs->diffopt);\n@@ -229,8 +229,35 @@ void diff_no_index(struct rev_info *revs,\n \tsetup_diff_pager(&revs->diffopt);\n \tDIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);\n \n-\tif (queue_diff(&revs->diffopt, paths[0], paths[1]))\n+\tif (get_mode(paths[0], &mode1) || get_mode(paths[1], &mode2))\n+\t\texit(2);\n+\n+\tif (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) {\n+\t\tstruct strbuf pathtofile;\n+\t\tconst char *dir, *file;\n+\t\tchar *filename;\n+\t\tint ret;\n+\n+\t\tdir = S_ISDIR(mode1) ? paths[0] : paths[1];\n+\t\tfile = (dir == paths[0]) ? paths[1] : paths[0];\n+\t\tstrbuf_init(&pathtofile, strlen(paths[0]) + strlen(paths[1]) + 1);\n+\t\tstrbuf_addstr(&pathtofile, dir);\n+\t\tif (pathtofile.len && pathtofile.buf[pathtofile.len - 1] != '/')\n+\t\t\t   strbuf_addch(&pathtofile, '/');\n+\t\tfilename = strrchr(file, '/');\n+\t\tstrbuf_addstr(&pathtofile, filename ? (filename + 1) : file);\n+\n+\t\tif (file == paths[0])\n+\t\t\tret = queue_diff(&revs->diffopt, file, pathtofile.buf);\n+\t\telse\n+\t\t\tret = queue_diff(&revs->diffopt, pathtofile.buf, file);\n+\t\tstrbuf_release(&pathtofile);\n+\t\tif (ret)\n+\t\t\texit(1);\n+\t}\n+\telse if (queue_diff(&revs->diffopt, paths[0], paths[1]))\n \t\texit(1);\n+\n \tdiff_set_mnemonic_prefix(&revs->diffopt, \"1/\", \"2/\");\n \tdiffcore_std(&revs->diffopt);\n \tdiff_flush(&revs->diffopt);\n-- \n1.7.1\n\n"},{"id":"258575","messageId":"xmqq4mp7xt5k.fsf@gitster.dls.corp.google.com","threadId":"38919","inReplyTo":"CAHLaBN+nE9tmGMdJM65V-bONKe8CE9PZ1Ottc1R9D=Pm0X7k_g@mail.gmail.com","subject":"Re: [PATCH V2/RFC][GSoC] diff-no-index: transform \"$directory $file\" args to \"$directory/$file $file\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-26T22:58:47Z","receivedAt":"2015-03-26T22:58:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Yurii Shevtsov <ungetch@gmail.com> writes:\n\n> git diff --no-index refuses to compare if args are directory and file,\n> instead of usual diff.\n>\n> Now git diff --no-index modifies args, if they're directory and file,\n> and diffs files, as usual diff does.\n>\n> Changes are done in diff_no_index().\n>\n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Yurii Shevtsov <ungetch@gmail.com>\n> ---\n>  diff-no-index.c |   31 +++++++++++++++++++++++++++++--\n>  1 files changed, 29 insertions(+), 2 deletions(-)\n\nThis round looks sensible.  Good catch to notice that POSIX wants\nyou to append not just the \"path to the file\", but the basename of\nthe file, to the directory name.\n\nI didn't try your patch, but I wouldn't be surprised if it passed\nthe tests in the patches I wrote last night in the $gmane/266315\nthread ;-).\n\nGood luck with your GSoC application.\n"}]}