backend: make Vec inside CommitId non-public

The recent e5dd93cbf7, whose description says "cleanup: make Vec
inside CommitId etc. non-public", made all ID types in the `backend`
module *except* for `CommitId` non-public :P This patch makes
This commit is contained in:
Martin von Zweigbergk 2021-11-17 14:20:54 -08:00
parent d34060f013
commit 8cf5dd286a
13 changed files with 127 additions and 88 deletions

View File

@ -23,7 +23,7 @@ use thiserror::Error;
use crate::repo_path::{RepoPath, RepoPathComponent};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct CommitId(pub Vec<u8>);
pub struct CommitId(Vec<u8>);
impl Debug for CommitId {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
@ -44,6 +44,10 @@ impl CommitId {
&self.0
}
pub fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
pub fn from_hex(hex: &str) -> Self {
Self(hex::decode(hex).unwrap())
}
@ -75,6 +79,10 @@ impl ChangeId {
&self.0
}
pub fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
pub fn from_hex(hex: &str) -> Self {
Self(hex::decode(hex).unwrap())
}
@ -98,10 +106,18 @@ impl TreeId {
Self(value)
}
pub fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
pub fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
pub fn hex(&self) -> String {
hex::encode(&self.0)
}
@ -121,10 +137,18 @@ impl FileId {
Self(value)
}
pub fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
pub fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
pub fn hex(&self) -> String {
hex::encode(&self.0)
}
@ -144,10 +168,18 @@ impl SymlinkId {
Self(value)
}
pub fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
pub fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
pub fn hex(&self) -> String {
hex::encode(&self.0)
}
@ -167,10 +199,18 @@ impl ConflictId {
Self(value)
}
pub fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
pub fn to_bytes(&self) -> Vec<u8> {
self.0.clone()
}
pub fn hex(&self) -> String {
hex::encode(&self.0)
}

View File

@ -31,8 +31,9 @@ pub struct CommitBuilder {
}
pub fn new_change_id() -> ChangeId {
ChangeId::new(Uuid::new_v4().as_bytes().to_vec())
ChangeId::from_bytes(Uuid::new_v4().as_bytes())
}
pub fn signature(settings: &UserSettings) -> Signature {
// TODO: check if it's slow to get the timezone etc for every signature
let timestamp = Timestamp::now();

View File

@ -72,7 +72,7 @@ pub fn import_refs(
continue;
}
};
let id = CommitId(git_commit.id().as_bytes().to_vec());
let id = CommitId::from_bytes(git_commit.id().as_bytes());
let commit = store.get_commit(&id).unwrap();
mut_repo.add_head(&commit);
// TODO: Make it configurable which remotes are publishing and update public
@ -225,7 +225,7 @@ pub fn push_updates(
let temp_ref_name = format!("refs/jj/git-push/{}", new_target.hex());
temp_refs.push(git_repo.reference(
&temp_ref_name,
git2::Oid::from_bytes(&new_target.0).unwrap(),
git2::Oid::from_bytes(new_target.as_bytes()).unwrap(),
true,
"temporary reference for git push",
)?);

View File

@ -159,9 +159,9 @@ fn signature_to_git(signature: &Signature) -> git2::Signature {
fn serialize_extras(commit: &Commit) -> Vec<u8> {
let mut proto = crate::protos::store::Commit::new();
proto.is_open = commit.is_open;
proto.change_id = commit.change_id.as_bytes().to_vec();
proto.change_id = commit.change_id.to_bytes();
for predecessor in &commit.predecessors {
proto.predecessors.push(predecessor.as_bytes().to_vec());
proto.predecessors.push(predecessor.to_bytes());
}
proto.write_to_bytes().unwrap()
}
@ -172,7 +172,7 @@ fn deserialize_extras(commit: &mut Commit, bytes: &[u8]) {
commit.is_open = proto.is_open;
commit.change_id = ChangeId::new(proto.change_id);
for predecessor in &proto.predecessors {
commit.predecessors.push(CommitId(predecessor.clone()));
commit.predecessors.push(CommitId::from_bytes(predecessor));
}
}
@ -265,18 +265,16 @@ impl Backend for GitBackend {
let name = entry.name().unwrap();
let (name, value) = match entry.kind().unwrap() {
git2::ObjectType::Tree => {
let id = TreeId::new(entry.id().as_bytes().to_vec());
let id = TreeId::from_bytes(entry.id().as_bytes());
(entry.name().unwrap(), TreeValue::Tree(id))
}
git2::ObjectType::Blob => match entry.filemode() {
0o100644 => {
let id = FileId::new(entry.id().as_bytes().to_vec());
let id = FileId::from_bytes(entry.id().as_bytes());
if name.ends_with(CONFLICT_SUFFIX) {
(
&name[0..name.len() - CONFLICT_SUFFIX.len()],
TreeValue::Conflict(ConflictId::new(
entry.id().as_bytes().to_vec(),
)),
TreeValue::Conflict(ConflictId::from_bytes(entry.id().as_bytes())),
)
} else {
(
@ -289,7 +287,7 @@ impl Backend for GitBackend {
}
}
0o100755 => {
let id = FileId::new(entry.id().as_bytes().to_vec());
let id = FileId::from_bytes(entry.id().as_bytes());
(
name,
TreeValue::Normal {
@ -299,13 +297,13 @@ impl Backend for GitBackend {
)
}
0o120000 => {
let id = SymlinkId::new(entry.id().as_bytes().to_vec());
let id = SymlinkId::from_bytes(entry.id().as_bytes());
(name, TreeValue::Symlink(id))
}
mode => panic!("unexpected file mode {:?}", mode),
},
git2::ObjectType::Commit => {
let id = CommitId(entry.id().as_bytes().to_vec());
let id = CommitId::from_bytes(entry.id().as_bytes());
(name, TreeValue::GitSubmodule(id))
}
kind => panic!("unexpected object type {:?}", kind),
@ -343,7 +341,7 @@ impl Backend for GitBackend {
.unwrap();
}
let oid = builder.write().unwrap();
Ok(TreeId::new(oid.as_bytes().to_vec()))
Ok(TreeId::from_bytes(oid.as_bytes()))
}
fn read_commit(&self, id: &CommitId) -> BackendResult<Commit> {
@ -369,9 +367,9 @@ impl Backend for GitBackend {
);
let parents = commit
.parent_ids()
.map(|oid| CommitId::new(oid.as_bytes().to_vec()))
.map(|oid| CommitId::from_bytes(oid.as_bytes()))
.collect_vec();
let tree_id = TreeId::new(commit.tree_id().as_bytes().to_vec());
let tree_id = TreeId::from_bytes(commit.tree_id().as_bytes());
let description = commit.message().unwrap_or("<no message>").to_owned();
let author = signature_from_git(commit.author());
let committer = signature_from_git(commit.committer());
@ -420,7 +418,7 @@ impl Backend for GitBackend {
&git_tree,
&parent_refs,
)?;
let id = CommitId(git_id.as_bytes().to_vec());
let id = CommitId::from_bytes(git_id.as_bytes());
let extras = serialize_extras(contents);
let mut mut_table = self
.extra_metadata_store
@ -443,7 +441,7 @@ impl Backend for GitBackend {
fn read_conflict(&self, id: &ConflictId) -> BackendResult<Conflict> {
let mut file = self.read_file(
&RepoPath::from_internal_string("unused"),
&FileId::new(id.as_bytes().to_vec()),
&FileId::new(id.to_bytes()),
)?;
let mut data = String::new();
file.read_to_string(&mut data)?;
@ -463,7 +461,7 @@ impl Backend for GitBackend {
let bytes = json_string.as_bytes();
let locked_repo = self.repo.lock().unwrap();
let oid = locked_repo.blob(bytes).unwrap();
Ok(ConflictId::new(oid.as_bytes().to_vec()))
Ok(ConflictId::from_bytes(oid.as_bytes()))
}
}
@ -590,7 +588,7 @@ mod tests {
// The change id is the leading reverse bits of the commit id
let change_id = ChangeId::from_hex("c64ee0b6e16777fe53991f9281a6cd25");
// Check that the git commit above got the hash we expect
assert_eq!(git_commit_id.as_bytes(), &commit_id.0);
assert_eq!(git_commit_id.as_bytes(), commit_id.as_bytes());
let store = GitBackend::init_external(store_path, git_repo_path);
let commit = store.read_commit(&commit_id).unwrap();
@ -618,7 +616,7 @@ mod tests {
let root_tree = store
.read_tree(
&RepoPath::root(),
&TreeId::new(root_tree_id.as_bytes().to_vec()),
&TreeId::from_bytes(root_tree_id.as_bytes()),
)
.unwrap();
let mut root_entries = root_tree.entries();
@ -627,13 +625,13 @@ mod tests {
assert_eq!(dir.name().as_str(), "dir");
assert_eq!(
dir.value(),
&TreeValue::Tree(TreeId::new(dir_tree_id.as_bytes().to_vec()))
&TreeValue::Tree(TreeId::from_bytes(dir_tree_id.as_bytes()))
);
let dir_tree = store
.read_tree(
&RepoPath::from_internal_string("dir"),
&TreeId::new(dir_tree_id.as_bytes().to_vec()),
&TreeId::from_bytes(dir_tree_id.as_bytes()),
)
.unwrap();
let mut files = dir_tree.entries();
@ -644,14 +642,14 @@ mod tests {
assert_eq!(
normal_file.value(),
&TreeValue::Normal {
id: FileId::new(blob1.as_bytes().to_vec()),
id: FileId::from_bytes(blob1.as_bytes()),
executable: false
}
);
assert_eq!(symlink.name().as_str(), "symlink");
assert_eq!(
symlink.value(),
&TreeValue::Symlink(SymlinkId::new(blob2.as_bytes().to_vec()))
&TreeValue::Symlink(SymlinkId::from_bytes(blob2.as_bytes()))
);
}
@ -685,7 +683,10 @@ mod tests {
.unwrap()
.map(|git_ref| git_ref.unwrap().target().unwrap())
.collect_vec();
assert_eq!(git_refs, vec![Oid::from_bytes(&commit_id.0).unwrap()]);
assert_eq!(
git_refs,
vec![Oid::from_bytes(commit_id.as_bytes()).unwrap()]
);
}
#[test]

View File

@ -181,7 +181,7 @@ impl CommitGraphEntry<'_> {
}
fn commit_id(&self) -> CommitId {
CommitId(self.data[36..36 + self.hash_length].to_vec())
CommitId::from_bytes(&self.data[36..36 + self.hash_length])
}
}
@ -196,7 +196,7 @@ impl CommitLookupEntry<'_> {
}
fn commit_id(&self) -> CommitId {
CommitId(self.data[0..self.hash_length].to_vec())
CommitId::from_bytes(&self.data[0..self.hash_length])
}
fn pos(&self) -> IndexPosition {
@ -278,16 +278,16 @@ impl HexPrefix {
pub fn bytes_prefixes(&self) -> (CommitId, CommitId) {
if self.0.len() % 2 == 0 {
let bytes = hex::decode(&self.0).unwrap();
(CommitId(bytes.clone()), CommitId(bytes))
(CommitId::new(bytes.clone()), CommitId::new(bytes))
} else {
let min_bytes = hex::decode(&(self.0.clone() + "0")).unwrap();
let prefix = min_bytes[0..min_bytes.len() - 1].to_vec();
(CommitId(prefix), CommitId(min_bytes))
(CommitId::new(prefix), CommitId::new(min_bytes))
}
}
pub fn matches(&self, id: &CommitId) -> bool {
hex::encode(&id.0).starts_with(&self.0)
id.hex().starts_with(&self.0)
}
}
@ -1088,7 +1088,7 @@ impl IndexSegment for ReadonlyIndex {
for i in lookup_pos.0..self.num_local_commits as u32 {
let entry = self.lookup_entry(i);
let id = entry.commit_id();
if !id.0.starts_with(&bytes_prefix.0) {
if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) {
break;
}
if prefix.matches(&id) {
@ -1180,7 +1180,7 @@ impl IndexSegment for MutableIndex {
break;
}
Some((id, _pos)) => {
if !id.0.starts_with(&bytes_prefix.0) {
if !id.as_bytes().starts_with(bytes_prefix.as_bytes()) {
break;
}
if prefix.matches(id) {
@ -1447,7 +1447,7 @@ impl ReadonlyIndex {
let mid = (low + high) / 2;
let entry = self.lookup_entry(mid);
let entry_commit_id = entry.commit_id();
let entry_prefix = &entry_commit_id.0[0..prefix_len];
let entry_prefix = &entry_commit_id.as_bytes()[0..prefix_len];
if high == low {
return Some(IndexPosition(mid));
}

View File

@ -242,13 +242,13 @@ impl Backend for LocalBackend {
pub fn commit_to_proto(commit: &Commit) -> crate::protos::store::Commit {
let mut proto = crate::protos::store::Commit::new();
for parent in &commit.parents {
proto.parents.push(parent.as_bytes().to_vec());
proto.parents.push(parent.to_bytes());
}
for predecessor in &commit.predecessors {
proto.predecessors.push(predecessor.as_bytes().to_vec());
proto.predecessors.push(predecessor.to_bytes());
}
proto.set_root_tree(commit.root_tree.as_bytes().to_vec());
proto.set_change_id(commit.change_id.as_bytes().to_vec());
proto.set_root_tree(commit.root_tree.to_bytes());
proto.set_change_id(commit.change_id.to_bytes());
proto.set_description(commit.description.clone());
proto.set_author(signature_to_proto(&commit.author));
proto.set_committer(signature_to_proto(&commit.committer));
@ -303,21 +303,21 @@ fn tree_value_to_proto(value: &TreeValue) -> crate::protos::store::TreeValue {
match value {
TreeValue::Normal { id, executable } => {
let mut file = crate::protos::store::TreeValue_NormalFile::new();
file.set_id(id.as_bytes().to_vec());
file.set_id(id.to_bytes());
file.set_executable(*executable);
proto.set_normal_file(file);
}
TreeValue::Symlink(id) => {
proto.set_symlink_id(id.as_bytes().to_vec());
proto.set_symlink_id(id.to_bytes());
}
TreeValue::GitSubmodule(_id) => {
panic!("cannot store git submodules");
}
TreeValue::Tree(id) => {
proto.set_tree_id(id.as_bytes().to_vec());
proto.set_tree_id(id.to_bytes());
}
TreeValue::Conflict(id) => {
proto.set_conflict_id(id.as_bytes().to_vec());
proto.set_conflict_id(id.to_bytes());
}
};
proto

View File

@ -74,7 +74,7 @@ fn resolve_branch(repo: RepoRef, symbol: &str) -> Result<Vec<CommitId>, RevsetEr
fn resolve_commit_id(repo: RepoRef, symbol: &str) -> Result<Vec<CommitId>, RevsetError> {
// First check if it's a full commit id.
if let Ok(binary_commit_id) = hex::decode(symbol) {
let commit_id = CommitId(binary_commit_id);
let commit_id = CommitId::new(binary_commit_id);
match repo.store().get_commit(&commit_id) {
Ok(_) => return Ok(vec![commit_id]),
Err(BackendError::NotFound) => {} // fall through

View File

@ -93,10 +93,7 @@ pub fn back_out_commit(
// TODO: i18n the description based on repo language
CommitBuilder::for_new_commit(settings, store, new_tree_id)
.set_parents(new_parent_ids)
.set_description(format!(
"backout of commit {}",
hex::encode(&old_commit.id().0)
))
.set_description(format!("backout of commit {}", &old_commit.id().hex()))
.write_to_repo(mut_repo)
}

View File

@ -200,12 +200,12 @@ fn operation_from_proto(proto: &crate::protos::op_store::Operation) -> Operation
fn view_to_proto(view: &View) -> crate::protos::op_store::View {
let mut proto = crate::protos::op_store::View::new();
proto.checkout = view.checkout.0.clone();
proto.checkout = view.checkout.to_bytes();
for head_id in &view.head_ids {
proto.head_ids.push(head_id.0.clone());
proto.head_ids.push(head_id.to_bytes());
}
for head_id in &view.public_head_ids {
proto.public_head_ids.push(head_id.0.clone());
proto.public_head_ids.push(head_id.to_bytes());
}
for (name, target) in &view.branches {
@ -241,13 +241,13 @@ fn view_to_proto(view: &View) -> crate::protos::op_store::View {
}
fn view_from_proto(proto: &crate::protos::op_store::View) -> View {
let mut view = View::new(CommitId(proto.checkout.clone()));
let mut view = View::new(CommitId::new(proto.checkout.clone()));
for head_id_bytes in proto.head_ids.iter() {
view.head_ids.insert(CommitId(head_id_bytes.to_vec()));
view.head_ids.insert(CommitId::from_bytes(head_id_bytes));
}
for head_id_bytes in proto.public_head_ids.iter() {
view.public_head_ids
.insert(CommitId(head_id_bytes.to_vec()));
.insert(CommitId::from_bytes(head_id_bytes));
}
for branch_proto in proto.branches.iter() {
@ -290,7 +290,7 @@ fn view_from_proto(proto: &crate::protos::op_store::View) -> View {
// Legacy format
view.git_refs.insert(
git_ref.name.clone(),
RefTarget::Normal(CommitId(git_ref.commit_id.to_vec())),
RefTarget::Normal(CommitId::new(git_ref.commit_id.clone())),
);
}
}
@ -302,15 +302,15 @@ fn ref_target_to_proto(value: &RefTarget) -> crate::protos::op_store::RefTarget
let mut proto = crate::protos::op_store::RefTarget::new();
match value {
RefTarget::Normal(id) => {
proto.set_commit_id(id.0.clone());
proto.set_commit_id(id.to_bytes());
}
RefTarget::Conflict { removes, adds } => {
let mut ref_conflict_proto = crate::protos::op_store::RefConflict::new();
for id in removes {
ref_conflict_proto.removes.push(id.0.clone());
ref_conflict_proto.removes.push(id.to_bytes());
}
for id in adds {
ref_conflict_proto.adds.push(id.0.clone());
ref_conflict_proto.adds.push(id.to_bytes());
}
proto.set_conflict(ref_conflict_proto);
}
@ -321,18 +321,18 @@ fn ref_target_to_proto(value: &RefTarget) -> crate::protos::op_store::RefTarget
fn ref_target_from_proto(proto: &crate::protos::op_store::RefTarget) -> RefTarget {
match proto.value.as_ref().unwrap() {
crate::protos::op_store::RefTarget_oneof_value::commit_id(id) => {
RefTarget::Normal(CommitId(id.to_vec()))
RefTarget::Normal(CommitId::from_bytes(id))
}
crate::protos::op_store::RefTarget_oneof_value::conflict(conflict) => {
let removes = conflict
.removes
.iter()
.map(|id_bytes| CommitId(id_bytes.to_vec()))
.map(|id_bytes| CommitId::from_bytes(id_bytes))
.collect_vec();
let adds = conflict
.adds
.iter()
.map(|id_bytes| CommitId(id_bytes.to_vec()))
.map(|id_bytes| CommitId::from_bytes(id_bytes))
.collect_vec();
RefTarget::Conflict { removes, adds }
}
@ -349,20 +349,20 @@ mod tests {
fn test_read_write_view() {
let temp_dir = TempDir::new().unwrap();
let store = SimpleOpStore::init(temp_dir.path().to_owned());
let head_id1 = CommitId(b"aaa111".to_vec());
let head_id2 = CommitId(b"aaa222".to_vec());
let public_head_id1 = CommitId(b"bbb444".to_vec());
let public_head_id2 = CommitId(b"bbb555".to_vec());
let branch_main_local_target = RefTarget::Normal(CommitId(b"ccc111".to_vec()));
let branch_main_origin_target = RefTarget::Normal(CommitId(b"ccc222".to_vec()));
let branch_deleted_origin_target = RefTarget::Normal(CommitId(b"ccc333".to_vec()));
let tag_v1_target = RefTarget::Normal(CommitId(b"ddd111".to_vec()));
let git_refs_main_target = RefTarget::Normal(CommitId(b"fff111".to_vec()));
let head_id1 = CommitId::from_hex("aaa111");
let head_id2 = CommitId::from_hex("aaa222");
let public_head_id1 = CommitId::from_hex("bbb444");
let public_head_id2 = CommitId::from_hex("bbb555");
let branch_main_local_target = RefTarget::Normal(CommitId::from_hex("ccc111"));
let branch_main_origin_target = RefTarget::Normal(CommitId::from_hex("ccc222"));
let branch_deleted_origin_target = RefTarget::Normal(CommitId::from_hex("ccc333"));
let tag_v1_target = RefTarget::Normal(CommitId::from_hex("ddd111"));
let git_refs_main_target = RefTarget::Normal(CommitId::from_hex("fff111"));
let git_refs_feature_target = RefTarget::Conflict {
removes: vec![CommitId(b"fff111".to_vec())],
adds: vec![CommitId(b"fff222".to_vec()), CommitId(b"fff333".to_vec())],
removes: vec![CommitId::from_hex("fff111")],
adds: vec![CommitId::from_hex("fff222"), CommitId::from_hex("fff333")],
};
let checkout_id = CommitId(b"abc111".to_vec());
let checkout_id = CommitId::from_hex("abc111");
let view = View {
head_ids: hashset! {head_id1, head_id2},
public_head_ids: hashset! {public_head_id1, public_head_id2},

View File

@ -41,7 +41,7 @@ pub struct Store {
impl Store {
fn new(backend: Box<dyn Backend>) -> Arc<Self> {
let root_commit_id = CommitId(vec![0; backend.hash_length()]);
let root_commit_id = CommitId::new(vec![0; backend.hash_length()]);
Arc::new(Store {
backend,
root_commit_id,

View File

@ -111,7 +111,7 @@ fn file_state_to_proto(file_state: &FileState) -> crate::protos::working_copy::F
FileType::Normal { executable: true } => crate::protos::working_copy::FileType::Executable,
FileType::Symlink => crate::protos::working_copy::FileType::Symlink,
FileType::Conflict { id } => {
proto.conflict_id = id.as_bytes().to_vec();
proto.conflict_id = id.to_bytes();
crate::protos::working_copy::FileType::Conflict
}
};
@ -262,7 +262,7 @@ impl TreeState {
fn save(&mut self) {
let mut proto = crate::protos::working_copy::TreeState::new();
proto.tree_id = self.tree_id.as_bytes().to_vec();
proto.tree_id = self.tree_id.to_bytes();
for (file, file_state) in &self.file_states {
proto.file_states.insert(
file.to_internal_file_string(),
@ -755,7 +755,7 @@ impl WorkingCopy {
pub fn current_commit_id(&self) -> CommitId {
if self.commit_id.borrow().is_none() {
let proto = self.read_proto();
let commit_id = CommitId(proto.commit_id);
let commit_id = CommitId::new(proto.commit_id);
self.commit_id.replace(Some(commit_id));
}
@ -804,7 +804,7 @@ impl WorkingCopy {
fn save(&mut self) {
let mut proto = crate::protos::working_copy::Checkout::new();
proto.commit_id = self.current_commit_id().0;
proto.commit_id = self.current_commit_id().to_bytes();
self.write_proto(proto);
}
@ -826,7 +826,7 @@ impl WorkingCopy {
// need for it.
let current_proto = self.read_proto();
if let Some(commit_id_at_read_time) = self.commit_id.borrow().as_ref() {
if current_proto.commit_id != commit_id_at_read_time.0 {
if current_proto.commit_id != commit_id_at_read_time.as_bytes() {
return Err(CheckoutError::ConcurrentCheckout);
}
}
@ -851,7 +851,7 @@ impl WorkingCopy {
let current_proto = self.read_proto();
self.commit_id
.replace(Some(CommitId(current_proto.commit_id)));
.replace(Some(CommitId::new(current_proto.commit_id)));
self.tree_state().as_mut().unwrap().write_tree();
LockedWorkingCopy {

View File

@ -49,7 +49,7 @@ fn empty_git_commit<'r>(
}
fn commit_id(commit: &git2::Commit) -> CommitId {
CommitId(commit.id().as_bytes().to_vec())
CommitId::from_bytes(commit.id().as_bytes())
}
#[test]
@ -454,7 +454,7 @@ fn test_push_updates_success() {
.find_reference("refs/heads/main")
.unwrap()
.target();
let new_oid = Oid::from_bytes(&setup.new_commit.id().0).unwrap();
let new_oid = Oid::from_bytes(setup.new_commit.id().as_bytes()).unwrap();
assert_eq!(new_target, Some(new_oid));
// Check that the ref got updated in the cloned repo. This just tests our
@ -530,7 +530,7 @@ fn test_push_updates_mixed_deletion_and_addition() {
.find_reference("refs/heads/topic")
.unwrap()
.target();
let new_oid = Oid::from_bytes(&setup.new_commit.id().0).unwrap();
let new_oid = Oid::from_bytes(setup.new_commit.id().as_bytes()).unwrap();
assert_eq!(new_target, Some(new_oid));
// Check that the main ref got deleted in the source repo
@ -584,7 +584,7 @@ fn test_push_updates_not_fast_forward_with_force() {
.find_reference("refs/heads/main")
.unwrap()
.target();
let new_oid = Oid::from_bytes(&new_commit.id().0).unwrap();
let new_oid = Oid::from_bytes(new_commit.id().as_bytes()).unwrap();
assert_eq!(new_target, Some(new_oid));
}

View File

@ -162,17 +162,17 @@ fn test_resolve_symbol_change_id() {
// Test the test setup
assert_eq!(
hex::encode(git_commit_ids[0].as_bytes()),
hex::encode(git_commit_ids[0]),
// "04e12a5467bba790efb88a9870894ec208b16bf1" reversed
"8fd68d104372910e19511df709e5dde62a548720"
);
assert_eq!(
hex::encode(git_commit_ids[1].as_bytes()),
hex::encode(git_commit_ids[1]),
// "040b3ba3a51d8edbc4c5855cbd09de71d4c29cca" reversed
"5339432b8e7b90bd3aa1a323db71b8a5c5dcd020"
);
assert_eq!(
hex::encode(git_commit_ids[2].as_bytes()),
hex::encode(git_commit_ids[2]),
// "04e1c7082e4e34f3f371d8a1a46770b861b9b547" reversed
"e2ad9d861d0ee625851b8ecfcf2c727410e38720"
);