Changeset 2971

Show
Ignore:
Timestamp:
01/02/08 14:55:56 (11 months ago)
Author:
ttressieres
Message:
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • perforceplugin/trunk/p4trac/api.py

    r2947 r2971  
    77from datetime import datetime 
    88 
    9 from genshi.builder import tag 
    10  
    119from trac.config import ListOption, Option 
    1210from trac.core import Component, implements, TracError 
    1311from trac.versioncontrol import Changeset, Node, Repository, \ 
    14                                 IRepositoryConnector, \ 
     12                                Authorizer, IRepositoryConnector, \ 
    1513                                NoSuchChangeset, NoSuchNode 
    1614from trac.versioncontrol.cache import CachedRepository 
    17 from trac.versioncontrol import Authorizer 
    1815from trac.versioncontrol.web_ui.browser import IPropertyRenderer 
    1916from trac.util import sorted, embedded_numbers 
     17from trac.util.text import to_unicode 
    2018from trac.util.datefmt import utc 
    2119 
     
    163161 
    164162class PerforcePropertyRenderer(Component): 
    165  
    166163    implements(IPropertyRenderer) 
    167164 
    168     def __init__(self): 
    169         self._externals_map = {} 
    170  
    171165    def match_property(self, name, mode): 
    172         return
    173      
     166        return name in ('Tickets') and 4 or
     167 
    174168    def render_property(self, name, mode, context, props): 
    175         pass 
     169        import string 
     170        from genshi.builder import tag 
     171        fragments = [] 
     172        vals = string.split(props[name], ' ') 
     173        for val in vals[1:]: 
     174            title = "ticket %s" % (val) 
     175            fragments.append(tag.a("#%s" % val, class_="ticket", 
     176                                   title=title, 
     177                                   href=context.href.ticket(val))) 
     178        return tag([tag(f, ', ') for f in fragments[:-1]], fragments[-1]) 
    176179 
    177180 
     
    290293    def get_oldest_rev(self): 
    291294        return self.next_rev(0) 
    292     oldest_rev = property(fget=get_oldest_rev) 
    293295 
    294296    def get_youngest_rev(self): 
    295297        return self._repos.getLatestChange() 
    296     youngest_rev = property(fget=get_youngest_rev) 
    297298 
    298299    def previous_rev(self, rev): 
     
    306307        output = _P4ChangesOutputConsumer(self._repos) 
    307308        self._connection.run('changes', '-l', '-s', 'submitted', 
    308                              '-m', '1', 
    309                              '@<%i' % rev, 
    310                              output=output) 
     309                             '-m', '1', '@<%i' % rev, output=output) 
    311310        if output.errors: 
    312311            from p4trac.repos import PerforcError 
     
    345344 
    346345        queryPath = self._repos.fromUnicode(queryPath) 
    347  
    348         self._log.debug(u'Looking for next_rev after change %i for %s' % (rev, path)) 
     346        self.log.debug(u'Looking for next_rev after change %i for %s' % (rev, path)) 
    349347 
    350348        # Perform a binary-search of sorts for the next revision 
     
    362360                else: 
    363361                    batchUpperBound = middle 
    364             self._log.debug( 
     362            self.log.debug( 
    365363                'Looking for changes in range [%i, %i]' % (lowerBound, 
    366364                                                           batchUpperBound)) 
     
    368366            from p4trac.repos import _P4ChangesOutputConsumer 
    369367            output = _P4ChangesOutputConsumer(self._repos) 
    370             depot_path = '%s%s@>=%i,@<=%i' % (self.rootPath(self._connection), 
    371                                                  queryPath, lowerBound, batchUpperBound) 
     368            depot_path = '%s%s@>=%i,@<=%i' % (rootPath(self._connection), 
     369                                              queryPath, lowerBound, batchUpperBound) 
    372370            self._connection.run('changes', '-l', '-s', 'submitted', 
    373371                                 '-m', str(batchSize), 
     
    385383                if lowerBound + batchSize >= batchUpperBound: 
    386384                    # There are no earlier changes 
    387                     self._log.debug('next_rev is %i' % lowest) 
     385                    self.log.debug('next_rev is %i' % lowest) 
    388386                    return lowest 
    389387                else: 
     
    462460        from p4trac.repos import NodePath 
    463461        nodePath = NodePath(NodePath.normalisePath(path), rev) 
    464         node = PerforceNode(nodePath, self._repos, self._log) 
     462        node = PerforceNode(nodePath, self._repos, self.log) 
    465463        return node.get_history(limit) 
    466464 
     
    482480 
    483481    def get_changes(self, old_path, old_rev, new_path, new_rev, ignore_ancestry=0): 
    484  
    485482        self.log.debug('PerforceRepository.get_changes(%r,%r,%r,%r)' % ( 
    486483                       old_path, old_rev, new_path, new_rev)) 
     
    573570        else: 
    574571            raise NoSuchNode(self._nodePath.path, self._nodePath.rev) 
    575      
     572 
    576573    def get_content(self): 
    577574        self._log.debug('PerforceNode.get_content()') 
     
    642639 
    643640                    nextNode = None 
    644                      
    645641                    if currentNode.integrations: 
    646642                        nodePath, how = currentNode.integrations[0] 
     
    685681 
    686682        elif self._node.isDirectory: 
    687              
     683 
    688684            # List all changelists that have affected this directory 
    689685            from p4trac.repos import _P4ChangesOutputConsumer 
     
    693689                queryPath = '%s%s' % (rootPath(self._repos._connection), self._nodePath.rev) 
    694690            else: 
    695                 queryPath = '%s/...%s' % (self._nodePath.path, 
    696                                           self._nodePath.rev) 
     691                queryPath = '%s/...%s' % (self._nodePath.path, self._nodePath.rev) 
    697692 
    698693            if limit is None: 
    699                 self._repos._connection.run( 
    700                     'changes', 
    701                     '-l', '-s', 'submitted', 
    702                     self._repos.fromUnicode(queryPath), 
    703                     output=output) 
    704             else: 
    705                 self._repos._connection.run( 
    706                     'changes', 
    707                     '-l', '-s', 'submitted', 
    708                     '-m', str(limit), 
    709                     self._repos.fromUnicode(queryPath), 
    710                     output=output) 
    711  
     694                self._repos._connection.run('changes', '-l', '-s', 'submitted', 
     695                                            self._repos.fromUnicode(queryPath), 
     696                                            output=output) 
     697            else: 
     698                self._repos._connection.run('changes', '-l', '-s', 'submitted', 
     699                                            '-m', str(limit), 
     700                                            self._repos.fromUnicode(queryPath), 
     701                                            output=output) 
    712702            if output.errors: 
    713703                raise PerforceError(output.errors) 
    714              
     704 
    715705            changes = output.changes 
    716706 
     
    727717                change = changes[i] 
    728718                nodePath = NodePath(self._nodePath.path, change) 
    729                  
     719 
    730720                if i < len(changes)-1: 
    731721                    prevChange = changes[i+1] 
     
    734724 
    735725                prevNodePath = NodePath(self._nodePath.path, prevChange) 
    736  
    737726                node = self._repos.getNode(nodePath) 
    738727                prevNode = self._repos.getNode(prevNodePath) 
     
    754743        else: 
    755744            raise NoSuchNode(self._nodePath.path, self._nodePath.rev) 
    756          
     745 
    757746    def get_annotations(self): 
    758747        annotations = [] 
     
    771760        self._log.debug('PerforceNode.get_properties') 
    772761        if self.kind is Node.FILE: 
    773             props = { 
    774                 'type' : self._node.type 
    775                 } 
     762            props = { 'type' : self._node.type } 
    776763            props.update(self._node.attributes) 
    777764            return props 
     
    800787 
    801788 
    802 class PerforceChangeset(object): 
     789class PerforceChangeset(Changeset): 
    803790    """A Perforce repository changelist""" 
    804791 
     
    811798        self._log = log 
    812799        self._changelist = self._repos.getChangelist(self._change) 
    813  
    814     def _get_message(self): 
    815         import p4trac.repos 
    816         try: 
    817             return self._changelist.description 
    818         except p4trac.repos.NoSuchChangelist, e: 
    819             raise NoSuchChangeset(e.change) 
    820     message = property(fget=_get_message) 
    821  
    822     def _get_date(self): 
    823         import p4trac.repos 
    824         try: 
    825             return datetime.fromtimestamp(self._changelist.time, utc) 
    826         except p4trac.repos.NoSuchChangelist, e: 
    827             raise NoSuchChangeset(e.change) 
    828     date = property(fget=_get_date) 
    829  
    830     def _get_author(self): 
    831         import p4trac.repos 
    832         try: 
    833             return self._changelist.user 
    834         except p4trac.repos.NoSuchChangelist, e: 
    835             raise NoSuchChangeset(e.change) 
    836     author = property(fget=_get_author) 
    837  
    838     def _get_rev(self): 
    839         import p4trac.repos 
    840         try: 
    841             return self._change 
    842         except p4trac.repos.NoSuchChangelist, e: 
    843             raise NoSuchChangeset(e.change) 
    844     rev = property(_get_rev) 
     800        Changeset.__init__(self, self._change, self._changelist.description, 
     801                           self._changelist.user, datetime.fromtimestamp(self._changelist.time, utc)) 
    845802 
    846803    def get_properties(self): 
     
    853810            props = {} 
    854811            fixes = '' 
    855             print results.records 
    856812            for record in results.records: 
    857813                tktid = int(record['Job'][self._job_prefix_length:]) 
    858                 fixes += '#%d ' % tktid 
     814                self._log.debug("get_properties  %d " % tktid) 
     815                fixes += ' %d' % tktid 
    859816 
    860817            if fixes != '': 
     
    867824        # Force population of the file history for the files modified in this 
    868825        # changelist. 
    869  
    870826        self._log.debug("PerforceChangeset(%i).get_changes()" % self._change) 
    871827        self._repos.precacheFileInformationForChanges([self._change]) 
  • perforceplugin/trunk/p4trac/repos.py

    r2947 r2971  
    361361    def __ne__(self, other): 
    362362        return not (self == other) 
    363      
     363 
     364 
    364365class Changelist(object): 
    365366    """A proxy object that gives access to details about a particular 
     
    16471648                                                     nodePathRepo], 
    16481649                                                    create=True) 
     1650 
    16491651            if fileInfo.rev is None: 
    16501652                fileInfo.rev = rev