Commit 8443ed6c1d1237e203474a772fb4281c382df6ac

Vicent Marti 2014-04-25T02:10:19

Merge pull request #2284 from jacquesg/push-progress-callback Fire progress and update tips callbacks also for pushes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
diff --git a/examples/network/fetch.c b/examples/network/fetch.c
index fdd82a1..03f1541 100644
--- a/examples/network/fetch.c
+++ b/examples/network/fetch.c
@@ -97,7 +97,7 @@ int fetch(git_repository *repo, int argc, char **argv)
 
 	// Set up the callbacks (only update_tips for now)
 	callbacks.update_tips = &update_cb;
-	callbacks.progress = &progress_cb;
+	callbacks.sideband_progress = &progress_cb;
 	callbacks.credentials = cred_acquire_cb;
 	git_remote_set_callbacks(remote, &callbacks);
 
diff --git a/include/git2/indexer.h b/include/git2/indexer.h
index e4c03ad..d2d315e 100644
--- a/include/git2/indexer.h
+++ b/include/git2/indexer.h
@@ -32,7 +32,7 @@ GIT_EXTERN(int) git_indexer_new(
 		const char *path,
 		unsigned int mode,
 		git_odb *odb,
-		git_transfer_progress_callback progress_cb,
+		git_transfer_progress_cb progress_cb,
 		void *progress_cb_payload);
 
 /**
diff --git a/include/git2/odb.h b/include/git2/odb.h
index c71e306..114f6b3 100644
--- a/include/git2/odb.h
+++ b/include/git2/odb.h
@@ -338,7 +338,7 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const gi
 GIT_EXTERN(int) git_odb_write_pack(
 	git_odb_writepack **out,
 	git_odb *db,
-	git_transfer_progress_callback progress_cb,
+	git_transfer_progress_cb progress_cb,
 	void *progress_payload);
 
 /**
diff --git a/include/git2/pack.h b/include/git2/pack.h
index 29c926c..e7f060d 100644
--- a/include/git2/pack.h
+++ b/include/git2/pack.h
@@ -140,7 +140,7 @@ GIT_EXTERN(int) git_packbuilder_write(
 	git_packbuilder *pb,
 	const char *path,
 	unsigned int mode,
-	git_transfer_progress_callback progress_cb,
+	git_transfer_progress_cb progress_cb,
 	void *progress_cb_payload);
 
 /**
diff --git a/include/git2/remote.h b/include/git2/remote.h
index ddde3e8..11e1e26 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -457,7 +457,7 @@ struct git_remote_callbacks {
 	 * progress side-band will be passed to this function (this is
 	 * the 'counting objects' output.
 	 */
-	int (*progress)(const char *str, int len, void *data);
+	git_transport_message_cb sideband_progress;
 
 	/**
 	 * Completion is called when different parts of the download
@@ -472,14 +472,14 @@ struct git_remote_callbacks {
 	 * Returning GIT_PASSTHROUGH will make libgit2 behave as
 	 * though this field isn't set.
 	 */
-	int (*credentials)(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types,	void *data);
+	git_cred_acquire_cb credentials;
 
 	/**
 	 * During the download of new data, this will be regularly
 	 * called with the current count of progress done by the
 	 * indexer.
 	 */
-	int (*transfer_progress)(const git_transfer_progress *stats, void *data);
+	git_transfer_progress_cb transfer_progress;
 
 	/**
 	 * Each time a reference is updated locally, this function
diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h
index 81bb082..77fe0dd 100644
--- a/include/git2/sys/odb_backend.h
+++ b/include/git2/sys/odb_backend.h
@@ -81,7 +81,7 @@ struct git_odb_backend {
 
 	int (* writepack)(
 		git_odb_writepack **, git_odb_backend *, git_odb *odb,
-		git_transfer_progress_callback progress_cb, void *progress_payload);
+		git_transfer_progress_cb progress_cb, void *progress_payload);
 
 	void (* free)(git_odb_backend *);
 };
diff --git a/include/git2/transport.h b/include/git2/transport.h
index 1665f97..a33146c 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -287,7 +287,7 @@ struct git_transport {
 		git_transport *transport,
 		git_repository *repo,
 		git_transfer_progress *stats,
-		git_transfer_progress_callback progress_cb,
+		git_transfer_progress_cb progress_cb,
 		void *progress_payload);
 
 	/* Checks to see if the transport is connected */
