From 546e0fd9e918b2ea3d9943124641d3b6af59a4fe Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 21 Jun 2012 14:09:50 -0400 Subject: diff: handle relative paths in no-index When diff-no-index is given a relative path to a file outside the repository, it aborts with error. However, if the file is given using an absolute path, the diff runs as expected. The two cases should be treated the same. Tests and commit message by Tim Henigan. Signed-off-by: Jeff King Signed-off-by: Tim Henigan Signed-off-by: Junio C Hamano --- diff-no-index.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'diff-no-index.c') diff --git a/diff-no-index.c b/diff-no-index.c index f0b0010aed..e6b9952b34 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -151,23 +151,6 @@ static int queue_diff(struct diff_options *o, } } -static int path_outside_repo(const char *path) -{ - const char *work_tree; - size_t len; - - if (!is_absolute_path(path)) - return 0; - work_tree = get_git_work_tree(); - if (!work_tree) - return 1; - len = strlen(work_tree); - if (strncmp(path, work_tree, len) || - (path[len] != '\0' && path[len] != '/')) - return 1; - return 0; -} - void diff_no_index(struct rev_info *revs, int argc, const char **argv, int nongit, const char *prefix) @@ -197,8 +180,8 @@ void diff_no_index(struct rev_info *revs, * a colourful "diff" replacement. */ if ((argc != i + 2) || - (!path_outside_repo(argv[i]) && - !path_outside_repo(argv[i+1]))) + (path_inside_repo(prefix, argv[i]) && + path_inside_repo(prefix, argv[i+1]))) return; } if (argc != i + 2) -- cgit v1.2.3 From 304970dd5d9e542e70eca98932c1e9f26770678e Mon Sep 17 00:00:00 2001 From: Tim Henigan Date: Thu, 21 Jun 2012 14:09:51 -0400 Subject: diff-no-index: exit(1) if 'diff --quiet ' finds changes When running 'git diff --quiet ', if file1 or file2 is outside the repository, it will exit(0) even if the files differ. It should exit(1) when they differ. This happens because 'diff_no_index' looks at the 'found_changes' member from 'diff_options' to determine if changes were made. This is the wrong thing to do, since it is only set if xdiff is actually run and it finds a change (the diff machinery will optimize out the xdiff call when it is not necessary) and in that case HAS_CHANGED flag needs to be taken into account. Use diff_result_code() that knows all these details for the correct exit value instead. Signed-off-by: Tim Henigan Signed-off-by: Junio C Hamano --- diff-no-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'diff-no-index.c') diff --git a/diff-no-index.c b/diff-no-index.c index e6b9952b34..63c31cc4de 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -256,5 +256,5 @@ void diff_no_index(struct rev_info *revs, * The return code for --no-index imitates diff(1): * 0 = no changes, 1 = changes, else error */ - exit(revs->diffopt.found_changes); + exit(diff_result_code(&revs->diffopt, 0)); } -- cgit v1.2.3