Skip to content

Commit f1d7c1c

Browse files
author
Sidney Douw
committed
generate index header
1 parent 085e76b commit f1d7c1c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

git-index/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub mod decode;
2222

2323
pub mod verify;
2424

25+
pub mod write;
26+
2527
/// All known versions of a git index file.
2628
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
2729
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]

git-index/src/write.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use bstr::{BString, ByteVec};
2+
3+
use crate::Version;
4+
5+
pub fn header(version: Version, num_entries: i32) -> BString {
6+
let mut header = BString::from("");
7+
8+
const SIGNATURE: &[u8; 4] = b"DIRC";
9+
10+
let version = match version {
11+
Version::V2 => 2_i32.to_be_bytes(),
12+
Version::V3 => 3_i32.to_be_bytes(),
13+
Version::V4 => 4_i32.to_be_bytes(),
14+
};
15+
16+
header.push_str(SIGNATURE);
17+
header.push_str(version);
18+
header.push_str(num_entries.to_be_bytes());
19+
20+
header
21+
}

0 commit comments

Comments
 (0)