blob: 69bf0c807c64b79216118f3485cfd5dac3b6a273 [file] [log] [blame]
Junio C Hamanoa84b7942013-04-13 11:56:41 -07001#ifndef COMMIT_SLAB_H
2#define COMMIT_SLAB_H
3
Nguyễn Thái Ngọc Duya9f1f1f2018-05-19 07:28:17 +02004#include "commit-slab-decl.h"
5#include "commit-slab-impl.h"
6
Junio C Hamanoa84b7942013-04-13 11:56:41 -07007/*
8 * define_commit_slab(slabname, elemtype) creates boilerplate code to define
9 * a new struct (struct slabname) that is used to associate a piece of data
10 * of elemtype to commits, and a few functions to use that struct.
11 *
12 * After including this header file, using:
13 *
Ville Skyttä2e3a16b2016-08-09 11:53:38 +030014 * define_commit_slab(indegree, int);
Junio C Hamanoa84b7942013-04-13 11:56:41 -070015 *
16 * will let you call the following functions:
17 *
18 * - int *indegree_at(struct indegree *, struct commit *);
19 *
20 * This function locates the data associated with the given commit in
Junio C Hamano862e7302015-05-14 15:25:52 -070021 * the indegree slab, and returns the pointer to it. The location to
22 * store the data is allocated as necessary.
23 *
24 * - int *indegree_peek(struct indegree *, struct commit *);
25 *
26 * This function is similar to indegree_at(), but it will return NULL
27 * until a call to indegree_at() was made for the commit.
Junio C Hamanoa84b7942013-04-13 11:56:41 -070028 *
29 * - void init_indegree(struct indegree *);
30 * void init_indegree_with_stride(struct indegree *, int);
31 *
32 * Initializes the indegree slab that associates an array of integers
33 * to each commit. 'stride' specifies how big each array is. The slab
Thomas Rastdcbbc8f2013-11-25 20:02:00 +010034 * that is initialized by the variant without "_with_stride" associates
Junio C Hamanoa84b7942013-04-13 11:56:41 -070035 * each commit with an array of one integer.
Thomas Rastdcbbc8f2013-11-25 20:02:00 +010036 *
37 * - void clear_indegree(struct indegree *);
38 *
39 * Empties the slab. The slab can be reused with the same stride
40 * without calling init_indegree() again or can be reconfigured to a
41 * different stride by calling init_indegree_with_stride().
42 *
43 * Call this function before the slab falls out of scope to avoid
44 * leaking memory.
Junio C Hamanoa84b7942013-04-13 11:56:41 -070045 */
46
Nguyễn Thái Ngọc Duya9f1f1f2018-05-19 07:28:17 +020047#define define_commit_slab(slabname, elemtype) \
48 declare_commit_slab(slabname, elemtype); \
Nguyễn Thái Ngọc Duy878f0bb2018-05-19 07:28:18 +020049 implement_static_commit_slab(slabname, elemtype)
Jeff King80cdaba2014-06-10 17:42:51 -040050
Junio C Hamanoa84b7942013-04-13 11:56:41 -070051#endif /* COMMIT_SLAB_H */