git-repack --max-pack-size: new file statics and code restructuring
Add "pack_size_limit", the limit specified by --max-pack-size, "written_list", the list of objects written to the current pack, and "nr_written", the number of objects in written_list. Put "base_name" at file scope again and add forward declarations. Move write_index_file() call from cnd_pack_objects() to write_pack_file() since only the latter will know how many times to call write_index_file(). Signed-off-by: Dana L. How <danahow@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Dana L. How committed
May 13, 2007 at 11:34 UTC
d01fb92f8d27cf8f0a843f4e9c0f8f022856b34d
1 file changed
+36
-32
builtin-pack-objects.c
+36
-32
@@ -52,7 +52,8 @@ struct object_entry {
52
* nice "minimum seek" order.
53
*/
54
static struct object_entry *objects;
55
-static uint32_t nr_objects, nr_alloc, nr_result;
55
+static struct object_entry **written_list;
56
+static uint32_t nr_objects, nr_alloc, nr_result, nr_written;
57
58
static int non_empty;
59
static int no_reuse_delta, no_reuse_object;
@@ -61,9 +62,11 @@ static int incremental;
62
static int allow_ofs_delta;
63
static const char *pack_tmp_name, *idx_tmp_name;
64
static char tmpname[PATH_MAX];
65
+static const char *base_name;
66
static unsigned char pack_file_sha1[20];
67
static int progress = 1;
68
static int window = 10;
69
+static uint32_t pack_size_limit;
70
static int depth = 50;
71
static int pack_to_stdout;
72
static int num_preferred_base;
@@ -501,7 +504,11 @@ static int open_object_dir_tmp(const char *path)
504
return mkstemp(tmpname);
505
}
506
504
-static off_t write_pack_file(void)
507
+/* forward declarations for write_pack_file */
508
+static void write_index_file(off_t last_obj_offset, unsigned char *sha1);
509
+static int adjust_perm(const char *path, mode_t mode);
510
+
511
+static void write_pack_file(void)
512
{
513
uint32_t i;
514
struct sha1file *f;
@@ -543,7 +550,32 @@ static off_t write_pack_file(void)
550
die("wrote %u objects while expecting %u", written, nr_result);
551
sha1close(f, pack_file_sha1, 1);
552
546
- return last_obj_offset;
553
+ if (!pack_to_stdout) {
554
+ unsigned char object_list_sha1[20];
555
+ mode_t mode = umask(0);
556
+
557
+ umask(mode);
558
+ mode = 0444 & ~mode;
559
+
560
+ write_index_file(last_obj_offset, object_list_sha1);
561
+ snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
562
+ base_name, sha1_to_hex(object_list_sha1));
563
+ if (adjust_perm(pack_tmp_name, mode))
564
+ die("unable to make temporary pack file readable: %s",
565
+ strerror(errno));
566
+ if (rename(pack_tmp_name, tmpname))
567
+ die("unable to rename temporary pack file: %s",
568
+ strerror(errno));
569
+ snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
570
+ base_name, sha1_to_hex(object_list_sha1));
571
+ if (adjust_perm(idx_tmp_name, mode))
572
+ die("unable to make temporary index file readable: %s",
573
+ strerror(errno));
574
+ if (rename(idx_tmp_name, tmpname))
575
+ die("unable to rename temporary index file: %s",
576
+ strerror(errno));
577
+ puts(sha1_to_hex(object_list_sha1));
578
+ }
579
}
580
581
static int sha1_sort(const void *_a, const void *_b)
@@ -1537,8 +1569,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1569
int use_internal_rev_list = 0;
1570
int thin = 0;
1571
uint32_t i;
1540
- off_t last_obj_offset;
1541
- const char *base_name = NULL;
1572
const char **rp_av;
1573
int rp_ac_alloc = 64;
1574
int rp_ac;
@@ -1707,33 +1737,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1737
fprintf(stderr, "Result has %u objects.\n", nr_result);
1738
if (nr_result)
1739
prepare_pack(window, depth);
1710
- last_obj_offset = write_pack_file();
1711
- if (!pack_to_stdout) {
1712
- unsigned char object_list_sha1[20];
1713
- mode_t mode = umask(0);
1714
-
1715
- umask(mode);
1716
- mode = 0444 & ~mode;
1717
-
1718
- write_index_file(last_obj_offset, object_list_sha1);
1719
- snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
1720
- base_name, sha1_to_hex(object_list_sha1));
1721
- if (adjust_perm(pack_tmp_name, mode))
1722
- die("unable to make temporary pack file readable: %s",
1723
- strerror(errno));
1724
- if (rename(pack_tmp_name, tmpname))
1725
- die("unable to rename temporary pack file: %s",
1726
- strerror(errno));
1727
- snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
1728
- base_name, sha1_to_hex(object_list_sha1));
1729
- if (adjust_perm(idx_tmp_name, mode))
1730
- die("unable to make temporary index file readable: %s",
1731
- strerror(errno));
1732
- if (rename(idx_tmp_name, tmpname))
1733
- die("unable to rename temporary index file: %s",
1734
- strerror(errno));
1735
- puts(sha1_to_hex(object_list_sha1));
1736
- }
1740
+ write_pack_file();
1741
if (progress)
1742
fprintf(stderr, "Total %u (delta %u), reused %u (delta %u)\n",
1743
written, written_delta, reused, reused_delta);