mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-04 13:33:41 +00:00
Remove old and unused error codes
This commit is contained in:
parent
b02bcd97f8
commit
3fbcac89c4
@ -21,98 +21,25 @@ typedef enum {
|
|||||||
GIT_SUCCESS = 0,
|
GIT_SUCCESS = 0,
|
||||||
GIT_ERROR = -1,
|
GIT_ERROR = -1,
|
||||||
|
|
||||||
/** Input was not a properly formatted Git object id. */
|
|
||||||
GIT_ENOTOID = -2,
|
|
||||||
|
|
||||||
/** Input does not exist in the scope searched. */
|
/** Input does not exist in the scope searched. */
|
||||||
GIT_ENOTFOUND = -3,
|
GIT_ENOTFOUND = -3,
|
||||||
|
|
||||||
/** Not enough space available. */
|
|
||||||
GIT_ENOMEM = -4,
|
|
||||||
|
|
||||||
/** Consult the OS error information. */
|
|
||||||
GIT_EOSERR = -5,
|
|
||||||
|
|
||||||
/** The specified object is of invalid type */
|
|
||||||
GIT_EOBJTYPE = -6,
|
|
||||||
|
|
||||||
/** The specified repository is invalid */
|
|
||||||
GIT_ENOTAREPO = -7,
|
|
||||||
|
|
||||||
/** The object type is invalid or doesn't match */
|
|
||||||
GIT_EINVALIDTYPE = -8,
|
|
||||||
|
|
||||||
/** The object cannot be written because it's missing internal data */
|
|
||||||
GIT_EMISSINGOBJDATA = -9,
|
|
||||||
|
|
||||||
/** The packfile for the ODB is corrupted */
|
|
||||||
GIT_EPACKCORRUPTED = -10,
|
|
||||||
|
|
||||||
/** Failed to acquire or release a file lock */
|
|
||||||
GIT_EFLOCKFAIL = -11,
|
|
||||||
|
|
||||||
/** The Z library failed to inflate/deflate an object's data */
|
|
||||||
GIT_EZLIB = -12,
|
|
||||||
|
|
||||||
/** The queried object is currently busy */
|
|
||||||
GIT_EBUSY = -13,
|
|
||||||
|
|
||||||
/** The index file is not backed up by an existing repository */
|
|
||||||
GIT_EBAREINDEX = -14,
|
|
||||||
|
|
||||||
/** The name of the reference is not valid */
|
|
||||||
GIT_EINVALIDREFNAME = -15,
|
|
||||||
|
|
||||||
/** The specified reference has its data corrupted */
|
|
||||||
GIT_EREFCORRUPTED = -16,
|
|
||||||
|
|
||||||
/** The specified symbolic reference is too deeply nested */
|
|
||||||
GIT_ETOONESTEDSYMREF = -17,
|
|
||||||
|
|
||||||
/** The pack-refs file is either corrupted or its format is not currently supported */
|
|
||||||
GIT_EPACKEDREFSCORRUPTED = -18,
|
|
||||||
|
|
||||||
/** The path is invalid */
|
|
||||||
GIT_EINVALIDPATH = -19,
|
|
||||||
|
|
||||||
/** The revision walker is empty; there are no more commits left to iterate */
|
|
||||||
GIT_EREVWALKOVER = -20,
|
|
||||||
|
|
||||||
/** The state of the reference is not valid */
|
|
||||||
GIT_EINVALIDREFSTATE = -21,
|
|
||||||
|
|
||||||
/** This feature has not been implemented yet */
|
|
||||||
GIT_ENOTIMPLEMENTED = -22,
|
|
||||||
|
|
||||||
/** A reference with this name already exists */
|
/** A reference with this name already exists */
|
||||||
GIT_EEXISTS = -23,
|
GIT_EEXISTS = -23,
|
||||||
|
|
||||||
/** The given integer literal is too large to be parsed */
|
/** The given integer literal is too large to be parsed */
|
||||||
GIT_EOVERFLOW = -24,
|
GIT_EOVERFLOW = -24,
|
||||||
|
|
||||||
/** The given literal is not a valid number */
|
|
||||||
GIT_ENOTNUM = -25,
|
|
||||||
|
|
||||||
/** Streaming error */
|
|
||||||
GIT_ESTREAM = -26,
|
|
||||||
|
|
||||||
/** invalid arguments to function */
|
|
||||||
GIT_EINVALIDARGS = -27,
|
|
||||||
|
|
||||||
/** The specified object has its data corrupted */
|
|
||||||
GIT_EOBJCORRUPTED = -28,
|
|
||||||
|
|
||||||
/** The given short oid is ambiguous */
|
/** The given short oid is ambiguous */
|
||||||
GIT_EAMBIGUOUS = -29,
|
GIT_EAMBIGUOUS = -29,
|
||||||
|
|
||||||
/** Skip and passthrough the given ODB backend */
|
/** Skip and passthrough the given ODB backend */
|
||||||
GIT_EPASSTHROUGH = -30,
|
GIT_EPASSTHROUGH = -30,
|
||||||
|
|
||||||
/** The path pattern and string did not match */
|
|
||||||
GIT_ENOMATCH = -31,
|
|
||||||
|
|
||||||
/** The buffer is too short to satisfy the request */
|
/** The buffer is too short to satisfy the request */
|
||||||
GIT_ESHORTBUFFER = -32,
|
GIT_ESHORTBUFFER = -32,
|
||||||
|
|
||||||
|
GIT_EREVWALKOVER = -33,
|
||||||
} git_error_t;
|
} git_error_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -137,45 +64,18 @@ typedef enum {
|
|||||||
GITERR_TREE,
|
GITERR_TREE,
|
||||||
} git_error_class;
|
} git_error_class;
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a detailed error string with the latest error
|
|
||||||
* that occurred in the library.
|
|
||||||
* @deprecated This will be replaced in the new error handling
|
|
||||||
* @return a string explaining the error
|
|
||||||
*/
|
|
||||||
GIT_EXTERN(const char *) git_lasterror(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* strerror() for the Git library
|
|
||||||
*
|
|
||||||
* Get a string description for a given error code.
|
|
||||||
* NOTE: This method will be eventually deprecated in favor
|
|
||||||
* of the new `git_lasterror`.
|
|
||||||
*
|
|
||||||
* @deprecated This will be replaced in the new error handling
|
|
||||||
* @param num The error code to explain
|
|
||||||
* @return a string explaining the error code
|
|
||||||
*/
|
|
||||||
GIT_EXTERN(const char *) git_strerror(int num);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the latest library error
|
|
||||||
* @deprecated This will be replaced in the new error handling
|
|
||||||
*/
|
|
||||||
GIT_EXTERN(void) git_clearerror(void);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the last `git_error` object that was generated for the
|
* Return the last `git_error` object that was generated for the
|
||||||
* current thread or NULL if no error has occurred.
|
* current thread or NULL if no error has occurred.
|
||||||
*
|
*
|
||||||
* @return A git_error object.
|
* @return A git_error object.
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(const git_error *) git_error_last(void);
|
GIT_EXTERN(const git_error *) giterr_last(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the last library error that occurred for this thread.
|
* Clear the last library error that occurred for this thread.
|
||||||
*/
|
*/
|
||||||
GIT_EXTERN(void) git_error_clear(void);
|
GIT_EXTERN(void) giterr_clear(void);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
GIT_END_DECL
|
GIT_END_DECL
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#ifndef INCLUDE_git_refspec_h__
|
#ifndef INCLUDE_git_refspec_h__
|
||||||
#define INCLUDE_git_refspec_h__
|
#define INCLUDE_git_refspec_h__
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,14 +36,13 @@ const char *git_refspec_src(const git_refspec *refspec);
|
|||||||
const char *git_refspec_dst(const git_refspec *refspec);
|
const char *git_refspec_dst(const git_refspec *refspec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Match a refspec's source descriptor with a reference name
|
* Check if a refspec's source descriptor matches a reference
|
||||||
*
|
*
|
||||||
* @param refspec the refspec
|
* @param refspec the refspec
|
||||||
* @param refname the name of the reference to check
|
* @param refname the name of the reference to check
|
||||||
* @return GIT_SUCCESS on successful match; GIT_ENOMACH on match
|
* @return 1 if the refspec matches, 0 otherwise
|
||||||
* failure or an error code on other failure
|
|
||||||
*/
|
*/
|
||||||
int git_refspec_src_match(const git_refspec *refspec, const char *refname);
|
int git_refspec_src_matches(const git_refspec *refspec, const char *refname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform a reference to its target following the refspec's rules
|
* Transform a reference to its target following the refspec's rules
|
||||||
|
@ -59,8 +59,7 @@ int git_config_new(git_config **out)
|
|||||||
git_config *cfg;
|
git_config *cfg;
|
||||||
|
|
||||||
cfg = git__malloc(sizeof(git_config));
|
cfg = git__malloc(sizeof(git_config));
|
||||||
if (cfg == NULL)
|
GITERR_CHECK_ALLOC(cfg);
|
||||||
return GIT_ENOMEM;
|
|
||||||
|
|
||||||
memset(cfg, 0x0, sizeof(git_config));
|
memset(cfg, 0x0, sizeof(git_config));
|
||||||
|
|
||||||
@ -221,7 +220,7 @@ int git_config_parse_bool(int *out, const char *value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GIT_EINVALIDTYPE;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_int64(int64_t *out, const char *value)
|
static int parse_int64(int64_t *out, const char *value)
|
||||||
|
@ -216,8 +216,7 @@ int git_filter_add__crlf_to_odb(git_vector *filters, git_repository *repo, const
|
|||||||
/* If we're good, we create a new filter object and push it
|
/* If we're good, we create a new filter object and push it
|
||||||
* into the filters array */
|
* into the filters array */
|
||||||
filter = git__malloc(sizeof(struct crlf_filter));
|
filter = git__malloc(sizeof(struct crlf_filter));
|
||||||
if (filter == NULL)
|
GITERR_CHECK_ALLOC(filter);
|
||||||
return GIT_ENOMEM;
|
|
||||||
|
|
||||||
filter->f.apply = &crlf_apply_to_odb;
|
filter->f.apply = &crlf_apply_to_odb;
|
||||||
filter->f.do_free = NULL;
|
filter->f.do_free = NULL;
|
||||||
|
@ -61,8 +61,9 @@ int git__delta_apply(
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res_dp = git__malloc(res_sz + 1)) == NULL)
|
res_dp = git__malloc(res_sz + 1);
|
||||||
return GIT_ENOMEM;
|
GITERR_CHECK_ALLOC(res_dp);
|
||||||
|
|
||||||
res_dp[res_sz] = '\0';
|
res_dp[res_sz] = '\0';
|
||||||
out->data = res_dp;
|
out->data = res_dp;
|
||||||
out->len = res_sz;
|
out->len = res_sz;
|
||||||
|
@ -35,10 +35,10 @@ static bool diff_path_matches_pathspec(git_diff_list *diff, const char *path)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
git_vector_foreach(&diff->pathspec, i, match) {
|
git_vector_foreach(&diff->pathspec, i, match) {
|
||||||
int result = git__fnmatch(match->pattern, path, 0);
|
int result = p_fnmatch(match->pattern, path, 0);
|
||||||
|
|
||||||
/* if we didn't match, look for exact dirname prefix match */
|
/* if we didn't match, look for exact dirname prefix match */
|
||||||
if (result == GIT_ENOMATCH &&
|
if (result == FNM_NOMATCH &&
|
||||||
(match->flags & GIT_ATTR_FNMATCH_HASWILD) == 0 &&
|
(match->flags & GIT_ATTR_FNMATCH_HASWILD) == 0 &&
|
||||||
strncmp(path, match->pattern, match->length) == 0 &&
|
strncmp(path, match->pattern, match->length) == 0 &&
|
||||||
path[match->length] == '/')
|
path[match->length] == '/')
|
||||||
@ -46,9 +46,6 @@ static bool diff_path_matches_pathspec(git_diff_list *diff, const char *path)
|
|||||||
|
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
return (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) ? false : true;
|
return (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) ? false : true;
|
||||||
|
|
||||||
if (result != GIT_ENOMATCH)
|
|
||||||
giterr_clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
106
src/errors.c
106
src/errors.c
@ -9,105 +9,6 @@
|
|||||||
#include "posix.h"
|
#include "posix.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
static struct {
|
|
||||||
int num;
|
|
||||||
const char *str;
|
|
||||||
} error_codes[] = {
|
|
||||||
{GIT_ERROR, "Unspecified error"},
|
|
||||||
{GIT_ENOTOID, "Input was not a properly formatted Git object id."},
|
|
||||||
{GIT_ENOTFOUND, "Object does not exist in the scope searched."},
|
|
||||||
{GIT_ENOMEM, "Not enough space available."},
|
|
||||||
{GIT_EOSERR, "Consult the OS error information."},
|
|
||||||
{GIT_EOBJTYPE, "The specified object is of invalid type"},
|
|
||||||
{GIT_EOBJCORRUPTED, "The specified object has its data corrupted"},
|
|
||||||
{GIT_ENOTAREPO, "The specified repository is invalid"},
|
|
||||||
{GIT_EINVALIDTYPE, "The object or config variable type is invalid or doesn't match"},
|
|
||||||
{GIT_EMISSINGOBJDATA, "The object cannot be written that because it's missing internal data"},
|
|
||||||
{GIT_EPACKCORRUPTED, "The packfile for the ODB is corrupted"},
|
|
||||||
{GIT_EFLOCKFAIL, "Failed to adquire or release a file lock"},
|
|
||||||
{GIT_EZLIB, "The Z library failed to inflate/deflate an object's data"},
|
|
||||||
{GIT_EBUSY, "The queried object is currently busy"},
|
|
||||||
{GIT_EINVALIDPATH, "The path is invalid"},
|
|
||||||
{GIT_EBAREINDEX, "The index file is not backed up by an existing repository"},
|
|
||||||
{GIT_EINVALIDREFNAME, "The name of the reference is not valid"},
|
|
||||||
{GIT_EREFCORRUPTED, "The specified reference has its data corrupted"},
|
|
||||||
{GIT_ETOONESTEDSYMREF, "The specified symbolic reference is too deeply nested"},
|
|
||||||
{GIT_EPACKEDREFSCORRUPTED, "The pack-refs file is either corrupted of its format is not currently supported"},
|
|
||||||
{GIT_EINVALIDPATH, "The path is invalid" },
|
|
||||||
{GIT_EREVWALKOVER, "The revision walker is empty; there are no more commits left to iterate"},
|
|
||||||
{GIT_EINVALIDREFSTATE, "The state of the reference is not valid"},
|
|
||||||
{GIT_ENOTIMPLEMENTED, "This feature has not been implemented yet"},
|
|
||||||
{GIT_EEXISTS, "A reference with this name already exists"},
|
|
||||||
{GIT_EOVERFLOW, "The given integer literal is too large to be parsed"},
|
|
||||||
{GIT_ENOTNUM, "The given literal is not a valid number"},
|
|
||||||
{GIT_EAMBIGUOUS, "The given oid prefix is ambiguous"},
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *git_strerror(int num)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (num == GIT_EOSERR)
|
|
||||||
return strerror(errno);
|
|
||||||
for (i = 0; i < ARRAY_SIZE(error_codes); i++)
|
|
||||||
if (num == error_codes[i].num)
|
|
||||||
return error_codes[i].str;
|
|
||||||
|
|
||||||
return "Unknown error";
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ERROR_MAX_LEN 1024
|
|
||||||
|
|
||||||
void git___rethrow(const char *msg, ...)
|
|
||||||
{
|
|
||||||
char new_error[ERROR_MAX_LEN];
|
|
||||||
char *last_error;
|
|
||||||
char *old_error = NULL;
|
|
||||||
|
|
||||||
va_list va;
|
|
||||||
|
|
||||||
last_error = GIT_GLOBAL->error.last;
|
|
||||||
|
|
||||||
va_start(va, msg);
|
|
||||||
vsnprintf(new_error, ERROR_MAX_LEN, msg, va);
|
|
||||||
va_end(va);
|
|
||||||
|
|
||||||
old_error = git__strdup(last_error);
|
|
||||||
|
|
||||||
snprintf(last_error, ERROR_MAX_LEN, "%s \n - %s", new_error, old_error);
|
|
||||||
|
|
||||||
git__free(old_error);
|
|
||||||
}
|
|
||||||
|
|
||||||
void git___throw(const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list va;
|
|
||||||
|
|
||||||
va_start(va, msg);
|
|
||||||
vsnprintf(GIT_GLOBAL->error.last, ERROR_MAX_LEN, msg, va);
|
|
||||||
va_end(va);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *git_lasterror(void)
|
|
||||||
{
|
|
||||||
char *last_error = GIT_GLOBAL->error.last;
|
|
||||||
|
|
||||||
if (!last_error[0]) {
|
|
||||||
const git_error *err = git_error_last();
|
|
||||||
if (err != NULL)
|
|
||||||
return err->message;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return last_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
void git_clearerror(void)
|
|
||||||
{
|
|
||||||
char *last_error = GIT_GLOBAL->error.last;
|
|
||||||
last_error[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************************************
|
/********************************************
|
||||||
* New error handling
|
* New error handling
|
||||||
********************************************/
|
********************************************/
|
||||||
@ -198,13 +99,8 @@ void giterr_clear(void)
|
|||||||
GIT_GLOBAL->last_error = NULL;
|
GIT_GLOBAL->last_error = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const git_error *git_error_last(void)
|
const git_error *giterr_last(void)
|
||||||
{
|
{
|
||||||
return GIT_GLOBAL->last_error;
|
return GIT_GLOBAL->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_error_clear(void)
|
|
||||||
{
|
|
||||||
giterr_clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
10
src/fetch.c
10
src/fetch.c
@ -29,21 +29,13 @@ struct filter_payload {
|
|||||||
static int filter_ref__cb(git_remote_head *head, void *payload)
|
static int filter_ref__cb(git_remote_head *head, void *payload)
|
||||||
{
|
{
|
||||||
struct filter_payload *p = payload;
|
struct filter_payload *p = payload;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!p->found_head && strcmp(head->name, GIT_HEAD_FILE) == 0) {
|
if (!p->found_head && strcmp(head->name, GIT_HEAD_FILE) == 0) {
|
||||||
p->found_head = 1;
|
p->found_head = 1;
|
||||||
} else {
|
} else {
|
||||||
/* If it doesn't match the refpec, we don't want it */
|
/* If it doesn't match the refpec, we don't want it */
|
||||||
ret = git_refspec_src_match(p->spec, head->name);
|
if (!git_refspec_src_matches(p->spec, head->name))
|
||||||
|
|
||||||
if (ret == GIT_ENOMATCH)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ret < GIT_SUCCESS) {
|
|
||||||
giterr_set(GITERR_NET, "Error matching remote ref name");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have the object, mark it so we don't ask for it */
|
/* If we have the object, mark it so we don't ask for it */
|
||||||
|
@ -92,11 +92,11 @@ int git_filters_load(git_vector *filters, git_repository *repo, const char *path
|
|||||||
if (mode == GIT_FILTER_TO_ODB) {
|
if (mode == GIT_FILTER_TO_ODB) {
|
||||||
/* Load the CRLF cleanup filter when writing to the ODB */
|
/* Load the CRLF cleanup filter when writing to the ODB */
|
||||||
error = git_filter_add__crlf_to_odb(filters, repo, path);
|
error = git_filter_add__crlf_to_odb(filters, repo, path);
|
||||||
if (error < GIT_SUCCESS)
|
if (error < 0)
|
||||||
return error;
|
return error;
|
||||||
} else {
|
} else {
|
||||||
giterr_set(GITERR_INVALID, "Worktree filters are not implemented yet");
|
giterr_set(GITERR_INVALID, "Worktree filters are not implemented yet");
|
||||||
return GIT_ENOTIMPLEMENTED;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)filters->length;
|
return (int)filters->length;
|
||||||
@ -135,7 +135,7 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
|
|||||||
/* Pre-grow the destination buffer to more or less the size
|
/* Pre-grow the destination buffer to more or less the size
|
||||||
* we expect it to have */
|
* we expect it to have */
|
||||||
if (git_buf_grow(dest, git_buf_len(source)) < 0)
|
if (git_buf_grow(dest, git_buf_len(source)) < 0)
|
||||||
return GIT_ENOMEM;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < filters->length; ++i) {
|
for (i = 0; i < filters->length; ++i) {
|
||||||
git_filter *filter = git_vector_get(filters, i);
|
git_filter *filter = git_vector_get(filters, i);
|
||||||
@ -153,7 +153,7 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
|
|||||||
src = dst;
|
src = dst;
|
||||||
|
|
||||||
if (git_buf_oom(dbuffer[dst]))
|
if (git_buf_oom(dbuffer[dst]))
|
||||||
return GIT_ENOMEM;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure that the output ends up in dbuffer[1] (i.e. the dest) */
|
/* Ensure that the output ends up in dbuffer[1] (i.e. the dest) */
|
||||||
|
@ -62,8 +62,7 @@ static int create_object(git_object **object_out, git_otype type)
|
|||||||
case GIT_OBJ_BLOB:
|
case GIT_OBJ_BLOB:
|
||||||
case GIT_OBJ_TREE:
|
case GIT_OBJ_TREE:
|
||||||
object = git__malloc(git_object__size(type));
|
object = git__malloc(git_object__size(type));
|
||||||
if (object == NULL)
|
GITERR_CHECK_ALLOC(object);
|
||||||
return GIT_ENOMEM;
|
|
||||||
memset(object, 0x0, git_object__size(type));
|
memset(object, 0x0, git_object__size(type));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "refspec.h"
|
#include "refspec.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "posix.h"
|
||||||
|
|
||||||
int git_refspec_parse(git_refspec *refspec, const char *str)
|
int git_refspec_parse(git_refspec *refspec, const char *str)
|
||||||
{
|
{
|
||||||
@ -52,9 +53,12 @@ const char *git_refspec_dst(const git_refspec *refspec)
|
|||||||
return refspec == NULL ? NULL : refspec->dst;
|
return refspec == NULL ? NULL : refspec->dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_refspec_src_match(const git_refspec *refspec, const char *refname)
|
int git_refspec_src_matches(const git_refspec *refspec, const char *refname)
|
||||||
{
|
{
|
||||||
return (refspec == NULL || refspec->src == NULL) ? GIT_ENOMATCH : git__fnmatch(refspec->src, refname, 0);
|
if (refspec == NULL || refspec->src == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return (p_fnmatch(refspec->src, refname, 0) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name)
|
int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name)
|
||||||
|
@ -486,7 +486,7 @@ static int push_glob_cb(const char *refname, void *data_)
|
|||||||
{
|
{
|
||||||
struct push_cb_data *data = (struct push_cb_data *)data_;
|
struct push_cb_data *data = (struct push_cb_data *)data_;
|
||||||
|
|
||||||
if (!git__fnmatch(data->glob, refname, 0))
|
if (!p_fnmatch(data->glob, refname, 0))
|
||||||
return push_ref(data->walk, refname, data->hide);
|
return push_ref(data->walk, refname, data->hide);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -420,7 +420,7 @@ int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_reposit
|
|||||||
assert(tag_names && repo && pattern);
|
assert(tag_names && repo && pattern);
|
||||||
|
|
||||||
if (git_vector_init(&taglist, 8, NULL) < GIT_SUCCESS)
|
if (git_vector_init(&taglist, 8, NULL) < GIT_SUCCESS)
|
||||||
return GIT_ENOMEM;
|
return -1;
|
||||||
|
|
||||||
filter.taglist = &taglist;
|
filter.taglist = &taglist;
|
||||||
filter.pattern = pattern;
|
filter.pattern = pattern;
|
||||||
|
@ -66,8 +66,10 @@ int git_transport_new(git_transport **out, const char *url)
|
|||||||
|
|
||||||
fn = transport_find_fn(url);
|
fn = transport_find_fn(url);
|
||||||
|
|
||||||
if (fn == NULL)
|
if (fn == NULL) {
|
||||||
return git__throw(GIT_EINVALIDARGS, "Unsupported URL or non-existent path");
|
giterr_set(GITERR_NET, "Unsupported URL protocol");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
error = fn(&transport);
|
error = fn(&transport);
|
||||||
if (error < GIT_SUCCESS)
|
if (error < GIT_SUCCESS)
|
||||||
|
@ -72,7 +72,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
|
|||||||
git_buf_putc(request, '\0');
|
git_buf_putc(request, '\0');
|
||||||
|
|
||||||
if (git_buf_oom(request))
|
if (git_buf_oom(request))
|
||||||
return GIT_ENOMEM;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ static int gen_request(git_buf *buf, const char *url, const char *host, const ch
|
|||||||
git_buf_puts(buf, "\r\n");
|
git_buf_puts(buf, "\r\n");
|
||||||
|
|
||||||
if (git_buf_oom(buf))
|
if (git_buf_oom(buf))
|
||||||
return GIT_ENOMEM;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -174,13 +174,13 @@ static int on_headers_complete(http_parser *parser)
|
|||||||
if (t->content_type == NULL) {
|
if (t->content_type == NULL) {
|
||||||
t->content_type = git__strdup(git_buf_cstr(buf));
|
t->content_type = git__strdup(git_buf_cstr(buf));
|
||||||
if (t->content_type == NULL)
|
if (t->content_type == NULL)
|
||||||
return t->error = GIT_ENOMEM;
|
return t->error = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
git_buf_clear(buf);
|
git_buf_clear(buf);
|
||||||
git_buf_printf(buf, "application/x-git-%s-advertisement", t->service);
|
git_buf_printf(buf, "application/x-git-%s-advertisement", t->service);
|
||||||
if (git_buf_oom(buf))
|
if (git_buf_oom(buf))
|
||||||
return t->error = GIT_ENOMEM;
|
return t->error = -1;
|
||||||
|
|
||||||
if (strcmp(t->content_type, git_buf_cstr(buf)))
|
if (strcmp(t->content_type, git_buf_cstr(buf)))
|
||||||
return t->error = -1;
|
return t->error = -1;
|
||||||
|
@ -82,24 +82,19 @@ static int read_tree_internal(git_tree_cache **out,
|
|||||||
git_tree_cache *tree = NULL;
|
git_tree_cache *tree = NULL;
|
||||||
const char *name_start, *buffer;
|
const char *name_start, *buffer;
|
||||||
int count;
|
int count;
|
||||||
int error = GIT_SUCCESS;
|
|
||||||
size_t name_len;
|
size_t name_len;
|
||||||
|
|
||||||
buffer = name_start = *buffer_in;
|
buffer = name_start = *buffer_in;
|
||||||
|
|
||||||
if ((buffer = memchr(buffer, '\0', buffer_end - buffer)) == NULL) {
|
if ((buffer = memchr(buffer, '\0', buffer_end - buffer)) == NULL)
|
||||||
error = GIT_EOBJCORRUPTED;
|
goto corrupted;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++buffer >= buffer_end) {
|
if (++buffer >= buffer_end)
|
||||||
error = GIT_EOBJCORRUPTED;
|
goto corrupted;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
name_len = strlen(name_start);
|
name_len = strlen(name_start);
|
||||||
if ((tree = git__malloc(sizeof(git_tree_cache) + name_len + 1)) == NULL)
|
tree = git__malloc(sizeof(git_tree_cache) + name_len + 1);
|
||||||
return GIT_ENOMEM;
|
GITERR_CHECK_ALLOC(tree);
|
||||||
|
|
||||||
memset(tree, 0x0, sizeof(git_tree_cache));
|
memset(tree, 0x0, sizeof(git_tree_cache));
|
||||||
tree->parent = parent;
|
tree->parent = parent;
|
||||||
@ -109,39 +104,28 @@ static int read_tree_internal(git_tree_cache **out,
|
|||||||
tree->name[name_len] = '\0';
|
tree->name[name_len] = '\0';
|
||||||
|
|
||||||
/* Blank-terminated ASCII decimal number of entries in this tree */
|
/* Blank-terminated ASCII decimal number of entries in this tree */
|
||||||
if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS || count < -1) {
|
if (git__strtol32(&count, buffer, &buffer, 10) < 0 || count < -1)
|
||||||
error = GIT_EOBJCORRUPTED;
|
goto corrupted;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
tree->entries = count;
|
tree->entries = count;
|
||||||
|
|
||||||
if (*buffer != ' ' || ++buffer >= buffer_end) {
|
if (*buffer != ' ' || ++buffer >= buffer_end)
|
||||||
error = GIT_EOBJCORRUPTED;
|
goto corrupted;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Number of children of the tree, newline-terminated */
|
/* Number of children of the tree, newline-terminated */
|
||||||
if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS ||
|
if (git__strtol32(&count, buffer, &buffer, 10) < 0 || count < 0)
|
||||||
count < 0) {
|
goto corrupted;
|
||||||
error = GIT_EOBJCORRUPTED;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
tree->children_count = count;
|
tree->children_count = count;
|
||||||
|
|
||||||
if (*buffer != '\n' || ++buffer > buffer_end) {
|
if (*buffer != '\n' || ++buffer > buffer_end)
|
||||||
error = GIT_EOBJCORRUPTED;
|
goto corrupted;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The SHA1 is only there if it's not invalidated */
|
/* The SHA1 is only there if it's not invalidated */
|
||||||
if (tree->entries >= 0) {
|
if (tree->entries >= 0) {
|
||||||
/* 160-bit SHA-1 for this tree and it's children */
|
/* 160-bit SHA-1 for this tree and it's children */
|
||||||
if (buffer + GIT_OID_RAWSZ > buffer_end) {
|
if (buffer + GIT_OID_RAWSZ > buffer_end)
|
||||||
error = GIT_EOBJCORRUPTED;
|
goto corrupted;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
git_oid_fromraw(&tree->oid, (const unsigned char *)buffer);
|
git_oid_fromraw(&tree->oid, (const unsigned char *)buffer);
|
||||||
buffer += GIT_OID_RAWSZ;
|
buffer += GIT_OID_RAWSZ;
|
||||||
@ -150,40 +134,39 @@ static int read_tree_internal(git_tree_cache **out,
|
|||||||
/* Parse children: */
|
/* Parse children: */
|
||||||
if (tree->children_count > 0) {
|
if (tree->children_count > 0) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int err;
|
|
||||||
|
|
||||||
tree->children = git__malloc(tree->children_count * sizeof(git_tree_cache *));
|
tree->children = git__malloc(tree->children_count * sizeof(git_tree_cache *));
|
||||||
if (tree->children == NULL)
|
GITERR_CHECK_ALLOC(tree->children);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < tree->children_count; ++i) {
|
for (i = 0; i < tree->children_count; ++i) {
|
||||||
err = read_tree_internal(&tree->children[i], &buffer, buffer_end, tree);
|
if (read_tree_internal(&tree->children[i], &buffer, buffer_end, tree) < 0)
|
||||||
|
return -1;
|
||||||
if (err < GIT_SUCCESS)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer_in = buffer;
|
*buffer_in = buffer;
|
||||||
*out = tree;
|
*out = tree;
|
||||||
return GIT_SUCCESS;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
corrupted:
|
||||||
git_tree_cache_free(tree);
|
git_tree_cache_free(tree);
|
||||||
return error;
|
giterr_set(GITERR_INDEX, "Corruped TREE extension in index");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size)
|
int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size)
|
||||||
{
|
{
|
||||||
const char *buffer_end = buffer + buffer_size;
|
const char *buffer_end = buffer + buffer_size;
|
||||||
int error;
|
|
||||||
|
|
||||||
error = read_tree_internal(tree, &buffer, buffer_end, NULL);
|
if (read_tree_internal(tree, &buffer, buffer_end, NULL) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (buffer < buffer_end)
|
if (buffer < buffer_end) {
|
||||||
return GIT_EOBJCORRUPTED;
|
giterr_set(GITERR_INDEX, "Corruped TREE extension in index (unexpected trailing data)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void git_tree_cache_free(git_tree_cache *tree)
|
void git_tree_cache_free(git_tree_cache *tree)
|
||||||
|
@ -741,7 +741,7 @@ int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payl
|
|||||||
|
|
||||||
case GIT_TREEWALK_PRE:
|
case GIT_TREEWALK_PRE:
|
||||||
tree_error("Preorder tree walking is still not implemented");
|
tree_error("Preorder tree walking is still not implemented");
|
||||||
return GIT_ENOTIMPLEMENTED;
|
return -1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
giterr_set(GITERR_INVALID, "Invalid walking mode for tree walk");
|
giterr_set(GITERR_INVALID, "Invalid walking mode for tree walk");
|
||||||
|
16
src/util.c
16
src/util.c
@ -60,22 +60,6 @@ int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int git__fnmatch(const char *pattern, const char *name, int flags)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = p_fnmatch(pattern, name, flags);
|
|
||||||
switch (ret) {
|
|
||||||
case 0:
|
|
||||||
return 0;
|
|
||||||
case FNM_NOMATCH:
|
|
||||||
return GIT_ENOMATCH;
|
|
||||||
default:
|
|
||||||
giterr_set(GITERR_OS, "Error trying to match path");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int base)
|
int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int base)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
|
@ -105,8 +105,6 @@ GIT_INLINE(const char *) git__next_line(const char *s)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int git__fnmatch(const char *pattern, const char *name, int flags);
|
|
||||||
|
|
||||||
extern void git__tsort(void **dst, size_t size, int (*cmp)(const void *, const void *));
|
extern void git__tsort(void **dst, size_t size, int (*cmp)(const void *, const void *));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
* return error codes!
|
* return error codes!
|
||||||
*/
|
*/
|
||||||
#define cl_git_pass(expr) do { \
|
#define cl_git_pass(expr) do { \
|
||||||
git_clearerror(); \
|
giterr_clear(); \
|
||||||
if ((expr) != GIT_SUCCESS) \
|
if ((expr) != 0) \
|
||||||
clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, git_lasterror(), 1); \
|
clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, giterr_last()->message, 1); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,46 +3,30 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "posix.h"
|
#include "posix.h"
|
||||||
|
|
||||||
#ifdef git__throw
|
|
||||||
void test_core_errors__old_school(void)
|
|
||||||
{
|
|
||||||
git_clearerror();
|
|
||||||
cl_assert(git_lasterror() == NULL);
|
|
||||||
|
|
||||||
cl_assert(git_strerror(GIT_ENOTFOUND) != NULL);
|
|
||||||
|
|
||||||
git__throw(GIT_ENOTFOUND, "My Message");
|
|
||||||
cl_assert(git_lasterror() != NULL);
|
|
||||||
cl_assert(git__prefixcmp(git_lasterror(), "My Message") == 0);
|
|
||||||
git_clearerror();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GITERR_CHECK_ALLOC
|
|
||||||
void test_core_errors__new_school(void)
|
void test_core_errors__new_school(void)
|
||||||
{
|
{
|
||||||
char *str_in_error;
|
char *str_in_error;
|
||||||
|
|
||||||
git_error_clear();
|
giterr_clear();
|
||||||
cl_assert(git_error_last() == NULL);
|
cl_assert(giterr_last() == NULL);
|
||||||
|
|
||||||
giterr_set_oom(); /* internal fn */
|
giterr_set_oom(); /* internal fn */
|
||||||
|
|
||||||
cl_assert(git_error_last() != NULL);
|
cl_assert(giterr_last() != NULL);
|
||||||
cl_assert(git_error_last()->klass == GITERR_NOMEMORY);
|
cl_assert(giterr_last()->klass == GITERR_NOMEMORY);
|
||||||
str_in_error = strstr(git_error_last()->message, "memory");
|
str_in_error = strstr(giterr_last()->message, "memory");
|
||||||
cl_assert(str_in_error != NULL);
|
cl_assert(str_in_error != NULL);
|
||||||
|
|
||||||
git_error_clear();
|
giterr_clear();
|
||||||
|
|
||||||
giterr_set(GITERR_REPOSITORY, "This is a test"); /* internal fn */
|
giterr_set(GITERR_REPOSITORY, "This is a test"); /* internal fn */
|
||||||
|
|
||||||
cl_assert(git_error_last() != NULL);
|
cl_assert(giterr_last() != NULL);
|
||||||
str_in_error = strstr(git_error_last()->message, "This is a test");
|
str_in_error = strstr(giterr_last()->message, "This is a test");
|
||||||
cl_assert(str_in_error != NULL);
|
cl_assert(str_in_error != NULL);
|
||||||
|
|
||||||
git_error_clear();
|
giterr_clear();
|
||||||
cl_assert(git_error_last() == NULL);
|
cl_assert(giterr_last() == NULL);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -52,26 +36,25 @@ void test_core_errors__new_school(void)
|
|||||||
} while (false);
|
} while (false);
|
||||||
giterr_set(GITERR_OS, "stat failed"); /* internal fn */
|
giterr_set(GITERR_OS, "stat failed"); /* internal fn */
|
||||||
|
|
||||||
cl_assert(git_error_last() != NULL);
|
cl_assert(giterr_last() != NULL);
|
||||||
str_in_error = strstr(git_error_last()->message, "stat failed");
|
str_in_error = strstr(giterr_last()->message, "stat failed");
|
||||||
cl_assert(str_in_error != NULL);
|
cl_assert(str_in_error != NULL);
|
||||||
cl_assert(git__prefixcmp(str_in_error, "stat failed: ") == 0);
|
cl_assert(git__prefixcmp(str_in_error, "stat failed: ") == 0);
|
||||||
cl_assert(strlen(str_in_error) > strlen("stat failed: "));
|
cl_assert(strlen(str_in_error) > strlen("stat failed: "));
|
||||||
|
|
||||||
#ifdef GIT_WIN32
|
#ifdef GIT_WIN32
|
||||||
git_error_clear();
|
giterr_clear();
|
||||||
|
|
||||||
/* The MSDN docs use this to generate a sample error */
|
/* The MSDN docs use this to generate a sample error */
|
||||||
cl_assert(GetProcessId(NULL) == 0);
|
cl_assert(GetProcessId(NULL) == 0);
|
||||||
giterr_set(GITERR_OS, "GetProcessId failed"); /* internal fn */
|
giterr_set(GITERR_OS, "GetProcessId failed"); /* internal fn */
|
||||||
|
|
||||||
cl_assert(git_error_last() != NULL);
|
cl_assert(giterr_last() != NULL);
|
||||||
str_in_error = strstr(git_error_last()->message, "GetProcessId failed");
|
str_in_error = strstr(giterr_last()->message, "GetProcessId failed");
|
||||||
cl_assert(str_in_error != NULL);
|
cl_assert(str_in_error != NULL);
|
||||||
cl_assert(git__prefixcmp(str_in_error, "GetProcessId failed: ") == 0);
|
cl_assert(git__prefixcmp(str_in_error, "GetProcessId failed: ") == 0);
|
||||||
cl_assert(strlen(str_in_error) > strlen("GetProcessId failed: "));
|
cl_assert(strlen(str_in_error) > strlen("GetProcessId failed: "));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
git_error_clear();
|
giterr_clear();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
@ -101,8 +101,8 @@ void test_network_remotes__save(void)
|
|||||||
|
|
||||||
void test_network_remotes__fnmatch(void)
|
void test_network_remotes__fnmatch(void)
|
||||||
{
|
{
|
||||||
cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/master"));
|
cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master"));
|
||||||
cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/multi/level/branch"));
|
cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_network_remotes__transform(void)
|
void test_network_remotes__transform(void)
|
||||||
|
@ -43,7 +43,7 @@ static void assert_tree_from_path(git_tree *root, const char *path, int expected
|
|||||||
static void assert_tree_from_path_klass(git_tree *root, const char *path, int expected_result, const char *expected_raw_oid)
|
static void assert_tree_from_path_klass(git_tree *root, const char *path, int expected_result, const char *expected_raw_oid)
|
||||||
{
|
{
|
||||||
assert_tree_from_path(root, path, GIT_ERROR, expected_raw_oid);
|
assert_tree_from_path(root, path, GIT_ERROR, expected_raw_oid);
|
||||||
cl_assert(git_error_last()->klass == expected_result);
|
cl_assert(giterr_last()->klass == expected_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
|
void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user