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

Method stash_list

atomic-repository/src/repository/stash.rs:393–442  ·  view source on GitHub ↗

List all stashes, newest first, with display indices assigned.

(&self)

Source from the content-addressed store, hash-verified

391
392 /// List all stashes, newest first, with display indices assigned.
393 pub fn stash_list(&self) -> Result<Vec<StashEntry>, String> {
394 let views = self.list_views().map_err(|e| e.to_string())?;
395
396 let mut stashes: Vec<StashEntry> = views
397 .into_iter()
398 .filter(|name| name.starts_with(STASH_PREFIX))
399 .map(|name| {
400 // Parse stash metadata from the view name (verbatim from
401 // the CLI): stash/{source}_{timestamp}_{message}.
402 let parts: Vec<&str> = name
403 .trim_start_matches(STASH_PREFIX)
404 .splitn(3, '_')
405 .collect();
406
407 let (source_view, message, timestamp) = if parts.len() >= 2 {
408 let ts: i64 = parts.get(1).and_then(|s| s.parse().ok()).unwrap_or(0);
409 let src = if parts[0] == "auto" {
410 "unknown".to_string()
411 } else {
412 parts[0].to_string()
413 };
414 let msg = parts
415 .get(2)
416 .map(|s| s.to_string())
417 .unwrap_or_else(|| DEFAULT_STASH_MESSAGE.to_string());
418 (src, msg, ts)
419 } else {
420 ("unknown".to_string(), DEFAULT_STASH_MESSAGE.to_string(), 0)
421 };
422
423 let created_at =
424 DateTime::from_timestamp_millis(timestamp).unwrap_or_else(Utc::now);
425
426 StashEntry {
427 index: 0,
428 view_name: name,
429 source_view,
430 message,
431 created_at,
432 }
433 })
434 .collect();
435
436 // Sort by creation time, newest first, and assign indices.
437 stashes.sort_by_key(|s| std::cmp::Reverse(s.created_at));
438 for (i, stash) in stashes.iter_mut().enumerate() {
439 stash.index = i;
440 }
441 Ok(stashes)
442 }
443
444 /// Resolve a stash reference (`stash@{N}`, `N`, or a view name) to
445 /// its entry. `None` resolves to the most recent stash.

Callers 7

list_stashesMethod · 0.80
run_pushMethod · 0.80
run_clearMethod · 0.80
stash_resolveMethod · 0.80
stash_clearMethod · 0.80
list_stashesMethod · 0.80

Calls 8

iter_mutMethod · 0.80
getMethod · 0.65
list_viewsMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
lenMethod · 0.45
okMethod · 0.45
parseMethod · 0.45