src/blame_git.c


Log

Author Commit Date CI Message
Edward Thomson 1458fb56 2022-01-29T07:18:26 xdiff: include new xdiff from git Update to the xdiff used in git v2.35.0, with updates to our build configuration to ignore the sort of warnings that we normally care about (signed/unsigned mismatch, unused, etc.) Any git-specific abstraction bits are now redefined for our use in `git-xdiff.h`. It is a (wildly optimistic) hope that we can use that indirection layer to standardize on a shared xdiff implementation.
punkymaniac 379c4646 2021-09-09T19:49:04 Fix coding style for pointer Make some syntax change to follow coding style.
Carl Schwan 9830ab3d 2020-01-29T02:00:04 blame: add option to ignore whitespace changes
Patrick Steinhardt c0486188 2019-08-08T10:28:09 blame_git: detect memory allocation errors The code in "blame_git.c" was mostly imported from git.git with only minor changes. One of these changes was to use our own allocators instead of git's `xmalloc`, but there's a subtle difference: `xmalloc` would abort the program if unable to allocate any memory, bit `git__malloc` doesn't. As we didn't check for memory allocation errors in some places, we might inadvertently dereference a `NULL` pointer in out-of-memory situations. Convert multiple functions to return proper error codes and add calls to `GIT_ERROR_CHECK_ALLOC` to fix this.
Edward Thomson f673e232 2018-12-27T13:47:34 git_error: use new names in internal APIs and usage Move to the `git_error` name in the internal API for error-related functions.
Edward Thomson 168fe39b 2018-11-28T14:26:57 object_type: use new enumeration names Use the new object_type enumeration names within the codebase.
Patrick Steinhardt 75203d03 2018-03-16T11:18:02 blame_git: fix coalescing step never being executed Since blame has been imported from git.git and had its first share of refactorings in b6f60a4d9 (Clean up ported code, 2013-09-21), the code is actually not doing the coalescing step of the generated blame. While the code to do the coalescing does exist, it is never being called as the function `git_blame__like_git` will directly return from its `while (true)` loop. The function that was being imported from git.git was the `assign_blame` function from "builtin/blame.c" from 717d1462b (git-blame --incremental, 2007-01-28), which hasn't really changed much. Upon taking an initial look, one can seet hat `coalesce` is actually never getting called in `assign_blame`, as well, so one may assume that not calling `coalesce` by accident is actually the right thing. But it is not, as `coalesce` is being called ever since cee7f245d (git-pickaxe: blame rewritten., 2006-10-19) after the blame has been done in the caller of `assign_blame`. Thus we can conclude the code of libgit2 is actually buggy since forever. To fix the issue, simply break out of the loop instead of doing a direct return. Note that this does not alter behaviour in any way visible to our tests, which is unfortunate. But in order to not diverge from what git.git does, I'd rather adapt to how it is being done upstream in order to avoid breaking certain edge cases than to just remove that code.
Patrick Steinhardt 0c7f49dd 2017-06-30T13:39:01 Make sure to always include "common.h" first 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.
Patrick Steinhardt 756138e4 2017-03-28T09:15:53 blame_git: check return value of `git__calloc` We do not check the return value of `git__calloc`, which may return `NULL` in out-of-memory situations. Fix the error by using `GITERR_CHECK_ALLOC`.
Patrick Steinhardt 4004d68f 2017-03-24T08:36:12 blame_git: remove spuriuous goto The recent addition of an error code to `pass_whole_blame` in ff8d2eb15 (blame_git: check return value of object lookup, 2017-03-20) introduced a spurious goto. Remove it.
Patrick Steinhardt ff8d2eb1 2017-03-20T09:34:25 blame_git: check return value of object lookup The function `pass_whole_blame` performs an object lookup but does not check if the lookup actually succeeds. Convert the function to return an error code and check for it in the calling function.
Patrick Steinhardt 21766702 2016-06-27T15:20:20 blame: do not decrement commit refcount in make_origin When we create a blame origin, we try to look up the blob that is to be blamed at a certain revision. When this lookup fails, e.g. because the file did not exist at that certain revision, we fail to create the blame origin and return `NULL`. The blame origin that we have just allocated is thereby free'd with `origin_decref`. The `origin_decref` function does not only decrement reference counts for the blame origin, though, but also for its commit and blob. When this is done in the error case, we will cause an uneven reference count for these objects. This may result in hard-to-debug failures at seemingly unrelated code paths, where we try to access these objects when they in fact have already been free'd. Fix the issue by refactoring `make_origin` such that we only allocate the object after the only function that may fail so that we do not have to call `origin_decref` at all. Also fix the `pass_blame` function, which indirectly calls `make_origin`, to free the commit when `make_origin` failed.
Patrick Steinhardt 8a4a343a 2016-03-10T16:33:49 blame_git: handle error returned by `git_commit_parent`
Patrick Steinhardt 944dbd12 2015-11-24T10:52:17 blame: use size_t for line counts in git_blame__entry The `git_blame__entry` struct keeps track of line counts with `int` fields. Since `int` is only guaranteed to be at least 16 bits we may overflow on certain platforms when line counts exceed 2^15. Fix this by instead storing line counts in `size_t`.
Edward Thomson ae195a71 2015-09-29T12:46:41 blame: guard xdiff calls for large files
Edward Thomson 234ca40a 2015-07-07T16:46:48 xdiff: upgrade to core git 2.4.5 Upgrade xdiff to version used in core git 2.4.5 (0df0541). Corrects an issue where an LF is added at EOF while applying an unrelated change (ba31180), cleans up some unused code (be89977 and e5b0662), and provides an improved callback to avoid leaking internal (to xdiff) structures (467d348). This also adds some additional functionality that we do not yet take advantage of, namely the ability to ignore changes whose lines are all blank (36617af).
Edward Thomson f1453c59 2015-02-12T12:19:37 Make our overflow check look more like gcc/clang's Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
Edward Thomson 392702ee 2015-02-09T23:41:13 allocations: test for overflow of requested size Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
Juan Rubén 0276f0f5 2014-02-26T19:22:19 Reset num_parents to 1 only for merge commits Also, correct test case to account for the boundary flag
Juan Rubén c7c83394 2014-02-21T00:22:07 Add option to limit blame to first parent
Ben Straub aad5403f 2013-11-05T10:55:54 Fix MSVC 64-bit warnings
Ben Straub 7dcb1c45 2013-10-28T11:21:23 Adjust for diff API changes
Ben Straub a7d28f40 2013-10-28T05:22:37 :heart: bool
Ben Straub 49781a03 2013-09-25T14:40:19 Blame: minor cleanup
Ben Straub b6f60a4d 2013-09-21T22:02:23 Clean up ported code
Ben Straub 0a0f0558 2013-09-20T15:51:22 git_blame is a scoreboard
Ben Straub a121e580 2013-09-20T15:20:03 Add typedefs for internal structs
Ben Straub 25c47aae 2013-09-20T14:31:51 Detect boundaries, support limiting commit range
Ben Straub 0afe9996 2013-09-17T16:46:27 Check errors from libgit2 calls
Ben Straub ceab4e26 2013-09-16T16:20:38 Port blame from git.git