提交 d8933f01 编写于 作者: S Shawn O. Pearce 提交者: Junio C Hamano

fast-export: Correctly generate initial commits with no parents

If we are exporting a commit which has no parents we may be doing
it to a branch that already exists, causing fast-import to assume
the branch's current revision should be the sole parent of the
new commit.  This can cause `git fast-export | git fast-import`
to produce an incorrect graph for:

   A-------M----o------o  refs/heads/master
          /
       B-+

In this graph A and B are initial commits (no parents) but if A was
output first to refs/heads/master and then B is output fast-import
would assume the graph was this instead:

   A-------M----o------o  refs/heads/master
    \     /
     +-B-+

Which would cause B, M, and all later commits to have a different
SHA-1, and obviously be quite a different graph.

Sending a reset command prior to B informs fast-import to clear
the implied parent of A, allowing B to remain an initial commit.
Reported-by: NBen Lynn <benlynn@gmail.com>
Deemed-obviously-correct-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 7b7b4516
......@@ -188,6 +188,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
mark_object(&commit->object);
if (!is_encoding_utf8(encoding))
reencoded = reencode_string(message, "UTF-8", encoding);
if (!commit->parents)
printf("reset %s\n", (const char*)commit->util);
printf("commit %s\nmark :%d\n%.*s\n%.*s\ndata %u\n%s",
(const char *)commit->util, last_idnum,
(int)(author_end - author), author,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册