Revision 4e1dc640097d4e389f12bcf12f75cdf7e4ceae61 authored by Junio C Hamano on 14 April 2006, 22:57:32 UTC, committed by Junio C Hamano on 15 April 2006, 04:52:50 UTC
I noticed bisect does not work well without both good and bad.
Running this script in git.git repository would give you quite
different results:

	#!/bin/sh
        initial=e83c5163316f89bfbde7d9ab23ca2e25604af290

        mid0=`git rev-list --bisect ^$initial --all`

        git rev-list $mid0 | wc -l
        git rev-list ^$mid0 --all | wc -l

        mid1=`git rev-list --bisect --all`

        git rev-list $mid1 | wc -l
        git rev-list ^$mid1 --all | wc -l

The $initial commit is the very first commit you made.  The
first midpoint bisects things evenly as designed, but the latter
does not.

The reason I got interested in this was because I was wondering
if something like the following would help people converting a
huge repository from foreign SCM, or preparing a repository to
be fetched over plain dumb HTTP only:

        #!/bin/sh

        N=4
        P=.git/objects/pack
        bottom=

        while test 0 \< $N
        do
                N=$((N-1))
                if test -z "$bottom"
                then
                        newbottom=`git rev-list --bisect --all`
                else
                        newbottom=`git rev-list --bisect ^$bottom --all`
                fi
                if test -z "$bottom"
                then
                        rev_list="$newbottom"
                elif test 0 = $N
                then
                        rev_list="^$bottom --all"
                else
                        rev_list="^$bottom $newbottom"
                fi
                p=$(git rev-list --unpacked --objects $rev_list |
                    git pack-objects $P/pack)
                git show-index <$P/pack-$p.idx | wc -l
                bottom=$newbottom
        done

The idea is to pack older half of the history to one pack, then
older half of the remaining history to another, to continue a
few times, using finer granularity as we get closer to the tip.

This may not matter, since for a truly huge history, running
bisect number of times could be quite time consuming, and we
might be better off running "git rev-list --all" once into a
temporary file, and manually pick cut-off points from the
resulting list of commits.  After all we are talking about
"approximately half" for such an usage, and older history does
not matter much.

Signed-off-by: Junio C Hamano <junkio@cox.net>

1 parent 40c2fe0
Raw File
t4109-apply-multifrag.sh
#!/bin/sh
#
# Copyright (c) 2005 Junio C Hamano
# Copyright (c) 2005 Robert Fitzsimons
#

test_description='git-apply test patches with multiple fragments.

'
. ./test-lib.sh

# setup

cat > patch1.patch <<\EOF
diff --git a/main.c b/main.c
new file mode 100644
--- /dev/null
+++ b/main.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int func(int num);
+void print_int(int num);
+
+int main() {
+	int i;
+
+	for (i = 0; i < 10; i++) {
+		print_int(func(i));
+	}
+
+	return 0;
+}
+
+int func(int num) {
+	return num * num;
+}
+
+void print_int(int num) {
+	printf("%d", num);
+}
+
EOF
cat > patch2.patch <<\EOF
diff --git a/main.c b/main.c
--- a/main.c
+++ b/main.c
@@ -1,7 +1,9 @@
+#include <stdlib.h>
 #include <stdio.h>
 
 int func(int num);
 void print_int(int num);
+void print_ln();
 
 int main() {
 	int i;
@@ -10,6 +12,8 @@
 		print_int(func(i));
 	}
 
+	print_ln();
+
 	return 0;
 }
 
@@ -21,3 +25,7 @@
 	printf("%d", num);
 }
 
+void print_ln() {
+	printf("\n");
+}
+
EOF
cat > patch3.patch <<\EOF
diff --git a/main.c b/main.c
--- a/main.c
+++ b/main.c
@@ -1,9 +1,7 @@
-#include <stdlib.h>
 #include <stdio.h>
 
 int func(int num);
 void print_int(int num);
-void print_ln();
 
 int main() {
 	int i;
@@ -12,8 +10,6 @@
 		print_int(func(i));
 	}
 
-	print_ln();
-
 	return 0;
 }
 
@@ -25,7 +21,3 @@
 	printf("%d", num);
 }
 
-void print_ln() {
-	printf("\n");
-}
-
EOF
cat > patch4.patch <<\EOF
diff --git a/main.c b/main.c
--- a/main.c
+++ b/main.c
@@ -1,13 +1,14 @@
 #include <stdio.h>
 
 int func(int num);
-void print_int(int num);
+int func2(int num);
 
 int main() {
 	int i;
 
 	for (i = 0; i < 10; i++) {
-		print_int(func(i));
+		printf("%d", func(i));
+		printf("%d", func3(i));
 	}
 
 	return 0;
@@ -17,7 +18,7 @@
 	return num * num;
 }
 
-void print_int(int num) {
-	printf("%d", num);
+int func2(int num) {
+	return num * num * num;
 }
 
EOF

test_expect_success "S = git-apply (1)" \
    'git-apply patch1.patch patch2.patch'
mv main.c main.c.git

test_expect_success "S = patch (1)" \
    'cat patch1.patch patch2.patch | patch -p1'

test_expect_success "S = cmp (1)" \
    'cmp main.c.git main.c'

rm -f main.c main.c.git

test_expect_success "S = git-apply (2)" \
    'git-apply patch1.patch patch2.patch patch3.patch'
mv main.c main.c.git

test_expect_success "S = patch (2)" \
    'cat patch1.patch patch2.patch patch3.patch | patch -p1'

test_expect_success "S = cmp (2)" \
    'cmp main.c.git main.c'

rm -f main.c main.c.git

test_expect_success "S = git-apply (3)" \
    'git-apply patch1.patch patch4.patch'
mv main.c main.c.git

test_expect_success "S = patch (3)" \
    'cat patch1.patch patch4.patch | patch -p1'

test_expect_success "S = cmp (3)" \
    'cmp main.c.git main.c'

test_done

back to top