mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-08-17 00:00:31 +03:00
move virtual outside of core
This commit is contained in:
parent
2cd91be6f4
commit
948c89e8be
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -2107,18 +2107,27 @@ name = "gitbutler-branch"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bstr",
|
||||
"diffy",
|
||||
"futures",
|
||||
"git2",
|
||||
"git2-hooks",
|
||||
"gitbutler-core",
|
||||
"gitbutler-git",
|
||||
"gitbutler-testsupport",
|
||||
"glob",
|
||||
"hex",
|
||||
"itertools 0.13.0",
|
||||
"md5",
|
||||
"once_cell",
|
||||
"pretty_assertions",
|
||||
"regex",
|
||||
"serde",
|
||||
"serial_test",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -11,6 +11,15 @@ anyhow = "1.0.86"
|
||||
git2.workspace = true
|
||||
tokio.workspace = true
|
||||
gitbutler-core.workspace = true
|
||||
serde = { workspace = true, features = ["std"]}
|
||||
bstr = "1.9.1"
|
||||
diffy = "0.3.0"
|
||||
hex = "0.4.3"
|
||||
regex = "1.10"
|
||||
git2-hooks = "0.3"
|
||||
url = { version = "2.5.2", features = ["serde"] }
|
||||
md5 = "0.7.0"
|
||||
futures = "0.3"
|
||||
|
||||
[[test]]
|
||||
name="branches"
|
||||
|
57
crates/gitbutler-branch/src/assets.rs
Normal file
57
crates/gitbutler-branch/src/assets.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use futures::future::join_all;
|
||||
|
||||
use crate::{Author, VirtualBranch, VirtualBranchCommit};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Proxy {
|
||||
core_proxy: gitbutler_core::assets::Proxy,
|
||||
}
|
||||
|
||||
impl Proxy {
|
||||
pub fn new(core_proxy: gitbutler_core::assets::Proxy) -> Self {
|
||||
Proxy { core_proxy }
|
||||
}
|
||||
pub async fn proxy_virtual_branches(&self, branches: Vec<VirtualBranch>) -> Vec<VirtualBranch> {
|
||||
join_all(
|
||||
branches
|
||||
.into_iter()
|
||||
.map(|branch| self.proxy_virtual_branch(branch))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn proxy_virtual_branch(&self, branch: VirtualBranch) -> VirtualBranch {
|
||||
VirtualBranch {
|
||||
commits: join_all(
|
||||
branch
|
||||
.commits
|
||||
.iter()
|
||||
.map(|commit| self.proxy_virtual_branch_commit(commit.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.await,
|
||||
..branch
|
||||
}
|
||||
}
|
||||
|
||||
async fn proxy_author(&self, author: Author) -> Author {
|
||||
Author {
|
||||
gravatar_url: self.core_proxy.proxy(&author.gravatar_url).await.unwrap_or_else(|error| {
|
||||
tracing::error!(gravatar_url = %author.gravatar_url, ?error, "failed to proxy gravatar url");
|
||||
author.gravatar_url
|
||||
}),
|
||||
..author
|
||||
}
|
||||
}
|
||||
|
||||
async fn proxy_virtual_branch_commit(
|
||||
&self,
|
||||
commit: VirtualBranchCommit,
|
||||
) -> VirtualBranchCommit {
|
||||
VirtualBranchCommit {
|
||||
author: self.proxy_author(commit.author).await,
|
||||
..commit
|
||||
}
|
||||
}
|
||||
}
|
@ -10,11 +10,12 @@ use std::{path::Path, sync::Arc};
|
||||
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
use super::r#virtual as branch;
|
||||
use gitbutler_core::virtual_branches;
|
||||
|
||||
use gitbutler_core::virtual_branches::{
|
||||
branch::{BranchId, BranchOwnershipClaims},
|
||||
target, BaseBranch, NameConflitResolution, RemoteBranchFile, VirtualBranchesHandle,
|
||||
target, BaseBranch, RemoteBranchFile, VirtualBranchesHandle,
|
||||
};
|
||||
use gitbutler_core::{
|
||||
git,
|
||||
@ -46,7 +47,7 @@ impl Controller {
|
||||
self.permit(project.ignore_project_semaphore).await;
|
||||
let project_repository = open_with_verify(project)?;
|
||||
let snapshot_tree = project_repository.project().prepare_snapshot();
|
||||
let result = virtual_branches::commit(
|
||||
let result = branch::commit(
|
||||
&project_repository,
|
||||
branch_id,
|
||||
message,
|
||||
@ -71,21 +72,17 @@ impl Controller {
|
||||
branch_name: &git::RemoteRefname,
|
||||
) -> Result<bool> {
|
||||
let project_repository = Repository::open(project)?;
|
||||
virtual_branches::is_remote_branch_mergeable(&project_repository, branch_name)
|
||||
.map_err(Into::into)
|
||||
branch::is_remote_branch_mergeable(&project_repository, branch_name).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn list_virtual_branches(
|
||||
&self,
|
||||
project: &Project,
|
||||
) -> Result<(
|
||||
Vec<virtual_branches::VirtualBranch>,
|
||||
Vec<git::diff::FileDiff>,
|
||||
)> {
|
||||
) -> Result<(Vec<branch::VirtualBranch>, Vec<git::diff::FileDiff>)> {
|
||||
self.permit(project.ignore_project_semaphore).await;
|
||||
|
||||
let project_repository = open_with_verify(project)?;
|
||||
virtual_branches::list_virtual_branches(&project_repository).map_err(Into::into)
|
||||
branch::list_virtual_branches(&project_repository).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn create_virtual_branch(
|
||||
@ -96,7 +93,7 @@ impl Controller {
|
||||
self.permit(project.ignore_project_semaphore).await;
|
||||
|
||||
let project_repository = open_with_verify(project)?;
|
||||
let branch_id = virtual_branches::create_virtual_branch(&project_repository, create)?.id;
|
||||
let branch_id = branch::create_virtual_branch(&project_repository, create)?.id;
|
||||
Ok(branch_id)
|
||||
}
|
||||
|
||||
@ -108,8 +105,7 @@ impl Controller {
|
||||
self.permit(project.ignore_project_semaphore).await;
|
||||
|
||||
let project_repository = open_with_verify(project)?;
|
||||
virtual_branches::create_virtual_branch_from_branch(&project_repository, branch)
|
||||
.map_err(Into::into)
|
||||
branch::create_virtual_branch_from_branch(&project_repository, branch).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn get_base_branch_data(&self, project: &Project) -> Result<BaseBranch> {
|
||||
@ -189,7 +185,7 @@ impl Controller {
|
||||
.project()
|
||||
.virtual_branches()
|
||||
.get_branch(branch_update.id)?;
|
||||
let result = virtual_branches::update_branch(&project_repository, &branch_update);
|
||||
let result = branch::update_branch(&project_repository, &branch_update);
|
||||
let _ = snapshot_tree.and_then(|snapshot_tree| {
|
||||
project_repository.project().snapshot_branch_update(
|
||||
snapshot_tree,
|
||||
@ -209,7 +205,7 @@ impl Controller {
|
||||
self.permit(project.ignore_project_semaphore).await;
|
||||
|
||||
let project_repository = open_with_verify(project)?;
|
||||
virtual_branches::delete_branch(&project_repository, branch_id)
|
||||
branch::delete_branch(&project_repository, branch_id)
|
||||
}
|
||||
|
||||
pub async fn unapply_ownership(
|
||||
@ -223,7 +219,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardHunk));
|
||||
virtual_branches::unapply_ownership(&project_repository, ownership).map_err(Into::into)
|
||||
branch::unapply_ownership(&project_repository, ownership).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn reset_files(&self, project: &Project, files: &Vec<String>) -> Result<()> {
|
||||
@ -233,7 +229,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardFile));
|
||||
virtual_branches::reset_files(&project_repository, files).map_err(Into::into)
|
||||
branch::reset_files(&project_repository, files).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn amend(
|
||||
@ -249,7 +245,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::AmendCommit));
|
||||
virtual_branches::amend(&project_repository, branch_id, commit_oid, ownership)
|
||||
branch::amend(&project_repository, branch_id, commit_oid, ownership)
|
||||
}
|
||||
|
||||
pub async fn move_commit_file(
|
||||
@ -266,7 +262,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommitFile));
|
||||
virtual_branches::move_commit_file(
|
||||
branch::move_commit_file(
|
||||
&project_repository,
|
||||
branch_id,
|
||||
from_commit_oid,
|
||||
@ -287,8 +283,7 @@ impl Controller {
|
||||
let project_repository = open_with_verify(project)?;
|
||||
let snapshot_tree = project_repository.project().prepare_snapshot();
|
||||
let result: Result<()> =
|
||||
virtual_branches::undo_commit(&project_repository, branch_id, commit_oid)
|
||||
.map_err(Into::into);
|
||||
branch::undo_commit(&project_repository, branch_id, commit_oid).map_err(Into::into);
|
||||
let _ = snapshot_tree.and_then(|snapshot_tree| {
|
||||
project_repository.project().snapshot_commit_undo(
|
||||
snapshot_tree,
|
||||
@ -312,7 +307,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::InsertBlankCommit));
|
||||
virtual_branches::insert_blank_commit(&project_repository, branch_id, commit_oid, offset)
|
||||
branch::insert_blank_commit(&project_repository, branch_id, commit_oid, offset)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -329,7 +324,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::ReorderCommit));
|
||||
virtual_branches::reorder_commit(&project_repository, branch_id, commit_oid, offset)
|
||||
branch::reorder_commit(&project_repository, branch_id, commit_oid, offset)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -345,21 +340,20 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::UndoCommit));
|
||||
virtual_branches::reset_branch(&project_repository, branch_id, target_commit_oid)
|
||||
.map_err(Into::into)
|
||||
branch::reset_branch(&project_repository, branch_id, target_commit_oid).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn convert_to_real_branch(
|
||||
&self,
|
||||
project: &Project,
|
||||
branch_id: BranchId,
|
||||
name_conflict_resolution: NameConflitResolution,
|
||||
name_conflict_resolution: branch::NameConflitResolution,
|
||||
) -> Result<ReferenceName> {
|
||||
self.permit(project.ignore_project_semaphore).await;
|
||||
|
||||
let project_repository = open_with_verify(project)?;
|
||||
let snapshot_tree = project_repository.project().prepare_snapshot();
|
||||
let result = virtual_branches::convert_to_real_branch(
|
||||
let result = branch::convert_to_real_branch(
|
||||
&project_repository,
|
||||
branch_id,
|
||||
name_conflict_resolution,
|
||||
@ -383,7 +377,7 @@ impl Controller {
|
||||
self.permit(project.ignore_project_semaphore).await;
|
||||
let helper = Helper::default();
|
||||
let project_repository = open_with_verify(project)?;
|
||||
virtual_branches::push(&project_repository, branch_id, with_force, &helper, askpass)
|
||||
branch::push(&project_repository, branch_id, with_force, &helper, askpass)
|
||||
}
|
||||
|
||||
pub async fn list_remote_branches(
|
||||
@ -415,7 +409,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::SquashCommit));
|
||||
virtual_branches::squash(&project_repository, branch_id, commit_oid).map_err(Into::into)
|
||||
branch::squash(&project_repository, branch_id, commit_oid).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn update_commit_message(
|
||||
@ -430,7 +424,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::UpdateCommitMessage));
|
||||
virtual_branches::update_commit_message(&project_repository, branch_id, commit_oid, message)
|
||||
branch::update_commit_message(&project_repository, branch_id, commit_oid, message)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -489,8 +483,7 @@ impl Controller {
|
||||
let _ = project_repository
|
||||
.project()
|
||||
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommit));
|
||||
virtual_branches::move_commit(&project_repository, target_branch_id, commit_oid)
|
||||
.map_err(Into::into)
|
||||
branch::move_commit(&project_repository, target_branch_id, commit_oid).map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn permit(&self, ignore: bool) {
|
||||
|
@ -1,3 +1,8 @@
|
||||
//! GitButler internal library containing functionaliry related to branches, i.e. the virtual branches implementation
|
||||
pub mod controller;
|
||||
pub use controller::Controller;
|
||||
|
||||
pub mod r#virtual;
|
||||
pub use r#virtual::*;
|
||||
|
||||
pub mod assets;
|
||||
|
3814
crates/gitbutler-branch/src/virtual.rs
Normal file
3814
crates/gitbutler-branch/src/virtual.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,5 @@
|
||||
use gitbutler_core::{
|
||||
id::Id,
|
||||
virtual_branches::{Branch, VirtualBranch},
|
||||
};
|
||||
use gitbutler_branch::VirtualBranch;
|
||||
use gitbutler_core::{id::Id, virtual_branches::Branch};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
pub(crate) fn dedup(existing: &[&str], new: &str) -> String {
|
||||
pub fn dedup(existing: &[&str], new: &str) -> String {
|
||||
dedup_fmt(existing, new, " ")
|
||||
}
|
||||
|
||||
/// Makes sure that _new_ is not in _existing_ by adding a number to it.
|
||||
/// the number is increased until the name is unique.
|
||||
pub(crate) fn dedup_fmt(existing: &[&str], new: &str, separator: &str) -> String {
|
||||
pub fn dedup_fmt(existing: &[&str], new: &str, separator: &str) -> String {
|
||||
existing
|
||||
.iter()
|
||||
.filter_map(|x| {
|
||||
|
@ -1,7 +1,7 @@
|
||||
pub mod commands {
|
||||
use crate::error::Error;
|
||||
use anyhow::{anyhow, Context};
|
||||
use gitbutler_branch::Controller;
|
||||
use gitbutler_branch::{Controller, NameConflitResolution, VirtualBranches};
|
||||
use gitbutler_core::{
|
||||
assets,
|
||||
error::Code,
|
||||
@ -10,8 +10,7 @@ pub mod commands {
|
||||
types::ReferenceName,
|
||||
virtual_branches::{
|
||||
branch::{self, BranchId, BranchOwnershipClaims},
|
||||
BaseBranch, NameConflitResolution, RemoteBranch, RemoteBranchData, RemoteBranchFile,
|
||||
VirtualBranches,
|
||||
BaseBranch, RemoteBranch, RemoteBranchData, RemoteBranchFile,
|
||||
},
|
||||
};
|
||||
use tauri::{AppHandle, Manager};
|
||||
@ -50,7 +49,8 @@ pub mod commands {
|
||||
.list_virtual_branches(&project)
|
||||
.await?;
|
||||
|
||||
let proxy = handle.state::<assets::Proxy>();
|
||||
let proxy =
|
||||
gitbutler_branch::assets::Proxy::new(handle.state::<assets::Proxy>().inner().clone());
|
||||
let branches = proxy.proxy_virtual_branches(branches).await;
|
||||
Ok(VirtualBranches {
|
||||
branches,
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::fmt::Display;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use gitbutler_branch::VirtualBranches;
|
||||
use gitbutler_core::projects::ProjectId;
|
||||
use gitbutler_core::virtual_branches;
|
||||
|
||||
/// An event for internal use, as merge between [super::file_monitor::Event] and [Action].
|
||||
#[derive(Debug)]
|
||||
@ -98,6 +98,6 @@ pub enum Change {
|
||||
GitActivity(ProjectId),
|
||||
VirtualBranches {
|
||||
project_id: ProjectId,
|
||||
virtual_branches: virtual_branches::VirtualBranches,
|
||||
virtual_branches: VirtualBranches,
|
||||
},
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use gitbutler_branch::VirtualBranches;
|
||||
use gitbutler_core::error::Marker;
|
||||
use gitbutler_core::ops::entry::{OperationKind, SnapshotDetails};
|
||||
use gitbutler_core::projects::ProjectId;
|
||||
use gitbutler_core::synchronize::sync_with_gitbutler;
|
||||
use gitbutler_core::virtual_branches::VirtualBranches;
|
||||
use gitbutler_core::{assets, git, project_repository, projects, users};
|
||||
use tracing::instrument;
|
||||
|
||||
@ -25,7 +25,7 @@ pub struct Handler {
|
||||
projects: projects::Controller,
|
||||
users: users::Controller,
|
||||
vbranch_controller: gitbutler_branch::Controller,
|
||||
assets_proxy: assets::Proxy,
|
||||
assets_proxy: gitbutler_branch::assets::Proxy,
|
||||
|
||||
/// A function to send events - decoupled from app-handle for testing purposes.
|
||||
#[allow(clippy::type_complexity)]
|
||||
@ -46,7 +46,7 @@ impl Handler {
|
||||
projects,
|
||||
users,
|
||||
vbranch_controller,
|
||||
assets_proxy,
|
||||
assets_proxy: gitbutler_branch::assets::Proxy::new(assets_proxy),
|
||||
send_event: Arc::new(send_event),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user