int not_pushed(struct commit *current_head){ struct commit *remote_head; unsigned char sha1[20]; const struct name_decoration decoration; int decoration_style=1; if (decoration_style) { load_ref_decorations(decoration_style); } decoration = get_name_decoration(¤t_head->object); const char* upstream = (branch_get(NULL)->merge)?branch_get(NULL)->merge[0]->dst : NULL; if (upstream==NULL) return (int)true; if (get_sha1(upstream, sha1)) remote_head = NULL; else { remote_head = lookup_commit_or_die(sha1, upstream); if (parse_commit(remote_head)) die(_("could not parse remote head commit")); } struct commit *old_ci=remote_head,*new_ci=current_head; if (old_ci->date > new_ci->date){ struct commit *tmp = old_ci; old_ci=new_ci; new_ci=tmp; } }
/* * 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; const 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 = get_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); }
/* * The caller makes sure there is no funny color before calling. * format_decorations_extended makes sure the same after return. */ void format_decorations_extended(struct strbuf *sb, const struct commit *commit, int use_color, const char *prefix, const char *separator, const char *suffix) { const struct name_decoration *decoration; const struct name_decoration *current_and_HEAD; const char *color_commit = diff_get_color(use_color, DIFF_COMMIT); const char *color_reset = decorate_get_color(use_color, DECORATION_NONE); decoration = get_name_decoration(&commit->object); if (!decoration) return; current_and_HEAD = current_pointed_by_HEAD(decoration); while (decoration) { /* * When both current and HEAD are there, only * show HEAD->current where HEAD would have * appeared, skipping the entry for current. */ if (decoration != current_and_HEAD) { strbuf_addstr(sb, color_commit); strbuf_addstr(sb, prefix); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); if (decoration->type == DECORATION_REF_TAG) strbuf_addstr(sb, "tag: "); show_name(sb, decoration); if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { strbuf_addstr(sb, color_reset); strbuf_addstr(sb, color_commit); strbuf_addstr(sb, " -> "); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); show_name(sb, current_and_HEAD); } strbuf_addstr(sb, color_reset); prefix = separator; } decoration = decoration->next; } strbuf_addstr(sb, color_commit); strbuf_addstr(sb, suffix); strbuf_addstr(sb, color_reset); }