Skip to content

Commit ab992eb

Browse files
ungpsdscho
authored andcommitted
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 <[email protected]> Signed-off-by: Paul-Sebastian Ungureanu <[email protected]>
1 parent 0d438c7 commit ab992eb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ struct object_context {
13191319
GET_OID_BLOB)
13201320

13211321
extern int get_oid(const char *str, struct object_id *oid);
1322+
extern int get_oidf(struct object_id *oid, const char *fmt, ...);
13221323
extern int get_oid_commit(const char *str, struct object_id *oid);
13231324
extern int get_oid_committish(const char *str, struct object_id *oid);
13241325
extern int get_oid_tree(const char *str, struct object_id *oid);

sha1-name.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,25 @@ int get_oid(const char *name, struct object_id *oid)
14711471
return get_oid_with_context(name, 0, oid, &unused);
14721472
}
14731473

1474+
/*
1475+
* This returns a non-zero value if the string (built using printf
1476+
* format and the given arguments) is not a valid object.
1477+
*/
1478+
int get_oidf(struct object_id *oid, const char *fmt, ...)
1479+
{
1480+
va_list ap;
1481+
int ret;
1482+
struct strbuf sb = STRBUF_INIT;
1483+
1484+
va_start(ap, fmt);
1485+
strbuf_vaddf(&sb, fmt, ap);
1486+
va_end(ap);
1487+
1488+
ret = get_oid(sb.buf, oid);
1489+
strbuf_release(&sb);
1490+
1491+
return ret;
1492+
}
14741493

14751494
/*
14761495
* Many callers know that the user meant to name a commit-ish by

0 commit comments

Comments
 (0)