Changeset 3174

Show
Ignore:
Timestamp:
02/05/08 05:28:35 (10 months ago)
Author:
hvr
Message:

GitPlugin:

  • speeded up get_history and rev_older_than
  • raise NoSuchChangeset exception if invalid changeset revision is requested (addresses #1639)

Signed-Off-By: Herbert Valerio Riedel <hvr@gnu.org>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gitplugin/0.10/gitplugin/git_fs.py

    r3173 r3174  
    11# -*- coding: iso-8859-1 -*- 
    22# 
    3 # Copyright (C) 2006 Herbert Valerio Riedel <hvr@gnu.org> 
     3# Copyright (C) 2006,2008 Herbert Valerio Riedel <hvr@gnu.org> 
    44# 
    55# This program is free software; you can redistribute it and/or 
     
    2727 
    2828        def get_repository(self, type, dir, authname): 
    29                 return GitRepository(dir, self.log) 
     29                options = dict(self.config.options(type)) 
     30                return GitRepository(dir, self.log, options) 
    3031 
    3132class GitRepository(Repository): 
    32         def __init__(self, path, log): 
     33        def __init__(self, path, log, options): 
    3334                self.gitrepo = path 
    3435                self.git = PyGIT.Storage(path) 
     
    5960                return GitNode(self.git, path, rev) 
    6061 
     62        def get_changesets(self, start, stop): 
     63                #print "get_changesets", start, stop 
     64                for rev in self.git.history_all(start, stop): 
     65                        yield self.get_changeset(rev) 
     66 
    6167        def get_changeset(self, rev): 
    6268                #print "get_changeset", rev 
     
    7480                        if mode2[0] == '1' or mode2[0] == '1': 
    7581                                kind = Node.DIRECTORY 
    76                                  
     82 
    7783                        if action == 'A': 
    7884                                change = Changeset.ADD 
     
    107113 
    108114        def rev_older_than(self, rev1, rev2): 
    109                 rc = rev1 in self.git.history(rev2, '', 1
    110                 #print "rev_older_than", (rev1, rev2, rc
     115                rc = self.git.rev_is_anchestor(rev1,rev2
     116                #rc = rev1 in self.git.history(rev2, '', skip=1
    111117                return rc 
    112118 
     
    122128                self.perm = None 
    123129                self.data_len = None 
    124                  
     130 
    125131                kind = Node.DIRECTORY 
    126132                p = path.strip('/') 
     
    146152                        else: 
    147153                                self.log.debug("kind is "+k) 
    148                          
     154 
    149155                Node.__init__(self, path, rev, kind) 
    150156 
     
    156162                if self.isfile: 
    157163                        return self.git.get_file(self.sha) 
    158                          
     164 
    159165                return None 
    160166 
     
    169175                if not self.isdir: 
    170176                        return 
    171                  
     177 
    172178                p = self.path.strip('/') 
    173179                if p != '': p = p + '/' 
    174180                for e in self.git.tree_ls(self.rev, p): 
    175181                        yield GitNode(self.git, e[3], self.rev, e) 
    176          
     182 
    177183        def get_content_type(self): 
    178184                if self.isdir: 
     
    188194 
    189195        def get_history(self, limit=None): 
     196                #print "get_history", limit, self.path 
    190197                p = self.path.strip('/') 
    191                 for rev in self.git.history(self.rev, p): 
     198                for rev in self.git.history(self.rev, p, limit): 
    192199                        yield (self.path, rev, Changeset.EDIT) 
    193200 
     
    198205        def __init__(self, git, sha): 
    199206                self.git = git 
    200                 (msg,props) = git.read_commit(sha) 
     207                try: 
     208                        (msg,props) = git.read_commit(sha) 
     209                except PyGIT.GitErrorSha: 
     210                        raise NoSuchChangeset(sha) 
    201211                self.props = props 
    202212 
    203213                committer = props['committer'][0] 
    204214                (user,time,tz) = committer.rsplit(None, 2) 
    205                  
     215 
    206216                Changeset.__init__(self, sha, msg, user, float(time)) 
    207217 
     
    223233                        if mode1[0:1] == '04' or mode2[0:1] == '04': 
    224234                                kind = Node.DIRECTORY 
    225                                  
     235 
    226236                        if action == 'A': 
    227237                                change = Changeset.ADD 
  • gitplugin/0.10/gitplugin/PyGIT.py

    r1536 r3174  
    11# -*- coding: iso-8859-1 -*- 
    22# 
    3 # Copyright (C) 2006 Herbert Valerio Riedel <hvr@gnu.org> 
     3# Copyright (C) 2006,2008 Herbert Valerio Riedel <hvr@gnu.org> 
    44# 
    55# This program is free software; you can redistribute it and/or 
     
    1717 
    1818class GitError(Exception): 
     19    pass 
     20 
     21class GitErrorSha(GitError): 
    1922    pass 
    2023 
     
    7578        lines = raw.splitlines() 
    7679 
     80        if not lines: 
     81            raise GitErrorSha 
     82 
    7783        line = lines.pop(0) 
    7884        d = {} 
     
    104110            if sha in revs[1:]: 
    105111                yield revs[0] 
    106          
    107     def history(self, sha, path, skip=0): 
    108         for rev in self._git_call_f("git-rev-list %s -- '%s'" % (sha,path)).readlines(): 
     112 
     113    def history(self, sha, path, limit=None, skip=0): 
     114        #print "history", sha, path, limit, skip 
     115        if limit is None: 
     116            limit = -1 
     117        for rev in self._git_call_f("git-rev-list -n%d %s -- '%s'" % (limit,sha,path)).readlines(): 
    109118            if(skip > 0): 
    110119                skip = skip - 1 
    111120                continue 
    112121            yield rev.strip() 
     122 
     123    def history_all(self, start, stop): 
     124        for rev in self._git_call_f("git-rev-list --reverse --max-age=%d --min-age=%d --all" \ 
     125                                        % (start,stop)).readlines(): 
     126            yield rev.strip() 
     127 
     128    def rev_is_anchestor(self, rev1, rev2): 
     129        rev1 = rev1.strip() 
     130        rev2 = rev2.strip() 
     131        for rev in self._git_call_f("git-rev-list %s ^%s^" % (rev2,rev1)).readlines(): 
     132            if rev1 == rev.strip(): 
     133                return True 
     134        return False 
    113135 
    114136    def last_change(self, sha, path): 
     
    130152if __name__ == '__main__': 
    131153    import sys 
    132      
     154 
    133155    g = Storage(sys.argv[1]) 
    134      
     156 
    135157    print "[%s]" % g.head() 
    136158    print g.tree_ls(g.head())