maintenance(systemd): support the Windows Subsystem for Linux
[git.git] / builtin / diff-files.c
blob50330b8dd2fd289a188b6143d528da2658327057
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "builtin.h"
7 #include "config.h"
8 #include "diff.h"
9 #include "diff-merges.h"
10 #include "commit.h"
11 #include "preload-index.h"
12 #include "repository.h"
13 #include "revision.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 */
32 prepare_repo_settings(the_repository);
33 the_repository->settings.command_requires_full_index = 0;
35 repo_init_revisions(the_repository, &rev, prefix);
36 rev.abbrev = 0;
39 * Consider "intent-to-add" files as new by default, unless
40 * explicitly specified in the command line or anywhere else.
42 rev.diffopt.ita_invisible_in_index = 1;
44 prefix = precompose_argv_prefix(argc, argv, prefix);
46 argc = setup_revisions(argc, argv, &rev, NULL);
47 while (1 < argc && argv[1][0] == '-') {
48 if (!strcmp(argv[1], "--base"))
49 rev.max_count = 1;
50 else if (!strcmp(argv[1], "--ours"))
51 rev.max_count = 2;
52 else if (!strcmp(argv[1], "--theirs"))
53 rev.max_count = 3;
54 else if (!strcmp(argv[1], "-q"))
55 options |= DIFF_SILENT_ON_REMOVED;
56 else
57 usage(diff_files_usage);
58 argv++; argc--;
60 if (!rev.diffopt.output_format)
61 rev.diffopt.output_format = DIFF_FORMAT_RAW;
62 rev.diffopt.rotate_to_strict = 1;
65 * Make sure there are NO revision (i.e. pending object) parameter,
66 * rev.max_count is reasonable (0 <= n <= 3), and
67 * there is no other revision filtering parameters.
69 if (rev.pending.nr ||
70 rev.min_age != -1 || rev.max_age != -1 ||
71 3 < rev.max_count)
72 usage(diff_files_usage);
75 * "diff-files --base -p" should not combine merges because it
76 * was not asked to. "diff-files -c -p" should not densify
77 * (the user should ask with "diff-files --cc" explicitly).
79 if (rev.max_count == -1 &&
80 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
81 diff_merges_set_dense_combined_if_unset(&rev);
83 if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
84 perror("repo_read_index_preload");
85 result = -1;
86 goto cleanup;
88 result = run_diff_files(&rev, options);
89 result = diff_result_code(&rev.diffopt, result);
90 cleanup:
91 release_revisions(&rev);
92 return result;