Skip to content

Commit afca16a

Browse files
committed
config: use a byte array for checksum
1 parent c6e1f2b commit afca16a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/config_file.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
#include "regexp.h"
2020
#include "sysdir.h"
2121
#include "wildmatch.h"
22+
#include "hash.h"
2223

2324
/* Max depth for [include] directives */
2425
#define MAX_INCLUDE_DEPTH 10
2526

2627
typedef struct config_file {
2728
git_futils_filestamp stamp;
28-
git_oid checksum;
29+
unsigned char checksum[GIT_HASH_SHA1_SIZE];
2930
char *path;
3031
git_array_t(struct config_file) includes;
3132
} config_file;
@@ -132,7 +133,7 @@ static int config_file_is_modified(int *modified, config_file *file)
132133
{
133134
config_file *include;
134135
git_str buf = GIT_STR_INIT;
135-
git_oid hash;
136+
unsigned char checksum[GIT_HASH_SHA1_SIZE];
136137
uint32_t i;
137138
int error = 0;
138139

@@ -144,10 +145,10 @@ static int config_file_is_modified(int *modified, config_file *file)
144145
if ((error = git_futils_readbuffer(&buf, file->path)) < 0)
145146
goto out;
146147

147-
if ((error = git_hash_buf(hash.id, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
148+
if ((error = git_hash_buf(checksum, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
148149
goto out;
149150

150-
if (!git_oid_equal(&hash, &file->checksum)) {
151+
if (memcmp(checksum, file->checksum, GIT_HASH_SHA1_SIZE) != 0) {
151152
*modified = 1;
152153
goto out;
153154
}
@@ -880,7 +881,7 @@ static int config_file_read(
880881
goto out;
881882

882883
git_futils_filestamp_set_from_stat(&file->stamp, &st);
883-
if ((error = git_hash_buf(file->checksum.id, contents.ptr, contents.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
884+
if ((error = git_hash_buf(file->checksum, contents.ptr, contents.size, GIT_HASH_ALGORITHM_SHA1)) < 0)
884885
goto out;
885886

886887
if ((error = config_file_read_buffer(entries, repo, file, level, depth,

0 commit comments

Comments
 (0)