{"thread":{"id":"13927","subject":"[PATCH] fast-export: Correctly generate initial commits with no parents","startedAt":"2008-06-13T04:38:55Z","lastAt":"2008-06-13T04:38:55Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"79669","messageId":"20080613043855.GA28644@spearce.org","threadId":"13927","inReplyTo":null,"subject":"[PATCH] fast-export: Correctly generate initial commits with no parents","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-06-13T04:38:55Z","receivedAt":"2008-06-13T04:38:55Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If we are exporting a commit which has no parents we may be doing\nit to a branch that already exists, causing fast-import to assume\nthe branch's current revision should be the sole parent of the\nnew commit.  This can cause `git fast-export | git fast-import`\nto produce an incorrect graph for:\n\n   A-------M----o------o  refs/heads/master\n          /\n       B-+\n\nIn this graph A and B are initial commits (no parents) but if A was\noutput first to refs/heads/master and then B is output fast-import\nwould assume the graph was this instead:\n\n   A-------M----o------o  refs/heads/master\n    \\     /\n     +-B-+\n\nWhich would cause B, M, and all later commits to have a different\nSHA-1, and obviously be quite a different graph.\n\nSending a reset command prior to B informs fast-import to clear\nthe implied parent of A, allowing B to remain an initial commit.\n\nReported-by: Ben Lynn <benlynn@gmail.com>\nDeemed-obviously-correct-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-fast-export.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex 1dfc01e..d0a462f 100644\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -188,6 +188,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)\n \tmark_object(&commit->object);\n \tif (!is_encoding_utf8(encoding))\n \t\treencoded = reencode_string(message, \"UTF-8\", encoding);\n+\tif (!commit->parents)\n+\t\tprintf(\"reset %s\\n\", (const char*)commit->util);\n \tprintf(\"commit %s\\nmark :%d\\n%.*s\\n%.*s\\ndata %u\\n%s\",\n \t       (const char *)commit->util, last_idnum,\n \t       (int)(author_end - author), author,\n-- \n1.5.6.rc2.165.g2a0cc\n"}]}