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 find_copies_harder
= 0;
11 static int diff_setup_opt
= 0;
12 static int diff_score_opt
= 0;
13 static const char *pickaxe
= NULL
;
14 static int pickaxe_opts
= 0;
15 static int diff_break_opt
= -1;
16 static const char *orderfile
= NULL
;
17 static const char *diff_filter
= NULL
;
19 static char *diff_stages_usage
=
20 "git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]"
21 COMMON_DIFF_OPTIONS_HELP
;
23 static void diff_stages(int stage1
, int stage2
)
26 while (i
< active_nr
) {
27 struct cache_entry
*ce
, *stages
[4] = { NULL
, };
28 struct cache_entry
*one
, *two
;
35 int stage
= ce_stage(ce
);
40 if (ce_namelen(ce
) != len
||
41 memcmp(name
, ce
->name
, len
))
49 diff_addremove('+', ntohl(two
->ce_mode
),
50 two
->sha1
, name
, NULL
);
52 diff_addremove('-', ntohl(one
->ce_mode
),
53 one
->sha1
, name
, NULL
);
54 else if (memcmp(one
->sha1
, two
->sha1
, 20) ||
55 (one
->ce_mode
!= two
->ce_mode
) ||
57 diff_change(ntohl(one
->ce_mode
), ntohl(two
->ce_mode
),
58 one
->sha1
, two
->sha1
, name
, NULL
);
62 int main(int ac
, const char **av
)
67 while (1 < ac
&& av
[1][0] == '-') {
68 const char *arg
= av
[1];
69 if (!strcmp(arg
, "-r"))
71 else if (!strcmp(arg
, "-p") || !strcmp(arg
, "-u"))
72 diff_output_format
= DIFF_FORMAT_PATCH
;
73 else if (!strncmp(arg
, "-B", 2)) {
74 if ((diff_break_opt
= diff_scoreopt_parse(arg
)) == -1)
75 usage(diff_stages_usage
);
77 else if (!strncmp(arg
, "-M", 2)) {
78 detect_rename
= DIFF_DETECT_RENAME
;
79 if ((diff_score_opt
= diff_scoreopt_parse(arg
)) == -1)
80 usage(diff_stages_usage
);
82 else if (!strncmp(arg
, "-C", 2)) {
83 detect_rename
= DIFF_DETECT_COPY
;
84 if ((diff_score_opt
= diff_scoreopt_parse(arg
)) == -1)
85 usage(diff_stages_usage
);
87 else if (!strcmp(arg
, "--find-copies-harder"))
88 find_copies_harder
= 1;
89 else if (!strcmp(arg
, "-z"))
90 diff_output_format
= DIFF_FORMAT_MACHINE
;
91 else if (!strcmp(arg
, "--name-only"))
92 diff_output_format
= DIFF_FORMAT_NAME
;
93 else if (!strcmp(arg
, "--name-only-z"))
94 diff_output_format
= DIFF_FORMAT_NAME_Z
;
95 else if (!strcmp(arg
, "-R"))
96 diff_setup_opt
|= DIFF_SETUP_REVERSE
;
97 else if (!strncmp(arg
, "-S", 2))
99 else if (!strncmp(arg
, "-O", 2))
101 else if (!strncmp(arg
, "--diff-filter=", 14))
102 diff_filter
= arg
+ 14;
103 else if (!strcmp(arg
, "--pickaxe-all"))
104 pickaxe_opts
= DIFF_PICKAXE_ALL
;
106 usage(diff_stages_usage
);
111 sscanf(av
[1], "%d", &stage1
) != 1 ||
112 ! (0 <= stage1
&& stage1
<= 3) ||
113 sscanf(av
[2], "%d", &stage2
) != 1 ||
114 ! (0 <= stage2
&& stage2
<= 3) ||
115 (find_copies_harder
&& detect_rename
!= DIFF_DETECT_COPY
))
116 usage(diff_stages_usage
);
118 av
+= 3; /* The rest from av[0] are for paths restriction. */
119 diff_setup(diff_setup_opt
);
121 diff_stages(stage1
, stage2
);
124 detect_rename
, diff_score_opt
,
125 pickaxe
, pickaxe_opts
,
129 diff_flush(diff_output_format
);