Data Structures19 sections · 729 units
Open in Course

Application: Git-like VCS

Branching and merging

Version control systems use persistent structures:

Commit: Create new version from current state Branch: Create new reference to a version Checkout: Set working state to any version Merge: Combine two versions (confluent persistence)

class SimpleVCS:
    commits: map from hash to tree_root
    branches: map from name to hash

    function commit(branch, changes)
        parent := commits[branches[branch]]
        newRoot := applyChanges(parent, changes)
        hash := computeHash(newRoot)
        commits[hash] := newRoot
        branches[branch] := hash

    function branch(name, fromBranch)
        branches[name] := branches[fromBranch]

Git's object model is a persistent data structure with content-addressed storage.