]> git.proxmox.com Git - libgit2.git/commitdiff
Remove old and unused error codes
authorVicent Martí <tanoku@gmail.com>
Thu, 3 May 2012 02:56:38 +0000 (19:56 -0700)
committerVicent Martí <tanoku@gmail.com>
Thu, 3 May 2012 02:56:38 +0000 (19:56 -0700)
24 files changed:
include/git2/errors.h
include/git2/refspec.h
src/config.c
src/crlf.c
src/delta-apply.c
src/diff.c
src/errors.c
src/fetch.c
src/filter.c
src/object.c
src/refspec.c
src/revwalk.c
src/tag.c
src/transport.c
src/transports/git.c
src/transports/http.c
src/tree-cache.c
src/tree.c
src/util.c
src/util.h
tests-clar/clar_libgit2.h
tests-clar/core/errors.c
tests-clar/network/remotes.c
tests-clar/object/tree/frompath.c

index 17a70107966eb52530aec89d15d9c01a6ce43378..0406c165a0cfee2329da1ddfd912ec5acc40850e 100644 (file)
@@ -21,98 +21,25 @@ typedef enum {
        GIT_SUCCESS = 0,
        GIT_ERROR = -1,
 
-       /** Input was not a properly formatted Git object id. */
-       GIT_ENOTOID = -2,
-
        /** Input does not exist in the scope searched. */
        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 */
        GIT_EEXISTS = -23,
 
        /** The given integer literal is too large to be parsed */
        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 */
        GIT_EAMBIGUOUS = -29,
 
        /** Skip and passthrough the given ODB backend */
        GIT_EPASSTHROUGH = -30,
 
-       /** The path pattern and string did not match */
-       GIT_ENOMATCH = -31,
-
        /** The buffer is too short to satisfy the request */
        GIT_ESHORTBUFFER = -32,
+
+       GIT_EREVWALKOVER = -33,
 } git_error_t;
 
 typedef struct {
@@ -137,45 +64,18 @@ typedef enum {
        GITERR_TREE,
 } 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
  * current thread or NULL if no error has occurred.
  *
  * @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.
  */
-GIT_EXTERN(void) git_error_clear(void);
+GIT_EXTERN(void) giterr_clear(void);
 
 /** @} */
 GIT_END_DECL
index 3acf1143dd2303694fd524d8bedd1106ae0b3b4f..28afe652d47ae4acebebb59c98b7faf1aff9098d 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef INCLUDE_git_refspec_h__
 #define INCLUDE_git_refspec_h__
 
+#include "common.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);
 
 /**
- * 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 refname the name of the reference to check
- * @return GIT_SUCCESS on successful match; GIT_ENOMACH on match
- * failure or an error code on other failure
+ * @return 1 if the refspec matches, 0 otherwise
  */
-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
index 4c971924c42ffb5d3e0d5e431571c16d82cf2671..0ab0cd424d1c2256a2bc2bf1adb37def6d2483f0 100644 (file)
@@ -59,8 +59,7 @@ int git_config_new(git_config **out)
        git_config *cfg;
 
        cfg = git__malloc(sizeof(git_config));
-       if (cfg == NULL)
-               return GIT_ENOMEM;
+       GITERR_CHECK_ALLOC(cfg);
 
        memset(cfg, 0x0, sizeof(git_config));
 
@@ -221,7 +220,7 @@ int git_config_parse_bool(int *out, const char *value)
                return 0;
        }
 
-       return GIT_EINVALIDTYPE;
+       return -1;
 }
 
 static int parse_int64(int64_t *out, const char *value)
index 8fe588a35072324bbc21d846664aaa15bf8de266..b495d2de038e34e8c337a9a604b86dcc31bbcb1c 100644 (file)
@@ -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
         * into the filters array */
        filter = git__malloc(sizeof(struct crlf_filter));
-       if (filter == NULL)
-               return GIT_ENOMEM;
+       GITERR_CHECK_ALLOC(filter);
 
        filter->f.apply = &crlf_apply_to_odb;
        filter->f.do_free = NULL;
index c8c662fa8a1725ad85ef0908ce3fa93bb4750b2b..d3be084e03da9406b6029274707134d4901b2ccd 100644 (file)
@@ -61,8 +61,9 @@ int git__delta_apply(
                return -1;
        }
 
