MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / index_git_shas

Method index_git_shas

atomic-repository/src/repository/insert.rs:3797–3839  ·  view source on GitHub ↗

Record missing Git SHA → Atomic change mappings in one transaction. Existing mappings are skipped. If every mapping is already indexed the write transaction is dropped without committing, keeping incremental no-op imports free of per-change database writes.

(&self, mappings: &[(String, Hash)])

Source from the content-addressed store, hash-verified

3795 /// write transaction is dropped without committing, keeping incremental
3796 /// no-op imports free of per-change database writes.
3797 pub fn index_git_shas(&self, mappings: &[(String, Hash)]) -> Result<usize, RepositoryError> {
3798 use atomic_core::pristine::{GitShaIndexMutTxnT, GitShaIndexTxnT};
3799
3800 if mappings.is_empty() {
3801 return Ok(0);
3802 }
3803
3804 let mut txn = self
3805 .pristine
3806 .write_txn()
3807 .map_err(|e| RepositoryError::Database(e.to_string()))?;
3808 let mut inserted = 0;
3809
3810 for (git_sha, change_hash) in mappings {
3811 if txn
3812 .has_git_sha(git_sha)
3813 .map_err(|e| RepositoryError::Database(e.to_string()))?
3814 {
3815 continue;
3816 }
3817
3818 let entity_id = txn
3819 .get_internal(change_hash)
3820 .map_err(|e| RepositoryError::Database(e.to_string()))?
3821 .ok_or_else(|| {
3822 RepositoryError::Database(format!(
3823 "Change hash not found in INTERNAL: {}",
3824 change_hash.to_base32()
3825 ))
3826 })?;
3827 txn.put_git_sha(git_sha, entity_id)
3828 .map_err(|e| RepositoryError::Database(e.to_string()))?;
3829 inserted += 1;
3830 }
3831
3832 if inserted == 0 {
3833 return Ok(0);
3834 }
3835
3836 txn.commit()
3837 .map_err(|e| RepositoryError::Database(e.to_string()))?;
3838 Ok(inserted)
3839 }
3840
3841 /// Check if a Git SHA has been indexed.
3842 pub fn has_git_sha(&self, git_sha: &str) -> Result<bool, RepositoryError> {

Callers 1

Calls 6

write_txnMethod · 0.80
put_git_shaMethod · 0.80
is_emptyMethod · 0.45
has_git_shaMethod · 0.45
get_internalMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected