<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/reftable/stack.c, branch main</title>
<subtitle>Fork of git SCM with my patches.</subtitle>
<id>http://git.kilabit.info/git/atom?h=main</id>
<link rel='self' href='http://git.kilabit.info/git/atom?h=main'/>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/'/>
<updated>2026-04-02T17:45:43Z</updated>
<entry>
<title>reftable/system: add abstraction to retrieve time in milliseconds</title>
<updated>2026-04-02T17:45:43Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2026-04-02T07:31:17Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=cb0882de1979522b2fc3dc4c3064b0ad21d50b06'/>
<id>urn:sha1:cb0882de1979522b2fc3dc4c3064b0ad21d50b06</id>
<content type='text'>
We directly call gettimeofday(3p), which may not be available on some
platforms. Provide the infrastructure to let projects easily use their
own implementations of this function.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: provide fsync(3p) via system header</title>
<updated>2026-04-02T17:45:43Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2026-04-02T07:31:15Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=b45ea595e6f6b03a749abc2c8e508504429a4cf3'/>
<id>urn:sha1:b45ea595e6f6b03a749abc2c8e508504429a4cf3</id>
<content type='text'>
Users of the reftable library are expected to provide their own function
callback in cases they want to sync(3p) data to disk via the reftable
write options. But if no such function was provided we end up calling
fsync(3p) directly, which may not even be available on some systems.

While dropping the explicit call to fsync(3p) would work, it would lead
to an unsafe default behaviour where a project may have forgotten to set
up the callback function, and that could lead to potential data loss. So
this is not a great solution.

Instead, drop the callback function and make it mandatory for the
project to define fsync(3p). In the case of Git, we can then easily
inject our custom implementation via the "reftable-system.h" header so
that we continue to use `fsync_component()`.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: add function to check if optimization is required</title>
<updated>2025-11-10T17:28:47Z</updated>
<author>
<name>Karthik Nayak</name>
<email>karthik.188@gmail.com</email>
</author>
<published>2025-11-08T21:51:54Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=e35155588aa9f0355eb7e116ea418c189479f62d'/>
<id>urn:sha1:e35155588aa9f0355eb7e116ea418c189479f62d</id>
<content type='text'>
The reftable backend performs auto-compaction as part of its regular
flow, which is required to keep the number of tables part of a stack at
bay. This allows it to stay optimized.

Compaction can also be triggered voluntarily by the user via the 'git
pack-refs' or the 'git refs optimize' command. However, currently there
is no way for the user to check if optimization is required without
actually performing it.

Extract out the heuristics logic from 'reftable_stack_auto_compact()'
into an internal function 'update_segment_if_compaction_required()'.
Then use this to add and expose `reftable_stack_compaction_required()`
which will allow users to check if the reftable backend can be
optimized.

Signed-off-by: Karthik Nayak &lt;karthik.188@gmail.com&gt;
Acked-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: return stack segments directly</title>
<updated>2025-11-10T17:28:47Z</updated>
<author>
<name>Karthik Nayak</name>
<email>karthik.188@gmail.com</email>
</author>
<published>2025-11-08T21:51:53Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=135f491f83d4763bdc61642eb0126ce2e6ada286'/>
<id>urn:sha1:135f491f83d4763bdc61642eb0126ce2e6ada286</id>
<content type='text'>
The `stack_table_sizes_for_compaction()` function returns individual
sizes of each reftable table. This function is only called by
`reftable_stack_auto_compact()` to decide which tables need to be
compacted, if any.

Modify the function to directly return the segments, which avoids the
extra step of receiving the sizes only to pass it to
`suggest_compaction_segment()`.

A future commit will also add functionality for checking whether
auto-compaction is necessary without performing it. This change allows
code re-usability in that context.

Signed-off-by: Karthik Nayak &lt;karthik.188@gmail.com&gt;
Acked-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'kn/reftable-consistency-checks'</title>
<updated>2025-10-14T05:00:35Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2025-10-14T05:00:35Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=f50f046794a06cfb97c4ccc879b08788629dd067'/>
<id>urn:sha1:f50f046794a06cfb97c4ccc879b08788629dd067</id>
<content type='text'>
The reftable backend learned to sanity check its on-disk data more
carefully.

* kn/reftable-consistency-checks:
  refs/reftable: add fsck check for checking the table name
  reftable: add code to facilitate consistency checks
  fsck: order 'fsck_msg_type' alphabetically
  Documentation/fsck-msgids: remove duplicate msg id
  reftable: check for trailing newline in 'tables.list'
  refs: move consistency check msg to generic layer
  refs: remove unused headers
