From 41e0562132b654b910754cc58184f46164ce92ee Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Tue, 29 Oct 2024 15:53:48 -0700 Subject: [PATCH] commits: support git commit text in more places Summary: By searching `::len` I found a few other places that need change to support the Git format. Reviewed By: zzl0 Differential Revision: D64948069 fbshipit-source-id: 8bd632438a8bd64c72affc9a567a75f63545555f --- eden/scm/lib/commits/src/hybrid.rs | 6 +++++- eden/scm/lib/commits/src/on_disk_commits.rs | 13 +++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/eden/scm/lib/commits/src/hybrid.rs b/eden/scm/lib/commits/src/hybrid.rs index f2b5857899671..cabb96a43a873 100644 --- a/eden/scm/lib/commits/src/hybrid.rs +++ b/eden/scm/lib/commits/src/hybrid.rs @@ -29,6 +29,7 @@ use edenapi::types::CommitLocationToHashRequest; use edenapi::SaplingRemoteApi; use format_util::git_sha1_serialize; use format_util::hg_sha1_deserialize; +use format_util::strip_sha1_header; use futures::stream; use futures::stream::BoxStream; use futures::stream::StreamExt; @@ -476,7 +477,10 @@ impl HybridResolver for Resolver { return Ok(Some(Bytes::new())); } match self.zstore.read().get(id)? { - Some(bytes) => Ok(Some(bytes.slice(Id20::len() * 2..))), + Some(bytes) => { + let text = strip_sha1_header(&bytes, self.format)?; + Ok(Some(text)) + } None => Ok(crate::revlog::get_hard_coded_commit_text(vertex)), } } diff --git a/eden/scm/lib/commits/src/on_disk_commits.rs b/eden/scm/lib/commits/src/on_disk_commits.rs index 46f77cebe522a..a150c772704a3 100644 --- a/eden/scm/lib/commits/src/on_disk_commits.rs +++ b/eden/scm/lib/commits/src/on_disk_commits.rs @@ -22,10 +22,9 @@ use dag::Group; use dag::Set; use dag::Vertex; use dag::VertexListWithOptions; -use format_util::git_sha1_deserialize; use format_util::git_sha1_serialize; -use format_util::hg_sha1_deserialize; use format_util::hg_sha1_serialize; +use format_util::strip_sha1_header; use futures::stream::BoxStream; use futures::stream::StreamExt; use minibytes::Bytes; @@ -207,11 +206,8 @@ fn get_commit_raw_text( let id = Id20::from_slice(vertex.as_ref())?; match store.get(id)? { Some(bytes) => { - let raw_text = match format { - SerializationFormat::Hg => hg_sha1_deserialize(bytes.as_ref())?.0, - SerializationFormat::Git => git_sha1_deserialize(bytes.as_ref())?.0, - }; - Ok(Some(bytes.slice_to_bytes(raw_text))) + let raw_text = strip_sha1_header(&bytes, format)?; + Ok(Some(raw_text)) } None => Ok(crate::revlog::get_hard_coded_commit_text(vertex)), } @@ -223,6 +219,7 @@ impl StreamCommitText for OnDiskCommits { stream: BoxStream<'static, anyhow::Result>, ) -> Result>> { let zstore = Zstore::open(&self.commits_path)?; + let format = self.format; let stream = stream.map(move |item| { let vertex = item?; let id = Id20::from_slice(vertex.as_ref())?; @@ -231,7 +228,7 @@ impl StreamCommitText for OnDiskCommits { Default::default() } else { match zstore.get(id)? { - Some(raw_data) => raw_data.slice(Id20::len() * 2..), + Some(raw_data) => strip_sha1_header(&raw_data, format)?, None => return vertex.not_found().map_err(Into::into), } };