class _open_fs(object): def __init__(self, repo_path, cls): self.repo_path = repo_path self.cls = cls def __enter__(self): self.time_mount = datetime.now() self.repo = GitStorage(self.repo_path, autocommit=False) self.git = self.repo.eg.git master_id = self.git.refs['refs/heads/master'] self.initial_tree_id = self.git.commit(master_id).tree msg = ("[temporary commit; currently mounted, since %s]" % datefmt(self.time_mount)) self.repo.commit(msg, branch="mounted", head_id=master_id) return self.cls(self.repo) def __exit__(self, e0, e1, e2): self.time_unmount = datetime.now() msg = ("Mounted operations:\n mounted at %s\n unmounted at %s\n" % (datefmt(self.time_mount), datefmt(self.time_unmount))) self.repo.commit(msg, amend=True, branch="mounted") mounted_id = self.git.refs['refs/heads/mounted'] mounted_tree_id = self.git.commit(mounted_id).tree if mounted_tree_id != self.initial_tree_id: self.git.refs['refs/heads/master'] = mounted_id del self.git.refs['refs/heads/mounted']
def __enter__(self): self.time_mount = datetime.now() self.repo = GitStorage(self.repo_path, autocommit=False) self.git = self.repo.eg.git master_id = self.git.refs['refs/heads/master'] self.initial_tree_id = self.git.commit(master_id).tree msg = ("[temporary commit; currently mounted, since %s]" % datefmt(self.time_mount)) self.repo.commit(msg, branch="mounted", head_id=master_id) return self.cls(self.repo)