Skip to content

Commit 0acaf3a

Browse files
committed
oid: define GIT_OID_SHA1_ZERO
Callers should not assume the layout of the oid structure; provide them a macro that defines the null / zero sha1 object id.
1 parent dbc4ac1 commit 0acaf3a

File tree

24 files changed

+65
-62
lines changed

24 files changed

+65
-62
lines changed

examples/general.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ static void reference_listing(git_repository *repo)
679679

680680
for (i = 0; i < ref_list.count; ++i) {
681681
git_reference *ref;
682-
char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = GIT_OID_HEX_ZERO;
682+
char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = GIT_OID_SHA1_HEXZERO;
683683
const char *refname;
684684

685685
refname = ref_list.strings[i];

include/git2/common.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ GIT_BEGIN_DECL
105105
*/
106106
#define GIT_PATH_MAX 4096
107107

108-
/**
109-
* The string representation of the null object ID.
110-
*/
111-
#define GIT_OID_HEX_ZERO "0000000000000000000000000000000000000000"
112-
113108
/**
114109
* Return the version of the libgit2 library
115110
* being currently used.

include/git2/oid.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ typedef struct git_oid {
3535
unsigned char id[GIT_OID_SHA1_SIZE];
3636
} git_oid;
3737

38+
/**
39+
* The binary representation of the null object ID.
40+
*/
41+
#define GIT_OID_SHA1_ZERO { { 0 } }
42+
43+
/**
44+
* The string representation of the null object ID.
45+
*/
46+
#define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000"
47+
3848
/**
3949
* Parse a hex formatted object id into a git_oid.
4050
*

src/libgit2/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ static int index_entry_similarity_calc(
10611061
const git_merge_options *opts)
10621062
{
10631063
git_blob *blob;
1064-
git_diff_file diff_file = {{{0}}};
1064+
git_diff_file diff_file = { GIT_OID_SHA1_ZERO };
10651065
git_object_size_t blobsize;
10661066
int error;
10671067

src/libgit2/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ int git_object_lookup_prefix(
230230
error = git_odb_read(&odb_obj, odb, id);
231231
}
232232
} else {
233-
git_oid short_oid = {{ 0 }};
233+
git_oid short_oid = GIT_OID_SHA1_ZERO;
234234

235235
git_oid__cpy_prefix(&short_oid, id, len);
236236

@@ -502,7 +502,7 @@ static int git_object__short_id(git_str *out, const git_object *obj)
502502
{
503503
git_repository *repo;
504504
int len = GIT_ABBREV_DEFAULT, error;
505-
git_oid id = {{0}};
505+
git_oid id = GIT_OID_SHA1_ZERO;
506506
git_odb *odb;
507507

508508
GIT_ASSERT_ARG(out);

src/libgit2/odb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ static int odb_exists_prefix_1(git_oid *out, git_odb *db,
914914
{
915915
size_t i;
916916
int error = GIT_ENOTFOUND, num_found = 0;
917-
git_oid last_found = {{0}}, found;
917+
git_oid last_found = GIT_OID_SHA1_ZERO, found;
918918

919919
if ((error = git_mutex_lock(&db->lock)) < 0) {
920920
git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock");
@@ -965,7 +965,7 @@ int git_odb_exists_prefix(
965965
git_oid *out, git_odb *db, const git_oid *short_id, size_t len)
966966
{
967967
int error;
968-
git_oid key = {{0}};
968+
git_oid key = GIT_OID_SHA1_ZERO;
969969

970970
GIT_ASSERT_ARG(db);
971971
GIT_ASSERT_ARG(short_id);
@@ -1305,7 +1305,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db,
13051305
{
13061306
size_t i;
13071307
int error = 0;
1308-
git_oid found_full_oid = {{0}};
1308+
git_oid found_full_oid = GIT_OID_SHA1_ZERO;
13091309
git_rawobj raw = {0};
13101310
void *data = NULL;
13111311
bool found = false;
@@ -1391,7 +1391,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db,
13911391
int git_odb_read_prefix(
13921392
git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len)
13931393
{
1394-
git_oid key = {{0}};
1394+
git_oid key = GIT_OID_SHA1_ZERO;
13951395
int error;
13961396

13971397
GIT_ASSERT_ARG(out);

src/libgit2/odb_pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static int pack_entry_find_prefix(
307307
{
308308
int error;
309309
size_t i;
310-
git_oid found_full_oid = {{0}};
310+
git_oid found_full_oid = GIT_OID_SHA1_ZERO;
311311
bool found = false;
312312
struct git_pack_file *last_found = backend->last_found, *p;
313313
git_midx_entry midx_entry;

src/libgit2/refdb_fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
21922192
static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *who, const char *message)
21932193
{
21942194
int error, is_symbolic, open_flags;
2195-
git_oid old_id = {{0}}, new_id = {{0}};
2195+
git_oid old_id = GIT_OID_SHA1_ZERO, new_id = GIT_OID_SHA1_ZERO;
21962196
git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
21972197
git_repository *repo = backend->repo;
21982198

src/libgit2/reflog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign
104104
previous = git_reflog_entry_byindex(reflog, 0);
105105

106106
if (previous == NULL)
107-
git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO);
107+
git_oid_fromstr(&entry->oid_old, GIT_OID_SHA1_HEXZERO);
108108
else
109109
git_oid_cpy(&entry->oid_old, &previous->oid_cur);
110110

@@ -219,7 +219,7 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry)
219219
/* If the oldest entry has just been removed... */
220220
if (idx == entrycount - 1) {
221221
/* ...clear the oid_old member of the "new" oldest entry */
222-
if (git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO) < 0)
222+
if (git_oid_fromstr(&entry->oid_old, GIT_OID_SHA1_HEXZERO) < 0)
223223
return -1;
224224

225225
return 0;

src/libgit2/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
16221622
const git_refspec *spec;
16231623
const char *refname;
16241624
int error;
1625-
git_oid zero_id = {{ 0 }};
1625+
git_oid zero_id = GIT_OID_SHA1_ZERO;
16261626

16271627
if (callbacks)
16281628
GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");

0 commit comments

Comments
 (0)