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