summaryrefslogtreecommitdiff
path: root/oid-array.h
diff options
context:
space:
mode:
authorLibravatar Jiang Xin <worldhello.net@gmail.com>2020-12-21 07:10:19 +0800
committerLibravatar Jiang Xin <worldhello.net@gmail.com>2020-12-21 07:10:19 +0800
commit3104153d5ea3bd0e68166e02ec847a895f9a76e6 (patch)
tree8b65383c203c550fab3f6ffea51cd474168ac34b /oid-array.h
parentl10n: Update Catalan translation (diff)
parentGit 2.30-rc1 (diff)
downloadtgif-3104153d5ea3bd0e68166e02ec847a895f9a76e6.tar.xz
Merge remote-tracking branch 'github/master' into git-po-master
* github/master: (42 commits) Git 2.30-rc1 git-gui: use gray background for inactive text widgets Another batch before 2.30-rc1 git-gui: Fix selected text colors Makefile: conditionally include GIT-VERSION-FILE git-gui: fix colored label backgrounds when using themed widgets config.mak.uname: remove old NonStop compatibility settings diff: correct interaction between --exit-code and -I<pattern> t/perf: fix test_export() failure with BSD `sed` style: do not "break" in switch() after "return" compat-util: pretend that stub setitimer() always succeeds strmap: make callers of strmap_remove() to call it in void context doc: mention Python 3.x supports index-format.txt: document v2 format of file system monitor extension docs: multi-pack-index: remove note about future 'verify' work init: provide useful advice about init.defaultBranch get_default_branch_name(): prepare for showing some advice branch -m: allow renaming a yet-unborn branch init: document `init.defaultBranch` better t7900: use --fixed-value in git-maintenance tests ...
Diffstat (limited to 'oid-array.h')
-rw-r--r--oid-array.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/oid-array.h b/oid-array.h
index f28d322c90..72bca78b7d 100644
--- a/oid-array.h
+++ b/oid-array.h
@@ -1,5 +1,7 @@
-#ifndef SHA1_ARRAY_H
-#define SHA1_ARRAY_H
+#ifndef OID_ARRAY_H
+#define OID_ARRAY_H
+
+#include "hash.h"
/**
* The API provides storage and manipulation of sets of object identifiers.
@@ -106,4 +108,30 @@ void oid_array_filter(struct oid_array *array,
for_each_oid_fn want,
void *cbdata);
-#endif /* SHA1_ARRAY_H */
+/**
+ * Sort the array in order of ascending object id.
+ */
+void oid_array_sort(struct oid_array *array);
+
+/**
+ * Find the next unique oid in the array after position "cur".
+ * The array must be sorted for this to work. You can iterate
+ * over unique elements like this:
+ *
+ * size_t i;
+ * oid_array_sort(array);
+ * for (i = 0; i < array->nr; i = oid_array_next_unique(array, i))
+ * printf("%s", oid_to_hex(array->oids[i]);
+ *
+ * Non-unique iteration can just increment with "i++" to visit each element.
+ */
+static inline size_t oid_array_next_unique(struct oid_array *array, size_t cur)
+{
+ do {
+ cur++;
+ } while (cur < array->nr &&
+ oideq(array->oid + cur, array->oid + cur - 1));
+ return cur;
+}
+
+#endif /* OID_ARRAY_H */