int i;
for (i = 0; i < array->nr; i++) {
- strbuf_addstr(&joined_hexs, oid_to_hex(array->oid + i));
+ strbuf_add_oid_hex(&joined_hexs, array->oid + i);
if (i + 1 < array->nr)
strbuf_addch(&joined_hexs, delim);
}
if (!repo_get_oid(the_repository, head, &head_oid) &&
!starts_with(head, "refs/heads/")) {
strbuf_reset(&start_head);
- strbuf_addstr(&start_head, oid_to_hex(&head_oid));
+ strbuf_add_oid_hex(&start_head, &head_oid);
} else if (!repo_get_oid(the_repository, head, &head_oid) &&
skip_prefix(head, "refs/heads/", &head)) {
strbuf_addstr(&start_head, head);
{
if (is_atom("objectname", atom, len)) {
if (!data->mark_query)
- strbuf_addstr(sb, oid_to_hex(&data->oid));
+ strbuf_add_oid_hex(sb, &data->oid);
} else if (is_atom("objecttype", atom, len)) {
if (data->mark_query)
data->info.typep = &data->type;
if (data->mark_query)
data->info.delta_base_oid = &data->delta_base_oid;
else
- strbuf_addstr(sb,
- oid_to_hex(&data->delta_base_oid));
+ strbuf_add_oid_hex(sb, &data->delta_base_oid);
} else if (is_atom("objectmode", atom, len)) {
if (!data->mark_query && !(S_IFINVALID == data->mode))
strbuf_addf(sb, "%06o", data->mode);
}
strbuf_setlen(&ref, base_len);
- strbuf_addstr(&ref, oid_to_hex(&oid));
+ strbuf_add_oid_hex(&ref, &oid);
full_hex = ref.buf + base_len;
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &oid)) {
/* step 4: substitute */
strbuf_addstr(buf, "Id: ");
- strbuf_addstr(buf, oid_to_hex(&oid));
+ strbuf_add_oid_hex(buf, &oid);
strbuf_addstr(buf, " $");
}
strbuf_add(buf, src, len);
buf = bufs + b;
b = (b + 1) % ARRAY_SIZE(bufs);
strbuf_reset(buf);
- strbuf_addstr(buf, oid_to_hex(oid));
+ strbuf_add_oid_hex(buf, oid);
if (name)
strbuf_addf(buf, " (%s)", name);
#include "git-compat-util.h"
#include "hash.h"
#include "hex.h"
+#include "strbuf.h"
static int get_hash_hex_algop(const char *hex, unsigned char *hash,
const struct git_hash_algo *algop)
{
return hash_to_hex_algop(oid->hash, &hash_algos[oid->algo]);
}
+
+void strbuf_add_oid_hex(struct strbuf *sb, const struct object_id *oid)
+{
+ const struct git_hash_algo *algop = oid->algo ?
+ &hash_algos[oid->algo] : the_hash_algo;
+ strbuf_grow(sb, algop->hexsz);
+ hash_to_hex_algop_r(sb->buf + sb->len, oid->hash, algop);
+ strbuf_setlen(sb, sb->len + algop->hexsz);
+}
char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */
char *oid_to_hex(const struct object_id *oid); /* same static buffer */
+struct strbuf;
+
+/* Apply oid_to_hex_r() to a strbuf to append the hexadecimal hash. */
+void strbuf_add_oid_hex(struct strbuf *sb, const struct object_id *oid);
+
/*
* Parse a 40-character hexadecimal object ID starting from hex, updating the
* pointer specified by end when parsing stops. The resulting object ID is
if (pp->abbrev)
strbuf_add_unique_abbrev(sb, oidp, pp->abbrev);
else
- strbuf_addstr(sb, oid_to_hex(oidp));
+ strbuf_add_oid_hex(sb, oidp);
parent = parent->next;
}
strbuf_addch(sb, '\n');
switch (placeholder[0]) {
case 'H': /* commit hash */
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
- strbuf_addstr(sb, oid_to_hex(&commit->object.oid));
+ strbuf_add_oid_hex(sb, &commit->object.oid);
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
return 1;
case 'h': /* abbreviated commit hash */
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
return 1;
case 'T': /* tree hash */
- strbuf_addstr(sb, oid_to_hex(get_commit_tree_oid(commit)));
+ strbuf_add_oid_hex(sb, get_commit_tree_oid(commit));
return 1;
case 't': /* abbreviated tree hash */
strbuf_add_unique_abbrev(sb,
for (p = commit->parents; p; p = p->next) {
if (p != commit->parents)
strbuf_addch(sb, ' ');
- strbuf_addstr(sb, oid_to_hex(&p->item->object.oid));
+ strbuf_add_oid_hex(sb, &p->item->object.oid);
}
return 1;
case 'p': /* abbreviated parent hashes */
if (referent && refs_read_symbolic_ref(refs, ref, referent) == NOT_A_SYMREF) {
struct object_id oid;
if (!refs_read_ref(refs, ref, &oid)) {
- strbuf_addstr(referent, oid_to_hex(&oid));
+ strbuf_add_oid_hex(referent, &oid);
ret = NOT_A_SYMREF;
}
}
repo_format_commit_message(r, commit,
"%h (%s, %ad)", msgbuf, &ctx);
} else {
- strbuf_addstr(msgbuf, oid_to_hex(&commit->object.oid));
+ strbuf_add_oid_hex(msgbuf, &commit->object.oid);
}
}
if (!has_conforming_footer(&ctx->message, NULL, 0))
strbuf_addch(&ctx->message, '\n');
strbuf_addstr(&ctx->message, cherry_picked_prefix);
- strbuf_addstr(&ctx->message, oid_to_hex(&commit->object.oid));
+ strbuf_add_oid_hex(&ctx->message, &commit->object.oid);
strbuf_addstr(&ctx->message, ")\n");
}
if (!is_fixup(command))
if (!extra)
return data.count;
for (size_t i = 0; i < extra->nr; i++) {
- strbuf_addstr(out, oid_to_hex(extra->oid + i));
+ strbuf_add_oid_hex(out, extra->oid + i);
strbuf_addch(out, '\n');
data.count++;
}
@@
- SB.buf ? SB.buf : ""
+ SB.buf
+
+@@
+expression SB, OID;
+@@
+- strbuf_addstr(SB, oid_to_hex(OID))
++ strbuf_add_oid_hex(SB, OID)
if (ref->peer_ref)
strbuf_addstr(&buf, ref->peer_ref->name);
else
- strbuf_addstr(&buf, oid_to_hex(&ref->new_oid));
+ strbuf_add_oid_hex(&buf, &ref->new_oid);
}
strbuf_addch(&buf, ':');
strbuf_addstr(&buf, ref->name);