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
10use crate::{10use crate::{
11 file,11 file,
12 store_impl::{file::loose, packed},12 store_impl::{file::loose, packed},
13 BString, FullNameRef, PartialNameCow, Reference,13 BStr, BString, FullNameRef, PartialNameCow, Reference,
14};14};
15 15
16enum Transform {16enum Transform {
@@ -161,26 +161,26 @@ impl file::Store { · 144 unmodified lines
161}161}
162 162
163impl file::Store {163impl 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) {
165 self.common_dir165 self.common_dir
166 .as_deref()166 .as_deref()
167 .and_then(|commondir| {167 .and_then(|commondir| {
168 name.category().map(|c| {168 name.category_and_short_name().and_then(|(c, sn)| {
169 use crate::Category::*;169 use crate::Category::*;
170 match c {170 Some(match c {
171 Tag | LocalBranch | RemoteBranch | Note | MainRef | MainPseudoRef | LinkedRef171 Tag | LocalBranch | RemoteBranch | Note => (commondir, name.as_bstr()),
172 | LinkedPseudoRef => commondir,172 MainRef | MainPseudoRef | LinkedRef | LinkedPseudoRef => (commondir, sn),
173 PseudoRef | Bisect | Rewritten | WorktreePrivate => self.git_dir.as_path(),173 PseudoRef | Bisect | Rewritten | WorktreePrivate => return None,
174 }174 })
175 })175 })
176 })176 })
177 .unwrap_or(self.git_dir.as_path())177 .unwrap_or((self.git_dir.as_path(), name.as_bstr()))
178 }178 }
179 179
180 /// Implements the logic required to transform a fully qualified refname into a filesystem path180 /// Implements the logic required to transform a fully qualified refname into a filesystem path
181 pub(crate) fn reference_path(&self, name: FullNameRef<'_>) -> PathBuf {181 pub(crate) fn reference_path(&self, name: FullNameRef<'_>) -> PathBuf {
182 let base = self.base_for_name(name);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(name.as_bstr());183 let relative_path = git_path::to_native_path_on_windows(relative_path);
184 match &self.namespace {184 match &self.namespace {
185 None => base.join(relative_path),185 None => base.join(relative_path),
186 Some(namespace) => base.join(namespace.to_path()).join(relative_path),186 Some(namespace) => base.join(namespace.to_path()).join(relative_path),