move error marker out of virtual_branches mod

It's useful outside of it
This commit is contained in:
Kiril Videlov 2024-06-28 11:35:44 +02:00
parent f67744eea1
commit b72f9c2199
No known key found for this signature in database
GPG Key ID: A4C733025427C471
10 changed files with 36 additions and 38 deletions

View File

@ -231,3 +231,30 @@ impl AnyhowContextExt for anyhow::Error {
})
}
}
/// A way to mark errors using `[anyhow::Context::context]` for later retrieval, e.g. to know
/// that a certain even happened.
///
/// Note that the display implementation is visible to users in logs, so it's a bit 'special'
/// to signify its marker status.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Marker {
/// Invalid state was detected, making the repository invalid for operation.
VerificationFailure,
/// An indicator for a conflict in the project.
///
/// See usages for details on what these conflicts can be.
ProjectConflict,
/// An indicator that a branch conflicted during applying to the workspace.
BranchConflict,
}
impl std::fmt::Display for Marker {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Marker::VerificationFailure => f.write_str("<verification-failed>"),
Marker::ProjectConflict => f.write_str("<project-conflict>"),
Marker::BranchConflict => f.write_str("<branch-conflict>"),
}
}
}

View File

@ -15,7 +15,7 @@ use crate::{
ssh, users,
virtual_branches::{Branch, BranchId},
};
use crate::{git::RepositoryExt, virtual_branches::errors::Marker};
use crate::{error::Marker, git::RepositoryExt};
pub struct Repository {
git_repository: git2::Repository,

View File

@ -1,6 +1,4 @@
use crate::{
git::CommitExt, git::RepositoryExt, project_repository, virtual_branches::errors::Marker,
};
use crate::{error::Marker, git::CommitExt, git::RepositoryExt, project_repository};
use anyhow::{anyhow, Context, Result};
use bstr::ByteSlice;

View File

@ -11,7 +11,7 @@ use super::{
},
target, BranchId, RemoteCommit, VirtualBranchHunk, VirtualBranchesHandle,
};
use crate::{git::RepositoryExt, rebase::cherry_rebase, virtual_branches::errors::Marker};
use crate::{error::Marker, git::RepositoryExt, rebase::cherry_rebase};
use crate::{
git::{self, diff},
project_repository::{self, LogUntil},

View File

@ -1,26 +0,0 @@
/// A way to mark errors using `[anyhow::Context::context]` for later retrieval, e.g. to know
/// that a certain even happened.
///
/// Note that the display implementation is visible to users in logs, so it's a bit 'special'
/// to signify its marker status.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Marker {
/// Invalid state was detected, making the repository invalid for operation.
VerificationFailure,
/// An indicator for a conflict in the project.
///
/// See usages for details on what these conflicts can be.
ProjectConflict,
/// An indicator that a branch conflicted during applying to the workspace.
BranchConflict,
}
impl std::fmt::Display for Marker {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Marker::VerificationFailure => f.write_str("<verification-failed>"),
Marker::ProjectConflict => f.write_str("<project-conflict>"),
Marker::BranchConflict => f.write_str("<branch-conflict>"),
}
}
}

View File

@ -5,8 +5,8 @@ use bstr::ByteSlice;
use lazy_static::lazy_static;
use super::VirtualBranchesHandle;
use crate::error::Marker;
use crate::git::RepositoryExt;
use crate::virtual_branches::errors::Marker;
use crate::{
git::{self, CommitExt},
project_repository::{self, conflicts, LogUntil},

View File

@ -2,8 +2,6 @@ pub mod branch;
pub use branch::{Branch, BranchId};
pub mod target;
pub mod errors;
mod files;
pub use files::*;

View File

@ -26,13 +26,13 @@ use super::{
branch_to_remote_branch, target, RemoteBranch, VirtualBranchesHandle,
};
use crate::error::Code;
use crate::error::Marker;
use crate::git::diff::GitHunk;
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
use crate::git::{CommitExt, RepositoryExt};
use crate::rebase::{cherry_rebase, cherry_rebase_group};
use crate::time::now_since_unix_epoch_ms;
use crate::virtual_branches::branch::HunkHash;
use crate::virtual_branches::errors::Marker;
use crate::{
dedup::{dedup, dedup_fmt},
git::{

View File

@ -1,7 +1,7 @@
use std::path::PathBuf;
use std::{fs, path, str::FromStr};
use gitbutler_core::virtual_branches::errors::Marker;
use gitbutler_core::error::Marker;
use gitbutler_core::{
git,
projects::{self, Project, ProjectId},

View File

@ -2,6 +2,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use anyhow::{Context, Result};
use gitbutler_core::error::Marker;
use gitbutler_core::ops::entry::{OperationKind, SnapshotDetails};
use gitbutler_core::projects::ProjectId;
use gitbutler_core::synchronize::sync_with_gitbutler;
@ -101,8 +102,8 @@ impl Handler {
}
Err(err)
if matches!(
err.downcast_ref::<virtual_branches::errors::Marker>(),
Some(virtual_branches::errors::Marker::VerificationFailure)
err.downcast_ref::<Marker>(),
Some(Marker::VerificationFailure)
) =>
{
Ok(())