{"record":{"id":"e186665fe8e8a76f","repo":"theonedev/onedev","slug":"cannot-combine-topo-sort-with-topo-keep-branch-tog","errorCode":null,"errorMessage":"Cannot combine topo sort with topo-keep-branch-together sort.","messagePattern":"Cannot combine topo sort with topo-keep-branch-together sort\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/eclipse/jgit/revwalk/StartGenerator.java","lineNumber":134,"sourceCode":"\t\t} else {\n\t\t\tg = new PendingGenerator(w, pending, rf, pendingOutputType);\n\n\t\t\tif (walker.hasRevSort(RevSort.BOUNDARY)) {\n\t\t\t\t// Because the boundary generator may produce uninteresting\n\t\t\t\t// commits we cannot allow the pending generator to dispose\n\t\t\t\t// of them early.\n\t\t\t\t//\n\t\t\t\t((PendingGenerator) g).canDispose = false;\n\t\t\t}\n\t\t}\n\n\t\tif ((g.outputType() & NEEDS_REWRITE) != 0) {\n\t\t\tg = new RewriteGenerator(g);\n\t\t}\n\n\t\tif (walker.hasRevSort(RevSort.TOPO)\n\t\t\t\t&& walker.hasRevSort(RevSort.TOPO_KEEP_BRANCH_TOGETHER)) {\n\t\t\tthrow new IllegalStateException(JGitText\n\t\t\t\t\t.get().cannotCombineTopoSortWithTopoKeepBranchTogetherSort);\n\t\t}\n\n\t\tif (walker.hasRevSort(RevSort.TOPO)\n\t\t\t\t&& (g.outputType() & SORT_TOPO) == 0) {\n\t\t\tg = new TopoSortGenerator(g);\n\t\t} else if (walker.hasRevSort(RevSort.TOPO_KEEP_BRANCH_TOGETHER)\n\t\t\t\t&& (g.outputType() & SORT_TOPO) == 0) {\n\t\t\tg = new TopoNonIntermixSortGenerator(g);\n\t\t}\n\t\tif (walker.hasRevSort(RevSort.REVERSE))\n\t\t\tg = new LIFORevQueue(g);\n\t\tif (boundary)\n\t\t\tg = new BoundaryGenerator(w, g);\n\t\telse if (uninteresting) {\n\t\t\t// Try to protect ourselves from uninteresting commits producing\n\t\t\t// due to clock skew in the commit time stamps. Delay such that\n\t\t\t// we have a chance at coloring enough of the graph correctly,","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/eclipse/jgit/revwalk/StartGenerator.java#L116-L152","documentation":"Thrown by StartGenerator.next() when the walk's sort order contains both RevSort.TOPO and RevSort.TOPO_KEEP_BRANCH_TOGETHER. These two topological ordering strategies are mutually exclusive; the generator pipeline cannot implement both at once, so JGit throws IllegalStateException when the walk starts.","triggerScenarios":"Calling RevWalk.sort(RevSort.TOPO) and RevWalk.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER) on the same walk, then iterating. Note sort() accumulates flags, so calling both — even conditionally from different code paths — triggers this.","commonSituations":"Merging sort requirements from user-facing options (e.g. '--topo-order' plus a branch-grouping option) into one RevWalk; incremental code that adds sorts without clearing previous ones.","solutions":["Remove one of the two sort(RevSort.TOPO / RevSort.TOPO_KEEP_BRANCH_TOGETHER) calls, keeping only the semantics you need","Reset the walk's sort order (or create a fresh RevWalk) when the desired ordering changes","In user-facing tools, treat the two orderings as mutually exclusive options and reject the combination in configuration parsing"],"exampleFix":"// before\nwalk.sort(RevSort.TOPO);\nwalk.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER);\n// after\nwalk.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER); // implies topological order; drop plain TOPO","handlingStrategy":"validation","validationCode":"if (sorts.contains(RevSort.TOPO) && sorts.contains(RevSort.TOPO_KEEP_BRANCH_TOGETHER)) {\n    throw new IllegalArgumentException(\"Choose either TOPO or TOPO_KEEP_BRANCH_TOGETHER, not both\");\n}","typeGuard":null,"tryCatchPattern":"try (RevWalk walk = new RevWalk(repo)) {\n    ...\n} catch (IllegalStateException e) {\n    // drop one of the sort orders on a fresh walk and retry\n}","preventionTips":["Centralize walk sort configuration in one place so conflicting sorts cannot accumulate","Remember sort() adds flags incrementally; create a new walk when ordering requirements change","In tools, make the two orderings mutually exclusive CLI/UI options"],"tags":["jgit","revwalk","sort-order","illegal-state"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}