summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-11-09 05:31:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-09 05:31:27 (GMT)
commitbde13700105a1c945819578ce8d5c0627d52c741 (patch)
treef099ae14f511cb3461a0f7e8361bb85b4679506e /sha1_file.c
parentb169d187682ed3f928df7806b00f3a62b83edfef (diff)
parent62a24c8923274b0ef941b2e7bc6efdb2fd52e6bf (diff)
downloadgit-bde13700105a1c945819578ce8d5c0627d52c741.zip
git-bde13700105a1c945819578ce8d5c0627d52c741.tar.gz
git-bde13700105a1c945819578ce8d5c0627d52c741.tar.bz2
Merge branch 'rs/hex-to-bytes-cleanup'
Code cleanup. * rs/hex-to-bytes-cleanup: sha1_file: use hex_to_bytes() http-push: use hex_to_bytes() notes: move hex_to_bytes() to hex.c and export it
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/sha1_file.c b/sha1_file.c
index d7de818..d708981 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1881,6 +1881,7 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
DIR *dir;
struct dirent *de;
int r = 0;
+ struct object_id oid;
if (subdir_nr > 0xff)
BUG("invalid loose object subdirectory: %x", subdir_nr);
@@ -1898,6 +1899,8 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
return r;
}
+ oid.hash[0] = subdir_nr;
+
while ((de = readdir(dir))) {
if (is_dot_or_dotdot(de->d_name))
continue;
@@ -1905,20 +1908,15 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
strbuf_setlen(path, baselen);
strbuf_addf(path, "/%s", de->d_name);
- if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2) {
- char hex[GIT_MAX_HEXSZ+1];
- struct object_id oid;
-
- xsnprintf(hex, sizeof(hex), "%02x%s",
- subdir_nr, de->d_name);
- if (!get_oid_hex(hex, &oid)) {
- if (obj_cb) {
- r = obj_cb(&oid, path->buf, data);
- if (r)
- break;
- }
- continue;
+ if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2 &&
+ !hex_to_bytes(oid.hash + 1, de->d_name,
+ GIT_SHA1_RAWSZ - 1)) {
+ if (obj_cb) {
+ r = obj_cb(&oid, path->buf, data);
+ if (r)
+ break;
}
+ continue;
}
if (cruft_cb) {