aboutsummaryrefslogtreecommitdiffstats
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-28 15:20:10 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-28 15:20:10 -0700
commitfead2836a16829fba427635f92d7df9acf771a55 (patch)
tree0c3d06b55308b094e8486ab8a4d02b381472a834 /sha1_file.c
parentd85a4feeee2cb94ff7060de45a5421f575ddf7b8 (diff)
parent8a498a05c3c6b2f53db669b24f36257ab213eb4c (diff)
downloadgit-fead2836a16829fba427635f92d7df9acf771a55.tar.gz
Merge fighting fsck-cache updates from Junio
It's just easier to let git help out with the merge than it is to try to fix up the diffs.
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 5c6e964a35..25208d2da3 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -185,10 +185,7 @@ char *sha1_file_name(const unsigned char *sha1)
return base;
}
-static struct alternate_object_database {
- char *base;
- char *name;
-} *alt_odb;
+struct alternate_object_database *alt_odb;
/*
* Prepare alternate object database registry.
@@ -206,13 +203,15 @@ static struct alternate_object_database {
* pointed by base fields of the array elements with one xmalloc();
* the string pool immediately follows the array.
*/
-static void prepare_alt_odb(void)
+void prepare_alt_odb(void)
{
int pass, totlen, i;
const char *cp, *last;
char *op = NULL;
const char *alt = gitenv(ALTERNATE_DB_ENVIRONMENT) ? : "";
+ if (alt_odb)
+ return;
/* The first pass counts how large an area to allocate to
* hold the entire alt_odb structure, including array of
* structs and path buffers for them. The second pass fills
@@ -259,8 +258,7 @@ static char *find_sha1_file(const unsigned char *sha1, struct stat *st)
if (!stat(name, st))
return name;
- if (!alt_odb)
- prepare_alt_odb();
+ prepare_alt_odb();
for (i = 0; (name = alt_odb[i].name) != NULL; i++) {
fill_sha1_path(name, sha1);
if (!stat(alt_odb[i].base, st))
@@ -272,15 +270,7 @@ static char *find_sha1_file(const unsigned char *sha1, struct stat *st)
#define PACK_MAX_SZ (1<<26)
static int pack_used_ctr;
static unsigned long pack_mapped;
-static struct packed_git {
- struct packed_git *next;
- unsigned long index_size;
- unsigned long pack_size;
- unsigned int *index_base;
- void *pack_base;
- unsigned int pack_last_used;
- char pack_name[0]; /* something like ".git/objects/pack/xxxxx.pack" */
-} *packed_git;
+struct packed_git *packed_git;
struct pack_entry {
unsigned int offset;
@@ -431,7 +421,7 @@ static void prepare_packed_git_one(char *objdir)
}
}
-static void prepare_packed_git(void)
+void prepare_packed_git(void)
{
int i;
static int run_once = 0;
@@ -440,8 +430,7 @@ static void prepare_packed_git(void)
return;
prepare_packed_git_one(get_object_directory());
- if (!alt_odb)
- prepare_alt_odb();
+ prepare_alt_odb();
for (i = 0; alt_odb[i].base != NULL; i++) {
alt_odb[i].name[0] = 0;
prepare_packed_git_one(alt_odb[i].base);
@@ -842,6 +831,22 @@ static void *unpack_entry(struct pack_entry *entry,
return unpack_non_delta_entry(pack, size, left);
}
+int num_packed_objects(const struct packed_git *p)
+{
+ /* See check_packed_git_idx and pack-objects.c */
+ return (p->index_size - 20 - 20 - 4*256) / 24;
+}
+
+int nth_packed_object_sha1(const struct packed_git *p, int n,
+ unsigned char* sha1)
+{
+ void *index = p->index_base + 256;
+ if (n < 0 || num_packed_objects(p) <= n)
+ return -1;
+ memcpy(sha1, (index + 24 * n + 4), 20);
+ return 0;
+}
+
static int find_pack_entry_1(const unsigned char *sha1,
struct pack_entry *e, struct packed_git *p)
{