+JobDependency* job_dependency_new(Job *subject, Job *object, bool matters) {
+ JobDependency *l;
+
+ assert(object);
+
+ /* Adds a new job link, which encodes that the 'subject' job
+ * needs the 'object' job in some way. If 'subject' is NULL
+ * this means the 'anchor' job (i.e. the one the user
+ * explcitily asked for) is the requester. */
+
+ if (!(l = new0(JobDependency, 1)))
+ return NULL;
+
+ l->subject = subject;
+ l->object = object;
+ l->matters = matters;
+
+ if (subject) {
+ l->subject_next = subject->subject_list;
+ subject->subject_list = l;
+ } else {
+ l->subject_next = object->manager->transaction_anchor;
+ object->manager->transaction_anchor = l;
+ }
+
+ if (l->subject_next)
+ l->subject_next->subject_prev = l;
+ l->subject_prev = NULL;
+
+ if ((l->object_next = object->object_list))
+ l->object_next->object_prev = l;
+ l->object_prev = NULL;
+ object->object_list = l;
+
+ return l;
+}
+
+void job_dependency_free(JobDependency *l) {
+ assert(l);
+
+ if (l->subject_prev)
+ l->subject_prev->subject_next = l->subject_next;
+ else if (l->subject)
+ l->subject->subject_list = l->subject_next;
+ else
+ l->object->manager->transaction_anchor = l->subject_next;
+
+ if (l->subject_next)
+ l->subject_next->subject_prev = l->subject_prev;
+
+ if (l->object_prev)
+ l->object_prev->object_next = l->object_next;
+ else
+ l->object->object_list = l->object_next;
+
+ if (l->object_next)
+ l->object_next->object_prev = l->object_prev;
+
+ free(l);
+}
+
+void job_dependency_delete(Job *subject, Job *object, bool *matters) {
+ JobDependency *l;
+
+ assert(object);
+
+ for (l = object->object_list; l; l = l->object_next) {
+ assert(l->object == object);
+
+ if (l->subject == subject)
+ break;
+ }
+
+ if (!l) {
+ if (matters)
+ *matters = false;
+ return;
+ }
+
+ if (matters)
+ *matters = l->matters;
+
+ job_dependency_free(l);
+}
+
+void job_dump(Job *j, FILE*f, const char *prefix) {