{"thread":{"id":"7914","subject":"[PATCH 2/8] git-repack --max-pack-size: code restructuring","startedAt":"2007-04-30T23:19:06Z","lastAt":"2007-04-30T23:19:06Z","messageCount":1,"participants":["Dana How"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"40768","messageId":"4636796A.5070807@gmail.com","threadId":"7914","inReplyTo":null,"subject":"[PATCH 2/8] git-repack --max-pack-size: code restructuring","fromName":"Dana How","fromEmail":"danahow@gmail.com","sentAt":"2007-04-30T23:19:06Z","receivedAt":"2007-04-30T23:19:06Z","isPatch":true,"sender":{"key":"danahow@gmail.com","avatar":null},"body":"\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().  Add forward\ndeclarations and make \"base_name\" file scope again.\n\nSigned-off-by: Dana L. How <danahow@gmail.com>\n---\n builtin-pack-objects.c |   64 ++++++++++++++++++++++++-----------------------\n 1 files changed, 33 insertions(+), 31 deletions(-)\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex ac2c15e..bc45ca6 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -62,6 +62,7 @@ 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@@ -561,7 +562,11 @@ static off_t write_one(struct sha1file *f,\n \treturn offset + size;\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@@ -605,7 +610,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\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 }\n \n static int sha1_sort(const void *_a, const void *_b)\n@@ -1588,8 +1618,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 +1768,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.766.gba60-dirty\n"}]}