diff options
| author | Russell Belfer <rb@github.com> | 2012-08-03 17:08:01 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-08-03 17:08:01 -0700 |
| commit | 5dca201072724e4230141796d7c9f8836a277de8 (patch) | |
| tree | 7eb6b8f3e08c8abc608ee43c0ddc32d4d043a2c6 /src/odb_pack.c | |
| parent | 2031760c626711cc69b4d63ac9798ff333583ca0 (diff) | |
| download | libgit2-5dca201072724e4230141796d7c9f8836a277de8.tar.gz | |
Update iterators for consistency across library
This updates all the `foreach()` type functions across the library
that take callbacks from the user to have a consistent behavior.
The rules are:
* A callback terminates the loop by returning any non-zero value
* Once the callback returns non-zero, it will not be called again
(i.e. the loop stops all iteration regardless of state)
* If the callback returns non-zero, the parent fn returns GIT_EUSER
* Although the parent returns GIT_EUSER, no error will be set in
the library and `giterr_last()` will return NULL if called.
This commit makes those changes across the library and adds tests
for most of the iteration APIs to make sure that they follow the
above rules.
Diffstat (limited to 'src/odb_pack.c')
| -rw-r--r-- | src/odb_pack.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c index 4b860e864..176be5f01 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -422,6 +422,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid) static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data) { + int error; struct git_pack_file *p; struct pack_backend *backend; unsigned int i; @@ -430,12 +431,14 @@ static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *o backend = (struct pack_backend *)_backend; /* Make sure we know about the packfiles */ - if (packfile_refresh_all(backend) < 0) - return -1; + if ((error = packfile_refresh_all(backend)) < 0) + return error; git_vector_foreach(&backend->packs, i, p) { - git_pack_foreach_entry(p, cb, &data); + if ((error = git_pack_foreach_entry(p, cb, &data)) < 0) + return error; } + return 0; } |
