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
0e0cf787
Commit
0e0cf787
authored
Oct 02, 2013
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clone: put the callbacks struct directly in the clone options
There's no need for this to be a pointer to somewhere else.
parent
ffc97d51
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
26 additions
and
35 deletions
+26
-35
examples/network/clone.c
+3
-5
include/git2/clone.h
+2
-2
include/git2/remote.h
+1
-1
src/clone.c
+1
-2
src/remote.c
+2
-2
tests-clar/clone/empty.c
+2
-0
tests-clar/clone/nonetwork.c
+2
-0
tests-clar/online/clone.c
+11
-23
tests-clar/online/fetchhead.c
+2
-0
No files found.
examples/network/clone.c
View file @
0e0cf787
...
...
@@ -57,7 +57,6 @@ int do_clone(git_repository *repo, int argc, char **argv)
git_repository
*
cloned_repo
=
NULL
;
git_clone_options
clone_opts
=
GIT_CLONE_OPTIONS_INIT
;
git_checkout_opts
checkout_opts
=
GIT_CHECKOUT_OPTS_INIT
;
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
const
char
*
url
=
argv
[
1
];
const
char
*
path
=
argv
[
2
];
int
error
;
...
...
@@ -75,10 +74,9 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts
.
progress_cb
=
checkout_progress
;
checkout_opts
.
progress_payload
=
&
pd
;
clone_opts
.
checkout_opts
=
checkout_opts
;
callbacks
.
transfer_progress
=
&
fetch_progress
;
callbacks
.
credentials
=
cred_acquire_cb
;
callbacks
.
payload
=
&
pd
;
clone_opts
.
remote_callbacks
=
&
callbacks
;
clone_opts
.
remote_callbacks
.
transfer_progress
=
&
fetch_progress
;
clone_opts
.
remote_callbacks
.
credentials
=
cred_acquire_cb
;
clone_opts
.
remote_callbacks
.
payload
=
&
pd
;
// Do the clone
error
=
git_clone
(
&
cloned_repo
,
url
,
path
,
&
clone_opts
);
...
...
include/git2/clone.h
View file @
0e0cf787
...
...
@@ -49,7 +49,7 @@ typedef struct git_clone_options {
unsigned
int
version
;
git_checkout_opts
checkout_opts
;
git_remote_callbacks
*
remote_callbacks
;
git_remote_callbacks
remote_callbacks
;
int
bare
;
int
ignore_cert_errors
;
...
...
@@ -58,7 +58,7 @@ typedef struct git_clone_options {
}
git_clone_options
;
#define GIT_CLONE_OPTIONS_VERSION 1
#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}}
#define GIT_CLONE_OPTIONS_INIT {GIT_CLONE_OPTIONS_VERSION, {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_SAFE_CREATE}
, GIT_REMOTE_CALLBACKS_INIT
}
/**
* Clone a remote repository.
...
...
include/git2/remote.h
View file @
0e0cf787
...
...
@@ -457,7 +457,7 @@ struct git_remote_callbacks {
* @param callbacks a pointer to the user's callback settings
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_remote_set_callbacks
(
git_remote
*
remote
,
git_remote_callbacks
*
callbacks
);
GIT_EXTERN
(
int
)
git_remote_set_callbacks
(
git_remote
*
remote
,
const
git_remote_callbacks
*
callbacks
);
/**
* Get the statistics structure that is filled in by the fetch operation.
...
...
src/clone.c
View file @
0e0cf787
...
...
@@ -315,8 +315,7 @@ static int create_and_configure_origin(
if
(
options
->
ignore_cert_errors
)
git_remote_check_cert
(
origin
,
0
);
if
(
options
->
remote_callbacks
&&
(
error
=
git_remote_set_callbacks
(
origin
,
options
->
remote_callbacks
))
<
0
)
if
((
error
=
git_remote_set_callbacks
(
origin
,
&
options
->
remote_callbacks
))
<
0
)
goto
on_error
;
if
((
error
=
git_remote_save
(
origin
))
<
0
)
...
...
src/remote.c
View file @
0e0cf787
...
...
@@ -1153,7 +1153,7 @@ void git_remote_check_cert(git_remote *remote, int check)
remote
->
check_cert
=
check
;
}
int
git_remote_set_callbacks
(
git_remote
*
remote
,
git_remote_callbacks
*
callbacks
)
int
git_remote_set_callbacks
(
git_remote
*
remote
,
const
git_remote_callbacks
*
callbacks
)
{
assert
(
remote
&&
callbacks
);
...
...
@@ -1162,7 +1162,7 @@ int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks
memcpy
(
&
remote
->
callbacks
,
callbacks
,
sizeof
(
git_remote_callbacks
));
if
(
remote
->
transport
&&
remote
->
transport
->
set_callbacks
)
remote
->
transport
->
set_callbacks
(
remote
->
transport
,
re
turn
re
mote
->
transport
->
set_callbacks
(
remote
->
transport
,
remote
->
callbacks
.
progress
,
NULL
,
remote
->
callbacks
.
payload
);
...
...
tests-clar/clone/empty.c
View file @
0e0cf787
...
...
@@ -10,12 +10,14 @@ static git_repository *g_repo_cloned;
void
test_clone_empty__initialize
(
void
)
{
git_repository
*
sandbox
=
cl_git_sandbox_init
(
"empty_bare.git"
);
git_remote_callbacks
dummy_callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
cl_git_remove_placeholders
(
git_repository_path
(
sandbox
),
"dummy-marker.txt"
);
g_repo
=
NULL
;
memset
(
&
g_options
,
0
,
sizeof
(
git_clone_options
));
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
remote_callbacks
=
dummy_callbacks
;
}
void
test_clone_empty__cleanup
(
void
)
...
...
tests-clar/clone/nonetwork.c
View file @
0e0cf787
...
...
@@ -15,6 +15,7 @@ static git_remote* g_remote;
void
test_clone_nonetwork__initialize
(
void
)
{
git_checkout_opts
dummy_opts
=
GIT_CHECKOUT_OPTS_INIT
;
git_remote_callbacks
dummy_callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
g_repo
=
NULL
;
...
...
@@ -22,6 +23,7 @@ void test_clone_nonetwork__initialize(void)
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
checkout_opts
=
dummy_opts
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
g_options
.
remote_callbacks
=
dummy_callbacks
;
}
void
test_clone_nonetwork__cleanup
(
void
)
...
...
tests-clar/online/clone.c
View file @
0e0cf787
...
...
@@ -18,6 +18,7 @@ static git_clone_options g_options;
void
test_online_clone__initialize
(
void
)
{
git_checkout_opts
dummy_opts
=
GIT_CHECKOUT_OPTS_INIT
;
git_remote_callbacks
dummy_callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
g_repo
=
NULL
;
...
...
@@ -25,6 +26,7 @@ void test_online_clone__initialize(void)
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
checkout_opts
=
dummy_opts
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
g_options
.
remote_callbacks
=
dummy_callbacks
;
}
void
test_online_clone__cleanup
(
void
)
...
...
@@ -100,15 +102,11 @@ void test_online_clone__can_checkout_a_cloned_repo(void)
bool
checkout_progress_cb_was_called
=
false
,
fetch_progress_cb_was_called
=
false
;
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE_CREATE
;
g_options
.
checkout_opts
.
progress_cb
=
&
checkout_progress
;
g_options
.
checkout_opts
.
progress_payload
=
&
checkout_progress_cb_was_called
;
callbacks
.
transfer_progress
=
&
fetch_progress
;
callbacks
.
payload
=
&
fetch_progress_cb_was_called
;
g_options
.
remote_callbacks
=
&
callbacks
;
g_options
.
remote_callbacks
.
transfer_progress
=
&
fetch_progress
;
g_options
.
remote_callbacks
.
payload
=
&
fetch_progress_cb_was_called
;
cl_git_pass
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
...
...
@@ -175,12 +173,10 @@ static int update_tips(const char *refname, const git_oid *a, const git_oid *b,
void
test_online_clone__custom_remote_callbacks
(
void
)
{
git_remote_callbacks
remote_callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
int
callcount
=
0
;
g_options
.
remote_callbacks
=
&
remote_callbacks
;
remote_callbacks
.
update_tips
=
update_tips
;
remote_callbacks
.
payload
=
&
callcount
;
g_options
.
remote_callbacks
.
update_tips
=
update_tips
;
g_options
.
remote_callbacks
.
payload
=
&
callcount
;
cl_git_pass
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
cl_assert
(
callcount
>
0
);
...
...
@@ -194,13 +190,11 @@ void test_online_clone__credentials(void)
cl_getenv
(
"GITTEST_REMOTE_USER"
),
cl_getenv
(
"GITTEST_REMOTE_PASS"
)
};
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
if
(
!
remote_url
)
return
;
callbacks
.
credentials
=
git_cred_userpass
;
callbacks
.
payload
=
&
user_pass
;
g_options
.
remote_callbacks
=
&
callbacks
;
g_options
.
remote_callbacks
.
credentials
=
git_cred_userpass
;
g_options
.
remote_callbacks
.
payload
=
&
user_pass
;
cl_git_pass
(
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
git_repository_free
(
g_repo
);
g_repo
=
NULL
;
...
...
@@ -213,11 +207,8 @@ void test_online_clone__bitbucket_style(void)
"libgit2"
,
"libgit2"
};
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
callbacks
.
credentials
=
git_cred_userpass
;
callbacks
.
payload
=
&
user_pass
;
g_options
.
remote_callbacks
=
&
callbacks
;
g_options
.
remote_callbacks
.
credentials
=
git_cred_userpass
;
g_options
.
remote_callbacks
.
payload
=
&
user_pass
;
cl_git_pass
(
git_clone
(
&
g_repo
,
BB_REPO_URL
,
"./foo"
,
&
g_options
));
git_repository_free
(
g_repo
);
g_repo
=
NULL
;
...
...
@@ -247,10 +238,7 @@ static int cancel_at_half(const git_transfer_progress *stats, void *payload)
void
test_online_clone__can_cancel
(
void
)
{
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
callbacks
.
transfer_progress
=
cancel_at_half
;
g_options
.
remote_callbacks
=
&
callbacks
;
g_options
.
remote_callbacks
.
transfer_progress
=
cancel_at_half
;
cl_git_fail_with
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
),
GIT_EUSER
);
}
...
...
tests-clar/online/fetchhead.c
View file @
0e0cf787
...
...
@@ -12,10 +12,12 @@ static git_clone_options g_options;
void
test_online_fetchhead__initialize
(
void
)
{
git_remote_callbacks
dummy_callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
g_repo
=
NULL
;
memset
(
&
g_options
,
0
,
sizeof
(
git_clone_options
));
g_options
.
version
=
GIT_CLONE_OPTIONS_VERSION
;
g_options
.
remote_callbacks
=
dummy_callbacks
;
}
void
test_online_fetchhead__cleanup
(
void
)
...
...
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