{"thread":{"id":"366","subject":"[PATCH] diff-tree-helper: do not report unmerged path outside specification.","startedAt":"2005-04-28T02:22:39Z","lastAt":"2005-04-28T02:22:39Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"1979","messageId":"7vwtqnbpxs.fsf@assigned-by-dhcp.cox.net","threadId":"366","inReplyTo":null,"subject":"[PATCH] diff-tree-helper: do not report unmerged path outside specification.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-04-28T02:22:39Z","receivedAt":"2005-04-28T02:22:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"My bad.  diff-tree-helper reports all unmerged paths even when\nthe command line specifies to filter the paths.  This patch\nfixes it.  Also reverse-diff option was left out during the last\nround, which this patch restores as well.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\ndiff-tree-helper.c |  110 ++++++++++++++++++++++++-----------------------------\n1 files changed, 50 insertions(+), 60 deletions(-)\n\n# - [PATCH] diff-tree -p implies diff-tree -p -r\n# + 04/27 19:18 Fix diff-tree-helper for unmerged path with path specification\n--- k/diff-tree-helper.c\n+++ l/diff-tree-helper.c\n@@ -5,7 +5,7 @@\n #include \"strbuf.h\"\n #include \"diff.h\"\n \n-static int matches_pathspec(const char *name, char **spec, int cnt)\n+static int matches_pathspec(const char *name, const char **spec, int cnt)\n {\n \tint i;\n \tint namelen = strlen(name);\n@@ -44,70 +44,69 @@ static int parse_oneside_change(const ch\n \treturn 0;\n }\n \n-#define PLEASE_WARN -1\n-#define WARNED_OURSELVES -2\n- \n-static int parse_diff_tree_output(const char *buf,\n-\t\t\t\t  struct diff_spec *old,\n-\t\t\t\t  struct diff_spec *new,\n-\t\t\t\t  char *path) {\n+static int parse_diff_tree_output(const char *buf, const char **spec, int cnt)\n+{\n+\tstruct diff_spec old, new;\n+\tchar path[PATH_MAX];\n \tconst char *cp = buf;\n \tint ch;\n \n \tswitch (*cp++) {\n \tcase 'U':\n-\t\tdiff_unmerge(cp + 1);\n-\t\treturn WARNED_OURSELVES;\n+\t\tif (!cnt || matches_pathspec(cp + 1, spec, cnt))\n+\t\t\tdiff_unmerge(cp + 1);\n+\t\treturn 0;\n \tcase '+':\n-\t\told->file_valid = 0;\n-\t\treturn parse_oneside_change(cp, new, path);\n+\t\told.file_valid = 0;\n+\t\tparse_oneside_change(cp, &new, path);\n+\t\tbreak;\n \tcase '-':\n-\t\tnew->file_valid = 0;\n-\t\treturn parse_oneside_change(cp, old, path);\n+\t\tnew.file_valid = 0;\n+\t\tparse_oneside_change(cp, &old, path);\n+\t\tbreak;\n \tcase '*':\n+\t\told.file_valid = old.sha1_valid =\n+\t\t\tnew.file_valid = new.sha1_valid = 1;\n+\t\told.mode = new.mode = 0;\n+\t\twhile ((ch = *cp) && ('0' <= ch && ch <= '7')) {\n+\t\t\told.mode = (old.mode << 3) | (ch - '0');\n+\t\t\tcp++;\n+\t\t}\n+\t\tif (strncmp(cp, \"->\", 2))\n+\t\t\treturn -1;\n+\t\tcp += 2;\n+\t\twhile ((ch = *cp) && ('0' <= ch && ch <= '7')) {\n+\t\t\tnew.mode = (new.mode << 3) | (ch - '0');\n+\t\t\tcp++;\n+\t\t}\n+\t\tif (strncmp(cp, \"\\tblob\\t\", 6))\n+\t\t\treturn -1;\n+\t\tcp += 6;\n+\t\tif (get_sha1_hex(cp, old.u.sha1))\n+\t\t\treturn -1;\n+\t\tcp += 40;\n+\t\tif (strncmp(cp, \"->\", 2))\n+\t\t\treturn -1;\n+\t\tcp += 2;\n+\t\tif (get_sha1_hex(cp, new.u.sha1))\n+\t\t\treturn -1;\n+\t\tcp += 40;\n+\t\tif (*cp++ != '\\t')\n+\t\t\treturn -1;\n+\t\tstrcpy(path, cp);\n \t\tbreak;\n \tdefault:\n-\t\treturn PLEASE_WARN;\n-\t}\n-\t\n-\t/* This is for '*' entries */\n-\told->file_valid = old->sha1_valid = 1;\n-\tnew->file_valid = new->sha1_valid = 1;\n-\n-\told->mode = new->mode = 0;\n-\twhile ((ch = *cp) && ('0' <= ch && ch <= '7')) {\n-\t\told->mode = (old->mode << 3) | (ch - '0');\n-\t\tcp++;\n-\t}\n-\tif (strncmp(cp, \"->\", 2))\n-\t\treturn PLEASE_WARN;\n-\tcp += 2;\n-\twhile ((ch = *cp) && ('0' <= ch && ch <= '7')) {\n-\t\tnew->mode = (new->mode << 3) | (ch - '0');\n-\t\tcp++;\n+\t\treturn -1;\n \t}\n-\tif (strncmp(cp, \"\\tblob\\t\", 6))\n-\t\treturn PLEASE_WARN;\n-\tcp += 6;\n-\tif (get_sha1_hex(cp, old->u.sha1))\n-\t\treturn PLEASE_WARN;\n-\tcp += 40;\n-\tif (strncmp(cp, \"->\", 2))\n-\t\treturn PLEASE_WARN;\n-\tcp += 2;\n-\tif (get_sha1_hex(cp, new->u.sha1))\n-\t\treturn PLEASE_WARN;\n-\tcp += 40;\n-\tif (*cp++ != '\\t')\n-\t\treturn PLEASE_WARN;\n-\tstrcpy(path, cp);\n+\tif (!cnt || matches_pathspec(path, spec, cnt))\n+\t\trun_external_diff(path, &old, &new);\n \treturn 0;\n }\n \n static const char *diff_tree_helper_usage =\n \"diff-tree-helper [-R] [-z] paths...\";\n \n-int main(int ac, char **av) {\n+int main(int ac, const char **av) {\n \tstruct strbuf sb;\n \tint reverse_diff = 0;\n \tint line_termination = '\\n';\n@@ -127,21 +126,12 @@ int main(int ac, char **av) {\n \n \twhile (1) {\n \t\tint status;\n-\t\tstruct diff_spec old, new;\n-\t\tchar path[PATH_MAX];\n \t\tread_line(&sb, stdin, line_termination);\n \t\tif (sb.eof)\n \t\t\tbreak;\n-\t\tstatus = parse_diff_tree_output(sb.buf, &old, &new, path);\n-\t\tif (status) {\n-\t\t\tif (status == PLEASE_WARN)\n-\t\t\t\tfprintf(stderr, \"cannot parse %s\\n\", sb.buf);\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (1 < ac && !matches_pathspec(path, av+1, ac-1))\n-\t\t\tcontinue;\n-\n-\t\trun_external_diff(path, &old, &new);\n+\t\tstatus = parse_diff_tree_output(sb.buf, av+1, ac-1);\n+\t\tif (status)\n+\t\t\tfprintf(stderr, \"cannot parse %s\\n\", sb.buf);\n \t}\n \treturn 0;\n }\n\n"}]}