def get_latest_downloadable_repository_metadata(trans, repository):
 encoded_repository_id = trans.security.encode_id(repository.id)
 repo = hg_util.get_repo_for_repository(trans.app, repository=repository, repo_path=None, create=False)
 tip_ctx = str(repo.changectx(repo.changelog.tip()))
 repository_metadata = None
 try:
  repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(trans.app, encoded_repository_id, tip_ctx)
  if ((repository_metadata is not None) and repository_metadata.downloadable):
   return repository_metadata
  return None
 except:
  latest_downloadable_revision = metadata_util.get_previous_metadata_changeset_revision(repository, repo, tip_ctx, downloadable=True)
  if (latest_downloadable_revision == hg_util.INITIAL_CHANGELOG_HASH):
   return None
  repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(trans.app, encoded_repository_id, latest_downloadable_revision)
  if ((repository_metadata is not None) and repository_metadata.downloadable):
   return repository_metadata
  return None

def get_latest_downloadable_repository_metadata ( trans , repository ) : encoded_repository_id = trans . security . encode_id ( repository . id ) repo = hg_util . get_repo_for_repository ( trans . app , repository = repository , repo_path = None , create = False ) tip_ctx = str ( repo . changectx ( repo . changelog . tip ( ) ) ) repository_metadata = None try : repository_metadata = metadata_util . get_repository_metadata_by_changeset_revision ( trans . app , encoded_repository_id , tip_ctx ) if ( ( repository_metadata is not None ) and repository_metadata . downloadable ) : return repository_metadata return None except : latest_downloadable_revision = metadata_util . get_previous_metadata_changeset_revision ( repository , repo , tip_ctx , downloadable = True ) if ( latest_downloadable_revision == hg_util . INITIAL_CHANGELOG_HASH ) : return None repository_metadata = metadata_util . get_repository_metadata_by_changeset_revision ( trans . app , encoded_repository_id , latest_downloadable_revision ) if ( ( repository_metadata is not None ) and repository_metadata . downloadable ) : return repository_metadata return None
return the latest downloadable repository_metadata record for the received repository .