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 static void diff_stages(int stage1, int stage2)
24 while (i < active_nr) {
25 struct cache_entry *ce, *stages[4] = { NULL, };
26 struct cache_entry *one, *two;
33 int stage = ce_stage(ce);
38 if (ce_namelen(ce) != len ||
39 memcmp(name, ce->name, len))
47 diff_addremove('+', ntohl(two->ce_mode),
48 two->sha1, name, NULL);
50 diff_addremove('-', ntohl(one->ce_mode),
51 one->sha1, name, NULL);
52 else if (memcmp(one->sha1, two->sha1, 20) ||
53 (one->ce_mode != two->ce_mode))
54 diff_change(ntohl(one->ce_mode), ntohl(two->ce_mode),
55 one->sha1, two->sha1, name, NULL);
59 int main(int ac, const char **av)
64 while (1 < ac && av[1][0] == '-') {
65 const char *arg = av[1];
66 if (!strcmp(arg, "-r"))
68 else if (!strcmp(arg, "-p"))
69 diff_output_format = DIFF_FORMAT_PATCH;
70 else if (!strncmp(arg, "-B", 2)) {
71 if ((diff_break_opt = diff_scoreopt_parse(arg)) == -1)
72 usage(diff_stages_usage);
74 else if (!strncmp(arg, "-M", 2)) {
75 detect_rename = DIFF_DETECT_RENAME;
76 if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
77 usage(diff_stages_usage);
79 else if (!strncmp(arg, "-C", 2)) {
80 detect_rename = DIFF_DETECT_COPY;
81 if ((diff_score_opt = diff_scoreopt_parse(arg)) == -1)
82 usage(diff_stages_usage);
84 else if (!strcmp(arg, "-z"))
85 diff_output_format = DIFF_FORMAT_MACHINE;
86 else if (!strcmp(arg, "-R"))
87 diff_setup_opt |= DIFF_SETUP_REVERSE;
88 else if (!strncmp(arg, "-S", 2))
90 else if (!strncmp(arg, "-O", 2))
92 else if (!strncmp(arg, "--diff-filter=", 14))
93 diff_filter = arg + 14;
94 else if (!strcmp(arg, "--pickaxe-all"))
95 pickaxe_opts = DIFF_PICKAXE_ALL;
97 usage(diff_stages_usage);
102 sscanf(av[1], "%d", &stage1) != 1 ||
103 ! (0 <= stage1 && stage1 <= 3) ||
104 sscanf(av[2], "%d", &stage2) != 1 ||
105 ! (0 <= stage2 && stage2 <= 3))
106 usage(diff_stages_usage);
108 av += 3; /* The rest from av[0] are for paths restriction. */
109 diff_setup(diff_setup_opt);
111 diff_stages(stage1, stage2);
114 detect_rename, diff_score_opt,
115 pickaxe, pickaxe_opts,
119 diff_flush(diff_output_format);