Commit Diff


commit - 1ab61ced3b985960fcf0256e1720fb712311aeb7
commit + aaf883177f27944f273eed3ea7cbe43075bb2741
blob - 019df06a6d16642bb74799bcec1df6d150cd3e99
blob + 15b4fba814f8f4788dc23ebe8ffa7dda85a44409
--- include/got_reference.h
+++ include/got_reference.h
@@ -43,12 +43,22 @@ const struct got_error *got_ref_open(struct got_refere
 const struct got_error *got_ref_alloc(struct got_reference **, const char *,
     struct got_object_id *);
 
+/*
+ * Allocate a new symbolic reference which points at a given reference.
+ * The caller must dispose of it with got_ref_close().
+ */
+const struct got_error *got_ref_alloc_symref(struct got_reference **,
+    const char *, 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 *);
 
+/* Get the name of the reference which a symoblic reference points at. */
+const char *got_ref_get_symref_target(struct got_reference *);
+
 /*
  * Create a duplicate copy of a reference.
  * The caller must dispose of this copy with got_ref_close().
blob - e572d687ec4e83e49ea1d418f2c5a61f9f67cc3e
blob + 6e1854a1044f6cceef1100295b634fdfd3a5a625
--- lib/reference.c
+++ lib/reference.c
@@ -294,6 +294,16 @@ got_ref_alloc(struct got_reference **ref, const char *
 		return got_error(GOT_ERR_BAD_REF_NAME);
 
 	return alloc_ref(ref, name, id, 0);
+}
+
+const struct got_error *
+got_ref_alloc_symref(struct got_reference **ref, const char *name,
+	struct got_reference *target_ref)
+{
+	if (!is_valid_ref_name(name))
+		return got_error(GOT_ERR_BAD_REF_NAME);
+
+	return alloc_symref(ref, name, got_ref_get_name(target_ref), 0);
 }
 
 static const struct got_error *
@@ -599,6 +609,15 @@ got_ref_get_name(struct got_reference *ref)
 	return ref->ref.ref.name;
 }
 
+const char *
+got_ref_get_symref_target(struct got_reference *ref)
+{
+	if (ref->flags & GOT_REF_IS_SYMBOLIC)
+		return ref->ref.symref.ref;
+
+	return NULL;
+}
+
 static const struct got_error *
 insert_ref(struct got_reflist_entry **newp, struct got_reflist_head *refs,
     struct got_reference *ref, struct got_repository *repo)