{"thread":{"id":"27433","subject":"[PATCH] Only use core 'git diff' if both paths are within the repo.","startedAt":"2011-05-23T04:44:16Z","lastAt":"2011-05-23T04:44:16Z","messageCount":1,"participants":["Anthony Foiani"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"168480","messageId":"4dd9e779.6300440a.1871.ffffcd9d@mx.google.com","threadId":"27433","inReplyTo":null,"subject":"[PATCH] Only use core 'git diff' if both paths are within the repo.","fromName":"Anthony Foiani","fromEmail":"anthony.foiani@gmail.com","sentAt":"2011-05-23T04:44:16Z","receivedAt":"2011-05-23T04:44:16Z","isPatch":true,"sender":{"key":"anthony.foiani@gmail.com","avatar":"https://gravatar.com/avatar/dc2ca9a2ec133021e09ad6a322d4951c7355aefcf12889c5ac837eb16187c2b9?d=mp&s=160"},"body":"The core 'git diff' engine can only handle pathspecs that are within a\ngiven repo.  Make sure that we don't invoke it unless both pathspec\nvalues are in the repo.\n\nSigned-off-by: Anthony Foiani <anthony.foiani@gmail.com>\n---\n diff-no-index.c |   39 ++++++++++++---------------------------\n 1 files changed, 12 insertions(+), 27 deletions(-)\n\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 3172788..b651f6d 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -227,43 +227,28 @@ void diff_no_index(struct rev_info *revs,\n \t/* If --no-index wasn't specified explicitly, check to see if\n \t * we need to force it. */\n \tif (!no_index) {\n-\n-\t\t/* The first pathspec is the \"left hand side\" */\n-\t\tconst char *lhs = (n_paths >= 1) ? argv[i] : NULL;\n-\t\tconst int lhs_in_repo = lhs && path_in_repo(lhs);\n-\n-\t\t/* And the second is the \"right hand side\" */\n-\t\tconst char *rhs = (n_paths >= 2) ? argv[i+1] : NULL;\n-\t\tconst int rhs_in_repo = rhs && path_in_repo(rhs);\n-\n-\t\tint force_no_index = 0;\n-\n \t\tif (nongit) {\n \t\t\twarning(\"'git diff' outside a repo, forcing --no-index\");\n-\t\t\tforce_no_index = 1;\n \t\t}\n \t\telse {\n-\t\t\tif (lhs_in_repo || rhs_in_repo)\n-\t\t\t\treturn; /* Normal git diff, let core handle it. */\n-\n-\t\t\tconst int lhs_untracked = (lhs && !lhs_in_repo);\n-\t\t\tconst int rhs_untracked = (rhs && !rhs_in_repo);\n+\t\t\t/* lhs = \"left hand side\", rhs = \"right hand side\" */\n+\t\t\tconst char *lhs = (n_paths >= 1) ? argv[i] : NULL;\n+\t\t\tconst char *rhs = (n_paths >= 2) ? argv[i+1] : NULL;\n+\t\t\tconst int lhs_tracked = lhs && path_in_repo(lhs);\n+\t\t\tconst int rhs_tracked = rhs && path_in_repo(rhs);\n \n-\t\t\tif (lhs_untracked && rhs_untracked)\n-\t\t\t\twarning(\"neither '%s' nor '%s' are tracked,\"\n-\t\t\t\t\t\" forcing --no-index\", lhs, rhs );\n-\t\t\telse if (lhs_untracked)\n+\t\t\tif (lhs_tracked && rhs_tracked)\n+\t\t\t\treturn; /* Normal git diff, let core handle it. */\n+\t\t\telse if (!lhs_tracked)\n \t\t\t\twarning(\"'%s' is not tracked,\"\n \t\t\t\t\t\" forcing --no-index\", lhs );\n-\t\t\telse if (rhs_untracked)\n+\t\t\telse if (!rhs_tracked)\n \t\t\t\twarning(\"'%s' is not tracked,\"\n \t\t\t\t\t\" forcing --no-index\", rhs );\n-\n-\t\t\tforce_no_index = lhs_untracked || rhs_untracked;\n+\t\t\telse\n+\t\t\t\twarning(\"neither '%s' nor '%s' are tracked,\"\n+\t\t\t\t\t\" forcing --no-index\", lhs, rhs );\n \t\t}\n-\n-\t\tif (!force_no_index) /* Impossible? */\n-\t\t\tdie(\"--no-index not set and not forced\");\n \t}\n \n \tif (n_paths != 2) {\n-- \n1.7.4.4\n"}]}