//! Opening the repo a command acts on, and the tree lookups commands share. module cli import os import src.history import src.snapshot import src.storage pub fn repo_root() !string { root := storage.find_root(os.getwd()) or { return error('not inside a koh repo — run "koh init" here, or "koh steal "') } return root } pub fn open_store() !storage.Store { root := repo_root()! return storage.open(root)! } // tree_of builds the tree a save records, for diffing. pub fn tree_of(store &storage.Store, save_id string) !snapshot.Tree { return snapshot.Tree{ files: history.files_of(store, save_id)! } } pub fn working_tree(store &storage.Store) !snapshot.Tree { return snapshot.Tree{ root: store.root files: snapshot.walk(store, store.root, snapshot.load(store.root))! } } pub fn label(store &storage.Store, id string) string { save := history.by_id(store, id) or { return id } return '${save.id} ${save.message}' }