Skip to content

Commit

Permalink
Merge branch 'remote-ls-refs'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 22, 2022
2 parents f90d772 + dcd6619 commit 39d585d
Show file tree
Hide file tree
Showing 122 changed files with 4,143 additions and 1,911 deletions.
8 changes: 5 additions & 3 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ check: ## Build all code in suitable configurations
cd git-transport && cargo check \
&& cargo check --features blocking-client \
&& cargo check --features async-client \
&& cargo check --features async-client,async-std \
&& cargo check --features http-client-curl
cd git-transport && if cargo check --all-features 2>/dev/null; then false; else true; fi
cd git-protocol && cargo check \
Expand All @@ -118,6 +119,7 @@ check: ## Build all code in suitable configurations
cd git-protocol && if cargo check --all-features 2>/dev/null; then false; else true; fi
cd git-repository && cargo check --no-default-features --features local \
&& cargo check --no-default-features --features async-network-client \
&& cargo check --no-default-features --features async-network-client-async-std \
&& cargo check --no-default-features --features blocking-network-client \
&& cargo check --no-default-features --features blocking-network-client,blocking-http-transport \
&& cargo check --no-default-features --features one-stop-shop \
Expand Down Expand Up @@ -151,6 +153,8 @@ unit-tests: ## run all unit tests
&& cargo test --features async-client \
&& cargo test
cd git-repository && cargo test \
&& cargo test --features async-network-client \
&& cargo test --features blocking-network-client \
&& cargo test --features regex
cd gitoxide-core && cargo test --lib

Expand Down
9 changes: 4 additions & 5 deletions cargo-smart-release/src/changelog/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl From<git::Url> for RepositoryUrl {

impl RepositoryUrl {
pub fn is_github(&self) -> bool {
self.inner.host.as_ref().map(|h| h == "github.com").unwrap_or(false)
self.inner.host().map(|h| h == "github.com").unwrap_or(false)
}

fn cleaned_path(&self) -> String {
Expand All @@ -59,15 +59,14 @@ impl RepositoryUrl {
}

pub fn github_https(&self) -> Option<String> {
match &self.inner.host {
Some(host) if host == "github.com" => match self.inner.scheme {
match &self.inner.host() {
Some(host) if *host == "github.com" => match self.inner.scheme {
Scheme::Http | Scheme::Https | Scheme::Git => {
format!("https://github.com{}", self.cleaned_path()).into()
}
Scheme::Ssh => self
.inner
.user
.as_ref()
.user()
.map(|user| format!("https://github.com{}/{}", user, self.cleaned_path())),
Scheme::Radicle | Scheme::File => None,
},
Expand Down
19 changes: 15 additions & 4 deletions crate-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Check out the [performance discussion][git-traverse-performance] as well.
### git-refspec
* [x] parse
* [ ] matching of references and object names
* [ ] for fetch
* [ ] for push

### git-note

Expand Down Expand Up @@ -459,9 +461,19 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/git-lock/README.
* **references**
* [x] peel to end
* [x] ref-log access
* [ ] clone from remote
* [ ] shallow
* [ ] execute hooks
* [x] remote name
* [x] find remote itself
- [ ] respect `branch.<name>.merge` in the returned remote.
* **remotes**
* [ ] clone
* [ ] shallow
* [ ] fetch
* [ ] push
* [ ] ls-refs
* [ ] list, find by name, create in memory.
* [ ] groups
* [ ] [remote and branch files](https://github.com/git/git/blob/master/remote.c#L300)
* [ ] execute hooks
* **refs**
* [ ] run transaction hooks and handle special repository states like quarantine
* [ ] support for different backends like `files` and `reftable`
Expand All @@ -488,7 +500,6 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/git-lock/README.
* [x] read and interpolate trusted paths
* [x] low-level API for more elaborate access to all details of `git-config` files
* [ ] a way to make changes to individual configuration files
* [ ] remotes with push and pull
* [x] mailmap
* [x] object replacements (`git replace`)
* [ ] configuration
Expand Down
2 changes: 1 addition & 1 deletion etc/check-package-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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 140KB)
(enter git-repository && indent cargo diet -n --package-size-limit 150KB)
(enter git-transport && indent cargo diet -n --package-size-limit 50KB)
(enter gitoxide-core && indent cargo diet -n --package-size-limit 80KB)
20 changes: 16 additions & 4 deletions git-config/src/file/access/comfort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::{borrow::Cow, convert::TryFrom};

use bstr::BStr;

use crate::{file::MetadataFilter, value, File};
use crate::parse::section;
use crate::{file::MetadataFilter, lookup, value, File};

/// Comfortable API for accessing values
impl<'event> File<'event> {
Expand Down Expand Up @@ -80,9 +81,20 @@ impl<'event> File<'event> {
key: impl AsRef<str>,
filter: &mut MetadataFilter,
) -> Option<Result<bool, value::Error>> {
self.raw_value_filter(section_name, subsection_name, key, filter)
.ok()
.map(|v| crate::Boolean::try_from(v).map(|b| b.into()))
let section_name = section_name.as_ref();
let key = key.as_ref();
match self.raw_value_filter(section_name, subsection_name, key, filter) {
Ok(v) => Some(crate::Boolean::try_from(v).map(|b| b.into())),
Err(lookup::existing::Error::KeyMissing) => {
let section = self
.section_filter(section_name, subsection_name, filter)
.ok()
.flatten()?;
let key = section::Key::try_from(key).ok()?;
section.key_and_value_range_by(&key).map(|_| Ok(true))
}
Err(_err) => None,
}
}

/// Like [`value()`][File::value()], but returning an `Option` if the integer wasn't found.
Expand Down
44 changes: 41 additions & 3 deletions git-config/src/file/access/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{

/// Mutating low-level access methods.
impl<'event> File<'event> {
/// Returns an mutable section with a given `name` and optional `subsection_name`.
/// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_.
pub fn section_mut<'a>(
&'a mut self,
name: impl AsRef<str>,
Expand All @@ -29,8 +29,46 @@ impl<'event> File<'event> {
.expect("BUG: Section did not have id from lookup")
.to_mut(nl))
}
/// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_, or create a new section.
pub fn section_mut_or_create_new<'a>(
&'a mut self,
name: impl AsRef<str>,
subsection_name: Option<&str>,
) -> Result<SectionMut<'a, 'event>, section::header::Error> {
self.section_mut_or_create_new_filter(name, subsection_name, &mut |_| true)
}

/// Returns an mutable section with a given `name` and optional `subsection_name`, _if it exists_ **and** passes `filter`, or create
/// a new section.
pub fn section_mut_or_create_new_filter<'a>(
&'a mut self,
name: impl AsRef<str>,
subsection_name: Option<&str>,
filter: &mut MetadataFilter,
) -> Result<SectionMut<'a, 'event>, section::header::Error> {
let name = name.as_ref();
match self
.section_ids_by_name_and_subname(name.as_ref(), subsection_name)
.ok()
.and_then(|it| {
it.rev().find(|id| {
let s = &self.sections[id];
filter(s.meta())
})
}) {
Some(id) => {
let nl = self.detect_newline_style_smallvec();
Ok(self
.sections
.get_mut(&id)
.expect("BUG: Section did not have id from lookup")
.to_mut(nl))
}
None => self.new_section(name.to_owned(), subsection_name.map(|n| Cow::Owned(n.to_owned()))),
}
}

/// Returns the last found mutable section with a given `name` and optional `subsection_name`, that matches `filter`.
/// Returns the last found mutable section with a given `name` and optional `subsection_name`, that matches `filter`, _if it exists_.
///
/// If there are sections matching `section_name` and `subsection_name` but the `filter` rejects all of them, `Ok(None)`
/// is returned.
Expand Down Expand Up @@ -78,7 +116,7 @@ impl<'event> File<'event> {
/// # use git_config::parse::section;
/// let mut git_config = git_config::File::default();
/// let mut section = git_config.new_section("hello", Some("world".into()))?;
/// section.push(section::Key::try_from("a")?, "b");
/// section.push(section::Key::try_from("a")?, Some("b".into()));
/// let nl = section.newline().to_owned();
/// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}"));
/// let _section = git_config.new_section("core", None);
Expand Down
78 changes: 70 additions & 8 deletions git-config/src/file/access/raw.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::TryInto;
use std::{borrow::Cow, collections::HashMap};

use bstr::BStr;
Expand Down Expand Up @@ -329,7 +330,9 @@ impl<'event> File<'event> {
}
}

/// Sets a value in a given section, optional subsection, and key value.
/// Sets a value in a given `section_name`, optional `subsection_name`, and `key`.
/// Note sections named `section_name` and `subsection_name` (if not `None`)
/// must exist for this method to work.
///
/// # Examples
///
Expand All @@ -351,7 +354,7 @@ impl<'event> File<'event> {
/// # use bstr::BStr;
/// # use std::convert::TryFrom;
/// # let mut git_config = git_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
/// git_config.set_raw_value("core", None, "a", "e".into())?;
/// git_config.set_existing_raw_value("core", None, "a", "e")?;
/// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
/// assert_eq!(
/// git_config.raw_values("core", None, "a")?,
Expand All @@ -363,17 +366,76 @@ impl<'event> File<'event> {
/// );
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn set_raw_value(
pub fn set_existing_raw_value<'b>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
key: impl AsRef<str>,
new_value: &BStr,
new_value: impl Into<&'b BStr>,
) -> Result<(), lookup::existing::Error> {
self.raw_value_mut(section_name, subsection_name, key.as_ref())
.map(|mut entry| entry.set(new_value))
}

/// Sets a value in a given `section_name`, optional `subsection_name`, and `key`.
/// Creates the section if necessary and the key as well, or overwrites the last existing value otherwise.
///
/// # Examples
///
/// Given the config,
///
/// ```text
/// [core]
/// a = b
/// ```
///
/// Setting a new value to the key `core.a` will yield the following:
///
/// ```
/// # use git_config::File;
/// # use std::borrow::Cow;
/// # use bstr::BStr;
/// # use std::convert::TryFrom;
/// # let mut git_config = git_config::File::try_from("[core]a=b").unwrap();
/// let prev = git_config.set_raw_value("core", None, "a", "e")?;
/// git_config.set_raw_value("core", None, "b", "f")?;
/// assert_eq!(prev.expect("present").as_ref(), "b");
/// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
/// assert_eq!(git_config.raw_value("core", None, "b")?, Cow::<BStr>::Borrowed("f".into()));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn set_raw_value<'b, Key, E>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
key: Key,
new_value: impl Into<&'b BStr>,
) -> Result<Option<Cow<'event, BStr>>, crate::file::set_raw_value::Error>
where
Key: TryInto<section::Key<'event>, Error = E>,
section::key::Error: From<E>,
{
self.set_raw_value_filter(section_name, subsection_name, key, new_value, &mut |_| true)
}

/// Similar to [`set_raw_value()`][Self::set_raw_value()], but only sets existing values in sections matching
/// `filter`, creating a new section otherwise.
pub fn set_raw_value_filter<'b, Key, E>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
key: Key,
new_value: impl Into<&'b BStr>,
filter: &mut MetadataFilter,
) -> Result<Option<Cow<'event, BStr>>, crate::file::set_raw_value::Error>
where
Key: TryInto<section::Key<'event>, Error = E>,
section::key::Error: From<E>,
{
let mut section = self.section_mut_or_create_new_filter(section_name, subsection_name, filter)?;
Ok(section.set(key.try_into().map_err(section::key::Error::from)?, new_value))
}

/// Sets a multivar in a given section, optional subsection, and key value.
///
/// This internally zips together the new values and the existing values.
Expand Down Expand Up @@ -413,7 +475,7 @@ impl<'event> File<'event> {
/// "y",
/// "z",
/// ];
/// git_config.set_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// git_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// let fetched_config = git_config.raw_values("core", None, "a")?;
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("x".into())));
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("y".into())));
Expand All @@ -433,7 +495,7 @@ impl<'event> File<'event> {
/// "x",
/// "y",
/// ];
/// git_config.set_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// git_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
/// let fetched_config = git_config.raw_values("core", None, "a")?;
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("x".into())));
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("y".into())));
Expand All @@ -454,11 +516,11 @@ impl<'event> File<'event> {
/// "z",
/// "discarded",
/// ];
/// git_config.set_raw_multi_value("core", None, "a", new_values)?;
/// git_config.set_existing_raw_multi_value("core", None, "a", new_values)?;
/// assert!(!git_config.raw_values("core", None, "a")?.contains(&Cow::<BStr>::Borrowed("discarded".into())));
/// # Ok::<(), git_config::lookup::existing::Error>(())
/// ```
pub fn set_raw_multi_value<'a, Iter, Item>(
pub fn set_existing_raw_multi_value<'a, Iter, Item>(
&mut self,
section_name: impl AsRef<str>,
subsection_name: Option<&str>,
Expand Down
Loading

0 comments on commit 39d585d

Please sign in to comment.