File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change
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
+
1
14
use std:: path:: { Path , PathBuf } ;
2
15
3
16
use anyhow:: Result ;
@@ -8,6 +21,9 @@ pub(crate) struct TempIndex<'repo> {
8
21
}
9
22
10
23
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.
11
27
pub ( crate ) fn new ( git_dir : & ' repo Path ) -> Result < Self > {
12
28
let pid = std:: process:: id ( ) ;
13
29
let filename = PathBuf :: from ( format ! ( "index-temp-stg-{pid}" ) ) ;
@@ -20,6 +36,10 @@ impl<'repo> TempIndex<'repo> {
20
36
Ok ( Self { git_dir, filename } )
21
37
}
22
38
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.
23
43
pub ( crate ) fn filename ( & self ) -> & Path {
24
44
self . filename . as_ref ( )
25
45
}
You can’t perform that action at this time.
0 commit comments