diff-files: do not play --no-index games
Being able to say "git diff A B" outside a git repository and getting a colourful version of "diff -u A B" may be nice, but such a cute hack should not give bogus results to scripts that want to give two paths, either or both of which happen to have been removed from the work tree, to "git diff-files". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 23, 2008 at 18:15 UTC
6304c29d518206b0780291a02f94f435abf82d74
3 files changed
+38
-13
Documentation/git-diff-files.txt
+1
-4
@@ -8,7 +8,7 @@ git-diff-files - Compares files in the working tree and the index
8
9
SYNOPSIS
10
--------
11
-'git-diff-files' [-q] [-0|-1|-2|-3|-c|--cc|--no-index] [<common diff options>] [<path>...]
11
+'git-diff-files' [-q] [-0|-1|-2|-3|-c|--cc] [<common diff options>] [<path>...]
12
13
DESCRIPTION
14
-----------
@@ -36,9 +36,6 @@ omit diff output for unmerged entries and just show "Unmerged".
36
diff, similar to the way 'diff-tree' shows a merge
37
commit with these flags.
38
39
---no-index::
40
- Compare the two given files / directories.
41
-
39
-q::
40
Remain silent even on nonexistent files
41
builtin-diff-files.c
+36
-8
@@ -10,26 +10,54 @@
10
#include "builtin.h"
11
12
static const char diff_files_usage[] =
13
-"git-diff-files [-q] [-0/-1/2/3 |-c|--cc|--no-index] [<common diff options>] [<path>...]"
13
+"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
14
COMMON_DIFF_OPTIONS_HELP;
15
16
int cmd_diff_files(int argc, const char **argv, const char *prefix)
17
{
18
struct rev_info rev;
19
- int nongit;
19
int result;
20
+ unsigned options = 0;
21
22
- prefix = setup_git_directory_gently(&nongit);
22
init_revisions(&rev, prefix);
23
git_config(git_diff_basic_config); /* no "diff" UI options */
24
rev.abbrev = 0;
25
27
- if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))
28
- argc = 0;
29
- else
30
- argc = setup_revisions(argc, argv, &rev, NULL);
26
+ argc = setup_revisions(argc, argv, &rev, NULL);
27
+ while (1 < argc && argv[1][0] == '-') {
28
+ if (!strcmp(argv[1], "--base"))
29
+ rev.max_count = 1;
30
+ else if (!strcmp(argv[1], "--ours"))
31
+ rev.max_count = 2;
32
+ else if (!strcmp(argv[1], "--theirs"))
33
+ rev.max_count = 3;
34
+ else if (!strcmp(argv[1], "-q"))
35
+ options |= DIFF_SILENT_ON_REMOVED;
36
+ else
37
+ usage(diff_files_usage);
38
+ argv++; argc--;
39
+ }
40
if (!rev.diffopt.output_format)
41
rev.diffopt.output_format = DIFF_FORMAT_RAW;
33
- result = run_diff_files_cmd(&rev, argc, argv);
42
+
43
+ /*
44
+ * Make sure there are NO revision (i.e. pending object) parameter,
45
+ * rev.max_count is reasonable (0 <= n <= 3), and
46
+ * there is no other revision filtering parameters.
47
+ */
48
+ if (rev.pending.nr ||
49
+ rev.min_age != -1 || rev.max_age != -1 ||
50
+ 3 < rev.max_count)
51
+ usage(diff_files_usage);
52
+
53
+ if (rev.max_count == -1 &&
54
+ (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
55
+ rev.combine_merges = rev.dense_combined_merges = 1;
56
+
57
+ if (read_cache() < 0) {
58
+ perror("read_cache");
59
+ return -1;
60
+ }
61
+ result = run_diff_files(&rev, options);
62
return diff_result_code(&rev.diffopt, result);
63
}
git.c
+1
-1
@@ -293,7 +293,7 @@ static void handle_internal_command(int argc, const char **argv)
293
{ "count-objects", cmd_count_objects, RUN_SETUP },
294
{ "describe", cmd_describe, RUN_SETUP },
295
{ "diff", cmd_diff },
296
- { "diff-files", cmd_diff_files },
296
+ { "diff-files", cmd_diff_files, RUN_SETUP },
297
{ "diff-index", cmd_diff_index, RUN_SETUP },
298
{ "diff-tree", cmd_diff_tree, RUN_SETUP },
299
{ "fast-export", cmd_fast_export, RUN_SETUP },