Using continues to reduce nesting
This commit is contained in:
65
app.ts
65
app.ts
@@ -71,9 +71,8 @@ const getCommitsForBranch = async (branch: string): Promise<Set<string>> => {
|
|||||||
const removeIgnoredBranches = (branchesWithDependencies: Record<string, any>) => {
|
const removeIgnoredBranches = (branchesWithDependencies: Record<string, any>) => {
|
||||||
let withoutIgnoredBranches = {}
|
let withoutIgnoredBranches = {}
|
||||||
for (const [branch, value] of Object.entries(branchesWithDependencies)) {
|
for (const [branch, value] of Object.entries(branchesWithDependencies)) {
|
||||||
if(!value.ignore) {
|
if(value.ignore) continue;
|
||||||
withoutIgnoredBranches[branch] = value;
|
withoutIgnoredBranches[branch] = value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return withoutIgnoredBranches;
|
return withoutIgnoredBranches;
|
||||||
}
|
}
|
||||||
@@ -90,45 +89,43 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
|
|||||||
let finalBranches: Record<string, BranchWithDependencies> = {};
|
let finalBranches: Record<string, BranchWithDependencies> = {};
|
||||||
for (const branchA of branches) {
|
for (const branchA of branches) {
|
||||||
for (const branchB of branches) {
|
for (const branchB of branches) {
|
||||||
if(branchA !== branchB) {
|
if(branchA !== branchB) continue;
|
||||||
const isSuperset: boolean = commitHistories[branchA].isSupersetOf(commitHistories[branchB]);
|
|
||||||
const difference: Set<string> = commitHistories[branchA].difference(commitHistories[branchB]);
|
|
||||||
|
|
||||||
if (isSuperset) {
|
const isSuperset: boolean = commitHistories[branchA].isSupersetOf(commitHistories[branchB]);
|
||||||
if(branchB === mainBranch) {
|
if (!isSuperset) continue;
|
||||||
// SUPERSET OF MAIN BRANCH, MEANING ALREADY REBASED
|
|
||||||
finalBranches[branchA] = {
|
const difference: Set<string> = commitHistories[branchA].difference(commitHistories[branchB]);
|
||||||
ignore: true
|
|
||||||
}
|
if(branchB === mainBranch) {
|
||||||
}
|
// SUPERSET OF MAIN BRANCH, MEANING ALREADY REBASED
|
||||||
if (difference.size === 0) {
|
finalBranches[branchA] = {
|
||||||
const prevBranches: string[] = finalBranches[branchA]?.equalBranches ?? [];
|
ignore: true
|
||||||
finalBranches[branchA] = {
|
|
||||||
rebaseBranch: mainBranch,
|
|
||||||
...finalBranches[branchA],
|
|
||||||
equalBranches: [...prevBranches, branchB]
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
if (branchA !== mainBranch && (!finalBranches[branchA] || finalBranches[branchA].differenceWithRebase > difference.size)) {
|
|
||||||
finalBranches[branchA] = {
|
|
||||||
...finalBranches[branchA],
|
|
||||||
rebaseBranch: branchB,
|
|
||||||
differenceWithRebase: difference.size
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (difference.size === 0) {
|
||||||
|
const prevBranches: string[] = finalBranches[branchA]?.equalBranches ?? [];
|
||||||
|
finalBranches[branchA] = {
|
||||||
|
rebaseBranch: mainBranch,
|
||||||
|
...finalBranches[branchA],
|
||||||
|
equalBranches: [...prevBranches, branchB]
|
||||||
|
};
|
||||||
|
} else if (branchA !== mainBranch && (!finalBranches[branchA] || finalBranches[branchA].differenceWithRebase > difference.size)) {
|
||||||
|
finalBranches[branchA] = {
|
||||||
|
...finalBranches[branchA],
|
||||||
|
rebaseBranch: branchB,
|
||||||
|
differenceWithRebase: difference.size
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set rebase for branches with no dependencies
|
// Set rebase for branches with no dependencies
|
||||||
for (const branch of branches) {
|
for (const branch of branches) {
|
||||||
if(branch !== mainBranch) {
|
if(branch !== mainBranch) continue;
|
||||||
finalBranches[branch] = finalBranches[branch] ?? {
|
|
||||||
rebaseBranch: mainBranch,
|
finalBranches[branch] = finalBranches[branch] ?? {
|
||||||
differenceWithRebase: 0
|
rebaseBranch: mainBranch,
|
||||||
}
|
differenceWithRebase: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
dist/app.js
vendored
2
dist/app.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user