Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings for git email create #847

Merged
merged 1 commit into from
Jun 13, 2022

Conversation

f0rget-the-sad
Copy link
Contributor

Add bindings for git_email_create_from_diff() and
git_email_create_from_commit(). Deprecate git_diff_format_email() to
reflect upstream changes.

git_diff_format_email was refactored in upsrtream.

It's also possible to impl git_email_create_from_diff/commit directly for Diff/Commit structs, and do not introduce Email struct, but I think current approach is better for future extension(e.g. there is plan to intorduce git_email_create_from_commits that produces a series of emails).

@f0rget-the-sad f0rget-the-sad force-pushed the email branch 2 times, most recently from 9dd96c5 to 1a64fbd Compare June 2, 2022 08:43
src/diff.rs Outdated
@@ -254,6 +254,8 @@ impl<'repo> Diff<'repo> {
/// Create an e-mail ready patch from a diff.
///
/// Matches the format created by `git format-patch`
#[doc(hidden)]
#[deprecated(note = "refactored to `email_from_diff` to match upstream")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this naming should be Email::from_diff perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, renamed.

@@ -3559,6 +3581,7 @@ extern "C" {
ancestor: *const git_oid,
) -> c_int;

#[deprecated(note = "refactored to `email_from_diff` to match upstream")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to skip the deprecation here since that's more for the API layer rather than the sys layer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/email.rs Outdated
Comment on lines 29 to 30
diff_opts: ptr::read(diff_opts.raw()),
diff_find_opts: ptr::read(DiffFindOptions::new().raw()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using unsafe code like ptr::read here I think this builder should probably embedd the builders for the other options? That way all the options can continue to be configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, changed.

src/email.rs Outdated
patch_count,
Binding::raw(commit_id),
summary.into_c_string()?.as_ptr(),
body.into_c_string()?.as_ptr(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think this may technically work I think it would be better to extract this to a local variable above to explicitly prevent the owned CString from being dropped too soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@f0rget-the-sad f0rget-the-sad force-pushed the email branch 2 times, most recently from 6e9ac89 to db76e5a Compare June 9, 2022 11:18
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Two more small things but otherwise seems good to go to me.

src/email.rs Outdated
/// A structure to represent patch in mbox format for sending via email
pub struct Email {
/// Buffer to store the e-mail patch in
pub buf: Buf,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making this a pub field could public accessors be provided for this? (sorry missed this earlier)

Ideally byte slices would be returned as well instead of &Buf too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/email.rs Outdated
/// Options to use when creating diffs
pub diff_options: DiffOptions,
/// Options for finding similarities within diffs
pub diff_find_options: DiffFindOptions,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making these pub could method accessors be provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Add bindings for `git_email_create_from_diff()` and
`git_email_create_from_commit()`. Deprecate `git_diff_format_email()` to
reflect upstream changes.
@alexcrichton alexcrichton merged commit d5a56e9 into rust-lang:master Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants