This series adds support for sending individual objects from packs in in git-ssh-push and removes map_sha1_file.
-Daniel *This .sig left intentionally blank*
threads / patch / 1195
Subject: [PATCH 0/2] Handing sending objects from packs
This series adds support for sending individual objects from packs in in git-ssh-push and removes map_sha1_file.
-Daniel *This .sig left intentionally blank*
[PATCH 1/2] write_sha1_to_fd()
Add write_sha1_to_fd(), which writes an object to a file descriptor. This includes support for unpacking it and recompressing it.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> --- commit 264ff9f3dcde5553728b34fa08e04643b2b55946 tree 353fe33ae9c7265d7b685bca864d657e3efe2849 parent c3eb461762b1d65e424fc4ede6a1d4f3e0a679f7 author Daniel Barkalow <barkalow@iabervon.org> 1121033477 -0400 committer Daniel Barkalow <barkalow@silva-tulga.(none)> 1121033477 -0400
Index: cache.h =================================================================== --- 545ef8191b517b7f9e4ea558edaf526038ed1895/cache.h (mode:100644 sha1:719a77dfabb24e58abd21b7f3a4b846a114e000a) +++ 353fe33ae9c7265d7b685bca864d657e3efe2849/cache.h (mode:100644 sha1:38dac6d6a413f1c788e5331ef4741fc15d72d9bd) @@ -187,6 +187,7 @@ extern int read_tree(void *buffer, unsigned long size, int stage); extern int write_sha1_from_fd(const unsigned char *sha1, int fd); +extern int write_sha1_to_fd(int fd, const unsigned char *sha1); extern int has_sha1_pack(const unsigned char *sha1); extern int has_sha1_file(const unsigned char *sha1); Index: sha1_file.c =================================================================== --- 545ef8191b517b7f9e4ea558edaf526038ed1895/sha1_file.c (mode:100644 sha1:27136fdba0fbf2dd943f2634cb49660cdbf95ec4) +++ 353fe33ae9c7265d7b685bca864d657e3efe2849/sha1_file.c (mode:100644 sha1:08560b2c7a6dff400a46160501c247081f9bb4c7) @@ -1326,6 +1326,65 @@ return 0; } +int write_sha1_to_fd(int fd, const unsigned char *sha1) +{ + ssize_t size; + unsigned long objsize; + int posn = 0; + char *buf = map_sha1_file_internal(sha1, &objsize, 0); + z_stream stream; + if (!buf) { + unsigned char *unpacked; + unsigned long len; + char type[20]; + char hdr[50]; + int hdrlen; + // need to unpack and recompress it by itself + unpacked = read_packed_sha1(sha1, type, &len); + + hdrlen = sprintf(hdr, "%s %lu", type, len) + 1; + + /* Set it up */ + memset(&stream, 0, sizeof(stream)); + deflateInit(&stream, Z_BEST_COMPRESSION); + size = deflateBound(&stream, len + hdrlen); + buf = xmalloc(size); + + /* Compress it */ + stream.next_out = buf; + stream.avail_out = size; + + /* First header.. */ + stream.next_in = hdr; + stream.avail_in = hdrlen; + while (deflate(&stream, 0) == Z_OK) + /* nothing */; + + /* Then the data itself.. */ + stream.next_in = unpacked; + stream.avail_in = len; + while (deflate(&stream, Z_FINISH) == Z_OK) + /* nothing */; + deflateEnd(&stream); + + objsize = stream.total_out; + } + + do { + size = write(fd, buf + posn, objsize - posn); + if (size <= 0) { + if (!size) { + fprintf(stderr, "write closed"); + } else { + perror("write "); + } + return -1; + } + posn += size; + } while (posn < objsize); + return 0; +} + int write_sha1_from_fd(const unsigned char *sha1, int fd) { char *filename = sha1_file_name(sha1); Index: ssh-push.c =================================================================== --- 545ef8191b517b7f9e4ea558edaf526038ed1895/ssh-push.c (mode:100644 sha1:090d6f9f8fbde2d736ac5bf563415b0fa402b5aa) +++ 353fe33ae9c7265d7b685bca864d657e3efe2849/ssh-push.c (mode:100644 sha1:aac70af514e0dc5507fa4997ebad54352c973215) @@ -7,13 +7,13 @@ static unsigned char local_version = 1; static unsigned char remote_version = 0; +static int verbose = 0; + static int serve_object(int fd_in, int fd_out) { ssize_t size; - int posn = 0; unsigned char sha1[20]; - unsigned long objsize; - void *buf; signed char remote; + int posn = 0; do { size = read(fd_in, sha1 + posn, 20 - posn); if (size < 0) { @@ -25,12 +25,12 @@ posn += size; } while (posn < 20); - /* fprintf(stderr, "Serving %s\n", sha1_to_hex(sha1)); */ + if (verbose) + fprintf(stderr, "Serving %s\n", sha1_to_hex(sha1)); + remote = 0; - buf = map_sha1_file(sha1, &objsize); - - if (!buf) { + if (!has_sha1_file(sha1)) { fprintf(stderr, "git-ssh-push: could not find %s\n", sha1_to_hex(sha1)); remote = -1; @@ -41,20 +41,7 @@ if (remote < 0) return 0; - posn = 0; - do { - size = write(fd_out, buf + posn, objsize - posn); - if (size <= 0) { - if (!size) { - fprintf(stderr, "git-ssh-push: write closed"); - } else { - perror("git-ssh-push: write "); - } - return -1; - } - posn += size; - } while (posn < objsize); - return 0; + return write_sha1_to_fd(fd_out, sha1); } static int serve_version(int fd_in, int fd_out) @@ -76,6 +63,10 @@ return -1; posn++; } while (ref[posn - 1]); + + if (verbose) + fprintf(stderr, "Serving %s\n", ref); + if (get_ref_sha1(ref, sha1)) remote = -1; write(fd_out, &remote, 1);
[PATCH 2/2] Remove map_sha1_file
Remove map_sha1_file(), now unused.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> --- commit c21a02262f770a25b005378e06354e582aa1bfd8 tree 7ac9fabe666f00f37572e7b349fdb859bf8a6491 parent 264ff9f3dcde5553728b34fa08e04643b2b55946 author Daniel Barkalow <barkalow@iabervon.org> 1121033599 -0400 committer Daniel Barkalow <barkalow@silva-tulga.(none)> 1121033599 -0400
Index: cache.h =================================================================== --- 353fe33ae9c7265d7b685bca864d657e3efe2849/cache.h (mode:100644 sha1:38dac6d6a413f1c788e5331ef4741fc15d72d9bd) +++ 7ac9fabe666f00f37572e7b349fdb859bf8a6491/cache.h (mode:100644 sha1:11ba95c8aa9202fa3b1a3cbc07bc976641cd1908) @@ -167,7 +167,6 @@ int safe_create_leading_directories(char *path); /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ -extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size); extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size); extern int parse_sha1_header(char *hdr, char *type, unsigned long *sizep); extern int sha1_object_info(const unsigned char *, char *, unsigned long *); Index: sha1_file.c =================================================================== --- 353fe33ae9c7265d7b685bca864d657e3efe2849/sha1_file.c (mode:100644 sha1:08560b2c7a6dff400a46160501c247081f9bb4c7) +++ 7ac9fabe666f00f37572e7b349fdb859bf8a6491/sha1_file.c (mode:100644 sha1:e082f2e6cb985caca11979311c291aa51d6c37fd) @@ -578,8 +578,7 @@ } static void *map_sha1_file_internal(const unsigned char *sha1, - unsigned long *size, - int say_error) + unsigned long *size) { struct stat st; void *map; @@ -587,8 +586,6 @@ char *filename = find_sha1_file(sha1, &st); if (!filename) { - if (say_error) - error("cannot map sha1 file %s", sha1_to_hex(sha1)); return NULL; } @@ -602,8 +599,6 @@ break; /* Fallthrough */ case 0: - if (say_error) - perror(filename); return NULL; } @@ -620,11 +615,6 @@ return map; } -void *map_sha1_file(const unsigned char *sha1, unsigned long *size) -{ - return map_sha1_file_internal(sha1, size, 1); -} - int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size) { /* Get the data stream */ @@ -1112,7 +1102,7 @@ z_stream stream; char hdr[128]; - map = map_sha1_file_internal(sha1, &mapsize, 0); + map = map_sha1_file_internal(sha1, &mapsize); if (!map) { struct pack_entry e; @@ -1151,7 +1141,7 @@ unsigned long mapsize; void *map, *buf; - map = map_sha1_file_internal(sha1, &mapsize, 0); + map = map_sha1_file_internal(sha1, &mapsize); if (map) { buf = unpack_sha1_file(map, mapsize, type, size); munmap(map, mapsize); @@ -1331,7 +1321,7 @@ ssize_t size; unsigned long objsize; int posn = 0; - char *buf = map_sha1_file_internal(sha1, &objsize, 0); + char *buf = map_sha1_file_internal(sha1, &objsize); z_stream stream; if (!buf) { unsigned char *unpacked;