diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/attr.c | 9 | ||||
-rw-r--r-- | src/config_file.c | 4 | ||||
-rw-r--r-- | src/diff_output.c | 103 | ||||
-rw-r--r-- | src/notes.c | 45 | ||||
-rw-r--r-- | src/odb.c | 5 | ||||
-rw-r--r-- | src/odb_loose.c | 14 | ||||
-rw-r--r-- | src/odb_pack.c | 9 | ||||
-rw-r--r-- | src/pack.c | 11 | ||||
-rw-r--r-- | src/path.h | 1 | ||||
-rw-r--r-- | src/refs.c | 22 | ||||
-rw-r--r-- | src/status.c | 22 | ||||
-rw-r--r-- | src/transports/git.c | 6 | ||||
-rw-r--r-- | src/transports/http.c | 6 | ||||
-rw-r--r-- | src/transports/local.c | 4 |
14 files changed, 149 insertions, 112 deletions
diff --git a/src/attr.c b/src/attr.c index 6fbd005d5..c58a1f045 100644 --- a/src/attr.c +++ b/src/attr.c @@ -163,11 +163,14 @@ int git_attr_foreach( continue; git_strmap_insert(seen, assign->name, assign, error); - if (error >= 0) - error = callback(assign->name, assign->value, payload); + if (error < 0) + goto cleanup; - if (error != 0) + error = callback(assign->name, assign->value, payload); + if (error) { + error = GIT_EUSER; goto cleanup; + } } } } diff --git a/src/config_file.c b/src/config_file.c index 7ced1e5ba..80c63d2a3 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -218,8 +218,10 @@ static int file_foreach( continue; /* abort iterator on non-zero return value */ - if ((result = fn(key, var->value, data)) != 0) + if (fn(key, var->value, data)) { + result = GIT_EUSER; goto cleanup; + } } ); diff --git a/src/diff_output.c b/src/diff_output.c index f6650b345..9f8779787 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -23,6 +23,7 @@ typedef struct { unsigned int index; git_diff_delta *delta; git_diff_range range; + int error; } diff_output_info; static int read_next_int(const char **str, int *value) @@ -49,25 +50,24 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len) /* expect something of the form "@@ -%d[,%d] +%d[,%d] @@" */ if (*scan != '@') - return -1; - - if (read_next_int(&scan, &range.old_start) < 0) - return -1; - if (*scan == ',' && read_next_int(&scan, &range.old_lines) < 0) - return -1; - - if (read_next_int(&scan, &range.new_start) < 0) - return -1; - if (*scan == ',' && read_next_int(&scan, &range.new_lines) < 0) - return -1; - - if (range.old_start < 0 || range.new_start < 0) - return -1; - - memcpy(&info->range, &range, sizeof(git_diff_range)); - - return info->hunk_cb( - info->cb_data, info->delta, &range, bufs[0].ptr, bufs[0].size); + info->error = -1; + else if (read_next_int(&scan, &range.old_start) < 0) + info->error = -1; + else if (*scan == ',' && read_next_int(&scan, &range.old_lines) < 0) + info->error = -1; + else if (read_next_int(&scan, &range.new_start) < 0) + info->error = -1; + else if (*scan == ',' && read_next_int(&scan, &range.new_lines) < 0) + info->error = -1; + else if (range.old_start < 0 || range.new_start < 0) + info->error = -1; + else { + memcpy(&info->range, &range, sizeof(git_diff_range)); + + if (info->hunk_cb( + info->cb_data, info->delta, &range, bufs[0].ptr, bufs[0].size)) + info->error = GIT_EUSER; + } } if ((len == 2 || len == 3) && info->line_cb) { @@ -80,23 +80,24 @@ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len) GIT_DIFF_LINE_CONTEXT; if (info->line_cb( - info->cb_data, info->delta, &info->range, origin, bufs[1].ptr, bufs[1].size) < 0) - return -1; + info->cb_data, info->delta, &info->range, origin, bufs[1].ptr, bufs[1].size)) + info->error = GIT_EUSER; /* This should only happen if we are adding a line that does not * have a newline at the end and the old code did. In that case, * we have a ADD with a DEL_EOFNL as a pair. */ - if (len == 3) { + else if (len == 3) { origin = (origin == GIT_DIFF_LINE_ADDITION) ? GIT_DIFF_LINE_DEL_EOFNL : GIT_DIFF_LINE_ADD_EOFNL; - return info->line_cb( - info->cb_data, info->delta, &info->range, origin, bufs[2].ptr, bufs[2].size); + if (info->line_cb( + info->cb_data, info->delta, &info->range, origin, bufs[2].ptr, bufs[2].size)) + info->error = GIT_EUSER; } } - return 0; + return info->error; } #define BINARY_DIFF_FLAGS (GIT_DIFF_FILE_BINARY|GIT_DIFF_FILE_NOT_BINARY) @@ -318,6 +319,7 @@ int git_diff_foreach( xdemitconf_t xdiff_config; xdemitcb_t xdiff_callback; + memset(&info, 0, sizeof(info)); info.diff = diff; info.cb_data = data; info.hunk_cb = hunk_cb; @@ -422,11 +424,11 @@ int git_diff_foreach( * diffs to tell if a file has really been changed. */ - if (file_cb != NULL) { - error = file_cb( - data, delta, (float)info.index / diff->deltas.length); - if (error < 0) - goto cleanup; + if (file_cb != NULL && + file_cb(data, delta, (float)info.index / diff->deltas.length)) + { + error = GIT_EUSER; + goto cleanup; } /* don't do hunk and line diffs if file is binary */ @@ -451,6 +453,7 @@ int git_diff_foreach( xdl_diff(&old_xdiff_data, &new_xdiff_data, &xdiff_params, &xdiff_config, &xdiff_callback); + error = info.error; cleanup: release_content(&delta->old_file, &old_data, old_blob); @@ -524,7 +527,11 @@ static int print_compact(void *data, git_diff_delta *delta, float progress) if (git_buf_oom(pi->buf)) return -1; - return pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf)); + if (pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR, + git_buf_cstr(pi->buf), git_buf_len(pi->buf))) + return GIT_EUSER; + + return 0; } int git_diff_print_compact( @@ -586,7 +593,6 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress) const char *oldpath = delta->old_file.path; const char *newpfx = pi->diff->opts.new_prefix; const char *newpath = delta->new_file.path; - int result; GIT_UNUSED(progress); @@ -619,9 +625,8 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress) if (git_buf_oom(pi->buf)) return -1; - result = pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf)); - if (result < 0) - return result; + if (pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf))) + return GIT_EUSER; if (delta->binary != 1) return 0; @@ -633,7 +638,11 @@ static int print_patch_file(void *data, git_diff_delta *delta, float progress) if (git_buf_oom(pi->buf)) return -1; - return pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_BINARY, git_buf_cstr(pi->buf), git_buf_len(pi->buf)); + if (pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_BINARY, + git_buf_cstr(pi->buf), git_buf_len(pi->buf))) + return GIT_EUSER; + + return 0; } static int print_patch_hunk( @@ -649,7 +658,11 @@ static int print_patch_hunk( if (git_buf_printf(pi->buf, "%.*s", (int)header_len, header) < 0) return -1; - return pi->print_cb(pi->cb_data, d, r, GIT_DIFF_LINE_HUNK_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf)); + if (pi->print_cb(pi->cb_data, d, r, GIT_DIFF_LINE_HUNK_HDR, + git_buf_cstr(pi->buf), git_buf_len(pi->buf))) + return GIT_EUSER; + + return 0; } static int print_patch_line( @@ -674,7 +687,11 @@ static int print_patch_line( if (git_buf_oom(pi->buf)) return -1; - return pi->print_cb(pi->cb_data, delta, range, line_origin, git_buf_cstr(pi->buf), git_buf_len(pi->buf)); + if (pi->print_cb(pi->cb_data, delta, range, line_origin, + git_buf_cstr(pi->buf), git_buf_len(pi->buf))) + return GIT_EUSER; + + return 0; } int git_diff_print_patch( @@ -763,11 +780,8 @@ int git_diff_blobs( if (file_is_binary_by_content(&delta, &old_map, &new_map) < 0) return -1; - if (file_cb != NULL) { - int error = file_cb(cb_data, &delta, 1); - if (error < 0) - return error; - } + if (file_cb != NULL && file_cb(cb_data, &delta, 1)) + return GIT_EUSER; /* don't do hunk and line diffs if the two blobs are identical */ if (delta.status == GIT_DELTA_UNMODIFIED) @@ -777,6 +791,7 @@ int git_diff_blobs( if (delta.binary == 1) return 0; + memset(&info, 0, sizeof(info)); info.diff = NULL; info.delta = δ info.cb_data = cb_data; @@ -790,5 +805,5 @@ int git_diff_blobs( xdl_diff(&old_data, &new_data, &xdiff_params, &xdiff_config, &xdiff_callback); - return 0; + return info.error; } diff --git a/src/notes.c b/src/notes.c index 7813e9985..212413a5a 100644 --- a/src/notes.c +++ b/src/notes.c @@ -522,13 +522,13 @@ static int process_entry_path( int (*note_cb)(git_note_data *note_data, void *payload), void *payload) { - int i = 0, j = 0, error = -1, len; + int i = 0, j = 0, error, len; git_buf buf = GIT_BUF_INIT; git_note_data note_data; - if (git_buf_puts(&buf, entry_path) < 0) + if ((error = git_buf_puts(&buf, entry_path)) < 0) goto cleanup; - + len = git_buf_len(&buf); while (i < len) { @@ -536,10 +536,9 @@ static int process_entry_path( i++; continue; } - + if (git__fromhex(buf.ptr[i]) < 0) { /* This is not a note entry */ - error = 0; goto cleanup; } @@ -555,16 +554,17 @@ static int process_entry_path( if (j != GIT_OID_HEXSZ) { /* This is not a note entry */ - error = 0; goto cleanup; } - if (git_oid_fromstr(¬e_data.annotated_object_oid, buf.ptr) < 0) - return -1; + if ((error = git_oid_fromstr( + ¬e_data.annotated_object_oid, buf.ptr)) < 0) + goto cleanup; git_oid_cpy(¬e_data.blob_oid, note_oid); - error = note_cb(¬e_data, payload); + if (note_cb(¬e_data, payload)) + error = GIT_EUSER; cleanup: git_buf_free(&buf); @@ -577,34 +577,27 @@ int git_note_foreach( int (*note_cb)(git_note_data *note_data, void *payload), void *payload) { - int error = -1; + int error; git_iterator *iter = NULL; git_tree *tree = NULL; git_commit *commit = NULL; const git_index_entry *item; - if ((error = retrieve_note_tree_and_commit(&tree, &commit, repo, ¬es_ref)) < 0) - goto cleanup; - - if (git_iterator_for_tree(&iter, repo, tree) < 0) - goto cleanup; + if (!(error = retrieve_note_tree_and_commit( + &tree, &commit, repo, ¬es_ref)) && + !(error = git_iterator_for_tree(&iter, repo, tree))) + error = git_iterator_current(iter, &item); - if (git_iterator_current(iter, &item) < 0) - goto cleanup; - - while (item) { - if (process_entry_path(item->path, &item->oid, note_cb, payload) < 0) - goto cleanup; + while (!error && item) { + error = process_entry_path(item->path, &item->oid, note_cb, payload); - if (git_iterator_advance(iter, &item) < 0) - goto cleanup; + if (!error) + error = git_iterator_advance(iter, &item); } - error = 0; - -cleanup: git_iterator_free(iter); git_tree_free(tree); git_commit_free(commit); + return error; } @@ -609,9 +609,12 @@ int git_odb_foreach(git_odb *db, int (*cb)(git_oid *oid, void *data), void *data { unsigned int i; backend_internal *internal; + git_vector_foreach(&db->backends, i, internal) { git_odb_backend *b = internal->backend; - b->foreach(b, cb, data); + int error = b->foreach(b, cb, data); + if (error < 0) + return error; } return 0; diff --git a/src/odb_loose.c b/src/odb_loose.c index 2197a4264..ccb899e8c 100644 --- a/src/odb_loose.c +++ b/src/odb_loose.c @@ -680,6 +680,7 @@ struct foreach_state { size_t dir_len; int (*cb)(git_oid *oid, void *data); void *data; + int cb_error; }; GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr) @@ -718,8 +719,10 @@ static int foreach_object_dir_cb(void *_state, git_buf *path) if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0) return 0; - if (state->cb(&oid, state->data) < 0) + if (state->cb(&oid, state->data)) { + state->cb_error = GIT_EUSER; return -1; + } return 0; } @@ -728,10 +731,7 @@ static int foreach_cb(void *_state, git_buf *path) { struct foreach_state *state = (struct foreach_state *) _state; - if (git_path_direach(path, foreach_object_dir_cb, state) < 0) - return -1; - - return 0; + return git_path_direach(path, foreach_object_dir_cb, state); } static int loose_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data) @@ -749,14 +749,16 @@ static int loose_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid * git_buf_sets(&buf, objects_dir); git_path_to_dir(&buf); + memset(&state, 0, sizeof(state)); state.cb = cb; state.data = data; state.dir_len = git_buf_len(&buf); error = git_path_direach(&buf, foreach_cb, &state); + git_buf_free(&buf); - return error; + return state.cb_error ? state.cb_error : error; } static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream) diff --git a/src/odb_pack.c b/src/odb_pack.c index 4b860e864..176be5f01 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -422,6 +422,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid) static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data) { + int error; struct git_pack_file *p; struct pack_backend *backend; unsigned int i; @@ -430,12 +431,14 @@ static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *o backend = (struct pack_backend *)_backend; /* Make sure we know about the packfiles */ - if (packfile_refresh_all(backend) < 0) - return -1; + if ((error = packfile_refresh_all(backend)) < 0) + return error; git_vector_foreach(&backend->packs, i, p) { - git_pack_foreach_entry(p, cb, &data); + if ((error = git_pack_foreach_entry(p, cb, &data)) < 0) + return error; } + return 0; } diff --git a/src/pack.c b/src/pack.c index 1d88eaa7d..acdb40d35 100644 --- a/src/pack.c +++ b/src/pack.c @@ -687,10 +687,9 @@ static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_ } int git_pack_foreach_entry( - struct git_pack_file *p, - int (*cb)(git_oid *oid, void *data), - void *data) - + struct git_pack_file *p, + int (*cb)(git_oid *oid, void *data), + void *data) { const unsigned char *index = p->index_map.data, *current; unsigned stride; @@ -722,7 +721,9 @@ int git_pack_foreach_entry( current = index; for (i = 0; i < p->num_objects; i++) { - cb((git_oid *)current, data); + if (cb((git_oid *)current, data)) + return GIT_EUSER; + current += stride; } diff --git a/src/path.h b/src/path.h index d68393b3d..d611428c1 100644 --- a/src/path.h +++ b/src/path.h @@ -217,6 +217,7 @@ extern int git_path_apply_relative(git_buf *target, const char *relpath); * the input state and the second arg is pathbuf. The function * may modify the pathbuf, but only by appending new text. * @param state to pass to fn as the first arg. + * @return 0 on success, GIT_EUSER on non-zero callback, or error code */ extern int git_path_direach( git_buf *pathbuf, diff --git a/src/refs.c b/src/refs.c index b3c140bec..723695cd6 100644 --- a/src/refs.c +++ b/src/refs.c @@ -501,6 +501,7 @@ struct dirent_list_data { int (*callback)(const char *, void *); void *callback_payload; + int callback_error; }; static int _dirent_loose_listall(void *_data, git_buf *full_path) @@ -521,7 +522,10 @@ static int _dirent_loose_listall(void *_data, git_buf *full_path) return 0; /* we are filtering out this reference */ } - return data->callback(file_path, data->callback_payload); + if (data->callback(file_path, data->callback_payload)) + data->callback_error = GIT_EUSER; + + return data->callback_error; } static int _dirent_loose_load(void *data, git_buf *full_path) @@ -844,15 +848,17 @@ static int reference_path_available( const char *ref, const char* old_ref) { + int error; struct reference_available_t data; data.new_ref = ref; data.old_ref = old_ref; data.available = 1; - if (git_reference_foreach(repo, GIT_REF_LISTALL, - _reference_available_cb, (void *)&data) < 0) - return -1; + error = git_reference_foreach( + repo, GIT_REF_LISTALL, _reference_available_cb, (void *)&data); + if (error < 0) + return error; if (!data.available) { giterr_set(GITERR_REFERENCE, @@ -1487,8 +1493,8 @@ int git_reference_foreach( return -1; git_strmap_foreach(repo->references.packfile, ref_name, ref, { - if (callback(ref_name, payload) < 0) - return 0; + if (callback(ref_name, payload)) + return GIT_EUSER; }); } @@ -1500,14 +1506,16 @@ int git_reference_foreach( data.repo = repo; data.callback = callback; data.callback_payload = payload; + data.callback_error = 0; if (git_buf_joinpath(&refs_path, repo->path_repository, GIT_REFS_DIR) < 0) return -1; result = git_path_direach(&refs_path, _dirent_loose_listall, &data); + git_buf_free(&refs_path); - return result; + return data.callback_error ? GIT_EUSER : result; } static int cb__reflist_add(const char *ref, void *data) diff --git a/src/status.c b/src/status.c index d78237689..618f60fd0 100644 --- a/src/status.c +++ b/src/status.c @@ -114,7 +114,8 @@ int git_status_foreach_ext( if (show == GIT_STATUS_SHOW_INDEX_THEN_WORKDIR) { for (i = 0; !err && i < idx2head->deltas.length; i++) { i2h = GIT_VECTOR_GET(&idx2head->deltas, i); - err = cb(i2h->old_file.path, index_delta2status(i2h->status), cbdata); + if (cb(i2h->old_file.path, index_delta2status(i2h->status), cbdata)) + err = GIT_EUSER; } git_diff_list_free(idx2head); idx2head = NULL; @@ -130,14 +131,17 @@ int git_status_foreach_ext( cmp = !w2i ? -1 : !i2h ? 1 : strcmp(i2h->old_file.path, w2i->old_file.path); if (cmp < 0) { - err = cb(i2h->old_file.path, index_delta2status(i2h->status), cbdata); + if (cb(i2h->old_file.path, index_delta2status(i2h->status), cbdata)) + err = GIT_EUSER; i++; } else if (cmp > 0) { - err = cb(w2i->old_file.path, workdir_delta2status(w2i->status), cbdata); + if (cb(w2i->old_file.path, workdir_delta2status(w2i->status), cbdata)) + err = GIT_EUSER; j++; } else { - err = cb(i2h->old_file.path, index_delta2status(i2h->status) | - workdir_delta2status(w2i->status), cbdata); + if (cb(i2h->old_file.path, index_delta2status(i2h->status) | + workdir_delta2status(w2i->status), cbdata)) + err = GIT_EUSER; i++; j++; } } @@ -146,6 +150,7 @@ cleanup: git_tree_free(head); git_diff_list_free(idx2head); git_diff_list_free(wd2idx); + return err; } @@ -166,9 +171,10 @@ int git_status_foreach( } struct status_file_info { + char *expected; unsigned int count; unsigned int status; - char *expected; + int ambiguous; }; static int get_one_status(const char *path, unsigned int status, void *data) @@ -183,6 +189,7 @@ static int get_one_status(const char *path, unsigned int status, void *data) p_fnmatch(sfi->expected, path, 0) != 0)) { giterr_set(GITERR_INVALID, "Ambiguous path '%s' given to git_status_file", sfi->expected); + sfi->ambiguous = true; return GIT_EAMBIGUOUS; } @@ -215,6 +222,9 @@ int git_status_file( error = git_status_foreach_ext(repo, &opts, get_one_status, &sfi); + if (error < 0 && sfi.ambiguous) + error = GIT_EAMBIGUOUS; + if (!error && !sfi.count) { giterr_set(GITERR_INVALID, "Attempt to get status of nonexistent file '%s'", path); diff --git a/src/transports/git.c b/src/transports/git.c index 45f571f20..0d0ec7821 100644 --- a/src/transports/git.c +++ b/src/transports/git.c @@ -239,10 +239,8 @@ static int git_ls(git_transport *transport, git_headlist_cb list_cb, void *opaqu pkt = (git_pkt_ref *)p; - if (list_cb(&pkt->head, opaque) < 0) { - giterr_set(GITERR_NET, "User callback returned error"); - return -1; - } + if (list_cb(&pkt->head, opaque)) + return GIT_EUSER; } return 0; diff --git a/src/transports/http.c b/src/transports/http.c index f25d639f3..993070aac 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -324,10 +324,8 @@ static int http_ls(git_transport *transport, git_headlist_cb list_cb, void *opaq if (p->type != GIT_PKT_REF) continue; - if (list_cb(&p->head, opaque) < 0) { - giterr_set(GITERR_NET, "The user callback returned error"); - return -1; - } + if (list_cb(&p->head, opaque)) + return GIT_EUSER; } return 0; diff --git a/src/transports/local.c b/src/transports/local.c index 0e1ae3752..ccbfb0492 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -126,8 +126,8 @@ static int local_ls(git_transport *transport, git_headlist_cb list_cb, void *pay assert(transport && transport->connected); git_vector_foreach(refs, i, h) { - if (list_cb(h, payload) < 0) - return -1; + if (list_cb(h, payload)) + return GIT_EUSER; } return 0; |