Coverage Report

Created: 2024-09-08 06:23

/src/git/builtin/diff-files.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * GIT - The information manager from hell
3
 *
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
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;
19
20
int cmd_diff_files(int argc, const char **argv, const char *prefix)
21
0
{
22
0
  struct rev_info rev;
23
0
  int result;
24
0
  unsigned options = 0;
25
26
0
  if (argc == 2 && !strcmp(argv[1], "-h"))
27
0
    usage(diff_files_usage);
28
29
0
  git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
30
31
0
  prepare_repo_settings(the_repository);
32
0
  the_repository->settings.command_requires_full_index = 0;
33
34
0
  repo_init_revisions(the_repository, &rev, prefix);
35
0
  rev.abbrev = 0;
36
37
  /*
38
   * Consider "intent-to-add" files as new by default, unless
39
   * explicitly specified in the command line or anywhere else.
40
   */
41
0
  rev.diffopt.ita_invisible_in_index = 1;
42
43
0
  prefix = precompose_argv_prefix(argc, argv, prefix);
44
45
0
  argc = setup_revisions(argc, argv, &rev, NULL);
46
0
  while (1 < argc && argv[1][0] == '-') {
47
0
    if (!strcmp(argv[1], "--base"))
48
0
      rev.max_count = 1;
49
0
    else if (!strcmp(argv[1], "--ours"))
50
0
      rev.max_count = 2;
51
0
    else if (!strcmp(argv[1], "--theirs"))
52
0
      rev.max_count = 3;
53
0
    else if (!strcmp(argv[1], "-q"))
54
0
      options |= DIFF_SILENT_ON_REMOVED;
55
0
    else
56
0
      usage(diff_files_usage);
57
0
    argv++; argc--;
58
0
  }
59
0
  if (!rev.diffopt.output_format)
60
0
    rev.diffopt.output_format = DIFF_FORMAT_RAW;
61
0
  rev.diffopt.rotate_to_strict = 1;
62
63
  /*
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.
67
   */
68
0
  if (rev.pending.nr ||
69
0
      rev.min_age != -1 || rev.max_age != -1 ||
70
0
      3 < rev.max_count)
71
0
    usage(diff_files_usage);
72
73
  /*
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).
77
   */
78
0
  if (rev.max_count == -1 &&
79
0
      (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
80
0
    diff_merges_set_dense_combined_if_unset(&rev);
81
82
0
  if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
83
0
    die_errno("repo_read_index_preload");
84
0
  run_diff_files(&rev, options);
85
0
  result = diff_result_code(&rev.diffopt);
86
0
  release_revisions(&rev);
87
0
  return result;
88
0
}