Skip to content

Commit 9eb54eb

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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27e3e78 commit 9eb54eb

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
@@ -1333,6 +1333,7 @@ struct object_context {
13331333
GET_OID_BLOB)
13341334

13351335
extern int get_oid(const char *str, struct object_id *oid);
1336+
extern int get_oidf(struct object_id *oid, const char *fmt, ...);
13361337
extern int get_oid_commit(const char *str, struct object_id *oid);
13371338
extern int get_oid_committish(const char *str, struct object_id *oid);
13381339
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
@@ -1542,6 +1542,25 @@ int get_oid(const char *name, struct object_id *oid)
15421542
return get_oid_with_context(name, 0, oid, &unused);
15431543
}
15441544

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+
}
15451564

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

0 commit comments

Comments
 (0)