[PATCH] diff-tree-helper: do not report unmerged path outside specification.

My bad.  diff-tree-helper reports all unmerged paths even when
the command line specifies to filter the paths.  This patch
fixes it.  Also reverse-diff option was left out during the last
round, which this patch restores as well.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Junio C Hamano
2005-04-28 10:13:01 -07:00
committed by Linus Torvalds
parent 2f97813870
commit 91a6eaa05d

View File

@ -5,7 +5,7 @@
#include "strbuf.h" #include "strbuf.h"
#include "diff.h" #include "diff.h"
static int matches_pathspec(const char *name, char **spec, int cnt) static int matches_pathspec(const char *name, const char **spec, int cnt)
{ {
int i; int i;
int namelen = strlen(name); int namelen = strlen(name);
@ -44,70 +44,69 @@ static int parse_oneside_change(const char *cp, struct diff_spec *one,
return 0; return 0;
} }
#define PLEASE_WARN -1 static int parse_diff_tree_output(const char *buf, const char **spec, int cnt)
#define WARNED_OURSELVES -2 {
struct diff_spec old, new;
static int parse_diff_tree_output(const char *buf, char path[PATH_MAX];
struct diff_spec *old,
struct diff_spec *new,
char *path) {
const char *cp = buf; const char *cp = buf;
int ch; int ch;
switch (*cp++) { switch (*cp++) {
case 'U': case 'U':
if (!cnt || matches_pathspec(cp + 1, spec, cnt))
diff_unmerge(cp + 1); diff_unmerge(cp + 1);
return WARNED_OURSELVES; return 0;
case '+': case '+':
old->file_valid = 0; old.file_valid = 0;
return parse_oneside_change(cp, new, path); parse_oneside_change(cp, &new, path);
case '-':
new->file_valid = 0;
return parse_oneside_change(cp, old, path);
case '*':
break; break;
default: case '-':
return PLEASE_WARN; new.file_valid = 0;
} parse_oneside_change(cp, &old, path);
break;
/* This is for '*' entries */ case '*':
old->file_valid = old->sha1_valid = 1; old.file_valid = old.sha1_valid =
new->file_valid = new->sha1_valid = 1; new.file_valid = new.sha1_valid = 1;
old.mode = new.mode = 0;
old->mode = new->mode = 0;
while ((ch = *cp) && ('0' <= ch && ch <= '7')) { while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
old->mode = (old->mode << 3) | (ch - '0'); old.mode = (old.mode << 3) | (ch - '0');
cp++; cp++;
} }
if (strncmp(cp, "->", 2)) if (strncmp(cp, "->", 2))
return PLEASE_WARN; return -1;
cp += 2; cp += 2;
while ((ch = *cp) && ('0' <= ch && ch <= '7')) { while ((ch = *cp) && ('0' <= ch && ch <= '7')) {
new->mode = (new->mode << 3) | (ch - '0'); new.mode = (new.mode << 3) | (ch - '0');
cp++; cp++;
} }
if (strncmp(cp, "\tblob\t", 6)) if (strncmp(cp, "\tblob\t", 6))
return PLEASE_WARN; return -1;
cp += 6; cp += 6;
if (get_sha1_hex(cp, old->u.sha1)) if (get_sha1_hex(cp, old.u.sha1))
return PLEASE_WARN; return -1;
cp += 40; cp += 40;
if (strncmp(cp, "->", 2)) if (strncmp(cp, "->", 2))
return PLEASE_WARN; return -1;
cp += 2; cp += 2;
if (get_sha1_hex(cp, new->u.sha1)) if (get_sha1_hex(cp, new.u.sha1))
return PLEASE_WARN; return -1;
cp += 40; cp += 40;
if (*cp++ != '\t') if (*cp++ != '\t')
return PLEASE_WARN; return -1;
strcpy(path, cp); strcpy(path, cp);
break;
default:
return -1;
}
if (!cnt || matches_pathspec(path, spec, cnt))
run_external_diff(path, &old, &new);
return 0; return 0;
} }
static const char *diff_tree_helper_usage = static const char *diff_tree_helper_usage =
"diff-tree-helper [-R] [-z] paths..."; "diff-tree-helper [-R] [-z] paths...";
int main(int ac, char **av) { int main(int ac, const char **av) {
struct strbuf sb; struct strbuf sb;
int reverse_diff = 0; int reverse_diff = 0;
int line_termination = '\n'; int line_termination = '\n';
@ -127,21 +126,12 @@ int main(int ac, char **av) {
while (1) { while (1) {
int status; int status;
struct diff_spec old, new;
char path[PATH_MAX];
read_line(&sb, stdin, line_termination); read_line(&sb, stdin, line_termination);
if (sb.eof) if (sb.eof)
break; break;
status = parse_diff_tree_output(sb.buf, &old, &new, path); status = parse_diff_tree_output(sb.buf, av+1, ac-1);
if (status) { if (status)
if (status == PLEASE_WARN)
fprintf(stderr, "cannot parse %s\n", sb.buf); fprintf(stderr, "cannot parse %s\n", sb.buf);
continue;
}
if (1 < ac && !matches_pathspec(path, av+1, ac-1))
continue;
run_external_diff(path, &old, &new);
} }
return 0; return 0;
} }