The eleventh batch
[git/gitster.git] / builtin / diff-files.c
blobe0e0ccec2343a285d85d6bf319395d1b98c042d2
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #define USE_THE_REPOSITORY_VARIABLE
7 #include "builtin.h"
8 #include "config.h"
9 #include "diff.h"
10 #include "diff-merges.h"
11 #include "commit.h"
12 #include "preload-index.h"
13 #include "revision.h"
15 static const char diff_files_usage[] =
16 "git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
17 "\n"
18 COMMON_DIFF_OPTIONS_HELP;
20 int cmd_diff_files(int argc,
21 const char **argv,
22 const char *prefix,
23 struct repository *repo UNUSED)
25 struct rev_info rev;
26 int result;
27 unsigned options = 0;
29 if (argc == 2 && !strcmp(argv[1], "-h"))
30 usage(diff_files_usage);
32 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
34 prepare_repo_settings(the_repository);
35 the_repository->settings.command_requires_full_index = 0;
37 repo_init_revisions(the_repository, &rev, prefix);
38 rev.abbrev = 0;
41 * Consider "intent-to-add" files as new by default, unless
42 * explicitly specified in the command line or anywhere else.
44 rev.diffopt.ita_invisible_in_index = 1;
46 prefix = precompose_argv_prefix(argc, argv, prefix);
48 argc = setup_revisions(argc, argv, &rev, NULL);
49 while (1 < argc && argv[1][0] == '-') {
50 if (!strcmp(argv[1], "--base"))
51 rev.max_count = 1;
52 else if (!strcmp(argv[1], "--ours"))
53 rev.max_count = 2;
54 else if (!strcmp(argv[1], "--theirs"))
55 rev.max_count = 3;
56 else if (!strcmp(argv[1], "-q"))
57 options |= DIFF_SILENT_ON_REMOVED;
58 else
59 usage(diff_files_usage);
60 argv++; argc--;
62 if (!rev.diffopt.output_format)
63 rev.diffopt.output_format = DIFF_FORMAT_RAW;
64 rev.diffopt.rotate_to_strict = 1;
67 * Make sure there are NO revision (i.e. pending object) parameter,
68 * rev.max_count is reasonable (0 <= n <= 3), and
69 * there is no other revision filtering parameters.
71 if (rev.pending.nr ||
72 rev.min_age != -1 || rev.max_age != -1 ||
73 3 < rev.max_count)
74 usage(diff_files_usage);
77 * "diff-files --base -p" should not combine merges because it
78 * was not asked to. "diff-files -c -p" should not densify
79 * (the user should ask with "diff-files --cc" explicitly).
81 if (rev.max_count == -1 &&
82 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
83 diff_merges_set_dense_combined_if_unset(&rev);
85 if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
86 die_errno("repo_read_index_preload");
87 run_diff_files(&rev, options);
88 result = diff_result_code(&rev);
89 release_revisions(&rev);
90 return result;