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>
brian m. carlson committed
May 2, 2018 at 00:25 UTC
69d124255ede771ff8162652762406c55ba491c0
3 files changed
+7
-2
cache-tree.c
+1
-1
@@ -523,7 +523,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
523
if (0 <= it->entry_count) {
524
if (size < rawsz)
525
goto free_return;
526
- memcpy(it->oid.hash, (const unsigned char*)buf, rawsz);
526
+ oidread(&it->oid, (const unsigned char *)buf);
527
buf += rawsz;
528
size -= rawsz;
529
}
cache.h
+5
@@ -1008,6 +1008,11 @@ static inline void oidclr(struct object_id *oid)
1008
memset(oid->hash, 0, GIT_MAX_RAWSZ);
1009
}
1010
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
+
1016
1017
#define EMPTY_TREE_SHA1_HEX \
1018
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
resolve-undo.c
+1
-1
@@ -90,7 +90,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
90
continue;
91
if (size < rawsz)
92
goto error;
93
- memcpy(ui->oid[i].hash, (const unsigned char *)data, rawsz);
93
+ oidread(&ui->oid[i], (const unsigned char *)data);
94
size -= rawsz;
95
data += rawsz;
96
}