summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-08-13 02:33:16 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-08-13 02:33:16 (GMT)
commit647377c4c91064fc5001acddd5357467c0da6ef9 (patch)
treeef5ee52aaf3b2f0b8e070153b47b9248aa32eed5
parenteb4541569d4fdfb1cbdf503cfbf433e63d79b663 (diff)
parent8e27364128b091e76059229d4f009bc7f869fa9f (diff)
downloadgit-647377c4c91064fc5001acddd5357467c0da6ef9.zip
git-647377c4c91064fc5001acddd5357467c0da6ef9.tar.gz
git-647377c4c91064fc5001acddd5357467c0da6ef9.tar.bz2
Merge branch 'jc/pack-objects'
-rw-r--r--builtin-pack-objects.c16
-rw-r--r--builtin-unpack-objects.c2
-rw-r--r--cache.h2
-rw-r--r--sha1_file.c35
4 files changed, 42 insertions, 13 deletions
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 2301cd5..2f99212 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -270,6 +270,22 @@ static unsigned long write_object(struct sha1file *f,
* and we do not need to deltify it.
*/
+ if (!entry->in_pack && !entry->delta) {
+ unsigned char *map;
+ unsigned long mapsize;
+ map = map_sha1_file(entry->sha1, &mapsize);
+ if (map && !legacy_loose_object(map)) {
+ /* We can copy straight into the pack file */
+ sha1write(f, map, mapsize);
+ munmap(map, mapsize);
+ written++;
+ reused++;
+ return mapsize;
+ }
+ if (map)
+ munmap(map, mapsize);
+ }
+
if (! to_reuse) {
buf = read_sha1_file(entry->sha1, type, &size);
if (!buf)
diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c
index 09d264d..63f4b8e 100644
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
@@ -266,6 +266,8 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
int i;
unsigned char sha1[20];
+ git_config(git_default_config);
+
quiet = !isatty(2);
for (i = 1 ; i < argc; i++) {
diff --git a/cache.h b/cache.h
index b2ab208..af77402 100644
--- a/cache.h
+++ b/cache.h
@@ -244,6 +244,8 @@ extern int move_temp_to_file(const char *tmpfile, char *filename);
extern int has_sha1_pack(const unsigned char *sha1);
extern int has_sha1_file(const unsigned char *sha1);
+extern void *map_sha1_file(const unsigned char *sha1, unsigned long *);
+extern int legacy_loose_object(unsigned char *);
extern int has_pack_file(const unsigned char *sha1);
extern int has_pack_index(const unsigned char *sha1);
diff --git a/sha1_file.c b/sha1_file.c
index 3db956d..842a6f3 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -646,8 +646,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long siz
return memcmp(sha1, real_sha1, 20) ? -1 : 0;
}
-static void *map_sha1_file_internal(const unsigned char *sha1,
- unsigned long *size)
+void *map_sha1_file(const unsigned char *sha1, unsigned long *size)
{
struct stat st;
void *map;
@@ -684,10 +683,26 @@ static void *map_sha1_file_internal(const unsigned char *sha1,
return map;
}
+int legacy_loose_object(unsigned char *map)
+{
+ unsigned int word;
+
+ /*
+ * Is it a zlib-compressed buffer? If so, the first byte
+ * must be 0x78 (15-bit window size, deflated), and the
+ * first 16-bit word is evenly divisible by 31
+ */
+ word = (map[0] << 8) + map[1];
+ if (map[0] == 0x78 && !(word % 31))
+ return 1;
+ else
+ return 0;
+}
+
static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz)
{
unsigned char c;
- unsigned int word, bits;
+ unsigned int bits;
unsigned long size;
static const char *typename[8] = {
NULL, /* OBJ_EXT */
@@ -703,13 +718,7 @@ static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned lon
stream->next_out = buffer;
stream->avail_out = bufsiz;
- /*
- * Is it a zlib-compressed buffer? If so, the first byte
- * must be 0x78 (15-bit window size, deflated), and the
- * first 16-bit word is evenly divisible by 31
- */
- word = (map[0] << 8) + map[1];
- if (map[0] == 0x78 && !(word % 31)) {
+ if (legacy_loose_object(map)) {
inflateInit(stream);
return inflate(stream, 0);
}
@@ -1246,7 +1255,7 @@ int sha1_object_info(const unsigned char *sha1, char *type, unsigned long *sizep
z_stream stream;
char hdr[128];
- map = map_sha1_file_internal(sha1, &mapsize);
+ map = map_sha1_file(sha1, &mapsize);
if (!map) {
struct pack_entry e;
@@ -1291,7 +1300,7 @@ void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size
if (find_pack_entry(sha1, &e))
return read_packed_sha1(sha1, type, size);
- map = map_sha1_file_internal(sha1, &mapsize);
+ map = map_sha1_file(sha1, &mapsize);
if (map) {
buf = unpack_sha1_file(map, mapsize, type, size);
munmap(map, mapsize);
@@ -1629,7 +1638,7 @@ int write_sha1_to_fd(int fd, const unsigned char *sha1)
{
int retval;
unsigned long objsize;
- void *buf = map_sha1_file_internal(sha1, &objsize);
+ void *buf = map_sha1_file(sha1, &objsize);
if (buf) {
retval = write_buffer(fd, buf, objsize);