Skip to content

Commit

Permalink
Merge branch 'worktree-stack'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 30, 2022
2 parents f06f666 + 3a41d5c commit 98da8ba
Show file tree
Hide file tree
Showing 113 changed files with 4,083 additions and 1,918 deletions.
32 changes: 31 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ members = [
"git-lock",
"git-attributes",
"git-pathspec",
"git-path",
"git-repository",
"gitoxide-core",
"git-tui",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
* **mailmap**
* [x] **verify** - check entries of a mailmap file for parse errors and display them
* **repository**
* **exclude**
* [x] **query** - check if path specs are excluded via gits exclusion rules like `.gitignore`.
* **verify** - validate a whole repository, for now only the object database.
* **commit**
* [x] **describe** - identify a commit by its closest tag in its past
Expand Down Expand Up @@ -122,6 +124,7 @@ Crates that seem feature complete and need to see some more use before they can
* [git-bitmap](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-bitmap)
* [git-revision](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-revision)
* [git-attributes](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-attributes)
* [git-path](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-path)
* **idea**
* [git-note](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-note)
* [git-filter](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-filter)
Expand Down
10 changes: 9 additions & 1 deletion crate-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ Check out the [performance discussion][git-traverse-performance] as well.
* [x] parsing
* [x] lookup and mapping of author names

### git-path
* [x] transformations to and from bytes
* [x] conversions between different platforms
* **spec**
* [ ] parse
* [ ] check for match

### git-pathspec
* [ ] parse
* [ ] check for match
Expand Down Expand Up @@ -429,7 +436,8 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/git-lock/README.
* **refs**
* [ ] run transaction hooks and handle special repository states like quarantine
* [ ] support for different backends like `files` and `reftable`
* [ ] worktrees
* **worktrees**
* [ ] open a repository with worktrees
* [ ] remotes with push and pull
* [x] mailmap
* [x] object replacements (`git replace`)
Expand Down
3 changes: 2 additions & 1 deletion etc/check-package-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ echo "in root: gitoxide CLI"
(enter cargo-smart-release && indent cargo diet -n --package-size-limit 90KB)
(enter git-actor && indent cargo diet -n --package-size-limit 5KB)
(enter git-pathspec && indent cargo diet -n --package-size-limit 5KB)
(enter git-path && indent cargo diet -n --package-size-limit 10KB)
(enter git-attributes && indent cargo diet -n --package-size-limit 10KB)
(enter git-index && indent cargo diet -n --package-size-limit 30KB)
(enter git-worktree && indent cargo diet -n --package-size-limit 25KB)
Expand Down Expand Up @@ -51,6 +52,6 @@ echo "in root: gitoxide CLI"
(enter git-odb && indent cargo diet -n --package-size-limit 120KB)
(enter git-protocol && indent cargo diet -n --package-size-limit 50KB)
(enter git-packetline && indent cargo diet -n --package-size-limit 35KB)
(enter git-repository && indent cargo diet -n --package-size-limit 90KB)
(enter git-repository && indent cargo diet -n --package-size-limit 100KB)
(enter git-transport && indent cargo diet -n --package-size-limit 50KB)
(enter gitoxide-core && indent cargo diet -n --package-size-limit 70KB)
4 changes: 3 additions & 1 deletion git-attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ doctest = false

[features]
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
serde1 = ["serde", "bstr/serde1", "git-glob/serde1"]
serde1 = ["serde", "bstr/serde1", "git-glob/serde1", "compact_str/serde"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
git-features = { version = "^0.20.0", path = "../git-features" }
git-path = { version = "^0.1.0", path = "../git-path" }
git-quote = { version = "^0.2.0", path = "../git-quote" }
git-glob = { version = "^0.2.0", path = "../git-glob" }

bstr = { version = "0.2.13", default-features = false, features = ["std"]}
unicode-bom = "1.1.4"
quick-error = "2.0.0"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
compact_str = "0.3.2"

[dev-dependencies]
git-testtools = { path = "../tests/tools"}
127 changes: 61 additions & 66 deletions git-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
#![deny(rust_2018_idioms)]

use bstr::{BStr, BString};
use compact_str::CompactStr;
use std::path::PathBuf;

pub use git_glob as glob;

/// The state an attribute can be in, referencing the value.
///
/// Note that this doesn't contain the name.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub enum State<'a> {
pub enum StateRef<'a> {
/// The attribute is listed, or has the special value 'true'
Set,
/// The attribute has the special value 'false', or was prefixed with a `-` sign.
Expand All @@ -18,87 +25,75 @@ pub enum State<'a> {
Unspecified,
}

/// A grouping of lists of patterns while possibly keeping associated to their base path.
/// The state an attribute can be in, owning the value.
///
/// Patterns with base path are queryable relative to that base, otherwise they are relative to the repository root.
/// Note that this doesn't contain the name.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub enum State {
/// The attribute is listed, or has the special value 'true'
Set,
/// The attribute has the special value 'false', or was prefixed with a `-` sign.
Unset,
/// The attribute is set to the given value, which followed the `=` sign.
/// Note that values can be empty.
Value(compact_str::CompactStr),
/// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
Unspecified,
}

