{"thread":{"id":"54378","subject":"Feature request: Exponential search in git bisect","startedAt":"2020-10-09T12:56:32Z","lastAt":"2020-11-02T10:36:21Z","messageCount":10,"participants":["Manuel Bärenz","Christian Couder","Philip Oakley","Junio C Hamano","Ævar Arnfjörð Bjarmason"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"407206","messageId":"945ab20e-dcde-540e-83a5-83992c2187b1@enigmage.de","threadId":"54378","inReplyTo":null,"subject":"Feature request: Exponential search in git bisect","fromName":"Manuel Bärenz","fromEmail":"manuel@enigmage.de","sentAt":"2020-10-09T12:56:27Z","receivedAt":"2020-10-09T12:56:32Z","isPatch":false,"sender":{"key":"manuel@enigmage.de","avatar":"https://gravatar.com/avatar/463077d57f57e1dea9d975afbd18b2a895df6efa8e6a81d98e4e04a3cdbdc229?d=mp&s=160"},"body":"This feature was requested 8 years ago and briefly discussed:\nhttps://public-inbox.org/git/20120318212957.GS1219@chaosreigns.com/\n\n\n  TL;DR\n\nBefore doing git bisect, I want to use exponential search to\nautomatically find a good commit, in logarithmic time.\n\n\n  Scenario\n\n  * I have a bug in HEAD.\n  * I strongly suspect that it was introduced some time ago, but I don't\n    know when exactly.\n  * I have an automated test that will find the bug if the test can run\n    properly.\n  * Most of the commits in the repository are not testable, i.e. the\n    test doesn't run properly. (E.g. because the feature it tests wasn't\n    introduced yet, refactoring, etc.)\n  * I have no idea what a good commit might be, because I don't know\n    when the first /testable/ good commit is.\n\nThis sounds like a standard application for git bisect. No matter how\nbig the repo, with binary search we would expect to find the first bad\ncommit in logarithmic time.\n\n\n  Failed attempt\n\nThe zeroth idea might be trying to find the good commit by hand, by\nreading changelogs, by trying some commits, whatever. In some\nsituations, this is not feasible. In fact, such situations occur\nfrequently for me, for example for undocumented features, unversioned\nrolling releases, incidental complexity leading to older commits not\nbeing testable, etc.\n\nThe first idea that comes to mind - and it was recommended 8 years agos,\nand I've tried it a few times already - is to simply mark the root\ncommit as good. (Now, there might be several roots, but that's a puzzle\nyou typically only have to figure out once per repo.) This sounds great\nin theory because binary search should get through the good old commits\nin logarithmic time.\n\nThe problem with this approach is that if most older commits are\nuntestable, I have to git bisect skip them. This basically kills the\nlogarithmic performance, because bisect skip doesn't do binary search,\nbut something rather random. Just yesterday I killed a bisect search\nthat took hours because it kept skipping and didn't find actual good\ncommits.\n\nYou might say that instead of skipping old commits, one should mark them\nas good. That's problematic because then I might accidentally mark a\ncommit as good that was already untestable bad. Given that bisect has no\nundo functionality, that can quickly mess up my search. Distinguishing\nuntestable good from untestable bad is really hard automatically. I\nshouldn't have to do that.\n\nLong story short: Going from the root commit typically isn't feasible.\nI've tried it.\n\n\n  Proposal: Exponential search\n\nInstead of going from the root commit, what I do manually before\nstarting git bisect is this:\n\ngit checkout HEAD~10\n./test.sh # Says: \"Bug is present\"\ngit checkout HEAD~20\n./test.sh # Says: \"Bug is still present\"\ngit checkout HEAD~40\n./test.sh # Says: \"Bug is still present\"\n[...] # Proceed exponentially\ngit checkout HEAD~640\n./test.sh # Says: \"Bug is GONE!\"\ngit bisect good\n\nThis technique is known as\nhttps://en.wikipedia.org/wiki/Exponential_search, and it works very well\nin practice. I find a good commit long before I enter the \"untestable\ngood\" region. But it's tedious to do this manually. In this example, I\nneeded to run the script 8 times manually, but of course it can be more\noften, and compiling and running the test may take time. This is ok for\na one-off search, but it's tedious for regular usages.\n\nYes, I could wrap this up in a shell script, but I guess there are\ncaveats that I didn't think of when the history isn't linear. Maybe\nsomeone even already has, and I'm unaware of that. But it feels like\nthis could be a proper git bisect feature, and a very useful one.\n"},{"id":"407269","messageId":"CAP8UFD16WX-HE6TW2Q15a3us8UMaogPpR+0C8shiEdP3-Cba=Q@mail.gmail.com","threadId":"54378","inReplyTo":"CAP8UFD2dWrUXJUuiFtgCu6krbnbGGqJZ7K+6KqstGTcNmSc_xQ@mail.gmail.com","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2020-10-10T09:46:44Z","receivedAt":"2020-10-10T22:56:37Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Sat, Oct 10, 2020 at 11:22 AM Christian Couder\n<christian.couder@gmail.com> wrote:\n>\n> On Fri, Oct 9, 2020 at 9:35 PM Manuel Bärenz <manuel@enigmage.de> wrote:\n\n> > That's problematic because then I might accidentally mark a\n> > commit as good that was already untestable bad. Given that bisect has no\n> > undo functionality, that can quickly mess up my search. Distinguishing\n> > untestable good from untestable bad is really hard automatically. I\n> > shouldn't have to do that.\n>\n> Sometimes it's not very difficult to test if the feature has been\n> implemented yet or not. For example with Git you could check if an\n> option for a command has been implemented by just checking if it\n> appears in the doc. So the bisection script could first check that and\n> exit 0 (which means good) if the option doesn't appear in the doc. If\n> it appears in the doc, then it could do the regular test: \"skip\" if\n> untestable, \"good\" if there is no bug, \"bad\" otherwise.\n\nAlso note that it might actually be simpler in many cases to find when\na feature has been implemented by different means than some checks in\nthe script.\n\nFor example in the above example to find using the documentation when\nan option for a Git command has been implemented, one could use:\n\ngit log --reverse  -S'--option' Documentation/git-command.txt\n\nIt could also work by using `git log --reverse  -S...` to find when\nsome functions or variables related to the feature appeared in the\ncode itself.\n"},{"id":"407273","messageId":"CAP8UFD2dWrUXJUuiFtgCu6krbnbGGqJZ7K+6KqstGTcNmSc_xQ@mail.gmail.com","threadId":"54378","inReplyTo":"945ab20e-dcde-540e-83a5-83992c2187b1@enigmage.de","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2020-10-10T09:22:49Z","receivedAt":"2020-10-10T23:09:59Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Fri, Oct 9, 2020 at 9:35 PM Manuel Bärenz <manuel@enigmage.de> wrote:\n>\n> This feature was requested 8 years ago and briefly discussed:\n> https://public-inbox.org/git/20120318212957.GS1219@chaosreigns.com/\n>\n>\n>   TL;DR\n>\n> Before doing git bisect, I want to use exponential search to\n> automatically find a good commit, in logarithmic time.\n\nOk, but the conclusion of the above discussion is that the problem\nwith this idea is being able to distinguish between a commit that is\nbad and a commit where the feature that you want to test cannot be\ntested for example because it hasn't been implemented yet.\n\n>   Scenario\n>\n>   * I have a bug in HEAD.\n>   * I strongly suspect that it was introduced some time ago, but I don't\n>     know when exactly.\n>   * I have an automated test that will find the bug if the test can run\n>     properly.\n>   * Most of the commits in the repository are not testable, i.e. the\n>     test doesn't run properly. (E.g. because the feature it tests wasn't\n>     introduced yet, refactoring, etc.)\n>   * I have no idea what a good commit might be, because I don't know\n>     when the first /testable/ good commit is.\n\nOk, so your test cannot distinguish between a bad commit and a commit\nwhere the feature hasn't been implemented.\n\nWhen you say that most of the commits in the repository are not\ntestable, it usually means that the feature has been implemented\nrelatively recently compared to the history of the project.\n\n> This sounds like a standard application for git bisect. No matter how\n> big the repo, with binary search we would expect to find the first bad\n> commit in logarithmic time.\n\nNot necessarily. If you cannot distinguish in any way between a bad\ncommit and a commit where the feature hasn't been implemented, then it\nmight be very difficult to find a good commit. And you need a good\ncommit before you can properly bisect.\n\nSuppose for example that the first bad commit (the commit that\nintroduced the bug you are looking for) is a direct child of the\ncommit that introduced the feature. Then unless you are very lucky any\nbinary search using your script will only test either bad commits or\ncommits where the feature hasn't been implemented yet, and it is\nunable to distinguish between them in your scenario.\n\n>   Failed attempt\n>\n> The zeroth idea might be trying to find the good commit by hand, by\n> reading changelogs, by trying some commits, whatever. In some\n> situations, this is not feasible. In fact, such situations occur\n> frequently for me, for example for undocumented features, unversioned\n> rolling releases, incidental complexity leading to older commits not\n> being testable, etc.\n\nI understand that it's not always easy to find a good commit.\n\n> The first idea that comes to mind - and it was recommended 8 years agos,\n> and I've tried it a few times already - is to simply mark the root\n> commit as good. (Now, there might be several roots, but that's a puzzle\n> you typically only have to figure out once per repo.) This sounds great\n> in theory because binary search should get through the good old commits\n> in logarithmic time.\n\nIt is not necessarily a good idea to do that. And in the thread, what\nwas actually suggested by Peff (Jeff King) was to test released\nversions (for example 1.6.0, 1.7.0, etc in the Git code base).\n\n> The problem with this approach is that if most older commits are\n> untestable, I have to git bisect skip them.\n\nSkipping untestable commits is not always the right thing to do. If\nyou know that they are untestable because the feature has not been\nimplemented yet, it might be better to mark them as good instead.\n\nThis is by the way what an ideal script should do. It should mark\ncommits where the feature has not been implemented yet as good, and\nshould \"skip\" only the commits where the feature has already been\nimplemented but that are not testable for another reason, like another\n\"temporary\" bug or \"temporary\" compile failures.\n\n> This basically kills the\n> logarithmic performance, because bisect skip doesn't do binary search,\n> but something rather random.\n\nI would say that the actual reason here is that bisect skip is used\nwhen it shouldn't be used.\n\n> Just yesterday I killed a bisect search\n> that took hours because it kept skipping and didn't find actual good\n> commits.\n\nOk.\n\n> You might say that instead of skipping old commits, one should mark them\n> as good.\n\nYes, they should be marked as good when the feature has not been\nimplemented yet.\n\n> That's problematic because then I might accidentally mark a\n> commit as good that was already untestable bad. Given that bisect has no\n> undo functionality, that can quickly mess up my search. Distinguishing\n> untestable good from untestable bad is really hard automatically. I\n> shouldn't have to do that.\n\nSometimes it's not very difficult to test if the feature has been\nimplemented yet or not. For example with Git you could check if an\noption for a command has been implemented by just checking if it\nappears in the doc. So the bisection script could first check that and\nexit 0 (which means good) if the option doesn't appear in the doc. If\nit appears in the doc, then it could do the regular test: \"skip\" if\nuntestable, \"good\" if there is no bug, \"bad\" otherwise.\n\n> Long story short: Going from the root commit typically isn't feasible.\n> I've tried it.\n\nIt seems that you might not have tried in the best possible way.\n\n>   Proposal: Exponential search\n>\n> Instead of going from the root commit, what I do manually before\n> starting git bisect is this:\n>\n> git checkout HEAD~10\n> ./test.sh # Says: \"Bug is present\"\n> git checkout HEAD~20\n> ./test.sh # Says: \"Bug is still present\"\n> git checkout HEAD~40\n> ./test.sh # Says: \"Bug is still present\"\n> [...] # Proceed exponentially\n> git checkout HEAD~640\n> ./test.sh # Says: \"Bug is GONE!\"\n> git bisect good\n\nIf your script cannot distinguish between a bad commit and a commit\nwhere the feature hasn't been implemented, then you were lucky that\nthat HEAD~640 was good. If the feature had been introduced between\nHEAD~639 and HEAD~321 then your script would have said  \"Bug is still\npresent\".\n\n> This technique is known as\n> https://en.wikipedia.org/wiki/Exponential_search, and it works very well\n> in practice. I find a good commit long before I enter the \"untestable\n> good\" region.\n\nIf you are lucky, yes, you find a good commit long before you enter\nthe \"untestable good\" region.\n\n> But it's tedious to do this manually. In this example, I\n> needed to run the script 8 times manually, but of course it can be more\n> often, and compiling and running the test may take time. This is ok for\n> a one-off search, but it's tedious for regular usages.\n>\n> Yes, I could wrap this up in a shell script, but I guess there are\n> caveats that I didn't think of when the history isn't linear. Maybe\n> someone even already has, and I'm unaware of that. But it feels like\n> this could be a proper git bisect feature, and a very useful one.\n\nI agree that it could be useful. It could be especially useful if\npeople have a script that can actually distinguish between a bad\ncommit and a commit where the feature hasn't been implemented.\n\nSo if someone plans to implement that in Git, particular care in the\ndocumentation should be taken to explain the issues related to testing\na feature when it might not be implemented yet.\n"},{"id":"408351","messageId":"b1adedaa-5809-9ea1-f664-3a7cabaf0d14@iee.email","threadId":"54378","inReplyTo":"CAP8UFD2dWrUXJUuiFtgCu6krbnbGGqJZ7K+6KqstGTcNmSc_xQ@mail.gmail.com","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2020-10-25T17:15:20Z","receivedAt":"2020-10-25T17:15:29Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Manuel,\n\nOn 10/10/2020 10:22, Christian Couder wrote:\n> On Fri, Oct 9, 2020 at 9:35 PM Manuel Bärenz <manuel@enigmage.de> wrote:\n>> This feature was requested 8 years ago and briefly discussed:\n>> https://public-inbox.org/git/20120318212957.GS1219@chaosreigns.com/\n>>\n>>\n>>   TL;DR\n>>\n>> Before doing git bisect, I want to use exponential search to\n>> automatically find a good commit, in logarithmic time.\n> Ok, but the conclusion of the above discussion is that the problem\n> with this idea is being able to distinguish between a commit that is\n> bad and a commit where the feature that you want to test cannot be\n> tested for example because it hasn't been implemented yet.\n\nDoes any of the proposed improvement in the \"bisect: loosen halfway()\ncheck for a large number of commits\"\nhttps://lore.kernel.org/git/20201022103806.26680-1-szeder.dev@gmail.com/\nassist in this.\n\nOr is the problem still with the need for a three way test that shows\nToo_Old / Good / Bad ?\n\n>\n>>   Scenario\n>>\n>>   * I have a bug in HEAD.\n>>   * I strongly suspect that it was introduced some time ago, but I don't\n>>     know when exactly.\n>>   * I have an automated test that will find the bug if the test can run\n>>     properly.\n>>   * Most of the commits in the repository are not testable, i.e. the\n>>     test doesn't run properly. (E.g. because the feature it tests wasn't\n>>     introduced yet, refactoring, etc.)\n>>   * I have no idea what a good commit might be, because I don't know\n>>     when the first /testable/ good commit is.\n> Ok, so your test cannot distinguish between a bad commit and a commit\n> where the feature hasn't been implemented.\n>\n> When you say that most of the commits in the repository are not\n> testable, it usually means that the feature has been implemented\n> relatively recently compared to the history of the project.\n>\n>> This sounds like a standard application for git bisect. No matter how\n>> big the repo, with binary search we would expect to find the first bad\n>> commit in logarithmic time.\n> Not necessarily. If you cannot distinguish in any way between a bad\n> commit and a commit where the feature hasn't been implemented, then it\n> might be very difficult to find a good commit. And you need a good\n> commit before you can properly bisect.\n>\n> Suppose for example that the first bad commit (the commit that\n> introduced the bug you are looking for) is a direct child of the\n> commit that introduced the feature. Then unless you are very lucky any\n> binary search using your script will only test either bad commits or\n> commits where the feature hasn't been implemented yet, and it is\n> unable to distinguish between them in your scenario.\n>\n>>   Failed attempt\n>>\n>> The zeroth idea might be trying to find the good commit by hand, by\n>> reading changelogs, by trying some commits, whatever. In some\n>> situations, this is not feasible. In fact, such situations occur\n>> frequently for me, for example for undocumented features, unversioned\n>> rolling releases, incidental complexity leading to older commits not\n>> being testable, etc.\n> I understand that it's not always easy to find a good commit.\n>\n>> The first idea that comes to mind - and it was recommended 8 years agos,\n>> and I've tried it a few times already - is to simply mark the root\n>> commit as good. (Now, there might be several roots, but that's a puzzle\n>> you typically only have to figure out once per repo.) This sounds great\n>> in theory because binary search should get through the good old commits\n>> in logarithmic time.\n> It is not necessarily a good idea to do that. And in the thread, what\n> was actually suggested by Peff (Jeff King) was to test released\n> versions (for example 1.6.0, 1.7.0, etc in the Git code base).\n>\n>> The problem with this approach is that if most older commits are\n>> untestable, I have to git bisect skip them.\n> Skipping untestable commits is not always the right thing to do. If\n> you know that they are untestable because the feature has not been\n> implemented yet, it might be better to mark them as good instead.\n>\n> This is by the way what an ideal script should do. It should mark\n> commits where the feature has not been implemented yet as good, and\n> should \"skip\" only the commits where the feature has already been\n> implemented but that are not testable for another reason, like another\n> \"temporary\" bug or \"temporary\" compile failures.\n>\n>> This basically kills the\n>> logarithmic performance, because bisect skip doesn't do binary search,\n>> but something rather random.\n> I would say that the actual reason here is that bisect skip is used\n> when it shouldn't be used.\n>\n>> Just yesterday I killed a bisect search\n>> that took hours because it kept skipping and didn't find actual good\n>> commits.\n> Ok.\n>\n>> You might say that instead of skipping old commits, one should mark them\n>> as good.\n> Yes, they should be marked as good when the feature has not been\n> implemented yet.\n>\n>> That's problematic because then I might accidentally mark a\n>> commit as good that was already untestable bad. Given that bisect has no\n>> undo functionality, that can quickly mess up my search. Distinguishing\n>> untestable good from untestable bad is really hard automatically. I\n>> shouldn't have to do that.\n> Sometimes it's not very difficult to test if the feature has been\n> implemented yet or not. For example with Git you could check if an\n> option for a command has been implemented by just checking if it\n> appears in the doc. So the bisection script could first check that and\n> exit 0 (which means good) if the option doesn't appear in the doc. If\n> it appears in the doc, then it could do the regular test: \"skip\" if\n> untestable, \"good\" if there is no bug, \"bad\" otherwise.\n>\n>> Long story short: Going from the root commit typically isn't feasible.\n>> I've tried it.\n> It seems that you might not have tried in the best possible way.\n>\n>>   Proposal: Exponential search\n>>\n>> Instead of going from the root commit, what I do manually before\n>> starting git bisect is this:\n>>\n>> git checkout HEAD~10\n>> ./test.sh # Says: \"Bug is present\"\n>> git checkout HEAD~20\n>> ./test.sh # Says: \"Bug is still present\"\n>> git checkout HEAD~40\n>> ./test.sh # Says: \"Bug is still present\"\n>> [...] # Proceed exponentially\n>> git checkout HEAD~640\n>> ./test.sh # Says: \"Bug is GONE!\"\n>> git bisect good\n> If your script cannot distinguish between a bad commit and a commit\n> where the feature hasn't been implemented, then you were lucky that\n> that HEAD~640 was good. If the feature had been introduced between\n> HEAD~639 and HEAD~321 then your script would have said  \"Bug is still\n> present\".\n>\n>> This technique is known as\n>> https://en.wikipedia.org/wiki/Exponential_search, and it works very well\n>> in practice. I find a good commit long before I enter the \"untestable\n>> good\" region.\n> If you are lucky, yes, you find a good commit long before you enter\n> the \"untestable good\" region.\n>\n>> But it's tedious to do this manually. In this example, I\n>> needed to run the script 8 times manually, but of course it can be more\n>> often, and compiling and running the test may take time. This is ok for\n>> a one-off search, but it's tedious for regular usages.\n>>\n>> Yes, I could wrap this up in a shell script, but I guess there are\n>> caveats that I didn't think of when the history isn't linear. Maybe\n>> someone even already has, and I'm unaware of that. But it feels like\n>> this could be a proper git bisect feature, and a very useful one.\n> I agree that it could be useful. It could be especially useful if\n> people have a script that can actually distinguish between a bad\n> commit and a commit where the feature hasn't been implemented.\n>\n> So if someone plans to implement that in Git, particular care in the\n> documentation should be taken to explain the issues related to testing\n> a feature when it might not be implemented yet.\n\n"},{"id":"408431","messageId":"xmqqpn54etyp.fsf@gitster.c.googlers.com","threadId":"54378","inReplyTo":"b1adedaa-5809-9ea1-f664-3a7cabaf0d14@iee.email","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-10-26T18:13:34Z","receivedAt":"2020-10-26T18:13:43Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philip Oakley <philipoakley@iee.email> writes:\n\n>> Ok, but the conclusion of the above discussion is that the problem\n>> with this idea is being able to distinguish between a commit that is\n>> bad and a commit where the feature that you want to test cannot be\n>> tested for example because it hasn't been implemented yet.\n>\n> Does any of the proposed improvement in the \"bisect: loosen halfway()\n> check for a large number of commits\"\n> https://lore.kernel.org/git/20201022103806.26680-1-szeder.dev@gmail.com/\n> assist in this.\n\nI doubt it.  \n\nIf you cannot say if a rev is testable or not, it would not help you\nmuch if Git asked \"is this good, bad or untestable?\" question 5\ntimes faster, I suspect.\n\n\n"},{"id":"408455","messageId":"5559c9b5-07d5-c25d-7c28-4091de34584f@iee.email","threadId":"54378","inReplyTo":"xmqqpn54etyp.fsf@gitster.c.googlers.com","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2020-10-26T20:59:58Z","receivedAt":"2020-10-26T21:00:03Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Junio,\n\nOn 26/10/2020 18:13, Junio C Hamano wrote:\n> Philip Oakley <philipoakley@iee.email> writes:\n>\n>>> Ok, but the conclusion of the above discussion is that the problem\n>>> with this idea is being able to distinguish between a commit that is\n>>> bad and a commit where the feature that you want to test cannot be\n>>> tested for example because it hasn't been implemented yet.\n>> Does any of the proposed improvement in the \"bisect: loosen halfway()\n>> check for a large number of commits\"\n>> https://lore.kernel.org/git/20201022103806.26680-1-szeder.dev@gmail.com/\n>> assist in this.\n> I doubt it.  \n>\n> If you cannot say if a rev is testable or not, it would not help you\n> much if Git asked \"is this good, bad or untestable?\" question 5\n> times faster, I suspect.\n>\n>\nI was more thinking along the lines, perhaps, of a narrower condition of\n\"Too_Old\" for such historical commits, rather than saying some\nmid-history commit just happens to be untestable in a rather\nindeterminate way. That would be distinctly different from the generic\n'untestable' condition where a commit needs to be skipped.\n\nIt would still need an update to bisect to exponentially find the\nsuitable start (good) zone for the real bisection.\n\nClearly if the user badly codes that 'Too_Old' test then they will get\npulled up short, but that would be expected.\n\nThe other point was to highlight to Manuel that if the halfway check\nimprovement was relevant to his situation then it may be that simply\nsaying those 'Too_Old' commits were 'good' anyway, and just use the\nimprovement it gave.\n"},{"id":"408502","messageId":"87wnzbhntw.fsf@evledraar.gmail.com","threadId":"54378","inReplyTo":"945ab20e-dcde-540e-83a5-83992c2187b1@enigmage.de","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2020-10-27T12:10:03Z","receivedAt":"2020-10-27T12:10:13Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Oct 09 2020, Manuel Bärenz wrote:\n\n> This feature was requested 8 years ago and briefly discussed:\n> https://public-inbox.org/git/20120318212957.GS1219@chaosreigns.com/\n>\n>\n>   TL;DR\n>\n> Before doing git bisect, I want to use exponential search to\n> automatically find a good commit, in logarithmic time.\n>\n>\n>   Scenario\n>\n>   * I have a bug in HEAD.\n>   * I strongly suspect that it was introduced some time ago, but I don't\n>     know when exactly.\n>   * I have an automated test that will find the bug if the test can run\n>     properly.\n>   * Most of the commits in the repository are not testable, i.e. the\n>     test doesn't run properly. (E.g. because the feature it tests wasn't\n>     introduced yet, refactoring, etc.)\n>   * I have no idea what a good commit might be, because I don't know\n>     when the first /testable/ good commit is.\n>\n> This sounds like a standard application for git bisect. No matter how\n> big the repo, with binary search we would expect to find the first bad\n> commit in logarithmic time.\n>\n>\n>   Failed attempt\n>\n> The zeroth idea might be trying to find the good commit by hand, by\n> reading changelogs, by trying some commits, whatever. In some\n> situations, this is not feasible. In fact, such situations occur\n> frequently for me, for example for undocumented features, unversioned\n> rolling releases, incidental complexity leading to older commits not\n> being testable, etc.\n>\n> The first idea that comes to mind - and it was recommended 8 years agos,\n> and I've tried it a few times already - is to simply mark the root\n> commit as good. (Now, there might be several roots, but that's a puzzle\n> you typically only have to figure out once per repo.) This sounds great\n> in theory because binary search should get through the good old commits\n> in logarithmic time.\n>\n> The problem with this approach is that if most older commits are\n> untestable, I have to git bisect skip them. This basically kills the\n> logarithmic performance, because bisect skip doesn't do binary search,\n> but something rather random. Just yesterday I killed a bisect search\n> that took hours because it kept skipping and didn't find actual good\n> commits.\n>\n> You might say that instead of skipping old commits, one should mark them\n> as good. That's problematic because then I might accidentally mark a\n> commit as good that was already untestable bad. Given that bisect has no\n> undo functionality, that can quickly mess up my search. Distinguishing\n> untestable good from untestable bad is really hard automatically. I\n> shouldn't have to do that.\n>\n> Long story short: Going from the root commit typically isn't feasible.\n> I've tried it.\n>\n>\n>   Proposal: Exponential search\n>\n> Instead of going from the root commit, what I do manually before\n> starting git bisect is this:\n>\n> git checkout HEAD~10\n> ./test.sh # Says: \"Bug is present\"\n> git checkout HEAD~20\n> ./test.sh # Says: \"Bug is still present\"\n> git checkout HEAD~40\n> ./test.sh # Says: \"Bug is still present\"\n> [...] # Proceed exponentially\n> git checkout HEAD~640\n> ./test.sh # Says: \"Bug is GONE!\"\n> git bisect good\n>\n> This technique is known as\n> https://en.wikipedia.org/wiki/Exponential_search, and it works very well\n> in practice. I find a good commit long before I enter the \"untestable\n> good\" region. But it's tedious to do this manually. In this example, I\n> needed to run the script 8 times manually, but of course it can be more\n> often, and compiling and running the test may take time. This is ok for\n> a one-off search, but it's tedious for regular usages.\n>\n> Yes, I could wrap this up in a shell script, but I guess there are\n> caveats that I didn't think of when the history isn't linear. Maybe\n> someone even already has, and I'm unaware of that. But it feels like\n> this could be a proper git bisect feature, and a very useful one.\n\nLet's suppose we have a repository with 700 linear commits:\n    \n    set -e\n    \n    cd /tmp\n    rm -rf /tmp/test-repo\n    mkdir /tmp/test-repo\n    cd /tmp/test-repo\n    git init\n    \n    for i in $(seq 1 700)\n    do\n        touch $i\n        git add $i\n        git commit -m\"add $i\"\n    done\n\nThen let's bisect it from the root:\n    \n    git bisect start HEAD HEAD~699\n\nAnd let's further suppose that the feature wasn't introduced until\ncommit 650, and it's broken since 653.\n\nWith the bisect method of finding this we're going to start our session\nwith these commits:\n\n    [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => good\n    [d271fdb29129dbba723d3eac1035b58b6dc6f583] add 525 => good\n    [b0c9b7da646334a6c7eadb333b5ae77ec35388b3] add 612 => good\n    [2a78858d04cc5542e176dd8f68fa2660b8b48ab3] add 656 => bad (or skip)\n\nWhereas with this proposed exponential search it'll be commits #:\n    \n    2\n    4\n    8\n    16\n    32\n    64\n    128\n    256\n    512\n\nSo we're going to test 8 commits before we get past the mid-point that\nbisect now starts with. Of course that may be more efficient, but if the\nregression is in some random place I don't see why we wouldn't test the\nmiddle instead of weighing things towards the start of the history. If\nthe relevant commit is an early one like #50 bisect is still faster.\n\nWith the disclaimer that I may be missing something, I'm just plowing\nahead:\n\nI don't see the usefulness of this proposed exponential search, but I\ndefinitely *do* see the usefulness of a \"bisect undo\", and I've been\nbitten many times by the lack of that myself. We should definitely have\nthat.\n\nAnd as Christian pointed out in [1] it seems you're (understandably, it\ncan be confusing) conflating skip and \"good\" in your example. So to\nre-state the problem you have, if I were to use \"skip\" in the above\nexample bisect for me will do:\n    \n    [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => skip\n    [15c181442dcbd785bf2b28cfddcf1932aaa71c42] add 351 => skip\n    [c985feffa2c92b2d3d9804a43b215e26c7275549] add 374 => skip\n    [effa691ec5dc2d80c0b070c4d8ac9fa70cbfea9f] add 168 => skip\n    [212a5ee3ff55834196661d0632f584098e9f6fb2] add 369 => skip\n    [2ca67a4500c9f3cd489b9e529d41eb99252dc8f6] add 179 => skip\n    [4067ee067e2298e1b104f4ff9aab15f4e815e101] add 337 => skip\n    [...]\n\nIf only there was a way to be on 350 and say \"skip everything up to this\npoint\", so I implemented it!:\n\n    [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => skip-to-here\n    [15c181442dcbd785bf2b28cfddcf1932aaa71c42] add 351 => skip\n    [6f7b5ca1dcc21c28af658a172136e503d7a2d0ea] add 420\n    [...]\n\netc. now we're not jumping around in 1..350:\n\n    $ git config alias.bisect-skip-to-here\n    !f() { good=$(git for-each-ref refs/bisect/good* --format=\"%(objectname)\"); git bisect skip $good..HEAD; }; f\n\nGreat eh? Not really, because I've just discovered a really tedious and\nexpensive (I created 350 \"skip\" refs) of re-inventing what I could do if\nI just did \"good\" on commit 350[2] :)\n\nI started looking at how to implement \"git bisect undo\", it should be\npossible by either winding .git/refs/bisect based on the BISECT_LOG, or\nsimply keeping copies of .git/refs/bisect (and adjusting HEAD), but then\nI wondered if this was something we could get for free with the ref\ntransactions in the reftable. CC'd Han-Wen in case he's got feedback,\nmaybe it's trivial, or maybe I'm imagining things.\n\n1. https://lore.kernel.org/git/CAP8UFD2dWrUXJUuiFtgCu6krbnbGGqJZ7K+6KqstGTcNmSc_xQ@mail.gmail.com/\n2. Not exactly, because in skip-to-here on 350 we'll next test 351, but\n   \"good\" will test 525, but as argued earlier that's a feature.\n"},{"id":"408850","messageId":"58ba4fcd-50ff-1d1a-fe11-1ee59ad1c533@enigmage.de","threadId":"54378","inReplyTo":"87wnzbhntw.fsf@evledraar.gmail.com","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Manuel Bärenz","fromEmail":"manuel@enigmage.de","sentAt":"2020-11-01T20:30:13Z","receivedAt":"2020-11-01T20:30:18Z","isPatch":false,"sender":{"key":"manuel@enigmage.de","avatar":"https://gravatar.com/avatar/463077d57f57e1dea9d975afbd18b2a895df6efa8e6a81d98e4e04a3cdbdc229?d=mp&s=160"},"body":"\n> Let's suppose we have a repository with 700 linear commits:\n>     \n>     set -e\n>     \n>     cd /tmp\n>     rm -rf /tmp/test-repo\n>     mkdir /tmp/test-repo\n>     cd /tmp/test-repo\n>     git init\n>     \n>     for i in $(seq 1 700)\n>     do\n>         touch $i\n>         git add $i\n>         git commit -m\"add $i\"\n>     done\n>\n> Then let's bisect it from the root:\n>     \n>     git bisect start HEAD HEAD~699\n>\n> And let's further suppose that the feature wasn't introduced until\n> commit 650, and it's broken since 653.\n>\n> With the bisect method of finding this we're going to start our session\n> with these commits:\n>\n>     [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => good\n>     [d271fdb29129dbba723d3eac1035b58b6dc6f583] add 525 => good\n>     [b0c9b7da646334a6c7eadb333b5ae77ec35388b3] add 612 => good\n>     [2a78858d04cc5542e176dd8f68fa2660b8b48ab3] add 656 => bad (or skip)\n>\n> Whereas with this proposed exponential search it'll be commits #:\n>     \n>     2\n>     4\n>     8\n>     16\n>     32\n>     64\n>     128\n>     256\n>     512\n>\n> So we're going to test 8 commits before we get past the mid-point that\n> bisect now starts with. Of course that may be more efficient, but if the\n> regression is in some random place I don't see why we wouldn't test the\n> middle instead of weighing things towards the start of the history. If\n> the relevant commit is an early one like #50 bisect is still faster.\nThat's true. If the feature was broken n commits ago, and exponential\nsearch has to be useful, then the feature must not have been introduced\nlater than a*n commits ago, where a is the exponent.\n> With the disclaimer that I may be missing something, I'm just plowing\n> ahead:\n>\n> I don't see the usefulness of this proposed exponential search, but I\n> definitely *do* see the usefulness of a \"bisect undo\", and I've been\n> bitten many times by the lack of that myself. We should definitely have\n> that.\nWhat exactly would you undo? If an older commit has been marked as\n\"bad\", should e.g. a later \"good\" marker undo the earlier \"bad\" marker?\nI don't know how this helps because the bigger problem is that if I tend\nto mark old commits as good rather than skip, I will more likely\naccidentally mark a bad commit as good, and I don't see how I could undo\nthat.\n> And as Christian pointed out in [1] it seems you're (understandably, it\n> can be confusing) conflating skip and \"good\" in your example.\nYes, knowingly, unfortunately. Or to put it more precise: I cannot write\na script that is good enough to really detect a good old commit reliably.\n>  So to\n> re-state the problem you have, if I were to use \"skip\" in the above\n> example bisect for me will do:\n>     \n>     [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => skip\n>     [15c181442dcbd785bf2b28cfddcf1932aaa71c42] add 351 => skip\n>     [c985feffa2c92b2d3d9804a43b215e26c7275549] add 374 => skip\n>     [effa691ec5dc2d80c0b070c4d8ac9fa70cbfea9f] add 168 => skip\n>     [212a5ee3ff55834196661d0632f584098e9f6fb2] add 369 => skip\n>     [2ca67a4500c9f3cd489b9e529d41eb99252dc8f6] add 179 => skip\n>     [4067ee067e2298e1b104f4ff9aab15f4e815e101] add 337 => skip\n>     [...]\n>\n> If only there was a way to be on 350 and say \"skip everything up to this\n> point\", so I implemented it!:\n>\n>     [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => skip-to-here\n>     [15c181442dcbd785bf2b28cfddcf1932aaa71c42] add 351 => skip\n>     [6f7b5ca1dcc21c28af658a172136e503d7a2d0ea] add 420\n>     [...]\n>\n> etc. now we're not jumping around in 1..350:\n>\n>     $ git config alias.bisect-skip-to-here\n>     !f() { good=$(git for-each-ref refs/bisect/good* --format=\"%(objectname)\"); git bisect skip $good..HEAD; }; f\n>\n> Great eh? Not really, because I've just discovered a really tedious and\n> expensive (I created 350 \"skip\" refs) of re-inventing what I could do if\n> I just did \"good\" on commit 350[2] :)\n\nI'm not entirely sure whether I understand yet. If you mark a whole\nrange of commits untestable, then yes. But how do you know whether the\nwhole range can be skipped? Maybe the feature was really introduced in\n300, 320 broke it and 350 just broke it because of a typo?\n\nMaybe another possible, simpler feature would be a different\n(configurable?) skip algorithm. It could move exponentially as well.\n(I'm not sure how useful that would be, though.)\n\n"},{"id":"408851","messageId":"a03a9674-921e-d8f4-19f8-ca60aa4a473a@enigmage.de","threadId":"54378","inReplyTo":"b1adedaa-5809-9ea1-f664-3a7cabaf0d14@iee.email","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Manuel Bärenz","fromEmail":"manuel@enigmage.de","sentAt":"2020-11-01T20:17:59Z","receivedAt":"2020-11-01T20:51:47Z","isPatch":false,"sender":{"key":"manuel@enigmage.de","avatar":"https://gravatar.com/avatar/463077d57f57e1dea9d975afbd18b2a895df6efa8e6a81d98e4e04a3cdbdc229?d=mp&s=160"},"body":"\nOn 25.10.20 18:15, Philip Oakley wrote:\n> Hi Manuel,\n>\n> On 10/10/2020 10:22, Christian Couder wrote:\n>> On Fri, Oct 9, 2020 at 9:35 PM Manuel Bärenz <manuel@enigmage.de> wrote:\n>>> This feature was requested 8 years ago and briefly discussed:\n>>> https://public-inbox.org/git/20120318212957.GS1219@chaosreigns.com/\n>>>\n>>>\n>>>   TL;DR\n>>>\n>>> Before doing git bisect, I want to use exponential search to\n>>> automatically find a good commit, in logarithmic time.\n>> Ok, but the conclusion of the above discussion is that the problem\n>> with this idea is being able to distinguish between a commit that is\n>> bad and a commit where the feature that you want to test cannot be\n>> tested for example because it hasn't been implemented yet.\n> Does any of the proposed improvement in the \"bisect: loosen halfway()\n> check for a large number of commits\"\n> https://lore.kernel.org/git/20201022103806.26680-1-szeder.dev@gmail.com/\n> assist in this.\n\nI'm afraid not, since the time to recompile and run tests usually\ndominates the search (at least in my case). So the fewer commits have to\nbe tested, the better.\n\nThe hard part is distinguishing in an automated way on an old commit\nwhen to skip and when to mark as good.\n\n\n"},{"id":"408855","messageId":"87r1pcgi5e.fsf@evledraar.gmail.com","threadId":"54378","inReplyTo":"58ba4fcd-50ff-1d1a-fe11-1ee59ad1c533@enigmage.de","subject":"Re: Feature request: Exponential search in git bisect","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2020-11-02T10:36:13Z","receivedAt":"2020-11-02T10:36:21Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, Nov 01 2020, Manuel Bärenz wrote:\n\n>> Let's suppose we have a repository with 700 linear commits:\n>>     \n>>     set -e\n>>     \n>>     cd /tmp\n>>     rm -rf /tmp/test-repo\n>>     mkdir /tmp/test-repo\n>>     cd /tmp/test-repo\n>>     git init\n>>     \n>>     for i in $(seq 1 700)\n>>     do\n>>         touch $i\n>>         git add $i\n>>         git commit -m\"add $i\"\n>>     done\n>>\n>> Then let's bisect it from the root:\n>>     \n>>     git bisect start HEAD HEAD~699\n>>\n>> And let's further suppose that the feature wasn't introduced until\n>> commit 650, and it's broken since 653.\n>>\n>> With the bisect method of finding this we're going to start our session\n>> with these commits:\n>>\n>>     [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => good\n>>     [d271fdb29129dbba723d3eac1035b58b6dc6f583] add 525 => good\n>>     [b0c9b7da646334a6c7eadb333b5ae77ec35388b3] add 612 => good\n>>     [2a78858d04cc5542e176dd8f68fa2660b8b48ab3] add 656 => bad (or skip)\n>>\n>> Whereas with this proposed exponential search it'll be commits #:\n>>     \n>>     2\n>>     4\n>>     8\n>>     16\n>>     32\n>>     64\n>>     128\n>>     256\n>>     512\n>>\n>> So we're going to test 8 commits before we get past the mid-point that\n>> bisect now starts with. Of course that may be more efficient, but if the\n>> regression is in some random place I don't see why we wouldn't test the\n>> middle instead of weighing things towards the start of the history. If\n>> the relevant commit is an early one like #50 bisect is still faster.\n> That's true. If the feature was broken n commits ago, and exponential\n> search has to be useful, then the feature must not have been introduced\n> later than a*n commits ago, where a is the exponent.\n\nRight, but it seems like a rather trivial saving in even those cases\ncompared to binary search, and I'd think in practice any such gains\nwould be outweighted by the practical trade-off that in real\nrepositories older commits tend to be harder to test/build\n(e.g. requiring old library versions or compilers).\n\n>> With the disclaimer that I may be missing something, I'm just plowing\n>> ahead:\n>>\n>> I don't see the usefulness of this proposed exponential search, but I\n>> definitely *do* see the usefulness of a \"bisect undo\", and I've been\n>> bitten many times by the lack of that myself. We should definitely have\n>> that.\n> What exactly would you undo? If an older commit has been marked as\n> \"bad\", should e.g. a later \"good\" marker undo the earlier \"bad\" marker?\n> I don't know how this helps because the bigger problem is that if I tend\n> to mark old commits as good rather than skip, I will more likely\n> accidentally mark a bad commit as good, and I don't see how I could undo\n> that.\n\nSometimes I mistype \"good\" or \"bad\" (usually via some shell history\naccident) and have to manually recover from seeing where I'd narrowed\ndown before with \"log\", so just an \"undo\" that allows you to revert the\nprevious step(s) would be useful.\n\n>> And as Christian pointed out in [1] it seems you're (understandably, it\n>> can be confusing) conflating skip and \"good\" in your example.\n> Yes, knowingly, unfortunately. Or to put it more precise: I cannot write\n> a script that is good enough to really detect a good old commit reliably.\n>>  So to\n>> re-state the problem you have, if I were to use \"skip\" in the above\n>> example bisect for me will do:\n>>     \n>>     [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => skip\n>>     [15c181442dcbd785bf2b28cfddcf1932aaa71c42] add 351 => skip\n>>     [c985feffa2c92b2d3d9804a43b215e26c7275549] add 374 => skip\n>>     [effa691ec5dc2d80c0b070c4d8ac9fa70cbfea9f] add 168 => skip\n>>     [212a5ee3ff55834196661d0632f584098e9f6fb2] add 369 => skip\n>>     [2ca67a4500c9f3cd489b9e529d41eb99252dc8f6] add 179 => skip\n>>     [4067ee067e2298e1b104f4ff9aab15f4e815e101] add 337 => skip\n>>     [...]\n>>\n>> If only there was a way to be on 350 and say \"skip everything up to this\n>> point\", so I implemented it!:\n>>\n>>     [bef4b96adf5f082b1103c170eb6a41d1526fa919] add 350 => skip-to-here\n>>     [15c181442dcbd785bf2b28cfddcf1932aaa71c42] add 351 => skip\n>>     [6f7b5ca1dcc21c28af658a172136e503d7a2d0ea] add 420\n>>     [...]\n>>\n>> etc. now we're not jumping around in 1..350:\n>>\n>>     $ git config alias.bisect-skip-to-here\n>>     !f() { good=$(git for-each-ref refs/bisect/good* --format=\"%(objectname)\"); git bisect skip $good..HEAD; }; f\n>>\n>> Great eh? Not really, because I've just discovered a really tedious and\n>> expensive (I created 350 \"skip\" refs) of re-inventing what I could do if\n>> I just did \"good\" on commit 350[2] :)\n>\n> I'm not entirely sure whether I understand yet. If you mark a whole\n> range of commits untestable, then yes. But how do you know whether the\n> whole range can be skipped? Maybe the feature was really introduced in\n> 300, 320 broke it and 350 just broke it because of a typo?\n\nI don't, but whatever problems I have with mislabeling 1..350 you'll\nalso have in mislabeling 16..32, 32..64 etc.\n\n> Maybe another possible, simpler feature would be a different\n> (configurable?) skip algorithm. It could move exponentially as well.\n> (I'm not sure how useful that would be, though.)\n\nI think the feature that would solve the problem you described in your\noriginal E-Mail would be some sort of verification mode for\nbisect. I.e. after we find that commit 656 is the bad one we could\noptionally continue testing. If we then found that something was \"good\"\non the side that should be \"bad\" or the other way around we'd walk back\nin some \"undo on steroids\" mode to figure out where the mislabeling\nhappened.\n\nBut I don't see how the problem you described would be solved by\nchanging how we do the commit walk during bisect. We could binary\nsearch, we could walk exponentially, we could test in chunks of 100\netc. All of those approaches would go equally wrong if we mislabel good\nas bad or bad as good.\n\n"}]}