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>

Jeff King committed Sep 12, 2016 at 20:23 UTC 475b362c2a326ddc9987ee0ff6448e795f009d5d
1 file changed +13 -12
builtin/diff.c
+13 -12
@@ -301,20 +301,21 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
301 break;
302 }
303
304 - if (!no_index)
304 + if (!no_index) {
305 prefix = setup_git_directory_gently(&nongit);
306
307 - /*
308 - * Treat git diff with at least one path outside of the
309 - * repo the same as if the command would have been executed
310 - * outside of a git repository. In this case it behaves
311 - * the same way as "git diff --no-index <a> <b>", which acts
312 - * as a colourful "diff" replacement.
313 - */
314 - if (nongit || ((argc == i + 2) &&
315 - (!path_inside_repo(prefix, argv[i]) ||
316 - !path_inside_repo(prefix, argv[i + 1]))))
317 - no_index = DIFF_NO_INDEX_IMPLICIT;
307 + /*
308 + * Treat git diff with at least one path outside of the
309 + * repo the same as if the command would have been executed
310 + * outside of a git repository. In this case it behaves
311 + * the same way as "git diff --no-index <a> <b>", which acts
312 + * as a colourful "diff" replacement.
313 + */
314 + if (nongit || ((argc == i + 2) &&
315 + (!path_inside_repo(prefix, argv[i]) ||
316 + !path_inside_repo(prefix, argv[i + 1]))))
317 + no_index = DIFF_NO_INDEX_IMPLICIT;
318 + }
319
320 if (!no_index)
321 gitmodules_config();