git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 3/3] ref-filter: allow merged and no-merged filters

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 13, 2020, 21:36 UTC
Message-ID
<CAPig+cTNp84Dm=0n-Bb9o=1nZNDFRE20XDWUPJT8yjdefv15rA@mail.gmail.com>
In-Reply-To
<20200913193140.66906-4-alipman88@gmail.com>
On Sun, Sep 13, 2020 at 3:32 PM Aaron Lipman <alipman88@gmail.com> wrote:
Show 6 quoted lines
> Enable ref-filter to process multiple merged and no-merged filters, and
> extend functionality to git branch, git tag and git for-each-ref. This
> provides an easy way to check for branches that are "graduation
> candidates:"
>
> $ git branch --no-merged master --merged next
A few subjective comments below, not necessarily worth a re-roll...
> To accomplish this, store the merged and no-merged filters in two
> commit_list structs (reachable_from and unreachable_from) rather than
> using a single commit struct (merge_commit).

This sort of implementation detail is readily discoverable by reading the patch itself, and since there is no complexity about it which requires extensive explanation, we'd normally leave it out of the commit message.

Show 18 quoted lines
> If passed more than one merged (or more than one no-merged) filter, refs
> must be reachable from any one of the merged commits, and reachable from
> none of the no-merged commits.
>
> Signed-off-by: Aaron Lipman <alipman88@gmail.com>
> ---
> diff --git a/ref-filter.c b/ref-filter.c
> @@ -2231,13 +2231,20 @@ void ref_array_clear(struct ref_array *array)
> -static void do_merge_filter(struct ref_filter_cbdata *ref_cbdata)
> +static void do_merge_filter(struct ref_filter_cbdata *ref_cbdata, int reachable)
>  {
>         [...]
> +       struct commit_list *check_reachable_list = reachable ?
> +               ref_cbdata->filter->reachable_from :
> +               ref_cbdata->filter->unreachable_from;
> +
> +       if (!check_reachable_list)
> +               return;

Rather than adding a boolean 'reachable' parameter to the function signature, you could instead directly pass in the `struct commit_list *` upon which to operate, which would allow you to drop the ternary operator here, and...

Show 5 quoted lines
> @@ -2322,8 +2337,8 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
> -       if (filter->merge_commit)
> -               do_merge_filter(&ref_cbdata);
> +       do_merge_filter(&ref_cbdata, 1);
> +       do_merge_filter(&ref_cbdata, 0);

... make the callers a bit less opaque by eliminating the less-than-meaningful 0-or-1, and making it obvious which list is being consulted:

    do_merge_filter(&ref_cbdata, ref_cbdata->filter->reachable_from);
    do_merge_filter(&ref_cbdata, ref_cbdata->filter->unreachable_from);
Show 5 quoted lines
> @@ -2541,31 +2556,22 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
> +       if (starts_with(opt->long_name, "no"))
> +               commit_list_insert(merge_commit, &rf->unreachable_from);
> +       else
> +               commit_list_insert(merge_commit, &rf->reachable_from);
... quite like it's obvious here into which list the item is being inserted.
Show 7 quoted lines
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> @@ -1299,8 +1299,8 @@ test_expect_success '--merged catches invalid object names' '
> -test_expect_success '--merged is incompatible with --no-merged' '
> -       test_must_fail git branch --merged HEAD --no-merged HEAD
> +test_expect_success '--merged is compatible with --no-merged' '
> +       git branch --merged master --no-merged master
>  '

This revised test doesn't seem to have all that much value since this combination is checked by new tests added elsewhere by the patch. Therefore, another option would be simply to drop the test rather than revising it. (But, again, it's a judgment call.)

Show 5 quoted lines
> diff --git a/t/t3201-branch-contains.sh b/t/t3201-branch-contains.sh
> @@ -226,6 +226,16 @@ test_expect_success 'multiple branch --contains' '
> +test_expect_success 'multiple branch --merged' '
> +test_expect_success 'multiple branch --no-merged' '
> +test_expect_success 'branch --merged combined with --no-merged' '

Would it make sense to also test multiple --merged and multiple --no-merged? (Genuine question, not a demand to add more tests.)

Show 6 quoted lines
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> @@ -2016,7 +2016,7 @@ test_expect_success '--merged can be used in non-list mode' '
>  test_expect_success '--merged is incompatible with --no-merged' '
> -       test_must_fail git tag --merged HEAD --no-merged HEAD
> +       git tag --merged HEAD --no-merged HEAD
>  '

I think you forgot s/incompatible/compatible/ in the test title (which you changed in the other cases).

Previous: Aaron LipmanNext: Junio C Hamano
Message 17 of 36 in “ref-filter: allow merged and no-merged filters”
  1. ref-filter: allow merged and no-merged filtersAaron Lipman, Sep 8, 2020
  2. Junio C HamanoSep 8, 2020
  3. Aaron LipmanSep 8, 2020
  4. Junio C HamanoSep 9, 2020
  5. 0/2 git branch: allow combining merged and no-merged filtersAaron Lipman, Sep 11, 2020
  6. 1/2 t3201: test multiple branch filter combinationsAaron Lipman, Sep 11, 2020
  7. 2/2 ref-filter: allow merged and no-merged filtersAaron Lipman, Sep 11, 2020
  8. Junio C HamanoSep 11, 2020
  9. 0/3 git branch: allow combining merged and no-merged filtersAaron Lipman, Sep 13, 2020
  10. 1/3 t3201: test multiple branch filter combinationsAaron Lipman, Sep 13, 2020
  11. Eric SunshineSep 13, 2020
  12. Junio C HamanoSep 14, 2020
  13. 2/3 Doc: cover multiple contains/no-contains filtersAaron Lipman, Sep 13, 2020
  14. Eric SunshineSep 13, 2020
  15. Junio C HamanoSep 14, 2020
  16. 3/3 ref-filter: allow merged and no-merged filtersAaron Lipman, Sep 13, 2020
  17. Eric SunshineSep 13, 2020
  18. Junio C HamanoSep 13, 2020
  19. Eric SunshineSep 13, 2020
  20. 0/3 git branch: allow combining merged and no-merged filtersAaron Lipman, Sep 16, 2020
  21. 1/3 t3201: test multiple branch filter combinationsAaron Lipman, Sep 16, 2020
  22. 2/3 Doc: cover multiple contains/no-contains filtersAaron Lipman, Sep 16, 2020
  23. Junio C HamanoSep 16, 2020
  24. 3/3 ref-filter: allow merged and no-merged filtersAaron Lipman, Sep 16, 2020
  25. Junio C HamanoSep 16, 2020
  26. Eric SunshineSep 16, 2020
  27. 0/2 ref-filter: merged & no-merged touch-upsAaron Lipman, Sep 18, 2020
  28. 1/2 ref-filter: refactor do_merge_filter()Aaron Lipman, Sep 18, 2020
  29. Eric SunshineSep 18, 2020
  30. Eric SunshineSep 18, 2020
  31. Junio C HamanoSep 18, 2020
  32. 2/2 Doc: prefer more specific file nameAaron Lipman, Sep 18, 2020
  33. Eric SunshineSep 18, 2020
  34. 0/2 ref-filter: merged & no-merged touch-upsAaron Lipman, Sep 18, 2020
  35. 1/2 ref-filter: make internal reachable-filter API more preciseAaron Lipman, Sep 18, 2020
  36. 2/2 Doc: prefer more specific file nameAaron Lipman, Sep 18, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.