Show More
@@ -1,376 +1,376 | |||
|
1 | 1 | # ASCII graph log extension for Mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2007 Joel Rosdahl <joel@rosdahl.net> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | '''command to view revision graphs from a shell |
|
9 | 9 | |
|
10 | 10 | This extension adds a --graph option to the incoming, outgoing and log |
|
11 | 11 | commands. When this options is given, an ASCII representation of the revision |
|
12 | 12 | graph is also shown. |
|
13 | 13 | ''' |
|
14 | 14 | |
|
15 | 15 | import os, sys |
|
16 | 16 | from mercurial.cmdutil import revrange, show_changeset |
|
17 | 17 | from mercurial.commands import templateopts |
|
18 | 18 | from mercurial.i18n import _ |
|
19 | 19 | from mercurial.node import nullrev |
|
20 | 20 | from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions |
|
21 | 21 | from mercurial import hg, url, util, graphmod |
|
22 | 22 | |
|
23 | 23 | ASCIIDATA = 'ASC' |
|
24 | 24 | |
|
25 | 25 | def asciiformat(ui, repo, revdag, opts, parentrepo=None): |
|
26 | 26 | """formats a changelog DAG walk for ASCII output""" |
|
27 | 27 | if parentrepo is None: |
|
28 | 28 | parentrepo = repo |
|
29 | 29 | showparents = [ctx.node() for ctx in parentrepo[None].parents()] |
|
30 | 30 | displayer = show_changeset(ui, repo, opts, buffered=True) |
|
31 | 31 | for (id, type, ctx, parentids) in revdag: |
|
32 | 32 | if type != graphmod.CHANGESET: |
|
33 | 33 | continue |
|
34 | 34 | displayer.show(ctx) |
|
35 | 35 | lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1] |
|
36 | 36 | char = ctx.node() in showparents and '@' or 'o' |
|
37 | 37 | yield (id, ASCIIDATA, (char, lines), parentids) |
|
38 | 38 | |
|
39 | 39 | def asciiedges(nodes): |
|
40 | 40 | """adds edge info to changelog DAG walk suitable for ascii()""" |
|
41 | 41 | seen = [] |
|
42 | 42 | for node, type, data, parents in nodes: |
|
43 | 43 | if node not in seen: |
|
44 | 44 | seen.append(node) |
|
45 | 45 | nodeidx = seen.index(node) |
|
46 | 46 | |
|
47 | 47 | knownparents = [] |
|
48 | 48 | newparents = [] |
|
49 | 49 | for parent in parents: |
|
50 | 50 | if parent in seen: |
|
51 | 51 | knownparents.append(parent) |
|
52 | 52 | else: |
|
53 | 53 | newparents.append(parent) |
|
54 | 54 | |
|
55 | 55 | ncols = len(seen) |
|
56 | 56 | nextseen = seen[:] |
|
57 | 57 | nextseen[nodeidx:nodeidx + 1] = newparents |
|
58 | 58 | edges = [(nodeidx, nextseen.index(p)) for p in knownparents] |
|
59 | 59 | |
|
60 | 60 | if len(newparents) > 0: |
|
61 | 61 | edges.append((nodeidx, nodeidx)) |
|
62 | 62 | if len(newparents) > 1: |
|
63 | 63 | edges.append((nodeidx, nodeidx + 1)) |
|
64 | 64 | nmorecols = len(nextseen) - ncols |
|
65 | 65 | seen = nextseen |
|
66 | 66 | yield (nodeidx, type, data, edges, ncols, nmorecols) |
|
67 | 67 | |
|
68 | 68 | def fix_long_right_edges(edges): |
|
69 | 69 | for (i, (start, end)) in enumerate(edges): |
|
70 | 70 | if end > start: |
|
71 | 71 | edges[i] = (start, end + 1) |
|
72 | 72 | |
|
73 | 73 | def get_nodeline_edges_tail( |
|
74 | 74 | node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): |
|
75 | 75 | if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: |
|
76 | 76 | # Still going in the same non-vertical direction. |
|
77 | 77 | if n_columns_diff == -1: |
|
78 | 78 | start = max(node_index + 1, p_node_index) |
|
79 | 79 | tail = ["|", " "] * (start - node_index - 1) |
|
80 | 80 | tail.extend(["/", " "] * (n_columns - start)) |
|
81 | 81 | return tail |
|
82 | 82 | else: |
|
83 | 83 | return ["\\", " "] * (n_columns - node_index - 1) |
|
84 | 84 | else: |
|
85 | 85 | return ["|", " "] * (n_columns - node_index - 1) |
|
86 | 86 | |
|
87 | 87 | def draw_edges(edges, nodeline, interline): |
|
88 | 88 | for (start, end) in edges: |
|
89 | 89 | if start == end + 1: |
|
90 | 90 | interline[2 * end + 1] = "/" |
|
91 | 91 | elif start == end - 1: |
|
92 | 92 | interline[2 * start + 1] = "\\" |
|
93 | 93 | elif start == end: |
|
94 | 94 | interline[2 * start] = "|" |
|
95 | 95 | else: |
|
96 | 96 | nodeline[2 * end] = "+" |
|
97 | 97 | if start > end: |
|
98 | (start, end) = (end,start) | |
|
98 | (start, end) = (end, start) | |
|
99 | 99 | for i in range(2 * start + 1, 2 * end): |
|
100 | 100 | if nodeline[i] != "+": |
|
101 | 101 | nodeline[i] = "-" |
|
102 | 102 | |
|
103 | 103 | def get_padding_line(ni, n_columns, edges): |
|
104 | 104 | line = [] |
|
105 | 105 | line.extend(["|", " "] * ni) |
|
106 | 106 | if (ni, ni - 1) in edges or (ni, ni) in edges: |
|
107 | 107 | # (ni, ni - 1) (ni, ni) |
|
108 | 108 | # | | | | | | | | |
|
109 | 109 | # +---o | | o---+ |
|
110 | 110 | # | | c | | c | | |
|
111 | 111 | # | |/ / | |/ / |
|
112 | 112 | # | | | | | | |
|
113 | 113 | c = "|" |
|
114 | 114 | else: |
|
115 | 115 | c = " " |
|
116 | 116 | line.extend([c, " "]) |
|
117 | 117 | line.extend(["|", " "] * (n_columns - ni - 1)) |
|
118 | 118 | return line |
|
119 | 119 | |
|
120 | 120 | def ascii(ui, dag): |
|
121 | 121 | """prints an ASCII graph of the DAG |
|
122 | 122 | |
|
123 | 123 | dag is a generator that emits tuples with the following elements: |
|
124 | 124 | |
|
125 | 125 | - Column of the current node in the set of ongoing edges. |
|
126 | 126 | - Type indicator of node data == ASCIIDATA. |
|
127 | 127 | - Payload: (char, lines): |
|
128 | 128 | - Character to use as node's symbol. |
|
129 | 129 | - List of lines to display as the node's text. |
|
130 | 130 | - Edges; a list of (col, next_col) indicating the edges between |
|
131 | 131 | the current node and its parents. |
|
132 | 132 | - Number of columns (ongoing edges) in the current revision. |
|
133 | 133 | - The difference between the number of columns (ongoing edges) |
|
134 | 134 | in the next revision and the number of columns (ongoing edges) |
|
135 | 135 | in the current revision. That is: -1 means one column removed; |
|
136 | 136 | 0 means no columns added or removed; 1 means one column added. |
|
137 | 137 | """ |
|
138 | 138 | prev_n_columns_diff = 0 |
|
139 | 139 | prev_node_index = 0 |
|
140 | 140 | for (node_index, type, (node_ch, node_lines), edges, n_columns, n_columns_diff) in dag: |
|
141 | 141 | |
|
142 | 142 | assert -2 < n_columns_diff < 2 |
|
143 | 143 | if n_columns_diff == -1: |
|
144 | 144 | # Transform |
|
145 | 145 | # |
|
146 | 146 | # | | | | | | |
|
147 | 147 | # o | | into o---+ |
|
148 | 148 | # |X / |/ / |
|
149 | 149 | # | | | | |
|
150 | 150 | fix_long_right_edges(edges) |
|
151 | 151 | |
|
152 | 152 | # add_padding_line says whether to rewrite |
|
153 | 153 | # |
|
154 | 154 | # | | | | | | | | |
|
155 | 155 | # | o---+ into | o---+ |
|
156 | 156 | # | / / | | | # <--- padding line |
|
157 | 157 | # o | | | / / |
|
158 | 158 | # o | | |
|
159 | 159 | add_padding_line = (len(node_lines) > 2 and |
|
160 | 160 | n_columns_diff == -1 and |
|
161 | 161 | [x for (x, y) in edges if x + 1 < y]) |
|
162 | 162 | |
|
163 | 163 | # fix_nodeline_tail says whether to rewrite |
|
164 | 164 | # |
|
165 | 165 | # | | o | | | | o | | |
|
166 | 166 | # | | |/ / | | |/ / |
|
167 | 167 | # | o | | into | o / / # <--- fixed nodeline tail |
|
168 | 168 | # | |/ / | |/ / |
|
169 | 169 | # o | | o | | |
|
170 | 170 | fix_nodeline_tail = len(node_lines) <= 2 and not add_padding_line |
|
171 | 171 | |
|
172 | 172 | # nodeline is the line containing the node character (typically o) |
|
173 | 173 | nodeline = ["|", " "] * node_index |
|
174 | 174 | nodeline.extend([node_ch, " "]) |
|
175 | 175 | |
|
176 | 176 | nodeline.extend( |
|
177 | 177 | get_nodeline_edges_tail( |
|
178 | 178 | node_index, prev_node_index, n_columns, n_columns_diff, |
|
179 | 179 | prev_n_columns_diff, fix_nodeline_tail)) |
|
180 | 180 | |
|
181 | 181 | # shift_interline is the line containing the non-vertical |
|
182 | 182 | # edges between this entry and the next |
|
183 | 183 | shift_interline = ["|", " "] * node_index |
|
184 | 184 | if n_columns_diff == -1: |
|
185 | 185 | n_spaces = 1 |
|
186 | 186 | edge_ch = "/" |
|
187 | 187 | elif n_columns_diff == 0: |
|
188 | 188 | n_spaces = 2 |
|
189 | 189 | edge_ch = "|" |
|
190 | 190 | else: |
|
191 | 191 | n_spaces = 3 |
|
192 | 192 | edge_ch = "\\" |
|
193 | 193 | shift_interline.extend(n_spaces * [" "]) |
|
194 | 194 | shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1)) |
|
195 | 195 | |
|
196 | 196 | # draw edges from the current node to its parents |
|
197 | 197 | draw_edges(edges, nodeline, shift_interline) |
|
198 | 198 | |
|
199 | 199 | # lines is the list of all graph lines to print |
|
200 | 200 | lines = [nodeline] |
|
201 | 201 | if add_padding_line: |
|
202 | 202 | lines.append(get_padding_line(node_index, n_columns, edges)) |
|
203 | 203 | lines.append(shift_interline) |
|
204 | 204 | |
|
205 | 205 | # make sure that there are as many graph lines as there are |
|
206 | 206 | # log strings |
|
207 | 207 | while len(node_lines) < len(lines): |
|
208 | 208 | node_lines.append("") |
|
209 | 209 | if len(lines) < len(node_lines): |
|
210 | 210 | extra_interline = ["|", " "] * (n_columns + n_columns_diff) |
|
211 | 211 | while len(lines) < len(node_lines): |
|
212 | 212 | lines.append(extra_interline) |
|
213 | 213 | |
|
214 | 214 | # print lines |
|
215 | 215 | indentation_level = max(n_columns, n_columns + n_columns_diff) |
|
216 | 216 | for (line, logstr) in zip(lines, node_lines): |
|
217 | 217 | ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) |
|
218 | 218 | ui.write(ln.rstrip() + '\n') |
|
219 | 219 | |
|
220 | 220 | # ... and start over |
|
221 | 221 | prev_node_index = node_index |
|
222 | 222 | prev_n_columns_diff = n_columns_diff |
|
223 | 223 | |
|
224 | 224 | def get_revs(repo, rev_opt): |
|
225 | 225 | if rev_opt: |
|
226 | 226 | revs = revrange(repo, rev_opt) |
|
227 | 227 | return (max(revs), min(revs)) |
|
228 | 228 | else: |
|
229 | 229 | return (len(repo) - 1, 0) |
|
230 | 230 | |
|
231 | 231 | def check_unsupported_flags(opts): |
|
232 | 232 | for op in ["follow", "follow_first", "date", "copies", "keyword", "remove", |
|
233 | 233 | "only_merges", "user", "only_branch", "prune", "newest_first", |
|
234 | 234 | "no_merges", "include", "exclude"]: |
|
235 | 235 | if op in opts and opts[op]: |
|
236 | 236 | raise util.Abort(_("--graph option is incompatible with --%s") % op) |
|
237 | 237 | |
|
238 | 238 | def graphlog(ui, repo, path=None, **opts): |
|
239 | 239 | """show revision history alongside an ASCII revision graph |
|
240 | 240 | |
|
241 | 241 | Print a revision history alongside a revision graph drawn with ASCII |
|
242 | 242 | characters. |
|
243 | 243 | |
|
244 | 244 | Nodes printed as an @ character are parents of the working directory. |
|
245 | 245 | """ |
|
246 | 246 | |
|
247 | 247 | check_unsupported_flags(opts) |
|
248 | 248 | limit = cmdutil.loglimit(opts) |
|
249 | 249 | start, stop = get_revs(repo, opts["rev"]) |
|
250 | 250 | stop = max(stop, start - limit + 1) |
|
251 | 251 | if start == nullrev: |
|
252 | 252 | return |
|
253 | 253 | |
|
254 | 254 | if path: |
|
255 | 255 | path = util.canonpath(repo.root, os.getcwd(), path) |
|
256 | 256 | if path: # could be reset in canonpath |
|
257 | 257 | revdag = graphmod.filerevs(repo, path, start, stop) |
|
258 | 258 | else: |
|
259 | 259 | revdag = graphmod.revisions(repo, start, stop) |
|
260 | 260 | |
|
261 | 261 | fmtdag = asciiformat(ui, repo, revdag, opts) |
|
262 | 262 | ascii(ui, asciiedges(fmtdag)) |
|
263 | 263 | |
|
264 | 264 | def graphrevs(repo, nodes, opts): |
|
265 | 265 | limit = cmdutil.loglimit(opts) |
|
266 | 266 | nodes.reverse() |
|
267 | 267 | if limit < sys.maxint: |
|
268 | 268 | nodes = nodes[:limit] |
|
269 | 269 | return graphmod.nodes(repo, nodes) |
|
270 | 270 | |
|
271 | 271 | def goutgoing(ui, repo, dest=None, **opts): |
|
272 | 272 | """show the outgoing changesets alongside an ASCII revision graph |
|
273 | 273 | |
|
274 | 274 | Print the outgoing changesets alongside a revision graph drawn with |
|
275 | 275 | ASCII characters. |
|
276 | 276 | |
|
277 | 277 | Nodes printed as an @ character are parents of the working |
|
278 | 278 | directory. |
|
279 | 279 | """ |
|
280 | 280 | |
|
281 | 281 | check_unsupported_flags(opts) |
|
282 | 282 | dest, revs, checkout = hg.parseurl( |
|
283 | 283 | ui.expandpath(dest or 'default-push', dest or 'default'), |
|
284 | 284 | opts.get('rev')) |
|
285 | 285 | if revs: |
|
286 | 286 | revs = [repo.lookup(rev) for rev in revs] |
|
287 | 287 | other = hg.repository(cmdutil.remoteui(ui, opts), dest) |
|
288 | 288 | ui.status(_('comparing with %s\n') % url.hidepassword(dest)) |
|
289 | 289 | o = repo.findoutgoing(other, force=opts.get('force')) |
|
290 | 290 | if not o: |
|
291 | 291 | ui.status(_("no changes found\n")) |
|
292 | 292 | return |
|
293 | 293 | |
|
294 | 294 | o = repo.changelog.nodesbetween(o, revs)[0] |
|
295 | 295 | revdag = graphrevs(repo, o, opts) |
|
296 | 296 | fmtdag = asciiformat(ui, repo, revdag, opts) |
|
297 | 297 | ascii(ui, asciiedges(fmtdag)) |
|
298 | 298 | |
|
299 | 299 | def gincoming(ui, repo, source="default", **opts): |
|
300 | 300 | """show the incoming changesets alongside an ASCII revision graph |
|
301 | 301 | |
|
302 | 302 | Print the incoming changesets alongside a revision graph drawn with ASCII |
|
303 | 303 | characters. |
|
304 | 304 | |
|
305 | 305 | Nodes printed as an @ character are parents of the working directory. |
|
306 | 306 | """ |
|
307 | 307 | |
|
308 | 308 | check_unsupported_flags(opts) |
|
309 | 309 | source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev')) |
|
310 | 310 | other = hg.repository(cmdutil.remoteui(repo, opts), source) |
|
311 | 311 | ui.status(_('comparing with %s\n') % url.hidepassword(source)) |
|
312 | 312 | if revs: |
|
313 | 313 | revs = [other.lookup(rev) for rev in revs] |
|
314 | 314 | incoming = repo.findincoming(other, heads=revs, force=opts["force"]) |
|
315 | 315 | if not incoming: |
|
316 | 316 | try: |
|
317 | 317 | os.unlink(opts["bundle"]) |
|
318 | 318 | except: |
|
319 | 319 | pass |
|
320 | 320 | ui.status(_("no changes found\n")) |
|
321 | 321 | return |
|
322 | 322 | |
|
323 | 323 | cleanup = None |
|
324 | 324 | try: |
|
325 | 325 | |
|
326 | 326 | fname = opts["bundle"] |
|
327 | 327 | if fname or not other.local(): |
|
328 | 328 | # create a bundle (uncompressed if other repo is not local) |
|
329 | 329 | if revs is None: |
|
330 | 330 | cg = other.changegroup(incoming, "incoming") |
|
331 | 331 | else: |
|
332 | 332 | cg = other.changegroupsubset(incoming, revs, 'incoming') |
|
333 | 333 | bundletype = other.local() and "HG10BZ" or "HG10UN" |
|
334 | 334 | fname = cleanup = changegroup.writebundle(cg, fname, bundletype) |
|
335 | 335 | # keep written bundle? |
|
336 | 336 | if opts["bundle"]: |
|
337 | 337 | cleanup = None |
|
338 | 338 | if not other.local(): |
|
339 | 339 | # use the created uncompressed bundlerepo |
|
340 | 340 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
341 | 341 | |
|
342 | 342 | chlist = other.changelog.nodesbetween(incoming, revs)[0] |
|
343 | 343 | revdag = graphrevs(other, chlist, opts) |
|
344 | 344 | fmtdag = asciiformat(ui, other, revdag, opts, parentrepo=repo) |
|
345 | 345 | ascii(ui, asciiedges(fmtdag)) |
|
346 | 346 | |
|
347 | 347 | finally: |
|
348 | 348 | if hasattr(other, 'close'): |
|
349 | 349 | other.close() |
|
350 | 350 | if cleanup: |
|
351 | 351 | os.unlink(cleanup) |
|
352 | 352 | |
|
353 | 353 | def uisetup(ui): |
|
354 | 354 | '''Initialize the extension.''' |
|
355 | 355 | _wrapcmd(ui, 'log', commands.table, graphlog) |
|
356 | 356 | _wrapcmd(ui, 'incoming', commands.table, gincoming) |
|
357 | 357 | _wrapcmd(ui, 'outgoing', commands.table, goutgoing) |
|
358 | 358 | |
|
359 | 359 | def _wrapcmd(ui, cmd, table, wrapfn): |
|
360 | 360 | '''wrap the command''' |
|
361 | 361 | def graph(orig, *args, **kwargs): |
|
362 | 362 | if kwargs['graph']: |
|
363 | 363 | return wrapfn(*args, **kwargs) |
|
364 | 364 | return orig(*args, **kwargs) |
|
365 | 365 | entry = extensions.wrapcommand(table, cmd, graph) |
|
366 | 366 | entry[1].append(('G', 'graph', None, _("show the revision DAG"))) |
|
367 | 367 | |
|
368 | 368 | cmdtable = { |
|
369 | 369 | "glog": |
|
370 | 370 | (graphlog, |
|
371 | 371 | [('l', 'limit', '', _('limit number of changes displayed')), |
|
372 | 372 | ('p', 'patch', False, _('show patch')), |
|
373 | 373 | ('r', 'rev', [], _('show the specified revision or range')), |
|
374 | 374 | ] + templateopts, |
|
375 | 375 | _('hg glog [OPTION]... [FILE]')), |
|
376 | 376 | } |
@@ -1,2617 +1,2617 | |||
|
1 | 1 | # mq.py - patch queues for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | '''manage a stack of patches |
|
9 | 9 | |
|
10 | 10 | This extension lets you work with a stack of patches in a Mercurial |
|
11 | 11 | repository. It manages two stacks of patches - all known patches, and applied |
|
12 | 12 | patches (subset of known patches). |
|
13 | 13 | |
|
14 | 14 | Known patches are represented as patch files in the .hg/patches directory. |
|
15 | 15 | Applied patches are both patch files and changesets. |
|
16 | 16 | |
|
17 | 17 | Common tasks (use "hg help command" for more details):: |
|
18 | 18 | |
|
19 | 19 | prepare repository to work with patches qinit |
|
20 | 20 | create new patch qnew |
|
21 | 21 | import existing patch qimport |
|
22 | 22 | |
|
23 | 23 | print patch series qseries |
|
24 | 24 | print applied patches qapplied |
|
25 | 25 | print name of top applied patch qtop |
|
26 | 26 | |
|
27 | 27 | add known patch to applied stack qpush |
|
28 | 28 | remove patch from applied stack qpop |
|
29 | 29 | refresh contents of top applied patch qrefresh |
|
30 | 30 | ''' |
|
31 | 31 | |
|
32 | 32 | from mercurial.i18n import _ |
|
33 | 33 | from mercurial.node import bin, hex, short, nullid, nullrev |
|
34 | 34 | from mercurial.lock import release |
|
35 | 35 | from mercurial import commands, cmdutil, hg, patch, util |
|
36 | 36 | from mercurial import repair, extensions, url, error |
|
37 | 37 | import os, sys, re, errno |
|
38 | 38 | |
|
39 | 39 | commands.norepo += " qclone" |
|
40 | 40 | |
|
41 | 41 | # Patch names looks like unix-file names. |
|
42 | 42 | # They must be joinable with queue directory and result in the patch path. |
|
43 | 43 | normname = util.normpath |
|
44 | 44 | |
|
45 | 45 | class statusentry(object): |
|
46 | 46 | def __init__(self, rev, name=None): |
|
47 | 47 | if not name: |
|
48 | 48 | fields = rev.split(':', 1) |
|
49 | 49 | if len(fields) == 2: |
|
50 | 50 | self.rev, self.name = fields |
|
51 | 51 | else: |
|
52 | 52 | self.rev, self.name = None, None |
|
53 | 53 | else: |
|
54 | 54 | self.rev, self.name = rev, name |
|
55 | 55 | |
|
56 | 56 | def __str__(self): |
|
57 | 57 | return self.rev + ':' + self.name |
|
58 | 58 | |
|
59 | 59 | class patchheader(object): |
|
60 | 60 | def __init__(self, pf): |
|
61 | 61 | def eatdiff(lines): |
|
62 | 62 | while lines: |
|
63 | 63 | l = lines[-1] |
|
64 | 64 | if (l.startswith("diff -") or |
|
65 | 65 | l.startswith("Index:") or |
|
66 | 66 | l.startswith("===========")): |
|
67 | 67 | del lines[-1] |
|
68 | 68 | else: |
|
69 | 69 | break |
|
70 | 70 | def eatempty(lines): |
|
71 | 71 | while lines: |
|
72 | 72 | l = lines[-1] |
|
73 | 73 | if re.match('\s*$', l): |
|
74 | 74 | del lines[-1] |
|
75 | 75 | else: |
|
76 | 76 | break |
|
77 | 77 | |
|
78 | 78 | message = [] |
|
79 | 79 | comments = [] |
|
80 | 80 | user = None |
|
81 | 81 | date = None |
|
82 | 82 | format = None |
|
83 | 83 | subject = None |
|
84 | 84 | diffstart = 0 |
|
85 | 85 | |
|
86 | 86 | for line in file(pf): |
|
87 | 87 | line = line.rstrip() |
|
88 | 88 | if line.startswith('diff --git'): |
|
89 | 89 | diffstart = 2 |
|
90 | 90 | break |
|
91 | 91 | if diffstart: |
|
92 | 92 | if line.startswith('+++ '): |
|
93 | 93 | diffstart = 2 |
|
94 | 94 | break |
|
95 | 95 | if line.startswith("--- "): |
|
96 | 96 | diffstart = 1 |
|
97 | 97 | continue |
|
98 | 98 | elif format == "hgpatch": |
|
99 | 99 | # parse values when importing the result of an hg export |
|
100 | 100 | if line.startswith("# User "): |
|
101 | 101 | user = line[7:] |
|
102 | 102 | elif line.startswith("# Date "): |
|
103 | 103 | date = line[7:] |
|
104 | 104 | elif not line.startswith("# ") and line: |
|
105 | 105 | message.append(line) |
|
106 | 106 | format = None |
|
107 | 107 | elif line == '# HG changeset patch': |
|
108 | 108 | format = "hgpatch" |
|
109 | 109 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
110 | 110 | line.startswith("subject: "))): |
|
111 | 111 | subject = line[9:] |
|
112 | 112 | format = "tag" |
|
113 | 113 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
114 | 114 | line.startswith("from: "))): |
|
115 | 115 | user = line[6:] |
|
116 | 116 | format = "tag" |
|
117 | 117 | elif format == "tag" and line == "": |
|
118 | 118 | # when looking for tags (subject: from: etc) they |
|
119 | 119 | # end once you find a blank line in the source |
|
120 | 120 | format = "tagdone" |
|
121 | 121 | elif message or line: |
|
122 | 122 | message.append(line) |
|
123 | 123 | comments.append(line) |
|
124 | 124 | |
|
125 | 125 | eatdiff(message) |
|
126 | 126 | eatdiff(comments) |
|
127 | 127 | eatempty(message) |
|
128 | 128 | eatempty(comments) |
|
129 | 129 | |
|
130 | 130 | # make sure message isn't empty |
|
131 | 131 | if format and format.startswith("tag") and subject: |
|
132 | 132 | message.insert(0, "") |
|
133 | 133 | message.insert(0, subject) |
|
134 | 134 | |
|
135 | 135 | self.message = message |
|
136 | 136 | self.comments = comments |
|
137 | 137 | self.user = user |
|
138 | 138 | self.date = date |
|
139 | 139 | self.haspatch = diffstart > 1 |
|
140 | 140 | |
|
141 | 141 | def setuser(self, user): |
|
142 | 142 | if not self.updateheader(['From: ', '# User '], user): |
|
143 | 143 | try: |
|
144 | 144 | patchheaderat = self.comments.index('# HG changeset patch') |
|
145 | 145 | self.comments.insert(patchheaderat + 1,'# User ' + user) |
|
146 | 146 | except ValueError: |
|
147 | 147 | self.comments = ['From: ' + user, ''] + self.comments |
|
148 | 148 | self.user = user |
|
149 | 149 | |
|
150 | 150 | def setdate(self, date): |
|
151 | 151 | if self.updateheader(['# Date '], date): |
|
152 | 152 | self.date = date |
|
153 | 153 | |
|
154 | 154 | def setmessage(self, message): |
|
155 | 155 | if self.comments: |
|
156 | 156 | self._delmsg() |
|
157 | 157 | self.message = [message] |
|
158 | 158 | self.comments += self.message |
|
159 | 159 | |
|
160 | 160 | def updateheader(self, prefixes, new): |
|
161 | 161 | '''Update all references to a field in the patch header. |
|
162 | 162 | Return whether the field is present.''' |
|
163 | 163 | res = False |
|
164 | 164 | for prefix in prefixes: |
|
165 | 165 | for i in xrange(len(self.comments)): |
|
166 | 166 | if self.comments[i].startswith(prefix): |
|
167 | 167 | self.comments[i] = prefix + new |
|
168 | 168 | res = True |
|
169 | 169 | break |
|
170 | 170 | return res |
|
171 | 171 | |
|
172 | 172 | def __str__(self): |
|
173 | 173 | if not self.comments: |
|
174 | 174 | return '' |
|
175 | 175 | return '\n'.join(self.comments) + '\n\n' |
|
176 | 176 | |
|
177 | 177 | def _delmsg(self): |
|
178 | 178 | '''Remove existing message, keeping the rest of the comments fields. |
|
179 | 179 | If comments contains 'subject: ', message will prepend |
|
180 | 180 | the field and a blank line.''' |
|
181 | 181 | if self.message: |
|
182 | 182 | subj = 'subject: ' + self.message[0].lower() |
|
183 | 183 | for i in xrange(len(self.comments)): |
|
184 | 184 | if subj == self.comments[i].lower(): |
|
185 | 185 | del self.comments[i] |
|
186 | 186 | self.message = self.message[2:] |
|
187 | 187 | break |
|
188 | 188 | ci = 0 |
|
189 | 189 | for mi in self.message: |
|
190 | 190 | while mi != self.comments[ci]: |
|
191 | 191 | ci += 1 |
|
192 | 192 | del self.comments[ci] |
|
193 | 193 | |
|
194 | 194 | class queue(object): |
|
195 | 195 | def __init__(self, ui, path, patchdir=None): |
|
196 | 196 | self.basepath = path |
|
197 | 197 | self.path = patchdir or os.path.join(path, "patches") |
|
198 | 198 | self.opener = util.opener(self.path) |
|
199 | 199 | self.ui = ui |
|
200 | 200 | self.applied_dirty = 0 |
|
201 | 201 | self.series_dirty = 0 |
|
202 | 202 | self.series_path = "series" |
|
203 | 203 | self.status_path = "status" |
|
204 | 204 | self.guards_path = "guards" |
|
205 | 205 | self.active_guards = None |
|
206 | 206 | self.guards_dirty = False |
|
207 | 207 | self._diffopts = None |
|
208 | 208 | |
|
209 | 209 | @util.propertycache |
|
210 | 210 | def applied(self): |
|
211 | 211 | if os.path.exists(self.join(self.status_path)): |
|
212 | 212 | lines = self.opener(self.status_path).read().splitlines() |
|
213 | 213 | return [statusentry(l) for l in lines] |
|
214 | 214 | return [] |
|
215 | 215 | |
|
216 | 216 | @util.propertycache |
|
217 | 217 | def full_series(self): |
|
218 | 218 | if os.path.exists(self.join(self.series_path)): |
|
219 | 219 | return self.opener(self.series_path).read().splitlines() |
|
220 | 220 | return [] |
|
221 | 221 | |
|
222 | 222 | @util.propertycache |
|
223 | 223 | def series(self): |
|
224 | 224 | self.parse_series() |
|
225 | 225 | return self.series |
|
226 | 226 | |
|
227 | 227 | @util.propertycache |
|
228 | 228 | def series_guards(self): |
|
229 | 229 | self.parse_series() |
|
230 | 230 | return self.series_guards |
|
231 | 231 | |
|
232 | 232 | def invalidate(self): |
|
233 | 233 | for a in 'applied full_series series series_guards'.split(): |
|
234 | 234 | if a in self.__dict__: |
|
235 | 235 | delattr(self, a) |
|
236 | 236 | self.applied_dirty = 0 |
|
237 | 237 | self.series_dirty = 0 |
|
238 | 238 | self.guards_dirty = False |
|
239 | 239 | self.active_guards = None |
|
240 | 240 | |
|
241 | 241 | def diffopts(self): |
|
242 | 242 | if self._diffopts is None: |
|
243 | 243 | self._diffopts = patch.diffopts(self.ui) |
|
244 | 244 | return self._diffopts |
|
245 | 245 | |
|
246 | 246 | def join(self, *p): |
|
247 | 247 | return os.path.join(self.path, *p) |
|
248 | 248 | |
|
249 | 249 | def find_series(self, patch): |
|
250 | 250 | pre = re.compile("(\s*)([^#]+)") |
|
251 | 251 | index = 0 |
|
252 | 252 | for l in self.full_series: |
|
253 | 253 | m = pre.match(l) |
|
254 | 254 | if m: |
|
255 | 255 | s = m.group(2) |
|
256 | 256 | s = s.rstrip() |
|
257 | 257 | if s == patch: |
|
258 | 258 | return index |
|
259 | 259 | index += 1 |
|
260 | 260 | return None |
|
261 | 261 | |
|
262 | 262 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') |
|
263 | 263 | |
|
264 | 264 | def parse_series(self): |
|
265 | 265 | self.series = [] |
|
266 | 266 | self.series_guards = [] |
|
267 | 267 | for l in self.full_series: |
|
268 | 268 | h = l.find('#') |
|
269 | 269 | if h == -1: |
|
270 | 270 | patch = l |
|
271 | 271 | comment = '' |
|
272 | 272 | elif h == 0: |
|
273 | 273 | continue |
|
274 | 274 | else: |
|
275 | 275 | patch = l[:h] |
|
276 | 276 | comment = l[h:] |
|
277 | 277 | patch = patch.strip() |
|
278 | 278 | if patch: |
|
279 | 279 | if patch in self.series: |
|
280 | 280 | raise util.Abort(_('%s appears more than once in %s') % |
|
281 | 281 | (patch, self.join(self.series_path))) |
|
282 | 282 | self.series.append(patch) |
|
283 | 283 | self.series_guards.append(self.guard_re.findall(comment)) |
|
284 | 284 | |
|
285 | 285 | def check_guard(self, guard): |
|
286 | 286 | if not guard: |
|
287 | 287 | return _('guard cannot be an empty string') |
|
288 | 288 | bad_chars = '# \t\r\n\f' |
|
289 | 289 | first = guard[0] |
|
290 | 290 | if first in '-+': |
|
291 | 291 | return (_('guard %r starts with invalid character: %r') % |
|
292 | 292 | (guard, first)) |
|
293 | 293 | for c in bad_chars: |
|
294 | 294 | if c in guard: |
|
295 | 295 | return _('invalid character in guard %r: %r') % (guard, c) |
|
296 | 296 | |
|
297 | 297 | def set_active(self, guards): |
|
298 | 298 | for guard in guards: |
|
299 | 299 | bad = self.check_guard(guard) |
|
300 | 300 | if bad: |
|
301 | 301 | raise util.Abort(bad) |
|
302 | 302 | guards = sorted(set(guards)) |
|
303 | 303 | self.ui.debug(_('active guards: %s\n') % ' '.join(guards)) |
|
304 | 304 | self.active_guards = guards |
|
305 | 305 | self.guards_dirty = True |
|
306 | 306 | |
|
307 | 307 | def active(self): |
|
308 | 308 | if self.active_guards is None: |
|
309 | 309 | self.active_guards = [] |
|
310 | 310 | try: |
|
311 | 311 | guards = self.opener(self.guards_path).read().split() |
|
312 | 312 | except IOError, err: |
|
313 | 313 | if err.errno != errno.ENOENT: raise |
|
314 | 314 | guards = [] |
|
315 | 315 | for i, guard in enumerate(guards): |
|
316 | 316 | bad = self.check_guard(guard) |
|
317 | 317 | if bad: |
|
318 | 318 | self.ui.warn('%s:%d: %s\n' % |
|
319 | 319 | (self.join(self.guards_path), i + 1, bad)) |
|
320 | 320 | else: |
|
321 | 321 | self.active_guards.append(guard) |
|
322 | 322 | return self.active_guards |
|
323 | 323 | |
|
324 | 324 | def set_guards(self, idx, guards): |
|
325 | 325 | for g in guards: |
|
326 | 326 | if len(g) < 2: |
|
327 | 327 | raise util.Abort(_('guard %r too short') % g) |
|
328 | 328 | if g[0] not in '-+': |
|
329 | 329 | raise util.Abort(_('guard %r starts with invalid char') % g) |
|
330 | 330 | bad = self.check_guard(g[1:]) |
|
331 | 331 | if bad: |
|
332 | 332 | raise util.Abort(bad) |
|
333 | 333 | drop = self.guard_re.sub('', self.full_series[idx]) |
|
334 | 334 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) |
|
335 | 335 | self.parse_series() |
|
336 | 336 | self.series_dirty = True |
|
337 | 337 | |
|
338 | 338 | def pushable(self, idx): |
|
339 | 339 | if isinstance(idx, str): |
|
340 | 340 | idx = self.series.index(idx) |
|
341 | 341 | patchguards = self.series_guards[idx] |
|
342 | 342 | if not patchguards: |
|
343 | 343 | return True, None |
|
344 | 344 | guards = self.active() |
|
345 | 345 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] |
|
346 | 346 | if exactneg: |
|
347 | 347 | return False, exactneg[0] |
|
348 | 348 | pos = [g for g in patchguards if g[0] == '+'] |
|
349 | 349 | exactpos = [g for g in pos if g[1:] in guards] |
|
350 | 350 | if pos: |
|
351 | 351 | if exactpos: |
|
352 | 352 | return True, exactpos[0] |
|
353 | 353 | return False, pos |
|
354 | 354 | return True, '' |
|
355 | 355 | |
|
356 | 356 | def explain_pushable(self, idx, all_patches=False): |
|
357 | 357 | write = all_patches and self.ui.write or self.ui.warn |
|
358 | 358 | if all_patches or self.ui.verbose: |
|
359 | 359 | if isinstance(idx, str): |
|
360 | 360 | idx = self.series.index(idx) |
|
361 | 361 | pushable, why = self.pushable(idx) |
|
362 | 362 | if all_patches and pushable: |
|
363 | 363 | if why is None: |
|
364 | 364 | write(_('allowing %s - no guards in effect\n') % |
|
365 | 365 | self.series[idx]) |
|
366 | 366 | else: |
|
367 | 367 | if not why: |
|
368 | 368 | write(_('allowing %s - no matching negative guards\n') % |
|
369 | 369 | self.series[idx]) |
|
370 | 370 | else: |
|
371 | 371 | write(_('allowing %s - guarded by %r\n') % |
|
372 | 372 | (self.series[idx], why)) |
|
373 | 373 | if not pushable: |
|
374 | 374 | if why: |
|
375 | 375 | write(_('skipping %s - guarded by %r\n') % |
|
376 | 376 | (self.series[idx], why)) |
|
377 | 377 | else: |
|
378 | 378 | write(_('skipping %s - no matching guards\n') % |
|
379 | 379 | self.series[idx]) |
|
380 | 380 | |
|
381 | 381 | def save_dirty(self): |
|
382 | 382 | def write_list(items, path): |
|
383 | 383 | fp = self.opener(path, 'w') |
|
384 | 384 | for i in items: |
|
385 | 385 | fp.write("%s\n" % i) |
|
386 | 386 | fp.close() |
|
387 | 387 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) |
|
388 | 388 | if self.series_dirty: write_list(self.full_series, self.series_path) |
|
389 | 389 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) |
|
390 | 390 | |
|
391 | 391 | def removeundo(self, repo): |
|
392 | 392 | undo = repo.sjoin('undo') |
|
393 | 393 | if not os.path.exists(undo): |
|
394 | 394 | return |
|
395 | 395 | try: |
|
396 | 396 | os.unlink(undo) |
|
397 | 397 | except OSError, inst: |
|
398 | 398 | self.ui.warn(_('error removing undo: %s\n') % str(inst)) |
|
399 | 399 | |
|
400 | 400 | def printdiff(self, repo, node1, node2=None, files=None, |
|
401 | 401 | fp=None, changes=None, opts={}): |
|
402 | 402 | m = cmdutil.match(repo, files, opts) |
|
403 | 403 | chunks = patch.diff(repo, node1, node2, m, changes, self.diffopts()) |
|
404 | 404 | write = fp is None and repo.ui.write or fp.write |
|
405 | 405 | for chunk in chunks: |
|
406 | 406 | write(chunk) |
|
407 | 407 | |
|
408 | 408 | def mergeone(self, repo, mergeq, head, patch, rev): |
|
409 | 409 | # first try just applying the patch |
|
410 | 410 | (err, n) = self.apply(repo, [ patch ], update_status=False, |
|
411 | 411 | strict=True, merge=rev) |
|
412 | 412 | |
|
413 | 413 | if err == 0: |
|
414 | 414 | return (err, n) |
|
415 | 415 | |
|
416 | 416 | if n is None: |
|
417 | 417 | raise util.Abort(_("apply failed for patch %s") % patch) |
|
418 | 418 | |
|
419 | 419 | self.ui.warn(_("patch didn't work out, merging %s\n") % patch) |
|
420 | 420 | |
|
421 | 421 | # apply failed, strip away that rev and merge. |
|
422 | 422 | hg.clean(repo, head) |
|
423 | 423 | self.strip(repo, n, update=False, backup='strip') |
|
424 | 424 | |
|
425 | 425 | ctx = repo[rev] |
|
426 | 426 | ret = hg.merge(repo, rev) |
|
427 | 427 | if ret: |
|
428 | 428 | raise util.Abort(_("update returned %d") % ret) |
|
429 | 429 | n = repo.commit(ctx.description(), ctx.user(), force=True) |
|
430 | 430 | if n is None: |
|
431 | 431 | raise util.Abort(_("repo commit failed")) |
|
432 | 432 | try: |
|
433 | 433 | ph = patchheader(mergeq.join(patch)) |
|
434 | 434 | except: |
|
435 | 435 | raise util.Abort(_("unable to read %s") % patch) |
|
436 | 436 | |
|
437 | 437 | patchf = self.opener(patch, "w") |
|
438 | 438 | comments = str(ph) |
|
439 | 439 | if comments: |
|
440 | 440 | patchf.write(comments) |
|
441 | 441 | self.printdiff(repo, head, n, fp=patchf) |
|
442 | 442 | patchf.close() |
|
443 | 443 | self.removeundo(repo) |
|
444 | 444 | return (0, n) |
|
445 | 445 | |
|
446 | 446 | def qparents(self, repo, rev=None): |
|
447 | 447 | if rev is None: |
|
448 | 448 | (p1, p2) = repo.dirstate.parents() |
|
449 | 449 | if p2 == nullid: |
|
450 | 450 | return p1 |
|
451 | 451 | if len(self.applied) == 0: |
|
452 | 452 | return None |
|
453 | 453 | return bin(self.applied[-1].rev) |
|
454 | 454 | pp = repo.changelog.parents(rev) |
|
455 | 455 | if pp[1] != nullid: |
|
456 | 456 | arevs = [ x.rev for x in self.applied ] |
|
457 | 457 | p0 = hex(pp[0]) |
|
458 | 458 | p1 = hex(pp[1]) |
|
459 | 459 | if p0 in arevs: |
|
460 | 460 | return pp[0] |
|
461 | 461 | if p1 in arevs: |
|
462 | 462 | return pp[1] |
|
463 | 463 | return pp[0] |
|
464 | 464 | |
|
465 | 465 | def mergepatch(self, repo, mergeq, series): |
|
466 | 466 | if len(self.applied) == 0: |
|
467 | 467 | # each of the patches merged in will have two parents. This |
|
468 | 468 | # can confuse the qrefresh, qdiff, and strip code because it |
|
469 | 469 | # needs to know which parent is actually in the patch queue. |
|
470 | 470 | # so, we insert a merge marker with only one parent. This way |
|
471 | 471 | # the first patch in the queue is never a merge patch |
|
472 | 472 | # |
|
473 | 473 | pname = ".hg.patches.merge.marker" |
|
474 | 474 | n = repo.commit('[mq]: merge marker', force=True) |
|
475 | 475 | self.removeundo(repo) |
|
476 | 476 | self.applied.append(statusentry(hex(n), pname)) |
|
477 | 477 | self.applied_dirty = 1 |
|
478 | 478 | |
|
479 | 479 | head = self.qparents(repo) |
|
480 | 480 | |
|
481 | 481 | for patch in series: |
|
482 | 482 | patch = mergeq.lookup(patch, strict=True) |
|
483 | 483 | if not patch: |
|
484 | 484 | self.ui.warn(_("patch %s does not exist\n") % patch) |
|
485 | 485 | return (1, None) |
|
486 | 486 | pushable, reason = self.pushable(patch) |
|
487 | 487 | if not pushable: |
|
488 | 488 | self.explain_pushable(patch, all_patches=True) |
|
489 | 489 | continue |
|
490 | 490 | info = mergeq.isapplied(patch) |
|
491 | 491 | if not info: |
|
492 | 492 | self.ui.warn(_("patch %s is not applied\n") % patch) |
|
493 | 493 | return (1, None) |
|
494 | 494 | rev = bin(info[1]) |
|
495 | 495 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev) |
|
496 | 496 | if head: |
|
497 | 497 | self.applied.append(statusentry(hex(head), patch)) |
|
498 | 498 | self.applied_dirty = 1 |
|
499 | 499 | if err: |
|
500 | 500 | return (err, head) |
|
501 | 501 | self.save_dirty() |
|
502 | 502 | return (0, head) |
|
503 | 503 | |
|
504 | 504 | def patch(self, repo, patchfile): |
|
505 | 505 | '''Apply patchfile to the working directory. |
|
506 | 506 | patchfile: name of patch file''' |
|
507 | 507 | files = {} |
|
508 | 508 | try: |
|
509 | 509 | fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root, |
|
510 | 510 | files=files, eolmode=None) |
|
511 | 511 | except Exception, inst: |
|
512 | 512 | self.ui.note(str(inst) + '\n') |
|
513 | 513 | if not self.ui.verbose: |
|
514 | 514 | self.ui.warn(_("patch failed, unable to continue (try -v)\n")) |
|
515 | 515 | return (False, files, False) |
|
516 | 516 | |
|
517 | 517 | return (True, files, fuzz) |
|
518 | 518 | |
|
519 | 519 | def apply(self, repo, series, list=False, update_status=True, |
|
520 | 520 | strict=False, patchdir=None, merge=None, all_files={}): |
|
521 | 521 | wlock = lock = tr = None |
|
522 | 522 | try: |
|
523 | 523 | wlock = repo.wlock() |
|
524 | 524 | lock = repo.lock() |
|
525 | 525 | tr = repo.transaction() |
|
526 | 526 | try: |
|
527 | 527 | ret = self._apply(repo, series, list, update_status, |
|
528 | 528 | strict, patchdir, merge, all_files=all_files) |
|
529 | 529 | tr.close() |
|
530 | 530 | self.save_dirty() |
|
531 | 531 | return ret |
|
532 | 532 | except: |
|
533 | 533 | try: |
|
534 | 534 | tr.abort() |
|
535 | 535 | finally: |
|
536 | 536 | repo.invalidate() |
|
537 | 537 | repo.dirstate.invalidate() |
|
538 | 538 | raise |
|
539 | 539 | finally: |
|
540 | 540 | del tr |
|
541 | 541 | release(lock, wlock) |
|
542 | 542 | self.removeundo(repo) |
|
543 | 543 | |
|
544 | 544 | def _apply(self, repo, series, list=False, update_status=True, |
|
545 | 545 | strict=False, patchdir=None, merge=None, all_files={}): |
|
546 | 546 | '''returns (error, hash) |
|
547 | 547 | error = 1 for unable to read, 2 for patch failed, 3 for patch fuzz''' |
|
548 | 548 | # TODO unify with commands.py |
|
549 | 549 | if not patchdir: |
|
550 | 550 | patchdir = self.path |
|
551 | 551 | err = 0 |
|
552 | 552 | n = None |
|
553 | 553 | for patchname in series: |
|
554 | 554 | pushable, reason = self.pushable(patchname) |
|
555 | 555 | if not pushable: |
|
556 | 556 | self.explain_pushable(patchname, all_patches=True) |
|
557 | 557 | continue |
|
558 | 558 | self.ui.status(_("applying %s\n") % patchname) |
|
559 | 559 | pf = os.path.join(patchdir, patchname) |
|
560 | 560 | |
|
561 | 561 | try: |
|
562 | 562 | ph = patchheader(self.join(patchname)) |
|
563 | 563 | except: |
|
564 | 564 | self.ui.warn(_("unable to read %s\n") % patchname) |
|
565 | 565 | err = 1 |
|
566 | 566 | break |
|
567 | 567 | |
|
568 | 568 | message = ph.message |
|
569 | 569 | if not message: |
|
570 | 570 | message = _("imported patch %s\n") % patchname |
|
571 | 571 | else: |
|
572 | 572 | if list: |
|
573 | 573 | message.append(_("\nimported patch %s") % patchname) |
|
574 | 574 | message = '\n'.join(message) |
|
575 | 575 | |
|
576 | 576 | if ph.haspatch: |
|
577 | 577 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
578 | 578 | all_files.update(files) |
|
579 | 579 | patcherr = not patcherr |
|
580 | 580 | else: |
|
581 | 581 | self.ui.warn(_("patch %s is empty\n") % patchname) |
|
582 | 582 | patcherr, files, fuzz = 0, [], 0 |
|
583 | 583 | |
|
584 | 584 | if merge and files: |
|
585 | 585 | # Mark as removed/merged and update dirstate parent info |
|
586 | 586 | removed = [] |
|
587 | 587 | merged = [] |
|
588 | 588 | for f in files: |
|
589 | 589 | if os.path.exists(repo.wjoin(f)): |
|
590 | 590 | merged.append(f) |
|
591 | 591 | else: |
|
592 | 592 | removed.append(f) |
|
593 | 593 | for f in removed: |
|
594 | 594 | repo.dirstate.remove(f) |
|
595 | 595 | for f in merged: |
|
596 | 596 | repo.dirstate.merge(f) |
|
597 | 597 | p1, p2 = repo.dirstate.parents() |
|
598 | 598 | repo.dirstate.setparents(p1, merge) |
|
599 | 599 | |
|
600 | 600 | files = patch.updatedir(self.ui, repo, files) |
|
601 | 601 | match = cmdutil.matchfiles(repo, files or []) |
|
602 | 602 | n = repo.commit(message, ph.user, ph.date, match=match, force=True) |
|
603 | 603 | |
|
604 | 604 | if n is None: |
|
605 | 605 | raise util.Abort(_("repo commit failed")) |
|
606 | 606 | |
|
607 | 607 | if update_status: |
|
608 | 608 | self.applied.append(statusentry(hex(n), patchname)) |
|
609 | 609 | |
|
610 | 610 | if patcherr: |
|
611 | 611 | self.ui.warn(_("patch failed, rejects left in working dir\n")) |
|
612 | 612 | err = 2 |
|
613 | 613 | break |
|
614 | 614 | |
|
615 | 615 | if fuzz and strict: |
|
616 | 616 | self.ui.warn(_("fuzz found when applying patch, stopping\n")) |
|
617 | 617 | err = 3 |
|
618 | 618 | break |
|
619 | 619 | return (err, n) |
|
620 | 620 | |
|
621 | 621 | def _cleanup(self, patches, numrevs, keep=False): |
|
622 | 622 | if not keep: |
|
623 | 623 | r = self.qrepo() |
|
624 | 624 | if r: |
|
625 | 625 | r.remove(patches, True) |
|
626 | 626 | else: |
|
627 | 627 | for p in patches: |
|
628 | 628 | os.unlink(self.join(p)) |
|
629 | 629 | |
|
630 | 630 | if numrevs: |
|
631 | 631 | del self.applied[:numrevs] |
|
632 | 632 | self.applied_dirty = 1 |
|
633 | 633 | |
|
634 | 634 | for i in sorted([self.find_series(p) for p in patches], reverse=True): |
|
635 | 635 | del self.full_series[i] |
|
636 | 636 | self.parse_series() |
|
637 | 637 | self.series_dirty = 1 |
|
638 | 638 | |
|
639 | 639 | def _revpatches(self, repo, revs): |
|
640 | 640 | firstrev = repo[self.applied[0].rev].rev() |
|
641 | 641 | patches = [] |
|
642 | 642 | for i, rev in enumerate(revs): |
|
643 | 643 | |
|
644 | 644 | if rev < firstrev: |
|
645 | 645 | raise util.Abort(_('revision %d is not managed') % rev) |
|
646 | 646 | |
|
647 | 647 | ctx = repo[rev] |
|
648 | 648 | base = bin(self.applied[i].rev) |
|
649 | 649 | if ctx.node() != base: |
|
650 | 650 | msg = _('cannot delete revision %d above applied patches') |
|
651 | 651 | raise util.Abort(msg % rev) |
|
652 | 652 | |
|
653 | 653 | patch = self.applied[i].name |
|
654 | 654 | for fmt in ('[mq]: %s', 'imported patch %s'): |
|
655 | 655 | if ctx.description() == fmt % patch: |
|
656 | 656 | msg = _('patch %s finalized without changeset message\n') |
|
657 | 657 | repo.ui.status(msg % patch) |
|
658 | 658 | break |
|
659 | 659 | |
|
660 | 660 | patches.append(patch) |
|
661 | 661 | return patches |
|
662 | 662 | |
|
663 | 663 | def finish(self, repo, revs): |
|
664 | 664 | patches = self._revpatches(repo, sorted(revs)) |
|
665 | 665 | self._cleanup(patches, len(patches)) |
|
666 | 666 | |
|
667 | 667 | def delete(self, repo, patches, opts): |
|
668 | 668 | if not patches and not opts.get('rev'): |
|
669 | 669 | raise util.Abort(_('qdelete requires at least one revision or ' |
|
670 | 670 | 'patch name')) |
|
671 | 671 | |
|
672 | 672 | realpatches = [] |
|
673 | 673 | for patch in patches: |
|
674 | 674 | patch = self.lookup(patch, strict=True) |
|
675 | 675 | info = self.isapplied(patch) |
|
676 | 676 | if info: |
|
677 | 677 | raise util.Abort(_("cannot delete applied patch %s") % patch) |
|
678 | 678 | if patch not in self.series: |
|
679 | 679 | raise util.Abort(_("patch %s not in series file") % patch) |
|
680 | 680 | realpatches.append(patch) |
|
681 | 681 | |
|
682 | 682 | numrevs = 0 |
|
683 | 683 | if opts.get('rev'): |
|
684 | 684 | if not self.applied: |
|
685 | 685 | raise util.Abort(_('no patches applied')) |
|
686 | 686 | revs = cmdutil.revrange(repo, opts['rev']) |
|
687 | 687 | if len(revs) > 1 and revs[0] > revs[1]: |
|
688 | 688 | revs.reverse() |
|
689 | 689 | revpatches = self._revpatches(repo, revs) |
|
690 | 690 | realpatches += revpatches |
|
691 | 691 | numrevs = len(revpatches) |
|
692 | 692 | |
|
693 | 693 | self._cleanup(realpatches, numrevs, opts.get('keep')) |
|
694 | 694 | |
|
695 | 695 | def check_toppatch(self, repo): |
|
696 | 696 | if len(self.applied) > 0: |
|
697 | 697 | top = bin(self.applied[-1].rev) |
|
698 | 698 | pp = repo.dirstate.parents() |
|
699 | 699 | if top not in pp: |
|
700 | 700 | raise util.Abort(_("working directory revision is not qtip")) |
|
701 | 701 | return top |
|
702 | 702 | return None |
|
703 | 703 | def check_localchanges(self, repo, force=False, refresh=True): |
|
704 | 704 | m, a, r, d = repo.status()[:4] |
|
705 | 705 | if m or a or r or d: |
|
706 | 706 | if not force: |
|
707 | 707 | if refresh: |
|
708 | 708 | raise util.Abort(_("local changes found, refresh first")) |
|
709 | 709 | else: |
|
710 | 710 | raise util.Abort(_("local changes found")) |
|
711 | 711 | return m, a, r, d |
|
712 | 712 | |
|
713 | 713 | _reserved = ('series', 'status', 'guards') |
|
714 | 714 | def check_reserved_name(self, name): |
|
715 | 715 | if (name in self._reserved or name.startswith('.hg') |
|
716 | 716 | or name.startswith('.mq')): |
|
717 | 717 | raise util.Abort(_('"%s" cannot be used as the name of a patch') |
|
718 | 718 | % name) |
|
719 | 719 | |
|
720 | 720 | def new(self, repo, patchfn, *pats, **opts): |
|
721 | 721 | """options: |
|
722 | 722 | msg: a string or a no-argument function returning a string |
|
723 | 723 | """ |
|
724 | 724 | msg = opts.get('msg') |
|
725 | 725 | force = opts.get('force') |
|
726 | 726 | user = opts.get('user') |
|
727 | 727 | date = opts.get('date') |
|
728 | 728 | if date: |
|
729 | 729 | date = util.parsedate(date) |
|
730 | 730 | self.check_reserved_name(patchfn) |
|
731 | 731 | if os.path.exists(self.join(patchfn)): |
|
732 | 732 | raise util.Abort(_('patch "%s" already exists') % patchfn) |
|
733 | 733 | if opts.get('include') or opts.get('exclude') or pats: |
|
734 | 734 | match = cmdutil.match(repo, pats, opts) |
|
735 | 735 | # detect missing files in pats |
|
736 | 736 | def badfn(f, msg): |
|
737 | 737 | raise util.Abort('%s: %s' % (f, msg)) |
|
738 | 738 | match.bad = badfn |
|
739 | 739 | m, a, r, d = repo.status(match=match)[:4] |
|
740 | 740 | else: |
|
741 | 741 | m, a, r, d = self.check_localchanges(repo, force) |
|
742 | 742 | match = cmdutil.matchfiles(repo, m + a + r) |
|
743 | 743 | commitfiles = m + a + r |
|
744 | 744 | self.check_toppatch(repo) |
|
745 | 745 | insert = self.full_series_end() |
|
746 | 746 | wlock = repo.wlock() |
|
747 | 747 | try: |
|
748 | 748 | # if patch file write fails, abort early |
|
749 | 749 | p = self.opener(patchfn, "w") |
|
750 | 750 | try: |
|
751 | 751 | if date: |
|
752 | 752 | p.write("# HG changeset patch\n") |
|
753 | 753 | if user: |
|
754 | 754 | p.write("# User " + user + "\n") |
|
755 | 755 | p.write("# Date %d %d\n\n" % date) |
|
756 | 756 | elif user: |
|
757 | 757 | p.write("From: " + user + "\n\n") |
|
758 | 758 | |
|
759 | 759 | if hasattr(msg, '__call__'): |
|
760 | 760 | msg = msg() |
|
761 | 761 | commitmsg = msg and msg or ("[mq]: %s" % patchfn) |
|
762 | 762 | n = repo.commit(commitmsg, user, date, match=match, force=True) |
|
763 | 763 | if n is None: |
|
764 | 764 | raise util.Abort(_("repo commit failed")) |
|
765 | 765 | try: |
|
766 | 766 | self.full_series[insert:insert] = [patchfn] |
|
767 | 767 | self.applied.append(statusentry(hex(n), patchfn)) |
|
768 | 768 | self.parse_series() |
|
769 | 769 | self.series_dirty = 1 |
|
770 | 770 | self.applied_dirty = 1 |
|
771 | 771 | if msg: |
|
772 | 772 | msg = msg + "\n\n" |
|
773 | 773 | p.write(msg) |
|
774 | 774 | if commitfiles: |
|
775 | 775 | diffopts = self.diffopts() |
|
776 | 776 | if opts.get('git'): diffopts.git = True |
|
777 | 777 | parent = self.qparents(repo, n) |
|
778 | 778 | chunks = patch.diff(repo, node1=parent, node2=n, |
|
779 | 779 | match=match, opts=diffopts) |
|
780 | 780 | for chunk in chunks: |
|
781 | 781 | p.write(chunk) |
|
782 | 782 | p.close() |
|
783 | 783 | wlock.release() |
|
784 | 784 | wlock = None |
|
785 | 785 | r = self.qrepo() |
|
786 | 786 | if r: r.add([patchfn]) |
|
787 | 787 | except: |
|
788 | 788 | repo.rollback() |
|
789 | 789 | raise |
|
790 | 790 | except Exception: |
|
791 | 791 | patchpath = self.join(patchfn) |
|
792 | 792 | try: |
|
793 | 793 | os.unlink(patchpath) |
|
794 | 794 | except: |
|
795 | 795 | self.ui.warn(_('error unlinking %s\n') % patchpath) |
|
796 | 796 | raise |
|
797 | 797 | self.removeundo(repo) |
|
798 | 798 | finally: |
|
799 | 799 | release(wlock) |
|
800 | 800 | |
|
801 | 801 | def strip(self, repo, rev, update=True, backup="all", force=None): |
|
802 | 802 | wlock = lock = None |
|
803 | 803 | try: |
|
804 | 804 | wlock = repo.wlock() |
|
805 | 805 | lock = repo.lock() |
|
806 | 806 | |
|
807 | 807 | if update: |
|
808 | 808 | self.check_localchanges(repo, force=force, refresh=False) |
|
809 | 809 | urev = self.qparents(repo, rev) |
|
810 | 810 | hg.clean(repo, urev) |
|
811 | 811 | repo.dirstate.write() |
|
812 | 812 | |
|
813 | 813 | self.removeundo(repo) |
|
814 | 814 | repair.strip(self.ui, repo, rev, backup) |
|
815 | 815 | # strip may have unbundled a set of backed up revisions after |
|
816 | 816 | # the actual strip |
|
817 | 817 | self.removeundo(repo) |
|
818 | 818 | finally: |
|
819 | 819 | release(lock, wlock) |
|
820 | 820 | |
|
821 | 821 | def isapplied(self, patch): |
|
822 | 822 | """returns (index, rev, patch)""" |
|
823 | 823 | for i, a in enumerate(self.applied): |
|
824 | 824 | if a.name == patch: |
|
825 | 825 | return (i, a.rev, a.name) |
|
826 | 826 | return None |
|
827 | 827 | |
|
828 | 828 | # if the exact patch name does not exist, we try a few |
|
829 | 829 | # variations. If strict is passed, we try only #1 |
|
830 | 830 | # |
|
831 | 831 | # 1) a number to indicate an offset in the series file |
|
832 | 832 | # 2) a unique substring of the patch name was given |
|
833 | 833 | # 3) patchname[-+]num to indicate an offset in the series file |
|
834 | 834 | def lookup(self, patch, strict=False): |
|
835 | 835 | patch = patch and str(patch) |
|
836 | 836 | |
|
837 | 837 | def partial_name(s): |
|
838 | 838 | if s in self.series: |
|
839 | 839 | return s |
|
840 | 840 | matches = [x for x in self.series if s in x] |
|
841 | 841 | if len(matches) > 1: |
|
842 | 842 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) |
|
843 | 843 | for m in matches: |
|
844 | 844 | self.ui.warn(' %s\n' % m) |
|
845 | 845 | return None |
|
846 | 846 | if matches: |
|
847 | 847 | return matches[0] |
|
848 | 848 | if len(self.series) > 0 and len(self.applied) > 0: |
|
849 | 849 | if s == 'qtip': |
|
850 | 850 | return self.series[self.series_end(True)-1] |
|
851 | 851 | if s == 'qbase': |
|
852 | 852 | return self.series[0] |
|
853 | 853 | return None |
|
854 | 854 | |
|
855 | 855 | if patch is None: |
|
856 | 856 | return None |
|
857 | 857 | if patch in self.series: |
|
858 | 858 | return patch |
|
859 | 859 | |
|
860 | 860 | if not os.path.isfile(self.join(patch)): |
|
861 | 861 | try: |
|
862 | 862 | sno = int(patch) |
|
863 | 863 | except(ValueError, OverflowError): |
|
864 | 864 | pass |
|
865 | 865 | else: |
|
866 | 866 | if -len(self.series) <= sno < len(self.series): |
|
867 | 867 | return self.series[sno] |
|
868 | 868 | |
|
869 | 869 | if not strict: |
|
870 | 870 | res = partial_name(patch) |
|
871 | 871 | if res: |
|
872 | 872 | return res |
|
873 | 873 | minus = patch.rfind('-') |
|
874 | 874 | if minus >= 0: |
|
875 | 875 | res = partial_name(patch[:minus]) |
|
876 | 876 | if res: |
|
877 | 877 | i = self.series.index(res) |
|
878 | 878 | try: |
|
879 | 879 | off = int(patch[minus+1:] or 1) |
|
880 | 880 | except(ValueError, OverflowError): |
|
881 | 881 | pass |
|
882 | 882 | else: |
|
883 | 883 | if i - off >= 0: |
|
884 | 884 | return self.series[i - off] |
|
885 | 885 | plus = patch.rfind('+') |
|
886 | 886 | if plus >= 0: |
|
887 | 887 | res = partial_name(patch[:plus]) |
|
888 | 888 | if res: |
|
889 | 889 | i = self.series.index(res) |
|
890 | 890 | try: |
|
891 | 891 | off = int(patch[plus+1:] or 1) |
|
892 | 892 | except(ValueError, OverflowError): |
|
893 | 893 | pass |
|
894 | 894 | else: |
|
895 | 895 | if i + off < len(self.series): |
|
896 | 896 | return self.series[i + off] |
|
897 | 897 | raise util.Abort(_("patch %s not in series") % patch) |
|
898 | 898 | |
|
899 | 899 | def push(self, repo, patch=None, force=False, list=False, |
|
900 | 900 | mergeq=None, all=False): |
|
901 | 901 | wlock = repo.wlock() |
|
902 | 902 | try: |
|
903 | 903 | if repo.dirstate.parents()[0] not in repo.heads(): |
|
904 | 904 | self.ui.status(_("(working directory not at a head)\n")) |
|
905 | 905 | |
|
906 | 906 | if not self.series: |
|
907 | 907 | self.ui.warn(_('no patches in series\n')) |
|
908 | 908 | return 0 |
|
909 | 909 | |
|
910 | 910 | patch = self.lookup(patch) |
|
911 | 911 | # Suppose our series file is: A B C and the current 'top' |
|
912 | 912 | # patch is B. qpush C should be performed (moving forward) |
|
913 | 913 | # qpush B is a NOP (no change) qpush A is an error (can't |
|
914 | 914 | # go backwards with qpush) |
|
915 | 915 | if patch: |
|
916 | 916 | info = self.isapplied(patch) |
|
917 | 917 | if info: |
|
918 | 918 | if info[0] < len(self.applied) - 1: |
|
919 | 919 | raise util.Abort( |
|
920 | 920 | _("cannot push to a previous patch: %s") % patch) |
|
921 | 921 | self.ui.warn( |
|
922 | 922 | _('qpush: %s is already at the top\n') % patch) |
|
923 | 923 | return |
|
924 | 924 | pushable, reason = self.pushable(patch) |
|
925 | 925 | if not pushable: |
|
926 | 926 | if reason: |
|
927 | 927 | reason = _('guarded by %r') % reason |
|
928 | 928 | else: |
|
929 | 929 | reason = _('no matching guards') |
|
930 | 930 | self.ui.warn(_("cannot push '%s' - %s\n") % (patch, reason)) |
|
931 | 931 | return 1 |
|
932 | 932 | elif all: |
|
933 | 933 | patch = self.series[-1] |
|
934 | 934 | if self.isapplied(patch): |
|
935 | 935 | self.ui.warn(_('all patches are currently applied\n')) |
|
936 | 936 | return 0 |
|
937 | 937 | |
|
938 | 938 | # Following the above example, starting at 'top' of B: |
|
939 | 939 | # qpush should be performed (pushes C), but a subsequent |
|
940 | 940 | # qpush without an argument is an error (nothing to |
|
941 | 941 | # apply). This allows a loop of "...while hg qpush..." to |
|
942 | 942 | # work as it detects an error when done |
|
943 | 943 | start = self.series_end() |
|
944 | 944 | if start == len(self.series): |
|
945 | 945 | self.ui.warn(_('patch series already fully applied\n')) |
|
946 | 946 | return 1 |
|
947 | 947 | if not force: |
|
948 | 948 | self.check_localchanges(repo) |
|
949 | 949 | |
|
950 | 950 | self.applied_dirty = 1 |
|
951 | 951 | if start > 0: |
|
952 | 952 | self.check_toppatch(repo) |
|
953 | 953 | if not patch: |
|
954 | 954 | patch = self.series[start] |
|
955 | 955 | end = start + 1 |
|
956 | 956 | else: |
|
957 | 957 | end = self.series.index(patch, start) + 1 |
|
958 | 958 | |
|
959 | 959 | s = self.series[start:end] |
|
960 | 960 | all_files = {} |
|
961 | 961 | try: |
|
962 | 962 | if mergeq: |
|
963 | 963 | ret = self.mergepatch(repo, mergeq, s) |
|
964 | 964 | else: |
|
965 | 965 | ret = self.apply(repo, s, list, all_files=all_files) |
|
966 | 966 | except: |
|
967 | 967 | self.ui.warn(_('cleaning up working directory...')) |
|
968 | 968 | node = repo.dirstate.parents()[0] |
|
969 | 969 | hg.revert(repo, node, None) |
|
970 | 970 | unknown = repo.status(unknown=True)[4] |
|
971 | 971 | # only remove unknown files that we know we touched or |
|
972 | 972 | # created while patching |
|
973 | 973 | for f in unknown: |
|
974 | 974 | if f in all_files: |
|
975 | 975 | util.unlink(repo.wjoin(f)) |
|
976 | 976 | self.ui.warn(_('done\n')) |
|
977 | 977 | raise |
|
978 | 978 | |
|
979 | 979 | top = self.applied[-1].name |
|
980 | 980 | if ret[0] and ret[0] > 1: |
|
981 | 981 | msg = _("errors during apply, please fix and refresh %s\n") |
|
982 | 982 | self.ui.write(msg % top) |
|
983 | 983 | else: |
|
984 | 984 | self.ui.write(_("now at: %s\n") % top) |
|
985 | 985 | return ret[0] |
|
986 | 986 | |
|
987 | 987 | finally: |
|
988 | 988 | wlock.release() |
|
989 | 989 | |
|
990 | 990 | def pop(self, repo, patch=None, force=False, update=True, all=False): |
|
991 | 991 | def getfile(f, rev, flags): |
|
992 | 992 | t = repo.file(f).read(rev) |
|
993 | 993 | repo.wwrite(f, t, flags) |
|
994 | 994 | |
|
995 | 995 | wlock = repo.wlock() |
|
996 | 996 | try: |
|
997 | 997 | if patch: |
|
998 | 998 | # index, rev, patch |
|
999 | 999 | info = self.isapplied(patch) |
|
1000 | 1000 | if not info: |
|
1001 | 1001 | patch = self.lookup(patch) |
|
1002 | 1002 | info = self.isapplied(patch) |
|
1003 | 1003 | if not info: |
|
1004 | 1004 | raise util.Abort(_("patch %s is not applied") % patch) |
|
1005 | 1005 | |
|
1006 | 1006 | if len(self.applied) == 0: |
|
1007 | 1007 | # Allow qpop -a to work repeatedly, |
|
1008 | 1008 | # but not qpop without an argument |
|
1009 | 1009 | self.ui.warn(_("no patches applied\n")) |
|
1010 | 1010 | return not all |
|
1011 | 1011 | |
|
1012 | 1012 | if all: |
|
1013 | 1013 | start = 0 |
|
1014 | 1014 | elif patch: |
|
1015 | 1015 | start = info[0] + 1 |
|
1016 | 1016 | else: |
|
1017 | 1017 | start = len(self.applied) - 1 |
|
1018 | 1018 | |
|
1019 | 1019 | if start >= len(self.applied): |
|
1020 | 1020 | self.ui.warn(_("qpop: %s is already at the top\n") % patch) |
|
1021 | 1021 | return |
|
1022 | 1022 | |
|
1023 | 1023 | if not update: |
|
1024 | 1024 | parents = repo.dirstate.parents() |
|
1025 | 1025 | rr = [ bin(x.rev) for x in self.applied ] |
|
1026 | 1026 | for p in parents: |
|
1027 | 1027 | if p in rr: |
|
1028 | 1028 | self.ui.warn(_("qpop: forcing dirstate update\n")) |
|
1029 | 1029 | update = True |
|
1030 | 1030 | else: |
|
1031 | 1031 | parents = [p.hex() for p in repo[None].parents()] |
|
1032 | 1032 | needupdate = False |
|
1033 | 1033 | for entry in self.applied[start:]: |
|
1034 | 1034 | if entry.rev in parents: |
|
1035 | 1035 | needupdate = True |
|
1036 | 1036 | break |
|
1037 | 1037 | update = needupdate |
|
1038 | 1038 | |
|
1039 | 1039 | if not force and update: |
|
1040 | 1040 | self.check_localchanges(repo) |
|
1041 | 1041 | |
|
1042 | 1042 | self.applied_dirty = 1 |
|
1043 | 1043 | end = len(self.applied) |
|
1044 | 1044 | rev = bin(self.applied[start].rev) |
|
1045 | 1045 | if update: |
|
1046 | 1046 | top = self.check_toppatch(repo) |
|
1047 | 1047 | |
|
1048 | 1048 | try: |
|
1049 | 1049 | heads = repo.changelog.heads(rev) |
|
1050 | 1050 | except error.LookupError: |
|
1051 | 1051 | node = short(rev) |
|
1052 | 1052 | raise util.Abort(_('trying to pop unknown node %s') % node) |
|
1053 | 1053 | |
|
1054 | 1054 | if heads != [bin(self.applied[-1].rev)]: |
|
1055 | 1055 | raise util.Abort(_("popping would remove a revision not " |
|
1056 | 1056 | "managed by this patch queue")) |
|
1057 | 1057 | |
|
1058 | 1058 | # we know there are no local changes, so we can make a simplified |
|
1059 | 1059 | # form of hg.update. |
|
1060 | 1060 | if update: |
|
1061 | 1061 | qp = self.qparents(repo, rev) |
|
1062 | 1062 | changes = repo.changelog.read(qp) |
|
1063 | 1063 | mmap = repo.manifest.read(changes[0]) |
|
1064 | 1064 | m, a, r, d = repo.status(qp, top)[:4] |
|
1065 | 1065 | if d: |
|
1066 | 1066 | raise util.Abort(_("deletions found between repo revs")) |
|
1067 | 1067 | for f in m: |
|
1068 | 1068 | getfile(f, mmap[f], mmap.flags(f)) |
|
1069 | 1069 | for f in r: |
|
1070 | 1070 | getfile(f, mmap[f], mmap.flags(f)) |
|
1071 | 1071 | for f in m + r: |
|
1072 | 1072 | repo.dirstate.normal(f) |
|
1073 | 1073 | for f in a: |
|
1074 | 1074 | try: |
|
1075 | 1075 | os.unlink(repo.wjoin(f)) |
|
1076 | 1076 | except OSError, e: |
|
1077 | 1077 | if e.errno != errno.ENOENT: |
|
1078 | 1078 | raise |
|
1079 | 1079 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
1080 | 1080 | except: pass |
|
1081 | 1081 | repo.dirstate.forget(f) |
|
1082 | 1082 | repo.dirstate.setparents(qp, nullid) |
|
1083 | 1083 | for patch in reversed(self.applied[start:end]): |
|
1084 | 1084 | self.ui.status(_("popping %s\n") % patch.name) |
|
1085 | 1085 | del self.applied[start:end] |
|
1086 | 1086 | self.strip(repo, rev, update=False, backup='strip') |
|
1087 | 1087 | if len(self.applied): |
|
1088 | 1088 | self.ui.write(_("now at: %s\n") % self.applied[-1].name) |
|
1089 | 1089 | else: |
|
1090 | 1090 | self.ui.write(_("patch queue now empty\n")) |
|
1091 | 1091 | finally: |
|
1092 | 1092 | wlock.release() |
|
1093 | 1093 | |
|
1094 | 1094 | def diff(self, repo, pats, opts): |
|
1095 | 1095 | top = self.check_toppatch(repo) |
|
1096 | 1096 | if not top: |
|
1097 | 1097 | self.ui.write(_("no patches applied\n")) |
|
1098 | 1098 | return |
|
1099 | 1099 | qp = self.qparents(repo, top) |
|
1100 | 1100 | self._diffopts = patch.diffopts(self.ui, opts) |
|
1101 | 1101 | self.printdiff(repo, qp, files=pats, opts=opts) |
|
1102 | 1102 | |
|
1103 | 1103 | def refresh(self, repo, pats=None, **opts): |
|
1104 | 1104 | if len(self.applied) == 0: |
|
1105 | 1105 | self.ui.write(_("no patches applied\n")) |
|
1106 | 1106 | return 1 |
|
1107 | 1107 | msg = opts.get('msg', '').rstrip() |
|
1108 | 1108 | newuser = opts.get('user') |
|
1109 | 1109 | newdate = opts.get('date') |
|
1110 | 1110 | if newdate: |
|
1111 | 1111 | newdate = '%d %d' % util.parsedate(newdate) |
|
1112 | 1112 | wlock = repo.wlock() |
|
1113 | 1113 | try: |
|
1114 | 1114 | self.check_toppatch(repo) |
|
1115 | 1115 | (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) |
|
1116 | 1116 | top = bin(top) |
|
1117 | 1117 | if repo.changelog.heads(top) != [top]: |
|
1118 | 1118 | raise util.Abort(_("cannot refresh a revision with children")) |
|
1119 | 1119 | cparents = repo.changelog.parents(top) |
|
1120 | 1120 | patchparent = self.qparents(repo, top) |
|
1121 | 1121 | ph = patchheader(self.join(patchfn)) |
|
1122 | 1122 | |
|
1123 | 1123 | patchf = self.opener(patchfn, 'r') |
|
1124 | 1124 | |
|
1125 | 1125 | # if the patch was a git patch, refresh it as a git patch |
|
1126 | 1126 | for line in patchf: |
|
1127 | 1127 | if line.startswith('diff --git'): |
|
1128 | 1128 | self.diffopts().git = True |
|
1129 | 1129 | break |
|
1130 | 1130 | |
|
1131 | 1131 | if msg: |
|
1132 | 1132 | ph.setmessage(msg) |
|
1133 | 1133 | if newuser: |
|
1134 | 1134 | ph.setuser(newuser) |
|
1135 | 1135 | if newdate: |
|
1136 | 1136 | ph.setdate(newdate) |
|
1137 | 1137 | |
|
1138 | 1138 | # only commit new patch when write is complete |
|
1139 | 1139 | patchf = self.opener(patchfn, 'w', atomictemp=True) |
|
1140 | 1140 | |
|
1141 | 1141 | patchf.seek(0) |
|
1142 | 1142 | patchf.truncate() |
|
1143 | 1143 | |
|
1144 | 1144 | comments = str(ph) |
|
1145 | 1145 | if comments: |
|
1146 | 1146 | patchf.write(comments) |
|
1147 | 1147 | |
|
1148 | 1148 | if opts.get('git'): |
|
1149 | 1149 | self.diffopts().git = True |
|
1150 | 1150 | tip = repo.changelog.tip() |
|
1151 | 1151 | if top == tip: |
|
1152 | 1152 | # if the top of our patch queue is also the tip, there is an |
|
1153 | 1153 | # optimization here. We update the dirstate in place and strip |
|
1154 | 1154 | # off the tip commit. Then just commit the current directory |
|
1155 | 1155 | # tree. We can also send repo.commit the list of files |
|
1156 | 1156 | # changed to speed up the diff |
|
1157 | 1157 | # |
|
1158 | 1158 | # in short mode, we only diff the files included in the |
|
1159 | 1159 | # patch already plus specified files |
|
1160 | 1160 | # |
|
1161 | 1161 | # this should really read: |
|
1162 | 1162 | # mm, dd, aa, aa2 = repo.status(tip, patchparent)[:4] |
|
1163 | 1163 | # but we do it backwards to take advantage of manifest/chlog |
|
1164 | 1164 | # caching against the next repo.status call |
|
1165 | 1165 | # |
|
1166 | 1166 | mm, aa, dd, aa2 = repo.status(patchparent, tip)[:4] |
|
1167 | 1167 | changes = repo.changelog.read(tip) |
|
1168 | 1168 | man = repo.manifest.read(changes[0]) |
|
1169 | 1169 | aaa = aa[:] |
|
1170 | 1170 | matchfn = cmdutil.match(repo, pats, opts) |
|
1171 | 1171 | if opts.get('short'): |
|
1172 | 1172 | # if amending a patch, we start with existing |
|
1173 | 1173 | # files plus specified files - unfiltered |
|
1174 | 1174 | match = cmdutil.matchfiles(repo, mm + aa + dd + matchfn.files()) |
|
1175 | 1175 | # filter with inc/exl options |
|
1176 | 1176 | matchfn = cmdutil.match(repo, opts=opts) |
|
1177 | 1177 | else: |
|
1178 | 1178 | match = cmdutil.matchall(repo) |
|
1179 | 1179 | m, a, r, d = repo.status(match=match)[:4] |
|
1180 | 1180 | |
|
1181 | 1181 | # we might end up with files that were added between |
|
1182 | 1182 | # tip and the dirstate parent, but then changed in the |
|
1183 | 1183 | # local dirstate. in this case, we want them to only |
|
1184 | 1184 | # show up in the added section |
|
1185 | 1185 | for x in m: |
|
1186 | 1186 | if x not in aa: |
|
1187 | 1187 | mm.append(x) |
|
1188 | 1188 | # we might end up with files added by the local dirstate that |
|
1189 | 1189 | # were deleted by the patch. In this case, they should only |
|
1190 | 1190 | # show up in the changed section. |
|
1191 | 1191 | for x in a: |
|
1192 | 1192 | if x in dd: |
|
1193 | 1193 | del dd[dd.index(x)] |
|
1194 | 1194 | mm.append(x) |
|
1195 | 1195 | else: |
|
1196 | 1196 | aa.append(x) |
|
1197 | 1197 | # make sure any files deleted in the local dirstate |
|
1198 | 1198 | # are not in the add or change column of the patch |
|
1199 | 1199 | forget = [] |
|
1200 | 1200 | for x in d + r: |
|
1201 | 1201 | if x in aa: |
|
1202 | 1202 | del aa[aa.index(x)] |
|
1203 | 1203 | forget.append(x) |
|
1204 | 1204 | continue |
|
1205 | 1205 | elif x in mm: |
|
1206 | 1206 | del mm[mm.index(x)] |
|
1207 | 1207 | dd.append(x) |
|
1208 | 1208 | |
|
1209 | 1209 | m = list(set(mm)) |
|
1210 | 1210 | r = list(set(dd)) |
|
1211 | 1211 | a = list(set(aa)) |
|
1212 | 1212 | c = [filter(matchfn, l) for l in (m, a, r)] |
|
1213 | 1213 | match = cmdutil.matchfiles(repo, set(c[0] + c[1] + c[2])) |
|
1214 | 1214 | chunks = patch.diff(repo, patchparent, match=match, |
|
1215 | 1215 | changes=c, opts=self.diffopts()) |
|
1216 | 1216 | for chunk in chunks: |
|
1217 | 1217 | patchf.write(chunk) |
|
1218 | 1218 | |
|
1219 | 1219 | try: |
|
1220 | 1220 | if self.diffopts().git: |
|
1221 | 1221 | copies = {} |
|
1222 | 1222 | for dst in a: |
|
1223 | 1223 | src = repo.dirstate.copied(dst) |
|
1224 | 1224 | # during qfold, the source file for copies may |
|
1225 | 1225 | # be removed. Treat this as a simple add. |
|
1226 | 1226 | if src is not None and src in repo.dirstate: |
|
1227 | 1227 | copies.setdefault(src, []).append(dst) |
|
1228 | 1228 | repo.dirstate.add(dst) |
|
1229 | 1229 | # remember the copies between patchparent and tip |
|
1230 | 1230 | for dst in aaa: |
|
1231 | 1231 | f = repo.file(dst) |
|
1232 | 1232 | src = f.renamed(man[dst]) |
|
1233 | 1233 | if src: |
|
1234 | 1234 | copies.setdefault(src[0], []).extend(copies.get(dst, [])) |
|
1235 | 1235 | if dst in a: |
|
1236 | 1236 | copies[src[0]].append(dst) |
|
1237 | 1237 | # we can't copy a file created by the patch itself |
|
1238 | 1238 | if dst in copies: |
|
1239 | 1239 | del copies[dst] |
|
1240 | 1240 | for src, dsts in copies.iteritems(): |
|
1241 | 1241 | for dst in dsts: |
|
1242 | 1242 | repo.dirstate.copy(src, dst) |
|
1243 | 1243 | else: |
|
1244 | 1244 | for dst in a: |
|
1245 | 1245 | repo.dirstate.add(dst) |
|
1246 | 1246 | # Drop useless copy information |
|
1247 | 1247 | for f in list(repo.dirstate.copies()): |
|
1248 | 1248 | repo.dirstate.copy(None, f) |
|
1249 | 1249 | for f in r: |
|
1250 | 1250 | repo.dirstate.remove(f) |
|
1251 | 1251 | # if the patch excludes a modified file, mark that |
|
1252 | 1252 | # file with mtime=0 so status can see it. |
|
1253 | 1253 | mm = [] |
|
1254 | 1254 | for i in xrange(len(m)-1, -1, -1): |
|
1255 | 1255 | if not matchfn(m[i]): |
|
1256 | 1256 | mm.append(m[i]) |
|
1257 | 1257 | del m[i] |
|
1258 | 1258 | for f in m: |
|
1259 | 1259 | repo.dirstate.normal(f) |
|
1260 | 1260 | for f in mm: |
|
1261 | 1261 | repo.dirstate.normallookup(f) |
|
1262 | 1262 | for f in forget: |
|
1263 | 1263 | repo.dirstate.forget(f) |
|
1264 | 1264 | |
|
1265 | 1265 | if not msg: |
|
1266 | 1266 | if not ph.message: |
|
1267 | 1267 | message = "[mq]: %s\n" % patchfn |
|
1268 | 1268 | else: |
|
1269 | 1269 | message = "\n".join(ph.message) |
|
1270 | 1270 | else: |
|
1271 | 1271 | message = msg |
|
1272 | 1272 | |
|
1273 | 1273 | user = ph.user or changes[1] |
|
1274 | 1274 | |
|
1275 | 1275 | # assumes strip can roll itself back if interrupted |
|
1276 | 1276 | repo.dirstate.setparents(*cparents) |
|
1277 | 1277 | self.applied.pop() |
|
1278 | 1278 | self.applied_dirty = 1 |
|
1279 | 1279 | self.strip(repo, top, update=False, |
|
1280 | 1280 | backup='strip') |
|
1281 | 1281 | except: |
|
1282 | 1282 | repo.dirstate.invalidate() |
|
1283 | 1283 | raise |
|
1284 | 1284 | |
|
1285 | 1285 | try: |
|
1286 | 1286 | # might be nice to attempt to roll back strip after this |
|
1287 | 1287 | patchf.rename() |
|
1288 | 1288 | n = repo.commit(message, user, ph.date, match=match, |
|
1289 | 1289 | force=True) |
|
1290 | 1290 | self.applied.append(statusentry(hex(n), patchfn)) |
|
1291 | 1291 | except: |
|
1292 | 1292 | ctx = repo[cparents[0]] |
|
1293 | 1293 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
1294 | 1294 | self.save_dirty() |
|
1295 | 1295 | self.ui.warn(_('refresh interrupted while patch was popped! ' |
|
1296 | 1296 | '(revert --all, qpush to recover)\n')) |
|
1297 | 1297 | raise |
|
1298 | 1298 | else: |
|
1299 | 1299 | self.printdiff(repo, patchparent, fp=patchf) |
|
1300 | 1300 | patchf.rename() |
|
1301 | 1301 | added = repo.status()[1] |
|
1302 | 1302 | for a in added: |
|
1303 | 1303 | f = repo.wjoin(a) |
|
1304 | 1304 | try: |
|
1305 | 1305 | os.unlink(f) |
|
1306 | 1306 | except OSError, e: |
|
1307 | 1307 | if e.errno != errno.ENOENT: |
|
1308 | 1308 | raise |
|
1309 | 1309 | try: os.removedirs(os.path.dirname(f)) |
|
1310 | 1310 | except: pass |
|
1311 | 1311 | # forget the file copies in the dirstate |
|
1312 | 1312 | # push should readd the files later on |
|
1313 | 1313 | repo.dirstate.forget(a) |
|
1314 | 1314 | self.pop(repo, force=True) |
|
1315 | 1315 | self.push(repo, force=True) |
|
1316 | 1316 | finally: |
|
1317 | 1317 | wlock.release() |
|
1318 | 1318 | self.removeundo(repo) |
|
1319 | 1319 | |
|
1320 | 1320 | def init(self, repo, create=False): |
|
1321 | 1321 | if not create and os.path.isdir(self.path): |
|
1322 | 1322 | raise util.Abort(_("patch queue directory already exists")) |
|
1323 | 1323 | try: |
|
1324 | 1324 | os.mkdir(self.path) |
|
1325 | 1325 | except OSError, inst: |
|
1326 | 1326 | if inst.errno != errno.EEXIST or not create: |
|
1327 | 1327 | raise |
|
1328 | 1328 | if create: |
|
1329 | 1329 | return self.qrepo(create=True) |
|
1330 | 1330 | |
|
1331 | 1331 | def unapplied(self, repo, patch=None): |
|
1332 | 1332 | if patch and patch not in self.series: |
|
1333 | 1333 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1334 | 1334 | if not patch: |
|
1335 | 1335 | start = self.series_end() |
|
1336 | 1336 | else: |
|
1337 | 1337 | start = self.series.index(patch) + 1 |
|
1338 | 1338 | unapplied = [] |
|
1339 | 1339 | for i in xrange(start, len(self.series)): |
|
1340 | 1340 | pushable, reason = self.pushable(i) |
|
1341 | 1341 | if pushable: |
|
1342 | 1342 | unapplied.append((i, self.series[i])) |
|
1343 | 1343 | self.explain_pushable(i) |
|
1344 | 1344 | return unapplied |
|
1345 | 1345 | |
|
1346 | 1346 | def qseries(self, repo, missing=None, start=0, length=None, status=None, |
|
1347 | 1347 | summary=False): |
|
1348 | 1348 | def displayname(pfx, patchname): |
|
1349 | 1349 | if summary: |
|
1350 | 1350 | ph = patchheader(self.join(patchname)) |
|
1351 | 1351 | msg = ph.message |
|
1352 | 1352 | msg = msg and ': ' + msg[0] or ': ' |
|
1353 | 1353 | else: |
|
1354 | 1354 | msg = '' |
|
1355 | 1355 | msg = "%s%s%s" % (pfx, patchname, msg) |
|
1356 | 1356 | if self.ui.interactive(): |
|
1357 | 1357 | msg = util.ellipsis(msg, util.termwidth()) |
|
1358 | 1358 | self.ui.write(msg + '\n') |
|
1359 | 1359 | |
|
1360 | 1360 | applied = set([p.name for p in self.applied]) |
|
1361 | 1361 | if length is None: |
|
1362 | 1362 | length = len(self.series) - start |
|
1363 | 1363 | if not missing: |
|
1364 | 1364 | if self.ui.verbose: |
|
1365 | 1365 | idxwidth = len(str(start+length - 1)) |
|
1366 | 1366 | for i in xrange(start, start+length): |
|
1367 | 1367 | patch = self.series[i] |
|
1368 | 1368 | if patch in applied: |
|
1369 | 1369 | stat = 'A' |
|
1370 | 1370 | elif self.pushable(i)[0]: |
|
1371 | 1371 | stat = 'U' |
|
1372 | 1372 | else: |
|
1373 | 1373 | stat = 'G' |
|
1374 | 1374 | pfx = '' |
|
1375 | 1375 | if self.ui.verbose: |
|
1376 | 1376 | pfx = '%*d %s ' % (idxwidth, i, stat) |
|
1377 | 1377 | elif status and status != stat: |
|
1378 | 1378 | continue |
|
1379 | 1379 | displayname(pfx, patch) |
|
1380 | 1380 | else: |
|
1381 | 1381 | msng_list = [] |
|
1382 | 1382 | for root, dirs, files in os.walk(self.path): |
|
1383 | 1383 | d = root[len(self.path) + 1:] |
|
1384 | 1384 | for f in files: |
|
1385 | 1385 | fl = os.path.join(d, f) |
|
1386 | 1386 | if (fl not in self.series and |
|
1387 | 1387 | fl not in (self.status_path, self.series_path, |
|
1388 | 1388 | self.guards_path) |
|
1389 | 1389 | and not fl.startswith('.')): |
|
1390 | 1390 | msng_list.append(fl) |
|
1391 | 1391 | for x in sorted(msng_list): |
|
1392 | 1392 | pfx = self.ui.verbose and ('D ') or '' |
|
1393 | 1393 | displayname(pfx, x) |
|
1394 | 1394 | |
|
1395 | 1395 | def issaveline(self, l): |
|
1396 | 1396 | if l.name == '.hg.patches.save.line': |
|
1397 | 1397 | return True |
|
1398 | 1398 | |
|
1399 | 1399 | def qrepo(self, create=False): |
|
1400 | 1400 | if create or os.path.isdir(self.join(".hg")): |
|
1401 | 1401 | return hg.repository(self.ui, path=self.path, create=create) |
|
1402 | 1402 | |
|
1403 | 1403 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
1404 | 1404 | c = repo.changelog.read(rev) |
|
1405 | 1405 | desc = c[4].strip() |
|
1406 | 1406 | lines = desc.splitlines() |
|
1407 | 1407 | i = 0 |
|
1408 | 1408 | datastart = None |
|
1409 | 1409 | series = [] |
|
1410 | 1410 | applied = [] |
|
1411 | 1411 | qpp = None |
|
1412 | 1412 | for i, line in enumerate(lines): |
|
1413 | 1413 | if line == 'Patch Data:': |
|
1414 | 1414 | datastart = i + 1 |
|
1415 | 1415 | elif line.startswith('Dirstate:'): |
|
1416 | 1416 | l = line.rstrip() |
|
1417 | 1417 | l = l[10:].split(' ') |
|
1418 | 1418 | qpp = [ bin(x) for x in l ] |
|
1419 | 1419 | elif datastart != None: |
|
1420 | 1420 | l = line.rstrip() |
|
1421 | 1421 | se = statusentry(l) |
|
1422 | 1422 | file_ = se.name |
|
1423 | 1423 | if se.rev: |
|
1424 | 1424 | applied.append(se) |
|
1425 | 1425 | else: |
|
1426 | 1426 | series.append(file_) |
|
1427 | 1427 | if datastart is None: |
|
1428 | 1428 | self.ui.warn(_("No saved patch data found\n")) |
|
1429 | 1429 | return 1 |
|
1430 | 1430 | self.ui.warn(_("restoring status: %s\n") % lines[0]) |
|
1431 | 1431 | self.full_series = series |
|
1432 | 1432 | self.applied = applied |
|
1433 | 1433 | self.parse_series() |
|
1434 | 1434 | self.series_dirty = 1 |
|
1435 | 1435 | self.applied_dirty = 1 |
|
1436 | 1436 | heads = repo.changelog.heads() |
|
1437 | 1437 | if delete: |
|
1438 | 1438 | if rev not in heads: |
|
1439 | 1439 | self.ui.warn(_("save entry has children, leaving it alone\n")) |
|
1440 | 1440 | else: |
|
1441 | 1441 | self.ui.warn(_("removing save entry %s\n") % short(rev)) |
|
1442 | 1442 | pp = repo.dirstate.parents() |
|
1443 | 1443 | if rev in pp: |
|
1444 | 1444 | update = True |
|
1445 | 1445 | else: |
|
1446 | 1446 | update = False |
|
1447 | 1447 | self.strip(repo, rev, update=update, backup='strip') |
|
1448 | 1448 | if qpp: |
|
1449 | 1449 | self.ui.warn(_("saved queue repository parents: %s %s\n") % |
|
1450 | 1450 | (short(qpp[0]), short(qpp[1]))) |
|
1451 | 1451 | if qupdate: |
|
1452 | 1452 | self.ui.status(_("queue directory updating\n")) |
|
1453 | 1453 | r = self.qrepo() |
|
1454 | 1454 | if not r: |
|
1455 | 1455 | self.ui.warn(_("Unable to load queue repository\n")) |
|
1456 | 1456 | return 1 |
|
1457 | 1457 | hg.clean(r, qpp[0]) |
|
1458 | 1458 | |
|
1459 | 1459 | def save(self, repo, msg=None): |
|
1460 | 1460 | if len(self.applied) == 0: |
|
1461 | 1461 | self.ui.warn(_("save: no patches applied, exiting\n")) |
|
1462 | 1462 | return 1 |
|
1463 | 1463 | if self.issaveline(self.applied[-1]): |
|
1464 | 1464 | self.ui.warn(_("status is already saved\n")) |
|
1465 | 1465 | return 1 |
|
1466 | 1466 | |
|
1467 | 1467 | ar = [ ':' + x for x in self.full_series ] |
|
1468 | 1468 | if not msg: |
|
1469 | 1469 | msg = _("hg patches saved state") |
|
1470 | 1470 | else: |
|
1471 | 1471 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
1472 | 1472 | r = self.qrepo() |
|
1473 | 1473 | if r: |
|
1474 | 1474 | pp = r.dirstate.parents() |
|
1475 | 1475 | msg += "\nDirstate: %s %s" % (hex(pp[0]), hex(pp[1])) |
|
1476 | 1476 | msg += "\n\nPatch Data:\n" |
|
1477 | 1477 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and |
|
1478 | 1478 | "\n".join(ar) + '\n' or "") |
|
1479 | 1479 | n = repo.commit(text, force=True) |
|
1480 | 1480 | if not n: |
|
1481 | 1481 | self.ui.warn(_("repo commit failed\n")) |
|
1482 | 1482 | return 1 |
|
1483 | 1483 | self.applied.append(statusentry(hex(n),'.hg.patches.save.line')) |
|
1484 | 1484 | self.applied_dirty = 1 |
|
1485 | 1485 | self.removeundo(repo) |
|
1486 | 1486 | |
|
1487 | 1487 | def full_series_end(self): |
|
1488 | 1488 | if len(self.applied) > 0: |
|
1489 | 1489 | p = self.applied[-1].name |
|
1490 | 1490 | end = self.find_series(p) |
|
1491 | 1491 | if end is None: |
|
1492 | 1492 | return len(self.full_series) |
|
1493 | 1493 | return end + 1 |
|
1494 | 1494 | return 0 |
|
1495 | 1495 | |
|
1496 | 1496 | def series_end(self, all_patches=False): |
|
1497 | 1497 | """If all_patches is False, return the index of the next pushable patch |
|
1498 | 1498 | in the series, or the series length. If all_patches is True, return the |
|
1499 | 1499 | index of the first patch past the last applied one. |
|
1500 | 1500 | """ |
|
1501 | 1501 | end = 0 |
|
1502 | 1502 | def next(start): |
|
1503 | 1503 | if all_patches: |
|
1504 | 1504 | return start |
|
1505 | 1505 | i = start |
|
1506 | 1506 | while i < len(self.series): |
|
1507 | 1507 | p, reason = self.pushable(i) |
|
1508 | 1508 | if p: |
|
1509 | 1509 | break |
|
1510 | 1510 | self.explain_pushable(i) |
|
1511 | 1511 | i += 1 |
|
1512 | 1512 | return i |
|
1513 | 1513 | if len(self.applied) > 0: |
|
1514 | 1514 | p = self.applied[-1].name |
|
1515 | 1515 | try: |
|
1516 | 1516 | end = self.series.index(p) |
|
1517 | 1517 | except ValueError: |
|
1518 | 1518 | return 0 |
|
1519 | 1519 | return next(end + 1) |
|
1520 | 1520 | return next(end) |
|
1521 | 1521 | |
|
1522 | 1522 | def appliedname(self, index): |
|
1523 | 1523 | pname = self.applied[index].name |
|
1524 | 1524 | if not self.ui.verbose: |
|
1525 | 1525 | p = pname |
|
1526 | 1526 | else: |
|
1527 | 1527 | p = str(self.series.index(pname)) + " " + pname |
|
1528 | 1528 | return p |
|
1529 | 1529 | |
|
1530 | 1530 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, |
|
1531 | 1531 | force=None, git=False): |
|
1532 | 1532 | def checkseries(patchname): |
|
1533 | 1533 | if patchname in self.series: |
|
1534 | 1534 | raise util.Abort(_('patch %s is already in the series file') |
|
1535 | 1535 | % patchname) |
|
1536 | 1536 | def checkfile(patchname): |
|
1537 | 1537 | if not force and os.path.exists(self.join(patchname)): |
|
1538 | 1538 | raise util.Abort(_('patch "%s" already exists') |
|
1539 | 1539 | % patchname) |
|
1540 | 1540 | |
|
1541 | 1541 | if rev: |
|
1542 | 1542 | if files: |
|
1543 | 1543 | raise util.Abort(_('option "-r" not valid when importing ' |
|
1544 | 1544 | 'files')) |
|
1545 | 1545 | rev = cmdutil.revrange(repo, rev) |
|
1546 | 1546 | rev.sort(reverse=True) |
|
1547 | 1547 | if (len(files) > 1 or len(rev) > 1) and patchname: |
|
1548 | 1548 | raise util.Abort(_('option "-n" not valid when importing multiple ' |
|
1549 | 1549 | 'patches')) |
|
1550 | 1550 | i = 0 |
|
1551 | 1551 | added = [] |
|
1552 | 1552 | if rev: |
|
1553 | 1553 | # If mq patches are applied, we can only import revisions |
|
1554 | 1554 | # that form a linear path to qbase. |
|
1555 | 1555 | # Otherwise, they should form a linear path to a head. |
|
1556 | 1556 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) |
|
1557 | 1557 | if len(heads) > 1: |
|
1558 | 1558 | raise util.Abort(_('revision %d is the root of more than one ' |
|
1559 | 1559 | 'branch') % rev[-1]) |
|
1560 | 1560 | if self.applied: |
|
1561 | 1561 | base = hex(repo.changelog.node(rev[0])) |
|
1562 | 1562 | if base in [n.rev for n in self.applied]: |
|
1563 | 1563 | raise util.Abort(_('revision %d is already managed') |
|
1564 | 1564 | % rev[0]) |
|
1565 | 1565 | if heads != [bin(self.applied[-1].rev)]: |
|
1566 | 1566 | raise util.Abort(_('revision %d is not the parent of ' |
|
1567 | 1567 | 'the queue') % rev[0]) |
|
1568 | 1568 | base = repo.changelog.rev(bin(self.applied[0].rev)) |
|
1569 | 1569 | lastparent = repo.changelog.parentrevs(base)[0] |
|
1570 | 1570 | else: |
|
1571 | 1571 | if heads != [repo.changelog.node(rev[0])]: |
|
1572 | 1572 | raise util.Abort(_('revision %d has unmanaged children') |
|
1573 | 1573 | % rev[0]) |
|
1574 | 1574 | lastparent = None |
|
1575 | 1575 | |
|
1576 | 1576 | if git: |
|
1577 | 1577 | self.diffopts().git = True |
|
1578 | 1578 | |
|
1579 | 1579 | for r in rev: |
|
1580 | 1580 | p1, p2 = repo.changelog.parentrevs(r) |
|
1581 | 1581 | n = repo.changelog.node(r) |
|
1582 | 1582 | if p2 != nullrev: |
|
1583 | 1583 | raise util.Abort(_('cannot import merge revision %d') % r) |
|
1584 | 1584 | if lastparent and lastparent != r: |
|
1585 | 1585 | raise util.Abort(_('revision %d is not the parent of %d') |
|
1586 | 1586 | % (r, lastparent)) |
|
1587 | 1587 | lastparent = p1 |
|
1588 | 1588 | |
|
1589 | 1589 | if not patchname: |
|
1590 | 1590 | patchname = normname('%d.diff' % r) |
|
1591 | 1591 | self.check_reserved_name(patchname) |
|
1592 | 1592 | checkseries(patchname) |
|
1593 | 1593 | checkfile(patchname) |
|
1594 | 1594 | self.full_series.insert(0, patchname) |
|
1595 | 1595 | |
|
1596 | 1596 | patchf = self.opener(patchname, "w") |
|
1597 | 1597 | patch.export(repo, [n], fp=patchf, opts=self.diffopts()) |
|
1598 | 1598 | patchf.close() |
|
1599 | 1599 | |
|
1600 | 1600 | se = statusentry(hex(n), patchname) |
|
1601 | 1601 | self.applied.insert(0, se) |
|
1602 | 1602 | |
|
1603 | 1603 | added.append(patchname) |
|
1604 | 1604 | patchname = None |
|
1605 | 1605 | self.parse_series() |
|
1606 | 1606 | self.applied_dirty = 1 |
|
1607 | 1607 | |
|
1608 | 1608 | for filename in files: |
|
1609 | 1609 | if existing: |
|
1610 | 1610 | if filename == '-': |
|
1611 | 1611 | raise util.Abort(_('-e is incompatible with import from -')) |
|
1612 | 1612 | if not patchname: |
|
1613 | 1613 | patchname = normname(filename) |
|
1614 | 1614 | self.check_reserved_name(patchname) |
|
1615 | 1615 | if not os.path.isfile(self.join(patchname)): |
|
1616 | 1616 | raise util.Abort(_("patch %s does not exist") % patchname) |
|
1617 | 1617 | else: |
|
1618 | 1618 | try: |
|
1619 | 1619 | if filename == '-': |
|
1620 | 1620 | if not patchname: |
|
1621 | 1621 | raise util.Abort(_('need --name to import a patch from -')) |
|
1622 | 1622 | text = sys.stdin.read() |
|
1623 | 1623 | else: |
|
1624 | 1624 | text = url.open(self.ui, filename).read() |
|
1625 | 1625 | except (OSError, IOError): |
|
1626 | 1626 | raise util.Abort(_("unable to read %s") % filename) |
|
1627 | 1627 | if not patchname: |
|
1628 | 1628 | patchname = normname(os.path.basename(filename)) |
|
1629 | 1629 | self.check_reserved_name(patchname) |
|
1630 | 1630 | checkfile(patchname) |
|
1631 | 1631 | patchf = self.opener(patchname, "w") |
|
1632 | 1632 | patchf.write(text) |
|
1633 | 1633 | if not force: |
|
1634 | 1634 | checkseries(patchname) |
|
1635 | 1635 | if patchname not in self.series: |
|
1636 | 1636 | index = self.full_series_end() + i |
|
1637 | 1637 | self.full_series[index:index] = [patchname] |
|
1638 | 1638 | self.parse_series() |
|
1639 | 1639 | self.ui.warn(_("adding %s to series file\n") % patchname) |
|
1640 | 1640 | i += 1 |
|
1641 | 1641 | added.append(patchname) |
|
1642 | 1642 | patchname = None |
|
1643 | 1643 | self.series_dirty = 1 |
|
1644 | 1644 | qrepo = self.qrepo() |
|
1645 | 1645 | if qrepo: |
|
1646 | 1646 | qrepo.add(added) |
|
1647 | 1647 | |
|
1648 | 1648 | def delete(ui, repo, *patches, **opts): |
|
1649 | 1649 | """remove patches from queue |
|
1650 | 1650 | |
|
1651 | 1651 | The patches must not be applied, and at least one patch is required. With |
|
1652 | 1652 | -k/--keep, the patch files are preserved in the patch directory. |
|
1653 | 1653 | |
|
1654 | 1654 | To stop managing a patch and move it into permanent history, |
|
1655 | 1655 | use the qfinish command.""" |
|
1656 | 1656 | q = repo.mq |
|
1657 | 1657 | q.delete(repo, patches, opts) |
|
1658 | 1658 | q.save_dirty() |
|
1659 | 1659 | return 0 |
|
1660 | 1660 | |
|
1661 | 1661 | def applied(ui, repo, patch=None, **opts): |
|
1662 | 1662 | """print the patches already applied""" |
|
1663 | 1663 | q = repo.mq |
|
1664 | 1664 | if patch: |
|
1665 | 1665 | if patch not in q.series: |
|
1666 | 1666 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1667 | 1667 | end = q.series.index(patch) + 1 |
|
1668 | 1668 | else: |
|
1669 | 1669 | end = q.series_end(True) |
|
1670 | 1670 | return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) |
|
1671 | 1671 | |
|
1672 | 1672 | def unapplied(ui, repo, patch=None, **opts): |
|
1673 | 1673 | """print the patches not yet applied""" |
|
1674 | 1674 | q = repo.mq |
|
1675 | 1675 | if patch: |
|
1676 | 1676 | if patch not in q.series: |
|
1677 | 1677 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1678 | 1678 | start = q.series.index(patch) + 1 |
|
1679 | 1679 | else: |
|
1680 | 1680 | start = q.series_end(True) |
|
1681 | 1681 | q.qseries(repo, start=start, status='U', summary=opts.get('summary')) |
|
1682 | 1682 | |
|
1683 | 1683 | def qimport(ui, repo, *filename, **opts): |
|
1684 | 1684 | """import a patch |
|
1685 | 1685 | |
|
1686 | 1686 | The patch is inserted into the series after the last applied patch. If no |
|
1687 | 1687 | patches have been applied, qimport prepends the patch to the series. |
|
1688 | 1688 | |
|
1689 | 1689 | The patch will have the same name as its source file unless you give it a |
|
1690 | 1690 | new one with -n/--name. |
|
1691 | 1691 | |
|
1692 | 1692 | You can register an existing patch inside the patch directory with the |
|
1693 | 1693 | -e/--existing flag. |
|
1694 | 1694 | |
|
1695 | 1695 | With -f/--force, an existing patch of the same name will be overwritten. |
|
1696 | 1696 | |
|
1697 | 1697 | An existing changeset may be placed under mq control with -r/--rev (e.g. |
|
1698 | 1698 | qimport --rev tip -n patch will place tip under mq control). With |
|
1699 | 1699 | -g/--git, patches imported with --rev will use the git diff format. See |
|
1700 | 1700 | the diffs help topic for information on why this is important for |
|
1701 | 1701 | preserving rename/copy information and permission changes. |
|
1702 | 1702 | |
|
1703 | 1703 | To import a patch from standard input, pass - as the patch file. When |
|
1704 | 1704 | importing from standard input, a patch name must be specified using the |
|
1705 | 1705 | --name flag. |
|
1706 | 1706 | """ |
|
1707 | 1707 | q = repo.mq |
|
1708 | 1708 | q.qimport(repo, filename, patchname=opts['name'], |
|
1709 | 1709 | existing=opts['existing'], force=opts['force'], rev=opts['rev'], |
|
1710 | 1710 | git=opts['git']) |
|
1711 | 1711 | q.save_dirty() |
|
1712 | 1712 | |
|
1713 | 1713 | if opts.get('push') and not opts.get('rev'): |
|
1714 | 1714 | return q.push(repo, None) |
|
1715 | 1715 | return 0 |
|
1716 | 1716 | |
|
1717 | 1717 | def init(ui, repo, **opts): |
|
1718 | 1718 | """init a new queue repository |
|
1719 | 1719 | |
|
1720 | 1720 | The queue repository is unversioned by default. If -c/--create-repo is |
|
1721 | 1721 | specified, qinit will create a separate nested repository for patches |
|
1722 | 1722 | (qinit -c may also be run later to convert an unversioned patch repository |
|
1723 | 1723 | into a versioned one). You can use qcommit to commit changes to this queue |
|
1724 | 1724 | repository. |
|
1725 | 1725 | """ |
|
1726 | 1726 | q = repo.mq |
|
1727 | 1727 | r = q.init(repo, create=opts['create_repo']) |
|
1728 | 1728 | q.save_dirty() |
|
1729 | 1729 | if r: |
|
1730 | 1730 | if not os.path.exists(r.wjoin('.hgignore')): |
|
1731 | 1731 | fp = r.wopener('.hgignore', 'w') |
|
1732 | 1732 | fp.write('^\\.hg\n') |
|
1733 | 1733 | fp.write('^\\.mq\n') |
|
1734 | 1734 | fp.write('syntax: glob\n') |
|
1735 | 1735 | fp.write('status\n') |
|
1736 | 1736 | fp.write('guards\n') |
|
1737 | 1737 | fp.close() |
|
1738 | 1738 | if not os.path.exists(r.wjoin('series')): |
|
1739 | 1739 | r.wopener('series', 'w').close() |
|
1740 | 1740 | r.add(['.hgignore', 'series']) |
|
1741 | 1741 | commands.add(ui, r) |
|
1742 | 1742 | return 0 |
|
1743 | 1743 | |
|
1744 | 1744 | def clone(ui, source, dest=None, **opts): |
|
1745 | 1745 | '''clone main and patch repository at same time |
|
1746 | 1746 | |
|
1747 | 1747 | If source is local, destination will have no patches applied. If source is |
|
1748 | 1748 | remote, this command can not check if patches are applied in source, so |
|
1749 | 1749 | cannot guarantee that patches are not applied in destination. If you clone |
|
1750 | 1750 | remote repository, be sure before that it has no patches applied. |
|
1751 | 1751 | |
|
1752 | 1752 | Source patch repository is looked for in <src>/.hg/patches by default. Use |
|
1753 | 1753 | -p <url> to change. |
|
1754 | 1754 | |
|
1755 | 1755 | The patch directory must be a nested Mercurial repository, as would be |
|
1756 | 1756 | created by qinit -c. |
|
1757 | 1757 | ''' |
|
1758 | 1758 | def patchdir(repo): |
|
1759 | 1759 | url = repo.url() |
|
1760 | 1760 | if url.endswith('/'): |
|
1761 | 1761 | url = url[:-1] |
|
1762 | 1762 | return url + '/.hg/patches' |
|
1763 | 1763 | if dest is None: |
|
1764 | 1764 | dest = hg.defaultdest(source) |
|
1765 | 1765 | sr = hg.repository(cmdutil.remoteui(ui, opts), ui.expandpath(source)) |
|
1766 | 1766 | if opts['patches']: |
|
1767 | 1767 | patchespath = ui.expandpath(opts['patches']) |
|
1768 | 1768 | else: |
|
1769 | 1769 | patchespath = patchdir(sr) |
|
1770 | 1770 | try: |
|
1771 | 1771 | hg.repository(ui, patchespath) |
|
1772 | 1772 | except error.RepoError: |
|
1773 | 1773 | raise util.Abort(_('versioned patch repository not found' |
|
1774 | 1774 | ' (see qinit -c)')) |
|
1775 | 1775 | qbase, destrev = None, None |
|
1776 | 1776 | if sr.local(): |
|
1777 | 1777 | if sr.mq.applied: |
|
1778 | 1778 | qbase = bin(sr.mq.applied[0].rev) |
|
1779 | 1779 | if not hg.islocal(dest): |
|
1780 | 1780 | heads = set(sr.heads()) |
|
1781 | 1781 | destrev = list(heads.difference(sr.heads(qbase))) |
|
1782 | 1782 | destrev.append(sr.changelog.parents(qbase)[0]) |
|
1783 | 1783 | elif sr.capable('lookup'): |
|
1784 | 1784 | try: |
|
1785 | 1785 | qbase = sr.lookup('qbase') |
|
1786 | 1786 | except error.RepoError: |
|
1787 | 1787 | pass |
|
1788 | 1788 | ui.note(_('cloning main repository\n')) |
|
1789 | 1789 | sr, dr = hg.clone(ui, sr.url(), dest, |
|
1790 | 1790 | pull=opts['pull'], |
|
1791 | 1791 | rev=destrev, |
|
1792 | 1792 | update=False, |
|
1793 | 1793 | stream=opts['uncompressed']) |
|
1794 | 1794 | ui.note(_('cloning patch repository\n')) |
|
1795 | 1795 | hg.clone(ui, opts['patches'] or patchdir(sr), patchdir(dr), |
|
1796 | 1796 | pull=opts['pull'], update=not opts['noupdate'], |
|
1797 | 1797 | stream=opts['uncompressed']) |
|
1798 | 1798 | if dr.local(): |
|
1799 | 1799 | if qbase: |
|
1800 | 1800 | ui.note(_('stripping applied patches from destination ' |
|
1801 | 1801 | 'repository\n')) |
|
1802 | 1802 | dr.mq.strip(dr, qbase, update=False, backup=None) |
|
1803 | 1803 | if not opts['noupdate']: |
|
1804 | 1804 | ui.note(_('updating destination repository\n')) |
|
1805 | 1805 | hg.update(dr, dr.changelog.tip()) |
|
1806 | 1806 | |
|
1807 | 1807 | def commit(ui, repo, *pats, **opts): |
|
1808 | 1808 | """commit changes in the queue repository""" |
|
1809 | 1809 | q = repo.mq |
|
1810 | 1810 | r = q.qrepo() |
|
1811 | 1811 | if not r: raise util.Abort('no queue repository') |
|
1812 | 1812 | commands.commit(r.ui, r, *pats, **opts) |
|
1813 | 1813 | |
|
1814 | 1814 | def series(ui, repo, **opts): |
|
1815 | 1815 | """print the entire series file""" |
|
1816 | 1816 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) |
|
1817 | 1817 | return 0 |
|
1818 | 1818 | |
|
1819 | 1819 | def top(ui, repo, **opts): |
|
1820 | 1820 | """print the name of the current patch""" |
|
1821 | 1821 | q = repo.mq |
|
1822 | 1822 | t = q.applied and q.series_end(True) or 0 |
|
1823 | 1823 | if t: |
|
1824 | 1824 | return q.qseries(repo, start=t-1, length=1, status='A', |
|
1825 | 1825 | summary=opts.get('summary')) |
|
1826 | 1826 | else: |
|
1827 | 1827 | ui.write(_("no patches applied\n")) |
|
1828 | 1828 | return 1 |
|
1829 | 1829 | |
|
1830 | 1830 | def next(ui, repo, **opts): |
|
1831 | 1831 | """print the name of the next patch""" |
|
1832 | 1832 | q = repo.mq |
|
1833 | 1833 | end = q.series_end() |
|
1834 | 1834 | if end == len(q.series): |
|
1835 | 1835 | ui.write(_("all patches applied\n")) |
|
1836 | 1836 | return 1 |
|
1837 | 1837 | return q.qseries(repo, start=end, length=1, summary=opts.get('summary')) |
|
1838 | 1838 | |
|
1839 | 1839 | def prev(ui, repo, **opts): |
|
1840 | 1840 | """print the name of the previous patch""" |
|
1841 | 1841 | q = repo.mq |
|
1842 | 1842 | l = len(q.applied) |
|
1843 | 1843 | if l == 1: |
|
1844 | 1844 | ui.write(_("only one patch applied\n")) |
|
1845 | 1845 | return 1 |
|
1846 | 1846 | if not l: |
|
1847 | 1847 | ui.write(_("no patches applied\n")) |
|
1848 | 1848 | return 1 |
|
1849 | 1849 | return q.qseries(repo, start=l-2, length=1, status='A', |
|
1850 | 1850 | summary=opts.get('summary')) |
|
1851 | 1851 | |
|
1852 | 1852 | def setupheaderopts(ui, opts): |
|
1853 | def do(opt,val): | |
|
1853 | def do(opt, val): | |
|
1854 | 1854 | if not opts[opt] and opts['current' + opt]: |
|
1855 | 1855 | opts[opt] = val |
|
1856 | 1856 | do('user', ui.username()) |
|
1857 | 1857 | do('date', "%d %d" % util.makedate()) |
|
1858 | 1858 | |
|
1859 | 1859 | def new(ui, repo, patch, *args, **opts): |
|
1860 | 1860 | """create a new patch |
|
1861 | 1861 | |
|
1862 | 1862 | qnew creates a new patch on top of the currently-applied patch (if any). |
|
1863 | 1863 | It will refuse to run if there are any outstanding changes unless |
|
1864 | 1864 | -f/--force is specified, in which case the patch will be initialized with |
|
1865 | 1865 | them. You may also use -I/--include, -X/--exclude, and/or a list of files |
|
1866 | 1866 | after the patch name to add only changes to matching files to the new |
|
1867 | 1867 | patch, leaving the rest as uncommitted modifications. |
|
1868 | 1868 | |
|
1869 | 1869 | -u/--user and -d/--date can be used to set the (given) user and date, |
|
1870 | 1870 | respectively. -U/--currentuser and -D/--currentdate set user to current |
|
1871 | 1871 | user and date to current date. |
|
1872 | 1872 | |
|
1873 | 1873 | -e/--edit, -m/--message or -l/--logfile set the patch header as well as |
|
1874 | 1874 | the commit message. If none is specified, the header is empty and the |
|
1875 | 1875 | commit message is '[mq]: PATCH'. |
|
1876 | 1876 | |
|
1877 | 1877 | Use the -g/--git option to keep the patch in the git extended diff format. |
|
1878 | 1878 | Read the diffs help topic for more information on why this is important |
|
1879 | 1879 | for preserving permission changes and copy/rename information. |
|
1880 | 1880 | """ |
|
1881 | 1881 | msg = cmdutil.logmessage(opts) |
|
1882 | 1882 | def getmsg(): return ui.edit(msg, ui.username()) |
|
1883 | 1883 | q = repo.mq |
|
1884 | 1884 | opts['msg'] = msg |
|
1885 | 1885 | if opts.get('edit'): |
|
1886 | 1886 | opts['msg'] = getmsg |
|
1887 | 1887 | else: |
|
1888 | 1888 | opts['msg'] = msg |
|
1889 | 1889 | setupheaderopts(ui, opts) |
|
1890 | 1890 | q.new(repo, patch, *args, **opts) |
|
1891 | 1891 | q.save_dirty() |
|
1892 | 1892 | return 0 |
|
1893 | 1893 | |
|
1894 | 1894 | def refresh(ui, repo, *pats, **opts): |
|
1895 | 1895 | """update the current patch |
|
1896 | 1896 | |
|
1897 | 1897 | If any file patterns are provided, the refreshed patch will contain only |
|
1898 | 1898 | the modifications that match those patterns; the remaining modifications |
|
1899 | 1899 | will remain in the working directory. |
|
1900 | 1900 | |
|
1901 | 1901 | If -s/--short is specified, files currently included in the patch will be |
|
1902 | 1902 | refreshed just like matched files and remain in the patch. |
|
1903 | 1903 | |
|
1904 | 1904 | hg add/remove/copy/rename work as usual, though you might want to use |
|
1905 | 1905 | git-style patches (-g/--git or [diff] git=1) to track copies and renames. |
|
1906 | 1906 | See the diffs help topic for more information on the git diff format. |
|
1907 | 1907 | """ |
|
1908 | 1908 | q = repo.mq |
|
1909 | 1909 | message = cmdutil.logmessage(opts) |
|
1910 | 1910 | if opts['edit']: |
|
1911 | 1911 | if not q.applied: |
|
1912 | 1912 | ui.write(_("no patches applied\n")) |
|
1913 | 1913 | return 1 |
|
1914 | 1914 | if message: |
|
1915 | 1915 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1916 | 1916 | patch = q.applied[-1].name |
|
1917 | 1917 | ph = patchheader(q.join(patch)) |
|
1918 | 1918 | message = ui.edit('\n'.join(ph.message), ph.user or ui.username()) |
|
1919 | 1919 | setupheaderopts(ui, opts) |
|
1920 | 1920 | ret = q.refresh(repo, pats, msg=message, **opts) |
|
1921 | 1921 | q.save_dirty() |
|
1922 | 1922 | return ret |
|
1923 | 1923 | |
|
1924 | 1924 | def diff(ui, repo, *pats, **opts): |
|
1925 | 1925 | """diff of the current patch and subsequent modifications |
|
1926 | 1926 | |
|
1927 | 1927 | Shows a diff which includes the current patch as well as any changes which |
|
1928 | 1928 | have been made in the working directory since the last refresh (thus |
|
1929 | 1929 | showing what the current patch would become after a qrefresh). |
|
1930 | 1930 | |
|
1931 | 1931 | Use 'hg diff' if you only want to see the changes made since the last |
|
1932 | 1932 | qrefresh, or 'hg export qtip' if you want to see changes made by the |
|
1933 | 1933 | current patch without including changes made since the qrefresh. |
|
1934 | 1934 | """ |
|
1935 | 1935 | repo.mq.diff(repo, pats, opts) |
|
1936 | 1936 | return 0 |
|
1937 | 1937 | |
|
1938 | 1938 | def fold(ui, repo, *files, **opts): |
|
1939 | 1939 | """fold the named patches into the current patch |
|
1940 | 1940 | |
|
1941 | 1941 | Patches must not yet be applied. Each patch will be successively applied |
|
1942 | 1942 | to the current patch in the order given. If all the patches apply |
|
1943 | 1943 | successfully, the current patch will be refreshed with the new cumulative |
|
1944 | 1944 | patch, and the folded patches will be deleted. With -k/--keep, the folded |
|
1945 | 1945 | patch files will not be removed afterwards. |
|
1946 | 1946 | |
|
1947 | 1947 | The header for each folded patch will be concatenated with the current |
|
1948 | 1948 | patch header, separated by a line of '* * *'. |
|
1949 | 1949 | """ |
|
1950 | 1950 | |
|
1951 | 1951 | q = repo.mq |
|
1952 | 1952 | |
|
1953 | 1953 | if not files: |
|
1954 | 1954 | raise util.Abort(_('qfold requires at least one patch name')) |
|
1955 | 1955 | if not q.check_toppatch(repo): |
|
1956 | 1956 | raise util.Abort(_('No patches applied')) |
|
1957 | 1957 | q.check_localchanges(repo) |
|
1958 | 1958 | |
|
1959 | 1959 | message = cmdutil.logmessage(opts) |
|
1960 | 1960 | if opts['edit']: |
|
1961 | 1961 | if message: |
|
1962 | 1962 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1963 | 1963 | |
|
1964 | 1964 | parent = q.lookup('qtip') |
|
1965 | 1965 | patches = [] |
|
1966 | 1966 | messages = [] |
|
1967 | 1967 | for f in files: |
|
1968 | 1968 | p = q.lookup(f) |
|
1969 | 1969 | if p in patches or p == parent: |
|
1970 | 1970 | ui.warn(_('Skipping already folded patch %s') % p) |
|
1971 | 1971 | if q.isapplied(p): |
|
1972 | 1972 | raise util.Abort(_('qfold cannot fold already applied patch %s') % p) |
|
1973 | 1973 | patches.append(p) |
|
1974 | 1974 | |
|
1975 | 1975 | for p in patches: |
|
1976 | 1976 | if not message: |
|
1977 | 1977 | ph = patchheader(q.join(p)) |
|
1978 | 1978 | if ph.message: |
|
1979 | 1979 | messages.append(ph.message) |
|
1980 | 1980 | pf = q.join(p) |
|
1981 | 1981 | (patchsuccess, files, fuzz) = q.patch(repo, pf) |
|
1982 | 1982 | if not patchsuccess: |
|
1983 | 1983 | raise util.Abort(_('Error folding patch %s') % p) |
|
1984 | 1984 | patch.updatedir(ui, repo, files) |
|
1985 | 1985 | |
|
1986 | 1986 | if not message: |
|
1987 | 1987 | ph = patchheader(q.join(parent)) |
|
1988 | 1988 | message, user = ph.message, ph.user |
|
1989 | 1989 | for msg in messages: |
|
1990 | 1990 | message.append('* * *') |
|
1991 | 1991 | message.extend(msg) |
|
1992 | 1992 | message = '\n'.join(message) |
|
1993 | 1993 | |
|
1994 | 1994 | if opts['edit']: |
|
1995 | 1995 | message = ui.edit(message, user or ui.username()) |
|
1996 | 1996 | |
|
1997 | 1997 | q.refresh(repo, msg=message) |
|
1998 | 1998 | q.delete(repo, patches, opts) |
|
1999 | 1999 | q.save_dirty() |
|
2000 | 2000 | |
|
2001 | 2001 | def goto(ui, repo, patch, **opts): |
|
2002 | 2002 | '''push or pop patches until named patch is at top of stack''' |
|
2003 | 2003 | q = repo.mq |
|
2004 | 2004 | patch = q.lookup(patch) |
|
2005 | 2005 | if q.isapplied(patch): |
|
2006 | 2006 | ret = q.pop(repo, patch, force=opts['force']) |
|
2007 | 2007 | else: |
|
2008 | 2008 | ret = q.push(repo, patch, force=opts['force']) |
|
2009 | 2009 | q.save_dirty() |
|
2010 | 2010 | return ret |
|
2011 | 2011 | |
|
2012 | 2012 | def guard(ui, repo, *args, **opts): |
|
2013 | 2013 | '''set or print guards for a patch |
|
2014 | 2014 | |
|
2015 | 2015 | Guards control whether a patch can be pushed. A patch with no guards is |
|
2016 | 2016 | always pushed. A patch with a positive guard ("+foo") is pushed only if |
|
2017 | 2017 | the qselect command has activated it. A patch with a negative guard |
|
2018 | 2018 | ("-foo") is never pushed if the qselect command has activated it. |
|
2019 | 2019 | |
|
2020 | 2020 | With no arguments, print the currently active guards. With arguments, set |
|
2021 | 2021 | guards for the named patch. |
|
2022 | 2022 | NOTE: Specifying negative guards now requires '--'. |
|
2023 | 2023 | |
|
2024 | 2024 | To set guards on another patch: |
|
2025 | 2025 | hg qguard -- other.patch +2.6.17 -stable |
|
2026 | 2026 | ''' |
|
2027 | 2027 | def status(idx): |
|
2028 | 2028 | guards = q.series_guards[idx] or ['unguarded'] |
|
2029 | 2029 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) |
|
2030 | 2030 | q = repo.mq |
|
2031 | 2031 | patch = None |
|
2032 | 2032 | args = list(args) |
|
2033 | 2033 | if opts['list']: |
|
2034 | 2034 | if args or opts['none']: |
|
2035 | 2035 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) |
|
2036 | 2036 | for i in xrange(len(q.series)): |
|
2037 | 2037 | status(i) |
|
2038 | 2038 | return |
|
2039 | 2039 | if not args or args[0][0:1] in '-+': |
|
2040 | 2040 | if not q.applied: |
|
2041 | 2041 | raise util.Abort(_('no patches applied')) |
|
2042 | 2042 | patch = q.applied[-1].name |
|
2043 | 2043 | if patch is None and args[0][0:1] not in '-+': |
|
2044 | 2044 | patch = args.pop(0) |
|
2045 | 2045 | if patch is None: |
|
2046 | 2046 | raise util.Abort(_('no patch to work with')) |
|
2047 | 2047 | if args or opts['none']: |
|
2048 | 2048 | idx = q.find_series(patch) |
|
2049 | 2049 | if idx is None: |
|
2050 | 2050 | raise util.Abort(_('no patch named %s') % patch) |
|
2051 | 2051 | q.set_guards(idx, args) |
|
2052 | 2052 | q.save_dirty() |
|
2053 | 2053 | else: |
|
2054 | 2054 | status(q.series.index(q.lookup(patch))) |
|
2055 | 2055 | |
|
2056 | 2056 | def header(ui, repo, patch=None): |
|
2057 | 2057 | """print the header of the topmost or specified patch""" |
|
2058 | 2058 | q = repo.mq |
|
2059 | 2059 | |
|
2060 | 2060 | if patch: |
|
2061 | 2061 | patch = q.lookup(patch) |
|
2062 | 2062 | else: |
|
2063 | 2063 | if not q.applied: |
|
2064 | 2064 | ui.write('no patches applied\n') |
|
2065 | 2065 | return 1 |
|
2066 | 2066 | patch = q.lookup('qtip') |
|
2067 | 2067 | ph = patchheader(repo.mq.join(patch)) |
|
2068 | 2068 | |
|
2069 | 2069 | ui.write('\n'.join(ph.message) + '\n') |
|
2070 | 2070 | |
|
2071 | 2071 | def lastsavename(path): |
|
2072 | 2072 | (directory, base) = os.path.split(path) |
|
2073 | 2073 | names = os.listdir(directory) |
|
2074 | 2074 | namere = re.compile("%s.([0-9]+)" % base) |
|
2075 | 2075 | maxindex = None |
|
2076 | 2076 | maxname = None |
|
2077 | 2077 | for f in names: |
|
2078 | 2078 | m = namere.match(f) |
|
2079 | 2079 | if m: |
|
2080 | 2080 | index = int(m.group(1)) |
|
2081 | 2081 | if maxindex is None or index > maxindex: |
|
2082 | 2082 | maxindex = index |
|
2083 | 2083 | maxname = f |
|
2084 | 2084 | if maxname: |
|
2085 | 2085 | return (os.path.join(directory, maxname), maxindex) |
|
2086 | 2086 | return (None, None) |
|
2087 | 2087 | |
|
2088 | 2088 | def savename(path): |
|
2089 | 2089 | (last, index) = lastsavename(path) |
|
2090 | 2090 | if last is None: |
|
2091 | 2091 | index = 0 |
|
2092 | 2092 | newpath = path + ".%d" % (index + 1) |
|
2093 | 2093 | return newpath |
|
2094 | 2094 | |
|
2095 | 2095 | def push(ui, repo, patch=None, **opts): |
|
2096 | 2096 | """push the next patch onto the stack |
|
2097 | 2097 | |
|
2098 | 2098 | When -f/--force is applied, all local changes in patched files will be |
|
2099 | 2099 | lost. |
|
2100 | 2100 | """ |
|
2101 | 2101 | q = repo.mq |
|
2102 | 2102 | mergeq = None |
|
2103 | 2103 | |
|
2104 | 2104 | if opts['merge']: |
|
2105 | 2105 | if opts['name']: |
|
2106 | 2106 | newpath = repo.join(opts['name']) |
|
2107 | 2107 | else: |
|
2108 | 2108 | newpath, i = lastsavename(q.path) |
|
2109 | 2109 | if not newpath: |
|
2110 | 2110 | ui.warn(_("no saved queues found, please use -n\n")) |
|
2111 | 2111 | return 1 |
|
2112 | 2112 | mergeq = queue(ui, repo.join(""), newpath) |
|
2113 | 2113 | ui.warn(_("merging with queue at: %s\n") % mergeq.path) |
|
2114 | 2114 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
|
2115 | 2115 | mergeq=mergeq, all=opts.get('all')) |
|
2116 | 2116 | return ret |
|
2117 | 2117 | |
|
2118 | 2118 | def pop(ui, repo, patch=None, **opts): |
|
2119 | 2119 | """pop the current patch off the stack |
|
2120 | 2120 | |
|
2121 | 2121 | By default, pops off the top of the patch stack. If given a patch name, |
|
2122 | 2122 | keeps popping off patches until the named patch is at the top of the |
|
2123 | 2123 | stack. |
|
2124 | 2124 | """ |
|
2125 | 2125 | localupdate = True |
|
2126 | 2126 | if opts['name']: |
|
2127 | 2127 | q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
2128 | 2128 | ui.warn(_('using patch queue: %s\n') % q.path) |
|
2129 | 2129 | localupdate = False |
|
2130 | 2130 | else: |
|
2131 | 2131 | q = repo.mq |
|
2132 | 2132 | ret = q.pop(repo, patch, force=opts['force'], update=localupdate, |
|
2133 | 2133 | all=opts['all']) |
|
2134 | 2134 | q.save_dirty() |
|
2135 | 2135 | return ret |
|
2136 | 2136 | |
|
2137 | 2137 | def rename(ui, repo, patch, name=None, **opts): |
|
2138 | 2138 | """rename a patch |
|
2139 | 2139 | |
|
2140 | 2140 | With one argument, renames the current patch to PATCH1. |
|
2141 | 2141 | With two arguments, renames PATCH1 to PATCH2.""" |
|
2142 | 2142 | |
|
2143 | 2143 | q = repo.mq |
|
2144 | 2144 | |
|
2145 | 2145 | if not name: |
|
2146 | 2146 | name = patch |
|
2147 | 2147 | patch = None |
|
2148 | 2148 | |
|
2149 | 2149 | if patch: |
|
2150 | 2150 | patch = q.lookup(patch) |
|
2151 | 2151 | else: |
|
2152 | 2152 | if not q.applied: |
|
2153 | 2153 | ui.write(_('no patches applied\n')) |
|
2154 | 2154 | return |
|
2155 | 2155 | patch = q.lookup('qtip') |
|
2156 | 2156 | absdest = q.join(name) |
|
2157 | 2157 | if os.path.isdir(absdest): |
|
2158 | 2158 | name = normname(os.path.join(name, os.path.basename(patch))) |
|
2159 | 2159 | absdest = q.join(name) |
|
2160 | 2160 | if os.path.exists(absdest): |
|
2161 | 2161 | raise util.Abort(_('%s already exists') % absdest) |
|
2162 | 2162 | |
|
2163 | 2163 | if name in q.series: |
|
2164 | 2164 | raise util.Abort(_('A patch named %s already exists in the series file') % name) |
|
2165 | 2165 | |
|
2166 | 2166 | if ui.verbose: |
|
2167 | 2167 | ui.write('renaming %s to %s\n' % (patch, name)) |
|
2168 | 2168 | i = q.find_series(patch) |
|
2169 | 2169 | guards = q.guard_re.findall(q.full_series[i]) |
|
2170 | 2170 | q.full_series[i] = name + ''.join([' #' + g for g in guards]) |
|
2171 | 2171 | q.parse_series() |
|
2172 | 2172 | q.series_dirty = 1 |
|
2173 | 2173 | |
|
2174 | 2174 | info = q.isapplied(patch) |
|
2175 | 2175 | if info: |
|
2176 | 2176 | q.applied[info[0]] = statusentry(info[1], name) |
|
2177 | 2177 | q.applied_dirty = 1 |
|
2178 | 2178 | |
|
2179 | 2179 | util.rename(q.join(patch), absdest) |
|
2180 | 2180 | r = q.qrepo() |
|
2181 | 2181 | if r: |
|
2182 | 2182 | wlock = r.wlock() |
|
2183 | 2183 | try: |
|
2184 | 2184 | if r.dirstate[patch] == 'a': |
|
2185 | 2185 | r.dirstate.forget(patch) |
|
2186 | 2186 | r.dirstate.add(name) |
|
2187 | 2187 | else: |
|
2188 | 2188 | if r.dirstate[name] == 'r': |
|
2189 | 2189 | r.undelete([name]) |
|
2190 | 2190 | r.copy(patch, name) |
|
2191 | 2191 | r.remove([patch], False) |
|
2192 | 2192 | finally: |
|
2193 | 2193 | wlock.release() |
|
2194 | 2194 | |
|
2195 | 2195 | q.save_dirty() |
|
2196 | 2196 | |
|
2197 | 2197 | def restore(ui, repo, rev, **opts): |
|
2198 | 2198 | """restore the queue state saved by a revision""" |
|
2199 | 2199 | rev = repo.lookup(rev) |
|
2200 | 2200 | q = repo.mq |
|
2201 | 2201 | q.restore(repo, rev, delete=opts['delete'], |
|
2202 | 2202 | qupdate=opts['update']) |
|
2203 | 2203 | q.save_dirty() |
|
2204 | 2204 | return 0 |
|
2205 | 2205 | |
|
2206 | 2206 | def save(ui, repo, **opts): |
|
2207 | 2207 | """save current queue state""" |
|
2208 | 2208 | q = repo.mq |
|
2209 | 2209 | message = cmdutil.logmessage(opts) |
|
2210 | 2210 | ret = q.save(repo, msg=message) |
|
2211 | 2211 | if ret: |
|
2212 | 2212 | return ret |
|
2213 | 2213 | q.save_dirty() |
|
2214 | 2214 | if opts['copy']: |
|
2215 | 2215 | path = q.path |
|
2216 | 2216 | if opts['name']: |
|
2217 | 2217 | newpath = os.path.join(q.basepath, opts['name']) |
|
2218 | 2218 | if os.path.exists(newpath): |
|
2219 | 2219 | if not os.path.isdir(newpath): |
|
2220 | 2220 | raise util.Abort(_('destination %s exists and is not ' |
|
2221 | 2221 | 'a directory') % newpath) |
|
2222 | 2222 | if not opts['force']: |
|
2223 | 2223 | raise util.Abort(_('destination %s exists, ' |
|
2224 | 2224 | 'use -f to force') % newpath) |
|
2225 | 2225 | else: |
|
2226 | 2226 | newpath = savename(path) |
|
2227 | 2227 | ui.warn(_("copy %s to %s\n") % (path, newpath)) |
|
2228 | 2228 | util.copyfiles(path, newpath) |
|
2229 | 2229 | if opts['empty']: |
|
2230 | 2230 | try: |
|
2231 | 2231 | os.unlink(q.join(q.status_path)) |
|
2232 | 2232 | except: |
|
2233 | 2233 | pass |
|
2234 | 2234 | return 0 |
|
2235 | 2235 | |
|
2236 | 2236 | def strip(ui, repo, rev, **opts): |
|
2237 | 2237 | """strip a revision and all its descendants from the repository |
|
2238 | 2238 | |
|
2239 | 2239 | If one of the working directory's parent revisions is stripped, the |
|
2240 | 2240 | working directory will be updated to the parent of the stripped revision. |
|
2241 | 2241 | """ |
|
2242 | 2242 | backup = 'all' |
|
2243 | 2243 | if opts['backup']: |
|
2244 | 2244 | backup = 'strip' |
|
2245 | 2245 | elif opts['nobackup']: |
|
2246 | 2246 | backup = 'none' |
|
2247 | 2247 | |
|
2248 | 2248 | rev = repo.lookup(rev) |
|
2249 | 2249 | p = repo.dirstate.parents() |
|
2250 | 2250 | cl = repo.changelog |
|
2251 | 2251 | update = True |
|
2252 | 2252 | if p[0] == nullid: |
|
2253 | 2253 | update = False |
|
2254 | 2254 | elif p[1] == nullid and rev != cl.ancestor(p[0], rev): |
|
2255 | 2255 | update = False |
|
2256 | 2256 | elif rev not in (cl.ancestor(p[0], rev), cl.ancestor(p[1], rev)): |
|
2257 | 2257 | update = False |
|
2258 | 2258 | |
|
2259 | 2259 | repo.mq.strip(repo, rev, backup=backup, update=update, force=opts['force']) |
|
2260 | 2260 | return 0 |
|
2261 | 2261 | |
|
2262 | 2262 | def select(ui, repo, *args, **opts): |
|
2263 | 2263 | '''set or print guarded patches to push |
|
2264 | 2264 | |
|
2265 | 2265 | Use the qguard command to set or print guards on patch, then use qselect |
|
2266 | 2266 | to tell mq which guards to use. A patch will be pushed if it has no guards |
|
2267 | 2267 | or any positive guards match the currently selected guard, but will not be |
|
2268 | 2268 | pushed if any negative guards match the current guard. For example: |
|
2269 | 2269 | |
|
2270 | 2270 | qguard foo.patch -stable (negative guard) |
|
2271 | 2271 | qguard bar.patch +stable (positive guard) |
|
2272 | 2272 | qselect stable |
|
2273 | 2273 | |
|
2274 | 2274 | This activates the "stable" guard. mq will skip foo.patch (because it has |
|
2275 | 2275 | a negative match) but push bar.patch (because it has a positive match). |
|
2276 | 2276 | |
|
2277 | 2277 | With no arguments, prints the currently active guards. With one argument, |
|
2278 | 2278 | sets the active guard. |
|
2279 | 2279 | |
|
2280 | 2280 | Use -n/--none to deactivate guards (no other arguments needed). When no |
|
2281 | 2281 | guards are active, patches with positive guards are skipped and patches |
|
2282 | 2282 | with negative guards are pushed. |
|
2283 | 2283 | |
|
2284 | 2284 | qselect can change the guards on applied patches. It does not pop guarded |
|
2285 | 2285 | patches by default. Use --pop to pop back to the last applied patch that |
|
2286 | 2286 | is not guarded. Use --reapply (which implies --pop) to push back to the |
|
2287 | 2287 | current patch afterwards, but skip guarded patches. |
|
2288 | 2288 | |
|
2289 | 2289 | Use -s/--series to print a list of all guards in the series file (no other |
|
2290 | 2290 | arguments needed). Use -v for more information. |
|
2291 | 2291 | ''' |
|
2292 | 2292 | |
|
2293 | 2293 | q = repo.mq |
|
2294 | 2294 | guards = q.active() |
|
2295 | 2295 | if args or opts['none']: |
|
2296 | 2296 | old_unapplied = q.unapplied(repo) |
|
2297 | 2297 | old_guarded = [i for i in xrange(len(q.applied)) if |
|
2298 | 2298 | not q.pushable(i)[0]] |
|
2299 | 2299 | q.set_active(args) |
|
2300 | 2300 | q.save_dirty() |
|
2301 | 2301 | if not args: |
|
2302 | 2302 | ui.status(_('guards deactivated\n')) |
|
2303 | 2303 | if not opts['pop'] and not opts['reapply']: |
|
2304 | 2304 | unapplied = q.unapplied(repo) |
|
2305 | 2305 | guarded = [i for i in xrange(len(q.applied)) |
|
2306 | 2306 | if not q.pushable(i)[0]] |
|
2307 | 2307 | if len(unapplied) != len(old_unapplied): |
|
2308 | 2308 | ui.status(_('number of unguarded, unapplied patches has ' |
|
2309 | 2309 | 'changed from %d to %d\n') % |
|
2310 | 2310 | (len(old_unapplied), len(unapplied))) |
|
2311 | 2311 | if len(guarded) != len(old_guarded): |
|
2312 | 2312 | ui.status(_('number of guarded, applied patches has changed ' |
|
2313 | 2313 | 'from %d to %d\n') % |
|
2314 | 2314 | (len(old_guarded), len(guarded))) |
|
2315 | 2315 | elif opts['series']: |
|
2316 | 2316 | guards = {} |
|
2317 | 2317 | noguards = 0 |
|
2318 | 2318 | for gs in q.series_guards: |
|
2319 | 2319 | if not gs: |
|
2320 | 2320 | noguards += 1 |
|
2321 | 2321 | for g in gs: |
|
2322 | 2322 | guards.setdefault(g, 0) |
|
2323 | 2323 | guards[g] += 1 |
|
2324 | 2324 | if ui.verbose: |
|
2325 | 2325 | guards['NONE'] = noguards |
|
2326 | 2326 | guards = guards.items() |
|
2327 | 2327 | guards.sort(key=lambda x: x[0][1:]) |
|
2328 | 2328 | if guards: |
|
2329 | 2329 | ui.note(_('guards in series file:\n')) |
|
2330 | 2330 | for guard, count in guards: |
|
2331 | 2331 | ui.note('%2d ' % count) |
|
2332 | 2332 | ui.write(guard, '\n') |
|
2333 | 2333 | else: |
|
2334 | 2334 | ui.note(_('no guards in series file\n')) |
|
2335 | 2335 | else: |
|
2336 | 2336 | if guards: |
|
2337 | 2337 | ui.note(_('active guards:\n')) |
|
2338 | 2338 | for g in guards: |
|
2339 | 2339 | ui.write(g, '\n') |
|
2340 | 2340 | else: |
|
2341 | 2341 | ui.write(_('no active guards\n')) |
|
2342 | 2342 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) |
|
2343 | 2343 | popped = False |
|
2344 | 2344 | if opts['pop'] or opts['reapply']: |
|
2345 | 2345 | for i in xrange(len(q.applied)): |
|
2346 | 2346 | pushable, reason = q.pushable(i) |
|
2347 | 2347 | if not pushable: |
|
2348 | 2348 | ui.status(_('popping guarded patches\n')) |
|
2349 | 2349 | popped = True |
|
2350 | 2350 | if i == 0: |
|
2351 | 2351 | q.pop(repo, all=True) |
|
2352 | 2352 | else: |
|
2353 | 2353 | q.pop(repo, i-1) |
|
2354 | 2354 | break |
|
2355 | 2355 | if popped: |
|
2356 | 2356 | try: |
|
2357 | 2357 | if reapply: |
|
2358 | 2358 | ui.status(_('reapplying unguarded patches\n')) |
|
2359 | 2359 | q.push(repo, reapply) |
|
2360 | 2360 | finally: |
|
2361 | 2361 | q.save_dirty() |
|
2362 | 2362 | |
|
2363 | 2363 | def finish(ui, repo, *revrange, **opts): |
|
2364 | 2364 | """move applied patches into repository history |
|
2365 | 2365 | |
|
2366 | 2366 | Finishes the specified revisions (corresponding to applied patches) by |
|
2367 | 2367 | moving them out of mq control into regular repository history. |
|
2368 | 2368 | |
|
2369 | 2369 | Accepts a revision range or the -a/--applied option. If --applied is |
|
2370 | 2370 | specified, all applied mq revisions are removed from mq control. |
|
2371 | 2371 | Otherwise, the given revisions must be at the base of the stack of applied |
|
2372 | 2372 | patches. |
|
2373 | 2373 | |
|
2374 | 2374 | This can be especially useful if your changes have been applied to an |
|
2375 | 2375 | upstream repository, or if you are about to push your changes to upstream. |
|
2376 | 2376 | """ |
|
2377 | 2377 | if not opts['applied'] and not revrange: |
|
2378 | 2378 | raise util.Abort(_('no revisions specified')) |
|
2379 | 2379 | elif opts['applied']: |
|
2380 | 2380 | revrange = ('qbase:qtip',) + revrange |
|
2381 | 2381 | |
|
2382 | 2382 | q = repo.mq |
|
2383 | 2383 | if not q.applied: |
|
2384 | 2384 | ui.status(_('no patches applied\n')) |
|
2385 | 2385 | return 0 |
|
2386 | 2386 | |
|
2387 | 2387 | revs = cmdutil.revrange(repo, revrange) |
|
2388 | 2388 | q.finish(repo, revs) |
|
2389 | 2389 | q.save_dirty() |
|
2390 | 2390 | return 0 |
|
2391 | 2391 | |
|
2392 | 2392 | def reposetup(ui, repo): |
|
2393 | 2393 | class mqrepo(repo.__class__): |
|
2394 | 2394 | @util.propertycache |
|
2395 | 2395 | def mq(self): |
|
2396 | 2396 | return queue(self.ui, self.join("")) |
|
2397 | 2397 | |
|
2398 | 2398 | def abort_if_wdir_patched(self, errmsg, force=False): |
|
2399 | 2399 | if self.mq.applied and not force: |
|
2400 | 2400 | parent = hex(self.dirstate.parents()[0]) |
|
2401 | 2401 | if parent in [s.rev for s in self.mq.applied]: |
|
2402 | 2402 | raise util.Abort(errmsg) |
|
2403 | 2403 | |
|
2404 | 2404 | def commit(self, text="", user=None, date=None, match=None, |
|
2405 | 2405 | force=False, editor=False, extra={}): |
|
2406 | 2406 | self.abort_if_wdir_patched( |
|
2407 | 2407 | _('cannot commit over an applied mq patch'), |
|
2408 | 2408 | force) |
|
2409 | 2409 | |
|
2410 | 2410 | return super(mqrepo, self).commit(text, user, date, match, force, |
|
2411 | 2411 | editor, extra) |
|
2412 | 2412 | |
|
2413 | 2413 | def push(self, remote, force=False, revs=None): |
|
2414 | 2414 | if self.mq.applied and not force and not revs: |
|
2415 | 2415 | raise util.Abort(_('source has mq patches applied')) |
|
2416 | 2416 | return super(mqrepo, self).push(remote, force, revs) |
|
2417 | 2417 | |
|
2418 | 2418 | def _findtags(self): |
|
2419 | 2419 | '''augment tags from base class with patch tags''' |
|
2420 | 2420 | result = super(mqrepo, self)._findtags() |
|
2421 | 2421 | |
|
2422 | 2422 | q = self.mq |
|
2423 | 2423 | if not q.applied: |
|
2424 | 2424 | return result |
|
2425 | 2425 | |
|
2426 | 2426 | mqtags = [(bin(patch.rev), patch.name) for patch in q.applied] |
|
2427 | 2427 | |
|
2428 | 2428 | if mqtags[-1][0] not in self.changelog.nodemap: |
|
2429 | 2429 | self.ui.warn(_('mq status file refers to unknown node %s\n') |
|
2430 | 2430 | % short(mqtags[-1][0])) |
|
2431 | 2431 | return result |
|
2432 | 2432 | |
|
2433 | 2433 | mqtags.append((mqtags[-1][0], 'qtip')) |
|
2434 | 2434 | mqtags.append((mqtags[0][0], 'qbase')) |
|
2435 | 2435 | mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) |
|
2436 | 2436 | tags = result[0] |
|
2437 | 2437 | for patch in mqtags: |
|
2438 | 2438 | if patch[1] in tags: |
|
2439 | 2439 | self.ui.warn(_('Tag %s overrides mq patch of the same name\n') |
|
2440 | 2440 | % patch[1]) |
|
2441 | 2441 | else: |
|
2442 | 2442 | tags[patch[1]] = patch[0] |
|
2443 | 2443 | |
|
2444 | 2444 | return result |
|
2445 | 2445 | |
|
2446 | 2446 | def _branchtags(self, partial, lrev): |
|
2447 | 2447 | q = self.mq |
|
2448 | 2448 | if not q.applied: |
|
2449 | 2449 | return super(mqrepo, self)._branchtags(partial, lrev) |
|
2450 | 2450 | |
|
2451 | 2451 | cl = self.changelog |
|
2452 | 2452 | qbasenode = bin(q.applied[0].rev) |
|
2453 | 2453 | if qbasenode not in cl.nodemap: |
|
2454 | 2454 | self.ui.warn(_('mq status file refers to unknown node %s\n') |
|
2455 | 2455 | % short(qbasenode)) |
|
2456 | 2456 | return super(mqrepo, self)._branchtags(partial, lrev) |
|
2457 | 2457 | |
|
2458 | 2458 | qbase = cl.rev(qbasenode) |
|
2459 | 2459 | start = lrev + 1 |
|
2460 | 2460 | if start < qbase: |
|
2461 | 2461 | # update the cache (excluding the patches) and save it |
|
2462 | 2462 | self._updatebranchcache(partial, lrev+1, qbase) |
|
2463 | 2463 | self._writebranchcache(partial, cl.node(qbase-1), qbase-1) |
|
2464 | 2464 | start = qbase |
|
2465 | 2465 | # if start = qbase, the cache is as updated as it should be. |
|
2466 | 2466 | # if start > qbase, the cache includes (part of) the patches. |
|
2467 | 2467 | # we might as well use it, but we won't save it. |
|
2468 | 2468 | |
|
2469 | 2469 | # update the cache up to the tip |
|
2470 | 2470 | self._updatebranchcache(partial, start, len(cl)) |
|
2471 | 2471 | |
|
2472 | 2472 | return partial |
|
2473 | 2473 | |
|
2474 | 2474 | if repo.local(): |
|
2475 | 2475 | repo.__class__ = mqrepo |
|
2476 | 2476 | |
|
2477 | 2477 | def mqimport(orig, ui, repo, *args, **kwargs): |
|
2478 | 2478 | if hasattr(repo, 'abort_if_wdir_patched'): |
|
2479 | 2479 | repo.abort_if_wdir_patched(_('cannot import over an applied patch'), |
|
2480 | 2480 | kwargs.get('force')) |
|
2481 | 2481 | return orig(ui, repo, *args, **kwargs) |
|
2482 | 2482 | |
|
2483 | 2483 | def uisetup(ui): |
|
2484 | 2484 | extensions.wrapcommand(commands.table, 'import', mqimport) |
|
2485 | 2485 | |
|
2486 | 2486 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] |
|
2487 | 2487 | |
|
2488 | 2488 | cmdtable = { |
|
2489 | 2489 | "qapplied": (applied, [] + seriesopts, _('hg qapplied [-s] [PATCH]')), |
|
2490 | 2490 | "qclone": |
|
2491 | 2491 | (clone, |
|
2492 | 2492 | [('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2493 | 2493 | ('U', 'noupdate', None, _('do not update the new working directories')), |
|
2494 | 2494 | ('', 'uncompressed', None, |
|
2495 | 2495 | _('use uncompressed transfer (fast over LAN)')), |
|
2496 | 2496 | ('p', 'patches', '', _('location of source patch repository')), |
|
2497 | 2497 | ] + commands.remoteopts, |
|
2498 | 2498 | _('hg qclone [OPTION]... SOURCE [DEST]')), |
|
2499 | 2499 | "qcommit|qci": |
|
2500 | 2500 | (commit, |
|
2501 | 2501 | commands.table["^commit|ci"][1], |
|
2502 | 2502 | _('hg qcommit [OPTION]... [FILE]...')), |
|
2503 | 2503 | "^qdiff": |
|
2504 | 2504 | (diff, |
|
2505 | 2505 | commands.diffopts + commands.diffopts2 + commands.walkopts, |
|
2506 | 2506 | _('hg qdiff [OPTION]... [FILE]...')), |
|
2507 | 2507 | "qdelete|qremove|qrm": |
|
2508 | 2508 | (delete, |
|
2509 | 2509 | [('k', 'keep', None, _('keep patch file')), |
|
2510 | 2510 | ('r', 'rev', [], _('stop managing a revision (DEPRECATED)'))], |
|
2511 | 2511 | _('hg qdelete [-k] [-r REV]... [PATCH]...')), |
|
2512 | 2512 | 'qfold': |
|
2513 | 2513 | (fold, |
|
2514 | 2514 | [('e', 'edit', None, _('edit patch header')), |
|
2515 | 2515 | ('k', 'keep', None, _('keep folded patch files')), |
|
2516 | 2516 | ] + commands.commitopts, |
|
2517 | 2517 | _('hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...')), |
|
2518 | 2518 | 'qgoto': |
|
2519 | 2519 | (goto, |
|
2520 | 2520 | [('f', 'force', None, _('overwrite any local changes'))], |
|
2521 | 2521 | _('hg qgoto [OPTION]... PATCH')), |
|
2522 | 2522 | 'qguard': |
|
2523 | 2523 | (guard, |
|
2524 | 2524 | [('l', 'list', None, _('list all patches and guards')), |
|
2525 | 2525 | ('n', 'none', None, _('drop all guards'))], |
|
2526 | 2526 | _('hg qguard [-l] [-n] -- [PATCH] [+GUARD]... [-GUARD]...')), |
|
2527 | 2527 | 'qheader': (header, [], _('hg qheader [PATCH]')), |
|
2528 | 2528 | "^qimport": |
|
2529 | 2529 | (qimport, |
|
2530 | 2530 | [('e', 'existing', None, _('import file in patch directory')), |
|
2531 | 2531 | ('n', 'name', '', _('name of patch file')), |
|
2532 | 2532 | ('f', 'force', None, _('overwrite existing files')), |
|
2533 | 2533 | ('r', 'rev', [], _('place existing revisions under mq control')), |
|
2534 | 2534 | ('g', 'git', None, _('use git extended diff format')), |
|
2535 | 2535 | ('P', 'push', None, _('qpush after importing'))], |
|
2536 | 2536 | _('hg qimport [-e] [-n NAME] [-f] [-g] [-P] [-r REV]... FILE...')), |
|
2537 | 2537 | "^qinit": |
|
2538 | 2538 | (init, |
|
2539 | 2539 | [('c', 'create-repo', None, _('create queue repository'))], |
|
2540 | 2540 | _('hg qinit [-c]')), |
|
2541 | 2541 | "qnew": |
|
2542 | 2542 | (new, |
|
2543 | 2543 | [('e', 'edit', None, _('edit commit message')), |
|
2544 | 2544 | ('f', 'force', None, _('import uncommitted changes into patch')), |
|
2545 | 2545 | ('g', 'git', None, _('use git extended diff format')), |
|
2546 | 2546 | ('U', 'currentuser', None, _('add "From: <current user>" to patch')), |
|
2547 | 2547 | ('u', 'user', '', _('add "From: <given user>" to patch')), |
|
2548 | 2548 | ('D', 'currentdate', None, _('add "Date: <current date>" to patch')), |
|
2549 | 2549 | ('d', 'date', '', _('add "Date: <given date>" to patch')) |
|
2550 | 2550 | ] + commands.walkopts + commands.commitopts, |
|
2551 | 2551 | _('hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH [FILE]...')), |
|
2552 | 2552 | "qnext": (next, [] + seriesopts, _('hg qnext [-s]')), |
|
2553 | 2553 | "qprev": (prev, [] + seriesopts, _('hg qprev [-s]')), |
|
2554 | 2554 | "^qpop": |
|
2555 | 2555 | (pop, |
|
2556 | 2556 | [('a', 'all', None, _('pop all patches')), |
|
2557 | 2557 | ('n', 'name', '', _('queue name to pop')), |
|
2558 | 2558 | ('f', 'force', None, _('forget any local changes'))], |
|
2559 | 2559 | _('hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]')), |
|
2560 | 2560 | "^qpush": |
|
2561 | 2561 | (push, |
|
2562 | 2562 | [('f', 'force', None, _('apply if the patch has rejects')), |
|
2563 | 2563 | ('l', 'list', None, _('list patch name in commit text')), |
|
2564 | 2564 | ('a', 'all', None, _('apply all patches')), |
|
2565 | 2565 | ('m', 'merge', None, _('merge from another queue')), |
|
2566 | 2566 | ('n', 'name', '', _('merge queue name'))], |
|
2567 | 2567 | _('hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]')), |
|
2568 | 2568 | "^qrefresh": |
|
2569 | 2569 | (refresh, |
|
2570 | 2570 | [('e', 'edit', None, _('edit commit message')), |
|
2571 | 2571 | ('g', 'git', None, _('use git extended diff format')), |
|
2572 | 2572 | ('s', 'short', None, _('refresh only files already in the patch and specified files')), |
|
2573 | 2573 | ('U', 'currentuser', None, _('add/update "From: <current user>" in patch')), |
|
2574 | 2574 | ('u', 'user', '', _('add/update "From: <given user>" in patch')), |
|
2575 | 2575 | ('D', 'currentdate', None, _('update "Date: <current date>" in patch (if present)')), |
|
2576 | 2576 | ('d', 'date', '', _('update "Date: <given date>" in patch (if present)')) |
|
2577 | 2577 | ] + commands.walkopts + commands.commitopts, |
|
2578 | 2578 | _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')), |
|
2579 | 2579 | 'qrename|qmv': |
|
2580 | 2580 | (rename, [], _('hg qrename PATCH1 [PATCH2]')), |
|
2581 | 2581 | "qrestore": |
|
2582 | 2582 | (restore, |
|
2583 | 2583 | [('d', 'delete', None, _('delete save entry')), |
|
2584 | 2584 | ('u', 'update', None, _('update queue working directory'))], |
|
2585 | 2585 | _('hg qrestore [-d] [-u] REV')), |
|
2586 | 2586 | "qsave": |
|
2587 | 2587 | (save, |
|
2588 | 2588 | [('c', 'copy', None, _('copy patch directory')), |
|
2589 | 2589 | ('n', 'name', '', _('copy directory name')), |
|
2590 | 2590 | ('e', 'empty', None, _('clear queue status file')), |
|
2591 | 2591 | ('f', 'force', None, _('force copy'))] + commands.commitopts, |
|
2592 | 2592 | _('hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]')), |
|
2593 | 2593 | "qselect": |
|
2594 | 2594 | (select, |
|
2595 | 2595 | [('n', 'none', None, _('disable all guards')), |
|
2596 | 2596 | ('s', 'series', None, _('list all guards in series file')), |
|
2597 | 2597 | ('', 'pop', None, _('pop to before first guarded applied patch')), |
|
2598 | 2598 | ('', 'reapply', None, _('pop, then reapply patches'))], |
|
2599 | 2599 | _('hg qselect [OPTION]... [GUARD]...')), |
|
2600 | 2600 | "qseries": |
|
2601 | 2601 | (series, |
|
2602 | 2602 | [('m', 'missing', None, _('print patches not in series')), |
|
2603 | 2603 | ] + seriesopts, |
|
2604 | 2604 | _('hg qseries [-ms]')), |
|
2605 | 2605 | "^strip": |
|
2606 | 2606 | (strip, |
|
2607 | 2607 | [('f', 'force', None, _('force removal with local changes')), |
|
2608 | 2608 | ('b', 'backup', None, _('bundle unrelated changesets')), |
|
2609 | 2609 | ('n', 'nobackup', None, _('no backups'))], |
|
2610 | 2610 | _('hg strip [-f] [-b] [-n] REV')), |
|
2611 | 2611 | "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), |
|
2612 | 2612 | "qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s] [PATCH]')), |
|
2613 | 2613 | "qfinish": |
|
2614 | 2614 | (finish, |
|
2615 | 2615 | [('a', 'applied', None, _('finish all applied changesets'))], |
|
2616 | 2616 | _('hg qfinish [-a] [REV]...')), |
|
2617 | 2617 | } |
@@ -1,303 +1,303 | |||
|
1 | 1 | # bundlerepo.py - repository class for viewing uncompressed bundles |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006, 2007 Benoit Boissinot <bboissin@gmail.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | """Repository class for viewing uncompressed bundles. |
|
9 | 9 | |
|
10 | 10 | This provides a read-only repository interface to bundles as if they |
|
11 | 11 | were part of the actual repository. |
|
12 | 12 | """ |
|
13 | 13 | |
|
14 | 14 | from node import nullid |
|
15 | 15 | from i18n import _ |
|
16 | 16 | import os, struct, bz2, zlib, tempfile, shutil |
|
17 | 17 | import changegroup, util, mdiff |
|
18 | 18 | import localrepo, changelog, manifest, filelog, revlog, error |
|
19 | 19 | |
|
20 | 20 | class bundlerevlog(revlog.revlog): |
|
21 | 21 | def __init__(self, opener, indexfile, bundlefile, |
|
22 | 22 | linkmapper=None): |
|
23 | 23 | # How it works: |
|
24 | 24 | # to retrieve a revision, we need to know the offset of |
|
25 | 25 | # the revision in the bundlefile (an opened file). |
|
26 | 26 | # |
|
27 | 27 | # We store this offset in the index (start), to differentiate a |
|
28 | 28 | # rev in the bundle and from a rev in the revlog, we check |
|
29 | 29 | # len(index[r]). If the tuple is bigger than 7, it is a bundle |
|
30 | 30 | # (it is bigger since we store the node to which the delta is) |
|
31 | 31 | # |
|
32 | 32 | revlog.revlog.__init__(self, opener, indexfile) |
|
33 | 33 | self.bundlefile = bundlefile |
|
34 | 34 | self.basemap = {} |
|
35 | 35 | def chunkpositer(): |
|
36 | 36 | for chunk in changegroup.chunkiter(bundlefile): |
|
37 | 37 | pos = bundlefile.tell() |
|
38 | 38 | yield chunk, pos - len(chunk) |
|
39 | 39 | n = len(self) |
|
40 | 40 | prev = None |
|
41 | 41 | for chunk, start in chunkpositer(): |
|
42 | 42 | size = len(chunk) |
|
43 | 43 | if size < 80: |
|
44 | 44 | raise util.Abort(_("invalid changegroup")) |
|
45 | 45 | start += 80 |
|
46 | 46 | size -= 80 |
|
47 | 47 | node, p1, p2, cs = struct.unpack("20s20s20s20s", chunk[:80]) |
|
48 | 48 | if node in self.nodemap: |
|
49 | 49 | prev = node |
|
50 | 50 | continue |
|
51 | 51 | for p in (p1, p2): |
|
52 | 52 | if not p in self.nodemap: |
|
53 | 53 | raise error.LookupError(p1, self.indexfile, |
|
54 | 54 | _("unknown parent")) |
|
55 | 55 | if linkmapper is None: |
|
56 | 56 | link = n |
|
57 | 57 | else: |
|
58 | 58 | link = linkmapper(cs) |
|
59 | 59 | |
|
60 | 60 | if not prev: |
|
61 | 61 | prev = p1 |
|
62 | 62 | # start, size, full unc. size, base (unused), link, p1, p2, node |
|
63 | 63 | e = (revlog.offset_type(start, 0), size, -1, -1, link, |
|
64 | 64 | self.rev(p1), self.rev(p2), node) |
|
65 | 65 | self.basemap[n] = prev |
|
66 | 66 | self.index.insert(-1, e) |
|
67 | 67 | self.nodemap[node] = n |
|
68 | 68 | prev = node |
|
69 | 69 | n += 1 |
|
70 | 70 | |
|
71 | 71 | def bundle(self, rev): |
|
72 | 72 | """is rev from the bundle""" |
|
73 | 73 | if rev < 0: |
|
74 | 74 | return False |
|
75 | 75 | return rev in self.basemap |
|
76 | 76 | def bundlebase(self, rev): return self.basemap[rev] |
|
77 | 77 | def chunk(self, rev, df=None, cachelen=4096): |
|
78 | 78 | # Warning: in case of bundle, the diff is against bundlebase, |
|
79 | 79 | # not against rev - 1 |
|
80 | 80 | # XXX: could use some caching |
|
81 | 81 | if not self.bundle(rev): |
|
82 | 82 | return revlog.revlog.chunk(self, rev, df) |
|
83 | 83 | self.bundlefile.seek(self.start(rev)) |
|
84 | 84 | return self.bundlefile.read(self.length(rev)) |
|
85 | 85 | |
|
86 | 86 | def revdiff(self, rev1, rev2): |
|
87 | 87 | """return or calculate a delta between two revisions""" |
|
88 | 88 | if self.bundle(rev1) and self.bundle(rev2): |
|
89 | 89 | # hot path for bundle |
|
90 | 90 | revb = self.rev(self.bundlebase(rev2)) |
|
91 | 91 | if revb == rev1: |
|
92 | 92 | return self.chunk(rev2) |
|
93 | 93 | elif not self.bundle(rev1) and not self.bundle(rev2): |
|
94 | 94 | return revlog.revlog.revdiff(self, rev1, rev2) |
|
95 | 95 | |
|
96 | 96 | return mdiff.textdiff(self.revision(self.node(rev1)), |
|
97 | 97 | self.revision(self.node(rev2))) |
|
98 | 98 | |
|
99 | 99 | def revision(self, node): |
|
100 | 100 | """return an uncompressed revision of a given""" |
|
101 | 101 | if node == nullid: return "" |
|
102 | 102 | |
|
103 | 103 | text = None |
|
104 | 104 | chain = [] |
|
105 | 105 | iter_node = node |
|
106 | 106 | rev = self.rev(iter_node) |
|
107 | 107 | # reconstruct the revision if it is from a changegroup |
|
108 | 108 | while self.bundle(rev): |
|
109 | 109 | if self._cache and self._cache[0] == iter_node: |
|
110 | 110 | text = self._cache[2] |
|
111 | 111 | break |
|
112 | 112 | chain.append(rev) |
|
113 | 113 | iter_node = self.bundlebase(rev) |
|
114 | 114 | rev = self.rev(iter_node) |
|
115 | 115 | if text is None: |
|
116 | 116 | text = revlog.revlog.revision(self, iter_node) |
|
117 | 117 | |
|
118 | 118 | while chain: |
|
119 | 119 | delta = self.chunk(chain.pop()) |
|
120 | 120 | text = mdiff.patches(text, [delta]) |
|
121 | 121 | |
|
122 | 122 | p1, p2 = self.parents(node) |
|
123 | 123 | if node != revlog.hash(text, p1, p2): |
|
124 | 124 | raise error.RevlogError(_("integrity check failed on %s:%d") |
|
125 | 125 | % (self.datafile, self.rev(node))) |
|
126 | 126 | |
|
127 | 127 | self._cache = (node, self.rev(node), text) |
|
128 | 128 | return text |
|
129 | 129 | |
|
130 | 130 | def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): |
|
131 | 131 | raise NotImplementedError |
|
132 | 132 | def addgroup(self, revs, linkmapper, transaction): |
|
133 | 133 | raise NotImplementedError |
|
134 | 134 | def strip(self, rev, minlink): |
|
135 | 135 | raise NotImplementedError |
|
136 | 136 | def checksize(self): |
|
137 | 137 | raise NotImplementedError |
|
138 | 138 | |
|
139 | 139 | class bundlechangelog(bundlerevlog, changelog.changelog): |
|
140 | 140 | def __init__(self, opener, bundlefile): |
|
141 | 141 | changelog.changelog.__init__(self, opener) |
|
142 | 142 | bundlerevlog.__init__(self, opener, self.indexfile, bundlefile) |
|
143 | 143 | |
|
144 | 144 | class bundlemanifest(bundlerevlog, manifest.manifest): |
|
145 | 145 | def __init__(self, opener, bundlefile, linkmapper): |
|
146 | 146 | manifest.manifest.__init__(self, opener) |
|
147 | 147 | bundlerevlog.__init__(self, opener, self.indexfile, bundlefile, |
|
148 | 148 | linkmapper) |
|
149 | 149 | |
|
150 | 150 | class bundlefilelog(bundlerevlog, filelog.filelog): |
|
151 | 151 | def __init__(self, opener, path, bundlefile, linkmapper): |
|
152 | 152 | filelog.filelog.__init__(self, opener, path) |
|
153 | 153 | bundlerevlog.__init__(self, opener, self.indexfile, bundlefile, |
|
154 | 154 | linkmapper) |
|
155 | 155 | |
|
156 | 156 | class bundlerepository(localrepo.localrepository): |
|
157 | 157 | def __init__(self, ui, path, bundlename): |
|
158 | 158 | self._tempparent = None |
|
159 | 159 | try: |
|
160 | 160 | localrepo.localrepository.__init__(self, ui, path) |
|
161 | 161 | except error.RepoError: |
|
162 | 162 | self._tempparent = tempfile.mkdtemp() |
|
163 | localrepo.instance(ui,self._tempparent,1) | |
|
163 | localrepo.instance(ui, self._tempparent, 1) | |
|
164 | 164 | localrepo.localrepository.__init__(self, ui, self._tempparent) |
|
165 | 165 | |
|
166 | 166 | if path: |
|
167 | 167 | self._url = 'bundle:' + path + '+' + bundlename |
|
168 | 168 | else: |
|
169 | 169 | self._url = 'bundle:' + bundlename |
|
170 | 170 | |
|
171 | 171 | self.tempfile = None |
|
172 | 172 | self.bundlefile = open(bundlename, "rb") |
|
173 | 173 | header = self.bundlefile.read(6) |
|
174 | 174 | if not header.startswith("HG"): |
|
175 | 175 | raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename) |
|
176 | 176 | elif not header.startswith("HG10"): |
|
177 | 177 | raise util.Abort(_("%s: unknown bundle version") % bundlename) |
|
178 | 178 | elif (header == "HG10BZ") or (header == "HG10GZ"): |
|
179 | 179 | fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-", |
|
180 | 180 | suffix=".hg10un", dir=self.path) |
|
181 | 181 | self.tempfile = temp |
|
182 | 182 | fptemp = os.fdopen(fdtemp, 'wb') |
|
183 | 183 | def generator(f): |
|
184 | 184 | if header == "HG10BZ": |
|
185 | 185 | zd = bz2.BZ2Decompressor() |
|
186 | 186 | zd.decompress("BZ") |
|
187 | 187 | elif header == "HG10GZ": |
|
188 | 188 | zd = zlib.decompressobj() |
|
189 | 189 | for chunk in f: |
|
190 | 190 | yield zd.decompress(chunk) |
|
191 | 191 | gen = generator(util.filechunkiter(self.bundlefile, 4096)) |
|
192 | 192 | |
|
193 | 193 | try: |
|
194 | 194 | fptemp.write("HG10UN") |
|
195 | 195 | for chunk in gen: |
|
196 | 196 | fptemp.write(chunk) |
|
197 | 197 | finally: |
|
198 | 198 | fptemp.close() |
|
199 | 199 | self.bundlefile.close() |
|
200 | 200 | |
|
201 | 201 | self.bundlefile = open(self.tempfile, "rb") |
|
202 | 202 | # seek right after the header |
|
203 | 203 | self.bundlefile.seek(6) |
|
204 | 204 | elif header == "HG10UN": |
|
205 | 205 | # nothing to do |
|
206 | 206 | pass |
|
207 | 207 | else: |
|
208 | 208 | raise util.Abort(_("%s: unknown bundle compression type") |
|
209 | 209 | % bundlename) |
|
210 | 210 | # dict with the mapping 'filename' -> position in the bundle |
|
211 | 211 | self.bundlefilespos = {} |
|
212 | 212 | |
|
213 | 213 | @util.propertycache |
|
214 | 214 | def changelog(self): |
|
215 | 215 | c = bundlechangelog(self.sopener, self.bundlefile) |
|
216 | 216 | self.manstart = self.bundlefile.tell() |
|
217 | 217 | return c |
|
218 | 218 | |
|
219 | 219 | @util.propertycache |
|
220 | 220 | def manifest(self): |
|
221 | 221 | self.bundlefile.seek(self.manstart) |
|
222 | 222 | m = bundlemanifest(self.sopener, self.bundlefile, self.changelog.rev) |
|
223 | 223 | self.filestart = self.bundlefile.tell() |
|
224 | 224 | return m |
|
225 | 225 | |
|
226 | 226 | @util.propertycache |
|
227 | 227 | def manstart(self): |
|
228 | 228 | self.changelog |
|
229 | 229 | return self.manstart |
|
230 | 230 | |
|
231 | 231 | @util.propertycache |
|
232 | 232 | def filestart(self): |
|
233 | 233 | self.manifest |
|
234 | 234 | return self.filestart |
|
235 | 235 | |
|
236 | 236 | def url(self): |
|
237 | 237 | return self._url |
|
238 | 238 | |
|
239 | 239 | def file(self, f): |
|
240 | 240 | if not self.bundlefilespos: |
|
241 | 241 | self.bundlefile.seek(self.filestart) |
|
242 | 242 | while 1: |
|
243 | 243 | chunk = changegroup.getchunk(self.bundlefile) |
|
244 | 244 | if not chunk: |
|
245 | 245 | break |
|
246 | 246 | self.bundlefilespos[chunk] = self.bundlefile.tell() |
|
247 | 247 | for c in changegroup.chunkiter(self.bundlefile): |
|
248 | 248 | pass |
|
249 | 249 | |
|
250 | 250 | if f[0] == '/': |
|
251 | 251 | f = f[1:] |
|
252 | 252 | if f in self.bundlefilespos: |
|
253 | 253 | self.bundlefile.seek(self.bundlefilespos[f]) |
|
254 | 254 | return bundlefilelog(self.sopener, f, self.bundlefile, |
|
255 | 255 | self.changelog.rev) |
|
256 | 256 | else: |
|
257 | 257 | return filelog.filelog(self.sopener, f) |
|
258 | 258 | |
|
259 | 259 | def close(self): |
|
260 | 260 | """Close assigned bundle file immediately.""" |
|
261 | 261 | self.bundlefile.close() |
|
262 | 262 | |
|
263 | 263 | def __del__(self): |
|
264 | 264 | bundlefile = getattr(self, 'bundlefile', None) |
|
265 | 265 | if bundlefile and not bundlefile.closed: |
|
266 | 266 | bundlefile.close() |
|
267 | 267 | tempfile = getattr(self, 'tempfile', None) |
|
268 | 268 | if tempfile is not None: |
|
269 | 269 | os.unlink(tempfile) |
|
270 | 270 | if self._tempparent: |
|
271 | 271 | shutil.rmtree(self._tempparent, True) |
|
272 | 272 | |
|
273 | 273 | def cancopy(self): |
|
274 | 274 | return False |
|
275 | 275 | |
|
276 | 276 | def getcwd(self): |
|
277 | 277 | return os.getcwd() # always outside the repo |
|
278 | 278 | |
|
279 | 279 | def instance(ui, path, create): |
|
280 | 280 | if create: |
|
281 | 281 | raise util.Abort(_('cannot create new bundle repository')) |
|
282 | 282 | parentpath = ui.config("bundle", "mainreporoot", "") |
|
283 | 283 | if parentpath: |
|
284 | 284 | # Try to make the full path relative so we get a nice, short URL. |
|
285 | 285 | # In particular, we don't want temp dir names in test outputs. |
|
286 | 286 | cwd = os.getcwd() |
|
287 | 287 | if parentpath == cwd: |
|
288 | 288 | parentpath = '' |
|
289 | 289 | else: |
|
290 | 290 | cwd = os.path.join(cwd,'') |
|
291 | 291 | if parentpath.startswith(cwd): |
|
292 | 292 | parentpath = parentpath[len(cwd):] |
|
293 | 293 | path = util.drop_scheme('file', path) |
|
294 | 294 | if path.startswith('bundle:'): |
|
295 | 295 | path = util.drop_scheme('bundle', path) |
|
296 | 296 | s = path.split("+", 1) |
|
297 | 297 | if len(s) == 1: |
|
298 | 298 | repopath, bundlename = parentpath, s[0] |
|
299 | 299 | else: |
|
300 | 300 | repopath, bundlename = s |
|
301 | 301 | else: |
|
302 | 302 | repopath, bundlename = parentpath, path |
|
303 | 303 | return bundlerepository(ui, repopath, bundlename) |
@@ -1,3518 +1,3518 | |||
|
1 | 1 | # commands.py - command processing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from node import hex, nullid, nullrev, short |
|
9 | 9 | from lock import release |
|
10 | 10 | from i18n import _, gettext |
|
11 | 11 | import os, re, sys, subprocess, difflib, time, tempfile |
|
12 | 12 | import hg, util, revlog, bundlerepo, extensions, copies, context, error |
|
13 | 13 | import patch, help, mdiff, url, encoding |
|
14 | 14 | import archival, changegroup, cmdutil, sshserver, hbisect |
|
15 | 15 | from hgweb import server |
|
16 | 16 | import merge as merge_ |
|
17 | 17 | import minirst |
|
18 | 18 | |
|
19 | 19 | # Commands start here, listed alphabetically |
|
20 | 20 | |
|
21 | 21 | def add(ui, repo, *pats, **opts): |
|
22 | 22 | """add the specified files on the next commit |
|
23 | 23 | |
|
24 | 24 | Schedule files to be version controlled and added to the repository. |
|
25 | 25 | |
|
26 | 26 | The files will be added to the repository at the next commit. To undo an |
|
27 | 27 | add before that, see hg forget. |
|
28 | 28 | |
|
29 | 29 | If no names are given, add all files to the repository. |
|
30 | 30 | """ |
|
31 | 31 | |
|
32 | 32 | bad = [] |
|
33 | 33 | exacts = {} |
|
34 | 34 | names = [] |
|
35 | 35 | m = cmdutil.match(repo, pats, opts) |
|
36 | 36 | oldbad = m.bad |
|
37 | 37 | m.bad = lambda x,y: bad.append(x) or oldbad(x,y) |
|
38 | 38 | |
|
39 | 39 | for f in repo.walk(m): |
|
40 | 40 | exact = m.exact(f) |
|
41 | 41 | if exact or f not in repo.dirstate: |
|
42 | 42 | names.append(f) |
|
43 | 43 | if ui.verbose or not exact: |
|
44 | 44 | ui.status(_('adding %s\n') % m.rel(f)) |
|
45 | 45 | if not opts.get('dry_run'): |
|
46 | 46 | bad += [f for f in repo.add(names) if f in m.files()] |
|
47 | 47 | return bad and 1 or 0 |
|
48 | 48 | |
|
49 | 49 | def addremove(ui, repo, *pats, **opts): |
|
50 | 50 | """add all new files, delete all missing files |
|
51 | 51 | |
|
52 | 52 | Add all new files and remove all missing files from the repository. |
|
53 | 53 | |
|
54 | 54 | New files are ignored if they match any of the patterns in .hgignore. As |
|
55 | 55 | with add, these changes take effect at the next commit. |
|
56 | 56 | |
|
57 | 57 | Use the -s/--similarity option to detect renamed files. With a parameter |
|
58 | 58 | greater than 0, this compares every removed file with every added file and |
|
59 | 59 | records those similar enough as renames. This option takes a percentage |
|
60 | 60 | between 0 (disabled) and 100 (files must be identical) as its parameter. |
|
61 | 61 | Detecting renamed files this way can be expensive. |
|
62 | 62 | """ |
|
63 | 63 | try: |
|
64 | 64 | sim = float(opts.get('similarity') or 0) |
|
65 | 65 | except ValueError: |
|
66 | 66 | raise util.Abort(_('similarity must be a number')) |
|
67 | 67 | if sim < 0 or sim > 100: |
|
68 | 68 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
69 | 69 | return cmdutil.addremove(repo, pats, opts, similarity=sim/100.) |
|
70 | 70 | |
|
71 | 71 | def annotate(ui, repo, *pats, **opts): |
|
72 | 72 | """show changeset information by line for each file |
|
73 | 73 | |
|
74 | 74 | List changes in files, showing the revision id responsible for each line |
|
75 | 75 | |
|
76 | 76 | This command is useful for discovering when a change was made and by whom. |
|
77 | 77 | |
|
78 | 78 | Without the -a/--text option, annotate will avoid processing files it |
|
79 | 79 | detects as binary. With -a, annotate will annotate the file anyway, |
|
80 | 80 | although the results will probably be neither useful nor desirable. |
|
81 | 81 | """ |
|
82 | 82 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
83 | 83 | getdate = util.cachefunc(lambda x: datefunc(x[0].date())) |
|
84 | 84 | |
|
85 | 85 | if not pats: |
|
86 | 86 | raise util.Abort(_('at least one filename or pattern is required')) |
|
87 | 87 | |
|
88 | 88 | opmap = [('user', lambda x: ui.shortuser(x[0].user())), |
|
89 | 89 | ('number', lambda x: str(x[0].rev())), |
|
90 | 90 | ('changeset', lambda x: short(x[0].node())), |
|
91 | 91 | ('date', getdate), |
|
92 | 92 | ('follow', lambda x: x[0].path()), |
|
93 | 93 | ] |
|
94 | 94 | |
|
95 | 95 | if (not opts.get('user') and not opts.get('changeset') and not opts.get('date') |
|
96 | 96 | and not opts.get('follow')): |
|
97 | 97 | opts['number'] = 1 |
|
98 | 98 | |
|
99 | 99 | linenumber = opts.get('line_number') is not None |
|
100 | 100 | if (linenumber and (not opts.get('changeset')) and (not opts.get('number'))): |
|
101 | 101 | raise util.Abort(_('at least one of -n/-c is required for -l')) |
|
102 | 102 | |
|
103 | 103 | funcmap = [func for op, func in opmap if opts.get(op)] |
|
104 | 104 | if linenumber: |
|
105 | 105 | lastfunc = funcmap[-1] |
|
106 | 106 | funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) |
|
107 | 107 | |
|
108 | 108 | ctx = repo[opts.get('rev')] |
|
109 | 109 | |
|
110 | 110 | m = cmdutil.match(repo, pats, opts) |
|
111 | 111 | for abs in ctx.walk(m): |
|
112 | 112 | fctx = ctx[abs] |
|
113 | 113 | if not opts.get('text') and util.binary(fctx.data()): |
|
114 | 114 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
115 | 115 | continue |
|
116 | 116 | |
|
117 | 117 | lines = fctx.annotate(follow=opts.get('follow'), |
|
118 | 118 | linenumber=linenumber) |
|
119 | 119 | pieces = [] |
|
120 | 120 | |
|
121 | 121 | for f in funcmap: |
|
122 | 122 | l = [f(n) for n, dummy in lines] |
|
123 | 123 | if l: |
|
124 | 124 | ml = max(map(len, l)) |
|
125 | 125 | pieces.append(["%*s" % (ml, x) for x in l]) |
|
126 | 126 | |
|
127 | 127 | if pieces: |
|
128 | 128 | for p, l in zip(zip(*pieces), lines): |
|
129 | 129 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
130 | 130 | |
|
131 | 131 | def archive(ui, repo, dest, **opts): |
|
132 | 132 | '''create an unversioned archive of a repository revision |
|
133 | 133 | |
|
134 | 134 | By default, the revision used is the parent of the working directory; use |
|
135 | 135 | -r/--rev to specify a different revision. |
|
136 | 136 | |
|
137 | 137 | To specify the type of archive to create, use -t/--type. Valid types are:: |
|
138 | 138 | |
|
139 | 139 | "files" (default): a directory full of files |
|
140 | 140 | "tar": tar archive, uncompressed |
|
141 | 141 | "tbz2": tar archive, compressed using bzip2 |
|
142 | 142 | "tgz": tar archive, compressed using gzip |
|
143 | 143 | "uzip": zip archive, uncompressed |
|
144 | 144 | "zip": zip archive, compressed using deflate |
|
145 | 145 | |
|
146 | 146 | The exact name of the destination archive or directory is given using a |
|
147 | 147 | format string; see 'hg help export' for details. |
|
148 | 148 | |
|
149 | 149 | Each member added to an archive file has a directory prefix prepended. Use |
|
150 | 150 | -p/--prefix to specify a format string for the prefix. The default is the |
|
151 | 151 | basename of the archive, with suffixes removed. |
|
152 | 152 | ''' |
|
153 | 153 | |
|
154 | 154 | ctx = repo[opts.get('rev')] |
|
155 | 155 | if not ctx: |
|
156 | 156 | raise util.Abort(_('no working directory: please specify a revision')) |
|
157 | 157 | node = ctx.node() |
|
158 | 158 | dest = cmdutil.make_filename(repo, dest, node) |
|
159 | 159 | if os.path.realpath(dest) == repo.root: |
|
160 | 160 | raise util.Abort(_('repository root cannot be destination')) |
|
161 | 161 | matchfn = cmdutil.match(repo, [], opts) |
|
162 | 162 | kind = opts.get('type') or 'files' |
|
163 | 163 | prefix = opts.get('prefix') |
|
164 | 164 | if dest == '-': |
|
165 | 165 | if kind == 'files': |
|
166 | 166 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
167 | 167 | dest = sys.stdout |
|
168 | 168 | if not prefix: prefix = os.path.basename(repo.root) + '-%h' |
|
169 | 169 | prefix = cmdutil.make_filename(repo, prefix, node) |
|
170 | 170 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
171 | 171 | matchfn, prefix) |
|
172 | 172 | |
|
173 | 173 | def backout(ui, repo, node=None, rev=None, **opts): |
|
174 | 174 | '''reverse effect of earlier changeset |
|
175 | 175 | |
|
176 | 176 | Commit the backed out changes as a new changeset. The new changeset is a |
|
177 | 177 | child of the backed out changeset. |
|
178 | 178 | |
|
179 | 179 | If you backout a changeset other than the tip, a new head is created. This |
|
180 | 180 | head will be the new tip and you should merge this backout changeset with |
|
181 | 181 | another head. |
|
182 | 182 | |
|
183 | 183 | The --merge option remembers the parent of the working directory before |
|
184 | 184 | starting the backout, then merges the new head with that changeset |
|
185 | 185 | afterwards. This saves you from doing the merge by hand. The result of |
|
186 | 186 | this merge is not committed, as with a normal merge. |
|
187 | 187 | |
|
188 | 188 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
189 | 189 | ''' |
|
190 | 190 | if rev and node: |
|
191 | 191 | raise util.Abort(_("please specify just one revision")) |
|
192 | 192 | |
|
193 | 193 | if not rev: |
|
194 | 194 | rev = node |
|
195 | 195 | |
|
196 | 196 | if not rev: |
|
197 | 197 | raise util.Abort(_("please specify a revision to backout")) |
|
198 | 198 | |
|
199 | 199 | date = opts.get('date') |
|
200 | 200 | if date: |
|
201 | 201 | opts['date'] = util.parsedate(date) |
|
202 | 202 | |
|
203 | 203 | cmdutil.bail_if_changed(repo) |
|
204 | 204 | node = repo.lookup(rev) |
|
205 | 205 | |
|
206 | 206 | op1, op2 = repo.dirstate.parents() |
|
207 | 207 | a = repo.changelog.ancestor(op1, node) |
|
208 | 208 | if a != node: |
|
209 | 209 | raise util.Abort(_('cannot backout change on a different branch')) |
|
210 | 210 | |
|
211 | 211 | p1, p2 = repo.changelog.parents(node) |
|
212 | 212 | if p1 == nullid: |
|
213 | 213 | raise util.Abort(_('cannot backout a change with no parents')) |
|
214 | 214 | if p2 != nullid: |
|
215 | 215 | if not opts.get('parent'): |
|
216 | 216 | raise util.Abort(_('cannot backout a merge changeset without ' |
|
217 | 217 | '--parent')) |
|
218 | 218 | p = repo.lookup(opts['parent']) |
|
219 | 219 | if p not in (p1, p2): |
|
220 | 220 | raise util.Abort(_('%s is not a parent of %s') % |
|
221 | 221 | (short(p), short(node))) |
|
222 | 222 | parent = p |
|
223 | 223 | else: |
|
224 | 224 | if opts.get('parent'): |
|
225 | 225 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
226 | 226 | parent = p1 |
|
227 | 227 | |
|
228 | 228 | # the backout should appear on the same branch |
|
229 | 229 | branch = repo.dirstate.branch() |
|
230 | 230 | hg.clean(repo, node, show_stats=False) |
|
231 | 231 | repo.dirstate.setbranch(branch) |
|
232 | 232 | revert_opts = opts.copy() |
|
233 | 233 | revert_opts['date'] = None |
|
234 | 234 | revert_opts['all'] = True |
|
235 | 235 | revert_opts['rev'] = hex(parent) |
|
236 | 236 | revert_opts['no_backup'] = None |
|
237 | 237 | revert(ui, repo, **revert_opts) |
|
238 | 238 | commit_opts = opts.copy() |
|
239 | 239 | commit_opts['addremove'] = False |
|
240 | 240 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
241 | 241 | # we don't translate commit messages |
|
242 | 242 | commit_opts['message'] = "Backed out changeset %s" % short(node) |
|
243 | 243 | commit_opts['force_editor'] = True |
|
244 | 244 | commit(ui, repo, **commit_opts) |
|
245 | 245 | def nice(node): |
|
246 | 246 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
247 | 247 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
248 | 248 | (nice(repo.changelog.tip()), nice(node))) |
|
249 | 249 | if op1 != node: |
|
250 | 250 | hg.clean(repo, op1, show_stats=False) |
|
251 | 251 | if opts.get('merge'): |
|
252 | 252 | ui.status(_('merging with changeset %s\n') % nice(repo.changelog.tip())) |
|
253 | 253 | hg.merge(repo, hex(repo.changelog.tip())) |
|
254 | 254 | else: |
|
255 | 255 | ui.status(_('the backout changeset is a new head - ' |
|
256 | 256 | 'do not forget to merge\n')) |
|
257 | 257 | ui.status(_('(use "backout --merge" ' |
|
258 | 258 | 'if you want to auto-merge)\n')) |
|
259 | 259 | |
|
260 | 260 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
261 | 261 | reset=None, good=None, bad=None, skip=None, noupdate=None): |
|
262 | 262 | """subdivision search of changesets |
|
263 | 263 | |
|
264 | 264 | This command helps to find changesets which introduce problems. To use, |
|
265 | 265 | mark the earliest changeset you know exhibits the problem as bad, then |
|
266 | 266 | mark the latest changeset which is free from the problem as good. Bisect |
|
267 | 267 | will update your working directory to a revision for testing (unless the |
|
268 | 268 | -U/--noupdate option is specified). Once you have performed tests, mark |
|
269 | 269 | the working directory as good or bad, and bisect will either update to |
|
270 | 270 | another candidate changeset or announce that it has found the bad |
|
271 | 271 | revision. |
|
272 | 272 | |
|
273 | 273 | As a shortcut, you can also use the revision argument to mark a revision |
|
274 | 274 | as good or bad without checking it out first. |
|
275 | 275 | |
|
276 | 276 | If you supply a command, it will be used for automatic bisection. Its exit |
|
277 | 277 | status will be used to mark revisions as good or bad: status 0 means good, |
|
278 | 278 | 125 means to skip the revision, 127 (command not found) will abort the |
|
279 | 279 | bisection, and any other non-zero exit status means the revision is bad. |
|
280 | 280 | """ |
|
281 | 281 | def print_result(nodes, good): |
|
282 | 282 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
283 | 283 | if len(nodes) == 1: |
|
284 | 284 | # narrowed it down to a single revision |
|
285 | 285 | if good: |
|
286 | 286 | ui.write(_("The first good revision is:\n")) |
|
287 | 287 | else: |
|
288 | 288 | ui.write(_("The first bad revision is:\n")) |
|
289 | 289 | displayer.show(repo[nodes[0]]) |
|
290 | 290 | else: |
|
291 | 291 | # multiple possible revisions |
|
292 | 292 | if good: |
|
293 | 293 | ui.write(_("Due to skipped revisions, the first " |
|
294 | 294 | "good revision could be any of:\n")) |
|
295 | 295 | else: |
|
296 | 296 | ui.write(_("Due to skipped revisions, the first " |
|
297 | 297 | "bad revision could be any of:\n")) |
|
298 | 298 | for n in nodes: |
|
299 | 299 | displayer.show(repo[n]) |
|
300 | 300 | |
|
301 | 301 | def check_state(state, interactive=True): |
|
302 | 302 | if not state['good'] or not state['bad']: |
|
303 | 303 | if (good or bad or skip or reset) and interactive: |
|
304 | 304 | return |
|
305 | 305 | if not state['good']: |
|
306 | 306 | raise util.Abort(_('cannot bisect (no known good revisions)')) |
|
307 | 307 | else: |
|
308 | 308 | raise util.Abort(_('cannot bisect (no known bad revisions)')) |
|
309 | 309 | return True |
|
310 | 310 | |
|
311 | 311 | # backward compatibility |
|
312 | 312 | if rev in "good bad reset init".split(): |
|
313 | 313 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
314 | 314 | cmd, rev, extra = rev, extra, None |
|
315 | 315 | if cmd == "good": |
|
316 | 316 | good = True |
|
317 | 317 | elif cmd == "bad": |
|
318 | 318 | bad = True |
|
319 | 319 | else: |
|
320 | 320 | reset = True |
|
321 | 321 | elif extra or good + bad + skip + reset + bool(command) > 1: |
|
322 | 322 | raise util.Abort(_('incompatible arguments')) |
|
323 | 323 | |
|
324 | 324 | if reset: |
|
325 | 325 | p = repo.join("bisect.state") |
|
326 | 326 | if os.path.exists(p): |
|
327 | 327 | os.unlink(p) |
|
328 | 328 | return |
|
329 | 329 | |
|
330 | 330 | state = hbisect.load_state(repo) |
|
331 | 331 | |
|
332 | 332 | if command: |
|
333 | 333 | commandpath = util.find_exe(command) |
|
334 | 334 | if commandpath is None: |
|
335 | 335 | raise util.Abort(_("cannot find executable: %s") % command) |
|
336 | 336 | changesets = 1 |
|
337 | 337 | try: |
|
338 | 338 | while changesets: |
|
339 | 339 | # update state |
|
340 | 340 | status = subprocess.call([commandpath]) |
|
341 | 341 | if status == 125: |
|
342 | 342 | transition = "skip" |
|
343 | 343 | elif status == 0: |
|
344 | 344 | transition = "good" |
|
345 | 345 | # status < 0 means process was killed |
|
346 | 346 | elif status == 127: |
|
347 | 347 | raise util.Abort(_("failed to execute %s") % command) |
|
348 | 348 | elif status < 0: |
|
349 | 349 | raise util.Abort(_("%s killed") % command) |
|
350 | 350 | else: |
|
351 | 351 | transition = "bad" |
|
352 | 352 | ctx = repo[rev or '.'] |
|
353 | 353 | state[transition].append(ctx.node()) |
|
354 | 354 | ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
355 | 355 | check_state(state, interactive=False) |
|
356 | 356 | # bisect |
|
357 | 357 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
358 | 358 | # update to next check |
|
359 | 359 | cmdutil.bail_if_changed(repo) |
|
360 | 360 | hg.clean(repo, nodes[0], show_stats=False) |
|
361 | 361 | finally: |
|
362 | 362 | hbisect.save_state(repo, state) |
|
363 | 363 | return print_result(nodes, not status) |
|
364 | 364 | |
|
365 | 365 | # update state |
|
366 | 366 | node = repo.lookup(rev or '.') |
|
367 | 367 | if good: |
|
368 | 368 | state['good'].append(node) |
|
369 | 369 | elif bad: |
|
370 | 370 | state['bad'].append(node) |
|
371 | 371 | elif skip: |
|
372 | 372 | state['skip'].append(node) |
|
373 | 373 | |
|
374 | 374 | hbisect.save_state(repo, state) |
|
375 | 375 | |
|
376 | 376 | if not check_state(state): |
|
377 | 377 | return |
|
378 | 378 | |
|
379 | 379 | # actually bisect |
|
380 | 380 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
381 | 381 | if changesets == 0: |
|
382 | 382 | print_result(nodes, good) |
|
383 | 383 | else: |
|
384 | 384 | assert len(nodes) == 1 # only a single node can be tested next |
|
385 | 385 | node = nodes[0] |
|
386 | 386 | # compute the approximate number of remaining tests |
|
387 | 387 | tests, size = 0, 2 |
|
388 | 388 | while size <= changesets: |
|
389 | 389 | tests, size = tests + 1, size * 2 |
|
390 | 390 | rev = repo.changelog.rev(node) |
|
391 | 391 | ui.write(_("Testing changeset %d:%s " |
|
392 | 392 | "(%d changesets remaining, ~%d tests)\n") |
|
393 | 393 | % (rev, short(node), changesets, tests)) |
|
394 | 394 | if not noupdate: |
|
395 | 395 | cmdutil.bail_if_changed(repo) |
|
396 | 396 | return hg.clean(repo, node) |
|
397 | 397 | |
|
398 | 398 | def branch(ui, repo, label=None, **opts): |
|
399 | 399 | """set or show the current branch name |
|
400 | 400 | |
|
401 | 401 | With no argument, show the current branch name. With one argument, set the |
|
402 | 402 | working directory branch name (the branch will not exist in the repository |
|
403 | 403 | until the next commit). Standard practice recommends that primary |
|
404 | 404 | development take place on the 'default' branch. |
|
405 | 405 | |
|
406 | 406 | Unless -f/--force is specified, branch will not let you set a branch name |
|
407 | 407 | that already exists, even if it's inactive. |
|
408 | 408 | |
|
409 | 409 | Use -C/--clean to reset the working directory branch to that of the parent |
|
410 | 410 | of the working directory, negating a previous branch change. |
|
411 | 411 | |
|
412 | 412 | Use the command 'hg update' to switch to an existing branch. Use 'hg |
|
413 | 413 | commit --close-branch' to mark this branch as closed. |
|
414 | 414 | """ |
|
415 | 415 | |
|
416 | 416 | if opts.get('clean'): |
|
417 | 417 | label = repo[None].parents()[0].branch() |
|
418 | 418 | repo.dirstate.setbranch(label) |
|
419 | 419 | ui.status(_('reset working directory to branch %s\n') % label) |
|
420 | 420 | elif label: |
|
421 | 421 | if not opts.get('force') and label in repo.branchtags(): |
|
422 | 422 | if label not in [p.branch() for p in repo.parents()]: |
|
423 | 423 | raise util.Abort(_('a branch of the same name already exists' |
|
424 | 424 | ' (use --force to override)')) |
|
425 | 425 | repo.dirstate.setbranch(encoding.fromlocal(label)) |
|
426 | 426 | ui.status(_('marked working directory as branch %s\n') % label) |
|
427 | 427 | else: |
|
428 | 428 | ui.write("%s\n" % encoding.tolocal(repo.dirstate.branch())) |
|
429 | 429 | |
|
430 | 430 | def branches(ui, repo, active=False, closed=False): |
|
431 | 431 | """list repository named branches |
|
432 | 432 | |
|
433 | 433 | List the repository's named branches, indicating which ones are inactive. |
|
434 | 434 | If -c/--closed is specified, also list branches which have been marked |
|
435 | 435 | closed (see hg commit --close-branch). |
|
436 | 436 | |
|
437 | 437 | If -a/--active is specified, only show active branches. A branch is |
|
438 | 438 | considered active if it contains repository heads. |
|
439 | 439 | |
|
440 | 440 | Use the command 'hg update' to switch to an existing branch. |
|
441 | 441 | """ |
|
442 | 442 | |
|
443 | 443 | hexfunc = ui.debugflag and hex or short |
|
444 | 444 | activebranches = [encoding.tolocal(repo[n].branch()) |
|
445 | 445 | for n in repo.heads()] |
|
446 | 446 | def testactive(tag, node): |
|
447 | 447 | realhead = tag in activebranches |
|
448 | 448 | open = node in repo.branchheads(tag, closed=False) |
|
449 | 449 | return realhead and open |
|
450 | 450 | branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag) |
|
451 | 451 | for tag, node in repo.branchtags().items()], |
|
452 | 452 | reverse=True) |
|
453 | 453 | |
|
454 | 454 | for isactive, node, tag in branches: |
|
455 | 455 | if (not active) or isactive: |
|
456 | 456 | if ui.quiet: |
|
457 | 457 | ui.write("%s\n" % tag) |
|
458 | 458 | else: |
|
459 | 459 | hn = repo.lookup(node) |
|
460 | 460 | if isactive: |
|
461 | 461 | notice = '' |
|
462 | 462 | elif hn not in repo.branchheads(tag, closed=False): |
|
463 | 463 | if not closed: |
|
464 | 464 | continue |
|
465 | 465 | notice = ' (closed)' |
|
466 | 466 | else: |
|
467 | 467 | notice = ' (inactive)' |
|
468 | 468 | rev = str(node).rjust(31 - encoding.colwidth(tag)) |
|
469 | 469 | data = tag, rev, hexfunc(hn), notice |
|
470 | 470 | ui.write("%s %s:%s%s\n" % data) |
|
471 | 471 | |
|
472 | 472 | def bundle(ui, repo, fname, dest=None, **opts): |
|
473 | 473 | """create a changegroup file |
|
474 | 474 | |
|
475 | 475 | Generate a compressed changegroup file collecting changesets not known to |
|
476 | 476 | be in another repository. |
|
477 | 477 | |
|
478 | 478 | If no destination repository is specified the destination is assumed to |
|
479 | 479 | have all the nodes specified by one or more --base parameters. To create a |
|
480 | 480 | bundle containing all changesets, use -a/--all (or --base null). |
|
481 | 481 | |
|
482 | 482 | You can change compression method with the -t/--type option. The available |
|
483 | 483 | compression methods are: none, bzip2, and gzip (by default, bundles are |
|
484 | 484 | compressed using bzip2). |
|
485 | 485 | |
|
486 | 486 | The bundle file can then be transferred using conventional means and |
|
487 | 487 | applied to another repository with the unbundle or pull command. This is |
|
488 | 488 | useful when direct push and pull are not available or when exporting an |
|
489 | 489 | entire repository is undesirable. |
|
490 | 490 | |
|
491 | 491 | Applying bundles preserves all changeset contents including permissions, |
|
492 | 492 | copy/rename information, and revision history. |
|
493 | 493 | """ |
|
494 | 494 | revs = opts.get('rev') or None |
|
495 | 495 | if revs: |
|
496 | 496 | revs = [repo.lookup(rev) for rev in revs] |
|
497 | 497 | if opts.get('all'): |
|
498 | 498 | base = ['null'] |
|
499 | 499 | else: |
|
500 | 500 | base = opts.get('base') |
|
501 | 501 | if base: |
|
502 | 502 | if dest: |
|
503 | 503 | raise util.Abort(_("--base is incompatible with specifying " |
|
504 | 504 | "a destination")) |
|
505 | 505 | base = [repo.lookup(rev) for rev in base] |
|
506 | 506 | # create the right base |
|
507 | 507 | # XXX: nodesbetween / changegroup* should be "fixed" instead |
|
508 | 508 | o = [] |
|
509 | 509 | has = set((nullid,)) |
|
510 | 510 | for n in base: |
|
511 | 511 | has.update(repo.changelog.reachable(n)) |
|
512 | 512 | if revs: |
|
513 | 513 | visit = list(revs) |
|
514 | 514 | else: |
|
515 | 515 | visit = repo.changelog.heads() |
|
516 | 516 | seen = {} |
|
517 | 517 | while visit: |
|
518 | 518 | n = visit.pop(0) |
|
519 | 519 | parents = [p for p in repo.changelog.parents(n) if p not in has] |
|
520 | 520 | if len(parents) == 0: |
|
521 | 521 | o.insert(0, n) |
|
522 | 522 | else: |
|
523 | 523 | for p in parents: |
|
524 | 524 | if p not in seen: |
|
525 | 525 | seen[p] = 1 |
|
526 | 526 | visit.append(p) |
|
527 | 527 | else: |
|
528 | 528 | dest, revs, checkout = hg.parseurl( |
|
529 | 529 | ui.expandpath(dest or 'default-push', dest or 'default'), revs) |
|
530 | 530 | other = hg.repository(cmdutil.remoteui(repo, opts), dest) |
|
531 | 531 | o = repo.findoutgoing(other, force=opts.get('force')) |
|
532 | 532 | |
|
533 | 533 | if revs: |
|
534 | 534 | cg = repo.changegroupsubset(o, revs, 'bundle') |
|
535 | 535 | else: |
|
536 | 536 | cg = repo.changegroup(o, 'bundle') |
|
537 | 537 | |
|
538 | 538 | bundletype = opts.get('type', 'bzip2').lower() |
|
539 | 539 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
540 | 540 | bundletype = btypes.get(bundletype) |
|
541 | 541 | if bundletype not in changegroup.bundletypes: |
|
542 | 542 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
543 | 543 | |
|
544 | 544 | changegroup.writebundle(cg, fname, bundletype) |
|
545 | 545 | |
|
546 | 546 | def cat(ui, repo, file1, *pats, **opts): |
|
547 | 547 | """output the current or given revision of files |
|
548 | 548 | |
|
549 | 549 | Print the specified files as they were at the given revision. If no |
|
550 | 550 | revision is given, the parent of the working directory is used, or tip if |
|
551 | 551 | no revision is checked out. |
|
552 | 552 | |
|
553 | 553 | Output may be to a file, in which case the name of the file is given using |
|
554 | 554 | a format string. The formatting rules are the same as for the export |
|
555 | 555 | command, with the following additions:: |
|
556 | 556 | |
|
557 | 557 | %s basename of file being printed |
|
558 | 558 | %d dirname of file being printed, or '.' if in repository root |
|
559 | 559 | %p root-relative path name of file being printed |
|
560 | 560 | """ |
|
561 | 561 | ctx = repo[opts.get('rev')] |
|
562 | 562 | err = 1 |
|
563 | 563 | m = cmdutil.match(repo, (file1,) + pats, opts) |
|
564 | 564 | for abs in ctx.walk(m): |
|
565 | 565 | fp = cmdutil.make_file(repo, opts.get('output'), ctx.node(), pathname=abs) |
|
566 | 566 | data = ctx[abs].data() |
|
567 | 567 | if opts.get('decode'): |
|
568 | 568 | data = repo.wwritedata(abs, data) |
|
569 | 569 | fp.write(data) |
|
570 | 570 | err = 0 |
|
571 | 571 | return err |
|
572 | 572 | |
|
573 | 573 | def clone(ui, source, dest=None, **opts): |
|
574 | 574 | """make a copy of an existing repository |
|
575 | 575 | |
|
576 | 576 | Create a copy of an existing repository in a new directory. |
|
577 | 577 | |
|
578 | 578 | If no destination directory name is specified, it defaults to the basename |
|
579 | 579 | of the source. |
|
580 | 580 | |
|
581 | 581 | The location of the source is added to the new repository's .hg/hgrc file, |
|
582 | 582 | as the default to be used for future pulls. |
|
583 | 583 | |
|
584 | 584 | If you use the -r/--rev option to clone up to a specific revision, no |
|
585 | 585 | subsequent revisions (including subsequent tags) will be present in the |
|
586 | 586 | cloned repository. This option implies --pull, even on local repositories. |
|
587 | 587 | |
|
588 | 588 | By default, clone will check out the head of the 'default' branch. If the |
|
589 | 589 | -U/--noupdate option is used, the new clone will contain only a repository |
|
590 | 590 | (.hg) and no working copy (the working copy parent is the null revision). |
|
591 | 591 | |
|
592 | 592 | See 'hg help urls' for valid source format details. |
|
593 | 593 | |
|
594 | 594 | It is possible to specify an ssh:// URL as the destination, but no |
|
595 | 595 | .hg/hgrc and working directory will be created on the remote side. Please |
|
596 | 596 | see 'hg help urls' for important details about ssh:// URLs. |
|
597 | 597 | |
|
598 | 598 | For efficiency, hardlinks are used for cloning whenever the source and |
|
599 | 599 | destination are on the same filesystem (note this applies only to the |
|
600 | 600 | repository data, not to the checked out files). Some filesystems, such as |
|
601 | 601 | AFS, implement hardlinking incorrectly, but do not report errors. In these |
|
602 | 602 | cases, use the --pull option to avoid hardlinking. |
|
603 | 603 | |
|
604 | 604 | In some cases, you can clone repositories and checked out files using full |
|
605 | 605 | hardlinks with :: |
|
606 | 606 | |
|
607 | 607 | $ cp -al REPO REPOCLONE |
|
608 | 608 | |
|
609 | 609 | This is the fastest way to clone, but it is not always safe. The operation |
|
610 | 610 | is not atomic (making sure REPO is not modified during the operation is up |
|
611 | 611 | to you) and you have to make sure your editor breaks hardlinks (Emacs and |
|
612 | 612 | most Linux Kernel tools do so). Also, this is not compatible with certain |
|
613 | 613 | extensions that place their metadata under the .hg directory, such as mq. |
|
614 | 614 | """ |
|
615 | 615 | hg.clone(cmdutil.remoteui(ui, opts), source, dest, |
|
616 | 616 | pull=opts.get('pull'), |
|
617 | 617 | stream=opts.get('uncompressed'), |
|
618 | 618 | rev=opts.get('rev'), |
|
619 | 619 | update=not opts.get('noupdate')) |
|
620 | 620 | |
|
621 | 621 | def commit(ui, repo, *pats, **opts): |
|
622 | 622 | """commit the specified files or all outstanding changes |
|
623 | 623 | |
|
624 | 624 | Commit changes to the given files into the repository. Unlike a |
|
625 | 625 | centralized RCS, this operation is a local operation. See hg push for a |
|
626 | 626 | way to actively distribute your changes. |
|
627 | 627 | |
|
628 | 628 | If a list of files is omitted, all changes reported by "hg status" will be |
|
629 | 629 | committed. |
|
630 | 630 | |
|
631 | 631 | If you are committing the result of a merge, do not provide any filenames |
|
632 | 632 | or -I/-X filters. |
|
633 | 633 | |
|
634 | 634 | If no commit message is specified, the configured editor is started to |
|
635 | 635 | prompt you for a message. |
|
636 | 636 | |
|
637 | 637 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
638 | 638 | """ |
|
639 | 639 | extra = {} |
|
640 | 640 | if opts.get('close_branch'): |
|
641 | 641 | extra['close'] = 1 |
|
642 | 642 | e = cmdutil.commiteditor |
|
643 | 643 | if opts.get('force_editor'): |
|
644 | 644 | e = cmdutil.commitforceeditor |
|
645 | 645 | |
|
646 | 646 | def commitfunc(ui, repo, message, match, opts): |
|
647 | 647 | return repo.commit(message, opts.get('user'), opts.get('date'), match, |
|
648 | 648 | editor=e, extra=extra) |
|
649 | 649 | |
|
650 | 650 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
651 | 651 | if not node: |
|
652 | 652 | ui.status(_("nothing changed\n")) |
|
653 | 653 | return |
|
654 | 654 | cl = repo.changelog |
|
655 | 655 | rev = cl.rev(node) |
|
656 | 656 | parents = cl.parentrevs(rev) |
|
657 | 657 | if rev - 1 in parents: |
|
658 | 658 | # one of the parents was the old tip |
|
659 | 659 | pass |
|
660 | 660 | elif (parents == (nullrev, nullrev) or |
|
661 | 661 | len(cl.heads(cl.node(parents[0]))) > 1 and |
|
662 | 662 | (parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)): |
|
663 | 663 | ui.status(_('created new head\n')) |
|
664 | 664 | |
|
665 | 665 | if ui.debugflag: |
|
666 | ui.write(_('committed changeset %d:%s\n') % (rev,hex(node))) | |
|
666 | ui.write(_('committed changeset %d:%s\n') % (rev, hex(node))) | |
|
667 | 667 | elif ui.verbose: |
|
668 | ui.write(_('committed changeset %d:%s\n') % (rev,short(node))) | |
|
668 | ui.write(_('committed changeset %d:%s\n') % (rev, short(node))) | |
|
669 | 669 | |
|
670 | 670 | def copy(ui, repo, *pats, **opts): |
|
671 | 671 | """mark files as copied for the next commit |
|
672 | 672 | |
|
673 | 673 | Mark dest as having copies of source files. If dest is a directory, copies |
|
674 | 674 | are put in that directory. If dest is a file, the source must be a single |
|
675 | 675 | file. |
|
676 | 676 | |
|
677 | 677 | By default, this command copies the contents of files as they exist in the |
|
678 | 678 | working directory. If invoked with -A/--after, the operation is recorded, |
|
679 | 679 | but no copying is performed. |
|
680 | 680 | |
|
681 | 681 | This command takes effect with the next commit. To undo a copy before |
|
682 | 682 | that, see hg revert. |
|
683 | 683 | """ |
|
684 | 684 | wlock = repo.wlock(False) |
|
685 | 685 | try: |
|
686 | 686 | return cmdutil.copy(ui, repo, pats, opts) |
|
687 | 687 | finally: |
|
688 | 688 | wlock.release() |
|
689 | 689 | |
|
690 | 690 | def debugancestor(ui, repo, *args): |
|
691 | 691 | """find the ancestor revision of two revisions in a given index""" |
|
692 | 692 | if len(args) == 3: |
|
693 | 693 | index, rev1, rev2 = args |
|
694 | 694 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index) |
|
695 | 695 | lookup = r.lookup |
|
696 | 696 | elif len(args) == 2: |
|
697 | 697 | if not repo: |
|
698 | 698 | raise util.Abort(_("There is no Mercurial repository here " |
|
699 | 699 | "(.hg not found)")) |
|
700 | 700 | rev1, rev2 = args |
|
701 | 701 | r = repo.changelog |
|
702 | 702 | lookup = repo.lookup |
|
703 | 703 | else: |
|
704 | 704 | raise util.Abort(_('either two or three arguments required')) |
|
705 | 705 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
706 | 706 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
707 | 707 | |
|
708 | 708 | def debugcommands(ui, cmd='', *args): |
|
709 | 709 | for cmd, vals in sorted(table.iteritems()): |
|
710 | 710 | cmd = cmd.split('|')[0].strip('^') |
|
711 | 711 | opts = ', '.join([i[1] for i in vals[1]]) |
|
712 | 712 | ui.write('%s: %s\n' % (cmd, opts)) |
|
713 | 713 | |
|
714 | 714 | def debugcomplete(ui, cmd='', **opts): |
|
715 | 715 | """returns the completion list associated with the given command""" |
|
716 | 716 | |
|
717 | 717 | if opts.get('options'): |
|
718 | 718 | options = [] |
|
719 | 719 | otables = [globalopts] |
|
720 | 720 | if cmd: |
|
721 | 721 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
722 | 722 | otables.append(entry[1]) |
|
723 | 723 | for t in otables: |
|
724 | 724 | for o in t: |
|
725 | 725 | if o[0]: |
|
726 | 726 | options.append('-%s' % o[0]) |
|
727 | 727 | options.append('--%s' % o[1]) |
|
728 | 728 | ui.write("%s\n" % "\n".join(options)) |
|
729 | 729 | return |
|
730 | 730 | |
|
731 | 731 | cmdlist = cmdutil.findpossible(cmd, table) |
|
732 | 732 | if ui.verbose: |
|
733 | 733 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
734 | 734 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
735 | 735 | |
|
736 | 736 | def debugfsinfo(ui, path = "."): |
|
737 | 737 | open('.debugfsinfo', 'w').write('') |
|
738 | 738 | ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) |
|
739 | 739 | ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) |
|
740 | 740 | ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') |
|
741 | 741 | and 'yes' or 'no')) |
|
742 | 742 | os.unlink('.debugfsinfo') |
|
743 | 743 | |
|
744 | 744 | def debugrebuildstate(ui, repo, rev="tip"): |
|
745 | 745 | """rebuild the dirstate as it would look like for the given revision""" |
|
746 | 746 | ctx = repo[rev] |
|
747 | 747 | wlock = repo.wlock() |
|
748 | 748 | try: |
|
749 | 749 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
750 | 750 | finally: |
|
751 | 751 | wlock.release() |
|
752 | 752 | |
|
753 | 753 | def debugcheckstate(ui, repo): |
|
754 | 754 | """validate the correctness of the current dirstate""" |
|
755 | 755 | parent1, parent2 = repo.dirstate.parents() |
|
756 | 756 | m1 = repo[parent1].manifest() |
|
757 | 757 | m2 = repo[parent2].manifest() |
|
758 | 758 | errors = 0 |
|
759 | 759 | for f in repo.dirstate: |
|
760 | 760 | state = repo.dirstate[f] |
|
761 | 761 | if state in "nr" and f not in m1: |
|
762 | 762 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
763 | 763 | errors += 1 |
|
764 | 764 | if state in "a" and f in m1: |
|
765 | 765 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
766 | 766 | errors += 1 |
|
767 | 767 | if state in "m" and f not in m1 and f not in m2: |
|
768 | 768 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
769 | 769 | (f, state)) |
|
770 | 770 | errors += 1 |
|
771 | 771 | for f in m1: |
|
772 | 772 | state = repo.dirstate[f] |
|
773 | 773 | if state not in "nrm": |
|
774 | 774 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
775 | 775 | errors += 1 |
|
776 | 776 | if errors: |
|
777 | 777 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
778 | 778 | raise util.Abort(error) |
|
779 | 779 | |
|
780 | 780 | def showconfig(ui, repo, *values, **opts): |
|
781 | 781 | """show combined config settings from all hgrc files |
|
782 | 782 | |
|
783 | 783 | With no arguments, print names and values of all config items. |
|
784 | 784 | |
|
785 | 785 | With one argument of the form section.name, print just the value of that |
|
786 | 786 | config item. |
|
787 | 787 | |
|
788 | 788 | With multiple arguments, print names and values of all config items with |
|
789 | 789 | matching section names. |
|
790 | 790 | |
|
791 | 791 | With --debug, the source (filename and line number) is printed for each |
|
792 | 792 | config item. |
|
793 | 793 | """ |
|
794 | 794 | |
|
795 | 795 | untrusted = bool(opts.get('untrusted')) |
|
796 | 796 | if values: |
|
797 | 797 | if len([v for v in values if '.' in v]) > 1: |
|
798 | 798 | raise util.Abort(_('only one config item permitted')) |
|
799 | 799 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
800 | 800 | sectname = section + '.' + name |
|
801 | 801 | if values: |
|
802 | 802 | for v in values: |
|
803 | 803 | if v == section: |
|
804 | 804 | ui.debug('%s: ' % |
|
805 | 805 | ui.configsource(section, name, untrusted)) |
|
806 | 806 | ui.write('%s=%s\n' % (sectname, value)) |
|
807 | 807 | elif v == sectname: |
|
808 | 808 | ui.debug('%s: ' % |
|
809 | 809 | ui.configsource(section, name, untrusted)) |
|
810 | 810 | ui.write(value, '\n') |
|
811 | 811 | else: |
|
812 | 812 | ui.debug('%s: ' % |
|
813 | 813 | ui.configsource(section, name, untrusted)) |
|
814 | 814 | ui.write('%s=%s\n' % (sectname, value)) |
|
815 | 815 | |
|
816 | 816 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
817 | 817 | """manually set the parents of the current working directory |
|
818 | 818 | |
|
819 | 819 | This is useful for writing repository conversion tools, but should be used |
|
820 | 820 | with care. |
|
821 | 821 | """ |
|
822 | 822 | |
|
823 | 823 | if not rev2: |
|
824 | 824 | rev2 = hex(nullid) |
|
825 | 825 | |
|
826 | 826 | wlock = repo.wlock() |
|
827 | 827 | try: |
|
828 | 828 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
829 | 829 | finally: |
|
830 | 830 | wlock.release() |
|
831 | 831 | |
|
832 | 832 | def debugstate(ui, repo, nodates=None): |
|
833 | 833 | """show the contents of the current dirstate""" |
|
834 | 834 | timestr = "" |
|
835 | 835 | showdate = not nodates |
|
836 | 836 | for file_, ent in sorted(repo.dirstate._map.iteritems()): |
|
837 | 837 | if showdate: |
|
838 | 838 | if ent[3] == -1: |
|
839 | 839 | # Pad or slice to locale representation |
|
840 | 840 | locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(0))) |
|
841 | 841 | timestr = 'unset' |
|
842 | 842 | timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr)) |
|
843 | 843 | else: |
|
844 | 844 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(ent[3])) |
|
845 | 845 | if ent[1] & 020000: |
|
846 | 846 | mode = 'lnk' |
|
847 | 847 | else: |
|
848 | 848 | mode = '%3o' % (ent[1] & 0777) |
|
849 | 849 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
850 | 850 | for f in repo.dirstate.copies(): |
|
851 | 851 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
852 | 852 | |
|
853 | 853 | def debugsub(ui, repo, rev=None): |
|
854 | 854 | if rev == '': |
|
855 | 855 | rev = None |
|
856 | 856 | for k,v in sorted(repo[rev].substate.items()): |
|
857 | 857 | ui.write('path %s\n' % k) |
|
858 | 858 | ui.write(' source %s\n' % v[0]) |
|
859 | 859 | ui.write(' revision %s\n' % v[1]) |
|
860 | 860 | |
|
861 | 861 | def debugdata(ui, file_, rev): |
|
862 | 862 | """dump the contents of a data file revision""" |
|
863 | 863 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i") |
|
864 | 864 | try: |
|
865 | 865 | ui.write(r.revision(r.lookup(rev))) |
|
866 | 866 | except KeyError: |
|
867 | 867 | raise util.Abort(_('invalid revision identifier %s') % rev) |
|
868 | 868 | |
|
869 | 869 | def debugdate(ui, date, range=None, **opts): |
|
870 | 870 | """parse and display a date""" |
|
871 | 871 | if opts["extended"]: |
|
872 | 872 | d = util.parsedate(date, util.extendeddateformats) |
|
873 | 873 | else: |
|
874 | 874 | d = util.parsedate(date) |
|
875 | 875 | ui.write("internal: %s %s\n" % d) |
|
876 | 876 | ui.write("standard: %s\n" % util.datestr(d)) |
|
877 | 877 | if range: |
|
878 | 878 | m = util.matchdate(range) |
|
879 | 879 | ui.write("match: %s\n" % m(d[0])) |
|
880 | 880 | |
|
881 | 881 | def debugindex(ui, file_): |
|
882 | 882 | """dump the contents of an index file""" |
|
883 | 883 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) |
|
884 | 884 | ui.write(" rev offset length base linkrev" |
|
885 | 885 | " nodeid p1 p2\n") |
|
886 | 886 | for i in r: |
|
887 | 887 | node = r.node(i) |
|
888 | 888 | try: |
|
889 | 889 | pp = r.parents(node) |
|
890 | 890 | except: |
|
891 | 891 | pp = [nullid, nullid] |
|
892 | 892 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
893 | 893 | i, r.start(i), r.length(i), r.base(i), r.linkrev(i), |
|
894 | 894 | short(node), short(pp[0]), short(pp[1]))) |
|
895 | 895 | |
|
896 | 896 | def debugindexdot(ui, file_): |
|
897 | 897 | """dump an index DAG as a graphviz dot file""" |
|
898 | 898 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) |
|
899 | 899 | ui.write("digraph G {\n") |
|
900 | 900 | for i in r: |
|
901 | 901 | node = r.node(i) |
|
902 | 902 | pp = r.parents(node) |
|
903 | 903 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
904 | 904 | if pp[1] != nullid: |
|
905 | 905 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
906 | 906 | ui.write("}\n") |
|
907 | 907 | |
|
908 | 908 | def debuginstall(ui): |
|
909 | 909 | '''test Mercurial installation''' |
|
910 | 910 | |
|
911 | 911 | def writetemp(contents): |
|
912 | 912 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
913 | 913 | f = os.fdopen(fd, "wb") |
|
914 | 914 | f.write(contents) |
|
915 | 915 | f.close() |
|
916 | 916 | return name |
|
917 | 917 | |
|
918 | 918 | problems = 0 |
|
919 | 919 | |
|
920 | 920 | # encoding |
|
921 | 921 | ui.status(_("Checking encoding (%s)...\n") % encoding.encoding) |
|
922 | 922 | try: |
|
923 | 923 | encoding.fromlocal("test") |
|
924 | 924 | except util.Abort, inst: |
|
925 | 925 | ui.write(" %s\n" % inst) |
|
926 | 926 | ui.write(_(" (check that your locale is properly set)\n")) |
|
927 | 927 | problems += 1 |
|
928 | 928 | |
|
929 | 929 | # compiled modules |
|
930 | 930 | ui.status(_("Checking extensions...\n")) |
|
931 | 931 | try: |
|
932 | 932 | import bdiff, mpatch, base85 |
|
933 | 933 | except Exception, inst: |
|
934 | 934 | ui.write(" %s\n" % inst) |
|
935 | 935 | ui.write(_(" One or more extensions could not be found")) |
|
936 | 936 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
937 | 937 | problems += 1 |
|
938 | 938 | |
|
939 | 939 | # templates |
|
940 | 940 | ui.status(_("Checking templates...\n")) |
|
941 | 941 | try: |
|
942 | 942 | import templater |
|
943 | 943 | templater.templater(templater.templatepath("map-cmdline.default")) |
|
944 | 944 | except Exception, inst: |
|
945 | 945 | ui.write(" %s\n" % inst) |
|
946 | 946 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
947 | 947 | problems += 1 |
|
948 | 948 | |
|
949 | 949 | # patch |
|
950 | 950 | ui.status(_("Checking patch...\n")) |
|
951 | 951 | patchproblems = 0 |
|
952 | 952 | a = "1\n2\n3\n4\n" |
|
953 | 953 | b = "1\n2\n3\ninsert\n4\n" |
|
954 | 954 | fa = writetemp(a) |
|
955 | 955 | d = mdiff.unidiff(a, None, b, None, os.path.basename(fa), |
|
956 | 956 | os.path.basename(fa)) |
|
957 | 957 | fd = writetemp(d) |
|
958 | 958 | |
|
959 | 959 | files = {} |
|
960 | 960 | try: |
|
961 | 961 | patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files) |
|
962 | 962 | except util.Abort, e: |
|
963 | 963 | ui.write(_(" patch call failed:\n")) |
|
964 | 964 | ui.write(" " + str(e) + "\n") |
|
965 | 965 | patchproblems += 1 |
|
966 | 966 | else: |
|
967 | 967 | if list(files) != [os.path.basename(fa)]: |
|
968 | 968 | ui.write(_(" unexpected patch output!\n")) |
|
969 | 969 | patchproblems += 1 |
|
970 | 970 | a = open(fa).read() |
|
971 | 971 | if a != b: |
|
972 | 972 | ui.write(_(" patch test failed!\n")) |
|
973 | 973 | patchproblems += 1 |
|
974 | 974 | |
|
975 | 975 | if patchproblems: |
|
976 | 976 | if ui.config('ui', 'patch'): |
|
977 | 977 | ui.write(_(" (Current patch tool may be incompatible with patch," |
|
978 | 978 | " or misconfigured. Please check your .hgrc file)\n")) |
|
979 | 979 | else: |
|
980 | 980 | ui.write(_(" Internal patcher failure, please report this error" |
|
981 | 981 | " to http://mercurial.selenic.com/bts/\n")) |
|
982 | 982 | problems += patchproblems |
|
983 | 983 | |
|
984 | 984 | os.unlink(fa) |
|
985 | 985 | os.unlink(fd) |
|
986 | 986 | |
|
987 | 987 | # editor |
|
988 | 988 | ui.status(_("Checking commit editor...\n")) |
|
989 | 989 | editor = ui.geteditor() |
|
990 | 990 | cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0]) |
|
991 | 991 | if not cmdpath: |
|
992 | 992 | if editor == 'vi': |
|
993 | 993 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
994 | 994 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) |
|
995 | 995 | else: |
|
996 | 996 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
997 | 997 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) |
|
998 | 998 | problems += 1 |
|
999 | 999 | |
|
1000 | 1000 | # check username |
|
1001 | 1001 | ui.status(_("Checking username...\n")) |
|
1002 | 1002 | user = os.environ.get("HGUSER") |
|
1003 | 1003 | if user is None: |
|
1004 | 1004 | user = ui.config("ui", "username") |
|
1005 | 1005 | if user is None: |
|
1006 | 1006 | user = os.environ.get("EMAIL") |
|
1007 | 1007 | if not user: |
|
1008 | 1008 | ui.warn(" ") |
|
1009 | 1009 | ui.username() |
|
1010 | 1010 | ui.write(_(" (specify a username in your .hgrc file)\n")) |
|
1011 | 1011 | |
|
1012 | 1012 | if not problems: |
|
1013 | 1013 | ui.status(_("No problems detected\n")) |
|
1014 | 1014 | else: |
|
1015 | 1015 | ui.write(_("%s problems detected," |
|
1016 | 1016 | " please check your install!\n") % problems) |
|
1017 | 1017 | |
|
1018 | 1018 | return problems |
|
1019 | 1019 | |
|
1020 | 1020 | def debugrename(ui, repo, file1, *pats, **opts): |
|
1021 | 1021 | """dump rename information""" |
|
1022 | 1022 | |
|
1023 | 1023 | ctx = repo[opts.get('rev')] |
|
1024 | 1024 | m = cmdutil.match(repo, (file1,) + pats, opts) |
|
1025 | 1025 | for abs in ctx.walk(m): |
|
1026 | 1026 | fctx = ctx[abs] |
|
1027 | 1027 | o = fctx.filelog().renamed(fctx.filenode()) |
|
1028 | 1028 | rel = m.rel(abs) |
|
1029 | 1029 | if o: |
|
1030 | 1030 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
1031 | 1031 | else: |
|
1032 | 1032 | ui.write(_("%s not renamed\n") % rel) |
|
1033 | 1033 | |
|
1034 | 1034 | def debugwalk(ui, repo, *pats, **opts): |
|
1035 | 1035 | """show how files match on given patterns""" |
|
1036 | 1036 | m = cmdutil.match(repo, pats, opts) |
|
1037 | 1037 | items = list(repo.walk(m)) |
|
1038 | 1038 | if not items: |
|
1039 | 1039 | return |
|
1040 | 1040 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
1041 | 1041 | max([len(abs) for abs in items]), |
|
1042 | 1042 | max([len(m.rel(abs)) for abs in items])) |
|
1043 | 1043 | for abs in items: |
|
1044 | 1044 | line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '') |
|
1045 | 1045 | ui.write("%s\n" % line.rstrip()) |
|
1046 | 1046 | |
|
1047 | 1047 | def diff(ui, repo, *pats, **opts): |
|
1048 | 1048 | """diff repository (or selected files) |
|
1049 | 1049 | |
|
1050 | 1050 | Show differences between revisions for the specified files. |
|
1051 | 1051 | |
|
1052 | 1052 | Differences between files are shown using the unified diff format. |
|
1053 | 1053 | |
|
1054 | 1054 | NOTE: diff may generate unexpected results for merges, as it will default |
|
1055 | 1055 | to comparing against the working directory's first parent changeset if no |
|
1056 | 1056 | revisions are specified. |
|
1057 | 1057 | |
|
1058 | 1058 | When two revision arguments are given, then changes are shown between |
|
1059 | 1059 | those revisions. If only one revision is specified then that revision is |
|
1060 | 1060 | compared to the working directory, and, when no revisions are specified, |
|
1061 | 1061 | the working directory files are compared to its parent. |
|
1062 | 1062 | |
|
1063 | 1063 | Without the -a/--text option, diff will avoid generating diffs of files it |
|
1064 | 1064 | detects as binary. With -a, diff will generate a diff anyway, probably |
|
1065 | 1065 | with undesirable results. |
|
1066 | 1066 | |
|
1067 | 1067 | Use the -g/--git option to generate diffs in the git extended diff format. |
|
1068 | 1068 | For more information, read 'hg help diffs'. |
|
1069 | 1069 | """ |
|
1070 | 1070 | |
|
1071 | 1071 | revs = opts.get('rev') |
|
1072 | 1072 | change = opts.get('change') |
|
1073 | 1073 | |
|
1074 | 1074 | if revs and change: |
|
1075 | 1075 | msg = _('cannot specify --rev and --change at the same time') |
|
1076 | 1076 | raise util.Abort(msg) |
|
1077 | 1077 | elif change: |
|
1078 | 1078 | node2 = repo.lookup(change) |
|
1079 | 1079 | node1 = repo[node2].parents()[0].node() |
|
1080 | 1080 | else: |
|
1081 | 1081 | node1, node2 = cmdutil.revpair(repo, revs) |
|
1082 | 1082 | |
|
1083 | 1083 | m = cmdutil.match(repo, pats, opts) |
|
1084 | 1084 | it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts)) |
|
1085 | 1085 | for chunk in it: |
|
1086 | 1086 | ui.write(chunk) |
|
1087 | 1087 | |
|
1088 | 1088 | def export(ui, repo, *changesets, **opts): |
|
1089 | 1089 | """dump the header and diffs for one or more changesets |
|
1090 | 1090 | |
|
1091 | 1091 | Print the changeset header and diffs for one or more revisions. |
|
1092 | 1092 | |
|
1093 | 1093 | The information shown in the changeset header is: author, changeset hash, |
|
1094 | 1094 | parent(s) and commit comment. |
|
1095 | 1095 | |
|
1096 | 1096 | NOTE: export may generate unexpected diff output for merge changesets, as |
|
1097 | 1097 | it will compare the merge changeset against its first parent only. |
|
1098 | 1098 | |
|
1099 | 1099 | Output may be to a file, in which case the name of the file is given using |
|
1100 | 1100 | a format string. The formatting rules are as follows:: |
|
1101 | 1101 | |
|
1102 | 1102 | %% literal "%" character |
|
1103 | 1103 | %H changeset hash (40 bytes of hexadecimal) |
|
1104 | 1104 | %N number of patches being generated |
|
1105 | 1105 | %R changeset revision number |
|
1106 | 1106 | %b basename of the exporting repository |
|
1107 | 1107 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1108 | 1108 | %n zero-padded sequence number, starting at 1 |
|
1109 | 1109 | %r zero-padded changeset revision number |
|
1110 | 1110 | |
|
1111 | 1111 | Without the -a/--text option, export will avoid generating diffs of files |
|
1112 | 1112 | it detects as binary. With -a, export will generate a diff anyway, |
|
1113 | 1113 | probably with undesirable results. |
|
1114 | 1114 | |
|
1115 | 1115 | Use the -g/--git option to generate diffs in the git extended diff format. |
|
1116 | 1116 | See 'hg help diffs' for more information. |
|
1117 | 1117 | |
|
1118 | 1118 | With the --switch-parent option, the diff will be against the second |
|
1119 | 1119 | parent. It can be useful to review a merge. |
|
1120 | 1120 | """ |
|
1121 | 1121 | if not changesets: |
|
1122 | 1122 | raise util.Abort(_("export requires at least one changeset")) |
|
1123 | 1123 | revs = cmdutil.revrange(repo, changesets) |
|
1124 | 1124 | if len(revs) > 1: |
|
1125 | 1125 | ui.note(_('exporting patches:\n')) |
|
1126 | 1126 | else: |
|
1127 | 1127 | ui.note(_('exporting patch:\n')) |
|
1128 | 1128 | patch.export(repo, revs, template=opts.get('output'), |
|
1129 | 1129 | switch_parent=opts.get('switch_parent'), |
|
1130 | 1130 | opts=patch.diffopts(ui, opts)) |
|
1131 | 1131 | |
|
1132 | 1132 | def forget(ui, repo, *pats, **opts): |
|
1133 | 1133 | """forget the specified files on the next commit |
|
1134 | 1134 | |
|
1135 | 1135 | Mark the specified files so they will no longer be tracked after the next |
|
1136 | 1136 | commit. |
|
1137 | 1137 | |
|
1138 | 1138 | This only removes files from the current branch, not from the entire |
|
1139 | 1139 | project history, and it does not delete them from the working directory. |
|
1140 | 1140 | |
|
1141 | 1141 | To undo a forget before the next commit, see hg add. |
|
1142 | 1142 | """ |
|
1143 | 1143 | |
|
1144 | 1144 | if not pats: |
|
1145 | 1145 | raise util.Abort(_('no files specified')) |
|
1146 | 1146 | |
|
1147 | 1147 | m = cmdutil.match(repo, pats, opts) |
|
1148 | 1148 | s = repo.status(match=m, clean=True) |
|
1149 | 1149 | forget = sorted(s[0] + s[1] + s[3] + s[6]) |
|
1150 | 1150 | |
|
1151 | 1151 | for f in m.files(): |
|
1152 | 1152 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
1153 | 1153 | ui.warn(_('not removing %s: file is already untracked\n') |
|
1154 | 1154 | % m.rel(f)) |
|
1155 | 1155 | |
|
1156 | 1156 | for f in forget: |
|
1157 | 1157 | if ui.verbose or not m.exact(f): |
|
1158 | 1158 | ui.status(_('removing %s\n') % m.rel(f)) |
|
1159 | 1159 | |
|
1160 | 1160 | repo.remove(forget, unlink=False) |
|
1161 | 1161 | |
|
1162 | 1162 | def grep(ui, repo, pattern, *pats, **opts): |
|
1163 | 1163 | """search for a pattern in specified files and revisions |
|
1164 | 1164 | |
|
1165 | 1165 | Search revisions of files for a regular expression. |
|
1166 | 1166 | |
|
1167 | 1167 | This command behaves differently than Unix grep. It only accepts |
|
1168 | 1168 | Python/Perl regexps. It searches repository history, not the working |
|
1169 | 1169 | directory. It always prints the revision number in which a match appears. |
|
1170 | 1170 | |
|
1171 | 1171 | By default, grep only prints output for the first revision of a file in |
|
1172 | 1172 | which it finds a match. To get it to print every revision that contains a |
|
1173 | 1173 | change in match status ("-" for a match that becomes a non-match, or "+" |
|
1174 | 1174 | for a non-match that becomes a match), use the --all flag. |
|
1175 | 1175 | """ |
|
1176 | 1176 | reflags = 0 |
|
1177 | 1177 | if opts.get('ignore_case'): |
|
1178 | 1178 | reflags |= re.I |
|
1179 | 1179 | try: |
|
1180 | 1180 | regexp = re.compile(pattern, reflags) |
|
1181 | 1181 | except Exception, inst: |
|
1182 | 1182 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
1183 | 1183 | return None |
|
1184 | 1184 | sep, eol = ':', '\n' |
|
1185 | 1185 | if opts.get('print0'): |
|
1186 | 1186 | sep = eol = '\0' |
|
1187 | 1187 | |
|
1188 | 1188 | getfile = util.lrucachefunc(repo.file) |
|
1189 | 1189 | |
|
1190 | 1190 | def matchlines(body): |
|
1191 | 1191 | begin = 0 |
|
1192 | 1192 | linenum = 0 |
|
1193 | 1193 | while True: |
|
1194 | 1194 | match = regexp.search(body, begin) |
|
1195 | 1195 | if not match: |
|
1196 | 1196 | break |
|
1197 | 1197 | mstart, mend = match.span() |
|
1198 | 1198 | linenum += body.count('\n', begin, mstart) + 1 |
|
1199 | 1199 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1200 | 1200 | begin = body.find('\n', mend) + 1 or len(body) |
|
1201 | 1201 | lend = begin - 1 |
|
1202 | 1202 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1203 | 1203 | |
|
1204 | 1204 | class linestate(object): |
|
1205 | 1205 | def __init__(self, line, linenum, colstart, colend): |
|
1206 | 1206 | self.line = line |
|
1207 | 1207 | self.linenum = linenum |
|
1208 | 1208 | self.colstart = colstart |
|
1209 | 1209 | self.colend = colend |
|
1210 | 1210 | |
|
1211 | 1211 | def __hash__(self): |
|
1212 | 1212 | return hash((self.linenum, self.line)) |
|
1213 | 1213 | |
|
1214 | 1214 | def __eq__(self, other): |
|
1215 | 1215 | return self.line == other.line |
|
1216 | 1216 | |
|
1217 | 1217 | matches = {} |
|
1218 | 1218 | copies = {} |
|
1219 | 1219 | def grepbody(fn, rev, body): |
|
1220 | 1220 | matches[rev].setdefault(fn, []) |
|
1221 | 1221 | m = matches[rev][fn] |
|
1222 | 1222 | for lnum, cstart, cend, line in matchlines(body): |
|
1223 | 1223 | s = linestate(line, lnum, cstart, cend) |
|
1224 | 1224 | m.append(s) |
|
1225 | 1225 | |
|
1226 | 1226 | def difflinestates(a, b): |
|
1227 | 1227 | sm = difflib.SequenceMatcher(None, a, b) |
|
1228 | 1228 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
1229 | 1229 | if tag == 'insert': |
|
1230 | 1230 | for i in xrange(blo, bhi): |
|
1231 | 1231 | yield ('+', b[i]) |
|
1232 | 1232 | elif tag == 'delete': |
|
1233 | 1233 | for i in xrange(alo, ahi): |
|
1234 | 1234 | yield ('-', a[i]) |
|
1235 | 1235 | elif tag == 'replace': |
|
1236 | 1236 | for i in xrange(alo, ahi): |
|
1237 | 1237 | yield ('-', a[i]) |
|
1238 | 1238 | for i in xrange(blo, bhi): |
|
1239 | 1239 | yield ('+', b[i]) |
|
1240 | 1240 | |
|
1241 | 1241 | def display(fn, r, pstates, states): |
|
1242 | 1242 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
1243 | 1243 | found = False |
|
1244 | 1244 | filerevmatches = {} |
|
1245 | 1245 | if opts.get('all'): |
|
1246 | 1246 | iter = difflinestates(pstates, states) |
|
1247 | 1247 | else: |
|
1248 | 1248 | iter = [('', l) for l in states] |
|
1249 | 1249 | for change, l in iter: |
|
1250 | 1250 | cols = [fn, str(r)] |
|
1251 | 1251 | if opts.get('line_number'): |
|
1252 | 1252 | cols.append(str(l.linenum)) |
|
1253 | 1253 | if opts.get('all'): |
|
1254 | 1254 | cols.append(change) |
|
1255 | 1255 | if opts.get('user'): |
|
1256 | 1256 | cols.append(ui.shortuser(get(r)[1])) |
|
1257 | 1257 | if opts.get('date'): |
|
1258 | 1258 | cols.append(datefunc(get(r)[2])) |
|
1259 | 1259 | if opts.get('files_with_matches'): |
|
1260 | 1260 | c = (fn, r) |
|
1261 | 1261 | if c in filerevmatches: |
|
1262 | 1262 | continue |
|
1263 | 1263 | filerevmatches[c] = 1 |
|
1264 | 1264 | else: |
|
1265 | 1265 | cols.append(l.line) |
|
1266 | 1266 | ui.write(sep.join(cols), eol) |
|
1267 | 1267 | found = True |
|
1268 | 1268 | return found |
|
1269 | 1269 | |
|
1270 | 1270 | skip = {} |
|
1271 | 1271 | revfiles = {} |
|
1272 | 1272 | get = util.cachefunc(lambda r: repo[r].changeset()) |
|
1273 | 1273 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) |
|
1274 | 1274 | found = False |
|
1275 | 1275 | follow = opts.get('follow') |
|
1276 | 1276 | for st, rev, fns in changeiter: |
|
1277 | 1277 | if st == 'window': |
|
1278 | 1278 | matches.clear() |
|
1279 | 1279 | revfiles.clear() |
|
1280 | 1280 | elif st == 'add': |
|
1281 | 1281 | ctx = repo[rev] |
|
1282 | 1282 | pctx = ctx.parents()[0] |
|
1283 | 1283 | parent = pctx.rev() |
|
1284 | 1284 | matches.setdefault(rev, {}) |
|
1285 | 1285 | matches.setdefault(parent, {}) |
|
1286 | 1286 | files = revfiles.setdefault(rev, []) |
|
1287 | 1287 | for fn in fns: |
|
1288 | 1288 | flog = getfile(fn) |
|
1289 | 1289 | try: |
|
1290 | 1290 | fnode = ctx.filenode(fn) |
|
1291 | 1291 | except error.LookupError: |
|
1292 | 1292 | continue |
|
1293 | 1293 | |
|
1294 | 1294 | copied = flog.renamed(fnode) |
|
1295 | 1295 | copy = follow and copied and copied[0] |
|
1296 | 1296 | if copy: |
|
1297 | 1297 | copies.setdefault(rev, {})[fn] = copy |
|
1298 | 1298 | if fn in skip: |
|
1299 | 1299 | if copy: |
|
1300 | 1300 | skip[copy] = True |
|
1301 | 1301 | continue |
|
1302 | 1302 | files.append(fn) |
|
1303 | 1303 | |
|
1304 | 1304 | if not matches[rev].has_key(fn): |
|
1305 | 1305 | grepbody(fn, rev, flog.read(fnode)) |
|
1306 | 1306 | |
|
1307 | 1307 | pfn = copy or fn |
|
1308 | 1308 | if not matches[parent].has_key(pfn): |
|
1309 | 1309 | try: |
|
1310 | 1310 | fnode = pctx.filenode(pfn) |
|
1311 | 1311 | grepbody(pfn, parent, flog.read(fnode)) |
|
1312 | 1312 | except error.LookupError: |
|
1313 | 1313 | pass |
|
1314 | 1314 | elif st == 'iter': |
|
1315 | 1315 | parent = repo[rev].parents()[0].rev() |
|
1316 | 1316 | for fn in sorted(revfiles.get(rev, [])): |
|
1317 | 1317 | states = matches[rev][fn] |
|
1318 | 1318 | copy = copies.get(rev, {}).get(fn) |
|
1319 | 1319 | if fn in skip: |
|
1320 | 1320 | if copy: |
|
1321 | 1321 | skip[copy] = True |
|
1322 | 1322 | continue |
|
1323 | 1323 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
1324 | 1324 | if pstates or states: |
|
1325 | 1325 | r = display(fn, rev, pstates, states) |
|
1326 | 1326 | found = found or r |
|
1327 | 1327 | if r and not opts.get('all'): |
|
1328 | 1328 | skip[fn] = True |
|
1329 | 1329 | if copy: |
|
1330 | 1330 | skip[copy] = True |
|
1331 | 1331 | |
|
1332 | 1332 | def heads(ui, repo, *branchrevs, **opts): |
|
1333 | 1333 | """show current repository heads or show branch heads |
|
1334 | 1334 | |
|
1335 | 1335 | With no arguments, show all repository head changesets. |
|
1336 | 1336 | |
|
1337 | 1337 | Repository "heads" are changesets that don't have child changesets. They |
|
1338 | 1338 | are where development generally takes place and are the usual targets for |
|
1339 | 1339 | update and merge operations. |
|
1340 | 1340 | |
|
1341 | 1341 | If one or more REV is given, the "branch heads" will be shown for the |
|
1342 | 1342 | named branch associated with that revision. The name of the branch is |
|
1343 | 1343 | called the revision's branch tag. |
|
1344 | 1344 | |
|
1345 | 1345 | Branch heads are revisions on a given named branch that do not have any |
|
1346 | 1346 | descendants on the same branch. A branch head could be a true head or it |
|
1347 | 1347 | could be the last changeset on a branch before a new branch was created. |
|
1348 | 1348 | If none of the branch heads are true heads, the branch is considered |
|
1349 | 1349 | inactive. If -c/--closed is specified, also show branch heads marked |
|
1350 | 1350 | closed (see hg commit --close-branch). |
|
1351 | 1351 | |
|
1352 | 1352 | If STARTREV is specified only those heads (or branch heads) that are |
|
1353 | 1353 | descendants of STARTREV will be displayed. |
|
1354 | 1354 | """ |
|
1355 | 1355 | if opts.get('rev'): |
|
1356 | 1356 | start = repo.lookup(opts['rev']) |
|
1357 | 1357 | else: |
|
1358 | 1358 | start = None |
|
1359 | 1359 | closed = opts.get('closed') |
|
1360 | 1360 | hideinactive, _heads = opts.get('active'), None |
|
1361 | 1361 | if not branchrevs: |
|
1362 | 1362 | # Assume we're looking repo-wide heads if no revs were specified. |
|
1363 | 1363 | heads = repo.heads(start) |
|
1364 | 1364 | else: |
|
1365 | 1365 | if hideinactive: |
|
1366 | 1366 | _heads = repo.heads(start) |
|
1367 | 1367 | heads = [] |
|
1368 | 1368 | visitedset = set() |
|
1369 | 1369 | for branchrev in branchrevs: |
|
1370 | 1370 | branch = repo[branchrev].branch() |
|
1371 | 1371 | if branch in visitedset: |
|
1372 | 1372 | continue |
|
1373 | 1373 | visitedset.add(branch) |
|
1374 | 1374 | bheads = repo.branchheads(branch, start, closed=closed) |
|
1375 | 1375 | if not bheads: |
|
1376 | 1376 | if not opts.get('rev'): |
|
1377 | 1377 | ui.warn(_("no open branch heads on branch %s\n") % branch) |
|
1378 | 1378 | elif branch != branchrev: |
|
1379 | 1379 | ui.warn(_("no changes on branch %s containing %s are " |
|
1380 | 1380 | "reachable from %s\n") |
|
1381 | 1381 | % (branch, branchrev, opts.get('rev'))) |
|
1382 | 1382 | else: |
|
1383 | 1383 | ui.warn(_("no changes on branch %s are reachable from %s\n") |
|
1384 | 1384 | % (branch, opts.get('rev'))) |
|
1385 | 1385 | if hideinactive: |
|
1386 | 1386 | bheads = [bhead for bhead in bheads if bhead in _heads] |
|
1387 | 1387 | heads.extend(bheads) |
|
1388 | 1388 | if not heads: |
|
1389 | 1389 | return 1 |
|
1390 | 1390 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
1391 | 1391 | for n in heads: |
|
1392 | 1392 | displayer.show(repo[n]) |
|
1393 | 1393 | |
|
1394 | 1394 | def help_(ui, name=None, with_version=False): |
|
1395 | 1395 | """show help for a given topic or a help overview |
|
1396 | 1396 | |
|
1397 | 1397 | With no arguments, print a list of commands with short help messages. |
|
1398 | 1398 | |
|
1399 | 1399 | Given a topic, extension, or command name, print help for that topic. |
|
1400 | 1400 | """ |
|
1401 | 1401 | option_lists = [] |
|
1402 | 1402 | textwidth = util.termwidth() - 2 |
|
1403 | 1403 | |
|
1404 | 1404 | def addglobalopts(aliases): |
|
1405 | 1405 | if ui.verbose: |
|
1406 | 1406 | option_lists.append((_("global options:"), globalopts)) |
|
1407 | 1407 | if name == 'shortlist': |
|
1408 | 1408 | option_lists.append((_('use "hg help" for the full list ' |
|
1409 | 1409 | 'of commands'), ())) |
|
1410 | 1410 | else: |
|
1411 | 1411 | if name == 'shortlist': |
|
1412 | 1412 | msg = _('use "hg help" for the full list of commands ' |
|
1413 | 1413 | 'or "hg -v" for details') |
|
1414 | 1414 | elif aliases: |
|
1415 | 1415 | msg = _('use "hg -v help%s" to show aliases and ' |
|
1416 | 1416 | 'global options') % (name and " " + name or "") |
|
1417 | 1417 | else: |
|
1418 | 1418 | msg = _('use "hg -v help %s" to show global options') % name |
|
1419 | 1419 | option_lists.append((msg, ())) |
|
1420 | 1420 | |
|
1421 | 1421 | def helpcmd(name): |
|
1422 | 1422 | if with_version: |
|
1423 | 1423 | version_(ui) |
|
1424 | 1424 | ui.write('\n') |
|
1425 | 1425 | |
|
1426 | 1426 | try: |
|
1427 | 1427 | aliases, i = cmdutil.findcmd(name, table, False) |
|
1428 | 1428 | except error.AmbiguousCommand, inst: |
|
1429 | 1429 | # py3k fix: except vars can't be used outside the scope of the |
|
1430 | 1430 | # except block, nor can be used inside a lambda. python issue4617 |
|
1431 | 1431 | prefix = inst.args[0] |
|
1432 | 1432 | select = lambda c: c.lstrip('^').startswith(prefix) |
|
1433 | 1433 | helplist(_('list of commands:\n\n'), select) |
|
1434 | 1434 | return |
|
1435 | 1435 | |
|
1436 | 1436 | # synopsis |
|
1437 | 1437 | if len(i) > 2: |
|
1438 | 1438 | if i[2].startswith('hg'): |
|
1439 | 1439 | ui.write("%s\n" % i[2]) |
|
1440 | 1440 | else: |
|
1441 | 1441 | ui.write('hg %s %s\n' % (aliases[0], i[2])) |
|
1442 | 1442 | else: |
|
1443 | 1443 | ui.write('hg %s\n' % aliases[0]) |
|
1444 | 1444 | |
|
1445 | 1445 | # aliases |
|
1446 | 1446 | if not ui.quiet and len(aliases) > 1: |
|
1447 | 1447 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
1448 | 1448 | |
|
1449 | 1449 | # description |
|
1450 | 1450 | doc = gettext(i[0].__doc__) |
|
1451 | 1451 | if not doc: |
|
1452 | 1452 | doc = _("(no help text available)") |
|
1453 | 1453 | if ui.quiet: |
|
1454 | 1454 | doc = doc.splitlines()[0] |
|
1455 | 1455 | ui.write("\n%s\n" % minirst.format(doc, textwidth)) |
|
1456 | 1456 | |
|
1457 | 1457 | if not ui.quiet: |
|
1458 | 1458 | # options |
|
1459 | 1459 | if i[1]: |
|
1460 | 1460 | option_lists.append((_("options:\n"), i[1])) |
|
1461 | 1461 | |
|
1462 | 1462 | addglobalopts(False) |
|
1463 | 1463 | |
|
1464 | 1464 | def helplist(header, select=None): |
|
1465 | 1465 | h = {} |
|
1466 | 1466 | cmds = {} |
|
1467 | 1467 | for c, e in table.iteritems(): |
|
1468 | 1468 | f = c.split("|", 1)[0] |
|
1469 | 1469 | if select and not select(f): |
|
1470 | 1470 | continue |
|
1471 | 1471 | if (not select and name != 'shortlist' and |
|
1472 | 1472 | e[0].__module__ != __name__): |
|
1473 | 1473 | continue |
|
1474 | 1474 | if name == "shortlist" and not f.startswith("^"): |
|
1475 | 1475 | continue |
|
1476 | 1476 | f = f.lstrip("^") |
|
1477 | 1477 | if not ui.debugflag and f.startswith("debug"): |
|
1478 | 1478 | continue |
|
1479 | 1479 | doc = e[0].__doc__ |
|
1480 | 1480 | if doc and 'DEPRECATED' in doc and not ui.verbose: |
|
1481 | 1481 | continue |
|
1482 | 1482 | doc = gettext(doc) |
|
1483 | 1483 | if not doc: |
|
1484 | 1484 | doc = _("(no help text available)") |
|
1485 | 1485 | h[f] = doc.splitlines()[0].rstrip() |
|
1486 | 1486 | cmds[f] = c.lstrip("^") |
|
1487 | 1487 | |
|
1488 | 1488 | if not h: |
|
1489 | 1489 | ui.status(_('no commands defined\n')) |
|
1490 | 1490 | return |
|
1491 | 1491 | |
|
1492 | 1492 | ui.status(header) |
|
1493 | 1493 | fns = sorted(h) |
|
1494 | 1494 | m = max(map(len, fns)) |
|
1495 | 1495 | for f in fns: |
|
1496 | 1496 | if ui.verbose: |
|
1497 | 1497 | commands = cmds[f].replace("|",", ") |
|
1498 | 1498 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
1499 | 1499 | else: |
|
1500 | 1500 | ui.write(' %-*s %s\n' % (m, f, util.wrap(h[f], m + 4))) |
|
1501 | 1501 | |
|
1502 | 1502 | if name != 'shortlist': |
|
1503 | 1503 | exts, maxlength = extensions.enabled() |
|
1504 | 1504 | text = help.listexts(_('enabled extensions:'), exts, maxlength) |
|
1505 | 1505 | if text: |
|
1506 | 1506 | ui.write("\n%s\n" % minirst.format(text, textwidth)) |
|
1507 | 1507 | |
|
1508 | 1508 | if not ui.quiet: |
|
1509 | 1509 | addglobalopts(True) |
|
1510 | 1510 | |
|
1511 | 1511 | def helptopic(name): |
|
1512 | 1512 | for names, header, doc in help.helptable: |
|
1513 | 1513 | if name in names: |
|
1514 | 1514 | break |
|
1515 | 1515 | else: |
|
1516 | 1516 | raise error.UnknownCommand(name) |
|
1517 | 1517 | |
|
1518 | 1518 | # description |
|
1519 | 1519 | if not doc: |
|
1520 | 1520 | doc = _("(no help text available)") |
|
1521 | 1521 | if hasattr(doc, '__call__'): |
|
1522 | 1522 | doc = doc() |
|
1523 | 1523 | |
|
1524 | 1524 | ui.write("%s\n\n" % header) |
|
1525 | 1525 | ui.write("%s\n" % minirst.format(doc, textwidth)) |
|
1526 | 1526 | |
|
1527 | 1527 | def helpext(name): |
|
1528 | 1528 | try: |
|
1529 | 1529 | mod = extensions.find(name) |
|
1530 | 1530 | except KeyError: |
|
1531 | 1531 | raise error.UnknownCommand(name) |
|
1532 | 1532 | |
|
1533 | 1533 | doc = gettext(mod.__doc__) or _('no help text available') |
|
1534 | 1534 | head, tail = doc.split('\n', 1) |
|
1535 | 1535 | ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head)) |
|
1536 | 1536 | if tail: |
|
1537 | 1537 | ui.write(minirst.format(tail, textwidth)) |
|
1538 | 1538 | ui.status('\n\n') |
|
1539 | 1539 | |
|
1540 | 1540 | try: |
|
1541 | 1541 | ct = mod.cmdtable |
|
1542 | 1542 | except AttributeError: |
|
1543 | 1543 | ct = {} |
|
1544 | 1544 | |
|
1545 | 1545 | modcmds = set([c.split('|', 1)[0] for c in ct]) |
|
1546 | 1546 | helplist(_('list of commands:\n\n'), modcmds.__contains__) |
|
1547 | 1547 | |
|
1548 | 1548 | if name and name != 'shortlist': |
|
1549 | 1549 | i = None |
|
1550 | 1550 | for f in (helptopic, helpcmd, helpext): |
|
1551 | 1551 | try: |
|
1552 | 1552 | f(name) |
|
1553 | 1553 | i = None |
|
1554 | 1554 | break |
|
1555 | 1555 | except error.UnknownCommand, inst: |
|
1556 | 1556 | i = inst |
|
1557 | 1557 | if i: |
|
1558 | 1558 | raise i |
|
1559 | 1559 | |
|
1560 | 1560 | else: |
|
1561 | 1561 | # program name |
|
1562 | 1562 | if ui.verbose or with_version: |
|
1563 | 1563 | version_(ui) |
|
1564 | 1564 | else: |
|
1565 | 1565 | ui.status(_("Mercurial Distributed SCM\n")) |
|
1566 | 1566 | ui.status('\n') |
|
1567 | 1567 | |
|
1568 | 1568 | # list of commands |
|
1569 | 1569 | if name == "shortlist": |
|
1570 | 1570 | header = _('basic commands:\n\n') |
|
1571 | 1571 | else: |
|
1572 | 1572 | header = _('list of commands:\n\n') |
|
1573 | 1573 | |
|
1574 | 1574 | helplist(header) |
|
1575 | 1575 | |
|
1576 | 1576 | # list all option lists |
|
1577 | 1577 | opt_output = [] |
|
1578 | 1578 | for title, options in option_lists: |
|
1579 | 1579 | opt_output.append(("\n%s" % title, None)) |
|
1580 | 1580 | for shortopt, longopt, default, desc in options: |
|
1581 | 1581 | if "DEPRECATED" in desc and not ui.verbose: continue |
|
1582 | 1582 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
1583 | 1583 | longopt and " --%s" % longopt), |
|
1584 | 1584 | "%s%s" % (desc, |
|
1585 | 1585 | default |
|
1586 | 1586 | and _(" (default: %s)") % default |
|
1587 | 1587 | or ""))) |
|
1588 | 1588 | |
|
1589 | 1589 | if not name: |
|
1590 | 1590 | ui.write(_("\nadditional help topics:\n\n")) |
|
1591 | 1591 | topics = [] |
|
1592 | 1592 | for names, header, doc in help.helptable: |
|
1593 | 1593 | names = [(-len(name), name) for name in names] |
|
1594 | 1594 | names.sort() |
|
1595 | 1595 | topics.append((names[0][1], header)) |
|
1596 | 1596 | topics_len = max([len(s[0]) for s in topics]) |
|
1597 | 1597 | for t, desc in topics: |
|
1598 | 1598 | ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
|
1599 | 1599 | |
|
1600 | 1600 | if opt_output: |
|
1601 | 1601 | opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0]) |
|
1602 | 1602 | for first, second in opt_output: |
|
1603 | 1603 | if second: |
|
1604 | 1604 | second = util.wrap(second, opts_len + 3) |
|
1605 | 1605 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
1606 | 1606 | else: |
|
1607 | 1607 | ui.write("%s\n" % first) |
|
1608 | 1608 | |
|
1609 | 1609 | def identify(ui, repo, source=None, |
|
1610 | 1610 | rev=None, num=None, id=None, branch=None, tags=None): |
|
1611 | 1611 | """identify the working copy or specified revision |
|
1612 | 1612 | |
|
1613 | 1613 | With no revision, print a summary of the current state of the repository. |
|
1614 | 1614 | |
|
1615 | 1615 | Specifying a path to a repository root or Mercurial bundle will cause |
|
1616 | 1616 | lookup to operate on that repository/bundle. |
|
1617 | 1617 | |
|
1618 | 1618 | This summary identifies the repository state using one or two parent hash |
|
1619 | 1619 | identifiers, followed by a "+" if there are uncommitted changes in the |
|
1620 | 1620 | working directory, a list of tags for this revision and a branch name for |
|
1621 | 1621 | non-default branches. |
|
1622 | 1622 | """ |
|
1623 | 1623 | |
|
1624 | 1624 | if not repo and not source: |
|
1625 | 1625 | raise util.Abort(_("There is no Mercurial repository here " |
|
1626 | 1626 | "(.hg not found)")) |
|
1627 | 1627 | |
|
1628 | 1628 | hexfunc = ui.debugflag and hex or short |
|
1629 | 1629 | default = not (num or id or branch or tags) |
|
1630 | 1630 | output = [] |
|
1631 | 1631 | |
|
1632 | 1632 | revs = [] |
|
1633 | 1633 | if source: |
|
1634 | 1634 | source, revs, checkout = hg.parseurl(ui.expandpath(source), []) |
|
1635 | 1635 | repo = hg.repository(ui, source) |
|
1636 | 1636 | |
|
1637 | 1637 | if not repo.local(): |
|
1638 | 1638 | if not rev and revs: |
|
1639 | 1639 | rev = revs[0] |
|
1640 | 1640 | if not rev: |
|
1641 | 1641 | rev = "tip" |
|
1642 | 1642 | if num or branch or tags: |
|
1643 | 1643 | raise util.Abort( |
|
1644 | 1644 | "can't query remote revision number, branch, or tags") |
|
1645 | 1645 | output = [hexfunc(repo.lookup(rev))] |
|
1646 | 1646 | elif not rev: |
|
1647 | 1647 | ctx = repo[None] |
|
1648 | 1648 | parents = ctx.parents() |
|
1649 | 1649 | changed = False |
|
1650 | 1650 | if default or id or num: |
|
1651 | 1651 | changed = ctx.files() + ctx.deleted() |
|
1652 | 1652 | if default or id: |
|
1653 | 1653 | output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]), |
|
1654 | 1654 | (changed) and "+" or "")] |
|
1655 | 1655 | if num: |
|
1656 | 1656 | output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]), |
|
1657 | 1657 | (changed) and "+" or "")) |
|
1658 | 1658 | else: |
|
1659 | 1659 | ctx = repo[rev] |
|
1660 | 1660 | if default or id: |
|
1661 | 1661 | output = [hexfunc(ctx.node())] |
|
1662 | 1662 | if num: |
|
1663 | 1663 | output.append(str(ctx.rev())) |
|
1664 | 1664 | |
|
1665 | 1665 | if repo.local() and default and not ui.quiet: |
|
1666 | 1666 | b = encoding.tolocal(ctx.branch()) |
|
1667 | 1667 | if b != 'default': |
|
1668 | 1668 | output.append("(%s)" % b) |
|
1669 | 1669 | |
|
1670 | 1670 | # multiple tags for a single parent separated by '/' |
|
1671 | 1671 | t = "/".join(ctx.tags()) |
|
1672 | 1672 | if t: |
|
1673 | 1673 | output.append(t) |
|
1674 | 1674 | |
|
1675 | 1675 | if branch: |
|
1676 | 1676 | output.append(encoding.tolocal(ctx.branch())) |
|
1677 | 1677 | |
|
1678 | 1678 | if tags: |
|
1679 | 1679 | output.extend(ctx.tags()) |
|
1680 | 1680 | |
|
1681 | 1681 | ui.write("%s\n" % ' '.join(output)) |
|
1682 | 1682 | |
|
1683 | 1683 | def import_(ui, repo, patch1, *patches, **opts): |
|
1684 | 1684 | """import an ordered set of patches |
|
1685 | 1685 | |
|
1686 | 1686 | Import a list of patches and commit them individually. |
|
1687 | 1687 | |
|
1688 | 1688 | If there are outstanding changes in the working directory, import will |
|
1689 | 1689 | abort unless given the -f/--force flag. |
|
1690 | 1690 | |
|
1691 | 1691 | You can import a patch straight from a mail message. Even patches as |
|
1692 | 1692 | attachments work (to use the body part, it must have type text/plain or |
|
1693 | 1693 | text/x-patch). From and Subject headers of email message are used as |
|
1694 | 1694 | default committer and commit message. All text/plain body parts before |
|
1695 | 1695 | first diff are added to commit message. |
|
1696 | 1696 | |
|
1697 | 1697 | If the imported patch was generated by hg export, user and description |
|
1698 | 1698 | from patch override values from message headers and body. Values given on |
|
1699 | 1699 | command line with -m/--message and -u/--user override these. |
|
1700 | 1700 | |
|
1701 | 1701 | If --exact is specified, import will set the working directory to the |
|
1702 | 1702 | parent of each patch before applying it, and will abort if the resulting |
|
1703 | 1703 | changeset has a different ID than the one recorded in the patch. This may |
|
1704 | 1704 | happen due to character set problems or other deficiencies in the text |
|
1705 | 1705 | patch format. |
|
1706 | 1706 | |
|
1707 | 1707 | With -s/--similarity, hg will attempt to discover renames and copies in |
|
1708 | 1708 | the patch in the same way as 'addremove'. |
|
1709 | 1709 | |
|
1710 | 1710 | To read a patch from standard input, use "-" as the patch name. If a URL |
|
1711 | 1711 | is specified, the patch will be downloaded from it. See 'hg help dates' |
|
1712 | 1712 | for a list of formats valid for -d/--date. |
|
1713 | 1713 | """ |
|
1714 | 1714 | patches = (patch1,) + patches |
|
1715 | 1715 | |
|
1716 | 1716 | date = opts.get('date') |
|
1717 | 1717 | if date: |
|
1718 | 1718 | opts['date'] = util.parsedate(date) |
|
1719 | 1719 | |
|
1720 | 1720 | try: |
|
1721 | 1721 | sim = float(opts.get('similarity') or 0) |
|
1722 | 1722 | except ValueError: |
|
1723 | 1723 | raise util.Abort(_('similarity must be a number')) |
|
1724 | 1724 | if sim < 0 or sim > 100: |
|
1725 | 1725 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
1726 | 1726 | |
|
1727 | 1727 | if opts.get('exact') or not opts.get('force'): |
|
1728 | 1728 | cmdutil.bail_if_changed(repo) |
|
1729 | 1729 | |
|
1730 | 1730 | d = opts["base"] |
|
1731 | 1731 | strip = opts["strip"] |
|
1732 | 1732 | wlock = lock = None |
|
1733 | 1733 | try: |
|
1734 | 1734 | wlock = repo.wlock() |
|
1735 | 1735 | lock = repo.lock() |
|
1736 | 1736 | for p in patches: |
|
1737 | 1737 | pf = os.path.join(d, p) |
|
1738 | 1738 | |
|
1739 | 1739 | if pf == '-': |
|
1740 | 1740 | ui.status(_("applying patch from stdin\n")) |
|
1741 | 1741 | pf = sys.stdin |
|
1742 | 1742 | else: |
|
1743 | 1743 | ui.status(_("applying %s\n") % p) |
|
1744 | 1744 | pf = url.open(ui, pf) |
|
1745 | 1745 | data = patch.extract(ui, pf) |
|
1746 | 1746 | tmpname, message, user, date, branch, nodeid, p1, p2 = data |
|
1747 | 1747 | |
|
1748 | 1748 | if tmpname is None: |
|
1749 | 1749 | raise util.Abort(_('no diffs found')) |
|
1750 | 1750 | |
|
1751 | 1751 | try: |
|
1752 | 1752 | cmdline_message = cmdutil.logmessage(opts) |
|
1753 | 1753 | if cmdline_message: |
|
1754 | 1754 | # pickup the cmdline msg |
|
1755 | 1755 | message = cmdline_message |
|
1756 | 1756 | elif message: |
|
1757 | 1757 | # pickup the patch msg |
|
1758 | 1758 | message = message.strip() |
|
1759 | 1759 | else: |
|
1760 | 1760 | # launch the editor |
|
1761 | 1761 | message = None |
|
1762 | 1762 | ui.debug(_('message:\n%s\n') % message) |
|
1763 | 1763 | |
|
1764 | 1764 | wp = repo.parents() |
|
1765 | 1765 | if opts.get('exact'): |
|
1766 | 1766 | if not nodeid or not p1: |
|
1767 | 1767 | raise util.Abort(_('not a Mercurial patch')) |
|
1768 | 1768 | p1 = repo.lookup(p1) |
|
1769 | 1769 | p2 = repo.lookup(p2 or hex(nullid)) |
|
1770 | 1770 | |
|
1771 | 1771 | if p1 != wp[0].node(): |
|
1772 | 1772 | hg.clean(repo, p1) |
|
1773 | 1773 | repo.dirstate.setparents(p1, p2) |
|
1774 | 1774 | elif p2: |
|
1775 | 1775 | try: |
|
1776 | 1776 | p1 = repo.lookup(p1) |
|
1777 | 1777 | p2 = repo.lookup(p2) |
|
1778 | 1778 | if p1 == wp[0].node(): |
|
1779 | 1779 | repo.dirstate.setparents(p1, p2) |
|
1780 | 1780 | except error.RepoError: |
|
1781 | 1781 | pass |
|
1782 | 1782 | if opts.get('exact') or opts.get('import_branch'): |
|
1783 | 1783 | repo.dirstate.setbranch(branch or 'default') |
|
1784 | 1784 | |
|
1785 | 1785 | files = {} |
|
1786 | 1786 | try: |
|
1787 | 1787 | patch.patch(tmpname, ui, strip=strip, cwd=repo.root, |
|
1788 | 1788 | files=files, eolmode=None) |
|
1789 | 1789 | finally: |
|
1790 | 1790 | files = patch.updatedir(ui, repo, files, similarity=sim/100.) |
|
1791 | 1791 | if not opts.get('no_commit'): |
|
1792 | 1792 | m = cmdutil.matchfiles(repo, files or []) |
|
1793 | 1793 | n = repo.commit(message, opts.get('user') or user, |
|
1794 | 1794 | opts.get('date') or date, match=m, |
|
1795 | 1795 | editor=cmdutil.commiteditor) |
|
1796 | 1796 | if opts.get('exact'): |
|
1797 | 1797 | if hex(n) != nodeid: |
|
1798 | 1798 | repo.rollback() |
|
1799 | 1799 | raise util.Abort(_('patch is damaged' |
|
1800 | 1800 | ' or loses information')) |
|
1801 | 1801 | # Force a dirstate write so that the next transaction |
|
1802 | 1802 | # backups an up-do-date file. |
|
1803 | 1803 | repo.dirstate.write() |
|
1804 | 1804 | finally: |
|
1805 | 1805 | os.unlink(tmpname) |
|
1806 | 1806 | finally: |
|
1807 | 1807 | release(lock, wlock) |
|
1808 | 1808 | |
|
1809 | 1809 | def incoming(ui, repo, source="default", **opts): |
|
1810 | 1810 | """show new changesets found in source |
|
1811 | 1811 | |
|
1812 | 1812 | Show new changesets found in the specified path/URL or the default pull |
|
1813 | 1813 | location. These are the changesets that would have been pulled if a pull |
|
1814 | 1814 | at the time you issued this command. |
|
1815 | 1815 | |
|
1816 | 1816 | For remote repository, using --bundle avoids downloading the changesets |
|
1817 | 1817 | twice if the incoming is followed by a pull. |
|
1818 | 1818 | |
|
1819 | 1819 | See pull for valid source format details. |
|
1820 | 1820 | """ |
|
1821 | 1821 | limit = cmdutil.loglimit(opts) |
|
1822 | 1822 | source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev')) |
|
1823 | 1823 | other = hg.repository(cmdutil.remoteui(repo, opts), source) |
|
1824 | 1824 | ui.status(_('comparing with %s\n') % url.hidepassword(source)) |
|
1825 | 1825 | if revs: |
|
1826 | 1826 | revs = [other.lookup(rev) for rev in revs] |
|
1827 | 1827 | common, incoming, rheads = repo.findcommonincoming(other, heads=revs, |
|
1828 | 1828 | force=opts["force"]) |
|
1829 | 1829 | if not incoming: |
|
1830 | 1830 | try: |
|
1831 | 1831 | os.unlink(opts["bundle"]) |
|
1832 | 1832 | except: |
|
1833 | 1833 | pass |
|
1834 | 1834 | ui.status(_("no changes found\n")) |
|
1835 | 1835 | return 1 |
|
1836 | 1836 | |
|
1837 | 1837 | cleanup = None |
|
1838 | 1838 | try: |
|
1839 | 1839 | fname = opts["bundle"] |
|
1840 | 1840 | if fname or not other.local(): |
|
1841 | 1841 | # create a bundle (uncompressed if other repo is not local) |
|
1842 | 1842 | |
|
1843 | 1843 | if revs is None and other.capable('changegroupsubset'): |
|
1844 | 1844 | revs = rheads |
|
1845 | 1845 | |
|
1846 | 1846 | if revs is None: |
|
1847 | 1847 | cg = other.changegroup(incoming, "incoming") |
|
1848 | 1848 | else: |
|
1849 | 1849 | cg = other.changegroupsubset(incoming, revs, 'incoming') |
|
1850 | 1850 | bundletype = other.local() and "HG10BZ" or "HG10UN" |
|
1851 | 1851 | fname = cleanup = changegroup.writebundle(cg, fname, bundletype) |
|
1852 | 1852 | # keep written bundle? |
|
1853 | 1853 | if opts["bundle"]: |
|
1854 | 1854 | cleanup = None |
|
1855 | 1855 | if not other.local(): |
|
1856 | 1856 | # use the created uncompressed bundlerepo |
|
1857 | 1857 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1858 | 1858 | |
|
1859 | 1859 | o = other.changelog.nodesbetween(incoming, revs)[0] |
|
1860 | 1860 | if opts.get('newest_first'): |
|
1861 | 1861 | o.reverse() |
|
1862 | 1862 | displayer = cmdutil.show_changeset(ui, other, opts) |
|
1863 | 1863 | count = 0 |
|
1864 | 1864 | for n in o: |
|
1865 | 1865 | if count >= limit: |
|
1866 | 1866 | break |
|
1867 | 1867 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1868 | 1868 | if opts.get('no_merges') and len(parents) == 2: |
|
1869 | 1869 | continue |
|
1870 | 1870 | count += 1 |
|
1871 | 1871 | displayer.show(other[n]) |
|
1872 | 1872 | finally: |
|
1873 | 1873 | if hasattr(other, 'close'): |
|
1874 | 1874 | other.close() |
|
1875 | 1875 | if cleanup: |
|
1876 | 1876 | os.unlink(cleanup) |
|
1877 | 1877 | |
|
1878 | 1878 | def init(ui, dest=".", **opts): |
|
1879 | 1879 | """create a new repository in the given directory |
|
1880 | 1880 | |
|
1881 | 1881 | Initialize a new repository in the given directory. If the given directory |
|
1882 | 1882 | does not exist, it will be created. |
|
1883 | 1883 | |
|
1884 | 1884 | If no directory is given, the current directory is used. |
|
1885 | 1885 | |
|
1886 | 1886 | It is possible to specify an ssh:// URL as the destination. See 'hg help |
|
1887 | 1887 | urls' for more information. |
|
1888 | 1888 | """ |
|
1889 | 1889 | hg.repository(cmdutil.remoteui(ui, opts), dest, create=1) |
|
1890 | 1890 | |
|
1891 | 1891 | def locate(ui, repo, *pats, **opts): |
|
1892 | 1892 | """locate files matching specific patterns |
|
1893 | 1893 | |
|
1894 | 1894 | Print files under Mercurial control in the working directory whose names |
|
1895 | 1895 | match the given patterns. |
|
1896 | 1896 | |
|
1897 | 1897 | By default, this command searches all directories in the working |
|
1898 | 1898 | directory. To search just the current directory and its subdirectories, |
|
1899 | 1899 | use "--include .". |
|
1900 | 1900 | |
|
1901 | 1901 | If no patterns are given to match, this command prints the names of all |
|
1902 | 1902 | files under Mercurial control in the working directory. |
|
1903 | 1903 | |
|
1904 | 1904 | If you want to feed the output of this command into the "xargs" command, |
|
1905 | 1905 | use the -0 option to both this command and "xargs". This will avoid the |
|
1906 | 1906 | problem of "xargs" treating single filenames that contain whitespace as |
|
1907 | 1907 | multiple filenames. |
|
1908 | 1908 | """ |
|
1909 | 1909 | end = opts.get('print0') and '\0' or '\n' |
|
1910 | 1910 | rev = opts.get('rev') or None |
|
1911 | 1911 | |
|
1912 | 1912 | ret = 1 |
|
1913 | 1913 | m = cmdutil.match(repo, pats, opts, default='relglob') |
|
1914 | 1914 | m.bad = lambda x,y: False |
|
1915 | 1915 | for abs in repo[rev].walk(m): |
|
1916 | 1916 | if not rev and abs not in repo.dirstate: |
|
1917 | 1917 | continue |
|
1918 | 1918 | if opts.get('fullpath'): |
|
1919 | 1919 | ui.write(repo.wjoin(abs), end) |
|
1920 | 1920 | else: |
|
1921 | 1921 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
1922 | 1922 | ret = 0 |
|
1923 | 1923 | |
|
1924 | 1924 | return ret |
|
1925 | 1925 | |
|
1926 | 1926 | def log(ui, repo, *pats, **opts): |
|
1927 | 1927 | """show revision history of entire repository or files |
|
1928 | 1928 | |
|
1929 | 1929 | Print the revision history of the specified files or the entire project. |
|
1930 | 1930 | |
|
1931 | 1931 | File history is shown without following rename or copy history of files. |
|
1932 | 1932 | Use -f/--follow with a filename to follow history across renames and |
|
1933 | 1933 | copies. --follow without a filename will only show ancestors or |
|
1934 | 1934 | descendants of the starting revision. --follow-first only follows the |
|
1935 | 1935 | first parent of merge revisions. |
|
1936 | 1936 | |
|
1937 | 1937 | If no revision range is specified, the default is tip:0 unless --follow is |
|
1938 | 1938 | set, in which case the working directory parent is used as the starting |
|
1939 | 1939 | revision. |
|
1940 | 1940 | |
|
1941 | 1941 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
1942 | 1942 | |
|
1943 | 1943 | By default this command prints revision number and changeset id, tags, |
|
1944 | 1944 | non-trivial parents, user, date and time, and a summary for each commit. |
|
1945 | 1945 | When the -v/--verbose switch is used, the list of changed files and full |
|
1946 | 1946 | commit message are shown. |
|
1947 | 1947 | |
|
1948 | 1948 | NOTE: log -p/--patch may generate unexpected diff output for merge |
|
1949 | 1949 | changesets, as it will only compare the merge changeset against its first |
|
1950 | 1950 | parent. Also, only files different from BOTH parents will appear in |
|
1951 | 1951 | files:. |
|
1952 | 1952 | """ |
|
1953 | 1953 | |
|
1954 | 1954 | get = util.cachefunc(lambda r: repo[r].changeset()) |
|
1955 | 1955 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) |
|
1956 | 1956 | |
|
1957 | 1957 | limit = cmdutil.loglimit(opts) |
|
1958 | 1958 | count = 0 |
|
1959 | 1959 | |
|
1960 | 1960 | if opts.get('copies') and opts.get('rev'): |
|
1961 | 1961 | endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1 |
|
1962 | 1962 | else: |
|
1963 | 1963 | endrev = len(repo) |
|
1964 | 1964 | rcache = {} |
|
1965 | 1965 | ncache = {} |
|
1966 | 1966 | def getrenamed(fn, rev): |
|
1967 | 1967 | '''looks up all renames for a file (up to endrev) the first |
|
1968 | 1968 | time the file is given. It indexes on the changerev and only |
|
1969 | 1969 | parses the manifest if linkrev != changerev. |
|
1970 | 1970 | Returns rename info for fn at changerev rev.''' |
|
1971 | 1971 | if fn not in rcache: |
|
1972 | 1972 | rcache[fn] = {} |
|
1973 | 1973 | ncache[fn] = {} |
|
1974 | 1974 | fl = repo.file(fn) |
|
1975 | 1975 | for i in fl: |
|
1976 | 1976 | node = fl.node(i) |
|
1977 | 1977 | lr = fl.linkrev(i) |
|
1978 | 1978 | renamed = fl.renamed(node) |
|
1979 | 1979 | rcache[fn][lr] = renamed |
|
1980 | 1980 | if renamed: |
|
1981 | 1981 | ncache[fn][node] = renamed |
|
1982 | 1982 | if lr >= endrev: |
|
1983 | 1983 | break |
|
1984 | 1984 | if rev in rcache[fn]: |
|
1985 | 1985 | return rcache[fn][rev] |
|
1986 | 1986 | |
|
1987 | 1987 | # If linkrev != rev (i.e. rev not found in rcache) fallback to |
|
1988 | 1988 | # filectx logic. |
|
1989 | 1989 | |
|
1990 | 1990 | try: |
|
1991 | 1991 | return repo[rev][fn].renamed() |
|
1992 | 1992 | except error.LookupError: |
|
1993 | 1993 | pass |
|
1994 | 1994 | return None |
|
1995 | 1995 | |
|
1996 | 1996 | df = False |
|
1997 | 1997 | if opts["date"]: |
|
1998 | 1998 | df = util.matchdate(opts["date"]) |
|
1999 | 1999 | |
|
2000 | 2000 | only_branches = opts.get('only_branch') |
|
2001 | 2001 | |
|
2002 | 2002 | displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn) |
|
2003 | 2003 | for st, rev, fns in changeiter: |
|
2004 | 2004 | if st == 'add': |
|
2005 | 2005 | parents = [p for p in repo.changelog.parentrevs(rev) |
|
2006 | 2006 | if p != nullrev] |
|
2007 | 2007 | if opts.get('no_merges') and len(parents) == 2: |
|
2008 | 2008 | continue |
|
2009 | 2009 | if opts.get('only_merges') and len(parents) != 2: |
|
2010 | 2010 | continue |
|
2011 | 2011 | |
|
2012 | 2012 | if only_branches: |
|
2013 | 2013 | revbranch = get(rev)[5]['branch'] |
|
2014 | 2014 | if revbranch not in only_branches: |
|
2015 | 2015 | continue |
|
2016 | 2016 | |
|
2017 | 2017 | if df: |
|
2018 | 2018 | changes = get(rev) |
|
2019 | 2019 | if not df(changes[2][0]): |
|
2020 | 2020 | continue |
|
2021 | 2021 | |
|
2022 | 2022 | if opts.get('keyword'): |
|
2023 | 2023 | changes = get(rev) |
|
2024 | 2024 | miss = 0 |
|
2025 | 2025 | for k in [kw.lower() for kw in opts['keyword']]: |
|
2026 | 2026 | if not (k in changes[1].lower() or |
|
2027 | 2027 | k in changes[4].lower() or |
|
2028 | 2028 | k in " ".join(changes[3]).lower()): |
|
2029 | 2029 | miss = 1 |
|
2030 | 2030 | break |
|
2031 | 2031 | if miss: |
|
2032 | 2032 | continue |
|
2033 | 2033 | |
|
2034 | 2034 | if opts['user']: |
|
2035 | 2035 | changes = get(rev) |
|
2036 | 2036 | if not [k for k in opts['user'] if k in changes[1]]: |
|
2037 | 2037 | continue |
|
2038 | 2038 | |
|
2039 | 2039 | copies = [] |
|
2040 | 2040 | if opts.get('copies') and rev: |
|
2041 | 2041 | for fn in get(rev)[3]: |
|
2042 | 2042 | rename = getrenamed(fn, rev) |
|
2043 | 2043 | if rename: |
|
2044 | 2044 | copies.append((fn, rename[0])) |
|
2045 | 2045 | displayer.show(context.changectx(repo, rev), copies=copies) |
|
2046 | 2046 | elif st == 'iter': |
|
2047 | 2047 | if count == limit: break |
|
2048 | 2048 | if displayer.flush(rev): |
|
2049 | 2049 | count += 1 |
|
2050 | 2050 | |
|
2051 | 2051 | def manifest(ui, repo, node=None, rev=None): |
|
2052 | 2052 | """output the current or given revision of the project manifest |
|
2053 | 2053 | |
|
2054 | 2054 | Print a list of version controlled files for the given revision. If no |
|
2055 | 2055 | revision is given, the first parent of the working directory is used, or |
|
2056 | 2056 | the null revision if no revision is checked out. |
|
2057 | 2057 | |
|
2058 | 2058 | With -v, print file permissions, symlink and executable bits. |
|
2059 | 2059 | With --debug, print file revision hashes. |
|
2060 | 2060 | """ |
|
2061 | 2061 | |
|
2062 | 2062 | if rev and node: |
|
2063 | 2063 | raise util.Abort(_("please specify just one revision")) |
|
2064 | 2064 | |
|
2065 | 2065 | if not node: |
|
2066 | 2066 | node = rev |
|
2067 | 2067 | |
|
2068 | 2068 | decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} |
|
2069 | 2069 | ctx = repo[node] |
|
2070 | 2070 | for f in ctx: |
|
2071 | 2071 | if ui.debugflag: |
|
2072 | 2072 | ui.write("%40s " % hex(ctx.manifest()[f])) |
|
2073 | 2073 | if ui.verbose: |
|
2074 | 2074 | ui.write(decor[ctx.flags(f)]) |
|
2075 | 2075 | ui.write("%s\n" % f) |
|
2076 | 2076 | |
|
2077 | 2077 | def merge(ui, repo, node=None, **opts): |
|
2078 | 2078 | """merge working directory with another revision |
|
2079 | 2079 | |
|
2080 | 2080 | The current working directory is updated with all changes made in the |
|
2081 | 2081 | requested revision since the last common predecessor revision. |
|
2082 | 2082 | |
|
2083 | 2083 | Files that changed between either parent are marked as changed for the |
|
2084 | 2084 | next commit and a commit must be performed before any further updates to |
|
2085 | 2085 | the repository are allowed. The next commit will have two parents. |
|
2086 | 2086 | |
|
2087 | 2087 | If no revision is specified, the working directory's parent is a head |
|
2088 | 2088 | revision, and the current branch contains exactly one other head, the |
|
2089 | 2089 | other head is merged with by default. Otherwise, an explicit revision with |
|
2090 | 2090 | which to merge with must be provided. |
|
2091 | 2091 | """ |
|
2092 | 2092 | |
|
2093 | 2093 | if opts.get('rev') and node: |
|
2094 | 2094 | raise util.Abort(_("please specify just one revision")) |
|
2095 | 2095 | if not node: |
|
2096 | 2096 | node = opts.get('rev') |
|
2097 | 2097 | |
|
2098 | 2098 | if not node: |
|
2099 | 2099 | branch = repo.changectx(None).branch() |
|
2100 | 2100 | bheads = repo.branchheads(branch) |
|
2101 | 2101 | if len(bheads) > 2: |
|
2102 | 2102 | raise util.Abort(_("branch '%s' has %d heads - " |
|
2103 | 2103 | "please merge with an explicit rev") % |
|
2104 | 2104 | (branch, len(bheads))) |
|
2105 | 2105 | |
|
2106 | 2106 | parent = repo.dirstate.parents()[0] |
|
2107 | 2107 | if len(bheads) == 1: |
|
2108 | 2108 | if len(repo.heads()) > 1: |
|
2109 | 2109 | raise util.Abort(_("branch '%s' has one head - " |
|
2110 | 2110 | "please merge with an explicit rev") % |
|
2111 | 2111 | branch) |
|
2112 | 2112 | msg = _('there is nothing to merge') |
|
2113 | 2113 | if parent != repo.lookup(repo[None].branch()): |
|
2114 | 2114 | msg = _('%s - use "hg update" instead') % msg |
|
2115 | 2115 | raise util.Abort(msg) |
|
2116 | 2116 | |
|
2117 | 2117 | if parent not in bheads: |
|
2118 | 2118 | raise util.Abort(_('working dir not at a head rev - ' |
|
2119 | 2119 | 'use "hg update" or merge with an explicit rev')) |
|
2120 | 2120 | node = parent == bheads[0] and bheads[-1] or bheads[0] |
|
2121 | 2121 | |
|
2122 | 2122 | if opts.get('preview'): |
|
2123 | 2123 | p1 = repo['.'] |
|
2124 | 2124 | p2 = repo[node] |
|
2125 | 2125 | common = p1.ancestor(p2) |
|
2126 | 2126 | roots, heads = [common.node()], [p2.node()] |
|
2127 | 2127 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2128 | 2128 | for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]: |
|
2129 | 2129 | displayer.show(repo[node]) |
|
2130 | 2130 | return 0 |
|
2131 | 2131 | |
|
2132 | 2132 | return hg.merge(repo, node, force=opts.get('force')) |
|
2133 | 2133 | |
|
2134 | 2134 | def outgoing(ui, repo, dest=None, **opts): |
|
2135 | 2135 | """show changesets not found in destination |
|
2136 | 2136 | |
|
2137 | 2137 | Show changesets not found in the specified destination repository or the |
|
2138 | 2138 | default push location. These are the changesets that would be pushed if a |
|
2139 | 2139 | push was requested. |
|
2140 | 2140 | |
|
2141 | 2141 | See pull for valid destination format details. |
|
2142 | 2142 | """ |
|
2143 | 2143 | limit = cmdutil.loglimit(opts) |
|
2144 | 2144 | dest, revs, checkout = hg.parseurl( |
|
2145 | 2145 | ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev')) |
|
2146 | 2146 | if revs: |
|
2147 | 2147 | revs = [repo.lookup(rev) for rev in revs] |
|
2148 | 2148 | |
|
2149 | 2149 | other = hg.repository(cmdutil.remoteui(repo, opts), dest) |
|
2150 | 2150 | ui.status(_('comparing with %s\n') % url.hidepassword(dest)) |
|
2151 | 2151 | o = repo.findoutgoing(other, force=opts.get('force')) |
|
2152 | 2152 | if not o: |
|
2153 | 2153 | ui.status(_("no changes found\n")) |
|
2154 | 2154 | return 1 |
|
2155 | 2155 | o = repo.changelog.nodesbetween(o, revs)[0] |
|
2156 | 2156 | if opts.get('newest_first'): |
|
2157 | 2157 | o.reverse() |
|
2158 | 2158 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2159 | 2159 | count = 0 |
|
2160 | 2160 | for n in o: |
|
2161 | 2161 | if count >= limit: |
|
2162 | 2162 | break |
|
2163 | 2163 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
2164 | 2164 | if opts.get('no_merges') and len(parents) == 2: |
|
2165 | 2165 | continue |
|
2166 | 2166 | count += 1 |
|
2167 | 2167 | displayer.show(repo[n]) |
|
2168 | 2168 | |
|
2169 | 2169 | def parents(ui, repo, file_=None, **opts): |
|
2170 | 2170 | """show the parents of the working directory or revision |
|
2171 | 2171 | |
|
2172 | 2172 | Print the working directory's parent revisions. If a revision is given via |
|
2173 | 2173 | -r/--rev, the parent of that revision will be printed. If a file argument |
|
2174 | 2174 | is given, the revision in which the file was last changed (before the |
|
2175 | 2175 | working directory revision or the argument to --rev if given) is printed. |
|
2176 | 2176 | """ |
|
2177 | 2177 | rev = opts.get('rev') |
|
2178 | 2178 | if rev: |
|
2179 | 2179 | ctx = repo[rev] |
|
2180 | 2180 | else: |
|
2181 | 2181 | ctx = repo[None] |
|
2182 | 2182 | |
|
2183 | 2183 | if file_: |
|
2184 | 2184 | m = cmdutil.match(repo, (file_,), opts) |
|
2185 | 2185 | if m.anypats() or len(m.files()) != 1: |
|
2186 | 2186 | raise util.Abort(_('can only specify an explicit filename')) |
|
2187 | 2187 | file_ = m.files()[0] |
|
2188 | 2188 | filenodes = [] |
|
2189 | 2189 | for cp in ctx.parents(): |
|
2190 | 2190 | if not cp: |
|
2191 | 2191 | continue |
|
2192 | 2192 | try: |
|
2193 | 2193 | filenodes.append(cp.filenode(file_)) |
|
2194 | 2194 | except error.LookupError: |
|
2195 | 2195 | pass |
|
2196 | 2196 | if not filenodes: |
|
2197 | 2197 | raise util.Abort(_("'%s' not found in manifest!") % file_) |
|
2198 | 2198 | fl = repo.file(file_) |
|
2199 | 2199 | p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes] |
|
2200 | 2200 | else: |
|
2201 | 2201 | p = [cp.node() for cp in ctx.parents()] |
|
2202 | 2202 | |
|
2203 | 2203 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2204 | 2204 | for n in p: |
|
2205 | 2205 | if n != nullid: |
|
2206 | 2206 | displayer.show(repo[n]) |
|
2207 | 2207 | |
|
2208 | 2208 | def paths(ui, repo, search=None): |
|
2209 | 2209 | """show aliases for remote repositories |
|
2210 | 2210 | |
|
2211 | 2211 | Show definition of symbolic path name NAME. If no name is given, show |
|
2212 | 2212 | definition of all available names. |
|
2213 | 2213 | |
|
2214 | 2214 | Path names are defined in the [paths] section of /etc/mercurial/hgrc and |
|
2215 | 2215 | $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2216 | 2216 | |
|
2217 | 2217 | See 'hg help urls' for more information. |
|
2218 | 2218 | """ |
|
2219 | 2219 | if search: |
|
2220 | 2220 | for name, path in ui.configitems("paths"): |
|
2221 | 2221 | if name == search: |
|
2222 | 2222 | ui.write("%s\n" % url.hidepassword(path)) |
|
2223 | 2223 | return |
|
2224 | 2224 | ui.warn(_("not found!\n")) |
|
2225 | 2225 | return 1 |
|
2226 | 2226 | else: |
|
2227 | 2227 | for name, path in ui.configitems("paths"): |
|
2228 | 2228 | ui.write("%s = %s\n" % (name, url.hidepassword(path))) |
|
2229 | 2229 | |
|
2230 | 2230 | def postincoming(ui, repo, modheads, optupdate, checkout): |
|
2231 | 2231 | if modheads == 0: |
|
2232 | 2232 | return |
|
2233 | 2233 | if optupdate: |
|
2234 | 2234 | if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout: |
|
2235 | 2235 | return hg.update(repo, checkout) |
|
2236 | 2236 | else: |
|
2237 | 2237 | ui.status(_("not updating, since new heads added\n")) |
|
2238 | 2238 | if modheads > 1: |
|
2239 | 2239 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
2240 | 2240 | else: |
|
2241 | 2241 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2242 | 2242 | |
|
2243 | 2243 | def pull(ui, repo, source="default", **opts): |
|
2244 | 2244 | """pull changes from the specified source |
|
2245 | 2245 | |
|
2246 | 2246 | Pull changes from a remote repository to a local one. |
|
2247 | 2247 | |
|
2248 | 2248 | This finds all changes from the repository at the specified path or URL |
|
2249 | 2249 | and adds them to a local repository (the current one unless -R is |
|
2250 | 2250 | specified). By default, this does not update the copy of the project in |
|
2251 | 2251 | the working directory. |
|
2252 | 2252 | |
|
2253 | 2253 | Use hg incoming if you want to see what would have been added by a pull at |
|
2254 | 2254 | the time you issued this command. If you then decide to added those |
|
2255 | 2255 | changes to the repository, you should use pull -r X where X is the last |
|
2256 | 2256 | changeset listed by hg incoming. |
|
2257 | 2257 | |
|
2258 | 2258 | If SOURCE is omitted, the 'default' path will be used. See 'hg help urls' |
|
2259 | 2259 | for more information. |
|
2260 | 2260 | """ |
|
2261 | 2261 | source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev')) |
|
2262 | 2262 | other = hg.repository(cmdutil.remoteui(repo, opts), source) |
|
2263 | 2263 | ui.status(_('pulling from %s\n') % url.hidepassword(source)) |
|
2264 | 2264 | if revs: |
|
2265 | 2265 | try: |
|
2266 | 2266 | revs = [other.lookup(rev) for rev in revs] |
|
2267 | 2267 | except error.CapabilityError: |
|
2268 | 2268 | err = _("Other repository doesn't support revision lookup, " |
|
2269 | 2269 | "so a rev cannot be specified.") |
|
2270 | 2270 | raise util.Abort(err) |
|
2271 | 2271 | |
|
2272 | 2272 | modheads = repo.pull(other, heads=revs, force=opts.get('force')) |
|
2273 | 2273 | return postincoming(ui, repo, modheads, opts.get('update'), checkout) |
|
2274 | 2274 | |
|
2275 | 2275 | def push(ui, repo, dest=None, **opts): |
|
2276 | 2276 | """push changes to the specified destination |
|
2277 | 2277 | |
|
2278 | 2278 | Push changes from the local repository to the given destination. |
|
2279 | 2279 | |
|
2280 | 2280 | This is the symmetrical operation for pull. It moves changes from the |
|
2281 | 2281 | current repository to a different one. If the destination is local this is |
|
2282 | 2282 | identical to a pull in that directory from the current one. |
|
2283 | 2283 | |
|
2284 | 2284 | By default, push will refuse to run if it detects the result would |
|
2285 | 2285 | increase the number of remote heads. This generally indicates the user |
|
2286 | 2286 | forgot to pull and merge before pushing. |
|
2287 | 2287 | |
|
2288 | 2288 | If -r/--rev is used, the named revision and all its ancestors will be |
|
2289 | 2289 | pushed to the remote repository. |
|
2290 | 2290 | |
|
2291 | 2291 | Please see 'hg help urls' for important details about ssh:// URLs. If |
|
2292 | 2292 | DESTINATION is omitted, a default path will be used. |
|
2293 | 2293 | """ |
|
2294 | 2294 | dest, revs, checkout = hg.parseurl( |
|
2295 | 2295 | ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev')) |
|
2296 | 2296 | other = hg.repository(cmdutil.remoteui(repo, opts), dest) |
|
2297 | 2297 | ui.status(_('pushing to %s\n') % url.hidepassword(dest)) |
|
2298 | 2298 | if revs: |
|
2299 | 2299 | revs = [repo.lookup(rev) for rev in revs] |
|
2300 | 2300 | |
|
2301 | 2301 | # push subrepos depth-first for coherent ordering |
|
2302 | 2302 | c = repo[''] |
|
2303 | 2303 | subs = c.substate # only repos that are committed |
|
2304 | 2304 | for s in sorted(subs): |
|
2305 | 2305 | c.sub(s).push(opts.get('force')) |
|
2306 | 2306 | |
|
2307 | 2307 | r = repo.push(other, opts.get('force'), revs=revs) |
|
2308 | 2308 | return r == 0 |
|
2309 | 2309 | |
|
2310 | 2310 | def recover(ui, repo): |
|
2311 | 2311 | """roll back an interrupted transaction |
|
2312 | 2312 | |
|
2313 | 2313 | Recover from an interrupted commit or pull. |
|
2314 | 2314 | |
|
2315 | 2315 | This command tries to fix the repository status after an interrupted |
|
2316 | 2316 | operation. It should only be necessary when Mercurial suggests it. |
|
2317 | 2317 | """ |
|
2318 | 2318 | if repo.recover(): |
|
2319 | 2319 | return hg.verify(repo) |
|
2320 | 2320 | return 1 |
|
2321 | 2321 | |
|
2322 | 2322 | def remove(ui, repo, *pats, **opts): |
|
2323 | 2323 | """remove the specified files on the next commit |
|
2324 | 2324 | |
|
2325 | 2325 | Schedule the indicated files for removal from the repository. |
|
2326 | 2326 | |
|
2327 | 2327 | This only removes files from the current branch, not from the entire |
|
2328 | 2328 | project history. -A/--after can be used to remove only files that have |
|
2329 | 2329 | already been deleted, -f/--force can be used to force deletion, and -Af |
|
2330 | 2330 | can be used to remove files from the next revision without deleting them |
|
2331 | 2331 | from the working directory. |
|
2332 | 2332 | |
|
2333 | 2333 | The following table details the behavior of remove for different file |
|
2334 | 2334 | states (columns) and option combinations (rows). The file states are Added |
|
2335 | 2335 | [A], Clean [C], Modified [M] and Missing [!] (as reported by hg status). |
|
2336 | 2336 | The actions are Warn, Remove (from branch) and Delete (from disk):: |
|
2337 | 2337 | |
|
2338 | 2338 | A C M ! |
|
2339 | 2339 | none W RD W R |
|
2340 | 2340 | -f R RD RD R |
|
2341 | 2341 | -A W W W R |
|
2342 | 2342 | -Af R R R R |
|
2343 | 2343 | |
|
2344 | 2344 | This command schedules the files to be removed at the next commit. To undo |
|
2345 | 2345 | a remove before that, see hg revert. |
|
2346 | 2346 | """ |
|
2347 | 2347 | |
|
2348 | 2348 | after, force = opts.get('after'), opts.get('force') |
|
2349 | 2349 | if not pats and not after: |
|
2350 | 2350 | raise util.Abort(_('no files specified')) |
|
2351 | 2351 | |
|
2352 | 2352 | m = cmdutil.match(repo, pats, opts) |
|
2353 | 2353 | s = repo.status(match=m, clean=True) |
|
2354 | 2354 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
|
2355 | 2355 | |
|
2356 | 2356 | for f in m.files(): |
|
2357 | 2357 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
2358 | 2358 | ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) |
|
2359 | 2359 | |
|
2360 | 2360 | def warn(files, reason): |
|
2361 | 2361 | for f in files: |
|
2362 | 2362 | ui.warn(_('not removing %s: file %s (use -f to force removal)\n') |
|
2363 | 2363 | % (m.rel(f), reason)) |
|
2364 | 2364 | |
|
2365 | 2365 | if force: |
|
2366 | 2366 | remove, forget = modified + deleted + clean, added |
|
2367 | 2367 | elif after: |
|
2368 | 2368 | remove, forget = deleted, [] |
|
2369 | 2369 | warn(modified + added + clean, _('still exists')) |
|
2370 | 2370 | else: |
|
2371 | 2371 | remove, forget = deleted + clean, [] |
|
2372 | 2372 | warn(modified, _('is modified')) |
|
2373 | 2373 | warn(added, _('has been marked for add')) |
|
2374 | 2374 | |
|
2375 | 2375 | for f in sorted(remove + forget): |
|
2376 | 2376 | if ui.verbose or not m.exact(f): |
|
2377 | 2377 | ui.status(_('removing %s\n') % m.rel(f)) |
|
2378 | 2378 | |
|
2379 | 2379 | repo.forget(forget) |
|
2380 | 2380 | repo.remove(remove, unlink=not after) |
|
2381 | 2381 | |
|
2382 | 2382 | def rename(ui, repo, *pats, **opts): |
|
2383 | 2383 | """rename files; equivalent of copy + remove |
|
2384 | 2384 | |
|
2385 | 2385 | Mark dest as copies of sources; mark sources for deletion. If dest is a |
|
2386 | 2386 | directory, copies are put in that directory. If dest is a file, there can |
|
2387 | 2387 | only be one source. |
|
2388 | 2388 | |
|
2389 | 2389 | By default, this command copies the contents of files as they exist in the |
|
2390 | 2390 | working directory. If invoked with -A/--after, the operation is recorded, |
|
2391 | 2391 | but no copying is performed. |
|
2392 | 2392 | |
|
2393 | 2393 | This command takes effect at the next commit. To undo a rename before |
|
2394 | 2394 | that, see hg revert. |
|
2395 | 2395 | """ |
|
2396 | 2396 | wlock = repo.wlock(False) |
|
2397 | 2397 | try: |
|
2398 | 2398 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
2399 | 2399 | finally: |
|
2400 | 2400 | wlock.release() |
|
2401 | 2401 | |
|
2402 | 2402 | def resolve(ui, repo, *pats, **opts): |
|
2403 | 2403 | """retry file merges from a merge or update |
|
2404 | 2404 | |
|
2405 | 2405 | This command will cleanly retry unresolved file merges using file |
|
2406 | 2406 | revisions preserved from the last update or merge. To attempt to resolve |
|
2407 | 2407 | all unresolved files, use the -a/--all switch. |
|
2408 | 2408 | |
|
2409 | 2409 | If a conflict is resolved manually, please note that the changes will be |
|
2410 | 2410 | overwritten if the merge is retried with resolve. The -m/--mark switch |
|
2411 | 2411 | should be used to mark the file as resolved. |
|
2412 | 2412 | |
|
2413 | 2413 | This command also allows listing resolved files and manually indicating |
|
2414 | 2414 | whether or not files are resolved. All files must be marked as resolved |
|
2415 | 2415 | before a commit is permitted. |
|
2416 | 2416 | |
|
2417 | 2417 | The codes used to show the status of files are:: |
|
2418 | 2418 | |
|
2419 | 2419 | U = unresolved |
|
2420 | 2420 | R = resolved |
|
2421 | 2421 | """ |
|
2422 | 2422 | |
|
2423 | 2423 | all, mark, unmark, show = [opts.get(o) for o in 'all mark unmark list'.split()] |
|
2424 | 2424 | |
|
2425 | 2425 | if (show and (mark or unmark)) or (mark and unmark): |
|
2426 | 2426 | raise util.Abort(_("too many options specified")) |
|
2427 | 2427 | if pats and all: |
|
2428 | 2428 | raise util.Abort(_("can't specify --all and patterns")) |
|
2429 | 2429 | if not (all or pats or show or mark or unmark): |
|
2430 | 2430 | raise util.Abort(_('no files or directories specified; ' |
|
2431 | 2431 | 'use --all to remerge all files')) |
|
2432 | 2432 | |
|
2433 | 2433 | ms = merge_.mergestate(repo) |
|
2434 | 2434 | m = cmdutil.match(repo, pats, opts) |
|
2435 | 2435 | |
|
2436 | 2436 | for f in ms: |
|
2437 | 2437 | if m(f): |
|
2438 | 2438 | if show: |
|
2439 | 2439 | ui.write("%s %s\n" % (ms[f].upper(), f)) |
|
2440 | 2440 | elif mark: |
|
2441 | 2441 | ms.mark(f, "r") |
|
2442 | 2442 | elif unmark: |
|
2443 | 2443 | ms.mark(f, "u") |
|
2444 | 2444 | else: |
|
2445 | 2445 | wctx = repo[None] |
|
2446 | 2446 | mctx = wctx.parents()[-1] |
|
2447 | 2447 | |
|
2448 | 2448 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
2449 | 2449 | a = repo.wjoin(f) |
|
2450 | 2450 | util.copyfile(a, a + ".resolve") |
|
2451 | 2451 | |
|
2452 | 2452 | # resolve file |
|
2453 | 2453 | ms.resolve(f, wctx, mctx) |
|
2454 | 2454 | |
|
2455 | 2455 | # replace filemerge's .orig file with our resolve file |
|
2456 | 2456 | util.rename(a + ".resolve", a + ".orig") |
|
2457 | 2457 | |
|
2458 | 2458 | def revert(ui, repo, *pats, **opts): |
|
2459 | 2459 | """restore individual files or directories to an earlier state |
|
2460 | 2460 | |
|
2461 | 2461 | (Use update -r to check out earlier revisions, revert does not change the |
|
2462 | 2462 | working directory parents.) |
|
2463 | 2463 | |
|
2464 | 2464 | With no revision specified, revert the named files or directories to the |
|
2465 | 2465 | contents they had in the parent of the working directory. This restores |
|
2466 | 2466 | the contents of the affected files to an unmodified state and unschedules |
|
2467 | 2467 | adds, removes, copies, and renames. If the working directory has two |
|
2468 | 2468 | parents, you must explicitly specify the revision to revert to. |
|
2469 | 2469 | |
|
2470 | 2470 | Using the -r/--rev option, revert the given files or directories to their |
|
2471 | 2471 | contents as of a specific revision. This can be helpful to "roll back" |
|
2472 | 2472 | some or all of an earlier change. See 'hg help dates' for a list of |
|
2473 | 2473 | formats valid for -d/--date. |
|
2474 | 2474 | |
|
2475 | 2475 | Revert modifies the working directory. It does not commit any changes, or |
|
2476 | 2476 | change the parent of the working directory. If you revert to a revision |
|
2477 | 2477 | other than the parent of the working directory, the reverted files will |
|
2478 | 2478 | thus appear modified afterwards. |
|
2479 | 2479 | |
|
2480 | 2480 | If a file has been deleted, it is restored. If the executable mode of a |
|
2481 | 2481 | file was changed, it is reset. |
|
2482 | 2482 | |
|
2483 | 2483 | If names are given, all files matching the names are reverted. If no |
|
2484 | 2484 | arguments are given, no files are reverted. |
|
2485 | 2485 | |
|
2486 | 2486 | Modified files are saved with a .orig suffix before reverting. To disable |
|
2487 | 2487 | these backups, use --no-backup. |
|
2488 | 2488 | """ |
|
2489 | 2489 | |
|
2490 | 2490 | if opts["date"]: |
|
2491 | 2491 | if opts["rev"]: |
|
2492 | 2492 | raise util.Abort(_("you can't specify a revision and a date")) |
|
2493 | 2493 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
2494 | 2494 | |
|
2495 | 2495 | if not pats and not opts.get('all'): |
|
2496 | 2496 | raise util.Abort(_('no files or directories specified; ' |
|
2497 | 2497 | 'use --all to revert the whole repo')) |
|
2498 | 2498 | |
|
2499 | 2499 | parent, p2 = repo.dirstate.parents() |
|
2500 | 2500 | if not opts.get('rev') and p2 != nullid: |
|
2501 | 2501 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
2502 | 2502 | 'specific revision')) |
|
2503 | 2503 | ctx = repo[opts.get('rev')] |
|
2504 | 2504 | node = ctx.node() |
|
2505 | 2505 | mf = ctx.manifest() |
|
2506 | 2506 | if node == parent: |
|
2507 | 2507 | pmf = mf |
|
2508 | 2508 | else: |
|
2509 | 2509 | pmf = None |
|
2510 | 2510 | |
|
2511 | 2511 | # need all matching names in dirstate and manifest of target rev, |
|
2512 | 2512 | # so have to walk both. do not print errors if files exist in one |
|
2513 | 2513 | # but not other. |
|
2514 | 2514 | |
|
2515 | 2515 | names = {} |
|
2516 | 2516 | |
|
2517 | 2517 | wlock = repo.wlock() |
|
2518 | 2518 | try: |
|
2519 | 2519 | # walk dirstate. |
|
2520 | 2520 | |
|
2521 | 2521 | m = cmdutil.match(repo, pats, opts) |
|
2522 | 2522 | m.bad = lambda x,y: False |
|
2523 | 2523 | for abs in repo.walk(m): |
|
2524 | 2524 | names[abs] = m.rel(abs), m.exact(abs) |
|
2525 | 2525 | |
|
2526 | 2526 | # walk target manifest. |
|
2527 | 2527 | |
|
2528 | 2528 | def badfn(path, msg): |
|
2529 | 2529 | if path in names: |
|
2530 | 2530 | return |
|
2531 | 2531 | path_ = path + '/' |
|
2532 | 2532 | for f in names: |
|
2533 | 2533 | if f.startswith(path_): |
|
2534 | 2534 | return |
|
2535 | 2535 | ui.warn("%s: %s\n" % (m.rel(path), msg)) |
|
2536 | 2536 | |
|
2537 | 2537 | m = cmdutil.match(repo, pats, opts) |
|
2538 | 2538 | m.bad = badfn |
|
2539 | 2539 | for abs in repo[node].walk(m): |
|
2540 | 2540 | if abs not in names: |
|
2541 | 2541 | names[abs] = m.rel(abs), m.exact(abs) |
|
2542 | 2542 | |
|
2543 | 2543 | m = cmdutil.matchfiles(repo, names) |
|
2544 | 2544 | changes = repo.status(match=m)[:4] |
|
2545 | 2545 | modified, added, removed, deleted = map(set, changes) |
|
2546 | 2546 | |
|
2547 | 2547 | # if f is a rename, also revert the source |
|
2548 | 2548 | cwd = repo.getcwd() |
|
2549 | 2549 | for f in added: |
|
2550 | 2550 | src = repo.dirstate.copied(f) |
|
2551 | 2551 | if src and src not in names and repo.dirstate[src] == 'r': |
|
2552 | 2552 | removed.add(src) |
|
2553 | 2553 | names[src] = (repo.pathto(src, cwd), True) |
|
2554 | 2554 | |
|
2555 | 2555 | def removeforget(abs): |
|
2556 | 2556 | if repo.dirstate[abs] == 'a': |
|
2557 | 2557 | return _('forgetting %s\n') |
|
2558 | 2558 | return _('removing %s\n') |
|
2559 | 2559 | |
|
2560 | 2560 | revert = ([], _('reverting %s\n')) |
|
2561 | 2561 | add = ([], _('adding %s\n')) |
|
2562 | 2562 | remove = ([], removeforget) |
|
2563 | 2563 | undelete = ([], _('undeleting %s\n')) |
|
2564 | 2564 | |
|
2565 | 2565 | disptable = ( |
|
2566 | 2566 | # dispatch table: |
|
2567 | 2567 | # file state |
|
2568 | 2568 | # action if in target manifest |
|
2569 | 2569 | # action if not in target manifest |
|
2570 | 2570 | # make backup if in target manifest |
|
2571 | 2571 | # make backup if not in target manifest |
|
2572 | 2572 | (modified, revert, remove, True, True), |
|
2573 | 2573 | (added, revert, remove, True, False), |
|
2574 | 2574 | (removed, undelete, None, False, False), |
|
2575 | 2575 | (deleted, revert, remove, False, False), |
|
2576 | 2576 | ) |
|
2577 | 2577 | |
|
2578 | 2578 | for abs, (rel, exact) in sorted(names.items()): |
|
2579 | 2579 | mfentry = mf.get(abs) |
|
2580 | 2580 | target = repo.wjoin(abs) |
|
2581 | 2581 | def handle(xlist, dobackup): |
|
2582 | 2582 | xlist[0].append(abs) |
|
2583 | 2583 | if dobackup and not opts.get('no_backup') and util.lexists(target): |
|
2584 | 2584 | bakname = "%s.orig" % rel |
|
2585 | 2585 | ui.note(_('saving current version of %s as %s\n') % |
|
2586 | 2586 | (rel, bakname)) |
|
2587 | 2587 | if not opts.get('dry_run'): |
|
2588 | 2588 | util.copyfile(target, bakname) |
|
2589 | 2589 | if ui.verbose or not exact: |
|
2590 | 2590 | msg = xlist[1] |
|
2591 | 2591 | if not isinstance(msg, basestring): |
|
2592 | 2592 | msg = msg(abs) |
|
2593 | 2593 | ui.status(msg % rel) |
|
2594 | 2594 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2595 | 2595 | if abs not in table: continue |
|
2596 | 2596 | # file has changed in dirstate |
|
2597 | 2597 | if mfentry: |
|
2598 | 2598 | handle(hitlist, backuphit) |
|
2599 | 2599 | elif misslist is not None: |
|
2600 | 2600 | handle(misslist, backupmiss) |
|
2601 | 2601 | break |
|
2602 | 2602 | else: |
|
2603 | 2603 | if abs not in repo.dirstate: |
|
2604 | 2604 | if mfentry: |
|
2605 | 2605 | handle(add, True) |
|
2606 | 2606 | elif exact: |
|
2607 | 2607 | ui.warn(_('file not managed: %s\n') % rel) |
|
2608 | 2608 | continue |
|
2609 | 2609 | # file has not changed in dirstate |
|
2610 | 2610 | if node == parent: |
|
2611 | 2611 | if exact: ui.warn(_('no changes needed to %s\n') % rel) |
|
2612 | 2612 | continue |
|
2613 | 2613 | if pmf is None: |
|
2614 | 2614 | # only need parent manifest in this unlikely case, |
|
2615 | 2615 | # so do not read by default |
|
2616 | 2616 | pmf = repo[parent].manifest() |
|
2617 | 2617 | if abs in pmf: |
|
2618 | 2618 | if mfentry: |
|
2619 | 2619 | # if version of file is same in parent and target |
|
2620 | 2620 | # manifests, do nothing |
|
2621 | 2621 | if (pmf[abs] != mfentry or |
|
2622 | 2622 | pmf.flags(abs) != mf.flags(abs)): |
|
2623 | 2623 | handle(revert, False) |
|
2624 | 2624 | else: |
|
2625 | 2625 | handle(remove, False) |
|
2626 | 2626 | |
|
2627 | 2627 | if not opts.get('dry_run'): |
|
2628 | 2628 | def checkout(f): |
|
2629 | 2629 | fc = ctx[f] |
|
2630 | 2630 | repo.wwrite(f, fc.data(), fc.flags()) |
|
2631 | 2631 | |
|
2632 | 2632 | audit_path = util.path_auditor(repo.root) |
|
2633 | 2633 | for f in remove[0]: |
|
2634 | 2634 | if repo.dirstate[f] == 'a': |
|
2635 | 2635 | repo.dirstate.forget(f) |
|
2636 | 2636 | continue |
|
2637 | 2637 | audit_path(f) |
|
2638 | 2638 | try: |
|
2639 | 2639 | util.unlink(repo.wjoin(f)) |
|
2640 | 2640 | except OSError: |
|
2641 | 2641 | pass |
|
2642 | 2642 | repo.dirstate.remove(f) |
|
2643 | 2643 | |
|
2644 | 2644 | normal = None |
|
2645 | 2645 | if node == parent: |
|
2646 | 2646 | # We're reverting to our parent. If possible, we'd like status |
|
2647 | 2647 | # to report the file as clean. We have to use normallookup for |
|
2648 | 2648 | # merges to avoid losing information about merged/dirty files. |
|
2649 | 2649 | if p2 != nullid: |
|
2650 | 2650 | normal = repo.dirstate.normallookup |
|
2651 | 2651 | else: |
|
2652 | 2652 | normal = repo.dirstate.normal |
|
2653 | 2653 | for f in revert[0]: |
|
2654 | 2654 | checkout(f) |
|
2655 | 2655 | if normal: |
|
2656 | 2656 | normal(f) |
|
2657 | 2657 | |
|
2658 | 2658 | for f in add[0]: |
|
2659 | 2659 | checkout(f) |
|
2660 | 2660 | repo.dirstate.add(f) |
|
2661 | 2661 | |
|
2662 | 2662 | normal = repo.dirstate.normallookup |
|
2663 | 2663 | if node == parent and p2 == nullid: |
|
2664 | 2664 | normal = repo.dirstate.normal |
|
2665 | 2665 | for f in undelete[0]: |
|
2666 | 2666 | checkout(f) |
|
2667 | 2667 | normal(f) |
|
2668 | 2668 | |
|
2669 | 2669 | finally: |
|
2670 | 2670 | wlock.release() |
|
2671 | 2671 | |
|
2672 | 2672 | def rollback(ui, repo): |
|
2673 | 2673 | """roll back the last transaction |
|
2674 | 2674 | |
|
2675 | 2675 | This command should be used with care. There is only one level of |
|
2676 | 2676 | rollback, and there is no way to undo a rollback. It will also restore the |
|
2677 | 2677 | dirstate at the time of the last transaction, losing any dirstate changes |
|
2678 | 2678 | since that time. This command does not alter the working directory. |
|
2679 | 2679 | |
|
2680 | 2680 | Transactions are used to encapsulate the effects of all commands that |
|
2681 | 2681 | create new changesets or propagate existing changesets into a repository. |
|
2682 | 2682 | For example, the following commands are transactional, and their effects |
|
2683 | 2683 | can be rolled back:: |
|
2684 | 2684 | |
|
2685 | 2685 | commit |
|
2686 | 2686 | import |
|
2687 | 2687 | pull |
|
2688 | 2688 | push (with this repository as destination) |
|
2689 | 2689 | unbundle |
|
2690 | 2690 | |
|
2691 | 2691 | This command is not intended for use on public repositories. Once changes |
|
2692 | 2692 | are visible for pull by other users, rolling a transaction back locally is |
|
2693 | 2693 | ineffective (someone else may already have pulled the changes). |
|
2694 | 2694 | Furthermore, a race is possible with readers of the repository; for |
|
2695 | 2695 | example an in-progress pull from the repository may fail if a rollback is |
|
2696 | 2696 | performed. |
|
2697 | 2697 | """ |
|
2698 | 2698 | repo.rollback() |
|
2699 | 2699 | |
|
2700 | 2700 | def root(ui, repo): |
|
2701 | 2701 | """print the root (top) of the current working directory |
|
2702 | 2702 | |
|
2703 | 2703 | Print the root directory of the current repository. |
|
2704 | 2704 | """ |
|
2705 | 2705 | ui.write(repo.root + "\n") |
|
2706 | 2706 | |
|
2707 | 2707 | def serve(ui, repo, **opts): |
|
2708 | 2708 | """export the repository via HTTP |
|
2709 | 2709 | |
|
2710 | 2710 | Start a local HTTP repository browser and pull server. |
|
2711 | 2711 | |
|
2712 | 2712 | By default, the server logs accesses to stdout and errors to stderr. Use |
|
2713 | 2713 | the -A/--accesslog and -E/--errorlog options to log to files. |
|
2714 | 2714 | """ |
|
2715 | 2715 | |
|
2716 | 2716 | if opts["stdio"]: |
|
2717 | 2717 | if repo is None: |
|
2718 | 2718 | raise error.RepoError(_("There is no Mercurial repository here" |
|
2719 | 2719 | " (.hg not found)")) |
|
2720 | 2720 | s = sshserver.sshserver(ui, repo) |
|
2721 | 2721 | s.serve_forever() |
|
2722 | 2722 | |
|
2723 | 2723 | baseui = repo and repo.baseui or ui |
|
2724 | 2724 | optlist = ("name templates style address port prefix ipv6" |
|
2725 | 2725 | " accesslog errorlog webdir_conf certificate encoding") |
|
2726 | 2726 | for o in optlist.split(): |
|
2727 | 2727 | if opts.get(o, None): |
|
2728 | 2728 | baseui.setconfig("web", o, str(opts[o])) |
|
2729 | 2729 | if (repo is not None) and (repo.ui != baseui): |
|
2730 | 2730 | repo.ui.setconfig("web", o, str(opts[o])) |
|
2731 | 2731 | |
|
2732 | 2732 | if repo is None and not ui.config("web", "webdir_conf"): |
|
2733 | 2733 | raise error.RepoError(_("There is no Mercurial repository here" |
|
2734 | 2734 | " (.hg not found)")) |
|
2735 | 2735 | |
|
2736 | 2736 | class service(object): |
|
2737 | 2737 | def init(self): |
|
2738 | 2738 | util.set_signal_handler() |
|
2739 | 2739 | self.httpd = server.create_server(baseui, repo) |
|
2740 | 2740 | |
|
2741 | 2741 | if not ui.verbose: return |
|
2742 | 2742 | |
|
2743 | 2743 | if self.httpd.prefix: |
|
2744 | 2744 | prefix = self.httpd.prefix.strip('/') + '/' |
|
2745 | 2745 | else: |
|
2746 | 2746 | prefix = '' |
|
2747 | 2747 | |
|
2748 | 2748 | port = ':%d' % self.httpd.port |
|
2749 | 2749 | if port == ':80': |
|
2750 | 2750 | port = '' |
|
2751 | 2751 | |
|
2752 | 2752 | bindaddr = self.httpd.addr |
|
2753 | 2753 | if bindaddr == '0.0.0.0': |
|
2754 | 2754 | bindaddr = '*' |
|
2755 | 2755 | elif ':' in bindaddr: # IPv6 |
|
2756 | 2756 | bindaddr = '[%s]' % bindaddr |
|
2757 | 2757 | |
|
2758 | 2758 | fqaddr = self.httpd.fqaddr |
|
2759 | 2759 | if ':' in fqaddr: |
|
2760 | 2760 | fqaddr = '[%s]' % fqaddr |
|
2761 | 2761 | ui.status(_('listening at http://%s%s/%s (bound to %s:%d)\n') % |
|
2762 | 2762 | (fqaddr, port, prefix, bindaddr, self.httpd.port)) |
|
2763 | 2763 | |
|
2764 | 2764 | def run(self): |
|
2765 | 2765 | self.httpd.serve_forever() |
|
2766 | 2766 | |
|
2767 | 2767 | service = service() |
|
2768 | 2768 | |
|
2769 | 2769 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
2770 | 2770 | |
|
2771 | 2771 | def status(ui, repo, *pats, **opts): |
|
2772 | 2772 | """show changed files in the working directory |
|
2773 | 2773 | |
|
2774 | 2774 | Show status of files in the repository. If names are given, only files |
|
2775 | 2775 | that match are shown. Files that are clean or ignored or the source of a |
|
2776 | 2776 | copy/move operation, are not listed unless -c/--clean, -i/--ignored, |
|
2777 | 2777 | -C/--copies or -A/--all are given. Unless options described with "show |
|
2778 | 2778 | only ..." are given, the options -mardu are used. |
|
2779 | 2779 | |
|
2780 | 2780 | Option -q/--quiet hides untracked (unknown and ignored) files unless |
|
2781 | 2781 | explicitly requested with -u/--unknown or -i/--ignored. |
|
2782 | 2782 | |
|
2783 | 2783 | NOTE: status may appear to disagree with diff if permissions have changed |
|
2784 | 2784 | or a merge has occurred. The standard diff format does not report |
|
2785 | 2785 | permission changes and diff only reports changes relative to one merge |
|
2786 | 2786 | parent. |
|
2787 | 2787 | |
|
2788 | 2788 | If one revision is given, it is used as the base revision. If two |
|
2789 | 2789 | revisions are given, the differences between them are shown. |
|
2790 | 2790 | |
|
2791 | 2791 | The codes used to show the status of files are:: |
|
2792 | 2792 | |
|
2793 | 2793 | M = modified |
|
2794 | 2794 | A = added |
|
2795 | 2795 | R = removed |
|
2796 | 2796 | C = clean |
|
2797 | 2797 | ! = missing (deleted by non-hg command, but still tracked) |
|
2798 | 2798 | ? = not tracked |
|
2799 | 2799 | I = ignored |
|
2800 | 2800 | = origin of the previous file listed as A (added) |
|
2801 | 2801 | """ |
|
2802 | 2802 | |
|
2803 | 2803 | node1, node2 = cmdutil.revpair(repo, opts.get('rev')) |
|
2804 | 2804 | cwd = (pats and repo.getcwd()) or '' |
|
2805 | 2805 | end = opts.get('print0') and '\0' or '\n' |
|
2806 | 2806 | copy = {} |
|
2807 | 2807 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
2808 | 2808 | show = [k for k in states if opts.get(k)] |
|
2809 | 2809 | if opts.get('all'): |
|
2810 | 2810 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
2811 | 2811 | if not show: |
|
2812 | 2812 | show = ui.quiet and states[:4] or states[:5] |
|
2813 | 2813 | |
|
2814 | 2814 | stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts), |
|
2815 | 2815 | 'ignored' in show, 'clean' in show, 'unknown' in show) |
|
2816 | 2816 | changestates = zip(states, 'MAR!?IC', stat) |
|
2817 | 2817 | |
|
2818 | 2818 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): |
|
2819 | 2819 | ctxn = repo[nullid] |
|
2820 | 2820 | ctx1 = repo[node1] |
|
2821 | 2821 | ctx2 = repo[node2] |
|
2822 | 2822 | added = stat[1] |
|
2823 | 2823 | if node2 is None: |
|
2824 | 2824 | added = stat[0] + stat[1] # merged? |
|
2825 | 2825 | |
|
2826 | 2826 | for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems(): |
|
2827 | 2827 | if k in added: |
|
2828 | 2828 | copy[k] = v |
|
2829 | 2829 | elif v in added: |
|
2830 | 2830 | copy[v] = k |
|
2831 | 2831 | |
|
2832 | 2832 | for state, char, files in changestates: |
|
2833 | 2833 | if state in show: |
|
2834 | 2834 | format = "%s %%s%s" % (char, end) |
|
2835 | 2835 | if opts.get('no_status'): |
|
2836 | 2836 | format = "%%s%s" % end |
|
2837 | 2837 | |
|
2838 | 2838 | for f in files: |
|
2839 | 2839 | ui.write(format % repo.pathto(f, cwd)) |
|
2840 | 2840 | if f in copy: |
|
2841 | 2841 | ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end)) |
|
2842 | 2842 | |
|
2843 | 2843 | def tag(ui, repo, name1, *names, **opts): |
|
2844 | 2844 | """add one or more tags for the current or given revision |
|
2845 | 2845 | |
|
2846 | 2846 | Name a particular revision using <name>. |
|
2847 | 2847 | |
|
2848 | 2848 | Tags are used to name particular revisions of the repository and are very |
|
2849 | 2849 | useful to compare different revisions, to go back to significant earlier |
|
2850 | 2850 | versions or to mark branch points as releases, etc. |
|
2851 | 2851 | |
|
2852 | 2852 | If no revision is given, the parent of the working directory is used, or |
|
2853 | 2853 | tip if no revision is checked out. |
|
2854 | 2854 | |
|
2855 | 2855 | To facilitate version control, distribution, and merging of tags, they are |
|
2856 | 2856 | stored as a file named ".hgtags" which is managed similarly to other |
|
2857 | 2857 | project files and can be hand-edited if necessary. The file |
|
2858 | 2858 | '.hg/localtags' is used for local tags (not shared among repositories). |
|
2859 | 2859 | |
|
2860 | 2860 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
2861 | 2861 | """ |
|
2862 | 2862 | |
|
2863 | 2863 | rev_ = "." |
|
2864 | 2864 | names = (name1,) + names |
|
2865 | 2865 | if len(names) != len(set(names)): |
|
2866 | 2866 | raise util.Abort(_('tag names must be unique')) |
|
2867 | 2867 | for n in names: |
|
2868 | 2868 | if n in ['tip', '.', 'null']: |
|
2869 | 2869 | raise util.Abort(_('the name \'%s\' is reserved') % n) |
|
2870 | 2870 | if opts.get('rev') and opts.get('remove'): |
|
2871 | 2871 | raise util.Abort(_("--rev and --remove are incompatible")) |
|
2872 | 2872 | if opts.get('rev'): |
|
2873 | 2873 | rev_ = opts['rev'] |
|
2874 | 2874 | message = opts.get('message') |
|
2875 | 2875 | if opts.get('remove'): |
|
2876 | 2876 | expectedtype = opts.get('local') and 'local' or 'global' |
|
2877 | 2877 | for n in names: |
|
2878 | 2878 | if not repo.tagtype(n): |
|
2879 | 2879 | raise util.Abort(_('tag \'%s\' does not exist') % n) |
|
2880 | 2880 | if repo.tagtype(n) != expectedtype: |
|
2881 | 2881 | if expectedtype == 'global': |
|
2882 | 2882 | raise util.Abort(_('tag \'%s\' is not a global tag') % n) |
|
2883 | 2883 | else: |
|
2884 | 2884 | raise util.Abort(_('tag \'%s\' is not a local tag') % n) |
|
2885 | 2885 | rev_ = nullid |
|
2886 | 2886 | if not message: |
|
2887 | 2887 | # we don't translate commit messages |
|
2888 | 2888 | message = 'Removed tag %s' % ', '.join(names) |
|
2889 | 2889 | elif not opts.get('force'): |
|
2890 | 2890 | for n in names: |
|
2891 | 2891 | if n in repo.tags(): |
|
2892 | 2892 | raise util.Abort(_('tag \'%s\' already exists ' |
|
2893 | 2893 | '(use -f to force)') % n) |
|
2894 | 2894 | if not rev_ and repo.dirstate.parents()[1] != nullid: |
|
2895 | 2895 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
2896 | 2896 | 'specific revision')) |
|
2897 | 2897 | r = repo[rev_].node() |
|
2898 | 2898 | |
|
2899 | 2899 | if not message: |
|
2900 | 2900 | # we don't translate commit messages |
|
2901 | 2901 | message = ('Added tag %s for changeset %s' % |
|
2902 | 2902 | (', '.join(names), short(r))) |
|
2903 | 2903 | |
|
2904 | 2904 | date = opts.get('date') |
|
2905 | 2905 | if date: |
|
2906 | 2906 | date = util.parsedate(date) |
|
2907 | 2907 | |
|
2908 | 2908 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date) |
|
2909 | 2909 | |
|
2910 | 2910 | def tags(ui, repo): |
|
2911 | 2911 | """list repository tags |
|
2912 | 2912 | |
|
2913 | 2913 | This lists both regular and local tags. When the -v/--verbose switch is |
|
2914 | 2914 | used, a third column "local" is printed for local tags. |
|
2915 | 2915 | """ |
|
2916 | 2916 | |
|
2917 | 2917 | hexfunc = ui.debugflag and hex or short |
|
2918 | 2918 | tagtype = "" |
|
2919 | 2919 | |
|
2920 | 2920 | for t, n in reversed(repo.tagslist()): |
|
2921 | 2921 | if ui.quiet: |
|
2922 | 2922 | ui.write("%s\n" % t) |
|
2923 | 2923 | continue |
|
2924 | 2924 | |
|
2925 | 2925 | try: |
|
2926 | 2926 | hn = hexfunc(n) |
|
2927 | 2927 | r = "%5d:%s" % (repo.changelog.rev(n), hn) |
|
2928 | 2928 | except error.LookupError: |
|
2929 | 2929 | r = " ?:%s" % hn |
|
2930 | 2930 | else: |
|
2931 | 2931 | spaces = " " * (30 - encoding.colwidth(t)) |
|
2932 | 2932 | if ui.verbose: |
|
2933 | 2933 | if repo.tagtype(t) == 'local': |
|
2934 | 2934 | tagtype = " local" |
|
2935 | 2935 | else: |
|
2936 | 2936 | tagtype = "" |
|
2937 | 2937 | ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype)) |
|
2938 | 2938 | |
|
2939 | 2939 | def tip(ui, repo, **opts): |
|
2940 | 2940 | """show the tip revision |
|
2941 | 2941 | |
|
2942 | 2942 | The tip revision (usually just called the tip) is the changeset most |
|
2943 | 2943 | recently added to the repository (and therefore the most recently changed |
|
2944 | 2944 | head). |
|
2945 | 2945 | |
|
2946 | 2946 | If you have just made a commit, that commit will be the tip. If you have |
|
2947 | 2947 | just pulled changes from another repository, the tip of that repository |
|
2948 | 2948 | becomes the current tip. The "tip" tag is special and cannot be renamed or |
|
2949 | 2949 | assigned to a different changeset. |
|
2950 | 2950 | """ |
|
2951 | 2951 | cmdutil.show_changeset(ui, repo, opts).show(repo[len(repo) - 1]) |
|
2952 | 2952 | |
|
2953 | 2953 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
2954 | 2954 | """apply one or more changegroup files |
|
2955 | 2955 | |
|
2956 | 2956 | Apply one or more compressed changegroup files generated by the bundle |
|
2957 | 2957 | command. |
|
2958 | 2958 | """ |
|
2959 | 2959 | fnames = (fname1,) + fnames |
|
2960 | 2960 | |
|
2961 | 2961 | lock = repo.lock() |
|
2962 | 2962 | try: |
|
2963 | 2963 | for fname in fnames: |
|
2964 | 2964 | f = url.open(ui, fname) |
|
2965 | 2965 | gen = changegroup.readbundle(f, fname) |
|
2966 | 2966 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) |
|
2967 | 2967 | finally: |
|
2968 | 2968 | lock.release() |
|
2969 | 2969 | |
|
2970 | 2970 | return postincoming(ui, repo, modheads, opts.get('update'), None) |
|
2971 | 2971 | |
|
2972 | 2972 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): |
|
2973 | 2973 | """update working directory |
|
2974 | 2974 | |
|
2975 | 2975 | Update the repository's working directory to the specified revision, or |
|
2976 | 2976 | the tip of the current branch if none is specified. Use null as the |
|
2977 | 2977 | revision to remove the working copy (like 'hg clone -U'). |
|
2978 | 2978 | |
|
2979 | 2979 | When the working directory contains no uncommitted changes, it will be |
|
2980 | 2980 | replaced by the state of the requested revision from the repository. When |
|
2981 | 2981 | the requested revision is on a different branch, the working directory |
|
2982 | 2982 | will additionally be switched to that branch. |
|
2983 | 2983 | |
|
2984 | 2984 | When there are uncommitted changes, use option -C/--clean to discard them, |
|
2985 | 2985 | forcibly replacing the state of the working directory with the requested |
|
2986 | 2986 | revision. Alternately, use -c/--check to abort. |
|
2987 | 2987 | |
|
2988 | 2988 | When there are uncommitted changes and option -C/--clean is not used, and |
|
2989 | 2989 | the parent revision and requested revision are on the same branch, and one |
|
2990 | 2990 | of them is an ancestor of the other, then the new working directory will |
|
2991 | 2991 | contain the requested revision merged with the uncommitted changes. |
|
2992 | 2992 | Otherwise, the update will fail with a suggestion to use 'merge' or |
|
2993 | 2993 | 'update -C' instead. |
|
2994 | 2994 | |
|
2995 | 2995 | If you want to update just one file to an older revision, use revert. |
|
2996 | 2996 | |
|
2997 | 2997 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
2998 | 2998 | """ |
|
2999 | 2999 | if rev and node: |
|
3000 | 3000 | raise util.Abort(_("please specify just one revision")) |
|
3001 | 3001 | |
|
3002 | 3002 | if not rev: |
|
3003 | 3003 | rev = node |
|
3004 | 3004 | |
|
3005 | 3005 | if not clean and check: |
|
3006 | 3006 | # we could use dirty() but we can ignore merge and branch trivia |
|
3007 | 3007 | c = repo[None] |
|
3008 | 3008 | if c.modified() or c.added() or c.removed(): |
|
3009 | 3009 | raise util.Abort(_("uncommitted local changes")) |
|
3010 | 3010 | |
|
3011 | 3011 | if date: |
|
3012 | 3012 | if rev: |
|
3013 | 3013 | raise util.Abort(_("you can't specify a revision and a date")) |
|
3014 | 3014 | rev = cmdutil.finddate(ui, repo, date) |
|
3015 | 3015 | |
|
3016 | 3016 | if clean: |
|
3017 | 3017 | return hg.clean(repo, rev) |
|
3018 | 3018 | else: |
|
3019 | 3019 | return hg.update(repo, rev) |
|
3020 | 3020 | |
|
3021 | 3021 | def verify(ui, repo): |
|
3022 | 3022 | """verify the integrity of the repository |
|
3023 | 3023 | |
|
3024 | 3024 | Verify the integrity of the current repository. |
|
3025 | 3025 | |
|
3026 | 3026 | This will perform an extensive check of the repository's integrity, |
|
3027 | 3027 | validating the hashes and checksums of each entry in the changelog, |
|
3028 | 3028 | manifest, and tracked files, as well as the integrity of their crosslinks |
|
3029 | 3029 | and indices. |
|
3030 | 3030 | """ |
|
3031 | 3031 | return hg.verify(repo) |
|
3032 | 3032 | |
|
3033 | 3033 | def version_(ui): |
|
3034 | 3034 | """output version and copyright information""" |
|
3035 | 3035 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
3036 | 3036 | % util.version()) |
|
3037 | 3037 | ui.status(_( |
|
3038 | 3038 | "\nCopyright (C) 2005-2009 Matt Mackall <mpm@selenic.com> and others\n" |
|
3039 | 3039 | "This is free software; see the source for copying conditions. " |
|
3040 | 3040 | "There is NO\nwarranty; " |
|
3041 | 3041 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
3042 | 3042 | )) |
|
3043 | 3043 | |
|
3044 | 3044 | # Command options and aliases are listed here, alphabetically |
|
3045 | 3045 | |
|
3046 | 3046 | globalopts = [ |
|
3047 | 3047 | ('R', 'repository', '', |
|
3048 | 3048 | _('repository root directory or symbolic path name')), |
|
3049 | 3049 | ('', 'cwd', '', _('change working directory')), |
|
3050 | 3050 | ('y', 'noninteractive', None, |
|
3051 | 3051 | _('do not prompt, assume \'yes\' for any required answers')), |
|
3052 | 3052 | ('q', 'quiet', None, _('suppress output')), |
|
3053 | 3053 | ('v', 'verbose', None, _('enable additional output')), |
|
3054 | 3054 | ('', 'config', [], _('set/override config option')), |
|
3055 | 3055 | ('', 'debug', None, _('enable debugging output')), |
|
3056 | 3056 | ('', 'debugger', None, _('start debugger')), |
|
3057 | 3057 | ('', 'encoding', encoding.encoding, _('set the charset encoding')), |
|
3058 | 3058 | ('', 'encodingmode', encoding.encodingmode, |
|
3059 | 3059 | _('set the charset encoding mode')), |
|
3060 | 3060 | ('', 'traceback', None, _('print traceback on exception')), |
|
3061 | 3061 | ('', 'time', None, _('time how long the command takes')), |
|
3062 | 3062 | ('', 'profile', None, _('print command execution profile')), |
|
3063 | 3063 | ('', 'version', None, _('output version information and exit')), |
|
3064 | 3064 | ('h', 'help', None, _('display help and exit')), |
|
3065 | 3065 | ] |
|
3066 | 3066 | |
|
3067 | 3067 | dryrunopts = [('n', 'dry-run', None, |
|
3068 | 3068 | _('do not perform actions, just print output'))] |
|
3069 | 3069 | |
|
3070 | 3070 | remoteopts = [ |
|
3071 | 3071 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3072 | 3072 | ('', 'remotecmd', '', _('specify hg command to run on the remote side')), |
|
3073 | 3073 | ] |
|
3074 | 3074 | |
|
3075 | 3075 | walkopts = [ |
|
3076 | 3076 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3077 | 3077 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
3078 | 3078 | ] |
|
3079 | 3079 | |
|
3080 | 3080 | commitopts = [ |
|
3081 | 3081 | ('m', 'message', '', _('use <text> as commit message')), |
|
3082 | 3082 | ('l', 'logfile', '', _('read commit message from <file>')), |
|
3083 | 3083 | ] |
|
3084 | 3084 | |
|
3085 | 3085 | commitopts2 = [ |
|
3086 | 3086 | ('d', 'date', '', _('record datecode as commit date')), |
|
3087 | 3087 | ('u', 'user', '', _('record the specified user as committer')), |
|
3088 | 3088 | ] |
|
3089 | 3089 | |
|
3090 | 3090 | templateopts = [ |
|
3091 | 3091 | ('', 'style', '', _('display using template map file')), |
|
3092 | 3092 | ('', 'template', '', _('display with template')), |
|
3093 | 3093 | ] |
|
3094 | 3094 | |
|
3095 | 3095 | logopts = [ |
|
3096 | 3096 | ('p', 'patch', None, _('show patch')), |
|
3097 | 3097 | ('g', 'git', None, _('use git extended diff format')), |
|
3098 | 3098 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
3099 | 3099 | ('M', 'no-merges', None, _('do not show merges')), |
|
3100 | 3100 | ] + templateopts |
|
3101 | 3101 | |
|
3102 | 3102 | diffopts = [ |
|
3103 | 3103 | ('a', 'text', None, _('treat all files as text')), |
|
3104 | 3104 | ('g', 'git', None, _('use git extended diff format')), |
|
3105 | 3105 | ('', 'nodates', None, _("don't include dates in diff headers")) |
|
3106 | 3106 | ] |
|
3107 | 3107 | |
|
3108 | 3108 | diffopts2 = [ |
|
3109 | 3109 | ('p', 'show-function', None, _('show which function each change is in')), |
|
3110 | 3110 | ('w', 'ignore-all-space', None, |
|
3111 | 3111 | _('ignore white space when comparing lines')), |
|
3112 | 3112 | ('b', 'ignore-space-change', None, |
|
3113 | 3113 | _('ignore changes in the amount of white space')), |
|
3114 | 3114 | ('B', 'ignore-blank-lines', None, |
|
3115 | 3115 | _('ignore changes whose lines are all blank')), |
|
3116 | 3116 | ('U', 'unified', '', _('number of lines of context to show')) |
|
3117 | 3117 | ] |
|
3118 | 3118 | |
|
3119 | 3119 | similarityopts = [ |
|
3120 | 3120 | ('s', 'similarity', '', |
|
3121 | 3121 | _('guess renamed files by similarity (0<=s<=100)')) |
|
3122 | 3122 | ] |
|
3123 | 3123 | |
|
3124 | 3124 | table = { |
|
3125 | 3125 | "^add": (add, walkopts + dryrunopts, _('[OPTION]... [FILE]...')), |
|
3126 | 3126 | "addremove": |
|
3127 | 3127 | (addremove, similarityopts + walkopts + dryrunopts, |
|
3128 | 3128 | _('[OPTION]... [FILE]...')), |
|
3129 | 3129 | "^annotate|blame": |
|
3130 | 3130 | (annotate, |
|
3131 | 3131 | [('r', 'rev', '', _('annotate the specified revision')), |
|
3132 | 3132 | ('f', 'follow', None, _('follow file copies and renames')), |
|
3133 | 3133 | ('a', 'text', None, _('treat all files as text')), |
|
3134 | 3134 | ('u', 'user', None, _('list the author (long with -v)')), |
|
3135 | 3135 | ('d', 'date', None, _('list the date (short with -q)')), |
|
3136 | 3136 | ('n', 'number', None, _('list the revision number (default)')), |
|
3137 | 3137 | ('c', 'changeset', None, _('list the changeset')), |
|
3138 | 3138 | ('l', 'line-number', None, |
|
3139 | 3139 | _('show line number at the first appearance')) |
|
3140 | 3140 | ] + walkopts, |
|
3141 | 3141 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')), |
|
3142 | 3142 | "archive": |
|
3143 | 3143 | (archive, |
|
3144 | 3144 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
3145 | 3145 | ('p', 'prefix', '', _('directory prefix for files in archive')), |
|
3146 | 3146 | ('r', 'rev', '', _('revision to distribute')), |
|
3147 | 3147 | ('t', 'type', '', _('type of distribution to create')), |
|
3148 | 3148 | ] + walkopts, |
|
3149 | 3149 | _('[OPTION]... DEST')), |
|
3150 | 3150 | "backout": |
|
3151 | 3151 | (backout, |
|
3152 | 3152 | [('', 'merge', None, |
|
3153 | 3153 | _('merge with old dirstate parent after backout')), |
|
3154 | 3154 | ('', 'parent', '', _('parent to choose when backing out merge')), |
|
3155 | 3155 | ('r', 'rev', '', _('revision to backout')), |
|
3156 | 3156 | ] + walkopts + commitopts + commitopts2, |
|
3157 | 3157 | _('[OPTION]... [-r] REV')), |
|
3158 | 3158 | "bisect": |
|
3159 | 3159 | (bisect, |
|
3160 | 3160 | [('r', 'reset', False, _('reset bisect state')), |
|
3161 | 3161 | ('g', 'good', False, _('mark changeset good')), |
|
3162 | 3162 | ('b', 'bad', False, _('mark changeset bad')), |
|
3163 | 3163 | ('s', 'skip', False, _('skip testing changeset')), |
|
3164 | 3164 | ('c', 'command', '', _('use command to check changeset state')), |
|
3165 | 3165 | ('U', 'noupdate', False, _('do not update to target'))], |
|
3166 | 3166 | _("[-gbsr] [-c CMD] [REV]")), |
|
3167 | 3167 | "branch": |
|
3168 | 3168 | (branch, |
|
3169 | 3169 | [('f', 'force', None, |
|
3170 | 3170 | _('set branch name even if it shadows an existing branch')), |
|
3171 | 3171 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
3172 | 3172 | _('[-fC] [NAME]')), |
|
3173 | 3173 | "branches": |
|
3174 | 3174 | (branches, |
|
3175 | 3175 | [('a', 'active', False, |
|
3176 | 3176 | _('show only branches that have unmerged heads')), |
|
3177 | 3177 | ('c', 'closed', False, |
|
3178 | 3178 | _('show normal and closed heads'))], |
|
3179 | 3179 | _('[-a]')), |
|
3180 | 3180 | "bundle": |
|
3181 | 3181 | (bundle, |
|
3182 | 3182 | [('f', 'force', None, |
|
3183 | 3183 | _('run even when remote repository is unrelated')), |
|
3184 | 3184 | ('r', 'rev', [], |
|
3185 | 3185 | _('a changeset up to which you would like to bundle')), |
|
3186 | 3186 | ('', 'base', [], |
|
3187 | 3187 | _('a base changeset to specify instead of a destination')), |
|
3188 | 3188 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
3189 | 3189 | ('t', 'type', 'bzip2', _('bundle compression type to use')), |
|
3190 | 3190 | ] + remoteopts, |
|
3191 | 3191 | _('[-f] [-a] [-r REV]... [--base REV]... FILE [DEST]')), |
|
3192 | 3192 | "cat": |
|
3193 | 3193 | (cat, |
|
3194 | 3194 | [('o', 'output', '', _('print output to file with formatted name')), |
|
3195 | 3195 | ('r', 'rev', '', _('print the given revision')), |
|
3196 | 3196 | ('', 'decode', None, _('apply any matching decode filter')), |
|
3197 | 3197 | ] + walkopts, |
|
3198 | 3198 | _('[OPTION]... FILE...')), |
|
3199 | 3199 | "^clone": |
|
3200 | 3200 | (clone, |
|
3201 | 3201 | [('U', 'noupdate', None, |
|
3202 | 3202 | _('the clone will only contain a repository (no working copy)')), |
|
3203 | 3203 | ('r', 'rev', [], |
|
3204 | 3204 | _('a changeset you would like to have after cloning')), |
|
3205 | 3205 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
3206 | 3206 | ('', 'uncompressed', None, |
|
3207 | 3207 | _('use uncompressed transfer (fast over LAN)')), |
|
3208 | 3208 | ] + remoteopts, |
|
3209 | 3209 | _('[OPTION]... SOURCE [DEST]')), |
|
3210 | 3210 | "^commit|ci": |
|
3211 | 3211 | (commit, |
|
3212 | 3212 | [('A', 'addremove', None, |
|
3213 | 3213 | _('mark new/missing files as added/removed before committing')), |
|
3214 | 3214 | ('', 'close-branch', None, |
|
3215 | 3215 | _('mark a branch as closed, hiding it from the branch list')), |
|
3216 | 3216 | ] + walkopts + commitopts + commitopts2, |
|
3217 | 3217 | _('[OPTION]... [FILE]...')), |
|
3218 | 3218 | "copy|cp": |
|
3219 | 3219 | (copy, |
|
3220 | 3220 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
3221 | 3221 | ('f', 'force', None, |
|
3222 | 3222 | _('forcibly copy over an existing managed file')), |
|
3223 | 3223 | ] + walkopts + dryrunopts, |
|
3224 | 3224 | _('[OPTION]... [SOURCE]... DEST')), |
|
3225 | 3225 | "debugancestor": (debugancestor, [], _('[INDEX] REV1 REV2')), |
|
3226 | 3226 | "debugcheckstate": (debugcheckstate, []), |
|
3227 | 3227 | "debugcommands": (debugcommands, [], _('[COMMAND]')), |
|
3228 | 3228 | "debugcomplete": |
|
3229 | 3229 | (debugcomplete, |
|
3230 | 3230 | [('o', 'options', None, _('show the command options'))], |
|
3231 | 3231 | _('[-o] CMD')), |
|
3232 | 3232 | "debugdate": |
|
3233 | 3233 | (debugdate, |
|
3234 | 3234 | [('e', 'extended', None, _('try extended date formats'))], |
|
3235 | 3235 | _('[-e] DATE [RANGE]')), |
|
3236 | 3236 | "debugdata": (debugdata, [], _('FILE REV')), |
|
3237 | 3237 | "debugfsinfo": (debugfsinfo, [], _('[PATH]')), |
|
3238 | 3238 | "debugindex": (debugindex, [], _('FILE')), |
|
3239 | 3239 | "debugindexdot": (debugindexdot, [], _('FILE')), |
|
3240 | 3240 | "debuginstall": (debuginstall, []), |
|
3241 | 3241 | "debugrebuildstate": |
|
3242 | 3242 | (debugrebuildstate, |
|
3243 | 3243 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
3244 | 3244 | _('[-r REV] [REV]')), |
|
3245 | 3245 | "debugrename": |
|
3246 | 3246 | (debugrename, |
|
3247 | 3247 | [('r', 'rev', '', _('revision to debug'))], |
|
3248 | 3248 | _('[-r REV] FILE')), |
|
3249 | 3249 | "debugsetparents": |
|
3250 | 3250 | (debugsetparents, [], _('REV1 [REV2]')), |
|
3251 | 3251 | "debugstate": |
|
3252 | 3252 | (debugstate, |
|
3253 | 3253 | [('', 'nodates', None, _('do not display the saved mtime'))], |
|
3254 | 3254 | _('[OPTION]...')), |
|
3255 | 3255 | "debugsub": |
|
3256 | 3256 | (debugsub, |
|
3257 | 3257 | [('r', 'rev', '', _('revision to check'))], |
|
3258 | 3258 | _('[-r REV] [REV]')), |
|
3259 | 3259 | "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')), |
|
3260 | 3260 | "^diff": |
|
3261 | 3261 | (diff, |
|
3262 | 3262 | [('r', 'rev', [], _('revision')), |
|
3263 | 3263 | ('c', 'change', '', _('change made by revision')) |
|
3264 | 3264 | ] + diffopts + diffopts2 + walkopts, |
|
3265 | 3265 | _('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')), |
|
3266 | 3266 | "^export": |
|
3267 | 3267 | (export, |
|
3268 | 3268 | [('o', 'output', '', _('print output to file with formatted name')), |
|
3269 | 3269 | ('', 'switch-parent', None, _('diff against the second parent')) |
|
3270 | 3270 | ] + diffopts, |
|
3271 | 3271 | _('[OPTION]... [-o OUTFILESPEC] REV...')), |
|
3272 | 3272 | "^forget": |
|
3273 | 3273 | (forget, |
|
3274 | 3274 | [] + walkopts, |
|
3275 | 3275 | _('[OPTION]... FILE...')), |
|
3276 | 3276 | "grep": |
|
3277 | 3277 | (grep, |
|
3278 | 3278 | [('0', 'print0', None, _('end fields with NUL')), |
|
3279 | 3279 | ('', 'all', None, _('print all revisions that match')), |
|
3280 | 3280 | ('f', 'follow', None, |
|
3281 | 3281 | _('follow changeset history, or file history across copies and renames')), |
|
3282 | 3282 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
3283 | 3283 | ('l', 'files-with-matches', None, |
|
3284 | 3284 | _('print only filenames and revisions that match')), |
|
3285 | 3285 | ('n', 'line-number', None, _('print matching line numbers')), |
|
3286 | 3286 | ('r', 'rev', [], _('search in given revision range')), |
|
3287 | 3287 | ('u', 'user', None, _('list the author (long with -v)')), |
|
3288 | 3288 | ('d', 'date', None, _('list the date (short with -q)')), |
|
3289 | 3289 | ] + walkopts, |
|
3290 | 3290 | _('[OPTION]... PATTERN [FILE]...')), |
|
3291 | 3291 | "heads": |
|
3292 | 3292 | (heads, |
|
3293 | 3293 | [('r', 'rev', '', _('show only heads which are descendants of REV')), |
|
3294 | 3294 | ('a', 'active', False, |
|
3295 | 3295 | _('show only the active heads from open branches')), |
|
3296 | 3296 | ('c', 'closed', False, |
|
3297 | 3297 | _('show normal and closed heads')), |
|
3298 | 3298 | ] + templateopts, |
|
3299 | 3299 | _('[-r STARTREV] [REV]...')), |
|
3300 | 3300 | "help": (help_, [], _('[TOPIC]')), |
|
3301 | 3301 | "identify|id": |
|
3302 | 3302 | (identify, |
|
3303 | 3303 | [('r', 'rev', '', _('identify the specified revision')), |
|
3304 | 3304 | ('n', 'num', None, _('show local revision number')), |
|
3305 | 3305 | ('i', 'id', None, _('show global revision id')), |
|
3306 | 3306 | ('b', 'branch', None, _('show branch')), |
|
3307 | 3307 | ('t', 'tags', None, _('show tags'))], |
|
3308 | 3308 | _('[-nibt] [-r REV] [SOURCE]')), |
|
3309 | 3309 | "import|patch": |
|
3310 | 3310 | (import_, |
|
3311 | 3311 | [('p', 'strip', 1, |
|
3312 | 3312 | _('directory strip option for patch. This has the same ' |
|
3313 | 3313 | 'meaning as the corresponding patch option')), |
|
3314 | 3314 | ('b', 'base', '', _('base path')), |
|
3315 | 3315 | ('f', 'force', None, |
|
3316 | 3316 | _('skip check for outstanding uncommitted changes')), |
|
3317 | 3317 | ('', 'no-commit', None, _("don't commit, just update the working directory")), |
|
3318 | 3318 | ('', 'exact', None, |
|
3319 | 3319 | _('apply patch to the nodes from which it was generated')), |
|
3320 | 3320 | ('', 'import-branch', None, |
|
3321 | 3321 | _('use any branch information in patch (implied by --exact)'))] + |
|
3322 | 3322 | commitopts + commitopts2 + similarityopts, |
|
3323 | 3323 | _('[OPTION]... PATCH...')), |
|
3324 | 3324 | "incoming|in": |
|
3325 | 3325 | (incoming, |
|
3326 | 3326 | [('f', 'force', None, |
|
3327 | 3327 | _('run even when remote repository is unrelated')), |
|
3328 | 3328 | ('n', 'newest-first', None, _('show newest record first')), |
|
3329 | 3329 | ('', 'bundle', '', _('file to store the bundles into')), |
|
3330 | 3330 | ('r', 'rev', [], |
|
3331 | 3331 | _('a specific revision up to which you would like to pull')), |
|
3332 | 3332 | ] + logopts + remoteopts, |
|
3333 | 3333 | _('[-p] [-n] [-M] [-f] [-r REV]...' |
|
3334 | 3334 | ' [--bundle FILENAME] [SOURCE]')), |
|
3335 | 3335 | "^init": |
|
3336 | 3336 | (init, |
|
3337 | 3337 | remoteopts, |
|
3338 | 3338 | _('[-e CMD] [--remotecmd CMD] [DEST]')), |
|
3339 | 3339 | "locate": |
|
3340 | 3340 | (locate, |
|
3341 | 3341 | [('r', 'rev', '', _('search the repository as it stood at REV')), |
|
3342 | 3342 | ('0', 'print0', None, |
|
3343 | 3343 | _('end filenames with NUL, for use with xargs')), |
|
3344 | 3344 | ('f', 'fullpath', None, |
|
3345 | 3345 | _('print complete paths from the filesystem root')), |
|
3346 | 3346 | ] + walkopts, |
|
3347 | 3347 | _('[OPTION]... [PATTERN]...')), |
|
3348 | 3348 | "^log|history": |
|
3349 | 3349 | (log, |
|
3350 | 3350 | [('f', 'follow', None, |
|
3351 | 3351 | _('follow changeset history, or file history across copies and renames')), |
|
3352 | 3352 | ('', 'follow-first', None, |
|
3353 | 3353 | _('only follow the first parent of merge changesets')), |
|
3354 | 3354 | ('d', 'date', '', _('show revisions matching date spec')), |
|
3355 | 3355 | ('C', 'copies', None, _('show copied files')), |
|
3356 | 3356 | ('k', 'keyword', [], _('do case-insensitive search for a keyword')), |
|
3357 | 3357 | ('r', 'rev', [], _('show the specified revision or range')), |
|
3358 | 3358 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3359 | 3359 | ('m', 'only-merges', None, _('show only merges')), |
|
3360 | 3360 | ('u', 'user', [], _('revisions committed by user')), |
|
3361 | 3361 | ('b', 'only-branch', [], |
|
3362 | 3362 | _('show only changesets within the given named branch')), |
|
3363 | 3363 | ('P', 'prune', [], _('do not display revision or any of its ancestors')), |
|
3364 | 3364 | ] + logopts + walkopts, |
|
3365 | 3365 | _('[OPTION]... [FILE]')), |
|
3366 | 3366 | "manifest": |
|
3367 | 3367 | (manifest, |
|
3368 | 3368 | [('r', 'rev', '', _('revision to display'))], |
|
3369 | 3369 | _('[-r REV]')), |
|
3370 | 3370 | "^merge": |
|
3371 | 3371 | (merge, |
|
3372 | 3372 | [('f', 'force', None, _('force a merge with outstanding changes')), |
|
3373 | 3373 | ('r', 'rev', '', _('revision to merge')), |
|
3374 | 3374 | ('P', 'preview', None, |
|
3375 | 3375 | _('review revisions to merge (no merge is performed)'))], |
|
3376 | 3376 | _('[-f] [[-r] REV]')), |
|
3377 | 3377 | "outgoing|out": |
|
3378 | 3378 | (outgoing, |
|
3379 | 3379 | [('f', 'force', None, |
|
3380 | 3380 | _('run even when remote repository is unrelated')), |
|
3381 | 3381 | ('r', 'rev', [], |
|
3382 | 3382 | _('a specific revision up to which you would like to push')), |
|
3383 | 3383 | ('n', 'newest-first', None, _('show newest record first')), |
|
3384 | 3384 | ] + logopts + remoteopts, |
|
3385 | 3385 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')), |
|
3386 | 3386 | "^parents": |
|
3387 | 3387 | (parents, |
|
3388 | 3388 | [('r', 'rev', '', _('show parents from the specified revision')), |
|
3389 | 3389 | ] + templateopts, |
|
3390 | 3390 | _('[-r REV] [FILE]')), |
|
3391 | 3391 | "paths": (paths, [], _('[NAME]')), |
|
3392 | 3392 | "^pull": |
|
3393 | 3393 | (pull, |
|
3394 | 3394 | [('u', 'update', None, |
|
3395 | 3395 | _('update to new tip if changesets were pulled')), |
|
3396 | 3396 | ('f', 'force', None, |
|
3397 | 3397 | _('run even when remote repository is unrelated')), |
|
3398 | 3398 | ('r', 'rev', [], |
|
3399 | 3399 | _('a specific revision up to which you would like to pull')), |
|
3400 | 3400 | ] + remoteopts, |
|
3401 | 3401 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')), |
|
3402 | 3402 | "^push": |
|
3403 | 3403 | (push, |
|
3404 | 3404 | [('f', 'force', None, _('force push')), |
|
3405 | 3405 | ('r', 'rev', [], |
|
3406 | 3406 | _('a specific revision up to which you would like to push')), |
|
3407 | 3407 | ] + remoteopts, |
|
3408 | 3408 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')), |
|
3409 | 3409 | "recover": (recover, []), |
|
3410 | 3410 | "^remove|rm": |
|
3411 | 3411 | (remove, |
|
3412 | 3412 | [('A', 'after', None, _('record delete for missing files')), |
|
3413 | 3413 | ('f', 'force', None, |
|
3414 | 3414 | _('remove (and delete) file even if added or modified')), |
|
3415 | 3415 | ] + walkopts, |
|
3416 | 3416 | _('[OPTION]... FILE...')), |
|
3417 | 3417 | "rename|mv": |
|
3418 | 3418 | (rename, |
|
3419 | 3419 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3420 | 3420 | ('f', 'force', None, |
|
3421 | 3421 | _('forcibly copy over an existing managed file')), |
|
3422 | 3422 | ] + walkopts + dryrunopts, |
|
3423 | 3423 | _('[OPTION]... SOURCE... DEST')), |
|
3424 | 3424 | "resolve": |
|
3425 | 3425 | (resolve, |
|
3426 | 3426 | [('a', 'all', None, _('remerge all unresolved files')), |
|
3427 | 3427 | ('l', 'list', None, _('list state of files needing merge')), |
|
3428 | 3428 | ('m', 'mark', None, _('mark files as resolved')), |
|
3429 | 3429 | ('u', 'unmark', None, _('unmark files as resolved'))] |
|
3430 | 3430 | + walkopts, |
|
3431 | 3431 | _('[OPTION]... [FILE]...')), |
|
3432 | 3432 | "revert": |
|
3433 | 3433 | (revert, |
|
3434 | 3434 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
3435 | 3435 | ('d', 'date', '', _('tipmost revision matching date')), |
|
3436 | 3436 | ('r', 'rev', '', _('revision to revert to')), |
|
3437 | 3437 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
3438 | 3438 | ] + walkopts + dryrunopts, |
|
3439 | 3439 | _('[OPTION]... [-r REV] [NAME]...')), |
|
3440 | 3440 | "rollback": (rollback, []), |
|
3441 | 3441 | "root": (root, []), |
|
3442 | 3442 | "^serve": |
|
3443 | 3443 | (serve, |
|
3444 | 3444 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
3445 | 3445 | ('d', 'daemon', None, _('run server in background')), |
|
3446 | 3446 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
3447 | 3447 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
3448 | 3448 | ('p', 'port', 0, _('port to listen on (default: 8000)')), |
|
3449 | 3449 | ('a', 'address', '', _('address to listen on (default: all interfaces)')), |
|
3450 | 3450 | ('', 'prefix', '', _('prefix path to serve from (default: server root)')), |
|
3451 | 3451 | ('n', 'name', '', |
|
3452 | 3452 | _('name to show in web pages (default: working directory)')), |
|
3453 | 3453 | ('', 'webdir-conf', '', _('name of the webdir config file' |
|
3454 | 3454 | ' (serve more than one repository)')), |
|
3455 | 3455 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
3456 | 3456 | ('', 'stdio', None, _('for remote clients')), |
|
3457 | 3457 | ('t', 'templates', '', _('web templates to use')), |
|
3458 | 3458 | ('', 'style', '', _('template style to use')), |
|
3459 | 3459 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
3460 | 3460 | ('', 'certificate', '', _('SSL certificate file'))], |
|
3461 | 3461 | _('[OPTION]...')), |
|
3462 | 3462 | "showconfig|debugconfig": |
|
3463 | 3463 | (showconfig, |
|
3464 | 3464 | [('u', 'untrusted', None, _('show untrusted configuration options'))], |
|
3465 | 3465 | _('[-u] [NAME]...')), |
|
3466 | 3466 | "^status|st": |
|
3467 | 3467 | (status, |
|
3468 | 3468 | [('A', 'all', None, _('show status of all files')), |
|
3469 | 3469 | ('m', 'modified', None, _('show only modified files')), |
|
3470 | 3470 | ('a', 'added', None, _('show only added files')), |
|
3471 | 3471 | ('r', 'removed', None, _('show only removed files')), |
|
3472 | 3472 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
3473 | 3473 | ('c', 'clean', None, _('show only files without changes')), |
|
3474 | 3474 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
3475 | 3475 | ('i', 'ignored', None, _('show only ignored files')), |
|
3476 | 3476 | ('n', 'no-status', None, _('hide status prefix')), |
|
3477 | 3477 | ('C', 'copies', None, _('show source of copied files')), |
|
3478 | 3478 | ('0', 'print0', None, |
|
3479 | 3479 | _('end filenames with NUL, for use with xargs')), |
|
3480 | 3480 | ('', 'rev', [], _('show difference from revision')), |
|
3481 | 3481 | ] + walkopts, |
|
3482 | 3482 | _('[OPTION]... [FILE]...')), |
|
3483 | 3483 | "tag": |
|
3484 | 3484 | (tag, |
|
3485 | 3485 | [('f', 'force', None, _('replace existing tag')), |
|
3486 | 3486 | ('l', 'local', None, _('make the tag local')), |
|
3487 | 3487 | ('r', 'rev', '', _('revision to tag')), |
|
3488 | 3488 | ('', 'remove', None, _('remove a tag')), |
|
3489 | 3489 | # -l/--local is already there, commitopts cannot be used |
|
3490 | 3490 | ('m', 'message', '', _('use <text> as commit message')), |
|
3491 | 3491 | ] + commitopts2, |
|
3492 | 3492 | _('[-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')), |
|
3493 | 3493 | "tags": (tags, []), |
|
3494 | 3494 | "tip": |
|
3495 | 3495 | (tip, |
|
3496 | 3496 | [('p', 'patch', None, _('show patch')), |
|
3497 | 3497 | ('g', 'git', None, _('use git extended diff format')), |
|
3498 | 3498 | ] + templateopts, |
|
3499 | 3499 | _('[-p]')), |
|
3500 | 3500 | "unbundle": |
|
3501 | 3501 | (unbundle, |
|
3502 | 3502 | [('u', 'update', None, |
|
3503 | 3503 | _('update to new tip if changesets were unbundled'))], |
|
3504 | 3504 | _('[-u] FILE...')), |
|
3505 | 3505 | "^update|up|checkout|co": |
|
3506 | 3506 | (update, |
|
3507 | 3507 | [('C', 'clean', None, _('overwrite locally modified files (no backup)')), |
|
3508 | 3508 | ('c', 'check', None, _('check for uncommitted changes')), |
|
3509 | 3509 | ('d', 'date', '', _('tipmost revision matching date')), |
|
3510 | 3510 | ('r', 'rev', '', _('revision'))], |
|
3511 | 3511 | _('[-C] [-d DATE] [[-r] REV]')), |
|
3512 | 3512 | "verify": (verify, []), |
|
3513 | 3513 | "version": (version_, []), |
|
3514 | 3514 | } |
|
3515 | 3515 | |
|
3516 | 3516 | norepo = ("clone init version help debugcommands debugcomplete debugdata" |
|
3517 | 3517 | " debugindex debugindexdot debugdate debuginstall debugfsinfo") |
|
3518 | 3518 | optionalrepo = ("identify paths serve showconfig debugancestor") |
@@ -1,206 +1,206 | |||
|
1 | 1 | # |
|
2 | 2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | import cStringIO, zlib, tempfile, errno, os, sys, urllib |
|
9 | 9 | from mercurial import util, streamclone |
|
10 | 10 | from mercurial.node import bin, hex |
|
11 | 11 | from mercurial import changegroup as changegroupmod |
|
12 | 12 | from common import ErrorResponse, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
|
13 | 13 | |
|
14 | 14 | # __all__ is populated with the allowed commands. Be sure to add to it if |
|
15 | 15 | # you're adding a new command, or the new command won't work. |
|
16 | 16 | |
|
17 | 17 | __all__ = [ |
|
18 | 18 | 'lookup', 'heads', 'branches', 'between', 'changegroup', |
|
19 | 19 | 'changegroupsubset', 'capabilities', 'unbundle', 'stream_out', |
|
20 | 20 | 'branchmap', |
|
21 | 21 | ] |
|
22 | 22 | |
|
23 | 23 | HGTYPE = 'application/mercurial-0.1' |
|
24 | 24 | |
|
25 | 25 | def lookup(repo, req): |
|
26 | 26 | try: |
|
27 | 27 | r = hex(repo.lookup(req.form['key'][0])) |
|
28 | 28 | success = 1 |
|
29 | except Exception,inst: | |
|
29 | except Exception, inst: | |
|
30 | 30 | r = str(inst) |
|
31 | 31 | success = 0 |
|
32 | 32 | resp = "%s %s\n" % (success, r) |
|
33 | 33 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
34 | 34 | yield resp |
|
35 | 35 | |
|
36 | 36 | def heads(repo, req): |
|
37 | 37 | resp = " ".join(map(hex, repo.heads())) + "\n" |
|
38 | 38 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
39 | 39 | yield resp |
|
40 | 40 | |
|
41 | 41 | def branchmap(repo, req): |
|
42 | 42 | branches = repo.branchmap() |
|
43 | 43 | heads = [] |
|
44 | 44 | for branch, nodes in branches.iteritems(): |
|
45 | 45 | branchname = urllib.quote(branch) |
|
46 | 46 | branchnodes = [hex(node) for node in nodes] |
|
47 | 47 | heads.append('%s %s' % (branchname, ' '.join(branchnodes))) |
|
48 | 48 | resp = '\n'.join(heads) |
|
49 | 49 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
50 | 50 | yield resp |
|
51 | 51 | |
|
52 | 52 | def branches(repo, req): |
|
53 | 53 | nodes = [] |
|
54 | 54 | if 'nodes' in req.form: |
|
55 | 55 | nodes = map(bin, req.form['nodes'][0].split(" ")) |
|
56 | 56 | resp = cStringIO.StringIO() |
|
57 | 57 | for b in repo.branches(nodes): |
|
58 | 58 | resp.write(" ".join(map(hex, b)) + "\n") |
|
59 | 59 | resp = resp.getvalue() |
|
60 | 60 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
61 | 61 | yield resp |
|
62 | 62 | |
|
63 | 63 | def between(repo, req): |
|
64 | 64 | if 'pairs' in req.form: |
|
65 | 65 | pairs = [map(bin, p.split("-")) |
|
66 | 66 | for p in req.form['pairs'][0].split(" ")] |
|
67 | 67 | resp = cStringIO.StringIO() |
|
68 | 68 | for b in repo.between(pairs): |
|
69 | 69 | resp.write(" ".join(map(hex, b)) + "\n") |
|
70 | 70 | resp = resp.getvalue() |
|
71 | 71 | req.respond(HTTP_OK, HGTYPE, length=len(resp)) |
|
72 | 72 | yield resp |
|
73 | 73 | |
|
74 | 74 | def changegroup(repo, req): |
|
75 | 75 | req.respond(HTTP_OK, HGTYPE) |
|
76 | 76 | nodes = [] |
|
77 | 77 | |
|
78 | 78 | if 'roots' in req.form: |
|
79 | 79 | nodes = map(bin, req.form['roots'][0].split(" ")) |
|
80 | 80 | |
|
81 | 81 | z = zlib.compressobj() |
|
82 | 82 | f = repo.changegroup(nodes, 'serve') |
|
83 | 83 | while 1: |
|
84 | 84 | chunk = f.read(4096) |
|
85 | 85 | if not chunk: |
|
86 | 86 | break |
|
87 | 87 | yield z.compress(chunk) |
|
88 | 88 | |
|
89 | 89 | yield z.flush() |
|
90 | 90 | |
|
91 | 91 | def changegroupsubset(repo, req): |
|
92 | 92 | req.respond(HTTP_OK, HGTYPE) |
|
93 | 93 | bases = [] |
|
94 | 94 | heads = [] |
|
95 | 95 | |
|
96 | 96 | if 'bases' in req.form: |
|
97 | 97 | bases = [bin(x) for x in req.form['bases'][0].split(' ')] |
|
98 | 98 | if 'heads' in req.form: |
|
99 | 99 | heads = [bin(x) for x in req.form['heads'][0].split(' ')] |
|
100 | 100 | |
|
101 | 101 | z = zlib.compressobj() |
|
102 | 102 | f = repo.changegroupsubset(bases, heads, 'serve') |
|
103 | 103 | while 1: |
|
104 | 104 | chunk = f.read(4096) |
|
105 | 105 | if not chunk: |
|
106 | 106 | break |
|
107 | 107 | yield z.compress(chunk) |
|
108 | 108 | |
|
109 | 109 | yield z.flush() |
|
110 | 110 | |
|
111 | 111 | def capabilities(repo, req): |
|
112 | 112 | caps = ['lookup', 'changegroupsubset', 'branchmap'] |
|
113 | 113 | if repo.ui.configbool('server', 'uncompressed', untrusted=True): |
|
114 | 114 | caps.append('stream=%d' % repo.changelog.version) |
|
115 | 115 | if changegroupmod.bundlepriority: |
|
116 | 116 | caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority)) |
|
117 | 117 | rsp = ' '.join(caps) |
|
118 | 118 | req.respond(HTTP_OK, HGTYPE, length=len(rsp)) |
|
119 | 119 | yield rsp |
|
120 | 120 | |
|
121 | 121 | def unbundle(repo, req): |
|
122 | 122 | |
|
123 | 123 | proto = req.env.get('wsgi.url_scheme') or 'http' |
|
124 | 124 | their_heads = req.form['heads'][0].split(' ') |
|
125 | 125 | |
|
126 | 126 | def check_heads(): |
|
127 | 127 | heads = map(hex, repo.heads()) |
|
128 | 128 | return their_heads == [hex('force')] or their_heads == heads |
|
129 | 129 | |
|
130 | 130 | # fail early if possible |
|
131 | 131 | if not check_heads(): |
|
132 | 132 | req.drain() |
|
133 | 133 | raise ErrorResponse(HTTP_OK, 'unsynced changes') |
|
134 | 134 | |
|
135 | 135 | # do not lock repo until all changegroup data is |
|
136 | 136 | # streamed. save to temporary file. |
|
137 | 137 | |
|
138 | 138 | fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
|
139 | 139 | fp = os.fdopen(fd, 'wb+') |
|
140 | 140 | try: |
|
141 | 141 | length = int(req.env['CONTENT_LENGTH']) |
|
142 | 142 | for s in util.filechunkiter(req, limit=length): |
|
143 | 143 | fp.write(s) |
|
144 | 144 | |
|
145 | 145 | try: |
|
146 | 146 | lock = repo.lock() |
|
147 | 147 | try: |
|
148 | 148 | if not check_heads(): |
|
149 | 149 | raise ErrorResponse(HTTP_OK, 'unsynced changes') |
|
150 | 150 | |
|
151 | 151 | fp.seek(0) |
|
152 | 152 | header = fp.read(6) |
|
153 | 153 | if header.startswith('HG') and not header.startswith('HG10'): |
|
154 | 154 | raise ValueError('unknown bundle version') |
|
155 | 155 | elif header not in changegroupmod.bundletypes: |
|
156 | 156 | raise ValueError('unknown bundle compression type') |
|
157 | 157 | gen = changegroupmod.unbundle(header, fp) |
|
158 | 158 | |
|
159 | 159 | # send addchangegroup output to client |
|
160 | 160 | |
|
161 | 161 | oldio = sys.stdout, sys.stderr |
|
162 | 162 | sys.stderr = sys.stdout = cStringIO.StringIO() |
|
163 | 163 | |
|
164 | 164 | try: |
|
165 | 165 | url = 'remote:%s:%s:%s' % ( |
|
166 | 166 | proto, |
|
167 | 167 | urllib.quote(req.env.get('REMOTE_HOST', '')), |
|
168 | 168 | urllib.quote(req.env.get('REMOTE_USER', ''))) |
|
169 | 169 | try: |
|
170 | 170 | ret = repo.addchangegroup(gen, 'serve', url) |
|
171 | 171 | except util.Abort, inst: |
|
172 | 172 | sys.stdout.write("abort: %s\n" % inst) |
|
173 | 173 | ret = 0 |
|
174 | 174 | finally: |
|
175 | 175 | val = sys.stdout.getvalue() |
|
176 | 176 | sys.stdout, sys.stderr = oldio |
|
177 | 177 | req.respond(HTTP_OK, HGTYPE) |
|
178 | 178 | return '%d\n%s' % (ret, val), |
|
179 | 179 | finally: |
|
180 | 180 | lock.release() |
|
181 | 181 | except ValueError, inst: |
|
182 | 182 | raise ErrorResponse(HTTP_OK, inst) |
|
183 | 183 | except (OSError, IOError), inst: |
|
184 | 184 | filename = getattr(inst, 'filename', '') |
|
185 | 185 | # Don't send our filesystem layout to the client |
|
186 | 186 | if filename.startswith(repo.root): |
|
187 | 187 | filename = filename[len(repo.root)+1:] |
|
188 | 188 | else: |
|
189 | 189 | filename = '' |
|
190 | 190 | error = getattr(inst, 'strerror', 'Unknown error') |
|
191 | 191 | if inst.errno == errno.ENOENT: |
|
192 | 192 | code = HTTP_NOT_FOUND |
|
193 | 193 | else: |
|
194 | 194 | code = HTTP_SERVER_ERROR |
|
195 | 195 | raise ErrorResponse(code, '%s: %s' % (error, filename)) |
|
196 | 196 | finally: |
|
197 | 197 | fp.close() |
|
198 | 198 | os.unlink(tempname) |
|
199 | 199 | |
|
200 | 200 | def stream_out(repo, req): |
|
201 | 201 | req.respond(HTTP_OK, HGTYPE) |
|
202 | 202 | try: |
|
203 | 203 | for chunk in streamclone.stream_out(repo, untrusted=True): |
|
204 | 204 | yield chunk |
|
205 | 205 | except streamclone.StreamException, inst: |
|
206 | 206 | yield str(inst) |
@@ -1,690 +1,690 | |||
|
1 | 1 | # |
|
2 | 2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | import os, mimetypes, re, cgi, copy |
|
9 | 9 | import webutil |
|
10 | 10 | from mercurial import error, archival, templater, templatefilters |
|
11 | 11 | from mercurial.node import short, hex |
|
12 | 12 | from mercurial.util import binary |
|
13 | 13 | from common import paritygen, staticfile, get_contact, ErrorResponse |
|
14 | 14 | from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND |
|
15 | 15 | from mercurial import graphmod |
|
16 | 16 | |
|
17 | 17 | # __all__ is populated with the allowed commands. Be sure to add to it if |
|
18 | 18 | # you're adding a new command, or the new command won't work. |
|
19 | 19 | |
|
20 | 20 | __all__ = [ |
|
21 | 21 | 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', |
|
22 | 22 | 'manifest', 'tags', 'branches', 'summary', 'filediff', 'diff', 'annotate', |
|
23 | 23 | 'filelog', 'archive', 'static', 'graph', |
|
24 | 24 | ] |
|
25 | 25 | |
|
26 | 26 | def log(web, req, tmpl): |
|
27 | 27 | if 'file' in req.form and req.form['file'][0]: |
|
28 | 28 | return filelog(web, req, tmpl) |
|
29 | 29 | else: |
|
30 | 30 | return changelog(web, req, tmpl) |
|
31 | 31 | |
|
32 | 32 | def rawfile(web, req, tmpl): |
|
33 | 33 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
34 | 34 | if not path: |
|
35 | 35 | content = manifest(web, req, tmpl) |
|
36 | 36 | req.respond(HTTP_OK, web.ctype) |
|
37 | 37 | return content |
|
38 | 38 | |
|
39 | 39 | try: |
|
40 | 40 | fctx = webutil.filectx(web.repo, req) |
|
41 | 41 | except error.LookupError, inst: |
|
42 | 42 | try: |
|
43 | 43 | content = manifest(web, req, tmpl) |
|
44 | 44 | req.respond(HTTP_OK, web.ctype) |
|
45 | 45 | return content |
|
46 | 46 | except ErrorResponse: |
|
47 | 47 | raise inst |
|
48 | 48 | |
|
49 | 49 | path = fctx.path() |
|
50 | 50 | text = fctx.data() |
|
51 | 51 | mt = mimetypes.guess_type(path)[0] |
|
52 | 52 | if mt is None: |
|
53 | 53 | mt = binary(text) and 'application/octet-stream' or 'text/plain' |
|
54 | 54 | |
|
55 | 55 | req.respond(HTTP_OK, mt, path, len(text)) |
|
56 | 56 | return [text] |
|
57 | 57 | |
|
58 | 58 | def _filerevision(web, tmpl, fctx): |
|
59 | 59 | f = fctx.path() |
|
60 | 60 | text = fctx.data() |
|
61 | 61 | parity = paritygen(web.stripecount) |
|
62 | 62 | |
|
63 | 63 | if binary(text): |
|
64 | 64 | mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
|
65 | 65 | text = '(binary:%s)' % mt |
|
66 | 66 | |
|
67 | 67 | def lines(): |
|
68 | 68 | for lineno, t in enumerate(text.splitlines(True)): |
|
69 | 69 | yield {"line": t, |
|
70 | 70 | "lineid": "l%d" % (lineno + 1), |
|
71 | 71 | "linenumber": "% 6d" % (lineno + 1), |
|
72 | 72 | "parity": parity.next()} |
|
73 | 73 | |
|
74 | 74 | return tmpl("filerevision", |
|
75 | 75 | file=f, |
|
76 | 76 | path=webutil.up(f), |
|
77 | 77 | text=lines(), |
|
78 | 78 | rev=fctx.rev(), |
|
79 | 79 | node=hex(fctx.node()), |
|
80 | 80 | author=fctx.user(), |
|
81 | 81 | date=fctx.date(), |
|
82 | 82 | desc=fctx.description(), |
|
83 | 83 | branch=webutil.nodebranchnodefault(fctx), |
|
84 | 84 | parent=webutil.parents(fctx), |
|
85 | 85 | child=webutil.children(fctx), |
|
86 | 86 | rename=webutil.renamelink(fctx), |
|
87 | 87 | permissions=fctx.manifest().flags(f)) |
|
88 | 88 | |
|
89 | 89 | def file(web, req, tmpl): |
|
90 | 90 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
91 | 91 | if not path: |
|
92 | 92 | return manifest(web, req, tmpl) |
|
93 | 93 | try: |
|
94 | 94 | return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) |
|
95 | 95 | except error.LookupError, inst: |
|
96 | 96 | try: |
|
97 | 97 | return manifest(web, req, tmpl) |
|
98 | 98 | except ErrorResponse: |
|
99 | 99 | raise inst |
|
100 | 100 | |
|
101 | 101 | def _search(web, tmpl, query): |
|
102 | 102 | |
|
103 | 103 | def changelist(**map): |
|
104 | 104 | cl = web.repo.changelog |
|
105 | 105 | count = 0 |
|
106 | 106 | qw = query.lower().split() |
|
107 | 107 | |
|
108 | 108 | def revgen(): |
|
109 | 109 | for i in xrange(len(cl) - 1, 0, -100): |
|
110 | 110 | l = [] |
|
111 | 111 | for j in xrange(max(0, i - 100), i + 1): |
|
112 | 112 | ctx = web.repo[j] |
|
113 | 113 | l.append(ctx) |
|
114 | 114 | l.reverse() |
|
115 | 115 | for e in l: |
|
116 | 116 | yield e |
|
117 | 117 | |
|
118 | 118 | for ctx in revgen(): |
|
119 | 119 | miss = 0 |
|
120 | 120 | for q in qw: |
|
121 | 121 | if not (q in ctx.user().lower() or |
|
122 | 122 | q in ctx.description().lower() or |
|
123 | 123 | q in " ".join(ctx.files()).lower()): |
|
124 | 124 | miss = 1 |
|
125 | 125 | break |
|
126 | 126 | if miss: |
|
127 | 127 | continue |
|
128 | 128 | |
|
129 | 129 | count += 1 |
|
130 | 130 | n = ctx.node() |
|
131 | 131 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
|
132 | 132 | files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
|
133 | 133 | |
|
134 | 134 | yield tmpl('searchentry', |
|
135 | 135 | parity=parity.next(), |
|
136 | 136 | author=ctx.user(), |
|
137 | 137 | parent=webutil.parents(ctx), |
|
138 | 138 | child=webutil.children(ctx), |
|
139 | 139 | changelogtag=showtags, |
|
140 | 140 | desc=ctx.description(), |
|
141 | 141 | date=ctx.date(), |
|
142 | 142 | files=files, |
|
143 | 143 | rev=ctx.rev(), |
|
144 | 144 | node=hex(n), |
|
145 | 145 | tags=webutil.nodetagsdict(web.repo, n), |
|
146 | 146 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
147 | 147 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
148 | 148 | |
|
149 | 149 | if count >= web.maxchanges: |
|
150 | 150 | break |
|
151 | 151 | |
|
152 | 152 | cl = web.repo.changelog |
|
153 | 153 | parity = paritygen(web.stripecount) |
|
154 | 154 | |
|
155 | 155 | return tmpl('search', |
|
156 | 156 | query=query, |
|
157 | 157 | node=hex(cl.tip()), |
|
158 | 158 | entries=changelist, |
|
159 | 159 | archives=web.archivelist("tip")) |
|
160 | 160 | |
|
161 | 161 | def changelog(web, req, tmpl, shortlog = False): |
|
162 | 162 | if 'node' in req.form: |
|
163 | 163 | ctx = webutil.changectx(web.repo, req) |
|
164 | 164 | else: |
|
165 | 165 | if 'rev' in req.form: |
|
166 | 166 | hi = req.form['rev'][0] |
|
167 | 167 | else: |
|
168 | 168 | hi = len(web.repo) - 1 |
|
169 | 169 | try: |
|
170 | 170 | ctx = web.repo[hi] |
|
171 | 171 | except error.RepoError: |
|
172 | 172 | return _search(web, tmpl, hi) # XXX redirect to 404 page? |
|
173 | 173 | |
|
174 | 174 | def changelist(limit=0, **map): |
|
175 | 175 | l = [] # build a list in forward order for efficiency |
|
176 | 176 | for i in xrange(start, end): |
|
177 | 177 | ctx = web.repo[i] |
|
178 | 178 | n = ctx.node() |
|
179 | 179 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
|
180 | 180 | files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
|
181 | 181 | |
|
182 | 182 | l.insert(0, {"parity": parity.next(), |
|
183 | 183 | "author": ctx.user(), |
|
184 | 184 | "parent": webutil.parents(ctx, i - 1), |
|
185 | 185 | "child": webutil.children(ctx, i + 1), |
|
186 | 186 | "changelogtag": showtags, |
|
187 | 187 | "desc": ctx.description(), |
|
188 | 188 | "date": ctx.date(), |
|
189 | 189 | "files": files, |
|
190 | 190 | "rev": i, |
|
191 | 191 | "node": hex(n), |
|
192 | 192 | "tags": webutil.nodetagsdict(web.repo, n), |
|
193 | 193 | "inbranch": webutil.nodeinbranch(web.repo, ctx), |
|
194 | 194 | "branches": webutil.nodebranchdict(web.repo, ctx) |
|
195 | 195 | }) |
|
196 | 196 | |
|
197 | 197 | if limit > 0: |
|
198 | 198 | l = l[:limit] |
|
199 | 199 | |
|
200 | 200 | for e in l: |
|
201 | 201 | yield e |
|
202 | 202 | |
|
203 | 203 | maxchanges = shortlog and web.maxshortchanges or web.maxchanges |
|
204 | 204 | cl = web.repo.changelog |
|
205 | 205 | count = len(cl) |
|
206 | 206 | pos = ctx.rev() |
|
207 | 207 | start = max(0, pos - maxchanges + 1) |
|
208 | 208 | end = min(count, start + maxchanges) |
|
209 | 209 | pos = end - 1 |
|
210 | 210 | parity = paritygen(web.stripecount, offset=start-end) |
|
211 | 211 | |
|
212 | 212 | changenav = webutil.revnavgen(pos, maxchanges, count, web.repo.changectx) |
|
213 | 213 | |
|
214 | 214 | return tmpl(shortlog and 'shortlog' or 'changelog', |
|
215 | 215 | changenav=changenav, |
|
216 | 216 | node=hex(ctx.node()), |
|
217 | 217 | rev=pos, changesets=count, |
|
218 | 218 | entries=lambda **x: changelist(limit=0,**x), |
|
219 | 219 | latestentry=lambda **x: changelist(limit=1,**x), |
|
220 | 220 | archives=web.archivelist("tip")) |
|
221 | 221 | |
|
222 | 222 | def shortlog(web, req, tmpl): |
|
223 | 223 | return changelog(web, req, tmpl, shortlog = True) |
|
224 | 224 | |
|
225 | 225 | def changeset(web, req, tmpl): |
|
226 | 226 | ctx = webutil.changectx(web.repo, req) |
|
227 | 227 | showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node()) |
|
228 | 228 | showbranch = webutil.nodebranchnodefault(ctx) |
|
229 | 229 | |
|
230 | 230 | files = [] |
|
231 | 231 | parity = paritygen(web.stripecount) |
|
232 | 232 | for f in ctx.files(): |
|
233 | 233 | template = f in ctx and 'filenodelink' or 'filenolink' |
|
234 | 234 | files.append(tmpl(template, |
|
235 | 235 | node=ctx.hex(), file=f, |
|
236 | 236 | parity=parity.next())) |
|
237 | 237 | |
|
238 | 238 | parity = paritygen(web.stripecount) |
|
239 | 239 | diffs = webutil.diffs(web.repo, tmpl, ctx, None, parity) |
|
240 | 240 | return tmpl('changeset', |
|
241 | 241 | diff=diffs, |
|
242 | 242 | rev=ctx.rev(), |
|
243 | 243 | node=ctx.hex(), |
|
244 | 244 | parent=webutil.parents(ctx), |
|
245 | 245 | child=webutil.children(ctx), |
|
246 | 246 | changesettag=showtags, |
|
247 | 247 | changesetbranch=showbranch, |
|
248 | 248 | author=ctx.user(), |
|
249 | 249 | desc=ctx.description(), |
|
250 | 250 | date=ctx.date(), |
|
251 | 251 | files=files, |
|
252 | 252 | archives=web.archivelist(ctx.hex()), |
|
253 | 253 | tags=webutil.nodetagsdict(web.repo, ctx.node()), |
|
254 | 254 | branch=webutil.nodebranchnodefault(ctx), |
|
255 | 255 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
256 | 256 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
257 | 257 | |
|
258 | 258 | rev = changeset |
|
259 | 259 | |
|
260 | 260 | def manifest(web, req, tmpl): |
|
261 | 261 | ctx = webutil.changectx(web.repo, req) |
|
262 | 262 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
263 | 263 | mf = ctx.manifest() |
|
264 | 264 | node = ctx.node() |
|
265 | 265 | |
|
266 | 266 | files = {} |
|
267 | 267 | dirs = {} |
|
268 | 268 | parity = paritygen(web.stripecount) |
|
269 | 269 | |
|
270 | 270 | if path and path[-1] != "/": |
|
271 | 271 | path += "/" |
|
272 | 272 | l = len(path) |
|
273 | 273 | abspath = "/" + path |
|
274 | 274 | |
|
275 | 275 | for f, n in mf.iteritems(): |
|
276 | 276 | if f[:l] != path: |
|
277 | 277 | continue |
|
278 | 278 | remain = f[l:] |
|
279 | 279 | elements = remain.split('/') |
|
280 | 280 | if len(elements) == 1: |
|
281 | 281 | files[remain] = f |
|
282 | 282 | else: |
|
283 | 283 | h = dirs # need to retain ref to dirs (root) |
|
284 | 284 | for elem in elements[0:-1]: |
|
285 | 285 | if elem not in h: |
|
286 | 286 | h[elem] = {} |
|
287 | 287 | h = h[elem] |
|
288 | 288 | if len(h) > 1: |
|
289 | 289 | break |
|
290 | 290 | h[None] = None # denotes files present |
|
291 | 291 | |
|
292 | 292 | if mf and not files and not dirs: |
|
293 | 293 | raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
|
294 | 294 | |
|
295 | 295 | def filelist(**map): |
|
296 | 296 | for f in sorted(files): |
|
297 | 297 | full = files[f] |
|
298 | 298 | |
|
299 | 299 | fctx = ctx.filectx(full) |
|
300 | 300 | yield {"file": full, |
|
301 | 301 | "parity": parity.next(), |
|
302 | 302 | "basename": f, |
|
303 | 303 | "date": fctx.date(), |
|
304 | 304 | "size": fctx.size(), |
|
305 | 305 | "permissions": mf.flags(full)} |
|
306 | 306 | |
|
307 | 307 | def dirlist(**map): |
|
308 | 308 | for d in sorted(dirs): |
|
309 | 309 | |
|
310 | 310 | emptydirs = [] |
|
311 | 311 | h = dirs[d] |
|
312 | 312 | while isinstance(h, dict) and len(h) == 1: |
|
313 | 313 | k,v = h.items()[0] |
|
314 | 314 | if v: |
|
315 | 315 | emptydirs.append(k) |
|
316 | 316 | h = v |
|
317 | 317 | |
|
318 | 318 | path = "%s%s" % (abspath, d) |
|
319 | 319 | yield {"parity": parity.next(), |
|
320 | 320 | "path": path, |
|
321 | 321 | "emptydirs": "/".join(emptydirs), |
|
322 | 322 | "basename": d} |
|
323 | 323 | |
|
324 | 324 | return tmpl("manifest", |
|
325 | 325 | rev=ctx.rev(), |
|
326 | 326 | node=hex(node), |
|
327 | 327 | path=abspath, |
|
328 | 328 | up=webutil.up(abspath), |
|
329 | 329 | upparity=parity.next(), |
|
330 | 330 | fentries=filelist, |
|
331 | 331 | dentries=dirlist, |
|
332 | 332 | archives=web.archivelist(hex(node)), |
|
333 | 333 | tags=webutil.nodetagsdict(web.repo, node), |
|
334 | 334 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
335 | 335 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
336 | 336 | |
|
337 | 337 | def tags(web, req, tmpl): |
|
338 | 338 | i = web.repo.tagslist() |
|
339 | 339 | i.reverse() |
|
340 | 340 | parity = paritygen(web.stripecount) |
|
341 | 341 | |
|
342 | def entries(notip=False,limit=0, **map): | |
|
342 | def entries(notip=False, limit=0, **map): | |
|
343 | 343 | count = 0 |
|
344 | 344 | for k, n in i: |
|
345 | 345 | if notip and k == "tip": |
|
346 | 346 | continue |
|
347 | 347 | if limit > 0 and count >= limit: |
|
348 | 348 | continue |
|
349 | 349 | count = count + 1 |
|
350 | 350 | yield {"parity": parity.next(), |
|
351 | 351 | "tag": k, |
|
352 | 352 | "date": web.repo[n].date(), |
|
353 | 353 | "node": hex(n)} |
|
354 | 354 | |
|
355 | 355 | return tmpl("tags", |
|
356 | 356 | node=hex(web.repo.changelog.tip()), |
|
357 | 357 | entries=lambda **x: entries(False,0, **x), |
|
358 | 358 | entriesnotip=lambda **x: entries(True,0, **x), |
|
359 | 359 | latestentry=lambda **x: entries(True,1, **x)) |
|
360 | 360 | |
|
361 | 361 | def branches(web, req, tmpl): |
|
362 | 362 | b = web.repo.branchtags() |
|
363 | 363 | tips = (web.repo[n] for t, n in web.repo.branchtags().iteritems()) |
|
364 | 364 | heads = web.repo.heads() |
|
365 | 365 | parity = paritygen(web.stripecount) |
|
366 | 366 | sortkey = lambda ctx: ('close' not in ctx.extra(), ctx.rev()) |
|
367 | 367 | |
|
368 | 368 | def entries(limit, **map): |
|
369 | 369 | count = 0 |
|
370 | 370 | for ctx in sorted(tips, key=sortkey, reverse=True): |
|
371 | 371 | if limit > 0 and count >= limit: |
|
372 | 372 | return |
|
373 | 373 | count += 1 |
|
374 | 374 | if ctx.node() not in heads: |
|
375 | 375 | status = 'inactive' |
|
376 | 376 | elif not web.repo.branchheads(ctx.branch()): |
|
377 | 377 | status = 'closed' |
|
378 | 378 | else: |
|
379 | 379 | status = 'open' |
|
380 | 380 | yield {'parity': parity.next(), |
|
381 | 381 | 'branch': ctx.branch(), |
|
382 | 382 | 'status': status, |
|
383 | 383 | 'node': ctx.hex(), |
|
384 | 384 | 'date': ctx.date()} |
|
385 | 385 | |
|
386 | 386 | return tmpl('branches', node=hex(web.repo.changelog.tip()), |
|
387 | 387 | entries=lambda **x: entries(0, **x), |
|
388 | 388 | latestentry=lambda **x: entries(1, **x)) |
|
389 | 389 | |
|
390 | 390 | def summary(web, req, tmpl): |
|
391 | 391 | i = web.repo.tagslist() |
|
392 | 392 | i.reverse() |
|
393 | 393 | |
|
394 | 394 | def tagentries(**map): |
|
395 | 395 | parity = paritygen(web.stripecount) |
|
396 | 396 | count = 0 |
|
397 | 397 | for k, n in i: |
|
398 | 398 | if k == "tip": # skip tip |
|
399 | 399 | continue |
|
400 | 400 | |
|
401 | 401 | count += 1 |
|
402 | 402 | if count > 10: # limit to 10 tags |
|
403 | 403 | break |
|
404 | 404 | |
|
405 | 405 | yield tmpl("tagentry", |
|
406 | 406 | parity=parity.next(), |
|
407 | 407 | tag=k, |
|
408 | 408 | node=hex(n), |
|
409 | 409 | date=web.repo[n].date()) |
|
410 | 410 | |
|
411 | 411 | def branches(**map): |
|
412 | 412 | parity = paritygen(web.stripecount) |
|
413 | 413 | |
|
414 | 414 | b = web.repo.branchtags() |
|
415 | 415 | l = [(-web.repo.changelog.rev(n), n, t) for t, n in b.iteritems()] |
|
416 | 416 | for r,n,t in sorted(l): |
|
417 | 417 | yield {'parity': parity.next(), |
|
418 | 418 | 'branch': t, |
|
419 | 419 | 'node': hex(n), |
|
420 | 420 | 'date': web.repo[n].date()} |
|
421 | 421 | |
|
422 | 422 | def changelist(**map): |
|
423 | 423 | parity = paritygen(web.stripecount, offset=start-end) |
|
424 | 424 | l = [] # build a list in forward order for efficiency |
|
425 | 425 | for i in xrange(start, end): |
|
426 | 426 | ctx = web.repo[i] |
|
427 | 427 | n = ctx.node() |
|
428 | 428 | hn = hex(n) |
|
429 | 429 | |
|
430 | 430 | l.insert(0, tmpl( |
|
431 | 431 | 'shortlogentry', |
|
432 | 432 | parity=parity.next(), |
|
433 | 433 | author=ctx.user(), |
|
434 | 434 | desc=ctx.description(), |
|
435 | 435 | date=ctx.date(), |
|
436 | 436 | rev=i, |
|
437 | 437 | node=hn, |
|
438 | 438 | tags=webutil.nodetagsdict(web.repo, n), |
|
439 | 439 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
440 | 440 | branches=webutil.nodebranchdict(web.repo, ctx))) |
|
441 | 441 | |
|
442 | 442 | yield l |
|
443 | 443 | |
|
444 | 444 | cl = web.repo.changelog |
|
445 | 445 | count = len(cl) |
|
446 | 446 | start = max(0, count - web.maxchanges) |
|
447 | 447 | end = min(count, start + web.maxchanges) |
|
448 | 448 | |
|
449 | 449 | return tmpl("summary", |
|
450 | 450 | desc=web.config("web", "description", "unknown"), |
|
451 | 451 | owner=get_contact(web.config) or "unknown", |
|
452 | 452 | lastchange=cl.read(cl.tip())[2], |
|
453 | 453 | tags=tagentries, |
|
454 | 454 | branches=branches, |
|
455 | 455 | shortlog=changelist, |
|
456 | 456 | node=hex(cl.tip()), |
|
457 | 457 | archives=web.archivelist("tip")) |
|
458 | 458 | |
|
459 | 459 | def filediff(web, req, tmpl): |
|
460 | 460 | fctx, ctx = None, None |
|
461 | 461 | try: |
|
462 | 462 | fctx = webutil.filectx(web.repo, req) |
|
463 | 463 | except LookupError: |
|
464 | 464 | ctx = webutil.changectx(web.repo, req) |
|
465 | 465 | path = webutil.cleanpath(web.repo, req.form['file'][0]) |
|
466 | 466 | if path not in ctx.files(): |
|
467 | 467 | raise |
|
468 | 468 | |
|
469 | 469 | if fctx is not None: |
|
470 | 470 | n = fctx.node() |
|
471 | 471 | path = fctx.path() |
|
472 | 472 | else: |
|
473 | 473 | n = ctx.node() |
|
474 | 474 | # path already defined in except clause |
|
475 | 475 | |
|
476 | 476 | parity = paritygen(web.stripecount) |
|
477 | 477 | diffs = webutil.diffs(web.repo, tmpl, fctx or ctx, [path], parity) |
|
478 | 478 | rename = fctx and webutil.renamelink(fctx) or [] |
|
479 | 479 | ctx = fctx and fctx or ctx |
|
480 | 480 | return tmpl("filediff", |
|
481 | 481 | file=path, |
|
482 | 482 | node=hex(n), |
|
483 | 483 | rev=ctx.rev(), |
|
484 | 484 | date=ctx.date(), |
|
485 | 485 | desc=ctx.description(), |
|
486 | 486 | author=ctx.user(), |
|
487 | 487 | rename=rename, |
|
488 | 488 | branch=webutil.nodebranchnodefault(ctx), |
|
489 | 489 | parent=webutil.parents(ctx), |
|
490 | 490 | child=webutil.children(ctx), |
|
491 | 491 | diff=diffs) |
|
492 | 492 | |
|
493 | 493 | diff = filediff |
|
494 | 494 | |
|
495 | 495 | def annotate(web, req, tmpl): |
|
496 | 496 | fctx = webutil.filectx(web.repo, req) |
|
497 | 497 | f = fctx.path() |
|
498 | 498 | parity = paritygen(web.stripecount) |
|
499 | 499 | |
|
500 | 500 | def annotate(**map): |
|
501 | 501 | last = None |
|
502 | 502 | if binary(fctx.data()): |
|
503 | 503 | mt = (mimetypes.guess_type(fctx.path())[0] |
|
504 | 504 | or 'application/octet-stream') |
|
505 | 505 | lines = enumerate([((fctx.filectx(fctx.filerev()), 1), |
|
506 | 506 | '(binary:%s)' % mt)]) |
|
507 | 507 | else: |
|
508 | 508 | lines = enumerate(fctx.annotate(follow=True, linenumber=True)) |
|
509 | 509 | for lineno, ((f, targetline), l) in lines: |
|
510 | 510 | fnode = f.filenode() |
|
511 | 511 | |
|
512 | 512 | if last != fnode: |
|
513 | 513 | last = fnode |
|
514 | 514 | |
|
515 | 515 | yield {"parity": parity.next(), |
|
516 | 516 | "node": hex(f.node()), |
|
517 | 517 | "rev": f.rev(), |
|
518 | 518 | "author": f.user(), |
|
519 | 519 | "desc": f.description(), |
|
520 | 520 | "file": f.path(), |
|
521 | 521 | "targetline": targetline, |
|
522 | 522 | "line": l, |
|
523 | 523 | "lineid": "l%d" % (lineno + 1), |
|
524 | 524 | "linenumber": "% 6d" % (lineno + 1)} |
|
525 | 525 | |
|
526 | 526 | return tmpl("fileannotate", |
|
527 | 527 | file=f, |
|
528 | 528 | annotate=annotate, |
|
529 | 529 | path=webutil.up(f), |
|
530 | 530 | rev=fctx.rev(), |
|
531 | 531 | node=hex(fctx.node()), |
|
532 | 532 | author=fctx.user(), |
|
533 | 533 | date=fctx.date(), |
|
534 | 534 | desc=fctx.description(), |
|
535 | 535 | rename=webutil.renamelink(fctx), |
|
536 | 536 | branch=webutil.nodebranchnodefault(fctx), |
|
537 | 537 | parent=webutil.parents(fctx), |
|
538 | 538 | child=webutil.children(fctx), |
|
539 | 539 | permissions=fctx.manifest().flags(f)) |
|
540 | 540 | |
|
541 | 541 | def filelog(web, req, tmpl): |
|
542 | 542 | |
|
543 | 543 | try: |
|
544 | 544 | fctx = webutil.filectx(web.repo, req) |
|
545 | 545 | f = fctx.path() |
|
546 | 546 | fl = fctx.filelog() |
|
547 | 547 | except error.LookupError: |
|
548 | 548 | f = webutil.cleanpath(web.repo, req.form['file'][0]) |
|
549 | 549 | fl = web.repo.file(f) |
|
550 | 550 | numrevs = len(fl) |
|
551 | 551 | if not numrevs: # file doesn't exist at all |
|
552 | 552 | raise |
|
553 | 553 | rev = webutil.changectx(web.repo, req).rev() |
|
554 | 554 | first = fl.linkrev(0) |
|
555 | 555 | if rev < first: # current rev is from before file existed |
|
556 | 556 | raise |
|
557 | 557 | frev = numrevs - 1 |
|
558 | 558 | while fl.linkrev(frev) > rev: |
|
559 | 559 | frev -= 1 |
|
560 | 560 | fctx = web.repo.filectx(f, fl.linkrev(frev)) |
|
561 | 561 | |
|
562 | 562 | count = fctx.filerev() + 1 |
|
563 | 563 | pagelen = web.maxshortchanges |
|
564 | 564 | start = max(0, fctx.filerev() - pagelen + 1) # first rev on this page |
|
565 | 565 | end = min(count, start + pagelen) # last rev on this page |
|
566 | 566 | parity = paritygen(web.stripecount, offset=start-end) |
|
567 | 567 | |
|
568 | 568 | def entries(limit=0, **map): |
|
569 | 569 | l = [] |
|
570 | 570 | |
|
571 | 571 | repo = web.repo |
|
572 | 572 | for i in xrange(start, end): |
|
573 | 573 | iterfctx = fctx.filectx(i) |
|
574 | 574 | |
|
575 | 575 | l.insert(0, {"parity": parity.next(), |
|
576 | 576 | "filerev": i, |
|
577 | 577 | "file": f, |
|
578 | 578 | "node": hex(iterfctx.node()), |
|
579 | 579 | "author": iterfctx.user(), |
|
580 | 580 | "date": iterfctx.date(), |
|
581 | 581 | "rename": webutil.renamelink(iterfctx), |
|
582 | 582 | "parent": webutil.parents(iterfctx), |
|
583 | 583 | "child": webutil.children(iterfctx), |
|
584 | 584 | "desc": iterfctx.description(), |
|
585 | 585 | "tags": webutil.nodetagsdict(repo, iterfctx.node()), |
|
586 | 586 | "branch": webutil.nodebranchnodefault(iterfctx), |
|
587 | 587 | "inbranch": webutil.nodeinbranch(repo, iterfctx), |
|
588 | 588 | "branches": webutil.nodebranchdict(repo, iterfctx)}) |
|
589 | 589 | |
|
590 | 590 | if limit > 0: |
|
591 | 591 | l = l[:limit] |
|
592 | 592 | |
|
593 | 593 | for e in l: |
|
594 | 594 | yield e |
|
595 | 595 | |
|
596 | 596 | nodefunc = lambda x: fctx.filectx(fileid=x) |
|
597 | 597 | nav = webutil.revnavgen(end - 1, pagelen, count, nodefunc) |
|
598 | 598 | return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav, |
|
599 | 599 | entries=lambda **x: entries(limit=0, **x), |
|
600 | 600 | latestentry=lambda **x: entries(limit=1, **x)) |
|
601 | 601 | |
|
602 | 602 | |
|
603 | 603 | def archive(web, req, tmpl): |
|
604 | 604 | type_ = req.form.get('type', [None])[0] |
|
605 | 605 | allowed = web.configlist("web", "allow_archive") |
|
606 | 606 | key = req.form['node'][0] |
|
607 | 607 | |
|
608 | 608 | if type_ not in web.archives: |
|
609 | 609 | msg = 'Unsupported archive type: %s' % type_ |
|
610 | 610 | raise ErrorResponse(HTTP_NOT_FOUND, msg) |
|
611 | 611 | |
|
612 | 612 | if not ((type_ in allowed or |
|
613 | 613 | web.configbool("web", "allow" + type_, False))): |
|
614 | 614 | msg = 'Archive type not allowed: %s' % type_ |
|
615 | 615 | raise ErrorResponse(HTTP_FORBIDDEN, msg) |
|
616 | 616 | |
|
617 | 617 | reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) |
|
618 | 618 | cnode = web.repo.lookup(key) |
|
619 | 619 | arch_version = key |
|
620 | 620 | if cnode == key or key == 'tip': |
|
621 | 621 | arch_version = short(cnode) |
|
622 | 622 | name = "%s-%s" % (reponame, arch_version) |
|
623 | 623 | mimetype, artype, extension, encoding = web.archive_specs[type_] |
|
624 | 624 | headers = [ |
|
625 | 625 | ('Content-Type', mimetype), |
|
626 | 626 | ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
|
627 | 627 | ] |
|
628 | 628 | if encoding: |
|
629 | 629 | headers.append(('Content-Encoding', encoding)) |
|
630 | 630 | req.header(headers) |
|
631 | 631 | req.respond(HTTP_OK) |
|
632 | 632 | archival.archive(web.repo, req, cnode, artype, prefix=name) |
|
633 | 633 | return [] |
|
634 | 634 | |
|
635 | 635 | |
|
636 | 636 | def static(web, req, tmpl): |
|
637 | 637 | fname = req.form['file'][0] |
|
638 | 638 | # a repo owner may set web.static in .hg/hgrc to get any file |
|
639 | 639 | # readable by the user running the CGI script |
|
640 | 640 | static = web.config("web", "static", None, untrusted=False) |
|
641 | 641 | if not static: |
|
642 | 642 | tp = web.templatepath or templater.templatepath() |
|
643 | 643 | if isinstance(tp, str): |
|
644 | 644 | tp = [tp] |
|
645 | 645 | static = [os.path.join(p, 'static') for p in tp] |
|
646 | 646 | return [staticfile(static, fname, req)] |
|
647 | 647 | |
|
648 | 648 | def graph(web, req, tmpl): |
|
649 | 649 | rev = webutil.changectx(web.repo, req).rev() |
|
650 | 650 | bg_height = 39 |
|
651 | 651 | |
|
652 | 652 | revcount = 25 |
|
653 | 653 | if 'revcount' in req.form: |
|
654 | 654 | revcount = int(req.form.get('revcount', [revcount])[0]) |
|
655 | 655 | tmpl.defaults['sessionvars']['revcount'] = revcount |
|
656 | 656 | |
|
657 | 657 | lessvars = copy.copy(tmpl.defaults['sessionvars']) |
|
658 | 658 | lessvars['revcount'] = revcount / 2 |
|
659 | 659 | morevars = copy.copy(tmpl.defaults['sessionvars']) |
|
660 | 660 | morevars['revcount'] = revcount * 2 |
|
661 | 661 | |
|
662 | 662 | max_rev = len(web.repo) - 1 |
|
663 | 663 | revcount = min(max_rev, revcount) |
|
664 | 664 | revnode = web.repo.changelog.node(rev) |
|
665 | 665 | revnode_hex = hex(revnode) |
|
666 | 666 | uprev = min(max_rev, rev + revcount) |
|
667 | 667 | downrev = max(0, rev - revcount) |
|
668 | 668 | count = len(web.repo) |
|
669 | 669 | changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx) |
|
670 | 670 | |
|
671 | 671 | dag = graphmod.revisions(web.repo, rev, downrev) |
|
672 | 672 | tree = list(graphmod.colored(dag)) |
|
673 | 673 | canvasheight = (len(tree) + 1) * bg_height - 27; |
|
674 | 674 | data = [] |
|
675 | 675 | for (id, type, ctx, vtx, edges) in tree: |
|
676 | 676 | if type != graphmod.CHANGESET: |
|
677 | 677 | continue |
|
678 | 678 | node = short(ctx.node()) |
|
679 | 679 | age = templatefilters.age(ctx.date()) |
|
680 | 680 | desc = templatefilters.firstline(ctx.description()) |
|
681 | 681 | desc = cgi.escape(templatefilters.nonempty(desc)) |
|
682 | 682 | user = cgi.escape(templatefilters.person(ctx.user())) |
|
683 | 683 | branch = ctx.branch() |
|
684 | 684 | branch = branch, web.repo.branchtags().get(branch) == ctx.node() |
|
685 | 685 | data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
|
686 | 686 | |
|
687 | 687 | return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, |
|
688 | 688 | lessvars=lessvars, morevars=morevars, downrev=downrev, |
|
689 | 689 | canvasheight=canvasheight, jsdata=data, bg_height=bg_height, |
|
690 | 690 | node=revnode_hex, changenav=changenav) |
@@ -1,225 +1,225 | |||
|
1 | 1 | # sshserver.py - ssh protocol server support for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2, incorporated herein by reference. |
|
8 | 8 | |
|
9 | 9 | from i18n import _ |
|
10 | 10 | from node import bin, hex |
|
11 | 11 | import streamclone, util, hook |
|
12 | 12 | import os, sys, tempfile, urllib |
|
13 | 13 | |
|
14 | 14 | class sshserver(object): |
|
15 | 15 | def __init__(self, ui, repo): |
|
16 | 16 | self.ui = ui |
|
17 | 17 | self.repo = repo |
|
18 | 18 | self.lock = None |
|
19 | 19 | self.fin = sys.stdin |
|
20 | 20 | self.fout = sys.stdout |
|
21 | 21 | |
|
22 | 22 | hook.redirect(True) |
|
23 | 23 | sys.stdout = sys.stderr |
|
24 | 24 | |
|
25 | 25 | # Prevent insertion/deletion of CRs |
|
26 | 26 | util.set_binary(self.fin) |
|
27 | 27 | util.set_binary(self.fout) |
|
28 | 28 | |
|
29 | 29 | def getarg(self): |
|
30 | 30 | argline = self.fin.readline()[:-1] |
|
31 | 31 | arg, l = argline.split() |
|
32 | 32 | val = self.fin.read(int(l)) |
|
33 | 33 | return arg, val |
|
34 | 34 | |
|
35 | 35 | def respond(self, v): |
|
36 | 36 | self.fout.write("%d\n" % len(v)) |
|
37 | 37 | self.fout.write(v) |
|
38 | 38 | self.fout.flush() |
|
39 | 39 | |
|
40 | 40 | def serve_forever(self): |
|
41 | 41 | try: |
|
42 | 42 | while self.serve_one(): pass |
|
43 | 43 | finally: |
|
44 | 44 | if self.lock is not None: |
|
45 | 45 | self.lock.release() |
|
46 | 46 | sys.exit(0) |
|
47 | 47 | |
|
48 | 48 | def serve_one(self): |
|
49 | 49 | cmd = self.fin.readline()[:-1] |
|
50 | 50 | if cmd: |
|
51 | 51 | impl = getattr(self, 'do_' + cmd, None) |
|
52 | 52 | if impl: impl() |
|
53 | 53 | else: self.respond("") |
|
54 | 54 | return cmd != '' |
|
55 | 55 | |
|
56 | 56 | def do_lookup(self): |
|
57 | 57 | arg, key = self.getarg() |
|
58 | 58 | assert arg == 'key' |
|
59 | 59 | try: |
|
60 | 60 | r = hex(self.repo.lookup(key)) |
|
61 | 61 | success = 1 |
|
62 | except Exception,inst: | |
|
62 | except Exception, inst: | |
|
63 | 63 | r = str(inst) |
|
64 | 64 | success = 0 |
|
65 | 65 | self.respond("%s %s\n" % (success, r)) |
|
66 | 66 | |
|
67 | 67 | def do_branchmap(self): |
|
68 | 68 | branchmap = self.repo.branchmap() |
|
69 | 69 | heads = [] |
|
70 | 70 | for branch, nodes in branchmap.iteritems(): |
|
71 | 71 | branchname = urllib.quote(branch) |
|
72 | 72 | branchnodes = [hex(node) for node in nodes] |
|
73 | 73 | heads.append('%s %s' % (branchname, ' '.join(branchnodes))) |
|
74 | 74 | self.respond('\n'.join(heads)) |
|
75 | 75 | |
|
76 | 76 | def do_heads(self): |
|
77 | 77 | h = self.repo.heads() |
|
78 | 78 | self.respond(" ".join(map(hex, h)) + "\n") |
|
79 | 79 | |
|
80 | 80 | def do_hello(self): |
|
81 | 81 | '''the hello command returns a set of lines describing various |
|
82 | 82 | interesting things about the server, in an RFC822-like format. |
|
83 | 83 | Currently the only one defined is "capabilities", which |
|
84 | 84 | consists of a line in the form: |
|
85 | 85 | |
|
86 | 86 | capabilities: space separated list of tokens |
|
87 | 87 | ''' |
|
88 | 88 | |
|
89 | 89 | caps = ['unbundle', 'lookup', 'changegroupsubset', 'branchmap'] |
|
90 | 90 | if self.ui.configbool('server', 'uncompressed'): |
|
91 | 91 | caps.append('stream=%d' % self.repo.changelog.version) |
|
92 | 92 | self.respond("capabilities: %s\n" % (' '.join(caps),)) |
|
93 | 93 | |
|
94 | 94 | def do_lock(self): |
|
95 | 95 | '''DEPRECATED - allowing remote client to lock repo is not safe''' |
|
96 | 96 | |
|
97 | 97 | self.lock = self.repo.lock() |
|
98 | 98 | self.respond("") |
|
99 | 99 | |
|
100 | 100 | def do_unlock(self): |
|
101 | 101 | '''DEPRECATED''' |
|
102 | 102 | |
|
103 | 103 | if self.lock: |
|
104 | 104 | self.lock.release() |
|
105 | 105 | self.lock = None |
|
106 | 106 | self.respond("") |
|
107 | 107 | |
|
108 | 108 | def do_branches(self): |
|
109 | 109 | arg, nodes = self.getarg() |
|
110 | 110 | nodes = map(bin, nodes.split(" ")) |
|
111 | 111 | r = [] |
|
112 | 112 | for b in self.repo.branches(nodes): |
|
113 | 113 | r.append(" ".join(map(hex, b)) + "\n") |
|
114 | 114 | self.respond("".join(r)) |
|
115 | 115 | |
|
116 | 116 | def do_between(self): |
|
117 | 117 | arg, pairs = self.getarg() |
|
118 | 118 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
119 | 119 | r = [] |
|
120 | 120 | for b in self.repo.between(pairs): |
|
121 | 121 | r.append(" ".join(map(hex, b)) + "\n") |
|
122 | 122 | self.respond("".join(r)) |
|
123 | 123 | |
|
124 | 124 | def do_changegroup(self): |
|
125 | 125 | nodes = [] |
|
126 | 126 | arg, roots = self.getarg() |
|
127 | 127 | nodes = map(bin, roots.split(" ")) |
|
128 | 128 | |
|
129 | 129 | cg = self.repo.changegroup(nodes, 'serve') |
|
130 | 130 | while True: |
|
131 | 131 | d = cg.read(4096) |
|
132 | 132 | if not d: |
|
133 | 133 | break |
|
134 | 134 | self.fout.write(d) |
|
135 | 135 | |
|
136 | 136 | self.fout.flush() |
|
137 | 137 | |
|
138 | 138 | def do_changegroupsubset(self): |
|
139 | 139 | argmap = dict([self.getarg(), self.getarg()]) |
|
140 | 140 | bases = [bin(n) for n in argmap['bases'].split(' ')] |
|
141 | 141 | heads = [bin(n) for n in argmap['heads'].split(' ')] |
|
142 | 142 | |
|
143 | 143 | cg = self.repo.changegroupsubset(bases, heads, 'serve') |
|
144 | 144 | while True: |
|
145 | 145 | d = cg.read(4096) |
|
146 | 146 | if not d: |
|
147 | 147 | break |
|
148 | 148 | self.fout.write(d) |
|
149 | 149 | |
|
150 | 150 | self.fout.flush() |
|
151 | 151 | |
|
152 | 152 | def do_addchangegroup(self): |
|
153 | 153 | '''DEPRECATED''' |
|
154 | 154 | |
|
155 | 155 | if not self.lock: |
|
156 | 156 | self.respond("not locked") |
|
157 | 157 | return |
|
158 | 158 | |
|
159 | 159 | self.respond("") |
|
160 | 160 | r = self.repo.addchangegroup(self.fin, 'serve', self.client_url()) |
|
161 | 161 | self.respond(str(r)) |
|
162 | 162 | |
|
163 | 163 | def client_url(self): |
|
164 | 164 | client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0] |
|
165 | 165 | return 'remote:ssh:' + client |
|
166 | 166 | |
|
167 | 167 | def do_unbundle(self): |
|
168 | 168 | their_heads = self.getarg()[1].split() |
|
169 | 169 | |
|
170 | 170 | def check_heads(): |
|
171 | 171 | heads = map(hex, self.repo.heads()) |
|
172 | 172 | return their_heads == [hex('force')] or their_heads == heads |
|
173 | 173 | |
|
174 | 174 | # fail early if possible |
|
175 | 175 | if not check_heads(): |
|
176 | 176 | self.respond(_('unsynced changes')) |
|
177 | 177 | return |
|
178 | 178 | |
|
179 | 179 | self.respond('') |
|
180 | 180 | |
|
181 | 181 | # write bundle data to temporary file because it can be big |
|
182 | 182 | tempname = fp = None |
|
183 | 183 | try: |
|
184 | 184 | fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
|
185 | 185 | fp = os.fdopen(fd, 'wb+') |
|
186 | 186 | |
|
187 | 187 | count = int(self.fin.readline()) |
|
188 | 188 | while count: |
|
189 | 189 | fp.write(self.fin.read(count)) |
|
190 | 190 | count = int(self.fin.readline()) |
|
191 | 191 | |
|
192 | 192 | was_locked = self.lock is not None |
|
193 | 193 | if not was_locked: |
|
194 | 194 | self.lock = self.repo.lock() |
|
195 | 195 | try: |
|
196 | 196 | if not check_heads(): |
|
197 | 197 | # someone else committed/pushed/unbundled while we |
|
198 | 198 | # were transferring data |
|
199 | 199 | self.respond(_('unsynced changes')) |
|
200 | 200 | return |
|
201 | 201 | self.respond('') |
|
202 | 202 | |
|
203 | 203 | # push can proceed |
|
204 | 204 | |
|
205 | 205 | fp.seek(0) |
|
206 | 206 | r = self.repo.addchangegroup(fp, 'serve', self.client_url()) |
|
207 | 207 | self.respond(str(r)) |
|
208 | 208 | finally: |
|
209 | 209 | if not was_locked: |
|
210 | 210 | self.lock.release() |
|
211 | 211 | self.lock = None |
|
212 | 212 | finally: |
|
213 | 213 | if fp is not None: |
|
214 | 214 | fp.close() |
|
215 | 215 | if tempname is not None: |
|
216 | 216 | os.unlink(tempname) |
|
217 | 217 | |
|
218 | 218 | def do_stream_out(self): |
|
219 | 219 | try: |
|
220 | 220 | for chunk in streamclone.stream_out(self.repo): |
|
221 | 221 | self.fout.write(chunk) |
|
222 | 222 | self.fout.flush() |
|
223 | 223 | except streamclone.StreamException, inst: |
|
224 | 224 | self.fout.write(str(inst)) |
|
225 | 225 | self.fout.flush() |
@@ -1,258 +1,258 | |||
|
1 | 1 | # verify.py - repository integrity checking for Mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from node import nullid, short |
|
9 | 9 | from i18n import _ |
|
10 | 10 | import revlog, util, error |
|
11 | 11 | |
|
12 | 12 | def verify(repo): |
|
13 | 13 | lock = repo.lock() |
|
14 | 14 | try: |
|
15 | 15 | return _verify(repo) |
|
16 | 16 | finally: |
|
17 | 17 | lock.release() |
|
18 | 18 | |
|
19 | 19 | def _verify(repo): |
|
20 | 20 | mflinkrevs = {} |
|
21 | 21 | filelinkrevs = {} |
|
22 | 22 | filenodes = {} |
|
23 | 23 | revisions = 0 |
|
24 | 24 | badrevs = set() |
|
25 | 25 | errors = [0] |
|
26 | 26 | warnings = [0] |
|
27 | 27 | ui = repo.ui |
|
28 | 28 | cl = repo.changelog |
|
29 | 29 | mf = repo.manifest |
|
30 | 30 | |
|
31 | 31 | if not repo.cancopy(): |
|
32 | 32 | raise util.Abort(_("cannot verify bundle or remote repos")) |
|
33 | 33 | |
|
34 | 34 | def err(linkrev, msg, filename=None): |
|
35 | 35 | if linkrev != None: |
|
36 | 36 | badrevs.add(linkrev) |
|
37 | 37 | else: |
|
38 | 38 | linkrev = '?' |
|
39 | 39 | msg = "%s: %s" % (linkrev, msg) |
|
40 | 40 | if filename: |
|
41 | 41 | msg = "%s@%s" % (filename, msg) |
|
42 | 42 | ui.warn(" " + msg + "\n") |
|
43 | 43 | errors[0] += 1 |
|
44 | 44 | |
|
45 | 45 | def exc(linkrev, msg, inst, filename=None): |
|
46 | 46 | if isinstance(inst, KeyboardInterrupt): |
|
47 | 47 | ui.warn(_("interrupted")) |
|
48 | 48 | raise |
|
49 | 49 | err(linkrev, "%s: %s" % (msg, inst), filename) |
|
50 | 50 | |
|
51 | 51 | def warn(msg): |
|
52 | 52 | ui.warn(msg + "\n") |
|
53 | 53 | warnings[0] += 1 |
|
54 | 54 | |
|
55 | 55 | def checklog(obj, name, linkrev): |
|
56 | 56 | if not len(obj) and (havecl or havemf): |
|
57 | 57 | err(linkrev, _("empty or missing %s") % name) |
|
58 | 58 | return |
|
59 | 59 | |
|
60 | 60 | d = obj.checksize() |
|
61 | 61 | if d[0]: |
|
62 | 62 | err(None, _("data length off by %d bytes") % d[0], name) |
|
63 | 63 | if d[1]: |
|
64 | 64 | err(None, _("index contains %d extra bytes") % d[1], name) |
|
65 | 65 | |
|
66 | 66 | if obj.version != revlog.REVLOGV0: |
|
67 | 67 | if not revlogv1: |
|
68 | 68 | warn(_("warning: `%s' uses revlog format 1") % name) |
|
69 | 69 | elif revlogv1: |
|
70 | 70 | warn(_("warning: `%s' uses revlog format 0") % name) |
|
71 | 71 | |
|
72 | 72 | def checkentry(obj, i, node, seen, linkrevs, f): |
|
73 | 73 | lr = obj.linkrev(obj.rev(node)) |
|
74 | 74 | if lr < 0 or (havecl and lr not in linkrevs): |
|
75 | 75 | if lr < 0 or lr >= len(cl): |
|
76 | 76 | msg = _("rev %d points to nonexistent changeset %d") |
|
77 | 77 | else: |
|
78 | 78 | msg = _("rev %d points to unexpected changeset %d") |
|
79 | 79 | err(None, msg % (i, lr), f) |
|
80 | 80 | if linkrevs: |
|
81 | warn(_(" (expected %s)") % " ".join(map(str,linkrevs))) | |
|
81 | warn(_(" (expected %s)") % " ".join(map(str, linkrevs))) | |
|
82 | 82 | lr = None # can't be trusted |
|
83 | 83 | |
|
84 | 84 | try: |
|
85 | 85 | p1, p2 = obj.parents(node) |
|
86 | 86 | if p1 not in seen and p1 != nullid: |
|
87 | 87 | err(lr, _("unknown parent 1 %s of %s") % |
|
88 | 88 | (short(p1), short(n)), f) |
|
89 | 89 | if p2 not in seen and p2 != nullid: |
|
90 | 90 | err(lr, _("unknown parent 2 %s of %s") % |
|
91 | 91 | (short(p2), short(p1)), f) |
|
92 | 92 | except Exception, inst: |
|
93 | 93 | exc(lr, _("checking parents of %s") % short(node), inst, f) |
|
94 | 94 | |
|
95 | 95 | if node in seen: |
|
96 | 96 | err(lr, _("duplicate revision %d (%d)") % (i, seen[n]), f) |
|
97 | 97 | seen[n] = i |
|
98 | 98 | return lr |
|
99 | 99 | |
|
100 | 100 | revlogv1 = cl.version != revlog.REVLOGV0 |
|
101 | 101 | if ui.verbose or not revlogv1: |
|
102 | 102 | ui.status(_("repository uses revlog format %d\n") % |
|
103 | 103 | (revlogv1 and 1 or 0)) |
|
104 | 104 | |
|
105 | 105 | havecl = len(cl) > 0 |
|
106 | 106 | havemf = len(mf) > 0 |
|
107 | 107 | |
|
108 | 108 | ui.status(_("checking changesets\n")) |
|
109 | 109 | seen = {} |
|
110 | 110 | checklog(cl, "changelog", 0) |
|
111 | 111 | for i in repo: |
|
112 | 112 | n = cl.node(i) |
|
113 | 113 | checkentry(cl, i, n, seen, [i], "changelog") |
|
114 | 114 | |
|
115 | 115 | try: |
|
116 | 116 | changes = cl.read(n) |
|
117 | 117 | mflinkrevs.setdefault(changes[0], []).append(i) |
|
118 | 118 | for f in changes[3]: |
|
119 | 119 | filelinkrevs.setdefault(f, []).append(i) |
|
120 | 120 | except Exception, inst: |
|
121 | 121 | exc(i, _("unpacking changeset %s") % short(n), inst) |
|
122 | 122 | |
|
123 | 123 | ui.status(_("checking manifests\n")) |
|
124 | 124 | seen = {} |
|
125 | 125 | checklog(mf, "manifest", 0) |
|
126 | 126 | for i in mf: |
|
127 | 127 | n = mf.node(i) |
|
128 | 128 | lr = checkentry(mf, i, n, seen, mflinkrevs.get(n, []), "manifest") |
|
129 | 129 | if n in mflinkrevs: |
|
130 | 130 | del mflinkrevs[n] |
|
131 | 131 | else: |
|
132 | 132 | err(lr, _("%s not in changesets") % short(n), "manifest") |
|
133 | 133 | |
|
134 | 134 | try: |
|
135 | 135 | for f, fn in mf.readdelta(n).iteritems(): |
|
136 | 136 | if not f: |
|
137 | 137 | err(lr, _("file without name in manifest")) |
|
138 | 138 | elif f != "/dev/null": |
|
139 | 139 | fns = filenodes.setdefault(f, {}) |
|
140 | 140 | if fn not in fns: |
|
141 | 141 | fns[fn] = i |
|
142 | 142 | except Exception, inst: |
|
143 | 143 | exc(lr, _("reading manifest delta %s") % short(n), inst) |
|
144 | 144 | |
|
145 | 145 | ui.status(_("crosschecking files in changesets and manifests\n")) |
|
146 | 146 | |
|
147 | 147 | if havemf: |
|
148 | 148 | for c,m in sorted([(c, m) for m in mflinkrevs for c in mflinkrevs[m]]): |
|
149 | 149 | err(c, _("changeset refers to unknown manifest %s") % short(m)) |
|
150 | 150 | mflinkrevs = None # del is bad here due to scope issues |
|
151 | 151 | |
|
152 | 152 | for f in sorted(filelinkrevs): |
|
153 | 153 | if f not in filenodes: |
|
154 | 154 | lr = filelinkrevs[f][0] |
|
155 | 155 | err(lr, _("in changeset but not in manifest"), f) |
|
156 | 156 | |
|
157 | 157 | if havecl: |
|
158 | 158 | for f in sorted(filenodes): |
|
159 | 159 | if f not in filelinkrevs: |
|
160 | 160 | try: |
|
161 | 161 | fl = repo.file(f) |
|
162 | 162 | lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]]) |
|
163 | 163 | except: |
|
164 | 164 | lr = None |
|
165 | 165 | err(lr, _("in manifest but not in changeset"), f) |
|
166 | 166 | |
|
167 | 167 | ui.status(_("checking files\n")) |
|
168 | 168 | |
|
169 | 169 | storefiles = set() |
|
170 | 170 | for f, f2, size in repo.store.datafiles(): |
|
171 | 171 | if not f: |
|
172 | 172 | err(None, _("cannot decode filename '%s'") % f2) |
|
173 | 173 | elif size > 0: |
|
174 | 174 | storefiles.add(f) |
|
175 | 175 | |
|
176 | 176 | files = sorted(set(filenodes) | set(filelinkrevs)) |
|
177 | 177 | for f in files: |
|
178 | 178 | try: |
|
179 | 179 | linkrevs = filelinkrevs[f] |
|
180 | 180 | except KeyError: |
|
181 | 181 | # in manifest but not in changelog |
|
182 | 182 | linkrevs = [] |
|
183 | 183 | |
|
184 | 184 | if linkrevs: |
|
185 | 185 | lr = linkrevs[0] |
|
186 | 186 | else: |
|
187 | 187 | lr = None |
|
188 | 188 | |
|
189 | 189 | try: |
|
190 | 190 | fl = repo.file(f) |
|
191 | 191 | except error.RevlogError, e: |
|
192 | 192 | err(lr, _("broken revlog! (%s)") % e, f) |
|
193 | 193 | continue |
|
194 | 194 | |
|
195 | 195 | for ff in fl.files(): |
|
196 | 196 | try: |
|
197 | 197 | storefiles.remove(ff) |
|
198 | 198 | except KeyError: |
|
199 | 199 | err(lr, _("missing revlog!"), ff) |
|
200 | 200 | |
|
201 | 201 | checklog(fl, f, lr) |
|
202 | 202 | seen = {} |
|
203 | 203 | for i in fl: |
|
204 | 204 | revisions += 1 |
|
205 | 205 | n = fl.node(i) |
|
206 | 206 | lr = checkentry(fl, i, n, seen, linkrevs, f) |
|
207 | 207 | if f in filenodes: |
|
208 | 208 | if havemf and n not in filenodes[f]: |
|
209 | 209 | err(lr, _("%s not in manifests") % (short(n)), f) |
|
210 | 210 | else: |
|
211 | 211 | del filenodes[f][n] |
|
212 | 212 | |
|
213 | 213 | # verify contents |
|
214 | 214 | try: |
|
215 | 215 | t = fl.read(n) |
|
216 | 216 | rp = fl.renamed(n) |
|
217 | 217 | if len(t) != fl.size(i): |
|
218 | 218 | if len(fl.revision(n)) != fl.size(i): |
|
219 | 219 | err(lr, _("unpacked size is %s, %s expected") % |
|
220 | 220 | (len(t), fl.size(i)), f) |
|
221 | 221 | except Exception, inst: |
|
222 | 222 | exc(lr, _("unpacking %s") % short(n), inst, f) |
|
223 | 223 | |
|
224 | 224 | # check renames |
|
225 | 225 | try: |
|
226 | 226 | if rp: |
|
227 | 227 | fl2 = repo.file(rp[0]) |
|
228 | 228 | if not len(fl2): |
|
229 | 229 | err(lr, _("empty or missing copy source revlog %s:%s") |
|
230 | 230 | % (rp[0], short(rp[1])), f) |
|
231 | 231 | elif rp[1] == nullid: |
|
232 | 232 | ui.note(_("warning: %s@%s: copy source" |
|
233 | 233 | " revision is nullid %s:%s\n") |
|
234 | 234 | % (f, lr, rp[0], short(rp[1]))) |
|
235 | 235 | else: |
|
236 | 236 | fl2.rev(rp[1]) |
|
237 | 237 | except Exception, inst: |
|
238 | 238 | exc(lr, _("checking rename of %s") % short(n), inst, f) |
|
239 | 239 | |
|
240 | 240 | # cross-check |
|
241 | 241 | if f in filenodes: |
|
242 | 242 | fns = [(mf.linkrev(l), n) for n,l in filenodes[f].iteritems()] |
|
243 | 243 | for lr, node in sorted(fns): |
|
244 | 244 | err(lr, _("%s in manifests not found") % short(node), f) |
|
245 | 245 | |
|
246 | 246 | for f in storefiles: |
|
247 | 247 | warn(_("warning: orphan revlog '%s'") % f) |
|
248 | 248 | |
|
249 | 249 | ui.status(_("%d files, %d changesets, %d total revisions\n") % |
|
250 | 250 | (len(files), len(cl), revisions)) |
|
251 | 251 | if warnings[0]: |
|
252 | 252 | ui.warn(_("%d warnings encountered!\n") % warnings[0]) |
|
253 | 253 | if errors[0]: |
|
254 | 254 | ui.warn(_("%d integrity errors encountered!\n") % errors[0]) |
|
255 | 255 | if badrevs: |
|
256 | 256 | ui.warn(_("(first damaged changeset appears to be %d)\n") |
|
257 | 257 | % min(badrevs)) |
|
258 | 258 | return 1 |
@@ -1,144 +1,144 | |||
|
1 | 1 | # win32.py - utility functions that use win32 API |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | """Utility functions that use win32 API. |
|
9 | 9 | |
|
10 | 10 | Mark Hammond's win32all package allows better functionality on |
|
11 | 11 | Windows. This module overrides definitions in util.py. If not |
|
12 | 12 | available, import of this module will fail, and generic code will be |
|
13 | 13 | used. |
|
14 | 14 | """ |
|
15 | 15 | |
|
16 | 16 | import win32api |
|
17 | 17 | |
|
18 | 18 | import errno, os, sys, pywintypes, win32con, win32file, win32process |
|
19 | 19 | import winerror |
|
20 | 20 | import osutil, encoding |
|
21 | from win32com.shell import shell,shellcon | |
|
21 | from win32com.shell import shell, shellcon | |
|
22 | 22 | |
|
23 | 23 | def os_link(src, dst): |
|
24 | 24 | try: |
|
25 | 25 | win32file.CreateHardLink(dst, src) |
|
26 | 26 | # CreateHardLink sometimes succeeds on mapped drives but |
|
27 | 27 | # following nlinks() returns 1. Check it now and bail out. |
|
28 | 28 | if nlinks(src) < 2: |
|
29 | 29 | try: |
|
30 | 30 | win32file.DeleteFile(dst) |
|
31 | 31 | except: |
|
32 | 32 | pass |
|
33 | 33 | # Fake hardlinking error |
|
34 | 34 | raise OSError(errno.EINVAL, 'Hardlinking not supported') |
|
35 | 35 | except pywintypes.error, details: |
|
36 | 36 | raise OSError(errno.EINVAL, 'target implements hardlinks improperly') |
|
37 | 37 | except NotImplementedError: # Another fake error win Win98 |
|
38 | 38 | raise OSError(errno.EINVAL, 'Hardlinking not supported') |
|
39 | 39 | |
|
40 | 40 | def nlinks(pathname): |
|
41 | 41 | """Return number of hardlinks for the given file.""" |
|
42 | 42 | try: |
|
43 | 43 | fh = win32file.CreateFile(pathname, |
|
44 | 44 | win32file.GENERIC_READ, win32file.FILE_SHARE_READ, |
|
45 | 45 | None, win32file.OPEN_EXISTING, 0, None) |
|
46 | 46 | res = win32file.GetFileInformationByHandle(fh) |
|
47 | 47 | fh.Close() |
|
48 | 48 | return res[7] |
|
49 | 49 | except pywintypes.error: |
|
50 | 50 | return os.lstat(pathname).st_nlink |
|
51 | 51 | |
|
52 | 52 | def testpid(pid): |
|
53 | 53 | '''return True if pid is still running or unable to |
|
54 | 54 | determine, False otherwise''' |
|
55 | 55 | try: |
|
56 | 56 | handle = win32api.OpenProcess( |
|
57 | 57 | win32con.PROCESS_QUERY_INFORMATION, False, pid) |
|
58 | 58 | if handle: |
|
59 | 59 | status = win32process.GetExitCodeProcess(handle) |
|
60 | 60 | return status == win32con.STILL_ACTIVE |
|
61 | 61 | except pywintypes.error, details: |
|
62 | 62 | return details[0] != winerror.ERROR_INVALID_PARAMETER |
|
63 | 63 | return True |
|
64 | 64 | |
|
65 | 65 | def lookup_reg(key, valname=None, scope=None): |
|
66 | 66 | ''' Look up a key/value name in the Windows registry. |
|
67 | 67 | |
|
68 | 68 | valname: value name. If unspecified, the default value for the key |
|
69 | 69 | is used. |
|
70 | 70 | scope: optionally specify scope for registry lookup, this can be |
|
71 | 71 | a sequence of scopes to look up in order. Default (CURRENT_USER, |
|
72 | 72 | LOCAL_MACHINE). |
|
73 | 73 | ''' |
|
74 | 74 | try: |
|
75 | 75 | from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \ |
|
76 | 76 | QueryValueEx, OpenKey |
|
77 | 77 | except ImportError: |
|
78 | 78 | return None |
|
79 | 79 | |
|
80 | 80 | if scope is None: |
|
81 | 81 | scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE) |
|
82 | 82 | elif not isinstance(scope, (list, tuple)): |
|
83 | 83 | scope = (scope,) |
|
84 | 84 | for s in scope: |
|
85 | 85 | try: |
|
86 | 86 | val = QueryValueEx(OpenKey(s, key), valname)[0] |
|
87 | 87 | # never let a Unicode string escape into the wild |
|
88 | 88 | return encoding.tolocal(val.encode('UTF-8')) |
|
89 | 89 | except EnvironmentError: |
|
90 | 90 | pass |
|
91 | 91 | |
|
92 | 92 | def system_rcpath_win32(): |
|
93 | 93 | '''return default os-specific hgrc search path''' |
|
94 | 94 | proc = win32api.GetCurrentProcess() |
|
95 | 95 | try: |
|
96 | 96 | # This will fail on windows < NT |
|
97 | 97 | filename = win32process.GetModuleFileNameEx(proc, 0) |
|
98 | 98 | except: |
|
99 | 99 | filename = win32api.GetModuleFileName(0) |
|
100 | 100 | # Use mercurial.ini found in directory with hg.exe |
|
101 | 101 | progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
|
102 | 102 | if os.path.isfile(progrc): |
|
103 | 103 | return [progrc] |
|
104 | 104 | # else look for a system rcpath in the registry |
|
105 | 105 | try: |
|
106 | 106 | value = win32api.RegQueryValue( |
|
107 | 107 | win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Mercurial') |
|
108 | 108 | rcpath = [] |
|
109 | 109 | for p in value.split(os.pathsep): |
|
110 | 110 | if p.lower().endswith('mercurial.ini'): |
|
111 | 111 | rcpath.append(p) |
|
112 | 112 | elif os.path.isdir(p): |
|
113 | 113 | for f, kind in osutil.listdir(p): |
|
114 | 114 | if f.endswith('.rc'): |
|
115 | 115 | rcpath.append(os.path.join(p, f)) |
|
116 | 116 | return rcpath |
|
117 | 117 | except pywintypes.error: |
|
118 | 118 | return [] |
|
119 | 119 | |
|
120 | 120 | def user_rcpath_win32(): |
|
121 | 121 | '''return os-specific hgrc search path to the user dir''' |
|
122 | 122 | userdir = os.path.expanduser('~') |
|
123 | 123 | if sys.getwindowsversion()[3] != 2 and userdir == '~': |
|
124 | 124 | # We are on win < nt: fetch the APPDATA directory location and use |
|
125 | 125 | # the parent directory as the user home dir. |
|
126 | 126 | appdir = shell.SHGetPathFromIDList( |
|
127 | 127 | shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA)) |
|
128 | 128 | userdir = os.path.dirname(appdir) |
|
129 | 129 | return [os.path.join(userdir, 'mercurial.ini'), |
|
130 | 130 | os.path.join(userdir, '.hgrc')] |
|
131 | 131 | |
|
132 | 132 | def getuser(): |
|
133 | 133 | '''return name of current user''' |
|
134 | 134 | return win32api.GetUserName() |
|
135 | 135 | |
|
136 | 136 | def set_signal_handler_win32(): |
|
137 | 137 | """Register a termination handler for console events including |
|
138 | 138 | CTRL+C. python signal handlers do not work well with socket |
|
139 | 139 | operations. |
|
140 | 140 | """ |
|
141 | 141 | def handler(event): |
|
142 | 142 | win32process.ExitProcess(1) |
|
143 | 143 | win32api.SetConsoleCtrlHandler(handler) |
|
144 | 144 |
General Comments 0
You need to be logged in to leave comments.
Login now