from datetime import datetime
from errno import ENOENT
from stat import S_IFDIR
from pygit2 import GIT_SORT_TIME

from gitfs import   FuseOSError
from log import log
from .view import View


class HistoryView(View):
    def getattr(self, path, fh=None):
        '''
        Returns a dictionary with keys identical to the stat C structure of
        stat(2).

        st_atime, st_mtime and st_ctime should be floats.

        NOTE: There is an incombatibility between Linux and Mac OS X
        concerning st_nlink of directories. Mac OS X counts all files inside
        the directory, while Linux counts only the subdirectories.
        '''

        return dict(st_mode=(S_IFDIR | 0755), st_nlink=2)


    def opendir(self, path):
        return 0

    def releasedir(self, path, fi):
        pass

    def access(self, path, amode):
        log.info('%s %s', path, amode)
        return 0

    def readdir(self, path, fh):
        return ['.', '..', 'gigi are mere']


@@ -1,58 +1,13 @@
-from datetime import datetime%0Afrom errno import ENOENT
+import os
 %0Afro
@@ -55,50 +55,22 @@
 GIT_
-SORT_TIME%0A%0Afrom gitfs import   FuseOSError
+FILEMODE_TREE%0A
 %0Afro
@@ -826,74 +826,846 @@
 def 
-readdir(self, path, fh):%0A        return %5B'.', '..', 'gigi are mere'%5D%0A
+_get_commit_subtree(self, tree, subtree_name):%0A        for e in tree:%0A            if e.filemode == GIT_FILEMODE_TREE:%0A                if e.name == subtree_name:%0A                    return self.repo%5Be.id%5D%0A                else:%0A                    return self._get_commit_subtree(self.repo%5Be.id%5D,%0A                                                    subtree_name)%0A%0A    def readdir(self, path, fh):%0A        dir_entries = %5B'.', '..'%5D%0A        commit = self.repo.revparse_single(self.commit_sha1)%0A        if getattr(self, 'relative_path'):%0A            tree_name = os.path.split(self.relative_path)%5B1%5D%0A            subtree = self._get_commit_subtree(commit.tree, tree_name)%0A            %5Bdir_entries.append(entry.name) for entry in subtree%5D%0A        else:%0A            %5Bdir_entries.append(entry.name) for entry in commit.tree%5D%0A        return dir_entries
 %0A

Add the possibility of browsing the tree of a particular commit.