2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
9 #include "diff-merges.h"
11 #include "preload-index.h"
12 #include "repository.h"
15 static const char diff_files_usage
[] =
16 "git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
18 COMMON_DIFF_OPTIONS_HELP
;
20 int cmd_diff_files(int argc
, const char **argv
, const char *prefix
)
26 if (argc
== 2 && !strcmp(argv
[1], "-h"))
27 usage(diff_files_usage
);
29 git_config(git_diff_basic_config
, NULL
); /* no "diff" UI options */
31 prepare_repo_settings(the_repository
);
32 the_repository
->settings
.command_requires_full_index
= 0;
34 repo_init_revisions(the_repository
, &rev
, prefix
);
38 * Consider "intent-to-add" files as new by default, unless
39 * explicitly specified in the command line or anywhere else.
41 rev
.diffopt
.ita_invisible_in_index
= 1;
43 prefix
= precompose_argv_prefix(argc
, argv
, prefix
);
45 argc
= setup_revisions(argc
, argv
, &rev
, NULL
);
46 while (1 < argc
&& argv
[1][0] == '-') {
47 if (!strcmp(argv
[1], "--base"))
49 else if (!strcmp(argv
[1], "--ours"))
51 else if (!strcmp(argv
[1], "--theirs"))
53 else if (!strcmp(argv
[1], "-q"))
54 options
|= DIFF_SILENT_ON_REMOVED
;
56 usage(diff_files_usage
);
59 if (!rev
.diffopt
.output_format
)
60 rev
.diffopt
.output_format
= DIFF_FORMAT_RAW
;
61 rev
.diffopt
.rotate_to_strict
= 1;
64 * Make sure there are NO revision (i.e. pending object) parameter,
65 * rev.max_count is reasonable (0 <= n <= 3), and
66 * there is no other revision filtering parameters.
69 rev
.min_age
!= -1 || rev
.max_age
!= -1 ||
71 usage(diff_files_usage
);
74 * "diff-files --base -p" should not combine merges because it
75 * was not asked to. "diff-files -c -p" should not densify
76 * (the user should ask with "diff-files --cc" explicitly).
78 if (rev
.max_count
== -1 &&
79 (rev
.diffopt
.output_format
& DIFF_FORMAT_PATCH
))
80 diff_merges_set_dense_combined_if_unset(&rev
);
82 if (repo_read_index_preload(the_repository
, &rev
.diffopt
.pathspec
, 0) < 0)
83 die_errno("repo_read_index_preload");
84 run_diff_files(&rev
, options
);
85 result
= diff_result_code(&rev
.diffopt
);
86 release_revisions(&rev
);