mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-30 16:10:23 +00:00
git_backend: extract helper to add extra metadata entry and save table
This commit is contained in:
parent
8a0fcfb032
commit
78c8dbc8fe
1 changed files with 18 additions and 8 deletions
|
@ -120,6 +120,23 @@ impl GitBackend {
|
||||||
.get_head()
|
.get_head()
|
||||||
.map_err(|err| BackendError::Other(format!("Failed to read non-git metadata: {err}")))
|
.map_err(|err| BackendError::Other(format!("Failed to read non-git metadata: {err}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_extra_metadata_entry(
|
||||||
|
&self,
|
||||||
|
table: &Arc<ReadonlyTable>,
|
||||||
|
id: &CommitId,
|
||||||
|
extras: Vec<u8>,
|
||||||
|
) -> BackendResult<()> {
|
||||||
|
let mut mut_table = table.start_mutation();
|
||||||
|
mut_table.add_entry(id.to_bytes(), extras);
|
||||||
|
self.extra_metadata_store
|
||||||
|
.save_table(mut_table)
|
||||||
|
.map_err(|err| {
|
||||||
|
BackendError::Other(format!("Failed to write non-git metadata: {err}"))
|
||||||
|
})?;
|
||||||
|
*self.cached_extra_metadata.lock().unwrap() = None;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature_from_git(signature: git2::Signature) -> Signature {
|
fn signature_from_git(signature: git2::Signature) -> Signature {
|
||||||
|
@ -514,7 +531,6 @@ impl Backend for GitBackend {
|
||||||
let parent_refs = parents.iter().collect_vec();
|
let parent_refs = parents.iter().collect_vec();
|
||||||
let extras = serialize_extras(&contents);
|
let extras = serialize_extras(&contents);
|
||||||
let table = self.read_extra_metadata_table()?;
|
let table = self.read_extra_metadata_table()?;
|
||||||
let mut mut_table = table.start_mutation();
|
|
||||||
let id = loop {
|
let id = loop {
|
||||||
let git_id = locked_repo
|
let git_id = locked_repo
|
||||||
.commit(
|
.commit(
|
||||||
|
@ -555,13 +571,7 @@ impl Backend for GitBackend {
|
||||||
contents.author.timestamp.timestamp = MillisSinceEpoch(author.when().seconds() * 1000);
|
contents.author.timestamp.timestamp = MillisSinceEpoch(author.when().seconds() * 1000);
|
||||||
contents.committer.timestamp.timestamp =
|
contents.committer.timestamp.timestamp =
|
||||||
MillisSinceEpoch(committer.when().seconds() * 1000);
|
MillisSinceEpoch(committer.when().seconds() * 1000);
|
||||||
mut_table.add_entry(id.to_bytes(), extras);
|
self.write_extra_metadata_entry(&table, &id, extras)?;
|
||||||
self.extra_metadata_store
|
|
||||||
.save_table(mut_table)
|
|
||||||
.map_err(|err| {
|
|
||||||
BackendError::Other(format!("Failed to write non-git metadata: {err}"))
|
|
||||||
})?;
|
|
||||||
*self.cached_extra_metadata.lock().unwrap() = None;
|
|
||||||
Ok((id, contents))
|
Ok((id, contents))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue