src/Pure/Tools/phabricator.scala
changeset 71550 f2b944898636
parent 71440 8b0b8b9ea653
child 71601 97ccf48c2f0c
equal deleted inserted replaced
71549:319599ba28cf 71550:f2b944898636
    57 
    57 
    58   def default_repo(name: String): Path = default_root(name) + Path.basic("repo")
    58   def default_repo(name: String): Path = default_root(name) + Path.basic("repo")
    59 
    59 
    60   val default_mailers: Path = Path.explode("mailers.json")
    60   val default_mailers: Path = Path.explode("mailers.json")
    61 
    61 
    62   val default_system_port = 22
    62   val default_system_port = SSH.default_port
    63   val alternative_system_port = 222
    63   val alternative_system_port = 222
    64   val default_server_port = 2222
    64   val default_server_port = 2222
    65 
    65 
    66   val standard_mercurial_source = "https://www.mercurial-scm.org/release/mercurial-3.9.2.tar.gz"
    66   val standard_mercurial_source = "https://www.mercurial-scm.org/release/mercurial-3.9.2.tar.gz"
    67 
    67 
   679   private val Port = """^\s*Port\s+(\d+)\s*$""".r
   679   private val Port = """^\s*Port\s+(\d+)\s*$""".r
   680   private val No_Port = """^#\s*Port\b.*$""".r
   680   private val No_Port = """^#\s*Port\b.*$""".r
   681   private val Any_Port = """^#?\s*Port\b.*$""".r
   681   private val Any_Port = """^#?\s*Port\b.*$""".r
   682 
   682 
   683   def conf_ssh_port(port: Int): String =
   683   def conf_ssh_port(port: Int): String =
   684     if (port == 22) "#Port 22" else "Port " + port
   684     if (port == SSH.default_port) "#Port " + SSH.default_port else "Port " + port
   685 
   685 
   686   def read_ssh_port(conf: Path): Int =
   686   def read_ssh_port(conf: Path): Int =
   687   {
   687   {
   688     val lines = split_lines(File.read(conf))
   688     val lines = split_lines(File.read(conf))
   689     val ports =
   689     val ports =
   690       lines.flatMap({
   690       lines.flatMap({
   691         case Port(Value.Int(p)) => Some(p)
   691         case Port(Value.Int(p)) => Some(p)
   692         case No_Port() => Some(22)
   692         case No_Port() => Some(SSH.default_port)
   693         case _ => None
   693         case _ => None
   694       })
   694       })
   695     ports match {
   695     ports match {
   696       case List(port) => port
   696       case List(port) => port
   697       case Nil => error("Missing Port specification in " + conf)
   697       case Nil => error("Missing Port specification in " + conf)
   792 """)
   792 """)
   793 
   793 
   794     for (config <- configs) {
   794     for (config <- configs) {
   795       progress.echo("phabricator " + quote(config.name) + " port " +  server_port)
   795       progress.echo("phabricator " + quote(config.name) + " port " +  server_port)
   796       config.execute("config set diffusion.ssh-port " + Bash.string(server_port.toString))
   796       config.execute("config set diffusion.ssh-port " + Bash.string(server_port.toString))
   797       if (server_port == 22) config.execute("config delete diffusion.ssh-port")
   797       if (server_port == SSH.default_port) config.execute("config delete diffusion.ssh-port")
   798     }
   798     }
   799   }
   799   }
   800 
   800 
   801 
   801 
   802   /* Isabelle tool wrapper */
   802   /* Isabelle tool wrapper */
   912     }
   912     }
   913 
   913 
   914 
   914 
   915     /* context for operations */
   915     /* context for operations */
   916 
   916 
   917     def apply(user: String, host: String, port: Int = 22): API =
   917     def apply(user: String, host: String, port: Int = SSH.default_port): API =
   918       new API(user, host, port)
   918       new API(user, host, port)
   919   }
   919   }
   920 
   920 
   921   final class API private(ssh_user: String, ssh_host: String, ssh_port: Int)
   921   final class API private(ssh_user: String, ssh_host: String, ssh_port: Int)
   922   {
   922   {
   923     /* connection */
   923     /* connection */
   924 
   924 
   925     require(ssh_host.nonEmpty && ssh_port >= 0)
   925     require(ssh_host.nonEmpty && ssh_port >= 0)
   926 
   926 
   927     private def ssh_user_prefix: String = if (ssh_user.isEmpty) "" else ssh_user + "@"
   927     private def ssh_user_prefix: String = SSH.user_prefix(ssh_user)
   928     private def ssh_port_suffix: String = if (ssh_port == 22) "" else ":" + ssh_port
   928     private def ssh_port_suffix: String = SSH.port_suffix(ssh_port)
   929 
   929 
   930     override def toString: String = ssh_user_prefix + ssh_host + ssh_port_suffix
   930     override def toString: String = ssh_user_prefix + ssh_host + ssh_port_suffix
   931     def hg_url: String = "ssh://" + ssh_user_prefix + ssh_host + ssh_port_suffix
   931     def hg_url: String = "ssh://" + ssh_user_prefix + ssh_host + ssh_port_suffix
   932 
   932 
   933 
   933