A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/GitoxideLabs/gitoxide/commit/43f92b5285af6696cd21f0e94f3bec568aef8468 below:

refactor · GitoxideLabs/gitoxide@43f92b5 · GitHub

1 +

use gix_object::bstr::ByteSlice;

2 +

use gix_path::RelativePath;

1 3

use std::{

2 4

borrow::Cow,

3 5

cmp::Ordering,

@@ -6,9 +8,6 @@ use std::{

6 8

path::{Path, PathBuf},

7 9

};

8 10 9 -

use gix_object::bstr::ByteSlice;

10 -

use gix_path::RelativePath;

11 - 12 11

use crate::{

13 12

file::loose::{self, iter::SortedLoosePaths},

14 13

store_impl::{file, packed},

@@ -85,46 +84,34 @@ impl<'p> LooseThenPacked<'p, '_> {

85 84

}

86 85 87 86

fn convert_loose(&mut self, res: std::io::Result<(PathBuf, FullName)>) -> Result<Reference, Error> {

88 -

convert_loose(&mut self.buf, self.git_dir, self.common_dir, self.namespace, res)

89 -

}

90 -

}

91 - 92 -

pub(crate) fn convert_loose(

93 -

buf: &mut Vec<u8>,

94 -

git_dir: &Path,

95 -

common_dir: Option<&Path>,

96 -

namespace: Option<&Namespace>,

97 -

res: std::io::Result<(PathBuf, FullName)>,

98 -

) -> Result<Reference, Error> {

99 -

let (refpath, name) = res.map_err(Error::Traversal)?;

100 -

std::fs::File::open(&refpath)

101 -

.and_then(|mut f| {

102 -

buf.clear();

103 -

f.read_to_end(buf)

104 -

})

105 -

.map_err(|err| Error::ReadFileContents {

106 -

source: err,

107 -

path: refpath.to_owned(),

108 -

})?;

109 -

loose::Reference::try_from_path(name, buf)

110 -

.map_err(|err| {

111 -

let relative_path = refpath

112 -

.strip_prefix(git_dir)

113 -

.ok()

114 -

.or_else(|| common_dir.and_then(|common_dir| refpath.strip_prefix(common_dir).ok()))

115 -

.expect("one of our bases contains the path");

116 -

Error::ReferenceCreation {

87 +

let buf = &mut self.buf;

88 +

let git_dir = self.git_dir;

89 +

let common_dir = self.common_dir;

90 +

let (refpath, name) = res.map_err(Error::Traversal)?;

91 +

std::fs::File::open(&refpath)

92 +

.and_then(|mut f| {

93 +

buf.clear();

94 +

f.read_to_end(buf)

95 +

})

96 +

.map_err(|err| Error::ReadFileContents {

117 97

source: err,

118 -

relative_path: relative_path.into(),

119 -

}

120 -

})

121 -

.map(Into::into)

122 -

.map(|mut r: Reference| {

123 -

if let Some(namespace) = namespace {

124 -

r.strip_namespace(namespace);

125 -

}

126 -

r

127 -

})

98 +

path: refpath.to_owned(),

99 +

})?;

100 +

loose::Reference::try_from_path(name, buf)

101 +

.map_err(|err| {

102 +

let relative_path = refpath

103 +

.strip_prefix(git_dir)

104 +

.ok()

105 +

.or_else(|| common_dir.and_then(|common_dir| refpath.strip_prefix(common_dir).ok()))

106 +

.expect("one of our bases contains the path");

107 +

Error::ReferenceCreation {

108 +

source: err,

109 +

relative_path: relative_path.into(),

110 +

}

111 +

})

112 +

.map(Into::into)

113 +

.map(|r| self.strip_namespace(r))

114 +

}

128 115

}

129 116 130 117

impl Iterator for LooseThenPacked<'_, '_> {

@@ -203,9 +190,9 @@ impl Iterator for LooseThenPacked<'_, '_> {

203 190

}

204 191 205 192

impl Platform<'_> {

206 -

/// Return an iterator over all references, loose or `packed`, sorted by their name.

193 +

/// Return an iterator over all references, loose or packed, sorted by their name.

207 194

///

208 -

/// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.

195 +

/// Errors are returned similarly to what would happen when loose and packed refs were iterated by themselves.

209 196

pub fn all(&self) -> std::io::Result<LooseThenPacked<'_, '_>> {

210 197

self.store.iter_packed(self.packed.as_ref().map(|b| &***b))

211 198

}

@@ -223,16 +210,17 @@ impl Platform<'_> {

223 210

.iter_prefixed_packed(prefix, self.packed.as_ref().map(|b| &***b))

224 211

}

225 212 226 -

/// Return an iterator over the pseudo references

227 -

pub fn psuedo_refs(&self) -> std::io::Result<LooseThenPacked<'_, '_>> {

228 -

self.store.iter_pseudo_refs()

213 +

/// Return an iterator over the pseudo references, like `HEAD` or `FETCH_HEAD`, or anything else suffixed with `HEAD`

214 +

/// in the root of the `.git` directory, sorted by name.

215 +

pub fn pseudo(&self) -> std::io::Result<LooseThenPacked<'_, '_>> {

216 +

self.store.iter_pseudo()

229 217

}

230 218

}

