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

Method index_git_shas

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

2656 /// write transaction is dropped without committing, keeping incremental
2657 /// no-op imports free of per-change database writes.
2658 pub fn index_git_shas(&self, mappings: &[(String, Hash)]) -> Result<usize, RepositoryError> {
2659 use atomic_core::pristine::{GitShaIndexMutTxnT, GitShaIndexTxnT};
2660
2661 if mappings.is_empty() {
2662 return Ok(0);
2663 }
2664
2665 let mut txn = self
2666 .pristine
2667 .write_txn()
2668 .map_err(|e| RepositoryError::Database(e.to_string()))?;
2669 let mut inserted = 0;
2670
2671 for (git_sha, change_hash) in mappings {
2672 if txn
2673 .has_git_sha(git_sha)
2674 .map_err(|e| RepositoryError::Database(e.to_string()))?
2675 {
2676 continue;
2677 }
2678
2679 let entity_id = txn
2680 .get_internal(change_hash)
2681 .map_err(|e| RepositoryError::Database(e.to_string()))?
2682 .ok_or_else(|| {
2683 RepositoryError::Database(format!(
2684 "Change hash not found in INTERNAL: {}",
2685 change_hash.to_base32()
2686 ))
2687 })?;
2688 txn.put_git_sha(git_sha, entity_id)
2689 .map_err(|e| RepositoryError::Database(e.to_string()))?;
2690 inserted += 1;
2691 }
2692
2693 if inserted == 0 {
2694 return Ok(0);
2695 }
2696
2697 txn.commit()
2698 .map_err(|e| RepositoryError::Database(e.to_string()))?;
2699 Ok(inserted)
2700 }
2701
2702 /// Check if a Git SHA has been indexed.
2703 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
commitMethod · 0.80
is_emptyMethod · 0.45
has_git_shaMethod · 0.45
get_internalMethod · 0.45

Tested by

no test coverage detected