Skip to content

Commit aaede5c

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 61e921a commit aaede5c

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
@@ -1353,6 +1353,7 @@ enum get_oid_result {
13531353
};
13541354

13551355
extern int get_oid(const char *str, struct object_id *oid);
1356+
extern int get_oidf(struct object_id *oid, const char *fmt, ...);
13561357
extern int get_oid_commit(const char *str, struct object_id *oid);
13571358
extern int get_oid_committish(const char *str, struct object_id *oid);
13581359
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
@@ -1518,6 +1518,25 @@ int get_oid(const char *name, struct object_id *oid)
15181518
return get_oid_with_context(the_repository, name, 0, oid, &unused);
15191519
}
15201520

1521+
/*
1522+
* This returns a non-zero value if the string (built using printf
1523+
* format and the given arguments) is not a valid object.
1524+
*/
1525+
int get_oidf(struct object_id *oid, const char *fmt, ...)
1526+
{
1527+
va_list ap;
1528+
int ret;
1529+
struct strbuf sb = STRBUF_INIT;
1530+
1531+
va_start(ap, fmt);
1532+
strbuf_vaddf(&sb, fmt, ap);
1533+
va_end(ap);
1534+
1535+
ret = get_oid(sb.buf, oid);
1536+
strbuf_release(&sb);
1537+
1538+
return ret;
1539+
}
15211540

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

0 commit comments

Comments
 (0)