Tucker McKnight <tmcknight@instructure.com> | Wed Jun 17 2026
Rough draft for cachine files instead of fetching from git show every time Instead of getting the commit by calling `git show` and `git blame` every time we want to see the contents of a file, save the contents of the file in a map called fileMap. The file's contents and git blame info are cached with a key of "filename-SHA". Next time we want to see the contents of the file, before calling `git show` and `git blame`, first check if the fileMap contains that filename/sha combo. If it doesn't, look at parent commits to see if the fileMap has the file cached for an earlier commit. However, if the commit modifies that file, then we know that the cache won't have what we're looking for, and we'll have to call `git show` and `git blame`. TODO: - performance test - see if it benefits from caching at the earliest possible commit, so that more commit SHAs will find the same cached contents - see if we should also cache at a higher-level commit
5 6 7 8 9 10
import childProcess from 'child_process'
import {minimatch} from 'minimatch'
import { type Repository} from './dataTypes.ts'
import cloneUrl from './vcses/git/helpers.ts'
import { addBranchToCommitsMap } from './vcses/git/operations.ts'
import { getLocation} from './helpers.ts'5 6 7 8 9 10
import childProcess from 'child_process'
import {minimatch} from 'minimatch'
import { type Repository, type FileInfo } from './dataTypes.ts'
import cloneUrl from './vcses/git/helpers.ts'
import { addBranchToCommitsMap } from './vcses/git/operations.ts'
import { getLocation} from './helpers.ts'136 137 138 139 140
}
let cachedRepos: Array<Repository> | null = null
const repos: (reposConfig: ReposConfiguration, outputDir: string, slugify: Function) => Promise<Array<Repository>> = async (reposConfig, outputDir, slugify) => {
if (cachedRepos !== null) { return cachedRepos }136 137 138 139 140 141 142 143 144
}
let cachedRepos: Array<Repository> | null = null
// A cached list of files that we have already found. Save things here
// when we read them from calling `git show`.
// The key for this map is a string like "filename-sha".
const fileMap: Map<string, FileInfo> = new Map()
const repos: (reposConfig: ReposConfiguration, outputDir: string, slugify: Function) => Promise<Array<Repository>> = async (reposConfig, outputDir, slugify) => {
if (cachedRepos !== null) { return cachedRepos }