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>
This commit is contained in:

committed by
Junio C Hamano

parent
4956a5ec86
commit
c862a92083
@ -447,7 +447,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
|
||||
if (all || (also && pathspec.nr)) {
|
||||
repo_hold_locked_index(the_repository, &index_lock,
|
||||
LOCK_DIE_ON_ERROR);
|
||||
add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
|
||||
add_files_to_cache(the_repository, also ? prefix : NULL,
|
||||
&pathspec, 0, 0);
|
||||
refresh_cache_or_die(refresh_flags);
|
||||
cache_tree_update(&the_index, WRITE_TREE_SILENT);
|
||||
if (write_locked_index(&the_index, &index_lock, 0))
|
||||
|
Reference in New Issue
Block a user