Mistaken idea about having each branch have a full list of commits

bcdc647c53c3fcec3b55781bd0a413a77cb9bac8

Tucker McKnight <tmcknight@instructure.com> | Mon May 18 2026

Mistaken idea about having each branch have a full list of commits

The previous commit, in the file-caching branch, also is based on this
idea. I'll need to undo that as well.

Putting this in a branch and saving it somewhere so that I can more easily
see what I was doing to undo it later.
src/flatPatches.ts:18
Before
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      const flatPatches: Array<FlatPatchRecord> = []
      let currentCommit: ReturnType<Repository['commits']['get']> | undefined = repo.commits.get(branch.sha)

      while (currentCommit !== undefined) {
        flatPatches.push({
          type: "branch",
          commit: currentCommit,
          repoName: repo.name,
          refName: branch.name
        })

        currentCommit = repo.commits.get(currentCommit.parent)
      }

      return flatPatches
    })
After
17
18
19
20
21
22
23
24
25
26


27
28
29
      const flatPatches: Array<FlatPatchRecord> = []
      let currentCommit: ReturnType<Repository['commits']['get']> | undefined = repo.commits.get(branch.sha)

      flatPatches.concat(branch.commits.map((commit) => {
        return {
          type: "branch",
          commit,
          repoName: repo.name,
          refName: branch.name
        }
⁣
⁣
      })

      return flatPatches
    })
src/flatPatches.ts:35
Before
34
35
36










37
38
    const tags = repo.tags.flatMap((tag) => {
      const flatPatches: Array<FlatPatchRecord> = []
      let currentCommit: ReturnType<Repository['commits']['get']> = repo.commits.get(tag.sha)
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
      while (currentCommit !== undefined) {
        flatPatches.push({
          type: "tag",
After
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    const tags = repo.tags.flatMap((tag) => {
      const flatPatches: Array<FlatPatchRecord> = []
      let currentCommit: ReturnType<Repository['commits']['get']> = repo.commits.get(tag.sha)

      flatPatches.concat(branch.commits.map((commit) => {
        return {
          type: "tag",
          commit,
          repoName: repo.name,
          refName: branch.name
        }
      })

      while (currentCommit !== undefined) {
        flatPatches.push({
          type: "tag",
src/repos.ts:6
Before
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'
After
5
6
7
8
9
10
import childProcess from 'child_process'
import {minimatch} from 'minimatch'

import { type Repository, type Commit } from './dataTypes.ts'
import cloneUrl from './vcses/git/helpers.ts'
import { addBranchToCommitsMap } from './vcses/git/operations.ts'
import { getLocation} from './helpers.ts'
src/repos.ts:149
Before
148
149
150

151
152

153
154


155
156
    const commits: Repository['commits'] = new Map()
    const branchesAndTags = await getBranchesAndTags(reposConfig.repos[repoName], repoName)
    const branchNames = branchesAndTags.branches.map(branch => branch.name)
⁣
    for (const branchName of branchNames) {
      await addBranchToCommitsMap(branchName, repoLocation, commits)
⁣
    }

⁣
⁣
    const branches = await Promise.all(branchesAndTags.branches.map(async (branch) => {
      const repoLocation = getLocation(reposConfig, outputDir, repoName, slugify)
      const branchHeadRes = await exec(`git -C ${repoLocation} show-ref refs/heads/${branch.name}`)
After
148
149
150
151
152
153
154
155
156
157
158
159
160
    const commits: Repository['commits'] = new Map()
    const branchesAndTags = await getBranchesAndTags(reposConfig.repos[repoName], repoName)
    const branchNames = branchesAndTags.branches.map(branch => branch.name)
    const branchCommits: Map<string, Array<Commit>> = new Map()
    for (const branchName of branchNames) {
      branchCommits.set(branchName, await addBranchToCommitsMap(branchName, repoLocation, commits))
      // once we've iterated through here, the commits map is fully filled in
    }

// TODO: don't have this happen in a second loop that waits for things -- can this all
// be done at once?
    const branches = await Promise.all(branchesAndTags.branches.map(async (branch) => {
      const repoLocation = getLocation(reposConfig, outputDir, repoName, slugify)
      const branchHeadRes = await exec(`git -C ${repoLocation} show-ref refs/heads/${branch.name}`)
src/repos.ts:160
Before
159
160
161
162

163
164
      const result = {
        name: branch.name,
        sha: branchHead,
        fileList: await getFileList(branch.name, repoLocation)
⁣
      }
      if (branch.description) { result['description'] = branch.description }
      if (branch.compareTo) { result['compareTo'] = branch.compareTo }
After
159
160
161
162
163
164
165
      const result = {
        name: branch.name,
        sha: branchHead,
        fileList: await getFileList(branch.name, repoLocation),
        commits: branchCommits.get(branch.name)
      }
      if (branch.description) { result['description'] = branch.description }
      if (branch.compareTo) { result['compareTo'] = branch.compareTo }
src/repos.ts:186
Before
After
src/vcses/git/operations.ts:2
Before
1
2
3
4
5
6
import childProcess from 'child_process'
const exec = util.promisify(childProcess.exec)
import { getGitDiffsFromPatchText} from '../../helpers.ts'
import { type Repository, type FileInfo } from '../../dataTypes.ts'

export const getFileList = async (
  branchName: string, repoLocation: string
After
1
2
3
4
5
6
import childProcess from 'child_process'
const exec = util.promisify(childProcess.exec)
import { getGitDiffsFromPatchText} from '../../helpers.ts'
import { type Repository, type FileInfo, type Commit } from '../../dataTypes.ts'

export const getFileList = async (
  branchName: string, repoLocation: string
src/vcses/git/operations.ts:93
Before
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    gitLogSubset = gitLogSubset.slice(nextPatchStart)

    const hash = currentPatch[0].replace("commit ", "").trim()
    console.log(`doing ${hash}`)
    // set the parent hash of the previous commit, unless we're on the first commit
    if (previousHash !== null) {
      commits.get(previousHash)['parent'] = hash
    }
    previousHash = hash

    // exit early if the commits map already includes this hash
    if (commits.has(hash)) {
      return
    }

    let author: string, date: string, isMerge: boolean
After
92
93
94
95






96
97
98
99
100
    gitLogSubset = gitLogSubset.slice(nextPatchStart)

    const hash = currentPatch[0].replace("commit ", "").trim()

⁣
⁣
⁣
⁣
⁣
⁣
    // exit early if the commits map already includes this hash
    if (commits.has(hash)) {
      continue
    }

    let author: string, date: string, isMerge: boolean
src/vcses/git/operations.ts:136
Before
135
136
137

138
139
140
    }).join("\n").trim()

    const diffs = getGitDiffsFromPatchText(currentPatch.slice(diffStart).join("\n"))
⁣
    commits.set(hash, {
      hash,
      message: commitMessage,
      isMerge: isMerge || false,
After
135
136
137
138
139
140
141
    }).join("\n").trim()

    const diffs = getGitDiffsFromPatchText(currentPatch.slice(diffStart).join("\n"))

    let commit = {
      hash,
      message: commitMessage,
      isMerge: isMerge || false,
src/vcses/git/operations.ts:145
Before
144
145
146


147

148
149
150
151
152
      diffs,
      parent: null,
      cachedFiles: new Map(),
⁣
⁣
    })
⁣
  } while (gitLogSubset.length > 1)

  return previousHash
}

export type BlameInfo = {
After
144
145
146
147
148
149
150
151
152
153
154
155
      diffs,
      parent: null,
      cachedFiles: new Map(),
    }

    orderedCommits.push(commit)
    commits.set(hash, commit)
  } while (gitLogSubset.length > 1)

  return orderedCommits
}

export type BlameInfo = {