Skip to content

Commit 3ecca88

Browse files
committed
Merge branch 'mh/fast-import-optimize-current-from'
Often a fast-import stream builds a new commit on top of the previous commit it built, and it often unconditionally emits a "from" command to specify the first parent, which can be omitted in such a case. This caused fast-import to forget the tree of the previous commit and then re-read it from scratch, which was inefficient. Optimize for this common case. * mh/fast-import-optimize-current-from: fast-import: do less work when given "from" matches current branch head
2 parents 85df7cd + 0df3245 commit 3ecca88

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

fast-import.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,14 +2594,12 @@ static int parse_from(struct branch *b)
25942594
{
25952595
const char *from;
25962596
struct branch *s;
2597+
unsigned char sha1[20];
25972598

25982599
if (!skip_prefix(command_buf.buf, "from ", &from))
25992600
return 0;
26002601

2601-
if (b->branch_tree.tree) {
2602-
release_tree_content_recursive(b->branch_tree.tree);
2603-
b->branch_tree.tree = NULL;
2604-
}
2602+
hashcpy(sha1, b->branch_tree.versions[1].sha1);
26052603

26062604
s = lookup_branch(from);
26072605
if (b == s)
@@ -2616,14 +2614,16 @@ static int parse_from(struct branch *b)
26162614
struct object_entry *oe = find_mark(idnum);
26172615
if (oe->type != OBJ_COMMIT)
26182616
die("Mark :%" PRIuMAX " not a commit", idnum);
2619-
hashcpy(b->sha1, oe->idx.sha1);
2620-
if (oe->pack_id != MAX_PACK_ID) {
2621-
unsigned long size;
2622-
char *buf = gfi_unpack_entry(oe, &size);
2623-
parse_from_commit(b, buf, size);
2624-
free(buf);
2625-
} else
2626-
parse_from_existing(b);
2617+
if (hashcmp(b->sha1, oe->idx.sha1)) {
2618+
hashcpy(b->sha1, oe->idx.sha1);
2619+
if (oe->pack_id != MAX_PACK_ID) {
2620+
unsigned long size;
2621+
char *buf = gfi_unpack_entry(oe, &size);
2622+
parse_from_commit(b, buf, size);
2623+
free(buf);
2624+
} else
2625+
parse_from_existing(b);
2626+
}
26272627
} else if (!get_sha1(from, b->sha1)) {
26282628
parse_from_existing(b);
26292629
if (is_null_sha1(b->sha1))
@@ -2632,6 +2632,11 @@ static int parse_from(struct branch *b)
26322632
else
26332633
die("Invalid ref name or SHA1 expression: %s", from);
26342634

2635+
if (b->branch_tree.tree && hashcmp(sha1, b->branch_tree.versions[1].sha1)) {
2636+
release_tree_content_recursive(b->branch_tree.tree);
2637+
b->branch_tree.tree = NULL;
2638+
}
2639+
26352640
read_next_command();
26362641
return 1;
26372642
}

0 commit comments

Comments
 (0)