summaryrefslogtreecommitdiff
path: root/sha1-name.c
diff options
context:
space:
mode:
authorPaul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>2019-02-25 23:16:05 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-02-28 23:03:46 (GMT)
commitf5116f43f69720059375059311485d99c462551b (patch)
treec6568906ccd64e06db803295ab9b788d3e8a6fa1 /sha1-name.c
parenteacdb4d2f4895b1fe5aa7e745a5559571f3f6b06 (diff)
downloadgit-f5116f43f69720059375059311485d99c462551b.zip
git-f5116f43f69720059375059311485d99c462551b.tar.gz
git-f5116f43f69720059375059311485d99c462551b.tar.bz2
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>
Diffstat (limited to 'sha1-name.c')
-rw-r--r--sha1-name.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/sha1-name.c b/sha1-name.c
index faa60f6..cf0e8a3 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1542,6 +1542,25 @@ int get_oid(const char *name, struct object_id *oid)
return get_oid_with_context(name, 0, oid, &unused);
}
+/*
+ * This returns a non-zero value if the string (built using printf
+ * format and the given arguments) is not a valid object.
+ */
+int get_oidf(struct object_id *oid, const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+ struct strbuf sb = STRBUF_INIT;
+
+ va_start(ap, fmt);
+ strbuf_vaddf(&sb, fmt, ap);
+ va_end(ap);
+
+ ret = get_oid(sb.buf, oid);
+ strbuf_release(&sb);
+
+ return ret;
+}
/*
* Many callers know that the user meant to name a commit-ish by