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

Re: [PATCH 3/3] stash: call reflog_delete from reflog.c

From
John Cai <johncai86@gmail.com>
Date
Feb 22, 2022, 02:36 UTC
Message-ID
<DAF4762E-6376-44BC-9E8C-B9C32B65D92B@gmail.com>
In-Reply-To
<220218.86o834gej9.gmgdl@evledraar.gmail.com>
Hi Ævar,
On 18 Feb 2022, at 14:20, Ævar Arnfjörð Bjarmason wrote:
Show 81 quoted lines
> On Fri, Feb 18 2022, John Cai via GitGitGadget wrote:
>
>> From: John Cai <johncai86@gmail.com>
>>
>> Now that cmd_reflog_delete has been libified an exported it into a new
>> reflog.c library so we can call it directly from builtin/stash.c. This
>> not only gives us a performance gain since we don't need to create a
>> subprocess, but it also allows us to use the ref transactions api in the
>> future.
>>
>> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> Signed-off-by: John Cai <johncai86@gmail.com>
>
> Very nicely done, and nice that despite the ~500 lines added/removed in
> the diffstat that the "actual" changes in this series are so small.q
>
>> @@ -635,18 +636,9 @@ static int reflog_is_empty(const char *refname)
>>  static int do_drop_stash(struct stash_info *info, int quiet)
>>  {
>>  	int ret;
>> -	struct child_process cp_reflog = CHILD_PROCESS_INIT;
>> -
>
> Nit: We usually separate variables decls with a \n\n, as is done in the
> pre-image, but you end up dropping that.
>
>> -	/*
>> -	 * reflog does not provide a simple function for deleting refs. One will
>> -	 * need to be added to avoid implementing too much reflog code here
>> -	 */
>> -
>> -	cp_reflog.git_cmd = 1;
>> -	strvec_pushl(&cp_reflog.args, "reflog", "delete", "--updateref",
>> -		     "--rewrite", NULL);
>> -	strvec_push(&cp_reflog.args, info->revision.buf);
>> -	ret = run_command(&cp_reflog);
>> +	ret = reflog_delete(info->revision.buf,
>> +			    EXPIRE_REFLOGS_REWRITE | EXPIRE_REFLOGS_REWRITE,
>> +			    0);
>>  	if (!ret) {
>>  		if (!quiet)
>>  			printf_ln(_("Dropped %s (%s)"), info->revision.buf,
>
> I think per the above squashing this in would be nice, i.e. you get rid
> of the long line & it'sclear that "ret" is not used for anything now:
>
> diff --git a/builtin/stash.c b/builtin/stash.c
> index d0967b3d3c3..7b939576720 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -635,11 +635,9 @@ static int reflog_is_empty(const char *refname)
>
>  static int do_drop_stash(struct stash_info *info, int quiet)
>  {
> -	int ret;
> -	ret = reflog_delete(info->revision.buf,
> -			    EXPIRE_REFLOGS_REWRITE | EXPIRE_REFLOGS_REWRITE,
> -			    0);
> -	if (!ret) {
> +	unsigned int flags = EXPIRE_REFLOGS_REWRITE | EXPIRE_REFLOGS_REWRITE;
> +
> +	if (!reflog_delete(info->revision.buf, flags, 0)) {
>  		if (!quiet)
>  			printf_ln(_("Dropped %s (%s)"), info->revision.buf,
>  				  oid_to_hex(&info->w_commit));
>
> But, having written that I notice that we have *_REWRITE twice there, so
> I almost just carried forward a new bug in 3/3 when composing this :)
>
> So one should be EXPIRE_REFLOGS_UPDATE_REF, presumably.
>
> And perhaps it's a big pain, but that suggests that the code isn't
> either used at all, or that we're missing a test for it.
>
> So adding a prep commit to this series where we either drop it, or add
> the missing test would be a very nice addition.
>
> See my quite recent 5ac15ad2509 (reflog tests: add --updateref tests,
> 2021-10-16) for adding such tests, but in that case I just covered "git
> reflog" itself, not "git stash". Maybe we can just add something to that
> for-loop in t1417 (or similar for a new stash test).

So I was trying to write a test to exercise the reflog --updateref and --rewrite cases. --updateref is pretty straightforward, but with --rewrite I noticed that it rewrites the old sha in the .git/log/refs/stash file. But, I was having trouble finding somewhere that read this value. The test could reach into this file and check the literal contents, but wondering if there is a better way. Any help appreciated!

Show 6 quoted lines
>
> Also, a s/unsigned int flags/enum expire_reflog_flags/ while we're at it
> would be very nice here, but that could be done as another small prep
> commit. I.e. it's *not* a new issue since cmd_reflog_delete() had it
> before, but when converting this to a documented API it would be very
> nice to have it reflect the actual type we end up using.
Previous: Taylor BlauNext: Ævar Arnfjörð Bjarmason
Message 8 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.