]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cache: add a function to read an object ID from a buffer
authorbrian m. carlson <sandals@crustytoothpaste.net>
Wed, 2 May 2018 00:25:29 +0000 (00:25 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 May 2018 04:59:48 +0000 (13:59 +0900)
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>
cache-tree.c
cache.h
resolve-undo.c

index 6a555f4d431f9f6dbf8dad06d75a4ec81a4254fd..8c7e1258a4861a7f692de6892c18c9a9e1e81061 100644 (file)
@@ -523,7 +523,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
        if (0 <= it->entry_count) {
                if (size < rawsz)
                        goto free_return;
-               memcpy(it->oid.hash, (const unsigned char*)buf, rawsz);
+               oidread(&it->oid, (const unsigned char *)buf);
                buf += rawsz;
                size -= rawsz;
        }
diff --git a/cache.h b/cache.h
index bbaf5c349ab893a6f0f4549b61bcc70eff50745f..4bca177cf3fe2200b89a8e51f16cb0f36263d8cf 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1008,6 +1008,11 @@ static inline void oidclr(struct object_id *oid)
        memset(oid->hash, 0, GIT_MAX_RAWSZ);
 }
 
+static inline void oidread(struct object_id *oid, const unsigned char *hash)
+{
+       memcpy(oid->hash, hash, the_hash_algo->rawsz);
+}
+
 
 #define EMPTY_TREE_SHA1_HEX \
        "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
index aed95b4b35fbb187bb96242afcf6b4d8e3d2008b..fc5b3b83d9a08e9deed55ee15520387f147da626 100644 (file)
@@ -90,7 +90,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
                                continue;
                        if (size < rawsz)
                                goto error;
-                       memcpy(ui->oid[i].hash, (const unsigned char *)data, rawsz);
+                       oidread(&ui->oid[i], (const unsigned char *)data);
                        size -= rawsz;
                        data += rawsz;
                }