Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit c43cb38

Browse files
pcloudspeff
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent db699a8 commit c43cb38

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

bisect.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,41 @@ int bisect_next_all(const char *prefix, int no_checkout)
956956
return bisect_checkout(bisect_rev_hex, no_checkout);
957957
}
958958

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -201,45 +201,6 @@ static void show_edge(struct commit *commit)
201201
printf("-%s\n", sha1_to_hex(commit->object.sha1));
202202
}
203203

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-
243204
void print_commit_list(struct commit_list *list,
244205
const char *format_cur,
245206
const char *format_last)

0 commit comments

Comments
 (0)