Re: [PATCH 3/3] worktree prune: improve prune logic when worktree is moved
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 3, 2018, 09:30 UTC
- Message-ID
- <CAPig+cQG8yEqunNUjoEAPY-W9+TtzWADhgjdL6udnyrG0YEOVg@mail.gmail.com>
- In-Reply-To
- <20180303033918.15751-4-pclouds@gmail.com>
On Fri, Mar 2, 2018 at 10:39 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> Worktree manual move support is actually gone in 618244e160 (worktree: > stop supporting moving worktrees manually - 2016-01-22). Before that, > this gitdir could be updated often when the worktree is accessed. That > keeps the worktree from being pruned by this logic.
I had a bit of trouble digesting this paragraph. Possible rewrite:
Automatic detection of worktree relocation by a user (via 'mv',
for instance) was removed by 618244e160 (worktree: stop supporting
moving worktrees manually - 2016-01-22). Prior to that,
.git/worktrees/<tag>/gitdir was updated whenever the worktree was
accessed in order to let the pruning logic know that the worktree
was "active" even if it disappeared for a while (due to being
located on removable media, for instance).Show 5 quoted lines
> "git worktree move" is coming so we don't really need this, but since > it's easy to do, perhaps we could keep supporting manual worktree move a > bit longer. Notice that when a worktree is active, the "index" file > should be updated pretty often in common case. The logic is updated to > check for index mtime to see if the worktree is alive.
Seems like a reasonable approximation of the pre-618244e160 way things worked.
Show 7 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -101,6 +101,9 @@ static int prune_worktree(const char *id, struct strbuf *reason)
> if (!file_exists(path)) {
> free(path);
> if (st.st_mtime <= expire) {This st.st_mtime is that of 'gitdir'...
> + if (!stat(git_path("worktrees/%s/index", id), &st) &&
> + st.st_mtime > expire)...and this st.st_mtime is of 'index'.
I wonder if it the 'gitdir' mtime check is really that useful anymore considering that 'index' mtime will almost certainly be more recent.
> + return 0;
> strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
> return 1;