Move estimate_bisect_steps to libgit.a
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>
Nguyễn Thái Ngọc Duy committed
Oct 26, 2012 at 22:53 UTC
c43cb38612192fa45bf7ed981a98bc4ddb86ce75
2 files changed
+38
-39
bisect.c
+38
@@ -956,3 +956,41 @@ int bisect_next_all(const char *prefix, int no_checkout)
956
return bisect_checkout(bisect_rev_hex, no_checkout);
957
}
958
959
+static inline int log2i(int n)
960
+{
961
+ int log2 = 0;
962
+
963
+ for (; n > 1; n >>= 1)
964
+ log2++;
965
+
966
+ return log2;
967
+}
968
+
969
+static inline int exp2i(int n)
970
+{
971
+ return 1 << n;
972
+}
973
+
974
+/*
975
+ * Estimate the number of bisect steps left (after the current step)
976
+ *
977
+ * For any x between 0 included and 2^n excluded, the probability for
978
+ * n - 1 steps left looks like:
979
+ *
980
+ * P(2^n + x) == (2^n - x) / (2^n + x)
981
+ *
982
+ * and P(2^n + x) < 0.5 means 2^n < 3x
983
+ */
984
+int estimate_bisect_steps(int all)
985
+{
986
+ int n, x, e;
987
+
988
+ if (all < 3)
989
+ return 0;
990
+
991
+ n = log2i(all);
992
+ e = exp2i(n);
993
+ x = all - e;
994
+
995
+ return (e < 3 * x) ? n : n - 1;
996
+}
builtin/rev-list.c
-39
@@ -201,45 +201,6 @@ static void show_edge(struct commit *commit)
201
printf("-%s\n", sha1_to_hex(commit->object.sha1));
202
}
203
204
-static inline int log2i(int n)
205
-{
206
- int log2 = 0;
207
-
208
- for (; n > 1; n >>= 1)
209
- log2++;
210
-
211
- return log2;
212
-}
213
-
214
-static inline int exp2i(int n)
215
-{
216
- return 1 << n;
217
-}
218
-
219
-/*
220
- * Estimate the number of bisect steps left (after the current step)
221
- *
222
- * For any x between 0 included and 2^n excluded, the probability for
223
- * n - 1 steps left looks like:
224
- *
225
- * P(2^n + x) == (2^n - x) / (2^n + x)
226
- *
227
- * and P(2^n + x) < 0.5 means 2^n < 3x
228
- */
229
-int estimate_bisect_steps(int all)
230
-{
231
- int n, x, e;
232
-
233
- if (all < 3)
234
- return 0;
235
-
236
- n = log2i(all);
237
- e = exp2i(n);
238
- x = all - e;
239
-
240
- return (e < 3 * x) ? n : n - 1;
241
-}
242
-
204
void print_commit_list(struct commit_list *list,
205
const char *format_cur,
206
const char *format_last)