Commit 0bd18d379f824371c6439f6c6d72b23c4169d99c

Stefan Sperling 2019-02-01T22:16:47

add potentially useful helpers for tag objects and refs

diff --git a/include/got_object.h b/include/got_object.h
index 04fbd07..33e4a1a 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -219,5 +219,14 @@ const struct got_error *got_object_open_as_tag(struct got_tag_object **,
 /* Dispose of a tag object. */
 void got_object_tag_close(struct got_tag_object *);
 
+/* Get type of the object a tag points to. */
+int got_object_tag_get_object_type(struct got_tag_object *);
+
+/*
+ * Get ID of the object a tag points to.
+ * This must not be freed by the caller. Use got_object_id_dup() if needed.
+ */
+struct got_object_id *got_object_tag_get_object_id(struct got_tag_object *);
+
 const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
     const char *);
diff --git a/include/got_reference.h b/include/got_reference.h
index 677800f..3845b3e 100644
--- a/include/got_reference.h
+++ b/include/got_reference.h
@@ -36,6 +36,9 @@ const struct got_error * got_ref_open(struct got_reference **,
 /* Dispose of a reference. */
 void got_ref_close(struct got_reference *);
 
+/* Get the name of the reference. */
+const char *got_ref_get_name(struct got_reference *);
+
 /*
  * Create a duplicate copy of a reference.
  * The caller must dispose of this copy with got_ref_close().
diff --git a/lib/object.c b/lib/object.c
index c2649fd..7857608 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1324,6 +1324,18 @@ got_object_tag_open(struct got_tag_object **tag,
 	return open_tag(tag, repo, got_object_get_id(obj), 1);
 }
 
+int
+got_object_tag_get_object_type(struct got_tag_object *tag)
+{
+	return tag->obj_type;
+}
+
+struct got_object_id *
+got_object_tag_get_object_id(struct got_tag_object *tag)
+{
+	return &tag->id;
+}
+
 static struct got_tree_entry *
 find_entry_by_name(struct got_tree_object *tree, const char *name, size_t len)
 {
diff --git a/lib/reference.c b/lib/reference.c
index c270896..b10ac6f 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -416,3 +416,12 @@ got_ref_to_str(struct got_reference *ref)
 
 	return str;
 }
+
+const char *
+got_ref_get_name(struct got_reference *ref)
+{
+	if (ref->flags & GOT_REF_IS_SYMBOLIC)
+		return ref->ref.symref.name;
+
+	return ref->ref.ref.name;
+}