Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/command/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const MAINTENANCE_LAST_RUN_KEY: &str = "maintenance.last-run";
const DEFAULT_LOOSE_OBJECT_THRESHOLD: usize = 100;
const DEFAULT_PACK_COUNT_THRESHOLD: usize = 5;
const LOOSE_OBJECT_AGE_SECONDS: u64 = 14 * 24 * 60 * 60; // 2 weeks
/// Grace period before an unreachable loose object may be deleted by `gc`.
///
/// This protects concurrent commands (add/commit/fetch/hash-object) that have
/// just written objects but not yet updated refs/reflogs/index. Objects newer
/// than this grace period are left in place even when unreachable.
const GC_PRUNE_GRACE_SECONDS: u64 = 60 * 60; // 1 hour

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply the GC grace period before pruning

The new grace-period constant is only declared; run_gc still iterates every unreachable loose object and calls fs::remove_file without checking the object's modified() time. When libra maintenance run --task gc overlaps with add/commit/fetch/hash-object after they write loose objects but before refs, reflogs, or the index become reachable, those fresh objects are still deleted, so the intended data-loss protection from this fix is not actually present. Skip objects younger than GC_PRUNE_GRACE_SECONDS before removing or reporting them.

Useful? React with 👍 / 👎.

Comment on lines +63 to +67

/// `--help` examples shown in `libra maintenance --help` output.
pub const MAINTENANCE_EXAMPLES: &str = "\
Expand Down
6 changes: 5 additions & 1 deletion src/command/stash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ async fn run_push(options: StashPushOptions) -> Result<StashOutput, StashError>

let index_tree =
tree::create_tree_from_index(&index).map_err(|e| StashError::WriteObject(e.to_string()))?;
let index_tree_hash = index_tree.id;
let index_tree_data = index_tree
.to_data()
.map_err(|e| StashError::WriteObject(e.to_string()))?;
let index_tree_hash = object::write_git_object(&git_dir, "tree", &index_tree_data)
.map_err(|e| StashError::WriteObject(e.to_string()))?;
Comment on lines +343 to +347

let (author, committer) = util::create_signatures().await;
let (current_branch_name, head_commit_summary) = match Head::current().await {
Expand Down
Loading