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
e07c2d22
Commit
e07c2d22
authored
Feb 26, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #574 from carlosmn/remotes
Add git_remote_list()
parents
6b63589e
8171998f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
0 deletions
+98
-0
include/git2/remote.h
+11
-0
src/remote.c
+69
-0
tests-clar/network/remotes.c
+18
-0
No files found.
include/git2/remote.h
View file @
e07c2d22
...
@@ -197,6 +197,17 @@ GIT_EXTERN(int) git_remote_update_tips(git_remote *remote);
...
@@ -197,6 +197,17 @@ GIT_EXTERN(int) git_remote_update_tips(git_remote *remote);
*/
*/
GIT_EXTERN
(
int
)
git_remote_valid_url
(
const
char
*
url
);
GIT_EXTERN
(
int
)
git_remote_valid_url
(
const
char
*
url
);
/**
* Get a list of the configured remotes for a repo
*
* The string array must be freed by the user.
*
* @param remotes_list a string array with the names of the remotes
* @param repo the repository to query
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_remote_list
(
git_strarray
*
remotes_list
,
git_repository
*
repo
);
/** @} */
/** @} */
GIT_END_DECL
GIT_END_DECL
#endif
#endif
src/remote.c
View file @
e07c2d22
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
#include "fetch.h"
#include "fetch.h"
#include "refs.h"
#include "refs.h"
#include <regex.h>
static
int
refspec_parse
(
git_refspec
*
refspec
,
const
char
*
str
)
static
int
refspec_parse
(
git_refspec
*
refspec
,
const
char
*
str
)
{
{
char
*
delim
;
char
*
delim
;
...
@@ -423,3 +425,70 @@ void git_remote_free(git_remote *remote)
...
@@ -423,3 +425,70 @@ void git_remote_free(git_remote *remote)
git_remote_disconnect
(
remote
);
git_remote_disconnect
(
remote
);
git__free
(
remote
);
git__free
(
remote
);
}
}
struct
cb_data
{
git_vector
*
list
;
regex_t
*
preg
;
};
static
int
remote_list_cb
(
const
char
*
name
,
const
char
*
GIT_UNUSED
(
value
),
void
*
data_
)
{
struct
cb_data
*
data
=
(
struct
cb_data
*
)
data_
;
size_t
nmatch
=
2
;
regmatch_t
pmatch
[
2
];
int
error
;
GIT_UNUSED_ARG
(
value
);
if
(
!
regexec
(
data
->
preg
,
name
,
nmatch
,
pmatch
,
0
))
{
char
*
remote_name
=
git__strndup
(
&
name
[
pmatch
[
1
].
rm_so
],
pmatch
[
1
].
rm_eo
-
pmatch
[
1
].
rm_so
);
if
(
remote_name
==
NULL
)
return
GIT_ENOMEM
;
error
=
git_vector_insert
(
data
->
list
,
remote_name
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
}
return
GIT_SUCCESS
;
}
int
git_remote_list
(
git_strarray
*
remotes_list
,
git_repository
*
repo
)
{
git_config
*
cfg
;
git_vector
list
;
regex_t
preg
;
struct
cb_data
data
;
int
error
;
error
=
git_repository_config__weakptr
(
&
cfg
,
repo
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
error
=
git_vector_init
(
&
list
,
4
,
NULL
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
error
=
regcomp
(
&
preg
,
"^remote
\\
.(.*)
\\
.url$"
,
REG_EXTENDED
);
if
(
error
<
0
)
return
GIT_EOSERR
;
data
.
list
=
&
list
;
data
.
preg
=
&
preg
;
error
=
git_config_foreach
(
cfg
,
remote_list_cb
,
&
data
);
regfree
(
&
preg
);
if
(
error
<
GIT_SUCCESS
)
{
size_t
i
;
char
*
elem
;
git_vector_foreach
(
&
list
,
i
,
elem
)
{
free
(
elem
);
}
git_vector_free
(
&
list
);
return
error
;
}
remotes_list
->
strings
=
(
char
**
)
list
.
contents
;
remotes_list
->
count
=
list
.
length
;
return
GIT_SUCCESS
;
}
tests-clar/network/remotes.c
View file @
e07c2d22
...
@@ -114,3 +114,21 @@ void test_network_remotes__missing_refspecs(void)
...
@@ -114,3 +114,21 @@ void test_network_remotes__missing_refspecs(void)
git_config_free
(
cfg
);
git_config_free
(
cfg
);
}
}
void
test_network_remotes__list
(
void
)
{
git_strarray
list
;
git_config
*
cfg
;
cl_git_pass
(
git_remote_list
(
&
list
,
_repo
));
cl_assert
(
list
.
count
==
1
);
git_strarray_free
(
&
list
);
cl_git_pass
(
git_repository_config
(
&
cfg
,
_repo
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"remote.specless.url"
,
"http://example.com"
));
cl_git_pass
(
git_remote_list
(
&
list
,
_repo
));
cl_assert
(
list
.
count
==
2
);
git_strarray_free
(
&
list
);
git_config_free
(
cfg
);
}
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