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
7192e26f
Unverified
Commit
7192e26f
authored
Jun 29, 2018
by
Patrick Steinhardt
Committed by
GitHub
Jun 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4519 from cynecx/refspec-parsing
refspec: add public parsing api
parents
967da2c7
630a6736
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
0 deletions
+54
-0
include/git2/refspec.h
+17
-0
src/refspec.c
+25
-0
tests/network/refspecs.c
+12
-0
No files found.
include/git2/refspec.h
View file @
7192e26f
...
...
@@ -22,6 +22,23 @@
GIT_BEGIN_DECL
/**
* Parse a given refspec string
*
* @param refspec a pointer to hold the refspec handle
* @param input the refspec string
* @param is_fetch is this a refspec for a fetch
* @return 0 if the refspec string could be parsed, -1 otherwise
*/
GIT_EXTERN
(
int
)
git_refspec_parse
(
git_refspec
**
refspec
,
const
char
*
input
,
int
is_fetch
);
/**
* Free a refspec object which has been created by git_refspec_parse
*
* @param refspec the refspec object
*/
GIT_EXTERN
(
void
)
git_refspec_free
(
git_refspec
*
refspec
);
/**
* Get the source specifier
*
* @param refspec the refspec
...
...
src/refspec.c
View file @
7192e26f
...
...
@@ -160,6 +160,31 @@ void git_refspec__free(git_refspec *refspec)
memset
(
refspec
,
0x0
,
sizeof
(
git_refspec
));
}
int
git_refspec_parse
(
git_refspec
**
out_refspec
,
const
char
*
input
,
int
is_fetch
)
{
git_refspec
*
refspec
;
assert
(
out_refspec
&&
input
);
*
out_refspec
=
NULL
;
refspec
=
git__malloc
(
sizeof
(
git_refspec
));
GITERR_CHECK_ALLOC
(
refspec
);
if
(
git_refspec__parse
(
refspec
,
input
,
!!
is_fetch
)
!=
0
)
{
git__free
(
refspec
);
return
-
1
;
}
*
out_refspec
=
refspec
;
return
0
;
}
void
git_refspec_free
(
git_refspec
*
refspec
)
{
git_refspec__free
(
refspec
);
git__free
(
refspec
);
}
const
char
*
git_refspec_src
(
const
git_refspec
*
refspec
)
{
return
refspec
==
NULL
?
NULL
:
refspec
->
src
;
...
...
tests/network/refspecs.c
View file @
7192e26f
...
...
@@ -158,3 +158,15 @@ void test_network_refspecs__matching(void)
git_refspec__free
(
&
spec
);
}
void
test_network_refspecs__parse_free
(
void
)
{
git_refspec
*
spec
=
NULL
;
cl_git_fail
(
git_refspec_parse
(
&
spec
,
""
,
0
));
cl_git_fail
(
git_refspec_parse
(
&
spec
,
":::"
,
0
));
cl_git_pass
(
git_refspec_parse
(
&
spec
,
"HEAD:"
,
1
));
cl_assert
(
spec
!=
NULL
);
git_refspec_free
(
spec
);
}
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