451
}
452
453
static int refcol_width = 10;
454
+static int compact_format;
455
456
static void adjust_refcol_width(const struct ref *ref)
457
{
463
464
max = term_columns();
465
rlen = utf8_strwidth(prettify_refname(ref->name));
466
+
467
llen = utf8_strwidth(prettify_refname(ref->peer_ref->name));
468
469
/*
472
* anyway because we don't know if the error explanation part
473
* will be printed in update_local_ref)
474
*/
475
+ if (compact_format) {
476
+ llen = 0;
477
+ max = max * 2 / 3;
478
+ }
479
len = 21 /* flag and summary */ + rlen + 4 /* -> */ + llen;
480
if (len >= max)
481
return;
482
483
+ /*
484
+ * Not precise calculation for compact mode because '*' can
485
+ * appear on the left hand side of '->' and shrink the column
486
+ * back.
487
+ */
488
if (refcol_width < rlen)
489
refcol_width = rlen;
490
}
492
static void prepare_format_display(struct ref *ref_map)
493
{
494
struct ref *rm;
495
+ const char *format = "full";
496
+
497
+ git_config_get_string_const("fetch.output", &format);
498
+ if (!strcasecmp(format, "full"))
499
+ compact_format = 0;
500
+ else if (!strcasecmp(format, "compact"))
501
+ compact_format = 1;
502
+ else
503
+ die(_("configuration fetch.output contains invalid value %s"),
504
+ format);
505
506
for (rm = ref_map; rm; rm = rm->next) {
507
if (rm->status == REF_STATUS_REJECT_SHALLOW ||
513
}
514
}
515
516
+static void print_remote_to_local(struct strbuf *display,
517
+ const char *remote, const char *local)
518
+{
519
+ strbuf_addf(display, "%-*s -> %s", refcol_width, remote, local);
520
+}
521
+
522
+static int find_and_replace(struct strbuf *haystack,
523
+ const char *needle,
524
+ const char *placeholder)
525
+{
526
+ const char *p = strstr(haystack->buf, needle);
527
+ int plen, nlen;
528
+
529
+ if (!p)
530
+ return 0;
531
+
532
+ if (p > haystack->buf && p[-1] != '/')
533
+ return 0;
534
+
535
+ plen = strlen(p);
536
+ nlen = strlen(needle);
537
+ if (plen > nlen && p[nlen] != '/')
538
+ return 0;
539
+
540
+ strbuf_splice(haystack, p - haystack->buf, nlen,
541
+ placeholder, strlen(placeholder));
542
+ return 1;
543
+}
544
+
545
+static void print_compact(struct strbuf *display,
546
+ const char *remote, const char *local)
547
+{
548
+ struct strbuf r = STRBUF_INIT;
549
+ struct strbuf l = STRBUF_INIT;
550
+
551
+ if (!strcmp(remote, local)) {
552
+ strbuf_addf(display, "%-*s -> *", refcol_width, remote);
553
+ return;
554
+ }
555
+
556
+ strbuf_addstr(&r, remote);
557
+ strbuf_addstr(&l, local);
558
+
559
+ if (!find_and_replace(&r, local, "*"))
560
+ find_and_replace(&l, remote, "*");
561
+ print_remote_to_local(display, r.buf, l.buf);
562
+
563
+ strbuf_release(&r);
564
+ strbuf_release(&l);
565
+}
566
+
567
static void format_display(struct strbuf *display, char code,
568
const char *summary, const char *error,
569
const char *remote, const char *local)
570
{
571
strbuf_addf(display, "%c %-*s ", code, TRANSPORT_SUMMARY(summary));
500
- strbuf_addf(display, "%-*s -> %s", refcol_width, remote, local);
572
+ if (!compact_format)
573
+ print_remote_to_local(display, remote, local);
574
+ else
575
+ print_compact(display, remote, local);
576
if (error)
577
strbuf_addf(display, " (%s)", error);
578
}