Added new error codes. Improved error handling. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Andreas Ericsson <ae@op5.se>
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
diff --git a/src/commit.c b/src/commit.c
index e740db6..46c7d0d 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -81,7 +81,7 @@ int git_commit_parse_existing(git_commit *commit)
return 0;
if (git_odb_read(&commit_obj, commit->object.pool->db, &commit->object.id) < 0)
- return -1;
+ return GIT_ENOTFOUND;
if (commit_obj.type != GIT_OBJ_COMMIT)
goto error_cleanup;
@@ -128,27 +128,27 @@ git_commit *git_commit_lookup(git_revpool *pool, const git_oid *id)
int git_commit__parse_time(time_t *commit_time, char *buffer, const char *buffer_end)
{
if (memcmp(buffer, "author ", 7) != 0)
- return -1;
+ return GIT_EOBJCORRUPTED;
buffer = memchr(buffer, '\n', buffer_end - buffer);
if (buffer == 0 || ++buffer >= buffer_end)
- return -1;
+ return GIT_EOBJCORRUPTED;
if (memcmp(buffer, "committer ", 10) != 0)
- return -1;
+ return GIT_EOBJCORRUPTED;
buffer = memchr(buffer, '>', buffer_end - buffer);
if (buffer == 0 || ++buffer >= buffer_end)
- return -1;
+ return GIT_EOBJCORRUPTED;
*commit_time = strtol(buffer, &buffer, 10);
if (*commit_time == 0)
- return -1;
+ return GIT_EOBJCORRUPTED;
buffer = memchr(buffer, '\n', buffer_end - buffer);
if (buffer == 0 || ++buffer >= buffer_end)
- return -1;
+ return GIT_EOBJCORRUPTED;
return (buffer < buffer_end) ? 0 : -1;
}
@@ -161,16 +161,16 @@ int git_commit__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_en
char *buffer = *buffer_out;
if (buffer + (header_len + sha_len + 1) > buffer_end)
- return -1;
+ return GIT_EOBJCORRUPTED;
if (memcmp(buffer, header, header_len) != 0)
- return -1;
+ return GIT_EOBJCORRUPTED;
if (buffer[header_len + sha_len] != '\n')
- return -1;
+ return GIT_EOBJCORRUPTED;
if (git_oid_mkstr(oid, buffer + header_len) < 0)
- return -1;
+ return GIT_EOBJCORRUPTED;
*buffer_out = buffer + (header_len + sha_len + 1);
@@ -188,7 +188,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
return 0;
if (git_commit__parse_oid(&oid, &buffer, buffer_end, "tree ") < 0)
- return -1;
+ return GIT_EOBJCORRUPTED;
/*
* TODO: load tree into commit object
@@ -199,7 +199,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
git_commit *parent;
if ((parent = git_commit_lookup(commit->object.pool, &oid)) == NULL)
- return -1;
+ return GIT_ENOTFOUND;
// Inherit uninteresting flag
if (commit->uninteresting)
@@ -209,21 +209,21 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
}
if (git_commit__parse_time(&commit->commit_time, buffer, buffer_end) < 0)
- return -1;
+ return GIT_EOBJCORRUPTED;
commit->parsed = 1;
return 0;
}
-void git_commit_list_push_back(git_commit_list *list, git_commit *commit)
+int git_commit_list_push_back(git_commit_list *list, git_commit *commit)
{
git_commit_node *node = NULL;
node = git__malloc(sizeof(git_commit_list));
if (node == NULL)
- return;
+ return GIT_ENOMEM;
node->commit = commit;
node->next = NULL;
@@ -237,16 +237,17 @@ void git_commit_list_push_back(git_commit_list *list, git_commit *commit)
}
list->size++;
+ return 0;
}
-void git_commit_list_push_front(git_commit_list *list, git_commit *commit)
+int git_commit_list_push_front(git_commit_list *list, git_commit *commit)
{
git_commit_node *node = NULL;
node = git__malloc(sizeof(git_commit_list));
if (node == NULL)
- return;
+ return GIT_ENOMEM;
node->commit = commit;
node->next = list->head;
@@ -260,6 +261,7 @@ void git_commit_list_push_front(git_commit_list *list, git_commit *commit)
}
list->size++;
+ return 0;
}
diff --git a/src/commit.h b/src/commit.h
index c62b80f..760529d 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -44,8 +44,8 @@ void git_commit__mark_uninteresting(git_commit *commit);
int git_commit_parse_existing(git_commit *commit);
-void git_commit_list_push_back(git_commit_list *list, git_commit *commit);
-void git_commit_list_push_front(git_commit_list *list, git_commit *commit);
+int git_commit_list_push_back(git_commit_list *list, git_commit *commit);
+int git_commit_list_push_front(git_commit_list *list, git_commit *commit);
git_commit *git_commit_list_pop_back(git_commit_list *list);
git_commit *git_commit_list_pop_front(git_commit_list *list);
diff --git a/src/git/common.h b/src/git/common.h
index 19c6a20..2506dae 100644
--- a/src/git/common.h
+++ b/src/git/common.h
@@ -77,6 +77,12 @@
/** Consult the OS error information. */
#define GIT_EOSERR (GIT_ERROR - 4)
+/** The specified object is of invalid type */
+#define GIT_EOBJTYPE (GIT_ERROR - 5)
+
+/** The specified object has its data corrupted */
+#define GIT_EOBJCORRUPTED (GIT_ERROR - 6)
+
GIT_BEGIN_DECL
/** A revision traversal pool. */
diff --git a/src/git/revwalk.h b/src/git/revwalk.h
index 0a902f9..027a51a 100644
--- a/src/git/revwalk.h
+++ b/src/git/revwalk.h
@@ -67,14 +67,14 @@ GIT_EXTERN(void) gitrp_reset(git_revpool *pool);
* @param pool the pool being used for the traversal.
* @param commit the commit to start from.
*/
-GIT_EXTERN(void) gitrp_push(git_revpool *pool, git_commit *commit);
+GIT_EXTERN(int) gitrp_push(git_revpool *pool, git_commit *commit);
/**
* Mark a commit (and its ancestors) uninteresting for the output.
* @param pool the pool being used for the traversal.
* @param commit the commit that will be ignored during the traversal
*/
-GIT_EXTERN(void) gitrp_hide(git_revpool *pool, git_commit *commit);
+GIT_EXTERN(int) gitrp_hide(git_revpool *pool, git_commit *commit);
/**
* Get the next commit from the revision traversal.
diff --git a/src/revwalk.c b/src/revwalk.c
index 200a946..186a08f 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -62,17 +62,17 @@ void gitrp_sorting(git_revpool *pool, unsigned int sort_mode)
gitrp_reset(pool);
}
-void gitrp_push(git_revpool *pool, git_commit *commit)
+int gitrp_push(git_revpool *pool, git_commit *commit)
{
if (commit == NULL || commit->seen)
- return;
+ return GIT_ENOTFOUND;
if (commit->object.pool != pool || pool->walking)
- return;
+ return GIT_ERROR;
if (!commit->parsed) {
if (git_commit_parse_existing(commit) < 0)
- return;
+ return GIT_EOBJCORRUPTED;
}
// Sanity check: make sure that if the commit
@@ -81,36 +81,48 @@ void gitrp_push(git_revpool *pool, git_commit *commit)
if (commit->uninteresting)
git_commit__mark_uninteresting(commit);
- git_commit_list_push_back(&pool->roots, commit);
+ if (git_commit_list_push_back(&pool->roots, commit) < 0)
+ return GIT_ENOMEM;
+
+ return 0;
}
-void gitrp_hide(git_revpool *pool, git_commit *commit)
+int gitrp_hide(git_revpool *pool, git_commit *commit)
{
if (pool->walking)
- return;
+ return GIT_ERROR;
git_commit__mark_uninteresting(commit);
- gitrp_push(pool, commit);
+ return gitrp_push(pool, commit);
}
-void gitrp__enroot(git_revpool *pool, git_commit *commit)
+int gitrp__enroot(git_revpool *pool, git_commit *commit)
{
+ int error;
git_commit_node *parents;
if (commit->seen)
- return;
+ return 0;
- if (commit->parsed == 0)
- git_commit_parse_existing(commit);
+ if (commit->parsed == 0) {
+ if (git_commit_parse_existing(commit))
+ return GIT_EOBJCORRUPTED;
+ }
commit->seen = 1;
for (parents = commit->parents.head; parents != NULL; parents = parents->next) {
parents->commit->in_degree++;
- gitrp__enroot(pool, parents->commit);
+
+ error = gitrp__enroot(pool, parents->commit);
+ if (error < 0)
+ return error;
}
- git_commit_list_push_back(&pool->iterator, commit);
+ if (git_commit_list_push_back(&pool->iterator, commit))
+ return GIT_ENOMEM;
+
+ return 0;
}
void gitrp__prepare_walk(git_revpool *pool)
diff --git a/src/revwalk.h b/src/revwalk.h
index bff873e..8929a79 100644
--- a/src/revwalk.h
+++ b/src/revwalk.h
@@ -18,6 +18,6 @@ struct git_revpool {
};
void gitrp__prepare_walk(git_revpool *pool);
-void gitrp__enroot(git_revpool *pool, git_commit *commit);
+int gitrp__enroot(git_revpool *pool, git_commit *commit);
#endif /* INCLUDE_revwalk_h__ */