@@ -2001,7 +2001,7 @@ struct ref_to_prune {
20012001struct pack_refs_cb_data {
20022002 unsigned int flags ;
20032003 struct ref_to_prune * ref_to_prune ;
2004- FILE * refs_file ;
2004+ int fd ;
20052005};
20062006
20072007static int pack_one_ref (struct ref_entry * entry , void * cb_data )
@@ -2020,15 +2020,13 @@ static int pack_one_ref(struct ref_entry *entry, void *cb_data)
20202020 !(entry -> flag & REF_ISPACKED ))
20212021 return 0 ;
20222022
2023- fprintf (cb -> refs_file , "%s %s\n" , sha1_to_hex (entry -> u .value .sha1 ),
2024- entry -> name );
2025-
20262023 peel_status = peel_entry (entry , 1 );
2027- if (peel_status == PEEL_PEELED )
2028- fprintf (cb -> refs_file , "^%s\n" , sha1_to_hex (entry -> u .value .peeled ));
2029- else if (peel_status != PEEL_NON_TAG )
2024+ if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG )
20302025 die ("internal error peeling reference %s (%s)" ,
20312026 entry -> name , sha1_to_hex (entry -> u .value .sha1 ));
2027+ write_packed_entry (cb -> fd , entry -> name , entry -> u .value .sha1 ,
2028+ peel_status == PEEL_PEELED ?
2029+ entry -> u .value .peeled : NULL );
20322030
20332031 /* If the ref was already packed, there is no need to prune it. */
20342032 if ((cb -> flags & PACK_REFS_PRUNE ) && !(entry -> flag & REF_ISPACKED )) {
@@ -2097,32 +2095,17 @@ static struct lock_file packlock;
20972095
20982096int pack_refs (unsigned int flags )
20992097{
2100- int fd ;
21012098 struct pack_refs_cb_data cbdata ;
21022099
21032100 memset (& cbdata , 0 , sizeof (cbdata ));
21042101 cbdata .flags = flags ;
21052102
2106- fd = hold_lock_file_for_update (& packlock , git_path ("packed-refs" ),
2107- LOCK_DIE_ON_ERROR );
2108- cbdata .refs_file = fdopen (fd , "w" );
2109- if (!cbdata .refs_file )
2110- die_errno ("unable to create ref-pack file structure" );
2103+ cbdata .fd = hold_lock_file_for_update (& packlock , git_path ("packed-refs" ),
2104+ LOCK_DIE_ON_ERROR );
21112105
2112- /* perhaps other traits later as well */
2113- fprintf (cbdata .refs_file , "# pack-refs with: peeled fully-peeled \n" );
2106+ write_or_die (cbdata .fd , PACKED_REFS_HEADER , strlen (PACKED_REFS_HEADER ));
21142107
21152108 do_for_each_entry (NULL , "" , pack_one_ref , & cbdata );
2116- if (ferror (cbdata .refs_file ))
2117- die ("failed to write ref-pack file" );
2118- if (fflush (cbdata .refs_file ) || fsync (fd ) || fclose (cbdata .refs_file ))
2119- die_errno ("failed to write ref-pack file" );
2120- /*
2121- * Since the lock file was fdopen()'ed and then fclose()'ed above,
2122- * assign -1 to the lock file descriptor so that commit_lock_file()
2123- * won't try to close() it.
2124- */
2125- packlock .fd = -1 ;
21262109 if (commit_lock_file (& packlock ) < 0 )
21272110 die_errno ("unable to overwrite old ref-pack file" );
21282111 prune_refs (cbdata .ref_to_prune );
0 commit comments