def checkout(gitdir: pathlib.Path, obj_name: str) -> None: for entry in read_index(gitdir): try: os.remove(entry.name) except FileNotFoundError: pass com = commit_parse(read_object(obj_name, gitdir)[1]) finished = False while not finished: trees: tp.List[tp.Tuple[pathlib.Path, tp.List[tp.Tuple[int, str, str]]]] trees = [(gitdir.parent, read_tree(read_object(com["tree"], gitdir)[1]))] while trees: tree_path, tree_content = trees[-1] del trees[-1] for file_data in tree_content: fmt, data = read_object(file_data[2], gitdir) if fmt == "tree": trees.append((tree_path / file_data[1], read_tree(data))) if not (tree_path / file_data[1]).exists(): (tree_path / file_data[1]).mkdir() else: if not (tree_path / file_data[1]).exists(): with (tree_path / file_data[1]).open("wb") as f: f.write(data) (tree_path / file_data[1]).chmod(int(str(file_data[0]), 8)) if "parent" in com: com.append(commit_parse((read_object(com["parent"], gitdir)[1]))) else: finished = True for dir in gitdir.parent.glob("*"): if dir != gitdir and dir.is_dir(): try: os.removedirs(dir) except OSError: continue
def checkout(gitdir: pathlib.Path, obj_name: str) -> None: for entry in read_index(gitdir): try: os.remove(entry.name) except FileNotFoundError: pass commit_que = [commit_parse(read_object(obj_name, gitdir)[1])] while len(commit_que) != 0: comm = commit_que.pop() if "parent" in comm: commit_que.append(commit_parse((read_object(comm["parent"], gitdir)[1]))) tree_que: tp.List[tp.Tuple[pathlib.Path, tp.List[tp.Tuple[int, str, str]]]] tree_que = [(gitdir.parent, read_tree(read_object(comm["tree"], gitdir)[1]))] while len(tree_que) != 0: tree_path, tree_content = tree_que.pop() for file_data in tree_content: fmt, data = read_object(file_data[2], gitdir) if fmt == "tree": tree_que.append((tree_path / file_data[1], read_tree(data))) try: (tree_path / file_data[1]).mkdir() except FileExistsError: pass else: if not (tree_path / file_data[1]).exists(): with (tree_path / file_data[1]).open("wb") as f: f.write(data) (tree_path / file_data[1]).chmod(file_data[0]) for dir in filter(lambda x: x != gitdir and x.is_dir(), gitdir.parent.glob("*")): dir_remover(dir)
def checkout(gitdir: pathlib.Path, obj_name: str) -> None: for i in read_index(gitdir): if pathlib.Path(i.name).exists(): os.remove(i.name) commit = commit_parse(read_object(obj_name, gitdir)[1]) q = True while q: trees: tp.List[tp.Tuple[tp.List[tp.Tuple[int, str, str]], pathlib.Path]] = [ (read_tree(read_object(commit["tree"], gitdir)[1]), gitdir.parent) ] while trees: tree_content, tree_path = trees.pop() for i in tree_content: fmt, data = read_object(i[2], gitdir) if fmt != "tree": if not (tree_path / i[1]).exists(): with (tree_path / i[1]).open("wb") as f: f.write(data) (tree_path / i[1]).chmod(int(str(i[0]), 8)) f.close() else: if not (tree_path / i[1]).exists(): (tree_path / i[1]).mkdir() trees.append((read_tree(data), tree_path / i[1])) if "parent" in commit: commit = commit_parse((read_object(commit["parent"], gitdir)[1])) else: q = not q for i in gitdir.parent.glob("*"): if i.is_dir() and i != gitdir: try: os.removedirs(i) except OSError: continue
def checkout(gitdir: pathlib.Path, obj_name: str) -> None: index = read_index(gitdir) for entry in index: if pathlib.Path(entry.name).exists(): os.remove(entry.name) commit_data = commit_parse(read_object(obj_name, gitdir)[1]) end = False while not end: trees: tp.List[tp.Tuple[pathlib.Path, tp.List[tp.Tuple[int, str, str]]]] = [ (gitdir.parent, read_tree( read_object(commit_data["tree"], gitdir)[1])) ] while trees: tree_path, tree_content = trees.pop() for file_data in tree_content: fmt, data = read_object(file_data[1], gitdir) if fmt == "tree": trees.append((tree_path / file_data[2], read_tree(data))) if not (tree_path / file_data[2]).exists(): (tree_path / file_data[2]).mkdir() else: if not (tree_path / file_data[2]).exists(): with (tree_path / file_data[2]).open("wb") as f: f.write(data) (tree_path / file_data[2]).chmod( int(str(file_data[0]), 8)) if "parent" in commit_data: commit_data = commit_parse((read_object(commit_data["parent"], gitdir)[1])) else: end = True dirs = gitdir.parent.glob("*") for dir in dirs: if dir != gitdir and dir.is_dir(): try: os.removedirs(dir) except OSError: continue
def checkout(gitdir: pathlib.Path, obj_name: str) -> None: for entry in read_index(gitdir): if pathlib.Path(entry.name).exists(): os.remove(entry.name) commit_data = commit_parse(read_object(obj_name, gitdir)[1]) doing = True while doing: trees: tp.List[tp.Tuple[tp.List[tp.Tuple[int, str, str]], pathlib.Path]] = [(read_tree( read_object(commit_data["tree"], gitdir)[1]), gitdir.parent)] while trees: tree_content, tree_path = trees.pop() for file_data in tree_content: fmt, data = read_object(file_data[2], gitdir) if fmt != "tree": if not (tree_path / file_data[1]).exists(): with (tree_path / file_data[1]).open("wb") as file: file.write(data) (tree_path / file_data[1]).chmod( int(str(file_data[0]), 8)) else: if not (tree_path / file_data[1]).exists(): (tree_path / file_data[1]).mkdir() trees.append((read_tree(data), tree_path / file_data[1])) if "parent" in commit_data: commit_data = commit_parse((read_object(commit_data["parent"], gitdir)[1])) else: doing = not doing for dir in gitdir.parent.glob("*"): if dir.is_dir() and dir != gitdir: try: os.removedirs(dir) except OSError: continue