From: Jonathan Tan Date: Mon, 15 May 2023 21:44:19 GMT Subject: Re: [PATCH v2 06/27] add: modify add_files_to_cache() to avoid globals Message-ID: <20230515214419.1445275-1-jonathantanmy@google.com> In-Reply-To: <13d6dd1095c6dcb8030b63b83635c760737b4163.1683875070.git.gitgitgadget@gmail.com> "Elijah Newren via GitGitGadget" writes: > From: Elijah Newren > > 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 I was checking that add_filer_to_cache() did not inadvertently use these global variables even after the refactoring, and it looks good. It's a pity that we can't remove the USE_THE_INDEX_VARIABLE #define even after this patch (other parts in builtin/add.c use it), but I couldn't see any more usages of the_index in that function. There is no more usage of include_sparse, indeed, as can be seen from the next patch (when the function is moved to another file that has no access to include_sparse declared in builtin/add.c).