{"thread":{"id":"608","subject":"[PATCH 2/3] Rename git-diff-tree-helper to git-diff-helper.","startedAt":"2005-05-14T01:40:54Z","lastAt":"2005-05-14T01:40:54Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"3275","messageId":"7vekca60ux.fsf@assigned-by-dhcp.cox.net","threadId":"608","inReplyTo":null,"subject":"[PATCH 2/3] Rename git-diff-tree-helper to git-diff-helper.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-14T01:40:54Z","receivedAt":"2005-05-14T01:40:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"It used to be that diff-tree needed helper support to parse its\nraw output to generate diffs, but these days git-diff-* family\nproduces the same output and the helper is not tied to diff-tree\nanymore.  Drop \"tree\" from its name.\n\nThis commit is done separately to record just the rename and no\nfile content changes.  Makefiles and documentation needs to be\nadjusted, which is done in the next commit.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\nDocumentation/git-diff-helper.txt      |   49 +++++++++++\nDocumentation/git-diff-tree-helper.txt |   49 -----------\ndiff-helper.c                          |  143 +++++++++++++++++++++++++++++++++\ndiff-tree-helper.c                     |  143 ---------------------------------\n4 files changed, 192 insertions(+), 192 deletions(-)\nDocumentation/git-diff-helper.txt (. --> 100644)\nDocumentation/git-diff-tree-helper.txt (100644 --> .)\ndiff-helper.c (. --> 100644)\ndiff-tree-helper.c (100644 --> .)\n\n--- a/Documentation/git-diff-helper.txt\n+++ b/Documentation/git-diff-helper.txt\n@@ -0,0 +1,49 @@\n+git-diff-tree-helper(1)\n+=======================\n+v0.1, May 2005\n+\n+NAME\n+----\n+git-diff-tree-helper - Generates patch format output for git-diff-*\n+\n+\n+SYNOPSIS\n+--------\n+'git-diff-tree-helper' [-z] [-R]\n+\n+DESCRIPTION\n+-----------\n+Reads output from \"git-diff-cache\", \"git-diff-tree\" and \"git-diff-files\" and\n+generates patch format output.\n+\n+OPTIONS\n+-------\n+-z::\n+\t\\0 line termination on input\n+\n+-R::\n+\tOutput diff in reverse.  This is useful for displaying output from\n+\t\"git-diff-cache\" which always compares tree with cache or working\n+\tfile.  E.g.\n+\n+\t\tgit-diff-cache <tree> | git-diff-tree-helper -R file.c\n++\n+would show a diff to bring the working file back to what is in the <tree>.\n+\n+See Also\n+--------\n+The section on generating patches in link:git-diff-cache.html[git-diff-cache]\n+\n+\n+Author\n+------\n+Written by Linus Torvalds <torvalds@osdl.org>\n+\n+Documentation\n+--------------\n+Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.\n+\n+GIT\n+---\n+Part of the link:git.html[git] suite\n+\n--- a/Documentation/git-diff-tree-helper.txt\n+++ b/Documentation/git-diff-tree-helper.txt\n@@ -1,49 +0,0 @@\n-git-diff-tree-helper(1)\n-=======================\n-v0.1, May 2005\n-\n-NAME\n-----\n-git-diff-tree-helper - Generates patch format output for git-diff-*\n-\n-\n-SYNOPSIS\n---------\n-'git-diff-tree-helper' [-z] [-R]\n-\n-DESCRIPTION\n------------\n-Reads output from \"git-diff-cache\", \"git-diff-tree\" and \"git-diff-files\" and\n-generates patch format output.\n-\n-OPTIONS\n--------\n--z::\n-\t\\0 line termination on input\n-\n--R::\n-\tOutput diff in reverse.  This is useful for displaying output from\n-\t\"git-diff-cache\" which always compares tree with cache or working\n-\tfile.  E.g.\n-\n-\t\tgit-diff-cache <tree> | git-diff-tree-helper -R file.c\n-+\n-would show a diff to bring the working file back to what is in the <tree>.\n-\n-See Also\n---------\n-The section on generating patches in link:git-diff-cache.html[git-diff-cache]\n-\n-\n-Author\n-------\n-Written by Linus Torvalds <torvalds@osdl.org>\n-\n-Documentation\n---------------\n-Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.\n-\n-GIT\n----\n-Part of the link:git.html[git] suite\n-\n--- a/diff-helper.c\n+++ b/diff-helper.c\n@@ -0,0 +1,143 @@\n+/*\n+ * Copyright (C) 2005 Junio C Hamano\n+ */\n+#include <limits.h>\n+#include \"cache.h\"\n+#include \"strbuf.h\"\n+#include \"diff.h\"\n+\n+static int matches_pathspec(const char *name, const char **spec, int cnt)\n+{\n+\tint i;\n+\tint namelen = strlen(name);\n+\tfor (i = 0; i < cnt; i++) {\n+\t\tint speclen = strlen(spec[i]);\n+\t\tif (! strncmp(spec[i], name, speclen) &&\n+\t\t    speclen <= namelen &&\n+\t\t    (name[speclen] == 0 ||\n+\t\t     name[speclen] == '/'))\n+\t\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+static int parse_oneside_change(const char *cp, struct diff_spec *one,\n+\t\t\t\tchar *path)\n+{\n+\tint ch;\n+\n+\tone->file_valid = one->sha1_valid = 1;\n+\tone->mode = 0;\n+\twhile ((ch = *cp) && '0' <= ch && ch <= '7') {\n+\t\tone->mode = (one->mode << 3) | (ch - '0');\n+\t\tcp++;\n+\t}\n+\n+\tif (strncmp(cp, \"\\tblob\\t\", 6))\n+\t\treturn -1;\n+\tcp += 6;\n+\tif (get_sha1_hex(cp, one->blob_sha1))\n+\t\treturn -1;\n+\tcp += 40;\n+\tif (*cp++ != '\\t')\n+\t\treturn -1;\n+\tstrcpy(path, cp);\n+\treturn 0;\n+}\n+\n+static int parse_diff_tree_output(const char *buf,\n+\t\t\t\t  const char **spec, int cnt, int reverse)\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\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\tparse_oneside_change(cp, &new, path);\n+\t\tbreak;\n+\tcase '-':\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.blob_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.blob_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 -1;\n+\t}\n+\tif (!cnt || matches_pathspec(path, spec, cnt)) {\n+\t\tif (reverse)\n+\t\t\trun_external_diff(path, &new, &old);\n+\t\telse\n+\t\t\trun_external_diff(path, &old, &new);\n+\t}\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, const char **av) {\n+\tstruct strbuf sb;\n+\tint reverse = 0;\n+\tint line_termination = '\\n';\n+\n+\tstrbuf_init(&sb);\n+\n+\twhile (1 < ac && av[1][0] == '-') {\n+\t\tif (av[1][1] == 'R')\n+\t\t\treverse = 1;\n+\t\telse if (av[1][1] == 'z')\n+\t\t\tline_termination = 0;\n+\t\telse\n+\t\t\tusage(diff_tree_helper_usage);\n+\t\tac--; av++;\n+\t}\n+\t/* the remaining parameters are paths patterns */\n+\n+\twhile (1) {\n+\t\tint status;\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, av+1, ac-1, reverse);\n+\t\tif (status)\n+\t\t\tfprintf(stderr, \"cannot parse %s\\n\", sb.buf);\n+\t}\n+\treturn 0;\n+}\n--- a/diff-tree-helper.c\n+++ b/diff-tree-helper.c\n@@ -1,143 +0,0 @@\n-/*\n- * Copyright (C) 2005 Junio C Hamano\n- */\n-#include <limits.h>\n-#include \"cache.h\"\n-#include \"strbuf.h\"\n-#include \"diff.h\"\n-\n-static int matches_pathspec(const char *name, const char **spec, int cnt)\n-{\n-\tint i;\n-\tint namelen = strlen(name);\n-\tfor (i = 0; i < cnt; i++) {\n-\t\tint speclen = strlen(spec[i]);\n-\t\tif (! strncmp(spec[i], name, speclen) &&\n-\t\t    speclen <= namelen &&\n-\t\t    (name[speclen] == 0 ||\n-\t\t     name[speclen] == '/'))\n-\t\t\treturn 1;\n-\t}\n-\treturn 0;\n-}\n-\n-static int parse_oneside_change(const char *cp, struct diff_spec *one,\n-\t\t\t\tchar *path)\n-{\n-\tint ch;\n-\n-\tone->file_valid = one->sha1_valid = 1;\n-\tone->mode = 0;\n-\twhile ((ch = *cp) && '0' <= ch && ch <= '7') {\n-\t\tone->mode = (one->mode << 3) | (ch - '0');\n-\t\tcp++;\n-\t}\n-\n-\tif (strncmp(cp, \"\\tblob\\t\", 6))\n-\t\treturn -1;\n-\tcp += 6;\n-\tif (get_sha1_hex(cp, one->blob_sha1))\n-\t\treturn -1;\n-\tcp += 40;\n-\tif (*cp++ != '\\t')\n-\t\treturn -1;\n-\tstrcpy(path, cp);\n-\treturn 0;\n-}\n-\n-static int parse_diff_tree_output(const char *buf,\n-\t\t\t\t  const char **spec, int cnt, int reverse)\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\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\tparse_oneside_change(cp, &new, path);\n-\t\tbreak;\n-\tcase '-':\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.blob_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.blob_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 -1;\n-\t}\n-\tif (!cnt || matches_pathspec(path, spec, cnt)) {\n-\t\tif (reverse)\n-\t\t\trun_external_diff(path, &new, &old);\n-\t\telse\n-\t\t\trun_external_diff(path, &old, &new);\n-\t}\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, const char **av) {\n-\tstruct strbuf sb;\n-\tint reverse = 0;\n-\tint line_termination = '\\n';\n-\n-\tstrbuf_init(&sb);\n-\n-\twhile (1 < ac && av[1][0] == '-') {\n-\t\tif (av[1][1] == 'R')\n-\t\t\treverse = 1;\n-\t\telse if (av[1][1] == 'z')\n-\t\t\tline_termination = 0;\n-\t\telse\n-\t\t\tusage(diff_tree_helper_usage);\n-\t\tac--; av++;\n-\t}\n-\t/* the remaining parameters are paths patterns */\n-\n-\twhile (1) {\n-\t\tint status;\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, av+1, ac-1, reverse);\n-\t\tif (status)\n-\t\t\tfprintf(stderr, \"cannot parse %s\\n\", sb.buf);\n-\t}\n-\treturn 0;\n-}\n\n"}]}