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

Re: [PATCH v2 2/3] reflog: libify delete reflog function and helpers

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 23, 2022, 09:02 UTC
Message-ID
<220223.86zgmi54q6.gmgdl@evledraar.gmail.com>
In-Reply-To
<e7c950218b1b6b91a3cecedf3d2339230522e2e0.1645554652.git.gitgitgadget@gmail.com>
On Tue, Feb 22 2022, John Cai via GitGitGadget wrote:
Show 71 quoted lines
> From: John Cai <johncai86@gmail.com>
>
> Currently stash shells out to reflog in order to delete refs. In an
> effort to reduce how much we shell out to a subprocess, libify the
> functionality that stash needs into reflog.c.
>
> Add a reflog_delete function that is pretty much the logic in the while
> loop in builtin/reflog.c cmd_reflog_delete(). This is a function that
> builtin/reflog.c and builtin/stash.c can both call.
>
> Also move functions needed by reflog_delete and export them.
>
> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> Signed-off-by: John Cai <johncai86@gmail.com>
> ---
>  Makefile         |   1 +
>  builtin/reflog.c | 451 +----------------------------------------------
>  object.h         |   2 +-
>  reflog.c         | 435 +++++++++++++++++++++++++++++++++++++++++++++
>  reflog.h         |  49 +++++
>  5 files changed, 490 insertions(+), 448 deletions(-)
>  create mode 100644 reflog.c
>  create mode 100644 reflog.h
>
> diff --git a/Makefile b/Makefile
> index 6f0b4b775fe..876d4dfd6cb 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -989,6 +989,7 @@ LIB_OBJS += rebase-interactive.o
>  LIB_OBJS += rebase.o
>  LIB_OBJS += ref-filter.o
>  LIB_OBJS += reflog-walk.o
> +LIB_OBJS += reflog.o
>  LIB_OBJS += refs.o
>  LIB_OBJS += refs/debug.o
>  LIB_OBJS += refs/files-backend.o
> diff --git a/builtin/reflog.c b/builtin/reflog.c
> index 85b838720c3..03d347e5832 100644
> --- a/builtin/reflog.c
> +++ b/builtin/reflog.c
> @@ -1,16 +1,13 @@
>  #include "builtin.h"
>  #include "config.h"
>  #include "lockfile.h"
> -#include "object-store.h"
>  #include "repository.h"
> -#include "commit.h"
> -#include "refs.h"
>  #include "dir.h"
> -#include "tree-walk.h"
>  #include "diff.h"
>  #include "revision.h"
>  #include "reachable.h"
>  #include "worktree.h"
> +#include "reflog.h"
> [...]
> diff --git a/reflog.c b/reflog.c
> new file mode 100644
> index 00000000000..8d57dc43503
> --- /dev/null
> +++ b/reflog.c
> @@ -0,0 +1,435 @@
> +#include "cache.h"
> +#include "commit.h"
> +#include "object-store.h"
> +#include "reachable.h"
> +#include "reflog.h"
> +#include "refs.h"
> +#include "revision.h"
> +#include "tree-walk.h"
> +#include "worktree.h"

I think you missed some now-redundant headers, and copied over others we didn't need. This compiles for me with this on top:

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 03d347e5832..940db196f62 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,9 +1,5 @@
 #include "builtin.h"
 #include "config.h"
-#include "lockfile.h"
-#include "repository.h"
-#include "dir.h"
-#include "diff.h"
 #include "revision.h"
 #include "reachable.h"
 #include "worktree.h"
diff --git a/reflog.c b/reflog.c
index 8d57dc43503..333fd8708fe 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,11 +1,8 @@
 #include "cache.h"
-#include "commit.h"
 #include "object-store.h"
-#include "reachable.h"
 #include "reflog.h"
 #include "refs.h"
 #include "revision.h"
-#include "tree-walk.h"
 #include "worktree.h"

But perhaps some of those are really "needed" but brought in implicitly?

> [...]
> diff --git a/reflog.h b/reflog.h
> new file mode 100644
> index 00000000000..3427021cdc2
> --- /dev/null
> +++ b/reflog.h
> @@ -0,0 +1,49 @@
> +#ifndef REFLOG_H
> +#define REFLOG_H
> +
> +#include "refs.h"

Just a nit but I think the reflog_delete() should be wrapped (ends up at
80 cols), and the usual style in this project is to not whitespace-pad
so much, i.e. this on top:

diff --git a/reflog.h b/reflog.h
index 3427021cdc2..d2906fb9f8d 100644
--- a/reflog.h
+++ b/reflog.h
@@ -1,6 +1,5 @@
 #ifndef REFLOG_H
 #define REFLOG_H
-
 #include "refs.h"
 
 struct cmd_reflog_expire_cb {
@@ -25,25 +24,20 @@ struct expire_reflog_policy_cb {
 	unsigned int dry_run:1;
 };
 
-int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose);
-
+int reflog_delete(const char *rev, enum expire_reflog_flags flags,
+		  int verbose);
 void reflog_expiry_cleanup(void *cb_data);
-
 void reflog_expiry_prepare(const char *refname, const struct object_id *oid,
 			   void *cb_data);
-
 int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
 			     const char *email, timestamp_t timestamp, int tz,
 			     const char *message, void *cb_data);