-       if ((res_dp = git__malloc(res_sz + 1)) == NULL)
-               return GIT_ENOMEM;
+       res_dp = git__malloc(res_sz + 1);
+       GITERR_CHECK_ALLOC(res_dp);
+
        res_dp[res_sz] = '\0';
        out->data = res_dp;
        out->len = res_sz;
index b21dfaf9029468689f17c260da4b3fb131874700..b845f9e8c05ac3ef8de390e98793044dc54a8ce4 100644 (file)
@@ -35,10 +35,10 @@ static bool diff_path_matches_pathspec(git_diff_list *diff, const char *path)
                return true;
 
        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 (result == GIT_ENOMATCH &&
+               if (result == FNM_NOMATCH &&
                        (match->flags & GIT_ATTR_FNMATCH_HASWILD) == 0 &&
                        strncmp(path, match->pattern, match->length) == 0 &&
                        path[match->length] == '/')
@@ -46,9 +46,6 @@ static bool diff_path_matches_pathspec(git_diff_list *diff, const char *path)
 
                if (result == 0)
                        return (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) ? false : true;
-
-               if (result != GIT_ENOMATCH)
-                       giterr_clear();
        }
 
        return false;
index 7a6bbd654ffcc4f645832abd1e3461cde8f7a13a..f708519abf65e5a6a2f7f188c2b7dbfa2d1d0b70 100644 (file)
@@ -9,105 +9,6 @@
 #include "posix.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
  ********************************************/
@@ -198,13 +99,8 @@ void giterr_clear(void)
        GIT_GLOBAL->last_error = NULL;
 }
 
-const git_error *git_error_last(void)
+const git_error *giterr_last(void)
 {
        return GIT_GLOBAL->last_error;
 }
 
