{"thread":{"id":"8039","subject":"[PATCH 1/4] git-repack --max-pack-size: new file statics and code restructuring","startedAt":"2007-05-08T20:02:13Z","lastAt":"2007-05-08T20:02:13Z","messageCount":1,"participants":["Dana How"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"41488","messageId":"4640D745.4060604@gmail.com","threadId":"8039","inReplyTo":null,"subject":"[PATCH 1/4] git-repack --max-pack-size: new file statics and code restructuring","fromName":"Dana How","fromEmail":"danahow@gmail.com","sentAt":"2007-05-08T20:02:13Z","receivedAt":"2007-05-08T20:02:13Z","isPatch":true,"sender":{"key":"danahow@gmail.com","avatar":null},"body":"\nAdd \"pack_size_limit\", the limit specified by --max-pack-size,\n\"written_list\", the list of objects written to the current pack,\nand \"nr_written\", the number of objects in written_list.\nPut \"base_name\" at file scope again and add forward declarations.\nMove write_index_file() call from cnd_pack_objects() to\nwrite_pack_file() since only the latter will know how\nmany times to call write_index_file().\n\nSigned-off-by: Dana L. How <danahow@gmail.com>\n---\n builtin-pack-objects.c |   68 +++++++++++++++++++++++++----------------------\n 1 files changed, 36 insertions(+), 32 deletions(-)\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 7bff8ea..d832e2d 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -52,7 +52,8 @@ struct object_entry {\n  * nice \"minimum seek\" order.\n  */\n static struct object_entry *objects;\n-static uint32_t nr_objects, nr_alloc, nr_result;\n+static struct object_entry **written_list;\n+static uint32_t nr_objects, nr_alloc, nr_result, nr_written;\n \n static int non_empty;\n static int no_reuse_delta;\n@@ -61,9 +62,11 @@ static int incremental;\n static int allow_ofs_delta;\n static const char *pack_tmp_name, *idx_tmp_name;\n static char tmpname[PATH_MAX];\n+static const char *base_name;\n static unsigned char pack_file_sha1[20];\n static int progress = 1;\n static int window = 10;\n+static uint32_t pack_size_limit;\n static int pack_to_stdout;\n static int num_preferred_base;\n static struct progress progress_state;\n@@ -565,7 +568,11 @@ static int open_object_dir_tmp(const char *path)\n     return mkstemp(tmpname);\n }\n \n-static off_t write_pack_file(void)\n+/* forward declarations for write_pack_file */\n+static void write_index_file(off_t last_obj_offset, unsigned char *sha1);\n+static int adjust_perm(const char *path, mode_t mode);\n+\n+static void write_pack_file(void)\n {\n \tuint32_t i;\n \tstruct sha1file *f;\n@@ -607,7 +614,32 @@ static off_t write_pack_file(void)\n \t\tdie(\"wrote %u objects while expecting %u\", written, nr_result);\n \tsha1close(f, pack_file_sha1, 1);\n \n-\treturn last_obj_offset;\n+\tif (!pack_to_stdout) {\n+\t\t\tunsigned char object_list_sha1[20];\n+\t\t\tmode_t mode = umask(0);\n+\n+\t\t\tumask(mode);\n+\t\t\tmode = 0444 & ~mode;\n+\n+\t\t\twrite_index_file(last_obj_offset, object_list_sha1);\n+\t\t\tsnprintf(tmpname, sizeof(tmpname), \"%s-%s.pack\",\n+\t\t\t\t base_name, sha1_to_hex(object_list_sha1));\n+\t\t\tif (adjust_perm(pack_tmp_name, mode))\n+\t\t\t\tdie(\"unable to make temporary pack file readable: %s\",\n+\t\t\t\t    strerror(errno));\n+\t\t\tif (rename(pack_tmp_name, tmpname))\n+\t\t\t\tdie(\"unable to rename temporary pack file: %s\",\n+\t\t\t\t    strerror(errno));\n+\t\t\tsnprintf(tmpname, sizeof(tmpname), \"%s-%s.idx\",\n+\t\t\t\t base_name, sha1_to_hex(object_list_sha1));\n+\t\t\tif (adjust_perm(idx_tmp_name, mode))\n+\t\t\t\tdie(\"unable to make temporary index file readable: %s\",\n+\t\t\t\t    strerror(errno));\n+\t\t\tif (rename(idx_tmp_name, tmpname))\n+\t\t\t\tdie(\"unable to rename temporary index file: %s\",\n+\t\t\t\t    strerror(errno));\n+\t\t\tputs(sha1_to_hex(object_list_sha1));\n+\t}\n }\n \n static int sha1_sort(const void *_a, const void *_b)\n@@ -1588,8 +1620,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \tint use_internal_rev_list = 0;\n \tint thin = 0;\n \tuint32_t i;\n-\toff_t last_obj_offset;\n-\tconst char *base_name = NULL;\n \tconst char **rp_av;\n \tint rp_ac_alloc = 64;\n \tint rp_ac;\n@@ -1740,33 +1770,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\tfprintf(stderr, \"Result has %u objects.\\n\", nr_result);\n \tif (nr_result)\n \t\tprepare_pack(window, depth);\n-\tlast_obj_offset = write_pack_file();\n-\tif (!pack_to_stdout) {\n-\t\tunsigned char object_list_sha1[20];\n-\t\tmode_t mode = umask(0);\n-\n-\t\tumask(mode);\n-\t\tmode = 0444 & ~mode;\n-\n-\t\twrite_index_file(last_obj_offset, object_list_sha1);\n-\t\tsnprintf(tmpname, sizeof(tmpname), \"%s-%s.pack\",\n-\t\t\t base_name, sha1_to_hex(object_list_sha1));\n-\t\tif (adjust_perm(pack_tmp_name, mode))\n-\t\t\tdie(\"unable to make temporary pack file readable: %s\",\n-\t\t\t    strerror(errno));\n-\t\tif (rename(pack_tmp_name, tmpname))\n-\t\t\tdie(\"unable to rename temporary pack file: %s\",\n-\t\t\t    strerror(errno));\n-\t\tsnprintf(tmpname, sizeof(tmpname), \"%s-%s.idx\",\n-\t\t\t base_name, sha1_to_hex(object_list_sha1));\n-\t\tif (adjust_perm(idx_tmp_name, mode))\n-\t\t\tdie(\"unable to make temporary index file readable: %s\",\n-\t\t\t    strerror(errno));\n-\t\tif (rename(idx_tmp_name, tmpname))\n-\t\t\tdie(\"unable to rename temporary index file: %s\",\n-\t\t\t    strerror(errno));\n-\t\tputs(sha1_to_hex(object_list_sha1));\n-\t}\n+\twrite_pack_file();\n \tif (progress)\n \t\tfprintf(stderr, \"Total %u (delta %u), reused %u (delta %u)\\n\",\n \t\t\twritten, written_delta, reused, reused_delta);\n-- \n1.5.2.rc0.787.g0014\n"}]}