Skip to content

Commit 7101e10

Browse files
committed
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 <[email protected]>
1 parent 8e3f52d commit 7101e10

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

transport.c

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
295295
}
296296
}
297297

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)
299301
{
300302
if (porcelain) {
301303
if (from)
@@ -307,7 +309,7 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
307309
else
308310
fprintf(stdout, "%s\n", summary);
309311
} else {
310-
fprintf(stderr, " %c %-*s ", flag, TRANSPORT_SUMMARY_WIDTH, summary);
312+
fprintf(stderr, " %c %-*s ", flag, summary_width, summary);
311313
if (from)
312314
fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
313315
else
@@ -321,15 +323,16 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
321323
}
322324
}
323325

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)
325327
{
326328
if (ref->deletion)
327-
print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain);
329+
print_ref_status('-', "[deleted]", ref, NULL, NULL,
330+
porcelain, summary_width);
328331
else if (is_null_oid(&ref->old_oid))
329332
print_ref_status('*',
330333
(starts_with(ref->name, "refs/tags/") ? "[new tag]" :
331334
"[new branch]"),
332-
ref, ref->peer_ref, NULL, porcelain);
335+
ref, ref->peer_ref, NULL, porcelain, summary_width);
333336
else {
334337
struct strbuf quickref = STRBUF_INIT;
335338
char type;
@@ -349,12 +352,14 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
349352
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
350353
DEFAULT_ABBREV);
351354

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);
353357
strbuf_release(&quickref);
354358
}
355359
}
356360

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)
358363
{
359364
if (!count) {
360365
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
364369

365370
switch(ref->status) {
366371
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);
368374
break;
369375
case REF_STATUS_REJECT_NODELETE:
370376
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);
372379
break;
373380
case REF_STATUS_UPTODATE:
374381
print_ref_status('=', "[up to date]", ref,
375-
ref->peer_ref, NULL, porcelain);
382+
ref->peer_ref, NULL, porcelain, summary_width);
376383
break;
377384
case REF_STATUS_REJECT_NONFASTFORWARD:
378385
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
379-
"non-fast-forward", porcelain);
386+
"non-fast-forward", porcelain, summary_width);
380387
break;
381388
case REF_STATUS_REJECT_ALREADY_EXISTS:
382389
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
383-
"already exists", porcelain);
390+
"already exists", porcelain, summary_width);
384391
break;
385392
case REF_STATUS_REJECT_FETCH_FIRST:
386393
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
387-
"fetch first", porcelain);
394+
"fetch first", porcelain, summary_width);
388395
break;
389396
case REF_STATUS_REJECT_NEEDS_FORCE:
390397
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
391-
"needs force", porcelain);
398+
"needs force", porcelain, summary_width);
392399
break;
393400
case REF_STATUS_REJECT_STALE:
394401
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
395-
"stale info", porcelain);
402+
"stale info", porcelain, summary_width);
396403
break;
397404
case REF_STATUS_REJECT_SHALLOW:
398405
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);
400408
break;
401409
case REF_STATUS_REMOTE_REJECT:
402410
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);
405413
break;
406414
case REF_STATUS_EXPECTING_REPORT:
407415
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);
410419
break;
411420
case REF_STATUS_ATOMIC_PUSH_FAILED:
412421
print_ref_status('!', "[rejected]", ref, ref->peer_ref,
413-
"atomic push failed", porcelain);
422+
"atomic push failed", porcelain, summary_width);
414423
break;
415424
case REF_STATUS_OK:
416-
print_ok_ref_status(ref, porcelain);
425+
print_ok_ref_status(ref, porcelain, summary_width);
417426
break;
418427
}
419428

@@ -427,25 +436,29 @@ void transport_print_push_status(const char *dest, struct ref *refs,
427436
int n = 0;
428437
unsigned char head_sha1[20];
429438
char *head;
439+
int summary_width = TRANSPORT_SUMMARY_WIDTH;
430440

431441
head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
432442

433443
if (verbose) {
434444
for (ref = refs; ref; ref = ref->next)
435445
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);
437448
}
438449

439450
for (ref = refs; ref; ref = ref->next)
440451
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);
442454

443455
*reject_reasons = 0;
444456
for (ref = refs; ref; ref = ref->next) {
445457
if (ref->status != REF_STATUS_NONE &&
446458
ref->status != REF_STATUS_UPTODATE &&
447459
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);
449462
if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) {
450463
if (head != NULL && !strcmp(head, ref->name))
451464
*reject_reasons |= REJECT_NON_FF_HEAD;

0 commit comments

Comments
 (0)