@@ -1,5 +1,6 @@
#include "cache.h"
#include "add-interactive.h"
+#include "alloc.h"
#include "strbuf.h"
#include "run-command.h"
#include "strvec.h"
@@ -1,6 +1,8 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "alias.h"
+#include "alloc.h"
#include "config.h"
+#include "gettext.h"
#include "string-list.h"
struct config_alias_data {
@@ -17,4 +17,79 @@ void *alloc_object_node(struct repository *r);
struct alloc_state *allocate_alloc_state(void);
void clear_alloc_state(struct alloc_state *s);
+#define alloc_nr(x) (((x)+16)*3/2)
+
+/**
+ * Dynamically growing an array using realloc() is error prone and boring.
+ *
+ * Define your array with:
+ *
+ * - a pointer (`item`) that points at the array, initialized to `NULL`
+ * (although please name the variable based on its contents, not on its
+ * type);
+ *
+ * - an integer variable (`alloc`) that keeps track of how big the current
+ * allocation is, initialized to `0`;
+ *
+ * - another integer variable (`nr`) to keep track of how many elements the
+ * array currently has, initialized to `0`.
+ *
+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,
+ * alloc)`. This ensures that the array can hold at least `n` elements by
+ * calling `realloc(3)` and adjusting `alloc` variable.
+ *
+ * ------------
+ * sometype *item;
+ * size_t nr;
+ * size_t alloc
+ *
+ * for (i = 0; i < nr; i++)
+ * if (we like item[i] already)
+ * return;
+ *
+ * // we did not like any existing one, so add one
+ * ALLOC_GROW(item, nr + 1, alloc);
+ * item[nr++] = value you like;
+ * ------------
+ *
+ * You are responsible for updating the `nr` variable.
+ *
+ * If you need to specify the number of elements to allocate explicitly
+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
+ *
+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
+ * added niceties.
+ *
+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
+ */
+#define ALLOC_GROW(x, nr, alloc) \
+ do { \
+ if ((nr) > alloc) { \
+ if (alloc_nr(alloc) < (nr)) \
+ alloc = (nr); \
+ else \
+ alloc = alloc_nr(alloc); \
+ REALLOC_ARRAY(x, alloc); \
+ } \
+ } while (0)
+
+/*
+ * Similar to ALLOC_GROW but handles updating of the nr value and
+ * zeroing the bytes of the newly-grown array elements.
+ *
+ * DO NOT USE any expression with side-effect for any of the
+ * arguments.
+ */
+#define ALLOC_GROW_BY(x, nr, increase, alloc) \
+ do { \
+ if (increase) { \
+ size_t new_nr = nr + (increase); \
+ if (new_nr < nr) \
+ BUG("negative growth in ALLOC_GROW_BY"); \
+ ALLOC_GROW(x, new_nr, alloc); \
+ memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
+ nr = new_nr; \
+ } \
+ } while (0)
+
#endif
@@ -8,6 +8,7 @@
*/
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "object-store.h"
#include "blob.h"
@@ -1,7 +1,8 @@
/*
* Copyright (c) 2005, 2006 Rene Scharfe
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "tar.h"
#include "archive.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "refs.h"
#include "object-store.h"
@@ -7,6 +7,7 @@
*/
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "exec-cmd.h"
#include "attr.h"
@@ -5,7 +5,8 @@
* See COPYING for licensing conditions
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "color.h"
#include "builtin.h"
@@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "diff.h"
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "alloc.h"
#include "config.h"
#include "entry.h"
#include "parallel-checkout.h"
@@ -1,5 +1,5 @@
#include "builtin.h"
-#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "color.h"
#include "parse-options.h"
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "alloc.h"
#include "parse-options.h"
#ifndef NO_UNIX_SOCKETS
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "alloc.h"
#include "pkt-line.h"
#include "fetch-pack.h"
#include "remote.h"
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "alloc.h"
#include "config.h"
#include "parse-options.h"
#include "fsmonitor.h"
@@ -4,6 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
+#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "blob.h"
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "alloc.h"
#include "config.h"
#include "delta.h"
#include "pack.h"
@@ -4,7 +4,8 @@
* (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "refs.h"
#include "object-store.h"
@@ -8,6 +8,7 @@
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "parse-options.h"
#include "builtin.h"
@@ -4,6 +4,7 @@
* Copyright (c) Junio C Hamano, 2006, 2009
*/
#include "builtin.h"
+#include "alloc.h"
#include "quote.h"
#include "tree.h"
#include "parse-options.h"
@@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
+#include "alloc.h"
#include "config.h"
#include "pathspec.h"
#include "lockfile.h"
@@ -1,5 +1,5 @@
#include "builtin.h"
-#include "cache.h"
+#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "commit.h"
@@ -1,5 +1,5 @@
#include "builtin.h"
-#include "cache.h"
+#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "attr.h"
@@ -1,5 +1,5 @@
#include "builtin.h"
-#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "dir.h"
#include "parse-options.h"
@@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "commit.h"
#include "refs.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "parse-options.h"
@@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
+#include "alloc.h"
#include "advice.h"
#include "config.h"
#include "lockfile.h"
@@ -1,5 +1,6 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
+#include "alloc.h"
#include "repository.h"
#include "cache.h"
#include "config.h"
@@ -1,7 +1,8 @@
/*
* Copyright (c) 2011, Google Inc.
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "bulk-checkin.h"
#include "lockfile.h"
#include "repository.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "lockfile.h"
#include "tree.h"
#include "tree-walk.h"
@@ -656,81 +656,6 @@ void initialize_repository_version(int hash_algo, int reinit);
void sanitize_stdfds(void);
int daemonize(void);
-#define alloc_nr(x) (((x)+16)*3/2)
-
-/**
- * Dynamically growing an array using realloc() is error prone and boring.
- *
- * Define your array with:
- *
- * - a pointer (`item`) that points at the array, initialized to `NULL`
- * (although please name the variable based on its contents, not on its
- * type);
- *
- * - an integer variable (`alloc`) that keeps track of how big the current
- * allocation is, initialized to `0`;
- *
- * - another integer variable (`nr`) to keep track of how many elements the
- * array currently has, initialized to `0`.
- *
- * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,
- * alloc)`. This ensures that the array can hold at least `n` elements by
- * calling `realloc(3)` and adjusting `alloc` variable.
- *
- * ------------
- * sometype *item;
- * size_t nr;
- * size_t alloc
- *
- * for (i = 0; i < nr; i++)
- * if (we like item[i] already)
- * return;
- *
- * // we did not like any existing one, so add one
- * ALLOC_GROW(item, nr + 1, alloc);
- * item[nr++] = value you like;
- * ------------
- *
- * You are responsible for updating the `nr` variable.
- *
- * If you need to specify the number of elements to allocate explicitly
- * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
- *
- * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
- * added niceties.
- *
- * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
- */
-#define ALLOC_GROW(x, nr, alloc) \
- do { \
- if ((nr) > alloc) { \
- if (alloc_nr(alloc) < (nr)) \
- alloc = (nr); \
- else \
- alloc = alloc_nr(alloc); \
- REALLOC_ARRAY(x, alloc); \
- } \
- } while (0)
-
-/*
- * Similar to ALLOC_GROW but handles updating of the nr value and
- * zeroing the bytes of the newly-grown array elements.
- *
- * DO NOT USE any expression with side-effect for any of the
- * arguments.
- */
-#define ALLOC_GROW_BY(x, nr, increase, alloc) \
- do { \
- if (increase) { \
- size_t new_nr = nr + (increase); \
- if (new_nr < nr) \
- BUG("negative growth in ALLOC_GROW_BY"); \
- ALLOC_GROW(x, new_nr, alloc); \
- memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
- nr = new_nr; \
- } \
- } while (0)
-
/* Initialize and use the cache information */
struct lock_file;
void preload_index(struct index_state *index,
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "chunk-format.h"
#include "csum-file.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "commit.h"
#include "commit-graph.h"
#include "decorate.h"
@@ -7,6 +7,7 @@
#include "../strbuf.h"
#include "../run-command.h"
#include "../cache.h"
+#include "../alloc.h"
#include "win32/lazyload.h"
#include "../config.h"
#include "dir.h"
@@ -5,7 +5,8 @@
* Copyright (C) Johannes Schindelin, 2005
*
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "date.h"
#include "branch.h"
#include "config.h"
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "pkt-line.h"
#include "run-command.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "attr.h"
#include "object.h"
#include "blob.h"
@@ -2,6 +2,7 @@
* Copyright (C) 2005 Junio C Hamano
*/
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "tempfile.h"
#include "quote.h"
@@ -3,6 +3,7 @@
* Copyright (C) 2005 Junio C Hamano
*/
#include "cache.h"
+#include "alloc.h"
#include "diff.h"
#include "diffcore.h"
#include "object-store.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "dir.h"
#include "iterator.h"
#include "dir-iterator.h"
@@ -5,7 +5,8 @@
* Copyright (C) Linus Torvalds, 2005-2006
* Junio Hamano, 2005-2006
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "dir.h"
#include "object-store.h"
@@ -16,7 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "ewok.h"
#define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))
@@ -17,9 +17,9 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "git-compat-util.h"
+#include "alloc.h"
#include "ewok.h"
#include "ewok_rlw.h"
-#include "cache.h"
static inline size_t min_size(size_t a, size_t b)
{
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "lockfile.h"
@@ -1,4 +1,5 @@
#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "refs.h"
#include "object-store.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "object-store.h"
#include "repository.h"
#include "object.h"
@@ -1,5 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "config.h"
+#include "gettext.h"
#include "repository.h"
#include "fsmonitor-ipc.h"
#include "fsmonitor-settings.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "exec-cmd.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "repository.h"
#include "refs.h"
@@ -1,4 +1,5 @@
#include "git-compat-util.h"
+#include "alloc.h"
#include "line-range.h"
#include "cache.h"
#include "tag.h"
@@ -1,6 +1,8 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "commit.h"
#include "config.h"
+#include "gettext.h"
#include "revision.h"
#include "strvec.h"
#include "list-objects.h"
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "dir.h"
#include "tag.h"
#include "commit.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "csum-file.h"
#include "dir.h"
@@ -6,7 +6,8 @@
* This handles basic git object files - packing, unpacking,
* creation etc.
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "string-list.h"
#include "lockfile.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "oid-array.h"
#include "hash-lookup.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "object-store.h"
#include "commit.h"
#include "tag.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "commit.h"
#include "strbuf.h"
#include "tag.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "object.h"
#include "pack.h"
#include "pack-objects.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "list.h"
#include "pack.h"
#include "repository.h"
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "entry.h"
#include "parallel-checkout.h"
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "commit.h"
#include "utf8.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "prio-queue.h"
static inline int compare(struct prio_queue *queue, int i, int j)
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "quote.h"
#include "strvec.h"
@@ -4,6 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "diff.h"
#include "diffcore.h"
@@ -1,5 +1,5 @@
-#include "builtin.h"
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "parse-options.h"
#include "refs.h"
#include "wildmatch.h"
@@ -13,7 +13,6 @@
#include "ref-filter.h"
#include "revision.h"
#include "utf8.h"
-#include "git-compat-util.h"
#include "version.h"
#include "trailer.h"
#include "wt-status.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "commit.h"
#include "refs.h"
#include "diff.h"
@@ -2,7 +2,8 @@
* The backend-independent part of the reference module.
*/
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "hashmap.h"
#include "lockfile.h"
@@ -1,4 +1,5 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
+#include "../alloc.h"
#include "../config.h"
#include "../refs.h"
#include "refs-internal.h"
@@ -1,4 +1,5 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
+#include "../alloc.h"
#include "../refs.h"
#include "refs-internal.h"
#include "ref-cache.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "strvec.h"
#include "refs.h"
#include "refspec.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "remote.h"
#include "connect.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "remote.h"
#include "urlmatch.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "lockfile.h"
#include "string-list.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "object-store.h"
#include "tag.h"
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "lockfile.h"
#include "dir.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "dir.h"
#include "repository.h"
#include "refs.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "sigchain.h"
#define SIGCHAIN_MAX_SIGNALS 32
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "repository.h"
#include "sparse-index.h"
#include "tree.h"
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "split-index.h"
#include "ewah/ewok.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "refs.h"
#include "string-list.h"
#include "utf8.h"
@@ -1,5 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "string-list.h"
+#include "alloc.h"
void string_list_init_nodup(struct string_list *list)
{
@@ -1,5 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "strvec.h"
+#include "alloc.h"
#include "strbuf.h"
const char *empty_strvec[] = { NULL };
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "dir.h"
#include "repository.h"
#include "config.h"
@@ -1,5 +1,5 @@
-
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "submodule-config.h"
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "cache.h"
+#include "alloc.h"
#include "commit.h"
#include "commit-reach.h"
#include "config.h"
@@ -1,5 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "thread-utils.h"
+#include "trace.h"
#include "trace2/tr2_tls.h"
/*
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "alloc.h"
#include "config.h"
#include "string-list.h"
#include "run-command.h"
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "transport.h"
#include "hook.h"
@@ -10,6 +11,7 @@
#include "walker.h"
#include "bundle.h"
#include "dir.h"
+#include "gettext.h"
#include "refs.h"
#include "refspec.h"
#include "branch.h"
@@ -1,5 +1,6 @@
#include "cache.h"
#include "tree-walk.h"
+#include "alloc.h"
#include "dir.h"
#include "object-store.h"
#include "tree.h"
@@ -1,7 +1,9 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "config.h"
#include "userdiff.h"
#include "attr.h"
+#include "strbuf.h"
static struct userdiff_driver *drivers;
static int ndrivers;
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "alloc.h"
#include "repository.h"
#include "refs.h"
#include "strbuf.h"