The old scripted `git stash' used to create a second index to save modified and untracked files, and restore untracked files, without affecting the main index. This behaviour was carried on when it was rewritten in C, and here, most operations performed on the second index are done by forked commands (ie. `read-tree' instead of reset_tree(), etc.). The goal of this series is to modernise (a bit) builtin/stash.c. Originally, this series was also meant to fix a bug reported by Son Luong Ngoc [0], but as emphasized by Gábor [1], the issue is not limited to `git stash', so this series is not a good fix for this particular issue. This series is based on a08a83db2b (The sixth batch, 2020-06-29), and it applies cleanly on top of the current master (e8ab941b67 (The second batch -- mostly minor typofixes, 2020-07-30)). The tip of this series is tagged as "stash-remove-second-index-v3" at https://github.com/agrn/git. [0] https://lore.kernel.org/git/EED2CFF1-5BEF-429D-AB99-AD148A867614@xxxxxxxxx/ [1] https://lore.kernel.org/git/20200615152715.GD2898@xxxxxxxxxx/ Changes since v2: - Typofix in the fifth patch, noticed by Christian Couder. Alban Gruin (6): stash: mark `i_tree' in reset_tree() const stash: remove the second index in stash_working_tree() stash: remove the second index in stash_patch() stash: remove the second index in save_untracked_files() stash: remove the second index in restore_untracked() stash: remove `stash_index_path' builtin/stash.c | 156 +++++++++++++++--------------------------------- 1 file changed, 48 insertions(+), 108 deletions(-) Range-diff against v2: 1: 598f03e76e = 1: 598f03e76e stash: mark `i_tree' in reset_tree() const 2: 7265cfe65c = 2: 7265cfe65c stash: remove the second index in stash_working_tree() 3: b5587c0d56 = 3: b5587c0d56 stash: remove the second index in stash_patch() 4: 5fbcddf899 = 4: 5fbcddf899 stash: remove the second index in save_untracked_files() 5: 0338986339 ! 5: a12a923014 stash: remove the second index in restore_untracked() @@ -6,7 +6,7 @@ The call to `read-tree' is replaced by reset_tree() with the appropriate parameters (no update, no reset). The environment of `checkout-index' - is no longer modified, and the cache is discarded when it exists. + is no longer modified, and the cache is discarded when it exits. In do_apply_stash(), the changes are a bit more involved: to avoid conflicts with the merged index, restore_untracked() is moved after 6: 4f151f4600 = 6: dd25e71f35 stash: remove `stash_index_path' -- 2.20.1