Update docs for new callback return value behavior

This commit is contained in:
Russell Belfer 2013-12-09 10:17:47 -08:00
parent 26c1cb91be
commit 373cf6a932
13 changed files with 91 additions and 58 deletions

View File

@ -199,8 +199,9 @@ typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *pa
* only once per attribute name, even if there are multiple * only once per attribute name, even if there are multiple
* rules for a given file. The highest priority rule will be * rules for a given file. The highest priority rule will be
* used. Return a non-zero value from this to stop looping. * used. Return a non-zero value from this to stop looping.
* The value will be returned from `git_attr_foreach`.
* @param payload Passed on as extra parameter to callback function. * @param payload Passed on as extra parameter to callback function.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_attr_foreach( GIT_EXTERN(int) git_attr_foreach(
git_repository *repo, git_repository *repo,

View File

@ -450,13 +450,13 @@ GIT_EXTERN(int) git_config_delete_multivar(git_config *cfg, const char *name, co
* *
* The callback receives the normalized name and value of each variable * The callback receives the normalized name and value of each variable
* in the config backend, and the data pointer passed to this function. * in the config backend, and the data pointer passed to this function.
* As soon as one of the callback functions returns something other than 0, * If the callback returns a non-zero value, the function stops iterating
* this function stops iterating and returns `GIT_EUSER`. * and returns that value to the caller.
* *
* @param cfg where to get the variables from * @param cfg where to get the variables from
* @param callback the function to call on each variable * @param callback the function to call on each variable
* @param payload the data to pass to the callback * @param payload the data to pass to the callback
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_config_foreach( GIT_EXTERN(int) git_config_foreach(
const git_config *cfg, const git_config *cfg,

View File

@ -870,7 +870,7 @@ GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff);
* files whose only changed is a file mode change. * files whose only changed is a file mode change.
* *
* Returning a non-zero value from any of the callbacks will terminate * Returning a non-zero value from any of the callbacks will terminate
* the iteration and cause this return `GIT_EUSER`. * the iteration and return the value to the user.
* *
* @param diff A git_diff generated by one of the above functions. * @param diff A git_diff generated by one of the above functions.
* @param file_cb Callback function to make per file in the diff. * @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);
* same callback will be made for context lines, added, and * same callback will be made for context lines, added, and
* removed lines, and even for a deleted trailing newline. * removed lines, and even for a deleted trailing newline.
* @param payload Reference pointer that will be passed to your callbacks. * @param payload Reference pointer that will be passed to your callbacks.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_diff_foreach( GIT_EXTERN(int) git_diff_foreach(
git_diff *diff, git_diff *diff,
@ -918,13 +918,13 @@ typedef enum {
* Iterate over a diff generating formatted text output. * Iterate over a diff generating formatted text output.
* *
* Returning a non-zero value from the callbacks will terminate the * Returning a non-zero value from the callbacks will terminate the
* iteration and cause this return `GIT_EUSER`. * iteration and return the non-zero value to the caller.
* *
* @param diff A git_diff generated by one of the above functions. * @param diff A git_diff generated by one of the above functions.
* @param format A git_diff_format_t value to pick the text format. * @param format A git_diff_format_t value to pick the text format.
* @param print_cb Callback to make per line of diff text. * @param print_cb Callback to make per line of diff text.
* @param payload Reference pointer that will be passed to your callback. * @param payload Reference pointer that will be passed to your callback.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_diff_print( GIT_EXTERN(int) git_diff_print(
git_diff *diff, git_diff *diff,
@ -964,7 +964,7 @@ GIT_EXTERN(int) git_diff_print(
* @param hunk_cb Callback for each hunk in diff; can be NULL * @param hunk_cb Callback for each hunk in diff; can be NULL
* @param line_cb Callback for each line in diff; can be NULL * @param line_cb Callback for each line in diff; can be NULL
* @param payload Payload passed to each callback function * @param payload Payload passed to each callback function
* @return 0 on success, GIT_EUSER on non-zero callback return, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_diff_blobs( GIT_EXTERN(int) git_diff_blobs(
const git_blob *old_blob, const git_blob *old_blob,
@ -999,7 +999,7 @@ GIT_EXTERN(int) git_diff_blobs(
* @param hunk_cb Callback for each hunk in diff; can be NULL * @param hunk_cb Callback for each hunk in diff; can be NULL
* @param line_cb Callback for each line in diff; can be NULL * @param line_cb Callback for each line in diff; can be NULL
* @param payload Payload passed to each callback function * @param payload Payload passed to each callback function
* @return 0 on success, GIT_EUSER on non-zero callback return, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_diff_blob_to_buffer( GIT_EXTERN(int) git_diff_blob_to_buffer(
const git_blob *old_blob, const git_blob *old_blob,

View File

@ -19,25 +19,38 @@ GIT_BEGIN_DECL
/** Generic return codes */ /** Generic return codes */
typedef enum { typedef enum {
GIT_OK = 0, GIT_OK = 0, /*< No error */
GIT_ERROR = -1,
GIT_ENOTFOUND = -3,
GIT_EEXISTS = -4,
GIT_EAMBIGUOUS = -5,
GIT_EBUFS = -6,
GIT_EUSER = -7,
GIT_EBAREREPO = -8,
GIT_EUNBORNBRANCH = -9,
GIT_EUNMERGED = -10,
GIT_ENONFASTFORWARD = -11,
GIT_EINVALIDSPEC = -12,
GIT_EMERGECONFLICT = -13,
GIT_ELOCKED = -14,
GIT_PASSTHROUGH = -30, GIT_ERROR = -1, /*< Generic error */
GIT_ITEROVER = -31, GIT_ENOTFOUND = -3, /*< Requested object could not be found */
GIT_EEXISTS = -4, /*< Object exists preventing operation */
GIT_EAMBIGUOUS = -5, /*< More than one object matches */
GIT_EBUFS = -6, /*< Output buffer too short to hold data */
/* GIT_EUSER is a special error that is never generated by libgit2
* code. You can return it from a callback (e.g to stop an iteration)
* to know that it was generated by the callback and not by libgit2.
*/
GIT_EUSER = -7,
GIT_EBAREREPO = -8, /*< Operation not allowed on bare repository */
GIT_EUNBORNBRANCH = -9, /*< HEAD refers to branch with no commits */
GIT_EUNMERGED = -10, /*< Merge in progress prevented operation */
GIT_ENONFASTFORWARD = -11, /*< Reference was not fast-forwardable */
GIT_EINVALIDSPEC = -12, /*< Name/ref spec was not in a valid format */
GIT_EMERGECONFLICT = -13, /*< Merge conflicts prevented operation */
GIT_ELOCKED = -14, /*< Lock file prevented operation */
GIT_PASSTHROUGH = -30, /*< Internal only */
GIT_ITEROVER = -31, /*< Signals end of iteration with iterator */
} git_error_code; } git_error_code;
/**
* Structure to store extra details of the last error that occurred.
*
* This is kept on a per-thread basis if GIT_THREADS was defined when the
* library was build, otherwise one is kept globally for the library
*/
typedef struct { typedef struct {
char *message; char *message;
int klass; int klass;

View File

@ -493,7 +493,7 @@ GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
* item in the working directory immediately *before* it is added to / * item in the working directory immediately *before* it is added to /
* updated in the index. Returning zero will add the item to the index, * updated in the index. Returning zero will add the item to the index,
* greater than zero will skip the item, and less than zero will abort the * greater than zero will skip the item, and less than zero will abort the
* scan and cause GIT_EUSER to be returned. * scan and return that value to the caller.
* *
* @param index an existing index object * @param index an existing index object
* @param pathspec array of path patterns * @param pathspec array of path patterns
@ -502,7 +502,7 @@ GIT_EXTERN(int) git_index_remove_bypath(git_index *index, const char *path);
* gets index of matching pathspec entry); can be NULL; * gets index of matching pathspec entry); can be NULL;
* return 0 to add, >0 to skip, <0 to abort scan. * return 0 to add, >0 to skip, <0 to abort scan.
* @param payload payload passed through to callback function * @param payload payload passed through to callback function
* @return 0 or an error code * @return 0 on success, negative callback return value, or error code
*/ */
GIT_EXTERN(int) git_index_add_all( GIT_EXTERN(int) git_index_add_all(
git_index *index, git_index *index,
@ -524,7 +524,7 @@ GIT_EXTERN(int) git_index_add_all(
* gets index of matching pathspec entry); can be NULL; * gets index of matching pathspec entry); can be NULL;
* return 0 to add, >0 to skip, <0 to abort scan. * return 0 to add, >0 to skip, <0 to abort scan.
* @param payload payload passed through to callback function * @param payload payload passed through to callback function
* @return 0 or an error code * @return 0 on success, negative callback return value, or error code
*/ */
GIT_EXTERN(int) git_index_remove_all( GIT_EXTERN(int) git_index_remove_all(
git_index *index, git_index *index,
@ -553,7 +553,7 @@ GIT_EXTERN(int) git_index_remove_all(
* gets index of matching pathspec entry); can be NULL; * gets index of matching pathspec entry); can be NULL;
* return 0 to add, >0 to skip, <0 to abort scan. * return 0 to add, >0 to skip, <0 to abort scan.
* @param payload payload passed through to callback function * @param payload payload passed through to callback function
* @return 0 or an error code * @return 0 on success, negative callback return value, or error code
*/ */
GIT_EXTERN(int) git_index_update_all( GIT_EXTERN(int) git_index_update_all(
git_index *index, git_index *index,

View File

@ -189,7 +189,7 @@ GIT_EXTERN(int) git_note_default_ref(const char **out, git_repository *repo);
* *
* @param payload Extra parameter to callback function. * @param payload Extra parameter to callback function.
* *
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_note_foreach( GIT_EXTERN(int) git_note_foreach(
git_repository *repo, git_repository *repo,

View File

@ -189,7 +189,7 @@ GIT_EXTERN(int) git_odb_refresh(struct git_odb *db);
* @param db database to use * @param db database to use
* @param cb the callback to call for each object * @param cb the callback to call for each object
* @param payload data to pass to the callback * @param payload data to pass to the callback
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload); GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload);

View File

@ -218,13 +218,13 @@ GIT_EXTERN(size_t) git_patch_size(
* Serialize the patch to text via callback. * Serialize the patch to text via callback.
* *
* Returning a non-zero value from the callback will terminate the iteration * Returning a non-zero value from the callback will terminate the iteration
* and cause this return `GIT_EUSER`. * and return that value to the caller.
* *
* @param patch A git_patch representing changes to one file * @param patch A git_patch representing changes to one file
* @param print_cb Callback function to output lines of the patch. Will be * @param print_cb Callback function to output lines of the patch. Will be
* called for file headers, hunk headers, and diff lines. * called for file headers, hunk headers, and diff lines.
* @param payload Reference pointer that will be passed to your callbacks. * @param payload Reference pointer that will be passed to your callbacks.
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_patch_print( GIT_EXTERN(int) git_patch_print(
git_patch *patch, git_patch *patch,

View File

@ -132,17 +132,19 @@ GIT_EXTERN(int) git_push_finish(git_push *push);
GIT_EXTERN(int) git_push_unpack_ok(git_push *push); GIT_EXTERN(int) git_push_unpack_ok(git_push *push);
/** /**
* Call callback `cb' on each status * Invoke callback `cb' on each status entry
* *
* For each of the updated references, we receive a status report in the * For each of the updated references, we receive a status report in the
* form of `ok refs/heads/master` or `ng refs/heads/master <msg>`. * form of `ok refs/heads/master` or `ng refs/heads/master <msg>`.
* `msg != NULL` means the reference has not been updated for the given * `msg != NULL` means the reference has not been updated for the given
* reason. * reason.
* *
* Return a non-zero value from the callback to stop the loop.
*
* @param push The push object * @param push The push object
* @param cb The callback to call on each object * @param cb The callback to call on each object
* *
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_push_status_foreach(git_push *push, GIT_EXTERN(int) git_push_status_foreach(git_push *push,
int (*cb)(const char *ref, const char *msg, void *data), int (*cb)(const char *ref, const char *msg, void *data),

View File

@ -310,20 +310,33 @@ typedef int (*git_reference_foreach_name_cb)(const char *name, void *payload);
* Perform a callback on each reference in the repository. * Perform a callback on each reference in the repository.
* *
* The `callback` function will be called for each reference in the * The `callback` function will be called for each reference in the
* repository, receiving the name of the reference and the `payload` value * repository, receiving the reference object and the `payload` value
* passed to this method. Returning a non-zero value from the callback * passed to this method. Returning a non-zero value from the callback
* will terminate the iteration. * will terminate the iteration.
* *
* @param repo Repository where to find the refs * @param repo Repository where to find the refs
* @param callback Function which will be called for every listed ref * @param callback Function which will be called for every listed ref
* @param payload Additional data to pass to the callback * @param payload Additional data to pass to the callback
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_reference_foreach( GIT_EXTERN(int) git_reference_foreach(
git_repository *repo, git_repository *repo,
git_reference_foreach_cb callback, git_reference_foreach_cb callback,
void *payload); void *payload);
/**
* Perform a callback on the fully-qualified name of each reference.
*
* The `callback` function will be called for each reference in the
* repository, receiving the name of the reference and the `payload` value
* passed to this method. Returning a non-zero value from the callback
* will terminate the iteration.
*
* @param repo Repository where to find the refs
* @param callback Function which will be called for every listed ref name
* @param payload Additional data to pass to the callback
* @return 0 on success, non-zero callback return value, or error code
*/
GIT_EXTERN(int) git_reference_foreach_name( GIT_EXTERN(int) git_reference_foreach_name(
git_repository *repo, git_repository *repo,
git_reference_foreach_name_cb callback, git_reference_foreach_name_cb callback,

View File

@ -503,14 +503,18 @@ typedef int (*git_repository_fetchhead_foreach_cb)(const char *ref_name,
void *payload); void *payload);
/** /**
* Call callback 'callback' for each entry in the given FETCH_HEAD file. * Invoke 'callback' for each entry in the given FETCH_HEAD file.
*
* Return a non-zero value from the callback to stop the loop.
* *
* @param repo A repository object * @param repo A repository object
* @param callback Callback function * @param callback Callback function
* @param payload Pointer to callback data (optional) * @param payload Pointer to callback data (optional)
* @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error * @return 0 on success, non-zero callback return value, GIT_ENOTFOUND if
* there is no FETCH_HEAD file, or other error code.
*/ */
GIT_EXTERN(int) git_repository_fetchhead_foreach(git_repository *repo, GIT_EXTERN(int) git_repository_fetchhead_foreach(
git_repository *repo,
git_repository_fetchhead_foreach_cb callback, git_repository_fetchhead_foreach_cb callback,
void *payload); void *payload);
@ -518,15 +522,19 @@ typedef int (*git_repository_mergehead_foreach_cb)(const git_oid *oid,
void *payload); void *payload);
/** /**
* If a merge is in progress, call callback 'cb' for each commit ID in the * If a merge is in progress, invoke 'callback' for each commit ID in the
* MERGE_HEAD file. * MERGE_HEAD file.
* *
* Return a non-zero value from the callback to stop the loop.
*
* @param repo A repository object * @param repo A repository object
* @param callback Callback function * @param callback Callback function
* @param payload Pointer to callback data (optional) * @param payload Pointer to callback data (optional)
* @return 0 on success, GIT_ENOTFOUND, GIT_EUSER or error * @return 0 on success, non-zero callback return value, GIT_ENOTFOUND if
* there is no MERGE_HEAD file, or other error code.
*/ */
GIT_EXTERN(int) git_repository_mergehead_foreach(git_repository *repo, GIT_EXTERN(int) git_repository_mergehead_foreach(
git_repository *repo,
git_repository_mergehead_foreach_cb callback, git_repository_mergehead_foreach_cb callback,
void *payload); void *payload);

View File

@ -62,19 +62,15 @@ GIT_EXTERN(int) git_stash_save(
unsigned int flags); unsigned int flags);
/** /**
* When iterating over all the stashed states, callback that will be * This is a callback function you can provide to iterate over all the
* issued per entry. * stashed states that will be invoked per entry.
* *
* @param index The position within the stash list. 0 points to the * @param index The position within the stash list. 0 points to the
* most recent stashed state. * most recent stashed state.
*
* @param message The stash message. * @param message The stash message.
*
* @param stash_id The commit oid of the stashed state. * @param stash_id The commit oid of the stashed state.
*
* @param payload Extra parameter to callback function. * @param payload Extra parameter to callback function.
* * @return 0 to continue iterating or non-zero to stop
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/ */
typedef int (*git_stash_cb)( typedef int (*git_stash_cb)(
size_t index, size_t index,
@ -89,12 +85,12 @@ typedef int (*git_stash_cb)(
* *
* @param repo Repository where to find the stash. * @param repo Repository where to find the stash.
* *
* @param callback Callback to invoke per found stashed state. The most recent * @param callback Callback to invoke per found stashed state. The most
* stash state will be enumerated first. * recent stash state will be enumerated first.
* *
* @param payload Extra parameter to callback function. * @param payload Extra parameter to callback function.
* *
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_stash_foreach( GIT_EXTERN(int) git_stash_foreach(
git_repository *repo, git_repository *repo,

View File

@ -203,12 +203,12 @@ typedef struct {
* into this function. * into this function.
* *
* If the callback returns a non-zero value, this function will stop looping * If the callback returns a non-zero value, this function will stop looping
* and return GIT_EUSER. * and return that value to caller.
* *
* @param repo A repository object * @param repo A repository object
* @param callback The function to call on each file * @param callback The function to call on each file
* @param payload Pointer to pass through to callback function * @param payload Pointer to pass through to callback function
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_status_foreach( GIT_EXTERN(int) git_status_foreach(
git_repository *repo, git_repository *repo,
@ -227,7 +227,7 @@ GIT_EXTERN(int) git_status_foreach(
* @param opts Status options structure * @param opts Status options structure
* @param callback The function to call on each file * @param callback The function to call on each file
* @param payload Pointer to pass through to callback function * @param payload Pointer to pass through to callback function
* @return 0 on success, GIT_EUSER on non-zero callback, or error code * @return 0 on success, non-zero callback return value, or error code
*/ */
GIT_EXTERN(int) git_status_foreach_ext( GIT_EXTERN(int) git_status_foreach_ext(
git_repository *repo, git_repository *repo,