MCPcopy Create free account
hub / github.com/git/git / format_decorations

Function format_decorations

log-tree.c:340–421  ·  view source on GitHub ↗

* The caller makes sure there is no funny color before calling. * format_decorations ensures the same after return. */

Source from the content-addressed store, hash-verified

338 * format_decorations ensures the same after return.
339 */
340void format_decorations(struct strbuf *sb,
341 const struct commit *commit,
342 enum git_colorbool use_color,
343 const struct decoration_options *opts)
344{
345 const struct name_decoration *decoration;
346 const struct name_decoration *current_and_HEAD;
347 const char *color_commit, *color_reset;
348
349 const char *prefix = " (";
350 const char *suffix = ")";
351 const char *separator = ", ";
352 const char *pointer = " -> ";
353 const char *tag = "tag: ";
354
355 decoration = get_name_decoration(&commit->object);
356 if (!decoration)
357 return;
358
359 if (opts) {
360 if (opts->prefix)
361 prefix = opts->prefix;
362 if (opts->suffix)
363 suffix = opts->suffix;
364 if (opts->separator)
365 separator = opts->separator;
366 if (opts->pointer)
367 pointer = opts->pointer;
368 if (opts->tag)
369 tag = opts->tag;
370 }
371
372 color_commit = diff_get_color(use_color, DIFF_COMMIT);
373 color_reset = decorate_get_color(use_color, DECORATION_NONE);
374
375 current_and_HEAD = current_pointed_by_HEAD(decoration);
376 while (decoration) {
377 /*
378 * When both current and HEAD are there, only
379 * show HEAD->current where HEAD would have
380 * appeared, skipping the entry for current.
381 */
382 if (decoration != current_and_HEAD) {
383 const char *color =
384 decorate_get_color(use_color, decoration->type);
385
386 if (*prefix) {
387 strbuf_addstr(sb, color_commit);
388 strbuf_addstr(sb, prefix);
389 strbuf_addstr(sb, color_reset);
390 }
391
392 if (*tag && decoration->type == DECORATION_REF_TAG) {
393 strbuf_addstr(sb, color);
394 strbuf_addstr(sb, tag);
395 strbuf_addstr(sb, color_reset);
396 }
397

Callers 2

format_commit_oneFunction · 0.85
show_decorationsFunction · 0.85

Calls 6

get_name_decorationFunction · 0.85
diff_get_colorFunction · 0.85
decorate_get_colorFunction · 0.85
current_pointed_by_HEADFunction · 0.85
strbuf_addstrFunction · 0.85
show_nameFunction · 0.70

Tested by

no test coverage detected