{"thread":{"id":"14921","subject":"[PATCH v3 4/4] Add test for diff-tree --stdin with two trees","startedAt":"2008-08-10T16:12:39Z","lastAt":"2008-08-10T17:04:21Z","messageCount":6,"participants":["Karl Hasselström"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"86686","messageId":"20080810161035.7116.2171.stgit@yoghurt","threadId":"14921","inReplyTo":"20080810153848.GA28032@diana.vm.bytemark.co.uk","subject":"[PATCH v3 0/4] Teach git diff-tree --stdin to diff trees","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-10T16:12:39Z","receivedAt":"2008-08-10T16:12:39Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"Updated after Junio's comments. (Patch 1/4 and 4/4 have not changed\nbut I'm resending them anyway for convenience.)\n\n---\n\nKarl Hasselström (4):\n      Add test for diff-tree --stdin with two trees\n      Teach git diff-tree --stdin to diff trees\n      diff-tree: Note that the commit ID is printed with --stdin\n      Refactoring: Split up diff_tree_stdin\n\n\n Documentation/git-diff-tree.txt |   19 ++++++++++---\n builtin-diff-tree.c             |   56 +++++++++++++++++++++++++++++++--------\n t/t4002-diff-basic.sh           |   14 ++++++++++\n 3 files changed, 72 insertions(+), 17 deletions(-)\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"86683","messageId":"20080810161247.7116.64777.stgit@yoghurt","threadId":"14921","inReplyTo":"20080810161035.7116.2171.stgit@yoghurt","subject":"[PATCH v3 1/4] Refactoring: Split up diff_tree_stdin","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-10T16:12:47Z","receivedAt":"2008-08-10T16:12:47Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"Into a first half that determines what operation to do, and a second\nhalf that does it.\n\nCurrently the only operation is diffing one or more commits, but a\nlater patch will add diffing of trees, at which point this refactoring\nwill pay off.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n builtin-diff-tree.c |   31 +++++++++++++++++++------------\n 1 files changed, 19 insertions(+), 12 deletions(-)\n\n\ndiff --git a/builtin-diff-tree.c b/builtin-diff-tree.c\nindex 415cb16..ebbd631 100644\n--- a/builtin-diff-tree.c\n+++ b/builtin-diff-tree.c\n@@ -14,20 +14,10 @@ static int diff_tree_commit_sha1(const unsigned char *sha1)\n \treturn log_tree_commit(&log_tree_opt, commit);\n }\n \n-static int diff_tree_stdin(char *line)\n+/* Diff one or more commits. */\n+static int stdin_diff_commit(struct commit *commit, char *line, int len)\n {\n-\tint len = strlen(line);\n \tunsigned char sha1[20];\n-\tstruct commit *commit;\n-\n-\tif (!len || line[len-1] != '\\n')\n-\t\treturn -1;\n-\tline[len-1] = 0;\n-\tif (get_sha1_hex(line, sha1))\n-\t\treturn -1;\n-\tcommit = lookup_commit(sha1);\n-\tif (!commit || parse_commit(commit))\n-\t\treturn -1;\n \tif (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {\n \t\t/* Graft the fake parents locally to the commit */\n \t\tint pos = 41;\n@@ -52,6 +42,23 @@ static int diff_tree_stdin(char *line)\n \treturn log_tree_commit(&log_tree_opt, commit);\n }\n \n+static int diff_tree_stdin(char *line)\n+{\n+\tint len = strlen(line);\n+\tunsigned char sha1[20];\n+\tstruct commit *commit;\n+\n+\tif (!len || line[len-1] != '\\n')\n+\t\treturn -1;\n+\tline[len-1] = 0;\n+\tif (get_sha1_hex(line, sha1))\n+\t\treturn -1;\n+\tcommit = lookup_commit(sha1);\n+\tif (!commit || parse_commit(commit))\n+\t\treturn -1;\n+\treturn stdin_diff_commit(commit, line, len);\n+}\n+\n static const char diff_tree_usage[] =\n \"git diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] \"\n \"[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\\n\"\n"},{"id":"86684","messageId":"20080810161253.7116.79513.stgit@yoghurt","threadId":"14921","inReplyTo":"20080810161035.7116.2171.stgit@yoghurt","subject":"[PATCH v3 2/4] diff-tree: Note that the commit ID is printed with --stdin","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-10T16:12:53Z","receivedAt":"2008-08-10T16:12:53Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"It's sort of already documented with the --no-commit-id command-line\nflag, but let's not hide important information from the user.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n Documentation/git-diff-tree.txt |   10 +++++++---\n 1 files changed, 7 insertions(+), 3 deletions(-)\n\n\ndiff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt\nindex 1fdf20d..1f4b91e 100644\n--- a/Documentation/git-diff-tree.txt\n+++ b/Documentation/git-diff-tree.txt\n@@ -52,10 +52,14 @@ include::diff-options.txt[]\n \treads either one <commit> or a list of <commit>\n \tseparated with a single space from its standard input.\n +\n-When a single commit is given on one line of such input, it compares\n-the commit with its parents.  The following flags further affects its\n-behavior.  The remaining commits, when given, are used as if they are\n+When a single commit is given, it compares the commit with its\n+parents.  The remaining commits, when given, are used as if they are\n parents of the first commit.\n++\n+The ID of the first (or only) commit, followed by a newline, is\n+printed before the differences.\n++\n+The following flags further affects its behavior.\n \n -m::\n \tBy default, 'git-diff-tree --stdin' does not show\n"},{"id":"86685","messageId":"20080810161258.7116.33770.stgit@yoghurt","threadId":"14921","inReplyTo":"20080810161035.7116.2171.stgit@yoghurt","subject":"[PATCH v3 3/4] Teach git diff-tree --stdin to diff trees","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-10T16:12:58Z","receivedAt":"2008-08-10T16:12:58Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"When feeding trees on the command line, you can give exactly two\ntrees, not three nor one; --stdin now supports this \"two tree\" form on\nits input, in addition to accepting lines with one or more commits.\n\nWhen diffing trees (either specified on the command line or from the\nstandard input), the -s, -v, --pretty, --abbrev-commit, --encoding,\n--no-commit-id, and --always options are ignored, since they do not\napply to trees; and the -m, -c, and --cc options are ignored since\nthey would require three trees, which is not supported (yet).\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n Documentation/git-diff-tree.txt |   15 ++++++++++-----\n builtin-diff-tree.c             |   33 +++++++++++++++++++++++++++++----\n 2 files changed, 39 insertions(+), 9 deletions(-)\n\n\ndiff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt\nindex 1f4b91e..5d48664 100644\n--- a/Documentation/git-diff-tree.txt\n+++ b/Documentation/git-diff-tree.txt\n@@ -49,17 +49,22 @@ include::diff-options.txt[]\n --stdin::\n \tWhen '--stdin' is specified, the command does not take\n \t<tree-ish> arguments from the command line.  Instead, it\n-\treads either one <commit> or a list of <commit>\n-\tseparated with a single space from its standard input.\n+\treads lines containing either two <tree>, one <commit>, or a\n+\tlist of <commit> from its standard input.  (Use a single space\n+\tas separator.)\n +\n+When two trees are given, it compares the first tree with the second.\n When a single commit is given, it compares the commit with its\n parents.  The remaining commits, when given, are used as if they are\n parents of the first commit.\n +\n-The ID of the first (or only) commit, followed by a newline, is\n-printed before the differences.\n+When comparing two trees, the ID of both trees (separated by a space\n+and terminated by a newline) is printed before the difference.  When\n+comparing commits, the ID of the first (or only) commit, followed by a\n+newline, is printed.\n +\n-The following flags further affects its behavior.\n+The following flags further affects the behavior when comparing\n+commits (but not trees).\n \n -m::\n \tBy default, 'git-diff-tree --stdin' does not show\ndiff --git a/builtin-diff-tree.c b/builtin-diff-tree.c\nindex ebbd631..5a56178 100644\n--- a/builtin-diff-tree.c\n+++ b/builtin-diff-tree.c\n@@ -42,21 +42,46 @@ static int stdin_diff_commit(struct commit *commit, char *line, int len)\n \treturn log_tree_commit(&log_tree_opt, commit);\n }\n \n+/* Diff two trees. */\n+static int stdin_diff_trees(struct tree *tree1, char *line, int len)\n+{\n+\tunsigned char sha1[20];\n+\tstruct tree *tree2;\n+\tif (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1))\n+\t\treturn error(\"Need precisely two trees, separated by a space\");\n+\ttree2 = lookup_tree(sha1);\n+\tif (!tree2 || parse_tree(tree2))\n+\t\treturn -1;\n+\tprintf(\"%s %s\\n\", sha1_to_hex(tree1->object.sha1),\n+\t\t\t  sha1_to_hex(tree2->object.sha1));\n+\tdiff_tree_sha1(tree1->object.sha1, tree2->object.sha1,\n+\t\t       \"\", &log_tree_opt.diffopt);\n+\tlog_tree_diff_flush(&log_tree_opt);\n+\treturn 0;\n+}\n+\n static int diff_tree_stdin(char *line)\n {\n \tint len = strlen(line);\n \tunsigned char sha1[20];\n-\tstruct commit *commit;\n+\tstruct object *obj;\n \n \tif (!len || line[len-1] != '\\n')\n \t\treturn -1;\n \tline[len-1] = 0;\n \tif (get_sha1_hex(line, sha1))\n \t\treturn -1;\n-\tcommit = lookup_commit(sha1);\n-\tif (!commit || parse_commit(commit))\n+\tobj = lookup_object(sha1);\n+\tobj = obj ? obj : parse_object(sha1);\n+\tif (!obj)\n \t\treturn -1;\n-\treturn stdin_diff_commit(commit, line, len);\n+\tif (obj->type == OBJ_COMMIT)\n+\t\treturn stdin_diff_commit((struct commit *)obj, line, len);\n+\tif (obj->type == OBJ_TREE)\n+\t\treturn stdin_diff_trees((struct tree *)obj, line, len);\n+\terror(\"Object %s is a %s, not a commit or tree\",\n+\t      sha1_to_hex(sha1), typename(obj->type));\n+\treturn -1;\n }\n \n static const char diff_tree_usage[] =\n"},{"id":"86682","messageId":"20080810161304.7116.56769.stgit@yoghurt","threadId":"14921","inReplyTo":"20080810161035.7116.2171.stgit@yoghurt","subject":"[PATCH v3 4/4] Add test for diff-tree --stdin with two trees","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-10T16:13:04Z","receivedAt":"2008-08-10T16:13:04Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"Signed-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n t/t4002-diff-basic.sh |   14 ++++++++++++++\n 1 files changed, 14 insertions(+), 0 deletions(-)\n\n\ndiff --git a/t/t4002-diff-basic.sh b/t/t4002-diff-basic.sh\nindex a4cfde6..27743c4 100755\n--- a/t/t4002-diff-basic.sh\n+++ b/t/t4002-diff-basic.sh\n@@ -169,6 +169,20 @@ test_expect_success \\\n      cmp -s .test-a .test-recursive-AB'\n \n test_expect_success \\\n+    'diff-tree --stdin of known trees.' \\\n+    'echo $tree_A $tree_B | git diff-tree --stdin > .test-a &&\n+     echo $tree_A $tree_B > .test-plain-ABx &&\n+     cat .test-plain-AB >> .test-plain-ABx &&\n+     cmp -s .test-a .test-plain-ABx'\n+\n+test_expect_success \\\n+    'diff-tree --stdin of known trees.' \\\n+    'echo $tree_A $tree_B | git diff-tree -r --stdin > .test-a &&\n+     echo $tree_A $tree_B > .test-recursive-ABx &&\n+     cat .test-recursive-AB >> .test-recursive-ABx &&\n+     cmp -s .test-a .test-recursive-ABx'\n+\n+test_expect_success \\\n     'diff-cache O with A in cache' \\\n     'git read-tree $tree_A &&\n      git diff-index --cached $tree_O >.test-a &&\n"},{"id":"86689","messageId":"20080810170421.GB28032@diana.vm.bytemark.co.uk","threadId":"14921","inReplyTo":"20080810161035.7116.2171.stgit@yoghurt","subject":"Re: [PATCH v3 0/4] Teach git diff-tree --stdin to diff trees","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-10T17:04:21Z","receivedAt":"2008-08-10T17:04:21Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-08-10 18:12:39 +0200, Karl Hasselström wrote:\n\n>       diff-tree: Note that the commit ID is printed with --stdin\n\nBTW, I imagine this one might be maint material, if deemed acceptable.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}