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
119bdd86
Commit
119bdd86
authored
May 20, 2017
by
Carlos Martín Nieto
Committed by
GitHub
May 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4231 from wabain/open-revrange
revparse: support open-ended ranges
parents
924f5d12
8b107dc5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
3 deletions
+57
-3
src/revparse.c
+22
-3
tests/refs/revparse.c
+35
-0
No files found.
src/revparse.c
View file @
119bdd86
...
@@ -892,6 +892,17 @@ int git_revparse(
...
@@ -892,6 +892,17 @@ int git_revparse(
const
char
*
rstr
;
const
char
*
rstr
;
revspec
->
flags
=
GIT_REVPARSE_RANGE
;
revspec
->
flags
=
GIT_REVPARSE_RANGE
;
/*
* Following git.git, don't allow '..' because it makes command line
* arguments which can be either paths or revisions ambiguous when the
* path is almost certainly intended. The empty range '...' is still
* allowed.
*/
if
(
!
git__strcmp
(
spec
,
".."
))
{
giterr_set
(
GITERR_INVALID
,
"Invalid pattern '..'"
);
return
GIT_EINVALIDSPEC
;
}
lstr
=
git__substrdup
(
spec
,
dotdot
-
spec
);
lstr
=
git__substrdup
(
spec
,
dotdot
-
spec
);
rstr
=
dotdot
+
2
;
rstr
=
dotdot
+
2
;
if
(
dotdot
[
2
]
==
'.'
)
{
if
(
dotdot
[
2
]
==
'.'
)
{
...
@@ -899,9 +910,17 @@ int git_revparse(
...
@@ -899,9 +910,17 @@ int git_revparse(
rstr
++
;
rstr
++
;
}
}
error
=
git_revparse_single
(
&
revspec
->
from
,
repo
,
lstr
);
error
=
git_revparse_single
(
if
(
!
error
)
&
revspec
->
from
,
error
=
git_revparse_single
(
&
revspec
->
to
,
repo
,
rstr
);
repo
,
*
lstr
==
'\0'
?
"HEAD"
:
lstr
);
if
(
!
error
)
{
error
=
git_revparse_single
(
&
revspec
->
to
,
repo
,
*
rstr
==
'\0'
?
"HEAD"
:
rstr
);
}
git__free
((
void
*
)
lstr
);
git__free
((
void
*
)
lstr
);
}
else
{
}
else
{
...
...
tests/refs/revparse.c
View file @
119bdd86
...
@@ -122,6 +122,14 @@ static void test_id(
...
@@ -122,6 +122,14 @@ static void test_id(
test_id_inrepo
(
spec
,
expected_left
,
expected_right
,
expected_flags
,
g_repo
);
test_id_inrepo
(
spec
,
expected_left
,
expected_right
,
expected_flags
,
g_repo
);
}
}
static
void
test_invalid_revspec
(
const
char
*
invalid_spec
)
{
git_revspec
revspec
;
cl_assert_equal_i
(
GIT_EINVALIDSPEC
,
git_revparse
(
&
revspec
,
g_repo
,
invalid_spec
));
}
void
test_refs_revparse__initialize
(
void
)
void
test_refs_revparse__initialize
(
void
)
{
{
cl_git_pass
(
git_repository_open
(
&
g_repo
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_repository_open
(
&
g_repo
,
cl_fixture
(
"testrepo.git"
)));
...
@@ -749,6 +757,33 @@ void test_refs_revparse__parses_range_operator(void)
...
@@ -749,6 +757,33 @@ void test_refs_revparse__parses_range_operator(void)
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
GIT_REVPARSE_RANGE
|
GIT_REVPARSE_MERGE_BASE
);
GIT_REVPARSE_RANGE
|
GIT_REVPARSE_MERGE_BASE
);
test_id
(
"HEAD~3.."
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
GIT_REVPARSE_RANGE
);
test_id
(
"HEAD~3..."
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
GIT_REVPARSE_RANGE
|
GIT_REVPARSE_MERGE_BASE
);
test_id
(
"..HEAD~3"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
GIT_REVPARSE_RANGE
);
test_id
(
"...HEAD~3"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
,
GIT_REVPARSE_RANGE
|
GIT_REVPARSE_MERGE_BASE
);
test_id
(
"..."
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
GIT_REVPARSE_RANGE
|
GIT_REVPARSE_MERGE_BASE
);
test_invalid_revspec
(
".."
);
}
}
void
test_refs_revparse__ext_retrieves_both_the_reference_and_its_target
(
void
)
void
test_refs_revparse__ext_retrieves_both_the_reference_and_its_target
(
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