builtin-branch: use strbuf in fill_tracking_info()
[git/spearce.git] / builtin-diff-files.c
blob2b578c714d36c600107f03b454ed8241dc2d4f19
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "cache.h"
7 #include "diff.h"
8 #include "commit.h"
9 #include "revision.h"
10 #include "builtin.h"
12 static const char diff_files_usage[] =
13 "git diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
14 COMMON_DIFF_OPTIONS_HELP;
16 int cmd_diff_files(int argc, const char **argv, const char *prefix)
18 struct rev_info rev;
19 int result;
20 unsigned options = 0;
22 init_revisions(&rev, prefix);
23 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
24 rev.abbrev = 0;
26 argc = setup_revisions(argc, argv, &rev, NULL);
27 while (1 < argc && argv[1][0] == '-') {
28 if (!strcmp(argv[1], "--base"))
29 rev.max_count = 1;
30 else if (!strcmp(argv[1], "--ours"))
31 rev.max_count = 2;
32 else if (!strcmp(argv[1], "--theirs"))
33 rev.max_count = 3;
34 else if (!strcmp(argv[1], "-q"))
35 options |= DIFF_SILENT_ON_REMOVED;
36 else
37 usage(diff_files_usage);
38 argv++; argc--;
40 if (!rev.diffopt.output_format)
41 rev.diffopt.output_format = DIFF_FORMAT_RAW;
44 * Make sure there are NO revision (i.e. pending object) parameter,
45 * rev.max_count is reasonable (0 <= n <= 3), and
46 * there is no other revision filtering parameters.
48 if (rev.pending.nr ||
49 rev.min_age != -1 || rev.max_age != -1 ||
50 3 < rev.max_count)
51 usage(diff_files_usage);
54 * "diff-files --base -p" should not combine merges because it
55 * was not asked to. "diff-files -c -p" should not densify
56 * (the user should ask with "diff-files --cc" explicitly).
58 if (rev.max_count == -1 && !rev.combine_merges &&
59 (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
60 rev.combine_merges = rev.dense_combined_merges = 1;
62 if (read_cache() < 0) {
63 perror("read_cache");
64 return -1;
66 result = run_diff_files(&rev, options);
67 return diff_result_code(&rev.diffopt, result);