231 219 232 220

impl file::Store {

233 221

/// Return a platform to obtain iterator over all references, or prefixed ones, loose or packed, sorted by their name.

234 222

///

235 -

/// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.

223 +

/// Errors are returned similarly to what would happen when loose and packed refs were iterated by themselves.

236 224

///

237 225

/// Note that since packed-refs are storing refs as precomposed unicode if [`Self::precompose_unicode`] is true, for consistency

238 226

/// we also return loose references as precomposed unicode.

@@ -271,7 +259,7 @@ pub(crate) enum IterInfo<'a> {

271 259

/// If `true`, we will convert decomposed into precomposed unicode.

272 260

precompose_unicode: bool,

273 261

},

274 -

PseudoRefs {

262 +

Pseudo {

275 263

base: &'a Path,

276 264

precompose_unicode: bool,

277 265

},

@@ -284,7 +272,7 @@ impl<'a> IterInfo<'a> {

284 272

IterInfo::PrefixAndBase { prefix, .. } => Some(gix_path::into_bstr(*prefix)),

285 273

IterInfo::BaseAndIterRoot { prefix, .. } => Some(gix_path::into_bstr(prefix.clone())),

286 274

IterInfo::ComputedIterationRoot { prefix, .. } => Some(prefix.clone()),

287 -

IterInfo::PseudoRefs { .. } => None,

275 +

IterInfo::Pseudo { .. } => None,

288 276

}

289 277

}

290 278

@@ -293,18 +281,18 @@ impl<'a> IterInfo<'a> {

293 281

IterInfo::Base {

294 282

base,

295 283

precompose_unicode,

296 -

} => SortedLoosePaths::at(&base.join("refs"), base.into(), None, None, false, precompose_unicode),

284 +

} => SortedLoosePaths::at(&base.join("refs"), base.into(), None, None, precompose_unicode),

297 285

IterInfo::BaseAndIterRoot {

298 286

base,

299 287

iter_root,

300 288

prefix: _,

301 289

precompose_unicode,

302 -

} => SortedLoosePaths::at(&iter_root, base.into(), None, None, false, precompose_unicode),

290 +

} => SortedLoosePaths::at(&iter_root, base.into(), None, None, precompose_unicode),

303 291

IterInfo::PrefixAndBase {

304 292

base,

305 293

prefix,

306 294

precompose_unicode,

307 -

} => SortedLoosePaths::at(&base.join(prefix), base.into(), None, None, false, precompose_unicode),

295 +

} => SortedLoosePaths::at(&base.join(prefix), base.into(), None, None, precompose_unicode),

308 296

IterInfo::ComputedIterationRoot {

309 297

iter_root,

310 298

base,

@@ -315,13 +303,12 @@ impl<'a> IterInfo<'a> {

315 303

base.into(),

316 304

Some(prefix.into_owned()),

317 305

None,

318 -

false,

319 306

precompose_unicode,

320 307

),

321 -

IterInfo::PseudoRefs {

308 +

IterInfo::Pseudo {

322 309

base,

323 310

precompose_unicode,

324 -

} => SortedLoosePaths::at(base, base.into(), None, Some("HEAD".into()), true, precompose_unicode),

311 +

} => SortedLoosePaths::at(base, base.into(), None, Some("HEAD".into()), precompose_unicode),

325 312

}

326 313

.peekable()

327 314

}

@@ -354,7 +341,7 @@ impl<'a> IterInfo<'a> {

354 341

impl file::Store {

355 342

/// Return an iterator over all references, loose or `packed`, sorted by their name.

356 343

///

357 -

/// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.

344 +

/// Errors are returned similarly to what would happen when loose and packed refs were iterated by themselves.

358 345

pub fn iter_packed<'s, 'p>(

359 346

&'s self,

360 347

packed: Option<&'p packed::Buffer>,

@@ -387,12 +374,13 @@ impl file::Store {

387 374

}

388 375

}

389 376 390 -

/// Return an iterator over all pseudo references, loose or `packed`, sorted by their name.

377 +

/// Return an iterator over the pseudo references, like `HEAD` or `FETCH_HEAD`, or anything else suffixed with `HEAD`

378 +

/// in the root of the `.git` directory, sorted by name.

391 379

///

392 -

/// Errors are returned similarly to what would happen when loose and packed refs where iterated by themselves.

393 -

pub fn iter_pseudo_refs<'p>(&'_ self) -> std::io::Result<LooseThenPacked<'p, '_>> {

380 +

/// Errors are returned similarly to what would happen when loose refs were iterated by themselves.

381 +

pub fn iter_pseudo<'p>(&'_ self) -> std::io::Result<LooseThenPacked<'p, '_>> {

394 382

self.iter_from_info(

395 -

IterInfo::PseudoRefs {

383 +

IterInfo::Pseudo {

396 384

base: self.git_dir(),

397 385

precompose_unicode: self.precompose_unicode,

398 386

},


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4