Skip to content

Commit fc046a7

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
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>
1 parent 8dbbd14 commit fc046a7

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

fsck-objects.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ static int objwarning(struct object *obj, const char *err, ...)
6060

6161
static void check_connectivity(void)
6262
{
63-
int i;
63+
int i, max;
6464

6565
/* 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++) {
6768
const struct object_refs *refs;
68-
struct object *obj = objs[i];
69+
struct object *obj = get_indexed_object(i);
6970

7071
if (!obj)
7172
continue;

name-rev.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,15 @@ int main(int argc, char **argv)
234234
fwrite(p_start, p - p_start, 1, stdout);
235235
}
236236
} else if (all) {
237-
int i;
237+
int i, max;
238238

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+
}
243246
} else {
244247
int i;
245248
for (i = 0; i < revs.nr; i++)

object.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@
55
#include "commit.h"
66
#include "tag.h"
77

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+
}
1120

1221
const char *type_names[] = {
1322
"none", "blob", "tree", "commit", "bad"

object.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ struct object {
4040
};
4141

4242
extern int track_object_refs;
43-
extern int obj_allocs;
44-
extern struct object **objs;
4543
extern const char *type_names[];
4644

45+
extern unsigned int get_max_object_index(void);
46+
extern struct object *get_indexed_object(unsigned int);
47+
4748
static inline const char *typename(unsigned int type)
4849
{
4950
return type_names[type > TYPE_TAG ? TYPE_BAD : type];

0 commit comments

Comments
 (0)