2 * Copyright (C) 2005 Junio C Hamano
8 static int matches_pathspec(const char *name, char **spec, int cnt)
11 int namelen = strlen(name);
12 for (i = 0; i < cnt; i++) {
13 int speclen = strlen(spec[i]);
14 if (! strncmp(spec[i], name, speclen) &&
16 (name[speclen] == 0 ||
17 name[speclen] == '/'))
23 static int parse_oneside_change(const char *cp, struct diff_spec *one,
28 one->file_valid = one->sha1_valid = 1;
30 while ((ch = *cp) && '0' <= ch && ch <= '7') {
31 one->mode = (one->mode << 3) | (ch - '0');
35 if (strncmp(cp, "\tblob\t", 6))
38 if (get_sha1_hex(cp, one->u.sha1))
47 #define PLEASE_WARN -1
48 #define WARNED_OURSELVES -2
50 static int parse_diff_tree_output(const char *buf,
51 struct diff_spec *old,
52 struct diff_spec *new,
60 return WARNED_OURSELVES;
63 return parse_oneside_change(cp, new, path);
66 return parse_oneside_change(cp, old, path);
73 /* This is for '*' entries */
74 old->file_valid = old->sha1_valid = 1;
75 new->file_valid = new->sha1_valid = 1;
77 old->mode = new->mode = 0;
78 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
79 old->mode = (old->mode << 3) | (ch - '0');
82 if (strncmp(cp, "->", 2))
85 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
86 new->mode = (new->mode << 3) | (ch - '0');
89 if (strncmp(cp, "\tblob\t", 6))
92 if (get_sha1_hex(cp, old->u.sha1))
95 if (strncmp(cp, "->", 2))
98 if (get_sha1_hex(cp, new->u.sha1))
107 static const char *diff_tree_helper_usage =
108 "diff-tree-helper [-R] [-z] paths...";
110 int main(int ac, char **av) {
112 int reverse_diff = 0;
113 int line_termination = '\n';
117 while (1 < ac && av[1][0] == '-') {
120 else if (av[1][1] == 'z')
121 line_termination = 0;
123 usage(diff_tree_helper_usage);
126 /* the remaining parameters are paths patterns */
130 struct diff_spec old, new;
132 read_line(&sb, stdin, line_termination);
135 status = parse_diff_tree_output(sb.buf, &old, &new, path);
137 if (status == PLEASE_WARN)
138 fprintf(stderr, "cannot parse %s\n", sb.buf);
141 if (1 < ac && !matches_pathspec(path, av+1, ac-1))
144 run_external_diff(path, &old, &new);