transport: pass summary_width down the callchain

The callchain that originates at transport_print_push_status() eventually hits a single leaf function, print_ref_status(), that is used to show from what old object to what new object a ref got updated, and the width of the part that shows old and new object names used a constant TRANSPORT_SUMMARY_WIDTH. Teach the callchain to pass the width down from the top instead. This allows a future enhancement to compute the necessary display width before calling down this callchain. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 21, 2016 at 14:39 UTC 7101e10ce7ba917d1b7a6ff73e0008c2be4a43ed
1 file changed +38 -25
transport.c
+38 -25
@@ -295,7 +295,9 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
295 }
296 }
297
298 -static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg, int porcelain)
298 +static void print_ref_status(char flag, const char *summary,
299 + struct ref *to, struct ref *from, const char *msg,
300 + int porcelain, int summary_width)
301 {
302 if (porcelain) {
303 if (from)
@@ -307,7 +309,7 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
309 else
310 fprintf(stdout, "%s\n", summary);
311 } else {
310 - fprintf(stderr, " %c %-*s ", flag, TRANSPORT_SUMMARY_WIDTH, summary);
312 + fprintf(stderr, " %c %-*s ", flag, summary_width, summary);
313 if (from)
314 fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
315 else
@@ -321,15 +323,16 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
323 }
324 }
325
324 -static void print_ok_ref_status(struct ref *ref, int porcelain)
326 +static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_width)
327 {
328 if (ref->deletion)
327 - print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain);
329 + print_ref_status('-', "[deleted]", ref, NULL, NULL,
330 + porcelain, summary_width);
331 else if (is_null_oid(&ref->old_oid))
332 print_ref_status('*',
333 (starts_with(ref->name, "refs/tags/") ? "[new tag]" :
334 "[new branch]"),
332 - ref, ref->peer_ref, NULL, porcelain);
335 + ref, ref->peer_ref, NULL, porcelain, summary_width);
336 else {
337 struct strbuf quickref = STRBUF_INIT;
338 char type;
@@ -349,12 +352,14 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
352 strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
353 DEFAULT_ABBREV);
354
352 - print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain);
355 + print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg,
356 + porcelain, summary_width);
357 strbuf_release(&quickref);
358 }
359 }
360
357 -static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain)
361 +static int print_one_push_status(struct ref *ref, const char *dest, int count,
362 + int porcelain, int summary_width)
363 {
364 if (!count) {
365 char *url = transport_anonymize_url(dest);
@@ -364,56 +369,60 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i
369
370 switch(ref->status) {
371 case REF_STATUS_NONE:
367 - print_ref_status('X', "[no match]", ref, NULL, NULL, porcelain);
372 + print_ref_status('X', "[no match]", ref, NULL, NULL,
373 + porcelain, summary_width);
374 break;
375 case REF_STATUS_REJECT_NODELETE:
376 print_ref_status('!', "[rejected]", ref, NULL,
371 - "remote does not support deleting refs", porcelain);
377 + "remote does not support deleting refs",
378 + porcelain, summary_width);
379 break;
380 case REF_STATUS_UPTODATE:
381 print_ref_status('=', "[up to date]", ref,
375 - ref->peer_ref, NULL, porcelain);
382 + ref->peer_ref, NULL, porcelain, summary_width);
383 break;
384 case REF_STATUS_REJECT_NONFASTFORWARD:
385 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
379 - "non-fast-forward", porcelain);
386 + "non-fast-forward", porcelain, summary_width);
387 break;
388 case REF_STATUS_REJECT_ALREADY_EXISTS:
389 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
383 - "already exists", porcelain);
390 + "already exists", porcelain, summary_width);
391 break;
392 case REF_STATUS_REJECT_FETCH_FIRST:
393 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
387 - "fetch first", porcelain);
394 + "fetch first", porcelain, summary_width);
395 break;
396 case REF_STATUS_REJECT_NEEDS_FORCE:
397 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
391 - "needs force", porcelain);
398 + "needs force", porcelain, summary_width);
399 break;
400 case REF_STATUS_REJECT_STALE:
401 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
395 - "stale info", porcelain);
402 + "stale info", porcelain, summary_width);
403 break;
404 case REF_STATUS_REJECT_SHALLOW:
405 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
399 - "new shallow roots not allowed", porcelain);
406 + "new shallow roots not allowed",
407 + porcelain, summary_width);
408 break;
409 case REF_STATUS_REMOTE_REJECT:
410 print_ref_status('!', "[remote rejected]", ref,
403 - ref->deletion ? NULL : ref->peer_ref,
404 - ref->remote_status, porcelain);
411 + ref->deletion ? NULL : ref->peer_ref,
412 + ref->remote_status, porcelain, summary_width);
413 break;
414 case REF_STATUS_EXPECTING_REPORT:
415 print_ref_status('!', "[remote failure]", ref,
408 - ref->deletion ? NULL : ref->peer_ref,
409 - "remote failed to report status", porcelain);
416 + ref->deletion ? NULL : ref->peer_ref,
417 + "remote failed to report status",
418 + porcelain, summary_width);
419 break;
420 case REF_STATUS_ATOMIC_PUSH_FAILED:
421 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
413 - "atomic push failed", porcelain);
422 + "atomic push failed", porcelain, summary_width);
423 break;
424 case REF_STATUS_OK:
416 - print_ok_ref_status(ref, porcelain);
425 + print_ok_ref_status(ref, porcelain, summary_width);
426 break;
427 }
428
@@ -427,25 +436,29 @@ void transport_print_push_status(const char *dest, struct ref *refs,
436 int n = 0;
437 unsigned char head_sha1[20];
438 char *head;
439 + int summary_width = TRANSPORT_SUMMARY_WIDTH;
440
441 head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
442
443 if (verbose) {
444 for (ref = refs; ref; ref = ref->next)
445 if (ref->status == REF_STATUS_UPTODATE)
436 - n += print_one_push_status(ref, dest, n, porcelain);
446 + n += print_one_push_status(ref, dest, n,
447 + porcelain, summary_width);
448 }
449
450 for (ref = refs; ref; ref = ref->next)
451 if (ref->status == REF_STATUS_OK)
441 - n += print_one_push_status(ref, dest, n, porcelain);
452 + n += print_one_push_status(ref, dest, n,
453 + porcelain, summary_width);
454
455 *reject_reasons = 0;
456 for (ref = refs; ref; ref = ref->next) {
457 if (ref->status != REF_STATUS_NONE &&
458 ref->status != REF_STATUS_UPTODATE &&
459 ref->status != REF_STATUS_OK)
448 - n += print_one_push_status(ref, dest, n, porcelain);
460 + n += print_one_push_status(ref, dest, n,
461 + porcelain, summary_width);
462 if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) {
463 if (head != NULL && !strcmp(head, ref->name))
464 *reject_reasons |= REJECT_NON_FF_HEAD;