コード例 #1
0
ファイル: api.py プロジェクト: nyuhuhuu/trachacks
    def get_node(self, path, rev=None):
        self._log.debug('get_node(%s, %s) called' % (path, rev))

        from p4trac.repos import NodePath
        nodePath = NodePath(NodePath.normalisePath(path), rev)
        
        return PerforceNode(nodePath, self._repos, self._log)
コード例 #2
0
ファイル: api.py プロジェクト: nyuhuhuu/trachacks
 def get_path_history(self, path, rev=None, limit=None):
     # TODO: This doesn't handle the case where the head node has been
     # deleted or a file has changed to a directory or vica versa.
     from p4trac.repos import NodePath
     nodePath = NodePath(NodePath.normalisePath(path), rev)
     node = PerforceNode(nodePath, self._repos, self._log)
     return node.get_history(limit)
コード例 #3
0
ファイル: api.py プロジェクト: pombredanne/trachacks
 def get_path_history(self, path, rev=None, limit=None):
     # TODO: This doesn't handle the case where the head node has been
     # deleted or a file has changed to a directory or vica versa.
     from p4trac.repos import NodePath
     nodePath = NodePath(NodePath.normalisePath(path), rev)
     node = PerforceNode(nodePath, self._repos, self._log)
     return node.get_history(limit)
コード例 #4
0
ファイル: api.py プロジェクト: pombredanne/trachacks
    def get_node(self, path, rev=None):
        self._log.debug('get_node(%s, %s) called' % (path, rev))

        from p4trac.repos import NodePath
        nodePath = NodePath(NodePath.normalisePath(path), rev)
        
        return PerforceNode(nodePath, self._repos, self._log)
コード例 #5
0
ファイル: api.py プロジェクト: nyuhuhuu/trachacks
def normalisePath(path):
    """Normalise a Perforce path and return it as a Trac-compatible path.

    If None or the empty string is passed then the root path is returned.
    The path is returned with a single leading slash rather than the Perforce
    depot notation which uses two leading slashes.

    @return: The normalised Perforce path.
    @rtype: C{unicode}
    """

    from p4trac.repos import NodePath
    path = NodePath.normalisePath(path)
    if path is None:
        return u'/'
    else:
        return path[1:]
コード例 #6
0
ファイル: api.py プロジェクト: pombredanne/trachacks
def normalisePath(path):
    """Normalise a Perforce path and return it as a Trac-compatible path.

    If None or the empty string is passed then the root path is returned.
    The path is returned with a single leading slash rather than the Perforce
    depot notation which uses two leading slashes.

    @return: The normalised Perforce path.
    @rtype: C{unicode}
    """

    from p4trac.repos import NodePath
    path = NodePath.normalisePath(path)
    if path is None:
        return u'/'
    else:
        return path[1:]
コード例 #7
0
ファイル: api.py プロジェクト: nyuhuhuu/trachacks
    def get_changes(self, old_path, old_rev, new_path, new_rev,
                    ignore_ancestry=1):

        self._log.debug('PerforceRepository.get_changes(%r,%r,%r,%r)' % (
            old_path, old_rev, new_path, new_rev))

        from p4trac.repos import NodePath
        oldNodePath = NodePath(NodePath.normalisePath(old_path), old_rev)
        oldNode = self._repos.getNode(oldNodePath)

        newNodePath = NodePath(NodePath.normalisePath(new_path), new_rev)
        newNode = self._repos.getNode(newNodePath)


        if (newNode.isFile and oldNode.isDirectory) or \
           (newNode.isDirectory and oldNode.isFile):
            raise TracError("Cannot view changes between directory and file")

        if newNode.isDirectory or oldNode.isDirectory:

            if oldNodePath.isRoot:
                oldQueryPath = u'//...%s' % oldNodePath.rev
            else:
                oldQueryPath = u'%s/...%s' % (oldNodePath.path,
                                             oldNodePath.rev)

            if newNodePath.isRoot:
                newQueryPath = u'//...%s' % newNodePath.rev
            else:
                newQueryPath = u'%s/...%s' % (newNodePath.path,
                                             newNodePath.rev)

        elif newNode.isFile or oldNode.isFile:

            oldQueryPath = oldNodePath.fullPath
            newQueryPath = newNodePath.fullPath

        else:
            raise TracError("Cannot diff two non-existant nodes")

        from p4trac.repos import _P4Diff2OutputConsumer
        output = _P4Diff2OutputConsumer(self._repos)

        self._connection.run(
                'diff2', '-ds',
                self._repos.fromUnicode(oldQueryPath),
                self._repos.fromUnicode(newQueryPath),
                output=output)

        if output.errors:
            from p4trac.repos import PerforceError
            raise PerforceError(output.errors)

        for change in output.changes:

            oldFileNodePath, newFileNodePath = change

            if oldFileNodePath is not None:
                oldFileNode = PerforceNode(oldFileNodePath,
                                           self._repos,
                                           self._log)
            else:
                oldFileNode = None

            if newFileNodePath is not None:
                newFileNode = PerforceNode(newFileNodePath,
                                           self._repos,
                                           self._log)
            else:
                newFileNode = None

            if newFileNode and oldFileNode:
                yield (oldFileNode,
                       newFileNode,
                       Node.FILE,
                       Changeset.EDIT)
            elif newFileNode:
                yield (oldFileNode,
                       newFileNode,
                       Node.FILE,
                       Changeset.ADD)
            elif oldFileNode:
                yield (oldFileNode,
                       newFileNode,
                       Node.FILE,
                       Changeset.DELETE)
