コード例 #1
0
    def _get_tree_hash(self, directory):
        """Recursively generate hashes of nodes for current directory"""
        # Validate the given root directory
        if not os.path.isdir(directory):
            raise ValueError('Not a directory: {}'.format(directory))

        # Get all files & directories for this level (excluding our pbb dir)
        directories = utils.list_directories(directory, [self.REPO_DIR])
        files = utils.list_files(directory)

        node_entries = []

        # Recursively create nodes for subdirectories
        for subdir in directories:
            node_hash = self._get_tree_hash(
                utils.posixjoin(directory, subdir)
            )
            node_entries.append('tree {} {}'.format(node_hash, subdir))

        for file in files:
            node_hash = self._get_blob_hash(
                utils.posixjoin(directory, file)
            )
            node_entries.append('blob {} {}'.format(node_hash, file))

        # Join node entries into the node content
        node_content = '\n'.join(node_entries) + '\n'

        # Get node content hash
        return self._hash_diget(self._byte_convert(node_content))
コード例 #2
0
    def _update_files(self):
        """Updates directory with the files for the given snapshot

        Clears out the entire directory, then rebuilds the directory from
        the repository. Would be better in the future to probably only
        overwrite files that needed updates and remove files that no longer
        should be there, but this was simple and I can optimize later if
        it needs better performance.
        """
        # Get all files and directories for this level (excluding repo)
        directories = utils.list_directories(self.root_dir, [self.REPO_DIR])
        files = utils.list_files(self.root_dir)

        # Remove all of these files and recursively remove directories
        # Remove files
        for file in files:
            os.remove(self._join_root(file))
        # Remove directories
        for directory in directories:
            shutil.rmtree(self._join_root(directory))

        # Clears the current hashcache; must be rebuild along with files
        self.objhashcache = {}

        # Get hash of the current snapshot
        top_hash, _ = self._current_snapshot_hash()

        self._build_tree(top_hash, self.root_dir)

        # Save the rebuilt hashcache
        self._save_objhashcache()
コード例 #3
0
    def _create_tree_node(self, directory):
        """Recursive function creates tree nodes for current snapshot"""
        # Validate the given root directory
        if not os.path.isdir(directory):
            raise ValueError('Not a directory: {}'.format(directory))

        # Get all files & directories for this level (excluding our pbb dir)
        directories = utils.list_directories(directory, [self.REPO_DIR])
        files = utils.list_files(directory)

        node_entries = []

        # Recursively create nodes for subdirectories
        for subdir in directories:
            node_hash = self._create_tree_node(
                utils.posixjoin(directory, subdir)
            )
            node_entries.append('tree {} {}'.format(node_hash, subdir))

        for file in files:
            node_hash = self._create_blob_node(
                utils.posixjoin(directory, file)
            )
            node_entries.append('blob {} {}'.format(node_hash, file))

        # Join node entries into the node content
        node_content = '\n'.join(node_entries) + '\n'

        # Save the node contents to a vc object
        return self._save_node(directory, node_content)
コード例 #4
0
 def list_branches(self):
     """Returns a list of all existing branch names"""
     return utils.list_files(self._join_root(self.DIRS['heads']))