Skip to content

Commit

Permalink
lib: rename Commit::{author,committer}{→ _raw}
Browse files Browse the repository at this point in the history
Prepare for `.mailmap` support.
  • Loading branch information
emilazy committed Jun 25, 2024
1 parent 6ae4f45 commit b24e73f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 45 deletions.
16 changes: 8 additions & 8 deletions cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,22 +472,22 @@ 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))
},
);
map.insert(
"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(
Expand Down
10 changes: 6 additions & 4 deletions lib/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lib/src/default_index/revset_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
};
Expand Down Expand Up @@ -1057,16 +1057,17 @@ 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) => {
let pattern = pattern.clone();
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) => {
Expand Down
28 changes: 14 additions & 14 deletions lib/tests/test_commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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")
Expand All @@ -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,
"[email protected]"
);
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,
"[email protected]"
);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions lib/tests/test_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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());
}

0 comments on commit b24e73f

Please sign in to comment.