Merge branch 'en/header-cleanup'

Code clean-up to clarify the rule that "git-compat-util.h" must be
the first to be included.

* en/header-cleanup:
  diff.h: remove unnecessary include of object.h
  Remove unnecessary includes of builtin.h
  treewide: replace cache.h with more direct headers, where possible
  replace-object.h: move read_replace_refs declaration from cache.h to here
  object-store.h: move struct object_info from cache.h
  dir.h: refactor to no longer need to include cache.h
  object.h: stop depending on cache.h; make cache.h depend on object.h
  ident.h: move ident-related declarations out of cache.h
  pretty.h: move has_non_ascii() declaration from commit.h
  cache.h: remove dependence on hex.h; make other files include it explicitly
  hex.h: move some hex-related declarations from cache.h
  hash.h: move some oid-related declarations from cache.h
  alloc.h: move ALLOC_GROW() functions from cache.h
  treewide: remove unnecessary cache.h includes in source files
  treewide: remove unnecessary cache.h includes
  treewide: remove unnecessary git-compat-util.h includes in headers
  treewide: ensure one of the appropriate headers is sourced first
This commit is contained in:
Junio C Hamano 2023-03-17 14:03:08 -07:00
commit 88cc8ed8bc
322 changed files with 858 additions and 529 deletions

View File

@ -442,8 +442,12 @@ For C programs:
detail.
- The first #include in C files, except in platform specific compat/
implementations, must be either "git-compat-util.h", "cache.h" or
"builtin.h". You do not have to include more than one of these.
implementations and sha1dc/, must be either "git-compat-util.h" or
one of the approved headers that includes it first for you. (The
approved headers currently include "cache.h", "builtin.h",
"t/helper/test-tool.h", "xdiff/xinclude.h", or
"reftable/system.h"). You do not have to include more than one of
these.
- A C file must directly include the header files that declare the
functions and the types it uses, except for the functions and types

View File

@ -3,6 +3,7 @@
#include "color.h"
#include "config.h"
#include "diffcore.h"
#include "hex.h"
#include "revision.h"
#include "refs.h"
#include "string-list.h"

View File

@ -1,5 +1,6 @@
#include "cache.h"
#include "add-interactive.h"
#include "alloc.h"
#include "strbuf.h"
#include "run-command.h"
#include "strvec.h"

View File

@ -1,6 +1,8 @@
#include "cache.h"
#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
#include "color.h"
#include "gettext.h"
#include "help.h"
#include "string-list.h"

View File

@ -1,8 +1,6 @@
#ifndef ADVICE_H
#define ADVICE_H
#include "git-compat-util.h"
struct string_list;
/*

View File

@ -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 {

View File

@ -8,7 +8,7 @@
* up with maximal alignment because it doesn't know what the object alignment
* for the new allocation is.
*/
#include "cache.h"
#include "git-compat-util.h"
#include "object.h"
#include "blob.h"
#include "tree.h"

75
alloc.h
View File

@ -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

View File

@ -8,12 +8,14 @@
*/
#include "cache.h"
#include "alloc.h"
#include "config.h"
#include "object-store.h"
#include "blob.h"
#include "delta.h"
#include "diff.h"
#include "dir.h"
#include "hex.h"
#include "xdiff-interface.h"
#include "ll-merge.h"
#include "lockfile.h"

View File

@ -1,8 +1,10 @@
/*
* Copyright (c) 2005, 2006 Rene Scharfe
*/
#include "cache.h"
#include "git-compat-util.h"
#include "alloc.h"
#include "config.h"
#include "hex.h"
#include "tar.h"
#include "archive.h"
#include "object-store.h"

View File

@ -4,6 +4,7 @@
#include "cache.h"
#include "config.h"
#include "archive.h"
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
#include "object-store.h"

View File

@ -1,5 +1,7 @@
#include "cache.h"
#include "git-compat-util.h"
#include "alloc.h"
#include "config.h"
#include "hex.h"
#include "refs.h"
#include "object-store.h"
#include "commit.h"

1
attr.c
View File

@ -7,6 +7,7 @@
*/
#include "cache.h"
#include "alloc.h"
#include "config.h"
#include "exec-cmd.h"
#include "attr.h"

View File

@ -2,6 +2,7 @@
#include "config.h"
#include "commit.h"
#include "diff.h"
#include "hex.h"
#include "revision.h"
#include "refs.h"
#include "list-objects.h"

View File

@ -5,6 +5,7 @@
#include "mergesort.h"
#include "diff.h"
#include "diffcore.h"
#include "hex.h"
#include "tag.h"
#include "blame.h"
#include "alloc.h"

View File

@ -1,7 +1,6 @@
#ifndef BLAME_H
#define BLAME_H
#include "cache.h"
#include "commit.h"
#include "xdiff-interface.h"
#include "revision.h"

2
blob.c
View File

@ -1,4 +1,4 @@
#include "cache.h"
#include "git-compat-util.h"
#include "blob.h"
#include "repository.h"
#include "alloc.h"

View File

@ -2,6 +2,7 @@
#include "cache.h"
#include "config.h"
#include "branch.h"
#include "hex.h"
#include "refs.h"
#include "refspec.h"
#include "remote.h"

View File

@ -8,6 +8,7 @@
#include "config.h"
#include "builtin.h"
#include "exec-cmd.h"
#include "hex.h"
#include "parse-options.h"
#include "dir.h"
#include "run-command.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "hex.h"
#include "parse-options.h"
#include "bisect.h"
#include "refs.h"

View File

@ -5,10 +5,12 @@
* 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"
#include "hex.h"
#include "repository.h"
#include "commit.h"
#include "diff.h"

View File

@ -5,9 +5,12 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "diff.h"
#include "hex.h"
#include "ident.h"
#include "parse-options.h"
#include "userdiff.h"
#include "streaming.h"
@ -15,6 +18,7 @@
#include "oid-array.h"
#include "packfile.h"
#include "object-store.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "config.h"
#include "ident.h"
#include "mailmap.h"
#include "parse-options.h"
#include "string-list.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "alloc.h"
#include "config.h"
#include "entry.h"
#include "parallel-checkout.h"

View File

@ -9,6 +9,7 @@
#include "config.h"
#include "diff.h"
#include "dir.h"
#include "hex.h"
#include "hook.h"
#include "ll-merge.h"
#include "lockfile.h"

View File

@ -11,6 +11,7 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "config.h"
#include "hex.h"
#include "lockfile.h"
#include "parse-options.h"
#include "fetch-pack.h"

View File

@ -1,12 +1,14 @@
#include "builtin.h"
#include "config.h"
#include "dir.h"
#include "hex.h"
#include "lockfile.h"
#include "parse-options.h"
#include "repository.h"
#include "commit-graph.h"
#include "object-store.h"
#include "progress.h"
#include "replace-object.h"
#include "tag.h"
#define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \

View File

@ -5,6 +5,7 @@
*/
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "object-store.h"
#include "repository.h"
#include "commit.h"

View File

@ -1,7 +1,8 @@
#include "builtin.h"
#include "cache.h"
#include "alloc.h"
#include "config.h"
#include "color.h"
#include "ident.h"
#include "parse-options.h"
#include "urlmatch.h"
#include "quote.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "alloc.h"
#include "parse-options.h"
#ifndef NO_UNIX_SOCKETS

View File

@ -1,6 +1,7 @@
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "lockfile.h"
#include "commit.h"
#include "tag.h"

View File

@ -3,6 +3,7 @@
#include "config.h"
#include "diff.h"
#include "commit.h"
#include "hex.h"
#include "log-tree.h"
#include "builtin.h"
#include "submodule.h"

View File

@ -17,6 +17,7 @@
#include "builtin.h"
#include "run-command.h"
#include "exec-cmd.h"
#include "hex.h"
#include "parse-options.h"
#include "strvec.h"
#include "strbuf.h"

View File

@ -6,6 +6,7 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "refs.h"
#include "refspec.h"
#include "object-store.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "hex.h"
#include "repository.h"
#include "config.h"
#include "lockfile.h"

View File

@ -1,4 +1,6 @@
#include "builtin.h"
#include "alloc.h"
#include "hex.h"
#include "pkt-line.h"
#include "fetch-pack.h"
#include "remote.h"

View File

@ -3,6 +3,7 @@
*/
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "repository.h"
#include "refs.h"
#include "refspec.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "hex.h"
#include "repository.h"
#include "config.h"
#include "commit.h"
@ -18,6 +19,7 @@
#include "decorate.h"
#include "packfile.h"
#include "object-store.h"
#include "replace-object.h"
#include "resolve-undo.h"
#include "run-command.h"
#include "worktree.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "alloc.h"
#include "config.h"
#include "parse-options.h"
#include "fsmonitor.h"

View File

@ -11,6 +11,7 @@
*/
#include "builtin.h"
#include "hex.h"
#include "repository.h"
#include "config.h"
#include "tempfile.h"

View File

@ -4,6 +4,8 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "cache.h"
#include "alloc.h"
#include "hex.h"
#include "repository.h"
#include "config.h"
#include "blob.h"

View File

@ -6,6 +6,7 @@
*/
#include "builtin.h"
#include "config.h"
#include "hex.h"
#include "object-store.h"
#include "blob.h"
#include "quote.h"

View File

@ -1,6 +1,8 @@
#include "builtin.h"
#include "alloc.h"
#include "config.h"
#include "delta.h"
#include "hex.h"
#include "pack.h"
#include "csum-file.h"
#include "blob.h"
@ -14,6 +16,7 @@
#include "thread-utils.h"
#include "packfile.h"
#include "object-store.h"
#include "replace-object.h"
#include "promisor-remote.h"
static const char index_pack_usage[] =

View File

@ -4,8 +4,10 @@
* (C) Copyright 2006 Linus Torvalds
* 2006 Junio Hamano
*/
#include "cache.h"
#include "git-compat-util.h"
#include "alloc.h"
#include "config.h"
#include "hex.h"
#include "refs.h"
#include "object-store.h"
#include "color.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "hex.h"
#include "transport.h"
#include "ref-filter.h"
#include "remote.h"

View File

@ -5,6 +5,7 @@
*/
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "object-store.h"
#include "blob.h"
#include "tree.h"

View File

@ -2,6 +2,7 @@
#include "cache.h"
#include "config.h"
#include "commit.h"
#include "hex.h"
#include "refs.h"
#include "diff.h"
#include "revision.h"

View File

@ -1,5 +1,6 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "hex.h"
#include "run-command.h"
static const char *pgm;

View File

@ -3,6 +3,7 @@
#include "tree-walk.h"
#include "xdiff-interface.h"
#include "help.h"
#include "hex.h"
#include "commit.h"
#include "commit-reach.h"
#include "merge-ort.h"

View File

@ -8,7 +8,9 @@
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "alloc.h"
#include "config.h"
#include "hex.h"
#include "parse-options.h"
#include "builtin.h"
#include "lockfile.h"

View File

@ -1,4 +1,5 @@
#include "builtin.h"
#include "hex.h"
#include "parse-options.h"
#include "tag.h"
#include "replace-object.h"

View File

@ -4,6 +4,8 @@
* Copyright (c) Junio C Hamano, 2006, 2009
*/
#include "builtin.h"
#include "alloc.h"
#include "hex.h"
#include "quote.h"
#include "tree.h"
#include "parse-options.h"

View File

@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "alloc.h"
#include "config.h"
#include "pathspec.h"
#include "lockfile.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "alloc.h"
#include "hex.h"
#include "repository.h"
#include "config.h"
#include "commit.h"

View File

@ -10,6 +10,7 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "hex.h"
#include "notes.h"
#include "object-store.h"
#include "repository.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "alloc.h"
#include "hex.h"
#include "repository.h"
#include "config.h"
#include "attr.h"
@ -31,6 +32,7 @@
#include "list.h"
#include "packfile.h"
#include "object-store.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
#include "trace2.h"

View File

@ -7,6 +7,7 @@
*/
#include "builtin.h"
#include "hex.h"
#include "repository.h"
#include "packfile.h"
#include "object-store.h"

View File

@ -2,6 +2,7 @@
#include "builtin.h"
#include "config.h"
#include "diff.h"
#include "hex.h"
#include "parse-options.h"
static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)

View File

@ -1,12 +1,14 @@
#include "cache.h"
#include "commit.h"
#include "diff.h"
#include "hex.h"
#include "revision.h"
#include "builtin.h"
#include "reachable.h"
#include "parse-options.h"
#include "progress.h"
#include "prune-packed.h"
#include "replace-object.h"
#include "object-store.h"
#include "shallow.h"

View File

@ -9,6 +9,7 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "hex.h"
#include "parse-options.h"
#include "exec-cmd.h"
#include "run-command.h"

View File

@ -7,6 +7,7 @@
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "lockfile.h"
#include "object.h"
#include "tree.h"

View File

@ -6,6 +6,7 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "hex.h"
#include "run-command.h"
#include "exec-cmd.h"
#include "strvec.h"

View File

@ -1,6 +1,7 @@
#include "builtin.h"
#include "repository.h"
#include "config.h"
#include "hex.h"
#include "lockfile.h"
#include "pack.h"
#include "refs.h"

View File

@ -1,7 +1,8 @@
#include "builtin.h"
#include "cache.h"
#include "alloc.h"
#include "config.h"
#include "dir.h"
#include "hex.h"
#include "parse-options.h"
#include "run-command.h"
#include "sigchain.h"

