author | wenzelm |
Wed, 12 Oct 2016 15:48:05 +0200 | |
changeset 64168 | e573b985390c |
parent 64167 | 097d122222f6 |
child 64169 | 3b618d52119e |
permissions | -rw-r--r-- |
63997
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/General/mercurial.scala |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
3 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
4 |
Support for Mercurial repositories. |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
5 |
*/ |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
6 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
8 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
9 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
10 |
import java.io.{File => JFile} |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
11 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
12 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
13 |
object Mercurial |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
14 |
{ |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
15 |
/* command-line syntax */ |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
16 |
|
63999 | 17 |
def optional(s: String, prefix: String = ""): String = |
18 |
if (s == "") "" else " " + prefix + " " + File.bash_string(s) |
|
19 |
||
20 |
def opt_flag(flag: String, b: Boolean): String = if (b) " " + flag else "" |
|
21 |
def opt_rev(s: String): String = optional(s, "--rev") |
|
22 |
def opt_template(s: String): String = optional(s, "--template") |
|
63997
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
23 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
24 |
|
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
25 |
/* repository access */ |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
26 |
|
64167
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
27 |
def repository(root: Path, ssh: Option[SSH.Session] = None): Repository = |
64168 | 28 |
{ |
29 |
val hg = new Repository(root, ssh) |
|
30 |
hg.command("root").check |
|
31 |
hg |
|
32 |
} |
|
33 |
||
34 |
def clone_repository( |
|
35 |
source: String, dest: Path, options: String = "", ssh: Option[SSH.Session] = None): Repository = |
|
36 |
{ |
|
37 |
val hg = new Repository(dest, ssh) |
|
38 |
hg.command("clone", |
|
39 |
File.bash_string(source) + " " + File.bash_string(dest.implode), options).check |
|
40 |
hg |
|
41 |
} |
|
63997
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
42 |
|
64167
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
43 |
class Repository private[Mercurial](val root: Path, ssh: Option[SSH.Session]) |
63997
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
44 |
{ |
64167
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
45 |
hg => |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
46 |
|
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
47 |
override def toString: String = |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
48 |
ssh match { |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
49 |
case None => root.implode |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
50 |
case Some(session) => quote(session.toString + ":" + root.implode) |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
51 |
} |
63997
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
52 |
|
64168 | 53 |
def command(name: String, args: String = "", options: String = ""): Process_Result = |
64167
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
54 |
{ |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
55 |
val cmdline = |
64168 | 56 |
"\"${HG:-hg}\"" + |
57 |
(if (name == "clone") "" else " --repository " + File.bash_string(root.implode)) + |
|
58 |
" --noninteractive " + name + " " + options + " " + args |
|
64167
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
59 |
ssh match { |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
60 |
case None => Isabelle_System.bash(cmdline) |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
61 |
case Some(session) => session.execute(cmdline) |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
62 |
} |
097d122222f6
support remote repositories via ssh command execution;
wenzelm
parents:
64162
diff
changeset
|
63 |
} |
63999 | 64 |
|
65 |
def heads(template: String = "{node|short}\n", options: String = ""): List[String] = |
|
64168 | 66 |
hg.command("heads", opt_template(template), options).check.out_lines |
63999 | 67 |
|
63998 | 68 |
def identify(rev: String = "", options: String = ""): String = |
64168 | 69 |
hg.command("id", opt_rev(rev), options).check.out_lines.headOption getOrElse "" |
63998 | 70 |
|
71 |
def manifest(rev: String = "", options: String = ""): List[String] = |
|
64168 | 72 |
hg.command("manifest", opt_rev(rev), options).check.out_lines |
63997
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
73 |
|
64033 | 74 |
def log(rev: String = "", template: String = "", options: String = ""): String = |
64168 | 75 |
hg.command("log", opt_rev(rev) + opt_template(template), options).check.out |
64027 | 76 |
|
63999 | 77 |
def pull(remote: String = "", rev: String = "", options: String = ""): Unit = |
64168 | 78 |
hg.command("pull", opt_rev(rev) + optional(remote), options).check |
63999 | 79 |
|
64168 | 80 |
def update( |
81 |
rev: String = "", clean: Boolean = false, check: Boolean = false, options: String = "") |
|
63999 | 82 |
{ |
64168 | 83 |
hg.command("update", |
84 |
opt_rev(rev) + opt_flag("--clean", clean) + opt_flag("--check", check), options).check |
|
63999 | 85 |
} |
63997
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
86 |
} |
e11ccb5aa82f
more formal Mercurial support (with the potential to upgrade to command server);
wenzelm
parents:
diff
changeset
|
87 |
} |