]> git.ipfire.org Git - thirdparty/git.git/commit - commit.c
commit-slab: introduce a macro to define a slab for new type
authorJunio C Hamano <gitster@pobox.com>
Sat, 13 Apr 2013 18:56:41 +0000 (11:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2013 17:02:12 +0000 (10:02 -0700)
commita84b794ad0622103cae98639d7176b2451dc6f92
tree4e8ee29ad0a408fc47ff7281e492c83d0f3e7e52
parent66eb375d3d334efa3f467775a5f2a647c131c4b1
commit-slab: introduce a macro to define a slab for new type

Introduce a header file to define a macro that can define the struct
type, initializer, accessor and cleanup functions to manage a commit
slab.  Update the "indegree" topological sort facility using it.

To associate 32 flag bits with each commit, you can write:

define_commit_slab(flag32, uint32);

to declare "struct flag32" type, define an instance of it with

struct flag32 flags;

and initialize it by calling

init_flag32(&flags);

After that, a call to flag32_at() function

uint32 *fp = flag32_at(&flags, commit);

will return a pointer pointing at a uint32 for that commit.  Once
you are done with these flags, clean them up with

clear_flag32(&flags);

Callers that cannot hard-code how wide the data to be associated
with the commit be at compile time can use the "_with_stride"
variant to initialize the slab.

Suppose you want to give one bit per existing ref, and paint commits
down to find which refs are descendants of each commit.  Saying

typedef uint32 bits320[5];
define_commit_slab(flagbits, bits320);

at compile time will still limit your code with hard-coded limit,
because you may find that you have more than 320 refs at runtime.

The code can declare a commit slab "struct flagbits" like this
instead:

define_commit_slab(flagbits, unsigned char);
struct flagbits flags;

and initialize it by:

nrefs = ... count number of refs ...
init_flagbits_with_stride(&flags, (nrefs + 7) / 8);

so that

unsigned char *fp = flagbits_at(&flags, commit);

will return a pointer pointing at an array of 40 "unsigned char"s
associated with the commit, once you figure out nrefs is 320 at
runtime.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-slab.h [new file with mode: 0644]
commit.c