-void git_error_clear(void)
-{
-       giterr_clear();
-}
-
index 6fe1b567682d98fce6221446a9fafa1d0bd85162..1944bd00507d485d0c8890102fba5ad20b587b78 100644 (file)
@@ -29,21 +29,13 @@ struct filter_payload {
 static int filter_ref__cb(git_remote_head *head, void *payload)
 {
        struct filter_payload *p = payload;
-       int ret;
 
        if (!p->found_head && strcmp(head->name, GIT_HEAD_FILE) == 0) {
                p->found_head = 1;
        } else {
                /* If it doesn't match the refpec, we don't want it */
-               ret = git_refspec_src_match(p->spec, head->name);
-
-               if (ret == GIT_ENOMATCH)
+               if (!git_refspec_src_matches(p->spec, head->name))
                        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 */
index d6c2e1c97f065152521604968980656eb8feb10c..73fe83e6148efbca3494f10fd578a4700c70dabd 100644 (file)
@@ -92,11 +92,11 @@ int git_filters_load(git_vector *filters, git_repository *repo, const char *path
        if (mode == GIT_FILTER_TO_ODB) {
                /* Load the CRLF cleanup filter when writing to the ODB */
                error = git_filter_add__crlf_to_odb(filters, repo, path);
-               if (error < GIT_SUCCESS)
+               if (error < 0)
                        return error;
        } else {
                giterr_set(GITERR_INVALID, "Worktree filters are not implemented yet");
-               return GIT_ENOTIMPLEMENTED;
+               return -1;
        }
 
        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
         * we expect it to have */
        if (git_buf_grow(dest, git_buf_len(source)) < 0)
-               return GIT_ENOMEM;
+               return -1;
 
        for (i = 0; i < filters->length; ++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;
 
                if (git_buf_oom(dbuffer[dst]))
-                       return GIT_ENOMEM;
+                       return -1;
        }
 
        /* Ensure that the output ends up in dbuffer[1] (i.e. the dest) */
index 979fb40cab7403d97400b6d40e3c2b225b34e87f..8e8eac4e32a7b6f5ed202c246a2e4dae4ce9ddcd 100644 (file)
@@ -62,8 +62,7 @@ static int create_object(git_object **object_out, git_otype type)
        case GIT_OBJ_BLOB:
        case GIT_OBJ_TREE:
                object = git__malloc(git_object__size(type));
-               if (object == NULL)
-                       return GIT_ENOMEM;
+               GITERR_CHECK_ALLOC(object);
                memset(object, 0x0, git_object__size(type));
                break;
 
index bec770a307593c4181a875a7310e0ec1d8334537..ee4d3a158151ef2d91f9fe29d5631e40091f51fb 100644 (file)
@@ -10,6 +10,7 @@
 #include "common.h"
 #include "refspec.h"
 #include "util.h"
+#include "posix.h"
 
 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;
 }
 
-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)
index c62bb4e0e822a2fe1c09c87efad77c0c1d543f19..1b539787ffa818607a289db8f8f4905d437166e4 100644 (file)
@@ -486,7 +486,7 @@ static int push_glob_cb(const char *refname, void *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 0;
index ff22bf79f9a14834bed5aae0e1770b05ff24b233..aa549fdd0cb7817f0c03211d88571caf2c8877ec 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -420,7 +420,7 @@ int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_reposit
        assert(tag_names && repo && pattern);
 
        if (git_vector_init(&taglist, 8, NULL) < GIT_SUCCESS)
-               return GIT_ENOMEM;
+               return -1;
 
        filter.taglist = &taglist;
        filter.pattern = pattern;
index 0c88e44d3e76e6553c5004338cd586337953d115..bc4248d5bef3fe7d828ae1e79f789ba6413f77d9 100644 (file)
@@ -66,8 +66,10 @@ int git_transport_new(git_transport **out, const char *url)
 
        fn = transport_find_fn(url);
 
-       if (fn == NULL)
-               return git__throw(GIT_EINVALIDARGS, "Unsupported URL or non-existent path");
+       if (fn == NULL) {
+               giterr_set(GITERR_NET, "Unsupported URL protocol");
+               return -1;
+       }
 
        error = fn(&transport);
        if (error < GIT_SUCCESS)
index 31bc21c961fe6f1b20942edc82cce0b1bf99c79b..c51b1670fe6b687a284f38f9ef51c75d5c775239 100644 (file)
@@ -72,7 +72,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
        git_buf_putc(request, '\0');
 
        if (git_buf_oom(request))
-               return GIT_ENOMEM;
+               return -1;
 
        return 0;
 }
index 3690f3dedac2e850f165de3da93dd783bfd5c173..1b2b5eb895b247318ff5c1f76e77c9f979c3676e 100644 (file)
@@ -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");
 
        if (git_buf_oom(buf))
-               return GIT_ENOMEM;
+               return -1;
 
        return 0;
 }
@@ -174,13 +174,13 @@ static int on_headers_complete(http_parser *parser)
        if (t->content_type == NULL) {
                t->content_type = git__strdup(git_buf_cstr(buf));
                if (t->content_type == NULL)
-                       return t->error = GIT_ENOMEM;
+                       return t->error = -1;
        }
 
        git_buf_clear(buf);
        git_buf_printf(buf, "application/x-git-%s-advertisement", t->service);
        if (git_buf_oom(buf))
-               return t->error = GIT_ENOMEM;
+               return t->error = -1;
 
        if (strcmp(t->content_type, git_buf_cstr(buf)))
                return t->error = -1;
index 9baa06a9901079ae134858c45e22f47a8c0557d0..ebc2c68070c6a9c1a342c9ae95fa392a7d6d2b91 100644 (file)
@@ -82,24 +82,19 @@ static int read_tree_internal(git_tree_cache **out,
        git_tree_cache *tree = NULL;
        const char *name_start, *buffer;
        int count;
-       int error = GIT_SUCCESS;
        size_t name_len;
 
        buffer = name_start = *buffer_in;
 
-       if ((buffer = memchr(buffer, '\0', buffer_end - buffer)) == NULL) {
-               error = GIT_EOBJCORRUPTED;
-               goto cleanup;
-       }
+       if ((buffer = memchr(buffer, '\0', buffer_end - buffer)) == NULL)
+               goto corrupted;
 
-       if (++buffer >= buffer_end) {
-               error = GIT_EOBJCORRUPTED;
-               goto cleanup;
-       }
+       if (++buffer >= buffer_end)
+               goto corrupted;
 
        name_len = strlen(name_start);
-       if ((tree = git__malloc(sizeof(git_tree_cache) + name_len + 1)) == NULL)
-               return GIT_ENOMEM;
+       tree = git__malloc(sizeof(git_tree_cache) + name_len + 1);
+       GITERR_CHECK_ALLOC(tree);
 
        memset(tree, 0x0, sizeof(git_tree_cache));
        tree->parent = parent;
@@ -109,39 +104,28 @@ static int read_tree_internal(git_tree_cache **out,
        tree->name[name_len] = '\0';
 
        /* Blank-terminated ASCII decimal number of entries in this tree */
-       if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS || count < -1) {
-               error = GIT_EOBJCORRUPTED;
-               goto cleanup;
-       }
+       if (git__strtol32(&count, buffer, &buffer, 10) < 0 || count < -1)
+               goto corrupted;
 
        tree->entries = count;
 
-       if (*buffer != ' ' || ++buffer >= buffer_end) {
-               error = GIT_EOBJCORRUPTED;
-               goto cleanup;
-       }
+       if (*buffer != ' ' || ++buffer >= buffer_end)
+               goto corrupted;
 
         /* Number of children of the tree, newline-terminated */
-       if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS ||
-               count < 0) {
-               error = GIT_EOBJCORRUPTED;
-               goto cleanup;
-       }
+       if (git__strtol32(&count, buffer, &buffer, 10) < 0 || count < 0)
+               goto corrupted;
 
        tree->children_count = count;
 
-       if (*buffer != '\n' || ++buffer > buffer_end) {
-               error = GIT_EOBJCORRUPTED;
-               goto cleanup;
-       }
+       if (*buffer != '\n' || ++buffer > buffer_end)
+               goto corrupted;
 
        /* The SHA1 is only there if it's not invalidated */
        if (tree->entries >= 0) {
                /* 160-bit SHA-1 for this tree and it's children */
-               if (buffer + GIT_OID_RAWSZ > buffer_end) {
-                       error = GIT_EOBJCORRUPTED;
-                       goto cleanup;
-               }
+               if (buffer + GIT_OID_RAWSZ > buffer_end)
+                       goto corrupted;
 
                git_oid_fromraw(&tree->oid, (const unsigned char *)buffer);
                buffer += GIT_OID_RAWSZ;
@@ -150,40 +134,39 @@ static int read_tree_internal(git_tree_cache **out,
        /* Parse children: */
        if (tree->children_count > 0) {
                unsigned int i;
-               int err;
 
                tree->children = git__malloc(tree->children_count * sizeof(git_tree_cache *));
-               if (tree->children == NULL)
-                       goto cleanup;
+               GITERR_CHECK_ALLOC(tree->children);
 
                for (i = 0; i < tree->children_count; ++i) {
-                       err = read_tree_internal(&tree->children[i], &buffer, buffer_end, tree);
-
-                       if (err < GIT_SUCCESS)
-                               goto cleanup;
+                       if (read_tree_internal(&tree->children[i], &buffer, buffer_end, tree) < 0)
+                               return -1;
                }
        }
 
        *buffer_in = buffer;
        *out = tree;
-       return GIT_SUCCESS;
+       return 0;
 
- cleanup:
+ corrupted:
        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)
 {
        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)
-               return GIT_EOBJCORRUPTED;
+       if (buffer < buffer_end) {
+               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)
index 09ed1a3e8fc04e47617b5d8e66f11c0690b3bc40..7e2bfc102c45024e0bb1d660f1cecf137f10ccad 100644 (file)
@@ -741,7 +741,7 @@ int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payl
 
                case GIT_TREEWALK_PRE:
                        tree_error("Preorder tree walking is still not implemented");
-                       return GIT_ENOTIMPLEMENTED;
+                       return -1;
 
                default:
                        giterr_set(GITERR_INVALID, "Invalid walking mode for tree walk");
index 2cf7b158b6038233267000544b0af6556e25f13b..20a627ea8f4349e28bb8b1b2768dee64992def84 100644 (file)
@@ -60,22 +60,6 @@ int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
        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)
 {
        const char *p;
index 1fee9a70ceb5b8a7818bea5ef03167623d7fe7b4..a76800141febd3ecd22c4fbb85128f4fb97a5264 100644 (file)
@@ -105,8 +105,6 @@ GIT_INLINE(const char *) git__next_line(const char *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 *));
 
 /**
index 4d338efca61eec40453f05a69f775a935a859745..63bc703d777aff9b2dd1ed7e38a4139060fa83b0 100644 (file)
@@ -13,9 +13,9 @@
  * return error codes!
  */
 #define cl_git_pass(expr) do { \
-       git_clearerror(); \
-       if ((expr) != GIT_SUCCESS) \
-               clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, git_lasterror(), 1); \
+       giterr_clear(); \
+       if ((expr) != 0) \
+               clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, giterr_last()->message, 1); \
        } while(0)
 
 /**
index 78f811c718d89e19718e023abd00dc49ee2ac63e..0be3e7acad86f0adaec5c91d155f60de0595956b 100644 (file)
@@ -3,46 +3,30 @@
 #include "util.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)
 {
        char *str_in_error;
 
-       git_error_clear();
-       cl_assert(git_error_last() == NULL);
+       giterr_clear();
+       cl_assert(giterr_last() == NULL);
 
        giterr_set_oom(); /* internal fn */
 
