Skip to content

Commit f4621cc

Browse files
committed
sketch out dir cache and realize that git uses chdir (#301)
Git is able to use relative paths by changing the working directory. See https://github.com/git/git/blob/main/builtin.h#L82:L82 We probably shouldn't do that as a library, but will compose the path instead like we do now, but should consider using the cache for file and directory handling to avoid allocations.
1 parent a39d476 commit f4621cc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

git-worktree/src/index/checkout.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
use bstr::BString;
22
use quick_error::quick_error;
3+
use std::path::PathBuf;
4+
5+
/// A cache for directory creation to reduce the amount of stat calls when creating
6+
/// directories safely, that is without following symlinks that might be on the way.
7+
///
8+
/// As a special case, it offers a 'prefix' which (by itself) is assumed to exist and may contain symlinks.
9+
/// Everything past that prefix boundary must not contain a symlink.
10+
///
11+
/// For this to work, it remembers the last 'good' path to a directory and assumes that all components of it
12+
/// are still valid, too.
13+
/// As directories are created, the cache will be adjusted to reflect the latest seen directory.
14+
///
15+
/// The caching is only useful if consecutive calls to create a directory are using a sorted list of entries.
16+
#[allow(unused)]
17+
pub(crate) struct DirCache {
18+
/// the most recent known cached that we know is valid.
19+
valid: PathBuf,
20+
}
321

422
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
523
pub struct Collision {

0 commit comments

Comments
 (0)