diff --git a/cli/src/commands/git/push.rs b/cli/src/commands/git/push.rs index e2bc696fa3..ce530a8295 100644 --- a/cli/src/commands/git/push.rs +++ b/cli/src/commands/git/push.rs @@ -289,14 +289,14 @@ pub fn cmd_git_push( if commit.description().is_empty() && !args.allow_empty_description { reasons.push("it has no description"); } - if commit.author().name.is_empty() - || commit.author().name == UserSettings::USER_NAME_PLACEHOLDER - || commit.author().email.is_empty() - || commit.author().email == UserSettings::USER_EMAIL_PLACEHOLDER - || commit.committer().name.is_empty() - || commit.committer().name == UserSettings::USER_NAME_PLACEHOLDER - || commit.committer().email.is_empty() - || commit.committer().email == UserSettings::USER_EMAIL_PLACEHOLDER + if commit.author_raw().name.is_empty() + || commit.author_raw().name == UserSettings::USER_NAME_PLACEHOLDER + || commit.author_raw().email.is_empty() + || commit.author_raw().email == UserSettings::USER_EMAIL_PLACEHOLDER + || commit.committer_raw().name.is_empty() + || commit.committer_raw().name == UserSettings::USER_NAME_PLACEHOLDER + || commit.committer_raw().email.is_empty() + || commit.committer_raw().email == UserSettings::USER_EMAIL_PLACEHOLDER { reasons.push("it has no author and/or committer set"); } diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index cfae822f35..df276bdfa3 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -472,7 +472,7 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm "author", |_language, _build_ctx, self_property, function| { function.expect_no_arguments()?; - let out_property = self_property.map(|commit| commit.author().clone()); + let out_property = self_property.map(|commit| commit.author_raw().clone()); Ok(L::wrap_signature(out_property)) }, ); @@ -480,14 +480,14 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm "committer", |_language, _build_ctx, self_property, function| { function.expect_no_arguments()?; - let out_property = self_property.map(|commit| commit.committer().clone()); + let out_property = self_property.map(|commit| commit.committer_raw().clone()); Ok(L::wrap_signature(out_property)) }, ); map.insert("mine", |language, _build_ctx, self_property, function| { function.expect_no_arguments()?; let user_email = language.revset_parse_context.user_email().to_owned(); - let out_property = self_property.map(move |commit| commit.author().email == user_email); + let out_property = self_property.map(move |commit| commit.author_raw().email == user_email); Ok(L::wrap_boolean(out_property)) }); map.insert( diff --git a/lib/src/commit.rs b/lib/src/commit.rs index 78d9934437..30ce536524 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -145,11 +145,13 @@ impl Commit { &self.data.description } - pub fn author(&self) -> &Signature { + /// Returns the raw author signature from the commit data. + pub fn author_raw(&self) -> &Signature { &self.data.author } - pub fn committer(&self) -> &Signature { + /// Returns the raw committer signature from the commit data. + pub fn committer_raw(&self) -> &Signature { &self.data.committer } @@ -193,8 +195,8 @@ pub(crate) struct CommitByCommitterTimestamp(pub Commit); impl Ord for CommitByCommitterTimestamp { fn cmp(&self, other: &Self) -> Ordering { - let self_timestamp = &self.0.committer().timestamp.timestamp; - let other_timestamp = &other.0.committer().timestamp.timestamp; + let self_timestamp = &self.0.committer_raw().timestamp.timestamp; + let other_timestamp = &other.0.committer_raw().timestamp.timestamp; self_timestamp .cmp(other_timestamp) .then_with(|| self.0.cmp(&other.0)) // to comply with Eq diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index 9afbbdd9bc..f5f78edce9 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -965,7 +965,7 @@ impl<'index> EvaluationContext<'index> { let entry = self.index.entry_by_pos(pos); let commit = self.store.get_commit(&entry.commit_id()).unwrap(); Reverse(Item { - timestamp: commit.committer().timestamp.timestamp, + timestamp: commit.committer_raw().timestamp.timestamp, pos: entry.position(), }) }; @@ -1057,7 +1057,8 @@ fn build_predicate_fn( box_pure_predicate_fn(move |index, pos| { let entry = index.entry_by_pos(pos); let commit = store.get_commit(&entry.commit_id()).unwrap(); - pattern.matches(&commit.author().name) || pattern.matches(&commit.author().email) + pattern.matches(&commit.author_raw().name) + || pattern.matches(&commit.author_raw().email) }) } RevsetFilterPredicate::Committer(pattern) => { @@ -1065,8 +1066,8 @@ fn build_predicate_fn( box_pure_predicate_fn(move |index, pos| { let entry = index.entry_by_pos(pos); let commit = store.get_commit(&entry.commit_id()).unwrap(); - pattern.matches(&commit.committer().name) - || pattern.matches(&commit.committer().email) + pattern.matches(&commit.committer_raw().name) + || pattern.matches(&commit.committer_raw().email) }) } RevsetFilterPredicate::File(expr) => { diff --git a/lib/tests/test_commit_builder.rs b/lib/tests/test_commit_builder.rs index 7ac52c69b1..7b79303494 100644 --- a/lib/tests/test_commit_builder.rs +++ b/lib/tests/test_commit_builder.rs @@ -82,8 +82,8 @@ fn test_initial(backend: TestRepoBackend) { assert_eq!(parents, vec![store.root_commit()]); assert!(commit.predecessors().next().is_none()); assert_eq!(commit.description(), "description"); - assert_eq!(commit.author(), &author_signature); - assert_eq!(commit.committer(), &committer_signature); + assert_eq!(commit.author_raw(), &author_signature); + assert_eq!(commit.committer_raw(), &committer_signature); assert_eq!( store .root_commit() @@ -158,14 +158,14 @@ fn test_rewrite(backend: TestRepoBackend) { assert_eq!(parents, vec![store.root_commit()]); let predecessors: Vec<_> = rewritten_commit.predecessors().try_collect().unwrap(); assert_eq!(predecessors, vec![initial_commit.clone()]); - assert_eq!(rewritten_commit.author().name, settings.user_name()); - assert_eq!(rewritten_commit.author().email, settings.user_email()); + assert_eq!(rewritten_commit.author_raw().name, settings.user_name()); + assert_eq!(rewritten_commit.author_raw().email, settings.user_email()); assert_eq!( - rewritten_commit.committer().name, + rewritten_commit.committer_raw().name, rewrite_settings.user_name() ); assert_eq!( - rewritten_commit.committer().email, + rewritten_commit.committer_raw().email, rewrite_settings.user_email() ); assert_eq!( @@ -214,10 +214,10 @@ fn test_rewrite_update_missing_user(backend: TestRepoBackend) { ) .write() .unwrap(); - assert_eq!(initial_commit.author().name, ""); - assert_eq!(initial_commit.author().email, ""); - assert_eq!(initial_commit.committer().name, ""); - assert_eq!(initial_commit.committer().email, ""); + assert_eq!(initial_commit.author_raw().name, ""); + assert_eq!(initial_commit.author_raw().email, ""); + assert_eq!(initial_commit.committer_raw().name, ""); + assert_eq!(initial_commit.committer_raw().email, ""); let config = config::Config::builder() .set_override("user.name", "Configured User") @@ -233,14 +233,14 @@ fn test_rewrite_update_missing_user(backend: TestRepoBackend) { .write() .unwrap(); - assert_eq!(rewritten_commit.author().name, "Configured User"); + assert_eq!(rewritten_commit.author_raw().name, "Configured User"); assert_eq!( - rewritten_commit.author().email, + rewritten_commit.author_raw().email, "configured.user@example.com" ); - assert_eq!(rewritten_commit.committer().name, "Configured User"); + assert_eq!(rewritten_commit.committer_raw().name, "Configured User"); assert_eq!( - rewritten_commit.committer().email, + rewritten_commit.committer_raw().email, "configured.user@example.com" ); } diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index 3f8a98a8cb..6594dd0c48 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -3121,8 +3121,8 @@ fn test_rewrite_imported_commit() { imported_commit.parent_ids().to_vec(), imported_commit.tree_id().clone(), ) - .set_author(imported_commit.author().clone()) - .set_committer(imported_commit.committer().clone()) + .set_author(imported_commit.author_raw().clone()) + .set_committer(imported_commit.committer_raw().clone()) .set_description(imported_commit.description()) .write() .unwrap(); @@ -3132,8 +3132,8 @@ fn test_rewrite_imported_commit() { // commit should be adjusted to create new commit. assert_ne!(imported_commit.id(), authored_commit.id()); assert_ne!( - imported_commit.committer().timestamp, - authored_commit.committer().timestamp, + imported_commit.committer_raw().timestamp, + authored_commit.committer_raw().timestamp, ); // The index should be consistent with the store. diff --git a/lib/tests/test_init.rs b/lib/tests/test_init.rs index 23ca072215..ee4aa018a1 100644 --- a/lib/tests/test_init.rs +++ b/lib/tests/test_init.rs @@ -150,10 +150,10 @@ fn test_init_no_config_set(backend: TestRepoBackend) { .get_wc_commit_id(&WorkspaceId::default()) .unwrap(); let wc_commit = repo.store().get_commit(wc_commit_id).unwrap(); - assert_eq!(wc_commit.author().name, "".to_string()); - assert_eq!(wc_commit.author().email, "".to_string()); - assert_eq!(wc_commit.committer().name, "".to_string()); - assert_eq!(wc_commit.committer().email, "".to_string()); + assert_eq!(wc_commit.author_raw().name, "".to_string()); + assert_eq!(wc_commit.author_raw().email, "".to_string()); + assert_eq!(wc_commit.committer_raw().name, "".to_string()); + assert_eq!(wc_commit.committer_raw().email, "".to_string()); } #[test_case(TestRepoBackend::Local ; "local backend")] @@ -175,8 +175,8 @@ fn test_init_checkout(backend: TestRepoBackend) { ); assert!(wc_commit.predecessors().next().is_none()); assert_eq!(wc_commit.description(), ""); - assert_eq!(wc_commit.author().name, settings.user_name()); - assert_eq!(wc_commit.author().email, settings.user_email()); - assert_eq!(wc_commit.committer().name, settings.user_name()); - assert_eq!(wc_commit.committer().email, settings.user_email()); + assert_eq!(wc_commit.author_raw().name, settings.user_name()); + assert_eq!(wc_commit.author_raw().email, settings.user_email()); + assert_eq!(wc_commit.committer_raw().name, settings.user_name()); + assert_eq!(wc_commit.committer_raw().email, settings.user_email()); }