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
0db1c57c
Commit
0db1c57c
authored
Jan 25, 2022
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oid: add sha256 typed oids
parent
3fbf580c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
54 deletions
+137
-54
include/git2/oid.h
+9
-4
src/libgit2/oid.h
+4
-0
tests/libgit2/core/oid.c
+123
-49
tests/libgit2/object/raw/size.c
+1
-1
No files found.
include/git2/oid.h
View file @
0db1c57c
...
...
@@ -19,18 +19,21 @@
*/
GIT_BEGIN_DECL
/** The type of object id
, currently only SHA1
. */
/** The type of object id. */
typedef
enum
{
GIT_OID_SHA1
=
1
/**< SHA1 */
GIT_OID_SHA1
=
1
,
/**< SHA1 */
GIT_OID_SHA256
=
2
/**< SHA256 */
}
git_oid_t
;
/** Size (in bytes) of a raw/binary oid */
#define GIT_OID_SHA1_SIZE 20
#define GIT_OID_MAX_SIZE GIT_OID_SHA1_SIZE
#define GIT_OID_SHA256_SIZE 32
#define GIT_OID_MAX_SIZE GIT_OID_SHA256_SIZE
/** Size (in bytes) of a hex formatted oid */
#define GIT_OID_SHA1_HEXSIZE (GIT_OID_SHA1_SIZE * 2)
#define GIT_OID_MAX_HEXSIZE GIT_OID_SHA1_HEXSIZE
#define GIT_OID_SHA256_HEXSIZE (GIT_OID_SHA256_SIZE * 2)
#define GIT_OID_MAX_HEXSIZE GIT_OID_SHA256_HEXSIZE
/** Minimum length (in number of hex characters,
* i.e. packets of 4 bits) of an oid prefix */
...
...
@@ -49,11 +52,13 @@ typedef struct git_oid {
* The binary representation of the null object ID.
*/
#define GIT_OID_SHA1_ZERO { GIT_OID_SHA1, { 0 } }
#define GIT_OID_SHA256_ZERO { GIT_OID_SHA256, { 0 } }
/**
* The string representation of the null object ID.
*/
#define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000"
#define GIT_OID_SHA256_HEXZERO "0000000000000000000000000000000000000000000000000000000000000000"
/**
* Parse a hex formatted object id into a git_oid.
...
...
src/libgit2/oid.h
View file @
0db1c57c
...
...
@@ -21,6 +21,8 @@ GIT_INLINE(size_t) git_oid_size(git_oid_t type)
switch
(
type
)
{
case
GIT_OID_SHA1
:
return
GIT_OID_SHA1_SIZE
;
case
GIT_OID_SHA256
:
return
GIT_OID_SHA256_SIZE
;
}
return
0
;
...
...
@@ -31,6 +33,8 @@ GIT_INLINE(size_t) git_oid_hexsize(git_oid_t type)
switch
(
type
)
{
case
GIT_OID_SHA1
:
return
GIT_OID_SHA1_HEXSIZE
;
case
GIT_OID_SHA256
:
return
GIT_OID_SHA256_HEXSIZE
;
}
return
0
;
...
...
tests/libgit2/core/oid.c
View file @
0db1c57c
#include "clar_libgit2.h"
#include "oid.h"
static
git_oid
id
;
static
git_oid
idp
;
static
git_oid
idm
;
const
char
*
str_oid
=
"ae90f12eea699729ed24555e40b9fd669da12a12"
;
const
char
*
str_oid_p
=
"ae90f12eea699729ed"
;
const
char
*
str_oid_m
=
"ae90f12eea699729ed24555e40b9fd669da12a12THIS IS EXTRA TEXT THAT SHOULD GET IGNORED"
;
static
git_oid
id_sha1
;
static
git_oid
idp_sha1
;
static
git_oid
idm_sha1
;
const
char
*
str_oid_sha1
=
"ae90f12eea699729ed24555e40b9fd669da12a12"
;
const
char
*
str_oid_sha1_p
=
"ae90f12eea699729ed"
;
const
char
*
str_oid_sha1_m
=
"ae90f12eea699729ed24555e40b9fd669da12a12THIS IS EXTRA TEXT THAT SHOULD GET IGNORED"
;
static
git_oid
id_sha256
;
static
git_oid
idp_sha256
;
static
git_oid
idm_sha256
;
const
char
*
str_oid_sha256
=
"d3e63d2f2e43d1fee23a74bf19a0ede156cba2d1bd602eba13de433cea1bb512"
;
const
char
*
str_oid_sha256_p
=
"d3e63d2f2e43d1fee2"
;
const
char
*
str_oid_sha256_m
=
"d3e63d2f2e43d1fee23a74bf19a0ede156cba2d1bd602eba13de433cea1bb512 GARBAGE EXTRA TEXT AT THE END"
;
void
test_core_oid__initialize
(
void
)
{
cl_git_pass
(
git_oid_fromstr
(
&
id
,
str_oid
,
GIT_OID_SHA1
));
cl_git_pass
(
git_oid_fromstrp
(
&
idp
,
str_oid_p
,
GIT_OID_SHA1
));
cl_git_fail
(
git_oid_fromstrp
(
&
idm
,
str_oid_m
,
GIT_OID_SHA1
));
cl_git_pass
(
git_oid_fromstr
(
&
id_sha1
,
str_oid_sha1
,
GIT_OID_SHA1
));
cl_git_pass
(
git_oid_fromstrp
(
&
idp_sha1
,
str_oid_sha1_p
,
GIT_OID_SHA1
));
cl_git_fail
(
git_oid_fromstrp
(
&
idm_sha1
,
str_oid_sha1_m
,
GIT_OID_SHA1
));
cl_git_pass
(
git_oid_fromstr
(
&
id_sha256
,
str_oid_sha256
,
GIT_OID_SHA256
));
cl_git_pass
(
git_oid_fromstrp
(
&
idp_sha256
,
str_oid_sha256_p
,
GIT_OID_SHA256
));
cl_git_fail
(
git_oid_fromstrp
(
&
idm_sha256
,
str_oid_sha256_m
,
GIT_OID_SHA256
));
}
void
test_core_oid__streq
(
void
)
void
test_core_oid__streq
_sha1
(
void
)
{
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
id
,
str_oid
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
id
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
));
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
id
_sha1
,
str_oid_sha1
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
id
_sha1
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
id
,
"deadbeef"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
id
,
"I'm not an oid.... :)"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
id
_sha1
,
"deadbeef"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
id
_sha1
,
"I'm not an oid.... :)"
));
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
idp
,
"ae90f12eea699729ed0000000000000000000000"
));
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
idp
,
"ae90f12eea699729ed"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
,
"ae90f12eea699729ed1"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
,
"ae90f12eea699729ec"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
));
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
idp
_sha1
,
"ae90f12eea699729ed0000000000000000000000"
));
cl_assert_equal_i
(
0
,
git_oid_streq
(
&
idp
_sha1
,
"ae90f12eea699729ed"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
_sha1
,
"ae90f12eea699729ed1"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
_sha1
,
"ae90f12eea699729ec"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
_sha1
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
,
"deadbeef"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
,
"I'm not an oid.... :)"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
_sha1
,
"deadbeef"
));
cl_assert_equal_i
(
-
1
,
git_oid_streq
(
&
idp
_sha1
,
"I'm not an oid.... :)"
));
}
void
test_core_oid__str
cmp
(
void
)
void
test_core_oid__str
eq_sha256
(
void
)
{
cl_assert_equal_i
(
0
,
git_oid_str
cmp
(
&
id
,
str_oid
));
cl_assert
(
git_oid_strcmp
(
&
id
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
<
0
);
cl_assert_equal_i
(
0
,
git_oid_str
eq
(
&
id_sha256
,
str_oid_sha256
));
cl_assert
_equal_i
(
-
1
,
git_oid_streq
(
&
id_sha256
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
);
cl_assert
(
git_oid_strcmp
(
&
id
,
"deadbeef"
)
<
0
);
cl_assert_equal_i
(
-
1
,
git_oid_str
cmp
(
&
id
,
"I'm not an oid.... :)"
));
cl_assert
_equal_i
(
-
1
,
git_oid_streq
(
&
id_sha256
,
"deadbeef"
)
);
cl_assert_equal_i
(
-
1
,
git_oid_str
eq
(
&
id_sha256
,
"I'm not an oid.... :)"
));
cl_assert_equal_i
(
0
,
git_oid_str
cmp
(
&
idp
,
"ae90f12eea699729ed
0000000000000000000000"
));
cl_assert_equal_i
(
0
,
git_oid_str
cmp
(
&
idp
,
"ae90f12eea699729ed
"
));
cl_assert
(
git_oid_strcmp
(
&
idp
,
"ae90f12eea699729ed1"
)
<
0
);
cl_assert
(
git_oid_strcmp
(
&
idp
,
"ae90f12eea699729ec"
)
>
0
);
cl_assert
(
git_oid_strcmp
(
&
idp
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
<
0
);
cl_assert_equal_i
(
0
,
git_oid_str
eq
(
&
idp_sha256
,
"d3e63d2f2e43d1fee2000000000000000000000000
0000000000000000000000"
));
cl_assert_equal_i
(
0
,
git_oid_str
eq
(
&
idp_sha256
,
"d3e63d2f2e43d1fee2
"
));
cl_assert
_equal_i
(
-
1
,
git_oid_streq
(
&
idp_sha1
,
"d3e63d2f2e43d1fee21"
)
);
cl_assert
_equal_i
(
-
1
,
git_oid_streq
(
&
idp_sha1
,
"d3e63d2f2e43d1fee1"
)
);
cl_assert
_equal_i
(
-
1
,
git_oid_streq
(
&
idp_sha256
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
);
cl_assert
(
git_oid_strcmp
(
&
idp
,
"deadbeef"
)
<
0
);
cl_assert_equal_i
(
-
1
,
git_oid_str
cmp
(
&
idp
,
"I'm not an oid.... :)"
));
cl_assert
_equal_i
(
-
1
,
git_oid_streq
(
&
idp_sha1
,
"deadbeef"
)
);
cl_assert_equal_i
(
-
1
,
git_oid_str
eq
(
&
idp_sha1
,
"I'm not an oid.... :)"
));
}
void
test_core_oid__
ncmp
(
void
)
void
test_core_oid__
strcmp_sha1
(
void
)
{
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
idp
,
0
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
idp
,
1
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
idp
,
2
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
idp
,
17
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
idp
,
18
));
cl_assert
(
git_oid_ncmp
(
&
id
,
&
idp
,
19
));
cl_assert
(
git_oid_ncmp
(
&
id
,
&
idp
,
40
));
cl_assert
(
git_oid_ncmp
(
&
id
,
&
idp
,
41
));
cl_assert
(
git_oid_ncmp
(
&
id
,
&
idp
,
42
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
id
,
0
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
id
,
1
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
id
,
39
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
id
,
40
));
cl_assert
(
!
git_oid_ncmp
(
&
id
,
&
id
,
41
));
cl_assert_equal_i
(
0
,
git_oid_strcmp
(
&
id_sha1
,
str_oid_sha1
));
cl_assert
(
git_oid_strcmp
(
&
id_sha1
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
<
0
);
cl_assert
(
git_oid_strcmp
(
&
id_sha1
,
"deadbeef"
)
<
0
);
cl_assert_equal_i
(
-
1
,
git_oid_strcmp
(
&
id_sha1
,
"I'm not an oid.... :)"
));
cl_assert_equal_i
(
0
,
git_oid_strcmp
(
&
idp_sha1
,
"ae90f12eea699729ed0000000000000000000000"
));
cl_assert_equal_i
(
0
,
git_oid_strcmp
(
&
idp_sha1
,
"ae90f12eea699729ed"
));
cl_assert
(
git_oid_strcmp
(
&
idp_sha1
,
"ae90f12eea699729ed1"
)
<
0
);
cl_assert
(
git_oid_strcmp
(
&
idp_sha1
,
"ae90f12eea699729ec"
)
>
0
);
cl_assert
(
git_oid_strcmp
(
&
idp_sha1
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
<
0
);
cl_assert
(
git_oid_strcmp
(
&
idp_sha1
,
"deadbeef"
)
<
0
);
cl_assert_equal_i
(
-
1
,
git_oid_strcmp
(
&
idp_sha1
,
"I'm not an oid.... :)"
));
}
void
test_core_oid__strcmp_sha256
(
void
)
{
cl_assert_equal_i
(
0
,
git_oid_strcmp
(
&
id_sha256
,
str_oid_sha256
));
cl_assert
(
git_oid_strcmp
(
&
id_sha256
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
<
0
);
cl_assert
(
git_oid_strcmp
(
&
id_sha256
,
"deadbeef"
)
<
0
);
cl_assert_equal_i
(
-
1
,
git_oid_strcmp
(
&
id_sha256
,
"I'm not an oid.... :)"
));
cl_assert_equal_i
(
0
,
git_oid_strcmp
(
&
idp_sha256
,
"d3e63d2f2e43d1fee20000000000000000000000"
));
cl_assert_equal_i
(
0
,
git_oid_strcmp
(
&
idp_sha256
,
"d3e63d2f2e43d1fee2"
));
cl_assert
(
git_oid_strcmp
(
&
idp_sha256
,
"d3e63d2f2e43d1fee21"
)
<
0
);
cl_assert
(
git_oid_strcmp
(
&
idp_sha256
,
"d3e63d2f2e43d1fee1"
)
>
0
);
cl_assert
(
git_oid_strcmp
(
&
idp_sha256
,
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
)
<
0
);
cl_assert
(
git_oid_strcmp
(
&
idp_sha256
,
"deadbeef"
)
<
0
);
cl_assert_equal_i
(
-
1
,
git_oid_strcmp
(
&
idp_sha256
,
"I'm not an oid.... :)"
));
}
void
test_core_oid__ncmp_sha1
(
void
)
{
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
0
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
1
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
2
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
17
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
18
));
cl_assert
(
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
19
));
cl_assert
(
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
40
));
cl_assert
(
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
41
));
cl_assert
(
git_oid_ncmp
(
&
id_sha1
,
&
idp_sha1
,
42
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
id_sha1
,
0
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
id_sha1
,
1
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
id_sha1
,
39
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
id_sha1
,
40
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha1
,
&
id_sha1
,
41
));
}
void
test_core_oid__ncmp_sha256
(
void
)
{
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
0
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
1
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
2
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
17
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
18
));
cl_assert
(
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
19
));
cl_assert
(
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
40
));
cl_assert
(
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
41
));
cl_assert
(
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
42
));
cl_assert
(
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
63
));
cl_assert
(
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
64
));
cl_assert
(
git_oid_ncmp
(
&
id_sha256
,
&
idp_sha256
,
65
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
0
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
1
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
39
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
40
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
41
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
63
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
64
));
cl_assert
(
!
git_oid_ncmp
(
&
id_sha256
,
&
id_sha256
,
65
));
}
void
test_core_oid__is_hexstr
(
void
)
...
...
tests/libgit2/object/raw/size.c
View file @
0db1c57c
...
...
@@ -9,5 +9,5 @@ void test_object_raw_size__validate_oid_size(void)
cl_assert
(
20
==
GIT_OID_SHA1_SIZE
);
cl_assert
(
40
==
GIT_OID_SHA1_HEXSIZE
);
cl_assert
(
sizeof
(
out
.
id
)
==
GIT_OID_
SHA1
_SIZE
);
cl_assert
(
sizeof
(
out
.
id
)
==
GIT_OID_
MAX
_SIZE
);
}
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