'Return a loaded tool whose tool config file name (e.g., filtering.xml) is the value
of tool_config_filename.  The value of changeset_revision is a valid (downloadable)
changeset revision.  The tool config will be located in the repository manifest between
the received valid changeset revision and the first changeset revision in the repository,
searching backwards.'

def load_tool_from_changeset_revision(self, repository_id, changeset_revision, tool_config_filename):

    original_tool_data_path = self.app.config.tool_data_path
    repository = repository_util.get_repository_in_tool_shed(self.app, repository_id)
    repo_files_dir = repository.repo_path(self.app)
    repo = hg_util.get_repo_for_repository(self.app, repository=None, repo_path=repo_files_dir, create=False)
    message = ''
    tool = None
    can_use_disk_file = False
    tool_config_filepath = repository_util.get_absolute_path_to_file_in_repository(repo_files_dir, tool_config_filename)
    work_dir = tempfile.mkdtemp(prefix='tmp-toolshed-ltfcr')
    can_use_disk_file = self.can_use_tool_config_disk_file(repository, repo, tool_config_filepath, changeset_revision)
    if can_use_disk_file:
        self.app.config.tool_data_path = work_dir
        (tool, valid, message, sample_files) = self.handle_sample_files_and_load_tool_from_disk(repo_files_dir, repository_id, tool_config_filepath, work_dir)
        if (tool is not None):
            invalid_files_and_errors_tups = self.check_tool_input_params(repo_files_dir, tool_config_filename, tool, sample_files)
            if invalid_files_and_errors_tups:
                message2 = tool_util.generate_message_for_invalid_tools(self.app, invalid_files_and_errors_tups, repository, metadata_dict=None, as_html=True, displaying_invalid_tool=True)
                message = self.concat_messages(message, message2)
    else:
        (tool, message, sample_files) = self.handle_sample_files_and_load_tool_from_tmp_config(repo, repository_id, changeset_revision, tool_config_filename, work_dir)
    basic_util.remove_dir(work_dir)
    self.app.config.tool_data_path = original_tool_data_path
    self.tdtm.reset_tool_data_tables()
    return (repository, tool, message)