-       cl_assert(git_error_last() != NULL);
-       cl_assert(git_error_last()->klass == GITERR_NOMEMORY);
-       str_in_error = strstr(git_error_last()->message, "memory");
+       cl_assert(giterr_last() != NULL);
+       cl_assert(giterr_last()->klass == GITERR_NOMEMORY);
+       str_in_error = strstr(giterr_last()->message, "memory");
        cl_assert(str_in_error != NULL);
 
-       git_error_clear();
+       giterr_clear();
 
        giterr_set(GITERR_REPOSITORY, "This is a test"); /* internal fn */
 
-       cl_assert(git_error_last() != NULL);
-       str_in_error = strstr(git_error_last()->message, "This is a test");
+       cl_assert(giterr_last() != NULL);
+       str_in_error = strstr(giterr_last()->message, "This is a test");
        cl_assert(str_in_error != NULL);
 
-       git_error_clear();
-       cl_assert(git_error_last() == NULL);
+       giterr_clear();
+       cl_assert(giterr_last() == NULL);
 
        do {
                struct stat st;
@@ -52,26 +36,25 @@ void test_core_errors__new_school(void)
        } while (false);
        giterr_set(GITERR_OS, "stat failed"); /* internal fn */
 
-       cl_assert(git_error_last() != NULL);
-       str_in_error = strstr(git_error_last()->message, "stat failed");
+       cl_assert(giterr_last() != NULL);
+       str_in_error = strstr(giterr_last()->message, "stat failed");
        cl_assert(str_in_error != NULL);
        cl_assert(git__prefixcmp(str_in_error, "stat failed: ") == 0);
        cl_assert(strlen(str_in_error) > strlen("stat failed: "));
 
 #ifdef GIT_WIN32
