mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
fast-import: do less work when given "from" matches current branch head
When building a fast-import stream, it's easy to forget the fact that for non-merge commits happening on top of the current branch head, there is no need for a "from" command. That is corroborated by the fact that at least git-p4, hg-fast-export and felipec's git-remote-hg all unconditionally use a "from" command. Unfortunately, giving a "from" command always resets the branch tree, forcing it to be re-read, and in many cases, the pack is also closed and reopened through gfi_unpack_entry. Both are unnecessary overhead, and the latter is particularly slow at least on OSX. Avoid resetting the tree when it's unmodified, and avoid calling gfi_unpack_entry when the given mark points to the same commit as the current branch head. Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7ecec52d42
commit
0df3245721
|
@ -2588,14 +2588,12 @@ static int parse_from(struct branch *b)
|
|||
{
|
||||
const char *from;
|
||||
struct branch *s;
|
||||
unsigned char sha1[20];
|
||||
|
||||
if (!skip_prefix(command_buf.buf, "from ", &from))
|
||||
return 0;
|
||||
|
||||
if (b->branch_tree.tree) {
|
||||
release_tree_content_recursive(b->branch_tree.tree);
|
||||
b->branch_tree.tree = NULL;
|
||||
}
|
||||
hashcpy(sha1, b->branch_tree.versions[1].sha1);
|
||||
|
||||
s = lookup_branch(from);
|
||||
if (b == s)
|
||||
|
@ -2610,6 +2608,7 @@ static int parse_from(struct branch *b)
|
|||
struct object_entry *oe = find_mark(idnum);
|
||||
if (oe->type != OBJ_COMMIT)
|
||||
die("Mark :%" PRIuMAX " not a commit", idnum);
|
||||
if (hashcmp(b->sha1, oe->idx.sha1)) {
|
||||
hashcpy(b->sha1, oe->idx.sha1);
|
||||
if (oe->pack_id != MAX_PACK_ID) {
|
||||
unsigned long size;
|
||||
|
@ -2618,6 +2617,7 @@ static int parse_from(struct branch *b)
|
|||
free(buf);
|
||||
} else
|
||||
parse_from_existing(b);
|
||||
}
|
||||
} else if (!get_sha1(from, b->sha1)) {
|
||||
parse_from_existing(b);
|
||||
if (is_null_sha1(b->sha1))
|
||||
|
@ -2626,6 +2626,11 @@ static int parse_from(struct branch *b)
|
|||
else
|
||||
die("Invalid ref name or SHA1 expression: %s", from);
|
||||
|
||||
if (b->branch_tree.tree && hashcmp(sha1, b->branch_tree.versions[1].sha1)) {
|
||||
release_tree_content_recursive(b->branch_tree.tree);
|
||||
b->branch_tree.tree = NULL;
|
||||
}
|
||||
|
||||
read_next_command();
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue