]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bisect: add parameters to "filter_skipped"
authorChristian Couder <chriscool@tuxfamily.org>
Sat, 6 Jun 2009 04:41:33 +0000 (06:41 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 6 Jun 2009 18:26:56 +0000 (11:26 -0700)
because we will need to get more information from this function in
some later patches.

The new "int *count" parameter gives the number of commits left after
the skipped commit have been filtered out.

The new "int *skipped_first" parameter tells us if the first commit
in the list has been skipped. Note that using this parameter also
changes the behavior of the function if the first commit is indeed
skipped. Because we assume that in this case we will want all the
filtered commits, not just the first one, even if "show_all" is not
set.

So using a not NULL "skipped_first" parameter really means that we
plan to choose to test another commit than the first non skipped
one if the first commit in the list is skipped. That in turn means
that, in case the first commit is skipped, we have to return a
fully filtered list.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bisect.c
bisect.h
builtin-rev-list.c

index 2c14f4d61669582da51013ceddc260eec9a134ec..115cf5fa41d91c047ee2081bf0d22cb6ae638970 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -521,14 +521,34 @@ static char *join_sha1_array_hex(struct sha1_array *array, char delim)
        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 **tried,
-                                  int show_all)
+                                  int show_all,
+                                  int *count,
+                                  int *skipped_first)
 {
        struct commit_list *filtered = NULL, **f = &filtered;
 
        *tried = NULL;
 
+       if (skipped_first)
+               *skipped_first = 0;
+       if (count)
+               *count = 0;
+
        if (!skipped_revs.sha1_nr)
                return list;
 
@@ -537,19 +557,31 @@ struct commit_list *filter_skipped(struct commit_list *list,
                list->next = NULL;
                if (0 <= lookup_sha1_array(&skipped_revs,
                                           list->item->object.sha1)) {
+                       if (skipped_first && !*skipped_first)
+                               *skipped_first = 1;
                        /* Move current to tried list */
                        *tried = list;
                        tried = &list->next;
                } else {
-                       if (!show_all)
-                               return list;
+                       if (!show_all) {
+                               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 */
                        *f = list;
                        f = &list->next;
+                       if (count)
+                               (*count)++;
                }
                list = next;
        }
 
+       if (skipped_first && *skipped_first == -1)
+               *skipped_first = 0;
+
        return filtered;
 }
 
@@ -865,7 +897,7 @@ int bisect_next_all(const char *prefix)
 
        revs.commits = find_bisection(revs.commits, &reaches, &all,
                                       !!skipped_revs.sha1_nr);
-       revs.commits = filter_skipped(revs.commits, &tried, 0);
+       revs.commits = filter_skipped(revs.commits, &tried, 0, NULL, NULL);
 
        if (!revs.commits) {
                /*
index fb744fdb79e1dd4a46cd3f2759b73747d8e79fbd..82f8fc1910a42c5c90ad3312d9aa8f35ef2b992f 100644 (file)
--- a/bisect.h
+++ b/bisect.h
@@ -7,7 +7,9 @@ extern struct commit_list *find_bisection(struct commit_list *list,
 
 extern struct commit_list *filter_skipped(struct commit_list *list,
                                          struct commit_list **tried,
-                                         int show_all);
+                                         int show_all,
+                                         int *count,
+                                         int *skipped_first);
 
 extern void print_commit_list(struct commit_list *list,
                              const char *format_cur,
index 31ea5f4aac4559a69ed5b0033696fff2333f5e5a..4ba1c12e0b6fedb056aebed6ffc8f8bb8d6cfd18 100644 (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))
                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