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

[PATCH 0/3] ref-filter: add a ref_sorting_release()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 20, 2021, 18:27 UTC
Message-ID
<cover-0.3-00000000000-20211020T182516Z-avarab@gmail.com>
In-Reply-To
<RFC-cover-v2-0.4-00000000000-20211020T131627Z-avarab@gmail.com>

A follow-up to https://lore.kernel.org/git/RFC-cover-v2-0.4-00000000000-20211020T131627Z-avarab@gmail.com/;

Junio: Hopefully this addresses the things you noted, thank[s| you]!
:)

I ejected your patch from this iteration, if you'd like to build on top of it it should address the build failures in "seen" when combined with your patch.

Ævar Arnfjörð Bjarmason (3):
  tag: use a "goto cleanup" pattern, leak less memory
  ref-filter API user: add and use a ref_sorting_release()
  branch: use ref_sorting_release()
 builtin/branch.c       |  8 +++++---
 builtin/for-each-ref.c |  2 +-
 builtin/tag.c          | 29 +++++++++++++++++------------
 ref-filter.c           |  9 +++++++++
 ref-filter.h           |  2 ++
 5 files changed, 34 insertions(+), 16 deletions(-)
Range-diff:
1:  fc776c3f1cd ! 1:  8ccd07abf86 tag: use a "goto cleanup" pattern, leak less memory
    @@ Metadata
      ## Commit message ##
         tag: use a "goto cleanup" pattern, leak less memory
     
    -    Change cmd_tag() to free its "struct string_list"'s instead of using
    -    an UNLEAK() pattern. This changes code added in 886e1084d78 (builtin/:
    +    Change cmd_tag() to free its "struct strbuf"'s instead of using an
    +    UNLEAK() pattern. This changes code added in 886e1084d78 (builtin/:
         add UNLEAKs, 2017-10-01).
     
    -    As shown in the context of the deceleration of the "struct
    +    As shown in the context of the declaration of the "struct
         msg_arg" (which I'm changing to use a designated initializer while at
         it, and to show the context in this change), that struct is just a
         thin wrapper around an int and "struct strbuf".
2:  0ae71c19ab7 ! 2:  07062ca276a ref-filter API user: add and use a ref_sorting_release()
    @@ ref-filter.c: int parse_opt_ref_sorting(const struct option *opt, const char *ar
      
     +void ref_sorting_release(struct ref_sorting *sorting)
     +{
    -+	struct ref_sorting *next = sorting->next;
    -+	if (next)
    -+	       ref_sorting_release(next);
    -+	free(sorting);
    ++	while (sorting) {
    ++		struct ref_sorting *next = sorting->next;
    ++		free(sorting);
    ++		sorting = next;
    ++	}
     +}
     +
      int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
3:  7abbbe4468c < -:  ----------- for-each-ref: delay parsing of --sort=<atom> options
4:  f7d87aea384 ! 3:  c8e8bc46ac4 branch: use ref_sorting_release()
    @@ Commit message
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## builtin/branch.c ##
    -@@ builtin/branch.c: static const char *color_branch_slots[] = {
    - 	[BRANCH_COLOR_WORKTREE] = "worktree",
    - };
    - 
    --static struct string_list output = STRING_LIST_INIT_DUP;
    - static unsigned int colopts;
    - 
    - define_list_config_array(color_branch_slots);
     @@ builtin/branch.c: static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
      	return strbuf_detach(&fmt, NULL);
      }
    @@ builtin/branch.c: static void print_ref_list(struct ref_filter *filter, struct r
      		} else {
      			fwrite(out.buf, 1, out.len, stdout);
      			putchar('\n');
    -@@ builtin/branch.c: int cmd_branch(int argc, const char **argv, const char *prefix)
    - 	enum branch_track track;
    - 	struct ref_filter filter;
    - 	int icase = 0;
    --	static struct ref_sorting *sorting;
    - 	struct string_list sorting_options = STRING_LIST_INIT_DUP;
    - 	struct ref_format format = REF_FORMAT_INIT;
    - 
    -@@ builtin/branch.c: int cmd_branch(int argc, const char **argv, const char *prefix)
    - 		print_current_branch_name();
    - 		return 0;
    - 	} else if (list) {
    -+		struct ref_sorting *sorting;
    -+		static struct string_list output = STRING_LIST_INIT_DUP;
    -+
    - 		/*  git branch --list also shows HEAD when it is detached */
    - 		if ((filter.kind & FILTER_REFS_BRANCHES) && filter.detached)
    - 			filter.kind |= FILTER_REFS_DETACHED_HEAD;
     @@ builtin/branch.c: int cmd_branch(int argc, const char **argv, const char *prefix)
      		ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
      		ref_sorting_set_sort_flags_all(
-- 
2.33.1.1338.g20da966911a
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 13 of 20 in “for-each-ref: delay parsing of --sort=<atom> options”
  1. for-each-ref: delay parsing of --sort=<atom> optionsJunio C Hamano, Oct 18, 2021
  2. Jeff KingOct 19, 2021
  3. Jeff KingOct 20, 2021
  4. Ævar Arnfjörð BjarmasonOct 20, 2021
  5. 0/4 for-each-ref: delay parsing of --sort=<atom> options + linux-leaks fixesÆvar Arnfjörð Bjarmason, Oct 20, 2021
  6. 1/4 tag: use a "goto cleanup" pattern, leak less memoryÆvar Arnfjörð Bjarmason, Oct 20, 2021
  7. Junio C HamanoOct 20, 2021
  8. 2/4 ref-filter API user: add and use a ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  9. Junio C HamanoOct 20, 2021
  10. 3/4 for-each-ref: delay parsing of --sort=<atom> optionsÆvar Arnfjörð Bjarmason, Oct 20, 2021
  11. 4/4 branch: use ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  12. Junio C HamanoOct 20, 2021
  13. 0/3 ref-filter: add a ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  14. 1/3 tag: use a "goto cleanup" pattern, leak less memoryÆvar Arnfjörð Bjarmason, Oct 20, 2021
  15. 2/3 ref-filter API user: add and use a ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  16. 3/3 branch: use ref_sorting_release()Ævar Arnfjörð Bjarmason, Oct 20, 2021
  17. Junio C HamanoOct 20, 2021
  18. Jeff KingOct 20, 2021
  19. Junio C HamanoOct 20, 2021
  20. Jeff KingOct 21, 2021

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.