Commit Graph

5 Commits (de6dda0dc3d95cd9aaf43a7b85ceeb57316dcc27)

Author SHA1 Message Date
SZEDER Gábor 1df15f8dee commit-slab: add a function to deep free entries on the slab
clear_##slabname() frees only the memory allocated for a commit slab
itself, but entries in the commit slab might own additional memory
outside the slab that should be freed as well.  We already have (at
least) one such commit slab, and this patch series is about to add one

To free all additional memory owned by entries on the commit slab the
user of such a slab could iterate over all commits it knows about,
peek whether there is a valid entry associated with each commit, and
free the additional memory, if any.  Or it could rely on intimate
knowledge about the internals of the commit slab implementation, and
could itself iterate directly through all entries in the slab, and
free the additional memory.  Or it could just leak the additional

Introduce deep_clear_##slabname() to allow releasing memory owned by
commit slab entries by invoking the 'void free_fn(elemtype *ptr)'
function specified as parameter for each entry in the slab.

Use it in get_shallow_commits() in 'shallow.c' to replace an
open-coded iteration over a commit slab's entries.

Signed-off-by: SZEDER Gábor <>
Signed-off-by: Derrick Stolee <>
Signed-off-by: Junio C Hamano <>
2020-06-08 12:28:49 -07:00
Carlo Marcelo Arenas Belón bbd8eb3ecb commit-slabs: move MAYBE_UNUSED out
after 36da893114 (" enable -Wunused-function", 2018-10-18)
it is expected to be used to prevent -Wunused-function warnings for code
that was macro generated

Signed-off-by: Carlo Marcelo Arenas Belón <>
Signed-off-by: Junio C Hamano <>
2018-10-24 14:52:50 +09:00
Stefan Beller 95bb9d4c32 commit-slabs: remove realloc counter outside of slab struct
The realloc counter is declared outside the struct for the given slabname,
which makes it harder for a follow up patch to move the declaration of the
struct around as then the counter variable would need special treatment.

As the reallocation counter is currently unused we can just remove it.
If we ever need to count the reallocations again, we can reintroduce
the counter as part of 'struct slabname' in commit-slab-decl.h.

Signed-off-by: Stefan Beller <>
Signed-off-by: Junio C Hamano <>
2018-06-29 10:43:40 -07:00
Nguyễn Thái Ngọc Duy 878f0bb819 commit-slab: support shared commit-slab
define_shared_commit_slab() could be used in a header file to define a
commit-slab. One of these C files must include commit-slab-impl.h and
"call" implement_shared_commit_slab().

Signed-off-by: Junio C Hamano <>
2018-05-21 14:07:19 +09:00
Nguyễn Thái Ngọc Duy a9f1f1f9f8 commit-slab.h: code split
The struct declaration and implementation macros are moved to
commit-slab-hdr.h and commit-slab-impl.h respectively.

This right now is not needed for current users but if we make a public
commit-slab type, we may want to avoid including the slab
implementation in a header file which gets replicated in every c file
that includes it.

Signed-off-by: Junio C Hamano <>
2018-05-21 14:07:19 +09:00