* [RFC/PATCH 1/2] bisect: add "git bisect replace" subcommand
@ 2008-11-02 1:19 Christian Couder
2008-11-02 4:16 ` Johannes Schindelin
0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2008-11-02 1:19 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This new subcommand should be used when you have a branch or a part of
a branch that isn't easily bisectable because at some point, say A, a
bug as been introduced. The bug has been fixed latter at another point,
say B, but between these points the code is not easily testable because
of the bug, so it's not easy to bisect between these points.
In this case you can create a branch starting at the parent of A, say
O, that has a fixed history. In this fixed history for example, there
could be first a commit C that is the result of squashing A and B
together and then all the commit between A and B that have been
cherry picked.
For example, let's say the commits between A and B are X1, X2, ... Xn
and they have been cherry picked after C as Y1, Y2, ... Yn:
C--Y1--Y2--...--Yn
/
...--O--A--X1--X2--...--Xn--B--...
By design, the last cherry picked commit (Yn) should point to the same
tree as commit B.
So in this case you can say:
$ git bisect replace B Yn
and commit B will be tagged with a special name like:
"bisect-replace-with-Yn"
When bisecting, commit with those tags will be grafted so that their
parents will be replaced by the commit specified in the tag.
In the example above that means that instead of the above graph, the
following graph will be bisected:
C--Y1--Y2--...--Yn
/ \
...--O B--...
This means that the bisections on this branch will be much easier
because the bug introduced by commit A and fixed by commit B will not
annoy you anymore.
---
builtin-rev-list.c | 29 ++++++++++++++++++++++++++++-
git-bisect.sh | 40 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 67 insertions(+), 2 deletions(-)
Thank you Junio for your help in designing this during the GitTogether,
especially for the trick to change the parents of the commit fixing the
bug.
I know this is lacking documentation but I plan to work on it soon and
send a documentation patch. The tests (in the following patch) are also
a bit lacking, so I will improve them too.
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 06cdeb7..5569bb2 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -529,6 +529,30 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
return best_bisection_sorted(list, nr);
}
+static int bisect_replace(const char *refname, const unsigned char *sha1,
+ int flag, void *cb_data)
+{
+ struct commit_graft *graft;
+
+ if (prefixcmp(refname, "bisect-replace-with-"))
+ return 0;
+
+ /* Create a graft to replace current commit */
+
+ graft = xmalloc(sizeof(*graft) + 20);
+
+ hashcpy(graft->sha1, sha1);
+ graft->nr_parent = 1;
+ if (get_sha1_hex(refname + 20, graft->parent[0])) {
+ free(graft);
+ return 0;
+ }
+
+ register_commit_graft(graft, 1);
+
+ return 0;
+}
+
static struct commit_list *find_bisection(struct commit_list *list,
int *reaches, int *all,
int find_all)
@@ -646,8 +670,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
save_commit_buffer = revs.verbose_header ||
revs.grep_filter.pattern_list;
- if (bisect_list)
+
+ if (bisect_list) {
+ for_each_tag_ref(bisect_replace, NULL);
revs.limited = 1;
+ }
if (prepare_revision_walk(&revs))
die("revision walk setup failed");
diff --git a/git-bisect.sh b/git-bisect.sh
index 0d0e278..245435c 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run]'
+USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run|replace]'
LONG_USAGE='git bisect help
print this long help message.
git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
@@ -23,6 +23,8 @@ git bisect log
show bisect log.
git bisect run <cmd>...
use <cmd>... to automatically bisect.
+git bisect replace <rev> [<rev>]
+ use another branch for bisection.
Please use "git help bisect" to get the full man page.'
@@ -618,6 +620,40 @@ bisect_run () {
done
}
+bisect_replace() {
+ test "$#" -ge 1 -a "$#" -le 2 ||
+ die "'git bisect replace' accept one or two arguments"
+
+ source="$1"
+ target="${2:-HEAD}"
+
+ # Check arguments
+ src_commit=$(git rev-parse --verify "$source^{commit}") ||
+ die "Bad rev input: $source"
+ tgt_commit=$(git rev-parse --verify "$target^{commit}") ||
+ die "Bad rev input: $target"
+
+ test "$src_commit" != "tgt_commit" ||
+ die "source and target should be different commits"
+
+ # Check that trees from source and target are identical
+ src_tree=$(git rev-parse --verify "$src_commit^{tree}") ||
+ die "Could not get tree for source: $source"
+ tgt_tree=$(git rev-parse --verify "$tgt_commit^{tree}") ||
+ die "Could not get tree for target: $target"
+
+ test "$src_tree" = "$tgt_tree" ||
+ die "source and target should point to the same tree"
+
+ # Tag the source commit
+ src_tag="bisect-replace-with-$tgt_commit"
+ git tag "$src_tag" "$src_commit" || exit
+
+ # Create branch for the target commit
+ tgt_branch="bisect-replace-$src_commit"
+ git branch "$tgt_branch" "$tgt_commit" || exit
+}
+
case "$#" in
0)
@@ -645,6 +681,8 @@ case "$#" in
cat "$GIT_DIR/BISECT_LOG" ;;
run)
bisect_run "$@" ;;
+ replace)
+ bisect_replace "$@" ;;
*)
usage ;;
esac
--
1.6.0.3.531.gd12eb.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [RFC/PATCH 1/2] bisect: add "git bisect replace" subcommand
2008-11-02 1:19 [RFC/PATCH 1/2] bisect: add "git bisect replace" subcommand Christian Couder
@ 2008-11-02 4:16 ` Johannes Schindelin
2008-11-02 11:20 ` Christian Couder
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2008-11-02 4:16 UTC (permalink / raw)
To: Christian Couder; +Cc: Junio C Hamano, git
Hi,
On Sun, 2 Nov 2008, Christian Couder wrote:
> This new subcommand should be used when you have a branch or a part of a
> branch that isn't easily bisectable because at some point, say A, a bug
> as been introduced. The bug has been fixed latter at another point, say
> B, but between these points the code is not easily testable because of
> the bug, so it's not easy to bisect between these points.
Would it not be more intuitive to have support for
git bisect skip A..B
?
Ciao,
Dscho
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC/PATCH 1/2] bisect: add "git bisect replace" subcommand
2008-11-02 4:16 ` Johannes Schindelin
@ 2008-11-02 11:20 ` Christian Couder
0 siblings, 0 replies; 3+ messages in thread
From: Christian Couder @ 2008-11-02 11:20 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Junio C Hamano, git
Hi,
Le dimanche 2 novembre 2008, Johannes Schindelin a écrit :
> Hi,
>
> On Sun, 2 Nov 2008, Christian Couder wrote:
> > This new subcommand should be used when you have a branch or a part of
> > a branch that isn't easily bisectable because at some point, say A, a
> > bug as been introduced. The bug has been fixed latter at another point,
> > say B, but between these points the code is not easily testable because
> > of the bug, so it's not easy to bisect between these points.
>
> Would it not be more intuitive to have support for
>
> git bisect skip A..B
>
> ?
We can have both. "bisect skip" is about not being able or wanting to test
some commits and "bisect replace" is about testing using fixed up branches
(that you can share with others) instead of branches that you can't test.
When working on big projects where many people are often bisecting (like the
Linux kernel), then having shared "bisect-replace" branches (and tags)
might save a lot of time to all people bisecting, as they will not have to
often skip the same commits or maintain sets of patches to apply when
bisecting.
Thanks,
Christian.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-11-02 11:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-02 1:19 [RFC/PATCH 1/2] bisect: add "git bisect replace" subcommand Christian Couder
2008-11-02 4:16 ` Johannes Schindelin
2008-11-02 11:20 ` Christian Couder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox