Skip to content

Commit 2163e5d

Browse files
peffgitster
authored andcommitted
cache.h: drop LOCAL_REPO_ENV_SIZE
We keep a static array of variables that should be cleared when invoking a sub-process on another repo. We statically size the array with the LOCAL_REPO_ENV_SIZE macro so that any readers do not have to count it themselves. As it turns out, no readers actually use the macro, and it creates a maintenance headache, as modifications to the array need to happen in two places (one to add the new element, and another to bump the size). Since it's NULL-terminated, we can just drop the size macro entirely. While we're at it, we'll clean up some comments around it, and add a new mention of it at the top of the list of environment variable macros. Even though local_repo_env is right below that list, it's easy to miss, and additions to that list should consider local_repo_env. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d4ef17 commit 2163e5d

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

cache.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ static inline enum object_type object_type(unsigned int mode)
341341
OBJ_BLOB;
342342
}
343343

344+
/* Double-check local_repo_env below if you add to this list. */
344345
#define GIT_DIR_ENVIRONMENT "GIT_DIR"
345346
#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
346347
#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
@@ -364,13 +365,12 @@ static inline enum object_type object_type(unsigned int mode)
364365
#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE"
365366

366367
/*
367-
* Repository-local GIT_* environment variables
368-
* The array is NULL-terminated to simplify its usage in contexts such
369-
* environment creation or simple walk of the list.
370-
* The number of non-NULL entries is available as a macro.
368+
* Repository-local GIT_* environment variables; these will be cleared
369+
* when git spawns a sub-process that runs inside another repository.
370+
* The array is NULL-terminated, which makes it easy to pass in the "env"
371+
* parameter of a run-command invocation, or to do a simple walk.
371372
*/
372-
#define LOCAL_REPO_ENV_SIZE 9
373-
extern const char *const local_repo_env[LOCAL_REPO_ENV_SIZE + 1];
373+
extern const char * const local_repo_env[];
374374

375375
extern int is_bare_repository_cfg;
376376
extern int is_bare_repository(void);

environment.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ static const char *git_dir;
7676
static char *git_object_dir, *git_index_file, *git_graft_file;
7777

7878
/*
79-
* Repository-local GIT_* environment variables
80-
* Remember to update local_repo_env_size in cache.h when
81-
* the size of the list changes
79+
* Repository-local GIT_* environment variables; see cache.h for details.
8280
*/
83-
const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = {
81+
const char * const local_repo_env[] = {
8482
ALTERNATE_DB_ENVIRONMENT,
8583
CONFIG_ENVIRONMENT,
8684
CONFIG_DATA_ENVIRONMENT,

0 commit comments

Comments
 (0)