Skip to content

Commit

Permalink
change!: rename Cache to Stack because it's more fitting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 19, 2023
1 parent e5fda60 commit 09f8063
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 40 deletions.
8 changes: 4 additions & 4 deletions gix-worktree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ use bstr::BString;
///
/// The caching is only useful if consecutive calls to create a directory are using a sorted list of entries.
#[derive(Clone)]
pub struct Cache {
pub struct Stack {
stack: gix_fs::Stack,
/// tells us what to do as we change paths.
state: cache::State,
state: stack::State,
/// A buffer used when reading attribute or ignore files or their respective objects from the object database.
buf: Vec<u8>,
/// If case folding should happen when looking up attributes or exclusions.
case: gix_glob::pattern::Case,
/// A lookup table for object ids to read from in some situations when looking up attributes or exclusions.
id_mappings: Vec<PathIdMapping>,
statistics: cache::Statistics,
statistics: stack::Statistics,
}

pub(crate) type PathIdMapping = (BString, gix_hash::ObjectId);

///
pub mod cache;
pub mod stack;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bstr::{BStr, ByteSlice};

use crate::{cache::State, PathIdMapping};
use crate::{stack::State, PathIdMapping};

/// Various aggregate numbers related to the stack delegate itself.
#[derive(Default, Clone, Copy, Debug)]
Expand Down
16 changes: 8 additions & 8 deletions gix-worktree/src/cache/mod.rs → gix-worktree/src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::path::{Path, PathBuf};
use bstr::{BStr, ByteSlice};
use gix_hash::oid;

use super::Cache;
use super::Stack;
use crate::PathIdMapping;

/// Various aggregate numbers collected from when the corresponding [`Cache`] was instantiated.
/// Various aggregate numbers collected from when the corresponding [`Stack`] was instantiated.
#[derive(Default, Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Statistics {
Expand Down Expand Up @@ -45,12 +45,12 @@ pub enum State {

#[must_use]
pub struct Platform<'a> {
parent: &'a Cache,
parent: &'a Stack,
is_dir: Option<bool>,
}

/// Initialization
impl Cache {
impl Stack {
/// Create a new instance with `worktree_root` being the base for all future paths we match.
/// `state` defines the capabilities of the cache.
/// The `case` configures attribute and exclusion case sensitivity at *query time*, which should match the case that
Expand All @@ -64,7 +64,7 @@ impl Cache {
id_mappings: Vec<PathIdMapping>,
) -> Self {
let root = worktree_root.into();
Cache {
Stack {
stack: gix_fs::Stack::new(root),
state,
case,
Expand All @@ -76,7 +76,7 @@ impl Cache {
}

/// Entry points for attribute query
impl Cache {
impl Stack {
/// Append the `relative` path to the root directory of the cache and efficiently create leading directories, while assuring that no
/// symlinks are in that path.
/// Unless `is_dir` is known with `Some(…)`, then `relative` points to a directory itself in which case the entire resulting
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Cache {
}

/// Mutation
impl Cache {
impl Stack {
/// Reset the statistics after returning them.
pub fn take_statistics(&mut self) -> Statistics {
std::mem::take(&mut self.statistics)
Expand All @@ -159,7 +159,7 @@ impl Cache {
}

/// Access
impl Cache {
impl Stack {
/// Return the statistics we gathered thus far.
pub fn statistics(&self) -> &Statistics {
&self.statistics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::Path;

use bstr::ByteSlice;

use crate::cache::Platform;
use crate::stack::Platform;

/// Access
impl<'a> Platform<'a> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use bstr::{BStr, ByteSlice};
use gix_glob::pattern::Case;

use crate::{
cache::state::{AttributeMatchGroup, Attributes},
Cache, PathIdMapping,
stack::state::{AttributeMatchGroup, Attributes},
PathIdMapping, Stack,
};

/// Various aggregate numbers related [`Attributes`].
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Attributes {
}

/// Attribute matching specific methods
impl Cache {
impl Stack {
/// Creates a new container to store match outcomes for all attribute matches.
///
/// ### Panics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bstr::{BStr, ByteSlice};
use gix_glob::pattern::Case;

use crate::{
cache::state::{Ignore, IgnoreMatchGroup},
stack::state::{Ignore, IgnoreMatchGroup},
PathIdMapping,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use bstr::{BString, ByteSlice};
use gix_glob::pattern::Case;

use crate::{cache::State, PathIdMapping};
use crate::{stack::State, PathIdMapping};

type AttributeMatchGroup = gix_attributes::Search;
type IgnoreMatchGroup = gix_ignore::Search;
Expand Down
5 changes: 3 additions & 2 deletions gix-worktree/tests/worktree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod cache;

use gix_hash::ObjectId;

mod stack;

pub type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;

pub fn hex_to_id(hex: &str) -> ObjectId {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bstr::ByteSlice;
use gix_attributes::search::Outcome;
use gix_glob::pattern::Case;
use gix_worktree::cache::state;
use gix_worktree::stack::state;

#[test]
fn baseline() -> crate::Result {
Expand All @@ -19,17 +19,17 @@ fn baseline() -> crate::Result {

let mut buf = Vec::new();
let mut collection = gix_attributes::search::MetadataCollection::default();
let state = gix_worktree::cache::State::for_checkout(
let state = gix_worktree::stack::State::for_checkout(
false,
state::Attributes::new(
gix_attributes::Search::new_globals([base.join("user.attributes")], &mut buf, &mut collection)?,
Some(git_dir.join("info").join("attributes")),
gix_worktree::cache::state::attributes::Source::WorktreeThenIdMapping,
gix_worktree::stack::state::attributes::Source::WorktreeThenIdMapping,
collection,
),
);

let mut cache = gix_worktree::Cache::new(&base, state, case, buf, vec![]);
let mut cache = gix_worktree::Stack::new(&base, state, case, buf, vec![]);

let mut actual = cache.attribute_matches();
let input = std::fs::read(base.join("baseline"))?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;

use gix_testtools::tempfile::{tempdir, TempDir};
use gix_worktree::{cache, Cache};
use gix_worktree::{stack, Stack};

#[allow(clippy::ptr_arg)]
fn panic_on_find<'buf>(_oid: &gix_hash::oid, _buf: &'buf mut Vec<u8>) -> std::io::Result<gix_object::BlobRef<'buf>> {
Expand All @@ -11,9 +11,9 @@ fn panic_on_find<'buf>(_oid: &gix_hash::oid, _buf: &'buf mut Vec<u8>) -> std::io
#[test]
fn root_is_assumed_to_exist_and_files_in_root_do_not_create_directory() -> crate::Result {
let dir = tempdir()?;
let mut cache = Cache::new(
let mut cache = Stack::new(
dir.path().join("non-existing-root"),
cache::State::for_checkout(false, Default::default()),
stack::State::for_checkout(false, Default::default()),
Default::default(),
Vec::new(),
Default::default(),
Expand Down Expand Up @@ -68,7 +68,7 @@ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::R
std::fs::write(tmp.path().join("file-in-dir"), [])?;

for dirname in &["file-in-dir", "link-to-dir"] {
if let cache::State::CreateDirectoryAndAttributesStack {
if let stack::State::CreateDirectoryAndAttributesStack {
unlink_on_collision, ..
} = cache.state_mut()
{
Expand All @@ -90,7 +90,7 @@ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::R
);
cache.take_statistics();
for dirname in &["link-to-dir", "file-in-dir"] {
if let cache::State::CreateDirectoryAndAttributesStack {
if let stack::State::CreateDirectoryAndAttributesStack {
unlink_on_collision, ..
} = cache.state_mut()
{
Expand All @@ -109,11 +109,11 @@ fn symlinks_or_files_in_path_are_forbidden_or_unlinked_when_forced() -> crate::R
Ok(())
}

fn new_cache() -> (Cache, TempDir) {
fn new_cache() -> (Stack, TempDir) {
let dir = tempdir().unwrap();
let cache = Cache::new(
let cache = Stack::new(
dir.path(),
cache::State::for_checkout(false, Default::default()),
stack::State::for_checkout(false, Default::default()),
Default::default(),
Vec::new(),
Default::default(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bstr::{BStr, ByteSlice};
use gix_glob::pattern::Case;
use gix_odb::FindExt;
use gix_worktree::{cache::state::ignore::Source, Cache};
use gix_worktree::{stack::state::ignore::Source, Stack};

use crate::hex_to_id;

Expand Down Expand Up @@ -37,16 +37,16 @@ fn exclude_by_dir_is_handled_just_like_git() {

let mut buf = Vec::new();
let case = gix_glob::pattern::Case::Sensitive;
let state = gix_worktree::cache::State::for_add(
let state = gix_worktree::stack::State::for_add(
Default::default(),
gix_worktree::cache::state::Ignore::new(
gix_worktree::stack::state::Ignore::new(
Default::default(),
gix_ignore::Search::from_git_dir(&git_dir, None, &mut buf).unwrap(),
None,
Source::WorktreeThenIdMappingIfNotSkipped,
),
);
let mut cache = Cache::new(&dir, state, case, buf, Default::default());
let mut cache = Stack::new(&dir, state, case, buf, Default::default());
let baseline = std::fs::read(git_dir.parent().unwrap().join("git-check-ignore.baseline")).unwrap();
let expectations = IgnoreExpectations {
lines: baseline.lines(),
Expand Down Expand Up @@ -95,9 +95,9 @@ fn check_against_baseline() -> crate::Result {
};
let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, Default::default())?;
let odb = gix_odb::at(git_dir.join("objects"))?;
let state = gix_worktree::cache::State::for_add(
let state = gix_worktree::stack::State::for_add(
Default::default(),
gix_worktree::cache::state::Ignore::new(
gix_worktree::stack::state::Ignore::new(
gix_ignore::Search::from_overrides(vec!["!force-include"]),
gix_ignore::Search::from_git_dir(&git_dir, Some(user_exclude_path), &mut buf)?,
None,
Expand All @@ -113,7 +113,7 @@ fn check_against_baseline() -> crate::Result {
hex_to_id("5c7e0ed672d3d31d83a3df61f13cc8f7b22d5bfd")
)]
);
let mut cache = Cache::new(&worktree_dir, state, case, buf, attribute_files_in_index);
let mut cache = Stack::new(&worktree_dir, state, case, buf, attribute_files_in_index);

let baseline = std::fs::read(git_dir.parent().unwrap().join("git-check-ignore.baseline"))?;
let expectations = IgnoreExpectations {
Expand Down
File renamed without changes.

0 comments on commit 09f8063

Please sign in to comment.