• Junio C Hamano's avatar
    commit-slab: introduce a macro to define a slab for new type · a84b794a
    Junio C Hamano authored
    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
    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
    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
    	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
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
commit-slab.h 2.88 KB