def make_remote_url(scheme, username, hostname, port, project):
    """Builds a gerrit remote URL."""
    if port is None and scheme == 'ssh':
        port = 29418
    hostport = '%s:%s' % (hostname, port) if port else hostname
    if username:
        return "%s://%s@%s/%s" % (scheme, username, hostport, project)
    else:
        return "%s://%s/%s" % (scheme, hostport, project)