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
0e8e5a61
Commit
0e8e5a61
authored
Feb 03, 2013
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revparse: Lookup sha before branch
parent
545b479a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
6 deletions
+103
-6
src/revparse.c
+29
-6
tests-clar/refs/revparse.c
+74
-0
No files found.
src/revparse.c
View file @
0e8e5a61
...
...
@@ -67,10 +67,9 @@ cleanup:
return
error
;
}
static
int
maybe_sha_or_abbrev
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
)
static
int
maybe_sha_or_abbrev
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
,
size_t
speclen
)
{
git_oid
oid
;
size_t
speclen
=
strlen
(
spec
);
if
(
git_oid_fromstrn
(
&
oid
,
spec
,
speclen
)
<
0
)
return
GIT_ENOTFOUND
;
...
...
@@ -78,6 +77,23 @@ static int maybe_sha_or_abbrev(git_object**out, git_repository *repo, const char
return
git_object_lookup_prefix
(
out
,
repo
,
&
oid
,
speclen
,
GIT_OBJ_ANY
);
}
static
int
maybe_sha
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
)
{
size_t
speclen
=
strlen
(
spec
);
if
(
speclen
!=
GIT_OID_HEXSZ
)
return
GIT_ENOTFOUND
;
return
maybe_sha_or_abbrev
(
out
,
repo
,
spec
,
speclen
);
}
static
int
maybe_abbrev
(
git_object
**
out
,
git_repository
*
repo
,
const
char
*
spec
)
{
size_t
speclen
=
strlen
(
spec
);
return
maybe_sha_or_abbrev
(
out
,
repo
,
spec
,
speclen
);
}
static
int
build_regex
(
regex_t
*
regex
,
const
char
*
pattern
)
{
int
error
;
...
...
@@ -118,7 +134,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
if
(
error
)
return
GIT_ENOTFOUND
;
return
maybe_
sha_or_
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
)
...
...
@@ -126,6 +142,13 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
int
error
;
git_reference
*
ref
;
error
=
maybe_sha
(
out
,
repo
,
spec
);
if
(
!
error
)
return
0
;
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
error
;
error
=
disambiguate_refname
(
&
ref
,
repo
,
spec
);
if
(
!
error
)
{
error
=
git_object_lookup
(
out
,
repo
,
git_reference_target
(
ref
),
GIT_OBJ_ANY
);
...
...
@@ -136,14 +159,14 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
error
;
error
=
maybe_
describe
(
out
,
repo
,
spec
);
error
=
maybe_
abbrev
(
out
,
repo
,
spec
);
if
(
!
error
)
return
0
;
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
return
error
;
error
=
maybe_
sha_or_abbrev
(
out
,
repo
,
spec
);
error
=
maybe_
describe
(
out
,
repo
,
spec
);
if
(
!
error
)
return
0
;
...
...
@@ -217,7 +240,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
if
(
error
<
0
&&
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
error
=
maybe_
sha_or_
abbrev
(
out
,
repo
,
git_buf_cstr
(
&
buf
));
error
=
maybe_abbrev
(
out
,
repo
,
git_buf_cstr
(
&
buf
));
goto
cleanup
;
}
...
...
tests-clar/refs/revparse.c
View file @
0e8e5a61
...
...
@@ -521,3 +521,77 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void)
git_object_free
(
target
);
cl_git_sandbox_cleanup
();
}
/**
* $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750
* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
*
* $ git rev-parse HEAD~3
* 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
*
* $ git branch a65fedf39aefe402d3bb6e24df4d4f5fe4547750 HEAD~3
*
* $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750
* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
*
* $ git rev-parse heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750
* 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
*/
void
test_refs_revparse__try_to_retrieve_sha_before_branch
(
void
)
{
git_repository
*
repo
;
git_reference
*
branch
;
git_object
*
target
;
char
sha
[
GIT_OID_HEXSZ
+
1
];
repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
test_object_inrepo
(
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
repo
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~3"
));
cl_git_pass
(
git_branch_create
(
&
branch
,
repo
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
(
git_commit
*
)
target
,
0
));
git_oid_tostr
(
sha
,
GIT_OID_HEXSZ
+
1
,
git_object_id
(
target
));
test_object_inrepo
(
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
repo
);
test_object_inrepo
(
"heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
,
sha
,
repo
);
git_reference_free
(
branch
);
git_object_free
(
target
);
cl_git_sandbox_cleanup
();
}
/**
* $ git rev-parse c47800
* c47800c7266a2be04c571c04d5a6614691ea99bd
*
* $ git rev-parse HEAD~3
* 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
*
* $ git branch c47800 HEAD~3
*
* $ git rev-parse c47800
* 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
*/
void
test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha
(
void
)
{
git_repository
*
repo
;
git_reference
*
branch
;
git_object
*
target
;
char
sha
[
GIT_OID_HEXSZ
+
1
];
repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
test_object_inrepo
(
"c47800"
,
"c47800c7266a2be04c571c04d5a6614691ea99bd"
,
repo
);
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~3"
));
cl_git_pass
(
git_branch_create
(
&
branch
,
repo
,
"c47800"
,
(
git_commit
*
)
target
,
0
));
git_oid_tostr
(
sha
,
GIT_OID_HEXSZ
+
1
,
git_object_id
(
target
));
test_object_inrepo
(
"c47800"
,
sha
,
repo
);
git_reference_free
(
branch
);
git_object_free
(
target
);
cl_git_sandbox_cleanup
();
}
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