2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_COMPATIBILITY_MACROS
13 #include "submodule.h"
15 static const char diff_files_usage
[] =
16 "git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
17 COMMON_DIFF_OPTIONS_HELP
;
19 int cmd_diff_files(int argc
, const char **argv
, const char *prefix
)
25 if (argc
== 2 && !strcmp(argv
[1], "-h"))
26 usage(diff_files_usage
);
28 git_config(git_diff_basic_config
, NULL
); /* no "diff" UI options */
29 repo_init_revisions(the_repository
, &rev
, prefix
);
31 precompose_argv(argc
, argv
);
33 argc
= setup_revisions(argc
, argv
, &rev
, NULL
);
34 while (1 < argc
&& argv
[1][0] == '-') {
35 if (!strcmp(argv
[1], "--base"))
37 else if (!strcmp(argv
[1], "--ours"))
39 else if (!strcmp(argv
[1], "--theirs"))
41 else if (!strcmp(argv
[1], "-q"))
42 options
|= DIFF_SILENT_ON_REMOVED
;
44 usage(diff_files_usage
);
47 if (!rev
.diffopt
.output_format
)
48 rev
.diffopt
.output_format
= DIFF_FORMAT_RAW
;
51 * Make sure there are NO revision (i.e. pending object) parameter,
52 * rev.max_count is reasonable (0 <= n <= 3), and
53 * there is no other revision filtering parameters.
56 rev
.min_age
!= -1 || rev
.max_age
!= -1 ||
58 usage(diff_files_usage
);
61 * "diff-files --base -p" should not combine merges because it
62 * was not asked to. "diff-files -c -p" should not densify
63 * (the user should ask with "diff-files --cc" explicitly).
65 if (rev
.max_count
== -1 && !rev
.combine_merges
&&
66 (rev
.diffopt
.output_format
& DIFF_FORMAT_PATCH
))
67 rev
.combine_merges
= rev
.dense_combined_merges
= 1;
69 if (read_cache_preload(&rev
.diffopt
.pathspec
) < 0) {
70 perror("read_cache_preload");
73 result
= run_diff_files(&rev
, options
);
74 return diff_result_code(&rev
.diffopt
, result
);