summaryrefslogtreecommitdiff
path: root/src/diff_parse.c
Commit message (Collapse)AuthorAgeFilesLines
* refcount: make refcounting conform to aliasing rulesPatrick Steinhardt2017-11-181-1/+1
| | | | | | | | | | | | | | | | | | | | | Strict aliasing rules dictate that for most data types, you are not allowed to cast them to another data type and then access the casted pointers. While this works just fine for most compilers, technically we end up in undefined behaviour when we hurt that rule. Our current refcounting code makes heavy use of casting and thus violates that rule. While we didn't have any problems with that code, Travis started spitting out a lot of warnings due to a change in their toolchain. In the refcounting case, the code is also easy to fix: as all refcounting-statements are actually macros, we can just access the `rc` field directly instead of casting. There are two outliers in our code where that doesn't work. Both the `git_diff` and `git_patch` structures have specializations for generated and parsed diffs/patches, which directly inherit from them. Because of that, the refcounting code is only part of the base structure and not of the children themselves. We can help that by instead passing their base into `GIT_REFCOUNT_INC`, though.
* parse: extract parse modulePatrick Steinhardt2017-11-111-1/+1
| | | | | | | | | | | | | | | | | | | The `git_patch_parse_ctx` encapsulates both parser state as well as options specific to patch parsing. To advance this state and keep it consistent, we provide a few functions which handle advancing the current position and accessing bytes of the patch contents. In fact, these functions are quite generic and not related to patch-parsing by themselves. Seeing that we have similar logic inside of other modules, it becomes quite enticing to extract this functionality into its own parser module. To do so, we create a new module `parse` with a central struct called `git_parse_ctx`. It encapsulates both the content that is to be parsed as well as its lengths and the current position. `git_patch_parse_ctx` now only contains this `parse_ctx` only, which is then accessed whenever we need to touch the current parser. This is the first step towards re-using this functionality across other modules which require parsing functionality and remove code-duplication.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* diff_parse: free object instead of its pointerPatrick Steinhardt2017-04-251-1/+1
| | | | | | | | | In e7330016a (diff_parse: check return value of `git_diff_init_options`, 2017-03-20), we've introduced an error check whether we're able to correctly initialize the diff options. This simple commit actually introduced a segfault in that we now try to free the pointer to the allocated diff in an error case, instead of the allocated diff itself. This commit fixes the issue.
* diff_parse: check return value of `git_diff_init_options`Patrick Steinhardt2017-03-211-1/+5
|
* diff_parse: correctly set options for parsed diffsPatrick Steinhardt2017-03-141-1/+3
| | | | | | | | | | | | The function `diff_parsed_alloc` allocates and initializes a `git_diff_parsed` structure. This structure also contains diff options. While we initialize its flags, we fail to do a real initialization of its values. This bites us when we want to actually use the generated diff as we do not se the option's version field, which is required to operate correctly. Fix the issue by executing `git_diff_init_options` on the embedded struct.
* Teach `git_patch_from_diff` about parsed diffsethomson/patch_from_diffEdward Thomson2016-08-241-6/+2
| | | | | Ensure that `git_patch_from_diff` can return the patch for parsed diffs, not just generate a patch for a generated diff.
* introduce `git_diff_from_buffer` to parse diffsEdward Thomson2016-05-261-0/+105
Parse diff files into a `git_diff` structure.