@@ -36,18 +36,15 @@ int option_parse_push_signed(const struct option *opt,
36
36
die ("bad %s argument: %s" , opt -> long_name , arg );
37
37
}
38
38
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 )
40
40
{
41
- char buf [42 ];
42
-
43
41
if (negative && !has_sha1_file (sha1 ))
44
- return 1 ;
42
+ return ;
45
43
46
- memcpy (buf + negative , sha1_to_hex (sha1 ), 40 );
47
44
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 );
51
48
}
52
49
53
50
/*
@@ -73,6 +70,7 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
73
70
NULL ,
74
71
};
75
72
struct child_process po = CHILD_PROCESS_INIT ;
73
+ FILE * po_in ;
76
74
int i ;
77
75
78
76
i = 4 ;
@@ -97,21 +95,22 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
97
95
* We feed the pack-objects we just spawned with revision
98
96
* parameters by writing to the pipe.
99
97
*/
98
+ po_in = xfdopen (po .in , "w" );
100
99
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 );
103
101
104
102
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 );
111
107
refs = refs -> next ;
112
108
}
113
109
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 );
115
114
116
115
if (args -> stateless_rpc ) {
117
116
char * buf = xmalloc (LARGE_PACKET_MAX );
0 commit comments