Skip to content

Commit

Permalink
Merge branch 'nd/builtin-to-libgit'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jeff King committed Nov 9, 2012
2 parents 9d91c0e + 745f7a8 commit 19fb613
Show file tree
Hide file tree
Showing 22 changed files with 1,535 additions and 1,497 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ LIB_OBJS += editor.o
LIB_OBJS += entry.o
LIB_OBJS += environment.o
LIB_OBJS += exec_cmd.o
LIB_OBJS += fetch-pack.o
LIB_OBJS += fsck.o
LIB_OBJS += gettext.o
LIB_OBJS += gpg-interface.o
Expand All @@ -763,6 +764,7 @@ LIB_OBJS += lockfile.o
LIB_OBJS += log-tree.o
LIB_OBJS += mailmap.o
LIB_OBJS += match-trees.o
LIB_OBJS += merge.o
LIB_OBJS += merge-file.o
LIB_OBJS += merge-recursive.o
LIB_OBJS += mergesort.o
Expand Down Expand Up @@ -797,6 +799,7 @@ LIB_OBJS += rerere.o
LIB_OBJS += resolve-undo.o
LIB_OBJS += revision.o
LIB_OBJS += run-command.o
LIB_OBJS += send-pack.o
LIB_OBJS += sequencer.o
LIB_OBJS += server-info.o
LIB_OBJS += setup.o
Expand Down
38 changes: 38 additions & 0 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions bisect.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ extern struct commit_list *filter_skipped(struct commit_list *list,
int *count,
int *skipped_first);

extern void print_commit_list(struct commit_list *list,
const char *format_cur,
const char *format_last);

#define BISECT_SHOW_ALL (1<<0)
#define REV_LIST_QUIET (1<<1)

Expand Down
4 changes: 0 additions & 4 deletions builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
const unsigned char *from_obj, const unsigned char *to_obj);
void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);

extern int check_pager_config(const char *cmd);
struct diff_options;
extern void setup_diff_pager(struct diff_options *);

extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);

extern int cmd_add(int argc, const char **argv, const char *prefix);
Expand Down
16 changes: 0 additions & 16 deletions builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,3 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
refresh_index_quietly();
return result;
}

void setup_diff_pager(struct diff_options *opt)
{
/*
* If the user asked for our exit code, then either they want --quiet
* or --exit-code. We should definitely not bother with a pager in the
* former case, as we will generate no output. Since we still properly
* report our exit code even when a pager is run, we _could_ run a
* pager with --exit-code. But since we have not done so historically,
* and because it is easy to find people oneline advising "git diff
* --exit-code" in hooks and other scripts, we do not do so.
*/
if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
check_pager_config("diff") != 0)
setup_pager();
}
Loading

0 comments on commit 19fb613

Please sign in to comment.