{"thread":{"id":"1195","subject":"[PATCH 0/2] Handing sending objects from packs","startedAt":"2005-07-10T22:22:07Z","lastAt":"2005-07-10T22:27:02Z","messageCount":3,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"5916","messageId":"Pine.LNX.4.21.0507101811390.30848-100000@iabervon.org","threadId":"1195","inReplyTo":null,"subject":"[PATCH 0/2] Handing sending objects from packs","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-07-10T22:22:07Z","receivedAt":"2005-07-10T22:22:07Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This series adds support for sending individual objects from packs in in\ngit-ssh-push and removes map_sha1_file.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"5918","messageId":"Pine.LNX.4.21.0507101822210.30848-100000@iabervon.org","threadId":"1195","inReplyTo":"Pine.LNX.4.21.0507101811390.30848-100000@iabervon.org","subject":"[PATCH 1/2] write_sha1_to_fd()","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-07-10T22:25:38Z","receivedAt":"2005-07-10T22:25:38Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"Add write_sha1_to_fd(), which writes an object to a file descriptor. This\nincludes support for unpacking it and recompressing it.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\ncommit 264ff9f3dcde5553728b34fa08e04643b2b55946\ntree 353fe33ae9c7265d7b685bca864d657e3efe2849\nparent c3eb461762b1d65e424fc4ede6a1d4f3e0a679f7\nauthor Daniel Barkalow <barkalow@iabervon.org> 1121033477 -0400\ncommitter Daniel Barkalow <barkalow@silva-tulga.(none)> 1121033477 -0400\n\nIndex: cache.h\n===================================================================\n--- 545ef8191b517b7f9e4ea558edaf526038ed1895/cache.h  (mode:100644 sha1:719a77dfabb24e58abd21b7f3a4b846a114e000a)\n+++ 353fe33ae9c7265d7b685bca864d657e3efe2849/cache.h  (mode:100644 sha1:38dac6d6a413f1c788e5331ef4741fc15d72d9bd)\n@@ -187,6 +187,7 @@\n extern int read_tree(void *buffer, unsigned long size, int stage);\n \n extern int write_sha1_from_fd(const unsigned char *sha1, int fd);\n+extern int write_sha1_to_fd(int fd, const unsigned char *sha1);\n \n extern int has_sha1_pack(const unsigned char *sha1);\n extern int has_sha1_file(const unsigned char *sha1);\nIndex: sha1_file.c\n===================================================================\n--- 545ef8191b517b7f9e4ea558edaf526038ed1895/sha1_file.c  (mode:100644 sha1:27136fdba0fbf2dd943f2634cb49660cdbf95ec4)\n+++ 353fe33ae9c7265d7b685bca864d657e3efe2849/sha1_file.c  (mode:100644 sha1:08560b2c7a6dff400a46160501c247081f9bb4c7)\n@@ -1326,6 +1326,65 @@\n \treturn 0;\n }\n \n+int write_sha1_to_fd(int fd, const unsigned char *sha1)\n+{\n+\tssize_t size;\n+\tunsigned long objsize;\n+\tint posn = 0;\n+\tchar *buf = map_sha1_file_internal(sha1, &objsize, 0);\n+\tz_stream stream;\n+\tif (!buf) {\n+\t\tunsigned char *unpacked;\n+\t\tunsigned long len;\n+\t\tchar type[20];\n+\t\tchar hdr[50];\n+\t\tint hdrlen;\n+\t\t// need to unpack and recompress it by itself\n+\t\tunpacked = read_packed_sha1(sha1, type, &len);\n+\n+\t\thdrlen = sprintf(hdr, \"%s %lu\", type, len) + 1;\n+\n+\t\t/* Set it up */\n+\t\tmemset(&stream, 0, sizeof(stream));\n+\t\tdeflateInit(&stream, Z_BEST_COMPRESSION);\n+\t\tsize = deflateBound(&stream, len + hdrlen);\n+\t\tbuf = xmalloc(size);\n+\n+\t\t/* Compress it */\n+\t\tstream.next_out = buf;\n+\t\tstream.avail_out = size;\n+\t\t\n+\t\t/* First header.. */\n+\t\tstream.next_in = hdr;\n+\t\tstream.avail_in = hdrlen;\n+\t\twhile (deflate(&stream, 0) == Z_OK)\n+\t\t\t/* nothing */;\n+\n+\t\t/* Then the data itself.. */\n+\t\tstream.next_in = unpacked;\n+\t\tstream.avail_in = len;\n+\t\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n+\t\t\t/* nothing */;\n+\t\tdeflateEnd(&stream);\n+\t\t\n+\t\tobjsize = stream.total_out;\n+\t}\n+\n+\tdo {\n+\t\tsize = write(fd, buf + posn, objsize - posn);\n+\t\tif (size <= 0) {\n+\t\t\tif (!size) {\n+\t\t\t\tfprintf(stderr, \"write closed\");\n+\t\t\t} else {\n+\t\t\t\tperror(\"write \");\n+\t\t\t}\n+\t\t\treturn -1;\n+\t\t}\n+\t\tposn += size;\n+\t} while (posn < objsize);\n+\treturn 0;\n+}\n+\n int write_sha1_from_fd(const unsigned char *sha1, int fd)\n {\n \tchar *filename = sha1_file_name(sha1);\nIndex: ssh-push.c\n===================================================================\n--- 545ef8191b517b7f9e4ea558edaf526038ed1895/ssh-push.c  (mode:100644 sha1:090d6f9f8fbde2d736ac5bf563415b0fa402b5aa)\n+++ 353fe33ae9c7265d7b685bca864d657e3efe2849/ssh-push.c  (mode:100644 sha1:aac70af514e0dc5507fa4997ebad54352c973215)\n@@ -7,13 +7,13 @@\n static unsigned char local_version = 1;\n static unsigned char remote_version = 0;\n \n+static int verbose = 0;\n+\n static int serve_object(int fd_in, int fd_out) {\n \tssize_t size;\n-\tint posn = 0;\n \tunsigned char sha1[20];\n-\tunsigned long objsize;\n-\tvoid *buf;\n \tsigned char remote;\n+\tint posn = 0;\n \tdo {\n \t\tsize = read(fd_in, sha1 + posn, 20 - posn);\n \t\tif (size < 0) {\n@@ -25,12 +25,12 @@\n \t\tposn += size;\n \t} while (posn < 20);\n \t\n-\t/* fprintf(stderr, \"Serving %s\\n\", sha1_to_hex(sha1)); */\n+\tif (verbose)\n+\t\tfprintf(stderr, \"Serving %s\\n\", sha1_to_hex(sha1));\n+\n \tremote = 0;\n \t\n-\tbuf = map_sha1_file(sha1, &objsize);\n-\t\n-\tif (!buf) {\n+\tif (!has_sha1_file(sha1)) {\n \t\tfprintf(stderr, \"git-ssh-push: could not find %s\\n\", \n \t\t\tsha1_to_hex(sha1));\n \t\tremote = -1;\n@@ -41,20 +41,7 @@\n \tif (remote < 0)\n \t\treturn 0;\n \t\n-\tposn = 0;\n-\tdo {\n-\t\tsize = write(fd_out, buf + posn, objsize - posn);\n-\t\tif (size <= 0) {\n-\t\t\tif (!size) {\n-\t\t\t\tfprintf(stderr, \"git-ssh-push: write closed\");\n-\t\t\t} else {\n-\t\t\t\tperror(\"git-ssh-push: write \");\n-\t\t\t}\n-\t\t\treturn -1;\n-\t\t}\n-\t\tposn += size;\n-\t} while (posn < objsize);\n-\treturn 0;\n+\treturn write_sha1_to_fd(fd_out, sha1);\n }\n \n static int serve_version(int fd_in, int fd_out)\n@@ -76,6 +63,10 @@\n \t\t\treturn -1;\n \t\tposn++;\n \t} while (ref[posn - 1]);\n+\n+\tif (verbose)\n+\t\tfprintf(stderr, \"Serving %s\\n\", ref);\n+\n \tif (get_ref_sha1(ref, sha1))\n \t\tremote = -1;\n \twrite(fd_out, &remote, 1);\n"},{"id":"5917","messageId":"Pine.LNX.4.21.0507101825420.30848-100000@iabervon.org","threadId":"1195","inReplyTo":"Pine.LNX.4.21.0507101811390.30848-100000@iabervon.org","subject":"[PATCH 2/2] Remove map_sha1_file","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-07-10T22:27:02Z","receivedAt":"2005-07-10T22:27:02Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"Remove map_sha1_file(), now unused.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\ncommit c21a02262f770a25b005378e06354e582aa1bfd8\ntree 7ac9fabe666f00f37572e7b349fdb859bf8a6491\nparent 264ff9f3dcde5553728b34fa08e04643b2b55946\nauthor Daniel Barkalow <barkalow@iabervon.org> 1121033599 -0400\ncommitter Daniel Barkalow <barkalow@silva-tulga.(none)> 1121033599 -0400\n\nIndex: cache.h\n===================================================================\n--- 353fe33ae9c7265d7b685bca864d657e3efe2849/cache.h  (mode:100644 sha1:38dac6d6a413f1c788e5331ef4741fc15d72d9bd)\n+++ 7ac9fabe666f00f37572e7b349fdb859bf8a6491/cache.h  (mode:100644 sha1:11ba95c8aa9202fa3b1a3cbc07bc976641cd1908)\n@@ -167,7 +167,6 @@\n int safe_create_leading_directories(char *path);\n \n /* Read and unpack a sha1 file into memory, write memory to a sha1 file */\n-extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size);\n extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size);\n extern int parse_sha1_header(char *hdr, char *type, unsigned long *sizep);\n extern int sha1_object_info(const unsigned char *, char *, unsigned long *);\nIndex: sha1_file.c\n===================================================================\n--- 353fe33ae9c7265d7b685bca864d657e3efe2849/sha1_file.c  (mode:100644 sha1:08560b2c7a6dff400a46160501c247081f9bb4c7)\n+++ 7ac9fabe666f00f37572e7b349fdb859bf8a6491/sha1_file.c  (mode:100644 sha1:e082f2e6cb985caca11979311c291aa51d6c37fd)\n@@ -578,8 +578,7 @@\n }\n \n static void *map_sha1_file_internal(const unsigned char *sha1,\n-\t\t\t\t    unsigned long *size,\n-\t\t\t\t    int say_error)\n+\t\t\t\t    unsigned long *size)\n {\n \tstruct stat st;\n \tvoid *map;\n@@ -587,8 +586,6 @@\n \tchar *filename = find_sha1_file(sha1, &st);\n \n \tif (!filename) {\n-\t\tif (say_error)\n-\t\t\terror(\"cannot map sha1 file %s\", sha1_to_hex(sha1));\n \t\treturn NULL;\n \t}\n \n@@ -602,8 +599,6 @@\n \t\t\t\tbreak;\n \t\t/* Fallthrough */\n \t\tcase 0:\n-\t\t\tif (say_error)\n-\t\t\t\tperror(filename);\n \t\t\treturn NULL;\n \t\t}\n \n@@ -620,11 +615,6 @@\n \treturn map;\n }\n \n-void *map_sha1_file(const unsigned char *sha1, unsigned long *size)\n-{\n-\treturn map_sha1_file_internal(sha1, size, 1);\n-}\n-\n int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size)\n {\n \t/* Get the data stream */\n@@ -1112,7 +1102,7 @@\n \tz_stream stream;\n \tchar hdr[128];\n \n-\tmap = map_sha1_file_internal(sha1, &mapsize, 0);\n+\tmap = map_sha1_file_internal(sha1, &mapsize);\n \tif (!map) {\n \t\tstruct pack_entry e;\n \n@@ -1151,7 +1141,7 @@\n \tunsigned long mapsize;\n \tvoid *map, *buf;\n \n-\tmap = map_sha1_file_internal(sha1, &mapsize, 0);\n+\tmap = map_sha1_file_internal(sha1, &mapsize);\n \tif (map) {\n \t\tbuf = unpack_sha1_file(map, mapsize, type, size);\n \t\tmunmap(map, mapsize);\n@@ -1331,7 +1321,7 @@\n \tssize_t size;\n \tunsigned long objsize;\n \tint posn = 0;\n-\tchar *buf = map_sha1_file_internal(sha1, &objsize, 0);\n+\tchar *buf = map_sha1_file_internal(sha1, &objsize);\n \tz_stream stream;\n \tif (!buf) {\n \t\tunsigned char *unpacked;\n"}]}