git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Manuel Bärenz" <manuel@enigmage.de>
To: git@vger.kernel.org
Subject: Feature request: Exponential search in git bisect
Date: Fri, 9 Oct 2020 14:56:27 +0200	[thread overview]
Message-ID: <945ab20e-dcde-540e-83a5-83992c2187b1@enigmage.de> (raw)

This feature was requested 8 years ago and briefly discussed:
https://public-inbox.org/git/20120318212957.GS1219@chaosreigns.com/


  TL;DR

Before doing git bisect, I want to use exponential search to
automatically find a good commit, in logarithmic time.


  Scenario

  * I have a bug in HEAD.
  * I strongly suspect that it was introduced some time ago, but I don't
    know when exactly.
  * I have an automated test that will find the bug if the test can run
    properly.
  * Most of the commits in the repository are not testable, i.e. the
    test doesn't run properly. (E.g. because the feature it tests wasn't
    introduced yet, refactoring, etc.)
  * I have no idea what a good commit might be, because I don't know
    when the first /testable/ good commit is.

This sounds like a standard application for git bisect. No matter how
big the repo, with binary search we would expect to find the first bad
commit in logarithmic time.


  Failed attempt

The zeroth idea might be trying to find the good commit by hand, by
reading changelogs, by trying some commits, whatever. In some
situations, this is not feasible. In fact, such situations occur
frequently for me, for example for undocumented features, unversioned
rolling releases, incidental complexity leading to older commits not
being testable, etc.

The first idea that comes to mind - and it was recommended 8 years agos,
and I've tried it a few times already - is to simply mark the root
commit as good. (Now, there might be several roots, but that's a puzzle
you typically only have to figure out once per repo.) This sounds great
in theory because binary search should get through the good old commits
in logarithmic time.

The problem with this approach is that if most older commits are
untestable, I have to git bisect skip them. This basically kills the
logarithmic performance, because bisect skip doesn't do binary search,
but something rather random. Just yesterday I killed a bisect search
that took hours because it kept skipping and didn't find actual good
commits.

You might say that instead of skipping old commits, one should mark them
as good. That's problematic because then I might accidentally mark a
commit as good that was already untestable bad. Given that bisect has no
undo functionality, that can quickly mess up my search. Distinguishing
untestable good from untestable bad is really hard automatically. I
shouldn't have to do that.

Long story short: Going from the root commit typically isn't feasible.
I've tried it.


  Proposal: Exponential search

Instead of going from the root commit, what I do manually before
starting git bisect is this:

git checkout HEAD~10
./test.sh # Says: "Bug is present"
git checkout HEAD~20
./test.sh # Says: "Bug is still present"
git checkout HEAD~40
./test.sh # Says: "Bug is still present"
[...] # Proceed exponentially
git checkout HEAD~640
./test.sh # Says: "Bug is GONE!"
git bisect good

This technique is known as
https://en.wikipedia.org/wiki/Exponential_search, and it works very well
in practice. I find a good commit long before I enter the "untestable
good" region. But it's tedious to do this manually. In this example, I
needed to run the script 8 times manually, but of course it can be more
often, and compiling and running the test may take time. This is ok for
a one-off search, but it's tedious for regular usages.

Yes, I could wrap this up in a shell script, but I guess there are
caveats that I didn't think of when the history isn't linear. Maybe
someone even already has, and I'm unaware of that. But it feels like
this could be a proper git bisect feature, and a very useful one.

             reply	other threads:[~2020-10-09 12:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09 12:56 Manuel Bärenz [this message]
2020-10-10  9:22 ` Feature request: Exponential search in git bisect Christian Couder
2020-10-10  9:46   ` Christian Couder
2020-10-25 17:15   ` Philip Oakley
2020-10-26 18:13     ` Junio C Hamano
2020-10-26 20:59       ` Philip Oakley
2020-11-01 20:17     ` Manuel Bärenz
2020-10-27 12:10 ` Ævar Arnfjörð Bjarmason
2020-11-01 20:30   ` Manuel Bärenz
2020-11-02 10:36     ` Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=945ab20e-dcde-540e-83a5-83992c2187b1@enigmage.de \
    --to=manuel@enigmage.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).