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

Method reinsert_change

atomic-repository/src/repository/history.rs:445–485  ·  view source on GitHub ↗

Reinsert a previously unrecorded change at a specific position. This is part of the Gerrit-like workflow where a change can be removed, modified, and re-inserted at its original position (or appended). # Arguments `hash` - Hash of the change to reinsert `at_sequence` - The sequence position to insert at (None = append to end) # Returns The new state and sequence after reinsertion. # Example

(
        &self,
        hash: &Hash,
        at_sequence: Option<u64>,
    )

Source from the content-addressed store, hash-verified

443 /// repo.reinsert_change(&hash, outcome.original_sequence)?;
444 /// ```
445 pub fn reinsert_change(
446 &self,
447 hash: &Hash,
448 at_sequence: Option<u64>,
449 ) -> Result<(Merkle, u64), RepositoryError> {
450 // Get write transaction
451 let mut txn = self
452 .pristine
453 .write_txn()
454 .map_err(|e| RepositoryError::Database(e.to_string()))?;
455
456 // Get the view
457 let mut view = txn
458 .open_or_create_view(&self.current_view)
459 .map_err(|e| RepositoryError::Database(e.to_string()))?;
460
461 // Get internal ID (must already be registered)
462 let change_id = txn
463 .get_internal(hash)
464 .map_err(|e| RepositoryError::Database(e.to_string()))?
465 .ok_or_else(|| RepositoryError::ChangeNotFound {
466 hash: hash.to_base32(),
467 })?;
468
469 // Determine insertion point
470 let insert_at = at_sequence.unwrap_or(view.change_count);
471
472 // Reinsert the change
473 txn.reinsert_change(&mut view, change_id, hash, insert_at)
474 .map_err(|e| RepositoryError::Database(e.to_string()))?;
475
476 // Update the view
477 txn.update_view(&view)
478 .map_err(|e| RepositoryError::Database(e.to_string()))?;
479
480 // Commit the transaction
481 txn.commit()
482 .map_err(|e| RepositoryError::Database(e.to_string()))?;
483
484 Ok((view.state, view.change_count))
485 }
486
487 /// Check if a change can be unrecorded.
488 ///

Callers

nothing calls this directly

Calls 6

write_txnMethod · 0.80
open_or_create_viewMethod · 0.80
update_viewMethod · 0.80
commitMethod · 0.80
get_internalMethod · 0.45
to_base32Method · 0.45

Tested by

no test coverage detected