@@ -76,7 +76,7 @@ static struct pack_idx_option pack_idx_opts;
7676static const char * base_name ;
7777static int progress = 1 ;
7878static int window = 10 ;
79- static unsigned long pack_size_limit , pack_size_limit_cfg ;
79+ static unsigned long pack_size_limit ;
8080static int depth = 50 ;
8181static int delta_search_threads ;
8282static int pack_to_stdout ;
@@ -638,7 +638,6 @@ static void write_pack_file(void)
638638 uint32_t i = 0 , j ;
639639 struct sha1file * f ;
640640 off_t offset ;
641- struct pack_header hdr ;
642641 uint32_t nr_remaining = nr_result ;
643642 time_t last_mtime = 0 ;
644643 struct object_entry * * write_order ;
@@ -652,22 +651,14 @@ static void write_pack_file(void)
652651 unsigned char sha1 [20 ];
653652 char * pack_tmp_name = NULL ;
654653
655- if (pack_to_stdout ) {
654+ if (pack_to_stdout )
656655 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" );
671662 nr_written = 0 ;
672663 for (; i < nr_objects ; i ++ ) {
673664 struct object_entry * e = write_order [i ];
@@ -693,49 +684,36 @@ static void write_pack_file(void)
693684
694685 if (!pack_to_stdout ) {
695686 struct stat st ;
696- const char * idx_tmp_name ;
697687 char tmpname [PATH_MAX ];
698688
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-
710689 /*
711690 * Packs are runtime accessed in their mtime
712691 * order since newer packs are more likely to contain
713692 * younger objects. So if we are creating multiple
714693 * packs then we should modify the mtime of later ones
715694 * to preserve this property.
716695 */
717- if (stat (tmpname , & st ) < 0 ) {
696+ if (stat (pack_tmp_name , & st ) < 0 ) {
718697 warning ("failed to stat %s: %s" ,
719- tmpname , strerror (errno ));
698+ pack_tmp_name , strerror (errno ));
720699 } else if (!last_mtime ) {
721700 last_mtime = st .st_mtime ;
722701 } else {
723702 struct utimbuf utb ;
724703 utb .actime = st .st_atime ;
725704 utb .modtime = -- last_mtime ;
726- if (utime (tmpname , & utb ) < 0 )
705+ if (utime (pack_tmp_name , & utb ) < 0 )
727706 warning ("failed utime() on %s: %s" ,
728707 tmpname , strerror (errno ));
729708 }
730709
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 );
739717 free (pack_tmp_name );
740718 puts (sha1_to_hex (sha1 ));
741719 }
@@ -2098,10 +2076,6 @@ static int git_pack_config(const char *k, const char *v, void *cb)
20982076 pack_idx_opts .version );
20992077 return 0 ;
21002078 }
2101- if (!strcmp (k , "pack.packsizelimit" )) {
2102- pack_size_limit_cfg = git_config_ulong (k , v );
2103- return 0 ;
2104- }
21052079 return git_default_config (k , v , cb );
21062080}
21072081
0 commit comments