diff --git a/include/git2/types.h b/include/git2/types.h
index 9db59b1..1b6f4cc 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -241,7 +241,7 @@ typedef struct git_transfer_progress {
  * @param stats Structure containing information about the state of the transfer
  * @param payload Payload provided by caller
  */
-typedef int (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
+typedef int (*git_transfer_progress_cb)(const git_transfer_progress *stats, void *payload);
 
 /**
  * Opaque structure representing a submodule.
diff --git a/src/fetch.h b/src/fetch.h
index 9605da1..f66e446 100644
--- a/src/fetch.h
+++ b/src/fetch.h
@@ -17,7 +17,7 @@ int git_fetch__download_pack(
 		git_transport *t,
 		git_repository *repo,
 		git_transfer_progress *stats,
-		git_transfer_progress_callback progress_cb,
+		git_transfer_progress_cb progress_cb,
 		void *progress_payload);
 
 int git_fetch_setup_walk(git_revwalk **out, git_repository *repo);
diff --git a/src/indexer.c b/src/indexer.c
index 346870f..adf5cea 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -45,7 +45,7 @@ struct git_indexer {
 	unsigned int fanout[256];
 	git_hash_ctx hash_ctx;
 	git_oid hash;
-	git_transfer_progress_callback progress_cb;
+	git_transfer_progress_cb progress_cb;
 	void *progress_payload;
 	char objbuf[8*1024];
 
@@ -120,7 +120,7 @@ int git_indexer_new(
 		const char *prefix,
 		unsigned int mode,
 		git_odb *odb,
-		git_transfer_progress_callback progress_cb,
+		git_transfer_progress_cb progress_cb,
 		void *progress_payload)
 {
 	git_indexer *idx;
diff --git a/src/odb.c b/src/odb.c
index 72d1506..00740d2 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -1051,7 +1051,7 @@ int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oi
 	return error;
 }
 
-int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_transfer_progress_callback progress_cb, void *progress_payload)
+int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_transfer_progress_cb progress_cb, void *progress_payload)
 {
 	size_t i, writes = 0;
 	int error = GIT_ERROR;
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 9ab6838..3750da3 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -563,7 +563,7 @@ static void pack_backend__writepack_free(struct git_odb_writepack *_writepack)
 static int pack_backend__writepack(struct git_odb_writepack **out,
 	git_odb_backend *_backend,
         git_odb *odb,
-	git_transfer_progress_callback progress_cb,
+	git_transfer_progress_cb progress_cb,
 	void *progress_payload)
 {
 	struct pack_backend *backend;
diff --git a/src/pack-objects.c b/src/pack-objects.c
index c881e6d..7e5f667 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -1288,7 +1288,7 @@ int git_packbuilder_write(
 	git_packbuilder *pb,
 	const char *path,
 	unsigned int mode,
-	git_transfer_progress_callback progress_cb,
+	git_transfer_progress_cb progress_cb,
 	void *progress_cb_payload)
 {
 	git_indexer *indexer;
diff --git a/src/push.c b/src/push.c
index 5c8de33..9943f21 100644
--- a/src/push.c
+++ b/src/push.c
@@ -208,9 +208,7 @@ int git_push_update_tips(
 	int error = 0;
 
 	git_vector_foreach(&push->status, i, status) {
-		/* If this ref update was successful (ok, not ng), it will have an empty message */
-		if (status->msg)
-			continue;
+		int fire_callback = 1;
 
 		/* Find the corresponding remote ref */
 		fetch_spec = git_remote__matching_refspec(push->remote, status->ref);
@@ -230,24 +228,38 @@ int git_push_update_tips(
 		if (j == push->specs.length)
 			continue;
 
-		/* Update the remote ref */
-		if (git_oid_iszero(&push_spec->loid)) {
-			error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));
+		/* If this ref update was successful (ok, not ng), it will have an empty message */
+		if (status->msg == NULL) {
+			/* Update the remote ref */
+			if (git_oid_iszero(&push_spec->loid)) {
+				error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));
 
-			if (!error) {
-				if ((error = git_reference_delete(remote_ref)) < 0) {
+				if (error >= 0) {
+					error = git_reference_delete(remote_ref);
 					git_reference_free(remote_ref);
-					goto on_error;
 				}
-				git_reference_free(remote_ref);
-			} else if (error == GIT_ENOTFOUND)
-				giterr_clear();
-			else
+			} else {
+				error = git_reference_create(NULL, push->remote->repo,
+							git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
+							reflog_message ? reflog_message : "update by push");
+			}
+		}
+
+		if (error < 0) {
+			if (error != GIT_ENOTFOUND)
 				goto on_error;
-		} else if ((error = git_reference_create(NULL, push->remote->repo,
-						git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
-						reflog_message ? reflog_message : "update by push")) < 0)
-			goto on_error;
+
+			giterr_clear();
+			fire_callback = 0;
+		}
+
+		if (fire_callback && push->remote->callbacks.update_tips) {
+			error = push->remote->callbacks.update_tips(git_buf_cstr(&remote_ref_name),
+						&push_spec->roid, &push_spec->loid, push->remote->callbacks.payload);
+
+			if (error < 0)
+				goto on_error;
+		}
 	}
 
 	error = 0;
