{"thread":{"id":"2627","subject":"diff-tree and does not respect grafts","startedAt":"2005-11-21T11:54:39Z","lastAt":"2005-11-22T03:02:41Z","messageCount":3,"participants":["Santi Béjar","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"12429","messageId":"87lkzi1aio.fsf@gmail.com","threadId":"2627","inReplyTo":null,"subject":"diff-tree and does not respect grafts","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2005-11-21T11:54:39Z","receivedAt":"2005-11-21T11:54:39Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"Hello:\n\n        diff-tree decode directly the commit, so it does not take into\n        account the graft file. Is this the expected behaviour?\n\n        Santi\n"},{"id":"12486","messageId":"7v4q65odkg.fsf@assigned-by-dhcp.cox.net","threadId":"2627","inReplyTo":"87lkzi1aio.fsf@gmail.com","subject":"Re: diff-tree and does not respect grafts","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-11-21T22:12:31Z","receivedAt":"2005-11-21T22:12:31Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Santi Béjar <sbejar@gmail.com> writes:\n\n>         diff-tree decode directly the commit, so it does not take into\n>         account the graft file. Is this the expected behaviour?\n\nExpected?  Yes, only because I happen to know diff-tree was\nwritten way before grafts are invented and nobody bothered to\nchange that behaviour.  Desireable?  Probably not.\n"},{"id":"12506","messageId":"7v3blpjsfi.fsf_-_@assigned-by-dhcp.cox.net","threadId":"2627","inReplyTo":"7v4q65odkg.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Teach diff-tree to honor grafts","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-11-22T03:02:41Z","receivedAt":"2005-11-22T03:02:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Santi Béjar <sbejar@gmail.com> writes:\n>\n>>         diff-tree decode directly the commit, so it does not take into\n>>         account the graft file. Is this the expected behaviour?\n>\n> Expected?  Yes, only because I happen to know diff-tree was\n> written way before grafts are invented and nobody bothered to\n> change that behaviour.  Desireable?  Probably not.\n\nSomething like this (only lightly tested) should make it work in\none-tree case.  The --stdin form does not necessarily need this\nif you tell rev-list to show the parents, but that case should\nbe covered as well with this patch.\n\n-- >8 --\n\n\"git-rev-list --parent\" piped to \"git-diff-tree --stdin\" honors\ngrafts because rev-list will explicitly tell diff-tree what base\ncommit to compare each commit against, but a single parameter\n\"git-diff-tree oneEnt\" form did its own thing to extract parent\ninformation from the commit object by hand, without honoring the\ngrafts the user has.  Rewrite that part to use parse_commit()\nAPI.\n\n---\n\ndiff --git a/diff-tree.c b/diff-tree.c\nindex 09d16ad..e79a134 100644\n--- a/diff-tree.c\n+++ b/diff-tree.c\n@@ -69,52 +69,50 @@ static int diff_root_tree(const unsigned\n \treturn retval;\n }\n \n-static const char *generate_header(const char *commit, const char *parent, const char *msg, unsigned long len)\n+static const char *generate_header(const char *commit, const char *parent, const char *msg)\n {\n \tstatic char this_header[16384];\n \tint offset;\n+\tunsigned long len;\n \n \tif (!verbose_header)\n \t\treturn commit;\n \n+\tlen = strlen(msg);\n \toffset = sprintf(this_header, \"%s%s (from %s)\\n\", header_prefix, commit, parent);\n \toffset += pretty_print_commit(commit_format, msg, len, this_header + offset, sizeof(this_header) - offset);\n \treturn this_header;\n }\n \n-static int diff_tree_commit(const unsigned char *commit, const char *name)\n+static int diff_tree_commit(const unsigned char *commit_sha1)\n {\n-\tunsigned long size, offset;\n-\tchar *buf = read_object_with_reference(commit, \"commit\", &size, NULL);\n+\tstruct commit *commit;\n+\tstruct commit_list *parents;\n+\tchar name[50];\n+\tunsigned char sha1[20];\n \n-\tif (!buf)\n+\tsprintf(name, \"%s^0\", sha1_to_hex(commit_sha1));\n+\tif (get_sha1(name, sha1))\n \t\treturn -1;\n-\n-\tif (!name) {\n-\t\tstatic char commit_name[60];\n-\t\tstrcpy(commit_name, sha1_to_hex(commit));\n-\t\tname = commit_name;\n-\t}\n-\n+\tname[40] = 0;\n+\tcommit = lookup_commit(sha1);\n+\t\n \t/* Root commit? */\n-\tif (show_root_diff && memcmp(buf + 46, \"parent \", 7)) {\n-\t\theader = generate_header(name, \"root\", buf, size);\n-\t\tdiff_root_tree(commit, \"\");\n+\tif (show_root_diff && !commit->parents) {\n+\t\theader = generate_header(name, \"root\", commit->buffer);\n+\t\tdiff_root_tree(commit_sha1, \"\");\n \t}\n \n \t/* More than one parent? */\n-\tif (ignore_merges) {\n-\t\tif (!memcmp(buf + 46 + 48, \"parent \", 7))\n+\tif (ignore_merges && commit->parents && commit->parents->next)\n \t\t\treturn 0;\n-\t}\n \n-\toffset = 46;\n-\twhile (offset + 48 < size && !memcmp(buf + offset, \"parent \", 7)) {\n-\t\tunsigned char parent[20];\n-\t\tif (get_sha1_hex(buf + offset + 7, parent))\n-\t\t\treturn -1;\n-\t\theader = generate_header(name, sha1_to_hex(parent), buf, size);\n-\t\tdiff_tree_sha1_top(parent, commit, \"\");\n+\tfor (parents = commit->parents; parents; parents = parents->next) {\n+\t\tstruct commit *parent = parents->item;\n+\t\theader = generate_header(name,\n+\t\t\t\t\t sha1_to_hex(parent->object.sha1),\n+\t\t\t\t\t commit->buffer);\n+\t\tdiff_tree_sha1_top(parent->object.sha1, commit_sha1, \"\");\n \t\tif (!header && verbose_header) {\n \t\t\theader_prefix = \"\\ndiff-tree \";\n \t\t\t/*\n@@ -122,9 +120,7 @@ static int diff_tree_commit(const unsign\n \t\t\t * don't print the diffs.\n \t\t\t */\n \t\t}\n-\t\toffset += 48;\n \t}\n-\tfree(buf);\n \treturn 0;\n }\n \n@@ -147,7 +143,7 @@ static int diff_tree_stdin(char *line)\n \t\treturn diff_tree_sha1_top(parent, commit, \"\");\n \t}\n \tline[40] = 0;\n-\treturn diff_tree_commit(commit, line);\n+\treturn diff_tree_commit(commit);\n }\n \n static const char diff_tree_usage[] =\n@@ -250,7 +246,7 @@ int main(int argc, const char **argv)\n \t\t\tusage(diff_tree_usage);\n \t\tbreak;\n \tcase 1:\n-\t\tdiff_tree_commit(sha1[0], NULL);\n+\t\tdiff_tree_commit(sha1[0]);\n \t\tbreak;\n \tcase 2:\n \t\tdiff_tree_sha1_top(sha1[0], sha1[1], \"\");\n"}]}