mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-07 18:11:43 +00:00
Merge pull request #2974 from libgit2/cmn/clone-everything
Make sure to pack referenced objects for non-branches
This commit is contained in:
commit
623fbd93f1
@ -127,6 +127,18 @@ GIT_EXTERN(int) git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid
|
|||||||
*/
|
*/
|
||||||
GIT_EXTERN(int) git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk);
|
GIT_EXTERN(int) git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively insert an object and its referenced objects
|
||||||
|
*
|
||||||
|
* Insert the object as well as any object it references.
|
||||||
|
*
|
||||||
|
* @param pb the packbuilder
|
||||||
|
* @param id the id of the root object to insert
|
||||||
|
* @param name optional name for the object
|
||||||
|
* @return 0 or an error code
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(int) git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the contents of the packfile to an in-memory buffer
|
* Write the contents of the packfile to an in-memory buffer
|
||||||
*
|
*
|
||||||
|
@ -1404,6 +1404,42 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name)
|
||||||
|
{
|
||||||
|
git_object *obj;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
assert(pb && id);
|
||||||
|
|
||||||
|
if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJ_ANY)) < 0)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
switch (git_object_type(obj)) {
|
||||||
|
case GIT_OBJ_BLOB:
|
||||||
|
error = git_packbuilder_insert(pb, id, name);
|
||||||
|
break;
|
||||||
|
case GIT_OBJ_TREE:
|
||||||
|
error = git_packbuilder_insert_tree(pb, id);
|
||||||
|
break;
|
||||||
|
case GIT_OBJ_COMMIT:
|
||||||
|
error = git_packbuilder_insert_commit(pb, id);
|
||||||
|
break;
|
||||||
|
case GIT_OBJ_TAG:
|
||||||
|
if ((error = git_packbuilder_insert(pb, id, name)) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
error = git_packbuilder_insert_recur(pb, git_tag_target_id((git_tag *) obj), NULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
giterr_set(GITERR_INVALID, "unknown object type");
|
||||||
|
error = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
git_object_free(obj);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t git_packbuilder_object_count(git_packbuilder *pb)
|
uint32_t git_packbuilder_object_count(git_packbuilder *pb)
|
||||||
{
|
{
|
||||||
return pb->nr_objects;
|
return pb->nr_objects;
|
||||||
|
@ -544,7 +544,8 @@ static int local_download_pack(
|
|||||||
error = 0;
|
error = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error = git_packbuilder_insert(pack, &rhead->oid, rhead->name);
|
/* Tag or some other wanted object. Add it on its own */
|
||||||
|
error = git_packbuilder_insert_recur(pack, &rhead->oid, rhead->name);
|
||||||
}
|
}
|
||||||
git_object_free(obj);
|
git_object_free(obj);
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
|
@ -858,7 +858,7 @@ int git_tree_entry_bypath(
|
|||||||
|
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
giterr_set(GITERR_TREE,
|
giterr_set(GITERR_TREE,
|
||||||
"The path '%s' does not exist in the given tree", path);
|
"the path '%.*s' does not exist in the given tree", filename_len, path);
|
||||||
return GIT_ENOTFOUND;
|
return GIT_ENOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,7 +868,7 @@ int git_tree_entry_bypath(
|
|||||||
* then this entry *must* be a tree */
|
* then this entry *must* be a tree */
|
||||||
if (!git_tree_entry__is_tree(entry)) {
|
if (!git_tree_entry__is_tree(entry)) {
|
||||||
giterr_set(GITERR_TREE,
|
giterr_set(GITERR_TREE,
|
||||||
"The path '%s' does not exist in the given tree", path);
|
"the path '%.*s' exists but is not a tree", filename_len, path);
|
||||||
return GIT_ENOTFOUND;
|
return GIT_ENOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,6 +246,51 @@ void test_clone_nonetwork__can_detached_head(void)
|
|||||||
cl_fixture_cleanup("./foo1");
|
cl_fixture_cleanup("./foo1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_clone_nonetwork__clone_tag_to_tree(void)
|
||||||
|
{
|
||||||
|
git_repository *stage;
|
||||||
|
git_index_entry entry;
|
||||||
|
git_index *index;
|
||||||
|
git_odb *odb;
|
||||||
|
git_oid tree_id;
|
||||||
|
git_tree *tree;
|
||||||
|
git_reference *tag;
|
||||||
|
git_tree_entry *tentry;
|
||||||
|
const char *file_path = "some/deep/path.txt";
|
||||||
|
const char *file_content = "some content\n";
|
||||||
|
const char *tag_name = "refs/tags/tree-tag";
|
||||||
|
|
||||||
|
stage = cl_git_sandbox_init("testrepo.git");
|
||||||
|
cl_git_pass(git_repository_odb(&odb, stage));
|
||||||
|
cl_git_pass(git_index_new(&index));
|
||||||
|
|
||||||
|
memset(&entry, 0, sizeof(git_index_entry));
|
||||||
|
entry.path = file_path;
|
||||||
|
entry.mode = GIT_FILEMODE_BLOB;
|
||||||
|
cl_git_pass(git_odb_write(&entry.id, odb, file_content, strlen(file_content), GIT_OBJ_BLOB));
|
||||||
|
|
||||||
|
cl_git_pass(git_index_add(index, &entry));
|
||||||
|
cl_git_pass(git_index_write_tree_to(&tree_id, index, stage));
|
||||||
|
cl_git_pass(git_reference_create(&tag, stage, tag_name, &tree_id, 0, NULL));
|
||||||
|
git_reference_free(tag);
|
||||||
|
git_odb_free(odb);
|
||||||
|
git_index_free(index);
|
||||||
|
|
||||||
|
g_options.local = GIT_CLONE_NO_LOCAL;
|
||||||
|
cl_git_pass(git_clone(&g_repo, cl_git_path_url(git_repository_path(stage)), "./foo", &g_options));
|
||||||
|
git_repository_free(stage);
|
||||||
|
|
||||||
|
cl_git_pass(git_reference_lookup(&tag, g_repo, tag_name));
|
||||||
|
cl_git_pass(git_tree_lookup(&tree, g_repo, git_reference_target(tag)));
|
||||||
|
git_reference_free(tag);
|
||||||
|
|
||||||
|
cl_git_pass(git_tree_entry_bypath(&tentry, tree, file_path));
|
||||||
|
git_tree_entry_free(tentry);
|
||||||
|
git_tree_free(tree);
|
||||||
|
|
||||||
|
cl_fixture_cleanup("testrepo.git");
|
||||||
|
}
|
||||||
|
|
||||||
static void assert_correct_reflog(const char *name)
|
static void assert_correct_reflog(const char *name)
|
||||||
{
|
{
|
||||||
git_reflog *log;
|
git_reflog *log;
|
||||||
|
Loading…
Reference in New Issue
Block a user