2 * Copyright (c) 2005 Junio C Hamano
8 static int diff_output_format = DIFF_FORMAT_HUMAN;
9 static int detect_rename = 0;
10 static int diff_setup_opt = 0;
11 static int diff_score_opt = 0;
12 static const char *pickaxe = NULL;
13 static int pickaxe_opts = 0;
14 static int diff_break_opt = -1;
15 static const char *orderfile = NULL;
16 static const char *diff_filter = NULL;
18 static char *diff_stages_usage =
19 "git-diff-stages [-p] [-r] [-z] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] <stage1> <stage2> [<path>...]";
21 int main(int ac, const char **av)
23 int stage1, stage2, i;
26 while (1 < ac && av[1][0] == '-') {
27 const char *arg = av[1];
28 if (!strcmp(arg, "-r"))
30 else if (!strcmp(arg, "-p"))
31 diff_output_format = DIFF_FORMAT_PATCH;
32 else if (!strncmp(arg, "-B", 2)) {
33 if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1)
34 usage(diff_stages_usage);
36 else if (!strncmp(arg, "-M", 2)) {
37 detect_rename = DIFF_DETECT_RENAME;
38 if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
39 usage(diff_stages_usage);
41 else if (!strncmp(arg, "-C", 2)) {
42 detect_rename = DIFF_DETECT_COPY;
43 if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
44 usage(diff_stages_usage);
46 else if (!strcmp(arg, "-z"))
47 diff_output_format = DIFF_FORMAT_MACHINE;
48 else if (!strcmp(arg, "-R"))
49 diff_setup_opt |= DIFF_SETUP_REVERSE;
50 else if (!strncmp(arg, "-S", 2))
52 else if (!strncmp(arg, "-O", 2))
54 else if (!strncmp(arg, "--diff-filter=", 14))
55 diff_filter = arg + 14;
56 else if (!strcmp(arg, "--pickaxe-all"))
57 pickaxe_opts = DIFF_PICKAXE_ALL;
59 usage(diff_stages_usage);
64 sscanf(av[1], "%d", &stage1) != 1 ||
65 ! (0 <= stage1 && stage1 <= 3) ||
66 sscanf(av[2], "%d", &stage2) != 1 ||
67 ! (0 <= stage2 && stage2 <= 3))
68 usage(diff_stages_usage);
70 av += 3; /* The rest from av[0] are for paths restriction. */
71 diff_setup(diff_setup_opt);
74 while (i < active_nr) {
75 struct cache_entry *ce, *stages[4] = { NULL, };
76 struct cache_entry *one, *two;
83 int stage = ce_stage(ce);
88 if (ce_namelen(ce) != len ||
89 memcmp(name, ce->name, len))
97 diff_addremove('+', ntohl(two->ce_mode),
98 two->sha1, name, NULL);
100 diff_addremove('-', ntohl(one->ce_mode),
101 one->sha1, name, NULL);
102 else if (memcmp(one->sha1, two->sha1, 20) ||
103 (one->ce_mode != two->ce_mode))
104 diff_change(ntohl(one->ce_mode), ntohl(two->ce_mode),
105 one->sha1, two->sha1, name, NULL);
109 detect_rename, diff_score_opt,
110 pickaxe, pickaxe_opts,
114 diff_flush(diff_output_format);