Commit 76c1d9a0 authored by brian m. carlson's avatar brian m. carlson Committed by Junio C Hamano

Convert object iteration callbacks to struct object_id

Convert each_loose_object_fn and each_packed_object_fn to take a pointer
to struct object_id.  Update the various callbacks.  Convert several
40-based constants to use GIT_SHA1_HEXSZ.
Signed-off-by: brian m. carlson's avatarbrian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent 068f85e3
......@@ -409,20 +409,20 @@ static int batch_object_cb(const unsigned char sha1[20], void *vdata)
return 0;
}
static int batch_loose_object(const unsigned char *sha1,
static int batch_loose_object(const struct object_id *oid,
const char *path,
void *data)
{
sha1_array_append(data, sha1);
sha1_array_append(data, oid->hash);
return 0;
}
static int batch_packed_object(const unsigned char *sha1,
static int batch_packed_object(const struct object_id *oid,
struct packed_git *pack,
uint32_t pos,
void *data)
{
sha1_array_append(data, sha1);
sha1_array_append(data, oid->hash);
return 0;
}
......
......@@ -53,7 +53,7 @@ static void loose_garbage(const char *path)
report_garbage(PACKDIR_FILE_GARBAGE, path);
}
static int count_loose(const unsigned char *sha1, const char *path, void *data)
static int count_loose(const struct object_id *oid, const char *path, void *data)
{
struct stat st;
......@@ -62,7 +62,7 @@ static int count_loose(const unsigned char *sha1, const char *path, void *data)
else {
loose_size += on_disk_bytes(st);
loose++;
if (verbose && has_sha1_pack(sha1))
if (verbose && has_sha1_pack(oid->hash))
packed_loose++;
}
return 0;
......
......@@ -491,7 +491,7 @@ static void get_default_heads(void)
}
}
static struct object *parse_loose_object(const unsigned char *sha1,
static struct object *parse_loose_object(const struct object_id *oid,
const char *path)
{
struct object *obj;
......@@ -500,27 +500,27 @@ static struct object *parse_loose_object(const unsigned char *sha1,
unsigned long size;
int eaten;
if (read_loose_object(path, sha1, &type, &size, &contents) < 0)
if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
return NULL;
if (!contents && type != OBJ_BLOB)
die("BUG: read_loose_object streamed a non-blob");
obj = parse_object_buffer(sha1, type, size, contents, &eaten);
obj = parse_object_buffer(oid->hash, type, size, contents, &eaten);
if (!eaten)
free(contents);
return obj;
}
static int fsck_loose(const unsigned char *sha1, const char *path, void *data)
static int fsck_loose(const struct object_id *oid, const char *path, void *data)
{
struct object *obj = parse_loose_object(sha1, path);
struct object *obj = parse_loose_object(oid, path);
if (!obj) {
errors_found |= ERROR_OBJECT;
error("%s: object corrupt or missing: %s",
sha1_to_hex(sha1), path);
oid_to_hex(oid), path);
return 0; /* keep checking other objects */
}
......@@ -619,26 +619,26 @@ static int fsck_cache_tree(struct cache_tree *it)
return err;
}
static void mark_object_for_connectivity(const unsigned char *sha1)
static void mark_object_for_connectivity(const struct object_id *oid)
{
struct object *obj = lookup_unknown_object(sha1);
struct object *obj = lookup_unknown_object(oid->hash);
obj->flags |= HAS_OBJ;
}
static int mark_loose_for_connectivity(const unsigned char *sha1,
static int mark_loose_for_connectivity(const struct object_id *oid,
const char *path,
void *data)
{
mark_object_for_connectivity(sha1);
mark_object_for_connectivity(oid);
return 0;
}
static int mark_packed_for_connectivity(const unsigned char *sha1,
static int mark_packed_for_connectivity(const struct object_id *oid,
struct packed_git *pack,
uint32_t pos,
void *data)
{
mark_object_for_connectivity(sha1);
mark_object_for_connectivity(oid);
return 0;
}
......
......@@ -2534,17 +2534,17 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
free(in_pack.array);
}
static int add_loose_object(const unsigned char *sha1, const char *path,
static int add_loose_object(const struct object_id *oid, const char *path,
void *data)
{
enum object_type type = sha1_object_info(sha1, NULL);
enum object_type type = sha1_object_info(oid->hash, NULL);
if (type < 0) {
warning("loose object at %s could not be examined", path);
return 0;
}
add_object_entry(sha1, type, "", 0);
add_object_entry(oid->hash, type, "", 0);
return 0;
}
......
......@@ -19,12 +19,12 @@ static int prune_subdir(int nr, const char *path, void *data)
return 0;
}
static int prune_object(const unsigned char *sha1, const char *path,
static int prune_object(const struct object_id *oid, const char *path,
void *data)
{
int *opts = data;
if (!has_sha1_pack(sha1))
if (!has_sha1_pack(oid->hash))
return 0;
if (*opts & PRUNE_PACKED_DRY_RUN)
......
......@@ -30,7 +30,7 @@ static int prune_tmp_file(const char *fullpath)
return 0;
}
static int prune_object(const unsigned char *sha1, const char *fullpath,
static int prune_object(const struct object_id *oid, const char *fullpath,
void *data)
{
struct stat st;
......@@ -39,7 +39,7 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
* Do we know about this object?
* It must have been reachable
*/
if (lookup_object(sha1))
if (lookup_object(oid->hash))
return 0;
if (lstat(fullpath, &st)) {
......@@ -50,8 +50,8 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
enum object_type type = sha1_object_info(sha1, NULL);
printf("%s %s\n", sha1_to_hex(sha1),
enum object_type type = sha1_object_info(oid->hash, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? typename(type) : "unknown");
}
if (!show_only)
......
......@@ -1655,7 +1655,7 @@ extern int unpack_object_header(struct packed_git *, struct pack_window **, off_
* scratch buffer, but restored to its original contents before
* the function returns.
*/
typedef int each_loose_object_fn(const unsigned char *sha1,
typedef int each_loose_object_fn(const struct object_id *oid,
const char *path,
void *data);
typedef int each_loose_cruft_fn(const char *basename,
......@@ -1681,7 +1681,7 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
* LOCAL_ONLY flag is set).
*/
#define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
typedef int each_packed_object_fn(const unsigned char *sha1,
typedef int each_packed_object_fn(const struct object_id *oid,
struct packed_git *pack,
uint32_t pos,
void *data);
......
......@@ -58,7 +58,7 @@ struct recent_data {
unsigned long timestamp;
};
static void add_recent_object(const unsigned char *sha1,
static void add_recent_object(const struct object_id *oid,
unsigned long mtime,
struct recent_data *data)
{
......@@ -75,37 +75,37 @@ static void add_recent_object(const unsigned char *sha1,
* later processing, and the revision machinery expects
* commits and tags to have been parsed.
*/
type = sha1_object_info(sha1, NULL);
type = sha1_object_info(oid->hash, NULL);
if (type < 0)
die("unable to get object info for %s", sha1_to_hex(sha1));
die("unable to get object info for %s", oid_to_hex(oid));
switch (type) {
case OBJ_TAG:
case OBJ_COMMIT:
obj = parse_object_or_die(sha1, NULL);
obj = parse_object_or_die(oid->hash, NULL);
break;
case OBJ_TREE:
obj = (struct object *)lookup_tree(sha1);
obj = (struct object *)lookup_tree(oid->hash);
break;
case OBJ_BLOB:
obj = (struct object *)lookup_blob(sha1);
obj = (struct object *)lookup_blob(oid->hash);
break;
default:
die("unknown object type for %s: %s",
sha1_to_hex(sha1), typename(type));
oid_to_hex(oid), typename(type));
}
if (!obj)
die("unable to lookup %s", sha1_to_hex(sha1));
die("unable to lookup %s", oid_to_hex(oid));
add_pending_object(data->revs, obj, "");
}
static int add_recent_loose(const unsigned char *sha1,
static int add_recent_loose(const struct object_id *oid,
const char *path, void *data)
{
struct stat st;
struct object *obj = lookup_object(sha1);
struct object *obj = lookup_object(oid->hash);
if (obj && obj->flags & SEEN)
return 0;
......@@ -119,22 +119,22 @@ static int add_recent_loose(const unsigned char *sha1,
*/
if (errno == ENOENT)
return 0;
return error_errno("unable to stat %s", sha1_to_hex(sha1));
return error_errno("unable to stat %s", oid_to_hex(oid));
}
add_recent_object(sha1, st.st_mtime, data);
add_recent_object(oid, st.st_mtime, data);
return 0;
}
static int add_recent_packed(const unsigned char *sha1,
static int add_recent_packed(const struct object_id *oid,
struct packed_git *p, uint32_t pos,
void *data)
{
struct object *obj = lookup_object(sha1);
struct object *obj = lookup_object(oid->hash);
if (obj && obj->flags & SEEN)
return 0;
add_recent_object(sha1, p->mtime, data);
add_recent_object(oid, p->mtime, data);
return 0;
}
......
......@@ -3685,15 +3685,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;
}
......@@ -3805,7 +3805,7 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c
return error("unable to get sha1 of object %u in %s",
i, p->pack_name);
r = cb(oid.hash, p, i, data);
r = cb(&oid, p, i, data);
if (r)
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment