@@ -36,18 +36,15 @@ int option_parse_push_signed(const struct option *opt,
3636 die ("bad %s argument: %s" , opt -> long_name , arg );
3737}
3838
39- static int feed_object (const unsigned char * sha1 , int fd , int negative )
39+ static void feed_object (const unsigned char * sha1 , FILE * fh , int negative )
4040{
41- char buf [42 ];
42-
4341 if (negative && !has_sha1_file (sha1 ))
44- return 1 ;
42+ return ;
4543
46- memcpy (buf + negative , sha1_to_hex (sha1 ), 40 );
4744 if (negative )
48- buf [ 0 ] = '^' ;
49- buf [ 40 + negative ] = '\n' ;
50- return write_or_whine ( fd , buf , 41 + negative , "send-pack: send refs" );
45+ putc ( '^' , fh ) ;
46+ fputs ( sha1_to_hex ( sha1 ), fh ) ;
47+ putc ( '\n' , fh );
5148}
5249
5350/*
@@ -73,6 +70,7 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
7370 NULL ,
7471 };
7572 struct child_process po = CHILD_PROCESS_INIT ;
73+ FILE * po_in ;
7674 int i ;
7775
7876 i = 4 ;
@@ -97,21 +95,22 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
9795 * We feed the pack-objects we just spawned with revision
9896 * parameters by writing to the pipe.
9997 */
98+ po_in = xfdopen (po .in , "w" );
10099 for (i = 0 ; i < extra -> nr ; i ++ )
101- if (!feed_object (extra -> sha1 [i ], po .in , 1 ))
102- break ;
100+ feed_object (extra -> sha1 [i ], po_in , 1 );
103101
104102 while (refs ) {
105- if (!is_null_oid (& refs -> old_oid ) &&
106- !feed_object (refs -> old_oid .hash , po .in , 1 ))
107- break ;
108- if (!is_null_oid (& refs -> new_oid ) &&
109- !feed_object (refs -> new_oid .hash , po .in , 0 ))
110- break ;
103+ if (!is_null_oid (& refs -> old_oid ))
104+ feed_object (refs -> old_oid .hash , po_in , 1 );
105+ if (!is_null_oid (& refs -> new_oid ))
106+ feed_object (refs -> new_oid .hash , po_in , 0 );
111107 refs = refs -> next ;
112108 }
113109
114- close (po .in );
110+ fflush (po_in );
111+ if (ferror (po_in ))
112+ die_errno ("error writing to pack-objects" );
113+ fclose (po_in );
115114
116115 if (args -> stateless_rpc ) {
117116 char * buf = xmalloc (LARGE_PACKET_MAX );
0 commit comments