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
cab65c2b
Commit
cab65c2b
authored
Jul 05, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revparse: detect incorrect "refname@{-n}" syntax
parent
1decf88b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
16 deletions
+14
-16
src/revparse.c
+13
-16
tests-clar/refs/revparse.c
+1
-0
No files found.
src/revparse.c
View file @
cab65c2b
...
...
@@ -21,9 +21,10 @@ typedef enum {
REVPARSE_STATE_DONE
,
}
revparse_state
;
static
void
set_invalid_syntax_err
(
const
char
*
spec
)
static
int
revspec_error
(
const
char
*
rev
spec
)
{
giterr_set
(
GITERR_INVALID
,
"Refspec '%s' is not valid."
,
spec
);
giterr_set
(
GITERR_INVALID
,
"Failed to parse revision specifier - Invalid pattern '%s'"
,
revspec
);
return
-
1
;
}
static
int
revparse_lookup_fully_qualifed_ref
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
)
...
...
@@ -154,21 +155,19 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
size_t
reflogspeclen
=
strlen
(
reflogspec
);
if
(
git__prefixcmp
(
reflogspec
,
"@{"
)
!=
0
||
git__suffixcmp
(
reflogspec
,
"}"
)
!=
0
)
{
giterr_set
(
GITERR_INVALID
,
"Bad reflogspec '%s'"
,
reflogspec
);
return
GIT_ERROR
;
}
git__suffixcmp
(
reflogspec
,
"}"
)
!=
0
)
return
revspec_error
(
reflogspec
);
/* "@{-N}" form means walk back N checkouts. That means the HEAD log. */
if
(
refspeclen
==
0
&&
!
git__prefixcmp
(
reflogspec
,
"@{-"
))
{
if
(
!
git__prefixcmp
(
reflogspec
,
"@{-"
))
{
regex_t
regex
;
int
regex_error
;
if
(
git__strtol32
(
&
n
,
reflogspec
+
3
,
NULL
,
0
)
<
0
||
n
<
1
)
{
giterr_set
(
GITERR_INVALID
,
"Invalid reflogspec %s"
,
reflogspec
);
return
GIT_ERROR
;
}
if
(
refspeclen
>
0
)
return
revspec_error
(
reflogspec
);
if
(
git__strtol32
(
&
n
,
reflogspec
+
3
,
NULL
,
0
)
<
0
||
n
<
1
)
return
revspec_error
(
reflogspec
);
if
(
!
git_reference_lookup
(
&
ref
,
repo
,
"HEAD"
))
{
if
(
!
git_reflog_read
(
&
reflog
,
ref
))
{
...
...
@@ -373,10 +372,8 @@ static int handle_caret_syntax(git_object **out, git_repository *repo, git_objec
int
n
;
if
(
*
movement
==
'{'
)
{
if
(
movement
[
movementlen
-
1
]
!=
'}'
)
{
set_invalid_syntax_err
(
movement
);
return
GIT_ERROR
;
}
if
(
movement
[
movementlen
-
1
]
!=
'}'
)
return
revspec_error
(
movement
);
/* {} -> Dereference until we reach an object that isn't a tag. */
if
(
movementlen
==
2
)
{
...
...
tests-clar/refs/revparse.c
View file @
cab65c2b
...
...
@@ -133,6 +133,7 @@ void test_refs_revparse__reflog(void)
{
cl_git_fail
(
git_revparse_single
(
&
g_obj
,
g_repo
,
"@{-xyz}"
));
cl_git_fail
(
git_revparse_single
(
&
g_obj
,
g_repo
,
"@{-0}"
));
cl_git_fail
(
git_revparse_single
(
&
g_obj
,
g_repo
,
"master@{-2}"
));
cl_git_fail
(
git_revparse_single
(
&
g_obj
,
g_repo
,
"@{1000}"
));
test_object
(
"nope@{0}"
,
NULL
);
...
...
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