Merge branch 'cc/bisect' (early part)

* 'cc/bisect' (early part):
  t6030: test skipping away from an already skipped commit
  bisect: when skipping, choose a commit away from a skipped commit
  bisect: add parameters to "filter_skipped"
  bisect: display first bad commit without forking a new process
  bisect: drop unparse_commit() and use clear_commit_marks()
This commit is contained in:
Junio C Hamano 2009-06-13 12:53:06 -07:00
commit cec3f989da
6 changed files with 130 additions and 32 deletions

120
bisect.c
View File

@ -7,6 +7,7 @@
#include "quote.h" #include "quote.h"
#include "sha1-lookup.h" #include "sha1-lookup.h"
#include "run-command.h" #include "run-command.h"
#include "log-tree.h"
#include "bisect.h" #include "bisect.h"
struct sha1_array { struct sha1_array {
@ -27,7 +28,6 @@ struct argv_array {
int argv_alloc; int argv_alloc;
}; };
static const char *argv_diff_tree[] = {"diff-tree", "--pretty", NULL, NULL};
static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL}; static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
static const char *argv_show_branch[] = {"show-branch", NULL, NULL}; static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
@ -521,14 +521,34 @@ static char *join_sha1_array_hex(struct sha1_array *array, char delim)
return strbuf_detach(&joined_hexs, NULL); return strbuf_detach(&joined_hexs, NULL);
} }
/*
* In this function, passing a not NULL skipped_first is very special.
* It means that we want to know if the first commit in the list is
* skipped because we will want to test a commit away from it if it is
* indeed skipped.
* So if the first commit is skipped, we cannot take the shortcut to
* just "return list" when we find the first non skipped commit, we
* have to return a fully filtered list.
*
* We use (*skipped_first == -1) to mean "it has been found that the
* first commit is not skipped". In this case *skipped_first is set back
* to 0 just before the function returns.
*/
struct commit_list *filter_skipped(struct commit_list *list, struct commit_list *filter_skipped(struct commit_list *list,
struct commit_list **tried, struct commit_list **tried,
int show_all) int show_all,
int *count,
int *skipped_first)
{ {
struct commit_list *filtered = NULL, **f = &filtered; struct commit_list *filtered = NULL, **f = &filtered;
*tried = NULL; *tried = NULL;
if (skipped_first)
*skipped_first = 0;
if (count)
*count = 0;
if (!skipped_revs.sha1_nr) if (!skipped_revs.sha1_nr)
return list; return list;
@ -537,22 +557,82 @@ struct commit_list *filter_skipped(struct commit_list *list,
list->next = NULL; list->next = NULL;
if (0 <= lookup_sha1_array(&skipped_revs, if (0 <= lookup_sha1_array(&skipped_revs,
list->item->object.sha1)) { list->item->object.sha1)) {
if (skipped_first && !*skipped_first)
*skipped_first = 1;
/* Move current to tried list */ /* Move current to tried list */
*tried = list; *tried = list;
tried = &list->next; tried = &list->next;
} else { } else {
if (!show_all) if (!show_all) {
return list; if (!skipped_first || !*skipped_first)
return list;
} else if (skipped_first && !*skipped_first) {
/* This means we know it's not skipped */
*skipped_first = -1;
}
/* Move current to filtered list */ /* Move current to filtered list */
*f = list; *f = list;
f = &list->next; f = &list->next;
if (count)
(*count)++;
} }
list = next; list = next;
} }
if (skipped_first && *skipped_first == -1)
*skipped_first = 0;
return filtered; return filtered;
} }
static struct commit_list *apply_skip_ratio(struct commit_list *list,
int count,
int skip_num, int skip_denom)
{
int index, i;
struct commit_list *cur, *previous;
cur = list;
previous = NULL;
index = count * skip_num / skip_denom;
for (i = 0; cur; cur = cur->next, i++) {
if (i == index) {
if (hashcmp(cur->item->object.sha1, current_bad_sha1))
return cur;
if (previous)
return previous;
return list;
}
previous = cur;
}
return list;
}
static struct commit_list *managed_skipped(struct commit_list *list,
struct commit_list **tried)
{
int count, skipped_first;
int skip_num, skip_denom;
*tried = NULL;
if (!skipped_revs.sha1_nr)
return list;
list = filter_skipped(list, tried, 0, &count, &skipped_first);
if (!skipped_first)
return list;
/* Use alternatively 1/5, 2/5 and 3/5 as skip ratio. */
skip_num = count % 3 + 1;
skip_denom = 5;
return apply_skip_ratio(list, count, skip_num, skip_denom);
}
static void bisect_rev_setup(struct rev_info *revs, const char *prefix, static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
const char *bad_format, const char *good_format, const char *bad_format, const char *good_format,
int read_paths) int read_paths)
@ -771,7 +851,7 @@ static int check_ancestors(const char *prefix)
/* Clean up objects used, as they will be reused. */ /* Clean up objects used, as they will be reused. */
for (i = 0; i < pending_copy.nr; i++) { for (i = 0; i < pending_copy.nr; i++) {
struct object *o = pending_copy.objects[i].item; struct object *o = pending_copy.objects[i].item;
unparse_commit((struct commit *)o); clear_commit_marks((struct commit *)o, ALL_REV_FLAGS);
} }
return res; return res;
@ -815,6 +895,31 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
close(fd); close(fd);
} }
/*
* This does "git diff-tree --pretty COMMIT" without one fork+exec.
*/
static void show_diff_tree(const char *prefix, struct commit *commit)
{
struct rev_info opt;
/* diff-tree init */
init_revisions(&opt, prefix);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
opt.abbrev = 0;
opt.diff = 1;
/* This is what "--pretty" does */
opt.verbose_header = 1;
opt.use_terminator = 0;
opt.commit_format = CMIT_FMT_DEFAULT;
/* diff-tree init */
if (!opt.diffopt.output_format)
opt.diffopt.output_format = DIFF_FORMAT_RAW;
log_tree_commit(&opt, commit);
}
/* /*
* We use the convention that exiting with an exit code 10 means that * We use the convention that exiting with an exit code 10 means that
* the bisection process finished successfully. * the bisection process finished successfully.
@ -840,7 +945,7 @@ int bisect_next_all(const char *prefix)
revs.commits = find_bisection(revs.commits, &reaches, &all, revs.commits = find_bisection(revs.commits, &reaches, &all,
!!skipped_revs.sha1_nr); !!skipped_revs.sha1_nr);
revs.commits = filter_skipped(revs.commits, &tried, 0); revs.commits = managed_skipped(revs.commits, &tried);
if (!revs.commits) { if (!revs.commits) {
/* /*
@ -860,8 +965,7 @@ int bisect_next_all(const char *prefix)
if (!hashcmp(bisect_rev, current_bad_sha1)) { if (!hashcmp(bisect_rev, current_bad_sha1)) {
exit_if_skipped_commits(tried, current_bad_sha1); exit_if_skipped_commits(tried, current_bad_sha1);
printf("%s is first bad commit\n", bisect_rev_hex); printf("%s is first bad commit\n", bisect_rev_hex);
argv_diff_tree[2] = bisect_rev_hex; show_diff_tree(prefix, revs.commits->item);
run_command_v_opt(argv_diff_tree, RUN_GIT_CMD);
/* This means the bisection process succeeded. */ /* This means the bisection process succeeded. */
exit(10); exit(10);
} }

