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

Re: [RFC/PATCH] Add multiple workdir support to branch/checkout

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 5, 2011, 04:07 UTC
Message-ID
<7vmxdg9j3r.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1317786204-57335-1-git-send-email-jaysoffian@gmail.com>
Jay Soffian <jaysoffian@gmail.com> writes:
Show 46 quoted lines
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 5e356a6c61..26259a41a7 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -709,12 +710,35 @@ static void orphaned_commit_warning(struct commit *commit)
>  	for_each_ref(clear_commit_marks_from_one_ref, NULL);
>  }
>  
> +static void record_checkout(const char *name, const char *work_tree)
> +{
> +	struct strbuf key = STRBUF_INIT;
> +	strbuf_addf(&key, "branch.%s.checkout", name);
> +	git_config_set(key.buf, work_tree);
> +	strbuf_release(&key);
> +}
> +
> +static void check_if_checked_out(struct checkout_opts *opts, const char *name)
> +{
> +	struct branch *branch = branch_get(name);
> +	if (branch->work_tree && strlen(branch->work_tree) &&
> +	    strcmp(branch->work_tree, get_git_work_tree())) {
> +		if (opts->force)
> +			warning(_("branch '%s' is currently checked out"
> +				  " in '%s'"), name, branch->work_tree);
> +		else
> +			die(_("branch '%s' is currently checked out"
> +			      " in '%s'"), name, branch->work_tree);
> +	}
> +}
> +
>  static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
>  {
>  	int ret = 0;
>  	struct branch_info old;
>  	unsigned char rev[20];
>  	int flag;
> +
>  	memset(&old, 0, sizeof(old));
>  	old.path = xstrdup(resolve_ref("HEAD", rev, 0, &flag));
>  	old.commit = lookup_commit_reference_gently(rev, 1);
> @@ -734,6 +758,9 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
>  		parse_commit(new->commit);
>  	}
>  
> +	if (opts->record_checkouts)
> +		check_if_checked_out(opts, new->name);

The close brace we can see in the context closes "if (!new->name) {", so this codepath is very well prepared to be called with new->name == NULL.

Is check_if_checked_out() prepared to be called with name == NULL and do the right thing?

Show 12 quoted lines
> @@ -743,6 +770,14 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
>  
>  	update_refs_for_switch(opts, &old, new);
>  
> +	if (opts->record_checkouts) {
> +		const char *work_tree = get_git_work_tree();
> +		struct branch *branch = branch_get(old.name);
> +		if (branch->work_tree && !strcmp(branch->work_tree, work_tree))
> +			record_checkout(old.name, "");
> +		record_checkout(new->name, work_tree);
> +	}
> +

Likewise for new->name, but also old.name which is only set when old.path is set and begins with "refs/heads/" and otherwise NULL.

Previous: Nguyen Thai Ngoc DuyNext: Jay Soffian
Message 32 of 35 in “Add multiple workdir support to branch/checkout”
  1. Add multiple workdir support to branch/checkoutJay Soffian, Oct 5, 2011
  2. Jay SoffianOct 5, 2011
  3. Nguyen Thai Ngoc DuyOct 5, 2011
  4. Jay SoffianOct 5, 2011
  5. Junio C HamanoOct 5, 2011
  6. Jay SoffianOct 5, 2011
  7. Junio C HamanoOct 5, 2011
  8. Jay SoffianOct 5, 2011
  9. Andreas KreyOct 5, 2011
  10. Jay SoffianOct 5, 2011
  11. Jonathan NiederOct 5, 2011
  12. Jay SoffianOct 5, 2011
  13. Jonathan NiederOct 5, 2011
  14. Junio C HamanoOct 5, 2011
  15. Jay SoffianOct 5, 2011
  16. Jay SoffianOct 5, 2011
  17. Nguyen Thai Ngoc DuyOct 5, 2011
  18. Junio C HamanoOct 5, 2011
  19. Nguyen Thai Ngoc DuyOct 5, 2011
  20. Junio C HamanoOct 5, 2011
  21. Jay SoffianOct 6, 2011
  22. Junio C HamanoOct 6, 2011
  23. Jay SoffianOct 6, 2011
  24. Junio C HamanoOct 6, 2011
  25. Jay SoffianOct 6, 2011
  26. Junio C HamanoOct 6, 2011
  27. Jay SoffianOct 6, 2011
  28. Nguyen Thai Ngoc DuyOct 6, 2011
  29. Bernhard R. LinkOct 6, 2011
  30. Jeff KingOct 6, 2011
  31. Nguyen Thai Ngoc DuyOct 5, 2011
  32. Junio C HamanoOct 5, 2011
  33. Jay SoffianOct 5, 2011
  34. Jay SoffianOct 5, 2011
  35. Julián LanderrecheOct 8, 2011

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.