Skip to content

Commit

Permalink
Merge branch 'submodules'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 6, 2023
2 parents 6b4a303 + 6a2e6a4 commit b629f8a
Show file tree
Hide file tree
Showing 39 changed files with 1,227 additions and 204 deletions.
18 changes: 14 additions & 4 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion crate-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ Make it the best-performing implementation and the most convenient one.
* [x] primitives to help with graph traversal, along with commit-graph acceleration.

### gix-submodule
* [ ] read `.gitmodule` files, access all their fields, and apply overrides
* CRUD for submodules
* try to handle with all the nifty interactions and be a little more comfortable than what git offers, lay a foundation for smarter git submodules.

Expand Down Expand Up @@ -721,7 +722,10 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/gix-lock/README.
* [ ] Use _Commit Graph_ to speed up certain queries
* [ ] subtree
* [ ] interactive rebase status/manipulation
* submodules
* **submodules**
* [ ] handle 'old' form for reading
* [ ] list
* [ ] traverse recursively
* [ ] API documentation
* [ ] Some examples

Expand Down Expand Up @@ -754,6 +758,7 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/gix-lock/README.

### gix-validate
* [x] validate ref names
* [x] validate submodule names
* [x] [validate][tagname-validation] tag names

### gix-ref
Expand Down
10 changes: 3 additions & 7 deletions gix-config/src/file/access/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,13 @@ impl<'event> File<'event> {
self.sections.remove(&id)
}

/// Adds the provided section to the config, returning a mutable reference
/// to it for immediate editing.
/// Adds the provided `section` to the config, returning a mutable reference to it for immediate editing.
/// Note that its meta-data will remain as is.
pub fn push_section(
&mut self,
section: file::Section<'event>,
) -> Result<SectionMut<'_, 'event>, section::header::Error> {
pub fn push_section(&mut self, section: file::Section<'event>) -> SectionMut<'_, 'event> {
let id = self.push_section_internal(section);
let nl = self.detect_newline_style_smallvec();
let section = self.sections.get_mut(&id).expect("each id yields a section").to_mut(nl);
Ok(section)
section
}

/// Renames the section with `name` and `subsection_name`, modifying the last matching section
Expand Down
22 changes: 12 additions & 10 deletions gix-ref/src/fullname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@ use gix_object::bstr::{BStr, BString, ByteSlice};
use crate::{bstr::ByteVec, name::is_pseudo_ref, Category, FullName, FullNameRef, Namespace, PartialNameRef};

impl TryFrom<&str> for FullName {
type Error = gix_validate::refname::Error;
type Error = gix_validate::reference::name::Error;

fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(FullName(gix_validate::refname(value.as_bytes().as_bstr())?.into()))
Ok(FullName(
gix_validate::reference::name(value.as_bytes().as_bstr())?.into(),
))
}
}

impl TryFrom<String> for FullName {
type Error = gix_validate::refname::Error;
type Error = gix_validate::reference::name::Error;

fn try_from(value: String) -> Result<Self, Self::Error> {
gix_validate::refname(value.as_bytes().as_bstr())?;
gix_validate::reference::name(value.as_bytes().as_bstr())?;
Ok(FullName(value.into()))
}
}

impl TryFrom<&BStr> for FullName {
type Error = gix_validate::refname::Error;
type Error = gix_validate::reference::name::Error;

fn try_from(value: &BStr) -> Result<Self, Self::Error> {
Ok(FullName(gix_validate::refname(value)?.into()))
Ok(FullName(gix_validate::reference::name(value)?.into()))
}
}

impl TryFrom<BString> for FullName {
type Error = gix_validate::refname::Error;
type Error = gix_validate::reference::name::Error;

fn try_from(value: BString) -> Result<Self, Self::Error> {
gix_validate::refname(value.as_ref())?;
gix_validate::reference::name(value.as_ref())?;
Ok(FullName(value))
}
}

impl TryFrom<&BString> for FullName {
type Error = gix_validate::refname::Error;
type Error = gix_validate::reference::name::Error;

fn try_from(value: &BString) -> Result<Self, Self::Error> {
gix_validate::refname(value.as_ref())?;
gix_validate::reference::name(value.as_ref())?;
Ok(FullName(value.clone()))
}
}
Expand Down
4 changes: 2 additions & 2 deletions gix-ref/src/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ impl Namespace {
/// Given a `namespace` 'foo we output 'refs/namespaces/foo', and given 'foo/bar' we output 'refs/namespaces/foo/refs/namespaces/bar'.
///
/// For more information, consult the [git namespace documentation](https://git-scm.com/docs/gitnamespaces).
pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, gix_validate::refname::Error>
pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, gix_validate::reference::name::Error>
where
Name: TryInto<&'a PartialNameRef, Error = E>,
gix_validate::refname::Error: From<E>,
gix_validate::reference::name::Error: From<E>,
{
let namespace = &namespace.try_into()?.0;
let mut out = BString::default();
Expand Down
20 changes: 11 additions & 9 deletions gix-ref/src/store/file/loose/reference/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ impl TryFrom<MaybeUnsafeState> for Target {
fn try_from(v: MaybeUnsafeState) -> Result<Self, Self::Error> {
Ok(match v {
MaybeUnsafeState::Id(id) => Target::Peeled(id),
MaybeUnsafeState::UnvalidatedPath(name) => Target::Symbolic(match gix_validate::refname(name.as_ref()) {
Ok(_) => FullName(name),
Err(err) => {
return Err(Error::RefnameValidation {
source: err,
path: name,
})
}
}),
MaybeUnsafeState::UnvalidatedPath(name) => {
Target::Symbolic(match gix_validate::reference::name(name.as_ref()) {
Ok(_) => FullName(name),
Err(err) => {
return Err(Error::RefnameValidation {
source: err,
path: name,
})
}
})
}
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions gix-ref/tests/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod expand {
fn backslashes_are_no_component_separators_and_invalid() {
assert!(matches!(
gix_ref::namespace::expand("foo\\bar").expect_err("empty invalid"),
gix_validate::refname::Error::Tag(
gix_validate::reference::name::Error::Tag(
gix_validate::tag::name::Error::InvalidByte{byte}
) if byte == "\\"
));
Expand All @@ -41,29 +41,29 @@ mod expand {
fn trailing_slashes_are_not_allowed() {
assert!(matches!(
gix_ref::namespace::expand("foo/").expect_err("empty invalid"),
gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
));
}

#[test]
fn empty_namespaces_are_not_allowed() {
assert!(matches!(
gix_ref::namespace::expand("").expect_err("empty invalid"),
gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::Empty)
gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::Empty)
));
}
#[test]
fn bare_slashes_are_not_allowed() {
assert!(matches!(
gix_ref::namespace::expand("/").expect_err("empty invalid"),
gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
));
}
#[test]
fn repeated_slashes_are_invalid() {
assert!(matches!(
gix_ref::namespace::expand("foo//bar").expect_err("empty invalid"),
gix_validate::refname::Error::RepeatedSlash
gix_validate::reference::name::Error::RepeatedSlash
));
}
}
2 changes: 1 addition & 1 deletion gix-refspec/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum Error {
#[error("Both sides of the specification need a pattern, like 'a/*:b/*'")]
PatternUnbalanced,
#[error(transparent)]
ReferenceName(#[from] gix_validate::refname::Error),
ReferenceName(#[from] gix_validate::reference::name::Error),
#[error(transparent)]
RevSpec(#[from] gix_revision::spec::parse::Error),
}
Expand Down
2 changes: 1 addition & 1 deletion gix-refspec/tests/parse/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn empty() {
fn empty_component() {
assert!(matches!(
try_parse("refs/heads/test:refs/remotes//test", Operation::Fetch).unwrap_err(),
Error::ReferenceName(gix_validate::refname::Error::RepeatedSlash)
Error::ReferenceName(gix_validate::reference::name::Error::RepeatedSlash)
));
}

Expand Down
12 changes: 12 additions & 0 deletions gix-submodule/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ rust-version = "1.65"
doctest = false

[dependencies]
gix-refspec = { version = "^0.14.1", path = "../gix-refspec" }
gix-config = { version = "^0.26.2", path = "../gix-config" }
gix-path = { version = "^0.8.4", path = "../gix-path" }
gix-url = { version = "^0.21.1", path = "../gix-url" }

bstr = { version = "1.5.0", default-features = false }
thiserror = "1.0.44"

[dev-dependencies]
gix-testtools = { path = "../tests/tools"}
gix-features = { path = "../gix-features", features = ["walkdir"] }

Loading

0 comments on commit b629f8a

Please sign in to comment.