Merge pull request #5265 from gitbutlerapp/refactor-gitbutler-repository

Refactor gitbutler-repository
This commit is contained in:
Kiril Videlov 2024-10-22 14:19:18 +02:00 committed by GitHub
commit b75f19b32b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 126 additions and 122 deletions

121
Cargo.lock generated
View File

@ -1328,7 +1328,7 @@ dependencies = [
"hashbrown 0.14.5",
"lock_api",
"once_cell",
"parking_lot_core 0.9.10",
"parking_lot_core",
]
[[package]]
@ -2189,6 +2189,7 @@ dependencies = [
"gitbutler-project",
"gitbutler-reference",
"gitbutler-repo",
"gitbutler-repo-actions",
"gitbutler-serde",
"gitbutler-stack",
"gitbutler-stack-api",
@ -2395,7 +2396,7 @@ dependencies = [
"gitbutler-notify-debouncer",
"mock_instant",
"notify",
"parking_lot 0.12.3",
"parking_lot",
"pretty_assertions",
"rstest",
"serde",
@ -2479,7 +2480,7 @@ dependencies = [
"gitbutler-storage",
"gitbutler-testsupport",
"gix",
"parking_lot 0.12.3",
"parking_lot",
"resolve-path",
"serde",
"serde_json",
@ -2516,31 +2517,47 @@ dependencies = [
"gitbutler-config",
"gitbutler-error",
"gitbutler-git",
"gitbutler-id",
"gitbutler-oxidize",
"gitbutler-project",
"gitbutler-reference",
"gitbutler-stack",
"gitbutler-testsupport",
"gitbutler-time",
"gitbutler-url",
"gitbutler-user",
"gix",
"infer 0.16.0",
"itertools 0.13.0",
"log",
"resolve-path",
"serde",
"serde_json",
"ssh2",
"tempfile",
"thiserror",
"tokio",
"toml 0.8.19",
"tracing",
"uuid",
]
[[package]]
name = "gitbutler-repo-actions"
version = "0.0.0"
dependencies = [
"anyhow",
"git2",
"gitbutler-command-context",
"gitbutler-commit",
"gitbutler-error",
"gitbutler-git",
"gitbutler-id",
"gitbutler-project",
"gitbutler-reference",
"gitbutler-repo",
"gitbutler-stack",
"gitbutler-time",
"log",
"serde",
"tokio",
"tracing",
]
[[package]]
name = "gitbutler-secret"
version = "0.0.0"
@ -2595,6 +2612,7 @@ dependencies = [
"gitbutler-patch-reference",
"gitbutler-reference",
"gitbutler-repo",
"gitbutler-repo-actions",
"gitbutler-stack",
"gitbutler-testsupport",
"gitbutler-time",
@ -2668,6 +2686,7 @@ dependencies = [
"gitbutler-project",
"gitbutler-reference",
"gitbutler-repo",
"gitbutler-repo-actions",
"gitbutler-secret",
"gitbutler-stack",
"gitbutler-storage",
@ -2679,7 +2698,7 @@ dependencies = [
"log",
"once_cell",
"open 5.3.0",
"parking_lot 0.12.3",
"parking_lot",
"pretty_assertions",
"reqwest 0.12.8",
"serde",
@ -2722,7 +2741,7 @@ dependencies = [
"gix-testtools",
"keyring",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"serde_json",
"tempfile",
"uuid",
@ -3135,7 +3154,7 @@ dependencies = [
"gix-utils 0.1.12 (git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb2399a06fae5e60)",
"libc",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"prodash 29.0.0",
"sha1",
"sha1_smol",
@ -3234,7 +3253,7 @@ checksum = "7ddf80e16f3c19ac06ce415a38b8591993d3f73aede049cb561becb5b3a8e242"
dependencies = [
"gix-hash 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hashbrown 0.14.5",
"parking_lot 0.12.3",
"parking_lot",
]
[[package]]
@ -3244,7 +3263,7 @@ source = "git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb23
dependencies = [
"gix-hash 0.14.2 (git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb2399a06fae5e60)",
"hashbrown 0.14.5",
"parking_lot 0.12.3",
"parking_lot",
]
[[package]]
@ -3416,7 +3435,7 @@ dependencies = [
"gix-pack",
"gix-path 0.10.11 (git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb2399a06fae5e60)",
"gix-quote 0.4.12 (git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb2399a06fae5e60)",
"parking_lot 0.12.3",
"parking_lot",
"tempfile",
"thiserror",
]
@ -3435,7 +3454,7 @@ dependencies = [
"gix-path 0.10.11 (git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb2399a06fae5e60)",
"gix-tempfile 14.0.2 (git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb2399a06fae5e60)",
"memmap2",
"parking_lot 0.12.3",
"parking_lot",
"smallvec",
"thiserror",
"uluru",
@ -3509,7 +3528,7 @@ source = "git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb23
dependencies = [
"gix-command",
"gix-config-value",
"parking_lot 0.12.3",
"parking_lot",
"rustix 0.38.37",
"thiserror",
]
@ -3721,7 +3740,7 @@ dependencies = [
"gix-fs 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"signal-hook",
"signal-hook-registry",
"tempfile",
@ -3736,7 +3755,7 @@ dependencies = [
"gix-fs 0.11.3 (git+https://github.com/Byron/gitoxide?rev=b36d7efb9743766338ac7bb7fb2399a06fae5e60)",
"libc",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"tempfile",
]
@ -3760,7 +3779,7 @@ dependencies = [
"io-close",
"is_ci",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"tar",
"tempfile",
"winnow 0.6.18",
@ -4917,7 +4936,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.6.0",
"libc",
"redox_syscall 0.5.3",
"redox_syscall",
]
[[package]]
@ -5623,17 +5642,6 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae"
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core 0.8.6",
]
[[package]]
name = "parking_lot"
version = "0.12.3"
@ -5641,21 +5649,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core 0.9.10",
]
[[package]]
name = "parking_lot_core"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall 0.2.16",
"smallvec",
"winapi",
"parking_lot_core",
]
[[package]]
@ -5666,7 +5660,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.5.3",
"redox_syscall",
"smallvec",
"windows-targets 0.52.6",
]
@ -6109,7 +6103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a266d8d6020c61a437be704c5e618037588e1985c7dbb7bf8d265db84cffe325"
dependencies = [
"log",
"parking_lot 0.12.3",
"parking_lot",
]
[[package]]
@ -6304,15 +6298,6 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.5.3"
@ -6929,7 +6914,7 @@ dependencies = [
"futures",
"log",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"scc",
"serial_test_derive",
]
@ -7154,18 +7139,6 @@ dependencies = [
"lock_api",
]
[[package]]
name = "ssh2"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7fe461910559f6d5604c3731d00d2aafc4a83d1665922e280f42f9a168d5455"
dependencies = [
"bitflags 1.3.2",
"libc",
"libssh2-sys",
"parking_lot 0.11.2",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
@ -7195,7 +7168,7 @@ checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b"
dependencies = [
"new_debug_unreachable",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"phf_shared 0.10.0",
"precomputed-hash",
"serde",
@ -7421,7 +7394,7 @@ dependencies = [
"ndk-sys",
"objc",
"once_cell",
"parking_lot 0.12.3",
"parking_lot",
"png",
"raw-window-handle",
"scopeguard",
@ -7885,7 +7858,7 @@ dependencies = [
"bytes",
"libc",
"mio 1.0.2",
"parking_lot 0.12.3",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.5.7",

View File

@ -10,6 +10,7 @@ members = [
"crates/gitbutler-sync",
"crates/gitbutler-oplog",
"crates/gitbutler-repo",
"crates/gitbutler-repo-actions",
"crates/gitbutler-command-context",
"crates/gitbutler-feedback",
"crates/gitbutler-config",
@ -68,6 +69,7 @@ gitbutler-branch-actions = { path = "crates/gitbutler-branch-actions" }
gitbutler-sync = { path = "crates/gitbutler-sync" }
gitbutler-oplog = { path = "crates/gitbutler-oplog" }
gitbutler-repo = { path = "crates/gitbutler-repo" }
gitbutler-repo-actions = { path = "crates/gitbutler-repo-actions" }
gitbutler-command-context = { path = "crates/gitbutler-command-context" }
gitbutler-feedback = { path = "crates/gitbutler-feedback" }
gitbutler-config = { path = "crates/gitbutler-config" }

View File

@ -13,6 +13,7 @@ gix = { workspace = true, features = ["blob-diff", "revision"] }
tokio.workspace = true
gitbutler-oplog.workspace = true
gitbutler-repo.workspace = true
gitbutler-repo-actions.workspace = true
gitbutler-user.workspace = true
gitbutler-branch.workspace = true
gitbutler-reference.workspace = true

View File

@ -26,7 +26,8 @@ use gitbutler_oplog::{
};
use gitbutler_project::{FetchResult, Project};
use gitbutler_reference::{ReferenceName, Refname, RemoteRefname};
use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use gitbutler_repo::RepositoryExt;
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::{BranchOwnershipClaims, StackId};
use std::path::PathBuf;
use tracing::instrument;

View File

@ -6,7 +6,8 @@ use gitbutler_command_context::CommandContext;
use gitbutler_error::error::Marker;
use gitbutler_project::FetchResult;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_repo::{LogUntil, RepoActionsExt, RepositoryExt};
use gitbutler_repo::{LogUntil, RepositoryExt};
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::{BranchOwnershipClaims, Stack, Target, VirtualBranchesHandle};
use gitbutler_stack_api::StackExt;
use serde::Serialize;

View File

@ -10,8 +10,9 @@ use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_repo::{
rebase::{cherry_rebase_group, gitbutler_merge_commits},
LogUntil, RepoActionsExt, RepositoryExt,
LogUntil, RepositoryExt,
};
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::{BranchOwnershipClaims, Stack, StackId};
use gitbutler_stack_api::StackExt;
use gitbutler_time::time::now_since_unix_epoch_ms;

View File

@ -7,7 +7,8 @@ use gitbutler_commit::commit_headers::CommitHeadersV2;
use gitbutler_oplog::SnapshotExt;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_reference::{normalize_branch_name, ReferenceName, Refname};
use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use gitbutler_repo::RepositoryExt;
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::{Stack, StackId};
use tracing::instrument;

View File

@ -6,7 +6,8 @@ use gitbutler_branch::ReferenceExt;
use gitbutler_command_context::CommandContext;
use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_repo::{LogUntil, RepoActionsExt, RepositoryExt};
use gitbutler_repo::{LogUntil, RepositoryExt};
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_serde::BStringForFrontend;
use gitbutler_stack::{Target, VirtualBranchesHandle};
use serde::Serialize;

View File

@ -6,7 +6,7 @@ use gitbutler_command_context::CommandContext;
use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_patch_reference::{CommitOrChangeId, PatchReference};
use gitbutler_project::Project;
use gitbutler_repo::RepoActionsExt;
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::{Stack, StackId, Target};
use gitbutler_stack_api::{
commit_by_oid_or_change_id, CommitsForId, PatchReferenceUpdate, StackExt,

View File

@ -4,8 +4,9 @@ use gitbutler_command_context::CommandContext;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_repo::{
rebase::{cherry_rebase_group, gitbutler_merge_commits},
LogUntil, RepoActionsExt as _, RepositoryExt as _,
LogUntil, RepositoryExt as _,
};
use gitbutler_repo_actions::RepoActionsExt as _;
use gitbutler_stack::{Stack, StackId, Target, VirtualBranchesHandle};
use gitbutler_stack_api::StackExt;
use serde::{Deserialize, Serialize};

View File

@ -25,8 +25,9 @@ use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_reference::{normalize_branch_name, Refname, RemoteRefname};
use gitbutler_repo::{
rebase::{cherry_rebase, cherry_rebase_group},
LogUntil, RepoActionsExt, RepositoryExt,
LogUntil, RepositoryExt,
};
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::{
reconcile_claims, BranchOwnershipClaims, Stack, StackId, Target, VirtualBranchesHandle,
};

View File

@ -0,0 +1,29 @@
[package]
name = "gitbutler-repo-actions"
version = "0.0.0"
edition = "2021"
authors = ["GitButler <gitbutler@gitbutler.com>"]
publish = false
[dependencies]
git2.workspace = true
serde = { workspace = true, features = ["std"] }
tokio = { workspace = true, features = [
"rt-multi-thread",
"rt",
"macros",
"sync",
] }
log = "^0.4"
anyhow = "1.0.86"
gitbutler-command-context.workspace = true
tracing.workspace = true
gitbutler-stack.workspace = true
gitbutler-id.workspace = true
gitbutler-git.workspace = true
gitbutler-project.workspace = true
gitbutler-error.workspace = true
gitbutler-commit.workspace = true
gitbutler-reference.workspace = true
gitbutler-repo.workspace = true
gitbutler-time.workspace = true

View File

@ -0,0 +1,4 @@
pub mod askpass;
mod repository;
pub use repository::RepoActionsExt;

View File

@ -8,7 +8,8 @@ use gitbutler_project::AuthKey;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_stack::{Stack, StackId};
use crate::{askpass, credentials, RepositoryExt};
use crate::askpass;
use gitbutler_repo::{credentials, LogUntil, RepositoryExt};
pub trait RepoActionsExt {
fn fetch(&self, remote_name: &str, askpass: Option<String>) -> Result<()>;
fn push(
@ -317,22 +318,6 @@ impl RepoActionsExt for CommandContext {
}
}
type OidFilter = dyn Fn(&git2::Commit) -> Result<bool>;
/// Generally, all traversals will use no particular ordering, it's implementation defined in `git2`.
pub enum LogUntil {
/// Traverse until one sees (or gets commits older than) the given commit.
/// Do not return that commit or anything older than that.
Commit(git2::Oid),
/// Traverse the given `n` commits.
Take(usize),
/// Traverse all commits until the given condition returns `false` for a commit.
/// Note that this commit-id will also be returned.
When(Box<OidFilter>),
/// Traverse the whole graph until it is exhausted.
End,
}
async fn handle_git_prompt_push(
prompt: String,
askpass: Option<Option<StackId>>,

View File

@ -10,33 +10,21 @@ git2.workspace = true
gix = { workspace = true, features = ["status", "tree-editor"] }
anyhow = "1.0.86"
bstr.workspace = true
tokio = { workspace = true, features = [
"rt-multi-thread",
"rt",
"macros",
"sync",
] }
gitbutler-git.workspace = true
tracing.workspace = true
tempfile = "3.13"
serde = { workspace = true, features = ["std"] }
log = "^0.4"
thiserror.workspace = true
resolve-path = "0.1.0"
ssh2 = { version = "0.9.4", features = ["vendored-openssl"] }
gitbutler-command-context.workspace = true
gitbutler-config.workspace = true
gitbutler-project.workspace = true
gitbutler-branch.workspace = true
gitbutler-reference.workspace = true
gitbutler-error.workspace = true
gitbutler-id.workspace = true
gitbutler-time.workspace = true
gitbutler-commit.workspace = true
gitbutler-url.workspace = true
gitbutler-cherry-pick.workspace = true
gitbutler-oxidize.workspace = true
gitbutler-stack.workspace = true
uuid.workspace = true
itertools = "0.13"
toml.workspace = true

View File

@ -1,13 +1,10 @@
pub mod rebase;
mod repository;
pub use repository::{LogUntil, RepoActionsExt};
mod commands;
pub use commands::{FileInfo, RepoCommands};
mod repository_ext;
pub use repository_ext::{GixRepositoryExt, RepositoryExt};
pub use repository_ext::{GixRepositoryExt, LogUntil, RepositoryExt};
pub mod credentials;
@ -15,6 +12,4 @@ mod config;
pub use config::Config;
pub mod askpass;
pub mod temporary_workdir;

View File

@ -4,7 +4,7 @@ use std::os::unix::fs::PermissionsExt;
use std::os::windows::process::CommandExt;
use std::{io::Write, path::Path, process::Stdio, str};
use crate::{Config, LogUntil};
use crate::Config;
use anyhow::{anyhow, bail, Context, Result};
use bstr::BString;
use git2::{BlameOptions, StatusOptions, Tree};
@ -704,3 +704,19 @@ impl GixRepositoryExt for gix::Repository {
Ok(self)
}
}
type OidFilter = dyn Fn(&git2::Commit) -> Result<bool>;
/// Generally, all traversals will use no particular ordering, it's implementation defined in `git2`.
pub enum LogUntil {
/// Traverse until one sees (or gets commits older than) the given commit.
/// Do not return that commit or anything older than that.
Commit(git2::Oid),
/// Traverse the given `n` commits.
Take(usize),
/// Traverse all commits until the given condition returns `false` for a commit.
/// Note that this commit-id will also be returned.
When(Box<OidFilter>),
/// Traverse the whole graph until it is exhausted.
End,
}

View File

@ -30,4 +30,5 @@ path = "tests/mod.rs"
[dev-dependencies]
gitbutler-git = { workspace = true, features = ["test-askpass-path"] }
gitbutler-testsupport.workspace = true
gitbutler-repo-actions.workspace = true
tempfile = "3.13"

View File

@ -3,7 +3,8 @@ use gitbutler_command_context::CommandContext;
use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_patch_reference::{CommitOrChangeId, PatchReference};
use gitbutler_reference::RemoteRefname;
use gitbutler_repo::{LogUntil, RepoActionsExt, RepositoryExt as _};
use gitbutler_repo::{LogUntil, RepositoryExt as _};
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::VirtualBranchesHandle;
use gitbutler_stack_api::{PatchReferenceUpdate, StackExt, TargetUpdate};
use itertools::Itertools;

View File

@ -55,6 +55,7 @@ gitbutler-watcher.workspace = true
gitbutler-branch-actions.workspace = true
gitbutler-oplog.workspace = true
gitbutler-repo.workspace = true
gitbutler-repo-actions.workspace = true
gitbutler-command-context.workspace = true
gitbutler-feedback.workspace = true
gitbutler-fs.workspace = true

View File

@ -6,7 +6,8 @@ use gitbutler_command_context::CommandContext;
use gitbutler_project as projects;
use gitbutler_project::ProjectId;
use gitbutler_reference::RemoteRefname;
use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use gitbutler_repo::RepositoryExt;
use gitbutler_repo_actions::RepoActionsExt;
use gitbutler_stack::StackId;
#[derive(Clone)]

View File

@ -1,6 +1,6 @@
pub mod commands {
use gitbutler_id::id::Id;
use gitbutler_repo::askpass::{self, AskpassRequest};
use gitbutler_repo_actions::askpass::{self, AskpassRequest};
#[tauri::command(async)]
#[tracing::instrument(skip(response))]

View File

@ -77,7 +77,7 @@ fn main() {
// SAFETY(qix-): This is safe because we're initializing the askpass broker here,
// SAFETY(qix-): before any other threads would ever access it.
unsafe {
gitbutler_repo::askpass::init({
gitbutler_repo_actions::askpass::init({
let handle = app_handle.clone();
move |event| {
handle