move time module to it's own crate

This commit is contained in:
Kiril Videlov 2024-07-09 13:08:12 +02:00
parent bf373c5d8f
commit 9023382c78
No known key found for this signature in database
GPG Key ID: A4C733025427C471
11 changed files with 32 additions and 14 deletions

6
Cargo.lock generated
View File

@ -2355,6 +2355,7 @@ dependencies = [
"gitbutler-project",
"gitbutler-reference",
"gitbutler-testsupport",
"gitbutler-time",
"gitbutler-user",
"log",
"resolve-path",
@ -2488,6 +2489,10 @@ dependencies = [
"tempfile",
]
[[package]]
name = "gitbutler-time"
version = "0.0.0"
[[package]]
name = "gitbutler-user"
version = "0.0.0"
@ -2526,6 +2531,7 @@ dependencies = [
"gitbutler-repo",
"gitbutler-serde",
"gitbutler-testsupport",
"gitbutler-time",
"gitbutler-user",
"glob",
"hex",

View File

@ -25,6 +25,7 @@ members = [
"crates/gitbutler-id",
"crates/gitbutler-storage",
"crates/gitbutler-fs",
"crates/gitbutler-time",
]
resolver = "2"
@ -61,6 +62,7 @@ gitbutler-secret = { path = "crates/gitbutler-secret" }
gitbutler-id = { path = "crates/gitbutler-id" }
gitbutler-storage = { path = "crates/gitbutler-storage" }
gitbutler-fs = { path = "crates/gitbutler-fs" }
gitbutler-time = { path = "crates/gitbutler-time" }
[profile.release]
codegen-units = 1 # Compile crates one after another so the compiler can optimize better

View File

@ -15,7 +15,6 @@
pub mod git;
pub mod path;
pub mod time;
pub mod types;
#[cfg(target_os = "windows")]
pub mod windows;

View File

@ -26,6 +26,7 @@ gitbutler-branch.workspace = true
gitbutler-reference.workspace = true
gitbutler-error.workspace = true
gitbutler-id.workspace = true
gitbutler-time.workspace = true
[[test]]
name="repo"

View File

@ -64,7 +64,7 @@ impl RepoActions for ProjectRepo {
let commit_id: git2::Oid = branch.get().peel_to_commit()?.id();
let now = gitbutler_core::time::now_ms();
let now = gitbutler_time::time::now_ms();
let branch_name = format!("test-push-{now}");
let refname =

View File

@ -0,0 +1,8 @@
[package]
name = "gitbutler-time"
version = "0.0.0"
edition = "2021"
authors = ["GitButler <gitbutler@gitbutler.com>"]
publish = false
[dependencies]

View File

@ -0,0 +1 @@
pub mod time;

View File

@ -20,6 +20,7 @@ gitbutler-reference.workspace = true
gitbutler-error.workspace = true
gitbutler-serde.workspace = true
gitbutler-id.workspace = true
gitbutler-time.workspace = true
serde = { workspace = true, features = ["std"]}
bstr = "1.9.1"
diffy = "0.3.0"

View File

@ -206,7 +206,7 @@ pub fn set_base_branch(
},
);
let now_ms = gitbutler_core::time::now_ms();
let now_ms = gitbutler_time::time::now_ms();
let (upstream, upstream_head) = if let Refname::Local(head_name) = &head_name {
let upstream_name = target_branch_ref.with_branch(head_name.branch());

View File

@ -35,10 +35,10 @@ use crate::integration::{get_integration_commiter, get_workspace_head};
use crate::remote::{branch_to_remote_branch, RemoteBranch};
use gitbutler_branch::target;
use gitbutler_core::git::{CommitExt, CommitHeadersV2, HasCommitHeaders};
use gitbutler_core::time::now_since_unix_epoch_ms;
use gitbutler_error::error::Code;
use gitbutler_error::error::Marker;
use gitbutler_repo::rebase::{cherry_rebase, cherry_rebase_group};
use gitbutler_time::time::now_since_unix_epoch_ms;
type AppliedStatuses = Vec<(branch::Branch, BranchStatus)>;
@ -830,7 +830,7 @@ pub fn create_virtual_branch(
}
}
let now = gitbutler_core::time::now_ms();
let now = gitbutler_time::time::now_ms();
let mut branch = Branch {
id: BranchId::generate(),
@ -1764,7 +1764,7 @@ pub fn reset_branch(
let old_head = get_workspace_head(&vb_state, project_repository)?;
branch.head = target_commit_id;
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
let updated_head = get_workspace_head(&vb_state, project_repository)?;
@ -2100,7 +2100,7 @@ pub fn commit(
let vb_state = project_repository.project().virtual_branches();
branch.tree = tree_oid;
branch.head = commit_oid;
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
crate::integration::update_gitbutler_integration(&vb_state, project_repository)
@ -2696,7 +2696,7 @@ pub fn reorder_commit(
let new_head = cherry_rebase_group(project_repository, parent_oid, &mut ids_to_rebase)
.context("rebase failed")?;
branch.head = new_head;
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
crate::integration::update_gitbutler_integration(&vb_state, project_repository)
@ -2730,7 +2730,7 @@ pub fn reorder_commit(
.context("rebase failed")?;
branch.head = new_head;
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
crate::integration::update_gitbutler_integration(&vb_state, project_repository)
@ -2789,7 +2789,7 @@ pub fn insert_blank_commit(
}
}
}
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
Ok(())
@ -2837,7 +2837,7 @@ pub fn undo_commit(
if new_commit_oid != commit_oid {
branch.head = new_commit_oid;
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
crate::integration::update_gitbutler_integration(&vb_state, project_repository)
@ -2925,7 +2925,7 @@ pub fn squash(
Ok(new_head_id) => {
// save new branch head
branch.head = new_head_id;
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
crate::integration::update_gitbutler_integration(&vb_state, project_repository)
@ -3002,7 +3002,7 @@ pub fn update_commit_message(
.map_err(|err| err.context("rebase error"))?;
// save new branch head
branch.head = new_head_id;
branch.updated_timestamp_ms = gitbutler_core::time::now_ms();
branch.updated_timestamp_ms = gitbutler_time::time::now_ms();
vb_state.set_branch(branch.clone())?;
crate::integration::update_gitbutler_integration(&vb_state, project_repository)
@ -3447,7 +3447,7 @@ pub fn create_virtual_branch_from_branch(
.any(|b| b.selected_for_changes.is_some()))
.then_some(now_since_unix_epoch_ms());
let now = gitbutler_core::time::now_ms();
let now = gitbutler_time::time::now_ms();
// add file ownership based off the diff
let target_commit = repo.find_commit(default_target.sha)?;