Commit Graph

15 Commits

Author SHA1 Message Date
lhchavez 37d110dbf0
Refactor all callbacks (#700) (#705)
This change is a preparation for another change that makes all callback
types return a Go error instead of an error code / an integer. That is
going to make make things a lot more idiomatic.

The reason this change is split is threefold:

a) This change is mostly mechanical and should contain no semantic
   changes.
b) This change is backwards-compatible (in the Go API compatibility
   sense of the word), and thus can be backported to all other releases.
c) It makes the other change a bit smaller and more focused on just one
   thing.

Concretely, this change makes all callbacks populate a Go error when
they fail. If the callback is invoked from the same stack as the
function to which it was passed (e.g. for `Tree.Walk`), it will preserve
the error object directly into a struct that also holds the callback
function. Otherwise if the callback is pased to one func and will be
invoked when run from another one (e.g. for `Repository.InitRebase`),
the error string is saved into the libgit2 thread-local storage and then
re-created as a `GitError`.

(cherry picked from commit 5d8eaf7e65)
2020-12-05 17:10:18 -08:00
lhchavez 14e29a3390 Fix a potential use-after-free in DiffNotifyCallback (#579)
This change makes the DiffNotifyCallback always use an "unowned"
*git.Diff that does _not_ run the finalizer. Since the underlying
git_diff object is still owned by libgit2, we shouldn't be calling
Diff.Free() on it, even by accident, since that would cause a whole lot
of undefined behavior.

Now instead of storing a reference to a *git.Diff in the intermediate
state while the diff operation is being done, create a brand new
*git.Diff for every callback invocation, and only create a fully-owned
*git.Diff when the diff operation is done and the ownership is
transfered to Go.

(cherry picked from commit c78ae57de6)
2020-08-16 07:19:09 -07:00
Carlos Martín Nieto a69a0b1919 patch: adjust to new function signature 2017-09-29 09:49:21 +02:00
Carlos Martín Nieto 0ebe7220d7 Go back to the v0.26 libgit2 release
Newer commits have changed the build scripts such that the HTTP parser is not
included in the static library.

This also reverts commit ecf4f7a137.
2017-09-03 19:49:30 +02:00
Carlos Martín Nieto ecf4f7a137 patch: correct a pointer type 2017-09-03 16:59:05 +02:00
Carlos Martín Nieto 55a1096141 Third round of keep-alive aditions 2017-07-08 16:07:51 +02:00
Adam Berkovec de521bb2b4 Fix memory leak in Patch.String()
Buffer allocated in Patch.String() was never freed

Signed-off-by: Can Berk Güder <cbguder@pivotal.io>
2017-03-23 12:16:43 -07:00
Carlos Martín Nieto cb6201b633 Add missing thread-locking 2014-12-11 02:46:42 +01:00
Jose Alvarez db17135a30 Export PatchFromBuffers function.
This change also factor out diffOptionsToC function to remove
duplicated code.
2014-12-06 16:29:25 -05:00
Carlos Martín Nieto 8c631b0c25 Add missing thread locking 2014-12-06 02:45:26 +01:00
Jesse Ezell 155f641683 don't expose 3 different diff foreach methods. use structures instead of pointers to structures for diff detail. add patch error code handling. trim excess data from diff structures. 2014-03-21 22:51:38 -07:00
Jesse Ezell aea899e877 set ptr to nil after free 2014-03-20 23:19:22 -07:00
Jesse Ezell d78036fe24 refactor and cleanup code 2014-03-20 22:54:18 -07:00
Jesse Ezell d0b334b244 cleanup and refactor diff / patch 2014-03-20 21:56:41 -07:00
lye bc80beb843 Add partial diff/patch functionality.
This commit adds barebones capacity to generate diffs from two trees and
to emit those as git-style diffs (via `Patch.String`), or to enumerate
the files/hunks/lines in the diff to emit the data yourself.

The walk functions have been implemented in the same manner as the Odb
walking methods.

Note that not all of the functionality is implemented for either the
`git_diff_*` nor the `git_patch_*` functions, and there are unexposed
constants which would likely be useful to add.
2014-02-20 00:29:03 -06:00