2 * Copyright (C) 2005 Junio C Hamano
8 static const char *pickaxe
= NULL
;
9 static int pickaxe_opts
= 0;
10 static const char *orderfile
= NULL
;
11 static const char *diff_filter
= NULL
;
12 static int line_termination
= '\n';
13 static int inter_name_termination
= '\t';
15 static void flush_them(int ac
, const char **av
)
17 diffcore_std_no_resolve(av
+ 1,
18 pickaxe
, pickaxe_opts
,
19 orderfile
, diff_filter
);
20 diff_flush(DIFF_FORMAT_PATCH
, '\n');
23 static const char diff_helper_usage
[] =
24 "git-diff-helper [-z] [-O<orderfile>] [-S<string>] [--pickaxe-all] [<path>...]";
26 int main(int ac
, const char **av
) {
28 const char *garbage_flush_format
;
32 while (1 < ac
&& av
[1][0] == '-') {
34 line_termination
= inter_name_termination
= 0;
35 else if (av
[1][1] == 'S') {
38 else if (!strcmp(av
[1], "--pickaxe-all"))
39 pickaxe_opts
= DIFF_PICKAXE_ALL
;
40 else if (!strncmp(av
[1], "--diff-filter=", 14))
41 diff_filter
= av
[1] + 14;
42 else if (!strncmp(av
[1], "-O", 2))
43 orderfile
= av
[1] + 2;
45 usage(diff_helper_usage
);
48 garbage_flush_format
= (line_termination
== 0) ? "%s" : "%s\n";
50 /* the remaining parameters are paths patterns */
54 unsigned old_mode
, new_mode
;
55 unsigned char old_sha1
[20], new_sha1
[20];
56 char old_path
[PATH_MAX
];
57 int status
, score
, two_paths
;
58 char new_path
[PATH_MAX
];
63 read_line(&sb
, stdin
, line_termination
);
68 /* parse the first part up to the status */
70 old_mode
= new_mode
= 0;
71 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
72 old_mode
= (old_mode
<< 3) | (ch
- '0');
77 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
78 new_mode
= (new_mode
<< 3) | (ch
- '0');
83 if (get_sha1_hex(cp
, old_sha1
))
88 if (get_sha1_hex(cp
, new_sha1
))
94 if (!strchr("MCRNDU", status
))
96 two_paths
= score
= 0;
97 if (status
== DIFF_STATUS_RENAMED
||
98 status
== DIFF_STATUS_COPIED
)
101 /* pick up score if exists */
102 if (sscanf(cp
, "%d", &score
) != 1)
105 inter_name_termination
);
108 if (*cp
++ != inter_name_termination
)
112 if (!line_termination
) {
113 read_line(&sb
, stdin
, line_termination
);
116 strcpy(old_path
, sb
.buf
);
119 strcpy(old_path
, cp
);
121 ep
= strchr(cp
, inter_name_termination
);
124 strncpy(old_path
, cp
, ep
-cp
);
129 /* second pathname */
131 strcpy(new_path
, old_path
);
133 if (!line_termination
) {
134 read_line(&sb
, stdin
,
138 strcpy(new_path
, sb
.buf
);
141 strcpy(new_path
, cp
);
143 diff_helper_input(old_mode
, new_mode
,
145 old_path
, status
, score
,
150 printf(garbage_flush_format
, sb
.buf
);