Skip to content

Commit e18a2fd

Browse files
committed
'link' extension decoding to the point where bitmaps are needed (#293)
1 parent 8971991 commit e18a2fd

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

git-index/src/extension/decode.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ mod error {
1515
MandatoryUnimplemented(signature: extension::Signature) {
1616
display("Encountered mandatory extension '{}' which isn't implemented yet", String::from_utf8_lossy(signature))
1717
}
18+
Link(err: extension::link::decode::Error) {
19+
display("Could not parse mandatory link extension")
20+
source(err)
21+
from()
22+
}
1823
}
1924
}
2025
}
@@ -35,7 +40,7 @@ pub fn all(maybe_beginning_of_extensions: &[u8], object_hash: git_hash::Kind) ->
3540
extension::end_of_index_entry::SIGNATURE => {} // skip already done
3641
extension::index_entry_offset_table::SIGNATURE => {} // not relevant/obtained already
3742
mandatory if mandatory[0].is_ascii_lowercase() => match mandatory {
38-
extension::link::SIGNATURE => ext.link = extension::link::decode(ext_data, object_hash),
43+
extension::link::SIGNATURE => ext.link = extension::link::decode(ext_data, object_hash)?.into(),
3944
unknown => return Err(Error::MandatoryUnimplemented(unknown)),
4045
},
4146
_unknown => {} // skip unknown extensions, too

git-index/src/extension/mod.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Tree {
2121
}
2222

2323
pub struct Link {
24-
shared_index_checksum: git_hash::ObjectId,
24+
pub shared_index_checksum: git_hash::ObjectId,
2525
}
2626

2727
mod iter;
@@ -34,11 +34,37 @@ pub(crate) mod end_of_index_entry;
3434

3535
pub(crate) mod index_entry_offset_table;
3636

37-
pub(crate) mod link {
37+
pub mod link {
3838
use crate::extension::{Link, Signature};
39+
use crate::util::split_at_pos;
40+
3941
pub const SIGNATURE: Signature = *b"link";
4042

41-
pub fn decode(_data: &[u8], _object_hash: git_hash::Kind) -> Option<Link> {
42-
todo!("decode link")
43+
pub mod decode {
44+
use quick_error::quick_error;
45+
46+
quick_error! {
47+
#[derive(Debug)]
48+
pub enum Error {
49+
Corrupt(message: &'static str) {
50+
display("{}", message)
51+
}
52+
}
53+
}
54+
}
55+
56+
pub fn decode(data: &[u8], object_hash: git_hash::Kind) -> Result<Link, decode::Error> {
57+
let (id, data) = split_at_pos(data, object_hash.len_in_bytes())
58+
.ok_or(decode::Error::Corrupt(
59+
"link extension too short to read share index checksum",
60+
))
61+
.map(|(id, d)| (git_hash::ObjectId::from(id), d))?;
62+
63+
if data.is_empty() {
64+
return Ok(Link {
65+
shared_index_checksum: id,
66+
});
67+
}
68+
todo!("decode link bitmaps")
4369
}
4470
}

0 commit comments

Comments
 (0)