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
8340dd5d
Commit
8340dd5d
authored
Jun 20, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clone: remove fragile path-handling code.
Also standardized on 3-space indentation. Sorry about that.
parent
da73fb70
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
26 deletions
+39
-26
src/clone.c
+31
-24
tests-clar/clone/clone.c
+8
-2
No files found.
src/clone.c
View file @
8340dd5d
...
...
@@ -19,12 +19,25 @@
GIT_BEGIN_DECL
static
int
git_checkout_
branch
(
git_repository
*
repo
,
const
char
*
branchname
)
static
int
git_checkout_
force
(
git_repository
*
repo
)
{
/* TODO */
return
0
;
}
static
int
update_head_to_remote
(
git_repository
*
repo
,
git_remote
*
remote
)
{
int
retcode
=
0
;
/* Get the remote's HEAD. This is always the first ref in remote->refs. */
git_buf
remote_default_branch
=
GIT_BUF_INIT
;
/* TODO */
git_buf_free
(
&
remote_default_branch
);
return
retcode
;
}
/*
* submodules?
* filemodes?
...
...
@@ -43,13 +56,19 @@ static int setup_remotes_and_fetch(git_repository *repo,
if
(
!
stats
)
stats
=
&
dummy_stats
;
/* Create the "origin" remote */
if
(
!
git_remote_add
(
&
origin
,
repo
,
"origin"
,
origin_url
))
{
/* Connect and download everything */
if
(
!
git_remote_connect
(
origin
,
GIT_DIR_FETCH
))
{
if
(
!
git_remote_download
(
origin
,
&
bytes
,
stats
))
{
/* Create "origin/foo" branches for all remote branches */
if
(
!
git_remote_update_tips
(
origin
,
NULL
))
{
/* Point HEAD to the same ref as the remote's head */
if
(
!
update_head_to_remote
(
repo
,
origin
))
{
retcode
=
0
;
}
}
}
git_remote_disconnect
(
origin
);
}
git_remote_free
(
origin
);
...
...
@@ -60,18 +79,23 @@ static int setup_remotes_and_fetch(git_repository *repo,
static
int
clone_internal
(
git_repository
**
out
,
const
char
*
origin_url
,
const
char
*
full
path
,
const
char
*
path
,
git_indexer_stats
*
stats
,
int
is_bare
)
{
int
retcode
=
GIT_ERROR
;
git_repository
*
repo
=
NULL
;
if
(
!
(
retcode
=
git_repository_init
(
&
repo
,
fullpath
,
is_bare
)))
{
if
(
git_path_exists
(
path
))
{
giterr_set
(
GITERR_INVALID
,
"Path '%s' already exists."
,
path
);
return
GIT_ERROR
;
}
if
(
!
(
retcode
=
git_repository_init
(
&
repo
,
path
,
is_bare
)))
{
if
((
retcode
=
setup_remotes_and_fetch
(
repo
,
origin_url
,
stats
))
<
0
)
{
/* Failed to fetch; clean up */
git_repository_free
(
repo
);
git_futils_rmdir_r
(
full
path
,
GIT_DIRREMOVAL_FILES_AND_DIRS
);
git_futils_rmdir_r
(
path
,
GIT_DIRREMOVAL_FILES_AND_DIRS
);
}
else
{
*
out
=
repo
;
retcode
=
0
;
...
...
@@ -86,15 +110,7 @@ int git_clone_bare(git_repository **out,
const
char
*
dest_path
,
git_indexer_stats
*
stats
)
{
char
fullpath
[
512
]
=
{
0
};
p_realpath
(
dest_path
,
fullpath
);
if
(
git_path_exists
(
fullpath
))
{
giterr_set
(
GITERR_INVALID
,
"Destination already exists: %s"
,
fullpath
);
return
GIT_ERROR
;
}
return
clone_internal
(
out
,
origin_url
,
fullpath
,
stats
,
1
);
return
clone_internal
(
out
,
origin_url
,
dest_path
,
stats
,
1
);
}
...
...
@@ -104,18 +120,9 @@ int git_clone(git_repository **out,
git_indexer_stats
*
stats
)
{
int
retcode
=
GIT_ERROR
;
char
fullpath
[
512
]
=
{
0
};
p_realpath
(
workdir_path
,
fullpath
);
if
(
git_path_exists
(
fullpath
))
{
giterr_set
(
GITERR_INVALID
,
"Destination already exists: %s"
,
fullpath
);
return
GIT_ERROR
;
}
if
(
!
clone_internal
(
out
,
origin_url
,
workdir_path
,
stats
,
0
))
{
char
default_branch_name
[
256
]
=
"master"
;
/* TODO */
retcode
=
git_checkout_branch
(
*
out
,
default_branch_name
);
if
(
!
(
retcode
=
clone_internal
(
out
,
origin_url
,
workdir_path
,
stats
,
0
)))
{
retcode
=
git_checkout_force
(
*
out
);
}
return
retcode
;
...
...
tests-clar/clone/clone.c
View file @
8340dd5d
...
...
@@ -86,16 +86,22 @@ void test_clone_clone__local(void)
}
void
test_clone_clone__network
(
void
)
void
test_clone_clone__network
_full
(
void
)
{
#if 0
cl_git_pass(git_clone(&g_repo,
"https://github.com/libgit2/libgit2.git",
"./libgit2", NULL));
git_futils_rmdir_r("./libgit2", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif
}
void
test_clone_clone__network_bare
(
void
)
{
#if 0
cl_git_pass(git_clone_bare(&g_repo,
"https://github.com/libgit2/libgit2.git",
"./libgit2.git", NULL));
git_futils_rmdir_r("./libgit2", GIT_DIRREMOVAL_FILES_AND_DIRS);
git_futils_rmdir_r("./libgit2.git", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif
}
...
...
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