@@ -76,7 +76,7 @@ static struct pack_idx_option pack_idx_opts;
76
76
static const char * base_name ;
77
77
static int progress = 1 ;
78
78
static int window = 10 ;
79
- static unsigned long pack_size_limit , pack_size_limit_cfg ;
79
+ static unsigned long pack_size_limit ;
80
80
static int depth = 50 ;
81
81
static int delta_search_threads ;
82
82
static int pack_to_stdout ;
@@ -638,7 +638,6 @@ static void write_pack_file(void)
638
638
uint32_t i = 0 , j ;
639
639
struct sha1file * f ;
640
640
off_t offset ;
641
- struct pack_header hdr ;
642
641
uint32_t nr_remaining = nr_result ;
643
642
time_t last_mtime = 0 ;
644
643
struct object_entry * * write_order ;
@@ -652,22 +651,14 @@ static void write_pack_file(void)
652
651
unsigned char sha1 [20 ];
653
652
char * pack_tmp_name = NULL ;
654
653
655
- if (pack_to_stdout ) {
654
+ if (pack_to_stdout )
656
655
f = sha1fd_throughput (1 , "<stdout>" , progress_state );
657
- } else {
658
- char tmpname [PATH_MAX ];
659
- int fd ;
660
- fd = odb_mkstemp (tmpname , sizeof (tmpname ),
661
- "pack/tmp_pack_XXXXXX" );
662
- pack_tmp_name = xstrdup (tmpname );
663
- f = sha1fd (fd , pack_tmp_name );
664
- }
665
-
666
- hdr .hdr_signature = htonl (PACK_SIGNATURE );
667
- hdr .hdr_version = htonl (PACK_VERSION );
668
- hdr .hdr_entries = htonl (nr_remaining );
669
- sha1write (f , & hdr , sizeof (hdr ));
670
- offset = sizeof (hdr );
656
+ else
657
+ f = create_tmp_packfile (& pack_tmp_name );
658
+
659
+ offset = write_pack_header (f , nr_remaining );
660
+ if (!offset )
661
+ die_errno ("unable to write pack header" );
671
662
nr_written = 0 ;
672
663
for (; i < nr_objects ; i ++ ) {
673
664
struct object_entry * e = write_order [i ];
@@ -693,49 +684,36 @@ static void write_pack_file(void)
693
684
694
685
if (!pack_to_stdout ) {
695
686
struct stat st ;
696
- const char * idx_tmp_name ;
697
687
char tmpname [PATH_MAX ];
698
688
699
- idx_tmp_name = write_idx_file (NULL , written_list , nr_written ,
700
- & pack_idx_opts , sha1 );
701
-
702
- snprintf (tmpname , sizeof (tmpname ), "%s-%s.pack" ,
703
- base_name , sha1_to_hex (sha1 ));
704
- free_pack_by_name (tmpname );
705
- if (adjust_shared_perm (pack_tmp_name ))
706
- die_errno ("unable to make temporary pack file readable" );
707
- if (rename (pack_tmp_name , tmpname ))
708
- die_errno ("unable to rename temporary pack file" );
709
-
710
689
/*
711
690
* Packs are runtime accessed in their mtime
712
691
* order since newer packs are more likely to contain
713
692
* younger objects. So if we are creating multiple
714
693
* packs then we should modify the mtime of later ones
715
694
* to preserve this property.
716
695
*/
717
- if (stat (tmpname , & st ) < 0 ) {
696
+ if (stat (pack_tmp_name , & st ) < 0 ) {
718
697
warning ("failed to stat %s: %s" ,
719
- tmpname , strerror (errno ));
698
+ pack_tmp_name , strerror (errno ));
720
699
} else if (!last_mtime ) {
721
700
last_mtime = st .st_mtime ;
722
701
} else {
723
702
struct utimbuf utb ;
724
703
utb .actime = st .st_atime ;
725
704
utb .modtime = -- last_mtime ;
726
- if (utime (tmpname , & utb ) < 0 )
705
+ if (utime (pack_tmp_name , & utb ) < 0 )
727
706
warning ("failed utime() on %s: %s" ,
728
707
tmpname , strerror (errno ));
729
708
}
730
709
731
- snprintf (tmpname , sizeof (tmpname ), "%s-%s.idx" ,
732
- base_name , sha1_to_hex (sha1 ));
733
- if (adjust_shared_perm (idx_tmp_name ))
734
- die_errno ("unable to make temporary index file readable" );
735
- if (rename (idx_tmp_name , tmpname ))
736
- die_errno ("unable to rename temporary index file" );
737
-
738
- free ((void * ) idx_tmp_name );
710
+ /* Enough space for "-<sha-1>.pack"? */
711
+ if (sizeof (tmpname ) <= strlen (base_name ) + 50 )
712
+ die ("pack base name '%s' too long" , base_name );
713
+ snprintf (tmpname , sizeof (tmpname ), "%s-" , base_name );
714
+ finish_tmp_packfile (tmpname , pack_tmp_name ,
715
+ written_list , nr_written ,
716
+ & pack_idx_opts , sha1 );
739
717
free (pack_tmp_name );
740
718
puts (sha1_to_hex (sha1 ));
741
719
}
@@ -2098,10 +2076,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
2098
2076
pack_idx_opts .version );
2099
2077
return 0 ;
2100
2078
}
2101
- if (!strcmp (k , "pack.packsizelimit" )) {
2102
- pack_size_limit_cfg = git_config_ulong (k , v );
2103
- return 0 ;
2104
- }
2105
2079
return git_default_config (k , v , cb );
2106
2080
}
2107
2081
0 commit comments