Merge branch 'mb/fast-import-reference-pending'
The 'from' command in 'git fast-import' has been updated to correctly resolve references to newly created commits and tags by checking the internal object table, preventing a crash when the objects are not yet available in the object database. * mb/fast-import-reference-pending: fast-import: allow 'from' to reference new commits and tags by oid
This commit is contained in:
commit
775dc1673e
2 files changed
+58
-4
No files matched your search
+15
-4
@@ -292,6 +292,9 @@ static void fast_import_state_init(struct fast_import_state *state,
|
||||
state->option = option;
|
||||
}
|
||||
|
||||
static struct object_entry *dereference(struct object_entry *oe,
|
||||
struct object_id *oid);
|
||||
|
||||
static void parse_argv(struct fast_import_state *state);
|
||||
static void parse_get_mark(struct fast_import_state *state, const char *p);
|
||||
static void parse_cat_blob(struct fast_import_state *state, const char *p);
|
||||
@@ -2654,12 +2657,20 @@ static void parse_from_existing(struct branch *b)
|
||||
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
|
||||
} else {
|
||||
unsigned long size;
|
||||
size_t size_st = 0;
|
||||
char *buf;
|
||||
struct object_entry *e = find_object(&b->oid);
|
||||
|
||||
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
|
||||
OBJ_COMMIT, &size_st, &b->oid);
|
||||
size = cast_size_t_to_ulong(size_st);
|
||||
while (e && e->type == OBJ_TAG)
|
||||
e = dereference(e, &b->oid);
|
||||
|
||||
if (e && e->type == OBJ_COMMIT && e->pack_id != MAX_PACK_ID) {
|
||||
buf = gfi_unpack_entry(e, &size);
|
||||
} else {
|
||||
size_t size_st = 0;
|
||||
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
|
||||
OBJ_COMMIT, &size_st, &b->oid);
|
||||
size = cast_size_t_to_ulong(size_st);
|
||||
}
|
||||
parse_from_commit(b, buf, size);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
@@ -3938,4 +3938,47 @@ test_expect_success 'Y: rewrite submodules' '
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'Y: reference pending tag or commit' '
|
||||
test_oid_cache <<-EOF &&
|
||||
pending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04
|
||||
pending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d
|
||||
pending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7
|
||||
pending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46
|
||||
EOF
|
||||
|
||||
git init reference-pending &&
|
||||
(
|
||||
cd reference-pending &&
|
||||
git fast-import <<-EOF
|
||||
commit refs/heads/main
|
||||
committer A U Thor <author@example.com> 1712563200 +0000
|
||||
data 14
|
||||
commit message
|
||||
M 644 inline test file
|
||||
data 14
|
||||
dummy content
|
||||
|
||||
tag newtag
|
||||
from $(test_oid pending_commit)
|
||||
tagger A U Thor <author@example.com> 1712563300 +0000
|
||||
data 11
|
||||
tag message
|
||||
# no emty line after tag data!
|
||||
reset refs/heads/other
|
||||
from $(test_oid pending_tag)
|
||||
|
||||
commit refs/heads/further
|
||||
committer A U Thor <author@example.com> 1712563400 +0000
|
||||
data 21
|
||||
what about 2nd commit
|
||||
from $(test_oid pending_commit)
|
||||
M 644 inline other test file
|
||||
data 19
|
||||
more dummy content
|
||||
|
||||
done
|
||||
EOF
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
Reference in new issue
Block a user