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

Re: [PATCH v6 6/8] receive-pack: clean dead code from update_worktree()

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 16, 2021, 05:49 UTC
Message-ID
<xmqqv90sbqg9.fsf@gitster.g>
In-Reply-To
<20211113033358.2179376-7-andersk@mit.edu>
Anders Kaseorg <andersk@mit.edu> writes:
> 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.

Yup. I remember seeing this analysed in earlier rounds' reviews. Nice lossage of lines ;-)

Show 57 quoted lines
>
> Signed-off-by: Anders Kaseorg <andersk@mit.edu>
> ---
>  builtin/receive-pack.c | 23 +++++++----------------
>  1 file changed, 7 insertions(+), 16 deletions(-)
>
> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index 5d7c4832c1..b04d4ad268 100644
> --- a/builtin/receive-pack.c
> +++ b/builtin/receive-pack.c
> @@ -1444,29 +1444,22 @@ 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 (!worktree || !worktree->path)
> +		BUG("worktree->path must be non-NULL");
>  
>  	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 (!find_hook(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;
> @@ -1587,9 +1580,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(worktrees, "HEAD",
> -							 name));
> +		ret = update_worktree(new_oid->hash, worktree);
>  		if (ret)
>  			goto out;
>  	}
Previous: Anders KaseorgNext: Anders Kaseorg
Message 15 of 21 in “protect branches checked out in all worktrees”
  1. 0/8 protect branches checked out in all worktreesAnders Kaseorg, Nov 13, 2021
  2. 1/8 fetch: lowercase error messagesAnders Kaseorg, Nov 13, 2021
  3. Junio C HamanoNov 16, 2021
  4. Anders KaseorgNov 16, 2021
  5. Junio C HamanoNov 17, 2021
  6. Jiang XinNov 22, 2021
  7. 2/8 receive-pack: lowercase error messagesAnders Kaseorg, Nov 13, 2021
  8. Junio C HamanoNov 18, 2021
  9. 5/8 fetch: protect branches checked out in all worktreesAnders Kaseorg, Nov 13, 2021
  10. Junio C HamanoNov 16, 2021
  11. Anders KaseorgNov 16, 2021
  12. Johannes SchindelinNov 22, 2021
  13. 3/8 branch: lowercase error messagesAnders Kaseorg, Nov 13, 2021
  14. 6/8 receive-pack: clean dead code from update_worktree()Anders Kaseorg, Nov 13, 2021
  15. Junio C HamanoNov 16, 2021
  16. 7/8 receive-pack: protect current branch for bare repository worktreeAnders Kaseorg, Nov 13, 2021
  17. 4/8 worktree: simplify find_shared_symref() memory ownership modelAnders Kaseorg, Nov 13, 2021
  18. Junio C HamanoNov 16, 2021
  19. Johannes SchindelinNov 22, 2021
  20. 8/8 branch: protect branches checked out in all worktreesAnders Kaseorg, Nov 13, 2021
  21. Johannes SchindelinNov 22, 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.