git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/7] Move estimate_bisect_steps to libgit.a

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 26, 2012, 15:53 UTC
Message-ID
<1351266835-22610-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1351266835-22610-1-git-send-email-pclouds@gmail.com>

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>
---
 bisect.c           | 38 ++++++++++++++++++++++++++++++++++++++
 builtin/rev-list.c | 39 ---------------------------------------
 2 files changed, 38 insertions(+), 39 deletions(-)
diff --git a/bisect.c b/bisect.c
index 1aad49b..bd1b7b5 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;
+}
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ff5a383..a0ec84e 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -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)
-- 
1.8.0.rc2.23.g1fb49df
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 7 of 13 in “Move try_merge_command and checkout_fast_forward to libgit.a”
  1. Move try_merge_command and checkout_fast_forward to libgit.aNguyễn Thái Ngọc Duy, Oct 23, 2012
  2. Jeff KingOct 25, 2012
  3. Nguyen Thai Ngoc DuyOct 25, 2012
  4. Jeff KingOct 26, 2012
  5. 0/7 Move code from builtin to libgit.aNguyễn Thái Ngọc Duy, Oct 26, 2012
  6. 1/7 Move try_merge_command and checkout_fast_forward to libgit.aNguyễn Thái Ngọc Duy, Oct 26, 2012
  7. 2/7 Move estimate_bisect_steps to libgit.aNguyễn Thái Ngọc Duy, Oct 26, 2012
  8. 3/7 Move print_commit_list to libgit.aNguyễn Thái Ngọc Duy, Oct 26, 2012
  9. 4/7 Move setup_diff_pager to libgit.aNguyễn Thái Ngọc Duy, Oct 26, 2012
  10. 5/7 send-pack: move core code to libgit.aNguyễn Thái Ngọc Duy, Oct 26, 2012
  11. 6/7 fetch-pack: remove global (static) configuration variable "args"Nguyễn Thái Ngọc Duy, Oct 26, 2012
  12. 7/7 fetch-pack: move core code to libgit.aNguyễn Thái Ngọc Duy, Oct 26, 2012
  13. Jeff KingOct 29, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.