Abstract out accesses to object hash array
There are a few special places where some programs accessed the object hash array directly, which bothered me because I wanted to play with some simple re-organizations. So this patch makes the object hash array data structures all entirely local to object.c, and the few users who wanted to look at it now get to use a function to query how many object index entries there can be, and to actually access the array. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Jun 29, 2006 at 21:38 UTC
fc046a75d539a78e6b2c16534c4078617a69a327
4 files changed
+27
-13
fsck-objects.c
+4
-3
@@ -60,12 +60,13 @@ static int objwarning(struct object *obj, const char *err, ...)
60
61
static void check_connectivity(void)
62
{
63
- int i;
63
+ int i, max;
64
65
/* Look up all the requirements, warn about missing objects.. */
66
- for (i = 0; i < obj_allocs; i++) {
66
+ max = get_max_object_index();
67
+ for (i = 0; i < max; i++) {
68
const struct object_refs *refs;
68
- struct object *obj = objs[i];
69
+ struct object *obj = get_indexed_object(i);
70
71
if (!obj)
72
continue;
name-rev.c
+8
-5
@@ -234,12 +234,15 @@ int main(int argc, char **argv)
234
fwrite(p_start, p - p_start, 1, stdout);
235
}
236
} else if (all) {
237
- int i;
237
+ int i, max;
238
239
- for (i = 0; i < obj_allocs; i++)
240
- if (objs[i])
241
- printf("%s %s\n", sha1_to_hex(objs[i]->sha1),
242
- get_rev_name(objs[i]));
239
+ max = get_max_object_index();
240
+ for (i = 0; i < max; i++) {
241
+ struct object * obj = get_indexed_object(i);
242
+ if (!obj)
243
+ continue;
244
+ printf("%s %s\n", sha1_to_hex(obj->sha1), get_rev_name(obj));
245
+ }
246
} else {
247
int i;
248
for (i = 0; i < revs.nr; i++)
object.c
+12
-3
@@ -5,9 +5,18 @@
5
#include "commit.h"
6
#include "tag.h"
7
8
-struct object **objs;
9
-static int nr_objs;
10
-int obj_allocs;
8
+static struct object **objs;
9
+static int nr_objs, obj_allocs;
10
+
11
+unsigned int get_max_object_index(void)
12
+{
13
+ return obj_allocs;
14
+}
15
+
16
+struct object *get_indexed_object(unsigned int idx)
17
+{
18
+ return objs[idx];
19
+}
20
21
const char *type_names[] = {
22
"none", "blob", "tree", "commit", "bad"
object.h
+3
-2
@@ -40,10 +40,11 @@ struct object {
40
};
41
42
extern int track_object_refs;
43
-extern int obj_allocs;
44
-extern struct object **objs;
43
extern const char *type_names[];
44
45
+extern unsigned int get_max_object_index(void);
46
+extern struct object *get_indexed_object(unsigned int);
47
+
48
static inline const char *typename(unsigned int type)
49
{
50
return type_names[type > TYPE_TAG ? TYPE_BAD : type];