git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Han-Wen Nienhuys via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Han-Wen Nienhuys <hanwenn@gmail.com>,
	Han-Wen Nienhuys <hanwen@google.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/4] refs: trim newline from reflog message
Date: Tue, 23 Nov 2021 11:24:12 +0100	[thread overview]
Message-ID: <211123.864k83w3y4.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <dfb639373234a6b8d5f9110380a66ffccbe0b1d6.1637590855.git.gitgitgadget@gmail.com>


On Mon, Nov 22 2021, Han-Wen Nienhuys via GitGitGadget wrote:

> From: Han-Wen Nienhuys <hanwen@google.com>
> [...]
> @@ -3059,18 +3059,18 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
>  	if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz,
>  				   message, policy_cb)) {
>  		if (!cb->newlog)
> -			printf("would prune %s", message);
> +			printf("would prune %s\n", message);
>  		else if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
> -			printf("prune %s", message);
> +			printf("prune %s\n", message);
>  	} else {
>  		if (cb->newlog) {
> -			fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s",
> -				oid_to_hex(ooid), oid_to_hex(noid),
> -				email, timestamp, tz, message);
> +			fprintf(cb->newlog, "%s %s %s %" PRItime " %+05d\t%s\n",
> +				oid_to_hex(ooid), oid_to_hex(noid), email,
> +				timestamp, tz, message);
>  			oidcpy(&cb->last_kept_oid, noid);
>  		}
>  		if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
> -			printf("keep %s", message);
> +			printf("keep %s\n", message);
>  	}
>  	return 0;
>  }

I haven't looked deeply into this topic as a whole, but FWIW this
conflicts with a topic I've got locally and was going to submit sometime
after the current batch of my own ref fixes in "next".

That we've got verbose output at all in file-backend.c is a wart, and it
should just be moved out if it entirely, this commit (stacked on top of
various other fixes I've got in the area) does that:
https://github.com/avar/git/commit/eff40d2d81b

With that change the reftable code will need to handle far less of this,
as it'll be handled in builtin/reflog.c, it just needs to behave
properly in the appropriate "expire reflog?" callback. I.e. the backend
tells us "does this expire?", the builtin/reflog.c code consumes that
and does any verbose or non-verbose (or progress etc.) output.

Now, the merge conflict between that and this looks rather trivial, but
I can't help but wonder if we're going in the wrong direction here
API-wise, or maybe "wrong direction" is too strong, but "sticking with
the wrong patterN?".

I think your cleanup works, but wouldn't a better thing be to move this
to callbacks rather than tweaking the fprintf formats?

I.e. in my version the whole body of this function has become:
	
	static int 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)
	{
		struct expire_reflog_cb *cb = cb_data;
		reflog_expiry_should_prune_fn *fn = cb->should_prune_fn;
	
		if (cb->rewrite)
			ooid = &cb->last_kept_oid;
	
		if (fn(ooid, noid, email, timestamp, tz, message, cb->policy_cb))
			return 0;
	
		if (cb->dry_run)
			return 0; /* --dry-run */
	
		fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s", oid_to_hex(ooid),
			oid_to_hex(noid), email, timestamp, tz, message);
		oidcpy(&cb->last_kept_oid, noid);
	
		return 0;
	}

The only file-backend specific part of it is that fprintf(). If we moved
towards making that part of it be:

	write_reflog_entry_cb(oid_to_hex(ooid), oid_to_hex(noid), email, timestamp, tz, message);

Then we could lift the whole of this API to a level that makes more
sense for a backed to implement.

The refs/files-backend.c shouldn't need to have one function calll the
"should_prune_fn" *and* write out the data. Instead some code common to
all backends should call the "should prune?", and then call the
backend's "here's an entry for you to write" callback.

