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

Re: [PATCH] gc: add git maintenance list command

From
Pablo Sabater <pabloosabaterr@gmail.com>
Date
Mar 13, 2026, 11:59 UTC
Message-ID
<20260313115932.15259-1-pabloosabaterr@gmail.com>
In-Reply-To
<pull.2201.git.git.1772040758787.gitgitgadget@gmail.com>
> char *config_file = NULL;
Show 21 quoted lines
>	if (config_file) {
>		git_configset_init(&cs);
>		git_configset_add_file(&cs, config_file);
>		if (git_configset_get_string_multi(&cs, key, &list)) {
>			/* No repositories registered in custom config */
>			git_configset_clear(&cs);
>			return 0;
>		}
>	} else {
>		global_config_file = git_global_config();
>		if (!global_config_file)
>			die(_("$HOME not set"));
>		git_configset_init(&cs);
>		git_configset_add_file(&cs, global_config_file);
>		if (git_configset_get_string_multi(&cs, key, &list)) {
>			/* No repositories registered in global config */
>			free(global_config_file);
>			git_configset_clear(&cs);
>			return 0;
>		}
>	}

Here the branches look too similar, after the third line at the else it becomes exactly the same. If you notice, global_config_file is initialized as NULL then in case of !config_file, its value comes from git_global_config(). Anyways, there's no need to separate the free logic because both NULL and git_global_config() can be freed.

you can avoid this by extracting the diferent logic from the else
  if (!config_file) {
      config_file = git_global_config();
      if (!config_file)
          die(_("$HOME not set"));
      global_config_file = config_file;
  }
and then the rest of the code is common for both cases
  git_configset_init(&cs);
  git_configset_add_file(&cs, config_file);
  if (git_configset_get_string_multi(&cs, key, &list)) {
      free(global_config_file);
      git_configset_clear(&cs);
      return 0;
  }
Previous: Rémy Léone via GitGitGadget
Message 2 of 2 in “gc: add git maintenance list command”
  1. gc: add git maintenance list commandRémy Léone via GitGitGadget, Feb 25, 2026
  2. Pablo SabaterMar 13, 2026

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.