2 * Copyright (C) 2005 Junio C Hamano
8 static const char *pickaxe
= NULL
;
9 static int pickaxe_opts
= 0;
10 static int line_termination
= '\n';
11 static int inter_name_termination
= '\t';
13 static const char *diff_helper_usage
=
14 "git-diff-helper [-z] [-S<string>] paths...";
16 int main(int ac
, const char **av
) {
18 const char *garbage_flush_format
;
22 while (1 < ac
&& av
[1][0] == '-') {
24 line_termination
= inter_name_termination
= 0;
25 else if (av
[1][1] == 'S') {
28 else if (!strcmp(av
[1], "--pickaxe-all"))
29 pickaxe_opts
= DIFF_PICKAXE_ALL
;
31 usage(diff_helper_usage
);
34 garbage_flush_format
= (line_termination
== 0) ? "%s" : "%s\n";
36 /* the remaining parameters are paths patterns */
40 unsigned old_mode
, new_mode
;
41 unsigned char old_sha1
[20], new_sha1
[20];
42 char old_path
[PATH_MAX
];
43 int status
, score
, two_paths
;
44 char new_path
[PATH_MAX
];
49 read_line(&sb
, stdin
, line_termination
);
54 /* parse the first part up to the status */
56 old_mode
= new_mode
= 0;
57 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
58 old_mode
= (old_mode
<< 3) | (ch
- '0');
63 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
64 new_mode
= (new_mode
<< 3) | (ch
- '0');
69 if (get_sha1_hex(cp
, old_sha1
))
74 if (get_sha1_hex(cp
, new_sha1
))
80 if (!strchr("MCRNDU", status
))
82 two_paths
= score
= 0;
83 if (status
== 'R' || status
== 'C') {
85 sscanf(cp
, "%d", &score
);
86 if (line_termination
) {
88 inter_name_termination
);
94 if (*cp
++ != inter_name_termination
)
98 if (!line_termination
) {
99 read_line(&sb
, stdin
, line_termination
);
102 strcpy(old_path
, sb
.buf
);
105 strcpy(old_path
, cp
);
107 ep
= strchr(cp
, inter_name_termination
);
110 strncpy(old_path
, cp
, ep
-cp
);
115 /* second pathname */
117 strcpy(new_path
, old_path
);
119 if (!line_termination
) {
120 read_line(&sb
, stdin
,
124 strcpy(new_path
, sb
.buf
);
127 strcpy(new_path
, cp
);
129 diff_helper_input(old_mode
, new_mode
,
131 old_path
, status
, score
,
136 diffcore_pathspec(av
+ 1);
138 diffcore_pickaxe(pickaxe
, pickaxe_opts
);
139 diff_flush(DIFF_FORMAT_PATCH
, 0);
140 printf(garbage_flush_format
, sb
.buf
);
143 diffcore_pathspec(av
+ 1);
145 diffcore_pickaxe(pickaxe
, pickaxe_opts
);
146 diff_flush(DIFF_FORMAT_PATCH
, 0);