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
def init_ra_and_client(self): """Initializes the RA and client layers, because sometimes getting unified diffs runs the remote server out of open files. """ # while we're in here we'll recreate our pool self.pool = core.Pool() if self.username: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) self.client_context = client.create_context() self.client_context.auth_baton = self.auth_baton self.client_context.config = svn_config callbacks = RaCallbacks() callbacks.auth_baton = self.auth_baton self.callbacks = callbacks try: self.ra = ra.open2(self.svn_url, callbacks, svn_config, self.pool) except SubversionException, e: # e.child contains a detailed error messages msglist = [] svn_exc = e while svn_exc: if svn_exc.args[0]: msglist.append(svn_exc.args[0]) svn_exc = svn_exc.child msg = '\n'.join(msglist) raise common.SubversionConnectionException(msg)
def init_ra_and_client(self): """Initializes the RA and client layers, because sometimes getting unified diffs runs the remote server out of open files. """ # while we're in here we'll recreate our pool self.pool = core.Pool() if self.username: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) self.client_context = client.create_context() self.client_context.auth_baton = self.auth_baton self.client_context.config = svn_config callbacks = RaCallbacks() callbacks.auth_baton = self.auth_baton self.callbacks = callbacks try: url = self.svn_url.encode('utf-8') scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) path=urllib.quote(path) url = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) self.ra = ra.open2(url, callbacks, svn_config, self.pool) except core.SubversionException, e: raise hgutil.Abort(e.args[0])
def svn_move(src_path, dst_path, username='', commitmsg=''): '''Move src_path to dst_path, where each is the url to a file or directory in a Subversion repository. Apply the change as username, and log with commitmsg. ''' def log_message(items, pool): '''Return a commit log message, use as a callback ''' def fname(s): return s.rstrip('/').rsplit('/', 1)[1] src_fname = fname(items[1][2]) dst_fname = fname(items[0][2]) default_msg = 'Moved %s to %s' % (src_fname, dst_fname) return commitmsg or default_msg src_path = core.svn_path_canonicalize(src_path) dst_path = core.svn_path_canonicalize(dst_path) force = False # Ignored for repository -> repository moves move_as_child = False # If dst_path exists don't attempt to move src_path # as it's child make_parents = False # Make parents of dst_path as needed (like mkdir -p) revprop_tbl = None # Use a dict of str prop: vals to set custom svn props # The move operation is coordinated by a client context, suitbly populated # To set the commit message we provide a callback that returns commitmsg client_ctx = client.create_context() client_ctx.log_msg_func3 = client.svn_swig_py_get_commit_log_func client_ctx.log_msg_baton3 = log_message # Configure minimal authentication, this is an example only auth_providers = [ client.svn_client_get_simple_provider(), client.svn_client_get_username_provider(), ] client_ctx.auth_baton = core.svn_auth_open(auth_providers) # libsvn normally infers the username from the environment the working copy # and the configuration. If requested override all that. if username is not None: core.svn_auth_set_parameter(client_ctx.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_USERNAME, username) # Move one directory or file to another location in the same repository # svn_client_move5 can mv a number of files/directories at once if dst_path # is a directory, we ignore this and pass a 1-tuple commit_info = client.svn_client_move5( (src_path, ), dst_path, force, # Ignored move_as_child, make_parents, revprop_tbl, client_ctx, ) print commit_info.revision
def svn_move(src_path, dst_path, username='', commitmsg=''): '''Move src_path to dst_path, where each is the url to a file or directory in a Subversion repository. Apply the change as username, and log with commitmsg. ''' def log_message(items, pool): '''Return a commit log message, use as a callback ''' def fname(s): return s.rstrip('/').rsplit('/', 1)[1] src_fname = fname(items[1][2]) dst_fname = fname(items[0][2]) default_msg = 'Moved %s to %s' % (src_fname, dst_fname) return commitmsg or default_msg src_path = core.svn_path_canonicalize(src_path) dst_path = core.svn_path_canonicalize(dst_path) force = False # Ignored for repository -> repository moves move_as_child = False # If dst_path exists don't attempt to move src_path # as it's child make_parents = False # Make parents of dst_path as needed (like mkdir -p) revprop_tbl = None # Use a dict of str prop: vals to set custom svn props # The move operation is coordinated by a client context, suitbly populated # To set the commit message we provide a callback that returns commitmsg client_ctx = client.create_context() client_ctx.log_msg_func3 = client.svn_swig_py_get_commit_log_func client_ctx.log_msg_baton3 = log_message # Configure minimal authentication, this is an example only auth_providers = [client.svn_client_get_simple_provider(), client.svn_client_get_username_provider(), ] client_ctx.auth_baton = core.svn_auth_open(auth_providers) # libsvn normally infers the username from the environment the working copy # and the configuration. If requested override all that. if username is not None: core.svn_auth_set_parameter(client_ctx.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_USERNAME, username) # Move one directory or file to another location in the same repository # svn_client_move5 can mv a number of files/directories at once if dst_path # is a directory, we ignore this and pass a 1-tuple commit_info = client.svn_client_move5((src_path,), dst_path, force, # Ignored move_as_child, make_parents, revprop_tbl, client_ctx, ) print commit_info.revision
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
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)))
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)))
def setUp(self): """Load a Subversion repository""" self.temper = utils.Temper() # Isolate each test from the others with a fresh repository. (self.repos, _, self.repos_uri) = self.temper.alloc_known_repo( 'trac/versioncontrol/tests/svnrepos.dump', suffix='-wc-repo') self.fs = repos.fs(self.repos) self.path = self.temper.alloc_empty_dir(suffix='-wc-wc') client_ctx = client.create_context() rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head client.checkout2(self.repos_uri, self.path, rev, rev, True, True, client_ctx) self.wc = wc.adm_open3(None, self.path, True, -1, None)
def init_ra_and_client(self): """Initializes the RA and client layers, because sometimes getting unified diffs runs the remote server out of open files. """ # while we're in here we'll recreate our pool self.pool = core.Pool() if self.username: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) self.client_context = client.create_context() self.client_context.auth_baton = self.auth_baton self.client_context.config = svn_config callbacks = RaCallbacks() callbacks.auth_baton = self.auth_baton self.callbacks = callbacks try: self.ra = ra.open2(self.svn_url, callbacks, svn_config, self.pool) except SubversionException, e: if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: msg = ('Subversion does not trust the SSL certificate for this ' 'site; please try running \'svn ls %s\' first.' % self.svn_url) elif e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED: msg = ('Failed to open Subversion repository; please try ' 'running \'svn ls %s\' for details.' % self.svn_url) else: msg = e.args[0] for k, v in vars(core).iteritems(): if k.startswith('SVN_ERR_') and v == e.apr_err: msg = '%s (%s)' % (msg, k) break raise common.SubversionConnectionException(msg)
def setUp(self): """Load a Subversion repository""" # Isolate each test from the others with a fresh repository. # Eventually, we should move this into a shared TestCase base # class that all test cases in this directory can use. SubversionRepositoryTestSetup().setUp() # Open repository directly for cross-checking self.repos = repos.open(REPOS_PATH) self.fs = repos.fs(self.repos) self.path = core.svn_path_canonicalize(tempfile.mktemp()) client_ctx = client.create_context() rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head client.checkout2(REPOS_URL, self.path, rev, rev, True, True, client_ctx) self.wc = wc.adm_open3(None, self.path, True, -1, None)
def init_ra_and_client(self): """Initializes the RA and client layers, because sometimes getting unified diffs runs the remote server out of open files. """ # while we're in here we'll recreate our pool self.pool = core.Pool() if self.username: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: core.svn_auth_set_parameter(self.auth_baton, core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, self.password) self.client_context = client.create_context() self.client_context.auth_baton = self.auth_baton self.client_context.config = svn_config callbacks = RaCallbacks() callbacks.auth_baton = self.auth_baton self.callbacks = callbacks try: self.ra = ra.open2(self.svn_url, callbacks, svn_config, self.pool) except SubversionException, e: if e.apr_err == core.SVN_ERR_RA_SERF_SSL_CERT_UNTRUSTED: msg = ( 'Subversion does not trust the SSL certificate for this ' 'site; please try running \'svn ls %s\' first.' % self.svn_url) elif e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED: msg = ('Failed to open Subversion repository; please try ' 'running \'svn ls %s\' for details.' % self.svn_url) else: msg = e.args[0] for k, v in vars(core).iteritems(): if k.startswith('SVN_ERR_') and v == e.apr_err: msg = '%s (%s)' % (msg, k) break raise common.SubversionConnectionException(msg)