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

Re: [PATCH 4/6] refs: drop unused params from the reflog iterator callback

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 20, 2024, 00:14 UTC
Message-ID
<xmqqplwsyotj.fsf@gitster.g>
In-Reply-To
<be512ef268b910852ff11df181d89c483ffc18ab.1708353264.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 9 quoted lines
> The ref and reflog iterators share much of the same underlying code to
> iterate over the corresponding entries. This results in some weird code
> because the reflog iterator also exposes an object ID as well as a flag
> to the callback function. Neither of these fields do refer to the reflog
> though -- they refer to the corresponding ref with the same name. This
> is quite misleading. In practice at least the object ID cannot really be
> implemented in any other way as a reflog does not have a specific object
> ID in the first place. This is further stressed by the fact that none of
> the callbacks except for our test helper make use of these fields.

Interesting observation. Of course this will make the callstack longer by another level of indirection ...

Show 14 quoted lines
> +struct do_for_each_reflog_help {
> +	each_reflog_fn *fn;
> +	void *cb_data;
> +};
> +
> +static int do_for_each_reflog_helper(struct repository *r UNUSED,
> +				     const char *refname,
> +				     const struct object_id *oid UNUSED,
> +				     int flags,
> +				     void *cb_data)
> +{
> +	struct do_for_each_reflog_help *hp = cb_data;
> +	return hp->fn(refname, hp->cb_data);
> +}
... but I think it would be worth it.
Show 15 quoted lines
> +/*
> + * The signature for the callback function for the {refs_,}for_each_reflog()
> + * functions below. The memory pointed to by the refname argument is only
> + * guaranteed to be valid for the duration of a single callback invocation.
> + */
> +typedef int each_reflog_fn(const char *refname, void *cb_data);
> +
>  /*
>   * Calls the specified function for each reflog file until it returns nonzero,
>   * and returns the value. Reflog file order is unspecified.
>   */
> -int refs_for_each_reflog(struct ref_store *refs, each_ref_fn fn, void *cb_data);
> -int for_each_reflog(each_ref_fn fn, void *cb_data);
> +int refs_for_each_reflog(struct ref_store *refs, each_reflog_fn fn, void *cb_data);
> +int for_each_reflog(each_reflog_fn fn, void *cb_data);
Nice simplification.
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 of 39 in “reflog: introduce subcommand to list reflogs”
  1. 0/6 reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 19, 2024
  2. 1/6 dir-iterator: pass name to `prepare_next_entry_data()` directlyPatrick Steinhardt, Feb 19, 2024
  3. 2/6 dir-iterator: support iteration in sorted orderPatrick Steinhardt, Feb 19, 2024
  4. Junio C HamanoFeb 19, 2024
  5. Patrick SteinhardtFeb 20, 2024
  6. 3/6 refs/files: sort reflogs returned by the reflog iteratorPatrick Steinhardt, Feb 19, 2024
  7. Junio C HamanoFeb 20, 2024
  8. Patrick SteinhardtFeb 20, 2024
  9. 4/6 refs: drop unused params from the reflog iterator callbackPatrick Steinhardt, Feb 19, 2024
  10. Junio C HamanoFeb 20, 2024
  11. Patrick SteinhardtFeb 20, 2024
  12. 5/6 refs: stop resolving ref corresponding to reflogsPatrick Steinhardt, Feb 19, 2024
  13. Junio C HamanoFeb 20, 2024
  14. Patrick SteinhardtFeb 20, 2024
  15. 6/6 builtin/reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 19, 2024
  16. Junio C HamanoFeb 20, 2024
  17. Patrick SteinhardtFeb 20, 2024
  18. 0/7 reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 20, 2024
  19. 1/7 dir-iterator: pass name to `prepare_next_entry_data()` directlyPatrick Steinhardt, Feb 20, 2024
  20. 2/7 dir-iterator: support iteration in sorted orderPatrick Steinhardt, Feb 20, 2024
  21. 3/7 refs/files: sort reflogs returned by the reflog iteratorPatrick Steinhardt, Feb 20, 2024
  22. 4/7 refs: always treat iterators as orderedPatrick Steinhardt, Feb 20, 2024
  23. 5/7 refs: drop unused params from the reflog iterator callbackPatrick Steinhardt, Feb 20, 2024
  24. 6/7 refs: stop resolving ref corresponding to reflogsPatrick Steinhardt, Feb 20, 2024
  25. 7/7 builtin/reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 20, 2024
  26. 7/7 builtin/reflog: introduce subcommand to list reflogsTeng Long, Apr 24, 2024
  27. Patrick SteinhardtApr 24, 2024
  28. Junio C HamanoApr 24, 2024
  29. Junio C HamanoFeb 20, 2024
  30. Patrick SteinhardtFeb 21, 2024
  31. 0/8 reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 21, 2024
  32. 1/8 dir-iterator: pass name to `prepare_next_entry_data()` directlyPatrick Steinhardt, Feb 21, 2024
  33. 2/8 dir-iterator: support iteration in sorted orderPatrick Steinhardt, Feb 21, 2024
  34. 3/8 refs/files: sort reflogs returned by the reflog iteratorPatrick Steinhardt, Feb 21, 2024
  35. 4/8 refs/files: sort merged worktree and common reflogsPatrick Steinhardt, Feb 21, 2024
  36. 5/8 refs: always treat iterators as orderedPatrick Steinhardt, Feb 21, 2024
  37. 6/8 refs: drop unused params from the reflog iterator callbackPatrick Steinhardt, Feb 21, 2024
  38. 7/8 refs: stop resolving ref corresponding to reflogsPatrick Steinhardt, Feb 21, 2024
  39. 8/8 builtin/reflog: introduce subcommand to list reflogsPatrick Steinhardt, Feb 21, 2024

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.