git_index/extension/
fs_monitor.rs1use bstr::BString;
2
3use crate::{
4 extension::{FsMonitor, Signature},
5 util::{read_u32, read_u64, split_at_byte_exclusive},
6};
7
8#[derive(Clone)]
9pub enum Token {
10 V1 { nanos_since_1970: u64 },
11 V2 { token: BString },
12}
13
14pub const SIGNATURE: Signature = *b"FSMN";
15
16pub fn decode(data: &[u8]) -> Option<FsMonitor> {
17 let (version, data) = read_u32(data)?;
18 let (token, data) = match version {
19 1 => {
20 let (nanos_since_1970, data) = read_u64(data)?;
21 (Token::V1 { nanos_since_1970 }, data)
22 }
23 2 => {
24 let (token, data) = split_at_byte_exclusive(data, 0)?;
25 (Token::V2 { token: token.into() }, data)
26 }
27 _ => return None,
28 };
29
30 let (ewah_size, data) = read_u32(data)?;
31 let (entry_dirty, data) = git_bitmap::ewah::decode(&data[..ewah_size as usize]).ok()?;
32
33 if !data.is_empty() {
34 return None;
35 }
36
37 FsMonitor { token, entry_dirty }.into()
38}