-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support for format-patch #2261
Support for format-patch #2261
Conversation
#include "buffer.h" | ||
#include "util.h" | ||
|
||
int write_file_modes_tobuf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be missing static, same for the function below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Allows for inserting the same character n amount of times
return error; | ||
} | ||
|
||
int git_format_patch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to have an object-like namespace. (Eg, git_blob
is an object and git_blob_foo
is a foo on a blob.) With that in mind, I think that git_patch_format
would be more appropriate as a name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same idea. But ...
We already have the concept of a git_patch
, which is not quite the same. This is more a collection of patches.
By the way, I am 👍 👍 👍 on the thorough test cases that you're including in your PRs. Thanks! |
Regarding the naming of the function, to me this feels like it is a flattening of We could shoehorn the special formatting into Instead of writing: git_commit_lookup(&commit, repo, &oid);
git_format_patch(&buf, repo, commit, 1, 1, NULL); you would write the slightly more verbose: git_diff_format_email_options email_opts;
git_commit_lookup(&commit, repo, &oid);
email_opts.patch_no = 1;
email_opts.total_patches = 1;
email_opts.subject_prefix = NULL; /* default to "[PATCH]" */
email_opts.signature = git_commit_author(commit);
email_opts.message = git_commit_summary(commit);
git_diff_commit(&diff, commit, NULL);
git_diff_format_email(&buf, diff, &email_opts);
git_diff_free(diff); To me, this second alternative seems to fix more neatly into the existing namespaces. However, I recognize that it is much more verbose and there is some messiness in setting up the email options correctly in order to generate appropriate patches. One thought, depending on whether you like or hate this alternative proposal would be to break things down a la the second proposal (which would give libgit2 users more flexibility in formatting various diffs for email, not just single commits), and also provide a |
Messiness is an understatement 😉. The part that took the longest was to print all the prettiness that core git does, took pretty much 85% of the time. Moving it to |
What I meant by it won't work is that it will be hard to inject the patch number and count if the prefix is provided by the user. |
Oh, that was just my overly quick reading of the meaning of the flag. Sorry! Keeping it a boolean is perfectly fine. At a basic level, does this restructuring of the API otherwise seem to make sense? I have three motivations for proposing it:
By adding the email formatting options structure, we can (incrementally) add flags / fields to support |
Genius! I'll make the changes. Maybe I got a little bit blinded by how close I am to this. |
@arrbee Is this what you meant? Note that I have added |
@arrbee So I'm trying to make this a little bit more generic, i.e. get I've added a test case for a Any suggestions or advice? |
So I got this to do the right thing (still a bit of refactoring todo), except for binary files. @arrbee I've added a test case to ensure
|
char commit_oidstr[GIT_OID_HEXSZ + 1]; | ||
|
||
git_oid_fmt(commit_oidstr, git_commit_id(commit)); | ||
commit_oidstr[GIT_OID_HEXSZ] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git_oid_tostr
does the same thing as these two lines :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and it returns a pointer to the stack buffer so you can pass it directly in the varargs in giterr_set
.
char buf[GIT_OID_HEXSZ + 1];
giterr_set(GITERR_INVALID, "Commit %s is a merge commit", git_commit_tostr(buf, 41, git_commit_id(commit)));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet! I'll use that instead :)
This is brilliant work by the way. Just that small nitpick and I think this is ready to merge. :) |
I'm still refactoring slightly, as I'm understanding the code base better :) I should finish it off tonight (I hope) |
I'm happy with this, feel that the test cases cover everything. |
…stats_insertions, git_diff_stats_deletions and git_diff_stats_to_buf
It will form part of the subject line and should thus be one line.
Ready to merge? |
I think so. :) |
Lovely job again. Can't wait to see what's next. :) |
🤘 |
Do we auto update the |
Summoning @carlosmn is the current way to "auto update the |
Haha, maybe some incarnation of a |
We could also use Travis to do that. :) |
Support for format-patch
This PR adds support for
git format-patch
behaviour. This is something we need to have for rebases #2253 and core git compatibility (git rebase
usesgit am
).It currently cannot generate a "patch" for merge commits (depends on #1965) or binary files.