Merge branch 'ps/receive-use-only-advertised'
[alt-git.git] / builtin / diff-files.c
blob096ea2fedbc497b51b3f6519f77cd698e83fe59a
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #define USE_THE_INDEX_COMPATIBILITY_MACROS
7 #include "cache.h"
8 #include "config.h"
9 #include "diff.h"
10 #include "diff-merges.h"
11 #include "commit.h"
12 #include "revision.h"
13 #include "builtin.h"
14 #include "submodule.h"
16 static const char diff_files_usage[] =
17 "git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
18 "\n"
19 COMMON_DIFF_OPTIONS_HELP;
21 int cmd_diff_files(int argc, const char **argv, const char *prefix)
23 struct rev_info rev;
24 int result;
25 unsigned options = 0;
27 if (argc == 2 && !strcmp(argv[1], "-h"))
28 usage(diff_files_usage);
30 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
31 repo_init_revisions(the_repository, &rev, prefix);
32 rev.abbrev = 0;
35 * Consider "intent-to-add" files as new by default, unless
36 * explicitly specified in the command line or anywhere else.
38 rev.diffopt.ita_invisible_in_index = 1;
40 prefix = precompose_argv_prefix(argc, argv, prefix);
42 argc = setup_revisions(argc, argv, &rev, NULL);
43 while (1 < argc && argv[1][0] == '-') {
44 if (!strcmp(argv[1], "--base"))
45 rev.max_count = 1;
46 else if (!strcmp(argv[1], "--ours"))
47 rev.max_count = 2;
48 else if (!strcmp(argv[1], "--theirs"))
49 rev.max_count = 3;
50 else if (!strcmp(argv[1], "-q"))
51 options |= DIFF_SILENT_ON_REMOVED;
52 else
53 usage(diff_files_usage);
54 argv++; argc--;
56 if (!rev.diffopt.output_format)
57 rev.diffopt.output_format = DIFF_FORMAT_RAW;
58 rev.diffopt.rotate_to_strict = 1;
61 * Make sure there are NO revision (i.e. pending object) parameter,
62 * rev.max_count is reasonable (0 <= n <= 3), and
63 * there is no other revision filtering parameters.
65 if (rev.pending.nr ||
66 rev.min_age != -1 || rev.max_age != -1 ||
67 3 < rev.max_count)
68 usage(diff_files_usage);
71 * "diff-files --base -p" should not combine merges because it
72 * was not asked to. "diff-files -c -p" should not densify
73 * (the user should ask with "diff-files --cc" explicitly).
75 if (rev.max_count == -1 &&
76 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
77 diff_merges_set_dense_combined_if_unset(&rev);
79 if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
80 perror("read_cache_preload");
81 result = -1;
82 goto cleanup;
84 result = run_diff_files(&rev, options);
85 result = diff_result_code(&rev.diffopt, result);
86 cleanup:
87 release_revisions(&rev);
88 return result;