]> granicus.if.org Git - git/commitdiff
sha1-name.c: add `get_oidf()` which acts like `get_oid()`
authorPaul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Mon, 25 Feb 2019 23:16:05 +0000 (23:16 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Feb 2019 23:03:46 +0000 (08:03 +0900)
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>
cache.h
sha1-name.c

diff --git a/cache.h b/cache.h
index ca36b44ee0b5851f837616c322a201ac420a90d2..7b6b89fc4c0c285efb29265c5ae10a01d80ffcbf 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1333,6 +1333,7 @@ struct object_context {
        GET_OID_BLOB)
 
 extern int get_oid(const char *str, struct object_id *oid);
+extern int get_oidf(struct object_id *oid, const char *fmt, ...);
 extern int get_oid_commit(const char *str, struct object_id *oid);
 extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
index faa60f69e311f5f09cd5b91a8fbbaf3e3e744ab0..cf0e8a3f85f6f0d72cb54a75221dd80fdc533a89 100644 (file)
@@ -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