@matheusbsbs / matheus-bagliano / commits / e204de28e6
Fork 0

Keep bisection log so that it can be replayed later.

The 'git bisect' command was very unforgiving in that once you made a mistake telling it good/bad it was very hard to take it back. Keep a log of what you told it in an earlier session, so that it can be replayed after removing everything after what you botched last time. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Sep 10, 2005 at 15:18 UTC e204de28e69617265e88c73dd13c416ffa15f355
1 file changed +47 -3
git-bisect.sh
+47 -3
@@ -8,7 +8,9 @@ git bisect bad [<rev>] mark <rev> a known-bad revision.
8 git bisect good [<rev>...] mark <rev>... known-good revisions.
9 git bisect next find next bisection to test and check it out.
10 git bisect reset [<branch>] finish bisection search and go back to branch.
11 -git bisect visualize show bisect status in gitk.'
11 +git bisect visualize show bisect status in gitk.
12 +git bisect replay <logfile> replay bisection log
13 +git bisect log show bisect log.'
14 exit 1
15 }
16
@@ -54,6 +56,7 @@ bisect_start() {
56 rm -f "$GIT_DIR/refs/heads/bisect"
57 rm -rf "$GIT_DIR/refs/bisect/"
58 mkdir "$GIT_DIR/refs/bisect"
59 + echo "git-bisect start" >"$GIT_DIR/BISECT_LOG"
60 }
61
62 bisect_bad() {
@@ -66,7 +69,9 @@ bisect_bad() {
69 *)
70 usage ;;
71 esac || exit
69 - echo "$rev" > "$GIT_DIR/refs/bisect/bad"
72 + echo "$rev" >"$GIT_DIR/refs/bisect/bad"
73 + echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
74 + echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
75 bisect_auto_next
76 }
77
@@ -81,6 +86,8 @@ bisect_good() {
86 do
87 rev=$(git-rev-parse --verify "$rev") || exit
88 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
89 + echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
90 + echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
91 done
92 bisect_auto_next
93 }
@@ -129,6 +136,7 @@ bisect_next() {
136 git checkout new-bisect || exit
137 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
138 ln -sf refs/heads/bisect "$GIT_DIR/HEAD"
139 + git-show-branch "$rev"
140 }
141
142 bisect_visualize() {
@@ -149,7 +157,39 @@ bisect_reset() {
157 esac
158 git checkout "$branch" &&
159 rm -fr "$GIT_DIR/refs/bisect"
152 - rm -f "$GIT_DIR/refs/reads/bisect"
160 + rm -f "$GIT_DIR/refs/heads/bisect"
161 + rm -f "$GIT_DIR/BISECT_LOG"
162 +}
163 +
164 +bisect_replay () {
165 + test -r "$1" || {
166 + echo >&2 "cannot read $1 for replaying"
167 + exit 1
168 + }
169 + bisect_reset
170 + while read bisect command rev
171 + do
172 + test "$bisect" = "git-bisect" || continue
173 + case "$command" in
174 + start)
175 + bisect_start
176 + ;;
177 + good)
178 + echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
179 + echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
180 + echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
181 + ;;
182 + bad)
183 + echo "$rev" >"$GIT_DIR/refs/bisect/bad"
184 + echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
185 + echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
186 + ;;
187 + *)
188 + echo >&2 "?? what are you talking about?"
189 + exit 1 ;;
190 + esac
191 + done <"$1"
192 + bisect_auto_next
193 }
194
195 case "$#" in
@@ -172,6 +212,10 @@ case "$#" in
212 bisect_visualize "$@" ;;
213 reset)
214 bisect_reset "$@" ;;
215 + replay)
216 + bisect_replay "$@" ;;
217 + log)
218 + cat "$GIT_DIR/BISECT_LOG" ;;
219 *)
220 usage ;;
221 esac