git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Cai <johncai86@gmail.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: John Cai via GitGitGadget <gitgitgadget@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH 3/3] stash: call reflog_delete from reflog.c
Date: Mon, 21 Feb 2022 21:36:13 -0500	[thread overview]
Message-ID: <DAF4762E-6376-44BC-9E8C-B9C32B65D92B@gmail.com> (raw)
In-Reply-To: <220218.86o834gej9.gmgdl@evledraar.gmail.com>

Hi Ævar,

On 18 Feb 2022, at 14:20, Ævar Arnfjörð Bjarmason wrote:

> 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!

>
> 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.

  parent reply	other threads:[~2022-02-22  2:36 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 18:40 [PATCH 0/3] libify reflog John Cai via GitGitGadget
2022-02-18 18:40 ` [PATCH 1/3] reflog: libify delete reflog function and helpers John Cai via GitGitGadget
2022-02-18 19:10   ` Ævar Arnfjörð Bjarmason
2022-02-18 19:39     ` Taylor Blau
2022-02-18 19:48       ` Ævar Arnfjörð Bjarmason
2022-02-18 19:35   ` Taylor Blau
2022-02-21  1:43     ` John Cai
2022-02-21  1:50       ` Taylor Blau
2022-02-23 19:50         ` John Cai
2022-02-18 20:00   ` Junio C Hamano
2022-02-19  2:53     ` Ævar Arnfjörð Bjarmason
2022-02-19  3:02       ` Taylor Blau
2022-02-20  7:49       ` Junio C Hamano
2022-02-18 20:21   ` Junio C Hamano
2022-02-18 18:40 ` [PATCH 2/3] reflog: call reflog_delete from reflog.c John Cai via GitGitGadget
2022-02-18 19:15   ` Ævar Arnfjörð Bjarmason
2022-02-18 20:26     ` Junio C Hamano
2022-02-18 18:40 ` [PATCH 3/3] stash: " John Cai via GitGitGadget
2022-02-18 19:20   ` Ævar Arnfjörð Bjarmason
2022-02-19  0:21     ` Taylor Blau
2022-02-22  2:36     ` John Cai [this message]
2022-02-22 10:51       ` Ævar Arnfjörð Bjarmason
2022-02-18 19:29 ` [PATCH 0/3] libify reflog Ævar Arnfjörð Bjarmason
2022-02-22 18:30 ` [PATCH v2 " John Cai via GitGitGadget
2022-02-22 18:30   ` [PATCH v2 1/3] stash: add test to ensure reflog --rewrite --updatref behavior John Cai via GitGitGadget
2022-02-23  8:54     ` Ævar Arnfjörð Bjarmason
2022-02-23 21:27       ` Junio C Hamano
2022-02-23 21:50         ` Ævar Arnfjörð Bjarmason
2022-02-24 18:21           ` John Cai
2022-02-25 11:45             ` Ævar Arnfjörð Bjarmason
2022-02-25 17:23               ` Junio C Hamano
2022-02-23 21:50         ` John Cai
2022-02-23 22:51       ` Junio C Hamano
2022-02-23 23:12         ` John Cai
2022-02-23 23:27           ` Ævar Arnfjörð Bjarmason
2022-02-23 23:50           ` Junio C Hamano
2022-02-24 14:53             ` John Cai
2022-02-22 18:30   ` [PATCH v2 2/3] reflog: libify delete reflog function and helpers John Cai via GitGitGadget
2022-02-23  9:02     ` Ævar Arnfjörð Bjarmason
2022-02-23 18:40       ` John Cai
2022-02-23 21:28     ` Junio C Hamano
2022-02-22 18:30   ` [PATCH v2 3/3] stash: call reflog_delete() in reflog.c John Cai via GitGitGadget
2022-02-25 19:30   ` [PATCH v3 0/3] libify reflog John Cai via GitGitGadget
2022-02-25 19:30     ` [PATCH v3 1/3] stash: add tests to ensure reflog --rewrite --updatref behavior John Cai via GitGitGadget
2022-03-02 18:52       ` Ævar Arnfjörð Bjarmason
2022-02-25 19:30     ` [PATCH v3 2/3] reflog: libify delete reflog function and helpers John Cai via GitGitGadget
2022-02-25 19:30     ` [PATCH v3 3/3] stash: call reflog_delete() in reflog.c John Cai via GitGitGadget
2022-02-25 19:38     ` [PATCH v3 0/3] libify reflog Taylor Blau
2022-03-02 16:43       ` John Cai
2022-03-02 18:55         ` Ævar Arnfjörð Bjarmason
2022-03-02 22:27     ` [PATCH v4 " John Cai via GitGitGadget
2022-03-02 22:27       ` [PATCH v4 1/3] stash: add tests to ensure reflog --rewrite --updatref behavior John Cai via GitGitGadget
2022-03-02 23:32         ` Junio C Hamano
2022-03-03 15:22           ` John Cai
2022-03-03 16:11           ` Phillip Wood
2022-03-03 16:52             ` Ævar Arnfjörð Bjarmason
2022-03-03 17:28               ` Phillip Wood
2022-03-03 19:12                 ` John Cai
2022-03-08 10:39                   ` Phillip Wood
2022-03-08 18:09                     ` John Cai
2022-03-02 22:27       ` [PATCH v4 2/3] reflog: libify delete reflog function and helpers John Cai via GitGitGadget
2022-03-02 22:27       ` [PATCH v4 3/3] stash: call reflog_delete() in reflog.c John Cai via GitGitGadget
2022-03-02 23:34       ` [PATCH v4 0/3] libify reflog Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DAF4762E-6376-44BC-9E8C-B9C32B65D92B@gmail.com \
    --to=johncai86@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).