</content>
</entry>
<entry>
<title>reftable: check for trailing newline in 'tables.list'</title>
<updated>2025-10-07T16:22:57Z</updated>
<author>
<name>Karthik Nayak</name>
<email>karthik.188@gmail.com</email>
</author>
<published>2025-10-07T12:11:27Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=f6442063775b68d9eeaeb9088379fba3298c80ac'/>
<id>urn:sha1:f6442063775b68d9eeaeb9088379fba3298c80ac</id>
<content type='text'>
In the reftable format, the 'tables.list' file contains a
newline separated list of tables. While we parse this file, we do not
check or care about the last newline. Tighten the parser in
`parse_names()` to return an appropriate error if the last newline is
missing.

This requires modification to `parse_names()` to now return the error
while accepting the output as a third argument.

Signed-off-by: Karthik Nayak &lt;karthik.188@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable: don't second-guess errors from flock interface</title>
<updated>2025-08-12T14:41:00Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-08-12T09:54:21Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=8fd7a0ebe100ac3ed757408bbafe478e205804f4'/>
<id>urn:sha1:8fd7a0ebe100ac3ed757408bbafe478e205804f4</id>
<content type='text'>
The `flock` interface is implemented as part of "reftable/system.c" and
thus needs to be implemented by the integrator between the reftable
library and its parent code base. As such, we cannot rely on any
specific implementation thereof.

Regardless of that, users of the `flock` subsystem rely on `errno` being
set to specific values. This is fragile and not documented anywhere and
doesn't really make for a good interface.

Refactor the code so that the implementations themselves are expected to
return reftable-specific error codes. Our implementation of the `flock`
subsystem already knows to do this for all error paths except one.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: handle outdated stacks when compacting</title>
<updated>2025-08-12T14:41:00Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-08-12T09:54:20Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=54d25de3ea93d42457bfdec43949683544d0031b'/>
<id>urn:sha1:54d25de3ea93d42457bfdec43949683544d0031b</id>
<content type='text'>
When we compact the reftable stack we first acquire the lock for the
"tables.list" file and then reload the stack to check that it is still
up-to-date. This is done by calling `stack_uptodate()`, which knows to
return zero in case the stack is up-to-date, a positive value if it is
not and a negative error code on unexpected conditions.

We don't do proper error checking though, but instead we only check
whether the returned error code is non-zero. If so, we simply bubble it
up the calling stack, which means that callers may see an unexpected
positive value.

Fix this issue by translating to `REFTABLE_OUTDATED_ERROR` instead.
Handle this situation in `reftable_addition_commit()`, where we perform
a best-effort auto-compaction.

All other callsites of `stack_uptodate()` know to handle a positive
return value and thus don't need to be fixed.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: allow passing flags to `reftable_stack_add()`</title>
<updated>2025-08-12T14:40:59Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-08-12T09:54:19Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=178c5885007b83dd10cac1e09b72ef8d9fe2ac29'/>
<id>urn:sha1:178c5885007b83dd10cac1e09b72ef8d9fe2ac29</id>
<content type='text'>
The `reftable_stack_add()` function is a simple wrapper to lock the
stack, add records to it via a callback and then commit the
result. One problem with it though is that it doesn't accept any flags
for creating the addition. This makes it impossible to automatically
reload the stack in case it was modified before we managed to lock the
stack.

Add a `flags` field to plug this gap and pass it through accordingly.
For now this new flag won't be used by us, but it will be used by
libgit2.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: fix compiler warning due to missing braces</title>
<updated>2025-08-12T14:40:59Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-08-12T09:54:18Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/git/commit/?id=6fb1d819b7c7796e7cfaae44f056d73436469efc'/>
<id>urn:sha1:6fb1d819b7c7796e7cfaae44f056d73436469efc</id>
<content type='text'>
While perfectly legal, older compiler toolchains complain when
zero-initializing structs that contain nested structs with `{0}`:

    /home/libgit2/source/deps/reftable/stack.c:862:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
            struct reftable_addition empty = REFTABLE_ADDITION_INIT;
                                             ^~~~~~~~~~~~~~~~~~~~~~
    /home/libgit2/source/deps/reftable/stack.c:707:33: note: expanded from macro 'REFTABLE_ADDITION_INIT'
    #define REFTABLE_ADDITION_INIT {0}
                                    ^

We had the discussion around whether or not we want to handle such bogus
compiler errors in the past already [1]. Back then we basically decided
that we do not care about such old-and-buggy compilers, so while we
could fix the issue by using `{{0}}` instead this is not the preferred
way to handle this in the Git codebase.

We have an easier fix though: we can just drop the macro altogether and
handle initialization of the struct in `reftable_stack_addition_init()`.
Callers are expected to call this function already, so this change even
simplifies the calling convention.

[1]: https://lore.kernel.org/git/20220710081135.74964-1-sunshine@sunshineco.com/T/

Suggested-by: Carlo Arenas &lt;carenas@gmail.com&gt;
Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
