8000 Merge pull request #1986 from libgit2/rb/error-handling-cleanups · libgit2/libgit2@79194bc · GitHub
[go: up one dir, main page]

Skip to content

Commit 79194bc

Browse files
author
Vicent Marti
committed
Merge pull request #1986 from libgit2/rb/error-handling-cleanups
Clean up some error handling and change callback error behavior
2 parents 25a1fab + 7a16d54 commit 79194bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2325
-1637
lines changed

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ OPTION( ANDROID "Build for android NDK" OFF )
3333

3434
OPTION( USE_ICONV "Link with and use iconv library" OFF )
3535
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
36+
OPTION( VALGRIND "Configure build for valgrind" OFF )
3637

3738
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
3839
SET( USE_ICONV ON )
@@ -340,9 +341,11 @@ IF (WIN32 AND NOT CYGWIN)
340341
ADD_DEFINITIONS(-DWIN32 -D_WIN32_WINNT=0x0501)
341342
FILE(GLOB SRC_OS src/win32/*.c src/win32/*.h)
342343
ELSEIF (AMIGA)
343-
ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R)
344-
FILE(GLOB SRC_OS src/amiga/*.c src/amiga/*.h)
344+
ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
345345
ELSE()
346+
IF (VALGRIND)
347+
ADD_DEFINITIONS(-DNO_MMAP)
348+
ENDIF()
346349
FILE(GLOB SRC_OS src/unix/*.c src/unix/*.h)
347350
ENDIF()
348351
FILE(GLOB SRC_GIT2 src/*.c src/*.h src/transports/*.c src/transports/*.h src/xdiff/*.c src/xdiff/*.h)

include/git2/attr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *pa
199199
* only once per attribute name, even if there are multiple
200200
* rules for a given file. The highest priority rule will be
201201
* used. Return a non-zero value from this to stop looping.
202+
* The value will be returned from `git_attr_foreach`.
202203
* @param payload Passed on as extra parameter to callback function.
203-
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
204+
* @return 0 on success, non-zero callback return value, or error code
204205
*/
205206
GIT_EXTERN(int) git_attr_foreach(
206207
git_repository *repo,

include/git2/blob.h

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,37 +159,32 @@ typedef int (*git_blob_chunk_cb)(char *content, size_t max_length, void *payload
159159
* Write a loose blob to the Object Database from a
160160
* provider of chunks of data.
161161
*
162-
* Provided the `hintpath` parameter is filled, its value
163-
* will help to determine what git filters should be applied
164-
* to the object before it can be placed to the object database.
162+
* If the `hintpath` parameter is filled, it will be used to determine
163+
* what git filters should be applied to the object before it is written
164+
* to the object database.
165165
*
166+
* The implementation of the callback MUST respect the following rules:
166167
*
167-
* The implementation of the callback has to respect the
168-
* following rules:
168+
* - `content` must be filled by the callback. The maximum number of
169+
* bytes that the buffer can accept per call is defined by the
170+
* `max_length` parameter. Allocation and freeing of the buffer will
171+
* be taken care of by libgit2.
169172
*
170-
* - `content` will have to be filled by the consumer. The maximum number
171-
* of bytes that the buffer can accept per call is defined by the
172-
* `max_length` parameter. Allocation and freeing of the buffer will be taken
173-
* care of by the function.
173+
* - The `callback` must return the number of bytes that have been
174+
* written to the `content` buffer.
174175
*
175-
* - The callback is expected to return the number of bytes
176-
* that `content` have been filled with.
177-
*
178-
* - When there is no more data to stream, the callback should
179-
* return 0. This will prevent it from being invoked anymore.
180-
*
181-
* - When an error occurs, the callback should return -1.
176+
* - When there is no more data to stream, `callback` should return
177+
* 0. This will prevent it from being invoked anymore.
182178
*
179+
* - If an error occurs, the callback should return a negative value.
180+
* This value will be returned to the caller.
183181
*
184182
* @param id Return the id of the written blob
185-
*
186-
* @param repo repository where the blob will be written.
187-
* This repository can be bare or not.
188-
*
189-
* @param hintpath if not NULL, will help selecting the filters
190-
* to apply onto the content of the blob to be created.
191-
*
192-
* @return 0 or an error code
183+
* @param repo Repository where the blob will be written.
184+
* This repository can be bare or not.
185+
* @param hintpath If not NULL, will be used to select data filters
186+
* to apply onto the content of the blob to be created.
187+
* @return 0 or error code (from either libgit2 or callback function)
193188
*/
194189
GIT_EXTERN(int) git_blob_create_fromchunks(
195190
git_oid *id,

include/git2/checkout.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ typedef enum {
174174
* - GIT_CHECKOUT_NOTIFY_IGNORED notifies about ignored files.
175175
*
176176
* Returning a non-zero value from this callback will cancel the checkout.
177-
* Notification callbacks are made prior to modifying any files on disk.
177+
* The non-zero return value will be propagated back and returned by the
178+
* git_checkout_... call.
179+
*
180+
* Notification callbacks are made prior to modifying any files on disk,
181+
* so canceling on any notification will still happen prior to any files
182+
* being modified.
178183
*/
179184
typedef enum {
180185
GIT_CHECKOUT_NOTIFY_NONE = 0,
@@ -252,9 +257,9 @@ typedef struct git_checkout_opts {
252257
*
253258
* @param repo repository to check out (must be non-bare)
254259
* @param opts specifies checkout options (may be NULL)
255-
* @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing
256-
* branch, GIT_ERROR otherwise (use giterr_last for information
257-
* about the error)
260+
* @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non
261+
* existing branch, non-zero value returned by `notify_cb`, or
262+
* other error code < 0 (use giterr_last for error details)
258263
*/
259264
GIT_EXTERN(int) git_checkout_head(
260265
git_repository *repo,
@@ -266,8 +271,8 @@ GIT_EXTERN(int) git_checkout_head(
266271
* @param repo repository into which to check out (must be non-bare)
267272
* @param index index to be checked out (or NULL to use repository index)
268273
* @param opts specifies checkout options (may be NULL)
269-
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
270-
* about the error)
274+
* @return 0 on success, non-zero return value from `notify_cb`, or error
275+
* code < 0 (use giterr_last for error details)
271276
*/
272277
GIT_EXTERN(int) git_checkout_index(
273278
git_repository *repo,
@@ -282,8 +287,8 @@ GIT_EXTERN(int) git_checkout_index(
282287
* @param treeish a commit, tag or tree which content will be used to update
283288
* the working directory (or NULL to use HEAD)
284289
* @param opts specifies checkout options (may be NULL)
285-
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
286-
* about the error)
290+
* @return 0 on success, non-zero return value from `notify_cb`, or error
291+
* code < 0 (use giterr_last for error details)
287292
*/
288293
GIT_EXTERN(int) git_checkout_tree(
289294
git_repository *repo,

include/git2/clone.h

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,25 @@ GIT_BEGIN_DECL
2626
/**
2727
* Clone options structure
2828
*
29-
* Use zeros to indicate default settings. It's easiest to use the
30-
* `GIT_CLONE_OPTIONS_INIT` macro:
29+
* Use the GIT_CLONE_OPTIONS_INIT to get the default settings, like this:
3130
*
3231
* git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
3332
*
34-
* - `checkout_opts` is options for the checkout step. To disable checkout,
35-
* set the `checkout_strategy` to GIT_CHECKOUT_DEFAULT.
36-
* - `bare` should be set to zero to create a standard repo, non-zero for
37-
* a bare repo
38-
* - `ignore_cert_errors` should be set to 1 if errors validating the remote host's
39-
* certificate should be ignored.
33+
* - `checkout_opts` are option passed to the checkout step. To disable
34+
* checkout, set the `checkout_strategy` to GIT_CHECKOUT_NONE.
35+
* Generally you will want the use GIT_CHECKOUT_SAFE_CREATE to create
36+
* all files in the working directory for the newly cloned repository.
37+
* - `bare` should be set to zero (false) to create a standard repo,
38+
* or non-zero for a bare repo
39+
* - `ignore_cert_errors` should be set to 1 if errors validating the
40+
* remote host's certificate should be ignored.
4041
*
4142
* ** "origin" remote options: **
42-
* - `remote_name` is the name given to the "origin" remote. The default is
43-
* "origin".
44-
* - `checkout_branch` gives the name of the branch to checkout. NULL means
45-
* use the remote's HEAD.
43+
*
44+
* - `remote_name` is the name to be given to the "origin" remote. The
45+
* default is "origin".
46+
* - `checkout_branch` gives the name of the branch to checkout. NULL
47+
* means use the remote's HEAD.
4648
*/
4749

4850
typedef struct git_clone_options {
@@ -70,16 +72,17 @@ typedef struct git_clone_options {
7072
* @param out pointer that will receive the resulting repository object
7173
* @param url the remote repository to clone
7274
* @param local_path local directory to clone to
73-
* @param options configuration options for the clone. If NULL, the function
74-
* works as though GIT_OPTIONS_INIT were passed.
75-
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
76-
* about the error)
75+
* @param options configuration options for the clone. If NULL, the
76+
* function works as though GIT_OPTIONS_INIT were passed.
77+
* @return 0 on success, any non-zero return value from a callback
78+
* function, or a negative value to indicate an error (use
79+
* `giterr_last` for a detailed error message)
7780
*/
7881
GIT_EXTERN(int) git_clone(
79-
git_repository **out,
80-
const char *url,
81-
const char *local_path,
82-
const git_clone_options *options);
82+
git_repository **out,
83+
const char *url,
84+
const char *local_path,
85+
const git_clone_options *options);
8386

8487
/**
8588
* Clone into a repository
@@ -91,11 +94,17 @@ GIT_EXTERN(int) git_clone(
9194
* @param repo the repository to use
9295
* @param remote the remote repository to clone from
9396
* @param co_opts options to use during checkout
94-
* @param branch the branch to checkout after the clone, pass NULL for the remote's
95-
* default branch
96-
* @return 0 on success or an error code
97+
* @param branch the branch to checkout after the clone, pass NULL for the
98+
* remote's default branch
99+
* @return 0 on success, any non-zero return value from a callback
100+
* function, or a negative value to indicate an error (use
101+
* `giterr_last` for a detailed error message)
97102
*/
98-
GIT_EXTERN(int) git_clone_into(git_repository *repo, git_remote *remote, const git_checkout_opts *co_opts, const char *branch);
103+
GIT_EXTERN(int) git_clone_into(
104+
git_repository *repo,
105+
git_remote *remote,
106+
const git_checkout_opts *co_opts,
107+
const char *branch);
99108

100109
/** @} */
101110
GIT_END_DECL

include/git2/config.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,13 @@ GIT_EXTERN(int) git_config_delete_multivar(git_config *cfg, const char *name, co
450450
*
451451
* The callback receives the normalized name and value of each variable
452452
* in the config backend, and the data pointer passed to this function.
453-
* As soon as one of the callback functions returns something other than 0,
454-
* this function stops iterating and returns `GIT_EUSER`.
453+
* If the callback returns a non-zero value, the function stop 10000 s iterating
454+
* and returns that value to the caller.
455455
*
456456
* @param cfg where to get the variables from
457457
* @param callback the function to call on each variable
458458
* @param payload the data to pass to the callback
459-
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
459+
* @return 0 on success, non-zero callback return value, or error code
460460
*/
461461
GIT_EXTERN(int) git_config_foreach(
462462
const git_config *cfg,
@@ -612,8 +612,8 @@ GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value);
612612
GIT_EXTERN(int) git_config_backend_foreach_match(
613613
git_config_backend *backend,
614614
const char *regexp,
615-
int (*fn)(const git_config_entry *, void *),
616-
void *data);
615+
git_config_foreach_cb callback,
616+
void *payload);
617617

618618

619619
/** @} */

include/git2/diff.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ typedef int (*git_diff_line_cb)(
468468
* Flags to control the behavior of diff rename/copy detection.
469469
*/
470470
typedef enum {
471-
/** Obey `diff.renames`. This is overridden by any other GIT_DIFF_FIND_ALL flag. */
471+
/** Obey `diff.renames`. Overridden by any other GIT_DIFF_FIND_... flag. */
472472
GIT_DIFF_FIND_BY_CONFIG = 0,
473473

474474
/** Look for renames? (`--find-renames`) */
@@ -577,9 +577,9 @@ typedef struct {
577577
unsigned int version;
578578

579579
/**
580-
* Combination of git_diff_find_t values (default FIND_BY_CONFIG).
581-
* Note that if you don't explicitly set this, `diff.renames` could be set
582-
* to false, resulting in `git_diff_find_similar` doing nothing.
580+
* Combination of git_diff_find_t values (default GIT_DIFF_FIND_BY_CONFIG).
581+
* NOTE: if you don't explicitly set this, `diff.renames` could be set
582+
* to false, resulting in `git_diff_find_similar` doing nothing.
583583
*/
584584
uint32_t flags;
585585

@@ -870,7 +870,7 @@ GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff);
870870
* files whose only changed is a file mode change.
871871
*
872872
* Returning a non-zero value from any of the callbacks will terminate
873-
* the iteration and cause this return `GIT_EUSER`.
873+
* the iteration and return the value to the user.
874874
*
875875
* @param diff A git_diff generated by one of the above functions.
876876
* @param file_cb Callback function to make per file in the diff.
@@ -881,7 +881,7 @@ GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff);
881881
* same callback will be made for context lines, added, and
882882
* removed lines, and even for a deleted trailing newline.
883883
* @param payload Reference pointer that will be passed to your callbacks.
884-
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
884+
* @return 0 on success, non-zero callback return value, or error code
885885
*/
886886
GIT_EXTERN(int) git_diff_foreach(
887887
git_diff *diff,
@@ -918,13 +918,13 @@ typedef enum {
918918
* Iterate over a diff generating formatted text output.
919919
*
920920
* Returning a non-zero value from the callbacks will terminate the
921-
* iteration and cause this return `GIT_EUSER`.
921+
* iteration and return the non-zero value to the caller.
922922
*
923923
* @param diff A git_diff generated by one of the above functions.
924924
* @param format A git_diff_format_t value to pick the text format.
925925
* @param print_cb Callback to make per line of diff text.
926926
* @param payload Reference pointer that will be passed to your callback.
927-
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
927+
* @return 0 on success, non-zero callback return value, or error code
928928
*/
929929
GIT_EXTERN(int) git_diff_print(
930930
git_diff *diff,
@@ -964,7 +964,7 @@ GIT_EXTERN(int) git_diff_print(
964964
* @param hunk_cb Callback for each hunk in diff; can be NULL
965965
* @param line_cb Callback for each line in diff; can be NULL
966966
* @param payload Payload passed to each callback function
967-
* @return 0 on success, GIT_EUSER on non-zero callback return, or error code
967+
* @return 0 on success, non-zero callback return value, or error code
968968
*/
969969
GIT_EXTERN(int) git_diff_blobs(
970970
const git_blob *old_blob,
@@ -999,7 +999,7 @@ GIT_EXTERN(int) git_diff_blobs(
999999
* @param hunk_cb Callback for each hunk in diff; can be NULL
10001000
* @param line_cb Callback for each line in diff; can be NULL
10011001
* @param payload Payload passed to each callback function
1002-
* @return 0 on success, GIT_EUSER on non-zero callback return, or error code
1002+
* @return 0 on success, non-zero callback return value, or error code
10031003
*/
10041004
GIT_EXTERN(int) git_diff_blob_to_buffer(
10051005
const git_blob *old_blob,

0 commit comments

Comments
 (0)
0