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
f2a855d5
Commit
f2a855d5
authored
Jun 19, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clone: restructure.
parent
bb1f6087
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
16 deletions
+30
-16
src/clone.c
+25
-15
tests-clar/clone/clone.c
+5
-1
No files found.
src/clone.c
View file @
f2a855d5
...
@@ -19,8 +19,9 @@
...
@@ -19,8 +19,9 @@
GIT_BEGIN_DECL
GIT_BEGIN_DECL
static
int
git_checkout
(
git_repository
*
repo
,
git_commit
*
commit
,
git_indexer_stats
*
stats
)
static
int
git_checkout
_branch
(
git_repository
*
repo
,
const
char
*
branchname
)
{
{
/* TODO */
return
0
;
return
0
;
}
}
...
@@ -31,7 +32,9 @@ static int git_checkout(git_repository *repo, git_commit *commit, git_indexer_st
...
@@ -31,7 +32,9 @@ static int git_checkout(git_repository *repo, git_commit *commit, git_indexer_st
static
int
setup_remotes_and_fetch
(
git_repository
*
repo
,
const
char
*
origin_url
,
git_indexer_stats
*
stats
)
static
int
setup_remotes_and_fetch
(
git_repository
*
repo
,
const
char
*
origin_url
,
git_indexer_stats
*
stats
)
{
{
int
retcode
=
GIT_ERROR
;
int
retcode
=
GIT_ERROR
;
git_remote
*
origin
=
NULL
;
git_remote
*
origin
=
NULL
;
...
@@ -55,11 +58,15 @@ static int setup_remotes_and_fetch(git_repository *repo, const char *origin_url,
...
@@ -55,11 +58,15 @@ static int setup_remotes_and_fetch(git_repository *repo, const char *origin_url,
return
retcode
;
return
retcode
;
}
}
static
int
clone_internal
(
git_repository
**
out
,
const
char
*
origin_url
,
const
char
*
fullpath
,
git_indexer_stats
*
stats
,
int
is_bare
)
static
int
clone_internal
(
git_repository
**
out
,
const
char
*
origin_url
,
const
char
*
fullpath
,
git_indexer_stats
*
stats
,
int
is_bare
)
{
{
int
retcode
=
GIT_ERROR
;
int
retcode
=
GIT_ERROR
;
git_repository
*
repo
=
NULL
;
git_repository
*
repo
=
NULL
;
if
(
!
(
retcode
=
git_repository_init
(
&
repo
,
fullpath
,
is_bare
)))
{
if
(
!
(
retcode
=
git_repository_init
(
&
repo
,
fullpath
,
is_bare
)))
{
if
((
retcode
=
setup_remotes_and_fetch
(
repo
,
origin_url
,
stats
))
<
0
)
{
if
((
retcode
=
setup_remotes_and_fetch
(
repo
,
origin_url
,
stats
))
<
0
)
{
/* Failed to fetch; clean up */
/* Failed to fetch; clean up */
...
@@ -70,25 +77,31 @@ static int clone_internal(git_repository **out, const char *origin_url, const ch
...
@@ -70,25 +77,31 @@ static int clone_internal(git_repository **out, const char *origin_url, const ch
retcode
=
0
;
retcode
=
0
;
}
}
}
}
return
retcode
;
return
retcode
;
}
}
int
git_clone_bare
(
git_repository
**
out
,
const
char
*
origin_url
,
const
char
*
dest_path
,
git_indexer_stats
*
stats
)
int
git_clone_bare
(
git_repository
**
out
,
const
char
*
origin_url
,
const
char
*
dest_path
,
git_indexer_stats
*
stats
)
{
{
char
fullpath
[
512
]
=
{
0
};
char
fullpath
[
512
]
=
{
0
};
p_realpath
(
dest_path
,
fullpath
);
p_realpath
(
dest_path
,
fullpath
);
if
(
git_path_exists
(
fullpath
))
{
if
(
git_path_exists
(
fullpath
))
{
giterr_set
(
GITERR_INVALID
,
"Destination already exists: %s"
,
fullpath
);
giterr_set
(
GITERR_INVALID
,
"Destination already exists: %s"
,
fullpath
);
return
GIT_ERROR
;
return
GIT_ERROR
;
}
}
return
clone_internal
(
out
,
origin_url
,
fullpath
,
stats
,
1
);
return
clone_internal
(
out
,
origin_url
,
fullpath
,
stats
,
1
);
}
}
int
git_clone
(
git_repository
**
out
,
const
char
*
origin_url
,
const
char
*
workdir_path
,
git_indexer_stats
*
stats
)
int
git_clone
(
git_repository
**
out
,
const
char
*
origin_url
,
const
char
*
workdir_path
,
git_indexer_stats
*
stats
)
{
{
int
retcode
=
GIT_ERROR
;
int
retcode
=
GIT_ERROR
;
char
fullpath
[
512
]
=
{
0
};
char
fullpath
[
512
]
=
{
0
};
...
@@ -100,12 +113,9 @@ int git_clone(git_repository **out, const char *origin_url, const char *workdir_
...
@@ -100,12 +113,9 @@ int git_clone(git_repository **out, const char *origin_url, const char *workdir_
}
}
if
(
!
clone_internal
(
out
,
origin_url
,
workdir_path
,
stats
,
0
))
{
if
(
!
clone_internal
(
out
,
origin_url
,
workdir_path
,
stats
,
0
))
{
git_object
*
commit_to_checkout
=
NULL
;
char
default_branch_name
[
256
]
=
"master"
;
if
(
!
git_revparse_single
(
&
commit_to_checkout
,
*
out
,
"master"
))
{
/* TODO */
if
(
git_object_type
(
commit_to_checkout
)
==
GIT_OBJ_COMMIT
)
{
retcode
=
git_checkout_branch
(
*
out
,
default_branch_name
);
retcode
=
git_checkout
(
*
out
,
(
git_commit
*
)
commit_to_checkout
,
stats
);
}
}
}
}
return
retcode
;
return
retcode
;
...
...
tests-clar/clone/clone.c
View file @
f2a855d5
...
@@ -65,7 +65,7 @@ void test_clone_clone__bad_url(void)
...
@@ -65,7 +65,7 @@ void test_clone_clone__bad_url(void)
cl_git_fail
(
git_clone
(
&
g_repo
,
"not_a_repo"
,
"./foo"
,
NULL
));
cl_git_fail
(
git_clone
(
&
g_repo
,
"not_a_repo"
,
"./foo"
,
NULL
));
cl_assert
(
!
git_path_exists
(
"./foo"
));
cl_assert
(
!
git_path_exists
(
"./foo"
));
cl_git_fail
(
git_clone_bare
(
&
g_repo
,
"not_a_repo"
,
"./foo.git"
,
NULL
));
cl_git_fail
(
git_clone_bare
(
&
g_repo
,
"not_a_repo"
,
"./foo.git"
,
NULL
));
cl_assert
(
!
git_path_exists
(
"./foo"
));
cl_assert
(
!
git_path_exists
(
"./foo
.git
"
));
}
}
...
@@ -89,7 +89,11 @@ void test_clone_clone__network(void)
...
@@ -89,7 +89,11 @@ void test_clone_clone__network(void)
cl_git_pass
(
git_clone
(
&
g_repo
,
cl_git_pass
(
git_clone
(
&
g_repo
,
"https://github.com/libgit2/libgit2.git"
,
"https://github.com/libgit2/libgit2.git"
,
"./libgit2"
,
NULL
));
"./libgit2"
,
NULL
));
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_DIRREMOVAL_FILES_AND_DIRS
);
git_futils_rmdir_r
(
"./libgit2.git"
,
GIT_DIRREMOVAL_FILES_AND_DIRS
);
}
}
...
...
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