/* * The caller makes sure there is no funny color before * calling. format_decorations makes sure the same after return. */ void format_decorations(struct strbuf *sb, const struct commit *commit, int use_color) { const char *prefix; struct name_decoration *decoration; const char *color_commit = diff_get_color(use_color, DIFF_COMMIT); const char *color_reset = decorate_get_color(use_color, DECORATION_NONE); decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; prefix = " ("; while (decoration) { strbuf_addstr(sb, color_commit); strbuf_addstr(sb, prefix); strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); if (decoration->type == DECORATION_REF_TAG) strbuf_addstr(sb, "tag: "); strbuf_addstr(sb, decoration->name); strbuf_addstr(sb, color_reset); prefix = ", "; decoration = decoration->next; } strbuf_addstr(sb, color_commit); strbuf_addch(sb, ')'); strbuf_addstr(sb, color_reset); }
static int get_object_mark(struct object *object) { void *decoration = lookup_decoration(&idnums, object); if (!decoration) return 0; return ptr_to_mark(decoration); }
static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct commit *commit) { struct tree *t1 = parent->tree; struct tree *t2 = commit->tree; if (!t1) return REV_TREE_NEW; if (!t2) return REV_TREE_OLD; if (revs->simplify_by_decoration) { /* * If we are simplifying by decoration, then the commit * is worth showing if it has a tag pointing at it. */ if (lookup_decoration(&name_decoration, &commit->object)) return REV_TREE_DIFFERENT; /* * A commit that is not pointed by a tag is uninteresting * if we are not limited by path. This means that you will * see the usual "commits that touch the paths" plus any * tagged commit by specifying both --simplify-by-decoration * and pathspec. */ if (!revs->prune_data) return REV_TREE_SAME; } tree_difference = REV_TREE_SAME; DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES); if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "", &revs->pruning) < 0) return REV_TREE_DIFFERENT; return tree_difference; }
static void show_children(struct rev_info *opt, struct commit *commit, int abbrev) { struct commit_list *p = lookup_decoration(&opt->children, &commit->object); for ( ; p; p = p->next) { printf(" %s", find_unique_abbrev(p->item->object.sha1, abbrev)); } }
void show_decorations(struct rev_info *opt, struct commit *commit) { const char *prefix; struct name_decoration *decoration; const char *color_commit = diff_get_color_opt(&opt->diffopt, DIFF_COMMIT); const char *color_reset = decorate_get_color_opt(&opt->diffopt, DECORATION_NONE); if (opt->show_source && commit->util) printf("\t%s", (char *) commit->util); if (!opt->show_decorations) return; decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; prefix = " ("; while (decoration) { printf("%s", prefix); fputs(decorate_get_color_opt(&opt->diffopt, decoration->type), stdout); if (decoration->type == DECORATION_REF_TAG) fputs("tag: ", stdout); printf("%s", decoration->name); fputs(color_reset, stdout); fputs(color_commit, stdout); prefix = ", "; decoration = decoration->next; } putchar(')'); }
static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs, struct commit *commit) { struct merge_simplify_state *st; st = lookup_decoration(&revs->merge_simplification, &commit->object); if (!st) { st = xcalloc(1, sizeof(*st)); add_decoration(&revs->merge_simplification, &commit->object, st); } return st; }
static const char *describe_object(struct fsck_options *o, struct object *obj) { static struct strbuf buf = STRBUF_INIT; char *name; strbuf_reset(&buf); strbuf_addstr(&buf, oid_to_hex(&obj->oid)); if (o->object_names && (name = lookup_decoration(o->object_names, obj))) strbuf_addf(&buf, " (%s)", name); return buf.buf; }
static const char *describe_object(struct object *obj) { static struct strbuf buf = STRBUF_INIT; char *name = name_objects ? lookup_decoration(fsck_walk_options.object_names, obj) : NULL; strbuf_reset(&buf); strbuf_addstr(&buf, oid_to_hex(&obj->oid)); if (name) strbuf_addf(&buf, " (%s)", name); return buf.buf; }
/* * We pass blame from the current commit to its parents. We keep saying * "parent" (and "porigin"), but what we mean is to find scapegoat to * exonerate ourselves. */ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit *commit, int reverse) { if (!reverse) { if (revs->first_parent_only && commit->parents && commit->parents->next) { free_commit_list(commit->parents->next); commit->parents->next = NULL; } return commit->parents; } return lookup_decoration(&revs->children, &commit->object); }
static void format_decoration(struct strbuf *sb, const struct commit *commit) { struct name_decoration *d; const char *prefix = " ("; load_ref_decorations(DECORATE_SHORT_REFS); d = lookup_decoration(&name_decoration, &commit->object); while (d) { strbuf_addstr(sb, prefix); prefix = ", "; strbuf_addstr(sb, d->name); d = d->next; } if (prefix[0] == ',') strbuf_addch(sb, ')'); }
static void put_object_name(struct fsck_options *options, struct object *obj, const char *fmt, ...) { va_list ap; struct strbuf buf = STRBUF_INIT; char *existing; if (!options->object_names) return; existing = lookup_decoration(options->object_names, obj); if (existing) return; va_start(ap, fmt); strbuf_vaddf(&buf, fmt, ap); add_decoration(options->object_names, obj, strbuf_detach(&buf, NULL)); va_end(ap); }
void show_commit_decorations(struct commit *commit) { struct name_decoration *deco; static char buf[1024]; buf[sizeof(buf) - 1] = 0; deco = lookup_decoration(&name_decoration, &commit->object); html("<span class='decoration'>"); while (deco) { if (!prefixcmp(deco->name, "refs/heads/")) { strncpy(buf, deco->name + 11, sizeof(buf) - 1); cgit_log_link(buf, NULL, "branch-deco", buf, NULL, ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); } else if (!prefixcmp(deco->name, "tag: refs/tags/")) { strncpy(buf, deco->name + 15, sizeof(buf) - 1); cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); } else if (!prefixcmp(deco->name, "refs/tags/")) { strncpy(buf, deco->name + 10, sizeof(buf) - 1); cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); } else if (!prefixcmp(deco->name, "refs/remotes/")) { if (!ctx.repo->enable_remote_branches) goto next; strncpy(buf, deco->name + 13, sizeof(buf) - 1); cgit_log_link(buf, NULL, "remote-deco", NULL, sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg); } else { strncpy(buf, deco->name, sizeof(buf) - 1); cgit_commit_link(buf, NULL, "deco", ctx.qry.head, sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); } next: deco = deco->next; } html("</span>"); }
void show_decorations(struct rev_info *opt, struct commit *commit) { const char *prefix; struct name_decoration *decoration; if (opt->show_source && commit->util) printf("\t%s", (char *) commit->util); if (!opt->show_decorations) return; decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; prefix = " ("; while (decoration) { printf("%s%s", prefix, decoration->name); prefix = ", "; decoration = decoration->next; } putchar(')'); }
static void show_commit(struct commit *commit, void *data) { struct rev_list_info *info = data; struct rev_info *revs = info->revs; graph_show_commit(revs->graph); if (info->show_timestamp) printf("%lu ", commit->date); if (info->header_prefix) fputs(info->header_prefix, stdout); if (!revs->graph) { if (commit->object.flags & BOUNDARY) putchar('-'); else if (commit->object.flags & UNINTERESTING) putchar('^'); else if (revs->left_right) { if (commit->object.flags & SYMMETRIC_LEFT) putchar('<'); else putchar('>'); } } if (revs->abbrev_commit && revs->abbrev) fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev), stdout); else fputs(sha1_to_hex(commit->object.sha1), stdout); if (revs->print_parents) { struct commit_list *parents = commit->parents; while (parents) { printf(" %s", sha1_to_hex(parents->item->object.sha1)); parents = parents->next; } } if (revs->children.name) { struct commit_list *children; children = lookup_decoration(&revs->children, &commit->object); while (children) { printf(" %s", sha1_to_hex(children->item->object.sha1)); children = children->next; } } show_decorations(revs, commit); if (revs->commit_format == CMIT_FMT_ONELINE) putchar(' '); else putchar('\n'); if (revs->verbose_header && commit->buffer) { struct strbuf buf = STRBUF_INIT; struct pretty_print_context ctx = {0}; ctx.abbrev = revs->abbrev; ctx.date_mode = revs->date_mode; pretty_print_commit(revs->commit_format, commit, &buf, &ctx); if (revs->graph) { if (buf.len) { if (revs->commit_format != CMIT_FMT_ONELINE) graph_show_oneline(revs->graph); graph_show_commit_msg(revs->graph, &buf); /* * Add a newline after the commit message. * * Usually, this newline produces a blank * padding line between entries, in which case * we need to add graph padding on this line. * * However, the commit message may not end in a * newline. In this case the newline simply * ends the last line of the commit message, * and we don't need any graph output. (This * always happens with CMIT_FMT_ONELINE, and it * happens with CMIT_FMT_USERFORMAT when the * format doesn't explicitly end in a newline.) */ if (buf.len && buf.buf[buf.len - 1] == '\n') graph_show_padding(revs->graph); putchar('\n'); } else { /* * If the message buffer is empty, just show * the rest of the graph output for this * commit. */ if (graph_show_remainder(revs->graph)) putchar('\n'); } } else { if (buf.len) printf("%s%c", buf.buf, info->hdr_termination); } strbuf_release(&buf); } else { if (graph_show_remainder(revs->graph)) putchar('\n'); } maybe_flush_or_die(stdout, "stdout"); finish_commit(commit, data); }
const struct name_decoration *get_name_decoration(const struct object *obj) { return lookup_decoration(&name_decoration, obj); }
static void show_commit(struct commit *commit, void *data) { struct rev_list_info *info = data; struct rev_info *revs = info->revs; display_progress(progress, ++progress_counter); if (info->flags & REV_LIST_QUIET) { finish_commit(commit, data); return; } graph_show_commit(revs->graph); if (revs->count) { if (commit->object.flags & PATCHSAME) revs->count_same++; else if (commit->object.flags & SYMMETRIC_LEFT) revs->count_left++; else revs->count_right++; finish_commit(commit, data); return; } if (info->show_timestamp) printf("%"PRItime" ", commit->date); if (info->header_prefix) fputs(info->header_prefix, stdout); if (!revs->graph) fputs(get_revision_mark(revs, commit), stdout); if (revs->abbrev_commit && revs->abbrev) fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev), stdout); else fputs(oid_to_hex(&commit->object.oid), stdout); if (revs->print_parents) { struct commit_list *parents = commit->parents; while (parents) { printf(" %s", oid_to_hex(&parents->item->object.oid)); parents = parents->next; } } if (revs->children.name) { struct commit_list *children; children = lookup_decoration(&revs->children, &commit->object); while (children) { printf(" %s", oid_to_hex(&children->item->object.oid)); children = children->next; } } show_decorations(revs, commit); if (revs->commit_format == CMIT_FMT_ONELINE) putchar(' '); else putchar('\n'); if (revs->verbose_header && get_cached_commit_buffer(commit, NULL)) { struct strbuf buf = STRBUF_INIT; struct pretty_print_context ctx = {0}; ctx.abbrev = revs->abbrev; ctx.date_mode = revs->date_mode; ctx.date_mode_explicit = revs->date_mode_explicit; ctx.fmt = revs->commit_format; ctx.output_encoding = get_log_output_encoding(); ctx.color = revs->diffopt.use_color; pretty_print_commit(&ctx, commit, &buf); if (buf.len) { if (revs->commit_format != CMIT_FMT_ONELINE) graph_show_oneline(revs->graph); graph_show_commit_msg(revs->graph, stdout, &buf); /* * Add a newline after the commit message. * * Usually, this newline produces a blank * padding line between entries, in which case * we need to add graph padding on this line. * * However, the commit message may not end in a * newline. In this case the newline simply * ends the last line of the commit message, * and we don't need any graph output. (This * always happens with CMIT_FMT_ONELINE, and it * happens with CMIT_FMT_USERFORMAT when the * format doesn't explicitly end in a newline.) */ if (buf.len && buf.buf[buf.len - 1] == '\n') graph_show_padding(revs->graph); putchar(info->hdr_termination); } else { /* * If the message buffer is empty, just show * the rest of the graph output for this * commit. */ if (graph_show_remainder(revs->graph)) putchar('\n'); if (revs->commit_format == CMIT_FMT_ONELINE) putchar('\n'); } strbuf_release(&buf); } else { if (graph_show_remainder(revs->graph)) putchar('\n'); } maybe_flush_or_die(stdout, "stdout"); finish_commit(commit, data); }
static struct obj_buffer *lookup_object_buffer(struct object *base) { return lookup_decoration(&obj_decorate, base); }
static char *get_object_name(struct fsck_options *options, struct object *obj) { if (!options->object_names) return NULL; return lookup_decoration(options->object_names, obj); }