Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(git): cache list of branches per-sha per repo #20839

Merged
merged 1 commit into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/util/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export async function initRepo(args: StorageConfig): Promise<void> {
config.ignoredAuthors = [];
config.additionalBranches = [];
config.branchIsModified = {};
config.commitBranches = {};
const { localDir } = GlobalConfig.get();
git = simpleGit(localDir, simpleGitConfig()).env({
...process.env,
Expand Down Expand Up @@ -584,13 +585,16 @@ export async function isBranchBehindBase(
await syncGit();
try {
const { currentBranchSha, currentBranch } = config;
const branches = await git.branch([
'--remotes',
'--verbose',
'--contains',
config.currentBranchSha,
]);
isBehind = !branches.all.map(localName).includes(branchName);
config.commitBranches[config.currentBranchSha] ??= (
await git.branch([
'--remotes',
'--verbose',
'--contains',
config.currentBranchSha,
])
).all.map(localName);
isBehind =
!config.commitBranches[config.currentBranchSha].includes(branchName);
logger.debug(
{ currentBranch, currentBranchSha },
`branch.isBehindBase(): ${isBehind}`
Expand Down
1 change: 1 addition & 0 deletions lib/util/git/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface LocalConfig extends StorageConfig {
currentBranchSha: string;
branchCommits: Record<string, CommitSha>;
branchIsModified: Record<string, boolean>;
commitBranches: Record<string, string[]>;
ignoredAuthors: string[];
gitAuthorName?: string | null;
gitAuthorEmail?: string;
Expand Down