move remote module to the branch crate

This commit is contained in:
Kiril Videlov 2024-07-07 20:48:12 +02:00
parent 3d0455f12b
commit a7aa9b0e10
No known key found for this signature in database
GPG Key ID: A4C733025427C471
10 changed files with 61 additions and 61 deletions

View File

@ -1,6 +1,10 @@
use futures::future::join_all;
use crate::{base::BaseBranch, VirtualBranch, VirtualBranchCommit};
use crate::{
base::BaseBranch,
remote::{RemoteBranchData, RemoteCommit},
VirtualBranch, VirtualBranchCommit,
};
#[derive(Clone)]
pub struct Proxy {
@ -21,6 +25,27 @@ impl Proxy {
.await
}
pub async fn proxy_remote_branch_data(&self, branch: RemoteBranchData) -> RemoteBranchData {
RemoteBranchData {
commits: join_all(
branch
.commits
.into_iter()
.map(|commit| self.proxy_remote_commit(commit))
.collect::<Vec<_>>(),
)
.await,
..branch
}
}
pub async fn proxy_remote_commit(&self, commit: RemoteCommit) -> RemoteCommit {
RemoteCommit {
author: self.core_proxy.proxy_author(commit.author).await,
..commit
}
}
pub async fn proxy_virtual_branch(&self, branch: VirtualBranch) -> VirtualBranch {
VirtualBranch {
commits: join_all(
@ -52,7 +77,7 @@ impl Proxy {
.clone()
.recent_commits
.into_iter()
.map(|commit| self.core_proxy.proxy_remote_commit(commit))
.map(|commit| self.proxy_remote_commit(commit))
.collect::<Vec<_>>(),
)
.await,
@ -61,7 +86,7 @@ impl Proxy {
.clone()
.upstream_commits
.into_iter()
.map(|commit| self.core_proxy.proxy_remote_commit(commit))
.map(|commit| self.proxy_remote_commit(commit))
.collect::<Vec<_>>(),
)
.await,

View File

@ -7,9 +7,10 @@ use serde::Serialize;
use super::r#virtual as vb;
use super::r#virtual::convert_to_real_branch;
use crate::integration::{get_workspace_head, update_gitbutler_integration};
use crate::remote::{commit_to_remote_commit, RemoteCommit};
use crate::VirtualBranchHunk;
use gitbutler_core::virtual_branches::{
branch, target, BranchId, RemoteCommit, VirtualBranchesHandle, GITBUTLER_INTEGRATION_REFERENCE,
branch, target, BranchId, VirtualBranchesHandle, GITBUTLER_INTEGRATION_REFERENCE,
};
use gitbutler_core::{error::Marker, git::RepositoryExt, rebase::cherry_rebase};
use gitbutler_core::{
@ -588,7 +589,7 @@ pub fn target_to_base_branch(
.log(oid, project_repository::LogUntil::Commit(target.sha))
.context("failed to get upstream commits")?
.iter()
.map(gitbutler_core::virtual_branches::commit_to_remote_commit)
.map(commit_to_remote_commit)
.collect::<Vec<_>>();
// get some recent commits
@ -596,7 +597,7 @@ pub fn target_to_base_branch(
.log(target.sha, LogUntil::Take(20))
.context("failed to get recent commits")?
.iter()
.map(gitbutler_core::virtual_branches::commit_to_remote_commit)
.map(commit_to_remote_commit)
.collect::<Vec<_>>();
// there has got to be a better way to do this.

View File

@ -14,8 +14,12 @@ use std::{path::Path, sync::Arc};
use tokio::sync::Semaphore;
use crate::base::{
get_base_branch_data, set_base_branch, set_target_push_remote, update_base_branch, BaseBranch,
use crate::{
base::{
get_base_branch_data, set_base_branch, set_target_push_remote, update_base_branch,
BaseBranch,
},
remote::{get_branch_data, list_remote_branches, RemoteBranch, RemoteBranchData},
};
use super::r#virtual as branch;
@ -388,21 +392,18 @@ impl Controller {
branch::push(&project_repository, branch_id, with_force, &helper, askpass)
}
pub async fn list_remote_branches(
&self,
project: Project,
) -> Result<Vec<virtual_branches::RemoteBranch>> {
pub async fn list_remote_branches(&self, project: Project) -> Result<Vec<RemoteBranch>> {
let project_repository = Repository::open(&project)?;
virtual_branches::list_remote_branches(&project_repository)
list_remote_branches(&project_repository)
}
pub async fn get_remote_branch_data(
&self,
project: &Project,
refname: &git::Refname,
) -> Result<virtual_branches::RemoteBranchData> {
) -> Result<RemoteBranchData> {
let project_repository = Repository::open(project)?;
virtual_branches::get_branch_data(&project_repository, refname)
get_branch_data(&project_repository, refname)
}
pub async fn squash(

View File

@ -12,3 +12,5 @@ pub mod base;
pub mod integration;
pub mod files;
pub mod remote;

View File

@ -4,8 +4,8 @@ use anyhow::{Context, Result};
use bstr::BString;
use serde::Serialize;
use super::{target, Author, VirtualBranchesHandle};
use crate::{
use gitbutler_core::virtual_branches::{target, Author, VirtualBranchesHandle};
use gitbutler_core::{
git::{self, CommitExt, RepositoryExt},
project_repository::{self, LogUntil},
};
@ -22,7 +22,7 @@ use crate::{
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RemoteBranch {
#[serde(with = "crate::serde::oid")]
#[serde(with = "gitbutler_core::serde::oid")]
pub sha: git2::Oid,
pub name: git::Refname,
pub upstream: Option<git::RemoteRefname>,
@ -33,13 +33,13 @@ pub struct RemoteBranch {
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RemoteBranchData {
#[serde(with = "crate::serde::oid")]
#[serde(with = "gitbutler_core::serde::oid")]
pub sha: git2::Oid,
pub name: git::Refname,
pub upstream: Option<git::RemoteRefname>,
pub behind: u32,
pub commits: Vec<RemoteCommit>,
#[serde(with = "crate::serde::oid_opt", default)]
#[serde(with = "gitbutler_core::serde::oid_opt", default)]
pub fork_point: Option<git2::Oid>,
}
@ -47,12 +47,12 @@ pub struct RemoteBranchData {
#[serde(rename_all = "camelCase")]
pub struct RemoteCommit {
pub id: String,
#[serde(serialize_with = "crate::serde::as_string_lossy")]
#[serde(serialize_with = "gitbutler_core::serde::as_string_lossy")]
pub description: BString,
pub created_at: u128,
pub author: Author,
pub change_id: Option<String>,
#[serde(with = "crate::serde::oid_vec")]
#[serde(with = "gitbutler_core::serde::oid_vec")]
pub parent_ids: Vec<git2::Oid>,
}

View File

@ -20,6 +20,7 @@ use hex::ToHex;
use serde::{Deserialize, Serialize};
use crate::integration::{get_integration_commiter, get_workspace_head};
use crate::remote::{branch_to_remote_branch, RemoteBranch};
use gitbutler_core::error::Code;
use gitbutler_core::error::Marker;
use gitbutler_core::git::diff::GitHunk;
@ -34,7 +35,7 @@ use gitbutler_core::virtual_branches::{
branch::{
self, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims, Hunk, OwnershipClaim,
},
branch_to_remote_branch, target, RemoteBranch, VirtualBranchesHandle,
target, VirtualBranchesHandle,
};
use gitbutler_core::{
dedup::{dedup, dedup_fmt},

View File

@ -1299,7 +1299,7 @@ fn detect_mergeable_branch() -> Result<()> {
};
vb_state.set_branch(branch4.clone())?;
let remotes = gitbutler_core::virtual_branches::list_remote_branches(project_repository)
let remotes = gitbutler_branch::remote::list_remote_branches(project_repository)
.expect("failed to list remotes");
let _remote1 = &remotes
.iter()

View File

@ -1,14 +1,10 @@
use std::{collections::HashMap, path, sync, time::Duration};
use anyhow::Result;
use futures::future::join_all;
use tokio::sync::Semaphore;
use url::Url;
use crate::{
users,
virtual_branches::{Author, RemoteBranchData, RemoteCommit},
};
use crate::{users, virtual_branches::Author};
#[derive(Clone)]
pub struct Proxy {
@ -38,20 +34,6 @@ impl Proxy {
user
}
pub async fn proxy_remote_branch_data(&self, branch: RemoteBranchData) -> RemoteBranchData {
RemoteBranchData {
commits: join_all(
branch
.commits
.into_iter()
.map(|commit| self.proxy_remote_commit(commit))
.collect::<Vec<_>>(),
)
.await,
..branch
}
}
pub async fn proxy_author(&self, author: Author) -> Author {
Author {
gravatar_url: self.proxy(&author.gravatar_url).await.unwrap_or_else(|error| {
@ -62,13 +44,6 @@ impl Proxy {
}
}
pub async fn proxy_remote_commit(&self, commit: RemoteCommit) -> RemoteCommit {
RemoteCommit {
author: self.proxy_author(commit.author).await,
..commit
}
}
// takes a url of a remote assets, downloads it into cache and returns a url that points to the cached file
pub async fn proxy(&self, src: &Url) -> Result<Url> {
#[cfg(unix)]

View File

@ -2,9 +2,6 @@ pub mod branch;
pub use branch::{Branch, BranchId};
pub mod target;
mod remote;
pub use remote::*;
mod state;
pub use state::VirtualBranches as VirtualBranchesState;
pub use state::VirtualBranchesHandle;

View File

@ -3,6 +3,7 @@ pub mod commands {
use anyhow::{anyhow, Context};
use gitbutler_branch::base::BaseBranch;
use gitbutler_branch::files::RemoteBranchFile;
use gitbutler_branch::remote::{RemoteBranch, RemoteBranchData};
use gitbutler_branch::{Controller, NameConflitResolution, VirtualBranches};
use gitbutler_core::{
assets,
@ -10,10 +11,7 @@ pub mod commands {
git,
projects::{self, ProjectId},
types::ReferenceName,
virtual_branches::{
branch::{self, BranchId, BranchOwnershipClaims},
RemoteBranch, RemoteBranchData,
},
virtual_branches::branch::{self, BranchId, BranchOwnershipClaims},
};
use tauri::{AppHandle, Manager};
use tracing::instrument;
@ -457,10 +455,10 @@ pub mod commands {
.state::<Controller>()
.get_remote_branch_data(&project, &refname)
.await?;
let branch_data = handle
.state::<assets::Proxy>()
.proxy_remote_branch_data(branch_data)
.await;
let proxy =
gitbutler_branch::assets::Proxy::new(handle.state::<assets::Proxy>().inner().clone());
let branch_data = proxy.proxy_remote_branch_data(branch_data).await;
Ok(branch_data)
}