Show More
@@ -1,103 +1,107 b'' | |||
|
1 | 1 | # changelog.py - changelog class for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from revlog import * |
|
9 | 9 | from i18n import gettext as _ |
|
10 | 10 | from demandload import demandload |
|
11 | 11 | demandload(globals(), "os time util") |
|
12 | 12 | |
|
13 | 13 | def _string_escape(text): |
|
14 | 14 | """ |
|
15 | 15 | >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} |
|
16 | 16 | >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d |
|
17 | 17 | >>> s |
|
18 | 18 | 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' |
|
19 | 19 | >>> res = _string_escape(s) |
|
20 | 20 | >>> s == _string_unescape(res) |
|
21 | 21 | True |
|
22 | 22 | """ |
|
23 | 23 | # subset of the string_escape codec |
|
24 | 24 | text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
|
25 | 25 | return text.replace('\0', '\\0') |
|
26 | 26 | |
|
27 | 27 | def _string_unescape(text): |
|
28 | 28 | return text.decode('string_escape') |
|
29 | 29 | |
|
30 | 30 | class changelog(revlog): |
|
31 | 31 | def __init__(self, opener, defversion=REVLOGV0): |
|
32 | 32 | revlog.__init__(self, opener, "00changelog.i", "00changelog.d", |
|
33 | 33 | defversion) |
|
34 | 34 | |
|
35 | 35 | def decode_extra(self, text): |
|
36 | 36 | extra = {} |
|
37 | 37 | for l in text.split('\0'): |
|
38 | 38 | if not l: |
|
39 | 39 | continue |
|
40 | 40 | k, v = _string_unescape(l).split(':', 1) |
|
41 | 41 | extra[k] = v |
|
42 | 42 | return extra |
|
43 | 43 | |
|
44 | 44 | def encode_extra(self, d): |
|
45 | 45 | items = [_string_escape(":".join(t)) for t in d.iteritems()] |
|
46 | 46 | return "\0".join(items) |
|
47 | 47 | |
|
48 | 48 | def extract(self, text): |
|
49 | 49 | """ |
|
50 | 50 | format used: |
|
51 | 51 | nodeid\n : manifest node in ascii |
|
52 | 52 | user\n : user, no \n or \r allowed |
|
53 | 53 | time tz extra\n : date (time is int or float, timezone is int) |
|
54 | 54 | : extra is metadatas, encoded and separated by '\0' |
|
55 | 55 | : older versions ignore it |
|
56 | 56 | files\n\n : files modified by the cset, no \n or \r allowed |
|
57 | 57 | (.*) : comment (free text, ideally utf-8) |
|
58 | 58 | |
|
59 | 59 | changelog v0 doesn't use extra |
|
60 | 60 | """ |
|
61 | 61 | if not text: |
|
62 | return (nullid, "", (0, 0), [], "", {}) | |
|
62 | return (nullid, "", (0, 0), [], "", {'branch': 'default'}) | |
|
63 | 63 | last = text.index("\n\n") |
|
64 | 64 | desc = util.tolocal(text[last + 2:]) |
|
65 | 65 | l = text[:last].split('\n') |
|
66 | 66 | manifest = bin(l[0]) |
|
67 | 67 | user = util.tolocal(l[1]) |
|
68 | 68 | |
|
69 | 69 | extra_data = l[2].split(' ', 2) |
|
70 | 70 | if len(extra_data) != 3: |
|
71 | 71 | time = float(extra_data.pop(0)) |
|
72 | 72 | try: |
|
73 | 73 | # various tools did silly things with the time zone field. |
|
74 | 74 | timezone = int(extra_data[0]) |
|
75 | 75 | except: |
|
76 | 76 | timezone = 0 |
|
77 | 77 | extra = {} |
|
78 | 78 | else: |
|
79 | 79 | time, timezone, extra = extra_data |
|
80 | 80 | time, timezone = float(time), int(timezone) |
|
81 | 81 | extra = self.decode_extra(extra) |
|
82 | if not extra.get('branch'): | |
|
83 | extra['branch'] = 'default' | |
|
82 | 84 | files = l[3:] |
|
83 | 85 | return (manifest, user, (time, timezone), files, desc, extra) |
|
84 | 86 | |
|
85 | 87 | def read(self, node): |
|
86 | 88 | return self.extract(self.revision(node)) |
|
87 | 89 | |
|
88 | 90 | def add(self, manifest, list, desc, transaction, p1=None, p2=None, |
|
89 | 91 | user=None, date=None, extra={}): |
|
90 | 92 | |
|
91 | 93 | user, desc = util.fromlocal(user), util.fromlocal(desc) |
|
92 | 94 | |
|
93 | 95 | if date: |
|
94 | 96 | parseddate = "%d %d" % util.parsedate(date) |
|
95 | 97 | else: |
|
96 | 98 | parseddate = "%d %d" % util.makedate() |
|
99 | if extra and extra.get("branch") in ("default", ""): | |
|
100 | del extra["branch"] | |
|
97 | 101 | if extra: |
|
98 | 102 | extra = self.encode_extra(extra) |
|
99 | 103 | parseddate = "%s %s" % (parseddate, extra) |
|
100 | 104 | list.sort() |
|
101 | 105 | l = [hex(manifest), user, parseddate] + list + ["", desc] |
|
102 | 106 | text = "\n".join(l) |
|
103 | 107 | return self.addrevision(text, transaction, self.count(), p1, p2) |
@@ -1,775 +1,776 b'' | |||
|
1 | 1 | # cmdutil.py - help for command processing in mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from demandload import demandload |
|
9 | 9 | from node import * |
|
10 | 10 | from i18n import gettext as _ |
|
11 | 11 | demandload(globals(), 'os sys') |
|
12 | 12 | demandload(globals(), 'mdiff util templater patch') |
|
13 | 13 | |
|
14 | 14 | revrangesep = ':' |
|
15 | 15 | |
|
16 | 16 | def revpair(repo, revs): |
|
17 | 17 | '''return pair of nodes, given list of revisions. second item can |
|
18 | 18 | be None, meaning use working dir.''' |
|
19 | 19 | |
|
20 | 20 | def revfix(repo, val, defval): |
|
21 | 21 | if not val and val != 0 and defval is not None: |
|
22 | 22 | val = defval |
|
23 | 23 | return repo.lookup(val) |
|
24 | 24 | |
|
25 | 25 | if not revs: |
|
26 | 26 | return repo.dirstate.parents()[0], None |
|
27 | 27 | end = None |
|
28 | 28 | if len(revs) == 1: |
|
29 | 29 | if revrangesep in revs[0]: |
|
30 | 30 | start, end = revs[0].split(revrangesep, 1) |
|
31 | 31 | start = revfix(repo, start, 0) |
|
32 | 32 | end = revfix(repo, end, repo.changelog.count() - 1) |
|
33 | 33 | else: |
|
34 | 34 | start = revfix(repo, revs[0], None) |
|
35 | 35 | elif len(revs) == 2: |
|
36 | 36 | if revrangesep in revs[0] or revrangesep in revs[1]: |
|
37 | 37 | raise util.Abort(_('too many revisions specified')) |
|
38 | 38 | start = revfix(repo, revs[0], None) |
|
39 | 39 | end = revfix(repo, revs[1], None) |
|
40 | 40 | else: |
|
41 | 41 | raise util.Abort(_('too many revisions specified')) |
|
42 | 42 | return start, end |
|
43 | 43 | |
|
44 | 44 | def revrange(repo, revs): |
|
45 | 45 | """Yield revision as strings from a list of revision specifications.""" |
|
46 | 46 | |
|
47 | 47 | def revfix(repo, val, defval): |
|
48 | 48 | if not val and val != 0 and defval is not None: |
|
49 | 49 | return defval |
|
50 | 50 | return repo.changelog.rev(repo.lookup(val)) |
|
51 | 51 | |
|
52 | 52 | seen, l = {}, [] |
|
53 | 53 | for spec in revs: |
|
54 | 54 | if revrangesep in spec: |
|
55 | 55 | start, end = spec.split(revrangesep, 1) |
|
56 | 56 | start = revfix(repo, start, 0) |
|
57 | 57 | end = revfix(repo, end, repo.changelog.count() - 1) |
|
58 | 58 | step = start > end and -1 or 1 |
|
59 | 59 | for rev in xrange(start, end+step, step): |
|
60 | 60 | if rev in seen: |
|
61 | 61 | continue |
|
62 | 62 | seen[rev] = 1 |
|
63 | 63 | l.append(rev) |
|
64 | 64 | else: |
|
65 | 65 | rev = revfix(repo, spec, None) |
|
66 | 66 | if rev in seen: |
|
67 | 67 | continue |
|
68 | 68 | seen[rev] = 1 |
|
69 | 69 | l.append(rev) |
|
70 | 70 | |
|
71 | 71 | return l |
|
72 | 72 | |
|
73 | 73 | def make_filename(repo, pat, node, |
|
74 | 74 | total=None, seqno=None, revwidth=None, pathname=None): |
|
75 | 75 | node_expander = { |
|
76 | 76 | 'H': lambda: hex(node), |
|
77 | 77 | 'R': lambda: str(repo.changelog.rev(node)), |
|
78 | 78 | 'h': lambda: short(node), |
|
79 | 79 | } |
|
80 | 80 | expander = { |
|
81 | 81 | '%': lambda: '%', |
|
82 | 82 | 'b': lambda: os.path.basename(repo.root), |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | try: |
|
86 | 86 | if node: |
|
87 | 87 | expander.update(node_expander) |
|
88 | 88 | if node and revwidth is not None: |
|
89 | 89 | expander['r'] = (lambda: |
|
90 | 90 | str(repo.changelog.rev(node)).zfill(revwidth)) |
|
91 | 91 | if total is not None: |
|
92 | 92 | expander['N'] = lambda: str(total) |
|
93 | 93 | if seqno is not None: |
|
94 | 94 | expander['n'] = lambda: str(seqno) |
|
95 | 95 | if total is not None and seqno is not None: |
|
96 | 96 | expander['n'] = lambda: str(seqno).zfill(len(str(total))) |
|
97 | 97 | if pathname is not None: |
|
98 | 98 | expander['s'] = lambda: os.path.basename(pathname) |
|
99 | 99 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
100 | 100 | expander['p'] = lambda: pathname |
|
101 | 101 | |
|
102 | 102 | newname = [] |
|
103 | 103 | patlen = len(pat) |
|
104 | 104 | i = 0 |
|
105 | 105 | while i < patlen: |
|
106 | 106 | c = pat[i] |
|
107 | 107 | if c == '%': |
|
108 | 108 | i += 1 |
|
109 | 109 | c = pat[i] |
|
110 | 110 | c = expander[c]() |
|
111 | 111 | newname.append(c) |
|
112 | 112 | i += 1 |
|
113 | 113 | return ''.join(newname) |
|
114 | 114 | except KeyError, inst: |
|
115 | 115 | raise util.Abort(_("invalid format spec '%%%s' in output file name") % |
|
116 | 116 | inst.args[0]) |
|
117 | 117 | |
|
118 | 118 | def make_file(repo, pat, node=None, |
|
119 | 119 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
120 | 120 | if not pat or pat == '-': |
|
121 | 121 | return 'w' in mode and sys.stdout or sys.stdin |
|
122 | 122 | if hasattr(pat, 'write') and 'w' in mode: |
|
123 | 123 | return pat |
|
124 | 124 | if hasattr(pat, 'read') and 'r' in mode: |
|
125 | 125 | return pat |
|
126 | 126 | return open(make_filename(repo, pat, node, total, seqno, revwidth, |
|
127 | 127 | pathname), |
|
128 | 128 | mode) |
|
129 | 129 | |
|
130 | 130 | def matchpats(repo, pats=[], opts={}, head='', globbed=False): |
|
131 | 131 | cwd = repo.getcwd() |
|
132 | 132 | if not pats and cwd: |
|
133 | 133 | opts['include'] = [os.path.join(cwd, i) |
|
134 | 134 | for i in opts.get('include', [])] |
|
135 | 135 | opts['exclude'] = [os.path.join(cwd, x) |
|
136 | 136 | for x in opts.get('exclude', [])] |
|
137 | 137 | cwd = '' |
|
138 | 138 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
139 | 139 | opts.get('exclude'), head, globbed=globbed) |
|
140 | 140 | |
|
141 | 141 | def walk(repo, pats=[], opts={}, node=None, head='', badmatch=None, |
|
142 | 142 | globbed=False): |
|
143 | 143 | files, matchfn, anypats = matchpats(repo, pats, opts, head, |
|
144 | 144 | globbed=globbed) |
|
145 | 145 | exact = dict.fromkeys(files) |
|
146 | 146 | for src, fn in repo.walk(node=node, files=files, match=matchfn, |
|
147 | 147 | badmatch=badmatch): |
|
148 | 148 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
149 | 149 | |
|
150 | 150 | def findrenames(repo, added=None, removed=None, threshold=0.5): |
|
151 | 151 | if added is None or removed is None: |
|
152 | 152 | added, removed = repo.status()[1:3] |
|
153 | 153 | changes = repo.changelog.read(repo.dirstate.parents()[0]) |
|
154 | 154 | mf = repo.manifest.read(changes[0]) |
|
155 | 155 | for a in added: |
|
156 | 156 | aa = repo.wread(a) |
|
157 | 157 | bestscore, bestname = None, None |
|
158 | 158 | for r in removed: |
|
159 | 159 | rr = repo.file(r).read(mf[r]) |
|
160 | 160 | delta = mdiff.textdiff(aa, rr) |
|
161 | 161 | if len(delta) < len(aa): |
|
162 | 162 | myscore = 1.0 - (float(len(delta)) / len(aa)) |
|
163 | 163 | if bestscore is None or myscore > bestscore: |
|
164 | 164 | bestscore, bestname = myscore, r |
|
165 | 165 | if bestname and bestscore >= threshold: |
|
166 | 166 | yield bestname, a, bestscore |
|
167 | 167 | |
|
168 | 168 | def addremove(repo, pats=[], opts={}, wlock=None, dry_run=None, |
|
169 | 169 | similarity=None): |
|
170 | 170 | if dry_run is None: |
|
171 | 171 | dry_run = opts.get('dry_run') |
|
172 | 172 | if similarity is None: |
|
173 | 173 | similarity = float(opts.get('similarity') or 0) |
|
174 | 174 | add, remove = [], [] |
|
175 | 175 | mapping = {} |
|
176 | 176 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
177 | 177 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
178 | 178 | add.append(abs) |
|
179 | 179 | mapping[abs] = rel, exact |
|
180 | 180 | if repo.ui.verbose or not exact: |
|
181 | 181 | repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
182 | 182 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
183 | 183 | remove.append(abs) |
|
184 | 184 | mapping[abs] = rel, exact |
|
185 | 185 | if repo.ui.verbose or not exact: |
|
186 | 186 | repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
187 | 187 | if not dry_run: |
|
188 | 188 | repo.add(add, wlock=wlock) |
|
189 | 189 | repo.remove(remove, wlock=wlock) |
|
190 | 190 | if similarity > 0: |
|
191 | 191 | for old, new, score in findrenames(repo, add, remove, similarity): |
|
192 | 192 | oldrel, oldexact = mapping[old] |
|
193 | 193 | newrel, newexact = mapping[new] |
|
194 | 194 | if repo.ui.verbose or not oldexact or not newexact: |
|
195 | 195 | repo.ui.status(_('recording removal of %s as rename to %s ' |
|
196 | 196 | '(%d%% similar)\n') % |
|
197 | 197 | (oldrel, newrel, score * 100)) |
|
198 | 198 | if not dry_run: |
|
199 | 199 | repo.copy(old, new, wlock=wlock) |
|
200 | 200 | |
|
201 | 201 | class changeset_printer(object): |
|
202 | 202 | '''show changeset information when templating not requested.''' |
|
203 | 203 | |
|
204 | 204 | def __init__(self, ui, repo, patch, brinfo, buffered): |
|
205 | 205 | self.ui = ui |
|
206 | 206 | self.repo = repo |
|
207 | 207 | self.buffered = buffered |
|
208 | 208 | self.patch = patch |
|
209 | 209 | self.brinfo = brinfo |
|
210 | 210 | self.header = {} |
|
211 | 211 | self.hunk = {} |
|
212 | 212 | self.lastheader = None |
|
213 | 213 | |
|
214 | 214 | def flush(self, rev): |
|
215 | 215 | if rev in self.header: |
|
216 | 216 | h = self.header[rev] |
|
217 | 217 | if h != self.lastheader: |
|
218 | 218 | self.lastheader = h |
|
219 | 219 | self.ui.write(h) |
|
220 | 220 | del self.header[rev] |
|
221 | 221 | if rev in self.hunk: |
|
222 | 222 | self.ui.write(self.hunk[rev]) |
|
223 | 223 | del self.hunk[rev] |
|
224 | 224 | return 1 |
|
225 | 225 | return 0 |
|
226 | 226 | |
|
227 | 227 | def show(self, rev=0, changenode=None, copies=None, **props): |
|
228 | 228 | if self.buffered: |
|
229 | 229 | self.ui.pushbuffer() |
|
230 | 230 | self._show(rev, changenode, copies, props) |
|
231 | 231 | self.hunk[rev] = self.ui.popbuffer() |
|
232 | 232 | else: |
|
233 | 233 | self._show(rev, changenode, copies, props) |
|
234 | 234 | |
|
235 | 235 | def _show(self, rev, changenode, copies, props): |
|
236 | 236 | '''show a single changeset or file revision''' |
|
237 | 237 | log = self.repo.changelog |
|
238 | 238 | if changenode is None: |
|
239 | 239 | changenode = log.node(rev) |
|
240 | 240 | elif not rev: |
|
241 | 241 | rev = log.rev(changenode) |
|
242 | 242 | |
|
243 | 243 | if self.ui.quiet: |
|
244 | 244 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
245 | 245 | return |
|
246 | 246 | |
|
247 | 247 | changes = log.read(changenode) |
|
248 | 248 | date = util.datestr(changes[2]) |
|
249 | 249 | extra = changes[5] |
|
250 | 250 | branch = extra.get("branch") |
|
251 | 251 | |
|
252 | 252 | hexfunc = self.ui.debugflag and hex or short |
|
253 | 253 | |
|
254 | 254 | parents = log.parentrevs(rev) |
|
255 | 255 | if not self.ui.debugflag: |
|
256 | 256 | if parents[1] == nullrev: |
|
257 | 257 | if parents[0] >= rev - 1: |
|
258 | 258 | parents = [] |
|
259 | 259 | else: |
|
260 | 260 | parents = [parents[0]] |
|
261 | 261 | parents = [(p, hexfunc(log.node(p))) for p in parents] |
|
262 | 262 | |
|
263 | 263 | self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode))) |
|
264 | 264 | |
|
265 | if branch: | |
|
265 | # don't show the default branch name | |
|
266 | if branch != 'default': | |
|
266 | 267 | branch = util.tolocal(branch) |
|
267 | 268 | self.ui.write(_("branch: %s\n") % branch) |
|
268 | 269 | for tag in self.repo.nodetags(changenode): |
|
269 | 270 | self.ui.write(_("tag: %s\n") % tag) |
|
270 | 271 | for parent in parents: |
|
271 | 272 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
272 | 273 | |
|
273 | 274 | if self.brinfo: |
|
274 | 275 | br = self.repo.branchlookup([changenode]) |
|
275 | 276 | if br: |
|
276 | 277 | self.ui.write(_("branch: %s\n") % " ".join(br[changenode])) |
|
277 | 278 | |
|
278 | 279 | if self.ui.debugflag: |
|
279 | 280 | self.ui.write(_("manifest: %d:%s\n") % |
|
280 | 281 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
281 | 282 | self.ui.write(_("user: %s\n") % changes[1]) |
|
282 | 283 | self.ui.write(_("date: %s\n") % date) |
|
283 | 284 | |
|
284 | 285 | if self.ui.debugflag: |
|
285 | 286 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
|
286 | 287 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
287 | 288 | files): |
|
288 | 289 | if value: |
|
289 | 290 | self.ui.write("%-12s %s\n" % (key, " ".join(value))) |
|
290 | 291 | elif changes[3] and self.ui.verbose: |
|
291 | 292 | self.ui.write(_("files: %s\n") % " ".join(changes[3])) |
|
292 | 293 | if copies and self.ui.verbose: |
|
293 | 294 | copies = ['%s (%s)' % c for c in copies] |
|
294 | 295 | self.ui.write(_("copies: %s\n") % ' '.join(copies)) |
|
295 | 296 | |
|
296 | 297 | if extra and self.ui.debugflag: |
|
297 | 298 | extraitems = extra.items() |
|
298 | 299 | extraitems.sort() |
|
299 | 300 | for key, value in extraitems: |
|
300 | 301 | self.ui.write(_("extra: %s=%s\n") |
|
301 | 302 | % (key, value.encode('string_escape'))) |
|
302 | 303 | |
|
303 | 304 | description = changes[4].strip() |
|
304 | 305 | if description: |
|
305 | 306 | if self.ui.verbose: |
|
306 | 307 | self.ui.write(_("description:\n")) |
|
307 | 308 | self.ui.write(description) |
|
308 | 309 | self.ui.write("\n\n") |
|
309 | 310 | else: |
|
310 | 311 | self.ui.write(_("summary: %s\n") % |
|
311 | 312 | description.splitlines()[0]) |
|
312 | 313 | self.ui.write("\n") |
|
313 | 314 | |
|
314 | 315 | self.showpatch(changenode) |
|
315 | 316 | |
|
316 | 317 | def showpatch(self, node): |
|
317 | 318 | if self.patch: |
|
318 | 319 | prev = self.repo.changelog.parents(node)[0] |
|
319 | 320 | patch.diff(self.repo, prev, node, match=self.patch, fp=self.ui) |
|
320 | 321 | self.ui.write("\n") |
|
321 | 322 | |
|
322 | 323 | class changeset_templater(changeset_printer): |
|
323 | 324 | '''format changeset information.''' |
|
324 | 325 | |
|
325 | 326 | def __init__(self, ui, repo, patch, brinfo, mapfile, buffered): |
|
326 | 327 | changeset_printer.__init__(self, ui, repo, patch, brinfo, buffered) |
|
327 | 328 | self.t = templater.templater(mapfile, templater.common_filters, |
|
328 | 329 | cache={'parent': '{rev}:{node|short} ', |
|
329 | 330 | 'manifest': '{rev}:{node|short}', |
|
330 | 331 | 'filecopy': '{name} ({source})'}) |
|
331 | 332 | |
|
332 | 333 | def use_template(self, t): |
|
333 | 334 | '''set template string to use''' |
|
334 | 335 | self.t.cache['changeset'] = t |
|
335 | 336 | |
|
336 | 337 | def _show(self, rev, changenode, copies, props): |
|
337 | 338 | '''show a single changeset or file revision''' |
|
338 | 339 | log = self.repo.changelog |
|
339 | 340 | if changenode is None: |
|
340 | 341 | changenode = log.node(rev) |
|
341 | 342 | elif not rev: |
|
342 | 343 | rev = log.rev(changenode) |
|
343 | 344 | |
|
344 | 345 | changes = log.read(changenode) |
|
345 | 346 | |
|
346 | 347 | def showlist(name, values, plural=None, **args): |
|
347 | 348 | '''expand set of values. |
|
348 | 349 | name is name of key in template map. |
|
349 | 350 | values is list of strings or dicts. |
|
350 | 351 | plural is plural of name, if not simply name + 's'. |
|
351 | 352 | |
|
352 | 353 | expansion works like this, given name 'foo'. |
|
353 | 354 | |
|
354 | 355 | if values is empty, expand 'no_foos'. |
|
355 | 356 | |
|
356 | 357 | if 'foo' not in template map, return values as a string, |
|
357 | 358 | joined by space. |
|
358 | 359 | |
|
359 | 360 | expand 'start_foos'. |
|
360 | 361 | |
|
361 | 362 | for each value, expand 'foo'. if 'last_foo' in template |
|
362 | 363 | map, expand it instead of 'foo' for last key. |
|
363 | 364 | |
|
364 | 365 | expand 'end_foos'. |
|
365 | 366 | ''' |
|
366 | 367 | if plural: names = plural |
|
367 | 368 | else: names = name + 's' |
|
368 | 369 | if not values: |
|
369 | 370 | noname = 'no_' + names |
|
370 | 371 | if noname in self.t: |
|
371 | 372 | yield self.t(noname, **args) |
|
372 | 373 | return |
|
373 | 374 | if name not in self.t: |
|
374 | 375 | if isinstance(values[0], str): |
|
375 | 376 | yield ' '.join(values) |
|
376 | 377 | else: |
|
377 | 378 | for v in values: |
|
378 | 379 | yield dict(v, **args) |
|
379 | 380 | return |
|
380 | 381 | startname = 'start_' + names |
|
381 | 382 | if startname in self.t: |
|
382 | 383 | yield self.t(startname, **args) |
|
383 | 384 | vargs = args.copy() |
|
384 | 385 | def one(v, tag=name): |
|
385 | 386 | try: |
|
386 | 387 | vargs.update(v) |
|
387 | 388 | except (AttributeError, ValueError): |
|
388 | 389 | try: |
|
389 | 390 | for a, b in v: |
|
390 | 391 | vargs[a] = b |
|
391 | 392 | except ValueError: |
|
392 | 393 | vargs[name] = v |
|
393 | 394 | return self.t(tag, **vargs) |
|
394 | 395 | lastname = 'last_' + name |
|
395 | 396 | if lastname in self.t: |
|
396 | 397 | last = values.pop() |
|
397 | 398 | else: |
|
398 | 399 | last = None |
|
399 | 400 | for v in values: |
|
400 | 401 | yield one(v) |
|
401 | 402 | if last is not None: |
|
402 | 403 | yield one(last, tag=lastname) |
|
403 | 404 | endname = 'end_' + names |
|
404 | 405 | if endname in self.t: |
|
405 | 406 | yield self.t(endname, **args) |
|
406 | 407 | |
|
407 | 408 | def showbranches(**args): |
|
408 | 409 | branch = changes[5].get("branch") |
|
409 | if branch: | |
|
410 | if branch != 'default': | |
|
410 | 411 | branch = util.tolocal(branch) |
|
411 | 412 | return showlist('branch', [branch], plural='branches', **args) |
|
412 | 413 | # add old style branches if requested |
|
413 | 414 | if self.brinfo: |
|
414 | 415 | br = self.repo.branchlookup([changenode]) |
|
415 | 416 | if changenode in br: |
|
416 | 417 | return showlist('branch', br[changenode], |
|
417 | 418 | plural='branches', **args) |
|
418 | 419 | |
|
419 | 420 | def showparents(**args): |
|
420 | 421 | parents = [[('rev', log.rev(p)), ('node', hex(p))] |
|
421 | 422 | for p in log.parents(changenode) |
|
422 | 423 | if self.ui.debugflag or p != nullid] |
|
423 | 424 | if (not self.ui.debugflag and len(parents) == 1 and |
|
424 | 425 | parents[0][0][1] == rev - 1): |
|
425 | 426 | return |
|
426 | 427 | return showlist('parent', parents, **args) |
|
427 | 428 | |
|
428 | 429 | def showtags(**args): |
|
429 | 430 | return showlist('tag', self.repo.nodetags(changenode), **args) |
|
430 | 431 | |
|
431 | 432 | def showextras(**args): |
|
432 | 433 | extras = changes[5].items() |
|
433 | 434 | extras.sort() |
|
434 | 435 | for key, value in extras: |
|
435 | 436 | args = args.copy() |
|
436 | 437 | args.update(dict(key=key, value=value)) |
|
437 | 438 | yield self.t('extra', **args) |
|
438 | 439 | |
|
439 | 440 | def showcopies(**args): |
|
440 | 441 | c = [{'name': x[0], 'source': x[1]} for x in copies] |
|
441 | 442 | return showlist('file_copy', c, plural='file_copies', **args) |
|
442 | 443 | |
|
443 | 444 | if self.ui.debugflag: |
|
444 | 445 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
|
445 | 446 | def showfiles(**args): |
|
446 | 447 | return showlist('file', files[0], **args) |
|
447 | 448 | def showadds(**args): |
|
448 | 449 | return showlist('file_add', files[1], **args) |
|
449 | 450 | def showdels(**args): |
|
450 | 451 | return showlist('file_del', files[2], **args) |
|
451 | 452 | def showmanifest(**args): |
|
452 | 453 | args = args.copy() |
|
453 | 454 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
|
454 | 455 | node=hex(changes[0]))) |
|
455 | 456 | return self.t('manifest', **args) |
|
456 | 457 | else: |
|
457 | 458 | def showfiles(**args): |
|
458 | 459 | return showlist('file', changes[3], **args) |
|
459 | 460 | showadds = '' |
|
460 | 461 | showdels = '' |
|
461 | 462 | showmanifest = '' |
|
462 | 463 | |
|
463 | 464 | defprops = { |
|
464 | 465 | 'author': changes[1], |
|
465 | 466 | 'branches': showbranches, |
|
466 | 467 | 'date': changes[2], |
|
467 | 468 | 'desc': changes[4], |
|
468 | 469 | 'file_adds': showadds, |
|
469 | 470 | 'file_dels': showdels, |
|
470 | 471 | 'files': showfiles, |
|
471 | 472 | 'file_copies': showcopies, |
|
472 | 473 | 'manifest': showmanifest, |
|
473 | 474 | 'node': hex(changenode), |
|
474 | 475 | 'parents': showparents, |
|
475 | 476 | 'rev': rev, |
|
476 | 477 | 'tags': showtags, |
|
477 | 478 | 'extras': showextras, |
|
478 | 479 | } |
|
479 | 480 | props = props.copy() |
|
480 | 481 | props.update(defprops) |
|
481 | 482 | |
|
482 | 483 | try: |
|
483 | 484 | if self.ui.debugflag and 'header_debug' in self.t: |
|
484 | 485 | key = 'header_debug' |
|
485 | 486 | elif self.ui.quiet and 'header_quiet' in self.t: |
|
486 | 487 | key = 'header_quiet' |
|
487 | 488 | elif self.ui.verbose and 'header_verbose' in self.t: |
|
488 | 489 | key = 'header_verbose' |
|
489 | 490 | elif 'header' in self.t: |
|
490 | 491 | key = 'header' |
|
491 | 492 | else: |
|
492 | 493 | key = '' |
|
493 | 494 | if key: |
|
494 | 495 | h = templater.stringify(self.t(key, **props)) |
|
495 | 496 | if self.buffered: |
|
496 | 497 | self.header[rev] = h |
|
497 | 498 | else: |
|
498 | 499 | self.ui.write(h) |
|
499 | 500 | if self.ui.debugflag and 'changeset_debug' in self.t: |
|
500 | 501 | key = 'changeset_debug' |
|
501 | 502 | elif self.ui.quiet and 'changeset_quiet' in self.t: |
|
502 | 503 | key = 'changeset_quiet' |
|
503 | 504 | elif self.ui.verbose and 'changeset_verbose' in self.t: |
|
504 | 505 | key = 'changeset_verbose' |
|
505 | 506 | else: |
|
506 | 507 | key = 'changeset' |
|
507 | 508 | self.ui.write(templater.stringify(self.t(key, **props))) |
|
508 | 509 | self.showpatch(changenode) |
|
509 | 510 | except KeyError, inst: |
|
510 | 511 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, |
|
511 | 512 | inst.args[0])) |
|
512 | 513 | except SyntaxError, inst: |
|
513 | 514 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) |
|
514 | 515 | |
|
515 | 516 | def show_changeset(ui, repo, opts, buffered=False, matchfn=False): |
|
516 | 517 | """show one changeset using template or regular display. |
|
517 | 518 | |
|
518 | 519 | Display format will be the first non-empty hit of: |
|
519 | 520 | 1. option 'template' |
|
520 | 521 | 2. option 'style' |
|
521 | 522 | 3. [ui] setting 'logtemplate' |
|
522 | 523 | 4. [ui] setting 'style' |
|
523 | 524 | If all of these values are either the unset or the empty string, |
|
524 | 525 | regular display via changeset_printer() is done. |
|
525 | 526 | """ |
|
526 | 527 | # options |
|
527 | 528 | patch = False |
|
528 | 529 | if opts.get('patch'): |
|
529 | 530 | patch = matchfn or util.always |
|
530 | 531 | |
|
531 | 532 | br = None |
|
532 | 533 | if opts.get('branches'): |
|
533 | 534 | ui.warn(_("the --branches option is deprecated, " |
|
534 | 535 | "please use 'hg branches' instead\n")) |
|
535 | 536 | br = True |
|
536 | 537 | tmpl = opts.get('template') |
|
537 | 538 | mapfile = None |
|
538 | 539 | if tmpl: |
|
539 | 540 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
540 | 541 | else: |
|
541 | 542 | mapfile = opts.get('style') |
|
542 | 543 | # ui settings |
|
543 | 544 | if not mapfile: |
|
544 | 545 | tmpl = ui.config('ui', 'logtemplate') |
|
545 | 546 | if tmpl: |
|
546 | 547 | tmpl = templater.parsestring(tmpl) |
|
547 | 548 | else: |
|
548 | 549 | mapfile = ui.config('ui', 'style') |
|
549 | 550 | |
|
550 | 551 | if tmpl or mapfile: |
|
551 | 552 | if mapfile: |
|
552 | 553 | if not os.path.split(mapfile)[0]: |
|
553 | 554 | mapname = (templater.templatepath('map-cmdline.' + mapfile) |
|
554 | 555 | or templater.templatepath(mapfile)) |
|
555 | 556 | if mapname: mapfile = mapname |
|
556 | 557 | try: |
|
557 | 558 | t = changeset_templater(ui, repo, patch, br, mapfile, buffered) |
|
558 | 559 | except SyntaxError, inst: |
|
559 | 560 | raise util.Abort(inst.args[0]) |
|
560 | 561 | if tmpl: t.use_template(tmpl) |
|
561 | 562 | return t |
|
562 | 563 | return changeset_printer(ui, repo, patch, br, buffered) |
|
563 | 564 | |
|
564 | 565 | def finddate(ui, repo, date): |
|
565 | 566 | """Find the tipmost changeset that matches the given date spec""" |
|
566 | 567 | df = util.matchdate(date + " to " + date) |
|
567 | 568 | get = util.cachefunc(lambda r: repo.changectx(r).changeset()) |
|
568 | 569 | changeiter, matchfn = walkchangerevs(ui, repo, [], get, {'rev':None}) |
|
569 | 570 | results = {} |
|
570 | 571 | for st, rev, fns in changeiter: |
|
571 | 572 | if st == 'add': |
|
572 | 573 | d = get(rev)[2] |
|
573 | 574 | if df(d[0]): |
|
574 | 575 | results[rev] = d |
|
575 | 576 | elif st == 'iter': |
|
576 | 577 | if rev in results: |
|
577 | 578 | ui.status("Found revision %s from %s\n" % |
|
578 | 579 | (rev, util.datestr(results[rev]))) |
|
579 | 580 | return str(rev) |
|
580 | 581 | |
|
581 | 582 | raise util.Abort(_("revision matching date not found")) |
|
582 | 583 | |
|
583 | 584 | def walkchangerevs(ui, repo, pats, change, opts): |
|
584 | 585 | '''Iterate over files and the revs they changed in. |
|
585 | 586 | |
|
586 | 587 | Callers most commonly need to iterate backwards over the history |
|
587 | 588 | it is interested in. Doing so has awful (quadratic-looking) |
|
588 | 589 | performance, so we use iterators in a "windowed" way. |
|
589 | 590 | |
|
590 | 591 | We walk a window of revisions in the desired order. Within the |
|
591 | 592 | window, we first walk forwards to gather data, then in the desired |
|
592 | 593 | order (usually backwards) to display it. |
|
593 | 594 | |
|
594 | 595 | This function returns an (iterator, matchfn) tuple. The iterator |
|
595 | 596 | yields 3-tuples. They will be of one of the following forms: |
|
596 | 597 | |
|
597 | 598 | "window", incrementing, lastrev: stepping through a window, |
|
598 | 599 | positive if walking forwards through revs, last rev in the |
|
599 | 600 | sequence iterated over - use to reset state for the current window |
|
600 | 601 | |
|
601 | 602 | "add", rev, fns: out-of-order traversal of the given file names |
|
602 | 603 | fns, which changed during revision rev - use to gather data for |
|
603 | 604 | possible display |
|
604 | 605 | |
|
605 | 606 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
606 | 607 | over with "add" - use to display data''' |
|
607 | 608 | |
|
608 | 609 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
609 | 610 | if start < end: |
|
610 | 611 | while start < end: |
|
611 | 612 | yield start, min(windowsize, end-start) |
|
612 | 613 | start += windowsize |
|
613 | 614 | if windowsize < sizelimit: |
|
614 | 615 | windowsize *= 2 |
|
615 | 616 | else: |
|
616 | 617 | while start > end: |
|
617 | 618 | yield start, min(windowsize, start-end-1) |
|
618 | 619 | start -= windowsize |
|
619 | 620 | if windowsize < sizelimit: |
|
620 | 621 | windowsize *= 2 |
|
621 | 622 | |
|
622 | 623 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
623 | 624 | follow = opts.get('follow') or opts.get('follow_first') |
|
624 | 625 | |
|
625 | 626 | if repo.changelog.count() == 0: |
|
626 | 627 | return [], matchfn |
|
627 | 628 | |
|
628 | 629 | if follow: |
|
629 | 630 | defrange = '%s:0' % repo.changectx().rev() |
|
630 | 631 | else: |
|
631 | 632 | defrange = 'tip:0' |
|
632 | 633 | revs = revrange(repo, opts['rev'] or [defrange]) |
|
633 | 634 | wanted = {} |
|
634 | 635 | slowpath = anypats or opts.get('removed') |
|
635 | 636 | fncache = {} |
|
636 | 637 | |
|
637 | 638 | if not slowpath and not files: |
|
638 | 639 | # No files, no patterns. Display all revs. |
|
639 | 640 | wanted = dict.fromkeys(revs) |
|
640 | 641 | copies = [] |
|
641 | 642 | if not slowpath: |
|
642 | 643 | # Only files, no patterns. Check the history of each file. |
|
643 | 644 | def filerevgen(filelog, node): |
|
644 | 645 | cl_count = repo.changelog.count() |
|
645 | 646 | if node is None: |
|
646 | 647 | last = filelog.count() - 1 |
|
647 | 648 | else: |
|
648 | 649 | last = filelog.rev(node) |
|
649 | 650 | for i, window in increasing_windows(last, nullrev): |
|
650 | 651 | revs = [] |
|
651 | 652 | for j in xrange(i - window, i + 1): |
|
652 | 653 | n = filelog.node(j) |
|
653 | 654 | revs.append((filelog.linkrev(n), |
|
654 | 655 | follow and filelog.renamed(n))) |
|
655 | 656 | revs.reverse() |
|
656 | 657 | for rev in revs: |
|
657 | 658 | # only yield rev for which we have the changelog, it can |
|
658 | 659 | # happen while doing "hg log" during a pull or commit |
|
659 | 660 | if rev[0] < cl_count: |
|
660 | 661 | yield rev |
|
661 | 662 | def iterfiles(): |
|
662 | 663 | for filename in files: |
|
663 | 664 | yield filename, None |
|
664 | 665 | for filename_node in copies: |
|
665 | 666 | yield filename_node |
|
666 | 667 | minrev, maxrev = min(revs), max(revs) |
|
667 | 668 | for file_, node in iterfiles(): |
|
668 | 669 | filelog = repo.file(file_) |
|
669 | 670 | # A zero count may be a directory or deleted file, so |
|
670 | 671 | # try to find matching entries on the slow path. |
|
671 | 672 | if filelog.count() == 0: |
|
672 | 673 | slowpath = True |
|
673 | 674 | break |
|
674 | 675 | for rev, copied in filerevgen(filelog, node): |
|
675 | 676 | if rev <= maxrev: |
|
676 | 677 | if rev < minrev: |
|
677 | 678 | break |
|
678 | 679 | fncache.setdefault(rev, []) |
|
679 | 680 | fncache[rev].append(file_) |
|
680 | 681 | wanted[rev] = 1 |
|
681 | 682 | if follow and copied: |
|
682 | 683 | copies.append(copied) |
|
683 | 684 | if slowpath: |
|
684 | 685 | if follow: |
|
685 | 686 | raise util.Abort(_('can only follow copies/renames for explicit ' |
|
686 | 687 | 'file names')) |
|
687 | 688 | |
|
688 | 689 | # The slow path checks files modified in every changeset. |
|
689 | 690 | def changerevgen(): |
|
690 | 691 | for i, window in increasing_windows(repo.changelog.count()-1, |
|
691 | 692 | nullrev): |
|
692 | 693 | for j in xrange(i - window, i + 1): |
|
693 | 694 | yield j, change(j)[3] |
|
694 | 695 | |
|
695 | 696 | for rev, changefiles in changerevgen(): |
|
696 | 697 | matches = filter(matchfn, changefiles) |
|
697 | 698 | if matches: |
|
698 | 699 | fncache[rev] = matches |
|
699 | 700 | wanted[rev] = 1 |
|
700 | 701 | |
|
701 | 702 | class followfilter: |
|
702 | 703 | def __init__(self, onlyfirst=False): |
|
703 | 704 | self.startrev = nullrev |
|
704 | 705 | self.roots = [] |
|
705 | 706 | self.onlyfirst = onlyfirst |
|
706 | 707 | |
|
707 | 708 | def match(self, rev): |
|
708 | 709 | def realparents(rev): |
|
709 | 710 | if self.onlyfirst: |
|
710 | 711 | return repo.changelog.parentrevs(rev)[0:1] |
|
711 | 712 | else: |
|
712 | 713 | return filter(lambda x: x != nullrev, |
|
713 | 714 | repo.changelog.parentrevs(rev)) |
|
714 | 715 | |
|
715 | 716 | if self.startrev == nullrev: |
|
716 | 717 | self.startrev = rev |
|
717 | 718 | return True |
|
718 | 719 | |
|
719 | 720 | if rev > self.startrev: |
|
720 | 721 | # forward: all descendants |
|
721 | 722 | if not self.roots: |
|
722 | 723 | self.roots.append(self.startrev) |
|
723 | 724 | for parent in realparents(rev): |
|
724 | 725 | if parent in self.roots: |
|
725 | 726 | self.roots.append(rev) |
|
726 | 727 | return True |
|
727 | 728 | else: |
|
728 | 729 | # backwards: all parents |
|
729 | 730 | if not self.roots: |
|
730 | 731 | self.roots.extend(realparents(self.startrev)) |
|
731 | 732 | if rev in self.roots: |
|
732 | 733 | self.roots.remove(rev) |
|
733 | 734 | self.roots.extend(realparents(rev)) |
|
734 | 735 | return True |
|
735 | 736 | |
|
736 | 737 | return False |
|
737 | 738 | |
|
738 | 739 | # it might be worthwhile to do this in the iterator if the rev range |
|
739 | 740 | # is descending and the prune args are all within that range |
|
740 | 741 | for rev in opts.get('prune', ()): |
|
741 | 742 | rev = repo.changelog.rev(repo.lookup(rev)) |
|
742 | 743 | ff = followfilter() |
|
743 | 744 | stop = min(revs[0], revs[-1]) |
|
744 | 745 | for x in xrange(rev, stop-1, -1): |
|
745 | 746 | if ff.match(x) and x in wanted: |
|
746 | 747 | del wanted[x] |
|
747 | 748 | |
|
748 | 749 | def iterate(): |
|
749 | 750 | if follow and not files: |
|
750 | 751 | ff = followfilter(onlyfirst=opts.get('follow_first')) |
|
751 | 752 | def want(rev): |
|
752 | 753 | if ff.match(rev) and rev in wanted: |
|
753 | 754 | return True |
|
754 | 755 | return False |
|
755 | 756 | else: |
|
756 | 757 | def want(rev): |
|
757 | 758 | return rev in wanted |
|
758 | 759 | |
|
759 | 760 | for i, window in increasing_windows(0, len(revs)): |
|
760 | 761 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
761 | 762 | nrevs = [rev for rev in revs[i:i+window] if want(rev)] |
|
762 | 763 | srevs = list(nrevs) |
|
763 | 764 | srevs.sort() |
|
764 | 765 | for rev in srevs: |
|
765 | 766 | fns = fncache.get(rev) |
|
766 | 767 | if not fns: |
|
767 | 768 | def fns_generator(): |
|
768 | 769 | for f in change(rev)[3]: |
|
769 | 770 | if matchfn(f): |
|
770 | 771 | yield f |
|
771 | 772 | fns = fns_generator() |
|
772 | 773 | yield 'add', rev, fns |
|
773 | 774 | for rev in nrevs: |
|
774 | 775 | yield 'iter', rev, None |
|
775 | 776 | return iterate(), matchfn |
@@ -1,3344 +1,3344 b'' | |||
|
1 | 1 | # commands.py - command processing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from demandload import demandload |
|
9 | 9 | from node import * |
|
10 | 10 | from i18n import gettext as _ |
|
11 | 11 | demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat") |
|
12 | 12 | demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo") |
|
13 | 13 | demandload(globals(), "difflib patch time help mdiff tempfile") |
|
14 | 14 | demandload(globals(), "traceback errno version atexit socket") |
|
15 | 15 | demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") |
|
16 | 16 | |
|
17 | 17 | class UnknownCommand(Exception): |
|
18 | 18 | """Exception raised if command is not in the command table.""" |
|
19 | 19 | class AmbiguousCommand(Exception): |
|
20 | 20 | """Exception raised if command shortcut matches more than one command.""" |
|
21 | 21 | |
|
22 | 22 | def bail_if_changed(repo): |
|
23 | 23 | modified, added, removed, deleted = repo.status()[:4] |
|
24 | 24 | if modified or added or removed or deleted: |
|
25 | 25 | raise util.Abort(_("outstanding uncommitted changes")) |
|
26 | 26 | |
|
27 | 27 | def logmessage(opts): |
|
28 | 28 | """ get the log message according to -m and -l option """ |
|
29 | 29 | message = opts['message'] |
|
30 | 30 | logfile = opts['logfile'] |
|
31 | 31 | |
|
32 | 32 | if message and logfile: |
|
33 | 33 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
34 | 34 | 'exclusive')) |
|
35 | 35 | if not message and logfile: |
|
36 | 36 | try: |
|
37 | 37 | if logfile == '-': |
|
38 | 38 | message = sys.stdin.read() |
|
39 | 39 | else: |
|
40 | 40 | message = open(logfile).read() |
|
41 | 41 | except IOError, inst: |
|
42 | 42 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
43 | 43 | (logfile, inst.strerror)) |
|
44 | 44 | return message |
|
45 | 45 | |
|
46 | 46 | def setremoteconfig(ui, opts): |
|
47 | 47 | "copy remote options to ui tree" |
|
48 | 48 | if opts.get('ssh'): |
|
49 | 49 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
50 | 50 | if opts.get('remotecmd'): |
|
51 | 51 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
52 | 52 | |
|
53 | 53 | # Commands start here, listed alphabetically |
|
54 | 54 | |
|
55 | 55 | def add(ui, repo, *pats, **opts): |
|
56 | 56 | """add the specified files on the next commit |
|
57 | 57 | |
|
58 | 58 | Schedule files to be version controlled and added to the repository. |
|
59 | 59 | |
|
60 | 60 | The files will be added to the repository at the next commit. To |
|
61 | 61 | undo an add before that, see hg revert. |
|
62 | 62 | |
|
63 | 63 | If no names are given, add all files in the repository. |
|
64 | 64 | """ |
|
65 | 65 | |
|
66 | 66 | names = [] |
|
67 | 67 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): |
|
68 | 68 | if exact: |
|
69 | 69 | if ui.verbose: |
|
70 | 70 | ui.status(_('adding %s\n') % rel) |
|
71 | 71 | names.append(abs) |
|
72 | 72 | elif repo.dirstate.state(abs) == '?': |
|
73 | 73 | ui.status(_('adding %s\n') % rel) |
|
74 | 74 | names.append(abs) |
|
75 | 75 | if not opts.get('dry_run'): |
|
76 | 76 | repo.add(names) |
|
77 | 77 | |
|
78 | 78 | def addremove(ui, repo, *pats, **opts): |
|
79 | 79 | """add all new files, delete all missing files |
|
80 | 80 | |
|
81 | 81 | Add all new files and remove all missing files from the repository. |
|
82 | 82 | |
|
83 | 83 | New files are ignored if they match any of the patterns in .hgignore. As |
|
84 | 84 | with add, these changes take effect at the next commit. |
|
85 | 85 | |
|
86 | 86 | Use the -s option to detect renamed files. With a parameter > 0, |
|
87 | 87 | this compares every removed file with every added file and records |
|
88 | 88 | those similar enough as renames. This option takes a percentage |
|
89 | 89 | between 0 (disabled) and 100 (files must be identical) as its |
|
90 | 90 | parameter. Detecting renamed files this way can be expensive. |
|
91 | 91 | """ |
|
92 | 92 | sim = float(opts.get('similarity') or 0) |
|
93 | 93 | if sim < 0 or sim > 100: |
|
94 | 94 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
95 | 95 | return cmdutil.addremove(repo, pats, opts, similarity=sim/100.) |
|
96 | 96 | |
|
97 | 97 | def annotate(ui, repo, *pats, **opts): |
|
98 | 98 | """show changeset information per file line |
|
99 | 99 | |
|
100 | 100 | List changes in files, showing the revision id responsible for each line |
|
101 | 101 | |
|
102 | 102 | This command is useful to discover who did a change or when a change took |
|
103 | 103 | place. |
|
104 | 104 | |
|
105 | 105 | Without the -a option, annotate will avoid processing files it |
|
106 | 106 | detects as binary. With -a, annotate will generate an annotation |
|
107 | 107 | anyway, probably with undesirable results. |
|
108 | 108 | """ |
|
109 | 109 | getdate = util.cachefunc(lambda x: util.datestr(x.date())) |
|
110 | 110 | |
|
111 | 111 | if not pats: |
|
112 | 112 | raise util.Abort(_('at least one file name or pattern required')) |
|
113 | 113 | |
|
114 | 114 | opmap = [['user', lambda x: ui.shortuser(x.user())], |
|
115 | 115 | ['number', lambda x: str(x.rev())], |
|
116 | 116 | ['changeset', lambda x: short(x.node())], |
|
117 | 117 | ['date', getdate], ['follow', lambda x: x.path()]] |
|
118 | 118 | if (not opts['user'] and not opts['changeset'] and not opts['date'] |
|
119 | 119 | and not opts['follow']): |
|
120 | 120 | opts['number'] = 1 |
|
121 | 121 | |
|
122 | 122 | ctx = repo.changectx(opts['rev']) |
|
123 | 123 | |
|
124 | 124 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, |
|
125 | 125 | node=ctx.node()): |
|
126 | 126 | fctx = ctx.filectx(abs) |
|
127 | 127 | if not opts['text'] and util.binary(fctx.data()): |
|
128 | 128 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
129 | 129 | continue |
|
130 | 130 | |
|
131 | 131 | lines = fctx.annotate(follow=opts.get('follow')) |
|
132 | 132 | pieces = [] |
|
133 | 133 | |
|
134 | 134 | for o, f in opmap: |
|
135 | 135 | if opts[o]: |
|
136 | 136 | l = [f(n) for n, dummy in lines] |
|
137 | 137 | if l: |
|
138 | 138 | m = max(map(len, l)) |
|
139 | 139 | pieces.append(["%*s" % (m, x) for x in l]) |
|
140 | 140 | |
|
141 | 141 | if pieces: |
|
142 | 142 | for p, l in zip(zip(*pieces), lines): |
|
143 | 143 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
144 | 144 | |
|
145 | 145 | def archive(ui, repo, dest, **opts): |
|
146 | 146 | '''create unversioned archive of a repository revision |
|
147 | 147 | |
|
148 | 148 | By default, the revision used is the parent of the working |
|
149 | 149 | directory; use "-r" to specify a different revision. |
|
150 | 150 | |
|
151 | 151 | To specify the type of archive to create, use "-t". Valid |
|
152 | 152 | types are: |
|
153 | 153 | |
|
154 | 154 | "files" (default): a directory full of files |
|
155 | 155 | "tar": tar archive, uncompressed |
|
156 | 156 | "tbz2": tar archive, compressed using bzip2 |
|
157 | 157 | "tgz": tar archive, compressed using gzip |
|
158 | 158 | "uzip": zip archive, uncompressed |
|
159 | 159 | "zip": zip archive, compressed using deflate |
|
160 | 160 | |
|
161 | 161 | The exact name of the destination archive or directory is given |
|
162 | 162 | using a format string; see "hg help export" for details. |
|
163 | 163 | |
|
164 | 164 | Each member added to an archive file has a directory prefix |
|
165 | 165 | prepended. Use "-p" to specify a format string for the prefix. |
|
166 | 166 | The default is the basename of the archive, with suffixes removed. |
|
167 | 167 | ''' |
|
168 | 168 | |
|
169 | 169 | node = repo.changectx(opts['rev']).node() |
|
170 | 170 | dest = cmdutil.make_filename(repo, dest, node) |
|
171 | 171 | if os.path.realpath(dest) == repo.root: |
|
172 | 172 | raise util.Abort(_('repository root cannot be destination')) |
|
173 | 173 | dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) |
|
174 | 174 | kind = opts.get('type') or 'files' |
|
175 | 175 | prefix = opts['prefix'] |
|
176 | 176 | if dest == '-': |
|
177 | 177 | if kind == 'files': |
|
178 | 178 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
179 | 179 | dest = sys.stdout |
|
180 | 180 | if not prefix: prefix = os.path.basename(repo.root) + '-%h' |
|
181 | 181 | prefix = cmdutil.make_filename(repo, prefix, node) |
|
182 | 182 | archival.archive(repo, dest, node, kind, not opts['no_decode'], |
|
183 | 183 | matchfn, prefix) |
|
184 | 184 | |
|
185 | 185 | def backout(ui, repo, rev, **opts): |
|
186 | 186 | '''reverse effect of earlier changeset |
|
187 | 187 | |
|
188 | 188 | Commit the backed out changes as a new changeset. The new |
|
189 | 189 | changeset is a child of the backed out changeset. |
|
190 | 190 | |
|
191 | 191 | If you back out a changeset other than the tip, a new head is |
|
192 | 192 | created. This head is the parent of the working directory. If |
|
193 | 193 | you back out an old changeset, your working directory will appear |
|
194 | 194 | old after the backout. You should merge the backout changeset |
|
195 | 195 | with another head. |
|
196 | 196 | |
|
197 | 197 | The --merge option remembers the parent of the working directory |
|
198 | 198 | before starting the backout, then merges the new head with that |
|
199 | 199 | changeset afterwards. This saves you from doing the merge by |
|
200 | 200 | hand. The result of this merge is not committed, as for a normal |
|
201 | 201 | merge.''' |
|
202 | 202 | |
|
203 | 203 | bail_if_changed(repo) |
|
204 | 204 | op1, op2 = repo.dirstate.parents() |
|
205 | 205 | if op2 != nullid: |
|
206 | 206 | raise util.Abort(_('outstanding uncommitted merge')) |
|
207 | 207 | node = repo.lookup(rev) |
|
208 | 208 | p1, p2 = repo.changelog.parents(node) |
|
209 | 209 | if p1 == nullid: |
|
210 | 210 | raise util.Abort(_('cannot back out a change with no parents')) |
|
211 | 211 | if p2 != nullid: |
|
212 | 212 | if not opts['parent']: |
|
213 | 213 | raise util.Abort(_('cannot back out a merge changeset without ' |
|
214 | 214 | '--parent')) |
|
215 | 215 | p = repo.lookup(opts['parent']) |
|
216 | 216 | if p not in (p1, p2): |
|
217 | 217 | raise util.Abort(_('%s is not a parent of %s') % |
|
218 | 218 | (short(p), short(node))) |
|
219 | 219 | parent = p |
|
220 | 220 | else: |
|
221 | 221 | if opts['parent']: |
|
222 | 222 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
223 | 223 | parent = p1 |
|
224 | 224 | hg.clean(repo, node, show_stats=False) |
|
225 | 225 | revert_opts = opts.copy() |
|
226 | 226 | revert_opts['date'] = None |
|
227 | 227 | revert_opts['all'] = True |
|
228 | 228 | revert_opts['rev'] = hex(parent) |
|
229 | 229 | revert(ui, repo, **revert_opts) |
|
230 | 230 | commit_opts = opts.copy() |
|
231 | 231 | commit_opts['addremove'] = False |
|
232 | 232 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
233 | 233 | commit_opts['message'] = _("Backed out changeset %s") % (hex(node)) |
|
234 | 234 | commit_opts['force_editor'] = True |
|
235 | 235 | commit(ui, repo, **commit_opts) |
|
236 | 236 | def nice(node): |
|
237 | 237 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
238 | 238 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
239 | 239 | (nice(repo.changelog.tip()), nice(node))) |
|
240 | 240 | if op1 != node: |
|
241 | 241 | if opts['merge']: |
|
242 | 242 | ui.status(_('merging with changeset %s\n') % nice(op1)) |
|
243 | 243 | n = _lookup(repo, hex(op1)) |
|
244 | 244 | hg.merge(repo, n) |
|
245 | 245 | else: |
|
246 | 246 | ui.status(_('the backout changeset is a new head - ' |
|
247 | 247 | 'do not forget to merge\n')) |
|
248 | 248 | ui.status(_('(use "backout --merge" ' |
|
249 | 249 | 'if you want to auto-merge)\n')) |
|
250 | 250 | |
|
251 | 251 | def branch(ui, repo, label=None): |
|
252 | 252 | """set or show the current branch name |
|
253 | 253 | |
|
254 | 254 | With <name>, set the current branch name. Otherwise, show the |
|
255 | 255 | current branch name. |
|
256 | 256 | """ |
|
257 | 257 | |
|
258 | 258 | if label is not None: |
|
259 | 259 | repo.opener("branch", "w").write(util.fromlocal(label) + '\n') |
|
260 | 260 | else: |
|
261 | 261 | b = util.tolocal(repo.workingctx().branch()) |
|
262 | 262 | if b: |
|
263 | 263 | ui.write("%s\n" % b) |
|
264 | 264 | |
|
265 | 265 | def branches(ui, repo): |
|
266 | 266 | """list repository named branches |
|
267 | 267 | |
|
268 | 268 | List the repository's named branches. |
|
269 | 269 | """ |
|
270 | 270 | b = repo.branchtags() |
|
271 | 271 | l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()] |
|
272 | 272 | l.sort() |
|
273 | 273 | for r, n, t in l: |
|
274 | 274 | hexfunc = ui.debugflag and hex or short |
|
275 | 275 | if ui.quiet: |
|
276 | 276 | ui.write("%s\n" % t) |
|
277 | 277 | else: |
|
278 | 278 | spaces = " " * (30 - util.locallen(t)) |
|
279 | 279 | ui.write("%s%s %s:%s\n" % (t, spaces, -r, hexfunc(n))) |
|
280 | 280 | |
|
281 | 281 | def bundle(ui, repo, fname, dest=None, **opts): |
|
282 | 282 | """create a changegroup file |
|
283 | 283 | |
|
284 | 284 | Generate a compressed changegroup file collecting changesets not |
|
285 | 285 | found in the other repository. |
|
286 | 286 | |
|
287 | 287 | If no destination repository is specified the destination is assumed |
|
288 | 288 | to have all the nodes specified by one or more --base parameters. |
|
289 | 289 | |
|
290 | 290 | The bundle file can then be transferred using conventional means and |
|
291 | 291 | applied to another repository with the unbundle or pull command. |
|
292 | 292 | This is useful when direct push and pull are not available or when |
|
293 | 293 | exporting an entire repository is undesirable. |
|
294 | 294 | |
|
295 | 295 | Applying bundles preserves all changeset contents including |
|
296 | 296 | permissions, copy/rename information, and revision history. |
|
297 | 297 | """ |
|
298 | 298 | revs = opts.get('rev') or None |
|
299 | 299 | if revs: |
|
300 | 300 | revs = [repo.lookup(rev) for rev in revs] |
|
301 | 301 | base = opts.get('base') |
|
302 | 302 | if base: |
|
303 | 303 | if dest: |
|
304 | 304 | raise util.Abort(_("--base is incompatible with specifiying " |
|
305 | 305 | "a destination")) |
|
306 | 306 | base = [repo.lookup(rev) for rev in base] |
|
307 | 307 | # create the right base |
|
308 | 308 | # XXX: nodesbetween / changegroup* should be "fixed" instead |
|
309 | 309 | o = [] |
|
310 | 310 | has = {nullid: None} |
|
311 | 311 | for n in base: |
|
312 | 312 | has.update(repo.changelog.reachable(n)) |
|
313 | 313 | if revs: |
|
314 | 314 | visit = list(revs) |
|
315 | 315 | else: |
|
316 | 316 | visit = repo.changelog.heads() |
|
317 | 317 | seen = {} |
|
318 | 318 | while visit: |
|
319 | 319 | n = visit.pop(0) |
|
320 | 320 | parents = [p for p in repo.changelog.parents(n) if p not in has] |
|
321 | 321 | if len(parents) == 0: |
|
322 | 322 | o.insert(0, n) |
|
323 | 323 | else: |
|
324 | 324 | for p in parents: |
|
325 | 325 | if p not in seen: |
|
326 | 326 | seen[p] = 1 |
|
327 | 327 | visit.append(p) |
|
328 | 328 | else: |
|
329 | 329 | setremoteconfig(ui, opts) |
|
330 | 330 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
331 | 331 | other = hg.repository(ui, dest) |
|
332 | 332 | o = repo.findoutgoing(other, force=opts['force']) |
|
333 | 333 | |
|
334 | 334 | if revs: |
|
335 | 335 | cg = repo.changegroupsubset(o, revs, 'bundle') |
|
336 | 336 | else: |
|
337 | 337 | cg = repo.changegroup(o, 'bundle') |
|
338 | 338 | changegroup.writebundle(cg, fname, "HG10BZ") |
|
339 | 339 | |
|
340 | 340 | def cat(ui, repo, file1, *pats, **opts): |
|
341 | 341 | """output the current or given revision of files |
|
342 | 342 | |
|
343 | 343 | Print the specified files as they were at the given revision. |
|
344 | 344 | If no revision is given, the parent of the working directory is used, |
|
345 | 345 | or tip if no revision is checked out. |
|
346 | 346 | |
|
347 | 347 | Output may be to a file, in which case the name of the file is |
|
348 | 348 | given using a format string. The formatting rules are the same as |
|
349 | 349 | for the export command, with the following additions: |
|
350 | 350 | |
|
351 | 351 | %s basename of file being printed |
|
352 | 352 | %d dirname of file being printed, or '.' if in repo root |
|
353 | 353 | %p root-relative path name of file being printed |
|
354 | 354 | """ |
|
355 | 355 | ctx = repo.changectx(opts['rev']) |
|
356 | 356 | for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, |
|
357 | 357 | ctx.node()): |
|
358 | 358 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) |
|
359 | 359 | fp.write(ctx.filectx(abs).data()) |
|
360 | 360 | |
|
361 | 361 | def clone(ui, source, dest=None, **opts): |
|
362 | 362 | """make a copy of an existing repository |
|
363 | 363 | |
|
364 | 364 | Create a copy of an existing repository in a new directory. |
|
365 | 365 | |
|
366 | 366 | If no destination directory name is specified, it defaults to the |
|
367 | 367 | basename of the source. |
|
368 | 368 | |
|
369 | 369 | The location of the source is added to the new repository's |
|
370 | 370 | .hg/hgrc file, as the default to be used for future pulls. |
|
371 | 371 | |
|
372 | 372 | For efficiency, hardlinks are used for cloning whenever the source |
|
373 | 373 | and destination are on the same filesystem (note this applies only |
|
374 | 374 | to the repository data, not to the checked out files). Some |
|
375 | 375 | filesystems, such as AFS, implement hardlinking incorrectly, but |
|
376 | 376 | do not report errors. In these cases, use the --pull option to |
|
377 | 377 | avoid hardlinking. |
|
378 | 378 | |
|
379 | 379 | You can safely clone repositories and checked out files using full |
|
380 | 380 | hardlinks with |
|
381 | 381 | |
|
382 | 382 | $ cp -al REPO REPOCLONE |
|
383 | 383 | |
|
384 | 384 | which is the fastest way to clone. However, the operation is not |
|
385 | 385 | atomic (making sure REPO is not modified during the operation is |
|
386 | 386 | up to you) and you have to make sure your editor breaks hardlinks |
|
387 | 387 | (Emacs and most Linux Kernel tools do so). |
|
388 | 388 | |
|
389 | 389 | If you use the -r option to clone up to a specific revision, no |
|
390 | 390 | subsequent revisions will be present in the cloned repository. |
|
391 | 391 | This option implies --pull, even on local repositories. |
|
392 | 392 | |
|
393 | 393 | See pull for valid source format details. |
|
394 | 394 | |
|
395 | 395 | It is possible to specify an ssh:// URL as the destination, but no |
|
396 | 396 | .hg/hgrc and working directory will be created on the remote side. |
|
397 | 397 | Look at the help text for the pull command for important details |
|
398 | 398 | about ssh:// URLs. |
|
399 | 399 | """ |
|
400 | 400 | setremoteconfig(ui, opts) |
|
401 | 401 | hg.clone(ui, ui.expandpath(source), dest, |
|
402 | 402 | pull=opts['pull'], |
|
403 | 403 | stream=opts['uncompressed'], |
|
404 | 404 | rev=opts['rev'], |
|
405 | 405 | update=not opts['noupdate']) |
|
406 | 406 | |
|
407 | 407 | def commit(ui, repo, *pats, **opts): |
|
408 | 408 | """commit the specified files or all outstanding changes |
|
409 | 409 | |
|
410 | 410 | Commit changes to the given files into the repository. |
|
411 | 411 | |
|
412 | 412 | If a list of files is omitted, all changes reported by "hg status" |
|
413 | 413 | will be committed. |
|
414 | 414 | |
|
415 | 415 | If no commit message is specified, the editor configured in your hgrc |
|
416 | 416 | or in the EDITOR environment variable is started to enter a message. |
|
417 | 417 | """ |
|
418 | 418 | message = logmessage(opts) |
|
419 | 419 | |
|
420 | 420 | if opts['addremove']: |
|
421 | 421 | cmdutil.addremove(repo, pats, opts) |
|
422 | 422 | fns, match, anypats = cmdutil.matchpats(repo, pats, opts) |
|
423 | 423 | if pats: |
|
424 | 424 | status = repo.status(files=fns, match=match) |
|
425 | 425 | modified, added, removed, deleted, unknown = status[:5] |
|
426 | 426 | files = modified + added + removed |
|
427 | 427 | slist = None |
|
428 | 428 | for f in fns: |
|
429 | 429 | if f not in files: |
|
430 | 430 | rf = repo.wjoin(f) |
|
431 | 431 | if f in unknown: |
|
432 | 432 | raise util.Abort(_("file %s not tracked!") % rf) |
|
433 | 433 | try: |
|
434 | 434 | mode = os.lstat(rf)[stat.ST_MODE] |
|
435 | 435 | except OSError: |
|
436 | 436 | raise util.Abort(_("file %s not found!") % rf) |
|
437 | 437 | if stat.S_ISDIR(mode): |
|
438 | 438 | name = f + '/' |
|
439 | 439 | if slist is None: |
|
440 | 440 | slist = list(files) |
|
441 | 441 | slist.sort() |
|
442 | 442 | i = bisect.bisect(slist, name) |
|
443 | 443 | if i >= len(slist) or not slist[i].startswith(name): |
|
444 | 444 | raise util.Abort(_("no match under directory %s!") |
|
445 | 445 | % rf) |
|
446 | 446 | elif not stat.S_ISREG(mode): |
|
447 | 447 | raise util.Abort(_("can't commit %s: " |
|
448 | 448 | "unsupported file type!") % rf) |
|
449 | 449 | else: |
|
450 | 450 | files = [] |
|
451 | 451 | try: |
|
452 | 452 | repo.commit(files, message, opts['user'], opts['date'], match, |
|
453 | 453 | force_editor=opts.get('force_editor')) |
|
454 | 454 | except ValueError, inst: |
|
455 | 455 | raise util.Abort(str(inst)) |
|
456 | 456 | |
|
457 | 457 | def docopy(ui, repo, pats, opts, wlock): |
|
458 | 458 | # called with the repo lock held |
|
459 | 459 | # |
|
460 | 460 | # hgsep => pathname that uses "/" to separate directories |
|
461 | 461 | # ossep => pathname that uses os.sep to separate directories |
|
462 | 462 | cwd = repo.getcwd() |
|
463 | 463 | errors = 0 |
|
464 | 464 | copied = [] |
|
465 | 465 | targets = {} |
|
466 | 466 | |
|
467 | 467 | # abs: hgsep |
|
468 | 468 | # rel: ossep |
|
469 | 469 | # return: hgsep |
|
470 | 470 | def okaytocopy(abs, rel, exact): |
|
471 | 471 | reasons = {'?': _('is not managed'), |
|
472 | 472 | 'a': _('has been marked for add'), |
|
473 | 473 | 'r': _('has been marked for remove')} |
|
474 | 474 | state = repo.dirstate.state(abs) |
|
475 | 475 | reason = reasons.get(state) |
|
476 | 476 | if reason: |
|
477 | 477 | if state == 'a': |
|
478 | 478 | origsrc = repo.dirstate.copied(abs) |
|
479 | 479 | if origsrc is not None: |
|
480 | 480 | return origsrc |
|
481 | 481 | if exact: |
|
482 | 482 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
483 | 483 | else: |
|
484 | 484 | return abs |
|
485 | 485 | |
|
486 | 486 | # origsrc: hgsep |
|
487 | 487 | # abssrc: hgsep |
|
488 | 488 | # relsrc: ossep |
|
489 | 489 | # target: ossep |
|
490 | 490 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
491 | 491 | abstarget = util.canonpath(repo.root, cwd, target) |
|
492 | 492 | reltarget = util.pathto(cwd, abstarget) |
|
493 | 493 | prevsrc = targets.get(abstarget) |
|
494 | 494 | if prevsrc is not None: |
|
495 | 495 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
496 | 496 | (reltarget, util.localpath(abssrc), |
|
497 | 497 | util.localpath(prevsrc))) |
|
498 | 498 | return |
|
499 | 499 | if (not opts['after'] and os.path.exists(reltarget) or |
|
500 | 500 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
501 | 501 | if not opts['force']: |
|
502 | 502 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
503 | 503 | reltarget) |
|
504 | 504 | return |
|
505 | 505 | if not opts['after'] and not opts.get('dry_run'): |
|
506 | 506 | os.unlink(reltarget) |
|
507 | 507 | if opts['after']: |
|
508 | 508 | if not os.path.exists(reltarget): |
|
509 | 509 | return |
|
510 | 510 | else: |
|
511 | 511 | targetdir = os.path.dirname(reltarget) or '.' |
|
512 | 512 | if not os.path.isdir(targetdir) and not opts.get('dry_run'): |
|
513 | 513 | os.makedirs(targetdir) |
|
514 | 514 | try: |
|
515 | 515 | restore = repo.dirstate.state(abstarget) == 'r' |
|
516 | 516 | if restore and not opts.get('dry_run'): |
|
517 | 517 | repo.undelete([abstarget], wlock) |
|
518 | 518 | try: |
|
519 | 519 | if not opts.get('dry_run'): |
|
520 | 520 | util.copyfile(relsrc, reltarget) |
|
521 | 521 | restore = False |
|
522 | 522 | finally: |
|
523 | 523 | if restore: |
|
524 | 524 | repo.remove([abstarget], wlock) |
|
525 | 525 | except IOError, inst: |
|
526 | 526 | if inst.errno == errno.ENOENT: |
|
527 | 527 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
528 | 528 | else: |
|
529 | 529 | ui.warn(_('%s: cannot copy - %s\n') % |
|
530 | 530 | (relsrc, inst.strerror)) |
|
531 | 531 | errors += 1 |
|
532 | 532 | return |
|
533 | 533 | if ui.verbose or not exact: |
|
534 | 534 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
535 | 535 | targets[abstarget] = abssrc |
|
536 | 536 | if abstarget != origsrc and not opts.get('dry_run'): |
|
537 | 537 | repo.copy(origsrc, abstarget, wlock) |
|
538 | 538 | copied.append((abssrc, relsrc, exact)) |
|
539 | 539 | |
|
540 | 540 | # pat: ossep |
|
541 | 541 | # dest ossep |
|
542 | 542 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
543 | 543 | # return: function that takes hgsep and returns ossep |
|
544 | 544 | def targetpathfn(pat, dest, srcs): |
|
545 | 545 | if os.path.isdir(pat): |
|
546 | 546 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
547 | 547 | abspfx = util.localpath(abspfx) |
|
548 | 548 | if destdirexists: |
|
549 | 549 | striplen = len(os.path.split(abspfx)[0]) |
|
550 | 550 | else: |
|
551 | 551 | striplen = len(abspfx) |
|
552 | 552 | if striplen: |
|
553 | 553 | striplen += len(os.sep) |
|
554 | 554 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
|
555 | 555 | elif destdirexists: |
|
556 | 556 | res = lambda p: os.path.join(dest, |
|
557 | 557 | os.path.basename(util.localpath(p))) |
|
558 | 558 | else: |
|
559 | 559 | res = lambda p: dest |
|
560 | 560 | return res |
|
561 | 561 | |
|
562 | 562 | # pat: ossep |
|
563 | 563 | # dest ossep |
|
564 | 564 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
565 | 565 | # return: function that takes hgsep and returns ossep |
|
566 | 566 | def targetpathafterfn(pat, dest, srcs): |
|
567 | 567 | if util.patkind(pat, None)[0]: |
|
568 | 568 | # a mercurial pattern |
|
569 | 569 | res = lambda p: os.path.join(dest, |
|
570 | 570 | os.path.basename(util.localpath(p))) |
|
571 | 571 | else: |
|
572 | 572 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
573 | 573 | if len(abspfx) < len(srcs[0][0]): |
|
574 | 574 | # A directory. Either the target path contains the last |
|
575 | 575 | # component of the source path or it does not. |
|
576 | 576 | def evalpath(striplen): |
|
577 | 577 | score = 0 |
|
578 | 578 | for s in srcs: |
|
579 | 579 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
|
580 | 580 | if os.path.exists(t): |
|
581 | 581 | score += 1 |
|
582 | 582 | return score |
|
583 | 583 | |
|
584 | 584 | abspfx = util.localpath(abspfx) |
|
585 | 585 | striplen = len(abspfx) |
|
586 | 586 | if striplen: |
|
587 | 587 | striplen += len(os.sep) |
|
588 | 588 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
589 | 589 | score = evalpath(striplen) |
|
590 | 590 | striplen1 = len(os.path.split(abspfx)[0]) |
|
591 | 591 | if striplen1: |
|
592 | 592 | striplen1 += len(os.sep) |
|
593 | 593 | if evalpath(striplen1) > score: |
|
594 | 594 | striplen = striplen1 |
|
595 | 595 | res = lambda p: os.path.join(dest, |
|
596 | 596 | util.localpath(p)[striplen:]) |
|
597 | 597 | else: |
|
598 | 598 | # a file |
|
599 | 599 | if destdirexists: |
|
600 | 600 | res = lambda p: os.path.join(dest, |
|
601 | 601 | os.path.basename(util.localpath(p))) |
|
602 | 602 | else: |
|
603 | 603 | res = lambda p: dest |
|
604 | 604 | return res |
|
605 | 605 | |
|
606 | 606 | |
|
607 | 607 | pats = util.expand_glob(pats) |
|
608 | 608 | if not pats: |
|
609 | 609 | raise util.Abort(_('no source or destination specified')) |
|
610 | 610 | if len(pats) == 1: |
|
611 | 611 | raise util.Abort(_('no destination specified')) |
|
612 | 612 | dest = pats.pop() |
|
613 | 613 | destdirexists = os.path.isdir(dest) |
|
614 | 614 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
615 | 615 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
616 | 616 | 'existing directory')) |
|
617 | 617 | if opts['after']: |
|
618 | 618 | tfn = targetpathafterfn |
|
619 | 619 | else: |
|
620 | 620 | tfn = targetpathfn |
|
621 | 621 | copylist = [] |
|
622 | 622 | for pat in pats: |
|
623 | 623 | srcs = [] |
|
624 | 624 | for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts, |
|
625 | 625 | globbed=True): |
|
626 | 626 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
627 | 627 | if origsrc: |
|
628 | 628 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
629 | 629 | if not srcs: |
|
630 | 630 | continue |
|
631 | 631 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
632 | 632 | if not copylist: |
|
633 | 633 | raise util.Abort(_('no files to copy')) |
|
634 | 634 | |
|
635 | 635 | for targetpath, srcs in copylist: |
|
636 | 636 | for origsrc, abssrc, relsrc, exact in srcs: |
|
637 | 637 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
638 | 638 | |
|
639 | 639 | if errors: |
|
640 | 640 | ui.warn(_('(consider using --after)\n')) |
|
641 | 641 | return errors, copied |
|
642 | 642 | |
|
643 | 643 | def copy(ui, repo, *pats, **opts): |
|
644 | 644 | """mark files as copied for the next commit |
|
645 | 645 | |
|
646 | 646 | Mark dest as having copies of source files. If dest is a |
|
647 | 647 | directory, copies are put in that directory. If dest is a file, |
|
648 | 648 | there can only be one source. |
|
649 | 649 | |
|
650 | 650 | By default, this command copies the contents of files as they |
|
651 | 651 | stand in the working directory. If invoked with --after, the |
|
652 | 652 | operation is recorded, but no copying is performed. |
|
653 | 653 | |
|
654 | 654 | This command takes effect in the next commit. To undo a copy |
|
655 | 655 | before that, see hg revert. |
|
656 | 656 | """ |
|
657 | 657 | wlock = repo.wlock(0) |
|
658 | 658 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
659 | 659 | return errs |
|
660 | 660 | |
|
661 | 661 | def debugancestor(ui, index, rev1, rev2): |
|
662 | 662 | """find the ancestor revision of two revisions in a given index""" |
|
663 | 663 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) |
|
664 | 664 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
665 | 665 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
666 | 666 | |
|
667 | 667 | def debugcomplete(ui, cmd='', **opts): |
|
668 | 668 | """returns the completion list associated with the given command""" |
|
669 | 669 | |
|
670 | 670 | if opts['options']: |
|
671 | 671 | options = [] |
|
672 | 672 | otables = [globalopts] |
|
673 | 673 | if cmd: |
|
674 | 674 | aliases, entry = findcmd(ui, cmd) |
|
675 | 675 | otables.append(entry[1]) |
|
676 | 676 | for t in otables: |
|
677 | 677 | for o in t: |
|
678 | 678 | if o[0]: |
|
679 | 679 | options.append('-%s' % o[0]) |
|
680 | 680 | options.append('--%s' % o[1]) |
|
681 | 681 | ui.write("%s\n" % "\n".join(options)) |
|
682 | 682 | return |
|
683 | 683 | |
|
684 | 684 | clist = findpossible(ui, cmd).keys() |
|
685 | 685 | clist.sort() |
|
686 | 686 | ui.write("%s\n" % "\n".join(clist)) |
|
687 | 687 | |
|
688 | 688 | def debugrebuildstate(ui, repo, rev=None): |
|
689 | 689 | """rebuild the dirstate as it would look like for the given revision""" |
|
690 | 690 | if not rev: |
|
691 | 691 | rev = repo.changelog.tip() |
|
692 | 692 | else: |
|
693 | 693 | rev = repo.lookup(rev) |
|
694 | 694 | change = repo.changelog.read(rev) |
|
695 | 695 | n = change[0] |
|
696 | 696 | files = repo.manifest.read(n) |
|
697 | 697 | wlock = repo.wlock() |
|
698 | 698 | repo.dirstate.rebuild(rev, files) |
|
699 | 699 | |
|
700 | 700 | def debugcheckstate(ui, repo): |
|
701 | 701 | """validate the correctness of the current dirstate""" |
|
702 | 702 | parent1, parent2 = repo.dirstate.parents() |
|
703 | 703 | repo.dirstate.read() |
|
704 | 704 | dc = repo.dirstate.map |
|
705 | 705 | keys = dc.keys() |
|
706 | 706 | keys.sort() |
|
707 | 707 | m1n = repo.changelog.read(parent1)[0] |
|
708 | 708 | m2n = repo.changelog.read(parent2)[0] |
|
709 | 709 | m1 = repo.manifest.read(m1n) |
|
710 | 710 | m2 = repo.manifest.read(m2n) |
|
711 | 711 | errors = 0 |
|
712 | 712 | for f in dc: |
|
713 | 713 | state = repo.dirstate.state(f) |
|
714 | 714 | if state in "nr" and f not in m1: |
|
715 | 715 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
716 | 716 | errors += 1 |
|
717 | 717 | if state in "a" and f in m1: |
|
718 | 718 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
719 | 719 | errors += 1 |
|
720 | 720 | if state in "m" and f not in m1 and f not in m2: |
|
721 | 721 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
722 | 722 | (f, state)) |
|
723 | 723 | errors += 1 |
|
724 | 724 | for f in m1: |
|
725 | 725 | state = repo.dirstate.state(f) |
|
726 | 726 | if state not in "nrm": |
|
727 | 727 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
728 | 728 | errors += 1 |
|
729 | 729 | if errors: |
|
730 | 730 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
731 | 731 | raise util.Abort(error) |
|
732 | 732 | |
|
733 | 733 | def showconfig(ui, repo, *values, **opts): |
|
734 | 734 | """show combined config settings from all hgrc files |
|
735 | 735 | |
|
736 | 736 | With no args, print names and values of all config items. |
|
737 | 737 | |
|
738 | 738 | With one arg of the form section.name, print just the value of |
|
739 | 739 | that config item. |
|
740 | 740 | |
|
741 | 741 | With multiple args, print names and values of all config items |
|
742 | 742 | with matching section names.""" |
|
743 | 743 | |
|
744 | 744 | untrusted = bool(opts.get('untrusted')) |
|
745 | 745 | if values: |
|
746 | 746 | if len([v for v in values if '.' in v]) > 1: |
|
747 | 747 | raise util.Abort(_('only one config item permitted')) |
|
748 | 748 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
749 | 749 | sectname = section + '.' + name |
|
750 | 750 | if values: |
|
751 | 751 | for v in values: |
|
752 | 752 | if v == section: |
|
753 | 753 | ui.write('%s=%s\n' % (sectname, value)) |
|
754 | 754 | elif v == sectname: |
|
755 | 755 | ui.write(value, '\n') |
|
756 | 756 | else: |
|
757 | 757 | ui.write('%s=%s\n' % (sectname, value)) |
|
758 | 758 | |
|
759 | 759 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
760 | 760 | """manually set the parents of the current working directory |
|
761 | 761 | |
|
762 | 762 | This is useful for writing repository conversion tools, but should |
|
763 | 763 | be used with care. |
|
764 | 764 | """ |
|
765 | 765 | |
|
766 | 766 | if not rev2: |
|
767 | 767 | rev2 = hex(nullid) |
|
768 | 768 | |
|
769 | 769 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
770 | 770 | |
|
771 | 771 | def debugstate(ui, repo): |
|
772 | 772 | """show the contents of the current dirstate""" |
|
773 | 773 | repo.dirstate.read() |
|
774 | 774 | dc = repo.dirstate.map |
|
775 | 775 | keys = dc.keys() |
|
776 | 776 | keys.sort() |
|
777 | 777 | for file_ in keys: |
|
778 | 778 | if dc[file_][3] == -1: |
|
779 | 779 | # Pad or slice to locale representation |
|
780 | 780 | locale_len = len(time.strftime("%x %X", time.localtime(0))) |
|
781 | 781 | timestr = 'unset' |
|
782 | 782 | timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr)) |
|
783 | 783 | else: |
|
784 | 784 | timestr = time.strftime("%x %X", time.localtime(dc[file_][3])) |
|
785 | 785 | ui.write("%c %3o %10d %s %s\n" |
|
786 | 786 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
787 | 787 | timestr, file_)) |
|
788 | 788 | for f in repo.dirstate.copies(): |
|
789 | 789 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
790 | 790 | |
|
791 | 791 | def debugdata(ui, file_, rev): |
|
792 | 792 | """dump the contents of an data file revision""" |
|
793 | 793 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
794 | 794 | file_[:-2] + ".i", file_, 0) |
|
795 | 795 | try: |
|
796 | 796 | ui.write(r.revision(r.lookup(rev))) |
|
797 | 797 | except KeyError: |
|
798 | 798 | raise util.Abort(_('invalid revision identifier %s') % rev) |
|
799 | 799 | |
|
800 | 800 | def debugdate(ui, date, range=None, **opts): |
|
801 | 801 | """parse and display a date""" |
|
802 | 802 | if opts["extended"]: |
|
803 | 803 | d = util.parsedate(date, util.extendeddateformats) |
|
804 | 804 | else: |
|
805 | 805 | d = util.parsedate(date) |
|
806 | 806 | ui.write("internal: %s %s\n" % d) |
|
807 | 807 | ui.write("standard: %s\n" % util.datestr(d)) |
|
808 | 808 | if range: |
|
809 | 809 | m = util.matchdate(range) |
|
810 | 810 | ui.write("match: %s\n" % m(d[0])) |
|
811 | 811 | |
|
812 | 812 | def debugindex(ui, file_): |
|
813 | 813 | """dump the contents of an index file""" |
|
814 | 814 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
815 | 815 | ui.write(" rev offset length base linkrev" + |
|
816 | 816 | " nodeid p1 p2\n") |
|
817 | 817 | for i in xrange(r.count()): |
|
818 | 818 | node = r.node(i) |
|
819 | 819 | pp = r.parents(node) |
|
820 | 820 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
821 | 821 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), |
|
822 | 822 | short(node), short(pp[0]), short(pp[1]))) |
|
823 | 823 | |
|
824 | 824 | def debugindexdot(ui, file_): |
|
825 | 825 | """dump an index DAG as a .dot file""" |
|
826 | 826 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
827 | 827 | ui.write("digraph G {\n") |
|
828 | 828 | for i in xrange(r.count()): |
|
829 | 829 | node = r.node(i) |
|
830 | 830 | pp = r.parents(node) |
|
831 | 831 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
832 | 832 | if pp[1] != nullid: |
|
833 | 833 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
834 | 834 | ui.write("}\n") |
|
835 | 835 | |
|
836 | 836 | def debuginstall(ui): |
|
837 | 837 | '''test Mercurial installation''' |
|
838 | 838 | |
|
839 | 839 | def writetemp(contents): |
|
840 | 840 | (fd, name) = tempfile.mkstemp() |
|
841 | 841 | f = os.fdopen(fd, "wb") |
|
842 | 842 | f.write(contents) |
|
843 | 843 | f.close() |
|
844 | 844 | return name |
|
845 | 845 | |
|
846 | 846 | problems = 0 |
|
847 | 847 | |
|
848 | 848 | # encoding |
|
849 | 849 | ui.status(_("Checking encoding (%s)...\n") % util._encoding) |
|
850 | 850 | try: |
|
851 | 851 | util.fromlocal("test") |
|
852 | 852 | except util.Abort, inst: |
|
853 | 853 | ui.write(" %s\n" % inst) |
|
854 | 854 | ui.write(_(" (check that your locale is properly set)\n")) |
|
855 | 855 | problems += 1 |
|
856 | 856 | |
|
857 | 857 | # compiled modules |
|
858 | 858 | ui.status(_("Checking extensions...\n")) |
|
859 | 859 | try: |
|
860 | 860 | import bdiff, mpatch, base85 |
|
861 | 861 | except Exception, inst: |
|
862 | 862 | ui.write(" %s\n" % inst) |
|
863 | 863 | ui.write(_(" One or more extensions could not be found")) |
|
864 | 864 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
865 | 865 | problems += 1 |
|
866 | 866 | |
|
867 | 867 | # templates |
|
868 | 868 | ui.status(_("Checking templates...\n")) |
|
869 | 869 | try: |
|
870 | 870 | import templater |
|
871 | 871 | t = templater.templater(templater.templatepath("map-cmdline.default")) |
|
872 | 872 | except Exception, inst: |
|
873 | 873 | ui.write(" %s\n" % inst) |
|
874 | 874 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
875 | 875 | problems += 1 |
|
876 | 876 | |
|
877 | 877 | # patch |
|
878 | 878 | ui.status(_("Checking patch...\n")) |
|
879 | 879 | path = os.environ.get('PATH', '') |
|
880 | 880 | patcher = util.find_in_path('gpatch', path, |
|
881 | 881 | util.find_in_path('patch', path, None)) |
|
882 | 882 | if not patcher: |
|
883 | 883 | ui.write(_(" Can't find patch or gpatch in PATH\n")) |
|
884 | 884 | ui.write(_(" (specify a patch utility in your .hgrc file)\n")) |
|
885 | 885 | problems += 1 |
|
886 | 886 | else: |
|
887 | 887 | # actually attempt a patch here |
|
888 | 888 | a = "1\n2\n3\n4\n" |
|
889 | 889 | b = "1\n2\n3\ninsert\n4\n" |
|
890 | 890 | d = mdiff.unidiff(a, None, b, None, "a") |
|
891 | 891 | fa = writetemp(a) |
|
892 | 892 | fd = writetemp(d) |
|
893 | 893 | fp = os.popen('%s %s %s' % (patcher, fa, fd)) |
|
894 | 894 | files = [] |
|
895 | 895 | output = "" |
|
896 | 896 | for line in fp: |
|
897 | 897 | output += line |
|
898 | 898 | if line.startswith('patching file '): |
|
899 | 899 | pf = util.parse_patch_output(line.rstrip()) |
|
900 | 900 | files.append(pf) |
|
901 | 901 | if files != [fa]: |
|
902 | 902 | ui.write(_(" unexpected patch output!")) |
|
903 | 903 | ui.write(_(" (you may have an incompatible version of patch)\n")) |
|
904 | 904 | ui.write(output) |
|
905 | 905 | problems += 1 |
|
906 | 906 | a = file(fa).read() |
|
907 | 907 | if a != b: |
|
908 | 908 | ui.write(_(" patch test failed!")) |
|
909 | 909 | ui.write(_(" (you may have an incompatible version of patch)\n")) |
|
910 | 910 | problems += 1 |
|
911 | 911 | os.unlink(fa) |
|
912 | 912 | os.unlink(fd) |
|
913 | 913 | |
|
914 | 914 | # merge helper |
|
915 | 915 | ui.status(_("Checking merge helper...\n")) |
|
916 | 916 | cmd = (os.environ.get("HGMERGE") or ui.config("ui", "merge") |
|
917 | 917 | or "hgmerge") |
|
918 | 918 | cmdpath = util.find_in_path(cmd, path) |
|
919 | 919 | if not cmdpath: |
|
920 | 920 | cmdpath = util.find_in_path(cmd.split()[0], path) |
|
921 | 921 | if not cmdpath: |
|
922 | 922 | if cmd == 'hgmerge': |
|
923 | 923 | ui.write(_(" No merge helper set and can't find default" |
|
924 | 924 | " hgmerge script in PATH\n")) |
|
925 | 925 | ui.write(_(" (specify a merge helper in your .hgrc file)\n")) |
|
926 | 926 | else: |
|
927 | 927 | ui.write(_(" Can't find merge helper '%s' in PATH\n") % cmd) |
|
928 | 928 | ui.write(_(" (specify a merge helper in your .hgrc file)\n")) |
|
929 | 929 | problems += 1 |
|
930 | 930 | else: |
|
931 | 931 | # actually attempt a patch here |
|
932 | 932 | fa = writetemp("1\n2\n3\n4\n") |
|
933 | 933 | fl = writetemp("1\n2\n3\ninsert\n4\n") |
|
934 | 934 | fr = writetemp("begin\n1\n2\n3\n4\n") |
|
935 | 935 | r = os.system('%s %s %s %s' % (cmd, fl, fa, fr)) |
|
936 | 936 | if r: |
|
937 | 937 | ui.write(_(" got unexpected merge error %d!") % r) |
|
938 | 938 | problems += 1 |
|
939 | 939 | m = file(fl).read() |
|
940 | 940 | if m != "begin\n1\n2\n3\ninsert\n4\n": |
|
941 | 941 | ui.write(_(" got unexpected merge results!") % r) |
|
942 | 942 | ui.write(_(" (your merge helper may have the" |
|
943 | 943 | " wrong argument order)\n")) |
|
944 | 944 | ui.write(m) |
|
945 | 945 | os.unlink(fa) |
|
946 | 946 | os.unlink(fl) |
|
947 | 947 | os.unlink(fr) |
|
948 | 948 | |
|
949 | 949 | # editor |
|
950 | 950 | ui.status(_("Checking commit editor...\n")) |
|
951 | 951 | editor = (os.environ.get("HGEDITOR") or |
|
952 | 952 | ui.config("ui", "editor") or |
|
953 | 953 | os.environ.get("EDITOR", "vi")) |
|
954 | 954 | cmdpath = util.find_in_path(editor, path) |
|
955 | 955 | if not cmdpath: |
|
956 | 956 | cmdpath = util.find_in_path(editor.split()[0], path) |
|
957 | 957 | if not cmdpath: |
|
958 | 958 | if editor == 'vi': |
|
959 | 959 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
960 | 960 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) |
|
961 | 961 | else: |
|
962 | 962 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
963 | 963 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) |
|
964 | 964 | problems += 1 |
|
965 | 965 | |
|
966 | 966 | # check username |
|
967 | 967 | ui.status(_("Checking username...\n")) |
|
968 | 968 | user = os.environ.get("HGUSER") |
|
969 | 969 | if user is None: |
|
970 | 970 | user = ui.config("ui", "username") |
|
971 | 971 | if user is None: |
|
972 | 972 | user = os.environ.get("EMAIL") |
|
973 | 973 | if not user: |
|
974 | 974 | ui.warn(" ") |
|
975 | 975 | ui.username() |
|
976 | 976 | ui.write(_(" (specify a username in your .hgrc file)\n")) |
|
977 | 977 | |
|
978 | 978 | if not problems: |
|
979 | 979 | ui.status(_("No problems detected\n")) |
|
980 | 980 | else: |
|
981 | 981 | ui.write(_("%s problems detected," |
|
982 | 982 | " please check your install!\n") % problems) |
|
983 | 983 | |
|
984 | 984 | return problems |
|
985 | 985 | |
|
986 | 986 | def debugrename(ui, repo, file1, *pats, **opts): |
|
987 | 987 | """dump rename information""" |
|
988 | 988 | |
|
989 | 989 | ctx = repo.changectx(opts.get('rev', 'tip')) |
|
990 | 990 | for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, |
|
991 | 991 | ctx.node()): |
|
992 | 992 | m = ctx.filectx(abs).renamed() |
|
993 | 993 | if m: |
|
994 | 994 | ui.write(_("%s renamed from %s:%s\n") % (rel, m[0], hex(m[1]))) |
|
995 | 995 | else: |
|
996 | 996 | ui.write(_("%s not renamed\n") % rel) |
|
997 | 997 | |
|
998 | 998 | def debugwalk(ui, repo, *pats, **opts): |
|
999 | 999 | """show how files match on given patterns""" |
|
1000 | 1000 | items = list(cmdutil.walk(repo, pats, opts)) |
|
1001 | 1001 | if not items: |
|
1002 | 1002 | return |
|
1003 | 1003 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1004 | 1004 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1005 | 1005 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1006 | 1006 | for src, abs, rel, exact in items: |
|
1007 | 1007 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1008 | 1008 | ui.write("%s\n" % line.rstrip()) |
|
1009 | 1009 | |
|
1010 | 1010 | def diff(ui, repo, *pats, **opts): |
|
1011 | 1011 | """diff repository (or selected files) |
|
1012 | 1012 | |
|
1013 | 1013 | Show differences between revisions for the specified files. |
|
1014 | 1014 | |
|
1015 | 1015 | Differences between files are shown using the unified diff format. |
|
1016 | 1016 | |
|
1017 | 1017 | NOTE: diff may generate unexpected results for merges, as it will |
|
1018 | 1018 | default to comparing against the working directory's first parent |
|
1019 | 1019 | changeset if no revisions are specified. |
|
1020 | 1020 | |
|
1021 | 1021 | When two revision arguments are given, then changes are shown |
|
1022 | 1022 | between those revisions. If only one revision is specified then |
|
1023 | 1023 | that revision is compared to the working directory, and, when no |
|
1024 | 1024 | revisions are specified, the working directory files are compared |
|
1025 | 1025 | to its parent. |
|
1026 | 1026 | |
|
1027 | 1027 | Without the -a option, diff will avoid generating diffs of files |
|
1028 | 1028 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1029 | 1029 | probably with undesirable results. |
|
1030 | 1030 | """ |
|
1031 | 1031 | node1, node2 = cmdutil.revpair(repo, opts['rev']) |
|
1032 | 1032 | |
|
1033 | 1033 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
1034 | 1034 | |
|
1035 | 1035 | patch.diff(repo, node1, node2, fns, match=matchfn, |
|
1036 | 1036 | opts=patch.diffopts(ui, opts)) |
|
1037 | 1037 | |
|
1038 | 1038 | def export(ui, repo, *changesets, **opts): |
|
1039 | 1039 | """dump the header and diffs for one or more changesets |
|
1040 | 1040 | |
|
1041 | 1041 | Print the changeset header and diffs for one or more revisions. |
|
1042 | 1042 | |
|
1043 | 1043 | The information shown in the changeset header is: author, |
|
1044 | 1044 | changeset hash, parent(s) and commit comment. |
|
1045 | 1045 | |
|
1046 | 1046 | NOTE: export may generate unexpected diff output for merge changesets, |
|
1047 | 1047 | as it will compare the merge changeset against its first parent only. |
|
1048 | 1048 | |
|
1049 | 1049 | Output may be to a file, in which case the name of the file is |
|
1050 | 1050 | given using a format string. The formatting rules are as follows: |
|
1051 | 1051 | |
|
1052 | 1052 | %% literal "%" character |
|
1053 | 1053 | %H changeset hash (40 bytes of hexadecimal) |
|
1054 | 1054 | %N number of patches being generated |
|
1055 | 1055 | %R changeset revision number |
|
1056 | 1056 | %b basename of the exporting repository |
|
1057 | 1057 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1058 | 1058 | %n zero-padded sequence number, starting at 1 |
|
1059 | 1059 | %r zero-padded changeset revision number |
|
1060 | 1060 | |
|
1061 | 1061 | Without the -a option, export will avoid generating diffs of files |
|
1062 | 1062 | it detects as binary. With -a, export will generate a diff anyway, |
|
1063 | 1063 | probably with undesirable results. |
|
1064 | 1064 | |
|
1065 | 1065 | With the --switch-parent option, the diff will be against the second |
|
1066 | 1066 | parent. It can be useful to review a merge. |
|
1067 | 1067 | """ |
|
1068 | 1068 | if not changesets: |
|
1069 | 1069 | raise util.Abort(_("export requires at least one changeset")) |
|
1070 | 1070 | revs = cmdutil.revrange(repo, changesets) |
|
1071 | 1071 | if len(revs) > 1: |
|
1072 | 1072 | ui.note(_('exporting patches:\n')) |
|
1073 | 1073 | else: |
|
1074 | 1074 | ui.note(_('exporting patch:\n')) |
|
1075 | 1075 | patch.export(repo, revs, template=opts['output'], |
|
1076 | 1076 | switch_parent=opts['switch_parent'], |
|
1077 | 1077 | opts=patch.diffopts(ui, opts)) |
|
1078 | 1078 | |
|
1079 | 1079 | def grep(ui, repo, pattern, *pats, **opts): |
|
1080 | 1080 | """search for a pattern in specified files and revisions |
|
1081 | 1081 | |
|
1082 | 1082 | Search revisions of files for a regular expression. |
|
1083 | 1083 | |
|
1084 | 1084 | This command behaves differently than Unix grep. It only accepts |
|
1085 | 1085 | Python/Perl regexps. It searches repository history, not the |
|
1086 | 1086 | working directory. It always prints the revision number in which |
|
1087 | 1087 | a match appears. |
|
1088 | 1088 | |
|
1089 | 1089 | By default, grep only prints output for the first revision of a |
|
1090 | 1090 | file in which it finds a match. To get it to print every revision |
|
1091 | 1091 | that contains a change in match status ("-" for a match that |
|
1092 | 1092 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1093 | 1093 | use the --all flag. |
|
1094 | 1094 | """ |
|
1095 | 1095 | reflags = 0 |
|
1096 | 1096 | if opts['ignore_case']: |
|
1097 | 1097 | reflags |= re.I |
|
1098 | 1098 | regexp = re.compile(pattern, reflags) |
|
1099 | 1099 | sep, eol = ':', '\n' |
|
1100 | 1100 | if opts['print0']: |
|
1101 | 1101 | sep = eol = '\0' |
|
1102 | 1102 | |
|
1103 | 1103 | fcache = {} |
|
1104 | 1104 | def getfile(fn): |
|
1105 | 1105 | if fn not in fcache: |
|
1106 | 1106 | fcache[fn] = repo.file(fn) |
|
1107 | 1107 | return fcache[fn] |
|
1108 | 1108 | |
|
1109 | 1109 | def matchlines(body): |
|
1110 | 1110 | begin = 0 |
|
1111 | 1111 | linenum = 0 |
|
1112 | 1112 | while True: |
|
1113 | 1113 | match = regexp.search(body, begin) |
|
1114 | 1114 | if not match: |
|
1115 | 1115 | break |
|
1116 | 1116 | mstart, mend = match.span() |
|
1117 | 1117 | linenum += body.count('\n', begin, mstart) + 1 |
|
1118 | 1118 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1119 | 1119 | lend = body.find('\n', mend) |
|
1120 | 1120 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1121 | 1121 | begin = lend + 1 |
|
1122 | 1122 | |
|
1123 | 1123 | class linestate(object): |
|
1124 | 1124 | def __init__(self, line, linenum, colstart, colend): |
|
1125 | 1125 | self.line = line |
|
1126 | 1126 | self.linenum = linenum |
|
1127 | 1127 | self.colstart = colstart |
|
1128 | 1128 | self.colend = colend |
|
1129 | 1129 | |
|
1130 | 1130 | def __eq__(self, other): |
|
1131 | 1131 | return self.line == other.line |
|
1132 | 1132 | |
|
1133 | 1133 | matches = {} |
|
1134 | 1134 | copies = {} |
|
1135 | 1135 | def grepbody(fn, rev, body): |
|
1136 | 1136 | matches[rev].setdefault(fn, []) |
|
1137 | 1137 | m = matches[rev][fn] |
|
1138 | 1138 | for lnum, cstart, cend, line in matchlines(body): |
|
1139 | 1139 | s = linestate(line, lnum, cstart, cend) |
|
1140 | 1140 | m.append(s) |
|
1141 | 1141 | |
|
1142 | 1142 | def difflinestates(a, b): |
|
1143 | 1143 | sm = difflib.SequenceMatcher(None, a, b) |
|
1144 | 1144 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
1145 | 1145 | if tag == 'insert': |
|
1146 | 1146 | for i in xrange(blo, bhi): |
|
1147 | 1147 | yield ('+', b[i]) |
|
1148 | 1148 | elif tag == 'delete': |
|
1149 | 1149 | for i in xrange(alo, ahi): |
|
1150 | 1150 | yield ('-', a[i]) |
|
1151 | 1151 | elif tag == 'replace': |
|
1152 | 1152 | for i in xrange(alo, ahi): |
|
1153 | 1153 | yield ('-', a[i]) |
|
1154 | 1154 | for i in xrange(blo, bhi): |
|
1155 | 1155 | yield ('+', b[i]) |
|
1156 | 1156 | |
|
1157 | 1157 | prev = {} |
|
1158 | 1158 | def display(fn, rev, states, prevstates): |
|
1159 | 1159 | counts = {'-': 0, '+': 0} |
|
1160 | 1160 | filerevmatches = {} |
|
1161 | 1161 | if incrementing or not opts['all']: |
|
1162 | 1162 | a, b, r = prevstates, states, rev |
|
1163 | 1163 | else: |
|
1164 | 1164 | a, b, r = states, prevstates, prev.get(fn, -1) |
|
1165 | 1165 | for change, l in difflinestates(a, b): |
|
1166 | 1166 | cols = [fn, str(r)] |
|
1167 | 1167 | if opts['line_number']: |
|
1168 | 1168 | cols.append(str(l.linenum)) |
|
1169 | 1169 | if opts['all']: |
|
1170 | 1170 | cols.append(change) |
|
1171 | 1171 | if opts['user']: |
|
1172 | 1172 | cols.append(ui.shortuser(get(r)[1])) |
|
1173 | 1173 | if opts['files_with_matches']: |
|
1174 | 1174 | c = (fn, r) |
|
1175 | 1175 | if c in filerevmatches: |
|
1176 | 1176 | continue |
|
1177 | 1177 | filerevmatches[c] = 1 |
|
1178 | 1178 | else: |
|
1179 | 1179 | cols.append(l.line) |
|
1180 | 1180 | ui.write(sep.join(cols), eol) |
|
1181 | 1181 | counts[change] += 1 |
|
1182 | 1182 | return counts['+'], counts['-'] |
|
1183 | 1183 | |
|
1184 | 1184 | fstate = {} |
|
1185 | 1185 | skip = {} |
|
1186 | 1186 | get = util.cachefunc(lambda r: repo.changectx(r).changeset()) |
|
1187 | 1187 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) |
|
1188 | 1188 | count = 0 |
|
1189 | 1189 | incrementing = False |
|
1190 | 1190 | follow = opts.get('follow') |
|
1191 | 1191 | for st, rev, fns in changeiter: |
|
1192 | 1192 | if st == 'window': |
|
1193 | 1193 | incrementing = rev |
|
1194 | 1194 | matches.clear() |
|
1195 | 1195 | elif st == 'add': |
|
1196 | 1196 | mf = repo.changectx(rev).manifest() |
|
1197 | 1197 | matches[rev] = {} |
|
1198 | 1198 | for fn in fns: |
|
1199 | 1199 | if fn in skip: |
|
1200 | 1200 | continue |
|
1201 | 1201 | fstate.setdefault(fn, {}) |
|
1202 | 1202 | try: |
|
1203 | 1203 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1204 | 1204 | if follow: |
|
1205 | 1205 | copied = getfile(fn).renamed(mf[fn]) |
|
1206 | 1206 | if copied: |
|
1207 | 1207 | copies.setdefault(rev, {})[fn] = copied[0] |
|
1208 | 1208 | except KeyError: |
|
1209 | 1209 | pass |
|
1210 | 1210 | elif st == 'iter': |
|
1211 | 1211 | states = matches[rev].items() |
|
1212 | 1212 | states.sort() |
|
1213 | 1213 | for fn, m in states: |
|
1214 | 1214 | copy = copies.get(rev, {}).get(fn) |
|
1215 | 1215 | if fn in skip: |
|
1216 | 1216 | if copy: |
|
1217 | 1217 | skip[copy] = True |
|
1218 | 1218 | continue |
|
1219 | 1219 | if incrementing or not opts['all'] or fstate[fn]: |
|
1220 | 1220 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1221 | 1221 | count += pos + neg |
|
1222 | 1222 | if pos and not opts['all']: |
|
1223 | 1223 | skip[fn] = True |
|
1224 | 1224 | if copy: |
|
1225 | 1225 | skip[copy] = True |
|
1226 | 1226 | fstate[fn] = m |
|
1227 | 1227 | if copy: |
|
1228 | 1228 | fstate[copy] = m |
|
1229 | 1229 | prev[fn] = rev |
|
1230 | 1230 | |
|
1231 | 1231 | if not incrementing: |
|
1232 | 1232 | fstate = fstate.items() |
|
1233 | 1233 | fstate.sort() |
|
1234 | 1234 | for fn, state in fstate: |
|
1235 | 1235 | if fn in skip: |
|
1236 | 1236 | continue |
|
1237 | 1237 | if fn not in copies.get(prev[fn], {}): |
|
1238 | 1238 | display(fn, rev, {}, state) |
|
1239 | 1239 | return (count == 0 and 1) or 0 |
|
1240 | 1240 | |
|
1241 | 1241 | def heads(ui, repo, **opts): |
|
1242 | 1242 | """show current repository heads |
|
1243 | 1243 | |
|
1244 | 1244 | Show all repository head changesets. |
|
1245 | 1245 | |
|
1246 | 1246 | Repository "heads" are changesets that don't have children |
|
1247 | 1247 | changesets. They are where development generally takes place and |
|
1248 | 1248 | are the usual targets for update and merge operations. |
|
1249 | 1249 | """ |
|
1250 | 1250 | if opts['rev']: |
|
1251 | 1251 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1252 | 1252 | else: |
|
1253 | 1253 | heads = repo.heads() |
|
1254 | 1254 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
1255 | 1255 | for n in heads: |
|
1256 | 1256 | displayer.show(changenode=n) |
|
1257 | 1257 | |
|
1258 | 1258 | def help_(ui, name=None, with_version=False): |
|
1259 | 1259 | """show help for a command, extension, or list of commands |
|
1260 | 1260 | |
|
1261 | 1261 | With no arguments, print a list of commands and short help. |
|
1262 | 1262 | |
|
1263 | 1263 | Given a command name, print help for that command. |
|
1264 | 1264 | |
|
1265 | 1265 | Given an extension name, print help for that extension, and the |
|
1266 | 1266 | commands it provides.""" |
|
1267 | 1267 | option_lists = [] |
|
1268 | 1268 | |
|
1269 | 1269 | def helpcmd(name): |
|
1270 | 1270 | if with_version: |
|
1271 | 1271 | version_(ui) |
|
1272 | 1272 | ui.write('\n') |
|
1273 | 1273 | aliases, i = findcmd(ui, name) |
|
1274 | 1274 | # synopsis |
|
1275 | 1275 | ui.write("%s\n\n" % i[2]) |
|
1276 | 1276 | |
|
1277 | 1277 | # description |
|
1278 | 1278 | doc = i[0].__doc__ |
|
1279 | 1279 | if not doc: |
|
1280 | 1280 | doc = _("(No help text available)") |
|
1281 | 1281 | if ui.quiet: |
|
1282 | 1282 | doc = doc.splitlines(0)[0] |
|
1283 | 1283 | ui.write("%s\n" % doc.rstrip()) |
|
1284 | 1284 | |
|
1285 | 1285 | if not ui.quiet: |
|
1286 | 1286 | # aliases |
|
1287 | 1287 | if len(aliases) > 1: |
|
1288 | 1288 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
1289 | 1289 | |
|
1290 | 1290 | # options |
|
1291 | 1291 | if i[1]: |
|
1292 | 1292 | option_lists.append(("options", i[1])) |
|
1293 | 1293 | |
|
1294 | 1294 | def helplist(select=None): |
|
1295 | 1295 | h = {} |
|
1296 | 1296 | cmds = {} |
|
1297 | 1297 | for c, e in table.items(): |
|
1298 | 1298 | f = c.split("|", 1)[0] |
|
1299 | 1299 | if select and not select(f): |
|
1300 | 1300 | continue |
|
1301 | 1301 | if name == "shortlist" and not f.startswith("^"): |
|
1302 | 1302 | continue |
|
1303 | 1303 | f = f.lstrip("^") |
|
1304 | 1304 | if not ui.debugflag and f.startswith("debug"): |
|
1305 | 1305 | continue |
|
1306 | 1306 | doc = e[0].__doc__ |
|
1307 | 1307 | if not doc: |
|
1308 | 1308 | doc = _("(No help text available)") |
|
1309 | 1309 | h[f] = doc.splitlines(0)[0].rstrip() |
|
1310 | 1310 | cmds[f] = c.lstrip("^") |
|
1311 | 1311 | |
|
1312 | 1312 | fns = h.keys() |
|
1313 | 1313 | fns.sort() |
|
1314 | 1314 | m = max(map(len, fns)) |
|
1315 | 1315 | for f in fns: |
|
1316 | 1316 | if ui.verbose: |
|
1317 | 1317 | commands = cmds[f].replace("|",", ") |
|
1318 | 1318 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
1319 | 1319 | else: |
|
1320 | 1320 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
1321 | 1321 | |
|
1322 | 1322 | def helptopic(name): |
|
1323 | 1323 | v = None |
|
1324 | 1324 | for i in help.helptable: |
|
1325 | 1325 | l = i.split('|') |
|
1326 | 1326 | if name in l: |
|
1327 | 1327 | v = i |
|
1328 | 1328 | header = l[-1] |
|
1329 | 1329 | if not v: |
|
1330 | 1330 | raise UnknownCommand(name) |
|
1331 | 1331 | |
|
1332 | 1332 | # description |
|
1333 | 1333 | doc = help.helptable[v] |
|
1334 | 1334 | if not doc: |
|
1335 | 1335 | doc = _("(No help text available)") |
|
1336 | 1336 | if callable(doc): |
|
1337 | 1337 | doc = doc() |
|
1338 | 1338 | |
|
1339 | 1339 | ui.write("%s\n" % header) |
|
1340 | 1340 | ui.write("%s\n" % doc.rstrip()) |
|
1341 | 1341 | |
|
1342 | 1342 | def helpext(name): |
|
1343 | 1343 | try: |
|
1344 | 1344 | mod = findext(name) |
|
1345 | 1345 | except KeyError: |
|
1346 | 1346 | raise UnknownCommand(name) |
|
1347 | 1347 | |
|
1348 | 1348 | doc = (mod.__doc__ or _('No help text available')).splitlines(0) |
|
1349 | 1349 | ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0])) |
|
1350 | 1350 | for d in doc[1:]: |
|
1351 | 1351 | ui.write(d, '\n') |
|
1352 | 1352 | |
|
1353 | 1353 | ui.status('\n') |
|
1354 | 1354 | |
|
1355 | 1355 | try: |
|
1356 | 1356 | ct = mod.cmdtable |
|
1357 | 1357 | except AttributeError: |
|
1358 | 1358 | ui.status(_('no commands defined\n')) |
|
1359 | 1359 | return |
|
1360 | 1360 | |
|
1361 | 1361 | if ui.verbose: |
|
1362 | 1362 | ui.status(_('list of commands:\n\n')) |
|
1363 | 1363 | else: |
|
1364 | 1364 | ui.status(_('list of commands (use "hg help -v %s" ' |
|
1365 | 1365 | 'to show aliases and global options):\n\n') % name) |
|
1366 | 1366 | |
|
1367 | 1367 | modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct]) |
|
1368 | 1368 | helplist(modcmds.has_key) |
|
1369 | 1369 | |
|
1370 | 1370 | if name and name != 'shortlist': |
|
1371 | 1371 | i = None |
|
1372 | 1372 | for f in (helpcmd, helptopic, helpext): |
|
1373 | 1373 | try: |
|
1374 | 1374 | f(name) |
|
1375 | 1375 | i = None |
|
1376 | 1376 | break |
|
1377 | 1377 | except UnknownCommand, inst: |
|
1378 | 1378 | i = inst |
|
1379 | 1379 | if i: |
|
1380 | 1380 | raise i |
|
1381 | 1381 | |
|
1382 | 1382 | else: |
|
1383 | 1383 | # program name |
|
1384 | 1384 | if ui.verbose or with_version: |
|
1385 | 1385 | version_(ui) |
|
1386 | 1386 | else: |
|
1387 | 1387 | ui.status(_("Mercurial Distributed SCM\n")) |
|
1388 | 1388 | ui.status('\n') |
|
1389 | 1389 | |
|
1390 | 1390 | # list of commands |
|
1391 | 1391 | if name == "shortlist": |
|
1392 | 1392 | ui.status(_('basic commands (use "hg help" ' |
|
1393 | 1393 | 'for the full list or option "-v" for details):\n\n')) |
|
1394 | 1394 | elif ui.verbose: |
|
1395 | 1395 | ui.status(_('list of commands:\n\n')) |
|
1396 | 1396 | else: |
|
1397 | 1397 | ui.status(_('list of commands (use "hg help -v" ' |
|
1398 | 1398 | 'to show aliases and global options):\n\n')) |
|
1399 | 1399 | |
|
1400 | 1400 | helplist() |
|
1401 | 1401 | |
|
1402 | 1402 | # global options |
|
1403 | 1403 | if ui.verbose: |
|
1404 | 1404 | option_lists.append(("global options", globalopts)) |
|
1405 | 1405 | |
|
1406 | 1406 | # list all option lists |
|
1407 | 1407 | opt_output = [] |
|
1408 | 1408 | for title, options in option_lists: |
|
1409 | 1409 | opt_output.append(("\n%s:\n" % title, None)) |
|
1410 | 1410 | for shortopt, longopt, default, desc in options: |
|
1411 | 1411 | if "DEPRECATED" in desc and not ui.verbose: continue |
|
1412 | 1412 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
1413 | 1413 | longopt and " --%s" % longopt), |
|
1414 | 1414 | "%s%s" % (desc, |
|
1415 | 1415 | default |
|
1416 | 1416 | and _(" (default: %s)") % default |
|
1417 | 1417 | or ""))) |
|
1418 | 1418 | |
|
1419 | 1419 | if opt_output: |
|
1420 | 1420 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
1421 | 1421 | for first, second in opt_output: |
|
1422 | 1422 | if second: |
|
1423 | 1423 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
1424 | 1424 | else: |
|
1425 | 1425 | ui.write("%s\n" % first) |
|
1426 | 1426 | |
|
1427 | 1427 | def identify(ui, repo): |
|
1428 | 1428 | """print information about the working copy |
|
1429 | 1429 | |
|
1430 | 1430 | Print a short summary of the current state of the repo. |
|
1431 | 1431 | |
|
1432 | 1432 | This summary identifies the repository state using one or two parent |
|
1433 | 1433 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1434 | 1434 | in the working directory, followed by a list of tags for this revision. |
|
1435 | 1435 | """ |
|
1436 | 1436 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1437 | 1437 | if not parents: |
|
1438 | 1438 | ui.write(_("unknown\n")) |
|
1439 | 1439 | return |
|
1440 | 1440 | |
|
1441 | 1441 | hexfunc = ui.debugflag and hex or short |
|
1442 | 1442 | modified, added, removed, deleted = repo.status()[:4] |
|
1443 | 1443 | output = ["%s%s" % |
|
1444 | 1444 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1445 | 1445 | (modified or added or removed or deleted) and "+" or "")] |
|
1446 | 1446 | |
|
1447 | 1447 | if not ui.quiet: |
|
1448 | 1448 | |
|
1449 | 1449 | branch = util.tolocal(repo.workingctx().branch()) |
|
1450 | if branch: | |
|
1450 | if branch != 'default': | |
|
1451 | 1451 | output.append("(%s)" % branch) |
|
1452 | 1452 | |
|
1453 | 1453 | # multiple tags for a single parent separated by '/' |
|
1454 | 1454 | parenttags = ['/'.join(tags) |
|
1455 | 1455 | for tags in map(repo.nodetags, parents) if tags] |
|
1456 | 1456 | # tags for multiple parents separated by ' + ' |
|
1457 | 1457 | if parenttags: |
|
1458 | 1458 | output.append(' + '.join(parenttags)) |
|
1459 | 1459 | |
|
1460 | 1460 | ui.write("%s\n" % ' '.join(output)) |
|
1461 | 1461 | |
|
1462 | 1462 | def import_(ui, repo, patch1, *patches, **opts): |
|
1463 | 1463 | """import an ordered set of patches |
|
1464 | 1464 | |
|
1465 | 1465 | Import a list of patches and commit them individually. |
|
1466 | 1466 | |
|
1467 | 1467 | If there are outstanding changes in the working directory, import |
|
1468 | 1468 | will abort unless given the -f flag. |
|
1469 | 1469 | |
|
1470 | 1470 | You can import a patch straight from a mail message. Even patches |
|
1471 | 1471 | as attachments work (body part must be type text/plain or |
|
1472 | 1472 | text/x-patch to be used). From and Subject headers of email |
|
1473 | 1473 | message are used as default committer and commit message. All |
|
1474 | 1474 | text/plain body parts before first diff are added to commit |
|
1475 | 1475 | message. |
|
1476 | 1476 | |
|
1477 | 1477 | If imported patch was generated by hg export, user and description |
|
1478 | 1478 | from patch override values from message headers and body. Values |
|
1479 | 1479 | given on command line with -m and -u override these. |
|
1480 | 1480 | |
|
1481 | 1481 | To read a patch from standard input, use patch name "-". |
|
1482 | 1482 | """ |
|
1483 | 1483 | patches = (patch1,) + patches |
|
1484 | 1484 | |
|
1485 | 1485 | if not opts['force']: |
|
1486 | 1486 | bail_if_changed(repo) |
|
1487 | 1487 | |
|
1488 | 1488 | d = opts["base"] |
|
1489 | 1489 | strip = opts["strip"] |
|
1490 | 1490 | |
|
1491 | 1491 | wlock = repo.wlock() |
|
1492 | 1492 | lock = repo.lock() |
|
1493 | 1493 | |
|
1494 | 1494 | for p in patches: |
|
1495 | 1495 | pf = os.path.join(d, p) |
|
1496 | 1496 | |
|
1497 | 1497 | if pf == '-': |
|
1498 | 1498 | ui.status(_("applying patch from stdin\n")) |
|
1499 | 1499 | tmpname, message, user, date = patch.extract(ui, sys.stdin) |
|
1500 | 1500 | else: |
|
1501 | 1501 | ui.status(_("applying %s\n") % p) |
|
1502 | 1502 | tmpname, message, user, date = patch.extract(ui, file(pf)) |
|
1503 | 1503 | |
|
1504 | 1504 | if tmpname is None: |
|
1505 | 1505 | raise util.Abort(_('no diffs found')) |
|
1506 | 1506 | |
|
1507 | 1507 | try: |
|
1508 | 1508 | cmdline_message = logmessage(opts) |
|
1509 | 1509 | if cmdline_message: |
|
1510 | 1510 | # pickup the cmdline msg |
|
1511 | 1511 | message = cmdline_message |
|
1512 | 1512 | elif message: |
|
1513 | 1513 | # pickup the patch msg |
|
1514 | 1514 | message = message.strip() |
|
1515 | 1515 | else: |
|
1516 | 1516 | # launch the editor |
|
1517 | 1517 | message = None |
|
1518 | 1518 | ui.debug(_('message:\n%s\n') % message) |
|
1519 | 1519 | |
|
1520 | 1520 | files = {} |
|
1521 | 1521 | try: |
|
1522 | 1522 | fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root, |
|
1523 | 1523 | files=files) |
|
1524 | 1524 | finally: |
|
1525 | 1525 | files = patch.updatedir(ui, repo, files, wlock=wlock) |
|
1526 | 1526 | repo.commit(files, message, user, date, wlock=wlock, lock=lock) |
|
1527 | 1527 | finally: |
|
1528 | 1528 | os.unlink(tmpname) |
|
1529 | 1529 | |
|
1530 | 1530 | def incoming(ui, repo, source="default", **opts): |
|
1531 | 1531 | """show new changesets found in source |
|
1532 | 1532 | |
|
1533 | 1533 | Show new changesets found in the specified path/URL or the default |
|
1534 | 1534 | pull location. These are the changesets that would be pulled if a pull |
|
1535 | 1535 | was requested. |
|
1536 | 1536 | |
|
1537 | 1537 | For remote repository, using --bundle avoids downloading the changesets |
|
1538 | 1538 | twice if the incoming is followed by a pull. |
|
1539 | 1539 | |
|
1540 | 1540 | See pull for valid source format details. |
|
1541 | 1541 | """ |
|
1542 | 1542 | source = ui.expandpath(source) |
|
1543 | 1543 | setremoteconfig(ui, opts) |
|
1544 | 1544 | |
|
1545 | 1545 | other = hg.repository(ui, source) |
|
1546 | 1546 | incoming = repo.findincoming(other, force=opts["force"]) |
|
1547 | 1547 | if not incoming: |
|
1548 | 1548 | ui.status(_("no changes found\n")) |
|
1549 | 1549 | return |
|
1550 | 1550 | |
|
1551 | 1551 | cleanup = None |
|
1552 | 1552 | try: |
|
1553 | 1553 | fname = opts["bundle"] |
|
1554 | 1554 | if fname or not other.local(): |
|
1555 | 1555 | # create a bundle (uncompressed if other repo is not local) |
|
1556 | 1556 | cg = other.changegroup(incoming, "incoming") |
|
1557 | 1557 | bundletype = other.local() and "HG10BZ" or "HG10UN" |
|
1558 | 1558 | fname = cleanup = changegroup.writebundle(cg, fname, bundletype) |
|
1559 | 1559 | # keep written bundle? |
|
1560 | 1560 | if opts["bundle"]: |
|
1561 | 1561 | cleanup = None |
|
1562 | 1562 | if not other.local(): |
|
1563 | 1563 | # use the created uncompressed bundlerepo |
|
1564 | 1564 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1565 | 1565 | |
|
1566 | 1566 | revs = None |
|
1567 | 1567 | if opts['rev']: |
|
1568 | 1568 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
1569 | 1569 | o = other.changelog.nodesbetween(incoming, revs)[0] |
|
1570 | 1570 | if opts['newest_first']: |
|
1571 | 1571 | o.reverse() |
|
1572 | 1572 | displayer = cmdutil.show_changeset(ui, other, opts) |
|
1573 | 1573 | for n in o: |
|
1574 | 1574 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1575 | 1575 | if opts['no_merges'] and len(parents) == 2: |
|
1576 | 1576 | continue |
|
1577 | 1577 | displayer.show(changenode=n) |
|
1578 | 1578 | finally: |
|
1579 | 1579 | if hasattr(other, 'close'): |
|
1580 | 1580 | other.close() |
|
1581 | 1581 | if cleanup: |
|
1582 | 1582 | os.unlink(cleanup) |
|
1583 | 1583 | |
|
1584 | 1584 | def init(ui, dest=".", **opts): |
|
1585 | 1585 | """create a new repository in the given directory |
|
1586 | 1586 | |
|
1587 | 1587 | Initialize a new repository in the given directory. If the given |
|
1588 | 1588 | directory does not exist, it is created. |
|
1589 | 1589 | |
|
1590 | 1590 | If no directory is given, the current directory is used. |
|
1591 | 1591 | |
|
1592 | 1592 | It is possible to specify an ssh:// URL as the destination. |
|
1593 | 1593 | Look at the help text for the pull command for important details |
|
1594 | 1594 | about ssh:// URLs. |
|
1595 | 1595 | """ |
|
1596 | 1596 | setremoteconfig(ui, opts) |
|
1597 | 1597 | hg.repository(ui, dest, create=1) |
|
1598 | 1598 | |
|
1599 | 1599 | def locate(ui, repo, *pats, **opts): |
|
1600 | 1600 | """locate files matching specific patterns |
|
1601 | 1601 | |
|
1602 | 1602 | Print all files under Mercurial control whose names match the |
|
1603 | 1603 | given patterns. |
|
1604 | 1604 | |
|
1605 | 1605 | This command searches the current directory and its |
|
1606 | 1606 | subdirectories. To search an entire repository, move to the root |
|
1607 | 1607 | of the repository. |
|
1608 | 1608 | |
|
1609 | 1609 | If no patterns are given to match, this command prints all file |
|
1610 | 1610 | names. |
|
1611 | 1611 | |
|
1612 | 1612 | If you want to feed the output of this command into the "xargs" |
|
1613 | 1613 | command, use the "-0" option to both this command and "xargs". |
|
1614 | 1614 | This will avoid the problem of "xargs" treating single filenames |
|
1615 | 1615 | that contain white space as multiple filenames. |
|
1616 | 1616 | """ |
|
1617 | 1617 | end = opts['print0'] and '\0' or '\n' |
|
1618 | 1618 | rev = opts['rev'] |
|
1619 | 1619 | if rev: |
|
1620 | 1620 | node = repo.lookup(rev) |
|
1621 | 1621 | else: |
|
1622 | 1622 | node = None |
|
1623 | 1623 | |
|
1624 | 1624 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, |
|
1625 | 1625 | head='(?:.*/|)'): |
|
1626 | 1626 | if not node and repo.dirstate.state(abs) == '?': |
|
1627 | 1627 | continue |
|
1628 | 1628 | if opts['fullpath']: |
|
1629 | 1629 | ui.write(os.path.join(repo.root, abs), end) |
|
1630 | 1630 | else: |
|
1631 | 1631 | ui.write(((pats and rel) or abs), end) |
|
1632 | 1632 | |
|
1633 | 1633 | def log(ui, repo, *pats, **opts): |
|
1634 | 1634 | """show revision history of entire repository or files |
|
1635 | 1635 | |
|
1636 | 1636 | Print the revision history of the specified files or the entire |
|
1637 | 1637 | project. |
|
1638 | 1638 | |
|
1639 | 1639 | File history is shown without following rename or copy history of |
|
1640 | 1640 | files. Use -f/--follow with a file name to follow history across |
|
1641 | 1641 | renames and copies. --follow without a file name will only show |
|
1642 | 1642 | ancestors or descendants of the starting revision. --follow-first |
|
1643 | 1643 | only follows the first parent of merge revisions. |
|
1644 | 1644 | |
|
1645 | 1645 | If no revision range is specified, the default is tip:0 unless |
|
1646 | 1646 | --follow is set, in which case the working directory parent is |
|
1647 | 1647 | used as the starting revision. |
|
1648 | 1648 | |
|
1649 | 1649 | By default this command outputs: changeset id and hash, tags, |
|
1650 | 1650 | non-trivial parents, user, date and time, and a summary for each |
|
1651 | 1651 | commit. When the -v/--verbose switch is used, the list of changed |
|
1652 | 1652 | files and full commit message is shown. |
|
1653 | 1653 | |
|
1654 | 1654 | NOTE: log -p may generate unexpected diff output for merge |
|
1655 | 1655 | changesets, as it will compare the merge changeset against its |
|
1656 | 1656 | first parent only. Also, the files: list will only reflect files |
|
1657 | 1657 | that are different from BOTH parents. |
|
1658 | 1658 | |
|
1659 | 1659 | """ |
|
1660 | 1660 | |
|
1661 | 1661 | get = util.cachefunc(lambda r: repo.changectx(r).changeset()) |
|
1662 | 1662 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) |
|
1663 | 1663 | |
|
1664 | 1664 | if opts['limit']: |
|
1665 | 1665 | try: |
|
1666 | 1666 | limit = int(opts['limit']) |
|
1667 | 1667 | except ValueError: |
|
1668 | 1668 | raise util.Abort(_('limit must be a positive integer')) |
|
1669 | 1669 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1670 | 1670 | else: |
|
1671 | 1671 | limit = sys.maxint |
|
1672 | 1672 | count = 0 |
|
1673 | 1673 | |
|
1674 | 1674 | if opts['copies'] and opts['rev']: |
|
1675 | 1675 | endrev = max(cmdutil.revrange(repo, opts['rev'])) + 1 |
|
1676 | 1676 | else: |
|
1677 | 1677 | endrev = repo.changelog.count() |
|
1678 | 1678 | rcache = {} |
|
1679 | 1679 | ncache = {} |
|
1680 | 1680 | dcache = [] |
|
1681 | 1681 | def getrenamed(fn, rev, man): |
|
1682 | 1682 | '''looks up all renames for a file (up to endrev) the first |
|
1683 | 1683 | time the file is given. It indexes on the changerev and only |
|
1684 | 1684 | parses the manifest if linkrev != changerev. |
|
1685 | 1685 | Returns rename info for fn at changerev rev.''' |
|
1686 | 1686 | if fn not in rcache: |
|
1687 | 1687 | rcache[fn] = {} |
|
1688 | 1688 | ncache[fn] = {} |
|
1689 | 1689 | fl = repo.file(fn) |
|
1690 | 1690 | for i in xrange(fl.count()): |
|
1691 | 1691 | node = fl.node(i) |
|
1692 | 1692 | lr = fl.linkrev(node) |
|
1693 | 1693 | renamed = fl.renamed(node) |
|
1694 | 1694 | rcache[fn][lr] = renamed |
|
1695 | 1695 | if renamed: |
|
1696 | 1696 | ncache[fn][node] = renamed |
|
1697 | 1697 | if lr >= endrev: |
|
1698 | 1698 | break |
|
1699 | 1699 | if rev in rcache[fn]: |
|
1700 | 1700 | return rcache[fn][rev] |
|
1701 | 1701 | mr = repo.manifest.rev(man) |
|
1702 | 1702 | if repo.manifest.parentrevs(mr) != (mr - 1, nullrev): |
|
1703 | 1703 | return ncache[fn].get(repo.manifest.find(man, fn)[0]) |
|
1704 | 1704 | if not dcache or dcache[0] != man: |
|
1705 | 1705 | dcache[:] = [man, repo.manifest.readdelta(man)] |
|
1706 | 1706 | if fn in dcache[1]: |
|
1707 | 1707 | return ncache[fn].get(dcache[1][fn]) |
|
1708 | 1708 | return None |
|
1709 | 1709 | |
|
1710 | 1710 | df = False |
|
1711 | 1711 | if opts["date"]: |
|
1712 | 1712 | df = util.matchdate(opts["date"]) |
|
1713 | 1713 | |
|
1714 | 1714 | |
|
1715 | 1715 | displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn) |
|
1716 | 1716 | for st, rev, fns in changeiter: |
|
1717 | 1717 | if st == 'add': |
|
1718 | 1718 | changenode = repo.changelog.node(rev) |
|
1719 | 1719 | parents = [p for p in repo.changelog.parentrevs(rev) |
|
1720 | 1720 | if p != nullrev] |
|
1721 | 1721 | if opts['no_merges'] and len(parents) == 2: |
|
1722 | 1722 | continue |
|
1723 | 1723 | if opts['only_merges'] and len(parents) != 2: |
|
1724 | 1724 | continue |
|
1725 | 1725 | |
|
1726 | 1726 | if df: |
|
1727 | 1727 | changes = get(rev) |
|
1728 | 1728 | if not df(changes[2][0]): |
|
1729 | 1729 | continue |
|
1730 | 1730 | |
|
1731 | 1731 | if opts['keyword']: |
|
1732 | 1732 | changes = get(rev) |
|
1733 | 1733 | miss = 0 |
|
1734 | 1734 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1735 | 1735 | if not (k in changes[1].lower() or |
|
1736 | 1736 | k in changes[4].lower() or |
|
1737 | 1737 | k in " ".join(changes[3][:20]).lower()): |
|
1738 | 1738 | miss = 1 |
|
1739 | 1739 | break |
|
1740 | 1740 | if miss: |
|
1741 | 1741 | continue |
|
1742 | 1742 | |
|
1743 | 1743 | copies = [] |
|
1744 | 1744 | if opts.get('copies') and rev: |
|
1745 | 1745 | mf = get(rev)[0] |
|
1746 | 1746 | for fn in get(rev)[3]: |
|
1747 | 1747 | rename = getrenamed(fn, rev, mf) |
|
1748 | 1748 | if rename: |
|
1749 | 1749 | copies.append((fn, rename[0])) |
|
1750 | 1750 | displayer.show(rev, changenode, copies=copies) |
|
1751 | 1751 | elif st == 'iter': |
|
1752 | 1752 | if count == limit: break |
|
1753 | 1753 | if displayer.flush(rev): |
|
1754 | 1754 | count += 1 |
|
1755 | 1755 | |
|
1756 | 1756 | def manifest(ui, repo, rev=None): |
|
1757 | 1757 | """output the current or given revision of the project manifest |
|
1758 | 1758 | |
|
1759 | 1759 | Print a list of version controlled files for the given revision. |
|
1760 | 1760 | If no revision is given, the parent of the working directory is used, |
|
1761 | 1761 | or tip if no revision is checked out. |
|
1762 | 1762 | |
|
1763 | 1763 | The manifest is the list of files being version controlled. If no revision |
|
1764 | 1764 | is given then the first parent of the working directory is used. |
|
1765 | 1765 | |
|
1766 | 1766 | With -v flag, print file permissions. With --debug flag, print |
|
1767 | 1767 | file revision hashes. |
|
1768 | 1768 | """ |
|
1769 | 1769 | |
|
1770 | 1770 | m = repo.changectx(rev).manifest() |
|
1771 | 1771 | files = m.keys() |
|
1772 | 1772 | files.sort() |
|
1773 | 1773 | |
|
1774 | 1774 | for f in files: |
|
1775 | 1775 | if ui.debugflag: |
|
1776 | 1776 | ui.write("%40s " % hex(m[f])) |
|
1777 | 1777 | if ui.verbose: |
|
1778 | 1778 | ui.write("%3s " % (m.execf(f) and "755" or "644")) |
|
1779 | 1779 | ui.write("%s\n" % f) |
|
1780 | 1780 | |
|
1781 | 1781 | def merge(ui, repo, node=None, force=None, branch=None): |
|
1782 | 1782 | """merge working directory with another revision |
|
1783 | 1783 | |
|
1784 | 1784 | Merge the contents of the current working directory and the |
|
1785 | 1785 | requested revision. Files that changed between either parent are |
|
1786 | 1786 | marked as changed for the next commit and a commit must be |
|
1787 | 1787 | performed before any further updates are allowed. |
|
1788 | 1788 | |
|
1789 | 1789 | If no revision is specified, the working directory's parent is a |
|
1790 | 1790 | head revision, and the repository contains exactly one other head, |
|
1791 | 1791 | the other head is merged with by default. Otherwise, an explicit |
|
1792 | 1792 | revision to merge with must be provided. |
|
1793 | 1793 | """ |
|
1794 | 1794 | |
|
1795 | 1795 | if node or branch: |
|
1796 | 1796 | node = _lookup(repo, node, branch) |
|
1797 | 1797 | else: |
|
1798 | 1798 | heads = repo.heads() |
|
1799 | 1799 | if len(heads) > 2: |
|
1800 | 1800 | raise util.Abort(_('repo has %d heads - ' |
|
1801 | 1801 | 'please merge with an explicit rev') % |
|
1802 | 1802 | len(heads)) |
|
1803 | 1803 | if len(heads) == 1: |
|
1804 | 1804 | raise util.Abort(_('there is nothing to merge - ' |
|
1805 | 1805 | 'use "hg update" instead')) |
|
1806 | 1806 | parent = repo.dirstate.parents()[0] |
|
1807 | 1807 | if parent not in heads: |
|
1808 | 1808 | raise util.Abort(_('working dir not at a head rev - ' |
|
1809 | 1809 | 'use "hg update" or merge with an explicit rev')) |
|
1810 | 1810 | node = parent == heads[0] and heads[-1] or heads[0] |
|
1811 | 1811 | return hg.merge(repo, node, force=force) |
|
1812 | 1812 | |
|
1813 | 1813 | def outgoing(ui, repo, dest=None, **opts): |
|
1814 | 1814 | """show changesets not found in destination |
|
1815 | 1815 | |
|
1816 | 1816 | Show changesets not found in the specified destination repository or |
|
1817 | 1817 | the default push location. These are the changesets that would be pushed |
|
1818 | 1818 | if a push was requested. |
|
1819 | 1819 | |
|
1820 | 1820 | See pull for valid destination format details. |
|
1821 | 1821 | """ |
|
1822 | 1822 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1823 | 1823 | setremoteconfig(ui, opts) |
|
1824 | 1824 | revs = None |
|
1825 | 1825 | if opts['rev']: |
|
1826 | 1826 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
1827 | 1827 | |
|
1828 | 1828 | other = hg.repository(ui, dest) |
|
1829 | 1829 | o = repo.findoutgoing(other, force=opts['force']) |
|
1830 | 1830 | if not o: |
|
1831 | 1831 | ui.status(_("no changes found\n")) |
|
1832 | 1832 | return |
|
1833 | 1833 | o = repo.changelog.nodesbetween(o, revs)[0] |
|
1834 | 1834 | if opts['newest_first']: |
|
1835 | 1835 | o.reverse() |
|
1836 | 1836 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
1837 | 1837 | for n in o: |
|
1838 | 1838 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
1839 | 1839 | if opts['no_merges'] and len(parents) == 2: |
|
1840 | 1840 | continue |
|
1841 | 1841 | displayer.show(changenode=n) |
|
1842 | 1842 | |
|
1843 | 1843 | def parents(ui, repo, file_=None, **opts): |
|
1844 | 1844 | """show the parents of the working dir or revision |
|
1845 | 1845 | |
|
1846 | 1846 | Print the working directory's parent revisions. |
|
1847 | 1847 | """ |
|
1848 | 1848 | rev = opts.get('rev') |
|
1849 | 1849 | if rev: |
|
1850 | 1850 | if file_: |
|
1851 | 1851 | ctx = repo.filectx(file_, changeid=rev) |
|
1852 | 1852 | else: |
|
1853 | 1853 | ctx = repo.changectx(rev) |
|
1854 | 1854 | p = [cp.node() for cp in ctx.parents()] |
|
1855 | 1855 | else: |
|
1856 | 1856 | p = repo.dirstate.parents() |
|
1857 | 1857 | |
|
1858 | 1858 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
1859 | 1859 | for n in p: |
|
1860 | 1860 | if n != nullid: |
|
1861 | 1861 | displayer.show(changenode=n) |
|
1862 | 1862 | |
|
1863 | 1863 | def paths(ui, repo, search=None): |
|
1864 | 1864 | """show definition of symbolic path names |
|
1865 | 1865 | |
|
1866 | 1866 | Show definition of symbolic path name NAME. If no name is given, show |
|
1867 | 1867 | definition of available names. |
|
1868 | 1868 | |
|
1869 | 1869 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
1870 | 1870 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
1871 | 1871 | """ |
|
1872 | 1872 | if search: |
|
1873 | 1873 | for name, path in ui.configitems("paths"): |
|
1874 | 1874 | if name == search: |
|
1875 | 1875 | ui.write("%s\n" % path) |
|
1876 | 1876 | return |
|
1877 | 1877 | ui.warn(_("not found!\n")) |
|
1878 | 1878 | return 1 |
|
1879 | 1879 | else: |
|
1880 | 1880 | for name, path in ui.configitems("paths"): |
|
1881 | 1881 | ui.write("%s = %s\n" % (name, path)) |
|
1882 | 1882 | |
|
1883 | 1883 | def postincoming(ui, repo, modheads, optupdate): |
|
1884 | 1884 | if modheads == 0: |
|
1885 | 1885 | return |
|
1886 | 1886 | if optupdate: |
|
1887 | 1887 | if modheads == 1: |
|
1888 | 1888 | return hg.update(repo, repo.changelog.tip()) # update |
|
1889 | 1889 | else: |
|
1890 | 1890 | ui.status(_("not updating, since new heads added\n")) |
|
1891 | 1891 | if modheads > 1: |
|
1892 | 1892 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
1893 | 1893 | else: |
|
1894 | 1894 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
1895 | 1895 | |
|
1896 | 1896 | def pull(ui, repo, source="default", **opts): |
|
1897 | 1897 | """pull changes from the specified source |
|
1898 | 1898 | |
|
1899 | 1899 | Pull changes from a remote repository to a local one. |
|
1900 | 1900 | |
|
1901 | 1901 | This finds all changes from the repository at the specified path |
|
1902 | 1902 | or URL and adds them to the local repository. By default, this |
|
1903 | 1903 | does not update the copy of the project in the working directory. |
|
1904 | 1904 | |
|
1905 | 1905 | Valid URLs are of the form: |
|
1906 | 1906 | |
|
1907 | 1907 | local/filesystem/path (or file://local/filesystem/path) |
|
1908 | 1908 | http://[user@]host[:port]/[path] |
|
1909 | 1909 | https://[user@]host[:port]/[path] |
|
1910 | 1910 | ssh://[user@]host[:port]/[path] |
|
1911 | 1911 | static-http://host[:port]/[path] |
|
1912 | 1912 | |
|
1913 | 1913 | Paths in the local filesystem can either point to Mercurial |
|
1914 | 1914 | repositories or to bundle files (as created by 'hg bundle' or |
|
1915 | 1915 | 'hg incoming --bundle'). The static-http:// protocol, albeit slow, |
|
1916 | 1916 | allows access to a Mercurial repository where you simply use a web |
|
1917 | 1917 | server to publish the .hg directory as static content. |
|
1918 | 1918 | |
|
1919 | 1919 | Some notes about using SSH with Mercurial: |
|
1920 | 1920 | - SSH requires an accessible shell account on the destination machine |
|
1921 | 1921 | and a copy of hg in the remote path or specified with as remotecmd. |
|
1922 | 1922 | - path is relative to the remote user's home directory by default. |
|
1923 | 1923 | Use an extra slash at the start of a path to specify an absolute path: |
|
1924 | 1924 | ssh://example.com//tmp/repository |
|
1925 | 1925 | - Mercurial doesn't use its own compression via SSH; the right thing |
|
1926 | 1926 | to do is to configure it in your ~/.ssh/config, e.g.: |
|
1927 | 1927 | Host *.mylocalnetwork.example.com |
|
1928 | 1928 | Compression no |
|
1929 | 1929 | Host * |
|
1930 | 1930 | Compression yes |
|
1931 | 1931 | Alternatively specify "ssh -C" as your ssh command in your hgrc or |
|
1932 | 1932 | with the --ssh command line option. |
|
1933 | 1933 | """ |
|
1934 | 1934 | source = ui.expandpath(source) |
|
1935 | 1935 | setremoteconfig(ui, opts) |
|
1936 | 1936 | |
|
1937 | 1937 | other = hg.repository(ui, source) |
|
1938 | 1938 | ui.status(_('pulling from %s\n') % (source)) |
|
1939 | 1939 | revs = None |
|
1940 | 1940 | if opts['rev']: |
|
1941 | 1941 | if 'lookup' in other.capabilities: |
|
1942 | 1942 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
1943 | 1943 | else: |
|
1944 | 1944 | error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.") |
|
1945 | 1945 | raise util.Abort(error) |
|
1946 | 1946 | modheads = repo.pull(other, heads=revs, force=opts['force']) |
|
1947 | 1947 | return postincoming(ui, repo, modheads, opts['update']) |
|
1948 | 1948 | |
|
1949 | 1949 | def push(ui, repo, dest=None, **opts): |
|
1950 | 1950 | """push changes to the specified destination |
|
1951 | 1951 | |
|
1952 | 1952 | Push changes from the local repository to the given destination. |
|
1953 | 1953 | |
|
1954 | 1954 | This is the symmetrical operation for pull. It helps to move |
|
1955 | 1955 | changes from the current repository to a different one. If the |
|
1956 | 1956 | destination is local this is identical to a pull in that directory |
|
1957 | 1957 | from the current one. |
|
1958 | 1958 | |
|
1959 | 1959 | By default, push will refuse to run if it detects the result would |
|
1960 | 1960 | increase the number of remote heads. This generally indicates the |
|
1961 | 1961 | the client has forgotten to sync and merge before pushing. |
|
1962 | 1962 | |
|
1963 | 1963 | Valid URLs are of the form: |
|
1964 | 1964 | |
|
1965 | 1965 | local/filesystem/path (or file://local/filesystem/path) |
|
1966 | 1966 | ssh://[user@]host[:port]/[path] |
|
1967 | 1967 | http://[user@]host[:port]/[path] |
|
1968 | 1968 | https://[user@]host[:port]/[path] |
|
1969 | 1969 | |
|
1970 | 1970 | Look at the help text for the pull command for important details |
|
1971 | 1971 | about ssh:// URLs. |
|
1972 | 1972 | |
|
1973 | 1973 | Pushing to http:// and https:// URLs is only possible, if this |
|
1974 | 1974 | feature is explicitly enabled on the remote Mercurial server. |
|
1975 | 1975 | """ |
|
1976 | 1976 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1977 | 1977 | setremoteconfig(ui, opts) |
|
1978 | 1978 | |
|
1979 | 1979 | other = hg.repository(ui, dest) |
|
1980 | 1980 | ui.status('pushing to %s\n' % (dest)) |
|
1981 | 1981 | revs = None |
|
1982 | 1982 | if opts['rev']: |
|
1983 | 1983 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
1984 | 1984 | r = repo.push(other, opts['force'], revs=revs) |
|
1985 | 1985 | return r == 0 |
|
1986 | 1986 | |
|
1987 | 1987 | def rawcommit(ui, repo, *pats, **opts): |
|
1988 | 1988 | """raw commit interface (DEPRECATED) |
|
1989 | 1989 | |
|
1990 | 1990 | (DEPRECATED) |
|
1991 | 1991 | Lowlevel commit, for use in helper scripts. |
|
1992 | 1992 | |
|
1993 | 1993 | This command is not intended to be used by normal users, as it is |
|
1994 | 1994 | primarily useful for importing from other SCMs. |
|
1995 | 1995 | |
|
1996 | 1996 | This command is now deprecated and will be removed in a future |
|
1997 | 1997 | release, please use debugsetparents and commit instead. |
|
1998 | 1998 | """ |
|
1999 | 1999 | |
|
2000 | 2000 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2001 | 2001 | |
|
2002 | 2002 | message = logmessage(opts) |
|
2003 | 2003 | |
|
2004 | 2004 | files, match, anypats = cmdutil.matchpats(repo, pats, opts) |
|
2005 | 2005 | if opts['files']: |
|
2006 | 2006 | files += open(opts['files']).read().splitlines() |
|
2007 | 2007 | |
|
2008 | 2008 | parents = [repo.lookup(p) for p in opts['parent']] |
|
2009 | 2009 | |
|
2010 | 2010 | try: |
|
2011 | 2011 | repo.rawcommit(files, message, opts['user'], opts['date'], *parents) |
|
2012 | 2012 | except ValueError, inst: |
|
2013 | 2013 | raise util.Abort(str(inst)) |
|
2014 | 2014 | |
|
2015 | 2015 | def recover(ui, repo): |
|
2016 | 2016 | """roll back an interrupted transaction |
|
2017 | 2017 | |
|
2018 | 2018 | Recover from an interrupted commit or pull. |
|
2019 | 2019 | |
|
2020 | 2020 | This command tries to fix the repository status after an interrupted |
|
2021 | 2021 | operation. It should only be necessary when Mercurial suggests it. |
|
2022 | 2022 | """ |
|
2023 | 2023 | if repo.recover(): |
|
2024 | 2024 | return hg.verify(repo) |
|
2025 | 2025 | return 1 |
|
2026 | 2026 | |
|
2027 | 2027 | def remove(ui, repo, *pats, **opts): |
|
2028 | 2028 | """remove the specified files on the next commit |
|
2029 | 2029 | |
|
2030 | 2030 | Schedule the indicated files for removal from the repository. |
|
2031 | 2031 | |
|
2032 | 2032 | This only removes files from the current branch, not from the |
|
2033 | 2033 | entire project history. If the files still exist in the working |
|
2034 | 2034 | directory, they will be deleted from it. If invoked with --after, |
|
2035 | 2035 | files that have been manually deleted are marked as removed. |
|
2036 | 2036 | |
|
2037 | 2037 | This command schedules the files to be removed at the next commit. |
|
2038 | 2038 | To undo a remove before that, see hg revert. |
|
2039 | 2039 | |
|
2040 | 2040 | Modified files and added files are not removed by default. To |
|
2041 | 2041 | remove them, use the -f/--force option. |
|
2042 | 2042 | """ |
|
2043 | 2043 | names = [] |
|
2044 | 2044 | if not opts['after'] and not pats: |
|
2045 | 2045 | raise util.Abort(_('no files specified')) |
|
2046 | 2046 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
2047 | 2047 | exact = dict.fromkeys(files) |
|
2048 | 2048 | mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5] |
|
2049 | 2049 | modified, added, removed, deleted, unknown = mardu |
|
2050 | 2050 | remove, forget = [], [] |
|
2051 | 2051 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): |
|
2052 | 2052 | reason = None |
|
2053 | 2053 | if abs not in deleted and opts['after']: |
|
2054 | 2054 | reason = _('is still present') |
|
2055 | 2055 | elif abs in modified and not opts['force']: |
|
2056 | 2056 | reason = _('is modified (use -f to force removal)') |
|
2057 | 2057 | elif abs in added: |
|
2058 | 2058 | if opts['force']: |
|
2059 | 2059 | forget.append(abs) |
|
2060 | 2060 | continue |
|
2061 | 2061 | reason = _('has been marked for add (use -f to force removal)') |
|
2062 | 2062 | elif abs in unknown: |
|
2063 | 2063 | reason = _('is not managed') |
|
2064 | 2064 | elif abs in removed: |
|
2065 | 2065 | continue |
|
2066 | 2066 | if reason: |
|
2067 | 2067 | if exact: |
|
2068 | 2068 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2069 | 2069 | else: |
|
2070 | 2070 | if ui.verbose or not exact: |
|
2071 | 2071 | ui.status(_('removing %s\n') % rel) |
|
2072 | 2072 | remove.append(abs) |
|
2073 | 2073 | repo.forget(forget) |
|
2074 | 2074 | repo.remove(remove, unlink=not opts['after']) |
|
2075 | 2075 | |
|
2076 | 2076 | def rename(ui, repo, *pats, **opts): |
|
2077 | 2077 | """rename files; equivalent of copy + remove |
|
2078 | 2078 | |
|
2079 | 2079 | Mark dest as copies of sources; mark sources for deletion. If |
|
2080 | 2080 | dest is a directory, copies are put in that directory. If dest is |
|
2081 | 2081 | a file, there can only be one source. |
|
2082 | 2082 | |
|
2083 | 2083 | By default, this command copies the contents of files as they |
|
2084 | 2084 | stand in the working directory. If invoked with --after, the |
|
2085 | 2085 | operation is recorded, but no copying is performed. |
|
2086 | 2086 | |
|
2087 | 2087 | This command takes effect in the next commit. To undo a rename |
|
2088 | 2088 | before that, see hg revert. |
|
2089 | 2089 | """ |
|
2090 | 2090 | wlock = repo.wlock(0) |
|
2091 | 2091 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2092 | 2092 | names = [] |
|
2093 | 2093 | for abs, rel, exact in copied: |
|
2094 | 2094 | if ui.verbose or not exact: |
|
2095 | 2095 | ui.status(_('removing %s\n') % rel) |
|
2096 | 2096 | names.append(abs) |
|
2097 | 2097 | if not opts.get('dry_run'): |
|
2098 | 2098 | repo.remove(names, True, wlock) |
|
2099 | 2099 | return errs |
|
2100 | 2100 | |
|
2101 | 2101 | def revert(ui, repo, *pats, **opts): |
|
2102 | 2102 | """revert files or dirs to their states as of some revision |
|
2103 | 2103 | |
|
2104 | 2104 | With no revision specified, revert the named files or directories |
|
2105 | 2105 | to the contents they had in the parent of the working directory. |
|
2106 | 2106 | This restores the contents of the affected files to an unmodified |
|
2107 | 2107 | state and unschedules adds, removes, copies, and renames. If the |
|
2108 | 2108 | working directory has two parents, you must explicitly specify the |
|
2109 | 2109 | revision to revert to. |
|
2110 | 2110 | |
|
2111 | 2111 | Modified files are saved with a .orig suffix before reverting. |
|
2112 | 2112 | To disable these backups, use --no-backup. |
|
2113 | 2113 | |
|
2114 | 2114 | Using the -r option, revert the given files or directories to their |
|
2115 | 2115 | contents as of a specific revision. This can be helpful to "roll |
|
2116 | 2116 | back" some or all of a change that should not have been committed. |
|
2117 | 2117 | |
|
2118 | 2118 | Revert modifies the working directory. It does not commit any |
|
2119 | 2119 | changes, or change the parent of the working directory. If you |
|
2120 | 2120 | revert to a revision other than the parent of the working |
|
2121 | 2121 | directory, the reverted files will thus appear modified |
|
2122 | 2122 | afterwards. |
|
2123 | 2123 | |
|
2124 | 2124 | If a file has been deleted, it is recreated. If the executable |
|
2125 | 2125 | mode of a file was changed, it is reset. |
|
2126 | 2126 | |
|
2127 | 2127 | If names are given, all files matching the names are reverted. |
|
2128 | 2128 | |
|
2129 | 2129 | If no arguments are given, no files are reverted. |
|
2130 | 2130 | """ |
|
2131 | 2131 | |
|
2132 | 2132 | if opts["date"]: |
|
2133 | 2133 | if opts["rev"]: |
|
2134 | 2134 | raise util.Abort(_("you can't specify a revision and a date")) |
|
2135 | 2135 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
2136 | 2136 | |
|
2137 | 2137 | if not pats and not opts['all']: |
|
2138 | 2138 | raise util.Abort(_('no files or directories specified; ' |
|
2139 | 2139 | 'use --all to revert the whole repo')) |
|
2140 | 2140 | |
|
2141 | 2141 | parent, p2 = repo.dirstate.parents() |
|
2142 | 2142 | if not opts['rev'] and p2 != nullid: |
|
2143 | 2143 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
2144 | 2144 | 'specific revision')) |
|
2145 | 2145 | node = repo.changectx(opts['rev']).node() |
|
2146 | 2146 | mf = repo.manifest.read(repo.changelog.read(node)[0]) |
|
2147 | 2147 | if node == parent: |
|
2148 | 2148 | pmf = mf |
|
2149 | 2149 | else: |
|
2150 | 2150 | pmf = None |
|
2151 | 2151 | |
|
2152 | 2152 | wlock = repo.wlock() |
|
2153 | 2153 | |
|
2154 | 2154 | # need all matching names in dirstate and manifest of target rev, |
|
2155 | 2155 | # so have to walk both. do not print errors if files exist in one |
|
2156 | 2156 | # but not other. |
|
2157 | 2157 | |
|
2158 | 2158 | names = {} |
|
2159 | 2159 | target_only = {} |
|
2160 | 2160 | |
|
2161 | 2161 | # walk dirstate. |
|
2162 | 2162 | |
|
2163 | 2163 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, |
|
2164 | 2164 | badmatch=mf.has_key): |
|
2165 | 2165 | names[abs] = (rel, exact) |
|
2166 | 2166 | if src == 'b': |
|
2167 | 2167 | target_only[abs] = True |
|
2168 | 2168 | |
|
2169 | 2169 | # walk target manifest. |
|
2170 | 2170 | |
|
2171 | 2171 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, |
|
2172 | 2172 | badmatch=names.has_key): |
|
2173 | 2173 | if abs in names: continue |
|
2174 | 2174 | names[abs] = (rel, exact) |
|
2175 | 2175 | target_only[abs] = True |
|
2176 | 2176 | |
|
2177 | 2177 | changes = repo.status(match=names.has_key, wlock=wlock)[:5] |
|
2178 | 2178 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
|
2179 | 2179 | |
|
2180 | 2180 | revert = ([], _('reverting %s\n')) |
|
2181 | 2181 | add = ([], _('adding %s\n')) |
|
2182 | 2182 | remove = ([], _('removing %s\n')) |
|
2183 | 2183 | forget = ([], _('forgetting %s\n')) |
|
2184 | 2184 | undelete = ([], _('undeleting %s\n')) |
|
2185 | 2185 | update = {} |
|
2186 | 2186 | |
|
2187 | 2187 | disptable = ( |
|
2188 | 2188 | # dispatch table: |
|
2189 | 2189 | # file state |
|
2190 | 2190 | # action if in target manifest |
|
2191 | 2191 | # action if not in target manifest |
|
2192 | 2192 | # make backup if in target manifest |
|
2193 | 2193 | # make backup if not in target manifest |
|
2194 | 2194 | (modified, revert, remove, True, True), |
|
2195 | 2195 | (added, revert, forget, True, False), |
|
2196 | 2196 | (removed, undelete, None, False, False), |
|
2197 | 2197 | (deleted, revert, remove, False, False), |
|
2198 | 2198 | (unknown, add, None, True, False), |
|
2199 | 2199 | (target_only, add, None, False, False), |
|
2200 | 2200 | ) |
|
2201 | 2201 | |
|
2202 | 2202 | entries = names.items() |
|
2203 | 2203 | entries.sort() |
|
2204 | 2204 | |
|
2205 | 2205 | for abs, (rel, exact) in entries: |
|
2206 | 2206 | mfentry = mf.get(abs) |
|
2207 | 2207 | def handle(xlist, dobackup): |
|
2208 | 2208 | xlist[0].append(abs) |
|
2209 | 2209 | update[abs] = 1 |
|
2210 | 2210 | if dobackup and not opts['no_backup'] and os.path.exists(rel): |
|
2211 | 2211 | bakname = "%s.orig" % rel |
|
2212 | 2212 | ui.note(_('saving current version of %s as %s\n') % |
|
2213 | 2213 | (rel, bakname)) |
|
2214 | 2214 | if not opts.get('dry_run'): |
|
2215 | 2215 | util.copyfile(rel, bakname) |
|
2216 | 2216 | if ui.verbose or not exact: |
|
2217 | 2217 | ui.status(xlist[1] % rel) |
|
2218 | 2218 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2219 | 2219 | if abs not in table: continue |
|
2220 | 2220 | # file has changed in dirstate |
|
2221 | 2221 | if mfentry: |
|
2222 | 2222 | handle(hitlist, backuphit) |
|
2223 | 2223 | elif misslist is not None: |
|
2224 | 2224 | handle(misslist, backupmiss) |
|
2225 | 2225 | else: |
|
2226 | 2226 | if exact: ui.warn(_('file not managed: %s\n') % rel) |
|
2227 | 2227 | break |
|
2228 | 2228 | else: |
|
2229 | 2229 | # file has not changed in dirstate |
|
2230 | 2230 | if node == parent: |
|
2231 | 2231 | if exact: ui.warn(_('no changes needed to %s\n') % rel) |
|
2232 | 2232 | continue |
|
2233 | 2233 | if pmf is None: |
|
2234 | 2234 | # only need parent manifest in this unlikely case, |
|
2235 | 2235 | # so do not read by default |
|
2236 | 2236 | pmf = repo.manifest.read(repo.changelog.read(parent)[0]) |
|
2237 | 2237 | if abs in pmf: |
|
2238 | 2238 | if mfentry: |
|
2239 | 2239 | # if version of file is same in parent and target |
|
2240 | 2240 | # manifests, do nothing |
|
2241 | 2241 | if pmf[abs] != mfentry: |
|
2242 | 2242 | handle(revert, False) |
|
2243 | 2243 | else: |
|
2244 | 2244 | handle(remove, False) |
|
2245 | 2245 | |
|
2246 | 2246 | if not opts.get('dry_run'): |
|
2247 | 2247 | repo.dirstate.forget(forget[0]) |
|
2248 | 2248 | r = hg.revert(repo, node, update.has_key, wlock) |
|
2249 | 2249 | repo.dirstate.update(add[0], 'a') |
|
2250 | 2250 | repo.dirstate.update(undelete[0], 'n') |
|
2251 | 2251 | repo.dirstate.update(remove[0], 'r') |
|
2252 | 2252 | return r |
|
2253 | 2253 | |
|
2254 | 2254 | def rollback(ui, repo): |
|
2255 | 2255 | """roll back the last transaction in this repository |
|
2256 | 2256 | |
|
2257 | 2257 | Roll back the last transaction in this repository, restoring the |
|
2258 | 2258 | project to its state prior to the transaction. |
|
2259 | 2259 | |
|
2260 | 2260 | Transactions are used to encapsulate the effects of all commands |
|
2261 | 2261 | that create new changesets or propagate existing changesets into a |
|
2262 | 2262 | repository. For example, the following commands are transactional, |
|
2263 | 2263 | and their effects can be rolled back: |
|
2264 | 2264 | |
|
2265 | 2265 | commit |
|
2266 | 2266 | import |
|
2267 | 2267 | pull |
|
2268 | 2268 | push (with this repository as destination) |
|
2269 | 2269 | unbundle |
|
2270 | 2270 | |
|
2271 | 2271 | This command should be used with care. There is only one level of |
|
2272 | 2272 | rollback, and there is no way to undo a rollback. |
|
2273 | 2273 | |
|
2274 | 2274 | This command is not intended for use on public repositories. Once |
|
2275 | 2275 | changes are visible for pull by other users, rolling a transaction |
|
2276 | 2276 | back locally is ineffective (someone else may already have pulled |
|
2277 | 2277 | the changes). Furthermore, a race is possible with readers of the |
|
2278 | 2278 | repository; for example an in-progress pull from the repository |
|
2279 | 2279 | may fail if a rollback is performed. |
|
2280 | 2280 | """ |
|
2281 | 2281 | repo.rollback() |
|
2282 | 2282 | |
|
2283 | 2283 | def root(ui, repo): |
|
2284 | 2284 | """print the root (top) of the current working dir |
|
2285 | 2285 | |
|
2286 | 2286 | Print the root directory of the current repository. |
|
2287 | 2287 | """ |
|
2288 | 2288 | ui.write(repo.root + "\n") |
|
2289 | 2289 | |
|
2290 | 2290 | def serve(ui, repo, **opts): |
|
2291 | 2291 | """export the repository via HTTP |
|
2292 | 2292 | |
|
2293 | 2293 | Start a local HTTP repository browser and pull server. |
|
2294 | 2294 | |
|
2295 | 2295 | By default, the server logs accesses to stdout and errors to |
|
2296 | 2296 | stderr. Use the "-A" and "-E" options to log to files. |
|
2297 | 2297 | """ |
|
2298 | 2298 | |
|
2299 | 2299 | if opts["stdio"]: |
|
2300 | 2300 | if repo is None: |
|
2301 | 2301 | raise hg.RepoError(_("There is no Mercurial repository here" |
|
2302 | 2302 | " (.hg not found)")) |
|
2303 | 2303 | s = sshserver.sshserver(ui, repo) |
|
2304 | 2304 | s.serve_forever() |
|
2305 | 2305 | |
|
2306 | 2306 | parentui = ui.parentui or ui |
|
2307 | 2307 | optlist = ("name templates style address port ipv6" |
|
2308 | 2308 | " accesslog errorlog webdir_conf") |
|
2309 | 2309 | for o in optlist.split(): |
|
2310 | 2310 | if opts[o]: |
|
2311 | 2311 | parentui.setconfig("web", o, str(opts[o])) |
|
2312 | 2312 | |
|
2313 | 2313 | if repo is None and not ui.config("web", "webdir_conf"): |
|
2314 | 2314 | raise hg.RepoError(_("There is no Mercurial repository here" |
|
2315 | 2315 | " (.hg not found)")) |
|
2316 | 2316 | |
|
2317 | 2317 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2318 | 2318 | rfd, wfd = os.pipe() |
|
2319 | 2319 | args = sys.argv[:] |
|
2320 | 2320 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2321 | 2321 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2322 | 2322 | args[0], args) |
|
2323 | 2323 | os.close(wfd) |
|
2324 | 2324 | os.read(rfd, 1) |
|
2325 | 2325 | os._exit(0) |
|
2326 | 2326 | |
|
2327 | 2327 | httpd = hgweb.server.create_server(parentui, repo) |
|
2328 | 2328 | |
|
2329 | 2329 | if ui.verbose: |
|
2330 | 2330 | if httpd.port != 80: |
|
2331 | 2331 | ui.status(_('listening at http://%s:%d/\n') % |
|
2332 | 2332 | (httpd.addr, httpd.port)) |
|
2333 | 2333 | else: |
|
2334 | 2334 | ui.status(_('listening at http://%s/\n') % httpd.addr) |
|
2335 | 2335 | |
|
2336 | 2336 | if opts['pid_file']: |
|
2337 | 2337 | fp = open(opts['pid_file'], 'w') |
|
2338 | 2338 | fp.write(str(os.getpid()) + '\n') |
|
2339 | 2339 | fp.close() |
|
2340 | 2340 | |
|
2341 | 2341 | if opts['daemon_pipefds']: |
|
2342 | 2342 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2343 | 2343 | os.close(rfd) |
|
2344 | 2344 | os.write(wfd, 'y') |
|
2345 | 2345 | os.close(wfd) |
|
2346 | 2346 | sys.stdout.flush() |
|
2347 | 2347 | sys.stderr.flush() |
|
2348 | 2348 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2349 | 2349 | if fd != 0: os.dup2(fd, 0) |
|
2350 | 2350 | if fd != 1: os.dup2(fd, 1) |
|
2351 | 2351 | if fd != 2: os.dup2(fd, 2) |
|
2352 | 2352 | if fd not in (0, 1, 2): os.close(fd) |
|
2353 | 2353 | |
|
2354 | 2354 | httpd.serve_forever() |
|
2355 | 2355 | |
|
2356 | 2356 | def status(ui, repo, *pats, **opts): |
|
2357 | 2357 | """show changed files in the working directory |
|
2358 | 2358 | |
|
2359 | 2359 | Show status of files in the repository. If names are given, only |
|
2360 | 2360 | files that match are shown. Files that are clean or ignored, are |
|
2361 | 2361 | not listed unless -c (clean), -i (ignored) or -A is given. |
|
2362 | 2362 | |
|
2363 | 2363 | NOTE: status may appear to disagree with diff if permissions have |
|
2364 | 2364 | changed or a merge has occurred. The standard diff format does not |
|
2365 | 2365 | report permission changes and diff only reports changes relative |
|
2366 | 2366 | to one merge parent. |
|
2367 | 2367 | |
|
2368 | 2368 | If one revision is given, it is used as the base revision. |
|
2369 | 2369 | If two revisions are given, the difference between them is shown. |
|
2370 | 2370 | |
|
2371 | 2371 | The codes used to show the status of files are: |
|
2372 | 2372 | M = modified |
|
2373 | 2373 | A = added |
|
2374 | 2374 | R = removed |
|
2375 | 2375 | C = clean |
|
2376 | 2376 | ! = deleted, but still tracked |
|
2377 | 2377 | ? = not tracked |
|
2378 | 2378 | I = ignored (not shown by default) |
|
2379 | 2379 | = the previous added file was copied from here |
|
2380 | 2380 | """ |
|
2381 | 2381 | |
|
2382 | 2382 | all = opts['all'] |
|
2383 | 2383 | node1, node2 = cmdutil.revpair(repo, opts.get('rev')) |
|
2384 | 2384 | |
|
2385 | 2385 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
2386 | 2386 | cwd = (pats and repo.getcwd()) or '' |
|
2387 | 2387 | modified, added, removed, deleted, unknown, ignored, clean = [ |
|
2388 | 2388 | n for n in repo.status(node1=node1, node2=node2, files=files, |
|
2389 | 2389 | match=matchfn, |
|
2390 | 2390 | list_ignored=all or opts['ignored'], |
|
2391 | 2391 | list_clean=all or opts['clean'])] |
|
2392 | 2392 | |
|
2393 | 2393 | changetypes = (('modified', 'M', modified), |
|
2394 | 2394 | ('added', 'A', added), |
|
2395 | 2395 | ('removed', 'R', removed), |
|
2396 | 2396 | ('deleted', '!', deleted), |
|
2397 | 2397 | ('unknown', '?', unknown), |
|
2398 | 2398 | ('ignored', 'I', ignored)) |
|
2399 | 2399 | |
|
2400 | 2400 | explicit_changetypes = changetypes + (('clean', 'C', clean),) |
|
2401 | 2401 | |
|
2402 | 2402 | end = opts['print0'] and '\0' or '\n' |
|
2403 | 2403 | |
|
2404 | 2404 | for opt, char, changes in ([ct for ct in explicit_changetypes |
|
2405 | 2405 | if all or opts[ct[0]]] |
|
2406 | 2406 | or changetypes): |
|
2407 | 2407 | if opts['no_status']: |
|
2408 | 2408 | format = "%%s%s" % end |
|
2409 | 2409 | else: |
|
2410 | 2410 | format = "%s %%s%s" % (char, end) |
|
2411 | 2411 | |
|
2412 | 2412 | for f in changes: |
|
2413 | 2413 | ui.write(format % util.pathto(cwd, f)) |
|
2414 | 2414 | if ((all or opts.get('copies')) and not opts.get('no_status')): |
|
2415 | 2415 | copied = repo.dirstate.copied(f) |
|
2416 | 2416 | if copied: |
|
2417 | 2417 | ui.write(' %s%s' % (util.pathto(cwd, copied), end)) |
|
2418 | 2418 | |
|
2419 | 2419 | def tag(ui, repo, name, rev_=None, **opts): |
|
2420 | 2420 | """add a tag for the current or given revision |
|
2421 | 2421 | |
|
2422 | 2422 | Name a particular revision using <name>. |
|
2423 | 2423 | |
|
2424 | 2424 | Tags are used to name particular revisions of the repository and are |
|
2425 | 2425 | very useful to compare different revision, to go back to significant |
|
2426 | 2426 | earlier versions or to mark branch points as releases, etc. |
|
2427 | 2427 | |
|
2428 | 2428 | If no revision is given, the parent of the working directory is used, |
|
2429 | 2429 | or tip if no revision is checked out. |
|
2430 | 2430 | |
|
2431 | 2431 | To facilitate version control, distribution, and merging of tags, |
|
2432 | 2432 | they are stored as a file named ".hgtags" which is managed |
|
2433 | 2433 | similarly to other project files and can be hand-edited if |
|
2434 | 2434 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2435 | 2435 | shared among repositories). |
|
2436 | 2436 | """ |
|
2437 | 2437 | if name in ['tip', '.', 'null']: |
|
2438 | 2438 | raise util.Abort(_("the name '%s' is reserved") % name) |
|
2439 | 2439 | if rev_ is not None: |
|
2440 | 2440 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2441 | 2441 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2442 | 2442 | if opts['rev']: |
|
2443 | 2443 | raise util.Abort(_("use only one form to specify the revision")) |
|
2444 | 2444 | if opts['rev']: |
|
2445 | 2445 | rev_ = opts['rev'] |
|
2446 | 2446 | if not rev_ and repo.dirstate.parents()[1] != nullid: |
|
2447 | 2447 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
2448 | 2448 | 'specific revision')) |
|
2449 | 2449 | r = repo.changectx(rev_).node() |
|
2450 | 2450 | |
|
2451 | 2451 | message = opts['message'] |
|
2452 | 2452 | if not message: |
|
2453 | 2453 | message = _('Added tag %s for changeset %s') % (name, short(r)) |
|
2454 | 2454 | |
|
2455 | 2455 | repo.tag(name, r, message, opts['local'], opts['user'], opts['date']) |
|
2456 | 2456 | |
|
2457 | 2457 | def tags(ui, repo): |
|
2458 | 2458 | """list repository tags |
|
2459 | 2459 | |
|
2460 | 2460 | List the repository tags. |
|
2461 | 2461 | |
|
2462 | 2462 | This lists both regular and local tags. |
|
2463 | 2463 | """ |
|
2464 | 2464 | |
|
2465 | 2465 | l = repo.tagslist() |
|
2466 | 2466 | l.reverse() |
|
2467 | 2467 | hexfunc = ui.debugflag and hex or short |
|
2468 | 2468 | for t, n in l: |
|
2469 | 2469 | try: |
|
2470 | 2470 | r = "%5d:%s" % (repo.changelog.rev(n), hexfunc(n)) |
|
2471 | 2471 | except KeyError: |
|
2472 | 2472 | r = " ?:?" |
|
2473 | 2473 | if ui.quiet: |
|
2474 | 2474 | ui.write("%s\n" % t) |
|
2475 | 2475 | else: |
|
2476 | 2476 | spaces = " " * (30 - util.locallen(t)) |
|
2477 | 2477 | ui.write("%s%s %s\n" % (t, spaces, r)) |
|
2478 | 2478 | |
|
2479 | 2479 | def tip(ui, repo, **opts): |
|
2480 | 2480 | """show the tip revision |
|
2481 | 2481 | |
|
2482 | 2482 | Show the tip revision. |
|
2483 | 2483 | """ |
|
2484 | 2484 | cmdutil.show_changeset(ui, repo, opts).show(nullrev+repo.changelog.count()) |
|
2485 | 2485 | |
|
2486 | 2486 | def unbundle(ui, repo, fname, **opts): |
|
2487 | 2487 | """apply a changegroup file |
|
2488 | 2488 | |
|
2489 | 2489 | Apply a compressed changegroup file generated by the bundle |
|
2490 | 2490 | command. |
|
2491 | 2491 | """ |
|
2492 | 2492 | if os.path.exists(fname): |
|
2493 | 2493 | f = open(fname, "rb") |
|
2494 | 2494 | else: |
|
2495 | 2495 | f = urllib.urlopen(fname) |
|
2496 | 2496 | gen = changegroup.readbundle(f, fname) |
|
2497 | 2497 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) |
|
2498 | 2498 | return postincoming(ui, repo, modheads, opts['update']) |
|
2499 | 2499 | |
|
2500 | 2500 | def update(ui, repo, node=None, clean=False, branch=None, date=None): |
|
2501 | 2501 | """update working directory |
|
2502 | 2502 | |
|
2503 | 2503 | Update the working directory to the specified revision. |
|
2504 | 2504 | |
|
2505 | 2505 | If there are no outstanding changes in the working directory and |
|
2506 | 2506 | there is a linear relationship between the current version and the |
|
2507 | 2507 | requested version, the result is the requested version. |
|
2508 | 2508 | |
|
2509 | 2509 | To merge the working directory with another revision, use the |
|
2510 | 2510 | merge command. |
|
2511 | 2511 | |
|
2512 | 2512 | By default, update will refuse to run if doing so would require |
|
2513 | 2513 | discarding local changes. |
|
2514 | 2514 | """ |
|
2515 | 2515 | if date: |
|
2516 | 2516 | if node: |
|
2517 | 2517 | raise util.Abort(_("you can't specify a revision and a date")) |
|
2518 | 2518 | node = cmdutil.finddate(ui, repo, date) |
|
2519 | 2519 | |
|
2520 | 2520 | node = _lookup(repo, node, branch) |
|
2521 | 2521 | if clean: |
|
2522 | 2522 | return hg.clean(repo, node) |
|
2523 | 2523 | else: |
|
2524 | 2524 | return hg.update(repo, node) |
|
2525 | 2525 | |
|
2526 | 2526 | def _lookup(repo, node, branch=None): |
|
2527 | 2527 | if branch: |
|
2528 | 2528 | repo.ui.warn(_("the --branch option is deprecated, " |
|
2529 | 2529 | "please use 'hg branch' instead\n")) |
|
2530 | 2530 | br = repo.branchlookup(branch=branch) |
|
2531 | 2531 | found = [] |
|
2532 | 2532 | for x in br: |
|
2533 | 2533 | if branch in br[x]: |
|
2534 | 2534 | found.append(x) |
|
2535 | 2535 | if len(found) > 1: |
|
2536 | 2536 | repo.ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2537 | 2537 | for x in found: |
|
2538 | 2538 | cmdutil.show_changeset(ui, repo, {}).show(changenode=x) |
|
2539 | 2539 | raise util.Abort("") |
|
2540 | 2540 | if len(found) == 1: |
|
2541 | 2541 | node = found[0] |
|
2542 | 2542 | repo.ui.warn(_("Using head %s for branch %s\n") |
|
2543 | 2543 | % (short(node), branch)) |
|
2544 | 2544 | else: |
|
2545 | 2545 | raise util.Abort(_("branch %s not found") % branch) |
|
2546 | 2546 | else: |
|
2547 | 2547 | if node: |
|
2548 | 2548 | node = repo.lookup(node) |
|
2549 | 2549 | else: |
|
2550 | 2550 | wc = repo.workingctx() |
|
2551 | 2551 | node = repo.branchtags()[wc.branch()] |
|
2552 | 2552 | return node |
|
2553 | 2553 | |
|
2554 | 2554 | def verify(ui, repo): |
|
2555 | 2555 | """verify the integrity of the repository |
|
2556 | 2556 | |
|
2557 | 2557 | Verify the integrity of the current repository. |
|
2558 | 2558 | |
|
2559 | 2559 | This will perform an extensive check of the repository's |
|
2560 | 2560 | integrity, validating the hashes and checksums of each entry in |
|
2561 | 2561 | the changelog, manifest, and tracked files, as well as the |
|
2562 | 2562 | integrity of their crosslinks and indices. |
|
2563 | 2563 | """ |
|
2564 | 2564 | return hg.verify(repo) |
|
2565 | 2565 | |
|
2566 | 2566 | def version_(ui): |
|
2567 | 2567 | """output version and copyright information""" |
|
2568 | 2568 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
2569 | 2569 | % version.get_version()) |
|
2570 | 2570 | ui.status(_( |
|
2571 | 2571 | "\nCopyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>\n" |
|
2572 | 2572 | "This is free software; see the source for copying conditions. " |
|
2573 | 2573 | "There is NO\nwarranty; " |
|
2574 | 2574 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
2575 | 2575 | )) |
|
2576 | 2576 | |
|
2577 | 2577 | # Command options and aliases are listed here, alphabetically |
|
2578 | 2578 | |
|
2579 | 2579 | globalopts = [ |
|
2580 | 2580 | ('R', 'repository', '', |
|
2581 | 2581 | _('repository root directory or symbolic path name')), |
|
2582 | 2582 | ('', 'cwd', '', _('change working directory')), |
|
2583 | 2583 | ('y', 'noninteractive', None, |
|
2584 | 2584 | _('do not prompt, assume \'yes\' for any required answers')), |
|
2585 | 2585 | ('q', 'quiet', None, _('suppress output')), |
|
2586 | 2586 | ('v', 'verbose', None, _('enable additional output')), |
|
2587 | 2587 | ('', 'config', [], _('set/override config option')), |
|
2588 | 2588 | ('', 'debug', None, _('enable debugging output')), |
|
2589 | 2589 | ('', 'debugger', None, _('start debugger')), |
|
2590 | 2590 | ('', 'encoding', util._encoding, _('set the charset encoding')), |
|
2591 | 2591 | ('', 'encodingmode', util._encodingmode, _('set the charset encoding mode')), |
|
2592 | 2592 | ('', 'lsprof', None, _('print improved command execution profile')), |
|
2593 | 2593 | ('', 'traceback', None, _('print traceback on exception')), |
|
2594 | 2594 | ('', 'time', None, _('time how long the command takes')), |
|
2595 | 2595 | ('', 'profile', None, _('print command execution profile')), |
|
2596 | 2596 | ('', 'version', None, _('output version information and exit')), |
|
2597 | 2597 | ('h', 'help', None, _('display help and exit')), |
|
2598 | 2598 | ] |
|
2599 | 2599 | |
|
2600 | 2600 | dryrunopts = [('n', 'dry-run', None, |
|
2601 | 2601 | _('do not perform actions, just print output'))] |
|
2602 | 2602 | |
|
2603 | 2603 | remoteopts = [ |
|
2604 | 2604 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2605 | 2605 | ('', 'remotecmd', '', _('specify hg command to run on the remote side')), |
|
2606 | 2606 | ] |
|
2607 | 2607 | |
|
2608 | 2608 | walkopts = [ |
|
2609 | 2609 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2610 | 2610 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
2611 | 2611 | ] |
|
2612 | 2612 | |
|
2613 | 2613 | commitopts = [ |
|
2614 | 2614 | ('m', 'message', '', _('use <text> as commit message')), |
|
2615 | 2615 | ('l', 'logfile', '', _('read commit message from <file>')), |
|
2616 | 2616 | ] |
|
2617 | 2617 | |
|
2618 | 2618 | table = { |
|
2619 | 2619 | "^add": (add, walkopts + dryrunopts, _('hg add [OPTION]... [FILE]...')), |
|
2620 | 2620 | "addremove": |
|
2621 | 2621 | (addremove, |
|
2622 | 2622 | [('s', 'similarity', '', |
|
2623 | 2623 | _('guess renamed files by similarity (0<=s<=100)')), |
|
2624 | 2624 | ] + walkopts + dryrunopts, |
|
2625 | 2625 | _('hg addremove [OPTION]... [FILE]...')), |
|
2626 | 2626 | "^annotate": |
|
2627 | 2627 | (annotate, |
|
2628 | 2628 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2629 | 2629 | ('f', 'follow', None, _('follow file copies and renames')), |
|
2630 | 2630 | ('a', 'text', None, _('treat all files as text')), |
|
2631 | 2631 | ('u', 'user', None, _('list the author')), |
|
2632 | 2632 | ('d', 'date', None, _('list the date')), |
|
2633 | 2633 | ('n', 'number', None, _('list the revision number (default)')), |
|
2634 | 2634 | ('c', 'changeset', None, _('list the changeset')), |
|
2635 | 2635 | ] + walkopts, |
|
2636 | 2636 | _('hg annotate [-r REV] [-f] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2637 | 2637 | "archive": |
|
2638 | 2638 | (archive, |
|
2639 | 2639 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
2640 | 2640 | ('p', 'prefix', '', _('directory prefix for files in archive')), |
|
2641 | 2641 | ('r', 'rev', '', _('revision to distribute')), |
|
2642 | 2642 | ('t', 'type', '', _('type of distribution to create')), |
|
2643 | 2643 | ] + walkopts, |
|
2644 | 2644 | _('hg archive [OPTION]... DEST')), |
|
2645 | 2645 | "backout": |
|
2646 | 2646 | (backout, |
|
2647 | 2647 | [('', 'merge', None, |
|
2648 | 2648 | _('merge with old dirstate parent after backout')), |
|
2649 | 2649 | ('d', 'date', '', _('record datecode as commit date')), |
|
2650 | 2650 | ('', 'parent', '', _('parent to choose when backing out merge')), |
|
2651 | 2651 | ('u', 'user', '', _('record user as committer')), |
|
2652 | 2652 | ] + walkopts + commitopts, |
|
2653 | 2653 | _('hg backout [OPTION]... REV')), |
|
2654 | 2654 | "branch": (branch, [], _('hg branch [NAME]')), |
|
2655 | 2655 | "branches": (branches, [], _('hg branches')), |
|
2656 | 2656 | "bundle": |
|
2657 | 2657 | (bundle, |
|
2658 | 2658 | [('f', 'force', None, |
|
2659 | 2659 | _('run even when remote repository is unrelated')), |
|
2660 | 2660 | ('r', 'rev', [], |
|
2661 | 2661 | _('a changeset you would like to bundle')), |
|
2662 | 2662 | ('', 'base', [], |
|
2663 | 2663 | _('a base changeset to specify instead of a destination')), |
|
2664 | 2664 | ] + remoteopts, |
|
2665 | 2665 | _('hg bundle [-f] [-r REV]... [--base REV]... FILE [DEST]')), |
|
2666 | 2666 | "cat": |
|
2667 | 2667 | (cat, |
|
2668 | 2668 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2669 | 2669 | ('r', 'rev', '', _('print the given revision')), |
|
2670 | 2670 | ] + walkopts, |
|
2671 | 2671 | _('hg cat [OPTION]... FILE...')), |
|
2672 | 2672 | "^clone": |
|
2673 | 2673 | (clone, |
|
2674 | 2674 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2675 | 2675 | ('r', 'rev', [], |
|
2676 | 2676 | _('a changeset you would like to have after cloning')), |
|
2677 | 2677 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2678 | 2678 | ('', 'uncompressed', None, |
|
2679 | 2679 | _('use uncompressed transfer (fast over LAN)')), |
|
2680 | 2680 | ] + remoteopts, |
|
2681 | 2681 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2682 | 2682 | "^commit|ci": |
|
2683 | 2683 | (commit, |
|
2684 | 2684 | [('A', 'addremove', None, |
|
2685 | 2685 | _('mark new/missing files as added/removed before committing')), |
|
2686 | 2686 | ('d', 'date', '', _('record datecode as commit date')), |
|
2687 | 2687 | ('u', 'user', '', _('record user as commiter')), |
|
2688 | 2688 | ] + walkopts + commitopts, |
|
2689 | 2689 | _('hg commit [OPTION]... [FILE]...')), |
|
2690 | 2690 | "copy|cp": |
|
2691 | 2691 | (copy, |
|
2692 | 2692 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2693 | 2693 | ('f', 'force', None, |
|
2694 | 2694 | _('forcibly copy over an existing managed file')), |
|
2695 | 2695 | ] + walkopts + dryrunopts, |
|
2696 | 2696 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2697 | 2697 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2698 | 2698 | "debugcomplete": |
|
2699 | 2699 | (debugcomplete, |
|
2700 | 2700 | [('o', 'options', None, _('show the command options'))], |
|
2701 | 2701 | _('debugcomplete [-o] CMD')), |
|
2702 | 2702 | "debuginstall": (debuginstall, [], _('debuginstall')), |
|
2703 | 2703 | "debugrebuildstate": |
|
2704 | 2704 | (debugrebuildstate, |
|
2705 | 2705 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2706 | 2706 | _('debugrebuildstate [-r REV] [REV]')), |
|
2707 | 2707 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2708 | 2708 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2709 | 2709 | "debugstate": (debugstate, [], _('debugstate')), |
|
2710 | 2710 | "debugdate": |
|
2711 | 2711 | (debugdate, |
|
2712 | 2712 | [('e', 'extended', None, _('try extended date formats'))], |
|
2713 | 2713 | _('debugdate [-e] DATE [RANGE]')), |
|
2714 | 2714 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2715 | 2715 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2716 | 2716 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2717 | 2717 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2718 | 2718 | "debugwalk": (debugwalk, walkopts, _('debugwalk [OPTION]... [FILE]...')), |
|
2719 | 2719 | "^diff": |
|
2720 | 2720 | (diff, |
|
2721 | 2721 | [('r', 'rev', [], _('revision')), |
|
2722 | 2722 | ('a', 'text', None, _('treat all files as text')), |
|
2723 | 2723 | ('p', 'show-function', None, |
|
2724 | 2724 | _('show which function each change is in')), |
|
2725 | 2725 | ('g', 'git', None, _('use git extended diff format')), |
|
2726 | 2726 | ('', 'nodates', None, _("don't include dates in diff headers")), |
|
2727 | 2727 | ('w', 'ignore-all-space', None, |
|
2728 | 2728 | _('ignore white space when comparing lines')), |
|
2729 | 2729 | ('b', 'ignore-space-change', None, |
|
2730 | 2730 | _('ignore changes in the amount of white space')), |
|
2731 | 2731 | ('B', 'ignore-blank-lines', None, |
|
2732 | 2732 | _('ignore changes whose lines are all blank')), |
|
2733 | 2733 | ] + walkopts, |
|
2734 | 2734 | _('hg diff [OPTION]... [-r REV1 [-r REV2]] [FILE]...')), |
|
2735 | 2735 | "^export": |
|
2736 | 2736 | (export, |
|
2737 | 2737 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2738 | 2738 | ('a', 'text', None, _('treat all files as text')), |
|
2739 | 2739 | ('g', 'git', None, _('use git extended diff format')), |
|
2740 | 2740 | ('', 'nodates', None, _("don't include dates in diff headers")), |
|
2741 | 2741 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2742 | 2742 | _('hg export [OPTION]... [-o OUTFILESPEC] REV...')), |
|
2743 | 2743 | "grep": |
|
2744 | 2744 | (grep, |
|
2745 | 2745 | [('0', 'print0', None, _('end fields with NUL')), |
|
2746 | 2746 | ('', 'all', None, _('print all revisions that match')), |
|
2747 | 2747 | ('f', 'follow', None, |
|
2748 | 2748 | _('follow changeset history, or file history across copies and renames')), |
|
2749 | 2749 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2750 | 2750 | ('l', 'files-with-matches', None, |
|
2751 | 2751 | _('print only filenames and revs that match')), |
|
2752 | 2752 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2753 | 2753 | ('r', 'rev', [], _('search in given revision range')), |
|
2754 | 2754 | ('u', 'user', None, _('print user who committed change')), |
|
2755 | 2755 | ] + walkopts, |
|
2756 | 2756 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2757 | 2757 | "heads": |
|
2758 | 2758 | (heads, |
|
2759 | 2759 | [('b', 'branches', None, _('show branches (DEPRECATED)')), |
|
2760 | 2760 | ('', 'style', '', _('display using template map file')), |
|
2761 | 2761 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2762 | 2762 | ('', 'template', '', _('display with template'))], |
|
2763 | 2763 | _('hg heads [-r REV]')), |
|
2764 | 2764 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2765 | 2765 | "identify|id": (identify, [], _('hg identify')), |
|
2766 | 2766 | "import|patch": |
|
2767 | 2767 | (import_, |
|
2768 | 2768 | [('p', 'strip', 1, |
|
2769 | 2769 | _('directory strip option for patch. This has the same\n' |
|
2770 | 2770 | 'meaning as the corresponding patch option')), |
|
2771 | 2771 | ('b', 'base', '', _('base path (DEPRECATED)')), |
|
2772 | 2772 | ('f', 'force', None, |
|
2773 | 2773 | _('skip check for outstanding uncommitted changes'))] + commitopts, |
|
2774 | 2774 | _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')), |
|
2775 | 2775 | "incoming|in": (incoming, |
|
2776 | 2776 | [('M', 'no-merges', None, _('do not show merges')), |
|
2777 | 2777 | ('f', 'force', None, |
|
2778 | 2778 | _('run even when remote repository is unrelated')), |
|
2779 | 2779 | ('', 'style', '', _('display using template map file')), |
|
2780 | 2780 | ('n', 'newest-first', None, _('show newest record first')), |
|
2781 | 2781 | ('', 'bundle', '', _('file to store the bundles into')), |
|
2782 | 2782 | ('p', 'patch', None, _('show patch')), |
|
2783 | 2783 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), |
|
2784 | 2784 | ('', 'template', '', _('display with template')), |
|
2785 | 2785 | ] + remoteopts, |
|
2786 | 2786 | _('hg incoming [-p] [-n] [-M] [-f] [-r REV]...' |
|
2787 | 2787 | ' [--bundle FILENAME] [SOURCE]')), |
|
2788 | 2788 | "^init": |
|
2789 | 2789 | (init, |
|
2790 | 2790 | remoteopts, |
|
2791 | 2791 | _('hg init [-e CMD] [--remotecmd CMD] [DEST]')), |
|
2792 | 2792 | "locate": |
|
2793 | 2793 | (locate, |
|
2794 | 2794 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2795 | 2795 | ('0', 'print0', None, |
|
2796 | 2796 | _('end filenames with NUL, for use with xargs')), |
|
2797 | 2797 | ('f', 'fullpath', None, |
|
2798 | 2798 | _('print complete paths from the filesystem root')), |
|
2799 | 2799 | ] + walkopts, |
|
2800 | 2800 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2801 | 2801 | "^log|history": |
|
2802 | 2802 | (log, |
|
2803 | 2803 | [('b', 'branches', None, _('show branches (DEPRECATED)')), |
|
2804 | 2804 | ('f', 'follow', None, |
|
2805 | 2805 | _('follow changeset history, or file history across copies and renames')), |
|
2806 | 2806 | ('', 'follow-first', None, |
|
2807 | 2807 | _('only follow the first parent of merge changesets')), |
|
2808 | 2808 | ('d', 'date', '', _('show revs matching date spec')), |
|
2809 | 2809 | ('C', 'copies', None, _('show copied files')), |
|
2810 | 2810 | ('k', 'keyword', [], _('search for a keyword')), |
|
2811 | 2811 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2812 | 2812 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2813 | 2813 | ('', 'removed', None, _('include revs where files were removed')), |
|
2814 | 2814 | ('M', 'no-merges', None, _('do not show merges')), |
|
2815 | 2815 | ('', 'style', '', _('display using template map file')), |
|
2816 | 2816 | ('m', 'only-merges', None, _('show only merges')), |
|
2817 | 2817 | ('p', 'patch', None, _('show patch')), |
|
2818 | 2818 | ('P', 'prune', [], _('do not display revision or any of its ancestors')), |
|
2819 | 2819 | ('', 'template', '', _('display with template')), |
|
2820 | 2820 | ] + walkopts, |
|
2821 | 2821 | _('hg log [OPTION]... [FILE]')), |
|
2822 | 2822 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
2823 | 2823 | "^merge": |
|
2824 | 2824 | (merge, |
|
2825 | 2825 | [('b', 'branch', '', _('merge with head of a specific branch (DEPRECATED)')), |
|
2826 | 2826 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
2827 | 2827 | _('hg merge [-f] [REV]')), |
|
2828 | 2828 | "outgoing|out": (outgoing, |
|
2829 | 2829 | [('M', 'no-merges', None, _('do not show merges')), |
|
2830 | 2830 | ('f', 'force', None, |
|
2831 | 2831 | _('run even when remote repository is unrelated')), |
|
2832 | 2832 | ('p', 'patch', None, _('show patch')), |
|
2833 | 2833 | ('', 'style', '', _('display using template map file')), |
|
2834 | 2834 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
2835 | 2835 | ('n', 'newest-first', None, _('show newest record first')), |
|
2836 | 2836 | ('', 'template', '', _('display with template')), |
|
2837 | 2837 | ] + remoteopts, |
|
2838 | 2838 | _('hg outgoing [-M] [-p] [-n] [-f] [-r REV]... [DEST]')), |
|
2839 | 2839 | "^parents": |
|
2840 | 2840 | (parents, |
|
2841 | 2841 | [('b', 'branches', None, _('show branches (DEPRECATED)')), |
|
2842 | 2842 | ('r', 'rev', '', _('show parents from the specified rev')), |
|
2843 | 2843 | ('', 'style', '', _('display using template map file')), |
|
2844 | 2844 | ('', 'template', '', _('display with template'))], |
|
2845 | 2845 | _('hg parents [-r REV] [FILE]')), |
|
2846 | 2846 | "paths": (paths, [], _('hg paths [NAME]')), |
|
2847 | 2847 | "^pull": |
|
2848 | 2848 | (pull, |
|
2849 | 2849 | [('u', 'update', None, |
|
2850 | 2850 | _('update to new tip if changesets were pulled')), |
|
2851 | 2851 | ('f', 'force', None, |
|
2852 | 2852 | _('run even when remote repository is unrelated')), |
|
2853 | 2853 | ('r', 'rev', [], |
|
2854 | 2854 | _('a specific revision up to which you would like to pull')), |
|
2855 | 2855 | ] + remoteopts, |
|
2856 | 2856 | _('hg pull [-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')), |
|
2857 | 2857 | "^push": |
|
2858 | 2858 | (push, |
|
2859 | 2859 | [('f', 'force', None, _('force push')), |
|
2860 | 2860 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
2861 | 2861 | ] + remoteopts, |
|
2862 | 2862 | _('hg push [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')), |
|
2863 | 2863 | "debugrawcommit|rawcommit": |
|
2864 | 2864 | (rawcommit, |
|
2865 | 2865 | [('p', 'parent', [], _('parent')), |
|
2866 | 2866 | ('d', 'date', '', _('date code')), |
|
2867 | 2867 | ('u', 'user', '', _('user')), |
|
2868 | 2868 | ('F', 'files', '', _('file list')) |
|
2869 | 2869 | ] + commitopts, |
|
2870 | 2870 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
2871 | 2871 | "recover": (recover, [], _('hg recover')), |
|
2872 | 2872 | "^remove|rm": |
|
2873 | 2873 | (remove, |
|
2874 | 2874 | [('A', 'after', None, _('record remove that has already occurred')), |
|
2875 | 2875 | ('f', 'force', None, _('remove file even if modified')), |
|
2876 | 2876 | ] + walkopts, |
|
2877 | 2877 | _('hg remove [OPTION]... FILE...')), |
|
2878 | 2878 | "rename|mv": |
|
2879 | 2879 | (rename, |
|
2880 | 2880 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
2881 | 2881 | ('f', 'force', None, |
|
2882 | 2882 | _('forcibly copy over an existing managed file')), |
|
2883 | 2883 | ] + walkopts + dryrunopts, |
|
2884 | 2884 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
2885 | 2885 | "^revert": |
|
2886 | 2886 | (revert, |
|
2887 | 2887 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
2888 | 2888 | ('d', 'date', '', _('tipmost revision matching date')), |
|
2889 | 2889 | ('r', 'rev', '', _('revision to revert to')), |
|
2890 | 2890 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
2891 | 2891 | ] + walkopts + dryrunopts, |
|
2892 | 2892 | _('hg revert [OPTION]... [-r REV] [NAME]...')), |
|
2893 | 2893 | "rollback": (rollback, [], _('hg rollback')), |
|
2894 | 2894 | "root": (root, [], _('hg root')), |
|
2895 | 2895 | "showconfig|debugconfig": |
|
2896 | 2896 | (showconfig, |
|
2897 | 2897 | [('u', 'untrusted', None, _('show untrusted configuration options'))], |
|
2898 | 2898 | _('showconfig [-u] [NAME]...')), |
|
2899 | 2899 | "^serve": |
|
2900 | 2900 | (serve, |
|
2901 | 2901 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
2902 | 2902 | ('d', 'daemon', None, _('run server in background')), |
|
2903 | 2903 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
2904 | 2904 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
2905 | 2905 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
2906 | 2906 | ('a', 'address', '', _('address to use')), |
|
2907 | 2907 | ('n', 'name', '', |
|
2908 | 2908 | _('name to show in web pages (default: working dir)')), |
|
2909 | 2909 | ('', 'webdir-conf', '', _('name of the webdir config file' |
|
2910 | 2910 | ' (serve more than one repo)')), |
|
2911 | 2911 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
2912 | 2912 | ('', 'stdio', None, _('for remote clients')), |
|
2913 | 2913 | ('t', 'templates', '', _('web templates to use')), |
|
2914 | 2914 | ('', 'style', '', _('template style to use')), |
|
2915 | 2915 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
2916 | 2916 | _('hg serve [OPTION]...')), |
|
2917 | 2917 | "^status|st": |
|
2918 | 2918 | (status, |
|
2919 | 2919 | [('A', 'all', None, _('show status of all files')), |
|
2920 | 2920 | ('m', 'modified', None, _('show only modified files')), |
|
2921 | 2921 | ('a', 'added', None, _('show only added files')), |
|
2922 | 2922 | ('r', 'removed', None, _('show only removed files')), |
|
2923 | 2923 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
2924 | 2924 | ('c', 'clean', None, _('show only files without changes')), |
|
2925 | 2925 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
2926 | 2926 | ('i', 'ignored', None, _('show only ignored files')), |
|
2927 | 2927 | ('n', 'no-status', None, _('hide status prefix')), |
|
2928 | 2928 | ('C', 'copies', None, _('show source of copied files')), |
|
2929 | 2929 | ('0', 'print0', None, |
|
2930 | 2930 | _('end filenames with NUL, for use with xargs')), |
|
2931 | 2931 | ('', 'rev', [], _('show difference from revision')), |
|
2932 | 2932 | ] + walkopts, |
|
2933 | 2933 | _('hg status [OPTION]... [FILE]...')), |
|
2934 | 2934 | "tag": |
|
2935 | 2935 | (tag, |
|
2936 | 2936 | [('l', 'local', None, _('make the tag local')), |
|
2937 | 2937 | ('m', 'message', '', _('message for tag commit log entry')), |
|
2938 | 2938 | ('d', 'date', '', _('record datecode as commit date')), |
|
2939 | 2939 | ('u', 'user', '', _('record user as commiter')), |
|
2940 | 2940 | ('r', 'rev', '', _('revision to tag'))], |
|
2941 | 2941 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
2942 | 2942 | "tags": (tags, [], _('hg tags')), |
|
2943 | 2943 | "tip": |
|
2944 | 2944 | (tip, |
|
2945 | 2945 | [('b', 'branches', None, _('show branches (DEPRECATED)')), |
|
2946 | 2946 | ('', 'style', '', _('display using template map file')), |
|
2947 | 2947 | ('p', 'patch', None, _('show patch')), |
|
2948 | 2948 | ('', 'template', '', _('display with template'))], |
|
2949 | 2949 | _('hg tip [-p]')), |
|
2950 | 2950 | "unbundle": |
|
2951 | 2951 | (unbundle, |
|
2952 | 2952 | [('u', 'update', None, |
|
2953 | 2953 | _('update to new tip if changesets were unbundled'))], |
|
2954 | 2954 | _('hg unbundle [-u] FILE')), |
|
2955 | 2955 | "^update|up|checkout|co": |
|
2956 | 2956 | (update, |
|
2957 | 2957 | [('b', 'branch', '', |
|
2958 | 2958 | _('checkout the head of a specific branch (DEPRECATED)')), |
|
2959 | 2959 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
2960 | 2960 | ('d', 'date', '', _('tipmost revision matching date'))], |
|
2961 | 2961 | _('hg update [-C] [-d DATE] [REV]')), |
|
2962 | 2962 | "verify": (verify, [], _('hg verify')), |
|
2963 | 2963 | "version": (version_, [], _('hg version')), |
|
2964 | 2964 | } |
|
2965 | 2965 | |
|
2966 | 2966 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
2967 | 2967 | " debugindex debugindexdot debugdate debuginstall") |
|
2968 | 2968 | optionalrepo = ("paths serve showconfig") |
|
2969 | 2969 | |
|
2970 | 2970 | def findpossible(ui, cmd): |
|
2971 | 2971 | """ |
|
2972 | 2972 | Return cmd -> (aliases, command table entry) |
|
2973 | 2973 | for each matching command. |
|
2974 | 2974 | Return debug commands (or their aliases) only if no normal command matches. |
|
2975 | 2975 | """ |
|
2976 | 2976 | choice = {} |
|
2977 | 2977 | debugchoice = {} |
|
2978 | 2978 | for e in table.keys(): |
|
2979 | 2979 | aliases = e.lstrip("^").split("|") |
|
2980 | 2980 | found = None |
|
2981 | 2981 | if cmd in aliases: |
|
2982 | 2982 | found = cmd |
|
2983 | 2983 | elif not ui.config("ui", "strict"): |
|
2984 | 2984 | for a in aliases: |
|
2985 | 2985 | if a.startswith(cmd): |
|
2986 | 2986 | found = a |
|
2987 | 2987 | break |
|
2988 | 2988 | if found is not None: |
|
2989 | 2989 | if aliases[0].startswith("debug") or found.startswith("debug"): |
|
2990 | 2990 | debugchoice[found] = (aliases, table[e]) |
|
2991 | 2991 | else: |
|
2992 | 2992 | choice[found] = (aliases, table[e]) |
|
2993 | 2993 | |
|
2994 | 2994 | if not choice and debugchoice: |
|
2995 | 2995 | choice = debugchoice |
|
2996 | 2996 | |
|
2997 | 2997 | return choice |
|
2998 | 2998 | |
|
2999 | 2999 | def findcmd(ui, cmd): |
|
3000 | 3000 | """Return (aliases, command table entry) for command string.""" |
|
3001 | 3001 | choice = findpossible(ui, cmd) |
|
3002 | 3002 | |
|
3003 | 3003 | if choice.has_key(cmd): |
|
3004 | 3004 | return choice[cmd] |
|
3005 | 3005 | |
|
3006 | 3006 | if len(choice) > 1: |
|
3007 | 3007 | clist = choice.keys() |
|
3008 | 3008 | clist.sort() |
|
3009 | 3009 | raise AmbiguousCommand(cmd, clist) |
|
3010 | 3010 | |
|
3011 | 3011 | if choice: |
|
3012 | 3012 | return choice.values()[0] |
|
3013 | 3013 | |
|
3014 | 3014 | raise UnknownCommand(cmd) |
|
3015 | 3015 | |
|
3016 | 3016 | def catchterm(*args): |
|
3017 | 3017 | raise util.SignalInterrupt |
|
3018 | 3018 | |
|
3019 | 3019 | def run(): |
|
3020 | 3020 | sys.exit(dispatch(sys.argv[1:])) |
|
3021 | 3021 | |
|
3022 | 3022 | class ParseError(Exception): |
|
3023 | 3023 | """Exception raised on errors in parsing the command line.""" |
|
3024 | 3024 | |
|
3025 | 3025 | def parse(ui, args): |
|
3026 | 3026 | options = {} |
|
3027 | 3027 | cmdoptions = {} |
|
3028 | 3028 | |
|
3029 | 3029 | try: |
|
3030 | 3030 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3031 | 3031 | except fancyopts.getopt.GetoptError, inst: |
|
3032 | 3032 | raise ParseError(None, inst) |
|
3033 | 3033 | |
|
3034 | 3034 | if args: |
|
3035 | 3035 | cmd, args = args[0], args[1:] |
|
3036 | 3036 | aliases, i = findcmd(ui, cmd) |
|
3037 | 3037 | cmd = aliases[0] |
|
3038 | 3038 | defaults = ui.config("defaults", cmd) |
|
3039 | 3039 | if defaults: |
|
3040 | 3040 | args = shlex.split(defaults) + args |
|
3041 | 3041 | c = list(i[1]) |
|
3042 | 3042 | else: |
|
3043 | 3043 | cmd = None |
|
3044 | 3044 | c = [] |
|
3045 | 3045 | |
|
3046 | 3046 | # combine global options into local |
|
3047 | 3047 | for o in globalopts: |
|
3048 | 3048 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3049 | 3049 | |
|
3050 | 3050 | try: |
|
3051 | 3051 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3052 | 3052 | except fancyopts.getopt.GetoptError, inst: |
|
3053 | 3053 | raise ParseError(cmd, inst) |
|
3054 | 3054 | |
|
3055 | 3055 | # separate global options back out |
|
3056 | 3056 | for o in globalopts: |
|
3057 | 3057 | n = o[1] |
|
3058 | 3058 | options[n] = cmdoptions[n] |
|
3059 | 3059 | del cmdoptions[n] |
|
3060 | 3060 | |
|
3061 | 3061 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3062 | 3062 | |
|
3063 | 3063 | external = {} |
|
3064 | 3064 | |
|
3065 | 3065 | def findext(name): |
|
3066 | 3066 | '''return module with given extension name''' |
|
3067 | 3067 | try: |
|
3068 | 3068 | return sys.modules[external[name]] |
|
3069 | 3069 | except KeyError: |
|
3070 | 3070 | for k, v in external.iteritems(): |
|
3071 | 3071 | if k.endswith('.' + name) or k.endswith('/' + name) or v == name: |
|
3072 | 3072 | return sys.modules[v] |
|
3073 | 3073 | raise KeyError(name) |
|
3074 | 3074 | |
|
3075 | 3075 | def load_extensions(ui): |
|
3076 | 3076 | added = [] |
|
3077 | 3077 | for ext_name, load_from_name in ui.extensions(): |
|
3078 | 3078 | if ext_name in external: |
|
3079 | 3079 | continue |
|
3080 | 3080 | try: |
|
3081 | 3081 | if load_from_name: |
|
3082 | 3082 | # the module will be loaded in sys.modules |
|
3083 | 3083 | # choose an unique name so that it doesn't |
|
3084 | 3084 | # conflicts with other modules |
|
3085 | 3085 | module_name = "hgext_%s" % ext_name.replace('.', '_') |
|
3086 | 3086 | mod = imp.load_source(module_name, load_from_name) |
|
3087 | 3087 | else: |
|
3088 | 3088 | def importh(name): |
|
3089 | 3089 | mod = __import__(name) |
|
3090 | 3090 | components = name.split('.') |
|
3091 | 3091 | for comp in components[1:]: |
|
3092 | 3092 | mod = getattr(mod, comp) |
|
3093 | 3093 | return mod |
|
3094 | 3094 | try: |
|
3095 | 3095 | mod = importh("hgext.%s" % ext_name) |
|
3096 | 3096 | except ImportError: |
|
3097 | 3097 | mod = importh(ext_name) |
|
3098 | 3098 | external[ext_name] = mod.__name__ |
|
3099 | 3099 | added.append((mod, ext_name)) |
|
3100 | 3100 | except (util.SignalInterrupt, KeyboardInterrupt): |
|
3101 | 3101 | raise |
|
3102 | 3102 | except Exception, inst: |
|
3103 | 3103 | ui.warn(_("*** failed to import extension %s: %s\n") % |
|
3104 | 3104 | (ext_name, inst)) |
|
3105 | 3105 | if ui.print_exc(): |
|
3106 | 3106 | return 1 |
|
3107 | 3107 | |
|
3108 | 3108 | for mod, name in added: |
|
3109 | 3109 | uisetup = getattr(mod, 'uisetup', None) |
|
3110 | 3110 | if uisetup: |
|
3111 | 3111 | uisetup(ui) |
|
3112 | 3112 | reposetup = getattr(mod, 'reposetup', None) |
|
3113 | 3113 | if reposetup: |
|
3114 | 3114 | hg.repo_setup_hooks.append(reposetup) |
|
3115 | 3115 | cmdtable = getattr(mod, 'cmdtable', {}) |
|
3116 | 3116 | for t in cmdtable: |
|
3117 | 3117 | if t in table: |
|
3118 | 3118 | ui.warn(_("module %s overrides %s\n") % (name, t)) |
|
3119 | 3119 | table.update(cmdtable) |
|
3120 | 3120 | |
|
3121 | 3121 | def parseconfig(config): |
|
3122 | 3122 | """parse the --config options from the command line""" |
|
3123 | 3123 | parsed = [] |
|
3124 | 3124 | for cfg in config: |
|
3125 | 3125 | try: |
|
3126 | 3126 | name, value = cfg.split('=', 1) |
|
3127 | 3127 | section, name = name.split('.', 1) |
|
3128 | 3128 | if not section or not name: |
|
3129 | 3129 | raise IndexError |
|
3130 | 3130 | parsed.append((section, name, value)) |
|
3131 | 3131 | except (IndexError, ValueError): |
|
3132 | 3132 | raise util.Abort(_('malformed --config option: %s') % cfg) |
|
3133 | 3133 | return parsed |
|
3134 | 3134 | |
|
3135 | 3135 | def dispatch(args): |
|
3136 | 3136 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
|
3137 | 3137 | num = getattr(signal, name, None) |
|
3138 | 3138 | if num: signal.signal(num, catchterm) |
|
3139 | 3139 | |
|
3140 | 3140 | try: |
|
3141 | 3141 | u = ui.ui(traceback='--traceback' in sys.argv[1:]) |
|
3142 | 3142 | except util.Abort, inst: |
|
3143 | 3143 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3144 | 3144 | return -1 |
|
3145 | 3145 | |
|
3146 | 3146 | load_extensions(u) |
|
3147 | 3147 | u.addreadhook(load_extensions) |
|
3148 | 3148 | |
|
3149 | 3149 | try: |
|
3150 | 3150 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3151 | 3151 | if options["encoding"]: |
|
3152 | 3152 | util._encoding = options["encoding"] |
|
3153 | 3153 | if options["encodingmode"]: |
|
3154 | 3154 | util._encodingmode = options["encodingmode"] |
|
3155 | 3155 | if options["time"]: |
|
3156 | 3156 | def get_times(): |
|
3157 | 3157 | t = os.times() |
|
3158 | 3158 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3159 | 3159 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3160 | 3160 | return t |
|
3161 | 3161 | s = get_times() |
|
3162 | 3162 | def print_time(): |
|
3163 | 3163 | t = get_times() |
|
3164 | 3164 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3165 | 3165 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3166 | 3166 | atexit.register(print_time) |
|
3167 | 3167 | |
|
3168 | 3168 | # enter the debugger before command execution |
|
3169 | 3169 | if options['debugger']: |
|
3170 | 3170 | pdb.set_trace() |
|
3171 | 3171 | |
|
3172 | 3172 | try: |
|
3173 | 3173 | if options['cwd']: |
|
3174 | 3174 | os.chdir(options['cwd']) |
|
3175 | 3175 | |
|
3176 | 3176 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3177 | 3177 | not options["noninteractive"], options["traceback"], |
|
3178 | 3178 | parseconfig(options["config"])) |
|
3179 | 3179 | |
|
3180 | 3180 | path = u.expandpath(options["repository"]) or "" |
|
3181 | 3181 | repo = path and hg.repository(u, path=path) or None |
|
3182 | 3182 | if repo and not repo.local(): |
|
3183 | 3183 | raise util.Abort(_("repository '%s' is not local") % path) |
|
3184 | 3184 | |
|
3185 | 3185 | if options['help']: |
|
3186 | 3186 | return help_(u, cmd, options['version']) |
|
3187 | 3187 | elif options['version']: |
|
3188 | 3188 | return version_(u) |
|
3189 | 3189 | elif not cmd: |
|
3190 | 3190 | return help_(u, 'shortlist') |
|
3191 | 3191 | |
|
3192 | 3192 | if cmd not in norepo.split(): |
|
3193 | 3193 | try: |
|
3194 | 3194 | if not repo: |
|
3195 | 3195 | repo = hg.repository(u, path=path) |
|
3196 | 3196 | u = repo.ui |
|
3197 | 3197 | except hg.RepoError: |
|
3198 | 3198 | if cmd not in optionalrepo.split(): |
|
3199 | 3199 | raise |
|
3200 | 3200 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3201 | 3201 | else: |
|
3202 | 3202 | d = lambda: func(u, *args, **cmdoptions) |
|
3203 | 3203 | |
|
3204 | 3204 | try: |
|
3205 | 3205 | if options['profile']: |
|
3206 | 3206 | import hotshot, hotshot.stats |
|
3207 | 3207 | prof = hotshot.Profile("hg.prof") |
|
3208 | 3208 | try: |
|
3209 | 3209 | try: |
|
3210 | 3210 | return prof.runcall(d) |
|
3211 | 3211 | except: |
|
3212 | 3212 | try: |
|
3213 | 3213 | u.warn(_('exception raised - generating ' |
|
3214 | 3214 | 'profile anyway\n')) |
|
3215 | 3215 | except: |
|
3216 | 3216 | pass |
|
3217 | 3217 | raise |
|
3218 | 3218 | finally: |
|
3219 | 3219 | prof.close() |
|
3220 | 3220 | stats = hotshot.stats.load("hg.prof") |
|
3221 | 3221 | stats.strip_dirs() |
|
3222 | 3222 | stats.sort_stats('time', 'calls') |
|
3223 | 3223 | stats.print_stats(40) |
|
3224 | 3224 | elif options['lsprof']: |
|
3225 | 3225 | try: |
|
3226 | 3226 | from mercurial import lsprof |
|
3227 | 3227 | except ImportError: |
|
3228 | 3228 | raise util.Abort(_( |
|
3229 | 3229 | 'lsprof not available - install from ' |
|
3230 | 3230 | 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) |
|
3231 | 3231 | p = lsprof.Profiler() |
|
3232 | 3232 | p.enable(subcalls=True) |
|
3233 | 3233 | try: |
|
3234 | 3234 | return d() |
|
3235 | 3235 | finally: |
|
3236 | 3236 | p.disable() |
|
3237 | 3237 | stats = lsprof.Stats(p.getstats()) |
|
3238 | 3238 | stats.sort() |
|
3239 | 3239 | stats.pprint(top=10, file=sys.stderr, climit=5) |
|
3240 | 3240 | else: |
|
3241 | 3241 | return d() |
|
3242 | 3242 | finally: |
|
3243 | 3243 | u.flush() |
|
3244 | 3244 | except: |
|
3245 | 3245 | # enter the debugger when we hit an exception |
|
3246 | 3246 | if options['debugger']: |
|
3247 | 3247 | pdb.post_mortem(sys.exc_info()[2]) |
|
3248 | 3248 | u.print_exc() |
|
3249 | 3249 | raise |
|
3250 | 3250 | except ParseError, inst: |
|
3251 | 3251 | if inst.args[0]: |
|
3252 | 3252 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3253 | 3253 | help_(u, inst.args[0]) |
|
3254 | 3254 | else: |
|
3255 | 3255 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3256 | 3256 | help_(u, 'shortlist') |
|
3257 | 3257 | except AmbiguousCommand, inst: |
|
3258 | 3258 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3259 | 3259 | (inst.args[0], " ".join(inst.args[1]))) |
|
3260 | 3260 | except UnknownCommand, inst: |
|
3261 | 3261 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3262 | 3262 | help_(u, 'shortlist') |
|
3263 | 3263 | except hg.RepoError, inst: |
|
3264 | 3264 | u.warn(_("abort: %s!\n") % inst) |
|
3265 | 3265 | except lock.LockHeld, inst: |
|
3266 | 3266 | if inst.errno == errno.ETIMEDOUT: |
|
3267 | 3267 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
3268 | 3268 | else: |
|
3269 | 3269 | reason = _('lock held by %s') % inst.locker |
|
3270 | 3270 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
3271 | 3271 | except lock.LockUnavailable, inst: |
|
3272 | 3272 | u.warn(_("abort: could not lock %s: %s\n") % |
|
3273 | 3273 | (inst.desc or inst.filename, inst.strerror)) |
|
3274 | 3274 | except revlog.RevlogError, inst: |
|
3275 | 3275 | u.warn(_("abort: %s!\n") % inst) |
|
3276 | 3276 | except util.SignalInterrupt: |
|
3277 | 3277 | u.warn(_("killed!\n")) |
|
3278 | 3278 | except KeyboardInterrupt: |
|
3279 | 3279 | try: |
|
3280 | 3280 | u.warn(_("interrupted!\n")) |
|
3281 | 3281 | except IOError, inst: |
|
3282 | 3282 | if inst.errno == errno.EPIPE: |
|
3283 | 3283 | if u.debugflag: |
|
3284 | 3284 | u.warn(_("\nbroken pipe\n")) |
|
3285 | 3285 | else: |
|
3286 | 3286 | raise |
|
3287 | 3287 | except socket.error, inst: |
|
3288 | 3288 | u.warn(_("abort: %s\n") % inst[1]) |
|
3289 | 3289 | except IOError, inst: |
|
3290 | 3290 | if hasattr(inst, "code"): |
|
3291 | 3291 | u.warn(_("abort: %s\n") % inst) |
|
3292 | 3292 | elif hasattr(inst, "reason"): |
|
3293 | 3293 | try: # usually it is in the form (errno, strerror) |
|
3294 | 3294 | reason = inst.reason.args[1] |
|
3295 | 3295 | except: # it might be anything, for example a string |
|
3296 | 3296 | reason = inst.reason |
|
3297 | 3297 | u.warn(_("abort: error: %s\n") % reason) |
|
3298 | 3298 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3299 | 3299 | if u.debugflag: |
|
3300 | 3300 | u.warn(_("broken pipe\n")) |
|
3301 | 3301 | elif getattr(inst, "strerror", None): |
|
3302 | 3302 | if getattr(inst, "filename", None): |
|
3303 | 3303 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3304 | 3304 | else: |
|
3305 | 3305 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3306 | 3306 | else: |
|
3307 | 3307 | raise |
|
3308 | 3308 | except OSError, inst: |
|
3309 | 3309 | if getattr(inst, "filename", None): |
|
3310 | 3310 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3311 | 3311 | else: |
|
3312 | 3312 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3313 | 3313 | except util.UnexpectedOutput, inst: |
|
3314 | 3314 | u.warn(_("abort: %s") % inst[0]) |
|
3315 | 3315 | if not isinstance(inst[1], basestring): |
|
3316 | 3316 | u.warn(" %r\n" % (inst[1],)) |
|
3317 | 3317 | elif not inst[1]: |
|
3318 | 3318 | u.warn(_(" empty string\n")) |
|
3319 | 3319 | else: |
|
3320 | 3320 | u.warn("\n%r\n" % util.ellipsis(inst[1])) |
|
3321 | 3321 | except util.Abort, inst: |
|
3322 | 3322 | u.warn(_("abort: %s\n") % inst) |
|
3323 | 3323 | except TypeError, inst: |
|
3324 | 3324 | # was this an argument error? |
|
3325 | 3325 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3326 | 3326 | if len(tb) > 2: # no |
|
3327 | 3327 | raise |
|
3328 | 3328 | u.debug(inst, "\n") |
|
3329 | 3329 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3330 | 3330 | help_(u, cmd) |
|
3331 | 3331 | except SystemExit, inst: |
|
3332 | 3332 | # Commands shouldn't sys.exit directly, but give a return code. |
|
3333 | 3333 | # Just in case catch this and and pass exit code to caller. |
|
3334 | 3334 | return inst.code |
|
3335 | 3335 | except: |
|
3336 | 3336 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3337 | 3337 | u.warn(_("** report bug details to " |
|
3338 | 3338 | "http://www.selenic.com/mercurial/bts\n")) |
|
3339 | 3339 | u.warn(_("** or mercurial@selenic.com\n")) |
|
3340 | 3340 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3341 | 3341 | % version.get_version()) |
|
3342 | 3342 | raise |
|
3343 | 3343 | |
|
3344 | 3344 | return -1 |
@@ -1,509 +1,509 b'' | |||
|
1 | 1 | # context.py - changeset and file context objects for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from node import * |
|
9 | 9 | from i18n import gettext as _ |
|
10 | 10 | from demandload import demandload |
|
11 | 11 | demandload(globals(), "ancestor bdiff repo revlog util os") |
|
12 | 12 | |
|
13 | 13 | class changectx(object): |
|
14 | 14 | """A changecontext object makes access to data related to a particular |
|
15 | 15 | changeset convenient.""" |
|
16 | 16 | def __init__(self, repo, changeid=None): |
|
17 | 17 | """changeid is a revision number, node, or tag""" |
|
18 | 18 | self._repo = repo |
|
19 | 19 | |
|
20 | 20 | if not changeid and changeid != 0: |
|
21 | 21 | p1, p2 = self._repo.dirstate.parents() |
|
22 | 22 | self._rev = self._repo.changelog.rev(p1) |
|
23 | 23 | if self._rev == -1: |
|
24 | 24 | changeid = 'tip' |
|
25 | 25 | else: |
|
26 | 26 | self._node = p1 |
|
27 | 27 | return |
|
28 | 28 | |
|
29 | 29 | self._node = self._repo.lookup(changeid) |
|
30 | 30 | self._rev = self._repo.changelog.rev(self._node) |
|
31 | 31 | |
|
32 | 32 | def __str__(self): |
|
33 | 33 | return short(self.node()) |
|
34 | 34 | |
|
35 | 35 | def __repr__(self): |
|
36 | 36 | return "<changectx %s>" % str(self) |
|
37 | 37 | |
|
38 | 38 | def __eq__(self, other): |
|
39 | 39 | try: |
|
40 | 40 | return self._rev == other._rev |
|
41 | 41 | except AttributeError: |
|
42 | 42 | return False |
|
43 | 43 | |
|
44 | 44 | def __nonzero__(self): |
|
45 | 45 | return self._rev != nullrev |
|
46 | 46 | |
|
47 | 47 | def __getattr__(self, name): |
|
48 | 48 | if name == '_changeset': |
|
49 | 49 | self._changeset = self._repo.changelog.read(self.node()) |
|
50 | 50 | return self._changeset |
|
51 | 51 | elif name == '_manifest': |
|
52 | 52 | self._manifest = self._repo.manifest.read(self._changeset[0]) |
|
53 | 53 | return self._manifest |
|
54 | 54 | elif name == '_manifestdelta': |
|
55 | 55 | md = self._repo.manifest.readdelta(self._changeset[0]) |
|
56 | 56 | self._manifestdelta = md |
|
57 | 57 | return self._manifestdelta |
|
58 | 58 | else: |
|
59 | 59 | raise AttributeError, name |
|
60 | 60 | |
|
61 | 61 | def changeset(self): return self._changeset |
|
62 | 62 | def manifest(self): return self._manifest |
|
63 | 63 | |
|
64 | 64 | def rev(self): return self._rev |
|
65 | 65 | def node(self): return self._node |
|
66 | 66 | def user(self): return self._changeset[1] |
|
67 | 67 | def date(self): return self._changeset[2] |
|
68 | 68 | def files(self): return self._changeset[3] |
|
69 | 69 | def description(self): return self._changeset[4] |
|
70 | 70 | def branch(self): return self._changeset[5].get("branch", "") |
|
71 | 71 | |
|
72 | 72 | def parents(self): |
|
73 | 73 | """return contexts for each parent changeset""" |
|
74 | 74 | p = self._repo.changelog.parents(self._node) |
|
75 | 75 | return [changectx(self._repo, x) for x in p] |
|
76 | 76 | |
|
77 | 77 | def children(self): |
|
78 | 78 | """return contexts for each child changeset""" |
|
79 | 79 | c = self._repo.changelog.children(self._node) |
|
80 | 80 | return [changectx(self._repo, x) for x in c] |
|
81 | 81 | |
|
82 | 82 | def filenode(self, path): |
|
83 | 83 | if '_manifest' in self.__dict__: |
|
84 | 84 | try: |
|
85 | 85 | return self._manifest[path] |
|
86 | 86 | except KeyError: |
|
87 | 87 | raise repo.LookupError(_("'%s' not found in manifest") % path) |
|
88 | 88 | if '_manifestdelta' in self.__dict__ or path in self.files(): |
|
89 | 89 | if path in self._manifestdelta: |
|
90 | 90 | return self._manifestdelta[path] |
|
91 | 91 | node, flag = self._repo.manifest.find(self._changeset[0], path) |
|
92 | 92 | if not node: |
|
93 | 93 | raise repo.LookupError(_("'%s' not found in manifest") % path) |
|
94 | 94 | |
|
95 | 95 | return node |
|
96 | 96 | |
|
97 | 97 | def filectx(self, path, fileid=None): |
|
98 | 98 | """get a file context from this changeset""" |
|
99 | 99 | if fileid is None: |
|
100 | 100 | fileid = self.filenode(path) |
|
101 | 101 | return filectx(self._repo, path, fileid=fileid, changectx=self) |
|
102 | 102 | |
|
103 | 103 | def filectxs(self): |
|
104 | 104 | """generate a file context for each file in this changeset's |
|
105 | 105 | manifest""" |
|
106 | 106 | mf = self.manifest() |
|
107 | 107 | m = mf.keys() |
|
108 | 108 | m.sort() |
|
109 | 109 | for f in m: |
|
110 | 110 | yield self.filectx(f, fileid=mf[f]) |
|
111 | 111 | |
|
112 | 112 | def ancestor(self, c2): |
|
113 | 113 | """ |
|
114 | 114 | return the ancestor context of self and c2 |
|
115 | 115 | """ |
|
116 | 116 | n = self._repo.changelog.ancestor(self._node, c2._node) |
|
117 | 117 | return changectx(self._repo, n) |
|
118 | 118 | |
|
119 | 119 | class filectx(object): |
|
120 | 120 | """A filecontext object makes access to data related to a particular |
|
121 | 121 | filerevision convenient.""" |
|
122 | 122 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
123 | 123 | filelog=None, changectx=None): |
|
124 | 124 | """changeid can be a changeset revision, node, or tag. |
|
125 | 125 | fileid can be a file revision or node.""" |
|
126 | 126 | self._repo = repo |
|
127 | 127 | self._path = path |
|
128 | 128 | |
|
129 | 129 | assert changeid is not None or fileid is not None |
|
130 | 130 | |
|
131 | 131 | if filelog: |
|
132 | 132 | self._filelog = filelog |
|
133 | 133 | if changectx: |
|
134 | 134 | self._changectx = changectx |
|
135 | 135 | self._changeid = changectx.node() |
|
136 | 136 | |
|
137 | 137 | if fileid is None: |
|
138 | 138 | self._changeid = changeid |
|
139 | 139 | else: |
|
140 | 140 | self._fileid = fileid |
|
141 | 141 | |
|
142 | 142 | def __getattr__(self, name): |
|
143 | 143 | if name == '_changectx': |
|
144 | 144 | self._changectx = changectx(self._repo, self._changeid) |
|
145 | 145 | return self._changectx |
|
146 | 146 | elif name == '_filelog': |
|
147 | 147 | self._filelog = self._repo.file(self._path) |
|
148 | 148 | return self._filelog |
|
149 | 149 | elif name == '_changeid': |
|
150 | 150 | self._changeid = self._filelog.linkrev(self._filenode) |
|
151 | 151 | return self._changeid |
|
152 | 152 | elif name == '_filenode': |
|
153 | 153 | try: |
|
154 | 154 | if '_fileid' in self.__dict__: |
|
155 | 155 | self._filenode = self._filelog.lookup(self._fileid) |
|
156 | 156 | else: |
|
157 | 157 | self._filenode = self._changectx.filenode(self._path) |
|
158 | 158 | except revlog.RevlogError, inst: |
|
159 | 159 | raise repo.LookupError(str(inst)) |
|
160 | 160 | return self._filenode |
|
161 | 161 | elif name == '_filerev': |
|
162 | 162 | self._filerev = self._filelog.rev(self._filenode) |
|
163 | 163 | return self._filerev |
|
164 | 164 | else: |
|
165 | 165 | raise AttributeError, name |
|
166 | 166 | |
|
167 | 167 | def __nonzero__(self): |
|
168 | 168 | try: |
|
169 | 169 | n = self._filenode |
|
170 | 170 | return True |
|
171 | 171 | except repo.LookupError: |
|
172 | 172 | # file is missing |
|
173 | 173 | return False |
|
174 | 174 | |
|
175 | 175 | def __str__(self): |
|
176 | 176 | return "%s@%s" % (self.path(), short(self.node())) |
|
177 | 177 | |
|
178 | 178 | def __repr__(self): |
|
179 | 179 | return "<filectx %s>" % str(self) |
|
180 | 180 | |
|
181 | 181 | def __eq__(self, other): |
|
182 | 182 | try: |
|
183 | 183 | return (self._path == other._path |
|
184 | 184 | and self._changeid == other._changeid) |
|
185 | 185 | except AttributeError: |
|
186 | 186 | return False |
|
187 | 187 | |
|
188 | 188 | def filectx(self, fileid): |
|
189 | 189 | '''opens an arbitrary revision of the file without |
|
190 | 190 | opening a new filelog''' |
|
191 | 191 | return filectx(self._repo, self._path, fileid=fileid, |
|
192 | 192 | filelog=self._filelog) |
|
193 | 193 | |
|
194 | 194 | def filerev(self): return self._filerev |
|
195 | 195 | def filenode(self): return self._filenode |
|
196 | 196 | def filelog(self): return self._filelog |
|
197 | 197 | |
|
198 | 198 | def rev(self): |
|
199 | 199 | if '_changectx' in self.__dict__: |
|
200 | 200 | return self._changectx.rev() |
|
201 | 201 | return self._filelog.linkrev(self._filenode) |
|
202 | 202 | |
|
203 | 203 | def node(self): return self._changectx.node() |
|
204 | 204 | def user(self): return self._changectx.user() |
|
205 | 205 | def date(self): return self._changectx.date() |
|
206 | 206 | def files(self): return self._changectx.files() |
|
207 | 207 | def description(self): return self._changectx.description() |
|
208 | 208 | def branch(self): return self._changectx.branch() |
|
209 | 209 | def manifest(self): return self._changectx.manifest() |
|
210 | 210 | def changectx(self): return self._changectx |
|
211 | 211 | |
|
212 | 212 | def data(self): return self._filelog.read(self._filenode) |
|
213 | 213 | def renamed(self): return self._filelog.renamed(self._filenode) |
|
214 | 214 | def path(self): return self._path |
|
215 | 215 | def size(self): return self._filelog.size(self._filerev) |
|
216 | 216 | |
|
217 | 217 | def cmp(self, text): return self._filelog.cmp(self._filenode, text) |
|
218 | 218 | |
|
219 | 219 | def parents(self): |
|
220 | 220 | p = self._path |
|
221 | 221 | fl = self._filelog |
|
222 | 222 | pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] |
|
223 | 223 | |
|
224 | 224 | r = self.renamed() |
|
225 | 225 | if r: |
|
226 | 226 | pl[0] = (r[0], r[1], None) |
|
227 | 227 | |
|
228 | 228 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
229 | 229 | for p,n,l in pl if n != nullid] |
|
230 | 230 | |
|
231 | 231 | def children(self): |
|
232 | 232 | # hard for renames |
|
233 | 233 | c = self._filelog.children(self._filenode) |
|
234 | 234 | return [filectx(self._repo, self._path, fileid=x, |
|
235 | 235 | filelog=self._filelog) for x in c] |
|
236 | 236 | |
|
237 | 237 | def annotate(self, follow=False): |
|
238 | 238 | '''returns a list of tuples of (ctx, line) for each line |
|
239 | 239 | in the file, where ctx is the filectx of the node where |
|
240 | 240 | that line was last changed''' |
|
241 | 241 | |
|
242 | 242 | def decorate(text, rev): |
|
243 | 243 | return ([rev] * len(text.splitlines()), text) |
|
244 | 244 | |
|
245 | 245 | def pair(parent, child): |
|
246 | 246 | for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
|
247 | 247 | child[0][b1:b2] = parent[0][a1:a2] |
|
248 | 248 | return child |
|
249 | 249 | |
|
250 | 250 | getlog = util.cachefunc(lambda x: self._repo.file(x)) |
|
251 | 251 | def getctx(path, fileid): |
|
252 | 252 | log = path == self._path and self._filelog or getlog(path) |
|
253 | 253 | return filectx(self._repo, path, fileid=fileid, filelog=log) |
|
254 | 254 | getctx = util.cachefunc(getctx) |
|
255 | 255 | |
|
256 | 256 | def parents(f): |
|
257 | 257 | # we want to reuse filectx objects as much as possible |
|
258 | 258 | p = f._path |
|
259 | 259 | if f._filerev is None: # working dir |
|
260 | 260 | pl = [(n.path(), n.filerev()) for n in f.parents()] |
|
261 | 261 | else: |
|
262 | 262 | pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] |
|
263 | 263 | |
|
264 | 264 | if follow: |
|
265 | 265 | r = f.renamed() |
|
266 | 266 | if r: |
|
267 | 267 | pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
|
268 | 268 | |
|
269 | 269 | return [getctx(p, n) for p, n in pl if n != nullrev] |
|
270 | 270 | |
|
271 | 271 | # use linkrev to find the first changeset where self appeared |
|
272 | 272 | if self.rev() != self._filelog.linkrev(self._filenode): |
|
273 | 273 | base = self.filectx(self.filerev()) |
|
274 | 274 | else: |
|
275 | 275 | base = self |
|
276 | 276 | |
|
277 | 277 | # find all ancestors |
|
278 | 278 | needed = {base: 1} |
|
279 | 279 | visit = [base] |
|
280 | 280 | files = [base._path] |
|
281 | 281 | while visit: |
|
282 | 282 | f = visit.pop(0) |
|
283 | 283 | for p in parents(f): |
|
284 | 284 | if p not in needed: |
|
285 | 285 | needed[p] = 1 |
|
286 | 286 | visit.append(p) |
|
287 | 287 | if p._path not in files: |
|
288 | 288 | files.append(p._path) |
|
289 | 289 | else: |
|
290 | 290 | # count how many times we'll use this |
|
291 | 291 | needed[p] += 1 |
|
292 | 292 | |
|
293 | 293 | # sort by revision (per file) which is a topological order |
|
294 | 294 | visit = [] |
|
295 | 295 | files.reverse() |
|
296 | 296 | for f in files: |
|
297 | 297 | fn = [(n._filerev, n) for n in needed.keys() if n._path == f] |
|
298 | 298 | fn.sort() |
|
299 | 299 | visit.extend(fn) |
|
300 | 300 | hist = {} |
|
301 | 301 | |
|
302 | 302 | for r, f in visit: |
|
303 | 303 | curr = decorate(f.data(), f) |
|
304 | 304 | for p in parents(f): |
|
305 | 305 | if p != nullid: |
|
306 | 306 | curr = pair(hist[p], curr) |
|
307 | 307 | # trim the history of unneeded revs |
|
308 | 308 | needed[p] -= 1 |
|
309 | 309 | if not needed[p]: |
|
310 | 310 | del hist[p] |
|
311 | 311 | hist[f] = curr |
|
312 | 312 | |
|
313 | 313 | return zip(hist[f][0], hist[f][1].splitlines(1)) |
|
314 | 314 | |
|
315 | 315 | def ancestor(self, fc2): |
|
316 | 316 | """ |
|
317 | 317 | find the common ancestor file context, if any, of self, and fc2 |
|
318 | 318 | """ |
|
319 | 319 | |
|
320 | 320 | acache = {} |
|
321 | 321 | |
|
322 | 322 | # prime the ancestor cache for the working directory |
|
323 | 323 | for c in (self, fc2): |
|
324 | 324 | if c._filerev == None: |
|
325 | 325 | pl = [(n.path(), n.filenode()) for n in c.parents()] |
|
326 | 326 | acache[(c._path, None)] = pl |
|
327 | 327 | |
|
328 | 328 | flcache = {self._path:self._filelog, fc2._path:fc2._filelog} |
|
329 | 329 | def parents(vertex): |
|
330 | 330 | if vertex in acache: |
|
331 | 331 | return acache[vertex] |
|
332 | 332 | f, n = vertex |
|
333 | 333 | if f not in flcache: |
|
334 | 334 | flcache[f] = self._repo.file(f) |
|
335 | 335 | fl = flcache[f] |
|
336 | 336 | pl = [(f, p) for p in fl.parents(n) if p != nullid] |
|
337 | 337 | re = fl.renamed(n) |
|
338 | 338 | if re: |
|
339 | 339 | pl.append(re) |
|
340 | 340 | acache[vertex] = pl |
|
341 | 341 | return pl |
|
342 | 342 | |
|
343 | 343 | a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
|
344 | 344 | v = ancestor.ancestor(a, b, parents) |
|
345 | 345 | if v: |
|
346 | 346 | f, n = v |
|
347 | 347 | return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
|
348 | 348 | |
|
349 | 349 | return None |
|
350 | 350 | |
|
351 | 351 | class workingctx(changectx): |
|
352 | 352 | """A workingctx object makes access to data related to |
|
353 | 353 | the current working directory convenient.""" |
|
354 | 354 | def __init__(self, repo): |
|
355 | 355 | self._repo = repo |
|
356 | 356 | self._rev = None |
|
357 | 357 | self._node = None |
|
358 | 358 | |
|
359 | 359 | def __str__(self): |
|
360 | 360 | return str(self._parents[0]) + "+" |
|
361 | 361 | |
|
362 | 362 | def __nonzero__(self): |
|
363 | 363 | return True |
|
364 | 364 | |
|
365 | 365 | def __getattr__(self, name): |
|
366 | 366 | if name == '_parents': |
|
367 | 367 | self._parents = self._repo.parents() |
|
368 | 368 | return self._parents |
|
369 | 369 | if name == '_status': |
|
370 | 370 | self._status = self._repo.status() |
|
371 | 371 | return self._status |
|
372 | 372 | if name == '_manifest': |
|
373 | 373 | self._buildmanifest() |
|
374 | 374 | return self._manifest |
|
375 | 375 | else: |
|
376 | 376 | raise AttributeError, name |
|
377 | 377 | |
|
378 | 378 | def _buildmanifest(self): |
|
379 | 379 | """generate a manifest corresponding to the working directory""" |
|
380 | 380 | |
|
381 | 381 | man = self._parents[0].manifest().copy() |
|
382 | 382 | copied = self._repo.dirstate.copies() |
|
383 | 383 | modified, added, removed, deleted, unknown = self._status[:5] |
|
384 | 384 | for i, l in (("a", added), ("m", modified), ("u", unknown)): |
|
385 | 385 | for f in l: |
|
386 | 386 | man[f] = man.get(copied.get(f, f), nullid) + i |
|
387 | 387 | try: |
|
388 | 388 | man.set(f, util.is_exec(self._repo.wjoin(f), man.execf(f))) |
|
389 | 389 | except OSError: |
|
390 | 390 | pass |
|
391 | 391 | |
|
392 | 392 | for f in deleted + removed: |
|
393 | 393 | if f in man: |
|
394 | 394 | del man[f] |
|
395 | 395 | |
|
396 | 396 | self._manifest = man |
|
397 | 397 | |
|
398 | 398 | def manifest(self): return self._manifest |
|
399 | 399 | |
|
400 | 400 | def user(self): return self._repo.ui.username() |
|
401 | 401 | def date(self): return util.makedate() |
|
402 | 402 | def description(self): return "" |
|
403 | 403 | def files(self): |
|
404 | 404 | f = self.modified() + self.added() + self.removed() |
|
405 | 405 | f.sort() |
|
406 | 406 | return f |
|
407 | 407 | |
|
408 | 408 | def modified(self): return self._status[0] |
|
409 | 409 | def added(self): return self._status[1] |
|
410 | 410 | def removed(self): return self._status[2] |
|
411 | 411 | def deleted(self): return self._status[3] |
|
412 | 412 | def unknown(self): return self._status[4] |
|
413 | 413 | def clean(self): return self._status[5] |
|
414 | 414 | def branch(self): |
|
415 | 415 | try: |
|
416 | return self._repo.opener("branch").read().strip() | |
|
416 | return self._repo.opener("branch").read().strip() or "default" | |
|
417 | 417 | except IOError: |
|
418 | return "" | |
|
418 | return "default" | |
|
419 | 419 | |
|
420 | 420 | def parents(self): |
|
421 | 421 | """return contexts for each parent changeset""" |
|
422 | 422 | return self._parents |
|
423 | 423 | |
|
424 | 424 | def children(self): |
|
425 | 425 | return [] |
|
426 | 426 | |
|
427 | 427 | def filectx(self, path): |
|
428 | 428 | """get a file context from the working directory""" |
|
429 | 429 | return workingfilectx(self._repo, path, workingctx=self) |
|
430 | 430 | |
|
431 | 431 | def ancestor(self, c2): |
|
432 | 432 | """return the ancestor context of self and c2""" |
|
433 | 433 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
434 | 434 | |
|
435 | 435 | class workingfilectx(filectx): |
|
436 | 436 | """A workingfilectx object makes access to data related to a particular |
|
437 | 437 | file in the working directory convenient.""" |
|
438 | 438 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
439 | 439 | """changeid can be a changeset revision, node, or tag. |
|
440 | 440 | fileid can be a file revision or node.""" |
|
441 | 441 | self._repo = repo |
|
442 | 442 | self._path = path |
|
443 | 443 | self._changeid = None |
|
444 | 444 | self._filerev = self._filenode = None |
|
445 | 445 | |
|
446 | 446 | if filelog: |
|
447 | 447 | self._filelog = filelog |
|
448 | 448 | if workingctx: |
|
449 | 449 | self._changectx = workingctx |
|
450 | 450 | |
|
451 | 451 | def __getattr__(self, name): |
|
452 | 452 | if name == '_changectx': |
|
453 | 453 | self._changectx = workingctx(repo) |
|
454 | 454 | return self._changectx |
|
455 | 455 | elif name == '_repopath': |
|
456 | 456 | self._repopath = (self._repo.dirstate.copied(self._path) |
|
457 | 457 | or self._path) |
|
458 | 458 | return self._repopath |
|
459 | 459 | elif name == '_filelog': |
|
460 | 460 | self._filelog = self._repo.file(self._repopath) |
|
461 | 461 | return self._filelog |
|
462 | 462 | else: |
|
463 | 463 | raise AttributeError, name |
|
464 | 464 | |
|
465 | 465 | def __nonzero__(self): |
|
466 | 466 | return True |
|
467 | 467 | |
|
468 | 468 | def __str__(self): |
|
469 | 469 | return "%s@%s" % (self.path(), self._changectx) |
|
470 | 470 | |
|
471 | 471 | def filectx(self, fileid): |
|
472 | 472 | '''opens an arbitrary revision of the file without |
|
473 | 473 | opening a new filelog''' |
|
474 | 474 | return filectx(self._repo, self._repopath, fileid=fileid, |
|
475 | 475 | filelog=self._filelog) |
|
476 | 476 | |
|
477 | 477 | def rev(self): |
|
478 | 478 | if '_changectx' in self.__dict__: |
|
479 | 479 | return self._changectx.rev() |
|
480 | 480 | return self._filelog.linkrev(self._filenode) |
|
481 | 481 | |
|
482 | 482 | def data(self): return self._repo.wread(self._path) |
|
483 | 483 | def renamed(self): |
|
484 | 484 | rp = self._repopath |
|
485 | 485 | if rp == self._path: |
|
486 | 486 | return None |
|
487 | 487 | return rp, self._workingctx._parents._manifest.get(rp, nullid) |
|
488 | 488 | |
|
489 | 489 | def parents(self): |
|
490 | 490 | '''return parent filectxs, following copies if necessary''' |
|
491 | 491 | p = self._path |
|
492 | 492 | rp = self._repopath |
|
493 | 493 | pcl = self._changectx._parents |
|
494 | 494 | fl = self._filelog |
|
495 | 495 | pl = [(rp, pcl[0]._manifest.get(rp, nullid), fl)] |
|
496 | 496 | if len(pcl) > 1: |
|
497 | 497 | if rp != p: |
|
498 | 498 | fl = None |
|
499 | 499 | pl.append((p, pcl[1]._manifest.get(p, nullid), fl)) |
|
500 | 500 | |
|
501 | 501 | return [filectx(self._repo, p, fileid=n, filelog=l) |
|
502 | 502 | for p,n,l in pl if n != nullid] |
|
503 | 503 | |
|
504 | 504 | def children(self): |
|
505 | 505 | return [] |
|
506 | 506 | |
|
507 | 507 | def size(self): return os.stat(self._repo.wjoin(self._path)).st_size |
|
508 | 508 | |
|
509 | 509 | def cmp(self, text): return self._repo.wread(self._path) == text |
@@ -1,2008 +1,2008 b'' | |||
|
1 | 1 | # localrepo.py - read/write repository class for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from node import * |
|
9 | 9 | from i18n import gettext as _ |
|
10 | 10 | from demandload import * |
|
11 | 11 | import repo |
|
12 | 12 | demandload(globals(), "appendfile changegroup") |
|
13 | 13 | demandload(globals(), "changelog dirstate filelog manifest context") |
|
14 | 14 | demandload(globals(), "re lock transaction tempfile stat mdiff errno ui") |
|
15 | 15 | demandload(globals(), "os revlog time util") |
|
16 | 16 | |
|
17 | 17 | class localrepository(repo.repository): |
|
18 | 18 | capabilities = ('lookup', 'changegroupsubset') |
|
19 | 19 | supported = ('revlogv1', 'store') |
|
20 |
branchcache_features = (' |
|
|
20 | branchcache_features = ('default',) | |
|
21 | 21 | |
|
22 | 22 | def __del__(self): |
|
23 | 23 | self.transhandle = None |
|
24 | 24 | def __init__(self, parentui, path=None, create=0): |
|
25 | 25 | repo.repository.__init__(self) |
|
26 | 26 | if not path: |
|
27 | 27 | p = os.getcwd() |
|
28 | 28 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
29 | 29 | oldp = p |
|
30 | 30 | p = os.path.dirname(p) |
|
31 | 31 | if p == oldp: |
|
32 | 32 | raise repo.RepoError(_("There is no Mercurial repository" |
|
33 | 33 | " here (.hg not found)")) |
|
34 | 34 | path = p |
|
35 | 35 | |
|
36 | 36 | self.root = os.path.realpath(path) |
|
37 | 37 | self.path = os.path.join(self.root, ".hg") |
|
38 | 38 | self.origroot = path |
|
39 | 39 | self.opener = util.opener(self.path) |
|
40 | 40 | self.wopener = util.opener(self.root) |
|
41 | 41 | |
|
42 | 42 | if not os.path.isdir(self.path): |
|
43 | 43 | if create: |
|
44 | 44 | if not os.path.exists(path): |
|
45 | 45 | os.mkdir(path) |
|
46 | 46 | os.mkdir(self.path) |
|
47 | 47 | os.mkdir(os.path.join(self.path, "store")) |
|
48 | 48 | requirements = ("revlogv1", "store") |
|
49 | 49 | reqfile = self.opener("requires", "w") |
|
50 | 50 | for r in requirements: |
|
51 | 51 | reqfile.write("%s\n" % r) |
|
52 | 52 | reqfile.close() |
|
53 | 53 | # create an invalid changelog |
|
54 | 54 | self.opener("00changelog.i", "a").write( |
|
55 | 55 | '\0\0\0\2' # represents revlogv2 |
|
56 | 56 | ' dummy changelog to prevent using the old repo layout' |
|
57 | 57 | ) |
|
58 | 58 | else: |
|
59 | 59 | raise repo.RepoError(_("repository %s not found") % path) |
|
60 | 60 | elif create: |
|
61 | 61 | raise repo.RepoError(_("repository %s already exists") % path) |
|
62 | 62 | else: |
|
63 | 63 | # find requirements |
|
64 | 64 | try: |
|
65 | 65 | requirements = self.opener("requires").read().splitlines() |
|
66 | 66 | except IOError, inst: |
|
67 | 67 | if inst.errno != errno.ENOENT: |
|
68 | 68 | raise |
|
69 | 69 | requirements = [] |
|
70 | 70 | # check them |
|
71 | 71 | for r in requirements: |
|
72 | 72 | if r not in self.supported: |
|
73 | 73 | raise repo.RepoError(_("requirement '%s' not supported") % r) |
|
74 | 74 | |
|
75 | 75 | # setup store |
|
76 | 76 | if "store" in requirements: |
|
77 | 77 | self.encodefn = util.encodefilename |
|
78 | 78 | self.decodefn = util.decodefilename |
|
79 | 79 | self.spath = os.path.join(self.path, "store") |
|
80 | 80 | else: |
|
81 | 81 | self.encodefn = lambda x: x |
|
82 | 82 | self.decodefn = lambda x: x |
|
83 | 83 | self.spath = self.path |
|
84 | 84 | self.sopener = util.encodedopener(util.opener(self.spath), self.encodefn) |
|
85 | 85 | |
|
86 | 86 | self.ui = ui.ui(parentui=parentui) |
|
87 | 87 | try: |
|
88 | 88 | self.ui.readconfig(self.join("hgrc"), self.root) |
|
89 | 89 | except IOError: |
|
90 | 90 | pass |
|
91 | 91 | |
|
92 | 92 | v = self.ui.configrevlog() |
|
93 | 93 | self.revlogversion = int(v.get('format', revlog.REVLOG_DEFAULT_FORMAT)) |
|
94 | 94 | self.revlogv1 = self.revlogversion != revlog.REVLOGV0 |
|
95 | 95 | fl = v.get('flags', None) |
|
96 | 96 | flags = 0 |
|
97 | 97 | if fl != None: |
|
98 | 98 | for x in fl.split(): |
|
99 | 99 | flags |= revlog.flagstr(x) |
|
100 | 100 | elif self.revlogv1: |
|
101 | 101 | flags = revlog.REVLOG_DEFAULT_FLAGS |
|
102 | 102 | |
|
103 | 103 | v = self.revlogversion | flags |
|
104 | 104 | self.manifest = manifest.manifest(self.sopener, v) |
|
105 | 105 | self.changelog = changelog.changelog(self.sopener, v) |
|
106 | 106 | |
|
107 | 107 | fallback = self.ui.config('ui', 'fallbackencoding') |
|
108 | 108 | if fallback: |
|
109 | 109 | util._fallbackencoding = fallback |
|
110 | 110 | |
|
111 | 111 | # the changelog might not have the inline index flag |
|
112 | 112 | # on. If the format of the changelog is the same as found in |
|
113 | 113 | # .hgrc, apply any flags found in the .hgrc as well. |
|
114 | 114 | # Otherwise, just version from the changelog |
|
115 | 115 | v = self.changelog.version |
|
116 | 116 | if v == self.revlogversion: |
|
117 | 117 | v |= flags |
|
118 | 118 | self.revlogversion = v |
|
119 | 119 | |
|
120 | 120 | self.tagscache = None |
|
121 | 121 | self.branchcache = None |
|
122 | 122 | self.nodetagscache = None |
|
123 | 123 | self.encodepats = None |
|
124 | 124 | self.decodepats = None |
|
125 | 125 | self.transhandle = None |
|
126 | 126 | |
|
127 | 127 | self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) |
|
128 | 128 | |
|
129 | 129 | def url(self): |
|
130 | 130 | return 'file:' + self.root |
|
131 | 131 | |
|
132 | 132 | def hook(self, name, throw=False, **args): |
|
133 | 133 | def callhook(hname, funcname): |
|
134 | 134 | '''call python hook. hook is callable object, looked up as |
|
135 | 135 | name in python module. if callable returns "true", hook |
|
136 | 136 | fails, else passes. if hook raises exception, treated as |
|
137 | 137 | hook failure. exception propagates if throw is "true". |
|
138 | 138 | |
|
139 | 139 | reason for "true" meaning "hook failed" is so that |
|
140 | 140 | unmodified commands (e.g. mercurial.commands.update) can |
|
141 | 141 | be run as hooks without wrappers to convert return values.''' |
|
142 | 142 | |
|
143 | 143 | self.ui.note(_("calling hook %s: %s\n") % (hname, funcname)) |
|
144 | 144 | d = funcname.rfind('.') |
|
145 | 145 | if d == -1: |
|
146 | 146 | raise util.Abort(_('%s hook is invalid ("%s" not in a module)') |
|
147 | 147 | % (hname, funcname)) |
|
148 | 148 | modname = funcname[:d] |
|
149 | 149 | try: |
|
150 | 150 | obj = __import__(modname) |
|
151 | 151 | except ImportError: |
|
152 | 152 | try: |
|
153 | 153 | # extensions are loaded with hgext_ prefix |
|
154 | 154 | obj = __import__("hgext_%s" % modname) |
|
155 | 155 | except ImportError: |
|
156 | 156 | raise util.Abort(_('%s hook is invalid ' |
|
157 | 157 | '(import of "%s" failed)') % |
|
158 | 158 | (hname, modname)) |
|
159 | 159 | try: |
|
160 | 160 | for p in funcname.split('.')[1:]: |
|
161 | 161 | obj = getattr(obj, p) |
|
162 | 162 | except AttributeError, err: |
|
163 | 163 | raise util.Abort(_('%s hook is invalid ' |
|
164 | 164 | '("%s" is not defined)') % |
|
165 | 165 | (hname, funcname)) |
|
166 | 166 | if not callable(obj): |
|
167 | 167 | raise util.Abort(_('%s hook is invalid ' |
|
168 | 168 | '("%s" is not callable)') % |
|
169 | 169 | (hname, funcname)) |
|
170 | 170 | try: |
|
171 | 171 | r = obj(ui=self.ui, repo=self, hooktype=name, **args) |
|
172 | 172 | except (KeyboardInterrupt, util.SignalInterrupt): |
|
173 | 173 | raise |
|
174 | 174 | except Exception, exc: |
|
175 | 175 | if isinstance(exc, util.Abort): |
|
176 | 176 | self.ui.warn(_('error: %s hook failed: %s\n') % |
|
177 | 177 | (hname, exc.args[0])) |
|
178 | 178 | else: |
|
179 | 179 | self.ui.warn(_('error: %s hook raised an exception: ' |
|
180 | 180 | '%s\n') % (hname, exc)) |
|
181 | 181 | if throw: |
|
182 | 182 | raise |
|
183 | 183 | self.ui.print_exc() |
|
184 | 184 | return True |
|
185 | 185 | if r: |
|
186 | 186 | if throw: |
|
187 | 187 | raise util.Abort(_('%s hook failed') % hname) |
|
188 | 188 | self.ui.warn(_('warning: %s hook failed\n') % hname) |
|
189 | 189 | return r |
|
190 | 190 | |
|
191 | 191 | def runhook(name, cmd): |
|
192 | 192 | self.ui.note(_("running hook %s: %s\n") % (name, cmd)) |
|
193 | 193 | env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()]) |
|
194 | 194 | r = util.system(cmd, environ=env, cwd=self.root) |
|
195 | 195 | if r: |
|
196 | 196 | desc, r = util.explain_exit(r) |
|
197 | 197 | if throw: |
|
198 | 198 | raise util.Abort(_('%s hook %s') % (name, desc)) |
|
199 | 199 | self.ui.warn(_('warning: %s hook %s\n') % (name, desc)) |
|
200 | 200 | return r |
|
201 | 201 | |
|
202 | 202 | r = False |
|
203 | 203 | hooks = [(hname, cmd) for hname, cmd in self.ui.configitems("hooks") |
|
204 | 204 | if hname.split(".", 1)[0] == name and cmd] |
|
205 | 205 | hooks.sort() |
|
206 | 206 | for hname, cmd in hooks: |
|
207 | 207 | if cmd.startswith('python:'): |
|
208 | 208 | r = callhook(hname, cmd[7:].strip()) or r |
|
209 | 209 | else: |
|
210 | 210 | r = runhook(hname, cmd) or r |
|
211 | 211 | return r |
|
212 | 212 | |
|
213 | 213 | tag_disallowed = ':\r\n' |
|
214 | 214 | |
|
215 | 215 | def tag(self, name, node, message, local, user, date): |
|
216 | 216 | '''tag a revision with a symbolic name. |
|
217 | 217 | |
|
218 | 218 | if local is True, the tag is stored in a per-repository file. |
|
219 | 219 | otherwise, it is stored in the .hgtags file, and a new |
|
220 | 220 | changeset is committed with the change. |
|
221 | 221 | |
|
222 | 222 | keyword arguments: |
|
223 | 223 | |
|
224 | 224 | local: whether to store tag in non-version-controlled file |
|
225 | 225 | (default False) |
|
226 | 226 | |
|
227 | 227 | message: commit message to use if committing |
|
228 | 228 | |
|
229 | 229 | user: name of user to use if committing |
|
230 | 230 | |
|
231 | 231 | date: date tuple to use if committing''' |
|
232 | 232 | |
|
233 | 233 | for c in self.tag_disallowed: |
|
234 | 234 | if c in name: |
|
235 | 235 | raise util.Abort(_('%r cannot be used in a tag name') % c) |
|
236 | 236 | |
|
237 | 237 | self.hook('pretag', throw=True, node=hex(node), tag=name, local=local) |
|
238 | 238 | |
|
239 | 239 | if local: |
|
240 | 240 | # local tags are stored in the current charset |
|
241 | 241 | self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name)) |
|
242 | 242 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
243 | 243 | return |
|
244 | 244 | |
|
245 | 245 | for x in self.status()[:5]: |
|
246 | 246 | if '.hgtags' in x: |
|
247 | 247 | raise util.Abort(_('working copy of .hgtags is changed ' |
|
248 | 248 | '(please commit .hgtags manually)')) |
|
249 | 249 | |
|
250 | 250 | # committed tags are stored in UTF-8 |
|
251 | 251 | line = '%s %s\n' % (hex(node), util.fromlocal(name)) |
|
252 | 252 | self.wfile('.hgtags', 'ab').write(line) |
|
253 | 253 | if self.dirstate.state('.hgtags') == '?': |
|
254 | 254 | self.add(['.hgtags']) |
|
255 | 255 | |
|
256 | 256 | self.commit(['.hgtags'], message, user, date) |
|
257 | 257 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
258 | 258 | |
|
259 | 259 | def tags(self): |
|
260 | 260 | '''return a mapping of tag to node''' |
|
261 | 261 | if not self.tagscache: |
|
262 | 262 | self.tagscache = {} |
|
263 | 263 | |
|
264 | 264 | def parsetag(line, context): |
|
265 | 265 | if not line: |
|
266 | 266 | return |
|
267 | 267 | s = l.split(" ", 1) |
|
268 | 268 | if len(s) != 2: |
|
269 | 269 | self.ui.warn(_("%s: cannot parse entry\n") % context) |
|
270 | 270 | return |
|
271 | 271 | node, key = s |
|
272 | 272 | key = util.tolocal(key.strip()) # stored in UTF-8 |
|
273 | 273 | try: |
|
274 | 274 | bin_n = bin(node) |
|
275 | 275 | except TypeError: |
|
276 | 276 | self.ui.warn(_("%s: node '%s' is not well formed\n") % |
|
277 | 277 | (context, node)) |
|
278 | 278 | return |
|
279 | 279 | if bin_n not in self.changelog.nodemap: |
|
280 | 280 | self.ui.warn(_("%s: tag '%s' refers to unknown node\n") % |
|
281 | 281 | (context, key)) |
|
282 | 282 | return |
|
283 | 283 | self.tagscache[key] = bin_n |
|
284 | 284 | |
|
285 | 285 | # read the tags file from each head, ending with the tip, |
|
286 | 286 | # and add each tag found to the map, with "newer" ones |
|
287 | 287 | # taking precedence |
|
288 | 288 | f = None |
|
289 | 289 | for rev, node, fnode in self._hgtagsnodes(): |
|
290 | 290 | f = (f and f.filectx(fnode) or |
|
291 | 291 | self.filectx('.hgtags', fileid=fnode)) |
|
292 | 292 | count = 0 |
|
293 | 293 | for l in f.data().splitlines(): |
|
294 | 294 | count += 1 |
|
295 | 295 | parsetag(l, _("%s, line %d") % (str(f), count)) |
|
296 | 296 | |
|
297 | 297 | try: |
|
298 | 298 | f = self.opener("localtags") |
|
299 | 299 | count = 0 |
|
300 | 300 | for l in f: |
|
301 | 301 | # localtags are stored in the local character set |
|
302 | 302 | # while the internal tag table is stored in UTF-8 |
|
303 | 303 | l = util.fromlocal(l) |
|
304 | 304 | count += 1 |
|
305 | 305 | parsetag(l, _("localtags, line %d") % count) |
|
306 | 306 | except IOError: |
|
307 | 307 | pass |
|
308 | 308 | |
|
309 | 309 | self.tagscache['tip'] = self.changelog.tip() |
|
310 | 310 | |
|
311 | 311 | return self.tagscache |
|
312 | 312 | |
|
313 | 313 | def _hgtagsnodes(self): |
|
314 | 314 | heads = self.heads() |
|
315 | 315 | heads.reverse() |
|
316 | 316 | last = {} |
|
317 | 317 | ret = [] |
|
318 | 318 | for node in heads: |
|
319 | 319 | c = self.changectx(node) |
|
320 | 320 | rev = c.rev() |
|
321 | 321 | try: |
|
322 | 322 | fnode = c.filenode('.hgtags') |
|
323 | 323 | except repo.LookupError: |
|
324 | 324 | continue |
|
325 | 325 | ret.append((rev, node, fnode)) |
|
326 | 326 | if fnode in last: |
|
327 | 327 | ret[last[fnode]] = None |
|
328 | 328 | last[fnode] = len(ret) - 1 |
|
329 | 329 | return [item for item in ret if item] |
|
330 | 330 | |
|
331 | 331 | def tagslist(self): |
|
332 | 332 | '''return a list of tags ordered by revision''' |
|
333 | 333 | l = [] |
|
334 | 334 | for t, n in self.tags().items(): |
|
335 | 335 | try: |
|
336 | 336 | r = self.changelog.rev(n) |
|
337 | 337 | except: |
|
338 | 338 | r = -2 # sort to the beginning of the list if unknown |
|
339 | 339 | l.append((r, t, n)) |
|
340 | 340 | l.sort() |
|
341 | 341 | return [(t, n) for r, t, n in l] |
|
342 | 342 | |
|
343 | 343 | def nodetags(self, node): |
|
344 | 344 | '''return the tags associated with a node''' |
|
345 | 345 | if not self.nodetagscache: |
|
346 | 346 | self.nodetagscache = {} |
|
347 | 347 | for t, n in self.tags().items(): |
|
348 | 348 | self.nodetagscache.setdefault(n, []).append(t) |
|
349 | 349 | return self.nodetagscache.get(node, []) |
|
350 | 350 | |
|
351 | 351 | def _branchtags(self): |
|
352 | 352 | partial, last, lrev = self._readbranchcache() |
|
353 | 353 | |
|
354 | 354 | tiprev = self.changelog.count() - 1 |
|
355 | 355 | if lrev != tiprev: |
|
356 | 356 | self._updatebranchcache(partial, lrev+1, tiprev+1) |
|
357 | 357 | self._writebranchcache(partial, self.changelog.tip(), tiprev) |
|
358 | 358 | |
|
359 | 359 | return partial |
|
360 | 360 | |
|
361 | 361 | def branchtags(self): |
|
362 | 362 | if self.branchcache is not None: |
|
363 | 363 | return self.branchcache |
|
364 | 364 | |
|
365 | 365 | self.branchcache = {} # avoid recursion in changectx |
|
366 | 366 | partial = self._branchtags() |
|
367 | 367 | |
|
368 | 368 | # the branch cache is stored on disk as UTF-8, but in the local |
|
369 | 369 | # charset internally |
|
370 | 370 | for k, v in partial.items(): |
|
371 | 371 | self.branchcache[util.tolocal(k)] = v |
|
372 | 372 | return self.branchcache |
|
373 | 373 | |
|
374 | 374 | def _readbranchcache(self): |
|
375 | 375 | partial = {} |
|
376 | 376 | try: |
|
377 | 377 | f = self.opener("branches.cache") |
|
378 | 378 | lines = f.read().split('\n') |
|
379 | 379 | f.close() |
|
380 | 380 | features = lines.pop(0).strip() |
|
381 | 381 | if not features.startswith('features: '): |
|
382 | 382 | raise ValueError(_('branch cache: no features specified')) |
|
383 | 383 | features = features.split(' ', 1)[1].split() |
|
384 | 384 | missing_features = [] |
|
385 | 385 | for feature in self.branchcache_features: |
|
386 | 386 | try: |
|
387 | 387 | features.remove(feature) |
|
388 | 388 | except ValueError, inst: |
|
389 | 389 | missing_features.append(feature) |
|
390 | 390 | if missing_features: |
|
391 | 391 | raise ValueError(_('branch cache: missing features: %s') |
|
392 | 392 | % ', '.join(missing_features)) |
|
393 | 393 | if features: |
|
394 | 394 | raise ValueError(_('branch cache: unknown features: %s') |
|
395 | 395 | % ', '.join(features)) |
|
396 | 396 | last, lrev = lines.pop(0).split(" ", 1) |
|
397 | 397 | last, lrev = bin(last), int(lrev) |
|
398 | 398 | if not (lrev < self.changelog.count() and |
|
399 | 399 | self.changelog.node(lrev) == last): # sanity check |
|
400 | 400 | # invalidate the cache |
|
401 | 401 | raise ValueError('Invalid branch cache: unknown tip') |
|
402 | 402 | for l in lines: |
|
403 | 403 | if not l: continue |
|
404 | 404 | node, label = l.split(" ", 1) |
|
405 | 405 | partial[label.strip()] = bin(node) |
|
406 | 406 | except (KeyboardInterrupt, util.SignalInterrupt): |
|
407 | 407 | raise |
|
408 | 408 | except Exception, inst: |
|
409 | 409 | if self.ui.debugflag: |
|
410 | 410 | self.ui.warn(str(inst), '\n') |
|
411 | 411 | partial, last, lrev = {}, nullid, nullrev |
|
412 | 412 | return partial, last, lrev |
|
413 | 413 | |
|
414 | 414 | def _writebranchcache(self, branches, tip, tiprev): |
|
415 | 415 | try: |
|
416 | 416 | f = self.opener("branches.cache", "w") |
|
417 | 417 | f.write(" features: %s\n" % ' '.join(self.branchcache_features)) |
|
418 | 418 | f.write("%s %s\n" % (hex(tip), tiprev)) |
|
419 | 419 | for label, node in branches.iteritems(): |
|
420 | 420 | f.write("%s %s\n" % (hex(node), label)) |
|
421 | 421 | except IOError: |
|
422 | 422 | pass |
|
423 | 423 | |
|
424 | 424 | def _updatebranchcache(self, partial, start, end): |
|
425 | 425 | for r in xrange(start, end): |
|
426 | 426 | c = self.changectx(r) |
|
427 | 427 | b = c.branch() |
|
428 | 428 | partial[b] = c.node() |
|
429 | 429 | |
|
430 | 430 | def lookup(self, key): |
|
431 | 431 | if key == '.': |
|
432 | 432 | key = self.dirstate.parents()[0] |
|
433 | 433 | if key == nullid: |
|
434 | 434 | raise repo.RepoError(_("no revision checked out")) |
|
435 | 435 | elif key == 'null': |
|
436 | 436 | return nullid |
|
437 | 437 | n = self.changelog._match(key) |
|
438 | 438 | if n: |
|
439 | 439 | return n |
|
440 | 440 | if key in self.tags(): |
|
441 | 441 | return self.tags()[key] |
|
442 | 442 | if key in self.branchtags(): |
|
443 | 443 | return self.branchtags()[key] |
|
444 | 444 | n = self.changelog._partialmatch(key) |
|
445 | 445 | if n: |
|
446 | 446 | return n |
|
447 | 447 | raise repo.RepoError(_("unknown revision '%s'") % key) |
|
448 | 448 | |
|
449 | 449 | def dev(self): |
|
450 | 450 | return os.lstat(self.path).st_dev |
|
451 | 451 | |
|
452 | 452 | def local(self): |
|
453 | 453 | return True |
|
454 | 454 | |
|
455 | 455 | def join(self, f): |
|
456 | 456 | return os.path.join(self.path, f) |
|
457 | 457 | |
|
458 | 458 | def sjoin(self, f): |
|
459 | 459 | f = self.encodefn(f) |
|
460 | 460 | return os.path.join(self.spath, f) |
|
461 | 461 | |
|
462 | 462 | def wjoin(self, f): |
|
463 | 463 | return os.path.join(self.root, f) |
|
464 | 464 | |
|
465 | 465 | def file(self, f): |
|
466 | 466 | if f[0] == '/': |
|
467 | 467 | f = f[1:] |
|
468 | 468 | return filelog.filelog(self.sopener, f, self.revlogversion) |
|
469 | 469 | |
|
470 | 470 | def changectx(self, changeid=None): |
|
471 | 471 | return context.changectx(self, changeid) |
|
472 | 472 | |
|
473 | 473 | def workingctx(self): |
|
474 | 474 | return context.workingctx(self) |
|
475 | 475 | |
|
476 | 476 | def parents(self, changeid=None): |
|
477 | 477 | ''' |
|
478 | 478 | get list of changectxs for parents of changeid or working directory |
|
479 | 479 | ''' |
|
480 | 480 | if changeid is None: |
|
481 | 481 | pl = self.dirstate.parents() |
|
482 | 482 | else: |
|
483 | 483 | n = self.changelog.lookup(changeid) |
|
484 | 484 | pl = self.changelog.parents(n) |
|
485 | 485 | if pl[1] == nullid: |
|
486 | 486 | return [self.changectx(pl[0])] |
|
487 | 487 | return [self.changectx(pl[0]), self.changectx(pl[1])] |
|
488 | 488 | |
|
489 | 489 | def filectx(self, path, changeid=None, fileid=None): |
|
490 | 490 | """changeid can be a changeset revision, node, or tag. |
|
491 | 491 | fileid can be a file revision or node.""" |
|
492 | 492 | return context.filectx(self, path, changeid, fileid) |
|
493 | 493 | |
|
494 | 494 | def getcwd(self): |
|
495 | 495 | return self.dirstate.getcwd() |
|
496 | 496 | |
|
497 | 497 | def wfile(self, f, mode='r'): |
|
498 | 498 | return self.wopener(f, mode) |
|
499 | 499 | |
|
500 | 500 | def wread(self, filename): |
|
501 | 501 | if self.encodepats == None: |
|
502 | 502 | l = [] |
|
503 | 503 | for pat, cmd in self.ui.configitems("encode"): |
|
504 | 504 | mf = util.matcher(self.root, "", [pat], [], [])[1] |
|
505 | 505 | l.append((mf, cmd)) |
|
506 | 506 | self.encodepats = l |
|
507 | 507 | |
|
508 | 508 | data = self.wopener(filename, 'r').read() |
|
509 | 509 | |
|
510 | 510 | for mf, cmd in self.encodepats: |
|
511 | 511 | if mf(filename): |
|
512 | 512 | self.ui.debug(_("filtering %s through %s\n") % (filename, cmd)) |
|
513 | 513 | data = util.filter(data, cmd) |
|
514 | 514 | break |
|
515 | 515 | |
|
516 | 516 | return data |
|
517 | 517 | |
|
518 | 518 | def wwrite(self, filename, data, fd=None): |
|
519 | 519 | if self.decodepats == None: |
|
520 | 520 | l = [] |
|
521 | 521 | for pat, cmd in self.ui.configitems("decode"): |
|
522 | 522 | mf = util.matcher(self.root, "", [pat], [], [])[1] |
|
523 | 523 | l.append((mf, cmd)) |
|
524 | 524 | self.decodepats = l |
|
525 | 525 | |
|
526 | 526 | for mf, cmd in self.decodepats: |
|
527 | 527 | if mf(filename): |
|
528 | 528 | self.ui.debug(_("filtering %s through %s\n") % (filename, cmd)) |
|
529 | 529 | data = util.filter(data, cmd) |
|
530 | 530 | break |
|
531 | 531 | |
|
532 | 532 | if fd: |
|
533 | 533 | return fd.write(data) |
|
534 | 534 | return self.wopener(filename, 'w').write(data) |
|
535 | 535 | |
|
536 | 536 | def transaction(self): |
|
537 | 537 | tr = self.transhandle |
|
538 | 538 | if tr != None and tr.running(): |
|
539 | 539 | return tr.nest() |
|
540 | 540 | |
|
541 | 541 | # save dirstate for rollback |
|
542 | 542 | try: |
|
543 | 543 | ds = self.opener("dirstate").read() |
|
544 | 544 | except IOError: |
|
545 | 545 | ds = "" |
|
546 | 546 | self.opener("journal.dirstate", "w").write(ds) |
|
547 | 547 | |
|
548 | 548 | renames = [(self.sjoin("journal"), self.sjoin("undo")), |
|
549 | 549 | (self.join("journal.dirstate"), self.join("undo.dirstate"))] |
|
550 | 550 | tr = transaction.transaction(self.ui.warn, self.sopener, |
|
551 | 551 | self.sjoin("journal"), |
|
552 | 552 | aftertrans(renames)) |
|
553 | 553 | self.transhandle = tr |
|
554 | 554 | return tr |
|
555 | 555 | |
|
556 | 556 | def recover(self): |
|
557 | 557 | l = self.lock() |
|
558 | 558 | if os.path.exists(self.sjoin("journal")): |
|
559 | 559 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
560 | 560 | transaction.rollback(self.sopener, self.sjoin("journal")) |
|
561 | 561 | self.reload() |
|
562 | 562 | return True |
|
563 | 563 | else: |
|
564 | 564 | self.ui.warn(_("no interrupted transaction available\n")) |
|
565 | 565 | return False |
|
566 | 566 | |
|
567 | 567 | def rollback(self, wlock=None): |
|
568 | 568 | if not wlock: |
|
569 | 569 | wlock = self.wlock() |
|
570 | 570 | l = self.lock() |
|
571 | 571 | if os.path.exists(self.sjoin("undo")): |
|
572 | 572 | self.ui.status(_("rolling back last transaction\n")) |
|
573 | 573 | transaction.rollback(self.sopener, self.sjoin("undo")) |
|
574 | 574 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) |
|
575 | 575 | self.reload() |
|
576 | 576 | self.wreload() |
|
577 | 577 | else: |
|
578 | 578 | self.ui.warn(_("no rollback information available\n")) |
|
579 | 579 | |
|
580 | 580 | def wreload(self): |
|
581 | 581 | self.dirstate.read() |
|
582 | 582 | |
|
583 | 583 | def reload(self): |
|
584 | 584 | self.changelog.load() |
|
585 | 585 | self.manifest.load() |
|
586 | 586 | self.tagscache = None |
|
587 | 587 | self.nodetagscache = None |
|
588 | 588 | |
|
589 | 589 | def do_lock(self, lockname, wait, releasefn=None, acquirefn=None, |
|
590 | 590 | desc=None): |
|
591 | 591 | try: |
|
592 | 592 | l = lock.lock(lockname, 0, releasefn, desc=desc) |
|
593 | 593 | except lock.LockHeld, inst: |
|
594 | 594 | if not wait: |
|
595 | 595 | raise |
|
596 | 596 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
597 | 597 | (desc, inst.locker)) |
|
598 | 598 | # default to 600 seconds timeout |
|
599 | 599 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), |
|
600 | 600 | releasefn, desc=desc) |
|
601 | 601 | if acquirefn: |
|
602 | 602 | acquirefn() |
|
603 | 603 | return l |
|
604 | 604 | |
|
605 | 605 | def lock(self, wait=1): |
|
606 | 606 | return self.do_lock(self.sjoin("lock"), wait, acquirefn=self.reload, |
|
607 | 607 | desc=_('repository %s') % self.origroot) |
|
608 | 608 | |
|
609 | 609 | def wlock(self, wait=1): |
|
610 | 610 | return self.do_lock(self.join("wlock"), wait, self.dirstate.write, |
|
611 | 611 | self.wreload, |
|
612 | 612 | desc=_('working directory of %s') % self.origroot) |
|
613 | 613 | |
|
614 | 614 | def filecommit(self, fn, manifest1, manifest2, linkrev, transaction, changelist): |
|
615 | 615 | """ |
|
616 | 616 | commit an individual file as part of a larger transaction |
|
617 | 617 | """ |
|
618 | 618 | |
|
619 | 619 | t = self.wread(fn) |
|
620 | 620 | fl = self.file(fn) |
|
621 | 621 | fp1 = manifest1.get(fn, nullid) |
|
622 | 622 | fp2 = manifest2.get(fn, nullid) |
|
623 | 623 | |
|
624 | 624 | meta = {} |
|
625 | 625 | cp = self.dirstate.copied(fn) |
|
626 | 626 | if cp: |
|
627 | 627 | # Mark the new revision of this file as a copy of another |
|
628 | 628 | # file. This copy data will effectively act as a parent |
|
629 | 629 | # of this new revision. If this is a merge, the first |
|
630 | 630 | # parent will be the nullid (meaning "look up the copy data") |
|
631 | 631 | # and the second one will be the other parent. For example: |
|
632 | 632 | # |
|
633 | 633 | # 0 --- 1 --- 3 rev1 changes file foo |
|
634 | 634 | # \ / rev2 renames foo to bar and changes it |
|
635 | 635 | # \- 2 -/ rev3 should have bar with all changes and |
|
636 | 636 | # should record that bar descends from |
|
637 | 637 | # bar in rev2 and foo in rev1 |
|
638 | 638 | # |
|
639 | 639 | # this allows this merge to succeed: |
|
640 | 640 | # |
|
641 | 641 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
642 | 642 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
643 | 643 | # \- 2 --- 4 as the merge base |
|
644 | 644 | # |
|
645 | 645 | meta["copy"] = cp |
|
646 | 646 | if not manifest2: # not a branch merge |
|
647 | 647 | meta["copyrev"] = hex(manifest1.get(cp, nullid)) |
|
648 | 648 | fp2 = nullid |
|
649 | 649 | elif fp2 != nullid: # copied on remote side |
|
650 | 650 | meta["copyrev"] = hex(manifest1.get(cp, nullid)) |
|
651 | 651 | elif fp1 != nullid: # copied on local side, reversed |
|
652 | 652 | meta["copyrev"] = hex(manifest2.get(cp)) |
|
653 | 653 | fp2 = fp1 |
|
654 | 654 | else: # directory rename |
|
655 | 655 | meta["copyrev"] = hex(manifest1.get(cp, nullid)) |
|
656 | 656 | self.ui.debug(_(" %s: copy %s:%s\n") % |
|
657 | 657 | (fn, cp, meta["copyrev"])) |
|
658 | 658 | fp1 = nullid |
|
659 | 659 | elif fp2 != nullid: |
|
660 | 660 | # is one parent an ancestor of the other? |
|
661 | 661 | fpa = fl.ancestor(fp1, fp2) |
|
662 | 662 | if fpa == fp1: |
|
663 | 663 | fp1, fp2 = fp2, nullid |
|
664 | 664 | elif fpa == fp2: |
|
665 | 665 | fp2 = nullid |
|
666 | 666 | |
|
667 | 667 | # is the file unmodified from the parent? report existing entry |
|
668 | 668 | if fp2 == nullid and not fl.cmp(fp1, t): |
|
669 | 669 | return fp1 |
|
670 | 670 | |
|
671 | 671 | changelist.append(fn) |
|
672 | 672 | return fl.add(t, meta, transaction, linkrev, fp1, fp2) |
|
673 | 673 | |
|
674 | 674 | def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None): |
|
675 | 675 | if p1 is None: |
|
676 | 676 | p1, p2 = self.dirstate.parents() |
|
677 | 677 | return self.commit(files=files, text=text, user=user, date=date, |
|
678 | 678 | p1=p1, p2=p2, wlock=wlock) |
|
679 | 679 | |
|
680 | 680 | def commit(self, files=None, text="", user=None, date=None, |
|
681 | 681 | match=util.always, force=False, lock=None, wlock=None, |
|
682 | 682 | force_editor=False, p1=None, p2=None, extra={}): |
|
683 | 683 | |
|
684 | 684 | commit = [] |
|
685 | 685 | remove = [] |
|
686 | 686 | changed = [] |
|
687 | 687 | use_dirstate = (p1 is None) # not rawcommit |
|
688 | 688 | extra = extra.copy() |
|
689 | 689 | |
|
690 | 690 | if use_dirstate: |
|
691 | 691 | if files: |
|
692 | 692 | for f in files: |
|
693 | 693 | s = self.dirstate.state(f) |
|
694 | 694 | if s in 'nmai': |
|
695 | 695 | commit.append(f) |
|
696 | 696 | elif s == 'r': |
|
697 | 697 | remove.append(f) |
|
698 | 698 | else: |
|
699 | 699 | self.ui.warn(_("%s not tracked!\n") % f) |
|
700 | 700 | else: |
|
701 | 701 | changes = self.status(match=match)[:5] |
|
702 | 702 | modified, added, removed, deleted, unknown = changes |
|
703 | 703 | commit = modified + added |
|
704 | 704 | remove = removed |
|
705 | 705 | else: |
|
706 | 706 | commit = files |
|
707 | 707 | |
|
708 | 708 | if use_dirstate: |
|
709 | 709 | p1, p2 = self.dirstate.parents() |
|
710 | 710 | update_dirstate = True |
|
711 | 711 | else: |
|
712 | 712 | p1, p2 = p1, p2 or nullid |
|
713 | 713 | update_dirstate = (self.dirstate.parents()[0] == p1) |
|
714 | 714 | |
|
715 | 715 | c1 = self.changelog.read(p1) |
|
716 | 716 | c2 = self.changelog.read(p2) |
|
717 | 717 | m1 = self.manifest.read(c1[0]).copy() |
|
718 | 718 | m2 = self.manifest.read(c2[0]) |
|
719 | 719 | |
|
720 | 720 | if use_dirstate: |
|
721 | 721 | branchname = self.workingctx().branch() |
|
722 | 722 | try: |
|
723 | 723 | branchname = branchname.decode('UTF-8').encode('UTF-8') |
|
724 | 724 | except UnicodeDecodeError: |
|
725 | 725 | raise util.Abort(_('branch name not in UTF-8!')) |
|
726 | 726 | else: |
|
727 | 727 | branchname = "" |
|
728 | 728 | |
|
729 | 729 | if use_dirstate: |
|
730 |
oldname = c1[5].get("branch" |
|
|
730 | oldname = c1[5].get("branch") or "default" # stored in UTF-8 | |
|
731 | 731 | if not commit and not remove and not force and p2 == nullid and \ |
|
732 | 732 | branchname == oldname: |
|
733 | 733 | self.ui.status(_("nothing changed\n")) |
|
734 | 734 | return None |
|
735 | 735 | |
|
736 | 736 | xp1 = hex(p1) |
|
737 | 737 | if p2 == nullid: xp2 = '' |
|
738 | 738 | else: xp2 = hex(p2) |
|
739 | 739 | |
|
740 | 740 | self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) |
|
741 | 741 | |
|
742 | 742 | if not wlock: |
|
743 | 743 | wlock = self.wlock() |
|
744 | 744 | if not lock: |
|
745 | 745 | lock = self.lock() |
|
746 | 746 | tr = self.transaction() |
|
747 | 747 | |
|
748 | 748 | # check in files |
|
749 | 749 | new = {} |
|
750 | 750 | linkrev = self.changelog.count() |
|
751 | 751 | commit.sort() |
|
752 | 752 | for f in commit: |
|
753 | 753 | self.ui.note(f + "\n") |
|
754 | 754 | try: |
|
755 | 755 | new[f] = self.filecommit(f, m1, m2, linkrev, tr, changed) |
|
756 | 756 | m1.set(f, util.is_exec(self.wjoin(f), m1.execf(f))) |
|
757 | 757 | except IOError: |
|
758 | 758 | if use_dirstate: |
|
759 | 759 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
760 | 760 | raise |
|
761 | 761 | else: |
|
762 | 762 | remove.append(f) |
|
763 | 763 | |
|
764 | 764 | # update manifest |
|
765 | 765 | m1.update(new) |
|
766 | 766 | remove.sort() |
|
767 | 767 | |
|
768 | 768 | for f in remove: |
|
769 | 769 | if f in m1: |
|
770 | 770 | del m1[f] |
|
771 | 771 | mn = self.manifest.add(m1, tr, linkrev, c1[0], c2[0], (new, remove)) |
|
772 | 772 | |
|
773 | 773 | # add changeset |
|
774 | 774 | new = new.keys() |
|
775 | 775 | new.sort() |
|
776 | 776 | |
|
777 | 777 | user = user or self.ui.username() |
|
778 | 778 | if not text or force_editor: |
|
779 | 779 | edittext = [] |
|
780 | 780 | if text: |
|
781 | 781 | edittext.append(text) |
|
782 | 782 | edittext.append("") |
|
783 | 783 | edittext.append("HG: user: %s" % user) |
|
784 | 784 | if p2 != nullid: |
|
785 | 785 | edittext.append("HG: branch merge") |
|
786 | 786 | edittext.extend(["HG: changed %s" % f for f in changed]) |
|
787 | 787 | edittext.extend(["HG: removed %s" % f for f in remove]) |
|
788 | 788 | if not changed and not remove: |
|
789 | 789 | edittext.append("HG: no files changed") |
|
790 | 790 | edittext.append("") |
|
791 | 791 | # run editor in the repository root |
|
792 | 792 | olddir = os.getcwd() |
|
793 | 793 | os.chdir(self.root) |
|
794 | 794 | text = self.ui.edit("\n".join(edittext), user) |
|
795 | 795 | os.chdir(olddir) |
|
796 | 796 | |
|
797 | 797 | lines = [line.rstrip() for line in text.rstrip().splitlines()] |
|
798 | 798 | while lines and not lines[0]: |
|
799 | 799 | del lines[0] |
|
800 | 800 | if not lines: |
|
801 | 801 | return None |
|
802 | 802 | text = '\n'.join(lines) |
|
803 | 803 | if branchname: |
|
804 | 804 | extra["branch"] = branchname |
|
805 | 805 | n = self.changelog.add(mn, changed + remove, text, tr, p1, p2, |
|
806 | 806 | user, date, extra) |
|
807 | 807 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
808 | 808 | parent2=xp2) |
|
809 | 809 | tr.close() |
|
810 | 810 | |
|
811 | 811 | if use_dirstate or update_dirstate: |
|
812 | 812 | self.dirstate.setparents(n) |
|
813 | 813 | if use_dirstate: |
|
814 | 814 | self.dirstate.update(new, "n") |
|
815 | 815 | self.dirstate.forget(remove) |
|
816 | 816 | |
|
817 | 817 | self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) |
|
818 | 818 | return n |
|
819 | 819 | |
|
820 | 820 | def walk(self, node=None, files=[], match=util.always, badmatch=None): |
|
821 | 821 | ''' |
|
822 | 822 | walk recursively through the directory tree or a given |
|
823 | 823 | changeset, finding all files matched by the match |
|
824 | 824 | function |
|
825 | 825 | |
|
826 | 826 | results are yielded in a tuple (src, filename), where src |
|
827 | 827 | is one of: |
|
828 | 828 | 'f' the file was found in the directory tree |
|
829 | 829 | 'm' the file was only in the dirstate and not in the tree |
|
830 | 830 | 'b' file was not found and matched badmatch |
|
831 | 831 | ''' |
|
832 | 832 | |
|
833 | 833 | if node: |
|
834 | 834 | fdict = dict.fromkeys(files) |
|
835 | 835 | for fn in self.manifest.read(self.changelog.read(node)[0]): |
|
836 | 836 | for ffn in fdict: |
|
837 | 837 | # match if the file is the exact name or a directory |
|
838 | 838 | if ffn == fn or fn.startswith("%s/" % ffn): |
|
839 | 839 | del fdict[ffn] |
|
840 | 840 | break |
|
841 | 841 | if match(fn): |
|
842 | 842 | yield 'm', fn |
|
843 | 843 | for fn in fdict: |
|
844 | 844 | if badmatch and badmatch(fn): |
|
845 | 845 | if match(fn): |
|
846 | 846 | yield 'b', fn |
|
847 | 847 | else: |
|
848 | 848 | self.ui.warn(_('%s: No such file in rev %s\n') % ( |
|
849 | 849 | util.pathto(self.getcwd(), fn), short(node))) |
|
850 | 850 | else: |
|
851 | 851 | for src, fn in self.dirstate.walk(files, match, badmatch=badmatch): |
|
852 | 852 | yield src, fn |
|
853 | 853 | |
|
854 | 854 | def status(self, node1=None, node2=None, files=[], match=util.always, |
|
855 | 855 | wlock=None, list_ignored=False, list_clean=False): |
|
856 | 856 | """return status of files between two nodes or node and working directory |
|
857 | 857 | |
|
858 | 858 | If node1 is None, use the first dirstate parent instead. |
|
859 | 859 | If node2 is None, compare node1 with working directory. |
|
860 | 860 | """ |
|
861 | 861 | |
|
862 | 862 | def fcmp(fn, mf): |
|
863 | 863 | t1 = self.wread(fn) |
|
864 | 864 | return self.file(fn).cmp(mf.get(fn, nullid), t1) |
|
865 | 865 | |
|
866 | 866 | def mfmatches(node): |
|
867 | 867 | change = self.changelog.read(node) |
|
868 | 868 | mf = self.manifest.read(change[0]).copy() |
|
869 | 869 | for fn in mf.keys(): |
|
870 | 870 | if not match(fn): |
|
871 | 871 | del mf[fn] |
|
872 | 872 | return mf |
|
873 | 873 | |
|
874 | 874 | modified, added, removed, deleted, unknown = [], [], [], [], [] |
|
875 | 875 | ignored, clean = [], [] |
|
876 | 876 | |
|
877 | 877 | compareworking = False |
|
878 | 878 | if not node1 or (not node2 and node1 == self.dirstate.parents()[0]): |
|
879 | 879 | compareworking = True |
|
880 | 880 | |
|
881 | 881 | if not compareworking: |
|
882 | 882 | # read the manifest from node1 before the manifest from node2, |
|
883 | 883 | # so that we'll hit the manifest cache if we're going through |
|
884 | 884 | # all the revisions in parent->child order. |
|
885 | 885 | mf1 = mfmatches(node1) |
|
886 | 886 | |
|
887 | 887 | # are we comparing the working directory? |
|
888 | 888 | if not node2: |
|
889 | 889 | if not wlock: |
|
890 | 890 | try: |
|
891 | 891 | wlock = self.wlock(wait=0) |
|
892 | 892 | except lock.LockException: |
|
893 | 893 | wlock = None |
|
894 | 894 | (lookup, modified, added, removed, deleted, unknown, |
|
895 | 895 | ignored, clean) = self.dirstate.status(files, match, |
|
896 | 896 | list_ignored, list_clean) |
|
897 | 897 | |
|
898 | 898 | # are we comparing working dir against its parent? |
|
899 | 899 | if compareworking: |
|
900 | 900 | if lookup: |
|
901 | 901 | # do a full compare of any files that might have changed |
|
902 | 902 | mf2 = mfmatches(self.dirstate.parents()[0]) |
|
903 | 903 | for f in lookup: |
|
904 | 904 | if fcmp(f, mf2): |
|
905 | 905 | modified.append(f) |
|
906 | 906 | else: |
|
907 | 907 | clean.append(f) |
|
908 | 908 | if wlock is not None: |
|
909 | 909 | self.dirstate.update([f], "n") |
|
910 | 910 | else: |
|
911 | 911 | # we are comparing working dir against non-parent |
|
912 | 912 | # generate a pseudo-manifest for the working dir |
|
913 | 913 | # XXX: create it in dirstate.py ? |
|
914 | 914 | mf2 = mfmatches(self.dirstate.parents()[0]) |
|
915 | 915 | for f in lookup + modified + added: |
|
916 | 916 | mf2[f] = "" |
|
917 | 917 | mf2.set(f, execf=util.is_exec(self.wjoin(f), mf2.execf(f))) |
|
918 | 918 | for f in removed: |
|
919 | 919 | if f in mf2: |
|
920 | 920 | del mf2[f] |
|
921 | 921 | else: |
|
922 | 922 | # we are comparing two revisions |
|
923 | 923 | mf2 = mfmatches(node2) |
|
924 | 924 | |
|
925 | 925 | if not compareworking: |
|
926 | 926 | # flush lists from dirstate before comparing manifests |
|
927 | 927 | modified, added, clean = [], [], [] |
|
928 | 928 | |
|
929 | 929 | # make sure to sort the files so we talk to the disk in a |
|
930 | 930 | # reasonable order |
|
931 | 931 | mf2keys = mf2.keys() |
|
932 | 932 | mf2keys.sort() |
|
933 | 933 | for fn in mf2keys: |
|
934 | 934 | if mf1.has_key(fn): |
|
935 | 935 | if mf1.flags(fn) != mf2.flags(fn) or \ |
|
936 | 936 | (mf1[fn] != mf2[fn] and (mf2[fn] != "" or fcmp(fn, mf1))): |
|
937 | 937 | modified.append(fn) |
|
938 | 938 | elif list_clean: |
|
939 | 939 | clean.append(fn) |
|
940 | 940 | del mf1[fn] |
|
941 | 941 | else: |
|
942 | 942 | added.append(fn) |
|
943 | 943 | |
|
944 | 944 | removed = mf1.keys() |
|
945 | 945 | |
|
946 | 946 | # sort and return results: |
|
947 | 947 | for l in modified, added, removed, deleted, unknown, ignored, clean: |
|
948 | 948 | l.sort() |
|
949 | 949 | return (modified, added, removed, deleted, unknown, ignored, clean) |
|
950 | 950 | |
|
951 | 951 | def add(self, list, wlock=None): |
|
952 | 952 | if not wlock: |
|
953 | 953 | wlock = self.wlock() |
|
954 | 954 | for f in list: |
|
955 | 955 | p = self.wjoin(f) |
|
956 | 956 | if not os.path.exists(p): |
|
957 | 957 | self.ui.warn(_("%s does not exist!\n") % f) |
|
958 | 958 | elif not os.path.isfile(p): |
|
959 | 959 | self.ui.warn(_("%s not added: only files supported currently\n") |
|
960 | 960 | % f) |
|
961 | 961 | elif self.dirstate.state(f) in 'an': |
|
962 | 962 | self.ui.warn(_("%s already tracked!\n") % f) |
|
963 | 963 | else: |
|
964 | 964 | self.dirstate.update([f], "a") |
|
965 | 965 | |
|
966 | 966 | def forget(self, list, wlock=None): |
|
967 | 967 | if not wlock: |
|
968 | 968 | wlock = self.wlock() |
|
969 | 969 | for f in list: |
|
970 | 970 | if self.dirstate.state(f) not in 'ai': |
|
971 | 971 | self.ui.warn(_("%s not added!\n") % f) |
|
972 | 972 | else: |
|
973 | 973 | self.dirstate.forget([f]) |
|
974 | 974 | |
|
975 | 975 | def remove(self, list, unlink=False, wlock=None): |
|
976 | 976 | if unlink: |
|
977 | 977 | for f in list: |
|
978 | 978 | try: |
|
979 | 979 | util.unlink(self.wjoin(f)) |
|
980 | 980 | except OSError, inst: |
|
981 | 981 | if inst.errno != errno.ENOENT: |
|
982 | 982 | raise |
|
983 | 983 | if not wlock: |
|
984 | 984 | wlock = self.wlock() |
|
985 | 985 | for f in list: |
|
986 | 986 | p = self.wjoin(f) |
|
987 | 987 | if os.path.exists(p): |
|
988 | 988 | self.ui.warn(_("%s still exists!\n") % f) |
|
989 | 989 | elif self.dirstate.state(f) == 'a': |
|
990 | 990 | self.dirstate.forget([f]) |
|
991 | 991 | elif f not in self.dirstate: |
|
992 | 992 | self.ui.warn(_("%s not tracked!\n") % f) |
|
993 | 993 | else: |
|
994 | 994 | self.dirstate.update([f], "r") |
|
995 | 995 | |
|
996 | 996 | def undelete(self, list, wlock=None): |
|
997 | 997 | p = self.dirstate.parents()[0] |
|
998 | 998 | mn = self.changelog.read(p)[0] |
|
999 | 999 | m = self.manifest.read(mn) |
|
1000 | 1000 | if not wlock: |
|
1001 | 1001 | wlock = self.wlock() |
|
1002 | 1002 | for f in list: |
|
1003 | 1003 | if self.dirstate.state(f) not in "r": |
|
1004 | 1004 | self.ui.warn("%s not removed!\n" % f) |
|
1005 | 1005 | else: |
|
1006 | 1006 | t = self.file(f).read(m[f]) |
|
1007 | 1007 | self.wwrite(f, t) |
|
1008 | 1008 | util.set_exec(self.wjoin(f), m.execf(f)) |
|
1009 | 1009 | self.dirstate.update([f], "n") |
|
1010 | 1010 | |
|
1011 | 1011 | def copy(self, source, dest, wlock=None): |
|
1012 | 1012 | p = self.wjoin(dest) |
|
1013 | 1013 | if not os.path.exists(p): |
|
1014 | 1014 | self.ui.warn(_("%s does not exist!\n") % dest) |
|
1015 | 1015 | elif not os.path.isfile(p): |
|
1016 | 1016 | self.ui.warn(_("copy failed: %s is not a file\n") % dest) |
|
1017 | 1017 | else: |
|
1018 | 1018 | if not wlock: |
|
1019 | 1019 | wlock = self.wlock() |
|
1020 | 1020 | if self.dirstate.state(dest) == '?': |
|
1021 | 1021 | self.dirstate.update([dest], "a") |
|
1022 | 1022 | self.dirstate.copy(source, dest) |
|
1023 | 1023 | |
|
1024 | 1024 | def heads(self, start=None): |
|
1025 | 1025 | heads = self.changelog.heads(start) |
|
1026 | 1026 | # sort the output in rev descending order |
|
1027 | 1027 | heads = [(-self.changelog.rev(h), h) for h in heads] |
|
1028 | 1028 | heads.sort() |
|
1029 | 1029 | return [n for (r, n) in heads] |
|
1030 | 1030 | |
|
1031 | 1031 | # branchlookup returns a dict giving a list of branches for |
|
1032 | 1032 | # each head. A branch is defined as the tag of a node or |
|
1033 | 1033 | # the branch of the node's parents. If a node has multiple |
|
1034 | 1034 | # branch tags, tags are eliminated if they are visible from other |
|
1035 | 1035 | # branch tags. |
|
1036 | 1036 | # |
|
1037 | 1037 | # So, for this graph: a->b->c->d->e |
|
1038 | 1038 | # \ / |
|
1039 | 1039 | # aa -----/ |
|
1040 | 1040 | # a has tag 2.6.12 |
|
1041 | 1041 | # d has tag 2.6.13 |
|
1042 | 1042 | # e would have branch tags for 2.6.12 and 2.6.13. Because the node |
|
1043 | 1043 | # for 2.6.12 can be reached from the node 2.6.13, that is eliminated |
|
1044 | 1044 | # from the list. |
|
1045 | 1045 | # |
|
1046 | 1046 | # It is possible that more than one head will have the same branch tag. |
|
1047 | 1047 | # callers need to check the result for multiple heads under the same |
|
1048 | 1048 | # branch tag if that is a problem for them (ie checkout of a specific |
|
1049 | 1049 | # branch). |
|
1050 | 1050 | # |
|
1051 | 1051 | # passing in a specific branch will limit the depth of the search |
|
1052 | 1052 | # through the parents. It won't limit the branches returned in the |
|
1053 | 1053 | # result though. |
|
1054 | 1054 | def branchlookup(self, heads=None, branch=None): |
|
1055 | 1055 | if not heads: |
|
1056 | 1056 | heads = self.heads() |
|
1057 | 1057 | headt = [ h for h in heads ] |
|
1058 | 1058 | chlog = self.changelog |
|
1059 | 1059 | branches = {} |
|
1060 | 1060 | merges = [] |
|
1061 | 1061 | seenmerge = {} |
|
1062 | 1062 | |
|
1063 | 1063 | # traverse the tree once for each head, recording in the branches |
|
1064 | 1064 | # dict which tags are visible from this head. The branches |
|
1065 | 1065 | # dict also records which tags are visible from each tag |
|
1066 | 1066 | # while we traverse. |
|
1067 | 1067 | while headt or merges: |
|
1068 | 1068 | if merges: |
|
1069 | 1069 | n, found = merges.pop() |
|
1070 | 1070 | visit = [n] |
|
1071 | 1071 | else: |
|
1072 | 1072 | h = headt.pop() |
|
1073 | 1073 | visit = [h] |
|
1074 | 1074 | found = [h] |
|
1075 | 1075 | seen = {} |
|
1076 | 1076 | while visit: |
|
1077 | 1077 | n = visit.pop() |
|
1078 | 1078 | if n in seen: |
|
1079 | 1079 | continue |
|
1080 | 1080 | pp = chlog.parents(n) |
|
1081 | 1081 | tags = self.nodetags(n) |
|
1082 | 1082 | if tags: |
|
1083 | 1083 | for x in tags: |
|
1084 | 1084 | if x == 'tip': |
|
1085 | 1085 | continue |
|
1086 | 1086 | for f in found: |
|
1087 | 1087 | branches.setdefault(f, {})[n] = 1 |
|
1088 | 1088 | branches.setdefault(n, {})[n] = 1 |
|
1089 | 1089 | break |
|
1090 | 1090 | if n not in found: |
|
1091 | 1091 | found.append(n) |
|
1092 | 1092 | if branch in tags: |
|
1093 | 1093 | continue |
|
1094 | 1094 | seen[n] = 1 |
|
1095 | 1095 | if pp[1] != nullid and n not in seenmerge: |
|
1096 | 1096 | merges.append((pp[1], [x for x in found])) |
|
1097 | 1097 | seenmerge[n] = 1 |
|
1098 | 1098 | if pp[0] != nullid: |
|
1099 | 1099 | visit.append(pp[0]) |
|
1100 | 1100 | # traverse the branches dict, eliminating branch tags from each |
|
1101 | 1101 | # head that are visible from another branch tag for that head. |
|
1102 | 1102 | out = {} |
|
1103 | 1103 | viscache = {} |
|
1104 | 1104 | for h in heads: |
|
1105 | 1105 | def visible(node): |
|
1106 | 1106 | if node in viscache: |
|
1107 | 1107 | return viscache[node] |
|
1108 | 1108 | ret = {} |
|
1109 | 1109 | visit = [node] |
|
1110 | 1110 | while visit: |
|
1111 | 1111 | x = visit.pop() |
|
1112 | 1112 | if x in viscache: |
|
1113 | 1113 | ret.update(viscache[x]) |
|
1114 | 1114 | elif x not in ret: |
|
1115 | 1115 | ret[x] = 1 |
|
1116 | 1116 | if x in branches: |
|
1117 | 1117 | visit[len(visit):] = branches[x].keys() |
|
1118 | 1118 | viscache[node] = ret |
|
1119 | 1119 | return ret |
|
1120 | 1120 | if h not in branches: |
|
1121 | 1121 | continue |
|
1122 | 1122 | # O(n^2), but somewhat limited. This only searches the |
|
1123 | 1123 | # tags visible from a specific head, not all the tags in the |
|
1124 | 1124 | # whole repo. |
|
1125 | 1125 | for b in branches[h]: |
|
1126 | 1126 | vis = False |
|
1127 | 1127 | for bb in branches[h].keys(): |
|
1128 | 1128 | if b != bb: |
|
1129 | 1129 | if b in visible(bb): |
|
1130 | 1130 | vis = True |
|
1131 | 1131 | break |
|
1132 | 1132 | if not vis: |
|
1133 | 1133 | l = out.setdefault(h, []) |
|
1134 | 1134 | l[len(l):] = self.nodetags(b) |
|
1135 | 1135 | return out |
|
1136 | 1136 | |
|
1137 | 1137 | def branches(self, nodes): |
|
1138 | 1138 | if not nodes: |
|
1139 | 1139 | nodes = [self.changelog.tip()] |
|
1140 | 1140 | b = [] |
|
1141 | 1141 | for n in nodes: |
|
1142 | 1142 | t = n |
|
1143 | 1143 | while 1: |
|
1144 | 1144 | p = self.changelog.parents(n) |
|
1145 | 1145 | if p[1] != nullid or p[0] == nullid: |
|
1146 | 1146 | b.append((t, n, p[0], p[1])) |
|
1147 | 1147 | break |
|
1148 | 1148 | n = p[0] |
|
1149 | 1149 | return b |
|
1150 | 1150 | |
|
1151 | 1151 | def between(self, pairs): |
|
1152 | 1152 | r = [] |
|
1153 | 1153 | |
|
1154 | 1154 | for top, bottom in pairs: |
|
1155 | 1155 | n, l, i = top, [], 0 |
|
1156 | 1156 | f = 1 |
|
1157 | 1157 | |
|
1158 | 1158 | while n != bottom: |
|
1159 | 1159 | p = self.changelog.parents(n)[0] |
|
1160 | 1160 | if i == f: |
|
1161 | 1161 | l.append(n) |
|
1162 | 1162 | f = f * 2 |
|
1163 | 1163 | n = p |
|
1164 | 1164 | i += 1 |
|
1165 | 1165 | |
|
1166 | 1166 | r.append(l) |
|
1167 | 1167 | |
|
1168 | 1168 | return r |
|
1169 | 1169 | |
|
1170 | 1170 | def findincoming(self, remote, base=None, heads=None, force=False): |
|
1171 | 1171 | """Return list of roots of the subsets of missing nodes from remote |
|
1172 | 1172 | |
|
1173 | 1173 | If base dict is specified, assume that these nodes and their parents |
|
1174 | 1174 | exist on the remote side and that no child of a node of base exists |
|
1175 | 1175 | in both remote and self. |
|
1176 | 1176 | Furthermore base will be updated to include the nodes that exists |
|
1177 | 1177 | in self and remote but no children exists in self and remote. |
|
1178 | 1178 | If a list of heads is specified, return only nodes which are heads |
|
1179 | 1179 | or ancestors of these heads. |
|
1180 | 1180 | |
|
1181 | 1181 | All the ancestors of base are in self and in remote. |
|
1182 | 1182 | All the descendants of the list returned are missing in self. |
|
1183 | 1183 | (and so we know that the rest of the nodes are missing in remote, see |
|
1184 | 1184 | outgoing) |
|
1185 | 1185 | """ |
|
1186 | 1186 | m = self.changelog.nodemap |
|
1187 | 1187 | search = [] |
|
1188 | 1188 | fetch = {} |
|
1189 | 1189 | seen = {} |
|
1190 | 1190 | seenbranch = {} |
|
1191 | 1191 | if base == None: |
|
1192 | 1192 | base = {} |
|
1193 | 1193 | |
|
1194 | 1194 | if not heads: |
|
1195 | 1195 | heads = remote.heads() |
|
1196 | 1196 | |
|
1197 | 1197 | if self.changelog.tip() == nullid: |
|
1198 | 1198 | base[nullid] = 1 |
|
1199 | 1199 | if heads != [nullid]: |
|
1200 | 1200 | return [nullid] |
|
1201 | 1201 | return [] |
|
1202 | 1202 | |
|
1203 | 1203 | # assume we're closer to the tip than the root |
|
1204 | 1204 | # and start by examining the heads |
|
1205 | 1205 | self.ui.status(_("searching for changes\n")) |
|
1206 | 1206 | |
|
1207 | 1207 | unknown = [] |
|
1208 | 1208 | for h in heads: |
|
1209 | 1209 | if h not in m: |
|
1210 | 1210 | unknown.append(h) |
|
1211 | 1211 | else: |
|
1212 | 1212 | base[h] = 1 |
|
1213 | 1213 | |
|
1214 | 1214 | if not unknown: |
|
1215 | 1215 | return [] |
|
1216 | 1216 | |
|
1217 | 1217 | req = dict.fromkeys(unknown) |
|
1218 | 1218 | reqcnt = 0 |
|
1219 | 1219 | |
|
1220 | 1220 | # search through remote branches |
|
1221 | 1221 | # a 'branch' here is a linear segment of history, with four parts: |
|
1222 | 1222 | # head, root, first parent, second parent |
|
1223 | 1223 | # (a branch always has two parents (or none) by definition) |
|
1224 | 1224 | unknown = remote.branches(unknown) |
|
1225 | 1225 | while unknown: |
|
1226 | 1226 | r = [] |
|
1227 | 1227 | while unknown: |
|
1228 | 1228 | n = unknown.pop(0) |
|
1229 | 1229 | if n[0] in seen: |
|
1230 | 1230 | continue |
|
1231 | 1231 | |
|
1232 | 1232 | self.ui.debug(_("examining %s:%s\n") |
|
1233 | 1233 | % (short(n[0]), short(n[1]))) |
|
1234 | 1234 | if n[0] == nullid: # found the end of the branch |
|
1235 | 1235 | pass |
|
1236 | 1236 | elif n in seenbranch: |
|
1237 | 1237 | self.ui.debug(_("branch already found\n")) |
|
1238 | 1238 | continue |
|
1239 | 1239 | elif n[1] and n[1] in m: # do we know the base? |
|
1240 | 1240 | self.ui.debug(_("found incomplete branch %s:%s\n") |
|
1241 | 1241 | % (short(n[0]), short(n[1]))) |
|
1242 | 1242 | search.append(n) # schedule branch range for scanning |
|
1243 | 1243 | seenbranch[n] = 1 |
|
1244 | 1244 | else: |
|
1245 | 1245 | if n[1] not in seen and n[1] not in fetch: |
|
1246 | 1246 | if n[2] in m and n[3] in m: |
|
1247 | 1247 | self.ui.debug(_("found new changeset %s\n") % |
|
1248 | 1248 | short(n[1])) |
|
1249 | 1249 | fetch[n[1]] = 1 # earliest unknown |
|
1250 | 1250 | for p in n[2:4]: |
|
1251 | 1251 | if p in m: |
|
1252 | 1252 | base[p] = 1 # latest known |
|
1253 | 1253 | |
|
1254 | 1254 | for p in n[2:4]: |
|
1255 | 1255 | if p not in req and p not in m: |
|
1256 | 1256 | r.append(p) |
|
1257 | 1257 | req[p] = 1 |
|
1258 | 1258 | seen[n[0]] = 1 |
|
1259 | 1259 | |
|
1260 | 1260 | if r: |
|
1261 | 1261 | reqcnt += 1 |
|
1262 | 1262 | self.ui.debug(_("request %d: %s\n") % |
|
1263 | 1263 | (reqcnt, " ".join(map(short, r)))) |
|
1264 | 1264 | for p in xrange(0, len(r), 10): |
|
1265 | 1265 | for b in remote.branches(r[p:p+10]): |
|
1266 | 1266 | self.ui.debug(_("received %s:%s\n") % |
|
1267 | 1267 | (short(b[0]), short(b[1]))) |
|
1268 | 1268 | unknown.append(b) |
|
1269 | 1269 | |
|
1270 | 1270 | # do binary search on the branches we found |
|
1271 | 1271 | while search: |
|
1272 | 1272 | n = search.pop(0) |
|
1273 | 1273 | reqcnt += 1 |
|
1274 | 1274 | l = remote.between([(n[0], n[1])])[0] |
|
1275 | 1275 | l.append(n[1]) |
|
1276 | 1276 | p = n[0] |
|
1277 | 1277 | f = 1 |
|
1278 | 1278 | for i in l: |
|
1279 | 1279 | self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i))) |
|
1280 | 1280 | if i in m: |
|
1281 | 1281 | if f <= 2: |
|
1282 | 1282 | self.ui.debug(_("found new branch changeset %s\n") % |
|
1283 | 1283 | short(p)) |
|
1284 | 1284 | fetch[p] = 1 |
|
1285 | 1285 | base[i] = 1 |
|
1286 | 1286 | else: |
|
1287 | 1287 | self.ui.debug(_("narrowed branch search to %s:%s\n") |
|
1288 | 1288 | % (short(p), short(i))) |
|
1289 | 1289 | search.append((p, i)) |
|
1290 | 1290 | break |
|
1291 | 1291 | p, f = i, f * 2 |
|
1292 | 1292 | |
|
1293 | 1293 | # sanity check our fetch list |
|
1294 | 1294 | for f in fetch.keys(): |
|
1295 | 1295 | if f in m: |
|
1296 | 1296 | raise repo.RepoError(_("already have changeset ") + short(f[:4])) |
|
1297 | 1297 | |
|
1298 | 1298 | if base.keys() == [nullid]: |
|
1299 | 1299 | if force: |
|
1300 | 1300 | self.ui.warn(_("warning: repository is unrelated\n")) |
|
1301 | 1301 | else: |
|
1302 | 1302 | raise util.Abort(_("repository is unrelated")) |
|
1303 | 1303 | |
|
1304 | 1304 | self.ui.debug(_("found new changesets starting at ") + |
|
1305 | 1305 | " ".join([short(f) for f in fetch]) + "\n") |
|
1306 | 1306 | |
|
1307 | 1307 | self.ui.debug(_("%d total queries\n") % reqcnt) |
|
1308 | 1308 | |
|
1309 | 1309 | return fetch.keys() |
|
1310 | 1310 | |
|
1311 | 1311 | def findoutgoing(self, remote, base=None, heads=None, force=False): |
|
1312 | 1312 | """Return list of nodes that are roots of subsets not in remote |
|
1313 | 1313 | |
|
1314 | 1314 | If base dict is specified, assume that these nodes and their parents |
|
1315 | 1315 | exist on the remote side. |
|
1316 | 1316 | If a list of heads is specified, return only nodes which are heads |
|
1317 | 1317 | or ancestors of these heads, and return a second element which |
|
1318 | 1318 | contains all remote heads which get new children. |
|
1319 | 1319 | """ |
|
1320 | 1320 | if base == None: |
|
1321 | 1321 | base = {} |
|
1322 | 1322 | self.findincoming(remote, base, heads, force=force) |
|
1323 | 1323 | |
|
1324 | 1324 | self.ui.debug(_("common changesets up to ") |
|
1325 | 1325 | + " ".join(map(short, base.keys())) + "\n") |
|
1326 | 1326 | |
|
1327 | 1327 | remain = dict.fromkeys(self.changelog.nodemap) |
|
1328 | 1328 | |
|
1329 | 1329 | # prune everything remote has from the tree |
|
1330 | 1330 | del remain[nullid] |
|
1331 | 1331 | remove = base.keys() |
|
1332 | 1332 | while remove: |
|
1333 | 1333 | n = remove.pop(0) |
|
1334 | 1334 | if n in remain: |
|
1335 | 1335 | del remain[n] |
|
1336 | 1336 | for p in self.changelog.parents(n): |
|
1337 | 1337 | remove.append(p) |
|
1338 | 1338 | |
|
1339 | 1339 | # find every node whose parents have been pruned |
|
1340 | 1340 | subset = [] |
|
1341 | 1341 | # find every remote head that will get new children |
|
1342 | 1342 | updated_heads = {} |
|
1343 | 1343 | for n in remain: |
|
1344 | 1344 | p1, p2 = self.changelog.parents(n) |
|
1345 | 1345 | if p1 not in remain and p2 not in remain: |
|
1346 | 1346 | subset.append(n) |
|
1347 | 1347 | if heads: |
|
1348 | 1348 | if p1 in heads: |
|
1349 | 1349 | updated_heads[p1] = True |
|
1350 | 1350 | if p2 in heads: |
|
1351 | 1351 | updated_heads[p2] = True |
|
1352 | 1352 | |
|
1353 | 1353 | # this is the set of all roots we have to push |
|
1354 | 1354 | if heads: |
|
1355 | 1355 | return subset, updated_heads.keys() |
|
1356 | 1356 | else: |
|
1357 | 1357 | return subset |
|
1358 | 1358 | |
|
1359 | 1359 | def pull(self, remote, heads=None, force=False, lock=None): |
|
1360 | 1360 | mylock = False |
|
1361 | 1361 | if not lock: |
|
1362 | 1362 | lock = self.lock() |
|
1363 | 1363 | mylock = True |
|
1364 | 1364 | |
|
1365 | 1365 | try: |
|
1366 | 1366 | fetch = self.findincoming(remote, force=force) |
|
1367 | 1367 | if fetch == [nullid]: |
|
1368 | 1368 | self.ui.status(_("requesting all changes\n")) |
|
1369 | 1369 | |
|
1370 | 1370 | if not fetch: |
|
1371 | 1371 | self.ui.status(_("no changes found\n")) |
|
1372 | 1372 | return 0 |
|
1373 | 1373 | |
|
1374 | 1374 | if heads is None: |
|
1375 | 1375 | cg = remote.changegroup(fetch, 'pull') |
|
1376 | 1376 | else: |
|
1377 | 1377 | if 'changegroupsubset' not in remote.capabilities: |
|
1378 | 1378 | raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset.")) |
|
1379 | 1379 | cg = remote.changegroupsubset(fetch, heads, 'pull') |
|
1380 | 1380 | return self.addchangegroup(cg, 'pull', remote.url()) |
|
1381 | 1381 | finally: |
|
1382 | 1382 | if mylock: |
|
1383 | 1383 | lock.release() |
|
1384 | 1384 | |
|
1385 | 1385 | def push(self, remote, force=False, revs=None): |
|
1386 | 1386 | # there are two ways to push to remote repo: |
|
1387 | 1387 | # |
|
1388 | 1388 | # addchangegroup assumes local user can lock remote |
|
1389 | 1389 | # repo (local filesystem, old ssh servers). |
|
1390 | 1390 | # |
|
1391 | 1391 | # unbundle assumes local user cannot lock remote repo (new ssh |
|
1392 | 1392 | # servers, http servers). |
|
1393 | 1393 | |
|
1394 | 1394 | if remote.capable('unbundle'): |
|
1395 | 1395 | return self.push_unbundle(remote, force, revs) |
|
1396 | 1396 | return self.push_addchangegroup(remote, force, revs) |
|
1397 | 1397 | |
|
1398 | 1398 | def prepush(self, remote, force, revs): |
|
1399 | 1399 | base = {} |
|
1400 | 1400 | remote_heads = remote.heads() |
|
1401 | 1401 | inc = self.findincoming(remote, base, remote_heads, force=force) |
|
1402 | 1402 | |
|
1403 | 1403 | update, updated_heads = self.findoutgoing(remote, base, remote_heads) |
|
1404 | 1404 | if revs is not None: |
|
1405 | 1405 | msng_cl, bases, heads = self.changelog.nodesbetween(update, revs) |
|
1406 | 1406 | else: |
|
1407 | 1407 | bases, heads = update, self.changelog.heads() |
|
1408 | 1408 | |
|
1409 | 1409 | if not bases: |
|
1410 | 1410 | self.ui.status(_("no changes found\n")) |
|
1411 | 1411 | return None, 1 |
|
1412 | 1412 | elif not force: |
|
1413 | 1413 | # check if we're creating new remote heads |
|
1414 | 1414 | # to be a remote head after push, node must be either |
|
1415 | 1415 | # - unknown locally |
|
1416 | 1416 | # - a local outgoing head descended from update |
|
1417 | 1417 | # - a remote head that's known locally and not |
|
1418 | 1418 | # ancestral to an outgoing head |
|
1419 | 1419 | |
|
1420 | 1420 | warn = 0 |
|
1421 | 1421 | |
|
1422 | 1422 | if remote_heads == [nullid]: |
|
1423 | 1423 | warn = 0 |
|
1424 | 1424 | elif not revs and len(heads) > len(remote_heads): |
|
1425 | 1425 | warn = 1 |
|
1426 | 1426 | else: |
|
1427 | 1427 | newheads = list(heads) |
|
1428 | 1428 | for r in remote_heads: |
|
1429 | 1429 | if r in self.changelog.nodemap: |
|
1430 | 1430 | desc = self.changelog.heads(r, heads) |
|
1431 | 1431 | l = [h for h in heads if h in desc] |
|
1432 | 1432 | if not l: |
|
1433 | 1433 | newheads.append(r) |
|
1434 | 1434 | else: |
|
1435 | 1435 | newheads.append(r) |
|
1436 | 1436 | if len(newheads) > len(remote_heads): |
|
1437 | 1437 | warn = 1 |
|
1438 | 1438 | |
|
1439 | 1439 | if warn: |
|
1440 | 1440 | self.ui.warn(_("abort: push creates new remote branches!\n")) |
|
1441 | 1441 | self.ui.status(_("(did you forget to merge?" |
|
1442 | 1442 | " use push -f to force)\n")) |
|
1443 | 1443 | return None, 1 |
|
1444 | 1444 | elif inc: |
|
1445 | 1445 | self.ui.warn(_("note: unsynced remote changes!\n")) |
|
1446 | 1446 | |
|
1447 | 1447 | |
|
1448 | 1448 | if revs is None: |
|
1449 | 1449 | cg = self.changegroup(update, 'push') |
|
1450 | 1450 | else: |
|
1451 | 1451 | cg = self.changegroupsubset(update, revs, 'push') |
|
1452 | 1452 | return cg, remote_heads |
|
1453 | 1453 | |
|
1454 | 1454 | def push_addchangegroup(self, remote, force, revs): |
|
1455 | 1455 | lock = remote.lock() |
|
1456 | 1456 | |
|
1457 | 1457 | ret = self.prepush(remote, force, revs) |
|
1458 | 1458 | if ret[0] is not None: |
|
1459 | 1459 | cg, remote_heads = ret |
|
1460 | 1460 | return remote.addchangegroup(cg, 'push', self.url()) |
|
1461 | 1461 | return ret[1] |
|
1462 | 1462 | |
|
1463 | 1463 | def push_unbundle(self, remote, force, revs): |
|
1464 | 1464 | # local repo finds heads on server, finds out what revs it |
|
1465 | 1465 | # must push. once revs transferred, if server finds it has |
|
1466 | 1466 | # different heads (someone else won commit/push race), server |
|
1467 | 1467 | # aborts. |
|
1468 | 1468 | |
|
1469 | 1469 | ret = self.prepush(remote, force, revs) |
|
1470 | 1470 | if ret[0] is not None: |
|
1471 | 1471 | cg, remote_heads = ret |
|
1472 | 1472 | if force: remote_heads = ['force'] |
|
1473 | 1473 | return remote.unbundle(cg, remote_heads, 'push') |
|
1474 | 1474 | return ret[1] |
|
1475 | 1475 | |
|
1476 | 1476 | def changegroupinfo(self, nodes): |
|
1477 | 1477 | self.ui.note(_("%d changesets found\n") % len(nodes)) |
|
1478 | 1478 | if self.ui.debugflag: |
|
1479 | 1479 | self.ui.debug(_("List of changesets:\n")) |
|
1480 | 1480 | for node in nodes: |
|
1481 | 1481 | self.ui.debug("%s\n" % hex(node)) |
|
1482 | 1482 | |
|
1483 | 1483 | def changegroupsubset(self, bases, heads, source): |
|
1484 | 1484 | """This function generates a changegroup consisting of all the nodes |
|
1485 | 1485 | that are descendents of any of the bases, and ancestors of any of |
|
1486 | 1486 | the heads. |
|
1487 | 1487 | |
|
1488 | 1488 | It is fairly complex as determining which filenodes and which |
|
1489 | 1489 | manifest nodes need to be included for the changeset to be complete |
|
1490 | 1490 | is non-trivial. |
|
1491 | 1491 | |
|
1492 | 1492 | Another wrinkle is doing the reverse, figuring out which changeset in |
|
1493 | 1493 | the changegroup a particular filenode or manifestnode belongs to.""" |
|
1494 | 1494 | |
|
1495 | 1495 | self.hook('preoutgoing', throw=True, source=source) |
|
1496 | 1496 | |
|
1497 | 1497 | # Set up some initial variables |
|
1498 | 1498 | # Make it easy to refer to self.changelog |
|
1499 | 1499 | cl = self.changelog |
|
1500 | 1500 | # msng is short for missing - compute the list of changesets in this |
|
1501 | 1501 | # changegroup. |
|
1502 | 1502 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) |
|
1503 | 1503 | self.changegroupinfo(msng_cl_lst) |
|
1504 | 1504 | # Some bases may turn out to be superfluous, and some heads may be |
|
1505 | 1505 | # too. nodesbetween will return the minimal set of bases and heads |
|
1506 | 1506 | # necessary to re-create the changegroup. |
|
1507 | 1507 | |
|
1508 | 1508 | # Known heads are the list of heads that it is assumed the recipient |
|
1509 | 1509 | # of this changegroup will know about. |
|
1510 | 1510 | knownheads = {} |
|
1511 | 1511 | # We assume that all parents of bases are known heads. |
|
1512 | 1512 | for n in bases: |
|
1513 | 1513 | for p in cl.parents(n): |
|
1514 | 1514 | if p != nullid: |
|
1515 | 1515 | knownheads[p] = 1 |
|
1516 | 1516 | knownheads = knownheads.keys() |
|
1517 | 1517 | if knownheads: |
|
1518 | 1518 | # Now that we know what heads are known, we can compute which |
|
1519 | 1519 | # changesets are known. The recipient must know about all |
|
1520 | 1520 | # changesets required to reach the known heads from the null |
|
1521 | 1521 | # changeset. |
|
1522 | 1522 | has_cl_set, junk, junk = cl.nodesbetween(None, knownheads) |
|
1523 | 1523 | junk = None |
|
1524 | 1524 | # Transform the list into an ersatz set. |
|
1525 | 1525 | has_cl_set = dict.fromkeys(has_cl_set) |
|
1526 | 1526 | else: |
|
1527 | 1527 | # If there were no known heads, the recipient cannot be assumed to |
|
1528 | 1528 | # know about any changesets. |
|
1529 | 1529 | has_cl_set = {} |
|
1530 | 1530 | |
|
1531 | 1531 | # Make it easy to refer to self.manifest |
|
1532 | 1532 | mnfst = self.manifest |
|
1533 | 1533 | # We don't know which manifests are missing yet |
|
1534 | 1534 | msng_mnfst_set = {} |
|
1535 | 1535 | # Nor do we know which filenodes are missing. |
|
1536 | 1536 | msng_filenode_set = {} |
|
1537 | 1537 | |
|
1538 | 1538 | junk = mnfst.index[mnfst.count() - 1] # Get around a bug in lazyindex |
|
1539 | 1539 | junk = None |
|
1540 | 1540 | |
|
1541 | 1541 | # A changeset always belongs to itself, so the changenode lookup |
|
1542 | 1542 | # function for a changenode is identity. |
|
1543 | 1543 | def identity(x): |
|
1544 | 1544 | return x |
|
1545 | 1545 | |
|
1546 | 1546 | # A function generating function. Sets up an environment for the |
|
1547 | 1547 | # inner function. |
|
1548 | 1548 | def cmp_by_rev_func(revlog): |
|
1549 | 1549 | # Compare two nodes by their revision number in the environment's |
|
1550 | 1550 | # revision history. Since the revision number both represents the |
|
1551 | 1551 | # most efficient order to read the nodes in, and represents a |
|
1552 | 1552 | # topological sorting of the nodes, this function is often useful. |
|
1553 | 1553 | def cmp_by_rev(a, b): |
|
1554 | 1554 | return cmp(revlog.rev(a), revlog.rev(b)) |
|
1555 | 1555 | return cmp_by_rev |
|
1556 | 1556 | |
|
1557 | 1557 | # If we determine that a particular file or manifest node must be a |
|
1558 | 1558 | # node that the recipient of the changegroup will already have, we can |
|
1559 | 1559 | # also assume the recipient will have all the parents. This function |
|
1560 | 1560 | # prunes them from the set of missing nodes. |
|
1561 | 1561 | def prune_parents(revlog, hasset, msngset): |
|
1562 | 1562 | haslst = hasset.keys() |
|
1563 | 1563 | haslst.sort(cmp_by_rev_func(revlog)) |
|
1564 | 1564 | for node in haslst: |
|
1565 | 1565 | parentlst = [p for p in revlog.parents(node) if p != nullid] |
|
1566 | 1566 | while parentlst: |
|
1567 | 1567 | n = parentlst.pop() |
|
1568 | 1568 | if n not in hasset: |
|
1569 | 1569 | hasset[n] = 1 |
|
1570 | 1570 | p = [p for p in revlog.parents(n) if p != nullid] |
|
1571 | 1571 | parentlst.extend(p) |
|
1572 | 1572 | for n in hasset: |
|
1573 | 1573 | msngset.pop(n, None) |
|
1574 | 1574 | |
|
1575 | 1575 | # This is a function generating function used to set up an environment |
|
1576 | 1576 | # for the inner function to execute in. |
|
1577 | 1577 | def manifest_and_file_collector(changedfileset): |
|
1578 | 1578 | # This is an information gathering function that gathers |
|
1579 | 1579 | # information from each changeset node that goes out as part of |
|
1580 | 1580 | # the changegroup. The information gathered is a list of which |
|
1581 | 1581 | # manifest nodes are potentially required (the recipient may |
|
1582 | 1582 | # already have them) and total list of all files which were |
|
1583 | 1583 | # changed in any changeset in the changegroup. |
|
1584 | 1584 | # |
|
1585 | 1585 | # We also remember the first changenode we saw any manifest |
|
1586 | 1586 | # referenced by so we can later determine which changenode 'owns' |
|
1587 | 1587 | # the manifest. |
|
1588 | 1588 | def collect_manifests_and_files(clnode): |
|
1589 | 1589 | c = cl.read(clnode) |
|
1590 | 1590 | for f in c[3]: |
|
1591 | 1591 | # This is to make sure we only have one instance of each |
|
1592 | 1592 | # filename string for each filename. |
|
1593 | 1593 | changedfileset.setdefault(f, f) |
|
1594 | 1594 | msng_mnfst_set.setdefault(c[0], clnode) |
|
1595 | 1595 | return collect_manifests_and_files |
|
1596 | 1596 | |
|
1597 | 1597 | # Figure out which manifest nodes (of the ones we think might be part |
|
1598 | 1598 | # of the changegroup) the recipient must know about and remove them |
|
1599 | 1599 | # from the changegroup. |
|
1600 | 1600 | def prune_manifests(): |
|
1601 | 1601 | has_mnfst_set = {} |
|
1602 | 1602 | for n in msng_mnfst_set: |
|
1603 | 1603 | # If a 'missing' manifest thinks it belongs to a changenode |
|
1604 | 1604 | # the recipient is assumed to have, obviously the recipient |
|
1605 | 1605 | # must have that manifest. |
|
1606 | 1606 | linknode = cl.node(mnfst.linkrev(n)) |
|
1607 | 1607 | if linknode in has_cl_set: |
|
1608 | 1608 | has_mnfst_set[n] = 1 |
|
1609 | 1609 | prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) |
|
1610 | 1610 | |
|
1611 | 1611 | # Use the information collected in collect_manifests_and_files to say |
|
1612 | 1612 | # which changenode any manifestnode belongs to. |
|
1613 | 1613 | def lookup_manifest_link(mnfstnode): |
|
1614 | 1614 | return msng_mnfst_set[mnfstnode] |
|
1615 | 1615 | |
|
1616 | 1616 | # A function generating function that sets up the initial environment |
|
1617 | 1617 | # the inner function. |
|
1618 | 1618 | def filenode_collector(changedfiles): |
|
1619 | 1619 | next_rev = [0] |
|
1620 | 1620 | # This gathers information from each manifestnode included in the |
|
1621 | 1621 | # changegroup about which filenodes the manifest node references |
|
1622 | 1622 | # so we can include those in the changegroup too. |
|
1623 | 1623 | # |
|
1624 | 1624 | # It also remembers which changenode each filenode belongs to. It |
|
1625 | 1625 | # does this by assuming the a filenode belongs to the changenode |
|
1626 | 1626 | # the first manifest that references it belongs to. |
|
1627 | 1627 | def collect_msng_filenodes(mnfstnode): |
|
1628 | 1628 | r = mnfst.rev(mnfstnode) |
|
1629 | 1629 | if r == next_rev[0]: |
|
1630 | 1630 | # If the last rev we looked at was the one just previous, |
|
1631 | 1631 | # we only need to see a diff. |
|
1632 | 1632 | delta = mdiff.patchtext(mnfst.delta(mnfstnode)) |
|
1633 | 1633 | # For each line in the delta |
|
1634 | 1634 | for dline in delta.splitlines(): |
|
1635 | 1635 | # get the filename and filenode for that line |
|
1636 | 1636 | f, fnode = dline.split('\0') |
|
1637 | 1637 | fnode = bin(fnode[:40]) |
|
1638 | 1638 | f = changedfiles.get(f, None) |
|
1639 | 1639 | # And if the file is in the list of files we care |
|
1640 | 1640 | # about. |
|
1641 | 1641 | if f is not None: |
|
1642 | 1642 | # Get the changenode this manifest belongs to |
|
1643 | 1643 | clnode = msng_mnfst_set[mnfstnode] |
|
1644 | 1644 | # Create the set of filenodes for the file if |
|
1645 | 1645 | # there isn't one already. |
|
1646 | 1646 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1647 | 1647 | # And set the filenode's changelog node to the |
|
1648 | 1648 | # manifest's if it hasn't been set already. |
|
1649 | 1649 | ndset.setdefault(fnode, clnode) |
|
1650 | 1650 | else: |
|
1651 | 1651 | # Otherwise we need a full manifest. |
|
1652 | 1652 | m = mnfst.read(mnfstnode) |
|
1653 | 1653 | # For every file in we care about. |
|
1654 | 1654 | for f in changedfiles: |
|
1655 | 1655 | fnode = m.get(f, None) |
|
1656 | 1656 | # If it's in the manifest |
|
1657 | 1657 | if fnode is not None: |
|
1658 | 1658 | # See comments above. |
|
1659 | 1659 | clnode = msng_mnfst_set[mnfstnode] |
|
1660 | 1660 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1661 | 1661 | ndset.setdefault(fnode, clnode) |
|
1662 | 1662 | # Remember the revision we hope to see next. |
|
1663 | 1663 | next_rev[0] = r + 1 |
|
1664 | 1664 | return collect_msng_filenodes |
|
1665 | 1665 | |
|
1666 | 1666 | # We have a list of filenodes we think we need for a file, lets remove |
|
1667 | 1667 | # all those we now the recipient must have. |
|
1668 | 1668 | def prune_filenodes(f, filerevlog): |
|
1669 | 1669 | msngset = msng_filenode_set[f] |
|
1670 | 1670 | hasset = {} |
|
1671 | 1671 | # If a 'missing' filenode thinks it belongs to a changenode we |
|
1672 | 1672 | # assume the recipient must have, then the recipient must have |
|
1673 | 1673 | # that filenode. |
|
1674 | 1674 | for n in msngset: |
|
1675 | 1675 | clnode = cl.node(filerevlog.linkrev(n)) |
|
1676 | 1676 | if clnode in has_cl_set: |
|
1677 | 1677 | hasset[n] = 1 |
|
1678 | 1678 | prune_parents(filerevlog, hasset, msngset) |
|
1679 | 1679 | |
|
1680 | 1680 | # A function generator function that sets up the a context for the |
|
1681 | 1681 | # inner function. |
|
1682 | 1682 | def lookup_filenode_link_func(fname): |
|
1683 | 1683 | msngset = msng_filenode_set[fname] |
|
1684 | 1684 | # Lookup the changenode the filenode belongs to. |
|
1685 | 1685 | def lookup_filenode_link(fnode): |
|
1686 | 1686 | return msngset[fnode] |
|
1687 | 1687 | return lookup_filenode_link |
|
1688 | 1688 | |
|
1689 | 1689 | # Now that we have all theses utility functions to help out and |
|
1690 | 1690 | # logically divide up the task, generate the group. |
|
1691 | 1691 | def gengroup(): |
|
1692 | 1692 | # The set of changed files starts empty. |
|
1693 | 1693 | changedfiles = {} |
|
1694 | 1694 | # Create a changenode group generator that will call our functions |
|
1695 | 1695 | # back to lookup the owning changenode and collect information. |
|
1696 | 1696 | group = cl.group(msng_cl_lst, identity, |
|
1697 | 1697 | manifest_and_file_collector(changedfiles)) |
|
1698 | 1698 | for chnk in group: |
|
1699 | 1699 | yield chnk |
|
1700 | 1700 | |
|
1701 | 1701 | # The list of manifests has been collected by the generator |
|
1702 | 1702 | # calling our functions back. |
|
1703 | 1703 | prune_manifests() |
|
1704 | 1704 | msng_mnfst_lst = msng_mnfst_set.keys() |
|
1705 | 1705 | # Sort the manifestnodes by revision number. |
|
1706 | 1706 | msng_mnfst_lst.sort(cmp_by_rev_func(mnfst)) |
|
1707 | 1707 | # Create a generator for the manifestnodes that calls our lookup |
|
1708 | 1708 | # and data collection functions back. |
|
1709 | 1709 | group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, |
|
1710 | 1710 | filenode_collector(changedfiles)) |
|
1711 | 1711 | for chnk in group: |
|
1712 | 1712 | yield chnk |
|
1713 | 1713 | |
|
1714 | 1714 | # These are no longer needed, dereference and toss the memory for |
|
1715 | 1715 | # them. |
|
1716 | 1716 | msng_mnfst_lst = None |
|
1717 | 1717 | msng_mnfst_set.clear() |
|
1718 | 1718 | |
|
1719 | 1719 | changedfiles = changedfiles.keys() |
|
1720 | 1720 | changedfiles.sort() |
|
1721 | 1721 | # Go through all our files in order sorted by name. |
|
1722 | 1722 | for fname in changedfiles: |
|
1723 | 1723 | filerevlog = self.file(fname) |
|
1724 | 1724 | # Toss out the filenodes that the recipient isn't really |
|
1725 | 1725 | # missing. |
|
1726 | 1726 | if msng_filenode_set.has_key(fname): |
|
1727 | 1727 | prune_filenodes(fname, filerevlog) |
|
1728 | 1728 | msng_filenode_lst = msng_filenode_set[fname].keys() |
|
1729 | 1729 | else: |
|
1730 | 1730 | msng_filenode_lst = [] |
|
1731 | 1731 | # If any filenodes are left, generate the group for them, |
|
1732 | 1732 | # otherwise don't bother. |
|
1733 | 1733 | if len(msng_filenode_lst) > 0: |
|
1734 | 1734 | yield changegroup.genchunk(fname) |
|
1735 | 1735 | # Sort the filenodes by their revision # |
|
1736 | 1736 | msng_filenode_lst.sort(cmp_by_rev_func(filerevlog)) |
|
1737 | 1737 | # Create a group generator and only pass in a changenode |
|
1738 | 1738 | # lookup function as we need to collect no information |
|
1739 | 1739 | # from filenodes. |
|
1740 | 1740 | group = filerevlog.group(msng_filenode_lst, |
|
1741 | 1741 | lookup_filenode_link_func(fname)) |
|
1742 | 1742 | for chnk in group: |
|
1743 | 1743 | yield chnk |
|
1744 | 1744 | if msng_filenode_set.has_key(fname): |
|
1745 | 1745 | # Don't need this anymore, toss it to free memory. |
|
1746 | 1746 | del msng_filenode_set[fname] |
|
1747 | 1747 | # Signal that no more groups are left. |
|
1748 | 1748 | yield changegroup.closechunk() |
|
1749 | 1749 | |
|
1750 | 1750 | if msng_cl_lst: |
|
1751 | 1751 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) |
|
1752 | 1752 | |
|
1753 | 1753 | return util.chunkbuffer(gengroup()) |
|
1754 | 1754 | |
|
1755 | 1755 | def changegroup(self, basenodes, source): |
|
1756 | 1756 | """Generate a changegroup of all nodes that we have that a recipient |
|
1757 | 1757 | doesn't. |
|
1758 | 1758 | |
|
1759 | 1759 | This is much easier than the previous function as we can assume that |
|
1760 | 1760 | the recipient has any changenode we aren't sending them.""" |
|
1761 | 1761 | |
|
1762 | 1762 | self.hook('preoutgoing', throw=True, source=source) |
|
1763 | 1763 | |
|
1764 | 1764 | cl = self.changelog |
|
1765 | 1765 | nodes = cl.nodesbetween(basenodes, None)[0] |
|
1766 | 1766 | revset = dict.fromkeys([cl.rev(n) for n in nodes]) |
|
1767 | 1767 | self.changegroupinfo(nodes) |
|
1768 | 1768 | |
|
1769 | 1769 | def identity(x): |
|
1770 | 1770 | return x |
|
1771 | 1771 | |
|
1772 | 1772 | def gennodelst(revlog): |
|
1773 | 1773 | for r in xrange(0, revlog.count()): |
|
1774 | 1774 | n = revlog.node(r) |
|
1775 | 1775 | if revlog.linkrev(n) in revset: |
|
1776 | 1776 | yield n |
|
1777 | 1777 | |
|
1778 | 1778 | def changed_file_collector(changedfileset): |
|
1779 | 1779 | def collect_changed_files(clnode): |
|
1780 | 1780 | c = cl.read(clnode) |
|
1781 | 1781 | for fname in c[3]: |
|
1782 | 1782 | changedfileset[fname] = 1 |
|
1783 | 1783 | return collect_changed_files |
|
1784 | 1784 | |
|
1785 | 1785 | def lookuprevlink_func(revlog): |
|
1786 | 1786 | def lookuprevlink(n): |
|
1787 | 1787 | return cl.node(revlog.linkrev(n)) |
|
1788 | 1788 | return lookuprevlink |
|
1789 | 1789 | |
|
1790 | 1790 | def gengroup(): |
|
1791 | 1791 | # construct a list of all changed files |
|
1792 | 1792 | changedfiles = {} |
|
1793 | 1793 | |
|
1794 | 1794 | for chnk in cl.group(nodes, identity, |
|
1795 | 1795 | changed_file_collector(changedfiles)): |
|
1796 | 1796 | yield chnk |
|
1797 | 1797 | changedfiles = changedfiles.keys() |
|
1798 | 1798 | changedfiles.sort() |
|
1799 | 1799 | |
|
1800 | 1800 | mnfst = self.manifest |
|
1801 | 1801 | nodeiter = gennodelst(mnfst) |
|
1802 | 1802 | for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): |
|
1803 | 1803 | yield chnk |
|
1804 | 1804 | |
|
1805 | 1805 | for fname in changedfiles: |
|
1806 | 1806 | filerevlog = self.file(fname) |
|
1807 | 1807 | nodeiter = gennodelst(filerevlog) |
|
1808 | 1808 | nodeiter = list(nodeiter) |
|
1809 | 1809 | if nodeiter: |
|
1810 | 1810 | yield changegroup.genchunk(fname) |
|
1811 | 1811 | lookup = lookuprevlink_func(filerevlog) |
|
1812 | 1812 | for chnk in filerevlog.group(nodeiter, lookup): |
|
1813 | 1813 | yield chnk |
|
1814 | 1814 | |
|
1815 | 1815 | yield changegroup.closechunk() |
|
1816 | 1816 | |
|
1817 | 1817 | if nodes: |
|
1818 | 1818 | self.hook('outgoing', node=hex(nodes[0]), source=source) |
|
1819 | 1819 | |
|
1820 | 1820 | return util.chunkbuffer(gengroup()) |
|
1821 | 1821 | |
|
1822 | 1822 | def addchangegroup(self, source, srctype, url): |
|
1823 | 1823 | """add changegroup to repo. |
|
1824 | 1824 | |
|
1825 | 1825 | return values: |
|
1826 | 1826 | - nothing changed or no source: 0 |
|
1827 | 1827 | - more heads than before: 1+added heads (2..n) |
|
1828 | 1828 | - less heads than before: -1-removed heads (-2..-n) |
|
1829 | 1829 | - number of heads stays the same: 1 |
|
1830 | 1830 | """ |
|
1831 | 1831 | def csmap(x): |
|
1832 | 1832 | self.ui.debug(_("add changeset %s\n") % short(x)) |
|
1833 | 1833 | return cl.count() |
|
1834 | 1834 | |
|
1835 | 1835 | def revmap(x): |
|
1836 | 1836 | return cl.rev(x) |
|
1837 | 1837 | |
|
1838 | 1838 | if not source: |
|
1839 | 1839 | return 0 |
|
1840 | 1840 | |
|
1841 | 1841 | self.hook('prechangegroup', throw=True, source=srctype, url=url) |
|
1842 | 1842 | |
|
1843 | 1843 | changesets = files = revisions = 0 |
|
1844 | 1844 | |
|
1845 | 1845 | tr = self.transaction() |
|
1846 | 1846 | |
|
1847 | 1847 | # write changelog data to temp files so concurrent readers will not see |
|
1848 | 1848 | # inconsistent view |
|
1849 | 1849 | cl = None |
|
1850 | 1850 | try: |
|
1851 | 1851 | cl = appendfile.appendchangelog(self.sopener, |
|
1852 | 1852 | self.changelog.version) |
|
1853 | 1853 | |
|
1854 | 1854 | oldheads = len(cl.heads()) |
|
1855 | 1855 | |
|
1856 | 1856 | # pull off the changeset group |
|
1857 | 1857 | self.ui.status(_("adding changesets\n")) |
|
1858 | 1858 | cor = cl.count() - 1 |
|
1859 | 1859 | chunkiter = changegroup.chunkiter(source) |
|
1860 | 1860 | if cl.addgroup(chunkiter, csmap, tr, 1) is None: |
|
1861 | 1861 | raise util.Abort(_("received changelog group is empty")) |
|
1862 | 1862 | cnr = cl.count() - 1 |
|
1863 | 1863 | changesets = cnr - cor |
|
1864 | 1864 | |
|
1865 | 1865 | # pull off the manifest group |
|
1866 | 1866 | self.ui.status(_("adding manifests\n")) |
|
1867 | 1867 | chunkiter = changegroup.chunkiter(source) |
|
1868 | 1868 | # no need to check for empty manifest group here: |
|
1869 | 1869 | # if the result of the merge of 1 and 2 is the same in 3 and 4, |
|
1870 | 1870 | # no new manifest will be created and the manifest group will |
|
1871 | 1871 | # be empty during the pull |
|
1872 | 1872 | self.manifest.addgroup(chunkiter, revmap, tr) |
|
1873 | 1873 | |
|
1874 | 1874 | # process the files |
|
1875 | 1875 | self.ui.status(_("adding file changes\n")) |
|
1876 | 1876 | while 1: |
|
1877 | 1877 | f = changegroup.getchunk(source) |
|
1878 | 1878 | if not f: |
|
1879 | 1879 | break |
|
1880 | 1880 | self.ui.debug(_("adding %s revisions\n") % f) |
|
1881 | 1881 | fl = self.file(f) |
|
1882 | 1882 | o = fl.count() |
|
1883 | 1883 | chunkiter = changegroup.chunkiter(source) |
|
1884 | 1884 | if fl.addgroup(chunkiter, revmap, tr) is None: |
|
1885 | 1885 | raise util.Abort(_("received file revlog group is empty")) |
|
1886 | 1886 | revisions += fl.count() - o |
|
1887 | 1887 | files += 1 |
|
1888 | 1888 | |
|
1889 | 1889 | cl.writedata() |
|
1890 | 1890 | finally: |
|
1891 | 1891 | if cl: |
|
1892 | 1892 | cl.cleanup() |
|
1893 | 1893 | |
|
1894 | 1894 | # make changelog see real files again |
|
1895 | 1895 | self.changelog = changelog.changelog(self.sopener, |
|
1896 | 1896 | self.changelog.version) |
|
1897 | 1897 | self.changelog.checkinlinesize(tr) |
|
1898 | 1898 | |
|
1899 | 1899 | newheads = len(self.changelog.heads()) |
|
1900 | 1900 | heads = "" |
|
1901 | 1901 | if oldheads and newheads != oldheads: |
|
1902 | 1902 | heads = _(" (%+d heads)") % (newheads - oldheads) |
|
1903 | 1903 | |
|
1904 | 1904 | self.ui.status(_("added %d changesets" |
|
1905 | 1905 | " with %d changes to %d files%s\n") |
|
1906 | 1906 | % (changesets, revisions, files, heads)) |
|
1907 | 1907 | |
|
1908 | 1908 | if changesets > 0: |
|
1909 | 1909 | self.hook('pretxnchangegroup', throw=True, |
|
1910 | 1910 | node=hex(self.changelog.node(cor+1)), source=srctype, |
|
1911 | 1911 | url=url) |
|
1912 | 1912 | |
|
1913 | 1913 | tr.close() |
|
1914 | 1914 | |
|
1915 | 1915 | if changesets > 0: |
|
1916 | 1916 | self.hook("changegroup", node=hex(self.changelog.node(cor+1)), |
|
1917 | 1917 | source=srctype, url=url) |
|
1918 | 1918 | |
|
1919 | 1919 | for i in xrange(cor + 1, cnr + 1): |
|
1920 | 1920 | self.hook("incoming", node=hex(self.changelog.node(i)), |
|
1921 | 1921 | source=srctype, url=url) |
|
1922 | 1922 | |
|
1923 | 1923 | # never return 0 here: |
|
1924 | 1924 | if newheads < oldheads: |
|
1925 | 1925 | return newheads - oldheads - 1 |
|
1926 | 1926 | else: |
|
1927 | 1927 | return newheads - oldheads + 1 |
|
1928 | 1928 | |
|
1929 | 1929 | |
|
1930 | 1930 | def stream_in(self, remote): |
|
1931 | 1931 | fp = remote.stream_out() |
|
1932 | 1932 | l = fp.readline() |
|
1933 | 1933 | try: |
|
1934 | 1934 | resp = int(l) |
|
1935 | 1935 | except ValueError: |
|
1936 | 1936 | raise util.UnexpectedOutput( |
|
1937 | 1937 | _('Unexpected response from remote server:'), l) |
|
1938 | 1938 | if resp == 1: |
|
1939 | 1939 | raise util.Abort(_('operation forbidden by server')) |
|
1940 | 1940 | elif resp == 2: |
|
1941 | 1941 | raise util.Abort(_('locking the remote repository failed')) |
|
1942 | 1942 | elif resp != 0: |
|
1943 | 1943 | raise util.Abort(_('the server sent an unknown error code')) |
|
1944 | 1944 | self.ui.status(_('streaming all changes\n')) |
|
1945 | 1945 | l = fp.readline() |
|
1946 | 1946 | try: |
|
1947 | 1947 | total_files, total_bytes = map(int, l.split(' ', 1)) |
|
1948 | 1948 | except ValueError, TypeError: |
|
1949 | 1949 | raise util.UnexpectedOutput( |
|
1950 | 1950 | _('Unexpected response from remote server:'), l) |
|
1951 | 1951 | self.ui.status(_('%d files to transfer, %s of data\n') % |
|
1952 | 1952 | (total_files, util.bytecount(total_bytes))) |
|
1953 | 1953 | start = time.time() |
|
1954 | 1954 | for i in xrange(total_files): |
|
1955 | 1955 | # XXX doesn't support '\n' or '\r' in filenames |
|
1956 | 1956 | l = fp.readline() |
|
1957 | 1957 | try: |
|
1958 | 1958 | name, size = l.split('\0', 1) |
|
1959 | 1959 | size = int(size) |
|
1960 | 1960 | except ValueError, TypeError: |
|
1961 | 1961 | raise util.UnexpectedOutput( |
|
1962 | 1962 | _('Unexpected response from remote server:'), l) |
|
1963 | 1963 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) |
|
1964 | 1964 | ofp = self.sopener(name, 'w') |
|
1965 | 1965 | for chunk in util.filechunkiter(fp, limit=size): |
|
1966 | 1966 | ofp.write(chunk) |
|
1967 | 1967 | ofp.close() |
|
1968 | 1968 | elapsed = time.time() - start |
|
1969 | 1969 | if elapsed <= 0: |
|
1970 | 1970 | elapsed = 0.001 |
|
1971 | 1971 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % |
|
1972 | 1972 | (util.bytecount(total_bytes), elapsed, |
|
1973 | 1973 | util.bytecount(total_bytes / elapsed))) |
|
1974 | 1974 | self.reload() |
|
1975 | 1975 | return len(self.heads()) + 1 |
|
1976 | 1976 | |
|
1977 | 1977 | def clone(self, remote, heads=[], stream=False): |
|
1978 | 1978 | '''clone remote repository. |
|
1979 | 1979 | |
|
1980 | 1980 | keyword arguments: |
|
1981 | 1981 | heads: list of revs to clone (forces use of pull) |
|
1982 | 1982 | stream: use streaming clone if possible''' |
|
1983 | 1983 | |
|
1984 | 1984 | # now, all clients that can request uncompressed clones can |
|
1985 | 1985 | # read repo formats supported by all servers that can serve |
|
1986 | 1986 | # them. |
|
1987 | 1987 | |
|
1988 | 1988 | # if revlog format changes, client will have to check version |
|
1989 | 1989 | # and format flags on "stream" capability, and use |
|
1990 | 1990 | # uncompressed only if compatible. |
|
1991 | 1991 | |
|
1992 | 1992 | if stream and not heads and remote.capable('stream'): |
|
1993 | 1993 | return self.stream_in(remote) |
|
1994 | 1994 | return self.pull(remote, heads) |
|
1995 | 1995 | |
|
1996 | 1996 | # used to avoid circular references so destructors work |
|
1997 | 1997 | def aftertrans(files): |
|
1998 | 1998 | renamefiles = [tuple(t) for t in files] |
|
1999 | 1999 | def a(): |
|
2000 | 2000 | for src, dest in renamefiles: |
|
2001 | 2001 | util.rename(src, dest) |
|
2002 | 2002 | return a |
|
2003 | 2003 | |
|
2004 | 2004 | def instance(ui, path, create): |
|
2005 | 2005 | return localrepository(ui, util.drop_scheme('file', path), create) |
|
2006 | 2006 | |
|
2007 | 2007 | def islocal(path): |
|
2008 | 2008 | return True |
@@ -1,172 +1,172 b'' | |||
|
1 | 1 | adding changesets |
|
2 | 2 | adding manifests |
|
3 | 3 | adding file changes |
|
4 | 4 | added 2 changesets with 2 changes to 1 files |
|
5 | 5 | (run 'hg update' to get a working copy) |
|
6 | 6 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
7 | 7 | % should fail with encoding error |
|
8 | 8 | M a |
|
9 | 9 | ? latin-1 |
|
10 | 10 | ? latin-1-tag |
|
11 | 11 | ? utf-8 |
|
12 | 12 | abort: decoding near ' encoded: οΏ½': 'ascii' codec can't decode byte 0xe9 in position 20: ordinal not in range(128)! |
|
13 | 13 | transaction abort! |
|
14 | 14 | rollback completed |
|
15 | 15 | % these should work |
|
16 | 16 | % ascii |
|
17 | 17 | changeset: 5:db5520b4645f |
|
18 | 18 | branch: ? |
|
19 | 19 | tag: tip |
|
20 | 20 | user: test |
|
21 | 21 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
22 | 22 | summary: latin1 branch |
|
23 | 23 | |
|
24 | 24 | changeset: 4:9cff3c980b58 |
|
25 | 25 | user: test |
|
26 | 26 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
27 | 27 | summary: Added tag ? for changeset 770b9b11621d |
|
28 | 28 | |
|
29 | 29 | changeset: 3:770b9b11621d |
|
30 | 30 | tag: ? |
|
31 | 31 | user: test |
|
32 | 32 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
33 | 33 | summary: utf-8 e' encoded: ? |
|
34 | 34 | |
|
35 | 35 | changeset: 2:0572af48b948 |
|
36 | 36 | user: test |
|
37 | 37 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
38 | 38 | summary: latin-1 e' encoded: ? |
|
39 | 39 | |
|
40 | 40 | changeset: 1:0e5b7e3f9c4a |
|
41 | 41 | user: test |
|
42 | 42 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
43 | 43 | summary: koi8-r: ????? = u'\u0440\u0442\u0443\u0442\u044c' |
|
44 | 44 | |
|
45 | 45 | changeset: 0:1e78a93102a3 |
|
46 | 46 | user: test |
|
47 | 47 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
48 | 48 | summary: latin-1 e': ? = u'\xe9' |
|
49 | 49 | |
|
50 | 50 | % latin-1 |
|
51 | 51 | changeset: 5:db5520b4645f |
|
52 | 52 | branch: οΏ½ |
|
53 | 53 | tag: tip |
|
54 | 54 | user: test |
|
55 | 55 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
56 | 56 | summary: latin1 branch |
|
57 | 57 | |
|
58 | 58 | changeset: 4:9cff3c980b58 |
|
59 | 59 | user: test |
|
60 | 60 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
61 | 61 | summary: Added tag οΏ½ for changeset 770b9b11621d |
|
62 | 62 | |
|
63 | 63 | changeset: 3:770b9b11621d |
|
64 | 64 | tag: οΏ½ |
|
65 | 65 | user: test |
|
66 | 66 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
67 | 67 | summary: utf-8 e' encoded: οΏ½ |
|
68 | 68 | |
|
69 | 69 | changeset: 2:0572af48b948 |
|
70 | 70 | user: test |
|
71 | 71 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
72 | 72 | summary: latin-1 e' encoded: οΏ½ |
|
73 | 73 | |
|
74 | 74 | changeset: 1:0e5b7e3f9c4a |
|
75 | 75 | user: test |
|
76 | 76 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
77 | 77 | summary: koi8-r: οΏ½οΏ½οΏ½οΏ½οΏ½ = u'\u0440\u0442\u0443\u0442\u044c' |
|
78 | 78 | |
|
79 | 79 | changeset: 0:1e78a93102a3 |
|
80 | 80 | user: test |
|
81 | 81 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
82 | 82 | summary: latin-1 e': οΏ½ = u'\xe9' |
|
83 | 83 | |
|
84 | 84 | % utf-8 |
|
85 | 85 | changeset: 5:db5520b4645f |
|
86 | 86 | branch: Γ© |
|
87 | 87 | tag: tip |
|
88 | 88 | user: test |
|
89 | 89 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
90 | 90 | summary: latin1 branch |
|
91 | 91 | |
|
92 | 92 | changeset: 4:9cff3c980b58 |
|
93 | 93 | user: test |
|
94 | 94 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
95 | 95 | summary: Added tag Γ© for changeset 770b9b11621d |
|
96 | 96 | |
|
97 | 97 | changeset: 3:770b9b11621d |
|
98 | 98 | tag: Γ© |
|
99 | 99 | user: test |
|
100 | 100 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
101 | 101 | summary: utf-8 e' encoded: Γ© |
|
102 | 102 | |
|
103 | 103 | changeset: 2:0572af48b948 |
|
104 | 104 | user: test |
|
105 | 105 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
106 | 106 | summary: latin-1 e' encoded: Γ© |
|
107 | 107 | |
|
108 | 108 | changeset: 1:0e5b7e3f9c4a |
|
109 | 109 | user: test |
|
110 | 110 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
111 | 111 | summary: koi8-r: ΓΓΓΓΓ = u'\u0440\u0442\u0443\u0442\u044c' |
|
112 | 112 | |
|
113 | 113 | changeset: 0:1e78a93102a3 |
|
114 | 114 | user: test |
|
115 | 115 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
116 | 116 | summary: latin-1 e': Γ© = u'\xe9' |
|
117 | 117 | |
|
118 | 118 | % ascii |
|
119 | 119 | tip 5:db5520b4645f |
|
120 | 120 | ? 3:770b9b11621d |
|
121 | 121 | % latin-1 |
|
122 | 122 | tip 5:db5520b4645f |
|
123 | 123 | οΏ½ 3:770b9b11621d |
|
124 | 124 | % utf-8 |
|
125 | 125 | tip 5:db5520b4645f |
|
126 | 126 | Γ© 3:770b9b11621d |
|
127 | 127 | % ascii |
|
128 | 128 | ? 5:db5520b4645f |
|
129 |
|
|
|
129 | default 4:9cff3c980b58 | |
|
130 | 130 | % latin-1 |
|
131 | 131 | οΏ½ 5:db5520b4645f |
|
132 |
|
|
|
132 | default 4:9cff3c980b58 | |
|
133 | 133 | % utf-8 |
|
134 | 134 | Γ© 5:db5520b4645f |
|
135 |
|
|
|
135 | default 4:9cff3c980b58 | |
|
136 | 136 | % utf-8 |
|
137 | 137 | changeset: 5:db5520b4645f |
|
138 | 138 | branch: Γ© |
|
139 | 139 | tag: tip |
|
140 | 140 | user: test |
|
141 | 141 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
142 | 142 | summary: latin1 branch |
|
143 | 143 | |
|
144 | 144 | changeset: 4:9cff3c980b58 |
|
145 | 145 | user: test |
|
146 | 146 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
147 | 147 | summary: Added tag Γ© for changeset 770b9b11621d |
|
148 | 148 | |
|
149 | 149 | changeset: 3:770b9b11621d |
|
150 | 150 | tag: Γ© |
|
151 | 151 | user: test |
|
152 | 152 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
153 | 153 | summary: utf-8 e' encoded: Γ© |
|
154 | 154 | |
|
155 | 155 | changeset: 2:0572af48b948 |
|
156 | 156 | user: test |
|
157 | 157 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
158 | 158 | summary: latin-1 e' encoded: Γ© |
|
159 | 159 | |
|
160 | 160 | changeset: 1:0e5b7e3f9c4a |
|
161 | 161 | user: test |
|
162 | 162 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
163 | 163 | summary: koi8-r: ΡΡΡΡΡ = u'\u0440\u0442\u0443\u0442\u044c' |
|
164 | 164 | |
|
165 | 165 | changeset: 0:1e78a93102a3 |
|
166 | 166 | user: test |
|
167 | 167 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
168 | 168 | summary: latin-1 e': Π = u'\xe9' |
|
169 | 169 | |
|
170 | 170 | abort: unknown encoding: dolphin, please check your locale settings |
|
171 | 171 | abort: decoding near 'οΏ½': 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128)! |
|
172 | 172 | abort: branch name not in UTF-8! |
@@ -1,216 +1,218 b'' | |||
|
1 | 1 | adding a |
|
2 | 2 | adding b |
|
3 | 3 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
4 | 4 | pulling from ../b |
|
5 | 5 | searching for changes |
|
6 | 6 | warning: repository is unrelated |
|
7 | 7 | adding changesets |
|
8 | 8 | adding manifests |
|
9 | 9 | adding file changes |
|
10 | 10 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
11 | 11 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
12 | 12 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
13 | 13 | (branch merge, don't forget to commit) |
|
14 | 14 | %% -R/--repository |
|
15 | 15 | changeset: 0:8580ff50825a |
|
16 | 16 | tag: tip |
|
17 | 17 | user: test |
|
18 | 18 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
19 | 19 | summary: a |
|
20 | 20 | |
|
21 | 21 | changeset: 0:b6c483daf290 |
|
22 | 22 | tag: tip |
|
23 | 23 | user: test |
|
24 | 24 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
25 | 25 | summary: b |
|
26 | 26 | |
|
27 | 27 | %% abbrev of long option |
|
28 | 28 | changeset: 1:b6c483daf290 |
|
29 | 29 | tag: tip |
|
30 | 30 | parent: -1:000000000000 |
|
31 | 31 | user: test |
|
32 | 32 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
33 | 33 | summary: b |
|
34 | 34 | |
|
35 | 35 | %% --cwd |
|
36 | 36 | changeset: 0:8580ff50825a |
|
37 | 37 | tag: tip |
|
38 | 38 | user: test |
|
39 | 39 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
40 | 40 | summary: a |
|
41 | 41 | |
|
42 | 42 | %% -y/--noninteractive - just be sure it is parsed |
|
43 | 43 | 0:8580ff50825a |
|
44 | 44 | 0:8580ff50825a |
|
45 | 45 | %% -q/--quiet |
|
46 | 46 | 0:8580ff50825a |
|
47 | 47 | 0:b6c483daf290 |
|
48 | 48 | 0:8580ff50825a |
|
49 | 49 | 1:b6c483daf290 |
|
50 | 50 | %% -v/--verbose |
|
51 | 51 | changeset: 1:b6c483daf290 |
|
52 | 52 | tag: tip |
|
53 | 53 | parent: -1:000000000000 |
|
54 | 54 | user: test |
|
55 | 55 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
56 | 56 | files: b |
|
57 | 57 | description: |
|
58 | 58 | b |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | changeset: 0:8580ff50825a |
|
62 | 62 | user: test |
|
63 | 63 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
64 | 64 | files: a |
|
65 | 65 | description: |
|
66 | 66 | a |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | changeset: 0:b6c483daf290 |
|
70 | 70 | tag: tip |
|
71 | 71 | user: test |
|
72 | 72 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
73 | 73 | files: b |
|
74 | 74 | description: |
|
75 | 75 | b |
|
76 | 76 | |
|
77 | 77 | |
|
78 | 78 | %% --config |
|
79 | 79 | quuxfoo |
|
80 | 80 | abort: malformed --config option: |
|
81 | 81 | abort: malformed --config option: a.b |
|
82 | 82 | abort: malformed --config option: a |
|
83 | 83 | abort: malformed --config option: a.= |
|
84 | 84 | abort: malformed --config option: .b= |
|
85 | 85 | %% --debug |
|
86 | 86 | changeset: 1:b6c483daf2907ce5825c0bb50f5716226281cc1a |
|
87 | 87 | tag: tip |
|
88 | 88 | parent: -1:0000000000000000000000000000000000000000 |
|
89 | 89 | parent: -1:0000000000000000000000000000000000000000 |
|
90 | 90 | manifest: 1:23226e7a252cacdc2d99e4fbdc3653441056de49 |
|
91 | 91 | user: test |
|
92 | 92 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
93 | 93 | files+: b |
|
94 | extra: branch=default | |
|
94 | 95 | description: |
|
95 | 96 | b |
|
96 | 97 | |
|
97 | 98 | |
|
98 | 99 | changeset: 0:8580ff50825a50c8f716709acdf8de0deddcd6ab |
|
99 | 100 | parent: -1:0000000000000000000000000000000000000000 |
|
100 | 101 | parent: -1:0000000000000000000000000000000000000000 |
|
101 | 102 | manifest: 0:a0c8bcbbb45c63b90b70ad007bf38961f64f2af0 |
|
102 | 103 | user: test |
|
103 | 104 | date: Thu Jan 01 00:00:01 1970 +0000 |
|
104 | 105 | files+: a |
|
106 | extra: branch=default | |
|
105 | 107 | description: |
|
106 | 108 | a |
|
107 | 109 | |
|
108 | 110 | |
|
109 | 111 | %% --traceback |
|
110 | 112 | Traceback (most recent call last): |
|
111 | 113 | %% --time |
|
112 | 114 | Time: real x.x secs (user x.x+x.x sys x.x+x.x) |
|
113 | 115 | %% --version |
|
114 | 116 | Mercurial Distributed SCM (version xxx) |
|
115 | 117 | %% -h/--help |
|
116 | 118 | Mercurial Distributed SCM |
|
117 | 119 | |
|
118 | 120 | list of commands (use "hg help -v" to show aliases and global options): |
|
119 | 121 | |
|
120 | 122 | add add the specified files on the next commit |
|
121 | 123 | addremove add all new files, delete all missing files |
|
122 | 124 | annotate show changeset information per file line |
|
123 | 125 | archive create unversioned archive of a repository revision |
|
124 | 126 | backout reverse effect of earlier changeset |
|
125 | 127 | branch set or show the current branch name |
|
126 | 128 | branches list repository named branches |
|
127 | 129 | bundle create a changegroup file |
|
128 | 130 | cat output the current or given revision of files |
|
129 | 131 | clone make a copy of an existing repository |
|
130 | 132 | commit commit the specified files or all outstanding changes |
|
131 | 133 | copy mark files as copied for the next commit |
|
132 | 134 | diff diff repository (or selected files) |
|
133 | 135 | export dump the header and diffs for one or more changesets |
|
134 | 136 | grep search for a pattern in specified files and revisions |
|
135 | 137 | heads show current repository heads |
|
136 | 138 | help show help for a command, extension, or list of commands |
|
137 | 139 | identify print information about the working copy |
|
138 | 140 | import import an ordered set of patches |
|
139 | 141 | incoming show new changesets found in source |
|
140 | 142 | init create a new repository in the given directory |
|
141 | 143 | locate locate files matching specific patterns |
|
142 | 144 | log show revision history of entire repository or files |
|
143 | 145 | manifest output the current or given revision of the project manifest |
|
144 | 146 | merge merge working directory with another revision |
|
145 | 147 | outgoing show changesets not found in destination |
|
146 | 148 | parents show the parents of the working dir or revision |
|
147 | 149 | paths show definition of symbolic path names |
|
148 | 150 | pull pull changes from the specified source |
|
149 | 151 | push push changes to the specified destination |
|
150 | 152 | recover roll back an interrupted transaction |
|
151 | 153 | remove remove the specified files on the next commit |
|
152 | 154 | rename rename files; equivalent of copy + remove |
|
153 | 155 | revert revert files or dirs to their states as of some revision |
|
154 | 156 | rollback roll back the last transaction in this repository |
|
155 | 157 | root print the root (top) of the current working dir |
|
156 | 158 | serve export the repository via HTTP |
|
157 | 159 | showconfig show combined config settings from all hgrc files |
|
158 | 160 | status show changed files in the working directory |
|
159 | 161 | tag add a tag for the current or given revision |
|
160 | 162 | tags list repository tags |
|
161 | 163 | tip show the tip revision |
|
162 | 164 | unbundle apply a changegroup file |
|
163 | 165 | update update working directory |
|
164 | 166 | verify verify the integrity of the repository |
|
165 | 167 | version output version and copyright information |
|
166 | 168 | Mercurial Distributed SCM |
|
167 | 169 | |
|
168 | 170 | list of commands (use "hg help -v" to show aliases and global options): |
|
169 | 171 | |
|
170 | 172 | add add the specified files on the next commit |
|
171 | 173 | addremove add all new files, delete all missing files |
|
172 | 174 | annotate show changeset information per file line |
|
173 | 175 | archive create unversioned archive of a repository revision |
|
174 | 176 | backout reverse effect of earlier changeset |
|
175 | 177 | branch set or show the current branch name |
|
176 | 178 | branches list repository named branches |
|
177 | 179 | bundle create a changegroup file |
|
178 | 180 | cat output the current or given revision of files |
|
179 | 181 | clone make a copy of an existing repository |
|
180 | 182 | commit commit the specified files or all outstanding changes |
|
181 | 183 | copy mark files as copied for the next commit |
|
182 | 184 | diff diff repository (or selected files) |
|
183 | 185 | export dump the header and diffs for one or more changesets |
|
184 | 186 | grep search for a pattern in specified files and revisions |
|
185 | 187 | heads show current repository heads |
|
186 | 188 | help show help for a command, extension, or list of commands |
|
187 | 189 | identify print information about the working copy |
|
188 | 190 | import import an ordered set of patches |
|
189 | 191 | incoming show new changesets found in source |
|
190 | 192 | init create a new repository in the given directory |
|
191 | 193 | locate locate files matching specific patterns |
|
192 | 194 | log show revision history of entire repository or files |
|
193 | 195 | manifest output the current or given revision of the project manifest |
|
194 | 196 | merge merge working directory with another revision |
|
195 | 197 | outgoing show changesets not found in destination |
|
196 | 198 | parents show the parents of the working dir or revision |
|
197 | 199 | paths show definition of symbolic path names |
|
198 | 200 | pull pull changes from the specified source |
|
199 | 201 | push push changes to the specified destination |
|
200 | 202 | recover roll back an interrupted transaction |
|
201 | 203 | remove remove the specified files on the next commit |
|
202 | 204 | rename rename files; equivalent of copy + remove |
|
203 | 205 | revert revert files or dirs to their states as of some revision |
|
204 | 206 | rollback roll back the last transaction in this repository |
|
205 | 207 | root print the root (top) of the current working dir |
|
206 | 208 | serve export the repository via HTTP |
|
207 | 209 | showconfig show combined config settings from all hgrc files |
|
208 | 210 | status show changed files in the working directory |
|
209 | 211 | tag add a tag for the current or given revision |
|
210 | 212 | tags list repository tags |
|
211 | 213 | tip show the tip revision |
|
212 | 214 | unbundle apply a changegroup file |
|
213 | 215 | update update working directory |
|
214 | 216 | verify verify the integrity of the repository |
|
215 | 217 | version output version and copyright information |
|
216 | 218 | %% not tested: --debugger |
@@ -1,59 +1,59 b'' | |||
|
1 | 1 | # mq patch on an empty repo |
|
2 | 2 | tip: 0 |
|
3 | 3 | No .hg/branches.cache |
|
4 | 4 | tip: 0 |
|
5 | 5 | No .hg/branches.cache |
|
6 | 6 | |
|
7 | 7 | # some regular revisions |
|
8 | 8 | Patch queue now empty |
|
9 | 9 | tip: 1 |
|
10 |
features: |
|
|
10 | features: default | |
|
11 | 11 | 3f910abad313ff802d3a23a7529433872df9b3ae 1 |
|
12 | 12 | 3f910abad313ff802d3a23a7529433872df9b3ae bar |
|
13 | 13 | 9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo |
|
14 | 14 | |
|
15 | 15 | # add some mq patches |
|
16 | 16 | applying p1 |
|
17 | 17 | Now at: p1 |
|
18 | 18 | tip: 2 |
|
19 |
features: |
|
|
19 | features: default | |
|
20 | 20 | 3f910abad313ff802d3a23a7529433872df9b3ae 1 |
|
21 | 21 | 3f910abad313ff802d3a23a7529433872df9b3ae bar |
|
22 | 22 | 9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo |
|
23 | 23 | tip: 3 |
|
24 |
features: |
|
|
24 | features: default | |
|
25 | 25 | 3f910abad313ff802d3a23a7529433872df9b3ae 1 |
|
26 | 26 | 3f910abad313ff802d3a23a7529433872df9b3ae bar |
|
27 | 27 | 9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo |
|
28 | 28 | branch foo: 3 |
|
29 | 29 | branch bar: 2 |
|
30 | 30 | |
|
31 | 31 | # removing the cache |
|
32 | 32 | tip: 3 |
|
33 |
features: |
|
|
33 | features: default | |
|
34 | 34 | 3f910abad313ff802d3a23a7529433872df9b3ae 1 |
|
35 | 35 | 3f910abad313ff802d3a23a7529433872df9b3ae bar |
|
36 | 36 | 9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo |
|
37 | 37 | branch foo: 3 |
|
38 | 38 | branch bar: 2 |
|
39 | 39 | |
|
40 | 40 | # importing rev 1 (the cache now ends in one of the patches) |
|
41 | 41 | tip: 3 |
|
42 |
features: |
|
|
42 | features: default | |
|
43 | 43 | 3f910abad313ff802d3a23a7529433872df9b3ae 1 |
|
44 | 44 | 3f910abad313ff802d3a23a7529433872df9b3ae bar |
|
45 | 45 | 9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo |
|
46 | 46 | branch foo: 3 |
|
47 | 47 | branch bar: 2 |
|
48 | 48 | qbase: 1 |
|
49 | 49 | |
|
50 | 50 | # detect an invalid cache |
|
51 | 51 | Patch queue now empty |
|
52 | 52 | applying p0 |
|
53 | 53 | applying p1 |
|
54 | 54 | applying p2 |
|
55 | 55 | Now at: p2 |
|
56 | 56 | tip: 3 |
|
57 |
features: |
|
|
57 | features: default | |
|
58 | 58 | 9539f35bdc80732cc9a3f84e46508f1ed1ec8cff 0 |
|
59 | 59 | 9539f35bdc80732cc9a3f84e46508f1ed1ec8cff foo |
@@ -1,99 +1,99 b'' | |||
|
1 | 1 | foo |
|
2 | 2 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
3 | 3 | foo |
|
4 | 4 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
5 | 5 | (branch merge, don't forget to commit) |
|
6 | 6 | foo |
|
7 | 7 | changeset: 5:5f8fb06e083e |
|
8 | 8 | branch: foo |
|
9 | 9 | tag: tip |
|
10 | 10 | parent: 4:4909a3732169 |
|
11 | 11 | parent: 3:bf1bc2f45e83 |
|
12 | 12 | user: test |
|
13 | 13 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
14 | 14 | summary: merge |
|
15 | 15 | |
|
16 | 16 | changeset: 4:4909a3732169 |
|
17 | 17 | branch: foo |
|
18 | 18 | parent: 1:b699b1cec9c2 |
|
19 | 19 | user: test |
|
20 | 20 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
21 | 21 | summary: modify a branch |
|
22 | 22 | |
|
23 | 23 | changeset: 3:bf1bc2f45e83 |
|
24 | 24 | user: test |
|
25 | 25 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
26 | 26 | summary: clear branch name |
|
27 | 27 | |
|
28 | 28 | changeset: 2:67ec16bde7f1 |
|
29 | 29 | branch: bar |
|
30 | 30 | user: test |
|
31 | 31 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
32 | 32 | summary: change branch name |
|
33 | 33 | |
|
34 | 34 | changeset: 1:b699b1cec9c2 |
|
35 | 35 | branch: foo |
|
36 | 36 | user: test |
|
37 | 37 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
38 | 38 | summary: add branch name |
|
39 | 39 | |
|
40 | 40 | changeset: 0:be8523e69bf8 |
|
41 | 41 | user: test |
|
42 | 42 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
43 | 43 | summary: initial |
|
44 | 44 | |
|
45 | 45 | foo 5:5f8fb06e083e |
|
46 |
|
|
|
46 | default 3:bf1bc2f45e83 | |
|
47 | 47 | bar 2:67ec16bde7f1 |
|
48 | 48 | foo |
|
49 | ||
|
49 | default | |
|
50 | 50 | bar |
|
51 | 51 | % test for invalid branch cache |
|
52 | 52 | rolling back last transaction |
|
53 | 53 | changeset: 4:4909a3732169 |
|
54 | 54 | branch: foo |
|
55 | 55 | tag: tip |
|
56 | 56 | parent: 1:b699b1cec9c2 |
|
57 | 57 | user: test |
|
58 | 58 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
59 | 59 | summary: modify a branch |
|
60 | 60 | |
|
61 | 61 | Invalid branch cache: unknown tip |
|
62 | 62 | changeset: 4:4909a3732169c0c20011c4f4b8fdff4e3d89b23f |
|
63 | 63 | branch: foo |
|
64 | 64 | tag: tip |
|
65 | 65 | parent: 1:b699b1cec9c2966b3700de4fef0dc123cd754c31 |
|
66 | 66 | parent: -1:0000000000000000000000000000000000000000 |
|
67 | 67 | manifest: 4:d01b250baaa05909152f7ae07d7a649deea0df9a |
|
68 | 68 | user: test |
|
69 | 69 | date: Mon Jan 12 13:46:40 1970 +0000 |
|
70 | 70 | files: a |
|
71 | 71 | extra: branch=foo |
|
72 | 72 | description: |
|
73 | 73 | modify a branch |
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | 4:4909a3732169 |
|
77 |
features: |
|
|
77 | features: default | |
|
78 | 78 | 4909a3732169c0c20011c4f4b8fdff4e3d89b23f 4 |
|
79 | bf1bc2f45e834c75404d0ddab57d53beab56e2f8 | |
|
79 | bf1bc2f45e834c75404d0ddab57d53beab56e2f8 default | |
|
80 | 80 | 4909a3732169c0c20011c4f4b8fdff4e3d89b23f foo |
|
81 | 81 | 67ec16bde7f1575d523313b9bca000f6a6f12dca bar |
|
82 | 82 | % test for different branch cache features |
|
83 | 83 | branch cache: no features specified |
|
84 | 84 | foo 4:4909a3732169c0c20011c4f4b8fdff4e3d89b23f |
|
85 |
|
|
|
85 | default 3:bf1bc2f45e834c75404d0ddab57d53beab56e2f8 | |
|
86 | 86 | bar 2:67ec16bde7f1575d523313b9bca000f6a6f12dca |
|
87 |
branch cache: |
|
|
87 | branch cache: missing features: default | |
|
88 | 88 | foo 4:4909a3732169c0c20011c4f4b8fdff4e3d89b23f |
|
89 |
|
|
|
89 | default 3:bf1bc2f45e834c75404d0ddab57d53beab56e2f8 | |
|
90 | 90 | bar 2:67ec16bde7f1575d523313b9bca000f6a6f12dca |
|
91 |
branch cache: missing features: |
|
|
91 | branch cache: missing features: default | |
|
92 | 92 | foo 4:4909a3732169c0c20011c4f4b8fdff4e3d89b23f |
|
93 |
|
|
|
93 | default 3:bf1bc2f45e834c75404d0ddab57d53beab56e2f8 | |
|
94 | 94 | bar 2:67ec16bde7f1575d523313b9bca000f6a6f12dca |
|
95 | 95 | % test old hg reading branch cache with feature list |
|
96 | 96 | ValueError raised correctly, good. |
|
97 | 97 | % update with no arguments: tipmost revision of the current branch |
|
98 | 98 | bf1bc2f45e83 |
|
99 | 99 | 4909a3732169 (foo) tip |
General Comments 0
You need to be logged in to leave comments.
Login now