]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Move estimate_bisect_steps to libgit.a
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 26 Oct 2012 15:53:50 +0000 (22:53 +0700)
committerJeff King <peff@peff.net>
Mon, 29 Oct 2012 07:08:30 +0000 (03:08 -0400)
This function is used by bisect.c, part of libgit.a while
estimate_bisect_steps stays in builtin/rev-list.c. Move it to bisect.a
so we won't have undefine reference if a standalone program that uses
libgit.a happens to pull it in.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
bisect.c
builtin/rev-list.c

index 1aad49b1a642a308f449001960958ccab79347d1..bd1b7b5dac81ada592a16630214d1f2cbb655b88 100644 (file)
--- 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;
+}
index ff5a38372d76cc50167a8f7e7862a67cc9d419ea..a0ec84e44bcefe274cc3f33b5e2115b8352b5c37 100644 (file)
@@ -201,45 +201,6 @@ static void show_edge(struct commit *commit)
        printf("-%s\n", sha1_to_hex(commit->object.sha1));
 }
 
-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;
-}
-
 void print_commit_list(struct commit_list *list,
                       const char *format_cur,
                       const char *format_last)