Skip to content

Commit

Permalink
sha1_file.c: move find_cached_object up so sha1_object_info can use it
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Feb 7, 2011
1 parent cf7b1ca commit c597ba8
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,41 @@ const unsigned char null_sha1[20];

static int git_open_noatime(const char *name, struct packed_git *p);

/*
* This is meant to hold a *small* number of objects that you would
* want read_sha1_file() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
static struct cached_object {
unsigned char sha1[20];
enum object_type type;
void *buf;
unsigned long size;
} *cached_objects;
static int cached_object_nr, cached_object_alloc;

static struct cached_object empty_tree = {
EMPTY_TREE_SHA1_BIN,
OBJ_TREE,
"",
0
};

static struct cached_object *find_cached_object(const unsigned char *sha1)
{
int i;
struct cached_object *co = cached_objects;

for (i = 0; i < cached_object_nr; i++, co++) {
if (!hashcmp(co->sha1, sha1))
return co;
}
if (!hashcmp(sha1, empty_tree.sha1))
return &empty_tree;
return NULL;
}

int safe_create_leading_directories(char *path)
{
char *pos = path + offset_1st_component(path);
Expand Down Expand Up @@ -2033,41 +2068,6 @@ static void *read_packed_sha1(const unsigned char *sha1,
return data;
}

/*
* This is meant to hold a *small* number of objects that you would
* want read_sha1_file() to be able to return, but yet you do not want
* to write them into the object store (e.g. a browse-only
* application).
*/
static struct cached_object {
unsigned char sha1[20];
enum object_type type;
void *buf;
unsigned long size;
} *cached_objects;
static int cached_object_nr, cached_object_alloc;

static struct cached_object empty_tree = {
EMPTY_TREE_SHA1_BIN,
OBJ_TREE,
"",
0
};

static struct cached_object *find_cached_object(const unsigned char *sha1)
{
int i;
struct cached_object *co = cached_objects;

for (i = 0; i < cached_object_nr; i++, co++) {
if (!hashcmp(co->sha1, sha1))
return co;
}
if (!hashcmp(sha1, empty_tree.sha1))
return &empty_tree;
return NULL;
}

int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
unsigned char *sha1)
{
Expand Down

0 comments on commit c597ba8

Please sign in to comment.