@@ -23,31 +23,14 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,
2323	list -> nr ++ ;
2424}
2525
26- /* Eventually this should go to strbuf.[ch] */ 
27- static  int  strbuf_readline_fd (struct  strbuf  * sb , int  fd )
28- {
29- 	strbuf_reset (sb );
30- 
31- 	while  (1 ) {
32- 		char  ch ;
33- 		ssize_t  len  =  xread (fd , & ch , 1 );
34- 		if  (len  <= 0 )
35- 			return  len ;
36- 		strbuf_addch (sb , ch );
37- 		if  (ch  ==  '\n' )
38- 			break ;
39- 	}
40- 	return  0 ;
41- }
42- 
4326static  int  parse_bundle_header (int  fd , struct  bundle_header  * header ,
4427			       const  char  * report_path )
4528{
4629	struct  strbuf  buf  =  STRBUF_INIT ;
4730	int  status  =  0 ;
4831
4932	/* The bundle header begins with the signature */ 
50- 	if  (strbuf_readline_fd (& buf , fd ) || 
33+ 	if  (strbuf_getwholeline_fd (& buf , fd ,  '\n' ) || 
5134	    strcmp (buf .buf , bundle_signature )) {
5235		if  (report_path )
5336			error ("'%s' does not look like a v2 bundle file" ,
@@ -57,7 +40,7 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
5740	}
5841
5942	/* The bundle header ends with an empty line */ 
60- 	while  (!strbuf_readline_fd (& buf , fd ) && 
43+ 	while  (!strbuf_getwholeline_fd (& buf , fd ,  '\n' ) && 
6144	       buf .len  &&  buf .buf [0 ] !=  '\n' ) {
6245		unsigned char   sha1 [20 ];
6346		int  is_prereq  =  0 ;
@@ -251,7 +234,7 @@ int create_bundle(struct bundle_header *header, const char *path,
251234	const  char  * * argv_boundary  =  xmalloc ((argc  +  4 ) *  sizeof (const  char  * ));
252235	const  char  * * argv_pack  =  xmalloc (6  *  sizeof (const  char  * ));
253236	int  i , ref_count  =  0 ;
254- 	char   buffer [ 1024 ] ;
237+ 	struct   strbuf   buf   =   STRBUF_INIT ;
255238	struct  rev_info  revs ;
256239	struct  child_process  rls ;
257240	FILE  * rls_fout ;
@@ -283,20 +266,21 @@ int create_bundle(struct bundle_header *header, const char *path,
283266	if  (start_command (& rls ))
284267		return  -1 ;
285268	rls_fout  =  xfdopen (rls .out , "r" );
286- 	while  (fgets ( buffer ,  sizeof ( buffer ),  rls_fout ) ) {
269+ 	while  (strbuf_getwholeline ( & buf ,  rls_fout ,  '\n' )  !=   EOF ) {
287270		unsigned char   sha1 [20 ];
288- 		if  (buffer [0 ] ==  '-' ) {
289- 			write_or_die (bundle_fd , buffer ,  strlen ( buffer ) );
290- 			if  (!get_sha1_hex (buffer  +  1 , sha1 )) {
271+ 		if  (buf . len   >   0   &&   buf . buf [0 ] ==  '-' ) {
272+ 			write_or_die (bundle_fd , buf . buf ,  buf . len );
273+ 			if  (!get_sha1_hex (buf . buf  +  1 , sha1 )) {
291274				struct  object  * object  =  parse_object (sha1 );
292275				object -> flags  |= UNINTERESTING ;
293- 				add_pending_object (& revs , object , buffer );
276+ 				add_pending_object (& revs , object , buf . buf );
294277			}
295- 		} else  if  (!get_sha1_hex (buffer , sha1 )) {
278+ 		} else  if  (!get_sha1_hex (buf . buf , sha1 )) {
296279			struct  object  * object  =  parse_object (sha1 );
297280			object -> flags  |= SHOWN ;
298281		}
299282	}
283+ 	strbuf_release (& buf );
300284	fclose (rls_fout );
301285	if  (finish_command (& rls ))
302286		return  error ("rev-list died" );
0 commit comments