Convert the remaining parts of fast-import.c to use struct object_id.
Convert several instances of get_sha1_hex to parse_oid_hex to avoid
needing to specify constants. Convert other hardcoded values to named
constants. Finally, use the is_empty_tree_oid function instead of a
direct comparison against a fixed string.
Note that the odd computation with GIT_MAX_HEXSZ is due to the insertion
of a slash between every two hex digits in the path, plus one for the
terminating NUL.
Signed-off-by: brian m. carlson
---
fast-import.c | 327 +-
1 file changed, 161 insertions(+), 166 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 052c59d82..6b0117e51 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -391,10 +391,8 @@ static void write_branch_report(FILE *rpt, struct branch
*b)
fputc('\n', rpt);
fprintf(rpt, " tip commit : %s\n", oid_to_hex(>oid));
- fprintf(rpt, " old tree: %s\n",
- oid_to_hex(>branch_tree.versions[0].oid));
- fprintf(rpt, " cur tree: %s\n",
- oid_to_hex(>branch_tree.versions[1].oid));
+ fprintf(rpt, " old tree: %s\n",
oid_to_hex(>branch_tree.versions[0].oid));
+ fprintf(rpt, " cur tree: %s\n",
oid_to_hex(>branch_tree.versions[1].oid));
fprintf(rpt, " commit clock: %" PRIuMAX "\n", b->last_commit);
fputs(" last pack : ", rpt);
@@ -557,7 +555,7 @@ static void alloc_objects(unsigned int cnt)
alloc_count += cnt;
}
-static struct object_entry *new_object(unsigned char *sha1)
+static struct object_entry *new_object(struct object_id *oid)
{
struct object_entry *e;
@@ -565,32 +563,32 @@ static struct object_entry *new_object(unsigned char
*sha1)
alloc_objects(object_entry_alloc);
e = blocks->next_free++;
- hashcpy(e->idx.sha1, sha1);
+ hashcpy(e->idx.sha1, oid->hash);
return e;
}
-static struct object_entry *find_object(unsigned char *sha1)
+static struct object_entry *find_object(struct object_id *oid)
{
- unsigned int h = sha1[0] << 8 | sha1[1];
+ unsigned int h = oid->hash[0] << 8 | oid->hash[1];
struct object_entry *e;
for (e = object_table[h]; e; e = e->next)
- if (!hashcmp(sha1, e->idx.sha1))
+ if (!hashcmp(oid->hash, e->idx.sha1))
return e;
return NULL;
}
-static struct object_entry *insert_object(unsigned char *sha1)
+static struct object_entry *insert_object(struct object_id *oid)
{
- unsigned int h = sha1[0] << 8 | sha1[1];
+ unsigned int h = oid->hash[0] << 8 | oid->hash[1];
struct object_entry *e = object_table[h];
while (e) {
- if (!hashcmp(sha1, e->idx.sha1))
+ if (!hashcmp(oid->hash, e->idx.sha1))
return e;
e = e->next;
}
- e = new_object(sha1);
+ e = new_object(oid);
e->next = object_table[h];
e->idx.offset = 0;
object_table[h] = e;
@@ -1007,17 +1005,17 @@ static void end_packfile(void)
clear_delta_base_cache();
if (object_count) {
struct packed_git *new_p;
- unsigned char cur_pack_sha1[20];
+ struct object_id cur_pack_oid;
char *idx_name;
int i;
struct branch *b;
struct tag *t;
close_pack_windows(pack_data);
- sha1close(pack_file, cur_pack_sha1, 0);
+ sha1close(pack_file, cur_pack_oid.hash, 0);
fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1,
pack_data->pack_name, object_count,
- cur_pack_sha1, pack_size);
+ cur_pack_oid.hash, pack_size);
if (object_count <= unpack_limit) {
if (!loosen_small_pack(pack_data)) {
@@ -1083,13 +1081,13 @@ static int store_object(
enum object_type type,
struct strbuf *dat,
struct last_object *last,
- unsigned char *sha1out,
+ struct object_id *oidout,
uintmax_t mark)
{
void *out, *delta;
struct object_entry *e;
unsigned char hdr[96];
- unsigned char sha1[20];
+ struct object_id oid;
unsigned long hdrlen, deltalen;
git_SHA_CTX c;
git_zstream s;
@@ -1099,17 +1097,17 @@ static int store_object(
git_SHA1_Init();
git_SHA1_Update(, hdr, hdrlen);
git_SHA1_Update(, dat->buf, dat->len);
- git_SHA1_Final(sha1, );
- if (sha1out)
- hashcpy(sha1out, sha1);
+ git_SHA1_Final(oid.hash, );
+ if (oidout)
+ oidcpy(oidout, );
- e = insert_object(sha1);
+ e = insert_object();
if (mark)
insert_mark(mark, e);