summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-03-17 20:50:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-17 20:50:25 (GMT)
commite1fae930193b3e8ff02cee936605625f63e1d1e4 (patch)
tree90ad9f3e50d1f1d6acd174ecb4dc0a8bbc28df27 /sha1_file.c
parent0a4ae91d1cf72b1185a46e5f072ac6b25b92350b (diff)
parente86ab2c1cd60ec4b9214e5cd8450a474fa175f5c (diff)
downloadgit-e1fae930193b3e8ff02cee936605625f63e1d1e4.zip
git-e1fae930193b3e8ff02cee936605625f63e1d1e4.tar.gz
git-e1fae930193b3e8ff02cee936605625f63e1d1e4.tar.bz2
Merge branch 'bc/object-id'
"uchar [40]" to "struct object_id" conversion continues. * bc/object-id: wt-status: convert to struct object_id builtin/merge-base: convert to struct object_id Convert object iteration callbacks to struct object_id sha1_file: introduce an nth_packed_object_oid function refs: simplify parsing of reflog entries refs: convert each_reflog_ent_fn to struct object_id reflog-walk: convert struct reflog_info to struct object_id builtin/replace: convert to struct object_id Convert remaining callers of resolve_refdup to object_id builtin/merge: convert to struct object_id builtin/clone: convert to struct object_id builtin/branch: convert to struct object_id builtin/grep: convert to struct object_id builtin/fmt-merge-message: convert to struct object_id builtin/fast-export: convert to struct object_id builtin/describe: convert to struct object_id builtin/diff-tree: convert to struct object_id builtin/commit: convert to struct object_id hex: introduce parse_oid_hex
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/sha1_file.c b/sha1_file.c
index f1c83a9..29bbc5f 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2706,6 +2706,17 @@ const unsigned char *nth_packed_object_sha1(struct packed_git *p,
}
}
+const struct object_id *nth_packed_object_oid(struct object_id *oid,
+ struct packed_git *p,
+ uint32_t n)
+{
+ const unsigned char *hash = nth_packed_object_sha1(p, n);
+ if (!hash)
+ return NULL;
+ hashcpy(oid->hash, hash);
+ return oid;
+}
+
void check_pack_index_ptr(const struct packed_git *p, const void *vptr)
{
const unsigned char *ptr = vptr;
@@ -3752,15 +3763,15 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
strbuf_setlen(path, baselen);
strbuf_addf(path, "/%s", de->d_name);
- if (strlen(de->d_name) == 38) {
- char hex[41];
- unsigned char sha1[20];
+ if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2) {
+ char hex[GIT_SHA1_HEXSZ+1];
+ struct object_id oid;
snprintf(hex, sizeof(hex), "%02x%s",
subdir_nr, de->d_name);
- if (!get_sha1_hex(hex, sha1)) {
+ if (!get_oid_hex(hex, &oid)) {
if (obj_cb) {
- r = obj_cb(sha1, path->buf, data);
+ r = obj_cb(&oid, path->buf, data);
if (r)
break;
}
@@ -3866,13 +3877,13 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c
int r = 0;
for (i = 0; i < p->num_objects; i++) {
- const unsigned char *sha1 = nth_packed_object_sha1(p, i);
+ struct object_id oid;
- if (!sha1)
+ if (!nth_packed_object_oid(&oid, p, i))
return error("unable to get sha1 of object %u in %s",
i, p->pack_name);
- r = cb(sha1, p, i, data);
+ r = cb(&oid, p, i, data);
if (r)
break;
}