Esempio n. 1
0
    def __init__(self, local_url, rev, first_rev, include_text, config_dir,
                 encoding):
        self.idx = -1
        self.first_rev = first_rev
        self.blame_data = []
        self.include_text = include_text
        self.encoding = encoding

        ctx = client.svn_client_create_context()
        core.svn_config_ensure(config_dir)
        ctx.config = core.svn_config_get_config(config_dir)
        ctx.auth_baton = core.svn_auth_open([])
        try:
            # TODO: Is this use of FIRST_REV always what we want?  Should we
            # pass 1 here instead and do filtering later?
            client.blame2(
                local_url,
                _rev2optrev(rev),
                _rev2optrev(first_rev),
                _rev2optrev(rev),
                self._blame_cb,
                ctx,
            )
        except core.SubversionException as e:
            if e.apr_err == core.SVN_ERR_CLIENT_IS_BINARY_FILE:
                raise vclib.NonTextualFileContents
            raise
Esempio n. 2
0
File: svn_fs.py Progetto: t2y/trac
 def get_annotations(self):
     """Return a list the last changed revision for each line.
     (wraps ``client.blame2``)
     """
     annotations = []
     if self.isfile:
         def blame_receiver(line_no, revision, author, date, line, pool):
             annotations.append(revision)
         try:
             rev = _svn_rev(self.rev)
             start = _svn_rev(0)
             file_url_utf8 = posixpath.join(self.repos.ra_url_utf8,
                                            quote(self._scoped_path_utf8))
             # svn_client_blame2() requires a canonical uri since
             # Subversion 1.7 (#11167)
             file_url_utf8 = _svn_uri_canonicalize(file_url_utf8)
             self.repos.log.info('opening ra_local session to %r',
                                 file_url_utf8)
             from svn import client
             client.blame2(file_url_utf8, rev, start, rev, blame_receiver,
                           client.create_context(), self.pool())
         except (core.SubversionException, AttributeError) as e:
             # svn thinks file is a binary or blame not supported
             raise TracError(_('svn blame failed on %(path)s: %(error)s',
                               path=self.path, error=to_unicode(e)))
     return annotations
Esempio n. 3
0
 def get_annotations(self):
     """Return a list the last changed revision for each line.
     (wraps ``client.blame2``)
     """
     annotations = []
     if self.isfile:
         def blame_receiver(line_no, revision, author, date, line, pool):
             annotations.append(revision)
         try:
             rev = _svn_rev(self.rev)
             start = _svn_rev(0)
             file_url_utf8 = posixpath.join(self.repos.ra_url_utf8,
                                            quote(self._scoped_path_utf8))
             # svn_client_blame2() requires a canonical uri since
             # Subversion 1.7 (#11167)
             file_url_utf8 = _svn_uri_canonicalize(file_url_utf8)
             self.repos.log.info('opening ra_local session to %r',
                                 file_url_utf8)
             from svn import client
             client.blame2(file_url_utf8, rev, start, rev, blame_receiver,
                           client.create_context(), self.pool())
         except (core.SubversionException, AttributeError) as e:
             # svn thinks file is a binary or blame not supported
             raise TracError(_('svn blame failed on %(path)s: %(error)s',
                               path=self.path, error=to_unicode(e)))
     return annotations
Esempio n. 4
0
    def annotate(self, path_parts, rev, include_text=False):
        path = self._getpath(path_parts)
        if self.itemtype(path_parts, rev) != vclib.FILE:  # does auth-check
            raise vclib.Error("Path '%s' is not a file." % path)
        rev = self._getrev(rev)
        url = self._geturl(path)

        # Examine logs for the file to determine the oldest revision we are
        # permitted to see.
        log_options = {
            'svn_cross_copies': 1,
            'svn_show_all_dir_logs': 1,
        }
        revs = self.itemlog(path_parts, rev, vclib.SORTBY_REV, 0, 0,
                            log_options)
        oldest_rev = revs[-1].number

        # Now calculate the annotation data.  Note that we'll not
        # inherently trust the provided author and date, because authz
        # rules might necessitate that we strip that information out.
        blame_data = []

        def _blame_cb(line_no,
                      revision,
                      author,
                      date,
                      line,
                      pool,
                      blame_data=blame_data):
            prev_rev = None
            if revision > 1:
                prev_rev = revision - 1

            # If we have an invalid revision, clear the date and author
            # values.  Otherwise, if we have authz filtering to do, use the
            # revinfo cache to do so.
            if revision < 0:
                date = author = None
            elif self.auth:
                date, author, msg, revprops, changes = self._revinfo(revision)
            else:
                author = _normalize_property_value(author, self.encoding)

            # Strip text if the caller doesn't want it.
            if not include_text:
                line = None
            blame_data.append(
                vclib.Annotation(line, line_no + 1, revision, prev_rev, author,
                                 date))

        client.blame2(url, _rev2optrev(rev), _rev2optrev(oldest_rev),
                      _rev2optrev(rev), _blame_cb, self.ctx)
        return blame_data, rev