@@ -677,9 +689,7 @@ void git_push_status_free(push_status *status)
 	if (status == NULL)
 		return;
 
-	if (status->msg)
-		git__free(status->msg);
-
+	git__free(status->msg);
 	git__free(status->ref);
 	git__free(status);
 }
diff --git a/src/remote.c b/src/remote.c
index c23a464..ea638e3 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -663,7 +663,7 @@ int git_remote_connect(git_remote *remote, git_direction direction)
 		return error;
 
 	if (t->set_callbacks &&
-		(error = t->set_callbacks(t, remote->callbacks.progress, NULL, remote->callbacks.payload)) < 0)
+		(error = t->set_callbacks(t, remote->callbacks.sideband_progress, NULL, remote->callbacks.payload)) < 0)
 		goto on_error;
 
 	if (!remote->check_cert)
@@ -1246,7 +1246,7 @@ int git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *cal
 
 	if (remote->transport && remote->transport->set_callbacks)
 		return remote->transport->set_callbacks(remote->transport,
-			remote->callbacks.progress,
+			remote->callbacks.sideband_progress,
 			NULL,
 			remote->callbacks.payload);
 
diff --git a/src/transports/local.c b/src/transports/local.c
index f8d511e..2c17e62 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -472,7 +472,7 @@ on_error:
 
 typedef struct foreach_data {
 	git_transfer_progress *stats;
-	git_transfer_progress_callback progress_cb;
+	git_transfer_progress_cb progress_cb;
 	void *progress_payload;
 	git_odb_writepack *writepack;
 } foreach_data;
@@ -489,7 +489,7 @@ static int local_download_pack(
 		git_transport *transport,
 		git_repository *repo,
 		git_transfer_progress *stats,
-		git_transfer_progress_callback progress_cb,
+		git_transfer_progress_cb progress_cb,
 		void *progress_payload)
 {
 	transport_local *t = (transport_local*)transport;
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 32f0be7..a2b6b2a 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -167,7 +167,7 @@ int git_smart__download_pack(
 	git_transport *transport,
 	git_repository *repo,
 	git_transfer_progress *stats,
-	git_transfer_progress_callback progress_cb,
+	git_transfer_progress_cb progress_cb,
 	void *progress_payload);
 
 /* smart.c */
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 2bb09c7..e9376ae 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -153,7 +153,7 @@ static int data_pkt(git_pkt **out, const char *line, size_t len)
 	return 0;
 }
 
