Skip to content

Commit f7495a2

Browse files
committed
Eliminate all remaining uses of git2::Index
This relates to sparse checkout support (#195). git2 does not comprehend sparse checkouts and thus using any index <=> worktree operations is likely to break sparse checkouts. Most important index operations have already been converted to using git commands, this gets all the remaining instances. N.B. in run_pre_commit_hook(), GIT_INDEX_FILE is no longer being supplied explicitly. In all of StGit's use cases either using the default index or inheriting GIT_INDEX_FILE from the calling environment should be okay.
1 parent f9d9de0 commit f7495a2

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

src/cmd/clean.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
patchname::PatchName,
1212
repo::RepositoryExtended,
1313
stack::{Stack, StackStateAccess},
14+
stupid::Stupid,
1415
};
1516

1617
use super::StGitCommand;
@@ -72,7 +73,7 @@ fn run(matches: &ArgMatches) -> Result<()> {
7273
// Do not clean the topmost patch if there are outstanding
7374
// conflicts. The patch is only empty because the conflicts caused
7475
// its contents to be dumped into the index and worktree.
75-
if !repo.index()?.has_conflicts() {
76+
if repo.stupid().statuses(None)?.check_conflicts().is_ok() {
7677
to_delete.push(pn.clone());
7778
}
7879
} else {

src/cmd/spill.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ fn run(matches: &ArgMatches) -> Result<()> {
8282
.clone();
8383
let patch_commit = stack.get_patch_commit(&patchname);
8484
let parent = patch_commit.parent(0)?;
85-
let mut index = repo.index()?;
8685

8786
let tree_id = if let Some(pathspecs) = matches.get_many::<PathBuf>("pathspecs") {
8887
stupid.with_temp_index(|stupid_temp| {
@@ -120,9 +119,7 @@ fn run(matches: &ArgMatches) -> Result<()> {
120119
.execute(&reflog_msg)?;
121120

122121
if matches.contains_id("reset") {
123-
let tree = repo.find_tree(tree_id)?;
124-
index.read_tree(&tree)?;
125-
index.write()?;
122+
stupid.read_tree(tree_id)?;
126123
}
127124

128125
Ok(())

src/cmd/sync.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,8 @@ fn series_merge_patch(
303303
}
304304
}
305305

306-
let mut index = trans.repo().index()?;
307-
index.read(true)?;
308-
index.update_all(changed_paths, None)?;
309-
index.write()?;
310-
let tree_id = index.write_tree()?;
306+
stupid.update_index(Some(changed_paths))?;
307+
let tree_id = stupid.write_tree()?;
311308

312309
stupid.read_tree_checkout(tree_id, trans.stack().branch_head.tree_id())?;
313310
if !stupid.merge_recursive(

src/hook.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,13 @@ pub(crate) fn run_pre_commit_hook(repo: &git2::Repository, use_editor: bool) ->
5454
let workdir = repo
5555
.workdir()
5656
.expect("should not get this far with a bare repo");
57-
hook_command.current_dir(workdir);
5857
if !use_editor {
5958
hook_command.env("GIT_EDITOR", ":");
6059
}
61-
let index = repo.index().expect("gotta have an index");
62-
let index_path = index.path().expect("index must be a file");
63-
hook_command.env("GIT_INDEX_FILE", index_path);
64-
hook_command.stdin(std::process::Stdio::null());
6560

6661
let status = hook_command
62+
.current_dir(workdir)
63+
.stdin(std::process::Stdio::null())
6764
.status()
6865
.with_context(|| format!("`{hook_name}` hook"))?;
6966

0 commit comments

Comments
 (0)