But maybe I'm overthinking this whole thing. I'm just wondering if we
have say a sqlite reflog backend as opposed to the file/reftable backend
that wants to store this data in a schema. Such a a backend would need
to unpack the data, as we're sprintf() formatting function parameters
before it gets passed to the backends.

  parent reply	other threads:[~2021-11-23 10:40 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 14:20 [PATCH 0/4] Inspect reflog data programmatically in more tests Han-Wen Nienhuys via GitGitGadget
2021-11-22 14:20 ` [PATCH 1/4] show-branch: show reflog message Han-Wen Nienhuys via GitGitGadget
2021-11-22 22:22   ` Junio C Hamano
2021-11-23  7:40   ` Bagas Sanjaya
2021-11-23  8:03     ` Elijah Newren
2021-11-22 14:20 ` [PATCH 2/4] refs: trim newline from " Han-Wen Nienhuys via GitGitGadget
2021-11-22 22:27   ` Junio C Hamano
2021-11-23 16:35     ` Han-Wen Nienhuys
2021-11-23 17:09       ` Junio C Hamano
2021-11-23 17:28         ` Han-Wen Nienhuys
2021-11-23 20:34           ` Junio C Hamano
2021-11-24 11:17             ` Han-Wen Nienhuys
2021-11-24 18:53               ` Junio C Hamano
2021-11-24 19:06                 ` Han-Wen Nienhuys
2021-11-24 20:55                   ` Junio C Hamano
2021-11-25 16:00                     ` Han-Wen Nienhuys
2021-11-29  2:30                       ` Junio C Hamano
2021-11-24 19:26               ` Junio C Hamano
2021-11-24 19:39                 ` Han-Wen Nienhuys
2021-11-26  8:35             ` Re* " Junio C Hamano
2021-11-28 17:50               ` Ævar Arnfjörð Bjarmason
2021-11-28 18:59                 ` Junio C Hamano
2021-11-28 19:25                   ` Junio C Hamano
2021-11-29  8:39                     ` Ævar Arnfjörð Bjarmason
2021-11-23 10:24   ` Ævar Arnfjörð Bjarmason [this message]
2021-11-23 16:44     ` Han-Wen Nienhuys
2021-11-22 14:20 ` [PATCH 3/4] test-ref-store: tweaks to for-each-reflog-ent format Han-Wen Nienhuys via GitGitGadget
2021-11-22 22:31   ` Junio C Hamano
2021-11-23 17:06     ` Han-Wen Nienhuys
2021-11-23 18:31       ` Junio C Hamano
2021-11-22 14:20 ` [PATCH 4/4] t1400: use test-helper ref-store to inspect reflog contents Han-Wen Nienhuys via GitGitGadget
2021-11-22 15:20   ` Ævar Arnfjörð Bjarmason
2021-11-22 17:07     ` Han-Wen Nienhuys
2021-11-22 22:22   ` Junio C Hamano
2021-11-25 15:57 ` [PATCH v2 0/5] Inspect reflog data programmatically in more tests Han-Wen Nienhuys via GitGitGadget
2021-11-25 15:57   ` [PATCH v2 1/5] show-branch: show reflog message Han-Wen Nienhuys via GitGitGadget
2021-11-25 15:57   ` [PATCH v2 2/5] test-ref-store: don't add newline to " Han-Wen Nienhuys via GitGitGadget
2021-11-26  7:56     ` Junio C Hamano
2021-11-25 15:57   ` [PATCH v2 3/5] t1405: check for_each_reflog_ent_reverse() more thoroughly Han-Wen Nienhuys via GitGitGadget
2021-11-25 15:57   ` [PATCH v2 4/5] test-ref-store: tweaks to for-each-reflog-ent format Han-Wen Nienhuys via GitGitGadget
2021-11-26  8:02     ` Junio C Hamano
2021-11-25 15:57   ` [PATCH v2 5/5] refs/debug: trim trailing LF from reflog message Han-Wen Nienhuys via GitGitGadget
2021-11-26  8:16     ` Junio C Hamano
2021-11-29 18:29       ` Han-Wen Nienhuys
2021-11-29 19:19         ` Junio C Hamano
2021-11-29 19:35           ` Junio C Hamano
2021-12-02 16:24           ` Han-Wen Nienhuys
2021-12-02 18:36             ` Junio C Hamano
2021-11-29 20:59         ` Ævar Arnfjörð Bjarmason
2021-11-29  9:50   ` [PATCH v2 0/5] Inspect reflog data programmatically in more tests Ævar Arnfjörð Bjarmason
2021-11-29 18:24     ` Han-Wen Nienhuys
2021-11-29 22:30       ` Junio C Hamano
2021-11-29 23:28       ` Ævar Arnfjörð Bjarmason
2021-12-02 16:11         ` Han-Wen Nienhuys
2021-12-02 17:36   ` [PATCH v3 " Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36     ` [PATCH v3 1/5] show-branch: show reflog message Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36     ` [PATCH v3 2/5] test-ref-store: don't add newline to " Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36     ` [PATCH v3 3/5] t1405: check for_each_reflog_ent_reverse() more thoroughly Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36     ` [PATCH v3 4/5] test-ref-store: tweaks to for-each-reflog-ent format Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36     ` [PATCH v3 5/5] refs/debug: trim trailing LF from reflog message Han-Wen Nienhuys via GitGitGadget

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=211123.864k83w3y4.gmgdl@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=hanwen@google.com \
    --cc=hanwenn@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).