diff options
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | 2007-02-25 23:35:27 +0100 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-02-28 16:32:31 -0800 |
commit | fcfa33ec905fcde1c16e7cbbe00d7147b89f1f01 (patch) | |
tree | 2de48ce64183245fd0beba56ef817dbc8e41d281 /diff-lib.c | |
parent | 2eb06531e3d53c2604f20c32e5cb791d5044ff02 (diff) | |
download | git-fcfa33ec905fcde1c16e7cbbe00d7147b89f1f01.tar.gz |
diff: make more cases implicit --no-index
When specifying an absolute path, or a relative path pointing outside
the working tree, do not fail, but roll your own diffopt parsing,
and execute a --no-index diff.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'diff-lib.c')
-rw-r--r-- | diff-lib.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/diff-lib.c b/diff-lib.c index 2e91619906..75ff0dd93d 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -200,6 +200,60 @@ static int handle_diff_files_args(struct rev_info *revs, return 0; } +static int is_outside_repo(const char *path, int nongit, const char *prefix) +{ + int i; + if (nongit || !strcmp(path, "-") || path[0] == '/') + return 1; + if (prefixcmp(path, "../")) + return 0; + if (!prefix) + return 1; + for (i = strlen(prefix); !prefixcmp(path, "../"); ) { + while (i > 0 && prefix[i - 1] != '/') + i--; + if (--i < 0) + return 1; + path += 3; + } + return 0; +} + +int setup_diff_no_index(struct rev_info *revs, + int argc, const char ** argv, int nongit, const char *prefix) +{ + int i; + for (i = 1; i < argc; i++) + if (argv[i][0] != '-') + break; + else if (!strcmp(argv[i], "--")) { + i++; + break; + } else if (i < argc - 3 && !strcmp(argv[i], "--no-index")) { + i = argc - 3; + break; + } + if (argc != i + 2 || (!is_outside_repo(argv[i + 1], nongit, prefix) && + !is_outside_repo(argv[i], nongit, prefix))) + return -1; + + diff_setup(&revs->diffopt); + for (i = 1; i < argc - 2; ) + if (!strcmp(argv[i], "--no-index")) + i++; + else { + int j = diff_opt_parse(&revs->diffopt, + argv + i, argc - i); + if (!j) + die("invalid diff option/value: %s", argv[i]); + i += j; + } + revs->diffopt.paths = argv + argc - 2; + revs->diffopt.nr_paths = 2; + revs->max_count = -2; + return 0; +} + int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv) { int silent_on_removed; |