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
e3a92f0d
Commit
e3a92f0d
authored
Sep 17, 2013
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clone: implement git_clone on top of git_clone_into
Unify the code bases.
parent
c8dbec48
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
58 deletions
+19
-58
src/clone.c
+19
-58
No files found.
src/clone.c
View file @
e3a92f0d
...
@@ -310,12 +310,6 @@ static int create_and_configure_origin(
...
@@ -310,12 +310,6 @@ static int create_and_configure_origin(
if
((
error
=
git_remote_create
(
&
origin
,
repo
,
options
->
remote_name
,
url
))
<
0
)
if
((
error
=
git_remote_create
(
&
origin
,
repo
,
options
->
remote_name
,
url
))
<
0
)
goto
on_error
;
goto
on_error
;
/*
* Don't write FETCH_HEAD, we'll check out the remote tracking
* branch ourselves based on the server's default.
*/
git_remote_set_update_fetchhead
(
origin
,
0
);
if
(
options
->
remote_callbacks
&&
if
(
options
->
remote_callbacks
&&
(
error
=
git_remote_set_callbacks
(
origin
,
options
->
remote_callbacks
))
<
0
)
(
error
=
git_remote_set_callbacks
(
origin
,
options
->
remote_callbacks
))
<
0
)
goto
on_error
;
goto
on_error
;
...
@@ -349,43 +343,6 @@ on_error:
...
@@ -349,43 +343,6 @@ on_error:
return
error
;
return
error
;
}
}
static
int
setup_remotes_and_fetch
(
git_repository
*
repo
,
const
char
*
url
,
const
git_clone_options
*
options
)
{
int
retcode
=
GIT_ERROR
;
git_remote
*
origin
=
NULL
;
/* Construct an origin remote */
if
((
retcode
=
create_and_configure_origin
(
&
origin
,
repo
,
url
,
options
))
<
0
)
goto
on_error
;
git_remote_set_update_fetchhead
(
origin
,
0
);
/* Make sure to download all tags as well. It is set here because
* we want to download tags on the initial clone, but do not
* want to persist the value in the configuration file.
*/
if
((
retcode
=
git_remote_add_fetch
(
origin
,
"refs/tags/*:refs/tags/*"
))
<
0
)
goto
on_error
;
if
((
retcode
=
git_remote_fetch
(
origin
))
<
0
)
goto
on_error
;
/* Point HEAD to the requested branch */
if
(
options
->
checkout_branch
)
retcode
=
update_head_to_branch
(
repo
,
options
->
remote_name
,
options
->
checkout_branch
);
/* Point HEAD to the same ref as the remote's head */
else
retcode
=
update_head_to_remote
(
repo
,
origin
);
on_error:
git_remote_free
(
origin
);
return
retcode
;
}
static
bool
should_checkout
(
static
bool
should_checkout
(
git_repository
*
repo
,
git_repository
*
repo
,
bool
is_bare
,
bool
is_bare
,
...
@@ -467,6 +424,7 @@ int git_clone(
...
@@ -467,6 +424,7 @@ int git_clone(
{
{
int
retcode
=
GIT_ERROR
;
int
retcode
=
GIT_ERROR
;
git_repository
*
repo
=
NULL
;
git_repository
*
repo
=
NULL
;
git_remote
*
origin
;
git_clone_options
normOptions
;
git_clone_options
normOptions
;
int
remove_directory_on_failure
=
0
;
int
remove_directory_on_failure
=
0
;
git_repository_init_options
initOptions
=
GIT_REPOSITORY_INIT_OPTIONS_INIT
;
git_repository_init_options
initOptions
=
GIT_REPOSITORY_INIT_OPTIONS_INIT
;
...
@@ -486,24 +444,27 @@ int git_clone(
...
@@ -486,24 +444,27 @@ int git_clone(
/* Only remove the directory on failure if we create it */
/* Only remove the directory on failure if we create it */
remove_directory_on_failure
=
!
git_path_exists
(
local_path
);
remove_directory_on_failure
=
!
git_path_exists
(
local_path
);
if
(
!
(
retcode
=
git_repository_init_ext
(
&
repo
,
local_path
,
normOptions
.
init_options
)))
{
if
((
retcode
=
git_repository_init_ext
(
&
repo
,
local_path
,
normOptions
.
init_options
))
<
0
)
if
((
retcode
=
setup_remotes_and_fetch
(
repo
,
url
,
&
normOptions
))
<
0
)
{
return
retcode
;
/* Failed to fetch; clean up */
git_repository_free
(
repo
);
if
((
retcode
=
create_and_configure_origin
(
&
origin
,
repo
,
url
,
&
normOptions
))
<
0
)
goto
cleanup
;
if
(
remove_directory_on_failure
)
retcode
=
git_clone_into
(
repo
,
origin
,
&
normOptions
.
checkout_opts
,
normOptions
.
checkout_branch
);
git_futils_rmdir_r
(
local_path
,
NULL
,
GIT_RMDIR_REMOVE_FILES
);
git_remote_free
(
origin
);
else
git_futils_cleanupdir_r
(
local_path
);
}
else
{
if
(
retcode
<
0
)
*
out
=
repo
;
goto
cleanup
;
retcode
=
0
;
}
}
if
(
!
retcode
&&
should_checkout
(
repo
,
normOptions
.
bare
,
&
normOptions
.
checkout_opts
))
*
out
=
repo
;
retcode
=
git_checkout_head
(
*
out
,
&
normOptions
.
checkout_opts
);
return
0
;
cleanup:
git_repository_free
(
repo
);
if
(
remove_directory_on_failure
)
git_futils_rmdir_r
(
local_path
,
NULL
,
GIT_RMDIR_REMOVE_FILES
);
else
git_futils_cleanupdir_r
(
local_path
);
return
retcode
;
return
retcode
;
}
}
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