[RFC PATCH 2/3] sha1-array: support appending unsigned char hash
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Jul 11, 2017, 19:48 UTC
- Message-ID
- <523f64e1395124a02316071329bedf9884757479.1499800530.git.jonathantanmy@google.com>
- In-Reply-To
- <cover.1499800530.git.jonathantanmy@google.com>
In a subsequent patch, sha1_file will need to append object names in the form of "unsigned char *" to oid arrays. Teach sha1-array support for that.
Signed-off-by: Jonathan Tan <jonathantanmy@google.com> --- sha1-array.c | 7 +++++++ sha1-array.h | 1 + 2 files changed, 8 insertions(+)
diff --git a/sha1-array.c b/sha1-array.c index 838b3bf84..6e0e35391 100644 --- a/sha1-array.c +++ b/sha1-array.c @@ -9,6 +9,13 @@ void oid_array_append(struct oid_array *array, const struct object_id *oid) array->sorted = 0; } +void oid_array_append_sha1(struct oid_array *array, const unsigned char *sha1) +{ + ALLOC_GROW(array->oid, array->nr + 1, array->alloc); + hashcpy(array->oid[array->nr++].hash, sha1); + array->sorted = 0; +} + static int void_hashcmp(const void *a, const void *b) { return oidcmp(a, b); diff --git a/sha1-array.h b/sha1-array.h index 04b075633..3479959e4 100644 --- a/sha1-array.h +++ b/sha1-array.h @@ -11,6 +11,7 @@ struct oid_array { #define OID_ARRAY_INIT { NULL, 0, 0, 0 } void oid_array_append(struct oid_array *array, const struct object_id *oid); +void oid_array_append_sha1(struct oid_array *array, const unsigned char *sha1); int oid_array_lookup(struct oid_array *array, const struct object_id *oid); void oid_array_clear(struct oid_array *array);
-- 2.13.2.932.g7449e964c-goog