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

Method reinsert_change

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

306 /// repo.reinsert_change(&hash, outcome.original_sequence)?;
307 /// ```
308 pub fn reinsert_change(
309 &self,
310 hash: &Hash,
311 at_sequence: Option<u64>,
312 ) -> Result<(Merkle, u64), RepositoryError> {
313 // Get write transaction
314 let mut txn = self
315 .pristine
316 .write_txn()
317 .map_err(|e| RepositoryError::Database(e.to_string()))?;
318
319 // Get the view
320 let mut view = txn
321 .open_or_create_view(&self.current_view)
322 .map_err(|e| RepositoryError::Database(e.to_string()))?;
323
324 // Get internal ID (must already be registered)
325 let change_id = txn
326 .get_internal(hash)
327 .map_err(|e| RepositoryError::Database(e.to_string()))?
328 .ok_or_else(|| RepositoryError::ChangeNotFound {
329 hash: hash.to_base32(),
330 })?;
331
332 // Determine insertion point
333 let insert_at = at_sequence.unwrap_or(view.change_count);
334
335 // Reinsert the change
336 txn.reinsert_change(&mut view, change_id, hash, insert_at)
337 .map_err(|e| RepositoryError::Database(e.to_string()))?;
338
339 // Update the view
340 txn.update_view(&view)
341 .map_err(|e| RepositoryError::Database(e.to_string()))?;
342
343 // Commit the transaction
344 txn.commit()
345 .map_err(|e| RepositoryError::Database(e.to_string()))?;
346
347 Ok((view.state, view.change_count))
348 }
349
350 /// Check if a change can be unrecorded.
351 ///

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