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
4b1f0f79
Commit
4b1f0f79
authored
Mar 08, 2016
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git_odb_expand_ids: rename func, return the type
parent
6c04269c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
32 deletions
+49
-32
include/git2/odb.h
+7
-6
src/odb.c
+11
-5
tests/odb/mixed.c
+31
-21
No files found.
include/git2/odb.h
View file @
4b1f0f79
...
...
@@ -175,11 +175,12 @@ GIT_EXTERN(int) git_odb_exists_prefix(
/**
* Determine if one or more objects can be found in the object database
* by their abbreviated object IDs. Callers may further restrict the
* lookup based on type. This function will write the complete object
* ID to the `id`s array, and the updated length to the `id_lengths`
* array. (If an object is found, it will have its length updated to
* `GIT_OID_HEXSZ`; if an object is not found, will be be `0`.)
* by their abbreviated object ID and type. The given array will be
* updated in place: for each abbreviated ID that is unique in the
* database, and of the given type (if specified), the full object ID,
* object ID length (`GIT_OID_HEXSZ`) and type will be written back to
* the array. For IDs that are not found (or are ambiguous), the
* array entry will be zeroed.
*
* Note that since this function operates on multiple objects, the
* underlying database will not be asked to be reloaded if an object is
...
...
@@ -194,7 +195,7 @@ GIT_EXTERN(int) git_odb_exists_prefix(
* @param cnt The length of the `ids`, `id_lengths` and `types` arrays
* @return 0 on success or an error code on failure
*/
GIT_EXTERN
(
int
)
git_odb_ex
ists_many_prefixe
s
(
GIT_EXTERN
(
int
)
git_odb_ex
pand_id
s
(
git_odb
*
db
,
git_oid
*
ids
,
size_t
*
id_lengths
,
...
...
src/odb.c
View file @
4b1f0f79
...
...
@@ -742,7 +742,7 @@ int git_odb_exists_prefix(
return
error
;
}
int
git_odb_ex
ists_many_prefixe
s
(
int
git_odb_ex
pand_id
s
(
git_odb
*
db
,
git_oid
*
ids
,
size_t
*
id_lengths
,
...
...
@@ -773,7 +773,7 @@ int git_odb_exists_many_prefixes(
if
(
!
error
)
{
actual_id
=
&
tmp
;
if
(
types
&&
types
[
i
]
!=
GIT_OBJ_ANY
)
if
(
types
)
error
=
git_odb_read_header
(
&
len
,
&
actual_type
,
db
,
&
tmp
);
else
actual_type
=
GIT_OBJ_ANY
;
...
...
@@ -789,13 +789,19 @@ int git_odb_exists_many_prefixes(
actual_type
=
0
;
if
(
!
actual_type
)
{
id_lengths
[
i
]
=
0
;
memset
(
&
ids
[
i
],
0
,
sizeof
(
git_oid
));
}
else
{
id_lengths
[
i
]
=
GIT_OID_HEXSZ
;
id_lengths
[
i
]
=
0
;
if
(
types
)
types
[
i
]
=
0
;
}
else
{
if
(
actual_id
)
git_oid_cpy
(
&
ids
[
i
],
actual_id
);
id_lengths
[
i
]
=
GIT_OID_HEXSZ
;
if
(
types
)
types
[
i
]
=
actual_type
;
}
}
...
...
tests/odb/mixed.c
View file @
4b1f0f79
...
...
@@ -109,13 +109,13 @@ void test_odb_mixed__dup_oid_prefix_0(void) {
git_odb_object_free
(
obj
);
}
struct
odb
_test_data
{
struct
expand_id
_test_data
{
char
*
lookup_id
;
char
*
expected_id
;
git_otype
expected_type
;
};
struct
odb_test_data
prefix
_data
[]
=
{
struct
expand_id_test_data
expand_id_test
_data
[]
=
{
/* some prefixes and their expected values */
{
"dea509d0"
,
NULL
,
GIT_OBJ_ANY
},
{
"00000000"
,
NULL
,
GIT_OBJ_ANY
},
...
...
@@ -155,16 +155,16 @@ static void setup_prefix_query(
git_otype
*
types
;
size_t
num
,
*
lengths
,
i
;
num
=
ARRAY_SIZE
(
prefix
_data
);
num
=
ARRAY_SIZE
(
expand_id_test
_data
);
cl_assert
((
ids
=
git__calloc
(
num
,
sizeof
(
git_oid
))));
cl_assert
((
lengths
=
git__calloc
(
num
,
sizeof
(
size_t
))));
cl_assert
((
types
=
git__calloc
(
num
,
sizeof
(
git_otype
))));
for
(
i
=
0
;
i
<
num
;
i
++
)
{
lengths
[
i
]
=
strlen
(
prefix
_data
[
i
].
lookup_id
);
git_oid_fromstrn
(
&
ids
[
i
],
prefix
_data
[
i
].
lookup_id
,
lengths
[
i
]);
types
[
i
]
=
prefix
_data
[
i
].
expected_type
;
lengths
[
i
]
=
strlen
(
expand_id_test
_data
[
i
].
lookup_id
);
git_oid_fromstrn
(
&
ids
[
i
],
expand_id_test
_data
[
i
].
lookup_id
,
lengths
[
i
]);
types
[
i
]
=
expand_id_test
_data
[
i
].
expected_type
;
}
*
out_ids
=
ids
;
...
...
@@ -173,40 +173,50 @@ static void setup_prefix_query(
*
out_num
=
num
;
}
static
void
assert_found_objects
(
git_oid
*
ids
,
size_t
*
lengths
)
static
void
assert_found_objects
(
git_oid
*
ids
,
size_t
*
lengths
,
git_otype
*
types
)
{
size_t
num
,
i
;
num
=
ARRAY_SIZE
(
prefix
_data
);
num
=
ARRAY_SIZE
(
expand_id_test
_data
);
for
(
i
=
0
;
i
<
num
;
i
++
)
{
git_oid
expected_id
=
{{
0
}};
size_t
expected_len
=
0
;
git_otype
expected_type
=
0
;
if
(
prefix
_data
[
i
].
expected_id
)
{
git_oid_fromstr
(
&
expected_id
,
prefix
_data
[
i
].
expected_id
);
if
(
expand_id_test
_data
[
i
].
expected_id
)
{
git_oid_fromstr
(
&
expected_id
,
expand_id_test
_data
[
i
].
expected_id
);
expected_len
=
GIT_OID_HEXSZ
;
expected_type
=
expand_id_test_data
[
i
].
expected_type
;
}
cl_assert_equal_i
(
expected_len
,
lengths
[
i
]);
cl_assert_equal_oid
(
&
expected_id
,
&
ids
[
i
]);
if
(
types
)
cl_assert_equal_i
(
expected_type
,
types
[
i
]);
}
}
static
void
assert_notfound_objects
(
git_oid
*
ids
,
size_t
*
lengths
)
static
void
assert_notfound_objects
(
git_oid
*
ids
,
size_t
*
lengths
,
git_otype
*
types
)
{
git_oid
expected_id
=
{{
0
}};
size_t
num
,
i
;
num
=
ARRAY_SIZE
(
prefix
_data
);
num
=
ARRAY_SIZE
(
expand_id_test
_data
);
for
(
i
=
0
;
i
<
num
;
i
++
)
{
cl_assert_equal_i
(
0
,
lengths
[
i
]);
cl_assert_equal_oid
(
&
expected_id
,
&
ids
[
i
]);
if
(
types
)
cl_assert_equal_i
(
0
,
types
[
i
]);
}
}
void
test_odb_mixed__
prefix_many
(
void
)
void
test_odb_mixed__
expand_ids
(
void
)
{
git_oid
*
ids
;
size_t
i
,
num
,
*
lengths
;
...
...
@@ -215,15 +225,15 @@ void test_odb_mixed__prefix_many(void)
/* test looking for the actual (correct) types */
setup_prefix_query
(
&
ids
,
&
lengths
,
&
types
,
&
num
);
cl_git_pass
(
git_odb_ex
ists_many_prefixe
s
(
_odb
,
ids
,
lengths
,
types
,
num
));
assert_found_objects
(
ids
,
lengths
);
cl_git_pass
(
git_odb_ex
pand_id
s
(
_odb
,
ids
,
lengths
,
types
,
num
));
assert_found_objects
(
ids
,
lengths
,
types
);
git__free
(
ids
);
git__free
(
lengths
);
git__free
(
types
);
/* test looking for no specified types (types array == NULL) */
setup_prefix_query
(
&
ids
,
&
lengths
,
&
types
,
&
num
);
cl_git_pass
(
git_odb_ex
ists_many_prefixe
s
(
_odb
,
ids
,
lengths
,
NULL
,
num
));
assert_found_objects
(
ids
,
lengths
);
cl_git_pass
(
git_odb_ex
pand_id
s
(
_odb
,
ids
,
lengths
,
NULL
,
num
));
assert_found_objects
(
ids
,
lengths
,
NULL
);
git__free
(
ids
);
git__free
(
lengths
);
git__free
(
types
);
/* test looking for an explicit GIT_OBJ_ANY */
...
...
@@ -233,8 +243,8 @@ void test_odb_mixed__prefix_many(void)
for
(
i
=
0
;
i
<
num
;
i
++
)
types
[
i
]
=
GIT_OBJ_ANY
;
cl_git_pass
(
git_odb_ex
ists_many_prefixe
s
(
_odb
,
ids
,
lengths
,
types
,
num
));
assert_found_objects
(
ids
,
lengths
);
cl_git_pass
(
git_odb_ex
pand_id
s
(
_odb
,
ids
,
lengths
,
types
,
num
));
assert_found_objects
(
ids
,
lengths
,
types
);
git__free
(
ids
);
git__free
(
lengths
);
git__free
(
types
);
/* test looking for the completely wrong type */
...
...
@@ -244,8 +254,8 @@ void test_odb_mixed__prefix_many(void)
for
(
i
=
0
;
i
<
num
;
i
++
)
types
[
i
]
=
(
types
[
i
]
==
GIT_OBJ_BLOB
)
?
GIT_OBJ_TREE
:
GIT_OBJ_BLOB
;
cl_git_pass
(
git_odb_ex
ists_many_prefixe
s
(
_odb
,
ids
,
lengths
,
types
,
num
));
assert_notfound_objects
(
ids
,
lengths
);
cl_git_pass
(
git_odb_ex
pand_id
s
(
_odb
,
ids
,
lengths
,
types
,
num
));
assert_notfound_objects
(
ids
,
lengths
,
types
);
git__free
(
ids
);
git__free
(
lengths
);
git__free
(
types
);
}
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