aboutsummaryrefslogtreecommitdiff
path: root/bisect.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-11-09 12:51:06 -0500
committerJeff King <peff@peff.net>2012-11-09 12:51:06 -0500
commit19fb61369583410a4f79dbc065b4dc8125236c0b (patch)
tree7f7498d204f8df97ddc0cd6726154a0ce5fa5bb7 /bisect.c
parent9d91c0e3d5d1bf9339a31ecbd5f6defdac8540d0 (diff)
parent745f7a8cacae55df3e00507344d8db2a31eb57e8 (diff)
downloadgit-19fb61369583410a4f79dbc065b4dc8125236c0b.tar.gz
git-19fb61369583410a4f79dbc065b4dc8125236c0b.tar.xz
Merge branch 'nd/builtin-to-libgit'
Code cleanups so that libgit.a does not depend on anything in the builtin/ directory. * nd/builtin-to-libgit: fetch-pack: move core code to libgit.a fetch-pack: remove global (static) configuration variable "args" send-pack: move core code to libgit.a Move setup_diff_pager to libgit.a Move print_commit_list to libgit.a Move estimate_bisect_steps to libgit.a Move try_merge_command and checkout_fast_forward to libgit.a
Diffstat (limited to 'bisect.c')
-rw-r--r--bisect.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/bisect.c b/bisect.c
index 1aad49b1a..bd1b7b5da 100644
--- a/bisect.c
+++ b/bisect.c
@@ -956,3 +956,41 @@ int bisect_next_all(const char *prefix, int no_checkout)
return bisect_checkout(bisect_rev_hex, no_checkout);
}
+static inline int log2i(int n)
+{
+ int log2 = 0;
+
+ for (; n > 1; n >>= 1)
+ log2++;
+
+ return log2;
+}
+
+static inline int exp2i(int n)
+{
+ return 1 << n;
+}
+
+/*
+ * Estimate the number of bisect steps left (after the current step)
+ *
+ * For any x between 0 included and 2^n excluded, the probability for
+ * n - 1 steps left looks like:
+ *
+ * P(2^n + x) == (2^n - x) / (2^n + x)
+ *
+ * and P(2^n + x) < 0.5 means 2^n < 3x
+ */
+int estimate_bisect_steps(int all)
+{
+ int n, x, e;
+
+ if (all < 3)
+ return 0;
+
+ n = log2i(all);
+ e = exp2i(n);
+ x = all - e;
+
+ return (e < 3 * x) ? n : n - 1;
+}