@@ -2001,7 +2001,7 @@ struct ref_to_prune {
2001
2001
struct pack_refs_cb_data {
2002
2002
unsigned int flags ;
2003
2003
struct ref_to_prune * ref_to_prune ;
2004
- FILE * refs_file ;
2004
+ int fd ;
2005
2005
};
2006
2006
2007
2007
static 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)
2020
2020
!(entry -> flag & REF_ISPACKED ))
2021
2021
return 0 ;
2022
2022
2023
- fprintf (cb -> refs_file , "%s %s\n" , sha1_to_hex (entry -> u .value .sha1 ),
2024
- entry -> name );
2025
-
2026
2023
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 )
2030
2025
die ("internal error peeling reference %s (%s)" ,
2031
2026
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 );
2032
2030
2033
2031
/* If the ref was already packed, there is no need to prune it. */
2034
2032
if ((cb -> flags & PACK_REFS_PRUNE ) && !(entry -> flag & REF_ISPACKED )) {
@@ -2097,32 +2095,17 @@ static struct lock_file packlock;
2097
2095
2098
2096
int pack_refs (unsigned int flags )
2099
2097
{
2100
- int fd ;
2101
2098
struct pack_refs_cb_data cbdata ;
2102
2099
2103
2100
memset (& cbdata , 0 , sizeof (cbdata ));
2104
2101
cbdata .flags = flags ;
2105
2102
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 );
2111
2105
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 ));
2114
2107
2115
2108
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 ;
2126
2109
if (commit_lock_file (& packlock ) < 0 )
2127
2110
die_errno ("unable to overwrite old ref-pack file" );
2128
2111
prune_refs (cbdata .ref_to_prune );
0 commit comments