Skip to content

Instantly share code, notes, and snippets.

@brewkode
brewkode / Git data model
Created July 20, 2020 21:01
Rough notes on git data model
# Git's data model
## Snapshot
collection of files & folders within a top-level dir as a series of snapshots.
- file is a "blob", bunch of bytes
- directory is a "tree" which maps names to blobs or trees
- snapshot is a top-level tree that is being tracked
## History
- DAG
- each snapshot refers to a "set of parents";
object UnionFind {
def undirectedEdge(tuple: (String, String)) = tuple :: tuple.swap :: Nil
def findRepresentative(it: Iterator[(String, String)]) = {
val (existingRepr, newReprCandidate) = it.next()
val newRepr = if(existingRepr.compareTo(newReprCandidate) <= 0) existingRepr else newReprCandidate
val updated = it.nonEmpty && (existingRepr != newRepr)
val items = (Iterator(existingRepr, newReprCandidate) ++ it.map(_._2)).filter(_ != newRepr)
items.map(k => (newRepr, k, updated))
}