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 static int parse_diff_tree_output(const char *buf,
48 struct diff_spec *old,
49 struct diff_spec *new,
57 return parse_oneside_change(cp, new, path);
60 return parse_oneside_change(cp, old, path);
67 /* This is for '*' entries */
68 old->file_valid = old->sha1_valid = 1;
69 new->file_valid = new->sha1_valid = 1;
71 old->mode = new->mode = 0;
72 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
73 old->mode = (old->mode << 3) | (ch - '0');
76 if (strncmp(cp, "->", 2))
79 while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
80 new->mode = (new->mode << 3) | (ch - '0');
83 if (strncmp(cp, "\tblob\t", 6))
86 if (get_sha1_hex(cp, old->u.sha1))
89 if (strncmp(cp, "->", 2))
92 if (get_sha1_hex(cp, new->u.sha1))
101 static const char *diff_tree_helper_usage =
102 "diff-tree-helper [-R] [-z] paths...";
104 int main(int ac, char **av) {
106 int reverse_diff = 0;
107 int line_termination = '\n';
111 while (1 < ac && av[1][0] == '-') {
114 else if (av[1][1] == 'z')
115 line_termination = 0;
117 usage(diff_tree_helper_usage);
120 /* the remaining parameters are paths patterns */
123 struct diff_spec old, new;
125 read_line(&sb, stdin, line_termination);
128 if (parse_diff_tree_output(sb.buf, &old, &new, path)) {
129 fprintf(stderr, "cannot parse %s\n", sb.buf);
132 if (1 < ac && !matches_pathspec(path, av+1, ac-1))
135 run_external_diff(path, &old, &new);