~ubuntu-branches/debian/sid/git/sid

« back to all changes in this revision

Viewing changes to bisect.c

  • Committer: Package Import Robot
  • Author(s): Jonathan Nieder
  • Date: 2013-06-12 07:50:53 UTC
  • mfrom: (1.2.19) (2.1.31 experimental)
  • Revision ID: package-import@ubuntu.com-20130612075053-uue9xe0dq0rvm44y
Tags: 1:1.8.3.1-1
* merge branch debian-experimental
* new upstream point release (see RelNotes/1.8.3.1.txt).
* debian/watch: use xz-compressed tarballs from kernel.org.

Show diffs side-by-side

added added

removed removed

Lines of Context:
525
525
 * is increased by one between each call, but that should not matter
526
526
 * for this application.
527
527
 */
528
 
static int get_prn(int count) {
 
528
static unsigned get_prn(unsigned count) {
529
529
        count = count * 1103515245 + 12345;
530
 
        return ((unsigned)(count/65536) % PRN_MODULO);
 
530
        return (count/65536) % PRN_MODULO;
531
531
}
532
532
 
533
533
/*
833
833
 */
834
834
static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
835
835
{
836
 
        const char *filename = git_path("BISECT_ANCESTORS_OK");
 
836
        char *filename = git_pathdup("BISECT_ANCESTORS_OK");
837
837
        struct stat st;
838
838
        int fd;
839
839
 
842
842
 
843
843
        /* Check if file BISECT_ANCESTORS_OK exists. */
844
844
        if (!stat(filename, &st) && S_ISREG(st.st_mode))
845
 
                return;
 
845
                goto done;
846
846
 
847
847
        /* Bisecting with no good rev is ok. */
848
848
        if (good_revs.nr == 0)
849
 
                return;
 
849
                goto done;
850
850
 
851
851
        /* Check if all good revs are ancestor of the bad rev. */
852
852
        if (check_ancestors(prefix))
859
859
                        filename, strerror(errno));
860
860
        else
861
861
                close(fd);
 
862
 done:
 
863
        free(filename);
862
864
}
863
865
 
864
866
/*
954
956
        return bisect_checkout(bisect_rev_hex, no_checkout);
955
957
}
956
958
 
 
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
}