History

Also build what should be a valid path for loose-ref lookup (#301)

Sebastian Thiel committed 4 years ago

Commit 37deca51 parent 19d53fb1 file · +11 −11Browse files

Unified · Split

git-ref/src/store/file/find.rs+11−11
@@ -10,7 +10,7 @@ use crate::name::is_pseudo_ref; · 9 unmodified lines
1010 use crate::{
1111 file,
1212 store_impl::{file::loose, packed},
13− BString, FullNameRef, PartialNameCow, Reference,
13+ BStr, BString, FullNameRef, PartialNameCow, Reference,
1414 };
1515
1616 enum Transform {
@@ -161,26 +161,26 @@ impl file::Store { · 144 unmodified lines
161161 }
162162
163163 impl file::Store {
164− fn base_for_name(&self, name: FullNameRef<'_>) -> &Path {
164+ fn base_dir_and_rela_path_for_name<'a>(&self, name: FullNameRef<'a>) -> (&Path, &'a BStr) {
165165 self.common_dir
166166 .as_deref()
167167 .and_then(|commondir| {
168− name.category().map(|c| {
168+ name.category_and_short_name().and_then(|(c, sn)| {
169169 use crate::Category::*;
170− match c {
171− Tag | LocalBranch | RemoteBranch | Note | MainRef | MainPseudoRef | LinkedRef
172− | LinkedPseudoRef => commondir,
173− PseudoRef | Bisect | Rewritten | WorktreePrivate => self.git_dir.as_path(),
174− }
170+ Some(match c {
171+ Tag | LocalBranch | RemoteBranch | Note => (commondir, name.as_bstr()),
172+ MainRef | MainPseudoRef | LinkedRef | LinkedPseudoRef => (commondir, sn),
173+ PseudoRef | Bisect | Rewritten | WorktreePrivate => return None,
174+ })
175175 })
176176 })
177− .unwrap_or(self.git_dir.as_path())
177+ .unwrap_or((self.git_dir.as_path(), name.as_bstr()))
178178 }
179179
180180 /// Implements the logic required to transform a fully qualified refname into a filesystem path
181181 pub(crate) fn reference_path(&self, name: FullNameRef<'_>) -> PathBuf {
182− let base = self.base_for_name(name);
183− let relative_path = git_path::to_native_path_on_windows(name.as_bstr());
182+ let (base, relative_path) = self.base_dir_and_rela_path_for_name(name);
183+ let relative_path = git_path::to_native_path_on_windows(relative_path);
184184 match &self.namespace {
185185 None => base.join(relative_path),
186186 Some(namespace) => base.join(namespace.to_path()).join(relative_path),