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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
068f85e313
commit
76c1d9a096
@ -409,20 +409,20 @@ static int batch_object_cb(const unsigned char sha1[20], void *vdata)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int batch_loose_object(const unsigned char *sha1,
|
static int batch_loose_object(const struct object_id *oid,
|
||||||
const char *path,
|
const char *path,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
sha1_array_append(data, sha1);
|
sha1_array_append(data, oid->hash);
|
||||||
return 0;
|
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,
|
struct packed_git *pack,
|
||||||
uint32_t pos,
|
uint32_t pos,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
sha1_array_append(data, sha1);
|
sha1_array_append(data, oid->hash);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ static void loose_garbage(const char *path)
|
|||||||
report_garbage(PACKDIR_FILE_GARBAGE, 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;
|
struct stat st;
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ static int count_loose(const unsigned char *sha1, const char *path, void *data)
|
|||||||
else {
|
else {
|
||||||
loose_size += on_disk_bytes(st);
|
loose_size += on_disk_bytes(st);
|
||||||
loose++;
|
loose++;
|
||||||
if (verbose && has_sha1_pack(sha1))
|
if (verbose && has_sha1_pack(oid->hash))
|
||||||
packed_loose++;
|
packed_loose++;
|
||||||
}
|
}
|
||||||
return 0;
|
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)
|
const char *path)
|
||||||
{
|
{
|
||||||
struct object *obj;
|
struct object *obj;
|
||||||
@ -500,27 +500,27 @@ static struct object *parse_loose_object(const unsigned char *sha1,
|
|||||||
unsigned long size;
|
unsigned long size;
|
||||||
int eaten;
|
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;
|
return NULL;
|
||||||
|
|
||||||
if (!contents && type != OBJ_BLOB)
|
if (!contents && type != OBJ_BLOB)
|
||||||
die("BUG: read_loose_object streamed a non-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)
|
if (!eaten)
|
||||||
free(contents);
|
free(contents);
|
||||||
return obj;
|
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) {
|
if (!obj) {
|
||||||
errors_found |= ERROR_OBJECT;
|
errors_found |= ERROR_OBJECT;
|
||||||
error("%s: object corrupt or missing: %s",
|
error("%s: object corrupt or missing: %s",
|
||||||
sha1_to_hex(sha1), path);
|
oid_to_hex(oid), path);
|
||||||
return 0; /* keep checking other objects */
|
return 0; /* keep checking other objects */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,26 +619,26 @@ static int fsck_cache_tree(struct cache_tree *it)
|
|||||||
return err;
|
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;
|
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,
|
const char *path,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
mark_object_for_connectivity(sha1);
|
mark_object_for_connectivity(oid);
|
||||||
return 0;
|
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,
|
struct packed_git *pack,
|
||||||
uint32_t pos,
|
uint32_t pos,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
mark_object_for_connectivity(sha1);
|
mark_object_for_connectivity(oid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2534,17 +2534,17 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
|
|||||||
free(in_pack.array);
|
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)
|
void *data)
|
||||||
{
|
{
|
||||||
enum object_type type = sha1_object_info(sha1, NULL);
|
enum object_type type = sha1_object_info(oid->hash, NULL);
|
||||||
|
|
||||||
if (type < 0) {
|
if (type < 0) {
|
||||||
warning("loose object at %s could not be examined", path);
|
warning("loose object at %s could not be examined", path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
add_object_entry(sha1, type, "", 0);
|
add_object_entry(oid->hash, type, "", 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@ static int prune_subdir(int nr, const char *path, void *data)
|
|||||||
return 0;
|
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)
|
void *data)
|
||||||
{
|
{
|
||||||
int *opts = data;
|
int *opts = data;
|
||||||
|
|
||||||
if (!has_sha1_pack(sha1))
|
if (!has_sha1_pack(oid->hash))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (*opts & PRUNE_PACKED_DRY_RUN)
|
if (*opts & PRUNE_PACKED_DRY_RUN)
|
||||||
|
@ -30,7 +30,7 @@ static int prune_tmp_file(const char *fullpath)
|
|||||||
return 0;
|
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)
|
void *data)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -39,7 +39,7 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
|
|||||||
* Do we know about this object?
|
* Do we know about this object?
|
||||||
* It must have been reachable
|
* It must have been reachable
|
||||||
*/
|
*/
|
||||||
if (lookup_object(sha1))
|
if (lookup_object(oid->hash))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (lstat(fullpath, &st)) {
|
if (lstat(fullpath, &st)) {
|
||||||
@ -50,8 +50,8 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,
|
|||||||
if (st.st_mtime > expire)
|
if (st.st_mtime > expire)
|
||||||
return 0;
|
return 0;
|
||||||
if (show_only || verbose) {
|
if (show_only || verbose) {
|
||||||
enum object_type type = sha1_object_info(sha1, NULL);
|
enum object_type type = sha1_object_info(oid->hash, NULL);
|
||||||
printf("%s %s\n", sha1_to_hex(sha1),
|
printf("%s %s\n", oid_to_hex(oid),
|
||||||
(type > 0) ? typename(type) : "unknown");
|
(type > 0) ? typename(type) : "unknown");
|
||||||
}
|
}
|
||||||
if (!show_only)
|
if (!show_only)
|
||||||
|
4
cache.h
4
cache.h
@ -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
|
* scratch buffer, but restored to its original contents before
|
||||||
* the function returns.
|
* 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,
|
const char *path,
|
||||||
void *data);
|
void *data);
|
||||||
typedef int each_loose_cruft_fn(const char *basename,
|
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).
|
* LOCAL_ONLY flag is set).
|
||||||
*/
|
*/
|
||||||
#define FOR_EACH_OBJECT_LOCAL_ONLY 0x1
|
#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,
|
struct packed_git *pack,
|
||||||
uint32_t pos,
|
uint32_t pos,
|
||||||
void *data);
|
void *data);
|
||||||
|
30
reachable.c
30
reachable.c
@ -58,7 +58,7 @@ struct recent_data {
|
|||||||
unsigned long timestamp;
|
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,
|
unsigned long mtime,
|
||||||
struct recent_data *data)
|
struct recent_data *data)
|
||||||
{
|
{
|
||||||
@ -75,37 +75,37 @@ static void add_recent_object(const unsigned char *sha1,
|
|||||||
* later processing, and the revision machinery expects
|
* later processing, and the revision machinery expects
|
||||||
* commits and tags to have been parsed.
|
* commits and tags to have been parsed.
|
||||||
*/
|
*/
|
||||||
type = sha1_object_info(sha1, NULL);
|
type = sha1_object_info(oid->hash, NULL);
|
||||||
if (type < 0)
|
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) {
|
switch (type) {
|
||||||
case OBJ_TAG:
|
case OBJ_TAG:
|
||||||
case OBJ_COMMIT:
|
case OBJ_COMMIT:
|
||||||
obj = parse_object_or_die(sha1, NULL);
|
obj = parse_object_or_die(oid->hash, NULL);
|
||||||
break;
|
break;
|
||||||
case OBJ_TREE:
|
case OBJ_TREE:
|
||||||
obj = (struct object *)lookup_tree(sha1);
|
obj = (struct object *)lookup_tree(oid->hash);
|
||||||
break;
|
break;
|
||||||
case OBJ_BLOB:
|
case OBJ_BLOB:
|
||||||
obj = (struct object *)lookup_blob(sha1);
|
obj = (struct object *)lookup_blob(oid->hash);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
die("unknown object type for %s: %s",
|
die("unknown object type for %s: %s",
|
||||||
sha1_to_hex(sha1), typename(type));
|
oid_to_hex(oid), typename(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!obj)
|
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, "");
|
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)
|
const char *path, void *data)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(oid->hash);
|
||||||
|
|
||||||
if (obj && obj->flags & SEEN)
|
if (obj && obj->flags & SEEN)
|
||||||
return 0;
|
return 0;
|
||||||
@ -119,22 +119,22 @@ static int add_recent_loose(const unsigned char *sha1,
|
|||||||
*/
|
*/
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return 0;
|
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;
|
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,
|
struct packed_git *p, uint32_t pos,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(oid->hash);
|
||||||
|
|
||||||
if (obj && obj->flags & SEEN)
|
if (obj && obj->flags & SEEN)
|
||||||
return 0;
|
return 0;
|
||||||
add_recent_object(sha1, p->mtime, data);
|
add_recent_object(oid, p->mtime, data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
sha1_file.c
12
sha1_file.c
@ -3685,15 +3685,15 @@ static int for_each_file_in_obj_subdir(int subdir_nr,
|
|||||||
strbuf_setlen(path, baselen);
|
strbuf_setlen(path, baselen);
|
||||||
strbuf_addf(path, "/%s", de->d_name);
|
strbuf_addf(path, "/%s", de->d_name);
|
||||||
|
|
||||||
if (strlen(de->d_name) == 38) {
|
if (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2) {
|
||||||
char hex[41];
|
char hex[GIT_SHA1_HEXSZ+1];
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
|
|
||||||
snprintf(hex, sizeof(hex), "%02x%s",
|
snprintf(hex, sizeof(hex), "%02x%s",
|
||||||
subdir_nr, de->d_name);
|
subdir_nr, de->d_name);
|
||||||
if (!get_sha1_hex(hex, sha1)) {
|
if (!get_oid_hex(hex, &oid)) {
|
||||||
if (obj_cb) {
|
if (obj_cb) {
|
||||||
r = obj_cb(sha1, path->buf, data);
|
r = obj_cb(&oid, path->buf, data);
|
||||||
if (r)
|
if (r)
|
||||||
break;
|
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",
|
return error("unable to get sha1 of object %u in %s",
|
||||||
i, p->pack_name);
|
i, p->pack_name);
|
||||||
|
|
||||||
r = cb(oid.hash, p, i, data);
|
r = cb(&oid, p, i, data);
|
||||||
if (r)
|
if (r)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user