Esempio n. 5
0
 def get_annotations(self):
     annotations = []
     if self.isfile:
         def blame_receiver(line_no, reviison, author, date, line, pool):
             annotations.append(revision)
         try:
             rev = _svn_rev(self.rev)
             start = _svn_rev(0)
             repo_url = 'file:///%s/%s' % (self.repos.path.lstrip('/'),
                                           self._scoped_svn_path)
             from svn import client
             client.blame2(repo_url, rev, start, rev, blame_receiver,
                           client.create_context(), self.pool())
             
         except:
             raise Exception('svn blame failed')
     return annotations
Esempio n. 6
0
    def get_annotations(self):
        annotations = []
        if self.isfile:

            def blame_receiver(line_no, revision, author, date, line, pool):
                annotations.append(revision)

            try:
                rev = _svn_rev(self._requested_rev)
                start = _svn_rev(0)
                file_url_utf8 = posixpath.join(self.repos.ra_url_utf8, self._scoped_path_utf8)
                self.repos.log.info("opening ra_local session to %r", file_url_utf8)
                from svn import client

                client.blame2(file_url_utf8, rev, start, rev, blame_receiver, client.create_context(), self.pool())
            except (core.SubversionException, AttributeError), e:
                # svn thinks file is a binary or blame not supported
                raise TracError(_("svn blame failed on %(path)s: %(error)s", path=self.path, error=to_unicode(e)))
Esempio n. 7
0
  def annotate(self, path_parts, rev, include_text=False):
    path = self._getpath(path_parts)
    if self.itemtype(path_parts, rev) != vclib.FILE:  # does auth-check
      raise vclib.Error("Path '%s' is not a file." % path)
    rev = self._getrev(rev)
    url = self._geturl(path)

    # Examine logs for the file to determine the oldest revision we are
    # permitted to see.
    log_options = {
      'svn_cross_copies' : 1,
      'svn_show_all_dir_logs' : 1,
      }
    revs = self.itemlog(path_parts, rev, vclib.SORTBY_REV, 0, 0, log_options)
    oldest_rev = revs[-1].number

    # Now calculate the annotation data.  Note that we'll not
    # inherently trust the provided author and date, because authz
    # rules might necessitate that we strip that information out.
    blame_data = []

    def _blame_cb(line_no, revision, author, date,
                  line, pool, blame_data=blame_data):
      prev_rev = None
      if revision > 1:
        prev_rev = revision - 1

      # If we have an invalid revision, clear the date and author
      # values.  Otherwise, if we have authz filtering to do, use the
      # revinfo cache to do so.
      if revision < 0:
        date = author = None
      elif self.auth:
        date, author, msg, revprops, changes = self._revinfo(revision)

      # Strip text if the caller doesn't want it.
      if not include_text:
        line = None
      blame_data.append(vclib.Annotation(line, line_no + 1, revision, prev_rev,
                                         author, date))
      
    client.blame2(url, _rev2optrev(rev), _rev2optrev(oldest_rev),
                  _rev2optrev(rev), _blame_cb, self.ctx)
    return blame_data, rev
Esempio n. 8
0
 def get_annotations(self):
     annotations = []
     if self.isfile:
         def blame_receiver(line_no, revision, author, date, line, pool):
             annotations.append(revision)
         try:
             rev = _svn_rev(self._requested_rev)
             start = _svn_rev(0)
             file_url_utf8 = posixpath.join(self.repos.ra_url_utf8,
                                            self._scoped_path_utf8)
             self.repos.log.info('opening ra_local session to %r',
                                 file_url_utf8)
             from svn import client
             client.blame2(file_url_utf8, rev, start, rev, blame_receiver,
                           client.create_context(), self.pool())
         except (core.SubversionException, AttributeError), e:
             # svn thinks file is a binary or blame not supported
             raise TracError(_('svn blame failed on %(path)s: %(error)s',
                               path=self.path, error=to_unicode(e)))
Esempio n. 9
0
  def __init__(self, local_url, rev, first_rev, config_dir):
    self.idx = -1
    self.first_rev = first_rev
    self.blame_data = []

    ctx = client.svn_client_create_context()
    core.svn_config_ensure(config_dir)
    ctx.config = core.svn_config_get_config(config_dir)
    ctx.auth_baton = core.svn_auth_open([])
    try:
      ### TODO: Is this use of FIRST_REV always what we want?  Should we
      ### pass 1 here instead and do filtering later?
      client.blame2(local_url, _rev2optrev(rev), _rev2optrev(first_rev),
                    _rev2optrev(rev), self._blame_cb, ctx)
    except core.SubversionException, e:
      _fix_subversion_exception(e)
      if e.apr_err == core.SVN_ERR_CLIENT_IS_BINARY_FILE:
        raise vclib.NonTextualFileContents
      raise