{"thread":{"id":"4265","subject":"[PATCH 1/2] Again: remove the artificial restriction tagsize < 8kb","startedAt":"2006-05-23T18:19:04Z","lastAt":"2006-05-23T18:19:04Z","messageCount":1,"participants":["Björn Engelmann"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"20559","messageId":"44735218.7070801@gmx.de","threadId":"4265","inReplyTo":null,"subject":"[PATCH 1/2] Again: remove the artificial restriction tagsize < 8kb","fromName":"Björn Engelmann","fromEmail":"bjengelmann@gmx.de","sentAt":"2006-05-23T18:19:04Z","receivedAt":"2006-05-23T18:19:04Z","isPatch":true,"sender":{"key":"bjengelmann@gmx.de","avatar":null},"body":"\n\n\n\nSigned-off-by: Bj�rn Engelmann <BjEngelmann@gmx.de>\n\n\n---\n\n430953ceafbc722226e2300b489e38938220d435\n cache.h     |    1 +\n mktag.c     |   19 +++++++++----------\n sha1_file.c |   46 ++++++++++++++++++++++++++++++++++++----------\n 3 files changed, 46 insertions(+), 20 deletions(-)\n\n430953ceafbc722226e2300b489e38938220d435\ndiff --git a/cache.h b/cache.h\nindex 4b7a439..19e90eb 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -154,6 +154,7 @@ extern int ce_match_stat(struct cache_en\n extern int ce_modified(struct cache_entry *ce, struct stat *st, int);\n extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);\n extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type);\n+extern int read_pipe(int fd, char** return_buf, unsigned long* return_size);\n extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object);\n extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);\n extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);\ndiff --git a/mktag.c b/mktag.c\nindex 2328878..f1598db 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -45,7 +45,7 @@ static int verify_tag(char *buffer, unsi\n \tunsigned char sha1[20];\n \tconst char *object, *type_line, *tag_line, *tagger_line;\n \n-\tif (size < 64 || size > MAXSIZE-1)\n+\tif (size < 64)\n \t\treturn -1;\n \tbuffer[size] = 0;\n \n@@ -105,8 +105,8 @@ static int verify_tag(char *buffer, unsi\n \n int main(int argc, char **argv)\n {\n-\tunsigned long size;\n-\tchar buffer[MAXSIZE];\n+\tunsigned long size = 4096;\n+\tchar *buffer = malloc(size);\n \tunsigned char result_sha1[20];\n \n \tif (argc != 1)\n@@ -114,13 +114,9 @@ int main(int argc, char **argv)\n \n \tsetup_git_directory();\n \n-\t// Read the signature\n-\tsize = 0;\n-\tfor (;;) {\n-\t\tint ret = xread(0, buffer + size, MAXSIZE - size);\n-\t\tif (ret <= 0)\n-\t\t\tbreak;\n-\t\tsize += ret;\n+\tif (read_pipe(0, &buffer, &size)) {\n+\t\tfree(buffer);\n+\t\tdie(\"could not read from stdin\");\n \t}\n \n \t// Verify it for some basic sanity: it needs to start with \"object <sha1>\\ntype\\ntagger \"\n@@ -129,6 +125,9 @@ int main(int argc, char **argv)\n \n \tif (write_sha1_file(buffer, size, tag_type, result_sha1) < 0)\n \t\tdie(\"unable to write tag file\");\n+\n+\tfree(buffer);\n+\n \tprintf(\"%s\\n\", sha1_to_hex(result_sha1));\n \treturn 0;\n }\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 2230010..e444d9d 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1645,16 +1645,24 @@ int has_sha1_file(const unsigned char *s\n \treturn find_sha1_file(sha1, &st) ? 1 : 0;\n }\n \n-int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)\n+/*\n+ * reads from fd as long as possible into a supplied buffer of size bytes.\n+ * If neccessary the buffer's size is increased using realloc()\n+ *\n+ * returns 0 if anything went fine and -1 otherwise\n+ *\n+ * NOTE: both buf and size may change, but even when -1 is returned\n+ * you still have to free() it yourself.\n+ */\n+int read_pipe(int fd, char** return_buf, unsigned long* return_size)\n {\n-\tunsigned long size = 4096;\n-\tchar *buf = malloc(size);\n-\tint iret, ret;\n+\tchar* buf = *return_buf;\n+\tunsigned long size = *return_size;\n+\tint iret;\n \tunsigned long off = 0;\n-\tunsigned char hdr[50];\n-\tint hdrlen;\n+\n \tdo {\n-\t\tiret = read(fd, buf + off, size - off);\n+\t\tiret = xread(fd, buf + off, size - off);\n \t\tif (iret > 0) {\n \t\t\toff += iret;\n \t\t\tif (off == size) {\n@@ -1663,16 +1671,34 @@ int index_pipe(unsigned char *sha1, int \n \t\t\t}\n \t\t}\n \t} while (iret > 0);\n-\tif (iret < 0) {\n+\n+\t*return_buf = buf;\n+\t*return_size = off;\n+\n+\tif (iret < 0)\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)\n+{\n+\tunsigned long size = 4096;\n+\tchar *buf = malloc(size);\n+\tint ret;\n+\tunsigned char hdr[50];\n+\tint hdrlen;\n+\n+\tif (read_pipe(fd, &buf, &size)) {\n \t\tfree(buf);\n \t\treturn -1;\n \t}\n+\n \tif (!type)\n \t\ttype = blob_type;\n \tif (write_object)\n-\t\tret = write_sha1_file(buf, off, type, sha1);\n+\t\tret = write_sha1_file(buf, size, type, sha1);\n \telse {\n-\t\twrite_sha1_file_prepare(buf, off, type, sha1, hdr, &hdrlen);\n+\t\twrite_sha1_file_prepare(buf, size, type, sha1, hdr, &hdrlen);\n \t\tret = 0;\n \t}\n \tfree(buf);\n-- \n1.3.3.g4309-dirty\n\n"}]}