summaryrefslogtreecommitdiff
path: root/builtin/diff.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-09-13 03:23:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-13 22:45:45 (GMT)
commit475b362c2a326ddc9987ee0ff6448e795f009d5d (patch)
treebd7ef92925e525e1d4860e2751d8cbef96956139 /builtin/diff.c
parent4a73aaaf18099ec1897330dd6c4a09f10ea2f573 (diff)
downloadgit-475b362c2a326ddc9987ee0ff6448e795f009d5d.zip
git-475b362c2a326ddc9987ee0ff6448e795f009d5d.tar.gz
git-475b362c2a326ddc9987ee0ff6448e795f009d5d.tar.bz2
diff: skip implicit no-index check when given --no-index
We can invoke no-index mode in two ways: by an explicit request from the user, or implicitly by noticing that we have two paths, and at least one is outside the repository. If the user already told us --no-index, there is no need for us to do the implicit test at all. However, we currently do, and downgrade our "explicit" to DIFF_NO_INDEX_IMPLICIT. This doesn't have any user-visible behavior, though it's not immediately obvious why. We only trigger the implicit check when we have exactly two non-option arguments. And the only code that cares about implicit versus explicit is an error message that we show when we _don't_ have two non-option arguments. However, it's worth fixing anyway. Besides being slightly more efficient, it makes the code easier to follow, which will help when we modify it in future patches. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/diff.c')
-rw-r--r--builtin/diff.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/builtin/diff.c b/builtin/diff.c
index d6b8f98..7b2a744 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -301,20 +301,21 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
break;
}
- if (!no_index)
+ if (!no_index) {
prefix = setup_git_directory_gently(&nongit);
- /*
- * Treat git diff with at least one path outside of the
- * repo the same as if the command would have been executed
- * outside of a git repository. In this case it behaves
- * the same way as "git diff --no-index <a> <b>", which acts
- * as a colourful "diff" replacement.
- */
- if (nongit || ((argc == i + 2) &&
- (!path_inside_repo(prefix, argv[i]) ||
- !path_inside_repo(prefix, argv[i + 1]))))
- no_index = DIFF_NO_INDEX_IMPLICIT;
+ /*
+ * Treat git diff with at least one path outside of the
+ * repo the same as if the command would have been executed
+ * outside of a git repository. In this case it behaves
+ * the same way as "git diff --no-index <a> <b>", which acts
+ * as a colourful "diff" replacement.
+ */
+ if (nongit || ((argc == i + 2) &&
+ (!path_inside_repo(prefix, argv[i]) ||
+ !path_inside_repo(prefix, argv[i + 1]))))
+ no_index = DIFF_NO_INDEX_IMPLICIT;
+ }
if (!no_index)
gitmodules_config();