Commit Diff


commit - 1accf02b5869ef6a1d4ec4fc3f7a1bdb6e4ff93b
commit + 32c85d2cf904f18a4a3090ec5e66c40d94ee64d0
blob - 51276fea65a8e55f42f4dfaa63fe70f9ddabf7d4
blob + d2d7bd81d20a0bc7fb36411f186d28e28e4ce1e5
--- lib/commit_graph.c
+++ lib/commit_graph.c
@@ -164,12 +164,27 @@ add_node_to_iter_list(struct got_commit_graph *graph,
 }
 
 static const struct got_error *
+close_branch(struct got_commit_graph *graph, struct got_object_id *commit_id)
+{
+	const struct got_error *err;
+
+	err = got_object_idset_remove(NULL, graph->open_branches, commit_id);
+	if (err && err->code != GOT_ERR_NO_OBJ)
+		return err;
+	return NULL;
+}
+
+static const struct got_error *
 advance_branch(struct got_commit_graph *graph, struct got_object_id *commit_id,
     struct got_commit_object *commit, struct got_repository *repo)
 {
 	const struct got_error *err;
 	struct got_object_qid *qid;
 
+	err = close_branch(graph, commit_id);
+	if (err)
+		return err;
+
 	if (graph->flags & GOT_COMMIT_GRAPH_FIRST_PARENT_TRAVERSAL) {
 		qid = SIMPLEQ_FIRST(&commit->parent_ids);
 		if (qid == NULL ||
@@ -414,11 +429,6 @@ fetch_commits_from_open_branches(struct got_commit_gra
 		commit = arg.tips[i].commit;
 		new_node = arg.tips[i].new_node;
 
-		err = got_object_idset_remove(NULL, graph->open_branches,
-		    commit_id);
-		if (err && err->code != GOT_ERR_NO_OBJ)
-			break;
-
 		err = detect_changed_path(&changed, commit, commit_id,
 		    graph->path, repo);
 		if (err) {
@@ -428,6 +438,9 @@ fetch_commits_from_open_branches(struct got_commit_gra
 			 * History of the path stops here on the current
 			 * branch. Keep going on other branches.
 			 */
+			err = close_branch(graph, commit_id);
+			if (err)
+				break;
 			continue;
 		}
 		if (changed)