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
89e05e2a
Commit
89e05e2a
authored
Sep 03, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2543 from libgit2/cmn/known-transports
Clean up transport lookup
parents
4c958046
05ac7051
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
56 deletions
+23
-56
include/git2/remote.h
+5
-8
src/transport.c
+4
-32
tests/network/remote/remotes.c
+14
-16
No files found.
include/git2/remote.h
View file @
89e05e2a
...
@@ -384,15 +384,12 @@ GIT_EXTERN(int) git_remote_fetch(
...
@@ -384,15 +384,12 @@ GIT_EXTERN(int) git_remote_fetch(
const
char
*
reflog_message
);
const
char
*
reflog_message
);
/**
/**
* Return whether a string is a valid remote URL
*
*
* @param url the url to check
* Return whether the library supports a particular URL scheme
* @return 1 if the url is valid, 0 otherwise
*
*/
* Both the built-in and externally-registered transport lists are
GIT_EXTERN
(
int
)
git_remote_valid_url
(
const
char
*
url
);
* searched for a transport which supports the scheme of the given
* URL.
/**
* Return whether the passed URL is supported by this version of the library.
*
*
* @param url the url to check
* @param url the url to check
* @return 1 if the url is supported, 0 otherwise
* @return 1 if the url is supported, 0 otherwise
...
...
src/transport.c
View file @
89e05e2a
...
@@ -25,16 +25,13 @@ static git_smart_subtransport_definition ssh_subtransport_definition = { git_sma
...
@@ -25,16 +25,13 @@ static git_smart_subtransport_definition ssh_subtransport_definition = { git_sma
#endif
#endif
static
transport_definition
local_transport_definition
=
{
"file://"
,
git_transport_local
,
NULL
};
static
transport_definition
local_transport_definition
=
{
"file://"
,
git_transport_local
,
NULL
};
#ifdef GIT_SSH
static
transport_definition
ssh_transport_definition
=
{
"ssh://"
,
git_transport_smart
,
&
ssh_subtransport_definition
};
#else
static
transport_definition
dummy_transport_definition
=
{
NULL
,
git_transport_dummy
,
NULL
};
#endif
static
transport_definition
transports
[]
=
{
static
transport_definition
transports
[]
=
{
{
"git://"
,
git_transport_smart
,
&
git_subtransport_definition
},
{
"git://"
,
git_transport_smart
,
&
git_subtransport_definition
},
{
"http://"
,
git_transport_smart
,
&
http_subtransport_definition
},
{
"http://"
,
git_transport_smart
,
&
http_subtransport_definition
},
#if defined(GIT_SSL) || defined(GIT_WINHTTP)
{
"https://"
,
git_transport_smart
,
&
http_subtransport_definition
},
{
"https://"
,
git_transport_smart
,
&
http_subtransport_definition
},
#endif
{
"file://"
,
git_transport_local
,
NULL
},
{
"file://"
,
git_transport_local
,
NULL
},
#ifdef GIT_SSH
#ifdef GIT_SSH
{
"ssh://"
,
git_transport_smart
,
&
ssh_subtransport_definition
},
{
"ssh://"
,
git_transport_smart
,
&
ssh_subtransport_definition
},
...
@@ -95,11 +92,6 @@ static int transport_find_fn(
...
@@ -95,11 +92,6 @@ static int transport_find_fn(
if
(
!
definition
&&
strrchr
(
url
,
':'
))
{
if
(
!
definition
&&
strrchr
(
url
,
':'
))
{
// re-search transports again with ssh:// as url so that we can find a third party ssh transport
// re-search transports again with ssh:// as url so that we can find a third party ssh transport
definition
=
transport_find_by_url
(
"ssh://"
);
definition
=
transport_find_by_url
(
"ssh://"
);
#ifndef GIT_SSH
if
(
!
definition
)
{
definition
=
&
dummy_transport_definition
;
}
#endif
}
}
#ifndef GIT_WIN32
#ifndef GIT_WIN32
...
@@ -121,15 +113,6 @@ static int transport_find_fn(
...
@@ -121,15 +113,6 @@ static int transport_find_fn(
* Public API *
* Public API *
**************/
**************/
int
git_transport_dummy
(
git_transport
**
transport
,
git_remote
*
owner
,
void
*
param
)
{
GIT_UNUSED
(
transport
);
GIT_UNUSED
(
owner
);
GIT_UNUSED
(
param
);
giterr_set
(
GITERR_NET
,
"This transport isn't implemented. Sorry"
);
return
-
1
;
}
int
git_transport_new
(
git_transport
**
out
,
git_remote
*
owner
,
const
char
*
url
)
int
git_transport_new
(
git_transport
**
out
,
git_remote
*
owner
,
const
char
*
url
)
{
{
git_transport_cb
fn
;
git_transport_cb
fn
;
...
@@ -229,24 +212,13 @@ done:
...
@@ -229,24 +212,13 @@ done:
return
error
;
return
error
;
}
}
/* from remote.h */
int
git_remote_valid_url
(
const
char
*
url
)
{
git_transport_cb
fn
;
void
*
param
;
return
!
transport_find_fn
(
&
fn
,
url
,
&
param
);
}
int
git_remote_supported_url
(
const
char
*
url
)
int
git_remote_supported_url
(
const
char
*
url
)
{
{
git_transport_cb
fn
;
git_transport_cb
fn
;
void
*
param
;
void
*
param
;
if
(
transport_find_fn
(
&
fn
,
url
,
&
param
)
<
0
)
/* The only error we expect is ENOTFOUND */
return
0
;
return
!
transport_find_fn
(
&
fn
,
url
,
&
param
);
return
fn
!=
&
git_transport_dummy
;
}
}
int
git_transport_init
(
git_transport
*
opts
,
unsigned
int
version
)
int
git_transport_init
(
git_transport
*
opts
,
unsigned
int
version
)
...
...
tests/network/remote/remotes.c
View file @
89e05e2a
...
@@ -91,26 +91,24 @@ void test_network_remote_remotes__error_when_no_push_available(void)
...
@@ -91,26 +91,24 @@ void test_network_remote_remotes__error_when_no_push_available(void)
git_remote_free
(
r
);
git_remote_free
(
r
);
}
}
void
test_network_remote_remotes__
parsing_ssh_remote
(
void
)
void
test_network_remote_remotes__
supported_urls
(
void
)
{
{
cl_assert
(
git_remote_valid_url
(
"git@github.com:libgit2/libgit2.git"
)
);
int
ssh_supported
=
0
,
https_supported
=
0
;
}
void
test_network_remote_remotes__parsing_local_path_fails_if_path_not_found
(
void
)
#ifdef GIT_SSH
{
ssh_supported
=
1
;
cl_assert
(
!
git_remote_valid_url
(
"/home/git/repos/libgit2.git"
)
);
#endif
}
void
test_network_remote_remotes__supported_transport_methods_are_supported
(
void
)
{
cl_assert
(
git_remote_supported_url
(
"git://github.com/libgit2/libgit2"
)
);
}
void
test_network_remote_remotes__unsupported_transport_methods_are_unsupported
(
void
)
#if defined(GIT_SSL) || defined(GIT_WINHTTP)
{
https_supported
=
1
;
#ifndef GIT_SSH
cl_assert
(
!
git_remote_supported_url
(
"git@github.com:libgit2/libgit2.git"
)
);
#endif
#endif
cl_assert
(
git_remote_supported_url
(
"git://github.com/libgit2/libgit2"
));
cl_assert
(
git_remote_supported_url
(
"http://github.com/libgit2/libgit2"
));
cl_assert_equal_i
(
ssh_supported
,
git_remote_supported_url
(
"git@github.com:libgit2/libgit2.git"
));
cl_assert_equal_i
(
ssh_supported
,
git_remote_supported_url
(
"ssh://git@github.com/libgit2/libgit2.git"
));
cl_assert_equal_i
(
https_supported
,
git_remote_supported_url
(
"https://github.com/libgit2/libgit2.git"
));
}
}
void
test_network_remote_remotes__refspec_parsing
(
void
)
void
test_network_remote_remotes__refspec_parsing
(
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