View File

@ -11,10 +11,12 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "hex.h"
#include "refs.h"
#include "parse-options.h"
#include "run-command.h"
#include "object-store.h"
#include "replace-object.h"
#include "repository.h"
#include "tag.h"

View File

@ -10,6 +10,7 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "config.h"
#include "hex.h"
#include "lockfile.h"
#include "tag.h"
#include "object.h"

View File

@ -2,6 +2,7 @@
#include "config.h"
#include "commit.h"
#include "diff.h"
#include "hex.h"
#include "revision.h"
#include "list-objects.h"
#include "list-objects-filter.h"

View File

@ -5,8 +5,10 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "cache.h"
#include "alloc.h"
#include "config.h"
#include "commit.h"
#include "hex.h"
#include "refs.h"
#include "quote.h"
#include "builtin.h"

View File

@ -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"

View File

@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "alloc.h"
#include "advice.h"
#include "config.h"
#include "lockfile.h"

View File

@ -1,6 +1,7 @@
#include "builtin.h"
#include "config.h"
#include "commit.h"
#include "hex.h"
#include "refs.h"
#include "pkt-line.h"
#include "sideband.h"

View File

@ -1,5 +1,6 @@
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "pretty.h"
#include "refs.h"
#include "builtin.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
#include "hex.h"
#include "pack.h"
#include "parse-options.h"

View File

@ -1,6 +1,7 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "refs.h"
#include "object-store.h"
#include "object.h"

View File

@ -1,6 +1,7 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "config.h"
#include "hex.h"
#include "parse-options.h"
#include "refs.h"
#include "lockfile.h"

View File

@ -1,5 +1,7 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "alloc.h"
#include "hex.h"
#include "repository.h"
#include "cache.h"
#include "config.h"

View File

@ -9,6 +9,7 @@
#include "cache.h"
#include "config.h"
#include "builtin.h"
#include "hex.h"
#include "refs.h"
#include "object-store.h"
#include "tag.h"

View File

@ -1,5 +1,6 @@
#include "builtin.h"
#include "config.h"
#include "hex.h"
#include "object-store.h"
static char *create_temp_file(struct object_id *oid)

View File

@ -2,12 +2,14 @@
#include "cache.h"
#include "bulk-checkin.h"
#include "config.h"
#include "hex.h"
#include "object-store.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
#include "blob.h"
#include "commit.h"
#include "replace-object.h"
#include "tag.h"
#include "tree.h"
#include "tree-walk.h"

View File

@ -7,6 +7,7 @@
#include "cache.h"
#include "bulk-checkin.h"
#include "config.h"
#include "hex.h"
#include "lockfile.h"
#include "quote.h"
#include "cache-tree.h"

View File

@ -4,6 +4,7 @@
#include "pkt-line.h"
#include "parse-options.h"
#include "protocol.h"
#include "replace-object.h"
#include "upload-pack.h"
#include "serve.h"

View File

@ -5,6 +5,7 @@
*/
#include "builtin.h"
#include "config.h"
#include "ident.h"
#include "refs.h"
static const char var_usage[] = "git var (-l | <variable>)";

View File

@ -3,6 +3,7 @@
#include "config.h"
#include "builtin.h"
#include "dir.h"
#include "hex.h"
#include "parse-options.h"
#include "strvec.h"
#include "branch.h"

View File

@ -7,6 +7,7 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "hex.h"
#include "tree.h"
#include "cache-tree.h"
#include "parse-options.h"

View File

@ -1,8 +1,10 @@
/*
* Copyright (c) 2011, Google Inc.
*/
#include "cache.h"
#include "git-compat-util.h"
#include "alloc.h"
#include "bulk-checkin.h"
#include "hex.h"
#include "lockfile.h"
#include "repository.h"
#include "csum-file.h"

View File

@ -1,6 +1,7 @@
#include "cache.h"
#include "lockfile.h"
#include "bundle.h"
#include "hex.h"
#include "object-store.h"
#include "repository.h"
#include "object.h"

View File

@ -1,4 +1,6 @@
#include "cache.h"
#include "git-compat-util.h"
#include "alloc.h"
#include "hex.h"
#include "lockfile.h"
#include "tree.h"
#include "tree-walk.h"

View File

@ -1,7 +1,6 @@
#ifndef CACHE_TREE_H
#define CACHE_TREE_H
#include "cache.h"
#include "tree.h"
#include "tree-walk.h"

305
cache.h
View File