aboutsummaryrefslogtreecommitdiff
path: root/wrapper.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-09-12 11:47:23 -0700
committerJunio C Hamano <gitster@pobox.com>2024-09-12 11:47:23 -0700
commit143682ec43d5772ee9327ed84eb0cdc007b1f489 (patch)
treef31ec1d5710d11b704afef67f270152226e8b537 /wrapper.h
parent3bf057a0cd6a75125a5bd239372f9fc4fea6c338 (diff)
parentc3459ae9ef26ee1b49d4de0af128444967910361 (diff)
downloadgit-143682ec43d5772ee9327ed84eb0cdc007b1f489.tar.xz
Merge branch 'ps/pack-refs-auto-heuristics'
"git pack-refs --auto" for the files backend was too aggressive, which has been a bit tamed. * ps/pack-refs-auto-heuristics: refs/files: use heuristic to decide whether to repack with `--auto` t0601: merge tests for auto-packing of refs wrapper: introduce `log2u()`
Diffstat (limited to 'wrapper.h')
-rw-r--r--wrapper.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/wrapper.h b/wrapper.h
index 1b2b047ea0..a6b3e1f09e 100644
--- a/wrapper.h
+++ b/wrapper.h
@@ -140,4 +140,22 @@ int csprng_bytes(void *buf, size_t len);
*/
uint32_t git_rand(void);
+/* Provide log2 of the given `size_t`. */
+static inline unsigned log2u(uintmax_t sz)
+{
+ unsigned l = 0;
+
+ /*
+ * Technically this isn't required, but it helps the compiler optimize
+ * this to a `bsr` instruction.
+ */
+ if (!sz)
+ return 0;
+
+ for (; sz; sz >>= 1)
+ l++;
+
+ return l - 1;
+}
+
#endif /* WRAPPER_H */