mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 02:53:12 +00:00
git_backend: extract helper to read extra metadata table and maintain cache
This commit is contained in:
parent
83753e59f6
commit
14243a85a0
1 changed files with 20 additions and 13 deletions
|
@ -102,6 +102,24 @@ impl GitBackend {
|
||||||
let path = self.repo.lock().unwrap().path().to_owned();
|
let path = self.repo.lock().unwrap().path().to_owned();
|
||||||
git2::Repository::open(path).unwrap()
|
git2::Repository::open(path).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cached_extra_metadata_table(&self) -> BackendResult<Arc<ReadonlyTable>> {
|
||||||
|
let mut locked_head = self.cached_extra_metadata.lock().unwrap();
|
||||||
|
match locked_head.as_ref() {
|
||||||
|
Some(head) => Ok(head.clone()),
|
||||||
|
None => {
|
||||||
|
let table = self.read_extra_metadata_table()?;
|
||||||
|
*locked_head = Some(table.clone());
|
||||||
|
Ok(table)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_extra_metadata_table(&self) -> BackendResult<Arc<ReadonlyTable>> {
|
||||||
|
self.extra_metadata_store
|
||||||
|
.get_head()
|
||||||
|
.map_err(|err| BackendError::Other(format!("Failed to read non-git metadata: {err}")))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature_from_git(signature: git2::Signature) -> Signature {
|
fn signature_from_git(signature: git2::Signature) -> Signature {
|
||||||
|
@ -449,19 +467,8 @@ impl Backend for GitBackend {
|
||||||
committer,
|
committer,
|
||||||
};
|
};
|
||||||
|
|
||||||
let table = {
|
let table = self.cached_extra_metadata_table()?;
|
||||||
let mut locked_head = self.cached_extra_metadata.lock().unwrap();
|
if let Some(extras) = table.get_value(git_commit_id.as_bytes()) {
|
||||||
match locked_head.as_ref() {
|
|
||||||
Some(head) => Ok(head.clone()),
|
|
||||||
None => self.extra_metadata_store.get_head().map(|x| {
|
|
||||||
*locked_head = Some(x.clone());
|
|
||||||
x
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.map_err(|err| BackendError::Other(format!("Failed to read non-git metadata: {err}")))?;
|
|
||||||
let maybe_extras = table.get_value(git_commit_id.as_bytes());
|
|
||||||
if let Some(extras) = maybe_extras {
|
|
||||||
deserialize_extras(&mut commit, extras);
|
deserialize_extras(&mut commit, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue