Skip to content

Commit bd4c5ec

Browse files
committed
docs: add doc strings to stupid/tempindex
1 parent c948b96 commit bd4c5ec

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/stupid/tempindex.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
//! Context for creating and auto-deleting a temporary index file.
4+
//!
5+
//! The temporary index file is created relative to `git_dir`.
6+
//!
7+
//! The file name is based on the PID of the StGit process to mitigate the most
8+
//! egregious name collision scenarios.
9+
//!
10+
//! When [`TempIndex`] instance is dropped, it will attempt to delete the temporary
11+
//! index file. It is okay if the file no longer exists at drop-time, but a panic will
12+
//! happen if the file exists but removal fails.
13+
114
use std::path::{Path, PathBuf};
215

316
use anyhow::Result;
@@ -8,6 +21,9 @@ pub(crate) struct TempIndex<'repo> {
821
}
922

1023
impl<'repo> TempIndex<'repo> {
24+
/// Create new temporary index file relative to `git_dir`.
25+
///
26+
/// The temporary index file will be auto-deleted when this value is dropped.
1127
pub(crate) fn new(git_dir: &'repo Path) -> Result<Self> {
1228
let pid = std::process::id();
1329
let filename = PathBuf::from(format!("index-temp-stg-{pid}"));
@@ -20,6 +36,10 @@ impl<'repo> TempIndex<'repo> {
2036
Ok(Self { git_dir, filename })
2137
}
2238

39+
/// Get a reference to the temporary index file name.
40+
///
41+
/// This is not a complete path to the file. The file exists relative to the git
42+
/// dir.
2343
pub(crate) fn filename(&self) -> &Path {
2444
self.filename.as_ref()
2545
}

0 commit comments

Comments
 (0)