Enum git_ref::Category

source ·
pub enum Category<'a> {
    Tag,
    LocalBranch,
    RemoteBranch,
    Note,
    PseudoRef,
    MainPseudoRef,
    MainRef,
    LinkedPseudoRef {
        name: &'a BStr,
    },
    LinkedRef {
        name: &'a BStr,
    },
    Bisect,
    Rewritten,
    WorktreePrivate,
}
Expand description

The various known categories of references.

This translates into a prefix containing all references of a given category.

Variants§

§

Tag

A tag in refs/tags

§

LocalBranch

A branch in refs/heads

§

RemoteBranch

A branch in refs/remotes

§

Note

A tag in refs/notes

§

PseudoRef

Something outside of ref/ in the current worktree, typically HEAD.

§

MainPseudoRef

A PseudoRef, but referenced so that it will always refer to the main worktree by prefixing it with main-worktree/.

§

MainRef

Any reference that is prefixed with main-worktree/refs/

§

LinkedPseudoRef

Fields

§name: &'a BStr

The name of the worktree.

A PseudoRef in another linked worktree, never in the main one, like worktrees/<id>/HEAD.

§

LinkedRef

Fields

§name: &'a BStr

The name of the worktree.

Any reference that is prefixed with worktrees/<id>/refs/.

§

Bisect

A ref that is private to each worktree (linked or main), with refs/bisect/ prefix

§

Rewritten

A ref that is private to each worktree (linked or main), with refs/rewritten/ prefix

§

WorktreePrivate

A ref that is private to each worktree (linked or main), with refs/worktree/ prefix

Implementations§

Return the prefix that would contain all references of our kind, or an empty string if the reference would be directly inside of the git_dir().

Examples found in repository?
src/name.rs (line 68)
65
66
67
68
69
70
71
    pub(crate) fn looks_like_full_name(&self) -> bool {
        let name = self.0.as_bstr();
        name.starts_with_str("refs/")
            || name.starts_with(Category::MainPseudoRef.prefix())
            || name.starts_with(Category::LinkedPseudoRef { name: "".into() }.prefix())
            || is_pseudo_ref(name)
    }
More examples
Hide additional examples
src/fullname.rs (line 109)
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    pub fn category_and_short_name(&self) -> Option<(Category<'_>, &BStr)> {
        let name = self.0.as_bstr();
        for category in &[Category::Tag, Category::LocalBranch, Category::RemoteBranch] {
            if let Some(shortened) = name.strip_prefix(category.prefix().as_ref()) {
                return Some((*category, shortened.as_bstr()));
            }
        }

        for category in &[
            Category::Note,
            Category::Bisect,
            Category::WorktreePrivate,
            Category::Rewritten,
        ] {
            if name.starts_with(category.prefix().as_ref()) {
                return Some((
                    *category,
                    name.strip_prefix(b"refs/")
                        .expect("we checked for refs/* above")
                        .as_bstr(),
                ));
            }
        }

        if is_pseudo_ref(name) {
            Some((Category::PseudoRef, name))
        } else if let Some(shortened) = name.strip_prefix(Category::MainPseudoRef.prefix().as_ref()) {
            if shortened.starts_with_str("refs/") {
                (Category::MainRef, shortened.as_bstr()).into()
            } else {
                is_pseudo_ref(shortened).then(|| (Category::MainPseudoRef, shortened.as_bstr()))
            }
        } else if let Some(shortened_with_worktree_name) =
            name.strip_prefix(Category::LinkedPseudoRef { name: "".into() }.prefix().as_ref())
        {
            let (name, shortened) = shortened_with_worktree_name.find_byte(b'/').map(|pos| {
                (
                    shortened_with_worktree_name[..pos].as_bstr(),
                    shortened_with_worktree_name[pos + 1..].as_bstr(),
                )
            })?;
            if shortened.starts_with_str("refs/") {
                (Category::LinkedRef { name }, shortened.as_bstr()).into()
            } else {
                is_pseudo_ref(shortened).then(|| (Category::LinkedPseudoRef { name }, shortened.as_bstr()))
            }
        } else {
            None
        }
    }

Returns true if the category is private to their worktrees, and never shared with other worktrees.

Examples found in repository?
src/store/file/overlay_iter.rs (line 121)
119
120
121
122
123
124
125
126
127
        fn advance_to_non_private(iter: &mut Peekable<SortedLoosePaths>) {
            while let Some(Ok((_path, name))) = iter.peek() {
                if name.category().map_or(true, |cat| cat.is_worktree_private()) {
                    iter.next();
                } else {
                    break;
                }
            }
        }
More examples
Hide additional examples
src/store/file/transaction/prepare.rs (line 419)
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
fn possibly_adjust_name_for_prefixes(name: &FullNameRef) -> Option<FullName> {
    match name.category_and_short_name() {
        Some((c, sn)) => {
            use crate::Category::*;
            let sn = FullNameRef::new_unchecked(sn);
            match c {
                Bisect | Rewritten | WorktreePrivate | LinkedPseudoRef { .. } | PseudoRef | MainPseudoRef => None,
                Tag | LocalBranch | RemoteBranch | Note => name.into(),
                MainRef | LinkedRef { .. } => sn
                    .category()
                    .map_or(false, |cat| !cat.is_worktree_private())
                    .then(|| sn),
            }
            .map(|n| n.to_owned())
        }
        None => Some(name.to_owned()), // allow (uncategorized/very special) refs to be packed
    }
}
src/store/file/find.rs (line 180)
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    pub(crate) fn to_base_dir_and_relative_name<'a>(
        &self,
        name: &'a FullNameRef,
        is_reflog: bool,
    ) -> (Cow<'_, Path>, &'a FullNameRef) {
        let commondir = self.common_dir_resolved();
        let linked_git_dir =
            |worktree_name: &BStr| commondir.join("worktrees").join(git_path::from_bstr(worktree_name));
        name.category_and_short_name()
            .and_then(|(c, sn)| {
                use crate::Category::*;
                let sn = FullNameRef::new_unchecked(sn);
                Some(match c {
                    LinkedPseudoRef { name: worktree_name } => is_reflog
                        .then(|| (linked_git_dir(worktree_name).into(), sn))
                        .unwrap_or((commondir.into(), name)),
                    Tag | LocalBranch | RemoteBranch | Note => (commondir.into(), name),
                    MainRef | MainPseudoRef => (commondir.into(), sn),
                    LinkedRef { name: worktree_name } => sn
                        .category()
                        .map_or(false, |cat| cat.is_worktree_private())
                        .then(|| {
                            if is_reflog {
                                (linked_git_dir(worktree_name).into(), sn)
                            } else {
                                (commondir.into(), name)
                            }
                        })
                        .unwrap_or((commondir.into(), sn)),
                    PseudoRef | Bisect | Rewritten | WorktreePrivate => return None,
                })
            })
            .unwrap_or((self.git_dir.as_path().into(), name))
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.