Skip to content

Commit

Permalink
format-util: add utility to strip SHA1 header
Browse files Browse the repository at this point in the history
Summary: This is used in upcoming changes.

Reviewed By: zzl0

Differential Revision: D64948063

fbshipit-source-id: 6eb05d220d9bcc73daee08415a01046db26017fb
  • Loading branch information
quark-zju authored and facebook-github-bot committed Oct 29, 2024
1 parent c526ec4 commit f40b3a5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions eden/scm/lib/util/format-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! Utilities interacting with store serialization formats (git or hg).
use anyhow::Result;
pub use minibytes::Bytes;
use minibytes::Text;
use types::Id20;

Expand Down Expand Up @@ -60,3 +61,12 @@ pub fn commit_text_to_fields(text: Text, format: SerializationFormat) -> Box<dyn
SerializationFormat::Git => Box::new(GitCommitLazyFields::new(text)),
}
}

/// `sha1_text` includes header like git's type and size, or hg's header like p1, p2.
pub fn strip_sha1_header(sha1_text: &Bytes, format: SerializationFormat) -> Result<Bytes> {
let text = match format {
SerializationFormat::Hg => hg_sha1_deserialize(sha1_text)?.0,
SerializationFormat::Git => git_sha1_deserialize(sha1_text)?.0,
};
Ok(sha1_text.slice_to_bytes(text))
}

0 comments on commit f40b3a5

Please sign in to comment.