From: Derrick Stolee Date: Mon, 06 Mar 2023 20:18:11 GMT Subject: Re: [PATCH 0/8] ahead-behind: new builtin for counting multiple commit ranges Message-ID: <8be01cb6-8937-faed-0850-4501a2f1ef55@github.com> In-Reply-To: On 3/6/2023 1:26 PM, Junio C Hamano wrote: > "Derrick Stolee via GitGitGadget" writes: > >> These numbers can be computed by 'git rev-list --count B..C' and 'git >> rev-list --count C..B', but there are common needs that benefit from having >> the checks being done in the same process: > > This makes readers wonder if "git rev-list --count B...C" should be > the end-user facing UI for this new feature, perhaps? > > Of course if you are checking how C0, C1, C2,... relate to a single > B, the existing rev-list syntax would not work, and makes a totally > new subcommand a possibilty. > >> 2. When a branch is updated, a background job checks if any pull requests >> that target that branch should be closed because their branches were >> merged implicitly by that update. These queries can e batched into 'git >> ahead-behind' calls. >> >> In that second example, we don't need the full ahead/behind counts (although >> it is sufficient to look for branches that are "zero commits ahead", meaning >> they are reachable from the base), so this builtin has an extra '--contains' >> mode that only checks reachability from the base to each of the tips. 'git >> ahead-behind --contains' is sort of the reverse of 'git branch --contains'. > > I thought that the reverse of "git branch --contains" was "git > branch --merged". "git branch --merged maint ??/\*" is how I cull > topic branches that have already served their purpose. > > Isn't closing pull requests because they have been already merged > the same idea? "git for-each-ref --merged main refs/pull/\*" or > something, perhaps? You are definitely on to something, and I was not aware of --merged as an option to either of these. 'git branch --merged' has some limitations that tags cannot be used. 'git for-each-ref --merged' is probably sufficient. The only difference being that it would be nice to specify the matching refs over stdin with --stdin to avoid long argument lists. With this in mind, I can update the performance test to look like this (after updating the setup step to add branches for each line in 'refs') test_perf 'batch reachability: git ahead-behind --contains' ' git ahead-behind --contains --base=HEAD --stdin