summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-06-24 12:12:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-24 18:09:50 (GMT)
commit0375f472d484041f9b1e5550b57d69286b3322e7 (patch)
tree04ac5e22c3c26373ed5b6e2389b9ce80738230ed /sha1_file.c
parent5a5bd5765ac5d180bf540ba7c6540a9f3dc16f4b (diff)
downloadgit-0375f472d484041f9b1e5550b57d69286b3322e7.zip
git-0375f472d484041f9b1e5550b57d69286b3322e7.tar.gz
git-0375f472d484041f9b1e5550b57d69286b3322e7.tar.bz2
sha1_file: let for_each_file_in_obj_subdir() handle subdir names
The function for_each_file_in_obj_subdir() takes a object subdirectory number and expects the name of the same subdirectory to be included in the path strbuf. Avoid this redundancy by letting the function append the hexadecimal subdirectory name itself. This makes it a bit easier and safer to use the function -- it becomes impossible to specify different subdirectories in subdir_nr and path. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 5e0ee2b..98ce85a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3742,15 +3742,22 @@ int for_each_file_in_obj_subdir(int subdir_nr,
each_loose_subdir_fn subdir_cb,
void *data)
{
- size_t baselen = path->len;
- DIR *dir = opendir(path->buf);
+ size_t origlen, baselen;
+ DIR *dir;
struct dirent *de;
int r = 0;
+ origlen = path->len;
+ strbuf_complete(path, '/');
+ strbuf_addf(path, "%02x", subdir_nr);
+ baselen = path->len;
+
+ dir = opendir(path->buf);
if (!dir) {
- if (errno == ENOENT)
- return 0;
- return error_errno("unable to open %s", path->buf);
+ if (errno != ENOENT)
+ r = error_errno("unable to open %s", path->buf);
+ strbuf_setlen(path, origlen);
+ return r;
}
while ((de = readdir(dir))) {
@@ -3788,6 +3795,8 @@ int for_each_file_in_obj_subdir(int subdir_nr,
if (!r && subdir_cb)
r = subdir_cb(subdir_nr, path->buf, data);
+ strbuf_setlen(path, origlen);
+
return r;
}
@@ -3797,15 +3806,12 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
each_loose_subdir_fn subdir_cb,
void *data)
{
- size_t baselen = path->len;
int r = 0;
int i;
for (i = 0; i < 256; i++) {
- strbuf_addf(path, "/%02x", i);
r = for_each_file_in_obj_subdir(i, path, obj_cb, cruft_cb,
subdir_cb, data);
- strbuf_setlen(path, baselen);
if (r)
break;
}