diff options
| author | Elijah Newren <newren@gmail.com> | 2023-05-16 06:33:46 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-06-21 13:39:53 -0700 |
| commit | 50c37ee839f0c6842816dec0764d0592b5d048b2 (patch) | |
| tree | f007ed761416e4a0bec338c72f3e45497feccb19 /cache.h | |
| parent | read-cache: move shared commit and ls-files code (diff) | |
| download | git-50c37ee839f0c6842816dec0764d0592b5d048b2.tar.gz git-50c37ee839f0c6842816dec0764d0592b5d048b2.zip | |
add: modify add_files_to_cache() to avoid globals
The function add_files_to_cache() is used by all three of builtin/{add,
checkout, commit}.c. That suggests this is common library code, and
should be moved somewhere else, like read-cache.c. However, the
function and its helpers made use of two global variables that made
straight code movement difficult:
* the_index
* include_sparse
The latter was perhaps more problematic since it was only accessible in
builtin/add.c but was still affecting builtin/checkout.c and
builtin/commit.c without this fact being very clear from the code. I'm
not sure if the other two callers would want to add a `--sparse` flag
similar to add.c to get non-default behavior, but exposing this
dependence will help if we ever decide we do want to add such a flag.
Modify add_files_to_cache() and its helpers to accept the necessary
arguments instead of relying on globals.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache.h')
| -rw-r--r-- | cache.h | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -554,7 +554,9 @@ int cmp_cache_name_compare(const void *a_, const void *b_); * return 0 if success, 1 - if addition of a file failed and * ADD_FILES_IGNORE_ERRORS was specified in flags */ -int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags); +int add_files_to_cache(struct repository *repo, const char *prefix, + const struct pathspec *pathspec, int include_sparse, + int flags); /* diff.c */ extern int diff_auto_refresh_index; |
