2 * Copyright (C) 2005 Junio C Hamano
9 static int detect_rename
= 0;
10 static int diff_score_opt
= 0;
11 static int generate_patch
= 1;
12 static const char *pickaxe
= NULL
;
14 static int parse_oneside_change(const char *cp
, int *mode
,
15 unsigned char *sha1
, char *path
)
20 while ((ch
= *cp
) && '0' <= ch
&& ch
<= '7') {
21 m
= (m
<< 3) | (ch
- '0');
25 if (strncmp(cp
, "\tblob\t", 6) && strncmp(cp
, " blob ", 6) &&
26 strncmp(cp
, "\ttree\t", 6) && strncmp(cp
, " tree ", 6))
29 if (get_sha1_hex(cp
, sha1
))
32 if ((*cp
!= '\t') && *cp
!= ' ')
38 static int parse_diff_raw_output(const char *buf
)
41 unsigned char old_sha1
[20], new_sha1
[20];
43 int ch
, old_mode
, new_mode
;
50 if (parse_oneside_change(cp
, &new_mode
, new_sha1
, path
))
52 diff_addremove('+', new_mode
, new_sha1
, path
, NULL
);
55 if (parse_oneside_change(cp
, &old_mode
, old_sha1
, path
))
57 diff_addremove('-', old_mode
, old_sha1
, path
, NULL
);
60 old_mode
= new_mode
= 0;
61 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
62 old_mode
= (old_mode
<< 3) | (ch
- '0');
65 if (strncmp(cp
, "->", 2))
68 while ((ch
= *cp
) && ('0' <= ch
&& ch
<= '7')) {
69 new_mode
= (new_mode
<< 3) | (ch
- '0');
72 if (strncmp(cp
, "\tblob\t", 6) && strncmp(cp
, " blob ", 6) &&
73 strncmp(cp
, "\ttree\t", 6) && strncmp(cp
, " tree ", 6))
76 if (get_sha1_hex(cp
, old_sha1
))
79 if (strncmp(cp
, "->", 2))
82 if (get_sha1_hex(cp
, new_sha1
))
85 if ((*cp
!= '\t') && *cp
!= ' ')
88 diff_change(old_mode
, new_mode
, old_sha1
, new_sha1
, path
, NULL
);
96 static const char *diff_helper_usage
=
97 "git-diff-helper [-z] [-R] [-M] [-C] [-S<string>] paths...";
99 int main(int ac
, const char **av
) {
102 int line_termination
= '\n';
106 while (1 < ac
&& av
[1][0] == '-') {
109 else if (av
[1][1] == 'z')
110 line_termination
= 0;
111 else if (av
[1][1] == 'p') /* hidden from the help */
113 else if (av
[1][1] == 'M') {
115 diff_score_opt
= diff_scoreopt_parse(av
[1]);
117 else if (av
[1][1] == 'C') {
119 diff_score_opt
= diff_scoreopt_parse(av
[1]);
121 else if (av
[1][1] == 'S') {
125 usage(diff_helper_usage
);
128 /* the remaining parameters are paths patterns */
130 diff_setup(detect_rename
, diff_score_opt
, pickaxe
,
131 reverse
, (generate_patch
? -1 : line_termination
),
136 read_line(&sb
, stdin
, line_termination
);
139 status
= parse_diff_raw_output(sb
.buf
);
142 printf("%s%c", sb
.buf
, line_termination
);