View File

@ -7,7 +7,9 @@ extern struct commit_list *find_bisection(struct commit_list *list,
extern struct commit_list *filter_skipped(struct commit_list *list, extern struct commit_list *filter_skipped(struct commit_list *list,
struct commit_list **tried, struct commit_list **tried,
int show_all); int show_all,
int *count,
int *skipped_first);
extern void print_commit_list(struct commit_list *list, extern void print_commit_list(struct commit_list *list,
const char *format_cur, const char *format_cur,

View File

@ -262,7 +262,9 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
if (!revs->commits && !(flags & BISECT_SHOW_TRIED)) if (!revs->commits && !(flags & BISECT_SHOW_TRIED))
return 1; return 1;
revs->commits = filter_skipped(revs->commits, &tried, flags & BISECT_SHOW_ALL); revs->commits = filter_skipped(revs->commits, &tried,
flags & BISECT_SHOW_ALL,
NULL, NULL);
/* /*
* revs->commits can reach "reaches" commits among * revs->commits can reach "reaches" commits among

View File

@ -316,26 +316,6 @@ int parse_commit(struct commit *item)
return ret; return ret;
} }
static void unparse_commit_list(struct commit_list *list)
{
for (; list; list = list->next)
unparse_commit(list->item);
}
void unparse_commit(struct commit *item)
{
item->object.flags = 0;
item->object.used = 0;
if (item->object.parsed) {
item->object.parsed = 0;
if (item->parents) {
unparse_commit_list(item->parents);
free_commit_list(item->parents);
item->parents = NULL;
}
}
}
struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p) struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
{ {
struct commit_list *new_list = xmalloc(sizeof(struct commit_list)); struct commit_list *new_list = xmalloc(sizeof(struct commit_list));

View File

@ -40,8 +40,6 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
int parse_commit(struct commit *item); int parse_commit(struct commit *item);
void unparse_commit(struct commit *item);
struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p);
unsigned commit_list_count(const struct commit_list *l); unsigned commit_list_count(const struct commit_list *l);
struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);

View File

@ -555,6 +555,18 @@ test_expect_success 'restricting bisection on one dir and a file' '
grep "$PARA_HASH4 is first bad commit" my_bisect_log.txt grep "$PARA_HASH4 is first bad commit" my_bisect_log.txt
' '
test_expect_success 'skipping away from skipped commit' '
git bisect start $PARA_HASH7 $HASH1 &&
para4=$(git rev-parse --verify HEAD) &&
test "$para4" = "$PARA_HASH4" &&
git bisect skip &&
hash7=$(git rev-parse --verify HEAD) &&
test "$hash7" = "$HASH7" &&
git bisect skip &&
hash3=$(git rev-parse --verify HEAD) &&
test "$hash3" = "$HASH3"
'
# #
# #
test_done test_done