From: Anthony Foiani <anthony.foiani@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH] Only use core 'git diff' if both paths are within the repo.
Date: Sun, 22 May 2011 22:44:16 -0600 [thread overview]
Message-ID: <4dd9e779.6300440a.1871.ffffcd9d@mx.google.com> (raw)
The core 'git diff' engine can only handle pathspecs that are within a
given repo. Make sure that we don't invoke it unless both pathspec
values are in the repo.
Signed-off-by: Anthony Foiani <anthony.foiani@gmail.com>
---
diff-no-index.c | 39 ++++++++++++---------------------------
1 files changed, 12 insertions(+), 27 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 3172788..b651f6d 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -227,43 +227,28 @@ void diff_no_index(struct rev_info *revs,
/* If --no-index wasn't specified explicitly, check to see if
* we need to force it. */
if (!no_index) {
-
- /* The first pathspec is the "left hand side" */
- const char *lhs = (n_paths >= 1) ? argv[i] : NULL;
- const int lhs_in_repo = lhs && path_in_repo(lhs);
-
- /* And the second is the "right hand side" */
- const char *rhs = (n_paths >= 2) ? argv[i+1] : NULL;
- const int rhs_in_repo = rhs && path_in_repo(rhs);
-
- int force_no_index = 0;
-
if (nongit) {
warning("'git diff' outside a repo, forcing --no-index");
- force_no_index = 1;
}
else {
- if (lhs_in_repo || rhs_in_repo)
- return; /* Normal git diff, let core handle it. */
-
- const int lhs_untracked = (lhs && !lhs_in_repo);
- const int rhs_untracked = (rhs && !rhs_in_repo);
+ /* lhs = "left hand side", rhs = "right hand side" */
+ const char *lhs = (n_paths >= 1) ? argv[i] : NULL;
+ const char *rhs = (n_paths >= 2) ? argv[i+1] : NULL;
+ const int lhs_tracked = lhs && path_in_repo(lhs);
+ const int rhs_tracked = rhs && path_in_repo(rhs);
- if (lhs_untracked && rhs_untracked)
- warning("neither '%s' nor '%s' are tracked,"
- " forcing --no-index", lhs, rhs );
- else if (lhs_untracked)
+ if (lhs_tracked && rhs_tracked)
+ return; /* Normal git diff, let core handle it. */
+ else if (!lhs_tracked)
warning("'%s' is not tracked,"
" forcing --no-index", lhs );
- else if (rhs_untracked)
+ else if (!rhs_tracked)
warning("'%s' is not tracked,"
" forcing --no-index", rhs );
-
- force_no_index = lhs_untracked || rhs_untracked;
+ else
+ warning("neither '%s' nor '%s' are tracked,"
+ " forcing --no-index", lhs, rhs );
}
-
- if (!force_no_index) /* Impossible? */
- die("--no-index not set and not forced");
}
if (n_paths != 2) {
--
1.7.4.4
reply other threads:[~2011-05-23 4:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4dd9e779.6300440a.1871.ffffcd9d@mx.google.com \
--to=anthony.foiani@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.