sha1-name.c: add `get_oidf()` which acts like `get_oid()`

Compared to `get_oid()`, `get_oidf()` has as parameters a pointer to `object_id`, a printf format string and additional arguments. This will help simplify the code in subsequent commits. Original-idea-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul-Sebastian Ungureanu committed Feb 25, 2019 at 23:16 UTC f5116f43f69720059375059311485d99c462551b
2 files changed +20
cache.h
+1
@@ -1333,6 +1333,7 @@ struct object_context {
1333 GET_OID_BLOB)
1334
1335 extern int get_oid(const char *str, struct object_id *oid);
1336 +extern int get_oidf(struct object_id *oid, const char *fmt, ...);
1337 extern int get_oid_commit(const char *str, struct object_id *oid);
1338 extern int get_oid_committish(const char *str, struct object_id *oid);
1339 extern int get_oid_tree(const char *str, struct object_id *oid);
sha1-name.c
+19
@@ -1542,6 +1542,25 @@ int get_oid(const char *name, struct object_id *oid)
1542 return get_oid_with_context(name, 0, oid, &unused);
1543 }
1544
1545 +/*
1546 + * This returns a non-zero value if the string (built using printf
1547 + * format and the given arguments) is not a valid object.
1548 + */
1549 +int get_oidf(struct object_id *oid, const char *fmt, ...)
1550 +{
1551 + va_list ap;
1552 + int ret;
1553 + struct strbuf sb = STRBUF_INIT;
1554 +
1555 + va_start(ap, fmt);
1556 + strbuf_vaddf(&sb, fmt, ap);
1557 + va_end(ap);
1558 +
1559 + ret = get_oid(sb.buf, oid);
1560 + strbuf_release(&sb);
1561 +
1562 + return ret;
1563 +}
1564
1565 /*
1566 * Many callers know that the user meant to name a commit-ish by