def _delete(self, key, branch='master'): trees={} path = key if path: while path: (path, name) = pathsplit(path) trees[path] = self._get_object(path, branch) else: trees[ROOT_PATH] = self._get_object(ROOT_PATH, branch) (path, name) = pathsplit(key) if name: del trees[path][name] else: for entry in trees[path].iteritems(): del trees[path][entry.path] if path: while path: (parent_path, name) = pathsplit(path) trees[parent_path].add(name, stat.S_IFDIR, trees[path].id) self.repo.object_store.add_object(trees[path]) path = parent_path self.repo.object_store.add_object(trees[ROOT_PATH]) else: self.repo.object_store.add_object(trees[ROOT_PATH]) return trees[ROOT_PATH]
def _delete(self, key, branch='master'): trees = {} path = key if path: while path: (path, name) = pathsplit(path) trees[path] = self._get_object(path, branch) else: trees[ROOT_PATH] = self._get_object(ROOT_PATH, branch) (path, name) = pathsplit(key) if name: del trees[path][name] else: for entry in trees[path].iteritems(): del trees[path][entry.path] if path: while path: (parent_path, name) = pathsplit(path) trees[parent_path].add(name, stat.S_IFDIR, trees[path].id) self.repo.object_store.add_object(trees[path]) path = parent_path self.repo.object_store.add_object(trees[ROOT_PATH]) else: self.repo.object_store.add_object(trees[ROOT_PATH]) return trees[ROOT_PATH]
def _delete(self, key, branch='master'): if branch == 'master': cache_key_prefix = self._head_cache_key(key) for cache_key in self.head_cache.keys(): if cache_key.startswith(cache_key_prefix): self.head_cache.remove(cache_key) trees={} path = key if path: while path: (path, name) = pathsplit(path) trees[path] = self._get_object(path, branch) else: trees[ROOT_PATH] = self._get_object(ROOT_PATH, branch) (path, name) = pathsplit(key) if name: del trees[path][name] else: for entry in trees[path].iteritems(): del trees[path][entry.path] if path: while path: if branch == 'master': cache_path_key = self._head_cache_key(path) if cache_path_key in self.head_cache: self.head_cache.remove(cache_path_key) (parent_path, name) = pathsplit(path) trees[parent_path].add(name, stat.S_IFDIR, trees[path].id) self.repo.object_store.add_object(trees[path]) path = parent_path self.repo.object_store.add_object(trees[ROOT_PATH]) else: self.repo.object_store.add_object(trees[ROOT_PATH]) return trees[ROOT_PATH]
def add_tree(path): if path in trees: return trees[path] dirname, basename = pathsplit(path) t = add_tree(dirname) assert isinstance(basename, basestring) newtree = {} t[basename] = newtree trees[path] = newtree return newtree
def add_tree(path): if path in trees: return trees[path] dirname, basename = pathsplit(path) t = add_tree(dirname) assert isinstance(basename, bytes) newtree = {} t[basename] = newtree trees[path] = newtree return newtree
def _add_tree(self, root_tree, blobs, branch='master', commit_sha=None): """Commit a new tree. :param root_tree: Root tree to add trees to :param blobs: Iterable over blob path, sha, mode entries :return: SHA1 of the created tree. """ trees = {"": {}} def add_tree(path): if path in trees: return trees[path] dirname, basename = pathsplit(path) t = add_tree(dirname) assert isinstance(basename, basestring) newtree = {} t[basename] = newtree trees[path] = newtree return newtree for path, sha, mode in blobs: if branch == 'master': cache_path_key = self._head_cache_key(path) if cache_path_key in self.head_cache: self.head_cache.remove(cache_path_key) tree_path, basename = pathsplit(path) tree = add_tree(tree_path) tree[basename] = (mode, sha) def build_tree(path): if branch == 'master': cache_path_key = self._head_cache_key(path) if cache_path_key in self.head_cache: self.head_cache.remove(cache_path_key) if path: tree = self._get_object(path, branch=branch, commit_sha=commit_sha) if not tree: tree = Tree() if not isinstance(tree, Tree): self.delete(path, branch=branch) tree = Tree() else: tree = root_tree for basename, entry in trees[path].iteritems(): if type(entry) == dict: mode = stat.S_IFDIR sha = build_tree(pathjoin(path, basename)) else: (mode, sha) = entry tree.add(basename, mode, sha) self.repo.object_store.add_object(tree) return tree.id return build_tree("")
def _add_tree(self, root_tree, blobs, branch='master', commit_sha=None): """Commit a new tree. :param root_tree: Root tree to add trees to :param blobs: Iterable over blob path, sha, mode entries :return: SHA1 of the created tree. """ trees = {"": {}} def add_tree(path): if path in trees: return trees[path] dirname, basename = pathsplit(path) t = add_tree(dirname) assert isinstance(basename, basestring) newtree = {} t[basename] = newtree trees[path] = newtree return newtree for path, sha, mode in blobs: tree_path, basename = pathsplit(path) tree = add_tree(tree_path) tree[basename] = (mode, sha) def build_tree(path): if path: tree = self._get_object(path, branch=branch, commit_sha=commit_sha) if not tree: tree = Tree() if not isinstance(tree, Tree): self.delete(path, branch=branch) tree = Tree() else: tree = root_tree for basename, entry in trees[path].iteritems(): if type(entry) == dict: mode = stat.S_IFDIR sha = build_tree(pathjoin(path, basename)) else: (mode, sha) = entry tree.add(basename, mode, sha) self.repo.object_store.add_object(tree) return tree.id return build_tree("")