Skip to content

Commit 19fb613

Browse files
committed
Merge branch 'nd/builtin-to-libgit'
Code cleanups so that libgit.a does not depend on anything in the builtin/ directory. * nd/builtin-to-libgit: fetch-pack: move core code to libgit.a fetch-pack: remove global (static) configuration variable "args" send-pack: move core code to libgit.a Move setup_diff_pager to libgit.a Move print_commit_list to libgit.a Move estimate_bisect_steps to libgit.a Move try_merge_command and checkout_fast_forward to libgit.a
2 parents 9d91c0e + 745f7a8 commit 19fb613

22 files changed

+1535
-1497
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ LIB_OBJS += editor.o
746746
LIB_OBJS += entry.o
747747
LIB_OBJS += environment.o
748748
LIB_OBJS += exec_cmd.o
749+
LIB_OBJS += fetch-pack.o
749750
LIB_OBJS += fsck.o
750751
LIB_OBJS += gettext.o
751752
LIB_OBJS += gpg-interface.o
@@ -763,6 +764,7 @@ LIB_OBJS += lockfile.o
763764
LIB_OBJS += log-tree.o
764765
LIB_OBJS += mailmap.o
765766
LIB_OBJS += match-trees.o
767+
LIB_OBJS += merge.o
766768
LIB_OBJS += merge-file.o
767769
LIB_OBJS += merge-recursive.o
768770
LIB_OBJS += mergesort.o
@@ -797,6 +799,7 @@ LIB_OBJS += rerere.o
797799
LIB_OBJS += resolve-undo.o
798800
LIB_OBJS += revision.o
799801
LIB_OBJS += run-command.o
802+
LIB_OBJS += send-pack.o
800803
LIB_OBJS += sequencer.o
801804
LIB_OBJS += server-info.o
802805
LIB_OBJS += setup.o

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+
}

bisect.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
1111
int *count,
1212
int *skipped_first);
1313

14-
extern void print_commit_list(struct commit_list *list,
15-
const char *format_cur,
16-
const char *format_last);
17-
1814
#define BISECT_SHOW_ALL (1<<0)
1915
#define REV_LIST_QUIET (1<<1)
2016

builtin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
3737
const unsigned char *from_obj, const unsigned char *to_obj);
3838
void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
3939

40-
extern int check_pager_config(const char *cmd);
41-
struct diff_options;
42-
extern void setup_diff_pager(struct diff_options *);
43-
4440
extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
4541

4642
extern int cmd_add(int argc, const char **argv, const char *prefix);

builtin/diff.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,3 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
418418
refresh_index_quietly();
419419
return result;
420420
}
421-
422-
void setup_diff_pager(struct diff_options *opt)
423-
{
424-
/*
425-
* If the user asked for our exit code, then either they want --quiet
426-
* or --exit-code. We should definitely not bother with a pager in the
427-
* former case, as we will generate no output. Since we still properly
428-
* report our exit code even when a pager is run, we _could_ run a
429-
* pager with --exit-code. But since we have not done so historically,
430-
* and because it is easy to find people oneline advising "git diff
431-
* --exit-code" in hooks and other scripts, we do not do so.
432-
*/
433-
if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
434-
check_pager_config("diff") != 0)
435-
setup_pager();
436-
}

0 commit comments

Comments
 (0)