Commit Diff


commit - 74a2356f3bd54be374a23546704e7ec7c876a247
commit + 9ca9aafb026269aef00e469133fb7d1e3c224952
blob - 70a21a16afc5917f022654870fcc9209079fe86d
blob + 33d4fabb70af7fc3afa0db3fb351ca550a129529
--- include/got_object.h
+++ include/got_object.h
@@ -35,6 +35,13 @@ const struct got_error *got_object_qid_alloc(struct go
 void got_object_qid_free(struct got_object_qid *);
 void got_object_id_queue_free(struct got_object_id_queue *);
 
+/*
+ * Deep-copy elements from ID queue src to ID queue dest. Do not copy any
+ * qid->data pointers! This is the caller's responsibility if needed.
+ */
+const struct got_error *got_object_id_queue_copy(
+    const struct got_object_id_queue *src, struct got_object_id_queue *dest);
+
 /* Object types. */
 #define GOT_OBJ_TYPE_ANY		0 /* wildcard value at run-time */
 #define GOT_OBJ_TYPE_COMMIT		1
blob - d599d8a2df794fac0197af296081abaca81c9eb6
blob + 52d8dac526f9596a3b372685396afc74d8eeea47
--- lib/object.c
+++ lib/object.c
@@ -899,6 +899,30 @@ got_object_qid_alloc(struct got_object_qid **qid, stru
 		got_object_qid_free(*qid);
 		*qid = NULL;
 		return err;
+	}
+
+	return NULL;
+}
+
+const struct got_error *
+got_object_id_queue_copy(const struct got_object_id_queue *src,
+    struct got_object_id_queue *dest)
+{
+	const struct got_error *err;
+	struct got_object_qid *qid;
+
+	SIMPLEQ_FOREACH(qid, src, entry) {
+		struct got_object_qid *new;
+		/*
+		 * Deep-copy the object ID only. Let the caller deal
+		 * with setting up the new->data pointer if needed.
+		 */
+		err = got_object_qid_alloc(&new, qid->id); 
+		if (err) {
+			got_object_id_queue_free(dest);
+			return err;
+		}
+		SIMPLEQ_INSERT_TAIL(dest, new, entry);
 	}
 
 	return NULL;