/// Name an attribute and describe it's assigned state.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
pub struct MatchGroup<T: match_group::Tag> {
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Assignment {
/// The name of the attribute.
pub name: CompactStr,
/// The state of the attribute.
pub state: State,
}

/// A grouping of lists of patterns while possibly keeping associated to their base path.
///
/// Pattern lists with base path are queryable relative to that base, otherwise they are relative to the repository root.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Default)]
pub struct MatchGroup<T: match_group::Pattern = Attributes> {
/// A list of pattern lists, each representing a patterns from a file or specified by hand, in the order they were
/// specified in.
///
/// During matching, this order is reversed.
pub patterns: Vec<PatternList<T>>,
}

/// A list of patterns with an optional names, for matching against it.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
pub struct PatternList<T: match_group::Tag> {
/// Patterns and their associated data in the order they were loaded in or specified.
/// A list of patterns which optionally know where they were loaded from and what their base is.
///
/// Knowing their base which is relative to a source directory, it will ignore all path to match against
/// that don't also start with said base.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Default)]
pub struct PatternList<T: match_group::Pattern> {
/// Patterns and their associated data in the order they were loaded in or specified,
/// the line number in its source file or its sequence number (_`(pattern, value, line_number)`_).
///
/// During matching, this order is reversed.
pub patterns: Vec<(git_glob::Pattern, T::Value)>,
pub patterns: Vec<PatternMapping<T::Value>>,

/// The path at which the patterns are located in a format suitable for matches, or `None` if the patterns
/// are relative to the worktree root.
base: Option<BString>,
}

mod match_group {
use crate::{MatchGroup, PatternList};
use std::ffi::OsString;
use std::path::PathBuf;

/// A marker trait to identify the type of a description.
pub trait Tag: Clone + PartialEq + Eq + std::fmt::Debug + std::hash::Hash + Ord + PartialOrd {
/// The value associated with a pattern.
type Value: PartialEq + Eq + std::fmt::Debug + std::hash::Hash + Ord + PartialOrd + Clone;
}

/// Identify ignore patterns.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
pub struct Ignore;
impl Tag for Ignore {
type Value = ();
}
/// The path from which the patterns were read, or `None` if the patterns
/// don't originate in a file on disk.
pub source: Option<PathBuf>,

/// Identify patterns with attributes.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
pub struct Attributes;
impl Tag for Attributes {
/// TODO: identify the actual value, should be name/State pairs, but there is the question of storage.
type Value = ();
}

impl MatchGroup<Ignore> {
/// See [PatternList::<Ignore>::from_overrides()] for details.
pub fn from_overrides(patterns: impl IntoIterator<Item = impl Into<OsString>>) -> Self {
MatchGroup {
patterns: vec![PatternList::<Ignore>::from_overrides(patterns)],
}
}
}
/// The parent directory of source, or `None` if the patterns are _global_ to match against the repository root.
/// It's processed to contain slashes only and to end with a trailing slash, and is relative to the repository root.
pub base: Option<BString>,
}

impl PatternList<Ignore> {
/// Parse a list of patterns, using slashes as path separators
pub fn from_overrides(patterns: impl IntoIterator<Item = impl Into<OsString>>) -> Self {
PatternList {
patterns: patterns
.into_iter()
.map(Into::into)
.filter_map(|pattern| {
let pattern = git_features::path::into_bytes(PathBuf::from(pattern)).ok()?;
git_glob::parse(pattern.as_ref()).map(|p| (p, ()))
})
.collect(),
base: None,
}
}
}
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
pub struct PatternMapping<T> {
pub pattern: git_glob::Pattern,
pub value: T,
pub sequence_number: usize,
}
pub use match_group::{Attributes, Ignore, Tag};

pub type Files = MatchGroup<Attributes>;
pub type IgnoreFiles = MatchGroup<Ignore>;
mod match_group;
pub use match_group::{Attributes, Ignore, Match, Pattern};

pub mod parse;

Expand Down

0 comments on commit 98da8ba

Please sign in to comment.