From: Manish Goregaokar <manishearth@gmail.com>
To: Manish Goregaokar <manishearth@gmail.com>
Cc: git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>,
Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs
Date: Tue, 16 May 2017 17:08:22 -0700 [thread overview]
Message-ID: <CACpkpx=O4UxrELRO3ojbbRL2LShcw0MLq=_4Dyck8csbwca9CQ@mail.gmail.com> (raw)
In-Reply-To: <CACpkpxn4zSdUMT-i6XWBR77sQTpr5-vudbLVTCs1_hiv7a2t_w@mail.gmail.com>
From 3f8015efdcc122e0d345baeb5f1f0485a9f0fcd8 Mon Sep 17 00:00:00 2001
From: Manish Goregaokar <manishearth@gmail.com>
Date: Tue, 16 May 2017 16:46:36 -0700
Subject: [PATCH 2/2] reachable: Add HEADs of all worktrees to reachability
analysis
* reachable.c:
mark_reachable_objects: Include other worktrees
Signed-off-by: Manish Goregaokar <manishearth@gmail.com>
---
reachable.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/reachable.c b/reachable.c
index d0199ca..439708e 100644
--- a/reachable.c
+++ b/reachable.c
@@ -178,6 +178,9 @@ void mark_reachable_objects(struct rev_info *revs,
int mark_reflog,
/* detached HEAD is not included in the list above */
head_ref(add_one_ref, revs);
+ /* worktrees are not included in either */
+ for_each_worktree_ref(add_one_ref, revs);
+
/* Add all reflog info */
if (mark_reflog)
add_reflogs_to_pending(revs, 0);
--
2.10.1
-Manish Goregaokar
On Tue, May 16, 2017 at 5:07 PM, Manish Goregaokar
<manishearth@gmail.com> wrote:
> Git prune will happily delete commits checked out in other worktrees.
> This is probably not desired.
>
> (Tabs have been converted to spaces in this email sadly, because GMail
> garbles these. This should suffice for review, and I'll send the patch
> as an attachment or in some other form when done so that it can be
> cleanly applied. Let me know if this won't work.)
>
>
> Thanks!
>
> Patch 1/2 follows (based on maint)
>
> -----
>
> From c3657cd0bb61921053fad4dd669589780881c574 Mon Sep 17 00:00:00 2001
> From: Manish Goregaokar <manishearth@gmail.com>
> Date: Tue, 16 May 2017 16:46:00 -0700
> Subject: refs: Add for_each_worktree_ref for iterating over all worktree HEADs
>
> To ensure that `git prune` does not remove refs checked out
> in other worktrees, we need to include these HEADs in the
> set of roots. This adds the iteration function necessary
> to do this.
>
> Signed-off-by: Manish Goregaokar <manishearth@gmail.com>
> ---
> refs.c | 16 ++++++++++++++++
> refs.h | 1 +
> 2 files changed, 17 insertions(+)
>
> diff --git a/refs.c b/refs.c
> index 2d71774..27e0b60 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -3,6 +3,7 @@
> */
>
> #include "cache.h"
> +#include "commit.h"
> #include "lockfile.h"
> #include "refs.h"
> #include "refs/refs-internal.h"
> @@ -1157,6 +1158,21 @@ int head_ref(each_ref_fn fn, void *cb_data)
> return head_ref_submodule(NULL, fn, cb_data);
> }
>
> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)
> +{
> + int i, flag, retval;
> + struct object_id oid;
> + struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);
> + for (i = 0; worktrees[i]; i++) {
> + struct commit* commit =
> lookup_commit_reference(worktrees[i]->head_sha1);
> + oid = commit->object.oid;
> + if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag)) {
> + if (retval = fn("HEAD", &oid, flag, cb_data))
> + return retval;
> + }
> + }
> +}
> +
> /*
> * Call fn for each reference in the specified submodule for which the
> * refname begins with prefix. If trim is non-zero, then trim that
> diff --git a/refs.h b/refs.h
> index 9fbff90..425a853 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,
> * stop the iteration.
> */
> int head_ref(each_ref_fn fn, void *cb_data);
> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data);
> int for_each_ref(each_ref_fn fn, void *cb_data);
> int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);
> int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,
> --
> 2.10.1
next prev parent reply other threads:[~2017-05-17 0:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-17 0:07 [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs Manish Goregaokar
2017-05-17 0:08 ` Manish Goregaokar [this message]
2017-05-17 0:28 ` Jonathan Nieder
2017-05-17 0:50 ` manish.earth
2017-05-17 0:50 ` [PATCH 2/2] reachable: Add HEADs of all worktrees to reachability analysis manish.earth
2017-05-17 0:55 ` [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs Manish Goregaokar
2017-05-17 21:48 ` Manish Goregaokar
2017-05-18 0:07 ` Brandon Williams
2017-05-18 1:16 ` Manish Goregaokar
2017-05-18 1:42 ` [PATCH v2 " manishearth
2017-05-18 1:42 ` [PATCH v2 2/2] reachable: Add HEADs of all worktrees to reachability analysis manishearth
2017-05-18 1:45 ` [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs Manish Goregaokar
2017-05-18 9:40 ` Simon Ruderich
2017-05-18 20:29 ` Samuel Lijin
2017-05-18 21:06 ` Brandon Williams
2017-05-20 10:30 ` Junio C Hamano
2017-05-20 17:33 ` Manish Goregaokar
2017-05-20 23:49 ` Junio C Hamano
2017-05-22 11:17 ` Duy Nguyen
2017-05-22 22:52 ` Manish Goregaokar
2017-05-25 12:51 ` Duy Nguyen
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACpkpx=O4UxrELRO3ojbbRL2LShcw0MLq=_4Dyck8csbwca9CQ@mail.gmail.com' \
--to=manishearth@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).