1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from translate.storage.versioncontrol import run_command
24 from translate.storage.versioncontrol import GenericRevisionControlSystem
25
26
28 """check if hg is installed"""
29 exitcode, output, error = run_command(["hg", "--version"])
30 return exitcode == 0
31
33 """return a tuple of (major, minor) for the installed bazaar client"""
34 import re
35 command = ["hg", "--version"]
36 exitcode, output, error = run_command(command)
37 if exitcode == 0:
38 version_line = output.splitlines()[0]
39 version_match = re.search(r"\d+\.\d+", version_line)
40 if version_match:
41 major, minor = version_match.group().split(".")
42 if (major.isdigit() and minor.isdigit()):
43 return (int(major), int(minor))
44
45 return (0, 0)
46
47
48 -class hg(GenericRevisionControlSystem):
49 """Class to manage items under revision control of mercurial."""
50
51 RCS_METADIR = ".hg"
52 SCAN_PARENTS = True
53
54 - def update(self, revision=None):
55 """Does a clean update of the given path
56
57 @param revision: ignored for hg
58 """
59
60 command = ["hg", "-R", self.root_dir, "revert",
61 "--all", self.location_abs]
62 exitcode, output_revert, error = run_command(command)
63 if exitcode != 0:
64 raise IOError("[Mercurial] error running '%s': %s" % (command, error))
65
66 command = ["hg", "-R", self.root_dir, "pull"]
67 exitcode, output_pull, error = run_command(command)
68 if exitcode != 0:
69 raise IOError("[Mercurial] error running '%s': %s" % (command, error))
70
71 command = ["hg", "-R", self.root_dir, "update"]
72 exitcode, output_update, error = run_command(command)
73 if exitcode != 0:
74 raise IOError("[Mercurial] error running '%s': %s" % (command, error))
75 return output_revert + output_pull + output_update
76
77 - def commit(self, message=None, author=None):
78 """Commits the file and supplies the given commit message if present"""
79 if message is None:
80 message = ""
81
82 command = ["hg", "-R", self.root_dir, "commit", "-m", message]
83
84 if author and (get_version() >= (1, 0)):
85 command.extend(["--user", author])
86
87 command.append(self.location_abs)
88 exitcode, output_commit, error = run_command(command)
89 if exitcode != 0:
90 raise IOError("[Mercurial] Error running '%s': %s" \
91 % (command, error))
92
93 command = ["hg", "-R", self.root_dir, "push"]
94 exitcode, output_push, error = run_command(command)
95 if exitcode != 0:
96 raise IOError("[Mercurial] Error running '%s': %s" \
97 % (command, error))
98 return output_commit + output_push
99
101 """Get a clean version of a file from the hg repository"""
102
103 command = ["hg", "-R", self.root_dir, "cat",
104 self.location_abs]
105 exitcode, output, error = run_command(command)
106 if exitcode != 0:
107 raise IOError("[Mercurial] Error running '%s': %s" \
108 % (command, error))
109 return output
110