mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-13 11:14:25 +00:00
git_backend: use non-owned str::from_utf8() to decode symlink target
Just for consistency with the other changes. str::Utf8Error is 2 words long, so I removed the boxing.
This commit is contained in:
parent
d1c71c05c9
commit
06c254e742
@ -251,9 +251,7 @@ pub enum BackendError {
|
|||||||
InvalidUtf8 {
|
InvalidUtf8 {
|
||||||
object_type: String,
|
object_type: String,
|
||||||
hash: String,
|
hash: String,
|
||||||
// Box to reduce size for other error types that include this one:
|
source: std::str::Utf8Error,
|
||||||
// https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
|
|
||||||
source: Box<std::string::FromUtf8Error>,
|
|
||||||
},
|
},
|
||||||
#[error("Object {hash} of type {object_type} not found: {source}")]
|
#[error("Object {hash} of type {object_type} not found: {source}")]
|
||||||
ObjectNotFound {
|
ObjectNotFound {
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::fmt::{Debug, Error, Formatter};
|
use std::fmt::{Debug, Error, Formatter};
|
||||||
use std::fs;
|
|
||||||
use std::io::{Cursor, Read};
|
use std::io::{Cursor, Read};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
|
use std::{fs, str};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use git2::Oid;
|
use git2::Oid;
|
||||||
@ -468,6 +468,14 @@ fn map_not_found_err(err: git2::Error, id: &impl ObjectId) -> BackendError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_invalid_utf8_err(source: str::Utf8Error, id: &impl ObjectId) -> BackendError {
|
||||||
|
BackendError::InvalidUtf8 {
|
||||||
|
object_type: id.object_type(),
|
||||||
|
hash: id.hex(),
|
||||||
|
source,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn import_extra_metadata_entries_from_heads(
|
fn import_extra_metadata_entries_from_heads(
|
||||||
git_repo: &git2::Repository,
|
git_repo: &git2::Repository,
|
||||||
mut_table: &mut MutableTable,
|
mut_table: &mut MutableTable,
|
||||||
@ -556,13 +564,9 @@ impl Backend for GitBackend {
|
|||||||
let blob = locked_repo
|
let blob = locked_repo
|
||||||
.find_blob(git_blob_id)
|
.find_blob(git_blob_id)
|
||||||
.map_err(|err| map_not_found_err(err, id))?;
|
.map_err(|err| map_not_found_err(err, id))?;
|
||||||
let target = String::from_utf8(blob.content().to_owned()).map_err(|err| {
|
let target = str::from_utf8(blob.content())
|
||||||
BackendError::InvalidUtf8 {
|
.map_err(|err| to_invalid_utf8_err(err, id))?
|
||||||
object_type: id.object_type(),
|
.to_owned();
|
||||||
hash: id.hex(),
|
|
||||||
source: Box::new(err),
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
Ok(target)
|
Ok(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user