Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
623fbd93
Commit
623fbd93
authored
Apr 10, 2015
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2974 from libgit2/cmn/clone-everything
Make sure to pack referenced objects for non-branches
parents
63af449e
c84a9dd2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
3 deletions
+97
-3
include/git2/pack.h
+12
-0
src/pack-objects.c
+36
-0
src/transports/local.c
+2
-1
src/tree.c
+2
-2
tests/clone/nonetwork.c
+45
-0
No files found.
include/git2/pack.h
View file @
623fbd93
...
...
@@ -128,6 +128,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
);
/**
* 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
*
* The contents of the buffer will become a valid packfile, even though there
...
...
src/pack-objects.c
View file @
623fbd93
...
...
@@ -1404,6 +1404,42 @@ int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
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
)
{
return
pb
->
nr_objects
;
...
...
src/transports/local.c
View file @
623fbd93
...
...
@@ -544,7 +544,8 @@ static int local_download_pack(
error
=
0
;
}
}
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
);
if
(
error
<
0
)
...
...
src/tree.c
View file @
623fbd93
...
...
@@ -858,7 +858,7 @@ int git_tree_entry_bypath(
if
(
entry
==
NULL
)
{
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
;
}
...
...
@@ -868,7 +868,7 @@ int git_tree_entry_bypath(
* then this entry *must* be a tree */
if
(
!
git_tree_entry__is_tree
(
entry
))
{
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
;
}
...
...
tests/clone/nonetwork.c
View file @
623fbd93
...
...
@@ -246,6 +246,51 @@ void test_clone_nonetwork__can_detached_head(void)
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
)
{
git_reflog
*
log
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment