2 * Copyright (C) 2005 Junio C Hamano
9 static int detect_rename
= 0;
10 static int diff_score_opt
= 0;
11 static const char *pickaxe
= NULL
;
12 static int diff_output_style
= DIFF_FORMAT_PATCH
;
13 static int line_termination
= '\n';
14 static int inter_name_termination
= '\t';
16 static int parse_diff_raw(char *buf1
, char *buf2
, char *buf3
)
18 char old_path
[PATH_MAX
];
19 unsigned char old_sha1
[20], new_sha1
[20];
22 int ch
, old_mode
, new_mode
;
24 old_mode
= new_mode
= 0;
25 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
26 old_mode
= (old_mode
<< 3) | (ch
- '0');
31 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
32 new_mode
= (new_mode
<< 3) | (ch
- '0');
37 if (get_sha1_hex(cp
, old_sha1
))
42 if (get_sha1_hex(cp
, new_sha1
))
45 if (*cp
++ != inter_name_termination
)
49 ep
= strchr(cp
, inter_name_termination
);
54 diff_guif(old_mode
, new_mode
, old_sha1
, new_sha1
,
55 old_path
, buf3
? buf3
: ep
);
59 static const char *diff_helper_usage
=
60 "git-diff-helper [-z] [-R] [-M] [-C] [-S<string>] paths...";
62 int main(int ac
, const char **av
) {
63 struct strbuf sb1
, sb2
, sb3
;
70 while (1 < ac
&& av
[1][0] == '-') {
73 else if (av
[1][1] == 'z')
74 line_termination
= inter_name_termination
= 0;
75 else if (av
[1][1] == 'p') /* hidden from the help */
76 diff_output_style
= DIFF_FORMAT_HUMAN
;
77 else if (av
[1][1] == 'P') /* hidden from the help */
78 diff_output_style
= DIFF_FORMAT_MACHINE
;
79 else if (av
[1][1] == 'M') {
80 detect_rename
= DIFF_DETECT_RENAME
;
81 diff_score_opt
= diff_scoreopt_parse(av
[1]);
83 else if (av
[1][1] == 'C') {
84 detect_rename
= DIFF_DETECT_COPY
;
85 diff_score_opt
= diff_scoreopt_parse(av
[1]);
87 else if (av
[1][1] == 'S') {
91 usage(diff_helper_usage
);
94 /* the remaining parameters are paths patterns */
96 diff_setup(reverse_diff
);
99 read_line(&sb1
, stdin
, line_termination
);
102 switch (sb1
.buf
[0]) {
104 diff_unmerge(sb1
.buf
+ 2);
111 if (!line_termination
) {
112 read_line(&sb2
, stdin
, line_termination
);
115 read_line(&sb3
, stdin
, line_termination
);
118 status
= parse_diff_raw(sb1
.buf
+1, sb2
.buf
, sb3
.buf
);
121 status
= parse_diff_raw(sb1
.buf
+1, NULL
, NULL
);
124 diff_flush(diff_output_style
);
125 printf("%s%c", sb1
.buf
, line_termination
);
129 diffcore_rename(detect_rename
, diff_score_opt
);
132 diffcore_pickaxe(pickaxe
);
134 diffcore_pathspec(av
+ 1);
135 diff_flush(diff_output_style
);