Skip to content

Commit

Permalink
git: initialize subprocess context without using git2::Repository
Browse files Browse the repository at this point in the history
yuja committed Feb 1, 2025
1 parent d4023d8 commit bba6f15
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
@@ -1644,9 +1644,11 @@ enum GitFetchImpl<'a> {

impl<'a> GitFetchImpl<'a> {
fn new(store: &Store, git_settings: &'a GitSettings) -> Result<Self, GitFetchPrepareError> {
let git_repo = get_git_backend(store)?.open_git_repo()?;
let git_backend = get_git_backend(store)?;
let git_repo = git_backend.open_git_repo()?;
if git_settings.subprocess {
let git_ctx = GitSubprocessContext::from_git2(&git_repo, &git_settings.executable_path);
let git_ctx =
GitSubprocessContext::from_git_backend(git_backend, &git_settings.executable_path);
Ok(GitFetchImpl::Subprocess { git_repo, git_ctx })
} else {
Ok(GitFetchImpl::Git2 { git_repo })
@@ -1894,9 +1896,11 @@ pub fn push_updates(
// TODO(ilyagr): `push_refs`, or parts of it, should probably be inlined. This
// requires adjusting some tests.

let git_repo = get_git_backend(repo.store())?.open_git_repo()?;
let git_backend = get_git_backend(repo.store())?;
let git_repo = git_backend.open_git_repo()?;
if git_settings.subprocess {
let git_ctx = GitSubprocessContext::from_git2(&git_repo, &git_settings.executable_path);
let git_ctx =
GitSubprocessContext::from_git_backend(git_backend, &git_settings.executable_path);
subprocess_push_refs(
&git_repo,
&git_ctx,
8 changes: 6 additions & 2 deletions lib/src/git_subprocess.rs
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ use crate::git::Progress;
use crate::git::RefSpec;
use crate::git::RefToPush;
use crate::git::RemoteCallbacks;
use crate::git_backend::GitBackend;

/// Error originating by a Git subprocess
#[derive(Error, Debug)]
@@ -69,8 +70,11 @@ impl<'a> GitSubprocessContext<'a> {
}
}

pub(crate) fn from_git2(git_repo: &git2::Repository, git_executable_path: &'a Path) -> Self {
Self::new(git_repo.path(), git_executable_path)
pub(crate) fn from_git_backend(
git_backend: &GitBackend,
git_executable_path: &'a Path,
) -> Self {
Self::new(git_backend.git_repo_path(), git_executable_path)
}

/// Create the Git command

0 comments on commit bba6f15

Please sign in to comment.