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
f672cd2a
Commit
f672cd2a
authored
May 10, 2013
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revparse: Make revparse_ext() return git_reference from names as well
parent
e841c533
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
16 deletions
+25
-16
src/revparse.c
+23
-14
tests-clar/refs/revparse.c
+2
-2
No files found.
src/revparse.c
View file @
f672cd2a
...
@@ -84,12 +84,16 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
...
@@ -84,12 +84,16 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
return
maybe_abbrev
(
out
,
repo
,
substr
+
2
);
return
maybe_abbrev
(
out
,
repo
,
substr
+
2
);
}
}
static
int
revparse_lookup_object
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
)
static
int
revparse_lookup_object
(
git_object
**
object_out
,
git_reference
**
reference_out
,
git_repository
*
repo
,
const
char
*
spec
)
{
{
int
error
;
int
error
;
git_reference
*
ref
;
git_reference
*
ref
;
error
=
maybe_sha
(
out
,
repo
,
spec
);
error
=
maybe_sha
(
o
bject_o
ut
,
repo
,
spec
);
if
(
!
error
)
if
(
!
error
)
return
0
;
return
0
;
...
@@ -98,22 +102,27 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
...
@@ -98,22 +102,27 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
error
=
git_reference_dwim
(
&
ref
,
repo
,
spec
);
error
=
git_reference_dwim
(
&
ref
,
repo
,
spec
);
if
(
!
error
)
{
if
(
!
error
)
{
error
=
git_object_lookup
(
out
,
repo
,
git_reference_target
(
ref
),
GIT_OBJ_ANY
);
git_reference_free
(
ref
);
error
=
git_object_lookup
(
object_out
,
repo
,
git_reference_target
(
ref
),
GIT_OBJ_ANY
);
if
(
!
error
)
*
reference_out
=
ref
;
return
error
;
return
error
;
}
}
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
error
;
return
error
;
error
=
maybe_abbrev
(
out
,
repo
,
spec
);
error
=
maybe_abbrev
(
o
bject_o
ut
,
repo
,
spec
);
if
(
!
error
)
if
(
!
error
)
return
0
;
return
0
;
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
error
;
return
error
;
error
=
maybe_describe
(
out
,
repo
,
spec
);
error
=
maybe_describe
(
o
bject_o
ut
,
repo
,
spec
);
if
(
!
error
)
if
(
!
error
)
return
0
;
return
0
;
...
@@ -609,7 +618,7 @@ static int object_from_reference(git_object **object, git_reference *reference)
...
@@ -609,7 +618,7 @@ static int object_from_reference(git_object **object, git_reference *reference)
return
error
;
return
error
;
}
}
static
int
ensure_base_rev_loaded
(
git_object
**
object
,
git_reference
*
reference
,
const
char
*
spec
,
size_t
identifier_len
,
git_repository
*
repo
,
bool
allow_empty_identifier
)
static
int
ensure_base_rev_loaded
(
git_object
**
object
,
git_reference
*
*
reference
,
const
char
*
spec
,
size_t
identifier_len
,
git_repository
*
repo
,
bool
allow_empty_identifier
)
{
{
int
error
;
int
error
;
git_buf
identifier
=
GIT_BUF_INIT
;
git_buf
identifier
=
GIT_BUF_INIT
;
...
@@ -617,8 +626,8 @@ static int ensure_base_rev_loaded(git_object **object, git_reference *reference,
...
@@ -617,8 +626,8 @@ static int ensure_base_rev_loaded(git_object **object, git_reference *reference,
if
(
*
object
!=
NULL
)
if
(
*
object
!=
NULL
)
return
0
;
return
0
;
if
(
reference
!=
NULL
)
if
(
*
reference
!=
NULL
)
return
object_from_reference
(
object
,
reference
);
return
object_from_reference
(
object
,
*
reference
);
if
(
!
allow_empty_identifier
&&
identifier_len
==
0
)
if
(
!
allow_empty_identifier
&&
identifier_len
==
0
)
return
GIT_EINVALIDSPEC
;
return
GIT_EINVALIDSPEC
;
...
@@ -626,7 +635,7 @@ static int ensure_base_rev_loaded(git_object **object, git_reference *reference,
...
@@ -626,7 +635,7 @@ static int ensure_base_rev_loaded(git_object **object, git_reference *reference,
if
(
git_buf_put
(
&
identifier
,
spec
,
identifier_len
)
<
0
)
if
(
git_buf_put
(
&
identifier
,
spec
,
identifier_len
)
<
0
)
return
-
1
;
return
-
1
;
error
=
revparse_lookup_object
(
object
,
repo
,
git_buf_cstr
(
&
identifier
));
error
=
revparse_lookup_object
(
object
,
re
ference
,
re
po
,
git_buf_cstr
(
&
identifier
));
git_buf_free
(
&
identifier
);
git_buf_free
(
&
identifier
);
return
error
;
return
error
;
...
@@ -684,7 +693,7 @@ int revparse__ext(
...
@@ -684,7 +693,7 @@ int revparse__ext(
while
(
spec
[
pos
])
{
while
(
spec
[
pos
])
{
switch
(
spec
[
pos
])
{
switch
(
spec
[
pos
])
{
case
'^'
:
case
'^'
:
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
reference
,
spec
,
identifier_len
,
repo
,
false
))
<
0
)
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
&
reference
,
spec
,
identifier_len
,
repo
,
false
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
(
spec
[
pos
+
1
]
==
'{'
)
{
if
(
spec
[
pos
+
1
]
==
'{'
)
{
...
@@ -719,7 +728,7 @@ int revparse__ext(
...
@@ -719,7 +728,7 @@ int revparse__ext(
if
((
error
=
extract_how_many
(
&
n
,
spec
,
&
pos
))
<
0
)
if
((
error
=
extract_how_many
(
&
n
,
spec
,
&
pos
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
reference
,
spec
,
identifier_len
,
repo
,
false
))
<
0
)
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
&
reference
,
spec
,
identifier_len
,
repo
,
false
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
((
error
=
handle_linear_syntax
(
&
temp_object
,
base_rev
,
n
))
<
0
)
if
((
error
=
handle_linear_syntax
(
&
temp_object
,
base_rev
,
n
))
<
0
)
...
@@ -738,7 +747,7 @@ int revparse__ext(
...
@@ -738,7 +747,7 @@ int revparse__ext(
goto
cleanup
;
goto
cleanup
;
if
(
any_left_hand_identifier
(
base_rev
,
reference
,
identifier_len
))
{
if
(
any_left_hand_identifier
(
base_rev
,
reference
,
identifier_len
))
{
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
reference
,
spec
,
identifier_len
,
repo
,
true
))
<
0
)
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
&
reference
,
spec
,
identifier_len
,
repo
,
true
))
<
0
)
goto
cleanup
;
goto
cleanup
;
if
((
error
=
handle_colon_syntax
(
&
temp_object
,
base_rev
,
git_buf_cstr
(
&
buf
)))
<
0
)
if
((
error
=
handle_colon_syntax
(
&
temp_object
,
base_rev
,
git_buf_cstr
(
&
buf
)))
<
0
)
...
@@ -795,7 +804,7 @@ int revparse__ext(
...
@@ -795,7 +804,7 @@ int revparse__ext(
}
}
}
}
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
reference
,
spec
,
identifier_len
,
repo
,
false
))
<
0
)
if
((
error
=
ensure_base_rev_loaded
(
&
base_rev
,
&
reference
,
spec
,
identifier_len
,
repo
,
false
))
<
0
)
goto
cleanup
;
goto
cleanup
;
*
object_out
=
base_rev
;
*
object_out
=
base_rev
;
...
...
tests-clar/refs/revparse.c
View file @
f672cd2a
...
@@ -732,10 +732,10 @@ void test_refs_revparse__ext_retrieves_both_the_reference_and_its_target(void)
...
@@ -732,10 +732,10 @@ void test_refs_revparse__ext_retrieves_both_the_reference_and_its_target(void)
"refs/heads/br2"
);
"refs/heads/br2"
);
}
}
void
test_refs_revparse__ext_
only_retrieve_the_object_target
(
void
)
void
test_refs_revparse__ext_
can_expand_short_reference_names
(
void
)
{
{
test_object_and_ref
(
test_object_and_ref
(
"master"
,
"master"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
NULL
);
"refs/heads/master"
);
}
}
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