diff --git a/src/Pure/Admin/build_history.scala b/src/Pure/Admin/build_history.scala --- a/src/Pure/Admin/build_history.scala +++ b/src/Pure/Admin/build_history.scala @@ -1,375 +1,375 @@ /* Title: Pure/Admin/build_history.scala Author: Makarius Build other history versions. */ package isabelle import java.io.{File => JFile} import java.time.format.DateTimeFormatter import java.util.Locale object Build_History { /* log files */ val BUILD_HISTORY = "build_history" val META_INFO_MARKER = "\fmeta_info = " /* augment settings */ def augment_settings( other_isabelle: Other_Isabelle, threads: Int, arch_64: Boolean = false, heap: Int = default_heap, max_heap: Option[Int] = None, more_settings: List[String]): String = { val (ml_platform, ml_settings) = { val windows_32 = "x86-windows" val windows_64 = "x86_64-windows" val platform_32 = other_isabelle("getenv -b ISABELLE_PLATFORM32").check.out val platform_64 = other_isabelle("getenv -b ISABELLE_PLATFORM64").check.out val platform_family = other_isabelle("getenv -b ISABELLE_PLATFORM_FAMILY").check.out val polyml_home = try { Path.explode(other_isabelle("getenv -b ML_HOME").check.out).dir } catch { case ERROR(msg) => error("Bad ML_HOME: " + msg) } def ml_home(platform: String): Path = polyml_home + Path.explode(platform) def err(platform: String): Nothing = error("Platform " + platform + " unavailable on this machine") def check_dir(platform: String): Boolean = platform != "" && ml_home(platform).is_dir val ml_platform = if (Platform.is_windows && arch_64) { if (check_dir(windows_64)) windows_64 else err(windows_64) } else if (Platform.is_windows && !arch_64) { if (check_dir(windows_32)) windows_32 else platform_32 // x86-cygwin } else { val (platform, platform_name) = if (arch_64) (platform_64, "x86_64-" + platform_family) else (platform_32, "x86-" + platform_family) if (check_dir(platform)) platform else err(platform_name) } val ml_options = "--minheap " + heap + (if (max_heap.isDefined) " --maxheap " + max_heap.get else "") + " --gcthreads " + threads + (if (ml_platform.endsWith("-windows")) " --codepage utf8" else "") (ml_platform, List( "ML_HOME=" + File.bash_path(ml_home(ml_platform)), "ML_PLATFORM=" + quote(ml_platform), "ML_OPTIONS=" + quote(ml_options))) } val thread_settings = List( "ISABELLE_JAVA_SYSTEM_OPTIONS=\"$ISABELLE_JAVA_SYSTEM_OPTIONS -Disabelle.threads=" + threads + "\"", "ISABELLE_BUILD_OPTIONS=\"threads=" + threads + "\"") val settings = List(ml_settings, thread_settings) ::: (if (more_settings.isEmpty) Nil else List(more_settings)) File.append(other_isabelle.etc_settings, "\n" + cat_lines(settings.map(terminate_lines(_)))) ml_platform } /** build_history **/ private val default_rev = "tip" private val default_threads = 1 private val default_heap = 1000 private val default_isabelle_identifier = "build_history" def build_history( hg: Mercurial.Repository, progress: Progress = Ignore_Progress, rev: String = default_rev, isabelle_identifier: String = default_isabelle_identifier, components_base: String = "", fresh: Boolean = false, nonfree: Boolean = false, multicore_base: Boolean = false, threads_list: List[Int] = List(default_threads), arch_64: Boolean = false, heap: Int = default_heap, max_heap: Option[Int] = None, more_settings: List[String] = Nil, verbose: Boolean = false, build_args: List[String] = Nil): List[(Process_Result, Path)] = { /* sanity checks */ if (File.eq(Path.explode("~~"), hg.root)) error("Repository coincides with ISABELLE_HOME=" + Path.explode("~~").expand) for (threads <- threads_list if threads < 1) error("Bad threads value < 1: " + threads) if (heap < 100) error("Bad heap value < 100: " + heap) if (max_heap.isDefined && max_heap.get < heap) error("Bad max_heap value < heap: " + max_heap.get) System.getenv("ISABELLE_SETTINGS_PRESENT") match { case null | "" => case _ => error("Cannot run build_history within existing Isabelle settings environment") } /* init repository */ hg.update(rev = rev, clean = true) progress.echo_if(verbose, hg.log(rev, options = "-l1")) - val isabelle_version = hg.identify(rev, options = "-i") + val isabelle_version = hg.id(rev) val other_isabelle = new Other_Isabelle(progress, hg.root, isabelle_identifier) /* main */ val build_history_date = Date.now() val build_host = Isabelle_System.hostname() var first_build = true for (threads <- threads_list) yield { /* init settings */ other_isabelle.init_settings(components_base, nonfree) other_isabelle.resolve_components(verbose) val ml_platform = augment_settings(other_isabelle, threads, arch_64, heap, max_heap, more_settings) val isabelle_output = Path.explode(other_isabelle("getenv -b ISABELLE_OUTPUT").check.out) val isabelle_output_log = isabelle_output + Path.explode("log") val isabelle_base_log = isabelle_output + Path.explode("../base_log") if (first_build) { other_isabelle.resolve_components(verbose) other_isabelle.bash( "env PATH=\"" + File.bash_path(Path.explode("~~/lib/dummy_stty").expand) + ":$PATH\" " + "bin/isabelle jedit -b" + (if (fresh) " -f" else ""), redirect = true, echo = verbose).check Isabelle_System.rm_tree(isabelle_base_log) } Isabelle_System.rm_tree(isabelle_output) Isabelle_System.mkdirs(isabelle_output) /* build */ if (multicore_base && !first_build && isabelle_base_log.is_dir) Isabelle_System.copy_dir(isabelle_base_log, isabelle_output_log) val build_start = Date.now() val res = other_isabelle("build -v " + File.bash_args(build_args), redirect = true, echo = verbose) val build_end = Date.now() /* output log */ val log_path = other_isabelle.isabelle_home_user + Build_Log.log_subdir(build_history_date) + Build_Log.log_filename( BUILD_HISTORY, build_history_date, ml_platform, "M" + threads).ext("gz") val build_info = Build_Log.Log_File(log_path.base.implode, res.out_lines).parse_build_info() val meta_info = List(Build_Log.Field.build_engine -> BUILD_HISTORY, Build_Log.Field.build_host -> build_host, Build_Log.Field.build_start -> Build_Log.print_date(build_start), Build_Log.Field.build_end -> Build_Log.print_date(build_end), Build_Log.Field.isabelle_version -> isabelle_version) val ml_statistics = build_info.finished_sessions.flatMap(session_name => { val session_log = isabelle_output_log + Path.explode(session_name).ext("gz") if (session_log.is_file) { Build_Log.Log_File(session_log).parse_session_info(ml_statistics = true). ml_statistics.map(props => (Build_Log.SESSION_NAME -> session_name) :: props) } else Nil }) val heap_sizes = build_info.finished_sessions.flatMap(session_name => { val heap = isabelle_output + Path.explode(session_name) if (heap.is_file) Some("Heap " + session_name + " (" + Value.Long(heap.file.length) + " bytes)") else None }) Isabelle_System.mkdirs(log_path.dir) File.write_gzip(log_path, terminate_lines( Build_Log.Log_File.print_props(META_INFO_MARKER, meta_info) :: res.out_lines ::: ml_statistics.map(Build_Log.Log_File.print_props(Build_Log.ML_STATISTICS_MARKER, _)) ::: heap_sizes)) /* next build */ if (multicore_base && first_build && isabelle_output_log.is_dir) Isabelle_System.copy_dir(isabelle_output_log, isabelle_base_log) first_build = false (res, log_path) } } /* command line entry point */ def main(args: Array[String]) { Command_Line.tool0 { var multicore_base = false var components_base = "" var heap: Option[Int] = None var max_heap: Option[Int] = None var threads_list = List(default_threads) var isabelle_identifier = default_isabelle_identifier var more_settings: List[String] = Nil var fresh = false var arch_64 = false var nonfree = false var rev = default_rev var verbose = false val getopts = Getopts(""" Usage: isabelle build_history [OPTIONS] REPOSITORY [ARGS ...] Options are: -B first multicore build serves as base for scheduling information -C DIR base directory for Isabelle components (default: $ISABELLE_HOME_USER/../contrib) -H SIZE minimal ML heap in MB (default: """ + default_heap + """ for x86, """ + default_heap * 2 + """ for x86_64) -M THREADS multicore configurations (comma-separated list, default: """ + default_threads + """) -N NAME alternative ISABELLE_IDENTIFIER (default: """ + default_isabelle_identifier + """) -U SIZE maximal ML heap in MB (default: unbounded) -e TEXT additional text for generated etc/settings -f fresh build of Isabelle/Scala components (recommended) -m ARCH processor architecture (32=x86, 64=x86_64, default: x86) -n include nonfree components -r REV update to revision (default: """ + default_rev + """) -v verbose Build Isabelle sessions from the history of another REPOSITORY clone, passing ARGS directly to its isabelle build tool. """, "B" -> (_ => multicore_base = true), "C:" -> (arg => components_base = arg), "H:" -> (arg => heap = Some(Value.Int.parse(arg))), "M:" -> (arg => threads_list = space_explode(',', arg).map(Value.Int.parse(_))), "N:" -> (arg => isabelle_identifier = arg), "U:" -> (arg => max_heap = Some(Value.Int.parse(arg))), "e:" -> (arg => more_settings = more_settings ::: List(arg)), "f" -> (_ => fresh = true), "m:" -> { case "32" | "x86" => arch_64 = false case "64" | "x86_64" => arch_64 = true case bad => error("Bad processor architecture: " + quote(bad)) }, "n" -> (_ => nonfree = true), "r:" -> (arg => rev = arg), "v" -> (_ => verbose = true)) val more_args = getopts(args) val (root, build_args) = more_args match { case root :: build_args => (root, build_args) case _ => getopts.usage() } val hg = Mercurial.repository(Path.explode(root)) val progress = new Console_Progress(stderr = true) val results = build_history(hg, progress = progress, rev = rev, isabelle_identifier = isabelle_identifier, components_base = components_base, fresh = fresh, nonfree = nonfree, multicore_base = multicore_base, threads_list = threads_list, arch_64 = arch_64, heap = heap.getOrElse(if (arch_64) default_heap * 2 else default_heap), max_heap = max_heap, more_settings = more_settings, verbose = verbose, build_args = build_args) for ((_, log_path) <- results) Output.writeln(log_path.implode, stdout = true) val rc = (0 /: results) { case (rc, (res, _)) => rc max res.rc } if (rc != 0) sys.exit(rc) } } /** remote build_history -- via command-line **/ def remote_build_history( session: SSH.Session, isabelle_repos_self: Path, isabelle_repos_other: Path, isabelle_repos_source: String = "http://isabelle.in.tum.de/repos/isabelle", self_update: Boolean = false, progress: Progress = Ignore_Progress, options: String = "", args: String = ""): List[(String, Bytes)] = { using(session.sftp())(sftp => { val isabelle_admin = sftp.path(isabelle_repos_self + Path.explode("Admin")) /* prepare repository clones */ val isabelle_hg = Mercurial.setup_repository( isabelle_repos_source, isabelle_repos_self, ssh = Some(session)) if (self_update) { isabelle_hg.pull() isabelle_hg.update(clean = true) session.execute(File.bash_string(isabelle_admin + "/build") + " jars_fresh").check } Mercurial.setup_repository( sftp.path(isabelle_repos_self), isabelle_repos_other, ssh = Some(session)) /* Admin/build_history */ val result = session.execute( File.bash_string(isabelle_admin + "/build_history") + " " + options + " " + File.bash_string(sftp.path(isabelle_repos_other)) + " " + args, progress_stderr = progress.echo(_)) result.check.out_lines.map(log => (Path.explode(log).base.implode, sftp.read_bytes(log))) }) } } diff --git a/src/Pure/Admin/ci_profile.scala b/src/Pure/Admin/ci_profile.scala --- a/src/Pure/Admin/ci_profile.scala +++ b/src/Pure/Admin/ci_profile.scala @@ -1,149 +1,149 @@ /* Title: Pure/Admin/ci_profile.scala Author: Lars Hupel Build profile for continuous integration services. */ package isabelle import java.time.{Instant, ZoneId} import java.time.format.DateTimeFormatter import java.util.{Properties => JProperties} abstract class CI_Profile extends Isabelle_Tool.Body { private def build(options: Options): (Build.Results, Time) = { val progress = new Console_Progress(verbose = true) val start_time = Time.now() val results = progress.interrupt_handler { Build.build_selection( options = options, progress = progress, clean_build = true, verbose = true, max_jobs = jobs, dirs = include, select_dirs = select, system_mode = false, selection = select_sessions _) } val end_time = Time.now() (results, end_time - start_time) } private def load_properties(): JProperties = { val props = new JProperties() val file_name = Isabelle_System.getenv("ISABELLE_CI_PROPERTIES") if (file_name != "") { val file = Path.explode(file_name).file if (file.exists()) props.load(new java.io.FileReader(file)) props } else props } private def compute_timing(results: Build.Results, group: Option[String]): Timing = { val timings = results.sessions.collect { case session if group.forall(results.info(session).groups.contains(_)) => results(session).timing } (Timing.zero /: timings)(_ + _) } private def with_documents(options: Options): Options = { if (documents) options .bool.update("browser_info", true) .string.update("document", "pdf") .string.update("document_variants", "document:outline=/proof,/ML") else options } final def hg_id(path: Path): String = - Mercurial.repository(path).identify(options = "-i") + Mercurial.repository(path).id() final def print_section(title: String): Unit = println(s"\n=== $title ===\n") final val isabelle_home = Path.explode(Isabelle_System.getenv_strict("ISABELLE_HOME")) final val isabelle_id = hg_id(isabelle_home) final val start_time = Instant.now().atZone(ZoneId.systemDefault).format(DateTimeFormatter.RFC_1123_DATE_TIME) override final def apply(args: List[String]): Unit = { print_section("CONFIGURATION") println(Build_Log.Settings.show()) val props = load_properties() System.getProperties().putAll(props) val options = with_documents(Options.init()) .int.update("parallel_proofs", 2) .int.update("threads", threads) print_section("BUILD") println(s"Build started at $start_time") println(s"Isabelle id $isabelle_id") pre_hook(args) print_section("LOG") val (results, elapsed_time) = build(options) print_section("TIMING") val groups = results.sessions.map(results.info).flatMap(_.groups) for (group <- groups) println(s"Group $group: " + compute_timing(results, Some(group)).message_resources) val total_timing = compute_timing(results, None).copy(elapsed = elapsed_time) println("Overall: " + total_timing.message_resources) if (!results.ok) { print_section("FAILED SESSIONS") for (name <- results.sessions) { if (results.cancelled(name)) { println(s"Session $name: CANCELLED") } else { val result = results(name) if (!result.ok) println(s"Session $name: FAILED ${result.rc}") } } } post_hook(results) System.exit(results.rc) } /* profile */ def documents: Boolean = true def threads: Int def jobs: Int def include: List[Path] def select: List[Path] def pre_hook(args: List[String]): Unit def post_hook(results: Build.Results): Unit def select_sessions(tree: Sessions.Tree): (List[String], Sessions.Tree) } diff --git a/src/Pure/Admin/isabelle_cronjob.scala b/src/Pure/Admin/isabelle_cronjob.scala --- a/src/Pure/Admin/isabelle_cronjob.scala +++ b/src/Pure/Admin/isabelle_cronjob.scala @@ -1,306 +1,309 @@ /* Title: Pure/Admin/isabelle_cronjob.scala Author: Makarius Main entry point for administrative cronjob at TUM. */ package isabelle import scala.annotation.tailrec import scala.collection.mutable object Isabelle_Cronjob { /* file-system state: owned by main cronjob */ val main_dir = Path.explode("~/cronjob") val main_state_file = main_dir + Path.explode("run/main.state") val current_log = main_dir + Path.explode("run/main.log") // owned by log service val cumulative_log = main_dir + Path.explode("log/main.log") // owned by log service val isabelle_repos = main_dir + Path.explode("isabelle") val isabelle_repos_test = main_dir + Path.explode("isabelle-test") val afp_repos = main_dir + Path.explode("AFP") val release_snapshot = Path.explode("~/html-data/release_snapshot") /** particular tasks **/ /* identify Isabelle + AFP repository snapshots */ private val isabelle_identify = Logger_Task("isabelle_identify", logger => { - val isabelle_id = Mercurial.repository(isabelle_repos).identify(options = "-i") + val isabelle_id = Mercurial.repository(isabelle_repos).id() val afp_id = - Mercurial.setup_repository( - logger.cronjob_options.string("afp_repos"), afp_repos).pull_id() + { + val hg = Mercurial.setup_repository(logger.cronjob_options.string("afp_repos"), afp_repos) + hg.pull() + hg.id() + } File.write(logger.log_dir + Build_Log.log_filename("isabelle_identify", logger.start_date), terminate_lines( List("isabelle_identify: " + Build_Log.print_date(logger.start_date), "", "Isabelle version: " + isabelle_id, "AFP version: " + afp_id))) }) /* integrity test of build_history vs. build_history_base */ private val build_history_base = Logger_Task("build_history_base", logger => { for { (result, log_path) <- Build_History.build_history(Mercurial.repository(isabelle_repos_test), rev = "build_history_base", fresh = true, build_args = List("HOL")) } { result.check File.copy(log_path, logger.log_dir + log_path.base) } }) /* build release from repository snapshot */ private val build_release = Logger_Task("build_release", logger => Isabelle_System.with_tmp_dir("isadist")(base_dir => { val new_snapshot = release_snapshot.ext("new") val old_snapshot = release_snapshot.ext("old") Isabelle_System.rm_tree(new_snapshot) Isabelle_System.rm_tree(old_snapshot) Build_Release.build_release(base_dir, parallel_jobs = 4, remote_mac = "macbroy30", website = Some(new_snapshot)) if (release_snapshot.is_dir) File.mv(release_snapshot, old_snapshot) File.mv(new_snapshot, release_snapshot) Isabelle_System.rm_tree(old_snapshot) })) /* remote build_history */ private sealed case class Remote_Build( host: String, user: String = "", port: Int = SSH.default_port, shared_home: Boolean = false, options: String = "", args: String = "-a") private val remote_builds = List( Remote_Build("lxbroy10", options = "-m32 -M4", shared_home = true), Remote_Build("macbroy2", options = "-m32 -M4")) private def remote_build_history(rev: String, r: Remote_Build): Logger_Task = Logger_Task("build_history-" + r.host, logger => { using(logger.ssh_context.open_session(host = r.host, user = r.user, port = r.port))( session => { val results = Build_History.remote_build_history(session, isabelle_repos, isabelle_repos.ext(r.host), isabelle_repos_source = logger.cronjob_options.string("isabelle_repos"), self_update = !r.shared_home, options = r.options + " -f -r " + File.bash_string(rev), args = r.args) for ((log, bytes) <- results) Bytes.write(logger.log_dir + Path.explode(log), bytes) }) }) /** task logging **/ sealed case class Logger_Task(name: String = "", body: Logger => Unit) class Log_Service private[Isabelle_Cronjob]( progress: Progress, val cronjob_options: Options, val ssh_context: SSH) { current_log.file.delete private val thread: Consumer_Thread[String] = Consumer_Thread.fork("cronjob: logger", daemon = true)( consume = (text: String) => { // critical File.append(current_log, text + "\n") File.append(cumulative_log, text + "\n") progress.echo(text) true }) def shutdown() { thread.shutdown() } val hostname = Isabelle_System.hostname() def log(date: Date, task_name: String, msg: String): Unit = if (task_name != "") thread.send( "[" + Build_Log.print_date(date) + ", " + hostname + ", " + task_name + "]: " + msg) def start_logger(start_date: Date, task_name: String): Logger = new Logger(this, start_date, task_name) def run_task(start_date: Date, task: Logger_Task) { val logger = start_logger(start_date, task.name) val res = Exn.capture { task.body(logger) } val end_date = Date.now() val err = res match { case Exn.Res(_) => None case Exn.Exn(exn) => Some(Exn.message(exn)) } logger.log_end(end_date, err) } def fork_task(start_date: Date, task: Logger_Task): Task = new Task(task.name, run_task(start_date, task)) } class Logger private[Isabelle_Cronjob]( val log_service: Log_Service, val start_date: Date, val task_name: String) { def cronjob_options: Options = log_service.cronjob_options def ssh_context: SSH = log_service.ssh_context def log(date: Date, msg: String): Unit = log_service.log(date, task_name, msg) def log_end(end_date: Date, err: Option[String]) { val elapsed_time = end_date.time - start_date.time val msg = (if (err.isEmpty) "finished" else "ERROR " + err.get) + (if (elapsed_time.seconds < 3.0) "" else " (" + elapsed_time.message_hms + " elapsed time)") log(end_date, msg) } val log_dir: Path = main_dir + Build_Log.log_subdir(start_date) Isabelle_System.mkdirs(log_dir) log(start_date, "started") } class Task private[Isabelle_Cronjob](name: String, body: => Unit) { private val future: Future[Unit] = Future.thread("cronjob: " + name) { body } def is_finished: Boolean = future.is_finished } /** cronjob **/ def cronjob(progress: Progress, exclude_task: Set[String]) { /* soft lock */ val still_running = try { Some(File.read(main_state_file)) } catch { case ERROR(_) => None } still_running match { case None | Some("") => case Some(running) => error("Isabelle cronjob appears to be still running: " + running) } /* log service */ val cronjob_options = Options.load(Path.explode("~~/Admin/cronjob/cronjob.options")) val ssh_context = SSH.init(Options.init()) val log_service = new Log_Service(progress, cronjob_options, ssh_context) def run(start_date: Date, task: Logger_Task) { log_service.run_task(start_date, task) } def run_now(task: Logger_Task) { run(Date.now(), task) } /* structured tasks */ def SEQ(tasks: Logger_Task*): Logger_Task = Logger_Task(body = _ => for (task <- tasks.iterator if !exclude_task(task.name) || task.name == "") run_now(task)) def PAR(tasks: Logger_Task*): Logger_Task = Logger_Task(body = _ => { @tailrec def join(running: List[Task]) { running.partition(_.is_finished) match { case (Nil, Nil) => case (Nil, _ :: _) => Thread.sleep(500); join(running) case (_ :: _, remaining) => join(remaining) } } val start_date = Date.now() val running = for (task <- tasks.toList if !exclude_task(task.name)) yield log_service.fork_task(start_date, task) join(running) }) /* main */ val main_start_date = Date.now() File.write(main_state_file, main_start_date + " " + log_service.hostname) - val rev = Mercurial.repository(isabelle_repos).identify(options = "-i") + val rev = Mercurial.repository(isabelle_repos).id() run(main_start_date, Logger_Task("isabelle_cronjob", _ => run_now( SEQ(isabelle_identify, build_history_base, build_release, PAR(remote_builds.map(remote_build_history(rev, _)):_*))))) log_service.shutdown() main_state_file.file.delete } /** command line entry point **/ def main(args: Array[String]) { Command_Line.tool0 { var force = false var verbose = false var exclude_task = Set.empty[String] val getopts = Getopts(""" Usage: Admin/cronjob/main [OPTIONS] Options are: -f apply force to do anything -v verbose -x NAME exclude tasks with this name """, "f" -> (_ => force = true), "v" -> (_ => verbose = true), "x:" -> (arg => exclude_task += arg)) val more_args = getopts(args) if (more_args.nonEmpty) getopts.usage() val progress = if (verbose) new Console_Progress() else Ignore_Progress if (force) cronjob(progress, exclude_task) else error("Need to apply force to do anything") } } } diff --git a/src/Pure/General/mercurial.scala b/src/Pure/General/mercurial.scala --- a/src/Pure/General/mercurial.scala +++ b/src/Pure/General/mercurial.scala @@ -1,107 +1,103 @@ /* Title: Pure/General/mercurial.scala Author: Makarius Support for Mercurial repositories. */ package isabelle import java.io.{File => JFile} object Mercurial { /* command-line syntax */ def optional(s: String, prefix: String = ""): String = if (s == "") "" else " " + prefix + " " + File.bash_string(s) def opt_flag(flag: String, b: Boolean): String = if (b) " " + flag else "" def opt_rev(s: String): String = optional(s, "--rev") def opt_template(s: String): String = optional(s, "--template") /* repository access */ def repository(root: Path, ssh: Option[SSH.Session] = None): Repository = { val hg = new Repository(root, ssh) hg.command("root").check hg } def clone_repository( source: String, root: Path, options: String = "", ssh: Option[SSH.Session] = None): Repository = { val hg = new Repository(root, ssh) hg.command("clone", File.bash_string(source) + " " + File.bash_path(hg.root), options).check hg } def setup_repository(source: String, root: Path, ssh: Option[SSH.Session] = None): Repository = ssh match { case None => if (root.is_dir) repository(root) else clone_repository(source, root) case Some(session) => using(session.sftp())(sftp => if (sftp.is_dir(sftp.path(root))) repository(root, ssh = ssh) else clone_repository(source, root, ssh = ssh)) } class Repository private[Mercurial](root_path: Path, ssh: Option[SSH.Session]) { hg => val root = ssh match { case None => root_path.expand case Some(session) => using(session.sftp())(sftp => root_path.expand_env(sftp.settings)) } override def toString: String = ssh match { case None => root.implode case Some(session) => session.toString + ":" + root.implode } def command(name: String, args: String = "", options: String = ""): Process_Result = { val cmdline = "\"${HG:-hg}\"" + (if (name == "clone") "" else " --repository " + File.bash_path(root)) + " --noninteractive " + name + " " + options + " " + args ssh match { case None => Isabelle_System.bash(cmdline) case Some(session) => session.execute(cmdline) } } def heads(template: String = "{node|short}\n", options: String = ""): List[String] = hg.command("heads", opt_template(template), options).check.out_lines - def identify(rev: String = "", options: String = ""): String = + def identify(rev: String = "tip", options: String = ""): String = hg.command("id", opt_rev(rev), options).check.out_lines.headOption getOrElse "" + def id(rev: String = "tip"): String = identify(rev, options = "-i") + def manifest(rev: String = "", options: String = ""): List[String] = hg.command("manifest", opt_rev(rev), options).check.out_lines def log(rev: String = "", template: String = "", options: String = ""): String = hg.command("log", opt_rev(rev) + opt_template(template), options).check.out def pull(remote: String = "", rev: String = "", options: String = ""): Unit = hg.command("pull", opt_rev(rev) + optional(remote), options).check - def pull_id(remote: String = ""): String = - { - hg.pull(remote = remote, options = "-q") - hg.identify("tip", options = "-i") - } - def update( rev: String = "", clean: Boolean = false, check: Boolean = false, options: String = "") { hg.command("update", opt_rev(rev) + opt_flag("--clean", clean) + opt_flag("--check", check), options).check } } }