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
58448910
Commit
58448910
authored
Feb 29, 2012
by
Ryan Wilcox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement support for username@host:path URLs in transport_find_fn()
parent
17b3d9b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
+35
-3
src/transport.c
+25
-3
tests-clar/network/remotes.c
+10
-0
No files found.
src/transport.c
View file @
58448910
...
...
@@ -10,6 +10,8 @@
#include "git2/net.h"
#include "transport.h"
#include <regex.h>
static
struct
{
char
*
prefix
;
git_transport_cb
fn
;
...
...
@@ -28,15 +30,35 @@ static struct {
static
git_transport_cb
transport_find_fn
(
const
char
*
url
)
{
size_t
i
=
0
;
regex_t
preg
;
int
error
;
git_transport_cb
output
=
NULL
;
/* TODO: Parse "example.com:project.git" as an SSH URL */
// First, check to see if it's an obvious URL, which a URL scheme
for
(
i
=
0
;
i
<
GIT_TRANSPORT_COUNT
;
++
i
)
{
if
(
!
strncasecmp
(
url
,
transports
[
i
].
prefix
,
strlen
(
transports
[
i
].
prefix
)))
return
transports
[
i
].
fn
;
}
return
NULL
;
// next, see if it matches un-schemed SSH paths used by Git
// if it does not match, it must be a local transport method
// use the slightly old fashioned :alnum: instead of \w or :word:, because
// both are Perl extensions to the Regular Expression language (and not available here)
error
=
regcomp
(
&
preg
,
"^[[:alnum:]_]+@[[:alnum:]_]+
\\
.[[:alnum:]_]+:.+
\\
.git$"
,
REG_EXTENDED
);
if
(
error
<
0
)
goto
cleanup
;
int
rc
=
regexec
(
&
preg
,
url
,
0
,
NULL
,
0
);
if
(
rc
==
REG_NOMATCH
)
output
=
NULL
;
// a match was not found - it's probably a file system path
else
output
=
&
git_transport_git
;
// a match was found!
cleanup:
regfree
(
&
preg
);
return
output
;
}
/**************
...
...
tests-clar/network/remotes.c
View file @
58448910
...
...
@@ -30,6 +30,16 @@ void test_network_remotes__parsing(void)
cl_assert
(
!
strcmp
(
git_remote_url
(
_remote
),
"git://github.com/libgit2/libgit2"
));
}
void
test_network_remotes__parsing_ssh_remote
(
void
)
{
cl_assert
(
git_remote_valid_url
(
"git@github.com:libgit2/libgit2.git"
)
);
}
void
test_network_remotes__parsing_local_path
(
void
)
{
cl_assert
(
!
git_remote_valid_url
(
"/home/git/repos/libgit2.git"
)
);
}
void
test_network_remotes__refspec_parsing
(
void
)
{
cl_assert
(
!
strcmp
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
));
...
...
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