'Get the latest revision of a tool config file named filename from the repository
manifest up to the value of changeset_revision.  This method is restricted to tool_config
files rather than any file since it is likely that, with the exception of tool config
files, multiple files will have the same name in various directories within the repository.'

def get_latest_tool_config_revision_from_repository_manifest(self, repo, filename, changeset_revision):

    stripped_filename = basic_util.strip_path(filename)
    for changeset in hg_util.reversed_upper_bounded_changelog(repo, changeset_revision):
        manifest_ctx = repo.changectx(changeset)
        for ctx_file in manifest_ctx.files():
            ctx_file_name = basic_util.strip_path(ctx_file)
            if (ctx_file_name == stripped_filename):
                try:
                    fctx = manifest_ctx[ctx_file]
                except LookupError:
                    continue
                fh = tempfile.NamedTemporaryFile('wb', prefix='tmp-toolshed-gltcrfrm')
                tmp_filename = fh.name
                fh.close()
                fh = open(tmp_filename, 'wb')
                fh.write(fctx.data())
                fh.close()
                return tmp_filename
    return None
