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
90befde4
Commit
90befde4
authored
Jun 03, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2399 from libgit2/cmn/path-to-path
clone: re-use the local transport's path resolution
parents
dfcba09e
18d7896c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
35 deletions
+26
-35
src/clone.c
+3
-15
src/path.c
+18
-0
src/path.h
+3
-0
src/transports/local.c
+2
-20
No files found.
src/clone.c
View file @
90befde4
...
@@ -472,11 +472,10 @@ static bool can_link(const char *src, const char *dst, int link)
...
@@ -472,11 +472,10 @@ static bool can_link(const char *src, const char *dst, int link)
int
git_clone_local_into
(
git_repository
*
repo
,
git_remote
*
remote
,
const
git_checkout_options
*
co_opts
,
const
char
*
branch
,
int
link
,
const
git_signature
*
signature
)
int
git_clone_local_into
(
git_repository
*
repo
,
git_remote
*
remote
,
const
git_checkout_options
*
co_opts
,
const
char
*
branch
,
int
link
,
const
git_signature
*
signature
)
{
{
int
error
,
root
,
flags
;
int
error
,
flags
;
git_repository
*
src
;
git_repository
*
src
;
git_buf
src_odb
=
GIT_BUF_INIT
,
dst_odb
=
GIT_BUF_INIT
,
src_path
=
GIT_BUF_INIT
;
git_buf
src_odb
=
GIT_BUF_INIT
,
dst_odb
=
GIT_BUF_INIT
,
src_path
=
GIT_BUF_INIT
;
git_buf
reflog_message
=
GIT_BUF_INIT
;
git_buf
reflog_message
=
GIT_BUF_INIT
;
const
char
*
url
;
assert
(
repo
&&
remote
);
assert
(
repo
&&
remote
);
...
@@ -490,19 +489,8 @@ int git_clone_local_into(git_repository *repo, git_remote *remote, const git_che
...
@@ -490,19 +489,8 @@ int git_clone_local_into(git_repository *repo, git_remote *remote, const git_che
* repo, if it's not rooted, the path should be relative to
* repo, if it's not rooted, the path should be relative to
* the repository's worktree/gitdir.
* the repository's worktree/gitdir.
*/
*/
url
=
git_remote_url
(
remote
);
if
((
error
=
git_path_from_url_or_path
(
&
src_path
,
git_remote_url
(
remote
)))
<
0
)
if
(
!
git__prefixcmp
(
url
,
"file://"
))
return
error
;
root
=
strlen
(
"file://"
);
else
root
=
git_path_root
(
url
);
if
(
root
>=
0
)
git_buf_puts
(
&
src_path
,
url
+
root
);
else
git_buf_joinpath
(
&
src_path
,
repository_base
(
repo
),
url
);
if
(
git_buf_oom
(
&
src_path
))
return
-
1
;
/* Copy .git/objects/ from the source to the target */
/* Copy .git/objects/ from the source to the target */
if
((
error
=
git_repository_open
(
&
src
,
git_buf_cstr
(
&
src_path
)))
<
0
)
{
if
((
error
=
git_repository_open
(
&
src
,
git_buf_cstr
(
&
src_path
)))
<
0
)
{
...
...
src/path.c
View file @
90befde4
...
@@ -1127,3 +1127,21 @@ int git_path_dirload_with_stat(
...
@@ -1127,3 +1127,21 @@ int git_path_dirload_with_stat(
return
error
;
return
error
;
}
}
int
git_path_from_url_or_path
(
git_buf
*
local_path_out
,
const
char
*
url_or_path
)
{
int
error
;
/* If url_or_path begins with file:// treat it as a URL */
if
(
!
git__prefixcmp
(
url_or_path
,
"file://"
))
{
if
((
error
=
git_path_fromurl
(
local_path_out
,
url_or_path
))
<
0
)
{
return
error
;
}
}
else
{
/* We assume url_or_path is already a path */
if
((
error
=
git_buf_sets
(
local_path_out
,
url_or_path
))
<
0
)
{
return
error
;
}
}
return
0
;
}
src/path.h
View file @
90befde4
...
@@ -438,4 +438,7 @@ extern int git_path_iconv(git_path_iconv_t *ic, char **in, size_t *inlen);
...
@@ -438,4 +438,7 @@ extern int git_path_iconv(git_path_iconv_t *ic, char **in, size_t *inlen);
extern
bool
git_path_does_fs_decompose_unicode
(
const
char
*
root
);
extern
bool
git_path_does_fs_decompose_unicode
(
const
char
*
root
);
/* Used for paths to repositories on the filesystem */
extern
int
git_path_from_url_or_path
(
git_buf
*
local_path_out
,
const
char
*
url_or_path
);
#endif
#endif
src/transports/local.c
View file @
90befde4
...
@@ -175,24 +175,6 @@ on_error:
...
@@ -175,24 +175,6 @@ on_error:
return
-
1
;
return
-
1
;
}
}
static
int
path_from_url_or_path
(
git_buf
*
local_path_out
,
const
char
*
url_or_path
)
{
int
error
;
/* If url_or_path begins with file:// treat it as a URL */
if
(
!
git__prefixcmp
(
url_or_path
,
"file://"
))
{
if
((
error
=
git_path_fromurl
(
local_path_out
,
url_or_path
))
<
0
)
{
return
error
;
}
}
else
{
/* We assume url_or_path is already a path */
if
((
error
=
git_buf_sets
(
local_path_out
,
url_or_path
))
<
0
)
{
return
error
;
}
}
return
0
;
}
/*
/*
* Try to open the url as a git directory. The direction doesn't
* Try to open the url as a git directory. The direction doesn't
* matter in this case because we're calculating the heads ourselves.
* matter in this case because we're calculating the heads ourselves.
...
@@ -222,7 +204,7 @@ static int local_connect(
...
@@ -222,7 +204,7 @@ static int local_connect(
t
->
flags
=
flags
;
t
->
flags
=
flags
;
/* 'url' may be a url or path; convert to a path */
/* 'url' may be a url or path; convert to a path */
if
((
error
=
path_from_url_or_path
(
&
buf
,
url
))
<
0
)
{
if
((
error
=
git_
path_from_url_or_path
(
&
buf
,
url
))
<
0
)
{
git_buf_free
(
&
buf
);
git_buf_free
(
&
buf
);
return
error
;
return
error
;
}
}
...
@@ -386,7 +368,7 @@ static int local_push(
...
@@ -386,7 +368,7 @@ static int local_push(
size_t
j
;
size_t
j
;
/* 'push->remote->url' may be a url or path; convert to a path */
/* 'push->remote->url' may be a url or path; convert to a path */
if
((
error
=
path_from_url_or_path
(
&
buf
,
push
->
remote
->
url
))
<
0
)
{
if
((
error
=
git_
path_from_url_or_path
(
&
buf
,
push
->
remote
->
url
))
<
0
)
{
git_buf_free
(
&
buf
);
git_buf_free
(
&
buf
);
return
error
;
return
error
;
}
}
...
...
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