All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jay Soffian <jaysoffian@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC/PATCH] Add multiple workdir support to branch/checkout
Date: Tue, 04 Oct 2011 21:07:36 -0700	[thread overview]
Message-ID: <7vmxdg9j3r.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1317786204-57335-1-git-send-email-jaysoffian@gmail.com> (Jay Soffian's message of "Tue, 4 Oct 2011 23:43:24 -0400")

Jay Soffian <jaysoffian@gmail.com> writes:

> 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?

> @@ -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.

  parent reply	other threads:[~2011-10-05  4:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-05  3:43 [RFC/PATCH] Add multiple workdir support to branch/checkout Jay Soffian
2011-10-05  3:48 ` Jay Soffian
2011-10-05  4:02 ` Nguyen Thai Ngoc Duy
2011-10-05 13:11   ` Jay Soffian
2011-10-05 16:46     ` Junio C Hamano
2011-10-05 17:17       ` Jay Soffian
2011-10-05 18:19         ` Junio C Hamano
2011-10-05 19:11           ` Jay Soffian
2011-10-05 20:00             ` Andreas Krey
2011-10-05 20:50               ` Jay Soffian
2011-10-05 21:30                 ` Jonathan Nieder
2011-10-05 21:52                   ` Jay Soffian
2011-10-05 21:57                     ` Jonathan Nieder
2011-10-05 21:29             ` Junio C Hamano
2011-10-05 21:49               ` Jay Soffian
2011-10-05 19:14           ` Jay Soffian
2011-10-05 22:47           ` Nguyen Thai Ngoc Duy
2011-10-05 22:56             ` Junio C Hamano
2011-10-05 23:11               ` Nguyen Thai Ngoc Duy
2011-10-05 23:49                 ` Junio C Hamano
2011-10-06  0:33                   ` Jay Soffian
2011-10-06  0:43                     ` Junio C Hamano
2011-10-06  0:57                       ` Jay Soffian
2011-10-06  1:15                         ` Junio C Hamano
2011-10-06  1:38                           ` Jay Soffian
2011-10-06  1:57                             ` Junio C Hamano
2011-10-06  4:02                               ` Jay Soffian
2011-10-06  2:06                   ` Nguyen Thai Ngoc Duy
2011-10-06 11:25           ` Bernhard R. Link
2011-10-06 14:42           ` Jeff King
2011-10-05 22:38       ` Nguyen Thai Ngoc Duy
2011-10-05  4:07 ` Junio C Hamano [this message]
2011-10-05 15:24   ` Jay Soffian
2011-10-05 16:01     ` Jay Soffian
2011-10-08 22:55 ` Julián Landerreche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vmxdg9j3r.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jaysoffian@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.