]>
Commit | Line | Data |
---|---|---|
8bc9a0c7 LT |
1 | /* |
2 | * GIT - The information manager from hell | |
3 | * | |
4 | * Copyright (C) Linus Torvalds, 2005 | |
5 | */ | |
e83c5163 | 6 | #include "cache.h" |
4a6bf9e1 | 7 | #include "diff.h" |
91539833 LT |
8 | #include "commit.h" |
9 | #include "revision.h" | |
e8cc9cd9 | 10 | #include "builtin.h" |
c0fb976a | 11 | |
4d1f1190 | 12 | static const char diff_files_usage[] = |
1b1dd23f | 13 | "git diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]" |
dda2d79a | 14 | COMMON_DIFF_OPTIONS_HELP; |
b8f80925 | 15 | |
a633fca0 | 16 | int cmd_diff_files(int argc, const char **argv, const char *prefix) |
e83c5163 | 17 | { |
6973dcae | 18 | struct rev_info rev; |
41bbf9d5 | 19 | int result; |
6304c29d | 20 | unsigned options = 0; |
e83c5163 | 21 | |
a633fca0 | 22 | init_revisions(&rev, prefix); |
ef90d6d4 | 23 | git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ |
6973dcae JH |
24 | rev.abbrev = 0; |
25 | ||
6304c29d JH |
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--; | |
39 | } | |
c9b5ef99 TH |
40 | if (!rev.diffopt.output_format) |
41 | rev.diffopt.output_format = DIFF_FORMAT_RAW; | |
6304c29d JH |
42 | |
43 | /* | |
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. | |
47 | */ | |
48 | if (rev.pending.nr || | |
49 | rev.min_age != -1 || rev.max_age != -1 || | |
50 | 3 < rev.max_count) | |
51 | usage(diff_files_usage); | |
52 | ||
53 | if (rev.max_count == -1 && | |
54 | (rev.diffopt.output_format & DIFF_FORMAT_PATCH)) | |
55 | rev.combine_merges = rev.dense_combined_merges = 1; | |
56 | ||
57 | if (read_cache() < 0) { | |
58 | perror("read_cache"); | |
59 | return -1; | |
60 | } | |
61 | result = run_diff_files(&rev, options); | |
da31b358 | 62 | return diff_result_code(&rev.diffopt, result); |
e83c5163 | 63 | } |