-       git_error_clear();
+       giterr_clear();
 
        /* The MSDN docs use this to generate a sample error */
        cl_assert(GetProcessId(NULL) == 0);
        giterr_set(GITERR_OS, "GetProcessId failed"); /* internal fn */
 
-       cl_assert(git_error_last() != NULL);
-       str_in_error = strstr(git_error_last()->message, "GetProcessId failed");
+       cl_assert(giterr_last() != NULL);
+       str_in_error = strstr(giterr_last()->message, "GetProcessId failed");
        cl_assert(str_in_error != NULL);
        cl_assert(git__prefixcmp(str_in_error, "GetProcessId failed: ") == 0);
        cl_assert(strlen(str_in_error) > strlen("GetProcessId failed: "));
 #endif
 
-       git_error_clear();
+       giterr_clear();
 }
-#endif
index 9d414c914a5f80ec2cc02f239eab7ea852cc86a2..766a461b93c4ebb5f38d12dd9cb6a5d04a985727 100644 (file)
@@ -101,8 +101,8 @@ void test_network_remotes__save(void)
 
 void test_network_remotes__fnmatch(void)
 {
-       cl_git_pass(git_refspec_src_match(_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/master"));
+       cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch"));
 }
 
 void test_network_remotes__transform(void)
index d4075c0b4218ab226321146d29cab8e73949ccaf..ea0add37b3ea2a01cc2970dc9077d3a76594187b 100644 (file)
@@ -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)
 {
        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)