From 8dd3003beca8a6db6f0575b2601b58bd5259cd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sat, 14 Sep 2024 18:49:18 +0200 Subject: [PATCH] refactor: mark `Timestamp` struct as `Copy` --- cli/src/commands/commit.rs | 2 +- cli/src/commands/describe.rs | 4 ++-- cli/src/operation_templater.rs | 4 ++-- lib/src/backend.rs | 2 +- lib/src/commit_builder.rs | 2 +- lib/src/op_store.rs | 2 +- lib/src/settings.rs | 2 +- lib/src/transaction.rs | 2 +- lib/tests/test_revset.rs | 32 ++++++++++++++++---------------- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cli/src/commands/commit.rs b/cli/src/commands/commit.rs index 680969a62..5d572f601 100644 --- a/cli/src/commands/commit.rs +++ b/cli/src/commands/commit.rs @@ -122,7 +122,7 @@ new working-copy commit. let new_author = Signature { name, email, - timestamp: commit_builder.author().timestamp.clone(), + timestamp: commit_builder.author().timestamp, }; commit_builder.set_author(new_author); } diff --git a/cli/src/commands/describe.rs b/cli/src/commands/describe.rs index 48881d9d5..d4f3ba295 100644 --- a/cli/src/commands/describe.rs +++ b/cli/src/commands/describe.rs @@ -155,7 +155,7 @@ pub(crate) fn cmd_describe( let new_author = Signature { name, email, - timestamp: commit.author().timestamp.clone(), + timestamp: commit.author().timestamp, }; commit_builder.set_author(new_author); } @@ -250,7 +250,7 @@ pub(crate) fn cmd_describe( let new_author = Signature { name, email, - timestamp: commit_builder.author().timestamp.clone(), + timestamp: commit_builder.author().timestamp, }; commit_builder = commit_builder.set_author(new_author); } diff --git a/cli/src/operation_templater.rs b/cli/src/operation_templater.rs index 4d0bee308..eb6b8dc3b 100644 --- a/cli/src/operation_templater.rs +++ b/cli/src/operation_templater.rs @@ -279,8 +279,8 @@ fn builtin_operation_methods() -> OperationTemplateBuildMethodFnMap { map.insert("time", |_language, _build_ctx, self_property, function| { function.expect_no_arguments()?; let out_property = self_property.map(|op| TimestampRange { - start: op.metadata().start_time.clone(), - end: op.metadata().end_time.clone(), + start: op.metadata().start_time, + end: op.metadata().end_time, }); Ok(L::wrap_timestamp_range(out_property)) }); diff --git a/lib/src/backend.rs b/lib/src/backend.rs index 2128cdde7..32b04ae26 100644 --- a/lib/src/backend.rs +++ b/lib/src/backend.rs @@ -53,7 +53,7 @@ id_type!(pub ConflictId); #[derive(ContentHash, Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)] pub struct MillisSinceEpoch(pub i64); -#[derive(ContentHash, Debug, PartialEq, Eq, Clone, PartialOrd, Ord)] +#[derive(ContentHash, Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)] pub struct Timestamp { pub timestamp: MillisSinceEpoch, // time zone offset in minutes diff --git a/lib/src/commit_builder.rs b/lib/src/commit_builder.rs index a4755db02..1884f394a 100644 --- a/lib/src/commit_builder.rs +++ b/lib/src/commit_builder.rs @@ -205,7 +205,7 @@ impl DetachedCommitBuilder { && commit.author.email == commit.committer.email && predecessor.is_discardable(repo).unwrap_or_default() { - commit.author.timestamp = commit.committer.timestamp.clone(); + commit.author.timestamp = commit.committer.timestamp; } DetachedCommitBuilder { diff --git a/lib/src/op_store.rs b/lib/src/op_store.rs index 2daa50fc3..47826b578 100644 --- a/lib/src/op_store.rs +++ b/lib/src/op_store.rs @@ -374,7 +374,7 @@ impl Operation { tz_offset: 0, }; let metadata = OperationMetadata { - start_time: timestamp.clone(), + start_time: timestamp, end_time: timestamp, description: "".to_string(), hostname: "".to_string(), diff --git a/lib/src/settings.rs b/lib/src/settings.rs index e3cffb5f1..e787f0b82 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -211,7 +211,7 @@ impl UserSettings { } pub fn signature(&self) -> Signature { - let timestamp = self.timestamp.clone().unwrap_or_else(Timestamp::now); + let timestamp = self.timestamp.unwrap_or_else(Timestamp::now); Signature { name: self.user_name(), email: self.user_email(), diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 1b0617f8a..32e98e0bf 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -150,7 +150,7 @@ pub fn create_op_metadata( let start_time = user_settings .operation_timestamp() .unwrap_or_else(Timestamp::now); - let end_time = start_time.clone(); + let end_time = start_time; let hostname = user_settings.operation_hostname(); let username = user_settings.operation_username(); OperationMetadata { diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index d7d1d2cd2..2467f1782 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -2456,7 +2456,7 @@ fn test_evaluate_expression_author() { .set_author(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp.clone(), + timestamp, }) .write() .unwrap(); @@ -2465,7 +2465,7 @@ fn test_evaluate_expression_author() { .set_author(Signature { name: "name2".to_string(), email: "email2".to_string(), - timestamp: timestamp.clone(), + timestamp, }) .write() .unwrap(); @@ -2543,12 +2543,12 @@ fn test_evaluate_expression_author_date() { .set_author(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp1.clone(), + timestamp: timestamp1, }) .set_committer(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .write() .unwrap(); @@ -2557,12 +2557,12 @@ fn test_evaluate_expression_author_date() { .set_author(Signature { name: "name2".to_string(), email: "email2".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .set_committer(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .write() .unwrap(); @@ -2576,7 +2576,7 @@ fn test_evaluate_expression_author_date() { .set_committer(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .write() .unwrap(); @@ -2610,12 +2610,12 @@ fn test_evaluate_expression_committer_date() { .set_author(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .set_committer(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp1.clone(), + timestamp: timestamp1, }) .write() .unwrap(); @@ -2624,12 +2624,12 @@ fn test_evaluate_expression_committer_date() { .set_author(Signature { name: "name2".to_string(), email: "email2".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .set_committer(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .write() .unwrap(); @@ -2638,7 +2638,7 @@ fn test_evaluate_expression_committer_date() { .set_author(Signature { name: "name3".to_string(), email: "email3".to_string(), - timestamp: timestamp2.clone(), + timestamp: timestamp2, }) .set_committer(Signature { name: "name1".to_string(), @@ -2676,7 +2676,7 @@ fn test_evaluate_expression_mine() { .set_author(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp.clone(), + timestamp, }) .write() .unwrap(); @@ -2685,7 +2685,7 @@ fn test_evaluate_expression_mine() { .set_author(Signature { name: "name2".to_string(), email: settings.user_email(), - timestamp: timestamp.clone(), + timestamp, }) .write() .unwrap(); @@ -2745,7 +2745,7 @@ fn test_evaluate_expression_committer() { .set_committer(Signature { name: "name1".to_string(), email: "email1".to_string(), - timestamp: timestamp.clone(), + timestamp, }) .write() .unwrap(); @@ -2754,7 +2754,7 @@ fn test_evaluate_expression_committer() { .set_committer(Signature { name: "name2".to_string(), email: "email2".to_string(), - timestamp: timestamp.clone(), + timestamp, }) .write() .unwrap();