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>) => {
|
||||
let withoutIgnoredBranches = {}
|
||||
for (const [branch, value] of Object.entries(branchesWithDependencies)) {
|
||||
if(!value.ignore) {
|
||||
withoutIgnoredBranches[branch] = value;
|
||||
}
|
||||
if(value.ignore) continue;
|
||||
withoutIgnoredBranches[branch] = value;
|
||||
}
|
||||
return withoutIgnoredBranches;
|
||||
}
|
||||
@@ -90,45 +89,43 @@ const buildRebaseDependencyGraph = async (branches: string[]): Promise<Record<st
|
||||
let finalBranches: Record<string, BranchWithDependencies> = {};
|
||||
for (const branchA of branches) {
|
||||
for (const branchB of branches) {
|
||||
if(branchA !== branchB) {
|
||||
const isSuperset: boolean = commitHistories[branchA].isSupersetOf(commitHistories[branchB]);
|
||||
const difference: Set<string> = commitHistories[branchA].difference(commitHistories[branchB]);
|
||||
if(branchA !== branchB) continue;
|
||||
|
||||
if (isSuperset) {
|
||||
if(branchB === mainBranch) {
|
||||
// SUPERSET OF MAIN BRANCH, MEANING ALREADY REBASED
|
||||
finalBranches[branchA] = {
|
||||
ignore: true
|
||||
}
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
const isSuperset: boolean = commitHistories[branchA].isSupersetOf(commitHistories[branchB]);
|
||||
if (!isSuperset) continue;
|
||||
|
||||
const difference: Set<string> = commitHistories[branchA].difference(commitHistories[branchB]);
|
||||
|
||||
if(branchB === mainBranch) {
|
||||
// SUPERSET OF MAIN BRANCH, MEANING ALREADY REBASED
|
||||
finalBranches[branchA] = {
|
||||
ignore: true
|
||||
}
|
||||
}
|
||||
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
|
||||
for (const branch of branches) {
|
||||
if(branch !== mainBranch) {
|
||||
finalBranches[branch] = finalBranches[branch] ?? {
|
||||
rebaseBranch: mainBranch,
|
||||
differenceWithRebase: 0
|
||||
}
|
||||
if(branch !== mainBranch) continue;
|
||||
|
||||
finalBranches[branch] = finalBranches[branch] ?? {
|
||||
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