Reading patch files#3223
Conversation
c0f0f65 to
0fa6725
Compare
464cb59 to
c1e2ab5
Compare
1c4837a to
aa72c47
Compare
|
So I think that we should review this now, and not worry about the three bullet points that I had previously listed, all of which have to do with the ability to apply patches that were created by old (non-git) Broadly speaking, these changes lay the groundwork for apply patches that are created by (for example) our I'm really happy with the "guts" of this, though diff-based patches and the diff mechanism are still fairly intertwined in a way that I could not easily refactor in the time allotted. (And I allotted myself a lot of time, this has been cooking off and on for a year and a half. Mostly "off", but still. Sheesh.) But the APIs need some work here. I don't think that the APIs are hard, here, just the terminology. Some things to point out: Our I think that broadly speaking, we will need two objects - a There are interesting other APIs that might surface, like pulling patches out of a patchlist, and perhaps applying a I actually think that the best course of action here is to drop the new Thoughts? |
|
I think it makes sense to restrict ourselves to git-produced patches; we shouldn't try to be a general replacement for patch(1). Regarding the naming for This is a generous number of commits, so it's bound to take some time to review. Thanks for sticking to it. |
That's true. I had initially not wanted to tackle that, because it would mean making |
c5dda46 to
214a27b
Compare
|
A couple of quick additions to squash some warnings and memory leaks. While doing that, I realized that the single For now, I'm just dup'ing the whole damned patch file, which is a minor amount of additional memory (just some paths and some prefixes) but reduces memory fragmentation or the need to pool or something else silly. I don't imagine that it will stick around in its current form for very long, anyway. |
6bb0e48 to
891ac49
Compare
7dee9fa to
829bb21
Compare
There was a problem hiding this comment.
Do we maybe wanna use p_strnlen() here instead of open-coding it?
There was a problem hiding this comment.
Sorry, not p_strnlen() but memchr().
Test with some postimages that actually grow/shrink from the original, adding new lines or removing them. (Also do so without context to ensure that we can add/remove from a non-zero part of the line vector.)
Parse diff files into a `git_diff` structure.
Like `git_patch_to_buf`, provide a simple helper method that can print an entire diff directory to a `git_buf`.
| git_diff *computed, *parsed; | ||
| git_tree *a, *b; | ||
| git_diff_options opts = GIT_DIFF_OPTIONS_INIT; | ||
| git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT; |
|
I took a quick look and things seems sensible (other than that one piece of indentation 😈) so I think we should merge it and let is have wider usage. |
Test that we can create a diff file, then parse the results and that the two are identical in-memory.
Patches may have no hunks when there's no modifications (for example, in a rename). Handle them.
When showing copy information because we are duplicating contents, for example, when performing a `diff --find-copies-harder -M100 -B100`, then show copy from/to lines in a patch, and do not show context. Ensure that we can also parse such patches.

Moved #2280 over here and based it on master. With the refactored binary diff handling, I can proceed on binary application.
This PR is attempting to take an initial bite out of patch application, a la
git-apply. My goal is to parse a git-style patch file created with libgit2 or git.git into agit_patchand be able to apply agit_patchto a buffer. This does not yet open up any public API for application, just internal methods; I was hoping to get some eyeballs on this and perhaps even merge it before I did something like applying patches into the working directory.Traditional-format patches (should just need to parse their headers)Improved whitespace tolerance during applicationContext reduction during application