@matheusbsbs / matheus-bagliano / commits / 5a18f540a5
Fork 0

Cleanup unpack_entry_gently and friends to use type_name array.

[PATCH 3/5] Cleanup unpack_entry_gently and friends to use type_name array. This change allows combining all of the non-delta entries into a single case, as well as to remove an unnecessary local variable in unpack_entry_gently. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn Pearce committed Aug 26, 2006 at 04:11 UTC 5a18f540a5f8f8ba8b4f8027ed7742bfec85433c
1 file changed +6 -28
sha1_file.c
+6 -28
@@ -996,16 +996,10 @@ void packed_object_info_detail(struct pack_entry *e,
996 }
997 switch (kind) {
998 case OBJ_COMMIT:
999 - strcpy(type, commit_type);
1000 - break;
999 case OBJ_TREE:
1002 - strcpy(type, tree_type);
1003 - break;
1000 case OBJ_BLOB:
1005 - strcpy(type, blob_type);
1006 - break;
1001 case OBJ_TAG:
1008 - strcpy(type, tag_type);
1002 + strcpy(type, type_names[kind]);
1003 break;
1004 default:
1005 die("corrupted pack file %s containing object of kind %d",
@@ -1036,16 +1030,10 @@ static int packed_object_info(struct pack_entry *entry,
1030 unuse_packed_git(p);
1031 return retval;
1032 case OBJ_COMMIT:
1039 - strcpy(type, commit_type);
1040 - break;
1033 case OBJ_TREE:
1042 - strcpy(type, tree_type);
1043 - break;
1034 case OBJ_BLOB:
1045 - strcpy(type, blob_type);
1046 - break;
1035 case OBJ_TAG:
1048 - strcpy(type, tag_type);
1036 + strcpy(type, type_names[kind]);
1037 break;
1038 default:
1039 die("corrupted pack file %s containing object of kind %d",
@@ -1143,33 +1131,23 @@ void *unpack_entry_gently(struct pack_entry *entry,
1131 unsigned long offset, size, left;
1132 unsigned char *pack;
1133 enum object_type kind;
1146 - void *retval;
1134
1135 offset = unpack_object_header(p, entry->offset, &kind, &size);
1136 pack = (unsigned char *) p->pack_base + offset;
1137 left = p->pack_size - offset;
1138 switch (kind) {
1139 case OBJ_DELTA:
1153 - retval = unpack_delta_entry(pack, size, left, type, sizep, p);
1154 - return retval;
1140 + return unpack_delta_entry(pack, size, left, type, sizep, p);
1141 case OBJ_COMMIT:
1156 - strcpy(type, commit_type);
1157 - break;
1142 case OBJ_TREE:
1159 - strcpy(type, tree_type);
1160 - break;
1143 case OBJ_BLOB:
1162 - strcpy(type, blob_type);
1163 - break;
1144 case OBJ_TAG:
1165 - strcpy(type, tag_type);
1166 - break;
1145 + strcpy(type, type_names[kind]);
1146 + *sizep = size;
1147 + return unpack_compressed_entry(pack, size, left);
1148 default:
1149 return NULL;
1150 }
1170 - *sizep = size;
1171 - retval = unpack_compressed_entry(pack, size, left);
1172 - return retval;
1151 }
1152
1153 int num_packed_objects(const struct packed_git *p)