mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-04 03:05:04 +00:00 
			
		
		
		
	Deploy GITERR_CHECK_VERSION
This commit is contained in:
		
							parent
							
								
									4ec197f304
								
							
						
					
					
						commit
						c7231c45fe
					
				@ -603,19 +603,6 @@ static int checkout_create_submodules(
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool opts_is_valid_version(git_checkout_opts *opts)
 | 
			
		||||
{
 | 
			
		||||
	if (!opts)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (opts->version > 0 &&  opts->version <= GIT_CHECKOUT_OPTS_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d on git_checkout_opts structure",
 | 
			
		||||
			opts->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int git_checkout_index(
 | 
			
		||||
	git_repository *repo,
 | 
			
		||||
	git_index *index,
 | 
			
		||||
@ -632,6 +619,8 @@ int git_checkout_index(
 | 
			
		||||
 | 
			
		||||
	assert(repo);
 | 
			
		||||
 | 
			
		||||
	GITERR_CHECK_VERSION(opts, GIT_CHECKOUT_OPTS_VERSION, "git_checkout_opts");
 | 
			
		||||
 | 
			
		||||
	if ((error = git_repository__ensure_not_bare(repo, "checkout")) < 0)
 | 
			
		||||
		return error;
 | 
			
		||||
 | 
			
		||||
@ -639,11 +628,6 @@ int git_checkout_index(
 | 
			
		||||
		GIT_DIFF_INCLUDE_UNMODIFIED | GIT_DIFF_INCLUDE_UNTRACKED |
 | 
			
		||||
		GIT_DIFF_INCLUDE_TYPECHANGE | GIT_DIFF_SKIP_BINARY_CHECK;
 | 
			
		||||
 | 
			
		||||
	if (!opts_is_valid_version(opts)) {
 | 
			
		||||
      error = -1;
 | 
			
		||||
		goto cleanup;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
	if (opts && opts->paths.count > 0)
 | 
			
		||||
		diff_opts.pathspec = opts->paths;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -93,9 +93,8 @@ int git_commit_create(
 | 
			
		||||
	git_odb *odb;
 | 
			
		||||
 | 
			
		||||
	assert(git_object_owner((const git_object *)tree) == repo);
 | 
			
		||||
	if (!git_signature__has_valid_version(author) ||
 | 
			
		||||
		 !git_signature__has_valid_version(committer))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(author, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
	GITERR_CHECK_VERSION(committer, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
 | 
			
		||||
	git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								src/common.h
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/common.h
									
									
									
									
									
								
							@ -65,6 +65,23 @@ void giterr_set(int error_class, const char *string, ...);
 | 
			
		||||
 */
 | 
			
		||||
void giterr_set_regex(const regex_t *regex, int error_code);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Check a versioned structure for validity
 | 
			
		||||
 */
 | 
			
		||||
GIT_INLINE(bool) giterr__check_version(const void *structure, unsigned int expected_max, const char *name)
 | 
			
		||||
{
 | 
			
		||||
	if (!structure)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	unsigned int actual = *(unsigned int*)structure;
 | 
			
		||||
	if (actual > 0 && actual <= expected_max)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d on %s", actual, name);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
#define GITERR_CHECK_VERSION(S,V,N) if (!giterr__check_version(S,V,N)) return -1
 | 
			
		||||
 | 
			
		||||
/* NOTE: other giterr functions are in the public errors.h header file */
 | 
			
		||||
 | 
			
		||||
#include "util.h"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								src/config.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/config.c
									
									
									
									
									
								
							@ -248,18 +248,6 @@ int git_config_open_level(
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool config_backend_has_valid_version(git_config_backend *backend)
 | 
			
		||||
{
 | 
			
		||||
	if (!backend)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (backend->version > 0 && backend->version <= GIT_CONFIG_BACKEND_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d for git_config_backend", backend->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int git_config_add_backend(
 | 
			
		||||
	git_config *cfg,
 | 
			
		||||
	git_config_backend *file,
 | 
			
		||||
@ -271,8 +259,7 @@ int git_config_add_backend(
 | 
			
		||||
 | 
			
		||||
	assert(cfg && file);
 | 
			
		||||
 | 
			
		||||
	if (!config_backend_has_valid_version(file))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(file, GIT_CONFIG_BACKEND_VERSION, "git_config_backend");
 | 
			
		||||
 | 
			
		||||
	if ((result = file->open(file, level)) < 0)
 | 
			
		||||
		return result;
 | 
			
		||||
 | 
			
		||||
@ -758,9 +758,8 @@ fail:
 | 
			
		||||
#define DIFF_FROM_ITERATORS(MAKE_FIRST, MAKE_SECOND) do { \
 | 
			
		||||
	git_iterator *a = NULL, *b = NULL; \
 | 
			
		||||
	char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; \
 | 
			
		||||
	if (!git_diff__opts_has_valid_version(opts)) \
 | 
			
		||||
		error = -1; \
 | 
			
		||||
	else if (!(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \
 | 
			
		||||
	GITERR_CHECK_VERSION(opts, GIT_DIFF_OPTIONS_VERSION, "git_diff_options"); \
 | 
			
		||||
	if (!(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \
 | 
			
		||||
		error = diff_from_iterators(diff, repo, a, b, opts); \
 | 
			
		||||
	git__free(pfx); git_iterator_free(a); git_iterator_free(b); \
 | 
			
		||||
} while (0)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								src/diff.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/diff.h
									
									
									
									
									
								
							@ -62,18 +62,5 @@ extern int git_diff__oid_for_file(
 | 
			
		||||
	git_repository *, const char *, uint16_t, git_off_t, git_oid *);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GIT_INLINE(bool) git_diff__opts_has_valid_version(const git_diff_options *opts)
 | 
			
		||||
{
 | 
			
		||||
	if (!opts)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (opts->version > 0 && opts->version <= GIT_DIFF_OPTIONS_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d in git_diff_options", opts->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1266,8 +1266,7 @@ int git_diff_blobs(
 | 
			
		||||
	git_diff_delta delta;
 | 
			
		||||
	git_diff_patch patch;
 | 
			
		||||
 | 
			
		||||
   if (!git_diff__opts_has_valid_version(options))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(options, GIT_DIFF_OPTIONS_VERSION, "git_diff_options");
 | 
			
		||||
 | 
			
		||||
	if (options && (options->flags & GIT_DIFF_REVERSE)) {
 | 
			
		||||
		git_blob *swap = old_blob;
 | 
			
		||||
 | 
			
		||||
@ -168,18 +168,6 @@ int git_diff_merge(
 | 
			
		||||
	return error;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool find_opts_has_valid_version(const git_diff_find_options *opts)
 | 
			
		||||
{
 | 
			
		||||
	if (!opts)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (opts->version > 0 && opts->version <= GIT_DIFF_FIND_OPTIONS_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d on git_diff_find_options", opts->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define DEFAULT_THRESHOLD 50
 | 
			
		||||
#define DEFAULT_BREAK_REWRITE_THRESHOLD 60
 | 
			
		||||
#define DEFAULT_TARGET_LIMIT 200
 | 
			
		||||
@ -211,8 +199,7 @@ static int normalize_find_opts(
 | 
			
		||||
			opts->flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!find_opts_has_valid_version(opts))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(opts, GIT_DIFF_FIND_OPTIONS_VERSION, "git_diff_find_options");
 | 
			
		||||
 | 
			
		||||
	/* some flags imply others */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								src/notes.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/notes.c
									
									
									
									
									
								
							@ -456,9 +456,8 @@ int git_note_create(
 | 
			
		||||
	git_commit *commit = NULL;
 | 
			
		||||
	git_tree *tree = NULL;
 | 
			
		||||
 | 
			
		||||
	if (!git_signature__has_valid_version(author) ||
 | 
			
		||||
		 !git_signature__has_valid_version(committer))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(author, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
	GITERR_CHECK_VERSION(committer, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
 | 
			
		||||
	target = git_oid_allocfmt(oid);
 | 
			
		||||
	GITERR_CHECK_ALLOC(target);
 | 
			
		||||
@ -487,9 +486,8 @@ int git_note_remove(git_repository *repo, const char *notes_ref,
 | 
			
		||||
	git_commit *commit = NULL;
 | 
			
		||||
	git_tree *tree = NULL;
 | 
			
		||||
 | 
			
		||||
	if (!git_signature__has_valid_version(author) ||
 | 
			
		||||
		 !git_signature__has_valid_version(committer))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(author, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
	GITERR_CHECK_VERSION(committer, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
 | 
			
		||||
	target = git_oid_allocfmt(oid);
 | 
			
		||||
	GITERR_CHECK_ALLOC(target);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								src/odb.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/odb.c
									
									
									
									
									
								
							@ -363,26 +363,13 @@ int git_odb_new(git_odb **out)
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool backend_has_valid_version(git_odb_backend *backend)
 | 
			
		||||
{
 | 
			
		||||
	if (!backend)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (backend->version > 0 && backend->version <= GIT_ODB_BACKEND_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d on git_odb_backend", backend->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int add_backend_internal(git_odb *odb, git_odb_backend *backend, int priority, int is_alternate)
 | 
			
		||||
{
 | 
			
		||||
	backend_internal *internal;
 | 
			
		||||
 | 
			
		||||
	assert(odb && backend);
 | 
			
		||||
 | 
			
		||||
	if (!backend_has_valid_version(backend))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend");
 | 
			
		||||
 | 
			
		||||
	/* Check if the backend is already owned by another ODB */
 | 
			
		||||
	assert(!backend->odb || backend->odb == odb);
 | 
			
		||||
 | 
			
		||||
@ -298,8 +298,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid,
 | 
			
		||||
 | 
			
		||||
	assert(reflog && new_oid && committer);
 | 
			
		||||
 | 
			
		||||
	if (!git_signature__has_valid_version(committer))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(committer, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
 | 
			
		||||
	if (reflog_entry_new(&entry) < 0)
 | 
			
		||||
		return -1;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								src/remote.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/remote.c
									
									
									
									
									
								
							@ -985,24 +985,11 @@ void git_remote_check_cert(git_remote *remote, int check)
 | 
			
		||||
	remote->check_cert = check;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool callbacks_have_valid_version(git_remote_callbacks *callbacks)
 | 
			
		||||
{
 | 
			
		||||
	if (!callbacks)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (callbacks->version > 0 && callbacks->version <= GIT_REMOTE_CALLBACKS_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d for git_remote_callbacks", callbacks->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks)
 | 
			
		||||
{
 | 
			
		||||
	assert(remote && callbacks);
 | 
			
		||||
 | 
			
		||||
	if (!callbacks_have_valid_version(callbacks))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
 | 
			
		||||
 | 
			
		||||
	memcpy(&remote->callbacks, callbacks, sizeof(git_remote_callbacks));
 | 
			
		||||
 | 
			
		||||
@ -1024,24 +1011,11 @@ void git_remote_set_cred_acquire_cb(
 | 
			
		||||
	remote->cred_acquire_cb = cred_acquire_cb;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool transport_has_valid_version(const git_transport *transport)
 | 
			
		||||
{
 | 
			
		||||
	if (!transport)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (transport->version > 0 && transport->version <= GIT_TRANSPORT_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d on git_transport", transport->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int git_remote_set_transport(git_remote *remote, git_transport *transport)
 | 
			
		||||
{
 | 
			
		||||
	assert(remote && transport);
 | 
			
		||||
 | 
			
		||||
	if (!transport_has_valid_version(transport))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(transport, GIT_TRANSPORT_VERSION, "git_transport");
 | 
			
		||||
 | 
			
		||||
	if (remote->transport) {
 | 
			
		||||
		giterr_set(GITERR_NET, "A transport is already bound to this remote");
 | 
			
		||||
 | 
			
		||||
@ -1160,18 +1160,6 @@ int git_repository_init(
 | 
			
		||||
	return git_repository_init_ext(repo_out, path, &opts);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool options_have_valid_version(git_repository_init_options *opts)
 | 
			
		||||
{
 | 
			
		||||
	if (!opts)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (opts->version > 0 && opts->version <= GIT_REMOTE_CALLBACKS_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d for git_repository_init_options", opts->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int git_repository_init_ext(
 | 
			
		||||
	git_repository **out,
 | 
			
		||||
	const char *given_repo,
 | 
			
		||||
@ -1182,8 +1170,7 @@ int git_repository_init_ext(
 | 
			
		||||
 | 
			
		||||
	assert(out && given_repo && opts);
 | 
			
		||||
 | 
			
		||||
	if (!options_have_valid_version(opts))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options");
 | 
			
		||||
 | 
			
		||||
	error = repo_init_directories(&repo_path, &wd_path, given_repo, opts);
 | 
			
		||||
	if (error < 0)
 | 
			
		||||
 | 
			
		||||
@ -15,16 +15,4 @@
 | 
			
		||||
int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender);
 | 
			
		||||
void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig);
 | 
			
		||||
 | 
			
		||||
GIT_INLINE(bool) git_signature__has_valid_version(const git_signature *sig)
 | 
			
		||||
{
 | 
			
		||||
	if (!sig)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (sig->version > 0 && sig->version <= GIT_SIGNATURE_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d on git_signature", sig->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -523,8 +523,7 @@ int git_stash_save(
 | 
			
		||||
 | 
			
		||||
	assert(out && repo && stasher);
 | 
			
		||||
 | 
			
		||||
	if (!git_signature__has_valid_version(stasher))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(stasher, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
 | 
			
		||||
	if ((error = ensure_non_bare_repository(repo)) < 0)
 | 
			
		||||
		return error;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								src/status.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/status.c
									
									
									
									
									
								
							@ -101,18 +101,6 @@ static int status_invoke_cb(
 | 
			
		||||
	return usercb->cb(path, status, usercb->payload);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool options_have_valid_version(const git_status_options *opts)
 | 
			
		||||
{
 | 
			
		||||
	if (!opts)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	if (opts->version > 0 && opts->version <= GIT_REMOTE_CALLBACKS_VERSION)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	giterr_set(GITERR_INVALID, "Invalid version %d for git_repository_init_options", opts->version);
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int git_status_foreach_ext(
 | 
			
		||||
	git_repository *repo,
 | 
			
		||||
	const git_status_options *opts,
 | 
			
		||||
@ -129,8 +117,7 @@ int git_status_foreach_ext(
 | 
			
		||||
 | 
			
		||||
	assert(show <= GIT_STATUS_SHOW_INDEX_THEN_WORKDIR);
 | 
			
		||||
 | 
			
		||||
	if (!options_have_valid_version(opts))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(opts, GIT_STATUS_OPTIONS_VERSION, "git_status_options");
 | 
			
		||||
 | 
			
		||||
	if (show != GIT_STATUS_SHOW_INDEX_ONLY &&
 | 
			
		||||
		(err = git_repository__ensure_not_bare(repo, "status")) < 0)
 | 
			
		||||
 | 
			
		||||
@ -244,8 +244,7 @@ static int git_tag_create__internal(
 | 
			
		||||
	assert(repo && tag_name && target);
 | 
			
		||||
	assert(!create_tag_annotation || (tagger && message));
 | 
			
		||||
 | 
			
		||||
	if (!git_signature__has_valid_version(tagger))
 | 
			
		||||
		return -1;
 | 
			
		||||
	GITERR_CHECK_VERSION(tagger, GIT_SIGNATURE_VERSION, "git_signature");
 | 
			
		||||
 | 
			
		||||
	if (git_object_owner(target) != repo) {
 | 
			
		||||
		giterr_set(GITERR_INVALID, "The given target does not belong to this repository");
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user