--- a/ForgeHg/forgehg/model/hg.py
+++ b/ForgeHg/forgehg/model/hg.py
@@ -116,9 +116,7 @@
         if all_commits:
             return list(topological_sort(graph))
         else:
-            return [
-                oid for oid in topological_sort(graph)
-                if M.Commit.query.find(dict(object_id=oid)).count() == 0 ]
+            return M.Commit.unknown_commit_ids_in(topological_sort(graph))
 
     def commit_context(self, commit):
         prev_ids = commit.parent_ids