Commit Diff


commit - 5faaa590496ab216fcb45ffd1846ff4dc425237f
commit + e9371be612bea2c580aec05a65644f6585e31f42
blob - cd36543257c4022c208f5dd8bcd03686acb074c6
blob + 0b569f983f714418bd0c72d32c121cc4fbdf8676
--- lib/pack_create.c
+++ lib/pack_create.c
@@ -1236,73 +1236,26 @@ done:
 }
 
 static const struct got_error *
-findtwixt(struct got_object_id ***res, int *nres, int *ncolored,
-    struct got_object_id **head, int nhead,
-    struct got_object_id **tail, int ntail,
+color_commits(int *ncolored, struct got_object_id_queue *ids,
+    struct got_object_idset *keep, struct got_object_idset *drop,
     struct got_repository *repo,
     got_pack_progress_cb progress_cb, void *progress_arg,
     struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
 {
 	const struct got_error *err = NULL;
-	struct got_object_id_queue ids;
-	struct got_object_idset *keep, *drop;
+	struct got_commit_object *commit = NULL;
 	struct got_object_qid *qid;
-	int i, ncolor, nkeep;
-
-	STAILQ_INIT(&ids);
-	*res = NULL;
-	*nres = 0;
-	*ncolored = 0;
-
-	keep = got_object_idset_alloc();
-	if (keep == NULL)
-		return got_error_from_errno("got_object_idset_alloc");
-
-	drop = got_object_idset_alloc();
-	if (drop == NULL) {
-		err = got_error_from_errno("got_object_idset_alloc");
-		goto done;
-	}
 
-	for (i = 0; i < nhead; i++) {
-		struct got_object_id *id = head[i];
-		int j, color = COLOR_KEEP;
-
-		if (id == NULL)
-			continue;
-
-		for (j = 0; j < ntail; j++) {
-			if (tail[j] != NULL &&
-			    got_object_id_cmp(id, tail[j]) == 0) {
-				color = COLOR_DROP;
-				break;
-			}
-		}
+	while (!STAILQ_EMPTY(ids)) {
+		int qcolor, ncolor;
 
-		err = queue_commit_or_tag_id(id, color, &ids, repo);
-		if (err)
-			goto done;
-	}		
-
-	for (i = 0; i < ntail; i++) {
-		struct got_object_id *id = tail[i];
-		if (id == NULL)
-			continue;
-		err = queue_commit_or_tag_id(id, COLOR_DROP, &ids, repo);
-		if (err)
-			goto done;
-	}
-
-	while (!STAILQ_EMPTY(&ids)) {
-		int qcolor;
-
 		if (cancel_cb) {
 			err = cancel_cb(cancel_arg);
 			if (err)
-				goto done;
+				break;
 		}
 
-		qid = STAILQ_FIRST(&ids);
+		qid = STAILQ_FIRST(ids);
 		qcolor = *((int *)qid->data);
 
 		if (got_object_idset_contains(drop, qid->id))
@@ -1316,11 +1269,11 @@ findtwixt(struct got_object_id ***res, int *nres, int 
 		err = report_progress(progress_cb, progress_arg, rl,
 		    *ncolored, 0, 0, 0L, 0, 0, 0, 0);
 		if (err)
-			goto done;
+			break;
 
 		if (ncolor == COLOR_DROP || (ncolor == COLOR_KEEP &&
 		    qcolor == COLOR_KEEP)) {
-			STAILQ_REMOVE_HEAD(&ids, entry);
+			STAILQ_REMOVE_HEAD(ids, entry);
 			got_object_qid_free(qid);
 			continue;
 		}
@@ -1329,7 +1282,7 @@ findtwixt(struct got_object_id ***res, int *nres, int 
 			err = drop_commit(keep, drop, qid->id, repo,
 			    cancel_cb, cancel_arg);
 			if (err)
-				goto done;
+				break;
 		} else if (ncolor == COLOR_BLANK) {
 			struct got_commit_object *commit;
 			const struct got_object_id_queue *parents;
@@ -1340,19 +1293,19 @@ findtwixt(struct got_object_id ***res, int *nres, int 
 			else
 				err = got_object_idset_add(drop, qid->id, NULL);
 			if (err)
-				goto done;
+				break;
 
 			err = got_object_open_as_commit(&commit, repo, qid->id);
 			if (err)
-				goto done;
+				break;
 
 			parents = got_object_commit_get_parent_ids(commit);
 			if (parents) {
 				STAILQ_FOREACH(pid, parents, entry) {
-					err = queue_commit_id(&ids, pid->id,
+					err = queue_commit_id(ids, pid->id,
 					    qcolor, repo);
 					if (err)
-						goto done;
+						break;
 				}
 			}
 			got_object_commit_close(commit);
@@ -1361,13 +1314,80 @@ findtwixt(struct got_object_id ***res, int *nres, int 
 			/* should not happen */
 			err = got_error_fmt(GOT_ERR_NOT_IMPL,
 			    "%s ncolor=%d qcolor=%d", __func__, ncolor, qcolor);
-			goto done;
+			break;
 		}
 
-		STAILQ_REMOVE_HEAD(&ids, entry);
+		STAILQ_REMOVE_HEAD(ids, entry);
 		got_object_qid_free(qid);
 	}
 
+	if (commit)
+		got_object_commit_close(commit);
+	return err;
+}
+
+static const struct got_error *
+findtwixt(struct got_object_id ***res, int *nres, int *ncolored,
+    struct got_object_id **head, int nhead,
+    struct got_object_id **tail, int ntail,
+    struct got_repository *repo,
+    got_pack_progress_cb progress_cb, void *progress_arg,
+    struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
+{
+	const struct got_error *err = NULL;
+	struct got_object_id_queue ids;
+	struct got_object_idset *keep, *drop;
+	int i, nkeep;
+
+	STAILQ_INIT(&ids);
+	*res = NULL;
+	*nres = 0;
+	*ncolored = 0;
+
+	keep = got_object_idset_alloc();
+	if (keep == NULL)
+		return got_error_from_errno("got_object_idset_alloc");
+
+	drop = got_object_idset_alloc();
+	if (drop == NULL) {
+		err = got_error_from_errno("got_object_idset_alloc");
+		goto done;
+	}
+
+	for (i = 0; i < nhead; i++) {
+		struct got_object_id *id = head[i];
+		int j, color = COLOR_KEEP;
+
+		if (id == NULL)
+			continue;
+
+		for (j = 0; j < ntail; j++) {
+			if (tail[j] != NULL &&
+			    got_object_id_cmp(id, tail[j]) == 0) {
+				color = COLOR_DROP;
+				break;
+			}
+		}
+
+		err = queue_commit_or_tag_id(id, color, &ids, repo);
+		if (err)
+			goto done;
+	}		
+
+	for (i = 0; i < ntail; i++) {
+		struct got_object_id *id = tail[i];
+		if (id == NULL)
+			continue;
+		err = queue_commit_or_tag_id(id, COLOR_DROP, &ids, repo);
+		if (err)
+			goto done;
+	}
+
+	err = color_commits(ncolored, &ids, keep, drop, repo,
+	    progress_cb, progress_arg, rl, cancel_cb, cancel_arg);
+	if (err)
+		goto done;
+
 	nkeep = got_object_idset_num_elements(keep);
 	if (nkeep > 0) {
 		struct append_id_arg arg;