From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/7] Move estimate_bisect_steps to libgit.a
Date: Fri, 26 Oct 2012 22:53:50 +0700 [thread overview]
Message-ID: <1351266835-22610-3-git-send-email-pclouds@gmail.com> (raw)
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
next prev parent reply other threads:[~2012-10-26 15:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-23 2:24 [PATCH] Move try_merge_command and checkout_fast_forward to libgit.a Nguyễn Thái Ngọc Duy
2012-10-25 9:45 ` Jeff King
2012-10-25 12:50 ` Nguyen Thai Ngoc Duy
2012-10-26 12:02 ` Jeff King
2012-10-26 15:53 ` [PATCH 0/7] Move code from builtin " Nguyễn Thái Ngọc Duy
2012-10-26 15:53 ` [PATCH 1/7] Move try_merge_command and checkout_fast_forward " Nguyễn Thái Ngọc Duy
2012-10-26 15:53 ` Nguyễn Thái Ngọc Duy [this message]
2012-10-26 15:53 ` [PATCH 3/7] Move print_commit_list " Nguyễn Thái Ngọc Duy
2012-10-26 15:53 ` [PATCH 4/7] Move setup_diff_pager " Nguyễn Thái Ngọc Duy
2012-10-26 15:53 ` [PATCH 5/7] send-pack: move core code " Nguyễn Thái Ngọc Duy
2012-10-26 15:53 ` [PATCH 6/7] fetch-pack: remove global (static) configuration variable "args" Nguyễn Thái Ngọc Duy
2012-10-26 15:53 ` [PATCH 7/7] fetch-pack: move core code to libgit.a Nguyễn Thái Ngọc Duy
2012-10-29 7:43 ` [PATCH 0/7] Move code from builtin " Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1351266835-22610-3-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).