@@ -58,7 +58,7 @@ static int recvline_fh(FILE *helper, struct strbuf *buffer, const char *name)
58
58
if (strbuf_getline (buffer , helper , '\n' ) == EOF ) {
59
59
if (debug )
60
60
fprintf (stderr , "Debug: Remote helper quit.\n" );
61
- exit ( 128 ) ;
61
+ return 1 ;
62
62
}
63
63
64
64
if (debug )
@@ -71,12 +71,6 @@ static int recvline(struct helper_data *helper, struct strbuf *buffer)
71
71
return recvline_fh (helper -> out , buffer , helper -> name );
72
72
}
73
73
74
- static void xchgline (struct helper_data * helper , struct strbuf * buffer )
75
- {
76
- sendline (helper , buffer );
77
- recvline (helper , buffer );
78
- }
79
-
80
74
static void write_constant (int fd , const char * str )
81
75
{
82
76
if (debug )
@@ -163,7 +157,8 @@ static struct child_process *get_helper(struct transport *transport)
163
157
while (1 ) {
164
158
const char * capname ;
165
159
int mandatory = 0 ;
166
- recvline (data , & buf );
160
+ if (recvline (data , & buf ))
161
+ exit (128 );
167
162
168
163
if (!* buf .buf )
169
164
break ;
@@ -200,15 +195,9 @@ static struct child_process *get_helper(struct transport *transport)
200
195
} else if (!strcmp (capname , "signed-tags" )) {
201
196
data -> signed_tags = 1 ;
202
197
} else if (starts_with (capname , "export-marks " )) {
203
- struct strbuf arg = STRBUF_INIT ;
204
- strbuf_addstr (& arg , "--export-marks=" );
205
- strbuf_addstr (& arg , capname + strlen ("export-marks " ));
206
- data -> export_marks = strbuf_detach (& arg , NULL );
198
+ data -> export_marks = xstrdup (capname + strlen ("export-marks " ));
207
199
} else if (starts_with (capname , "import-marks" )) {
208
- struct strbuf arg = STRBUF_INIT ;
209
- strbuf_addstr (& arg , "--import-marks=" );
210
- strbuf_addstr (& arg , capname + strlen ("import-marks " ));
211
- data -> import_marks = strbuf_detach (& arg , NULL );
200
+ data -> import_marks = xstrdup (capname + strlen ("import-marks " ));
212
201
} else if (starts_with (capname , "no-private-update" )) {
213
202
data -> no_private_update = 1 ;
214
203
} else if (mandatory ) {
@@ -307,7 +296,9 @@ static int set_helper_option(struct transport *transport,
307
296
quote_c_style (value , & buf , NULL , 0 );
308
297
strbuf_addch (& buf , '\n' );
309
298
310
- xchgline (data , & buf );
299
+ sendline (data , & buf );
300
+ if (recvline (data , & buf ))
301
+ exit (128 );
311
302
312
303
if (!strcmp (buf .buf , "ok" ))
313
304
ret = 0 ;
@@ -379,7 +370,8 @@ static int fetch_with_fetch(struct transport *transport,
379
370
sendline (data , & buf );
380
371
381
372
while (1 ) {
382
- recvline (data , & buf );
373
+ if (recvline (data , & buf ))
374
+ exit (128 );
383
375
384
376
if (starts_with (buf .buf , "lock " )) {
385
377
const char * name = buf .buf + 5 ;
@@ -430,6 +422,8 @@ static int get_exporter(struct transport *transport,
430
422
struct helper_data * data = transport -> data ;
431
423
struct child_process * helper = get_helper (transport );
432
424
int argc = 0 , i ;
425
+ struct strbuf tmp = STRBUF_INIT ;
426
+
433
427
memset (fastexport , 0 , sizeof (* fastexport ));
434
428
435
429
/* we need to duplicate helper->in because we want to use it after
@@ -440,10 +434,14 @@ static int get_exporter(struct transport *transport,
440
434
fastexport -> argv [argc ++ ] = "--use-done-feature" ;
441
435
fastexport -> argv [argc ++ ] = data -> signed_tags ?
442
436
"--signed-tags=verbatim" : "--signed-tags=warn-strip" ;
443
- if (data -> export_marks )
444
- fastexport -> argv [argc ++ ] = data -> export_marks ;
445
- if (data -> import_marks )
446
- fastexport -> argv [argc ++ ] = data -> import_marks ;
437
+ if (data -> export_marks ) {
438
+ strbuf_addf (& tmp , "--export-marks=%s.tmp" , data -> export_marks );
439
+ fastexport -> argv [argc ++ ] = strbuf_detach (& tmp , NULL );
440
+ }
441
+ if (data -> import_marks ) {
442
+ strbuf_addf (& tmp , "--import-marks=%s" , data -> import_marks );
443
+ fastexport -> argv [argc ++ ] = strbuf_detach (& tmp , NULL );
444
+ }
447
445
448
446
for (i = 0 ; i < revlist_args -> nr ; i ++ )
449
447
fastexport -> argv [argc ++ ] = revlist_args -> items [i ].string ;
@@ -563,7 +561,9 @@ static int process_connect_service(struct transport *transport,
563
561
goto exit ;
564
562
565
563
sendline (data , & cmdbuf );
566
- recvline_fh (input , & cmdbuf , name );
564
+ if (recvline_fh (input , & cmdbuf , name ))
565
+ exit (128 );
566
+
567
567
if (!strcmp (cmdbuf .buf , "" )) {
568
568
data -> no_disconnect_req = 1 ;
569
569
if (debug )
@@ -739,16 +739,22 @@ static int push_update_ref_status(struct strbuf *buf,
739
739
return !(status == REF_STATUS_OK );
740
740
}
741
741
742
- static void push_update_refs_status (struct helper_data * data ,
742
+ static int push_update_refs_status (struct helper_data * data ,
743
743
struct ref * remote_refs ,
744
744
int flags )
745
745
{
746
746
struct strbuf buf = STRBUF_INIT ;
747
747
struct ref * ref = remote_refs ;
748
+ int ret = 0 ;
749
+
748
750
for (;;) {
749
751
char * private ;
750
752
751
- recvline (data , & buf );
753
+ if (recvline (data , & buf )) {
754
+ ret = 1 ;
755
+ break ;
756
+ }
757
+
752
758
if (!buf .len )
753
759
break ;
754
760
@@ -766,6 +772,7 @@ static void push_update_refs_status(struct helper_data *data,
766
772
free (private );
767
773
}
768
774
strbuf_release (& buf );
775
+ return ret ;
769
776
}
770
777
771
778
static int push_refs_with_push (struct transport * transport ,
@@ -846,8 +853,7 @@ static int push_refs_with_push(struct transport *transport,
846
853
sendline (data , & buf );
847
854
strbuf_release (& buf );
848
855
849
- push_update_refs_status (data , remote_refs , flags );
850
- return 0 ;
856
+ return push_update_refs_status (data , remote_refs , flags );
851
857
}
852
858
853
859
static int push_refs_with_export (struct transport * transport ,
@@ -905,7 +911,15 @@ static int push_refs_with_export(struct transport *transport,
905
911
906
912
if (finish_command (& exporter ))
907
913
die ("Error while running fast-export" );
908
- push_update_refs_status (data , remote_refs , flags );
914
+ if (push_update_refs_status (data , remote_refs , flags ))
915
+ return 1 ;
916
+
917
+ if (data -> export_marks ) {
918
+ strbuf_addf (& buf , "%s.tmp" , data -> export_marks );
919
+ rename (buf .buf , data -> export_marks );
920
+ strbuf_release (& buf );
921
+ }
922
+
909
923
return 0 ;
910
924
}
911
925
@@ -974,7 +988,8 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
974
988
975
989
while (1 ) {
976
990
char * eov , * eon ;
977
- recvline (data , & buf );
991
+ if (recvline (data , & buf ))
992
+ exit (128 );
978
993
979
994
if (!* buf .buf )
980
995
break ;
0 commit comments