Re: [PATCH v3 4/6] worktree.c: retrieve lock status (and optionally reason) in get_worktrees()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nguyễn Thái Ngọc Duy  <pclouds@xxxxxxxxx> writes:

> We need this later to avoid double locking a worktree, or unlocking one
> when it's not even locked.

Shouldn't this be done lazily?

If a user is working in worktree B and is not doing anything funky,
she would not care why worktree A and C are locked, even though she
might care the fact that they are locked.

> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
>  worktree.c | 12 ++++++++++++
>  worktree.h |  1 +
>  2 files changed, 13 insertions(+)
>
> diff --git a/worktree.c b/worktree.c
> index 6432eec..c6a64b1 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -98,6 +98,7 @@ static struct worktree *get_main_worktree(void)
>  	worktree->is_detached = is_detached;
>  	worktree->is_current = 0;
>  	add_head_info(&head_ref, worktree);
> +	worktree->lock_reason = NULL;
>  
>  done:
>  	strbuf_release(&path);
> @@ -144,6 +145,17 @@ static struct worktree *get_linked_worktree(const char *id)
>  	worktree->is_current = 0;
>  	add_head_info(&head_ref, worktree);
>  
> +	strbuf_reset(&path);
> +	strbuf_addf(&path, "%s/worktrees/%s/locked", get_git_common_dir(), id);
> +	if (file_exists(path.buf)) {
> +		struct strbuf lock_reason = STRBUF_INIT;
> +		if (strbuf_read_file(&lock_reason, path.buf, 0) < 0)
> +			die_errno(_("failed to read '%s'"), path.buf);
> +		strbuf_trim(&lock_reason);
> +		worktree->lock_reason = strbuf_detach(&lock_reason, NULL);
> +	} else
> +		worktree->lock_reason = NULL;
> +
>  done:
>  	strbuf_release(&path);
>  	strbuf_release(&worktree_path);
> diff --git a/worktree.h b/worktree.h
> index e1c4715..9932710 100644
> --- a/worktree.h
> +++ b/worktree.h
> @@ -5,6 +5,7 @@ struct worktree {
>  	char *path;
>  	char *id;
>  	char *head_ref;
> +	char *lock_reason;	/* NULL means not locked */
>  	unsigned char head_sha1[20];
>  	int is_detached;
>  	int is_bare;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]