mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-31 23:25:09 +00:00
cleanup: consistently use BackendResult
We have the type alias so we should use it consistently.
This commit is contained in:
parent
47c010fce4
commit
428e209304
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use futures::{StreamExt, TryFutureExt, TryStreamExt};
|
||||
use itertools::Itertools;
|
||||
use jj_lib::backend::{BackendError, FileId, MergedTreeId, TreeValue};
|
||||
use jj_lib::backend::{BackendError, BackendResult, FileId, MergedTreeId, TreeValue};
|
||||
use jj_lib::conflicts::{materialize_tree_value, MaterializedTreeValue};
|
||||
use jj_lib::diff::{find_line_ranges, Diff, DiffHunk};
|
||||
use jj_lib::files::{self, ContentHunk, MergeResult};
|
||||
@ -412,7 +412,7 @@ pub fn apply_diff_builtin(
|
||||
right_tree: &MergedTree,
|
||||
changed_files: Vec<RepoPathBuf>,
|
||||
files: &[scm_record::File],
|
||||
) -> Result<MergedTreeId, BackendError> {
|
||||
) -> BackendResult<MergedTreeId> {
|
||||
let mut tree_builder = MergedTreeBuilder::new(left_tree.id().clone());
|
||||
assert_eq!(
|
||||
changed_files.len(),
|
||||
|
@ -19,8 +19,7 @@ use std::fmt::{Debug, Error, Formatter};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::backend;
|
||||
use crate::backend::{BackendError, ChangeId, CommitId, MergedTreeId, Signature};
|
||||
use crate::backend::{self, BackendResult, ChangeId, CommitId, MergedTreeId, Signature};
|
||||
use crate::merged_tree::MergedTree;
|
||||
use crate::signing::{SignResult, Verification};
|
||||
use crate::store::Store;
|
||||
@ -101,7 +100,7 @@ impl Commit {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn tree(&self) -> Result<MergedTree, BackendError> {
|
||||
pub fn tree(&self) -> BackendResult<MergedTree> {
|
||||
self.store.get_root_tree(&self.data.root_tree)
|
||||
}
|
||||
|
||||
@ -109,7 +108,7 @@ impl Commit {
|
||||
&self.data.root_tree
|
||||
}
|
||||
|
||||
pub fn has_conflict(&self) -> Result<bool, BackendError> {
|
||||
pub fn has_conflict(&self) -> BackendResult<bool> {
|
||||
if let MergedTreeId::Merge(tree_ids) = self.tree_id() {
|
||||
Ok(!tree_ids.is_resolved())
|
||||
} else {
|
||||
|
@ -448,7 +448,7 @@ fn commit_from_git_without_root_parent(
|
||||
id: &CommitId,
|
||||
git_object: &gix::Object,
|
||||
uses_tree_conflict_format: bool,
|
||||
) -> Result<Commit, BackendError> {
|
||||
) -> BackendResult<Commit> {
|
||||
let commit = git_object
|
||||
.try_to_commit_ref()
|
||||
.map_err(|err| to_read_object_err(err, id))?;
|
||||
@ -659,7 +659,7 @@ fn recreate_no_gc_refs(
|
||||
git_repo: &gix::Repository,
|
||||
new_heads: impl IntoIterator<Item = CommitId>,
|
||||
keep_newer: SystemTime,
|
||||
) -> Result<(), BackendError> {
|
||||
) -> BackendResult<()> {
|
||||
// Calculate diff between existing no-gc refs and new heads.
|
||||
let new_heads: HashSet<CommitId> = new_heads.into_iter().collect();
|
||||
let mut no_gc_refs_to_keep_count: usize = 0;
|
||||
@ -738,7 +738,7 @@ fn run_git_gc(git_dir: &Path) -> Result<(), GitGcError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_git_object_id(id: &impl ObjectId) -> Result<gix::ObjectId, BackendError> {
|
||||
fn validate_git_object_id(id: &impl ObjectId) -> BackendResult<gix::ObjectId> {
|
||||
if id.as_bytes().len() != HASH_LENGTH {
|
||||
return Err(BackendError::InvalidHashLength {
|
||||
expected: HASH_LENGTH,
|
||||
@ -872,7 +872,7 @@ impl Backend for GitBackend {
|
||||
Ok(FileId::new(oid.as_bytes().to_vec()))
|
||||
}
|
||||
|
||||
async fn read_symlink(&self, _path: &RepoPath, id: &SymlinkId) -> Result<String, BackendError> {
|
||||
async fn read_symlink(&self, _path: &RepoPath, id: &SymlinkId) -> BackendResult<String> {
|
||||
let git_blob_id = validate_git_object_id(id)?;
|
||||
let locked_repo = self.lock_git_repo();
|
||||
let mut blob = locked_repo
|
||||
@ -886,7 +886,7 @@ impl Backend for GitBackend {
|
||||
Ok(target)
|
||||
}
|
||||
|
||||
fn write_symlink(&self, _path: &RepoPath, target: &str) -> Result<SymlinkId, BackendError> {
|
||||
fn write_symlink(&self, _path: &RepoPath, target: &str) -> BackendResult<SymlinkId> {
|
||||
let locked_repo = self.lock_git_repo();
|
||||
let oid =
|
||||
locked_repo
|
||||
@ -1237,7 +1237,7 @@ impl Backend for GitBackend {
|
||||
fn write_tree_conflict(
|
||||
repo: &gix::Repository,
|
||||
conflict: &Merge<TreeId>,
|
||||
) -> Result<gix::ObjectId, BackendError> {
|
||||
) -> BackendResult<gix::ObjectId> {
|
||||
// Tree entries to be written must be sorted by Entry::filename().
|
||||
let mut entries = itertools::chain(
|
||||
conflict
|
||||
|
@ -184,13 +184,13 @@ impl Backend for LocalBackend {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
async fn read_symlink(&self, _path: &RepoPath, id: &SymlinkId) -> Result<String, BackendError> {
|
||||
async fn read_symlink(&self, _path: &RepoPath, id: &SymlinkId) -> BackendResult<String> {
|
||||
let path = self.symlink_path(id);
|
||||
let target = fs::read_to_string(path).map_err(|err| map_not_found_err(err, id))?;
|
||||
Ok(target)
|
||||
}
|
||||
|
||||
fn write_symlink(&self, _path: &RepoPath, target: &str) -> Result<SymlinkId, BackendError> {
|
||||
fn write_symlink(&self, _path: &RepoPath, target: &str) -> BackendResult<SymlinkId> {
|
||||
let mut temp_file = NamedTempFile::new_in(&self.path).map_err(to_other_err)?;
|
||||
temp_file
|
||||
.write_all(target.as_bytes())
|
||||
|
@ -40,7 +40,8 @@ use thiserror::Error;
|
||||
use tracing::{instrument, trace_span};
|
||||
|
||||
use crate::backend::{
|
||||
BackendError, FileId, MergedTreeId, MillisSinceEpoch, SymlinkId, TreeId, TreeValue,
|
||||
BackendError, BackendResult, FileId, MergedTreeId, MillisSinceEpoch, SymlinkId, TreeId,
|
||||
TreeValue,
|
||||
};
|
||||
use crate::commit::Commit;
|
||||
use crate::conflicts::{self, materialize_tree_value, MaterializedTreeValue};
|
||||
@ -663,7 +664,7 @@ impl TreeState {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn current_tree(&self) -> Result<MergedTree, BackendError> {
|
||||
fn current_tree(&self) -> BackendResult<MergedTree> {
|
||||
self.store.get_root_tree(&self.tree_id)
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,7 @@ use std::sync::Arc;
|
||||
use itertools::Itertools;
|
||||
use smallvec::{smallvec_inline, SmallVec};
|
||||
|
||||
use crate::backend;
|
||||
use crate::backend::{BackendError, FileId, TreeId, TreeValue};
|
||||
use crate::backend::{self, BackendResult, FileId, TreeId, TreeValue};
|
||||
use crate::content_hash::{ContentHash, DigestUpdate};
|
||||
use crate::object_id::ObjectId;
|
||||
use crate::repo_path::RepoPath;
|
||||
@ -559,7 +558,7 @@ where
|
||||
&self,
|
||||
store: &Arc<Store>,
|
||||
dir: &RepoPath,
|
||||
) -> Result<Option<Merge<Tree>>, BackendError> {
|
||||
) -> BackendResult<Option<Merge<Tree>>> {
|
||||
let tree_id_merge = self.maybe_map(|term| match term {
|
||||
None => Some(None),
|
||||
Some(value) => {
|
||||
@ -571,7 +570,7 @@ where
|
||||
}
|
||||
});
|
||||
if let Some(tree_id_merge) = tree_id_merge {
|
||||
let get_tree = |id: &Option<&TreeId>| -> Result<Tree, BackendError> {
|
||||
let get_tree = |id: &Option<&TreeId>| -> BackendResult<Tree> {
|
||||
if let Some(id) = id {
|
||||
store.get_tree(dir, id)
|
||||
} else {
|
||||
|
@ -26,7 +26,7 @@ use futures::stream::StreamExt;
|
||||
use futures::{Future, Stream, TryStreamExt};
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::backend::{BackendError, BackendResult, ConflictId, MergedTreeId, TreeId, TreeValue};
|
||||
use crate::backend::{BackendResult, ConflictId, MergedTreeId, TreeId, TreeValue};
|
||||
use crate::matchers::{EverythingMatcher, Matcher};
|
||||
use crate::merge::{Merge, MergeBuilder, MergedTreeValue};
|
||||
use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent, RepoPathComponentsIter};
|
||||
@ -1226,7 +1226,7 @@ impl MergedTreeBuilder {
|
||||
self,
|
||||
mut base_tree_ids: Merge<TreeId>,
|
||||
store: &Arc<Store>,
|
||||
) -> Result<Merge<TreeId>, BackendError> {
|
||||
) -> BackendResult<Merge<TreeId>> {
|
||||
let num_sides = self
|
||||
.overrides
|
||||
.values()
|
||||
|
@ -1009,7 +1009,7 @@ impl MutableRepo {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_all_references(&mut self, settings: &UserSettings) -> Result<(), BackendError> {
|
||||
fn update_all_references(&mut self, settings: &UserSettings) -> BackendResult<()> {
|
||||
for (old_parent_id, rewrite) in self.parent_mapping.clone() {
|
||||
// Call `new_parents()` here since `parent_mapping` only contains direct
|
||||
// mappings, not transitive ones.
|
||||
@ -1026,7 +1026,7 @@ impl MutableRepo {
|
||||
settings: &UserSettings,
|
||||
old_commit_id: CommitId,
|
||||
new_commit_ids: Vec<CommitId>,
|
||||
) -> Result<(), BackendError> {
|
||||
) -> BackendResult<()> {
|
||||
// We arbitrarily pick a new working-copy commit among the candidates.
|
||||
let abandoned_old_commit = matches!(
|
||||
self.parent_mapping.get(&old_commit_id),
|
||||
@ -1084,7 +1084,7 @@ impl MutableRepo {
|
||||
old_commit_id: &CommitId,
|
||||
new_commit_id: &CommitId,
|
||||
abandoned_old_commit: bool,
|
||||
) -> Result<(), BackendError> {
|
||||
) -> BackendResult<()> {
|
||||
let workspaces_to_update = self.view().workspaces_for_wc_commit_id(old_commit_id);
|
||||
if workspaces_to_update.is_empty() {
|
||||
return Ok(());
|
||||
|
@ -179,7 +179,7 @@ impl Backend for TestBackend {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
async fn read_symlink(&self, path: &RepoPath, id: &SymlinkId) -> Result<String, BackendError> {
|
||||
async fn read_symlink(&self, path: &RepoPath, id: &SymlinkId) -> BackendResult<String> {
|
||||
match self
|
||||
.locked_data()
|
||||
.symlinks
|
||||
@ -196,7 +196,7 @@ impl Backend for TestBackend {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_symlink(&self, path: &RepoPath, target: &str) -> Result<SymlinkId, BackendError> {
|
||||
fn write_symlink(&self, path: &RepoPath, target: &str) -> BackendResult<SymlinkId> {
|
||||
let id = SymlinkId::new(get_hash(target.as_bytes()));
|
||||
self.locked_data()
|
||||
.symlinks
|
||||
|
Loading…
x
Reference in New Issue
Block a user