Subject: Re: reflog existence & reftable

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Wed, 21 Apr 2021 13:57:09 +0200

On Wed, Apr 21 2021, Han-Wen Nienhuys wrote:

> Hi there,
>
> (splitting off from a code review of my test cleanups.)

Just changing the "Subject" won't break In-Reply-To and prune CC, FWIW
the missing In-Reply-To is (probably):
https://lore.kernel.org/git/[email-masked]/

> Currently, reflogs are stored in .git/log/*. Git adds entries to the
> reflog only if the reflog already exists (See the log_ref_setup()
> function).
>
> The current iteration of the reftable design has a unified key space
> of {refname,index-number} for reflog entries. This causes there to be
> no distinction between
>
>   1) reflog is empty (.git/logs/blah is a 0-byte file)
>   2) reflog does not exist (.git/logs/blah does not exist)
>
> This trips up some current tests that make assumptions on reflog existence.
>
> I don't know why one can tweak reflog to be written or not, but the
> current functionality will cause a change in operation with reftable.
> I see two ways forward:
>
> 1) Have different functionality in case of reftable: you cannot query
> for the existence of reflogs, and writing reflogs doesn't depend on
> the existence of a reflog.
>
> 2) Add a reflog existence feature to reftable. We could introduce a
> magical reflog entry, which indicates that the reflog exists (but
> might be empty). This adds some complexity to the C code, but lets us
> maintain backward compatibility.
>
> What do you think?

I think we should fix the tests first, per [1] :)

Because there's a third case revealed by the test case, which would be
teased out by not entirely skipping the test with REFFILES, but
incrementally splitting it up:

Which is that the current reftable implementation is failing a test
(well, probably a lot more, but the one under discussion) that:

 A. Sets core.logAllRefUpdates=false
 B. Checks out an orphan branch
 C. Checks that it has no existing reflog
 D. Makes a commit there
 E. Checks that it has no reflog

Only the "E" case is covered by your summary above.

But no matter how reftable's behavior is under
core.logAllRefUpdates=false it should surely not be returning true in
the "C" case, because there's no log entry to serve up, and indeed the
branch being asked for has no commits.

So for that case somewhere in the guts of the reftable integration we're
losing the distinction between asking for a log that can't exist
v.s. one that's empty, maybe the reftable code is returning "yes I have
logging on" or "yes I have some entries somewhere" in that case?

And in "E", related to "C" isn't in unambiguous to not write it if
there's no existing entry for the branch in question and
core.logAllRefUpdates=false is in effect?

For the rest of this is the behavior under reftable indistinguishable
from having core.logAllRefUpdates=always set?

In any case, I don't think the emergent behavior of the files backend is
worth emulating, but maybe if some feel that way it might be better to
transition the setting in general to core.logAllRefUpdates being a
global on/off boolean, and having a branch.<name>.logRefUpdates, but I
suspect that there's not going to be any/many users of this selective
logging feature.

1. https://lore.kernel.org/git/[email-masked]/