git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Peter Jones <pjones@redhat.com>
Cc: git@vger.kernel.org, "Eric Sunshine" <sunshine@sunshineco.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: Re: [PATCH v2 2/4] libgit: Expose more worktree functionality.
Date: Mon, 21 Oct 2019 10:59:01 +0900	[thread overview]
Message-ID: <xmqqpniqn9ju.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20191018194542.1316981-2-pjones@redhat.com> (Peter Jones's message of "Fri, 18 Oct 2019 15:45:40 -0400")

Peter Jones <pjones@redhat.com> writes:

Same comment on the commit title as 1/4; also, we tend not to upcase
the first word after the <area>: word and omit the full-stop on the
title (see "git shortlog -32 --no-merges" on our project for
examples).

> Add delete_worktrees_dir_if_empty() and prune_worktree() to the public
> API, so they can be used from more places.  Also add a new function,
> prune_worktree_if_missing(), which prunes unlocked worktrees if they
> aren't present on the filesystem.

It probably is cleaner to do the "also" part as a separate step, as
that allows readers to skip this step without reading it deeply, but
let's see how it is done.

> @@ -144,7 +73,7 @@ static void prune_worktrees(void)
>  		if (is_dot_or_dotdot(d->d_name))
>  			continue;
>  		strbuf_reset(&reason);
> -		if (!prune_worktree(d->d_name, &reason))
> +		if (!prune_worktree(d->d_name, &reason, expire))
>  			continue;
>  		if (show_only || verbose)
>  			printf("%s\n", reason.buf);
> diff --git a/worktree.c b/worktree.c
> index 4924805c389..08454a4e65d 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -608,3 +608,91 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
> +int prune_worktree(const char *id, struct strbuf *reason, timestamp_t expire)

This is not a mere code movement, because the original relied on the
file-scope static "expire", and the public version wants to give
callers control over the expiration value.  That is a good change
that deserves to be advertised and explained in the proposed log
message.

> +int prune_worktree_if_missing(const struct worktree *wt)
> +{
> +	struct strbuf reason = STRBUF_INIT;
> +	int ret;
> +
> +	if (is_worktree_locked(wt) ||
> +	    access(wt->path, F_OK) >= 0 ||
> +	    (errno != ENOENT && errno == ENOTDIR)) {
> +		errno = EEXIST;
> +		return -1;
> +	}

When access() failed but not because the named path did not exist
(i.e. the directory may still exist---it is just this invocation of
the process happened to fail to see it---or it may not exist but we
cannot see far enough to notice that it does not exist) then we play
safe, assume it does exist, and refrain from calling prune_worktree()
on it.  Which makes sense, but do we need to set errno to EEXIST
here?  Does prune_worktree() ensure the value left in errno when it
returns failure in a similar way to allow the caller of this new
helper make effective and reliable use of errno?

> +	strbuf_addf(&reason, _("Removing worktrees/%s: worktree directory is not present"), wt->id);
> +	ret = prune_worktree(wt->id, &reason, TIME_MAX);
> +	return ret;
> +}

  reply	other threads:[~2019-10-21  1:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 16:28 [PATCH 1/2] Make die_if_checked_out() ignore missing worktree checkouts Peter Jones
2019-10-17 16:28 ` [PATCH 2/2] Make "git branch -d" prune missing worktrees automatically Peter Jones
2019-10-17 17:28   ` Eric Sunshine
2019-10-18 19:43     ` Peter Jones
2019-10-18 19:45       ` [PATCH v2 1/4] libgit: Add a read-only helper to test the worktree lock Peter Jones
2019-10-18 19:45         ` [PATCH v2 2/4] libgit: Expose more worktree functionality Peter Jones
2019-10-21  1:59           ` Junio C Hamano [this message]
2019-10-18 19:45         ` [PATCH v2 3/4] Make die_if_checked_out() prune missing checkouts of unlocked worktrees Peter Jones
2019-10-21  2:09           ` Junio C Hamano
2019-10-18 19:45         ` [PATCH v2 4/4] Make "git branch -d" prune missing worktrees automatically Peter Jones
2019-10-21  1:36         ` [PATCH v2 1/4] libgit: Add a read-only helper to test the worktree lock Junio C Hamano
2019-11-08 10:14       ` [PATCH 2/2] Make "git branch -d" prune missing worktrees automatically Eric Sunshine
2019-11-08 14:56         ` Phillip Wood
2019-11-09 11:34           ` Eric Sunshine
2019-10-17 16:44 ` [PATCH 1/2] Make die_if_checked_out() ignore missing worktree checkouts SZEDER Gábor

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=xmqqpniqn9ju.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pjones@redhat.com \
    --cc=sunshine@sunshineco.com \
    --cc=szeder.dev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).