diff options
author | Vicent Marti <vicent@github.com> | 2014-04-18 12:33:19 +0200 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-04-18 12:33:19 +0200 |
commit | 28fd7206b1359b6564bad3c66382b47a8f2e3eb1 (patch) | |
tree | e0d9204bdfea2a948d94b2b14d382a697b00b6db /src/tree-cache.c | |
parent | 2bed3553f4595a42d9a6884edc66b991e21f881e (diff) | |
parent | 8303827226db114a1157e6173e731f316c217851 (diff) | |
download | libgit2-28fd7206b1359b6564bad3c66382b47a8f2e3eb1.tar.gz |
Merge pull request #2108 from libgit2/rb/threadsafe-index-iterator
Make index iterator thread safe
Diffstat (limited to 'src/tree-cache.c')
-rw-r--r-- | src/tree-cache.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/tree-cache.c b/src/tree-cache.c index 1d3997154..49afd6e49 100644 --- a/src/tree-cache.c +++ b/src/tree-cache.c @@ -7,23 +7,16 @@ #include "tree-cache.h" -static git_tree_cache *find_child(const git_tree_cache *tree, const char *path) +static git_tree_cache *find_child( + const git_tree_cache *tree, const char *path, const char *end) { - size_t i, dirlen; - const char *end; - - end = strchr(path, '/'); - if (end == NULL) { - end = strrchr(path, '\0'); - } - - dirlen = end - path; + size_t i, dirlen = end ? (size_t)(end - path) : strlen(path); for (i = 0; i < tree->children_count; ++i) { - const char *childname = tree->children[i]->name; + git_tree_cache *child = tree->children[i]; - if (strlen(childname) == dirlen && !memcmp(path, childname, dirlen)) - return tree->children[i]; + if (child->namelen == dirlen && !memcmp(path, child->name, dirlen)) + return child; } return NULL; @@ -44,7 +37,7 @@ void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path) if (end == NULL) /* End of path */ break; - tree = find_child(tree, ptr); + tree = find_child(tree, ptr, end); if (tree == NULL) /* We don't have that tree */ return; @@ -64,10 +57,9 @@ const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char while (1) { end = strchr(ptr, '/'); - tree = find_child(tree, ptr); - if (tree == NULL) { /* Can't find it */ + tree = find_child(tree, ptr, end); + if (tree == NULL) /* Can't find it */ return NULL; - } if (end == NULL || *end + 1 == '\0') return tree; @@ -100,6 +92,7 @@ static int read_tree_internal(git_tree_cache **out, tree->parent = parent; /* NUL-terminated tree name */ + tree->namelen = name_len; memcpy(tree->name, name_start, name_len); tree->name[name_len] = '\0'; |