git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] refs: Add for_each_worktree_ref for iterating over all worktree HEADs

From
Manish Goregaokar <manish.earth@gmail.com>
Date
May 17, 2017, 00:55 UTC
Message-ID
<CAM2h-yfRc69W8f=inRRjtyBh4EZWJk6W2gCTM=S=ifJn3g8auA@mail.gmail.com>
In-Reply-To
<20170517005041.46310-1-manishearth@gmail.com>

I *think* I got send-email to work but I can't be certain :) The tabs seem to be back!

It didn't thread correctly, unsure why.
Sorry about the patch problems,
On Tue, May 16, 2017 at 5:50 PM,  <manish.earth@gmail.com> wrote:
Show 62 quoted lines
> From: Manish Goregaokar <manishearth@gmail.com>
>
> 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
>
Previous: manish.earth@gmail.comNext: Manish Goregaokar
Message 6 of 21 in “refs: Add for_each_worktree_ref for iterating over all worktree HEADs”
  1. 1/2 refs: Add for_each_worktree_ref for iterating over all worktree HEADsManish Goregaokar, May 17, 2017
  2. Manish GoregaokarMay 17, 2017
  3. Jonathan NiederMay 17, 2017
  4. 1/2 refs: Add for_each_worktree_ref for iterating over all worktree HEADsmanish.earth@gmail.com, May 17, 2017
  5. 2/2 reachable: Add HEADs of all worktrees to reachability analysismanish.earth@gmail.com, May 17, 2017
  6. Manish GoregaokarMay 17, 2017
  7. Manish GoregaokarMay 17, 2017
  8. Brandon WilliamsMay 18, 2017
  9. Manish GoregaokarMay 18, 2017
  10. 1/2 refs: Add for_each_worktree_ref for iterating over all worktree HEADsmanishearth@gmail.com, May 18, 2017
  11. 2/2 reachable: Add HEADs of all worktrees to reachability analysismanishearth@gmail.com, May 18, 2017
  12. Manish GoregaokarMay 18, 2017
  13. Simon RuderichMay 18, 2017
  14. Samuel LijinMay 18, 2017
  15. Brandon WilliamsMay 18, 2017
  16. Junio C HamanoMay 20, 2017
  17. Manish GoregaokarMay 20, 2017
  18. Junio C HamanoMay 20, 2017
  19. Duy NguyenMay 22, 2017
  20. Manish GoregaokarMay 22, 2017
  21. Duy NguyenMay 25, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.