@@ -165,6 +165,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
165
165
const unsigned char * sha1 ;
166
166
unsigned in_vain = 0 ;
167
167
int got_continue = 0 ;
168
+ struct strbuf req_buf = STRBUF_INIT ;
168
169
169
170
if (marked )
170
171
for_each_ref (clear_marks , NULL );
@@ -175,6 +176,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
175
176
fetching = 0 ;
176
177
for ( ; refs ; refs = refs -> next ) {
177
178
unsigned char * remote = refs -> old_sha1 ;
179
+ const char * remote_hex ;
178
180
struct object * o ;
179
181
180
182
/*
@@ -192,27 +194,36 @@ static int find_common(int fd[2], unsigned char *result_sha1,
192
194
continue ;
193
195
}
194
196
195
- if (!fetching )
196
- packet_write (fd [1 ], "want %s%s%s%s%s%s%s%s\n" ,
197
- sha1_to_hex (remote ),
198
- (multi_ack ? " multi_ack" : "" ),
199
- (use_sideband == 2 ? " side-band-64k" : "" ),
200
- (use_sideband == 1 ? " side-band" : "" ),
201
- (args .use_thin_pack ? " thin-pack" : "" ),
202
- (args .no_progress ? " no-progress" : "" ),
203
- (args .include_tag ? " include-tag" : "" ),
204
- (prefer_ofs_delta ? " ofs-delta" : "" ));
205
- else
206
- packet_write (fd [1 ], "want %s\n" , sha1_to_hex (remote ));
197
+ remote_hex = sha1_to_hex (remote );
198
+ if (!fetching ) {
199
+ struct strbuf c = STRBUF_INIT ;
200
+ if (multi_ack ) strbuf_addstr (& c , " multi_ack" );
201
+ if (use_sideband == 2 ) strbuf_addstr (& c , " side-band-64k" );
202
+ if (use_sideband == 1 ) strbuf_addstr (& c , " side-band" );
203
+ if (args .use_thin_pack ) strbuf_addstr (& c , " thin-pack" );
204
+ if (args .no_progress ) strbuf_addstr (& c , " no-progress" );
205
+ if (args .include_tag ) strbuf_addstr (& c , " include-tag" );
206
+ if (prefer_ofs_delta ) strbuf_addstr (& c , " ofs-delta" );
207
+ packet_buf_write (& req_buf , "want %s%s\n" , remote_hex , c .buf );
208
+ strbuf_release (& c );
209
+ } else
210
+ packet_buf_write (& req_buf , "want %s\n" , remote_hex );
207
211
fetching ++ ;
208
212
}
213
+
214
+ if (!fetching ) {
215
+ strbuf_release (& req_buf );
216
+ packet_flush (fd [1 ]);
217
+ return 1 ;
218
+ }
219
+
209
220
if (is_repository_shallow ())
210
- write_shallow_commits (fd [ 1 ] , 1 );
221
+ write_shallow_commits (& req_buf , 1 );
211
222
if (args .depth > 0 )
212
- packet_write ( fd [ 1 ] , "deepen %d" , args .depth );
213
- packet_flush ( fd [ 1 ] );
214
- if (! fetching )
215
- return 1 ;
223
+ packet_buf_write ( & req_buf , "deepen %d" , args .depth );
224
+ packet_buf_flush ( & req_buf );
225
+
226
+ safe_write ( fd [ 1 ], req_buf . buf , req_buf . len ) ;
216
227
217
228
if (args .depth > 0 ) {
218
229
char line [1024 ];
@@ -296,6 +307,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,
296
307
multi_ack = 0 ;
297
308
flushes ++ ;
298
309
}
310
+ strbuf_release (& req_buf );
311
+
299
312
while (flushes || multi_ack ) {
300
313
int ack = get_ack (fd [0 ], result_sha1 );
301
314
if (ack ) {
@@ -809,6 +822,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
809
822
810
823
if (args .depth > 0 ) {
811
824
struct cache_time mtime ;
825
+ struct strbuf sb = STRBUF_INIT ;
812
826
char * shallow = git_path ("shallow" );
813
827
int fd ;
814
828
@@ -826,12 +840,14 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
826
840
827
841
fd = hold_lock_file_for_update (& lock , shallow ,
828
842
LOCK_DIE_ON_ERROR );
829
- if (!write_shallow_commits (fd , 0 )) {
843
+ if (!write_shallow_commits (& sb , 0 )
844
+ || write_in_full (fd , sb .buf , sb .len ) != sb .len ) {
830
845
unlink_or_warn (shallow );
831
846
rollback_lock_file (& lock );
832
847
} else {
833
848
commit_lock_file (& lock );
834
849
}
850
+ strbuf_release (& sb );
835
851
}
836
852
837
853
reprepare_packed_git ();
0 commit comments