Skip to content

Commit 69d1242

Browse files
bk2204gitster
authored andcommitted
cache: add a function to read an object ID from a buffer
In various places throughout the codebase, we need to read data into a struct object_id from a pack or other unsigned char buffer. Add an inline function that does this based on the current hash algorithm in use, and use it in several places. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fe0a9ea commit 69d1242

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

cache-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
523523
if (0 <= it->entry_count) {
524524
if (size < rawsz)
525525
goto free_return;
526-
memcpy(it->oid.hash, (const unsigned char*)buf, rawsz);
526+
oidread(&it->oid, (const unsigned char *)buf);
527527
buf += rawsz;
528528
size -= rawsz;
529529
}

cache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,11 @@ static inline void oidclr(struct object_id *oid)
10081008
memset(oid->hash, 0, GIT_MAX_RAWSZ);
10091009
}
10101010

1011+
static inline void oidread(struct object_id *oid, const unsigned char *hash)
1012+
{
1013+
memcpy(oid->hash, hash, the_hash_algo->rawsz);
1014+
}
1015+
10111016

10121017
#define EMPTY_TREE_SHA1_HEX \
10131018
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"

resolve-undo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
9090
continue;
9191
if (size < rawsz)
9292
goto error;
93-
memcpy(ui->oid[i].hash, (const unsigned char *)data, rawsz);
93+
oidread(&ui->oid[i], (const unsigned char *)data);
9494
size -= rawsz;
9595
data += rawsz;
9696
}

0 commit comments

Comments
 (0)