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

[PATCH v4 2/4] receive-pack: Clean dead code from update_worktree()

From
Anders Kaseorg <andersk@mit.edu>
Date
Nov 9, 2021, 03:00 UTC
Message-ID
<20211109030028.2196416-2-andersk@mit.edu>
In-Reply-To
<20211109030028.2196416-1-andersk@mit.edu>

update_worktree() can only be called with a non-NULL worktree parameter, because that’s the only case where we set do_update_worktree = 1. worktree->path is always initialized to non-NULL.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
---
 builtin/receive-pack.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 49b846d960..cf575280fc 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1449,29 +1449,19 @@ static const char *push_to_checkout(unsigned char *hash,
 
 static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree)
 {
-	const char *retval, *work_tree, *git_dir = NULL;
+	const char *retval, *git_dir;
 	struct strvec env = STRVEC_INIT;
 
-	if (worktree && worktree->path)
-		work_tree = worktree->path;
-	else if (git_work_tree_cfg)
-		work_tree = git_work_tree_cfg;
-	else
-		work_tree = "..";
-
 	if (is_bare_repository())
 		return "denyCurrentBranch = updateInstead needs a worktree";
-	if (worktree)
-		git_dir = get_worktree_git_dir(worktree);
-	if (!git_dir)
-		git_dir = get_git_dir();
+	git_dir = get_worktree_git_dir(worktree);
 
 	strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir));
 
 	if (!hook_exists(push_to_checkout_hook))
-		retval = push_to_deploy(sha1, &env, work_tree);
+		retval = push_to_deploy(sha1, &env, worktree->path);
 	else
-		retval = push_to_checkout(sha1, &env, work_tree);
+		retval = push_to_checkout(sha1, &env, worktree->path);
 
 	strvec_clear(&env);
 	return retval;
@@ -1579,7 +1569,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
 	}
 
 	if (do_update_worktree) {
-		ret = update_worktree(new_oid->hash, find_shared_symref("HEAD", name));
+		ret = update_worktree(new_oid->hash, worktree);
 		if (ret)
 			return ret;
 	}
-- 
2.33.1
Previous: Anders KaseorgNext: Johannes Schindelin
Message 7 of 34 in “receive-pack: Protect current branch for bare repository worktree”
  1. 2/2 receive-pack: Protect current branch for bare repository worktreeAnders Kaseorg, Nov 8, 2021
  2. Junio C HamanoNov 8, 2021
  3. Junio C HamanoNov 9, 2021
  4. Johannes SchindelinNov 9, 2021
  5. Anders KaseorgNov 9, 2021
  6. 1/4 fetch: Protect branches checked out in all worktreesAnders Kaseorg, Nov 9, 2021
  7. 2/4 receive-pack: Clean dead code from update_worktree()Anders Kaseorg, Nov 9, 2021
  8. Johannes SchindelinNov 9, 2021
  9. Anders KaseorgNov 9, 2021
  10. 3/4 receive-pack: Protect current branch for bare repository worktreeAnders Kaseorg, Nov 9, 2021
  11. Johannes SchindelinNov 9, 2021
  12. Anders KaseorgNov 9, 2021
  13. 1/4 fetch: Protect branches checked out in all worktreesAnders Kaseorg, Nov 9, 2021
  14. 3/4 receive-pack: Protect current branch for bare repository worktreeAnders Kaseorg, Nov 9, 2021
  15. Ævar Arnfjörð BjarmasonNov 10, 2021
  16. 4/4 branch: Protect branches checked out in all worktreesAnders Kaseorg, Nov 9, 2021
  17. Ævar Arnfjörð BjarmasonNov 10, 2021
  18. 2/4 receive-pack: Clean dead code from update_worktree()Anders Kaseorg, Nov 9, 2021
  19. Ævar Arnfjörð BjarmasonNov 10, 2021
  20. Johannes SchindelinNov 10, 2021
  21. Ævar Arnfjörð BjarmasonNov 10, 2021
  22. Johannes SchindelinNov 10, 2021
  23. Junio C HamanoNov 10, 2021
  24. Junio C HamanoNov 11, 2021
  25. Junio C HamanoNov 10, 2021
  26. Anders KaseorgNov 10, 2021
  27. 4/4 branch: Protect branches checked out in all worktreesAnders Kaseorg, Nov 9, 2021
  28. Johannes SchindelinNov 9, 2021
  29. Johannes SchindelinNov 9, 2021
  30. Anders KaseorgNov 9, 2021
  31. Junio C HamanoNov 9, 2021
  32. Junio C HamanoNov 9, 2021
  33. Anders KaseorgNov 9, 2021
  34. Johannes SchindelinNov 9, 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.