Skip to content

Commit

Permalink
refactor(git): cache list of branches per-sha per repo (#20839)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 19, 2023
1 parent c2fe56a commit e804fda
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/util/git/index.ts
Expand Up @@ -242,6 +242,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 @@ -587,13 +588,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
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

0 comments on commit e804fda

Please sign in to comment.