-
 int count_reflog_ent(struct object_id *ooid, struct object_id *noid,
 		     const char *email, timestamp_t timestamp, int tz,
 		     const char *message, void *cb_data);
-
 int should_expire_reflog_ent_verbose(struct object_id *ooid,
 				     struct object_id *noid,
 				     const char *email,
 				     timestamp_t timestamp, int tz,
 				     const char *message, void *cb_data);
-
 #endif /* REFLOG_H */


Other than all that I really can't find anything at all to comment on,
and I see that all the points raised in previous rounds by others were
addressed.
Previous: John Cai via GitGitGadgetNext: John Cai
Message 39 of 63 in “libify reflog”
  1. 0/3 libify reflogJohn Cai via GitGitGadget, Feb 18, 2022
  2. 2/3 reflog: call reflog_delete from reflog.cJohn Cai via GitGitGadget, Feb 18, 2022
  3. Ævar Arnfjörð BjarmasonFeb 18, 2022
  4. Junio C HamanoFeb 18, 2022
  5. 3/3 stash: call reflog_delete from reflog.cJohn Cai via GitGitGadget, Feb 18, 2022
  6. Ævar Arnfjörð BjarmasonFeb 18, 2022
  7. Taylor BlauFeb 19, 2022
  8. John CaiFeb 22, 2022
  9. Ævar Arnfjörð BjarmasonFeb 22, 2022
  10. 1/3 reflog: libify delete reflog function and helpersJohn Cai via GitGitGadget, Feb 18, 2022
  11. Ævar Arnfjörð BjarmasonFeb 18, 2022
  12. Taylor BlauFeb 18, 2022
  13. Ævar Arnfjörð BjarmasonFeb 18, 2022
  14. Taylor BlauFeb 18, 2022
  15. John CaiFeb 21, 2022
  16. Taylor BlauFeb 21, 2022
  17. John CaiFeb 23, 2022
  18. Junio C HamanoFeb 18, 2022
  19. Ævar Arnfjörð BjarmasonFeb 19, 2022
  20. Taylor BlauFeb 19, 2022
  21. Junio C HamanoFeb 20, 2022
  22. Junio C HamanoFeb 18, 2022
  23. Ævar Arnfjörð BjarmasonFeb 18, 2022
  24. 0/3 libify reflogJohn Cai via GitGitGadget, Feb 22, 2022
  25. 1/3 stash: add test to ensure reflog --rewrite --updatref behaviorJohn Cai via GitGitGadget, Feb 22, 2022
  26. Ævar Arnfjörð BjarmasonFeb 23, 2022
  27. Junio C HamanoFeb 23, 2022
  28. John CaiFeb 23, 2022
  29. Ævar Arnfjörð BjarmasonFeb 23, 2022
  30. John CaiFeb 24, 2022
  31. Ævar Arnfjörð BjarmasonFeb 25, 2022
  32. Junio C HamanoFeb 25, 2022
  33. Junio C HamanoFeb 23, 2022
  34. John CaiFeb 23, 2022
  35. Junio C HamanoFeb 23, 2022
  36. John CaiFeb 24, 2022
  37. Ævar Arnfjörð BjarmasonFeb 23, 2022
  38. 2/3 reflog: libify delete reflog function and helpersJohn Cai via GitGitGadget, Feb 22, 2022
  39. Ævar Arnfjörð BjarmasonFeb 23, 2022
  40. John CaiFeb 23, 2022
  41. Junio C HamanoFeb 23, 2022
  42. 3/3 stash: call reflog_delete() in reflog.cJohn Cai via GitGitGadget, Feb 22, 2022
  43. 0/3 libify reflogJohn Cai via GitGitGadget, Feb 25, 2022
  44. 1/3 stash: add tests to ensure reflog --rewrite --updatref behaviorJohn Cai via GitGitGadget, Feb 25, 2022
  45. Ævar Arnfjörð BjarmasonMar 2, 2022
  46. 3/3 stash: call reflog_delete() in reflog.cJohn Cai via GitGitGadget, Feb 25, 2022
  47. 2/3 reflog: libify delete reflog function and helpersJohn Cai via GitGitGadget, Feb 25, 2022
  48. Taylor BlauFeb 25, 2022
  49. John CaiMar 2, 2022
  50. Ævar Arnfjörð BjarmasonMar 2, 2022
  51. 0/3 libify reflogJohn Cai via GitGitGadget, Mar 2, 2022
  52. 1/3 stash: add tests to ensure reflog --rewrite --updatref behaviorJohn Cai via GitGitGadget, Mar 2, 2022
  53. Junio C HamanoMar 2, 2022
  54. John CaiMar 3, 2022
  55. Phillip WoodMar 3, 2022
  56. Ævar Arnfjörð BjarmasonMar 3, 2022
  57. Phillip WoodMar 3, 2022
  58. John CaiMar 3, 2022
  59. Phillip WoodMar 8, 2022
  60. John CaiMar 8, 2022
  61. 3/3 stash: call reflog_delete() in reflog.cJohn Cai via GitGitGadget, Mar 2, 2022
  62. 2/3 reflog: libify delete reflog function and helpersJohn Cai via GitGitGadget, Mar 2, 2022
  63. Junio C HamanoMar 2, 2022

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.