Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 13, 2023
1 parent 03c3afa commit c3e0b00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/git/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::{git_oid_type, GitObjectId, GitOid};
use crate::libgit::{FileMode, RawTree};
use crate::oid::ObjectId;
use crate::tree_util::{Empty, MayRecurse, ParseTree, RecurseAs, TreeIter, WithPath};
use crate::util::{FromBytes, SliceExt};
use crate::util::SliceExt;

git_oid_type!(TreeId(GitObjectId));

Expand Down Expand Up @@ -68,9 +68,20 @@ impl ParseTree for RawTree {

fn parse_one_entry(buf: &mut &[u8]) -> Result<WithPath<Self::Inner>, Self::Error> {
(|| {
let [mode, remainder] = buf.splitn_exact(b' ')?;
let mode = FileMode::from_bytes(mode).ok()?;
let [path, remainder] = remainder.splitn_exact(b'\0')?;
let mut mode = 0u16;
let mut bytes = buf.iter();
for b in &mut bytes {
match b {
b' ' => break,
b'0'..=b'7' => {
mode <<= 3;
mode += (b - b'0') as u16;
}
_ => return None,
}
}
let mode = FileMode::from(mode);
let [path, remainder] = bytes.as_slice().splitn_exact(b'\0')?;
if path.is_empty() {
return None;
}
Expand Down
6 changes: 6 additions & 0 deletions src/libgit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@ impl From<FileMode> for u16 {
}
}

impl From<u16> for FileMode {
fn from(value: u16) -> Self {
FileMode(value)
}
}

impl FromBytes for FileMode {
type Err = ParseIntError;

Expand Down

0 comments on commit c3e0b00

Please sign in to comment.