Commit ed51feb74b33ca115ddf739ce3574a76cb7a6fa6

Edward Thomson 2018-01-21T18:01:20

oidarray: introduce git_oidarray__reverse Provide a simple function to reverse an oidarray.

diff --git a/src/oidarray.c b/src/oidarray.c
index fda3b63..e70e9dd 100644
--- a/src/oidarray.c
+++ b/src/oidarray.c
@@ -20,3 +20,15 @@ void git_oidarray__from_array(git_oidarray *arr, git_array_oid_t *array)
 	arr->count = array->size;
 	arr->ids = array->ptr;
 }
+
+void git_oidarray__reverse(git_oidarray *arr)
+{
+	size_t i;
+	git_oid tmp;
+
+	for (i = 0; i < arr->count / 2; i++) {
+		git_oid_cpy(&tmp, &arr->ids[i]);
+		git_oid_cpy(&arr->ids[i], &arr->ids[(arr->count-1)-i]);
+		git_oid_cpy(&arr->ids[(arr->count-1)-i], &tmp);
+	}
+}
diff --git a/src/oidarray.h b/src/oidarray.h
index f051a0e..eed3a10 100644
--- a/src/oidarray.h
+++ b/src/oidarray.h
@@ -14,6 +14,7 @@
 
 typedef git_array_t(git_oid) git_array_oid_t;
 
+extern void git_oidarray__reverse(git_oidarray *arr);
 extern void git_oidarray__from_array(git_oidarray *arr, git_array_oid_t *array);
 
 #endif