Replace unpack_entry_gently with unpack_entry.
The unpack_entry_gently function currently has only two callers: the delta base resolution in sha1_file.c and the main loop of pack-check.c. Both of these must change to using unpack_entry directly when we implement sliding window mmap logic, so I'm doing it earlier to help break down the change set. This may cause a slight performance decrease for delta base resolution as well as for pack-check.c's verify_packfile(), as the pack use counter will be incremented and decremented for every object that is unpacked. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Dec 23, 2006 at 02:33 UTC
4d703a1a9016cd0a08994ddf7fc2f4739f223112
3 files changed
+14
-23
cache.h
+1
-1
@@ -394,7 +394,7 @@ extern struct packed_git *add_packed_git(char *, int, int);
394
extern int num_packed_objects(const struct packed_git *p);
395
extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*);
396
extern unsigned long find_pack_entry_one(const unsigned char *, struct packed_git *);
397
-extern void *unpack_entry_gently(struct packed_git *, unsigned long, char *, unsigned long *);
397
+extern void *unpack_entry(struct packed_git *, unsigned long, char *, unsigned long *);
398
extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
399
extern void packed_object_info_detail(struct packed_git *, unsigned long, char *, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
400
pack-check.c
+1
-1
@@ -51,7 +51,7 @@ static int verify_packfile(struct packed_git *p)
51
offset = find_pack_entry_one(sha1, p);
52
if (!offset)
53
die("internal error pack-check find-pack-entry-one");
54
- data = unpack_entry_gently(p, offset, type, &size);
54
+ data = unpack_entry(p, offset, type, &size);
55
if (!data) {
56
err = error("cannot unpack %s from %s",
57
sha1_to_hex(sha1), p->pack_name);
sha1_file.c
+12
-21
@@ -1110,7 +1110,7 @@ static void *unpack_delta_entry(struct packed_git *p,
1110
unsigned long result_size, base_size, base_offset;
1111
1112
offset = get_delta_base(p, offset, kind, obj_offset, &base_offset);
1113
- base = unpack_entry_gently(p, base_offset, type, &base_size);
1113
+ base = unpack_entry(p, base_offset, type, &base_size);
1114
if (!base)
1115
die("failed to read delta base object at %lu from %s",
1116
base_offset, p->pack_name);
@@ -1127,43 +1127,34 @@ static void *unpack_delta_entry(struct packed_git *p,
1127
return result;
1128
}
1129
1130
-static void *unpack_entry(struct pack_entry *entry,
1130
+void *unpack_entry(struct packed_git *p, unsigned long offset,
1131
char *type, unsigned long *sizep)
1132
{
1133
- struct packed_git *p = entry->p;
1133
+ unsigned long size, obj_offset = offset;
1134
+ enum object_type kind;
1135
void *retval;
1136
1137
if (use_packed_git(p))
1138
die("cannot map packed file");
1138
- retval = unpack_entry_gently(p, entry->offset, type, sizep);
1139
- unuse_packed_git(p);
1140
- if (!retval)
1141
- die("corrupted pack file %s", p->pack_name);
1142
- return retval;
1143
-}
1144
-
1145
-/* The caller is responsible for use_packed_git()/unuse_packed_git() pair */
1146
-void *unpack_entry_gently(struct packed_git *p, unsigned long offset,
1147
- char *type, unsigned long *sizep)
1148
-{
1149
- unsigned long size, obj_offset = offset;
1150
- enum object_type kind;
1151
-
1139
offset = unpack_object_header(p, offset, &kind, &size);
1140
switch (kind) {
1141
case OBJ_OFS_DELTA:
1142
case OBJ_REF_DELTA:
1156
- return unpack_delta_entry(p, offset, size, kind, obj_offset, type, sizep);
1143
+ retval = unpack_delta_entry(p, offset, size, kind, obj_offset, type, sizep);
1144
+ break;
1145
case OBJ_COMMIT:
1146
case OBJ_TREE:
1147
case OBJ_BLOB:
1148
case OBJ_TAG:
1149
strcpy(type, type_names[kind]);
1150
*sizep = size;
1163
- return unpack_compressed_entry(p, offset, size);
1151
+ retval = unpack_compressed_entry(p, offset, size);
1152
+ break;
1153
default:
1165
- return NULL;
1154
+ die("unknown object type %i in %s", kind, p->pack_name);
1155
}
1156
+ unuse_packed_git(p);
1157
+ return retval;
1158
}
1159
1160
int num_packed_objects(const struct packed_git *p)
@@ -1312,7 +1303,7 @@ static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned lo
1303
error("cannot read sha1_file for %s", sha1_to_hex(sha1));
1304
return NULL;
1305
}
1315
- return unpack_entry(&e, type, size);
1306
+ return unpack_entry(e.p, e.offset, type, size);
1307
}
1308
1309
void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)