src/Pure/Tools/mkroot.scala
changeset 67069 f11486d31586
parent 67043 848672fcaee5
     1.1 --- a/src/Pure/Tools/mkroot.scala	Mon Nov 13 15:00:21 2017 +0100
     1.2 +++ b/src/Pure/Tools/mkroot.scala	Mon Nov 13 15:07:03 2017 +0100
     1.3 @@ -22,6 +22,7 @@
     1.4      session_name: String = "",
     1.5      session_dir: Path = Path.current,
     1.6      session_parent: String = "",
     1.7 +    init_repos: Boolean = false,
     1.8      title: String = "",
     1.9      author: String = "",
    1.10      progress: Progress = No_Progress)
    1.11 @@ -37,6 +38,9 @@
    1.12      val document_path = session_dir + Path.explode("document")
    1.13      if (document_path.file.exists) error("Cannot overwrite existing " + document_path)
    1.14  
    1.15 +    val root_tex = session_dir + Path.explode("document/root.tex")
    1.16 +
    1.17 +
    1.18      progress.echo("\nPreparing session " + quote(name) + " in " + session_dir)
    1.19  
    1.20  
    1.21 @@ -61,7 +65,6 @@
    1.22      /* document directory */
    1.23  
    1.24      {
    1.25 -      val root_tex = session_dir + Path.explode("document/root.tex")
    1.26        progress.echo("  creating " + root_tex)
    1.27  
    1.28        Isabelle_System.mkdirs(root_tex.dir)
    1.29 @@ -130,6 +133,33 @@
    1.30      }
    1.31  
    1.32  
    1.33 +    /* Mercurial repository */
    1.34 +
    1.35 +    if (init_repos) {
    1.36 +      progress.echo("  \nInitializing Mercurial repository " + session_dir)
    1.37 +
    1.38 +      val hg = Mercurial.init_repository(session_dir)
    1.39 +
    1.40 +      val hg_ignore = session_dir + Path.explode(".hgignore")
    1.41 +      File.write(hg_ignore,
    1.42 +"""syntax: glob
    1.43 +
    1.44 +*~
    1.45 +*.marks
    1.46 +*.orig
    1.47 +*.rej
    1.48 +.DS_Store
    1.49 +.swp
    1.50 +
    1.51 +syntax: regexp
    1.52 +
    1.53 +^output/
    1.54 +""")
    1.55 +
    1.56 +      hg.add(List(root_path, root_tex, hg_ignore))
    1.57 +    }
    1.58 +
    1.59 +
    1.60      /* notes */
    1.61  
    1.62      {
    1.63 @@ -149,6 +179,7 @@
    1.64    val isabelle_tool = Isabelle_Tool("mkroot", "prepare session root directory", args =>
    1.65    {
    1.66      var author = ""
    1.67 +    var init_repos = false
    1.68      var title = ""
    1.69      var session_name = ""
    1.70  
    1.71 @@ -157,12 +188,14 @@
    1.72  
    1.73    Options are:
    1.74      -A LATEX     provide author in LaTeX notation (default: user name)
    1.75 +    -I           init Mercurial repository and add generated files
    1.76      -T LATEX     provide title in LaTeX notation (default: session name)
    1.77      -n NAME      alternative session name (default: directory base name)
    1.78  
    1.79    Prepare session root directory (default: current directory).
    1.80  """,
    1.81        "A:" -> (arg => author = arg),
    1.82 +      "I" -> (arg => init_repos = true),
    1.83        "T:" -> (arg => title = arg),
    1.84        "n:" -> (arg => session_name = arg))
    1.85  
    1.86 @@ -175,7 +208,7 @@
    1.87          case _ => getopts.usage()
    1.88        }
    1.89  
    1.90 -    mkroot(session_name = session_name, session_dir = session_dir, author = author, title = title,
    1.91 -      progress = new Console_Progress)
    1.92 +    mkroot(session_name = session_name, session_dir = session_dir, init_repos = init_repos,
    1.93 +      author = author, title = title, progress = new Console_Progress)
    1.94    })
    1.95  }