Remove old and unused error codes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
diff --git a/include/git2/errors.h b/include/git2/errors.h
index 17a7010..0406c16 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -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 {
@@ -138,44 +65,17 @@ typedef enum {
} 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
diff --git a/include/git2/refspec.h b/include/git2/refspec.h
index 3acf114..28afe65 100644
--- a/include/git2/refspec.h
+++ b/include/git2/refspec.h
@@ -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
diff --git a/src/config.c b/src/config.c
index 4c97192..0ab0cd4 100644
--- a/src/config.c
+++ b/src/config.c
@@ -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)
diff --git a/src/crlf.c b/src/crlf.c
index 8fe588a..b495d2d 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -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;
diff --git a/src/delta-apply.c b/src/delta-apply.c
index c8c662f..d3be084 100644
--- a/src/delta-apply.c
+++ b/src/delta-apply.c
@@ -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;
diff --git a/src/diff.c b/src/diff.c
index b21dfaf..b845f9e 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -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;
diff --git a/src/errors.c b/src/errors.c
index 7a6bbd6..f708519 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -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();
-}
-
diff --git a/src/fetch.c b/src/fetch.c
index 6fe1b56..1944bd0 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -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 */
diff --git a/src/filter.c b/src/filter.c
index d6c2e1c..73fe83e 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -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) */
diff --git a/src/object.c b/src/object.c
index 979fb40..8e8eac4 100644
--- a/src/object.c
+++ b/src/object.c
@@ -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;
diff --git a/src/refspec.c b/src/refspec.c
index bec770a..ee4d3a1 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -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)
diff --git a/src/revwalk.c b/src/revwalk.c
index c62bb4e..1b53978 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -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;
diff --git a/src/tag.c b/src/tag.c
index ff22bf7..aa549fd 100644
--- 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;
diff --git a/src/transport.c b/src/transport.c
index 0c88e44..bc4248d 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -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)
diff --git a/src/transports/git.c b/src/transports/git.c
index 31bc21c..c51b167 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -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;
}
diff --git a/src/transports/http.c b/src/transports/http.c
index 3690f3d..1b2b5eb 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -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;
diff --git a/src/tree-cache.c b/src/tree-cache.c
index 9baa06a..ebc2c68 100644
--- a/src/tree-cache.c
+++ b/src/tree-cache.c
@@ -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)
diff --git a/src/tree.c b/src/tree.c
index 09ed1a3..7e2bfc1 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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");
diff --git a/src/util.c b/src/util.c
index 2cf7b15..20a627e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;
diff --git a/src/util.h b/src/util.h
index 1fee9a7..a768001 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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 *));
/**
diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h
index 4d338ef..63bc703 100644
--- a/tests-clar/clar_libgit2.h
+++ b/tests-clar/clar_libgit2.h
@@ -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)
/**
diff --git a/tests-clar/core/errors.c b/tests-clar/core/errors.c
index 78f811c..0be3e7a 100644
--- a/tests-clar/core/errors.c
+++ b/tests-clar/core/errors.c
@@ -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
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 9d414c9..766a461 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -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)
diff --git a/tests-clar/object/tree/frompath.c b/tests-clar/object/tree/frompath.c
index d4075c0..ea0add3 100644
--- a/tests-clar/object/tree/frompath.c
+++ b/tests-clar/object/tree/frompath.c
@@ -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)