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

Method index_git_shas

atomic-repository/src/repository/insert.rs:3719–3761  ·  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

3717 /// write transaction is dropped without committing, keeping incremental
3718 /// no-op imports free of per-change database writes.
3719 pub fn index_git_shas(&self, mappings: &[(String, Hash)]) -> Result<usize, RepositoryError> {
3720 use atomic_core::pristine::{GitShaIndexMutTxnT, GitShaIndexTxnT};
3721
3722 if mappings.is_empty() {
3723 return Ok(0);
3724 }
3725
3726 let mut txn = self
3727 .pristine
3728 .write_txn()
3729 .map_err(|e| RepositoryError::Database(e.to_string()))?;
3730 let mut inserted = 0;
3731
3732 for (git_sha, change_hash) in mappings {
3733 if txn
3734 .has_git_sha(git_sha)
3735 .map_err(|e| RepositoryError::Database(e.to_string()))?
3736 {
3737 continue;
3738 }
3739
3740 let entity_id = txn
3741 .get_internal(change_hash)
3742 .map_err(|e| RepositoryError::Database(e.to_string()))?
3743 .ok_or_else(|| {
3744 RepositoryError::Database(format!(
3745 "Change hash not found in INTERNAL: {}",
3746 change_hash.to_base32()
3747 ))
3748 })?;
3749 txn.put_git_sha(git_sha, entity_id)
3750 .map_err(|e| RepositoryError::Database(e.to_string()))?;
3751 inserted += 1;
3752 }
3753
3754 if inserted == 0 {
3755 return Ok(0);
3756 }
3757
3758 txn.commit()
3759 .map_err(|e| RepositoryError::Database(e.to_string()))?;
3760 Ok(inserted)
3761 }
3762
3763 /// Check if a Git SHA has been indexed.
3764 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