Radish alpha
r
rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt
Git libraries for Radicle
Radicle
Git
clippy: explicit lifetimes
Fintan Halpenny committed 4 months ago
commit 68d6fa879f5c272c0577788533de04c8def71a14
parent 320f316
10 files changed +52 -37
modified radicle-git-ext/git-ref-format/core/src/deriv.rs
@@ -73,7 +73,7 @@ impl<'a> Qualified<'a> {
        Qualified(self.0.join(other).into())
    }

-
    pub fn to_pattern<P>(&self, pattern: P) -> QualifiedPattern
+
    pub fn to_pattern<P>(&'a self, pattern: P) -> QualifiedPattern<'a>
    where
        P: AsRef<PatternStr>,
    {
@@ -81,7 +81,7 @@ impl<'a> Qualified<'a> {
    }

    #[inline]
-
    pub fn to_namespaced(&self) -> Option<Namespaced> {
+
    pub fn to_namespaced(&'a self) -> Option<Namespaced<'a>> {
        self.0.as_ref().into()
    }

@@ -98,7 +98,7 @@ impl<'a> Qualified<'a> {
    }

    /// Like [`Self::non_empty_components`], but with string slices.
-
    pub fn non_empty_iter(&self) -> (&str, &str, &str, name::Iter) {
+
    pub fn non_empty_iter(&'a self) -> (&'a str, &'a str, &'a str, name::Iter<'a>) {
        let mut iter = self.iter();
        (
            iter.next().unwrap(),
@@ -114,7 +114,14 @@ impl<'a> Qualified<'a> {
    /// A qualified ref is guaranteed to have at least three components, which
    /// this method provides a witness of. This is useful eg. for pattern
    /// matching on the prefix.
-
    pub fn non_empty_components(&self) -> (Component, Component, Component, name::Components) {
+
    pub fn non_empty_components(
+
        &'a self,
+
    ) -> (
+
        Component<'a>,
+
        Component<'a>,
+
        Component<'a>,
+
        name::Components<'a>,
+
    ) {
        let mut cs = self.components();
        (
            cs.next().unwrap(),
@@ -287,7 +294,7 @@ impl Display for Qualified<'_> {
pub struct Namespaced<'a>(Cow<'a, RefStr>);

impl<'a> Namespaced<'a> {
-
    pub fn namespace(&self) -> Component {
+
    pub fn namespace(&'a self) -> Component<'a> {
        self.components().nth(2).unwrap()
    }

modified radicle-git-ext/git-ref-format/core/src/name.rs
@@ -130,24 +130,24 @@ impl RefStr {
    }

    #[inline]
-
    pub fn qualified(&self) -> Option<Qualified> {
+
    pub fn qualified<'a>(&'a self) -> Option<Qualified<'a>> {
        Qualified::from_refstr(self)
    }

    #[inline]
-
    pub fn to_namespaced(&self) -> Option<Namespaced> {
+
    pub fn to_namespaced<'a>(&'a self) -> Option<Namespaced<'a>> {
        self.into()
    }

-
    pub fn iter(&self) -> Iter {
+
    pub fn iter<'a>(&'a self) -> Iter<'a> {
        self.0.split('/')
    }

-
    pub fn components(&self) -> Components {
+
    pub fn components<'a>(&'a self) -> Components<'a> {
        Components::from(self)
    }

-
    pub fn head(&self) -> Component {
+
    pub fn head<'a>(&'a self) -> Component<'a> {
        self.components().next().expect("`RefStr` cannot be empty")
    }

modified radicle-git-ext/git-ref-format/core/src/refspec.rs
@@ -49,22 +49,22 @@ impl PatternStr {
    }

    #[inline]
-
    pub fn qualified(&self) -> Option<QualifiedPattern> {
+
    pub fn qualified<'a>(&'a self) -> Option<QualifiedPattern<'a>> {
        QualifiedPattern::from_patternstr(self)
    }

    #[inline]
-
    pub fn to_namespaced(&self) -> Option<NamespacedPattern> {
+
    pub fn to_namespaced<'a>(&'a self) -> Option<NamespacedPattern<'a>> {
        self.into()
    }

    #[inline]
-
    pub fn iter(&self) -> Iter {
+
    pub fn iter<'a>(&'a self) -> Iter<'a> {
        self.0.split('/')
    }

    #[inline]
-
    pub fn components(&self) -> Components {
+
    pub fn components<'a>(&'a self) -> Components<'a> {
        Components::from(self)
    }

@@ -333,7 +333,7 @@ impl<'a> QualifiedPattern<'a> {
    }

    #[inline]
-
    pub fn to_namespaced(&self) -> Option<NamespacedPattern> {
+
    pub fn to_namespaced(&'a self) -> Option<NamespacedPattern<'a>> {
        self.0.as_ref().into()
    }

@@ -353,7 +353,7 @@ impl<'a> QualifiedPattern<'a> {
    }

    /// Like [`Self::non_empty_components`], but with string slices.
-
    pub fn non_empty_iter(&self) -> (&str, &str, &str, Iter) {
+
    pub fn non_empty_iter(&'a self) -> (&'a str, &'a str, &'a str, Iter<'a>) {
        let mut iter = self.iter();
        (
            iter.next().unwrap(),
@@ -369,7 +369,9 @@ impl<'a> QualifiedPattern<'a> {
    /// A qualified ref is guaranteed to have at least three components, which
    /// this method provides a witness of. This is useful eg. for pattern
    /// matching on the prefix.
-
    pub fn non_empty_components(&self) -> (Component, Component, Component, Components) {
+
    pub fn non_empty_components(
+
        &'a self,
+
    ) -> (Component<'a>, Component<'a>, Component<'a>, Components<'a>) {
        let mut cs = self.components();
        (
            cs.next().unwrap(),
@@ -480,7 +482,7 @@ impl From<QualifiedPattern<'_>> for PatternString {
pub struct NamespacedPattern<'a>(Cow<'a, PatternStr>);

impl<'a> NamespacedPattern<'a> {
-
    pub fn namespace(&self) -> Component {
+
    pub fn namespace(&'a self) -> Component<'a> {
        self.components().nth(2).unwrap()
    }

modified radicle-git-ext/src/commit.rs
@@ -125,7 +125,7 @@ impl<Tree, Parent> CommitData<Tree, Parent> {

    /// The [`Signature`]s found in this commit, i.e. the headers corresponding
    /// to `gpgsig`.
-
    pub fn signatures(&self) -> impl Iterator<Item = Signature> + '_ {
+
    pub fn signatures<'a>(&'a self) -> impl Iterator<Item = Signature<'a>> + 'a {
        self.headers.signatures()
    }

modified radicle-git-ext/src/commit/headers.rs
@@ -56,7 +56,7 @@ impl Headers {
            .filter_map(move |(k, v)| (k == name).then_some(v))
    }

-
    pub fn signatures(&self) -> impl Iterator<Item = Signature> + '_ {
+
    pub fn signatures<'a>(&'a self) -> impl Iterator<Item = Signature<'a>> + 'a {
        self.0.iter().filter_map(|(k, v)| {
            if k == "gpgsig" {
                Signature::from_str(v).ok()
modified radicle-git-ext/src/tree.rs
@@ -106,7 +106,7 @@ pub enum Node<'a> {
    Tree(Tree<'a>),
}

-
pub fn blob(slice: &[u8]) -> Node {
+
pub fn blob<'a>(slice: &'a [u8]) -> Node<'a> {
    Node::from(slice)
}

modified radicle-surf/src/branch.rs
@@ -49,7 +49,7 @@ impl Branch {
    /// Give back the fully qualified `Branch` refname,
    /// e.g. `refs/remotes/origin/fix/ref-format`,
    /// `refs/heads/fix/ref-format`.
-
    pub fn refname(&self) -> Qualified {
+
    pub fn refname<'a>(&'a self) -> Qualified<'a> {
        match self {
            Branch::Local(local) => local.refname(),
            Branch::Remote(remote) => remote.refname(),
@@ -146,7 +146,7 @@ impl Local {

    /// Return the fully qualified `Local` refname,
    /// e.g. `refs/heads/fix/ref-format`.
-
    pub fn refname(&self) -> Qualified {
+
    pub fn refname<'a>(&'a self) -> Qualified<'a> {
        lit::refs_heads(&self.name).into()
    }
}
@@ -251,7 +251,7 @@ impl Remote {

    /// Give back the fully qualified `Remote` refname,
    /// e.g. `refs/remotes/origin/fix/ref-format`.
-
    pub fn refname(&self) -> Qualified {
+
    pub fn refname<'a>(&'a self) -> Qualified<'a> {
        lit::refs_remotes(self.remote.join(&self.name)).into()
    }
}
modified radicle-surf/src/diff.rs
@@ -455,7 +455,7 @@ impl Line {
        String::from_utf8(self.0)
    }

-
    pub fn from_utf8_lossy(&self) -> Cow<str> {
+
    pub fn from_utf8_lossy<'a>(&'a self) -> Cow<'a, str> {
        String::from_utf8_lossy(&self.0)
    }
}
modified radicle-surf/src/repo.rs
@@ -87,7 +87,7 @@ impl Repository {
    }

    /// Returns an iterator of branches that match `pattern`.
-
    pub fn branches<G>(&self, pattern: G) -> Result<Branches, Error>
+
    pub fn branches<'a, G>(&'a self, pattern: G) -> Result<Branches<'a>, Error>
    where
        G: Into<Glob<Branch>>,
    {
@@ -102,7 +102,7 @@ impl Repository {
    }

    /// Lists branch names with `filter`.
-
    pub fn branch_names<G>(&self, filter: G) -> Result<BranchNames, Error>
+
    pub fn branch_names<'a, G>(&'a self, filter: G) -> Result<BranchNames<'a>, Error>
    where
        G: Into<Glob<Branch>>,
    {
@@ -110,7 +110,7 @@ impl Repository {
    }

    /// Returns an iterator of tags that match `pattern`.
-
    pub fn tags(&self, pattern: &Glob<Tag>) -> Result<Tags, Error> {
+
    pub fn tags<'a>(&'a self, pattern: &Glob<Tag>) -> Result<Tags<'a>, Error> {
        let mut tags = Tags::default();
        for glob in pattern.globs() {
            let namespaced = self.namespaced_pattern(glob)?;
@@ -121,11 +121,14 @@ impl Repository {
    }

    /// Lists tag names in the local RefScope.
-
    pub fn tag_names(&self, filter: &Glob<Tag>) -> Result<TagNames, Error> {
+
    pub fn tag_names<'a>(&'a self, filter: &Glob<Tag>) -> Result<TagNames<'a>, Error> {
        Ok(self.tags(filter)?.names())
    }

-
    pub fn categories(&self, pattern: &Glob<Qualified<'_>>) -> Result<Categories, Error> {
+
    pub fn categories<'a>(
+
        &'a self,
+
        pattern: &Glob<Qualified<'_>>,
+
    ) -> Result<Categories<'a>, Error> {
        let mut cats = Categories::default();
        for glob in pattern.globs() {
            let namespaced = self.namespaced_pattern(glob)?;
@@ -327,7 +330,7 @@ impl Repository {
    // TODO(finto): I think this can be removed in favour of using
    // `source::Blob::new`
    /// Retrieves the file with `path` in this commit.
-
    pub fn get_commit_file<P, R>(&self, rev: &R, path: &P) -> Result<FileContent, Error>
+
    pub fn get_commit_file<'a, P, R>(&'a self, rev: &R, path: &P) -> Result<FileContent<'a>, Error>
    where
        P: AsRef<Path>,
        R: Revision,
@@ -383,7 +386,7 @@ impl Repository {
    }

    /// Returns the history with the `head` commit.
-
    pub fn history<C: ToCommit>(&self, head: C) -> Result<History, Error> {
+
    pub fn history<'a, C: ToCommit>(&'a self, head: C) -> Result<History<'a>, Error> {
        History::new(self, head)
    }

@@ -416,7 +419,10 @@ impl Repository {
        self.inner.is_bare()
    }

-
    pub(crate) fn find_submodule(&self, name: &str) -> Result<git2::Submodule, git2::Error> {
+
    pub(crate) fn find_submodule<'a>(
+
        &'a self,
+
        name: &str,
+
    ) -> Result<git2::Submodule<'a>, git2::Error> {
        self.inner.find_submodule(name)
    }

@@ -492,12 +498,12 @@ impl Repository {
    /// expected.
    ///
    /// Reference: <https://github.com/libgit2/libgit2/issues/6637>
-
    fn diff_commits(
-
        &self,
+
    fn diff_commits<'a>(
+
        &'a self,
        path: Option<&Path>,
        from: Option<&git2::Commit>,
        to: &git2::Commit,
-
    ) -> Result<git2::Diff, Error> {
+
    ) -> Result<git2::Diff<'a>, Error> {
        let new_tree = to.tree()?;
        let old_tree = from.map_or(Ok(None), |c| c.tree().map(Some))?;

modified radicle-surf/src/tag.rs
@@ -54,7 +54,7 @@ impl Tag {

    /// Return the fully qualified `Tag` refname,
    /// e.g. `refs/tags/release/v1`.
-
    pub fn refname(&self) -> Qualified {
+
    pub fn refname<'a>(&'a self) -> Qualified<'a> {
        lit::refs_tags(self.short_name()).into()
    }
}