mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-28 15:26:25 +00:00
git_backend: configure committer (and author) of gix::Repository
Otherwise, ref updates would fail if we port git::export_refs() to gitoxide. This change isn't strictly needed for the backend itself, but we'll reuse the gix::Repository instance created by the backend when importing and exporting Git refs.
This commit is contained in:
parent
ea32c0cb9e
commit
b42a69db6d
1 changed files with 31 additions and 10 deletions
|
@ -127,14 +127,15 @@ impl GitBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_internal(
|
pub fn init_internal(
|
||||||
_settings: &UserSettings,
|
settings: &UserSettings,
|
||||||
store_path: &Path,
|
store_path: &Path,
|
||||||
) -> Result<Self, Box<GitBackendInitError>> {
|
) -> Result<Self, Box<GitBackendInitError>> {
|
||||||
let git_repo_path = Path::new("git");
|
let git_repo_path = Path::new("git");
|
||||||
let git_repo = gix::ThreadSafeRepository::init(
|
let git_repo = gix::ThreadSafeRepository::init_opts(
|
||||||
store_path.join(git_repo_path),
|
store_path.join(git_repo_path),
|
||||||
gix::create::Kind::Bare,
|
gix::create::Kind::Bare,
|
||||||
gix::create::Options::default(),
|
gix::create::Options::default(),
|
||||||
|
gix_open_opts_from_settings(settings),
|
||||||
)
|
)
|
||||||
.map_err(GitBackendInitError::InitRepository)?;
|
.map_err(GitBackendInitError::InitRepository)?;
|
||||||
Self::init_with_repo(store_path, git_repo_path, git_repo)
|
Self::init_with_repo(store_path, git_repo_path, git_repo)
|
||||||
|
@ -143,7 +144,7 @@ impl GitBackend {
|
||||||
/// Initializes backend by creating a new Git repo at the specified
|
/// Initializes backend by creating a new Git repo at the specified
|
||||||
/// workspace path. The workspace directory must exist.
|
/// workspace path. The workspace directory must exist.
|
||||||
pub fn init_colocated(
|
pub fn init_colocated(
|
||||||
_settings: &UserSettings,
|
settings: &UserSettings,
|
||||||
store_path: &Path,
|
store_path: &Path,
|
||||||
workspace_root: &Path,
|
workspace_root: &Path,
|
||||||
) -> Result<Self, Box<GitBackendInitError>> {
|
) -> Result<Self, Box<GitBackendInitError>> {
|
||||||
|
@ -153,10 +154,11 @@ impl GitBackend {
|
||||||
.context(&path)
|
.context(&path)
|
||||||
.map_err(GitBackendInitError::Path)?
|
.map_err(GitBackendInitError::Path)?
|
||||||
};
|
};
|
||||||
let git_repo = gix::ThreadSafeRepository::init(
|
let git_repo = gix::ThreadSafeRepository::init_opts(
|
||||||
canonical_workspace_root,
|
canonical_workspace_root,
|
||||||
gix::create::Kind::WithWorktree,
|
gix::create::Kind::WithWorktree,
|
||||||
gix::create::Options::default(),
|
gix::create::Options::default(),
|
||||||
|
gix_open_opts_from_settings(settings),
|
||||||
)
|
)
|
||||||
.map_err(GitBackendInitError::InitRepository)?;
|
.map_err(GitBackendInitError::InitRepository)?;
|
||||||
let git_repo_path = workspace_root.join(".git");
|
let git_repo_path = workspace_root.join(".git");
|
||||||
|
@ -165,7 +167,7 @@ impl GitBackend {
|
||||||
|
|
||||||
/// Initializes backend with an existing Git repo at the specified path.
|
/// Initializes backend with an existing Git repo at the specified path.
|
||||||
pub fn init_external(
|
pub fn init_external(
|
||||||
_settings: &UserSettings,
|
settings: &UserSettings,
|
||||||
store_path: &Path,
|
store_path: &Path,
|
||||||
git_repo_path: &Path,
|
git_repo_path: &Path,
|
||||||
) -> Result<Self, Box<GitBackendInitError>> {
|
) -> Result<Self, Box<GitBackendInitError>> {
|
||||||
|
@ -175,8 +177,11 @@ impl GitBackend {
|
||||||
.context(&path)
|
.context(&path)
|
||||||
.map_err(GitBackendInitError::Path)?
|
.map_err(GitBackendInitError::Path)?
|
||||||
};
|
};
|
||||||
let git_repo = gix::ThreadSafeRepository::open(canonical_git_repo_path)
|
let git_repo = gix::ThreadSafeRepository::open_opts(
|
||||||
.map_err(GitBackendInitError::OpenRepository)?;
|
canonical_git_repo_path,
|
||||||
|
gix_open_opts_from_settings(settings),
|
||||||
|
)
|
||||||
|
.map_err(GitBackendInitError::OpenRepository)?;
|
||||||
Self::init_with_repo(store_path, git_repo_path, git_repo)
|
Self::init_with_repo(store_path, git_repo_path, git_repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +219,7 @@ impl GitBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(
|
pub fn load(
|
||||||
_settings: &UserSettings,
|
settings: &UserSettings,
|
||||||
store_path: &Path,
|
store_path: &Path,
|
||||||
) -> Result<Self, Box<GitBackendLoadError>> {
|
) -> Result<Self, Box<GitBackendLoadError>> {
|
||||||
let git_repo_path = {
|
let git_repo_path = {
|
||||||
|
@ -228,8 +233,11 @@ impl GitBackend {
|
||||||
.context(&git_repo_path)
|
.context(&git_repo_path)
|
||||||
.map_err(GitBackendLoadError::Path)?
|
.map_err(GitBackendLoadError::Path)?
|
||||||
};
|
};
|
||||||
let repo = gix::ThreadSafeRepository::open(git_repo_path)
|
let repo = gix::ThreadSafeRepository::open_opts(
|
||||||
.map_err(GitBackendLoadError::OpenRepository)?;
|
git_repo_path,
|
||||||
|
gix_open_opts_from_settings(settings),
|
||||||
|
)
|
||||||
|
.map_err(GitBackendLoadError::OpenRepository)?;
|
||||||
let extra_metadata_store = TableStore::load(store_path.join("extra"), HASH_LENGTH);
|
let extra_metadata_store = TableStore::load(store_path.join("extra"), HASH_LENGTH);
|
||||||
Ok(GitBackend::new(repo, extra_metadata_store))
|
Ok(GitBackend::new(repo, extra_metadata_store))
|
||||||
}
|
}
|
||||||
|
@ -348,6 +356,19 @@ impl GitBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gix_open_opts_from_settings(settings: &UserSettings) -> gix::open::Options {
|
||||||
|
let user_name = settings.user_name();
|
||||||
|
let user_email = settings.user_email();
|
||||||
|
gix::open::Options::default().config_overrides([
|
||||||
|
// Committer has to be configured to record reflog. Author isn't
|
||||||
|
// needed, but let's copy the same values.
|
||||||
|
format!("author.name={user_name}"),
|
||||||
|
format!("author.email={user_email}"),
|
||||||
|
format!("committer.name={user_name}"),
|
||||||
|
format!("committer.email={user_email}"),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
fn commit_from_git_without_root_parent(
|
fn commit_from_git_without_root_parent(
|
||||||
id: &CommitId,
|
id: &CommitId,
|
||||||
commit: &gix::objs::CommitRef,
|
commit: &gix::objs::CommitRef,
|
||||||
|
|
Loading…
Reference in a new issue