object-name: introduce `repo_get_oid_with_flags()`

Introduce a new function `repo_get_oid_with_flags()`. This function behaves the same as `repo_get_oid()`, except that it takes an extra `flags` parameter that it ends up passing to `get_oid_with_context()`. This function will be used in a subsequent commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 12, 2025 at 16:56 UTC 37e7546b91fb7d7c263d809dbf7d85831c15cc4f
2 files changed +14 -6
object-name.c
+8 -6
@@ -1794,18 +1794,20 @@ void object_context_release(struct object_context *ctx)
1794 strbuf_release(&ctx->symlink_path);
1795 }
1796
1797 -/*
1798 - * This is like "get_oid_basic()", except it allows "object ID expressions",
1799 - * notably "xyz^" for "parent of xyz"
1800 - */
1801 -int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
1797 +int repo_get_oid_with_flags(struct repository *r, const char *name,
1798 + struct object_id *oid, unsigned flags)
1799 {
1800 struct object_context unused;
1804 - int ret = get_oid_with_context(r, name, 0, oid, &unused);
1801 + int ret = get_oid_with_context(r, name, flags, oid, &unused);
1802 object_context_release(&unused);
1803 return ret;
1804 }
1805
1806 +int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
1807 +{
1808 + return repo_get_oid_with_flags(r, name, oid, 0);
1809 +}
1810 +
1811 /*
1812 * This returns a non-zero value if the string (built using printf
1813 * format and the given arguments) is not a valid object.
object-name.h
+6
@@ -51,6 +51,12 @@ void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
51 void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
52 int abbrev_len);
53
54 +/*
55 + * This is like "get_oid_basic()", except it allows "object ID expressions",
56 + * notably "xyz^" for "parent of xyz". Accepts GET_OID_* flags.
57 + */
58 +int repo_get_oid_with_flags(struct repository *r, const char *str,
59 + struct object_id *oid, unsigned flags);
60 int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
61 __attribute__((format (printf, 2, 3)))
62 int get_oidf(struct object_id *oid, const char *fmt, ...);