Skip to content

Commit b629f8a

Browse files
committed
Merge branch 'submodules'
2 parents 6b4a303 + 6a2e6a4 commit b629f8a

File tree

39 files changed

+1227
-204
lines changed

39 files changed

+1227
-204
lines changed

Cargo.lock

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crate-status.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ Make it the best-performing implementation and the most convenient one.
486486
* [x] primitives to help with graph traversal, along with commit-graph acceleration.
487487

488488
### gix-submodule
489+
* [ ] read `.gitmodule` files, access all their fields, and apply overrides
489490
* CRUD for submodules
490491
* 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.
491492

@@ -721,7 +722,10 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/gix-lock/README.
721722
* [ ] Use _Commit Graph_ to speed up certain queries
722723
* [ ] subtree
723724
* [ ] interactive rebase status/manipulation
724-
* submodules
725+
* **submodules**
726+
* [ ] handle 'old' form for reading
727+
* [ ] list
728+
* [ ] traverse recursively
725729
* [ ] API documentation
726730
* [ ] Some examples
727731

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

755759
### gix-validate
756760
* [x] validate ref names
761+
* [x] validate submodule names
757762
* [x] [validate][tagname-validation] tag names
758763

759764
### gix-ref

gix-config/src/file/access/mutate.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,13 @@ impl<'event> File<'event> {
272272
self.sections.remove(&id)
273273
}
274274

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

288284
/// Renames the section with `name` and `subsection_name`, modifying the last matching section

gix-ref/src/fullname.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,46 @@ use gix_object::bstr::{BStr, BString, ByteSlice};
55
use crate::{bstr::ByteVec, name::is_pseudo_ref, Category, FullName, FullNameRef, Namespace, PartialNameRef};
66

77
impl TryFrom<&str> for FullName {
8-
type Error = gix_validate::refname::Error;
8+
type Error = gix_validate::reference::name::Error;
99

1010
fn try_from(value: &str) -> Result<Self, Self::Error> {
11-
Ok(FullName(gix_validate::refname(value.as_bytes().as_bstr())?.into()))
11+
Ok(FullName(
12+
gix_validate::reference::name(value.as_bytes().as_bstr())?.into(),
13+
))
1214
}
1315
}
1416

1517
impl TryFrom<String> for FullName {
16-
type Error = gix_validate::refname::Error;
18+
type Error = gix_validate::reference::name::Error;
1719

1820
fn try_from(value: String) -> Result<Self, Self::Error> {
19-
gix_validate::refname(value.as_bytes().as_bstr())?;
21+
gix_validate::reference::name(value.as_bytes().as_bstr())?;
2022
Ok(FullName(value.into()))
2123
}
2224
}
2325

2426
impl TryFrom<&BStr> for FullName {
25-
type Error = gix_validate::refname::Error;
27+
type Error = gix_validate::reference::name::Error;
2628

2729
fn try_from(value: &BStr) -> Result<Self, Self::Error> {
28-
Ok(FullName(gix_validate::refname(value)?.into()))
30+
Ok(FullName(gix_validate::reference::name(value)?.into()))
2931
}
3032
}
3133

3234
impl TryFrom<BString> for FullName {
33-
type Error = gix_validate::refname::Error;
35+
type Error = gix_validate::reference::name::Error;
3436

3537
fn try_from(value: BString) -> Result<Self, Self::Error> {
36-
gix_validate::refname(value.as_ref())?;
38+
gix_validate::reference::name(value.as_ref())?;
3739
Ok(FullName(value))
3840
}
3941
}
4042

4143
impl TryFrom<&BString> for FullName {
42-
type Error = gix_validate::refname::Error;
44+
type Error = gix_validate::reference::name::Error;
4345

4446
fn try_from(value: &BString) -> Result<Self, Self::Error> {
45-
gix_validate::refname(value.as_ref())?;
47+
gix_validate::reference::name(value.as_ref())?;
4648
Ok(FullName(value.clone()))
4749
}
4850
}

gix-ref/src/namespace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ impl Namespace {
3636
/// Given a `namespace` 'foo we output 'refs/namespaces/foo', and given 'foo/bar' we output 'refs/namespaces/foo/refs/namespaces/bar'.
3737
///
3838
/// For more information, consult the [git namespace documentation](https://git-scm.com/docs/gitnamespaces).
39-
pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, gix_validate::refname::Error>
39+
pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, gix_validate::reference::name::Error>
4040
where
4141
Name: TryInto<&'a PartialNameRef, Error = E>,
42-
gix_validate::refname::Error: From<E>,
42+
gix_validate::reference::name::Error: From<E>,
4343
{
4444
let namespace = &namespace.try_into()?.0;
4545
let mut out = BString::default();

gix-ref/src/store/file/loose/reference/decode.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ impl TryFrom<MaybeUnsafeState> for Target {
3939
fn try_from(v: MaybeUnsafeState) -> Result<Self, Self::Error> {
4040
Ok(match v {
4141
MaybeUnsafeState::Id(id) => Target::Peeled(id),
42-
MaybeUnsafeState::UnvalidatedPath(name) => Target::Symbolic(match gix_validate::refname(name.as_ref()) {
43-
Ok(_) => FullName(name),
44-
Err(err) => {
45-
return Err(Error::RefnameValidation {
46-
source: err,
47-
path: name,
48-
})
49-
}
50-
}),
42+
MaybeUnsafeState::UnvalidatedPath(name) => {
43+
Target::Symbolic(match gix_validate::reference::name(name.as_ref()) {
44+
Ok(_) => FullName(name),
45+
Err(err) => {
46+
return Err(Error::RefnameValidation {
47+
source: err,
48+
path: name,
49+
})
50+
}
51+
})
52+
}
5153
})
5254
}
5355
}

gix-ref/tests/namespace/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod expand {
3131
fn backslashes_are_no_component_separators_and_invalid() {
3232
assert!(matches!(
3333
gix_ref::namespace::expand("foo\\bar").expect_err("empty invalid"),
34-
gix_validate::refname::Error::Tag(
34+
gix_validate::reference::name::Error::Tag(
3535
gix_validate::tag::name::Error::InvalidByte{byte}
3636
) if byte == "\\"
3737
));
@@ -41,29 +41,29 @@ mod expand {
4141
fn trailing_slashes_are_not_allowed() {
4242
assert!(matches!(
4343
gix_ref::namespace::expand("foo/").expect_err("empty invalid"),
44-
gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
44+
gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
4545
));
4646
}
4747

4848
#[test]
4949
fn empty_namespaces_are_not_allowed() {
5050
assert!(matches!(
5151
gix_ref::namespace::expand("").expect_err("empty invalid"),
52-
gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::Empty)
52+
gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::Empty)
5353
));
5454
}
5555
#[test]
5656
fn bare_slashes_are_not_allowed() {
5757
assert!(matches!(
5858
gix_ref::namespace::expand("/").expect_err("empty invalid"),
59-
gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
59+
gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash)
6060
));
6161
}
6262
#[test]
6363
fn repeated_slashes_are_invalid() {
6464
assert!(matches!(
6565
gix_ref::namespace::expand("foo//bar").expect_err("empty invalid"),
66-
gix_validate::refname::Error::RepeatedSlash
66+
gix_validate::reference::name::Error::RepeatedSlash
6767
));
6868
}
6969
}

gix-refspec/src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum Error {
2525
#[error("Both sides of the specification need a pattern, like 'a/*:b/*'")]
2626
PatternUnbalanced,
2727
#[error(transparent)]
28-
ReferenceName(#[from] gix_validate::refname::Error),
28+
ReferenceName(#[from] gix_validate::reference::name::Error),
2929
#[error(transparent)]
3030
RevSpec(#[from] gix_revision::spec::parse::Error),
3131
}

gix-refspec/tests/parse/invalid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn empty() {
1111
fn empty_component() {
1212
assert!(matches!(
1313
try_parse("refs/heads/test:refs/remotes//test", Operation::Fetch).unwrap_err(),
14-
Error::ReferenceName(gix_validate::refname::Error::RepeatedSlash)
14+
Error::ReferenceName(gix_validate::reference::name::Error::RepeatedSlash)
1515
));
1616
}
1717

gix-submodule/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ rust-version = "1.65"
1212
doctest = false
1313

1414
[dependencies]
15+
gix-refspec = { version = "^0.14.1", path = "../gix-refspec" }
16+
gix-config = { version = "^0.26.2", path = "../gix-config" }
17+
gix-path = { version = "^0.8.4", path = "../gix-path" }
18+
gix-url = { version = "^0.21.1", path = "../gix-url" }
19+
20+
bstr = { version = "1.5.0", default-features = false }
21+
thiserror = "1.0.44"
22+
23+
[dev-dependencies]
24+
gix-testtools = { path = "../tests/tools"}
25+
gix-features = { path = "../gix-features", features = ["walkdir"] }
26+

0 commit comments

Comments
 (0)