{"thread":{"id":"45988","subject":"[PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","startedAt":"2017-05-17T00:08:05Z","lastAt":"2017-05-25T12:52:37Z","messageCount":21,"participants":["Manish Goregaokar","Jonathan Nieder","manish.earth@gmail.com","Brandon Williams","manishearth@gmail.com","Simon Ruderich","Samuel Lijin","Junio C Hamano","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"319974","messageId":"CACpkpxn4zSdUMT-i6XWBR77sQTpr5-vudbLVTCs1_hiv7a2t_w@mail.gmail.com","threadId":"45988","inReplyTo":null,"subject":"[PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-17T00:07:39Z","receivedAt":"2017-05-17T00:08:05Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"Git prune will happily delete commits checked out in other worktrees.\nThis is probably not desired.\n\n(Tabs have been converted to spaces in this email sadly, because GMail\ngarbles these. This should suffice for review, and I'll send the patch\nas an attachment or in some other form when done so that it can be\ncleanly applied. Let me know if this won't work.)\n\n\nThanks!\n\nPatch 1/2 follows (based on maint)\n\n-----\n\nFrom c3657cd0bb61921053fad4dd669589780881c574 Mon Sep 17 00:00:00 2001\nFrom: Manish Goregaokar <manishearth@gmail.com>\nDate: Tue, 16 May 2017 16:46:00 -0700\nSubject: refs: Add for_each_worktree_ref for iterating over all worktree HEADs\n\nTo ensure that `git prune` does not remove refs checked out\nin other worktrees, we need to include these HEADs in the\nset of roots. This adds the iteration function necessary\nto do this.\n\nSigned-off-by: Manish Goregaokar <manishearth@gmail.com>\n---\n refs.c | 16 ++++++++++++++++\n refs.h |  1 +\n 2 files changed, 17 insertions(+)\n\ndiff --git a/refs.c b/refs.c\nindex 2d71774..27e0b60 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -3,6 +3,7 @@\n  */\n\n #include \"cache.h\"\n+#include \"commit.h\"\n #include \"lockfile.h\"\n #include \"refs.h\"\n #include \"refs/refs-internal.h\"\n@@ -1157,6 +1158,21 @@ int head_ref(each_ref_fn fn, void *cb_data)\n     return head_ref_submodule(NULL, fn, cb_data);\n }\n\n+int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n+{\n+    int i, flag, retval;\n+    struct object_id oid;\n+    struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n+    for (i = 0; worktrees[i]; i++) {\n+        struct commit* commit =\nlookup_commit_reference(worktrees[i]->head_sha1);\n+        oid = commit->object.oid;\n+        if (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n+            if (retval = fn(\"HEAD\", &oid, flag, cb_data))\n+                return retval;\n+        }\n+    }\n+}\n+\n /*\n  * Call fn for each reference in the specified submodule for which the\n  * refname begins with prefix. If trim is non-zero, then trim that\ndiff --git a/refs.h b/refs.h\nindex 9fbff90..425a853 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n  * stop the iteration.\n  */\n int head_ref(each_ref_fn fn, void *cb_data);\n+int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n int for_each_ref(each_ref_fn fn, void *cb_data);\n int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n-- \n2.10.1\n"},{"id":"319975","messageId":"CACpkpx=O4UxrELRO3ojbbRL2LShcw0MLq=_4Dyck8csbwca9CQ@mail.gmail.com","threadId":"45988","inReplyTo":"CACpkpxn4zSdUMT-i6XWBR77sQTpr5-vudbLVTCs1_hiv7a2t_w@mail.gmail.com","subject":"Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-17T00:08:22Z","receivedAt":"2017-05-17T00:08:49Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"From 3f8015efdcc122e0d345baeb5f1f0485a9f0fcd8 Mon Sep 17 00:00:00 2001\nFrom: Manish Goregaokar <manishearth@gmail.com>\nDate: Tue, 16 May 2017 16:46:36 -0700\nSubject: [PATCH 2/2] reachable: Add HEADs of all worktrees to reachability\n analysis\n\n* reachable.c:\n  mark_reachable_objects: Include other worktrees\n\nSigned-off-by: Manish Goregaokar <manishearth@gmail.com>\n---\n reachable.c | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/reachable.c b/reachable.c\nindex d0199ca..439708e 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -178,6 +178,9 @@ void mark_reachable_objects(struct rev_info *revs,\nint mark_reflog,\n     /* detached HEAD is not included in the list above */\n     head_ref(add_one_ref, revs);\n\n+    /* worktrees are not included in either */\n+    for_each_worktree_ref(add_one_ref, revs);\n+\n     /* Add all reflog info */\n     if (mark_reflog)\n         add_reflogs_to_pending(revs, 0);\n-- \n2.10.1\n\n-Manish Goregaokar\n\n\nOn Tue, May 16, 2017 at 5:07 PM, Manish Goregaokar\n<manishearth@gmail.com> wrote:\n> Git prune will happily delete commits checked out in other worktrees.\n> This is probably not desired.\n>\n> (Tabs have been converted to spaces in this email sadly, because GMail\n> garbles these. This should suffice for review, and I'll send the patch\n> as an attachment or in some other form when done so that it can be\n> cleanly applied. Let me know if this won't work.)\n>\n>\n> Thanks!\n>\n> Patch 1/2 follows (based on maint)\n>\n> -----\n>\n> From c3657cd0bb61921053fad4dd669589780881c574 Mon Sep 17 00:00:00 2001\n> From: Manish Goregaokar <manishearth@gmail.com>\n> Date: Tue, 16 May 2017 16:46:00 -0700\n> Subject: refs: Add for_each_worktree_ref for iterating over all worktree HEADs\n>\n> To ensure that `git prune` does not remove refs checked out\n> in other worktrees, we need to include these HEADs in the\n> set of roots. This adds the iteration function necessary\n> to do this.\n>\n> Signed-off-by: Manish Goregaokar <manishearth@gmail.com>\n> ---\n>  refs.c | 16 ++++++++++++++++\n>  refs.h |  1 +\n>  2 files changed, 17 insertions(+)\n>\n> diff --git a/refs.c b/refs.c\n> index 2d71774..27e0b60 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -3,6 +3,7 @@\n>   */\n>\n>  #include \"cache.h\"\n> +#include \"commit.h\"\n>  #include \"lockfile.h\"\n>  #include \"refs.h\"\n>  #include \"refs/refs-internal.h\"\n> @@ -1157,6 +1158,21 @@ int head_ref(each_ref_fn fn, void *cb_data)\n>      return head_ref_submodule(NULL, fn, cb_data);\n>  }\n>\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n> +{\n> +    int i, flag, retval;\n> +    struct object_id oid;\n> +    struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n> +    for (i = 0; worktrees[i]; i++) {\n> +        struct commit* commit =\n> lookup_commit_reference(worktrees[i]->head_sha1);\n> +        oid = commit->object.oid;\n> +        if (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n> +            if (retval = fn(\"HEAD\", &oid, flag, cb_data))\n> +                return retval;\n> +        }\n> +    }\n> +}\n> +\n>  /*\n>   * Call fn for each reference in the specified submodule for which the\n>   * refname begins with prefix. If trim is non-zero, then trim that\n> diff --git a/refs.h b/refs.h\n> index 9fbff90..425a853 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n>   * stop the iteration.\n>   */\n>  int head_ref(each_ref_fn fn, void *cb_data);\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n>  int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n> --\n> 2.10.1\n"},{"id":"319976","messageId":"20170517002825.GR27400@aiede.svl.corp.google.com","threadId":"45988","inReplyTo":"CACpkpxn4zSdUMT-i6XWBR77sQTpr5-vudbLVTCs1_hiv7a2t_w@mail.gmail.com","subject":"Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2017-05-17T00:28:25Z","receivedAt":"2017-05-17T00:28:36Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"(+cc: Duy, worktree expert)\nHi Manish,\n\nManish Goregaokar wrote:\n\n> Git prune will happily delete commits checked out in other worktrees.\n> This is probably not desired.\n\nYikes.  Thanks for working on it.\n\n> (Tabs have been converted to spaces in this email sadly, because GMail\n> garbles these. This should suffice for review, and I'll send the patch\n> as an attachment or in some other form when done so that it can be\n> cleanly applied. Let me know if this won't work.)\n\nI don't think this will work well --- many reviewers (e.g. I am one of\nthem) rely on being able to apply patches and inspect them locally.\nSee the Discussion and MUA-Specific Hints sections of git-format-patch(1)\nfor some hints about how to accomplish that.\n\nPatch left unsnipped for reference.\n\nThanks,\nJonathan\n\n> To ensure that `git prune` does not remove refs checked out\n> in other worktrees, we need to include these HEADs in the\n> set of roots. This adds the iteration function necessary\n> to do this.\n> \n> Signed-off-by: Manish Goregaokar <manishearth@gmail.com>\n> ---\n>  refs.c | 16 ++++++++++++++++\n>  refs.h |  1 +\n>  2 files changed, 17 insertions(+)\n> \n> diff --git a/refs.c b/refs.c\n> index 2d71774..27e0b60 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -3,6 +3,7 @@\n>   */\n> \n>  #include \"cache.h\"\n> +#include \"commit.h\"\n>  #include \"lockfile.h\"\n>  #include \"refs.h\"\n>  #include \"refs/refs-internal.h\"\n> @@ -1157,6 +1158,21 @@ int head_ref(each_ref_fn fn, void *cb_data)\n>      return head_ref_submodule(NULL, fn, cb_data);\n>  }\n> \n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n> +{\n> +    int i, flag, retval;\n> +    struct object_id oid;\n> +    struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n> +    for (i = 0; worktrees[i]; i++) {\n> +        struct commit* commit =\n> lookup_commit_reference(worktrees[i]->head_sha1);\n> +        oid = commit->object.oid;\n> +        if (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n> +            if (retval = fn(\"HEAD\", &oid, flag, cb_data))\n> +                return retval;\n> +        }\n> +    }\n> +}\n> +\n>  /*\n>   * Call fn for each reference in the specified submodule for which the\n>   * refname begins with prefix. If trim is non-zero, then trim that\n> diff --git a/refs.h b/refs.h\n> index 9fbff90..425a853 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n>   * stop the iteration.\n>   */\n>  int head_ref(each_ref_fn fn, void *cb_data);\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n>  int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n> -- \n> 2.10.1\n"},{"id":"319977","messageId":"20170517005041.46310-1-manishearth@gmail.com","threadId":"45988","inReplyTo":"20170517002825.GR27400@aiede.svl.corp.google.com","subject":"[PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"","fromEmail":"manish.earth@gmail.com","sentAt":"2017-05-17T00:50:40Z","receivedAt":"2017-05-17T00:50:54Z","isPatch":true,"sender":{"key":"manish.earth@gmail.com","avatar":"https://gravatar.com/avatar/17ebbe70c4c9e03b74c1ae6cb78a8dbb33f7a1697a3c1b5406f8d24b45d0ee73?d=mp&s=160"},"body":"From: Manish Goregaokar <manishearth@gmail.com>\n\nTo ensure that `git prune` does not remove refs checked out\nin other worktrees, we need to include these HEADs in the\nset of roots. This adds the iteration function necessary\nto do this.\n\nSigned-off-by: Manish Goregaokar <manishearth@gmail.com>\n---\n refs.c | 16 ++++++++++++++++\n refs.h |  1 +\n 2 files changed, 17 insertions(+)\n\ndiff --git a/refs.c b/refs.c\nindex 2d71774..27e0b60 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -3,6 +3,7 @@\n  */\n \n #include \"cache.h\"\n+#include \"commit.h\"\n #include \"lockfile.h\"\n #include \"refs.h\"\n #include \"refs/refs-internal.h\"\n@@ -1157,6 +1158,21 @@ int head_ref(each_ref_fn fn, void *cb_data)\n \treturn head_ref_submodule(NULL, fn, cb_data);\n }\n \n+int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n+{\n+\tint i, flag, retval;\n+\tstruct object_id oid;\n+\tstruct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n+\tfor (i = 0; worktrees[i]; i++) {\n+\t\tstruct commit* commit = lookup_commit_reference(worktrees[i]->head_sha1);\n+\t\toid = commit->object.oid;\n+\t\tif (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n+\t\t\tif (retval = fn(\"HEAD\", &oid, flag, cb_data))\n+\t\t\t\treturn retval;\n+\t\t}\n+\t}\n+}\n+\n /*\n  * Call fn for each reference in the specified submodule for which the\n  * refname begins with prefix. If trim is non-zero, then trim that\ndiff --git a/refs.h b/refs.h\nindex 9fbff90..425a853 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n  * stop the iteration.\n  */\n int head_ref(each_ref_fn fn, void *cb_data);\n+int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n int for_each_ref(each_ref_fn fn, void *cb_data);\n int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n-- \n2.10.1\n\n"},{"id":"319978","messageId":"20170517005041.46310-2-manishearth@gmail.com","threadId":"45988","inReplyTo":"20170517005041.46310-1-manishearth@gmail.com","subject":"[PATCH 2/2] reachable: Add HEADs of all worktrees to reachability analysis","fromName":"","fromEmail":"manish.earth@gmail.com","sentAt":"2017-05-17T00:50:41Z","receivedAt":"2017-05-17T00:51:00Z","isPatch":true,"sender":{"key":"manish.earth@gmail.com","avatar":"https://gravatar.com/avatar/17ebbe70c4c9e03b74c1ae6cb78a8dbb33f7a1697a3c1b5406f8d24b45d0ee73?d=mp&s=160"},"body":"From: Manish Goregaokar <manishearth@gmail.com>\n\n* reachable.c:\n  mark_reachable_objects: Include other worktrees\n\nSigned-off-by: Manish Goregaokar <manishearth@gmail.com>\n---\n reachable.c | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/reachable.c b/reachable.c\nindex d0199ca..439708e 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -178,6 +178,9 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,\n \t/* detached HEAD is not included in the list above */\n \thead_ref(add_one_ref, revs);\n \n+\t/* worktrees are not included in either */\n+\tfor_each_worktree_ref(add_one_ref, revs);\n+\n \t/* Add all reflog info */\n \tif (mark_reflog)\n \t\tadd_reflogs_to_pending(revs, 0);\n-- \n2.10.1\n\n"},{"id":"319980","messageId":"CAM2h-yfRc69W8f=inRRjtyBh4EZWJk6W2gCTM=S=ifJn3g8auA@mail.gmail.com","threadId":"45988","inReplyTo":"20170517005041.46310-1-manishearth@gmail.com","subject":"Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manish.earth@gmail.com","sentAt":"2017-05-17T00:55:28Z","receivedAt":"2017-05-17T00:55:34Z","isPatch":true,"sender":{"key":"manish.earth@gmail.com","avatar":"https://gravatar.com/avatar/17ebbe70c4c9e03b74c1ae6cb78a8dbb33f7a1697a3c1b5406f8d24b45d0ee73?d=mp&s=160"},"body":"I *think* I got send-email to work but I can't be certain :) The tabs\nseem to be back!\n\nIt didn't thread correctly, unsure why.\n\nSorry about the patch problems,\n\nOn Tue, May 16, 2017 at 5:50 PM,  <manish.earth@gmail.com> wrote:\n> From: Manish Goregaokar <manishearth@gmail.com>\n>\n> To ensure that `git prune` does not remove refs checked out\n> in other worktrees, we need to include these HEADs in the\n> set of roots. This adds the iteration function necessary\n> to do this.\n>\n> Signed-off-by: Manish Goregaokar <manishearth@gmail.com>\n> ---\n>  refs.c | 16 ++++++++++++++++\n>  refs.h |  1 +\n>  2 files changed, 17 insertions(+)\n>\n> diff --git a/refs.c b/refs.c\n> index 2d71774..27e0b60 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -3,6 +3,7 @@\n>   */\n>\n>  #include \"cache.h\"\n> +#include \"commit.h\"\n>  #include \"lockfile.h\"\n>  #include \"refs.h\"\n>  #include \"refs/refs-internal.h\"\n> @@ -1157,6 +1158,21 @@ int head_ref(each_ref_fn fn, void *cb_data)\n>         return head_ref_submodule(NULL, fn, cb_data);\n>  }\n>\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n> +{\n> +       int i, flag, retval;\n> +       struct object_id oid;\n> +       struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n> +       for (i = 0; worktrees[i]; i++) {\n> +               struct commit* commit = lookup_commit_reference(worktrees[i]->head_sha1);\n> +               oid = commit->object.oid;\n> +               if (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n> +                       if (retval = fn(\"HEAD\", &oid, flag, cb_data))\n> +                               return retval;\n> +               }\n> +       }\n> +}\n> +\n>  /*\n>   * Call fn for each reference in the specified submodule for which the\n>   * refname begins with prefix. If trim is non-zero, then trim that\n> diff --git a/refs.h b/refs.h\n> index 9fbff90..425a853 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n>   * stop the iteration.\n>   */\n>  int head_ref(each_ref_fn fn, void *cb_data);\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n>  int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n> --\n> 2.10.1\n>\n"},{"id":"320111","messageId":"CACpkpx=usSnEBPPPppdeaM+HUNc06ZuN3mrfN4Nemspn96K9dQ@mail.gmail.com","threadId":"45988","inReplyTo":"CAM2h-yfRc69W8f=inRRjtyBh4EZWJk6W2gCTM=S=ifJn3g8auA@mail.gmail.com","subject":"Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-17T21:48:07Z","receivedAt":"2017-05-17T21:48:33Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"Oh, btw, refs.c needs an #include \"worktree.h\" to work; I didn't get a\nchance to test this after rebasing onto the maint branch.\n\n(There's also another fix it needs to have no warnings, but that's not\ngoing to affect building). I have this fixed locally, but I'll wait\nfor the rest of the review before pushing them up.\n-Manish Goregaokar\n\n\nOn Tue, May 16, 2017 at 5:55 PM, Manish Goregaokar\n<manish.earth@gmail.com> wrote:\n> I *think* I got send-email to work but I can't be certain :) The tabs\n> seem to be back!\n>\n> It didn't thread correctly, unsure why.\n>\n> Sorry about the patch problems,\n>\n> On Tue, May 16, 2017 at 5:50 PM,  <manish.earth@gmail.com> wrote:\n>> From: Manish Goregaokar <manishearth@gmail.com>\n>>\n>> To ensure that `git prune` does not remove refs checked out\n>> in other worktrees, we need to include these HEADs in the\n>> set of roots. This adds the iteration function necessary\n>> to do this.\n>>\n>> Signed-off-by: Manish Goregaokar <manishearth@gmail.com>\n>> ---\n>>  refs.c | 16 ++++++++++++++++\n>>  refs.h |  1 +\n>>  2 files changed, 17 insertions(+)\n>>\n>> diff --git a/refs.c b/refs.c\n>> index 2d71774..27e0b60 100644\n>> --- a/refs.c\n>> +++ b/refs.c\n>> @@ -3,6 +3,7 @@\n>>   */\n>>\n>>  #include \"cache.h\"\n>> +#include \"commit.h\"\n>>  #include \"lockfile.h\"\n>>  #include \"refs.h\"\n>>  #include \"refs/refs-internal.h\"\n>> @@ -1157,6 +1158,21 @@ int head_ref(each_ref_fn fn, void *cb_data)\n>>         return head_ref_submodule(NULL, fn, cb_data);\n>>  }\n>>\n>> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n>> +{\n>> +       int i, flag, retval;\n>> +       struct object_id oid;\n>> +       struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n>> +       for (i = 0; worktrees[i]; i++) {\n>> +               struct commit* commit = lookup_commit_reference(worktrees[i]->head_sha1);\n>> +               oid = commit->object.oid;\n>> +               if (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n>> +                       if (retval = fn(\"HEAD\", &oid, flag, cb_data))\n>> +                               return retval;\n>> +               }\n>> +       }\n>> +}\n>> +\n>>  /*\n>>   * Call fn for each reference in the specified submodule for which the\n>>   * refname begins with prefix. If trim is non-zero, then trim that\n>> diff --git a/refs.h b/refs.h\n>> index 9fbff90..425a853 100644\n>> --- a/refs.h\n>> +++ b/refs.h\n>> @@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n>>   * stop the iteration.\n>>   */\n>>  int head_ref(each_ref_fn fn, void *cb_data);\n>> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n>>  int for_each_ref(each_ref_fn fn, void *cb_data);\n>>  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n>>  int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n>> --\n>> 2.10.1\n>>\n"},{"id":"320115","messageId":"20170518000735.GD185461@google.com","threadId":"45988","inReplyTo":"CACpkpx=usSnEBPPPppdeaM+HUNc06ZuN3mrfN4Nemspn96K9dQ@mail.gmail.com","subject":"Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-05-18T00:07:35Z","receivedAt":"2017-05-18T00:07:43Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 05/17, Manish Goregaokar wrote:\n> Oh, btw, refs.c needs an #include \"worktree.h\" to work; I didn't get a\n> chance to test this after rebasing onto the maint branch.\n> \n> (There's also another fix it needs to have no warnings, but that's not\n> going to affect building). I have this fixed locally, but I'll wait\n> for the rest of the review before pushing them up.\n> -Manish Goregaokar\n\nJust as an fyi, its usually fine to send out a path RFC (request for\ncomments) or WIP (Work in Progress) which compiles with warnings (or\nmaybe not at all) and which doesn't pass all tests.  If you do that just\nmake sure to indicate as such.\n\nThough if you are sending out a patch which you want to be seriously\nreviewed and ultimately merged then the best practice is to ensure that\nit compiles without warnings and that all tests pass.  I'm definitely\nguilty of this occasionally (no one's perfect!) but I'm just hoping to\nprovide you with some of the expectations we have.\n\nI'm assuming you're newer to the community, so Welcome! Take a load off\nand stay a while :)\n\n-- \nBrandon Williams\n"},{"id":"320121","messageId":"CACpkpxkGWhcALQZ2+2nOCRKgzAa7U7EjZg--S71zocdGY8NYag@mail.gmail.com","threadId":"45988","inReplyTo":"20170518000735.GD185461@google.com","subject":"Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-18T01:16:15Z","receivedAt":"2017-05-18T01:16:42Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"> Just as an fyi, its usually fine to send out a path RFC\n\nAh, this is helpful! Yes, I was still trying to get the tests to run,\nso consider this WIP.\n\nI have since gotten them to run and found one failure which I fixed\n(didn't null-check `commit`).\n\nWaiting for them to finish again, will send new patches when done.\nSorry about that.\n\n\n> but I'm just hoping to provide you with some of the expectations we have.\n\nThank you!\n\nI thought I'd submit the patch early so that I could get the basic\ndesign through review; I wasn't sure if I was using the right APIs for\nthis task.\n\nI should probably write a test for this too. Looks straightforward enough.\n\n> Welcome! Take a load off and stay a while :)\n\n:)\n-Manish Goregaokar\n\n\nOn Wed, May 17, 2017 at 5:07 PM, Brandon Williams <bmwill@google.com> wrote:\n> On 05/17, Manish Goregaokar wrote:\n>> Oh, btw, refs.c needs an #include \"worktree.h\" to work; I didn't get a\n>> chance to test this after rebasing onto the maint branch.\n>>\n>> (There's also another fix it needs to have no warnings, but that's not\n>> going to affect building). I have this fixed locally, but I'll wait\n>> for the rest of the review before pushing them up.\n>> -Manish Goregaokar\n>\n> Just as an fyi, its usually fine to send out a path RFC (request for\n> comments) or WIP (Work in Progress) which compiles with warnings (or\n> maybe not at all) and which doesn't pass all tests.  If you do that just\n> make sure to indicate as such.\n>\n> Though if you are sending out a patch which you want to be seriously\n> reviewed and ultimately merged then the best practice is to ensure that\n> it compiles without warnings and that all tests pass.  I'm definitely\n> guilty of this occasionally (no one's perfect!) but I'm just hoping to\n> provide you with some of the expectations we have.\n>\n> I'm assuming you're newer to the community, so Welcome! Take a load off\n> and stay a while :)\n>\n> --\n> Brandon Williams\n"},{"id":"320122","messageId":"20170518014210.94189-1-manishearth@gmail.com","threadId":"45988","inReplyTo":"CACpkpxkGWhcALQZ2+2nOCRKgzAa7U7EjZg--S71zocdGY8NYag@mail.gmail.com","subject":"[PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-18T01:42:09Z","receivedAt":"2017-05-18T01:42:21Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"From: Manish Goregaokar <manishearth@gmail.com>\n\nTo ensure that `git prune` does not remove refs checked out\nin other worktrees, we need to include these HEADs in the\nset of roots. This adds the iteration function necessary\nto do this.\n\nSigned-off-by: Manish Goregaokar <manishearth@gmail.com>\n---\n refs.c | 20 ++++++++++++++++++++\n refs.h |  1 +\n 2 files changed, 21 insertions(+)\n\ndiff --git a/refs.c b/refs.c\nindex 2d71774..7dc82ba 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -3,10 +3,12 @@\n  */\n \n #include \"cache.h\"\n+#include \"commit.h\"\n #include \"lockfile.h\"\n #include \"refs.h\"\n #include \"refs/refs-internal.h\"\n #include \"object.h\"\n+#include \"worktree.h\"\n #include \"tag.h\"\n \n /*\n@@ -1157,6 +1159,24 @@ int head_ref(each_ref_fn fn, void *cb_data)\n \treturn head_ref_submodule(NULL, fn, cb_data);\n }\n \n+int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n+{\n+\tint i, flag, retval = 0;\n+\tstruct object_id oid;\n+\tstruct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n+\tstruct commit* commit;\n+\tfor (i = 0; worktrees[i]; i++) {\n+\t\tif ((commit = lookup_commit_reference(worktrees[i]->head_sha1))) {\n+\t\t\toid = commit->object.oid;\n+\t\t\tif (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n+\t\t\t\tif ((retval = fn(\"HEAD\", &oid, flag, cb_data)))\n+\t\t\t\t\treturn retval;\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn retval;\n+}\n+\n /*\n  * Call fn for each reference in the specified submodule for which the\n  * refname begins with prefix. If trim is non-zero, then trim that\ndiff --git a/refs.h b/refs.h\nindex 9fbff90..425a853 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n  * stop the iteration.\n  */\n int head_ref(each_ref_fn fn, void *cb_data);\n+int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n int for_each_ref(each_ref_fn fn, void *cb_data);\n int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n-- \n2.10.1\n\n"},{"id":"320123","messageId":"20170518014210.94189-2-manishearth@gmail.com","threadId":"45988","inReplyTo":"20170518014210.94189-1-manishearth@gmail.com","subject":"[PATCH v2 2/2] reachable: Add HEADs of all worktrees to reachability analysis","fromName":"","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-18T01:42:10Z","receivedAt":"2017-05-18T01:42:31Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"From: Manish Goregaokar <manishearth@gmail.com>\n\n* reachable.c:\n  mark_reachable_objects: Include other worktrees\n\nSigned-off-by: Manish Goregaokar <manishearth@gmail.com>\n---\n reachable.c | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/reachable.c b/reachable.c\nindex d0199ca..439708e 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -178,6 +178,9 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,\n \t/* detached HEAD is not included in the list above */\n \thead_ref(add_one_ref, revs);\n \n+\t/* worktrees are not included in either */\n+\tfor_each_worktree_ref(add_one_ref, revs);\n+\n \t/* Add all reflog info */\n \tif (mark_reflog)\n \t\tadd_reflogs_to_pending(revs, 0);\n-- \n2.10.1\n\n"},{"id":"320124","messageId":"CACpkpxn1D_g=im0um4ncLiq3A18HRPpfu-sb1FLoY__tet0--Q@mail.gmail.com","threadId":"45988","inReplyTo":"20170518014210.94189-1-manishearth@gmail.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-18T01:45:31Z","receivedAt":"2017-05-18T01:45:57Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"Hm, my invocation of git-send-email keeps getting the threading wrong.\nIs there a recommended set of arguments to the command?\n\nThanks,\n-Manish Goregaokar\n\n\nOn Wed, May 17, 2017 at 6:42 PM,  <manishearth@gmail.com> wrote:\n> From: Manish Goregaokar <manishearth@gmail.com>\n>\n> To ensure that `git prune` does not remove refs checked out\n> in other worktrees, we need to include these HEADs in the\n> set of roots. This adds the iteration function necessary\n> to do this.\n>\n> Signed-off-by: Manish Goregaokar <manishearth@gmail.com>\n> ---\n>  refs.c | 20 ++++++++++++++++++++\n>  refs.h |  1 +\n>  2 files changed, 21 insertions(+)\n>\n> diff --git a/refs.c b/refs.c\n> index 2d71774..7dc82ba 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -3,10 +3,12 @@\n>   */\n>\n>  #include \"cache.h\"\n> +#include \"commit.h\"\n>  #include \"lockfile.h\"\n>  #include \"refs.h\"\n>  #include \"refs/refs-internal.h\"\n>  #include \"object.h\"\n> +#include \"worktree.h\"\n>  #include \"tag.h\"\n>\n>  /*\n> @@ -1157,6 +1159,24 @@ int head_ref(each_ref_fn fn, void *cb_data)\n>         return head_ref_submodule(NULL, fn, cb_data);\n>  }\n>\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n> +{\n> +       int i, flag, retval = 0;\n> +       struct object_id oid;\n> +       struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n> +       struct commit* commit;\n> +       for (i = 0; worktrees[i]; i++) {\n> +               if ((commit = lookup_commit_reference(worktrees[i]->head_sha1))) {\n> +                       oid = commit->object.oid;\n> +                       if (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n> +                               if ((retval = fn(\"HEAD\", &oid, flag, cb_data)))\n> +                                       return retval;\n> +                       }\n> +               }\n> +       }\n> +       return retval;\n> +}\n> +\n>  /*\n>   * Call fn for each reference in the specified submodule for which the\n>   * refname begins with prefix. If trim is non-zero, then trim that\n> diff --git a/refs.h b/refs.h\n> index 9fbff90..425a853 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -192,6 +192,7 @@ typedef int each_ref_fn(const char *refname,\n>   * stop the iteration.\n>   */\n>  int head_ref(each_ref_fn fn, void *cb_data);\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref(each_ref_fn fn, void *cb_data);\n>  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);\n>  int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,\n> --\n> 2.10.1\n>\n"},{"id":"320149","messageId":"20170518094038.x3xvpsfte3zxpuqd@ruderich.org","threadId":"45988","inReplyTo":"CACpkpxn1D_g=im0um4ncLiq3A18HRPpfu-sb1FLoY__tet0--Q@mail.gmail.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Simon Ruderich","fromEmail":"simon@ruderich.org","sentAt":"2017-05-18T09:40:38Z","receivedAt":"2017-05-18T09:40:46Z","isPatch":true,"sender":{"key":"simon@ruderich.org","avatar":"https://avatars.githubusercontent.com/u/390994?v=4"},"body":"On Wed, May 17, 2017 at 06:45:31PM -0700, Manish Goregaokar wrote:\n> Hm, my invocation of git-send-email keeps getting the threading wrong.\n> Is there a recommended set of arguments to the command?\n\nThe threading looks fine here (for both cases where you mentioned\nit being wrong). Why do you think it's wrong? How does it look on\nyour end?\n\nRegards\nSimon\n-- \n+ privacy is necessary\n+ using gnupg http://gnupg.org\n+ public key id: 0x92FEFDB7E44C32F9\n"},{"id":"320209","messageId":"CAJZjrdUXXEU9g+n5Xhq3eq4pW8zdaev9gVcwdcNeiDvPpgDzgQ@mail.gmail.com","threadId":"45988","inReplyTo":"20170518094038.x3xvpsfte3zxpuqd@ruderich.org","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Samuel Lijin","fromEmail":"sxlijin@gmail.com","sentAt":"2017-05-18T20:29:46Z","receivedAt":"2017-05-18T20:30:45Z","isPatch":true,"sender":{"key":"sxlijin@gmail.com","avatar":"https://gravatar.com/avatar/01777bf1eae64e2b4dca97dcac182a6abbcf6fd8cb4d5b8fa33edf9f8cc21746?d=mp&s=160"},"body":"On Thu, May 18, 2017 at 5:40 AM, Simon Ruderich <simon@ruderich.org> wrote:\n> On Wed, May 17, 2017 at 06:45:31PM -0700, Manish Goregaokar wrote:\n>> Hm, my invocation of git-send-email keeps getting the threading wrong.\n>> Is there a recommended set of arguments to the command?\n>\n> The threading looks fine here (for both cases where you mentioned\n> it being wrong). Why do you think it's wrong? How does it look on\n> your end?\n\nIf you're on gmail (as Manish and I both are) patches in a subsequent\nversion will be threaded (wrongly) against \"earlier\" versions of the\npatch. So if you have patch series A0, A1, A2, A3 and new version B0,\nB1, B2, if you thread them as\n\nA0\n- A1\n- A2\n- A3\n- B0\n  - B1\n  - B2\n\ngmail will show them in your inbox as\n\nA0\n- B0\n\nA1\n- B1\n\nA2\n\nA3\n- B2\n\nDepending on whatever heuristics they use to match up \"threads\",\npresumably because most emails aren't threaded correctly.\n"},{"id":"320210","messageId":"20170518210624.GF112091@google.com","threadId":"45988","inReplyTo":"CAJZjrdUXXEU9g+n5Xhq3eq4pW8zdaev9gVcwdcNeiDvPpgDzgQ@mail.gmail.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-05-18T21:06:24Z","receivedAt":"2017-05-18T21:06:32Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 05/18, Samuel Lijin wrote:\n> On Thu, May 18, 2017 at 5:40 AM, Simon Ruderich <simon@ruderich.org> wrote:\n> > On Wed, May 17, 2017 at 06:45:31PM -0700, Manish Goregaokar wrote:\n> >> Hm, my invocation of git-send-email keeps getting the threading wrong.\n> >> Is there a recommended set of arguments to the command?\n> >\n> > The threading looks fine here (for both cases where you mentioned\n> > it being wrong). Why do you think it's wrong? How does it look on\n> > your end?\n> \n> If you're on gmail (as Manish and I both are) patches in a subsequent\n\nGmail does not do threading, well not true threading.  It does grouping\nof emails by subject line, that's it. If you want to view threading\n(based on message-id) properly then you'll probably need to use a\ndifferent email client.\n\n> version will be threaded (wrongly) against \"earlier\" versions of the\n> patch. So if you have patch series A0, A1, A2, A3 and new version B0,\n> B1, B2, if you thread them as\n> \n> A0\n> - A1\n> - A2\n> - A3\n> - B0\n>   - B1\n>   - B2\n> \n> gmail will show them in your inbox as\n> \n> A0\n> - B0\n> \n> A1\n> - B1\n> \n> A2\n> \n> A3\n> - B2\n> \n> Depending on whatever heuristics they use to match up \"threads\",\n> presumably because most emails aren't threaded correctly.\n\n-- \nBrandon Williams\n"},{"id":"320306","messageId":"xmqqy3trstup.fsf@gitster.mtv.corp.google.com","threadId":"45988","inReplyTo":"20170518014210.94189-1-manishearth@gmail.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-05-20T10:30:54Z","receivedAt":"2017-05-20T10:31:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"manishearth@gmail.com writes:\n\n> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n> +{\n> +\tint i, flag, retval = 0;\n> +\tstruct object_id oid;\n> +\tstruct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n> +\tstruct commit* commit;\n> +\tfor (i = 0; worktrees[i]; i++) {\n> +\t\tif ((commit = lookup_commit_reference(worktrees[i]->head_sha1))) {\n> +\t\t\toid = commit->object.oid;\n> +\t\t\tif (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n> +\t\t\t\tif ((retval = fn(\"HEAD\", &oid, flag, cb_data)))\n> +\t\t\t\t\treturn retval;\n> +\t\t\t}\n> +\t\t}\n> +\t}\n> +\treturn retval;\n> +}\n\nI would have expected for-each-worktree-ref to iterate over all the\nrefs in a given worktree, but that is not what this does.  This\ninstead iterates over worktrees and shows only their HEAD ref, no\nother refs.  This helper is somewhat misnamed.\n\nBy the way, doesn't nd/prune-in-worktree topic that has been cooking\nin 'pu' supersede this change?  It not just protects the commit at\nthe tip of HEAD in each worktree, it also makes sure the ones in\nHEAD's reflog are not prematurely pruned.\n\nThanks.\n\n"},{"id":"320319","messageId":"CACpkpxmGzz0hUsypX5ORX7FLB3rh_xbyPOKz4SUt-zrjSjCq_g@mail.gmail.com","threadId":"45988","inReplyTo":"xmqqy3trstup.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-20T17:33:25Z","receivedAt":"2017-05-20T17:33:53Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"Yes, you are right (on both counts).\n\nOne thing which I think hasn't been covered yet is the rebase\nORIG_HEAD. I'll see if that's still a problem on `pu` and make a patch\nfor it if so.\n\n(I recall `git prune` during a rebase messing up repo state, though\nit's really my fault for trying that in the first place. Would be nice\nif it worked, though)\n-Manish Goregaokar\n\n\nOn Sat, May 20, 2017 at 3:30 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> manishearth@gmail.com writes:\n>\n>> +int for_each_worktree_ref(each_ref_fn fn, void *cb_data)\n>> +{\n>> +     int i, flag, retval = 0;\n>> +     struct object_id oid;\n>> +     struct worktree **worktrees = get_worktrees(GWT_SORT_LINKED);\n>> +     struct commit* commit;\n>> +     for (i = 0; worktrees[i]; i++) {\n>> +             if ((commit = lookup_commit_reference(worktrees[i]->head_sha1))) {\n>> +                     oid = commit->object.oid;\n>> +                     if (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag)) {\n>> +                             if ((retval = fn(\"HEAD\", &oid, flag, cb_data)))\n>> +                                     return retval;\n>> +                     }\n>> +             }\n>> +     }\n>> +     return retval;\n>> +}\n>\n> I would have expected for-each-worktree-ref to iterate over all the\n> refs in a given worktree, but that is not what this does.  This\n> instead iterates over worktrees and shows only their HEAD ref, no\n> other refs.  This helper is somewhat misnamed.\n>\n> By the way, doesn't nd/prune-in-worktree topic that has been cooking\n> in 'pu' supersede this change?  It not just protects the commit at\n> the tip of HEAD in each worktree, it also makes sure the ones in\n> HEAD's reflog are not prematurely pruned.\n>\n> Thanks.\n>\n"},{"id":"320361","messageId":"xmqqzie7qeal.fsf@gitster.mtv.corp.google.com","threadId":"45988","inReplyTo":"CACpkpxmGzz0hUsypX5ORX7FLB3rh_xbyPOKz4SUt-zrjSjCq_g@mail.gmail.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-05-20T23:49:54Z","receivedAt":"2017-05-20T23:50:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Manish Goregaokar <manishearth@gmail.com> writes:\n\n> One thing which I think hasn't been covered yet is the rebase\n> ORIG_HEAD. I'll see if that's still a problem on `pu` and make a patch\n> for it if so.\n\nIIRC, ORIG_HEAD, FETCH_HEAD, MERGE_HEAD and others are be transitory\nand never served as the starting points of reachability traversal,\neven in the primary worktree (also when you are not using any extra\nworktrees).  The commits listed in the todo list of \"rebase -i\" and\n\"git cherry-pick A..B\" are the same way.\n\nBecause ORIG_HEAD is expected to be in a reflog of some ref (at\nleast, the reflog of HEAD), I do not see much benefit (or \"more\nsafety\") in adding it to the starting points.\n\nAmong the ones that appear in .git/ and we never considered as\nstarting points, the commits in FETCH_HEAD might be the ones we may\nwant to give extra protection over what we currently have, simply\nbecause the ones that do not have remote-tracking branches have NO\nother refs pointing at them (compared to these transitory artifacts\nresulting from a local operation, i.e. ORIG_HEAD and ones in the\ntodo list).  But they by definition are \"new\" objects, and the\nreason why the user does *not* use remote-tracking branches for them\nis because the user does not want to keep record of them unless the\nuser decides to merge them somewhere in the repository's history, so\neven for them the benefit is dubious...\n\n"},{"id":"320402","messageId":"CACsJy8CN0ZvWD6v2vkK3Lbt7xgrMwCjFKT6Nx7HtwZiEzmowpw@mail.gmail.com","threadId":"45988","inReplyTo":"xmqqy3trstup.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2017-05-22T11:17:57Z","receivedAt":"2017-05-22T11:18:36Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, May 20, 2017 at 5:30 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> By the way, doesn't nd/prune-in-worktree topic that has been cooking\n> in 'pu' supersede this change?  It not just protects the commit at\n> the tip of HEAD in each worktree, it also makes sure the ones in\n> HEAD's reflog are not prematurely pruned.\n\nYou have probably noticed I have stayed silent for a long time (and\nprobably will continue). But yes nd/prune-in-worktree should fix this.\nUnfortunately I will not be able to fix it up (I think Michael\nresponded on my last question about the proper way to fix\nfiles_for_each_ref). So anyone feel free to pick that series up and\nfix it (or drop it). For now, pretend that I'm kidnapped by aliens.\n-- \nDuy\n"},{"id":"320488","messageId":"CACpkpxk4X+hvmWR_ohHaKpJiiJe5pdZYcdRYjZqk=Ae0416w2g@mail.gmail.com","threadId":"45988","inReplyTo":"CACsJy8CN0ZvWD6v2vkK3Lbt7xgrMwCjFKT6Nx7HtwZiEzmowpw@mail.gmail.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Manish Goregaokar","fromEmail":"manishearth@gmail.com","sentAt":"2017-05-22T22:52:23Z","receivedAt":"2017-05-22T22:52:49Z","isPatch":true,"sender":{"key":"manishearth@gmail.com","avatar":"https://gravatar.com/avatar/023027eb83ba0eeb1774e43360d71f411f5cd9aff19ce1c954bc0459b766217a?d=mp&s=160"},"body":"What work is remaining for prune-in-worktree? Link to the relevant discussions?\n\nI might be able to take it over the finish line. (No guarantees)\n-Manish Goregaokar\n\n\nOn Mon, May 22, 2017 at 4:17 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Sat, May 20, 2017 at 5:30 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> By the way, doesn't nd/prune-in-worktree topic that has been cooking\n>> in 'pu' supersede this change?  It not just protects the commit at\n>> the tip of HEAD in each worktree, it also makes sure the ones in\n>> HEAD's reflog are not prematurely pruned.\n>\n> You have probably noticed I have stayed silent for a long time (and\n> probably will continue). But yes nd/prune-in-worktree should fix this.\n> Unfortunately I will not be able to fix it up (I think Michael\n> responded on my last question about the proper way to fix\n> files_for_each_ref). So anyone feel free to pick that series up and\n> fix it (or drop it). For now, pretend that I'm kidnapped by aliens.\n> --\n> Duy\n"},{"id":"320708","messageId":"CACsJy8AgAVjCTcvYf_YSiVcZVBr+NNJOomVGy=2Ej4X22=v6eA@mail.gmail.com","threadId":"45988","inReplyTo":"CACpkpxk4X+hvmWR_ohHaKpJiiJe5pdZYcdRYjZqk=Ae0416w2g@mail.gmail.com","subject":"Re: [PATCH v2 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2017-05-25T12:51:24Z","receivedAt":"2017-05-25T12:52:37Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, May 23, 2017 at 5:52 AM, Manish Goregaokar\n<manishearth@gmail.com> wrote:\n> What work is remaining for prune-in-worktree? Link to the relevant discussions?\n>\n> I might be able to take it over the finish line. (No guarantees)\n\nThe finish line should be pretty close. I've addressed Michael's other\ncomments except [1]. I pushed what I have done here [2]. The \"wip\"\ncommit was what I proposed to Michael and I believe he had a better\nway of doing it  I think I had a look at the merge iterator once\nbefore writing mine, but maybe I didn't look close enough to see it as\nreusable in this use case.\n\n[1] http://public-inbox.org/git/%3C00720e90-ed85-e8d8-a2e4-f42f93a33d33@alum.mit.edu%3E/#r\n[2] https://github.com/pclouds/git/commits/prune-in-worktrees-2\n-- \nDuy\n"}]}