-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
467 additions
and
84 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use bstr::BString; | ||
|
||
use crate::{ | ||
extension::{FsMonitor, Signature}, | ||
util::{read_u32, read_u64, split_at_byte_exclusive}, | ||
}; | ||
|
||
pub enum Token { | ||
V1 { nanos_since_1970: u64 }, | ||
V2 { token: BString }, | ||
} | ||
|
||
pub const SIGNATURE: Signature = *b"FSMN"; | ||
|
||
pub fn decode(data: &[u8]) -> Option<FsMonitor> { | ||
let (version, data) = read_u32(data)?; | ||
let (token, data) = match version { | ||
1 => { | ||
let (nanos_since_1970, data) = read_u64(data)?; | ||
(Token::V1 { nanos_since_1970 }, data) | ||
} | ||
2 => { | ||
let (token, data) = split_at_byte_exclusive(data, 0)?; | ||
(Token::V2 { token: token.into() }, data) | ||
} | ||
_ => return None, | ||
}; | ||
|
||
let (ewah_size, data) = read_u32(data)?; | ||
let (entry_dirty, data) = git_bitmap::ewah::decode(&data[..ewah_size as usize]).ok()?; | ||
|
||
if !data.is_empty() { | ||
return None; | ||
} | ||
|
||
FsMonitor { token, entry_dirty }.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use git_repository as git; | ||
|
||
#[cfg(feature = "serde1")] | ||
pub(crate) fn to_json( | ||
mut out: &mut impl std::io::Write, | ||
file: &git::index::File, | ||
entry: &git::index::Entry, | ||
is_last: bool, | ||
) -> anyhow::Result<()> { | ||
use git_repository::bstr::ByteSlice; | ||
|
||
#[cfg_attr(feature = "serde1", derive(serde::Serialize))] | ||
struct Entry<'a> { | ||
stat: &'a git::index::entry::Stat, | ||
hex_id: String, | ||
flags: u32, | ||
mode: u32, | ||
path: std::borrow::Cow<'a, str>, | ||
} | ||
|
||
serde_json::to_writer( | ||
&mut out, | ||
&Entry { | ||
stat: &entry.stat, | ||
hex_id: entry.id.to_hex().to_string(), | ||
flags: entry.flags.bits(), | ||
mode: entry.mode.bits(), | ||
path: entry.path(&file.state).to_str_lossy(), | ||
}, | ||
)?; | ||
|
||
if is_last { | ||
out.write_all(b"\n")?; | ||
} else { | ||
out.write_all(b",\n")?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn to_human( | ||
out: &mut impl std::io::Write, | ||
file: &git::index::File, | ||
entry: &git::index::Entry, | ||
) -> std::io::Result<()> { | ||
writeln!( | ||
out, | ||
"{} {}{:?} {} {}", | ||
match entry.flags.stage() { | ||
0 => "BASE ", | ||
1 => "OURS ", | ||
2 => "THEIRS ", | ||
_ => "UNKNOWN", | ||
}, | ||
if entry.flags.is_empty() { | ||
"".to_string() | ||
} else { | ||
format!("{:?} ", entry.flags) | ||
}, | ||
entry.mode, | ||
entry.id, | ||
entry.path(&file.state) | ||
) | ||
} |
Oops, something went wrong.