-static int progress_pkt(git_pkt **out, const char *line, size_t len)
+static int sideband_progress_pkt(git_pkt **out, const char *line, size_t len)
 {
 	git_pkt_progress *pkt;
 
@@ -403,7 +403,7 @@ int git_pkt_parse_line(
 	if (*line == GIT_SIDE_BAND_DATA)
 		ret = data_pkt(head, line, len);
 	else if (*line == GIT_SIDE_BAND_PROGRESS)
-		ret = progress_pkt(head, line, len);
+		ret = sideband_progress_pkt(head, line, len);
 	else if (*line == GIT_SIDE_BAND_ERROR)
 		ret = sideband_error_pkt(head, line, len);
 	else if (!git__prefixcmp(line, "ACK"))
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 7e8fcdd..5dd6bab 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -450,7 +450,7 @@ static int no_sideband(transport_smart *t, struct git_odb_writepack *writepack, 
 
 struct network_packetsize_payload
 {
-	git_transfer_progress_callback callback;
+	git_transfer_progress_cb callback;
 	void *payload;
 	git_transfer_progress *stats;
 	size_t last_fired_bytes;
@@ -478,7 +478,7 @@ int git_smart__download_pack(
 	git_transport *transport,
 	git_repository *repo,
 	git_transfer_progress *stats,
-	git_transfer_progress_callback progress_cb,
+	git_transfer_progress_cb transfer_progress_cb,
 	void *progress_payload)
 {
 	transport_smart *t = (transport_smart *)transport;
@@ -490,8 +490,8 @@ int git_smart__download_pack(
 
 	memset(stats, 0, sizeof(git_transfer_progress));
 
-	if (progress_cb) {
-		npp.callback = progress_cb;
+	if (transfer_progress_cb) {
+		npp.callback = transfer_progress_cb;
 		npp.payload = progress_payload;
 		npp.stats = stats;
 		t->packetsize_cb = &network_packetsize;
@@ -504,7 +504,7 @@ int git_smart__download_pack(
 	}
 
 	if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 ||
-		((error = git_odb_write_pack(&writepack, odb, progress_cb, progress_payload)) != 0))
+		((error = git_odb_write_pack(&writepack, odb, transfer_progress_cb, progress_payload)) != 0))
 		goto done;
 
 	/*
@@ -518,7 +518,7 @@ int git_smart__download_pack(
 	}
 
 	do {
-		git_pkt *pkt;
+		git_pkt *pkt = NULL;
 
 		/* Check cancellation before network call */
 		if (t->cancelled.val) {
@@ -527,40 +527,34 @@ int git_smart__download_pack(
 			goto done;
 		}
 
-		if ((error = recv_pkt(&pkt, buf)) < 0)
-			goto done;
-
-		/* Check cancellation after network call */
-		if (t->cancelled.val) {
-			giterr_clear();
-			error = GIT_EUSER;
-			goto done;
+		if ((error = recv_pkt(&pkt, buf)) >= 0) {
+			/* Check cancellation after network call */
+			if (t->cancelled.val) {
+				giterr_clear();
+				error = GIT_EUSER;
+			} else if (pkt->type == GIT_PKT_PROGRESS) {
+				if (t->progress_cb) {
+					git_pkt_progress *p = (git_pkt_progress *) pkt;
+					error = t->progress_cb(p->data, p->len, t->message_cb_payload);
+				}
+			} else if (pkt->type == GIT_PKT_DATA) {
+				git_pkt_data *p = (git_pkt_data *) pkt;
+				error = writepack->append(writepack, p->data, p->len, stats);
+			} else if (pkt->type == GIT_PKT_FLUSH) {
+				/* A flush indicates the end of the packfile */
+				git__free(pkt);
+				break;
+			}
 		}
 
-		if (pkt->type == GIT_PKT_PROGRESS) {
-			if (t->progress_cb) {
-				git_pkt_progress *p = (git_pkt_progress *) pkt;
-				error = t->progress_cb(p->data, p->len, t->message_cb_payload);
-				if (error)
-					goto done;
-			}
-			git__free(pkt);
-		} else if (pkt->type == GIT_PKT_DATA) {
-			git_pkt_data *p = (git_pkt_data *) pkt;
-			error = writepack->append(writepack, p->data, p->len, stats);
+		git__free(pkt);
+		if (error < 0)
+			goto done;
 
-			git__free(pkt);
-			if (error != 0)
-				goto done;
-		} else if (pkt->type == GIT_PKT_FLUSH) {
-			/* A flush indicates the end of the packfile */
-			git__free(pkt);
-			break;
-		}
 	} while (1);
 
 	/*
-	 * Trailing execution of progress_cb, if necessary...
+	 * Trailing execution of transfer_progress_cb, if necessary...
 	 * Only the callback through the npp datastructure currently
 	 * updates the last_fired_bytes value. It is possible that
 	 * progress has already been reported with the correct
@@ -579,7 +573,7 @@ int git_smart__download_pack(
 done:
 	if (writepack)
 		writepack->free(writepack);
-	if (progress_cb) {
+	if (transfer_progress_cb) {
 		t->packetsize_cb = NULL;
 		t->packetsize_payload = NULL;
 	}
@@ -634,7 +628,7 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt)
 
 	switch (pkt->type) {
 		case GIT_PKT_OK:
-			status = git__calloc(1, sizeof(push_status));
+			status = git__calloc(sizeof(push_status), 1);
 			GITERR_CHECK_ALLOC(status);
 			status->msg = NULL;
 			status->ref = git__strdup(((git_pkt_ok *)pkt)->ref);
@@ -696,10 +690,11 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt)
 	return 0;
 }
 
-static int parse_report(gitno_buffer *buf, git_push *push)
+static int parse_report(transport_smart *transport, git_push *push)
 {
 	git_pkt *pkt = NULL;
 	const char *line_end = NULL;
+	gitno_buffer *buf = &transport->buffer;
 	int error, recvd;
 
 	for (;;) {
@@ -738,6 +733,10 @@ static int parse_report(gitno_buffer *buf, git_push *push)
 				error = -1;
 				break;
 			case GIT_PKT_PROGRESS:
+				if (transport->progress_cb) {
+					git_pkt_progress *p = (git_pkt_progress *) pkt;
+					error = transport->progress_cb(p->data, p->len, transport->message_cb_payload);
+				}
 				break;
 			default:
 				error = add_push_report_pkt(push, pkt);
@@ -883,10 +882,7 @@ static int stream_thunk(void *buf, size_t size, void *data)
 
 		if ((current_time - payload->last_progress_report_time) >= MIN_PROGRESS_UPDATE_INTERVAL) {
 			payload->last_progress_report_time = current_time;
-			if (payload->cb(payload->pb->nr_written, payload->pb->nr_objects, payload->last_bytes, payload->cb_payload)) {
-				giterr_clear();
-				error = GIT_EUSER;
-			}
+			error = payload->cb(payload->pb->nr_written, payload->pb->nr_objects, payload->last_bytes, payload->cb_payload);
 		}
 	}
 
@@ -953,12 +949,19 @@ int git_smart__push(git_transport *transport, git_push *push)
 	 * we consider the pack to have been unpacked successfully */
 	if (!push->specs.length || !push->report_status)
 		push->unpack_ok = 1;
-	else if ((error = parse_report(&t->buffer, push)) < 0)
+	else if ((error = parse_report(t, push)) < 0)
 		goto done;
 
 	/* If progress is being reported write the final report */
 	if (push->transfer_progress_cb) {
-		push->transfer_progress_cb(push->pb->nr_written, push->pb->nr_objects, packbuilder_payload.last_bytes, push->transfer_progress_cb_payload);
+		error = push->transfer_progress_cb(
+					push->pb->nr_written,
+					push->pb->nr_objects,
+					packbuilder_payload.last_bytes,
+					push->transfer_progress_cb_payload);
+
+		if (error < 0)
+			goto done;
 	}
 
 	if (push->status.length) {
diff --git a/tests/online/push.c b/tests/online/push.c
index 716e2e9..6da27bb 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -254,8 +254,7 @@ static void verify_tracking_branches(git_remote *remote, expected_ref expected_r
 	}
 
 failed:
-
-	if(failed)
+	if (failed)
 		cl_fail(git_buf_cstr(&msg));
 
 	git_vector_foreach(&actual_refs, i, actual_ref)
@@ -264,7 +263,52 @@ failed:
 	git_vector_free(&actual_refs);
 	git_buf_free(&msg);
 	git_buf_free(&ref_name);
-	return;
+}
+
+static void verify_update_tips_callback(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len)
+{
+	git_refspec *fetch_spec;
+	git_buf msg = GIT_BUF_INIT;
+	git_buf ref_name = GIT_BUF_INIT;
+	updated_tip *tip = NULL;
+	size_t i, j;
+	int failed = 0;
+
+	for (i = 0; i < expected_refs_len; ++i) {
+		/* Convert remote reference name into tracking branch name.
+		 * If the spec is not under refs/heads/, then skip.
+		 */
+		fetch_spec = git_remote__matching_refspec(remote, expected_refs[i].name);
+		if (!fetch_spec)
+			continue;
+
+		cl_git_pass(git_refspec_transform(&ref_name, fetch_spec, expected_refs[i].name));
+
+		/* Find matching update_tip entry */
+		git_vector_foreach(&_record_cbs_data.updated_tips, j, tip) {
+			if (!strcmp(git_buf_cstr(&ref_name), tip->name))
+				break;
+		}
+
+		if (j == _record_cbs_data.updated_tips.length) {
+			git_buf_printf(&msg, "Did not find expected updated tip entry for branch '%s'.", git_buf_cstr(&ref_name));
+			failed = 1;
+			goto failed;
+		}
+
+		if (git_oid_cmp(expected_refs[i].oid, tip->new_oid) != 0) {
+			git_buf_printf(&msg, "Updated tip ID does not match expected ID");
+			failed = 1;
+			goto failed;
+		}
+	}
+
+failed:
+	if (failed)
+		cl_fail(git_buf_cstr(&msg));
+
+	git_buf_free(&ref_name);
+	git_buf_free(&msg);
 }
 
 void test_online_push__initialize(void)
@@ -409,7 +453,7 @@ static void do_push(
 	const char *refspecs[], size_t refspecs_len,
 	push_status expected_statuses[], size_t expected_statuses_len,
 	expected_ref expected_refs[], size_t expected_refs_len,
-	int expected_ret, int check_progress_cb)
+	int expected_ret, int check_progress_cb, int check_update_tips_cb)
 {
 	git_push *push;
 	git_push_options opts = GIT_PUSH_OPTIONS_INIT;
@@ -461,6 +505,9 @@ static void do_push(
 		cl_git_pass(git_push_update_tips(push, pusher, "test push"));
 		verify_tracking_branches(_remote, expected_refs, expected_refs_len);
 
+		if (check_update_tips_cb)
+			verify_update_tips_callback(_remote, expected_refs, expected_refs_len);
+
 		git_push_free(push);
 
 		git_remote_disconnect(_remote);
@@ -472,7 +519,7 @@ static void do_push(
 /* Call push_finish() without ever calling git_push_add_refspec() */
 void test_online_push__noop(void)
 {
-	do_push(NULL, 0, NULL, 0, NULL, 0, 0, 0);
+	do_push(NULL, 0, NULL, 0, NULL, 0, 0, 0, 1);
 }
 
 void test_online_push__b1(void)
@@ -482,7 +529,7 @@ void test_online_push__b1(void)
 	expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__b2(void)
@@ -492,7 +539,7 @@ void test_online_push__b2(void)
 	expected_ref exp_refs[] = { { "refs/heads/b2", &_oid_b2 } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__b3(void)
@@ -502,7 +549,7 @@ void test_online_push__b3(void)
 	expected_ref exp_refs[] = { { "refs/heads/b3", &_oid_b3 } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__b4(void)
@@ -512,7 +559,7 @@ void test_online_push__b4(void)
 	expected_ref exp_refs[] = { { "refs/heads/b4", &_oid_b4 } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__b5(void)
@@ -522,13 +569,13 @@ void test_online_push__b5(void)
 	expected_ref exp_refs[] = { { "refs/heads/b5", &_oid_b5 } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__b5_cancel(void)
 {
 	const char *specs[] = { "refs/heads/b5:refs/heads/b5" };
-	do_push(specs, ARRAY_SIZE(specs), NULL, 0, NULL, 0, GIT_EUSER, 1);
+	do_push(specs, ARRAY_SIZE(specs), NULL, 0, NULL, 0, GIT_EUSER, 1, 1);
 }
 
 void test_online_push__multi(void)
@@ -559,7 +606,7 @@ void test_online_push__multi(void)
 	};
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 
 	cl_git_pass(git_reflog_read(&log, _repo, "refs/remotes/test/b1"));
 	entry = git_reflog_entry_byindex(log, 0);
@@ -586,10 +633,10 @@ void test_online_push__implicit_tgt(void)
 
 	do_push(specs1, ARRAY_SIZE(specs1),
 		exp_stats1, ARRAY_SIZE(exp_stats1),
-		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
+		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1);
 	do_push(specs2, ARRAY_SIZE(specs2),
 		exp_stats2, ARRAY_SIZE(exp_stats2),
-		exp_refs2, ARRAY_SIZE(exp_refs2), 0, 0);
+		exp_refs2, ARRAY_SIZE(exp_refs2), 0, 0, 0);
 }
 
 void test_online_push__fast_fwd(void)
@@ -611,19 +658,19 @@ void test_online_push__fast_fwd(void)
 
 	do_push(specs_init, ARRAY_SIZE(specs_init),
 		exp_stats_init, ARRAY_SIZE(exp_stats_init),
-		exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 1);
+		exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 1, 1);
 
 	do_push(specs_ff, ARRAY_SIZE(specs_ff),
 		exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
-		exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0);
+		exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0, 0);
 
 	do_push(specs_reset, ARRAY_SIZE(specs_reset),
 		exp_stats_init, ARRAY_SIZE(exp_stats_init),
-		exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 0);
+		exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 0, 0);
 
 	do_push(specs_ff_force, ARRAY_SIZE(specs_ff_force),
 		exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
-		exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0);
+		exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0, 0);
 }
 
 void test_online_push__tag_commit(void)
@@ -633,7 +680,7 @@ void test_online_push__tag_commit(void)
 	expected_ref exp_refs[] = { { "refs/tags/tag-commit", &_tag_commit } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__tag_tree(void)
@@ -643,7 +690,7 @@ void test_online_push__tag_tree(void)
 	expected_ref exp_refs[] = { { "refs/tags/tag-tree", &_tag_tree } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__tag_blob(void)
@@ -653,7 +700,7 @@ void test_online_push__tag_blob(void)
 	expected_ref exp_refs[] = { { "refs/tags/tag-blob", &_tag_blob } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__tag_lightweight(void)
@@ -663,7 +710,7 @@ void test_online_push__tag_lightweight(void)
 	expected_ref exp_refs[] = { { "refs/tags/tag-lightweight", &_tag_lightweight } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 }
 
 void test_online_push__tag_to_tag(void)
@@ -673,7 +720,7 @@ void test_online_push__tag_to_tag(void)
 	expected_ref exp_refs[] = { { "refs/tags/tag-tag", &_tag_tag } };
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 0);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 0, 0);
 }
 
 void test_online_push__force(void)
@@ -690,16 +737,17 @@ void test_online_push__force(void)
 
 	do_push(specs1, ARRAY_SIZE(specs1),
 		exp_stats1, ARRAY_SIZE(exp_stats1),
-		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
+		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1);
 
 	do_push(specs2, ARRAY_SIZE(specs2),
 		NULL, 0,
-		exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD, 0);
+		exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD, 0, 0);
 
 	/* Non-fast-forward update with force should pass. */
+	record_callbacks_data_clear(&_record_cbs_data);
 	do_push(specs2_force, ARRAY_SIZE(specs2_force),
 		exp_stats2_force, ARRAY_SIZE(exp_stats2_force),
-		exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0, 1);
+		exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0, 1, 1);
 }
 
 void test_online_push__delete(void)
@@ -730,7 +778,7 @@ void test_online_push__delete(void)
 
 	do_push(specs1, ARRAY_SIZE(specs1),
 		exp_stats1, ARRAY_SIZE(exp_stats1),
-		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
+		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1, 1);
 
 	/* When deleting a non-existent branch, the git client sends zero for both
 	 * the old and new commit id.  This should succeed on the server with the
@@ -740,23 +788,23 @@ void test_online_push__delete(void)
 	 */
 	do_push(specs_del_fake, ARRAY_SIZE(specs_del_fake),
 		exp_stats_fake, 1,
-		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
+		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0);
 	do_push(specs_del_fake_force, ARRAY_SIZE(specs_del_fake_force),
 		exp_stats_fake, 1,
-		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
+		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0);
 
 	/* Delete one of the pushed branches. */
 	do_push(specs_delete, ARRAY_SIZE(specs_delete),
 		exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
-		exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0);
+		exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0, 0);
 
 	/* Re-push branches and retry delete with force. */
 	do_push(specs1, ARRAY_SIZE(specs1),
 		exp_stats1, ARRAY_SIZE(exp_stats1),
-		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
+		exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0, 0);
 	do_push(specs_delete_force, ARRAY_SIZE(specs_delete_force),
 		exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
-		exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0);
+		exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0, 0);
 }
 
 void test_online_push__bad_refspecs(void)
@@ -790,11 +838,11 @@ void test_online_push__expressions(void)
 	/* TODO: Find a more precise way of checking errors than a exit code of -1. */
 	do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr),
 		NULL, 0,
-		NULL, 0, -1, 0);
+		NULL, 0, -1, 0, 0);
 
 	do_push(specs_right_expr, ARRAY_SIZE(specs_right_expr),
 		exp_stats_right_expr, ARRAY_SIZE(exp_stats_right_expr),
-		NULL, 0, 0, 1);
+		NULL, 0, 0, 1, 1);
 }
 
 void test_online_push__notes(void)
@@ -814,7 +862,7 @@ void test_online_push__notes(void)
 
 	do_push(specs, ARRAY_SIZE(specs),
 		exp_stats, ARRAY_SIZE(exp_stats),
-		exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
+		exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1);
 
 	git_signature_free(signature);
 }