2 * Copyright (C) 2005 Junio C Hamano
8 static int detect_rename
= 0;
9 static int diff_score_opt
= 0;
10 static const char *pickaxe
= NULL
;
11 static int diff_output_style
= DIFF_FORMAT_PATCH
;
12 static int line_termination
= '\n';
13 static int inter_name_termination
= '\t';
15 static int parse_diff_raw(char *buf1
, char *buf2
, char *buf3
)
17 char old_path
[PATH_MAX
];
18 unsigned char old_sha1
[20], new_sha1
[20];
21 int ch
, old_mode
, new_mode
;
23 old_mode
= new_mode
= 0;
24 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
25 old_mode
= (old_mode
<< 3) | (ch
- '0');
30 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
31 new_mode
= (new_mode
<< 3) | (ch
- '0');
36 if (get_sha1_hex(cp
, old_sha1
))
41 if (get_sha1_hex(cp
, new_sha1
))
44 if (*cp
++ != inter_name_termination
)
48 ep
= strchr(cp
, inter_name_termination
);
53 diff_guif(old_mode
, new_mode
, old_sha1
, new_sha1
,
54 old_path
, buf3
? buf3
: ep
);
58 static const char *diff_helper_usage
=
59 "git-diff-helper [-z] [-R] [-M] [-C] [-S<string>] paths...";
61 int main(int ac
, const char **av
) {
62 struct strbuf sb1
, sb2
, sb3
;
69 while (1 < ac
&& av
[1][0] == '-') {
72 else if (av
[1][1] == 'z')
73 line_termination
= inter_name_termination
= 0;
74 else if (av
[1][1] == 'p') /* hidden from the help */
75 diff_output_style
= DIFF_FORMAT_HUMAN
;
76 else if (av
[1][1] == 'P') /* hidden from the help */
77 diff_output_style
= DIFF_FORMAT_MACHINE
;
78 else if (av
[1][1] == 'M') {
79 detect_rename
= DIFF_DETECT_RENAME
;
80 diff_score_opt
= diff_scoreopt_parse(av
[1]);
82 else if (av
[1][1] == 'C') {
83 detect_rename
= DIFF_DETECT_COPY
;
84 diff_score_opt
= diff_scoreopt_parse(av
[1]);
86 else if (av
[1][1] == 'S') {
90 usage(diff_helper_usage
);
93 /* the remaining parameters are paths patterns */
95 diff_setup(reverse_diff
);
98 read_line(&sb1
, stdin
, line_termination
);
101 switch (sb1
.buf
[0]) {
103 diff_unmerge(sb1
.buf
+ 2);
110 if (!line_termination
) {
111 read_line(&sb2
, stdin
, line_termination
);
114 read_line(&sb3
, stdin
, line_termination
);
117 status
= parse_diff_raw(sb1
.buf
+1, sb2
.buf
, sb3
.buf
);
120 status
= parse_diff_raw(sb1
.buf
+1, NULL
, NULL
);
123 diff_flush(diff_output_style
);
124 printf("%s\n", sb1
.buf
);
128 diffcore_rename(detect_rename
, diff_score_opt
);
131 diffcore_pickaxe(pickaxe
);
133 diffcore_pathspec(av
+ 1);
134 diff_flush(diff_output_style
);