コード例 #8
0
ファイル: api.py プロジェクト: nyuhuhuu/trachacks
    def next_rev(self, rev, path=''):

        # Finding the next revision is a little more difficult in Perforce
        # as we can only ask for the n most recent changes according to a
        # given criteria. We query batches of changes using a binary search
        # technique so that the number of changes queried is of the order of
        # log N where N is the number of changes greater than rev. This way
        # it is still fairly efficient if the next change is 1 or 1000 changes
        # later.

        self._log.debug('next_rev(%r,%r)' % (rev, path))

        from p4trac.repos import NodePath
        if not path:
            path = u'//'
        else:
            path = NodePath.normalisePath(path)
        node = self._repos.getNode(NodePath(path, rev))

        if node.isDirectory:
            if node.nodePath.isRoot:
                # Handle the root path specially since it encompasses all
                # changes and so can use the repository's internal cache.
                return self._repos.getNextChange(int(rev))
            else:
                queryPath = u'%s/...' % node.nodePath.path
        else:
            queryPath = node.nodePath.path

        queryPath = self._repos.fromUnicode(queryPath)

        self._log.debug(
            u'Looing for next_rev after change %i for %s' % (rev, path))

        # Perform a binary-search of sorts for the next revision
        batchSize = 50
        lowerBound = rev + 1
        upperBound = self.youngest_rev

        while lowerBound <= upperBound:

            if lowerBound + batchSize > upperBound:
                batchUpperBound = upperBound
            else:
                middle = (upperBound + lowerBound) / 2
                if middle - lowerBound < batchSize:
                    batchUpperBound = lowerBound + batchSize
                else:
                    batchUpperBound = middle

            self._log.debug(
                'Looking for changes in range [%i, %i]' % (lowerBound,
                                                           batchUpperBound))
                    
            from p4trac.repos import _P4ChangesOutputConsumer
            output = _P4ChangesOutputConsumer(self._repos)
            self._connection.run('changes', '-l', '-s', 'submitted',
                                 '-m', str(batchSize),
                                 '%s@>=%i,@<=%i' % (queryPath,
                                                    lowerBound,
                                                    batchUpperBound),
                                 output=output)

            if output.errors:
                from p4trac.repos import PerforcError
                raise PerforcError(output.errors)
                
            if output.changes:
                lowest = min(output.changes)
                assert lowest >= lowerBound
                assert lowest <= batchUpperBound

                if lowerBound + batchSize >= batchUpperBound:
                    # There are no earlier changes
                    self._log.debug('next_rev is %i' % lowest)
                    return lowest
                else:
                    # There may be another earlier changes but we know it
                    # can't be any later than lowest.
                    upperBound = lowest
            else:
                # Didn't find any changes in (lowerBound, batchUpperBound)
                # Try searching from batchUpperBound + 1 onwards
                lowerBound = batchUpperBound + 1

        return None
コード例 #9
0
ファイル: api.py プロジェクト: nyuhuhuu/trachacks
 def has_node(self, path, rev=None):
     from p4trac.repos import NodePath
     path = NodePath.normalisePath(path)
     return self._repos.getNode(NodePath(path, rev)).exists
コード例 #10
0
ファイル: api.py プロジェクト: pombredanne/trachacks
    def get_changes(self, old_path, old_rev, new_path, new_rev,
                    ignore_ancestry=1):

        self._log.debug('PerforceRepository.get_changes(%r,%r,%r,%r)' % (
            old_path, old_rev, new_path, new_rev))

        from p4trac.repos import NodePath
        oldNodePath = NodePath(NodePath.normalisePath(old_path), old_rev)
        oldNode = self._repos.getNode(oldNodePath)

        newNodePath = NodePath(NodePath.normalisePath(new_path), new_rev)
        newNode = self._repos.getNode(newNodePath)


        if (newNode.isFile and oldNode.isDirectory) or \
           (newNode.isDirectory and oldNode.isFile):
            raise TracError("Cannot view changes between directory and file")

        if newNode.isDirectory or oldNode.isDirectory:

            if oldNodePath.isRoot:
                oldQueryPath = u'//...%s' % oldNodePath.rev
            else:
                oldQueryPath = u'%s/...%s' % (oldNodePath.path,
                                             oldNodePath.rev)

            if newNodePath.isRoot:
                newQueryPath = u'//...%s' % newNodePath.rev
            else:
                newQueryPath = u'%s/...%s' % (newNodePath.path,
                                             newNodePath.rev)

        elif newNode.isFile or oldNode.isFile:

            oldQueryPath = oldNodePath.fullPath
            newQueryPath = newNodePath.fullPath

        else:
            raise TracError("Cannot diff two non-existant nodes")

        from p4trac.repos import _P4Diff2OutputConsumer
        output = _P4Diff2OutputConsumer(self._repos)

        self._connection.run(
                'diff2', '-ds',
                self._repos.fromUnicode(oldQueryPath),
                self._repos.fromUnicode(newQueryPath),
                output=output)

        if output.errors:
            from p4trac.repos import PerforceError
            raise PerforceError(output.errors)

        for change in output.changes:

            oldFileNodePath, newFileNodePath = change

            if oldFileNodePath is not None:
                oldFileNode = PerforceNode(oldFileNodePath,
                                           self._repos,
                                           self._log)
            else:
                oldFileNode = None

            if newFileNodePath is not None:
                newFileNode = PerforceNode(newFileNodePath,
                                           self._repos,
                                           self._log)
            else:
                newFileNode = None

            if newFileNode and oldFileNode:
                yield (oldFileNode,
                       newFileNode,
                       Node.FILE,
                       Changeset.EDIT)
            elif newFileNode:
                yield (oldFileNode,
                       newFileNode,
                       Node.FILE,
                       Changeset.ADD)
            elif oldFileNode:
                yield (oldFileNode,
                       newFileNode,
                       Node.FILE,
                       Changeset.DELETE)
コード例 #11
0
ファイル: api.py プロジェクト: pombredanne/trachacks
    def next_rev(self, rev, path=''):

        # Finding the next revision is a little more difficult in Perforce
        # as we can only ask for the n most recent changes according to a
        # given criteria. We query batches of changes using a binary search
        # technique so that the number of changes queried is of the order of
        # log N where N is the number of changes greater than rev. This way
        # it is still fairly efficient if the next change is 1 or 1000 changes
        # later.

        self._log.debug('next_rev(%r,%r)' % (rev, path))

        from p4trac.repos import NodePath
        if not path:
            path = u'//'
        else:
            path = NodePath.normalisePath(path)
        node = self._repos.getNode(NodePath(path, rev))

        if node.isDirectory:
            if node.nodePath.isRoot:
                # Handle the root path specially since it encompasses all
                # changes and so can use the repository's internal cache.
                return self._repos.getNextChange(int(rev))
            else:
                queryPath = u'%s/...' % node.nodePath.path
        else:
            queryPath = node.nodePath.path

        queryPath = self._repos.fromUnicode(queryPath)

        self._log.debug(
            u'Looing for next_rev after change %i for %s' % (rev, path))

        # Perform a binary-search of sorts for the next revision
        batchSize = 50
        lowerBound = rev + 1
        upperBound = self.youngest_rev

        while lowerBound <= upperBound:

            if lowerBound + batchSize > upperBound:
                batchUpperBound = upperBound
            else:
                middle = (upperBound + lowerBound) / 2
                if middle - lowerBound < batchSize:
                    batchUpperBound = lowerBound + batchSize
                else:
                    batchUpperBound = middle

            self._log.debug(
                'Looking for changes in range [%i, %i]' % (lowerBound,
                                                           batchUpperBound))
                    
            from p4trac.repos import _P4ChangesOutputConsumer
            output = _P4ChangesOutputConsumer(self._repos)
            self._connection.run('changes', '-l', '-s', 'submitted',
                                 '-m', str(batchSize),
                                 '%s@>=%i,@<=%i' % (queryPath,
                                                    lowerBound,
                                                    batchUpperBound),
                                 output=output)

            if output.errors:
                from p4trac.repos import PerforcError
                raise PerforcError(output.errors)
                
            if output.changes:
                lowest = min(output.changes)
                assert lowest >= lowerBound
                assert lowest <= batchUpperBound

                if lowerBound + batchSize >= batchUpperBound:
                    # There are no earlier changes
                    self._log.debug('next_rev is %i' % lowest)
                    return lowest
                else:
                    # There may be another earlier changes but we know it
                    # can't be any later than lowest.
                    upperBound = lowest
            else:
                # Didn't find any changes in (lowerBound, batchUpperBound)
                # Try searching from batchUpperBound + 1 onwards
                lowerBound = batchUpperBound + 1

        return None
コード例 #12
0
ファイル: api.py プロジェクト: pombredanne/trachacks
 def has_node(self, path, rev=None):
     from p4trac.repos import NodePath
     path = NodePath.normalisePath(path)
     return self._repos.getNode(NodePath(path, rev)).exists