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

Method reinsert_change

atomic-repository/src/repository/history.rs:366–406  ·  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

364 /// repo.reinsert_change(&hash, outcome.original_sequence)?;
365 /// ```
366 pub fn reinsert_change(
367 &self,
368 hash: &Hash,
369 at_sequence: Option<u64>,
370 ) -> Result<(Merkle, u64), RepositoryError> {
371 // Get write transaction
372 let mut txn = self
373 .pristine
374 .write_txn()
375 .map_err(|e| RepositoryError::Database(e.to_string()))?;
376
377 // Get the view
378 let mut view = txn
379 .open_or_create_view(&self.current_view)
380 .map_err(|e| RepositoryError::Database(e.to_string()))?;
381
382 // Get internal ID (must already be registered)
383 let change_id = txn
384 .get_internal(hash)
385 .map_err(|e| RepositoryError::Database(e.to_string()))?
386 .ok_or_else(|| RepositoryError::ChangeNotFound {
387 hash: hash.to_base32(),
388 })?;
389
390 // Determine insertion point
391 let insert_at = at_sequence.unwrap_or(view.change_count);
392
393 // Reinsert the change
394 txn.reinsert_change(&mut view, change_id, hash, insert_at)
395 .map_err(|e| RepositoryError::Database(e.to_string()))?;
396
397 // Update the view
398 txn.update_view(&view)
399 .map_err(|e| RepositoryError::Database(e.to_string()))?;
400
401 // Commit the transaction
402 txn.commit()
403 .map_err(|e| RepositoryError::Database(e.to_string()))?;
404
405 Ok((view.state, view.change_count))
406 }
407
408 /// Check if a change can be unrecorded.
409 ///

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