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

[PATCH 2/2] branch: drop unused worktrees variable

From
Jeff King <peff@peff.net>
Date
Jun 19, 2022, 03:55 UTC
Message-ID
<Yq6eJFUPPTv/zc0o@coredump.intra.peff.net>
In-Reply-To
<Yq6deQf96g8M5wdg@coredump.intra.peff.net>

After b489b9d9aa (branch: use branch_checked_out() when deleting refs, 2022-06-14), we no longer look at our local "worktrees" variable, since branch_checked_out() handles it under the hood. The compiler didn't notice the unused variable because we call functions to initialize and free it (so it's not totally unused, it just doesn't do anything useful).

Signed-off-by: Jeff King <peff@peff.net>
---
It would be neat if there was some way to mark a function as "this is
just allocating a structure, with no useful side effects" and another as
"this is just freeing", which would let the compiler notice that we
don't do anything useful with the structure in between the two. I have a
feeling adding such annotations might be more work than occasionally
finding and cleaning up such useless variables, though. :)
 builtin/branch.c | 4 ----
 1 file changed, 4 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index f875952e7b..55cd9a6e99 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -204,7 +204,6 @@ static void delete_branch_config(const char *branchname)
 static int delete_branches(int argc, const char **argv, int force, int kinds,
 			   int quiet)
 {
-	struct worktree **worktrees;
 	struct commit *head_rev = NULL;
 	struct object_id oid;
 	char *name = NULL;
@@ -242,8 +241,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 			die(_("Couldn't look up commit object for HEAD"));
 	}
 
-	worktrees = get_worktrees();
-
 	for (i = 0; i < argc; i++, strbuf_reset(&bname)) {
 		char *target = NULL;
 		int flags = 0;
@@ -314,7 +311,6 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 
 	free(name);
 	strbuf_release(&bname);
-	free_worktrees(worktrees);
 
 	return ret;
 }
-- 
2.37.0.rc1.385.g5f9aa3aa78
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 3 of 7 in “extra cleanups on top of ds/branch-checked-out”
  1. 0/2 extra cleanups on top of ds/branch-checked-outJeff King, Jun 19, 2022
  2. 1/2 fetch: stop passing around unused worktrees variableJeff King, Jun 19, 2022
  3. 2/2 branch: drop unused worktrees variableJeff King, Jun 19, 2022
  4. Ævar Arnfjörð BjarmasonJun 20, 2022
  5. Jeff KingJul 1, 2022
  6. Junio C HamanoJun 21, 2022
  7. Derrick StoleeJun 19, 2022

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.