Show More
@@ -1,3402 +1,3397 | |||
|
1 | 1 | # cmdutil.py - help for command processing in 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 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import hex, bin, nullid, nullrev, short |
|
9 | 9 | from i18n import _ |
|
10 | 10 | import os, sys, errno, re, tempfile, cStringIO |
|
11 | 11 | import util, scmutil, templater, patch, error, templatekw, revlog, copies |
|
12 | 12 | import match as matchmod |
|
13 | 13 | import repair, graphmod, revset, phases, obsolete, pathutil |
|
14 | 14 | import changelog |
|
15 | 15 | import bookmarks |
|
16 | 16 | import encoding |
|
17 | 17 | import formatter |
|
18 | 18 | import crecord as crecordmod |
|
19 | 19 | import lock as lockmod |
|
20 | 20 | |
|
21 | 21 | def ishunk(x): |
|
22 | 22 | hunkclasses = (crecordmod.uihunk, patch.recordhunk) |
|
23 | 23 | return isinstance(x, hunkclasses) |
|
24 | 24 | |
|
25 | 25 | def newandmodified(chunks, originalchunks): |
|
26 | 26 | newlyaddedandmodifiedfiles = set() |
|
27 | 27 | for chunk in chunks: |
|
28 | 28 | if ishunk(chunk) and chunk.header.isnewfile() and chunk not in \ |
|
29 | 29 | originalchunks: |
|
30 | 30 | newlyaddedandmodifiedfiles.add(chunk.header.filename()) |
|
31 | 31 | return newlyaddedandmodifiedfiles |
|
32 | 32 | |
|
33 | 33 | def parsealiases(cmd): |
|
34 | 34 | return cmd.lstrip("^").split("|") |
|
35 | 35 | |
|
36 | 36 | def setupwrapcolorwrite(ui): |
|
37 | 37 | # wrap ui.write so diff output can be labeled/colorized |
|
38 | 38 | def wrapwrite(orig, *args, **kw): |
|
39 | 39 | label = kw.pop('label', '') |
|
40 | 40 | for chunk, l in patch.difflabel(lambda: args): |
|
41 | 41 | orig(chunk, label=label + l) |
|
42 | 42 | |
|
43 | 43 | oldwrite = ui.write |
|
44 | 44 | def wrap(*args, **kwargs): |
|
45 | 45 | return wrapwrite(oldwrite, *args, **kwargs) |
|
46 | 46 | setattr(ui, 'write', wrap) |
|
47 | 47 | return oldwrite |
|
48 | 48 | |
|
49 | 49 | def filterchunks(ui, originalhunks, usecurses, testfile, operation=None): |
|
50 | 50 | if usecurses: |
|
51 | 51 | if testfile: |
|
52 | 52 | recordfn = crecordmod.testdecorator(testfile, |
|
53 | 53 | crecordmod.testchunkselector) |
|
54 | 54 | else: |
|
55 | 55 | recordfn = crecordmod.chunkselector |
|
56 | 56 | |
|
57 | 57 | return crecordmod.filterpatch(ui, originalhunks, recordfn, operation) |
|
58 | 58 | |
|
59 | 59 | else: |
|
60 | 60 | return patch.filterpatch(ui, originalhunks, operation) |
|
61 | 61 | |
|
62 | 62 | def recordfilter(ui, originalhunks, operation=None): |
|
63 | 63 | """ Prompts the user to filter the originalhunks and return a list of |
|
64 | 64 | selected hunks. |
|
65 | 65 | *operation* is used for ui purposes to indicate the user |
|
66 | 66 | what kind of filtering they are doing: reverting, committing, shelving, etc. |
|
67 | 67 | *operation* has to be a translated string. |
|
68 | 68 | """ |
|
69 | 69 | usecurses = crecordmod.checkcurses(ui) |
|
70 | 70 | testfile = ui.config('experimental', 'crecordtest', None) |
|
71 | 71 | oldwrite = setupwrapcolorwrite(ui) |
|
72 | 72 | try: |
|
73 | 73 | newchunks, newopts = filterchunks(ui, originalhunks, usecurses, |
|
74 | 74 | testfile, operation) |
|
75 | 75 | finally: |
|
76 | 76 | ui.write = oldwrite |
|
77 | 77 | return newchunks, newopts |
|
78 | 78 | |
|
79 | 79 | def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, |
|
80 | 80 | filterfn, *pats, **opts): |
|
81 | 81 | import merge as mergemod |
|
82 | 82 | |
|
83 | 83 | if not ui.interactive(): |
|
84 | 84 | if cmdsuggest: |
|
85 | 85 | msg = _('running non-interactively, use %s instead') % cmdsuggest |
|
86 | 86 | else: |
|
87 | 87 | msg = _('running non-interactively') |
|
88 | 88 | raise error.Abort(msg) |
|
89 | 89 | |
|
90 | 90 | # make sure username is set before going interactive |
|
91 | 91 | if not opts.get('user'): |
|
92 | 92 | ui.username() # raise exception, username not provided |
|
93 | 93 | |
|
94 | 94 | def recordfunc(ui, repo, message, match, opts): |
|
95 | 95 | """This is generic record driver. |
|
96 | 96 | |
|
97 | 97 | Its job is to interactively filter local changes, and |
|
98 | 98 | accordingly prepare working directory into a state in which the |
|
99 | 99 | job can be delegated to a non-interactive commit command such as |
|
100 | 100 | 'commit' or 'qrefresh'. |
|
101 | 101 | |
|
102 | 102 | After the actual job is done by non-interactive command, the |
|
103 | 103 | working directory is restored to its original state. |
|
104 | 104 | |
|
105 | 105 | In the end we'll record interesting changes, and everything else |
|
106 | 106 | will be left in place, so the user can continue working. |
|
107 | 107 | """ |
|
108 | 108 | |
|
109 | 109 | checkunfinished(repo, commit=True) |
|
110 | 110 | merge = len(repo[None].parents()) > 1 |
|
111 | 111 | if merge: |
|
112 | 112 | raise error.Abort(_('cannot partially commit a merge ' |
|
113 | 113 | '(use "hg commit" instead)')) |
|
114 | 114 | |
|
115 | 115 | status = repo.status(match=match) |
|
116 | 116 | diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True) |
|
117 | 117 | diffopts.nodates = True |
|
118 | 118 | diffopts.git = True |
|
119 | 119 | diffopts.showfunc = True |
|
120 | 120 | originaldiff = patch.diff(repo, changes=status, opts=diffopts) |
|
121 | 121 | originalchunks = patch.parsepatch(originaldiff) |
|
122 | 122 | |
|
123 | 123 | # 1. filter patch, so we have intending-to apply subset of it |
|
124 | 124 | try: |
|
125 | 125 | chunks, newopts = filterfn(ui, originalchunks) |
|
126 | 126 | except patch.PatchError as err: |
|
127 | 127 | raise error.Abort(_('error parsing patch: %s') % err) |
|
128 | 128 | opts.update(newopts) |
|
129 | 129 | |
|
130 | 130 | # We need to keep a backup of files that have been newly added and |
|
131 | 131 | # modified during the recording process because there is a previous |
|
132 | 132 | # version without the edit in the workdir |
|
133 | 133 | newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
|
134 | 134 | contenders = set() |
|
135 | 135 | for h in chunks: |
|
136 | 136 | try: |
|
137 | 137 | contenders.update(set(h.files())) |
|
138 | 138 | except AttributeError: |
|
139 | 139 | pass |
|
140 | 140 | |
|
141 | 141 | changed = status.modified + status.added + status.removed |
|
142 | 142 | newfiles = [f for f in changed if f in contenders] |
|
143 | 143 | if not newfiles: |
|
144 | 144 | ui.status(_('no changes to record\n')) |
|
145 | 145 | return 0 |
|
146 | 146 | |
|
147 | 147 | modified = set(status.modified) |
|
148 | 148 | |
|
149 | 149 | # 2. backup changed files, so we can restore them in the end |
|
150 | 150 | |
|
151 | 151 | if backupall: |
|
152 | 152 | tobackup = changed |
|
153 | 153 | else: |
|
154 | 154 | tobackup = [f for f in newfiles if f in modified or f in \ |
|
155 | 155 | newlyaddedandmodifiedfiles] |
|
156 | 156 | backups = {} |
|
157 | 157 | if tobackup: |
|
158 | 158 | backupdir = repo.join('record-backups') |
|
159 | 159 | try: |
|
160 | 160 | os.mkdir(backupdir) |
|
161 | 161 | except OSError as err: |
|
162 | 162 | if err.errno != errno.EEXIST: |
|
163 | 163 | raise |
|
164 | 164 | try: |
|
165 | 165 | # backup continues |
|
166 | 166 | for f in tobackup: |
|
167 | 167 | fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.', |
|
168 | 168 | dir=backupdir) |
|
169 | 169 | os.close(fd) |
|
170 | 170 | ui.debug('backup %r as %r\n' % (f, tmpname)) |
|
171 | 171 | util.copyfile(repo.wjoin(f), tmpname, copystat=True) |
|
172 | 172 | backups[f] = tmpname |
|
173 | 173 | |
|
174 | 174 | fp = cStringIO.StringIO() |
|
175 | 175 | for c in chunks: |
|
176 | 176 | fname = c.filename() |
|
177 | 177 | if fname in backups: |
|
178 | 178 | c.write(fp) |
|
179 | 179 | dopatch = fp.tell() |
|
180 | 180 | fp.seek(0) |
|
181 | 181 | |
|
182 | 182 | [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles] |
|
183 | 183 | # 3a. apply filtered patch to clean repo (clean) |
|
184 | 184 | if backups: |
|
185 | 185 | # Equivalent to hg.revert |
|
186 | 186 | m = scmutil.matchfiles(repo, backups.keys()) |
|
187 | 187 | mergemod.update(repo, repo.dirstate.p1(), |
|
188 | 188 | False, True, matcher=m) |
|
189 | 189 | |
|
190 | 190 | # 3b. (apply) |
|
191 | 191 | if dopatch: |
|
192 | 192 | try: |
|
193 | 193 | ui.debug('applying patch\n') |
|
194 | 194 | ui.debug(fp.getvalue()) |
|
195 | 195 | patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
|
196 | 196 | except patch.PatchError as err: |
|
197 | 197 | raise error.Abort(str(err)) |
|
198 | 198 | del fp |
|
199 | 199 | |
|
200 | 200 | # 4. We prepared working directory according to filtered |
|
201 | 201 | # patch. Now is the time to delegate the job to |
|
202 | 202 | # commit/qrefresh or the like! |
|
203 | 203 | |
|
204 | 204 | # Make all of the pathnames absolute. |
|
205 | 205 | newfiles = [repo.wjoin(nf) for nf in newfiles] |
|
206 | 206 | return commitfunc(ui, repo, *newfiles, **opts) |
|
207 | 207 | finally: |
|
208 | 208 | # 5. finally restore backed-up files |
|
209 | 209 | try: |
|
210 | 210 | dirstate = repo.dirstate |
|
211 | 211 | for realname, tmpname in backups.iteritems(): |
|
212 | 212 | ui.debug('restoring %r to %r\n' % (tmpname, realname)) |
|
213 | 213 | |
|
214 | 214 | if dirstate[realname] == 'n': |
|
215 | 215 | # without normallookup, restoring timestamp |
|
216 | 216 | # may cause partially committed files |
|
217 | 217 | # to be treated as unmodified |
|
218 | 218 | dirstate.normallookup(realname) |
|
219 | 219 | |
|
220 | 220 | # copystat=True here and above are a hack to trick any |
|
221 | 221 | # editors that have f open that we haven't modified them. |
|
222 | 222 | # |
|
223 | 223 | # Also note that this racy as an editor could notice the |
|
224 | 224 | # file's mtime before we've finished writing it. |
|
225 | 225 | util.copyfile(tmpname, repo.wjoin(realname), copystat=True) |
|
226 | 226 | os.unlink(tmpname) |
|
227 | 227 | if tobackup: |
|
228 | 228 | os.rmdir(backupdir) |
|
229 | 229 | except OSError: |
|
230 | 230 | pass |
|
231 | 231 | |
|
232 | 232 | def recordinwlock(ui, repo, message, match, opts): |
|
233 | 233 | with repo.wlock(): |
|
234 | 234 | return recordfunc(ui, repo, message, match, opts) |
|
235 | 235 | |
|
236 | 236 | return commit(ui, repo, recordinwlock, pats, opts) |
|
237 | 237 | |
|
238 | 238 | def findpossible(cmd, table, strict=False): |
|
239 | 239 | """ |
|
240 | 240 | Return cmd -> (aliases, command table entry) |
|
241 | 241 | for each matching command. |
|
242 | 242 | Return debug commands (or their aliases) only if no normal command matches. |
|
243 | 243 | """ |
|
244 | 244 | choice = {} |
|
245 | 245 | debugchoice = {} |
|
246 | 246 | |
|
247 | 247 | if cmd in table: |
|
248 | 248 | # short-circuit exact matches, "log" alias beats "^log|history" |
|
249 | 249 | keys = [cmd] |
|
250 | 250 | else: |
|
251 | 251 | keys = table.keys() |
|
252 | 252 | |
|
253 | 253 | allcmds = [] |
|
254 | 254 | for e in keys: |
|
255 | 255 | aliases = parsealiases(e) |
|
256 | 256 | allcmds.extend(aliases) |
|
257 | 257 | found = None |
|
258 | 258 | if cmd in aliases: |
|
259 | 259 | found = cmd |
|
260 | 260 | elif not strict: |
|
261 | 261 | for a in aliases: |
|
262 | 262 | if a.startswith(cmd): |
|
263 | 263 | found = a |
|
264 | 264 | break |
|
265 | 265 | if found is not None: |
|
266 | 266 | if aliases[0].startswith("debug") or found.startswith("debug"): |
|
267 | 267 | debugchoice[found] = (aliases, table[e]) |
|
268 | 268 | else: |
|
269 | 269 | choice[found] = (aliases, table[e]) |
|
270 | 270 | |
|
271 | 271 | if not choice and debugchoice: |
|
272 | 272 | choice = debugchoice |
|
273 | 273 | |
|
274 | 274 | return choice, allcmds |
|
275 | 275 | |
|
276 | 276 | def findcmd(cmd, table, strict=True): |
|
277 | 277 | """Return (aliases, command table entry) for command string.""" |
|
278 | 278 | choice, allcmds = findpossible(cmd, table, strict) |
|
279 | 279 | |
|
280 | 280 | if cmd in choice: |
|
281 | 281 | return choice[cmd] |
|
282 | 282 | |
|
283 | 283 | if len(choice) > 1: |
|
284 | 284 | clist = choice.keys() |
|
285 | 285 | clist.sort() |
|
286 | 286 | raise error.AmbiguousCommand(cmd, clist) |
|
287 | 287 | |
|
288 | 288 | if choice: |
|
289 | 289 | return choice.values()[0] |
|
290 | 290 | |
|
291 | 291 | raise error.UnknownCommand(cmd, allcmds) |
|
292 | 292 | |
|
293 | 293 | def findrepo(p): |
|
294 | 294 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
295 | 295 | oldp, p = p, os.path.dirname(p) |
|
296 | 296 | if p == oldp: |
|
297 | 297 | return None |
|
298 | 298 | |
|
299 | 299 | return p |
|
300 | 300 | |
|
301 | 301 | def bailifchanged(repo, merge=True): |
|
302 | 302 | if merge and repo.dirstate.p2() != nullid: |
|
303 | 303 | raise error.Abort(_('outstanding uncommitted merge')) |
|
304 | 304 | modified, added, removed, deleted = repo.status()[:4] |
|
305 | 305 | if modified or added or removed or deleted: |
|
306 | 306 | raise error.Abort(_('uncommitted changes')) |
|
307 | 307 | ctx = repo[None] |
|
308 | 308 | for s in sorted(ctx.substate): |
|
309 | 309 | ctx.sub(s).bailifchanged() |
|
310 | 310 | |
|
311 | 311 | def logmessage(ui, opts): |
|
312 | 312 | """ get the log message according to -m and -l option """ |
|
313 | 313 | message = opts.get('message') |
|
314 | 314 | logfile = opts.get('logfile') |
|
315 | 315 | |
|
316 | 316 | if message and logfile: |
|
317 | 317 | raise error.Abort(_('options --message and --logfile are mutually ' |
|
318 | 318 | 'exclusive')) |
|
319 | 319 | if not message and logfile: |
|
320 | 320 | try: |
|
321 | 321 | if logfile == '-': |
|
322 | 322 | message = ui.fin.read() |
|
323 | 323 | else: |
|
324 | 324 | message = '\n'.join(util.readfile(logfile).splitlines()) |
|
325 | 325 | except IOError as inst: |
|
326 | 326 | raise error.Abort(_("can't read commit message '%s': %s") % |
|
327 | 327 | (logfile, inst.strerror)) |
|
328 | 328 | return message |
|
329 | 329 | |
|
330 | 330 | def mergeeditform(ctxorbool, baseformname): |
|
331 | 331 | """return appropriate editform name (referencing a committemplate) |
|
332 | 332 | |
|
333 | 333 | 'ctxorbool' is either a ctx to be committed, or a bool indicating whether |
|
334 | 334 | merging is committed. |
|
335 | 335 | |
|
336 | 336 | This returns baseformname with '.merge' appended if it is a merge, |
|
337 | 337 | otherwise '.normal' is appended. |
|
338 | 338 | """ |
|
339 | 339 | if isinstance(ctxorbool, bool): |
|
340 | 340 | if ctxorbool: |
|
341 | 341 | return baseformname + ".merge" |
|
342 | 342 | elif 1 < len(ctxorbool.parents()): |
|
343 | 343 | return baseformname + ".merge" |
|
344 | 344 | |
|
345 | 345 | return baseformname + ".normal" |
|
346 | 346 | |
|
347 | 347 | def getcommiteditor(edit=False, finishdesc=None, extramsg=None, |
|
348 | 348 | editform='', **opts): |
|
349 | 349 | """get appropriate commit message editor according to '--edit' option |
|
350 | 350 | |
|
351 | 351 | 'finishdesc' is a function to be called with edited commit message |
|
352 | 352 | (= 'description' of the new changeset) just after editing, but |
|
353 | 353 | before checking empty-ness. It should return actual text to be |
|
354 | 354 | stored into history. This allows to change description before |
|
355 | 355 | storing. |
|
356 | 356 | |
|
357 | 357 | 'extramsg' is a extra message to be shown in the editor instead of |
|
358 | 358 | 'Leave message empty to abort commit' line. 'HG: ' prefix and EOL |
|
359 | 359 | is automatically added. |
|
360 | 360 | |
|
361 | 361 | 'editform' is a dot-separated list of names, to distinguish |
|
362 | 362 | the purpose of commit text editing. |
|
363 | 363 | |
|
364 | 364 | 'getcommiteditor' returns 'commitforceeditor' regardless of |
|
365 | 365 | 'edit', if one of 'finishdesc' or 'extramsg' is specified, because |
|
366 | 366 | they are specific for usage in MQ. |
|
367 | 367 | """ |
|
368 | 368 | if edit or finishdesc or extramsg: |
|
369 | 369 | return lambda r, c, s: commitforceeditor(r, c, s, |
|
370 | 370 | finishdesc=finishdesc, |
|
371 | 371 | extramsg=extramsg, |
|
372 | 372 | editform=editform) |
|
373 | 373 | elif editform: |
|
374 | 374 | return lambda r, c, s: commiteditor(r, c, s, editform=editform) |
|
375 | 375 | else: |
|
376 | 376 | return commiteditor |
|
377 | 377 | |
|
378 | 378 | def loglimit(opts): |
|
379 | 379 | """get the log limit according to option -l/--limit""" |
|
380 | 380 | limit = opts.get('limit') |
|
381 | 381 | if limit: |
|
382 | 382 | try: |
|
383 | 383 | limit = int(limit) |
|
384 | 384 | except ValueError: |
|
385 | 385 | raise error.Abort(_('limit must be a positive integer')) |
|
386 | 386 | if limit <= 0: |
|
387 | 387 | raise error.Abort(_('limit must be positive')) |
|
388 | 388 | else: |
|
389 | 389 | limit = None |
|
390 | 390 | return limit |
|
391 | 391 | |
|
392 | 392 | def makefilename(repo, pat, node, desc=None, |
|
393 | 393 | total=None, seqno=None, revwidth=None, pathname=None): |
|
394 | 394 | node_expander = { |
|
395 | 395 | 'H': lambda: hex(node), |
|
396 | 396 | 'R': lambda: str(repo.changelog.rev(node)), |
|
397 | 397 | 'h': lambda: short(node), |
|
398 | 398 | 'm': lambda: re.sub('[^\w]', '_', str(desc)) |
|
399 | 399 | } |
|
400 | 400 | expander = { |
|
401 | 401 | '%': lambda: '%', |
|
402 | 402 | 'b': lambda: os.path.basename(repo.root), |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | try: |
|
406 | 406 | if node: |
|
407 | 407 | expander.update(node_expander) |
|
408 | 408 | if node: |
|
409 | 409 | expander['r'] = (lambda: |
|
410 | 410 | str(repo.changelog.rev(node)).zfill(revwidth or 0)) |
|
411 | 411 | if total is not None: |
|
412 | 412 | expander['N'] = lambda: str(total) |
|
413 | 413 | if seqno is not None: |
|
414 | 414 | expander['n'] = lambda: str(seqno) |
|
415 | 415 | if total is not None and seqno is not None: |
|
416 | 416 | expander['n'] = lambda: str(seqno).zfill(len(str(total))) |
|
417 | 417 | if pathname is not None: |
|
418 | 418 | expander['s'] = lambda: os.path.basename(pathname) |
|
419 | 419 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
420 | 420 | expander['p'] = lambda: pathname |
|
421 | 421 | |
|
422 | 422 | newname = [] |
|
423 | 423 | patlen = len(pat) |
|
424 | 424 | i = 0 |
|
425 | 425 | while i < patlen: |
|
426 | 426 | c = pat[i] |
|
427 | 427 | if c == '%': |
|
428 | 428 | i += 1 |
|
429 | 429 | c = pat[i] |
|
430 | 430 | c = expander[c]() |
|
431 | 431 | newname.append(c) |
|
432 | 432 | i += 1 |
|
433 | 433 | return ''.join(newname) |
|
434 | 434 | except KeyError as inst: |
|
435 | 435 | raise error.Abort(_("invalid format spec '%%%s' in output filename") % |
|
436 | 436 | inst.args[0]) |
|
437 | 437 | |
|
438 | 438 | class _unclosablefile(object): |
|
439 | 439 | def __init__(self, fp): |
|
440 | 440 | self._fp = fp |
|
441 | 441 | |
|
442 | 442 | def close(self): |
|
443 | 443 | pass |
|
444 | 444 | |
|
445 | 445 | def __iter__(self): |
|
446 | 446 | return iter(self._fp) |
|
447 | 447 | |
|
448 | 448 | def __getattr__(self, attr): |
|
449 | 449 | return getattr(self._fp, attr) |
|
450 | 450 | |
|
451 | 451 | def makefileobj(repo, pat, node=None, desc=None, total=None, |
|
452 | 452 | seqno=None, revwidth=None, mode='wb', modemap=None, |
|
453 | 453 | pathname=None): |
|
454 | 454 | |
|
455 | 455 | writable = mode not in ('r', 'rb') |
|
456 | 456 | |
|
457 | 457 | if not pat or pat == '-': |
|
458 | 458 | if writable: |
|
459 | 459 | fp = repo.ui.fout |
|
460 | 460 | else: |
|
461 | 461 | fp = repo.ui.fin |
|
462 | 462 | return _unclosablefile(fp) |
|
463 | 463 | if util.safehasattr(pat, 'write') and writable: |
|
464 | 464 | return pat |
|
465 | 465 | if util.safehasattr(pat, 'read') and 'r' in mode: |
|
466 | 466 | return pat |
|
467 | 467 | fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname) |
|
468 | 468 | if modemap is not None: |
|
469 | 469 | mode = modemap.get(fn, mode) |
|
470 | 470 | if mode == 'wb': |
|
471 | 471 | modemap[fn] = 'ab' |
|
472 | 472 | return open(fn, mode) |
|
473 | 473 | |
|
474 | 474 | def openrevlog(repo, cmd, file_, opts): |
|
475 | 475 | """opens the changelog, manifest, a filelog or a given revlog""" |
|
476 | 476 | cl = opts['changelog'] |
|
477 | 477 | mf = opts['manifest'] |
|
478 | 478 | dir = opts['dir'] |
|
479 | 479 | msg = None |
|
480 | 480 | if cl and mf: |
|
481 | 481 | msg = _('cannot specify --changelog and --manifest at the same time') |
|
482 | 482 | elif cl and dir: |
|
483 | 483 | msg = _('cannot specify --changelog and --dir at the same time') |
|
484 | 484 | elif cl or mf: |
|
485 | 485 | if file_: |
|
486 | 486 | msg = _('cannot specify filename with --changelog or --manifest') |
|
487 | 487 | elif not repo: |
|
488 | 488 | msg = _('cannot specify --changelog or --manifest or --dir ' |
|
489 | 489 | 'without a repository') |
|
490 | 490 | if msg: |
|
491 | 491 | raise error.Abort(msg) |
|
492 | 492 | |
|
493 | 493 | r = None |
|
494 | 494 | if repo: |
|
495 | 495 | if cl: |
|
496 | 496 | r = repo.unfiltered().changelog |
|
497 | 497 | elif dir: |
|
498 | 498 | if 'treemanifest' not in repo.requirements: |
|
499 | 499 | raise error.Abort(_("--dir can only be used on repos with " |
|
500 | 500 | "treemanifest enabled")) |
|
501 | 501 | dirlog = repo.dirlog(file_) |
|
502 | 502 | if len(dirlog): |
|
503 | 503 | r = dirlog |
|
504 | 504 | elif mf: |
|
505 | 505 | r = repo.manifest |
|
506 | 506 | elif file_: |
|
507 | 507 | filelog = repo.file(file_) |
|
508 | 508 | if len(filelog): |
|
509 | 509 | r = filelog |
|
510 | 510 | if not r: |
|
511 | 511 | if not file_: |
|
512 | 512 | raise error.CommandError(cmd, _('invalid arguments')) |
|
513 | 513 | if not os.path.isfile(file_): |
|
514 | 514 | raise error.Abort(_("revlog '%s' not found") % file_) |
|
515 | 515 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), |
|
516 | 516 | file_[:-2] + ".i") |
|
517 | 517 | return r |
|
518 | 518 | |
|
519 | 519 | def copy(ui, repo, pats, opts, rename=False): |
|
520 | 520 | # called with the repo lock held |
|
521 | 521 | # |
|
522 | 522 | # hgsep => pathname that uses "/" to separate directories |
|
523 | 523 | # ossep => pathname that uses os.sep to separate directories |
|
524 | 524 | cwd = repo.getcwd() |
|
525 | 525 | targets = {} |
|
526 | 526 | after = opts.get("after") |
|
527 | 527 | dryrun = opts.get("dry_run") |
|
528 | 528 | wctx = repo[None] |
|
529 | 529 | |
|
530 | 530 | def walkpat(pat): |
|
531 | 531 | srcs = [] |
|
532 | 532 | if after: |
|
533 | 533 | badstates = '?' |
|
534 | 534 | else: |
|
535 | 535 | badstates = '?r' |
|
536 | 536 | m = scmutil.match(repo[None], [pat], opts, globbed=True) |
|
537 | 537 | for abs in repo.walk(m): |
|
538 | 538 | state = repo.dirstate[abs] |
|
539 | 539 | rel = m.rel(abs) |
|
540 | 540 | exact = m.exact(abs) |
|
541 | 541 | if state in badstates: |
|
542 | 542 | if exact and state == '?': |
|
543 | 543 | ui.warn(_('%s: not copying - file is not managed\n') % rel) |
|
544 | 544 | if exact and state == 'r': |
|
545 | 545 | ui.warn(_('%s: not copying - file has been marked for' |
|
546 | 546 | ' remove\n') % rel) |
|
547 | 547 | continue |
|
548 | 548 | # abs: hgsep |
|
549 | 549 | # rel: ossep |
|
550 | 550 | srcs.append((abs, rel, exact)) |
|
551 | 551 | return srcs |
|
552 | 552 | |
|
553 | 553 | # abssrc: hgsep |
|
554 | 554 | # relsrc: ossep |
|
555 | 555 | # otarget: ossep |
|
556 | 556 | def copyfile(abssrc, relsrc, otarget, exact): |
|
557 | 557 | abstarget = pathutil.canonpath(repo.root, cwd, otarget) |
|
558 | 558 | if '/' in abstarget: |
|
559 | 559 | # We cannot normalize abstarget itself, this would prevent |
|
560 | 560 | # case only renames, like a => A. |
|
561 | 561 | abspath, absname = abstarget.rsplit('/', 1) |
|
562 | 562 | abstarget = repo.dirstate.normalize(abspath) + '/' + absname |
|
563 | 563 | reltarget = repo.pathto(abstarget, cwd) |
|
564 | 564 | target = repo.wjoin(abstarget) |
|
565 | 565 | src = repo.wjoin(abssrc) |
|
566 | 566 | state = repo.dirstate[abstarget] |
|
567 | 567 | |
|
568 | 568 | scmutil.checkportable(ui, abstarget) |
|
569 | 569 | |
|
570 | 570 | # check for collisions |
|
571 | 571 | prevsrc = targets.get(abstarget) |
|
572 | 572 | if prevsrc is not None: |
|
573 | 573 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
574 | 574 | (reltarget, repo.pathto(abssrc, cwd), |
|
575 | 575 | repo.pathto(prevsrc, cwd))) |
|
576 | 576 | return |
|
577 | 577 | |
|
578 | 578 | # check for overwrites |
|
579 | 579 | exists = os.path.lexists(target) |
|
580 | 580 | samefile = False |
|
581 | 581 | if exists and abssrc != abstarget: |
|
582 | 582 | if (repo.dirstate.normalize(abssrc) == |
|
583 | 583 | repo.dirstate.normalize(abstarget)): |
|
584 | 584 | if not rename: |
|
585 | 585 | ui.warn(_("%s: can't copy - same file\n") % reltarget) |
|
586 | 586 | return |
|
587 | 587 | exists = False |
|
588 | 588 | samefile = True |
|
589 | 589 | |
|
590 | 590 | if not after and exists or after and state in 'mn': |
|
591 | 591 | if not opts['force']: |
|
592 | 592 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
593 | 593 | reltarget) |
|
594 | 594 | return |
|
595 | 595 | |
|
596 | 596 | if after: |
|
597 | 597 | if not exists: |
|
598 | 598 | if rename: |
|
599 | 599 | ui.warn(_('%s: not recording move - %s does not exist\n') % |
|
600 | 600 | (relsrc, reltarget)) |
|
601 | 601 | else: |
|
602 | 602 | ui.warn(_('%s: not recording copy - %s does not exist\n') % |
|
603 | 603 | (relsrc, reltarget)) |
|
604 | 604 | return |
|
605 | 605 | elif not dryrun: |
|
606 | 606 | try: |
|
607 | 607 | if exists: |
|
608 | 608 | os.unlink(target) |
|
609 | 609 | targetdir = os.path.dirname(target) or '.' |
|
610 | 610 | if not os.path.isdir(targetdir): |
|
611 | 611 | os.makedirs(targetdir) |
|
612 | 612 | if samefile: |
|
613 | 613 | tmp = target + "~hgrename" |
|
614 | 614 | os.rename(src, tmp) |
|
615 | 615 | os.rename(tmp, target) |
|
616 | 616 | else: |
|
617 | 617 | util.copyfile(src, target) |
|
618 | 618 | srcexists = True |
|
619 | 619 | except IOError as inst: |
|
620 | 620 | if inst.errno == errno.ENOENT: |
|
621 | 621 | ui.warn(_('%s: deleted in working directory\n') % relsrc) |
|
622 | 622 | srcexists = False |
|
623 | 623 | else: |
|
624 | 624 | ui.warn(_('%s: cannot copy - %s\n') % |
|
625 | 625 | (relsrc, inst.strerror)) |
|
626 | 626 | return True # report a failure |
|
627 | 627 | |
|
628 | 628 | if ui.verbose or not exact: |
|
629 | 629 | if rename: |
|
630 | 630 | ui.status(_('moving %s to %s\n') % (relsrc, reltarget)) |
|
631 | 631 | else: |
|
632 | 632 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
633 | 633 | |
|
634 | 634 | targets[abstarget] = abssrc |
|
635 | 635 | |
|
636 | 636 | # fix up dirstate |
|
637 | 637 | scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget, |
|
638 | 638 | dryrun=dryrun, cwd=cwd) |
|
639 | 639 | if rename and not dryrun: |
|
640 | 640 | if not after and srcexists and not samefile: |
|
641 | 641 | util.unlinkpath(repo.wjoin(abssrc)) |
|
642 | 642 | wctx.forget([abssrc]) |
|
643 | 643 | |
|
644 | 644 | # pat: ossep |
|
645 | 645 | # dest ossep |
|
646 | 646 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
647 | 647 | # return: function that takes hgsep and returns ossep |
|
648 | 648 | def targetpathfn(pat, dest, srcs): |
|
649 | 649 | if os.path.isdir(pat): |
|
650 | 650 | abspfx = pathutil.canonpath(repo.root, cwd, pat) |
|
651 | 651 | abspfx = util.localpath(abspfx) |
|
652 | 652 | if destdirexists: |
|
653 | 653 | striplen = len(os.path.split(abspfx)[0]) |
|
654 | 654 | else: |
|
655 | 655 | striplen = len(abspfx) |
|
656 | 656 | if striplen: |
|
657 | 657 | striplen += len(os.sep) |
|
658 | 658 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
|
659 | 659 | elif destdirexists: |
|
660 | 660 | res = lambda p: os.path.join(dest, |
|
661 | 661 | os.path.basename(util.localpath(p))) |
|
662 | 662 | else: |
|
663 | 663 | res = lambda p: dest |
|
664 | 664 | return res |
|
665 | 665 | |
|
666 | 666 | # pat: ossep |
|
667 | 667 | # dest ossep |
|
668 | 668 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
669 | 669 | # return: function that takes hgsep and returns ossep |
|
670 | 670 | def targetpathafterfn(pat, dest, srcs): |
|
671 | 671 | if matchmod.patkind(pat): |
|
672 | 672 | # a mercurial pattern |
|
673 | 673 | res = lambda p: os.path.join(dest, |
|
674 | 674 | os.path.basename(util.localpath(p))) |
|
675 | 675 | else: |
|
676 | 676 | abspfx = pathutil.canonpath(repo.root, cwd, pat) |
|
677 | 677 | if len(abspfx) < len(srcs[0][0]): |
|
678 | 678 | # A directory. Either the target path contains the last |
|
679 | 679 | # component of the source path or it does not. |
|
680 | 680 | def evalpath(striplen): |
|
681 | 681 | score = 0 |
|
682 | 682 | for s in srcs: |
|
683 | 683 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
|
684 | 684 | if os.path.lexists(t): |
|
685 | 685 | score += 1 |
|
686 | 686 | return score |
|
687 | 687 | |
|
688 | 688 | abspfx = util.localpath(abspfx) |
|
689 | 689 | striplen = len(abspfx) |
|
690 | 690 | if striplen: |
|
691 | 691 | striplen += len(os.sep) |
|
692 | 692 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
693 | 693 | score = evalpath(striplen) |
|
694 | 694 | striplen1 = len(os.path.split(abspfx)[0]) |
|
695 | 695 | if striplen1: |
|
696 | 696 | striplen1 += len(os.sep) |
|
697 | 697 | if evalpath(striplen1) > score: |
|
698 | 698 | striplen = striplen1 |
|
699 | 699 | res = lambda p: os.path.join(dest, |
|
700 | 700 | util.localpath(p)[striplen:]) |
|
701 | 701 | else: |
|
702 | 702 | # a file |
|
703 | 703 | if destdirexists: |
|
704 | 704 | res = lambda p: os.path.join(dest, |
|
705 | 705 | os.path.basename(util.localpath(p))) |
|
706 | 706 | else: |
|
707 | 707 | res = lambda p: dest |
|
708 | 708 | return res |
|
709 | 709 | |
|
710 | 710 | pats = scmutil.expandpats(pats) |
|
711 | 711 | if not pats: |
|
712 | 712 | raise error.Abort(_('no source or destination specified')) |
|
713 | 713 | if len(pats) == 1: |
|
714 | 714 | raise error.Abort(_('no destination specified')) |
|
715 | 715 | dest = pats.pop() |
|
716 | 716 | destdirexists = os.path.isdir(dest) and not os.path.islink(dest) |
|
717 | 717 | if not destdirexists: |
|
718 | 718 | if len(pats) > 1 or matchmod.patkind(pats[0]): |
|
719 | 719 | raise error.Abort(_('with multiple sources, destination must be an ' |
|
720 | 720 | 'existing directory')) |
|
721 | 721 | if util.endswithsep(dest): |
|
722 | 722 | raise error.Abort(_('destination %s is not a directory') % dest) |
|
723 | 723 | |
|
724 | 724 | tfn = targetpathfn |
|
725 | 725 | if after: |
|
726 | 726 | tfn = targetpathafterfn |
|
727 | 727 | copylist = [] |
|
728 | 728 | for pat in pats: |
|
729 | 729 | srcs = walkpat(pat) |
|
730 | 730 | if not srcs: |
|
731 | 731 | continue |
|
732 | 732 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
733 | 733 | if not copylist: |
|
734 | 734 | raise error.Abort(_('no files to copy')) |
|
735 | 735 | |
|
736 | 736 | errors = 0 |
|
737 | 737 | for targetpath, srcs in copylist: |
|
738 | 738 | for abssrc, relsrc, exact in srcs: |
|
739 | 739 | if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
|
740 | 740 | errors += 1 |
|
741 | 741 | |
|
742 | 742 | if errors: |
|
743 | 743 | ui.warn(_('(consider using --after)\n')) |
|
744 | 744 | |
|
745 | 745 | return errors != 0 |
|
746 | 746 | |
|
747 | 747 | def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
|
748 | 748 | runargs=None, appendpid=False): |
|
749 | 749 | '''Run a command as a service.''' |
|
750 | 750 | |
|
751 | 751 | def writepid(pid): |
|
752 | 752 | if opts['pid_file']: |
|
753 | 753 | if appendpid: |
|
754 | 754 | mode = 'a' |
|
755 | 755 | else: |
|
756 | 756 | mode = 'w' |
|
757 | 757 | fp = open(opts['pid_file'], mode) |
|
758 | 758 | fp.write(str(pid) + '\n') |
|
759 | 759 | fp.close() |
|
760 | 760 | |
|
761 | 761 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
762 | 762 | # Signal child process startup with file removal |
|
763 | 763 | lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') |
|
764 | 764 | os.close(lockfd) |
|
765 | 765 | try: |
|
766 | 766 | if not runargs: |
|
767 | 767 | runargs = util.hgcmd() + sys.argv[1:] |
|
768 | 768 | runargs.append('--daemon-pipefds=%s' % lockpath) |
|
769 | 769 | # Don't pass --cwd to the child process, because we've already |
|
770 | 770 | # changed directory. |
|
771 | 771 | for i in xrange(1, len(runargs)): |
|
772 | 772 | if runargs[i].startswith('--cwd='): |
|
773 | 773 | del runargs[i] |
|
774 | 774 | break |
|
775 | 775 | elif runargs[i].startswith('--cwd'): |
|
776 | 776 | del runargs[i:i + 2] |
|
777 | 777 | break |
|
778 | 778 | def condfn(): |
|
779 | 779 | return not os.path.exists(lockpath) |
|
780 | 780 | pid = util.rundetached(runargs, condfn) |
|
781 | 781 | if pid < 0: |
|
782 | 782 | raise error.Abort(_('child process failed to start')) |
|
783 | 783 | writepid(pid) |
|
784 | 784 | finally: |
|
785 | 785 | try: |
|
786 | 786 | os.unlink(lockpath) |
|
787 | 787 | except OSError as e: |
|
788 | 788 | if e.errno != errno.ENOENT: |
|
789 | 789 | raise |
|
790 | 790 | if parentfn: |
|
791 | 791 | return parentfn(pid) |
|
792 | 792 | else: |
|
793 | 793 | return |
|
794 | 794 | |
|
795 | 795 | if initfn: |
|
796 | 796 | initfn() |
|
797 | 797 | |
|
798 | 798 | if not opts['daemon']: |
|
799 | 799 | writepid(os.getpid()) |
|
800 | 800 | |
|
801 | 801 | if opts['daemon_pipefds']: |
|
802 | 802 | lockpath = opts['daemon_pipefds'] |
|
803 | 803 | try: |
|
804 | 804 | os.setsid() |
|
805 | 805 | except AttributeError: |
|
806 | 806 | pass |
|
807 | 807 | os.unlink(lockpath) |
|
808 | 808 | util.hidewindow() |
|
809 | 809 | sys.stdout.flush() |
|
810 | 810 | sys.stderr.flush() |
|
811 | 811 | |
|
812 | 812 | nullfd = os.open(os.devnull, os.O_RDWR) |
|
813 | 813 | logfilefd = nullfd |
|
814 | 814 | if logfile: |
|
815 | 815 | logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND) |
|
816 | 816 | os.dup2(nullfd, 0) |
|
817 | 817 | os.dup2(logfilefd, 1) |
|
818 | 818 | os.dup2(logfilefd, 2) |
|
819 | 819 | if nullfd not in (0, 1, 2): |
|
820 | 820 | os.close(nullfd) |
|
821 | 821 | if logfile and logfilefd not in (0, 1, 2): |
|
822 | 822 | os.close(logfilefd) |
|
823 | 823 | |
|
824 | 824 | if runfn: |
|
825 | 825 | return runfn() |
|
826 | 826 | |
|
827 | 827 | ## facility to let extension process additional data into an import patch |
|
828 | 828 | # list of identifier to be executed in order |
|
829 | 829 | extrapreimport = [] # run before commit |
|
830 | 830 | extrapostimport = [] # run after commit |
|
831 | 831 | # mapping from identifier to actual import function |
|
832 | 832 | # |
|
833 | 833 | # 'preimport' are run before the commit is made and are provided the following |
|
834 | 834 | # arguments: |
|
835 | 835 | # - repo: the localrepository instance, |
|
836 | 836 | # - patchdata: data extracted from patch header (cf m.patch.patchheadermap), |
|
837 | 837 | # - extra: the future extra dictionary of the changeset, please mutate it, |
|
838 | 838 | # - opts: the import options. |
|
839 | 839 | # XXX ideally, we would just pass an ctx ready to be computed, that would allow |
|
840 | 840 | # mutation of in memory commit and more. Feel free to rework the code to get |
|
841 | 841 | # there. |
|
842 | 842 | extrapreimportmap = {} |
|
843 | 843 | # 'postimport' are run after the commit is made and are provided the following |
|
844 | 844 | # argument: |
|
845 | 845 | # - ctx: the changectx created by import. |
|
846 | 846 | extrapostimportmap = {} |
|
847 | 847 | |
|
848 | 848 | def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc): |
|
849 | 849 | """Utility function used by commands.import to import a single patch |
|
850 | 850 | |
|
851 | 851 | This function is explicitly defined here to help the evolve extension to |
|
852 | 852 | wrap this part of the import logic. |
|
853 | 853 | |
|
854 | 854 | The API is currently a bit ugly because it a simple code translation from |
|
855 | 855 | the import command. Feel free to make it better. |
|
856 | 856 | |
|
857 | 857 | :hunk: a patch (as a binary string) |
|
858 | 858 | :parents: nodes that will be parent of the created commit |
|
859 | 859 | :opts: the full dict of option passed to the import command |
|
860 | 860 | :msgs: list to save commit message to. |
|
861 | 861 | (used in case we need to save it when failing) |
|
862 | 862 | :updatefunc: a function that update a repo to a given node |
|
863 | 863 | updatefunc(<repo>, <node>) |
|
864 | 864 | """ |
|
865 | 865 | # avoid cycle context -> subrepo -> cmdutil |
|
866 | 866 | import context |
|
867 | 867 | extractdata = patch.extract(ui, hunk) |
|
868 | 868 | tmpname = extractdata.get('filename') |
|
869 | 869 | message = extractdata.get('message') |
|
870 | 870 | user = opts.get('user') or extractdata.get('user') |
|
871 | 871 | date = opts.get('date') or extractdata.get('date') |
|
872 | 872 | branch = extractdata.get('branch') |
|
873 | 873 | nodeid = extractdata.get('nodeid') |
|
874 | 874 | p1 = extractdata.get('p1') |
|
875 | 875 | p2 = extractdata.get('p2') |
|
876 | 876 | |
|
877 | 877 | nocommit = opts.get('no_commit') |
|
878 | 878 | importbranch = opts.get('import_branch') |
|
879 | 879 | update = not opts.get('bypass') |
|
880 | 880 | strip = opts["strip"] |
|
881 | 881 | prefix = opts["prefix"] |
|
882 | 882 | sim = float(opts.get('similarity') or 0) |
|
883 | 883 | if not tmpname: |
|
884 | 884 | return (None, None, False) |
|
885 | 885 | |
|
886 | 886 | rejects = False |
|
887 | 887 | |
|
888 | 888 | try: |
|
889 | 889 | cmdline_message = logmessage(ui, opts) |
|
890 | 890 | if cmdline_message: |
|
891 | 891 | # pickup the cmdline msg |
|
892 | 892 | message = cmdline_message |
|
893 | 893 | elif message: |
|
894 | 894 | # pickup the patch msg |
|
895 | 895 | message = message.strip() |
|
896 | 896 | else: |
|
897 | 897 | # launch the editor |
|
898 | 898 | message = None |
|
899 | 899 | ui.debug('message:\n%s\n' % message) |
|
900 | 900 | |
|
901 | 901 | if len(parents) == 1: |
|
902 | 902 | parents.append(repo[nullid]) |
|
903 | 903 | if opts.get('exact'): |
|
904 | 904 | if not nodeid or not p1: |
|
905 | 905 | raise error.Abort(_('not a Mercurial patch')) |
|
906 | 906 | p1 = repo[p1] |
|
907 | 907 | p2 = repo[p2 or nullid] |
|
908 | 908 | elif p2: |
|
909 | 909 | try: |
|
910 | 910 | p1 = repo[p1] |
|
911 | 911 | p2 = repo[p2] |
|
912 | 912 | # Without any options, consider p2 only if the |
|
913 | 913 | # patch is being applied on top of the recorded |
|
914 | 914 | # first parent. |
|
915 | 915 | if p1 != parents[0]: |
|
916 | 916 | p1 = parents[0] |
|
917 | 917 | p2 = repo[nullid] |
|
918 | 918 | except error.RepoError: |
|
919 | 919 | p1, p2 = parents |
|
920 | 920 | if p2.node() == nullid: |
|
921 | 921 | ui.warn(_("warning: import the patch as a normal revision\n" |
|
922 | 922 | "(use --exact to import the patch as a merge)\n")) |
|
923 | 923 | else: |
|
924 | 924 | p1, p2 = parents |
|
925 | 925 | |
|
926 | 926 | n = None |
|
927 | 927 | if update: |
|
928 | 928 | if p1 != parents[0]: |
|
929 | 929 | updatefunc(repo, p1.node()) |
|
930 | 930 | if p2 != parents[1]: |
|
931 | 931 | repo.setparents(p1.node(), p2.node()) |
|
932 | 932 | |
|
933 | 933 | if opts.get('exact') or importbranch: |
|
934 | 934 | repo.dirstate.setbranch(branch or 'default') |
|
935 | 935 | |
|
936 | 936 | partial = opts.get('partial', False) |
|
937 | 937 | files = set() |
|
938 | 938 | try: |
|
939 | 939 | patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix, |
|
940 | 940 | files=files, eolmode=None, similarity=sim / 100.0) |
|
941 | 941 | except patch.PatchError as e: |
|
942 | 942 | if not partial: |
|
943 | 943 | raise error.Abort(str(e)) |
|
944 | 944 | if partial: |
|
945 | 945 | rejects = True |
|
946 | 946 | |
|
947 | 947 | files = list(files) |
|
948 | 948 | if nocommit: |
|
949 | 949 | if message: |
|
950 | 950 | msgs.append(message) |
|
951 | 951 | else: |
|
952 | 952 | if opts.get('exact') or p2: |
|
953 | 953 | # If you got here, you either use --force and know what |
|
954 | 954 | # you are doing or used --exact or a merge patch while |
|
955 | 955 | # being updated to its first parent. |
|
956 | 956 | m = None |
|
957 | 957 | else: |
|
958 | 958 | m = scmutil.matchfiles(repo, files or []) |
|
959 | 959 | editform = mergeeditform(repo[None], 'import.normal') |
|
960 | 960 | if opts.get('exact'): |
|
961 | 961 | editor = None |
|
962 | 962 | else: |
|
963 | 963 | editor = getcommiteditor(editform=editform, **opts) |
|
964 | 964 | allowemptyback = repo.ui.backupconfig('ui', 'allowemptycommit') |
|
965 | 965 | extra = {} |
|
966 | 966 | for idfunc in extrapreimport: |
|
967 | 967 | extrapreimportmap[idfunc](repo, extractdata, extra, opts) |
|
968 | 968 | try: |
|
969 | 969 | if partial: |
|
970 | 970 | repo.ui.setconfig('ui', 'allowemptycommit', True) |
|
971 | 971 | n = repo.commit(message, user, |
|
972 | 972 | date, match=m, |
|
973 | 973 | editor=editor, extra=extra) |
|
974 | 974 | for idfunc in extrapostimport: |
|
975 | 975 | extrapostimportmap[idfunc](repo[n]) |
|
976 | 976 | finally: |
|
977 | 977 | repo.ui.restoreconfig(allowemptyback) |
|
978 | 978 | else: |
|
979 | 979 | if opts.get('exact') or importbranch: |
|
980 | 980 | branch = branch or 'default' |
|
981 | 981 | else: |
|
982 | 982 | branch = p1.branch() |
|
983 | 983 | store = patch.filestore() |
|
984 | 984 | try: |
|
985 | 985 | files = set() |
|
986 | 986 | try: |
|
987 | 987 | patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix, |
|
988 | 988 | files, eolmode=None) |
|
989 | 989 | except patch.PatchError as e: |
|
990 | 990 | raise error.Abort(str(e)) |
|
991 | 991 | if opts.get('exact'): |
|
992 | 992 | editor = None |
|
993 | 993 | else: |
|
994 | 994 | editor = getcommiteditor(editform='import.bypass') |
|
995 | 995 | memctx = context.makememctx(repo, (p1.node(), p2.node()), |
|
996 | 996 | message, |
|
997 | 997 | user, |
|
998 | 998 | date, |
|
999 | 999 | branch, files, store, |
|
1000 | 1000 | editor=editor) |
|
1001 | 1001 | n = memctx.commit() |
|
1002 | 1002 | finally: |
|
1003 | 1003 | store.close() |
|
1004 | 1004 | if opts.get('exact') and nocommit: |
|
1005 | 1005 | # --exact with --no-commit is still useful in that it does merge |
|
1006 | 1006 | # and branch bits |
|
1007 | 1007 | ui.warn(_("warning: can't check exact import with --no-commit\n")) |
|
1008 | 1008 | elif opts.get('exact') and hex(n) != nodeid: |
|
1009 | 1009 | raise error.Abort(_('patch is damaged or loses information')) |
|
1010 | 1010 | msg = _('applied to working directory') |
|
1011 | 1011 | if n: |
|
1012 | 1012 | # i18n: refers to a short changeset id |
|
1013 | 1013 | msg = _('created %s') % short(n) |
|
1014 | 1014 | return (msg, n, rejects) |
|
1015 | 1015 | finally: |
|
1016 | 1016 | os.unlink(tmpname) |
|
1017 | 1017 | |
|
1018 | 1018 | # facility to let extensions include additional data in an exported patch |
|
1019 | 1019 | # list of identifiers to be executed in order |
|
1020 | 1020 | extraexport = [] |
|
1021 | 1021 | # mapping from identifier to actual export function |
|
1022 | 1022 | # function as to return a string to be added to the header or None |
|
1023 | 1023 | # it is given two arguments (sequencenumber, changectx) |
|
1024 | 1024 | extraexportmap = {} |
|
1025 | 1025 | |
|
1026 | 1026 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
|
1027 | 1027 | opts=None, match=None): |
|
1028 | 1028 | '''export changesets as hg patches.''' |
|
1029 | 1029 | |
|
1030 | 1030 | total = len(revs) |
|
1031 | 1031 | revwidth = max([len(str(rev)) for rev in revs]) |
|
1032 | 1032 | filemode = {} |
|
1033 | 1033 | |
|
1034 | 1034 | def single(rev, seqno, fp): |
|
1035 | 1035 | ctx = repo[rev] |
|
1036 | 1036 | node = ctx.node() |
|
1037 | 1037 | parents = [p.node() for p in ctx.parents() if p] |
|
1038 | 1038 | branch = ctx.branch() |
|
1039 | 1039 | if switch_parent: |
|
1040 | 1040 | parents.reverse() |
|
1041 | 1041 | |
|
1042 | 1042 | if parents: |
|
1043 | 1043 | prev = parents[0] |
|
1044 | 1044 | else: |
|
1045 | 1045 | prev = nullid |
|
1046 | 1046 | |
|
1047 | 1047 | shouldclose = False |
|
1048 | 1048 | if not fp and len(template) > 0: |
|
1049 | 1049 | desc_lines = ctx.description().rstrip().split('\n') |
|
1050 | 1050 | desc = desc_lines[0] #Commit always has a first line. |
|
1051 | 1051 | fp = makefileobj(repo, template, node, desc=desc, total=total, |
|
1052 | 1052 | seqno=seqno, revwidth=revwidth, mode='wb', |
|
1053 | 1053 | modemap=filemode) |
|
1054 | 1054 | shouldclose = True |
|
1055 | 1055 | if fp and not getattr(fp, 'name', '<unnamed>').startswith('<'): |
|
1056 | 1056 | repo.ui.note("%s\n" % fp.name) |
|
1057 | 1057 | |
|
1058 | 1058 | if not fp: |
|
1059 | 1059 | write = repo.ui.write |
|
1060 | 1060 | else: |
|
1061 | 1061 | def write(s, **kw): |
|
1062 | 1062 | fp.write(s) |
|
1063 | 1063 | |
|
1064 | 1064 | write("# HG changeset patch\n") |
|
1065 | 1065 | write("# User %s\n" % ctx.user()) |
|
1066 | 1066 | write("# Date %d %d\n" % ctx.date()) |
|
1067 | 1067 | write("# %s\n" % util.datestr(ctx.date())) |
|
1068 | 1068 | if branch and branch != 'default': |
|
1069 | 1069 | write("# Branch %s\n" % branch) |
|
1070 | 1070 | write("# Node ID %s\n" % hex(node)) |
|
1071 | 1071 | write("# Parent %s\n" % hex(prev)) |
|
1072 | 1072 | if len(parents) > 1: |
|
1073 | 1073 | write("# Parent %s\n" % hex(parents[1])) |
|
1074 | 1074 | |
|
1075 | 1075 | for headerid in extraexport: |
|
1076 | 1076 | header = extraexportmap[headerid](seqno, ctx) |
|
1077 | 1077 | if header is not None: |
|
1078 | 1078 | write('# %s\n' % header) |
|
1079 | 1079 | write(ctx.description().rstrip()) |
|
1080 | 1080 | write("\n\n") |
|
1081 | 1081 | |
|
1082 | 1082 | for chunk, label in patch.diffui(repo, prev, node, match, opts=opts): |
|
1083 | 1083 | write(chunk, label=label) |
|
1084 | 1084 | |
|
1085 | 1085 | if shouldclose: |
|
1086 | 1086 | fp.close() |
|
1087 | 1087 | |
|
1088 | 1088 | for seqno, rev in enumerate(revs): |
|
1089 | 1089 | single(rev, seqno + 1, fp) |
|
1090 | 1090 | |
|
1091 | 1091 | def diffordiffstat(ui, repo, diffopts, node1, node2, match, |
|
1092 | 1092 | changes=None, stat=False, fp=None, prefix='', |
|
1093 | 1093 | root='', listsubrepos=False): |
|
1094 | 1094 | '''show diff or diffstat.''' |
|
1095 | 1095 | if fp is None: |
|
1096 | 1096 | write = ui.write |
|
1097 | 1097 | else: |
|
1098 | 1098 | def write(s, **kw): |
|
1099 | 1099 | fp.write(s) |
|
1100 | 1100 | |
|
1101 | 1101 | if root: |
|
1102 | 1102 | relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) |
|
1103 | 1103 | else: |
|
1104 | 1104 | relroot = '' |
|
1105 | 1105 | if relroot != '': |
|
1106 | 1106 | # XXX relative roots currently don't work if the root is within a |
|
1107 | 1107 | # subrepo |
|
1108 | 1108 | uirelroot = match.uipath(relroot) |
|
1109 | 1109 | relroot += '/' |
|
1110 | 1110 | for matchroot in match.files(): |
|
1111 | 1111 | if not matchroot.startswith(relroot): |
|
1112 | 1112 | ui.warn(_('warning: %s not inside relative root %s\n') % ( |
|
1113 | 1113 | match.uipath(matchroot), uirelroot)) |
|
1114 | 1114 | |
|
1115 | 1115 | if stat: |
|
1116 | 1116 | diffopts = diffopts.copy(context=0) |
|
1117 | 1117 | width = 80 |
|
1118 | 1118 | if not ui.plain(): |
|
1119 | 1119 | width = ui.termwidth() |
|
1120 | 1120 | chunks = patch.diff(repo, node1, node2, match, changes, diffopts, |
|
1121 | 1121 | prefix=prefix, relroot=relroot) |
|
1122 | 1122 | for chunk, label in patch.diffstatui(util.iterlines(chunks), |
|
1123 | 1123 | width=width, |
|
1124 | 1124 | git=diffopts.git): |
|
1125 | 1125 | write(chunk, label=label) |
|
1126 | 1126 | else: |
|
1127 | 1127 | for chunk, label in patch.diffui(repo, node1, node2, match, |
|
1128 | 1128 | changes, diffopts, prefix=prefix, |
|
1129 | 1129 | relroot=relroot): |
|
1130 | 1130 | write(chunk, label=label) |
|
1131 | 1131 | |
|
1132 | 1132 | if listsubrepos: |
|
1133 | 1133 | ctx1 = repo[node1] |
|
1134 | 1134 | ctx2 = repo[node2] |
|
1135 | 1135 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
|
1136 | 1136 | tempnode2 = node2 |
|
1137 | 1137 | try: |
|
1138 | 1138 | if node2 is not None: |
|
1139 | 1139 | tempnode2 = ctx2.substate[subpath][1] |
|
1140 | 1140 | except KeyError: |
|
1141 | 1141 | # A subrepo that existed in node1 was deleted between node1 and |
|
1142 | 1142 | # node2 (inclusive). Thus, ctx2's substate won't contain that |
|
1143 | 1143 | # subpath. The best we can do is to ignore it. |
|
1144 | 1144 | tempnode2 = None |
|
1145 | 1145 | submatch = matchmod.narrowmatcher(subpath, match) |
|
1146 | 1146 | sub.diff(ui, diffopts, tempnode2, submatch, changes=changes, |
|
1147 | 1147 | stat=stat, fp=fp, prefix=prefix) |
|
1148 | 1148 | |
|
1149 | 1149 | class changeset_printer(object): |
|
1150 | 1150 | '''show changeset information when templating not requested.''' |
|
1151 | 1151 | |
|
1152 | 1152 | def __init__(self, ui, repo, matchfn, diffopts, buffered): |
|
1153 | 1153 | self.ui = ui |
|
1154 | 1154 | self.repo = repo |
|
1155 | 1155 | self.buffered = buffered |
|
1156 | 1156 | self.matchfn = matchfn |
|
1157 | 1157 | self.diffopts = diffopts |
|
1158 | 1158 | self.header = {} |
|
1159 | 1159 | self.hunk = {} |
|
1160 | 1160 | self.lastheader = None |
|
1161 | 1161 | self.footer = None |
|
1162 | 1162 | |
|
1163 | 1163 | def flush(self, ctx): |
|
1164 | 1164 | rev = ctx.rev() |
|
1165 | 1165 | if rev in self.header: |
|
1166 | 1166 | h = self.header[rev] |
|
1167 | 1167 | if h != self.lastheader: |
|
1168 | 1168 | self.lastheader = h |
|
1169 | 1169 | self.ui.write(h) |
|
1170 | 1170 | del self.header[rev] |
|
1171 | 1171 | if rev in self.hunk: |
|
1172 | 1172 | self.ui.write(self.hunk[rev]) |
|
1173 | 1173 | del self.hunk[rev] |
|
1174 | 1174 | return 1 |
|
1175 | 1175 | return 0 |
|
1176 | 1176 | |
|
1177 | 1177 | def close(self): |
|
1178 | 1178 | if self.footer: |
|
1179 | 1179 | self.ui.write(self.footer) |
|
1180 | 1180 | |
|
1181 | 1181 | def show(self, ctx, copies=None, matchfn=None, **props): |
|
1182 | 1182 | if self.buffered: |
|
1183 | 1183 | self.ui.pushbuffer(labeled=True) |
|
1184 | 1184 | self._show(ctx, copies, matchfn, props) |
|
1185 | 1185 | self.hunk[ctx.rev()] = self.ui.popbuffer() |
|
1186 | 1186 | else: |
|
1187 | 1187 | self._show(ctx, copies, matchfn, props) |
|
1188 | 1188 | |
|
1189 | 1189 | def _show(self, ctx, copies, matchfn, props): |
|
1190 | 1190 | '''show a single changeset or file revision''' |
|
1191 | 1191 | changenode = ctx.node() |
|
1192 | 1192 | rev = ctx.rev() |
|
1193 | 1193 | if self.ui.debugflag: |
|
1194 | 1194 | hexfunc = hex |
|
1195 | 1195 | else: |
|
1196 | 1196 | hexfunc = short |
|
1197 | 1197 | # as of now, wctx.node() and wctx.rev() return None, but we want to |
|
1198 | 1198 | # show the same values as {node} and {rev} templatekw |
|
1199 | 1199 | revnode = (scmutil.intrev(rev), hexfunc(bin(ctx.hex()))) |
|
1200 | 1200 | |
|
1201 | 1201 | if self.ui.quiet: |
|
1202 | 1202 | self.ui.write("%d:%s\n" % revnode, label='log.node') |
|
1203 | 1203 | return |
|
1204 | 1204 | |
|
1205 | 1205 | date = util.datestr(ctx.date()) |
|
1206 | 1206 | |
|
1207 | 1207 | # i18n: column positioning for "hg log" |
|
1208 | 1208 | self.ui.write(_("changeset: %d:%s\n") % revnode, |
|
1209 | 1209 | label='log.changeset changeset.%s' % ctx.phasestr()) |
|
1210 | 1210 | |
|
1211 | 1211 | # branches are shown first before any other names due to backwards |
|
1212 | 1212 | # compatibility |
|
1213 | 1213 | branch = ctx.branch() |
|
1214 | 1214 | # don't show the default branch name |
|
1215 | 1215 | if branch != 'default': |
|
1216 | 1216 | # i18n: column positioning for "hg log" |
|
1217 | 1217 | self.ui.write(_("branch: %s\n") % branch, |
|
1218 | 1218 | label='log.branch') |
|
1219 | 1219 | |
|
1220 | 1220 | for name, ns in self.repo.names.iteritems(): |
|
1221 | 1221 | # branches has special logic already handled above, so here we just |
|
1222 | 1222 | # skip it |
|
1223 | 1223 | if name == 'branches': |
|
1224 | 1224 | continue |
|
1225 | 1225 | # we will use the templatename as the color name since those two |
|
1226 | 1226 | # should be the same |
|
1227 | 1227 | for name in ns.names(self.repo, changenode): |
|
1228 | 1228 | self.ui.write(ns.logfmt % name, |
|
1229 | 1229 | label='log.%s' % ns.colorname) |
|
1230 | 1230 | if self.ui.debugflag: |
|
1231 | 1231 | # i18n: column positioning for "hg log" |
|
1232 | 1232 | self.ui.write(_("phase: %s\n") % ctx.phasestr(), |
|
1233 | 1233 | label='log.phase') |
|
1234 | 1234 | for pctx in scmutil.meaningfulparents(self.repo, ctx): |
|
1235 | 1235 | label = 'log.parent changeset.%s' % pctx.phasestr() |
|
1236 | 1236 | # i18n: column positioning for "hg log" |
|
1237 | 1237 | self.ui.write(_("parent: %d:%s\n") |
|
1238 | 1238 | % (pctx.rev(), hexfunc(pctx.node())), |
|
1239 | 1239 | label=label) |
|
1240 | 1240 | |
|
1241 | 1241 | if self.ui.debugflag and rev is not None: |
|
1242 | 1242 | mnode = ctx.manifestnode() |
|
1243 | 1243 | # i18n: column positioning for "hg log" |
|
1244 | 1244 | self.ui.write(_("manifest: %d:%s\n") % |
|
1245 | 1245 | (self.repo.manifest.rev(mnode), hex(mnode)), |
|
1246 | 1246 | label='ui.debug log.manifest') |
|
1247 | 1247 | # i18n: column positioning for "hg log" |
|
1248 | 1248 | self.ui.write(_("user: %s\n") % ctx.user(), |
|
1249 | 1249 | label='log.user') |
|
1250 | 1250 | # i18n: column positioning for "hg log" |
|
1251 | 1251 | self.ui.write(_("date: %s\n") % date, |
|
1252 | 1252 | label='log.date') |
|
1253 | 1253 | |
|
1254 | 1254 | if self.ui.debugflag: |
|
1255 | 1255 | files = ctx.p1().status(ctx)[:3] |
|
1256 | 1256 | for key, value in zip([# i18n: column positioning for "hg log" |
|
1257 | 1257 | _("files:"), |
|
1258 | 1258 | # i18n: column positioning for "hg log" |
|
1259 | 1259 | _("files+:"), |
|
1260 | 1260 | # i18n: column positioning for "hg log" |
|
1261 | 1261 | _("files-:")], files): |
|
1262 | 1262 | if value: |
|
1263 | 1263 | self.ui.write("%-12s %s\n" % (key, " ".join(value)), |
|
1264 | 1264 | label='ui.debug log.files') |
|
1265 | 1265 | elif ctx.files() and self.ui.verbose: |
|
1266 | 1266 | # i18n: column positioning for "hg log" |
|
1267 | 1267 | self.ui.write(_("files: %s\n") % " ".join(ctx.files()), |
|
1268 | 1268 | label='ui.note log.files') |
|
1269 | 1269 | if copies and self.ui.verbose: |
|
1270 | 1270 | copies = ['%s (%s)' % c for c in copies] |
|
1271 | 1271 | # i18n: column positioning for "hg log" |
|
1272 | 1272 | self.ui.write(_("copies: %s\n") % ' '.join(copies), |
|
1273 | 1273 | label='ui.note log.copies') |
|
1274 | 1274 | |
|
1275 | 1275 | extra = ctx.extra() |
|
1276 | 1276 | if extra and self.ui.debugflag: |
|
1277 | 1277 | for key, value in sorted(extra.items()): |
|
1278 | 1278 | # i18n: column positioning for "hg log" |
|
1279 | 1279 | self.ui.write(_("extra: %s=%s\n") |
|
1280 | 1280 | % (key, value.encode('string_escape')), |
|
1281 | 1281 | label='ui.debug log.extra') |
|
1282 | 1282 | |
|
1283 | 1283 | description = ctx.description().strip() |
|
1284 | 1284 | if description: |
|
1285 | 1285 | if self.ui.verbose: |
|
1286 | 1286 | self.ui.write(_("description:\n"), |
|
1287 | 1287 | label='ui.note log.description') |
|
1288 | 1288 | self.ui.write(description, |
|
1289 | 1289 | label='ui.note log.description') |
|
1290 | 1290 | self.ui.write("\n\n") |
|
1291 | 1291 | else: |
|
1292 | 1292 | # i18n: column positioning for "hg log" |
|
1293 | 1293 | self.ui.write(_("summary: %s\n") % |
|
1294 | 1294 | description.splitlines()[0], |
|
1295 | 1295 | label='log.summary') |
|
1296 | 1296 | self.ui.write("\n") |
|
1297 | 1297 | |
|
1298 | 1298 | self.showpatch(ctx, matchfn) |
|
1299 | 1299 | |
|
1300 | 1300 | def showpatch(self, ctx, matchfn): |
|
1301 | 1301 | if not matchfn: |
|
1302 | 1302 | matchfn = self.matchfn |
|
1303 | 1303 | if matchfn: |
|
1304 | 1304 | stat = self.diffopts.get('stat') |
|
1305 | 1305 | diff = self.diffopts.get('patch') |
|
1306 | 1306 | diffopts = patch.diffallopts(self.ui, self.diffopts) |
|
1307 | 1307 | node = ctx.node() |
|
1308 | 1308 | prev = ctx.p1().node() |
|
1309 | 1309 | if stat: |
|
1310 | 1310 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1311 | 1311 | match=matchfn, stat=True) |
|
1312 | 1312 | if diff: |
|
1313 | 1313 | if stat: |
|
1314 | 1314 | self.ui.write("\n") |
|
1315 | 1315 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1316 | 1316 | match=matchfn, stat=False) |
|
1317 | 1317 | self.ui.write("\n") |
|
1318 | 1318 | |
|
1319 | 1319 | class jsonchangeset(changeset_printer): |
|
1320 | 1320 | '''format changeset information.''' |
|
1321 | 1321 | |
|
1322 | 1322 | def __init__(self, ui, repo, matchfn, diffopts, buffered): |
|
1323 | 1323 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1324 | 1324 | self.cache = {} |
|
1325 | 1325 | self._first = True |
|
1326 | 1326 | |
|
1327 | 1327 | def close(self): |
|
1328 | 1328 | if not self._first: |
|
1329 | 1329 | self.ui.write("\n]\n") |
|
1330 | 1330 | else: |
|
1331 | 1331 | self.ui.write("[]\n") |
|
1332 | 1332 | |
|
1333 | 1333 | def _show(self, ctx, copies, matchfn, props): |
|
1334 | 1334 | '''show a single changeset or file revision''' |
|
1335 | 1335 | rev = ctx.rev() |
|
1336 | 1336 | if rev is None: |
|
1337 | 1337 | jrev = jnode = 'null' |
|
1338 | 1338 | else: |
|
1339 | 1339 | jrev = str(rev) |
|
1340 | 1340 | jnode = '"%s"' % hex(ctx.node()) |
|
1341 | 1341 | j = encoding.jsonescape |
|
1342 | 1342 | |
|
1343 | 1343 | if self._first: |
|
1344 | 1344 | self.ui.write("[\n {") |
|
1345 | 1345 | self._first = False |
|
1346 | 1346 | else: |
|
1347 | 1347 | self.ui.write(",\n {") |
|
1348 | 1348 | |
|
1349 | 1349 | if self.ui.quiet: |
|
1350 | 1350 | self.ui.write('\n "rev": %s' % jrev) |
|
1351 | 1351 | self.ui.write(',\n "node": %s' % jnode) |
|
1352 | 1352 | self.ui.write('\n }') |
|
1353 | 1353 | return |
|
1354 | 1354 | |
|
1355 | 1355 | self.ui.write('\n "rev": %s' % jrev) |
|
1356 | 1356 | self.ui.write(',\n "node": %s' % jnode) |
|
1357 | 1357 | self.ui.write(',\n "branch": "%s"' % j(ctx.branch())) |
|
1358 | 1358 | self.ui.write(',\n "phase": "%s"' % ctx.phasestr()) |
|
1359 | 1359 | self.ui.write(',\n "user": "%s"' % j(ctx.user())) |
|
1360 | 1360 | self.ui.write(',\n "date": [%d, %d]' % ctx.date()) |
|
1361 | 1361 | self.ui.write(',\n "desc": "%s"' % j(ctx.description())) |
|
1362 | 1362 | |
|
1363 | 1363 | self.ui.write(',\n "bookmarks": [%s]' % |
|
1364 | 1364 | ", ".join('"%s"' % j(b) for b in ctx.bookmarks())) |
|
1365 | 1365 | self.ui.write(',\n "tags": [%s]' % |
|
1366 | 1366 | ", ".join('"%s"' % j(t) for t in ctx.tags())) |
|
1367 | 1367 | self.ui.write(',\n "parents": [%s]' % |
|
1368 | 1368 | ", ".join('"%s"' % c.hex() for c in ctx.parents())) |
|
1369 | 1369 | |
|
1370 | 1370 | if self.ui.debugflag: |
|
1371 | 1371 | if rev is None: |
|
1372 | 1372 | jmanifestnode = 'null' |
|
1373 | 1373 | else: |
|
1374 | 1374 | jmanifestnode = '"%s"' % hex(ctx.manifestnode()) |
|
1375 | 1375 | self.ui.write(',\n "manifest": %s' % jmanifestnode) |
|
1376 | 1376 | |
|
1377 | 1377 | self.ui.write(',\n "extra": {%s}' % |
|
1378 | 1378 | ", ".join('"%s": "%s"' % (j(k), j(v)) |
|
1379 | 1379 | for k, v in ctx.extra().items())) |
|
1380 | 1380 | |
|
1381 | 1381 | files = ctx.p1().status(ctx) |
|
1382 | 1382 | self.ui.write(',\n "modified": [%s]' % |
|
1383 | 1383 | ", ".join('"%s"' % j(f) for f in files[0])) |
|
1384 | 1384 | self.ui.write(',\n "added": [%s]' % |
|
1385 | 1385 | ", ".join('"%s"' % j(f) for f in files[1])) |
|
1386 | 1386 | self.ui.write(',\n "removed": [%s]' % |
|
1387 | 1387 | ", ".join('"%s"' % j(f) for f in files[2])) |
|
1388 | 1388 | |
|
1389 | 1389 | elif self.ui.verbose: |
|
1390 | 1390 | self.ui.write(',\n "files": [%s]' % |
|
1391 | 1391 | ", ".join('"%s"' % j(f) for f in ctx.files())) |
|
1392 | 1392 | |
|
1393 | 1393 | if copies: |
|
1394 | 1394 | self.ui.write(',\n "copies": {%s}' % |
|
1395 | 1395 | ", ".join('"%s": "%s"' % (j(k), j(v)) |
|
1396 | 1396 | for k, v in copies)) |
|
1397 | 1397 | |
|
1398 | 1398 | matchfn = self.matchfn |
|
1399 | 1399 | if matchfn: |
|
1400 | 1400 | stat = self.diffopts.get('stat') |
|
1401 | 1401 | diff = self.diffopts.get('patch') |
|
1402 | 1402 | diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True) |
|
1403 | 1403 | node, prev = ctx.node(), ctx.p1().node() |
|
1404 | 1404 | if stat: |
|
1405 | 1405 | self.ui.pushbuffer() |
|
1406 | 1406 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1407 | 1407 | match=matchfn, stat=True) |
|
1408 | 1408 | self.ui.write(',\n "diffstat": "%s"' % j(self.ui.popbuffer())) |
|
1409 | 1409 | if diff: |
|
1410 | 1410 | self.ui.pushbuffer() |
|
1411 | 1411 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
1412 | 1412 | match=matchfn, stat=False) |
|
1413 | 1413 | self.ui.write(',\n "diff": "%s"' % j(self.ui.popbuffer())) |
|
1414 | 1414 | |
|
1415 | 1415 | self.ui.write("\n }") |
|
1416 | 1416 | |
|
1417 | 1417 | class changeset_templater(changeset_printer): |
|
1418 | 1418 | '''format changeset information.''' |
|
1419 | 1419 | |
|
1420 | 1420 | def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): |
|
1421 | 1421 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1422 | 1422 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) |
|
1423 | 1423 | defaulttempl = { |
|
1424 | 1424 | 'parent': '{rev}:{node|formatnode} ', |
|
1425 | 1425 | 'manifest': '{rev}:{node|formatnode}', |
|
1426 | 1426 | 'file_copy': '{name} ({source})', |
|
1427 | 1427 | 'extra': '{key}={value|stringescape}' |
|
1428 | 1428 | } |
|
1429 | 1429 | # filecopy is preserved for compatibility reasons |
|
1430 | 1430 | defaulttempl['filecopy'] = defaulttempl['file_copy'] |
|
1431 | 1431 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, |
|
1432 | 1432 | cache=defaulttempl) |
|
1433 | 1433 | if tmpl: |
|
1434 | 1434 | self.t.cache['changeset'] = tmpl |
|
1435 | 1435 | |
|
1436 | 1436 | self.cache = {} |
|
1437 | 1437 | |
|
1438 | 1438 | # find correct templates for current mode |
|
1439 | 1439 | tmplmodes = [ |
|
1440 | 1440 | (True, None), |
|
1441 | 1441 | (self.ui.verbose, 'verbose'), |
|
1442 | 1442 | (self.ui.quiet, 'quiet'), |
|
1443 | 1443 | (self.ui.debugflag, 'debug'), |
|
1444 | 1444 | ] |
|
1445 | 1445 | |
|
1446 | 1446 | self._parts = {'header': '', 'footer': '', 'changeset': 'changeset', |
|
1447 | 1447 | 'docheader': '', 'docfooter': ''} |
|
1448 | 1448 | for mode, postfix in tmplmodes: |
|
1449 | 1449 | for t in self._parts: |
|
1450 | 1450 | cur = t |
|
1451 | 1451 | if postfix: |
|
1452 | 1452 | cur += "_" + postfix |
|
1453 | 1453 | if mode and cur in self.t: |
|
1454 | 1454 | self._parts[t] = cur |
|
1455 | 1455 | |
|
1456 | 1456 | if self._parts['docheader']: |
|
1457 | 1457 | self.ui.write(templater.stringify(self.t(self._parts['docheader']))) |
|
1458 | 1458 | |
|
1459 | 1459 | def close(self): |
|
1460 | 1460 | if self._parts['docfooter']: |
|
1461 | 1461 | if not self.footer: |
|
1462 | 1462 | self.footer = "" |
|
1463 | 1463 | self.footer += templater.stringify(self.t(self._parts['docfooter'])) |
|
1464 | 1464 | return super(changeset_templater, self).close() |
|
1465 | 1465 | |
|
1466 | 1466 | def _show(self, ctx, copies, matchfn, props): |
|
1467 | 1467 | '''show a single changeset or file revision''' |
|
1468 | 1468 | props = props.copy() |
|
1469 | 1469 | props.update(templatekw.keywords) |
|
1470 | 1470 | props['templ'] = self.t |
|
1471 | 1471 | props['ctx'] = ctx |
|
1472 | 1472 | props['repo'] = self.repo |
|
1473 | 1473 | props['revcache'] = {'copies': copies} |
|
1474 | 1474 | props['cache'] = self.cache |
|
1475 | 1475 | |
|
1476 | 1476 | try: |
|
1477 | 1477 | # write header |
|
1478 | 1478 | if self._parts['header']: |
|
1479 | 1479 | h = templater.stringify(self.t(self._parts['header'], **props)) |
|
1480 | 1480 | if self.buffered: |
|
1481 | 1481 | self.header[ctx.rev()] = h |
|
1482 | 1482 | else: |
|
1483 | 1483 | if self.lastheader != h: |
|
1484 | 1484 | self.lastheader = h |
|
1485 | 1485 | self.ui.write(h) |
|
1486 | 1486 | |
|
1487 | 1487 | # write changeset metadata, then patch if requested |
|
1488 | 1488 | key = self._parts['changeset'] |
|
1489 | 1489 | self.ui.write(templater.stringify(self.t(key, **props))) |
|
1490 | 1490 | self.showpatch(ctx, matchfn) |
|
1491 | 1491 | |
|
1492 | 1492 | if self._parts['footer']: |
|
1493 | 1493 | if not self.footer: |
|
1494 | 1494 | self.footer = templater.stringify( |
|
1495 | 1495 | self.t(self._parts['footer'], **props)) |
|
1496 | 1496 | except KeyError as inst: |
|
1497 | 1497 | msg = _("%s: no key named '%s'") |
|
1498 | 1498 | raise error.Abort(msg % (self.t.mapfile, inst.args[0])) |
|
1499 | 1499 | except SyntaxError as inst: |
|
1500 | 1500 | raise error.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
|
1501 | 1501 | |
|
1502 | 1502 | def gettemplate(ui, tmpl, style): |
|
1503 | 1503 | """ |
|
1504 | 1504 | Find the template matching the given template spec or style. |
|
1505 | 1505 | """ |
|
1506 | 1506 | |
|
1507 | 1507 | # ui settings |
|
1508 | 1508 | if not tmpl and not style: # template are stronger than style |
|
1509 | 1509 | tmpl = ui.config('ui', 'logtemplate') |
|
1510 | 1510 | if tmpl: |
|
1511 | 1511 | try: |
|
1512 | 1512 | tmpl = templater.unquotestring(tmpl) |
|
1513 | 1513 | except SyntaxError: |
|
1514 | 1514 | pass |
|
1515 | 1515 | return tmpl, None |
|
1516 | 1516 | else: |
|
1517 | 1517 | style = util.expandpath(ui.config('ui', 'style', '')) |
|
1518 | 1518 | |
|
1519 | 1519 | if not tmpl and style: |
|
1520 | 1520 | mapfile = style |
|
1521 | 1521 | if not os.path.split(mapfile)[0]: |
|
1522 | 1522 | mapname = (templater.templatepath('map-cmdline.' + mapfile) |
|
1523 | 1523 | or templater.templatepath(mapfile)) |
|
1524 | 1524 | if mapname: |
|
1525 | 1525 | mapfile = mapname |
|
1526 | 1526 | return None, mapfile |
|
1527 | 1527 | |
|
1528 | 1528 | if not tmpl: |
|
1529 | 1529 | return None, None |
|
1530 | 1530 | |
|
1531 | 1531 | return formatter.lookuptemplate(ui, 'changeset', tmpl) |
|
1532 | 1532 | |
|
1533 | 1533 | def show_changeset(ui, repo, opts, buffered=False): |
|
1534 | 1534 | """show one changeset using template or regular display. |
|
1535 | 1535 | |
|
1536 | 1536 | Display format will be the first non-empty hit of: |
|
1537 | 1537 | 1. option 'template' |
|
1538 | 1538 | 2. option 'style' |
|
1539 | 1539 | 3. [ui] setting 'logtemplate' |
|
1540 | 1540 | 4. [ui] setting 'style' |
|
1541 | 1541 | If all of these values are either the unset or the empty string, |
|
1542 | 1542 | regular display via changeset_printer() is done. |
|
1543 | 1543 | """ |
|
1544 | 1544 | # options |
|
1545 | 1545 | matchfn = None |
|
1546 | 1546 | if opts.get('patch') or opts.get('stat'): |
|
1547 | 1547 | matchfn = scmutil.matchall(repo) |
|
1548 | 1548 | |
|
1549 | 1549 | if opts.get('template') == 'json': |
|
1550 | 1550 | return jsonchangeset(ui, repo, matchfn, opts, buffered) |
|
1551 | 1551 | |
|
1552 | 1552 | tmpl, mapfile = gettemplate(ui, opts.get('template'), opts.get('style')) |
|
1553 | 1553 | |
|
1554 | 1554 | if not tmpl and not mapfile: |
|
1555 | 1555 | return changeset_printer(ui, repo, matchfn, opts, buffered) |
|
1556 | 1556 | |
|
1557 | 1557 | try: |
|
1558 | 1558 | t = changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile, |
|
1559 | 1559 | buffered) |
|
1560 | 1560 | except SyntaxError as inst: |
|
1561 | 1561 | raise error.Abort(inst.args[0]) |
|
1562 | 1562 | return t |
|
1563 | 1563 | |
|
1564 | 1564 | def showmarker(ui, marker): |
|
1565 | 1565 | """utility function to display obsolescence marker in a readable way |
|
1566 | 1566 | |
|
1567 | 1567 | To be used by debug function.""" |
|
1568 | 1568 | ui.write(hex(marker.precnode())) |
|
1569 | 1569 | for repl in marker.succnodes(): |
|
1570 | 1570 | ui.write(' ') |
|
1571 | 1571 | ui.write(hex(repl)) |
|
1572 | 1572 | ui.write(' %X ' % marker.flags()) |
|
1573 | 1573 | parents = marker.parentnodes() |
|
1574 | 1574 | if parents is not None: |
|
1575 | 1575 | ui.write('{%s} ' % ', '.join(hex(p) for p in parents)) |
|
1576 | 1576 | ui.write('(%s) ' % util.datestr(marker.date())) |
|
1577 | 1577 | ui.write('{%s}' % (', '.join('%r: %r' % t for t in |
|
1578 | 1578 | sorted(marker.metadata().items()) |
|
1579 | 1579 | if t[0] != 'date'))) |
|
1580 | 1580 | ui.write('\n') |
|
1581 | 1581 | |
|
1582 | 1582 | def finddate(ui, repo, date): |
|
1583 | 1583 | """Find the tipmost changeset that matches the given date spec""" |
|
1584 | 1584 | |
|
1585 | 1585 | df = util.matchdate(date) |
|
1586 | 1586 | m = scmutil.matchall(repo) |
|
1587 | 1587 | results = {} |
|
1588 | 1588 | |
|
1589 | 1589 | def prep(ctx, fns): |
|
1590 | 1590 | d = ctx.date() |
|
1591 | 1591 | if df(d[0]): |
|
1592 | 1592 | results[ctx.rev()] = d |
|
1593 | 1593 | |
|
1594 | 1594 | for ctx in walkchangerevs(repo, m, {'rev': None}, prep): |
|
1595 | 1595 | rev = ctx.rev() |
|
1596 | 1596 | if rev in results: |
|
1597 | 1597 | ui.status(_("found revision %s from %s\n") % |
|
1598 | 1598 | (rev, util.datestr(results[rev]))) |
|
1599 | 1599 | return str(rev) |
|
1600 | 1600 | |
|
1601 | 1601 | raise error.Abort(_("revision matching date not found")) |
|
1602 | 1602 | |
|
1603 | 1603 | def increasingwindows(windowsize=8, sizelimit=512): |
|
1604 | 1604 | while True: |
|
1605 | 1605 | yield windowsize |
|
1606 | 1606 | if windowsize < sizelimit: |
|
1607 | 1607 | windowsize *= 2 |
|
1608 | 1608 | |
|
1609 | 1609 | class FileWalkError(Exception): |
|
1610 | 1610 | pass |
|
1611 | 1611 | |
|
1612 | 1612 | def walkfilerevs(repo, match, follow, revs, fncache): |
|
1613 | 1613 | '''Walks the file history for the matched files. |
|
1614 | 1614 | |
|
1615 | 1615 | Returns the changeset revs that are involved in the file history. |
|
1616 | 1616 | |
|
1617 | 1617 | Throws FileWalkError if the file history can't be walked using |
|
1618 | 1618 | filelogs alone. |
|
1619 | 1619 | ''' |
|
1620 | 1620 | wanted = set() |
|
1621 | 1621 | copies = [] |
|
1622 | 1622 | minrev, maxrev = min(revs), max(revs) |
|
1623 | 1623 | def filerevgen(filelog, last): |
|
1624 | 1624 | """ |
|
1625 | 1625 | Only files, no patterns. Check the history of each file. |
|
1626 | 1626 | |
|
1627 | 1627 | Examines filelog entries within minrev, maxrev linkrev range |
|
1628 | 1628 | Returns an iterator yielding (linkrev, parentlinkrevs, copied) |
|
1629 | 1629 | tuples in backwards order |
|
1630 | 1630 | """ |
|
1631 | 1631 | cl_count = len(repo) |
|
1632 | 1632 | revs = [] |
|
1633 | 1633 | for j in xrange(0, last + 1): |
|
1634 | 1634 | linkrev = filelog.linkrev(j) |
|
1635 | 1635 | if linkrev < minrev: |
|
1636 | 1636 | continue |
|
1637 | 1637 | # only yield rev for which we have the changelog, it can |
|
1638 | 1638 | # happen while doing "hg log" during a pull or commit |
|
1639 | 1639 | if linkrev >= cl_count: |
|
1640 | 1640 | break |
|
1641 | 1641 | |
|
1642 | 1642 | parentlinkrevs = [] |
|
1643 | 1643 | for p in filelog.parentrevs(j): |
|
1644 | 1644 | if p != nullrev: |
|
1645 | 1645 | parentlinkrevs.append(filelog.linkrev(p)) |
|
1646 | 1646 | n = filelog.node(j) |
|
1647 | 1647 | revs.append((linkrev, parentlinkrevs, |
|
1648 | 1648 | follow and filelog.renamed(n))) |
|
1649 | 1649 | |
|
1650 | 1650 | return reversed(revs) |
|
1651 | 1651 | def iterfiles(): |
|
1652 | 1652 | pctx = repo['.'] |
|
1653 | 1653 | for filename in match.files(): |
|
1654 | 1654 | if follow: |
|
1655 | 1655 | if filename not in pctx: |
|
1656 | 1656 | raise error.Abort(_('cannot follow file not in parent ' |
|
1657 | 1657 | 'revision: "%s"') % filename) |
|
1658 | 1658 | yield filename, pctx[filename].filenode() |
|
1659 | 1659 | else: |
|
1660 | 1660 | yield filename, None |
|
1661 | 1661 | for filename_node in copies: |
|
1662 | 1662 | yield filename_node |
|
1663 | 1663 | |
|
1664 | 1664 | for file_, node in iterfiles(): |
|
1665 | 1665 | filelog = repo.file(file_) |
|
1666 | 1666 | if not len(filelog): |
|
1667 | 1667 | if node is None: |
|
1668 | 1668 | # A zero count may be a directory or deleted file, so |
|
1669 | 1669 | # try to find matching entries on the slow path. |
|
1670 | 1670 | if follow: |
|
1671 | 1671 | raise error.Abort( |
|
1672 | 1672 | _('cannot follow nonexistent file: "%s"') % file_) |
|
1673 | 1673 | raise FileWalkError("Cannot walk via filelog") |
|
1674 | 1674 | else: |
|
1675 | 1675 | continue |
|
1676 | 1676 | |
|
1677 | 1677 | if node is None: |
|
1678 | 1678 | last = len(filelog) - 1 |
|
1679 | 1679 | else: |
|
1680 | 1680 | last = filelog.rev(node) |
|
1681 | 1681 | |
|
1682 | 1682 | # keep track of all ancestors of the file |
|
1683 | 1683 | ancestors = set([filelog.linkrev(last)]) |
|
1684 | 1684 | |
|
1685 | 1685 | # iterate from latest to oldest revision |
|
1686 | 1686 | for rev, flparentlinkrevs, copied in filerevgen(filelog, last): |
|
1687 | 1687 | if not follow: |
|
1688 | 1688 | if rev > maxrev: |
|
1689 | 1689 | continue |
|
1690 | 1690 | else: |
|
1691 | 1691 | # Note that last might not be the first interesting |
|
1692 | 1692 | # rev to us: |
|
1693 | 1693 | # if the file has been changed after maxrev, we'll |
|
1694 | 1694 | # have linkrev(last) > maxrev, and we still need |
|
1695 | 1695 | # to explore the file graph |
|
1696 | 1696 | if rev not in ancestors: |
|
1697 | 1697 | continue |
|
1698 | 1698 | # XXX insert 1327 fix here |
|
1699 | 1699 | if flparentlinkrevs: |
|
1700 | 1700 | ancestors.update(flparentlinkrevs) |
|
1701 | 1701 | |
|
1702 | 1702 | fncache.setdefault(rev, []).append(file_) |
|
1703 | 1703 | wanted.add(rev) |
|
1704 | 1704 | if copied: |
|
1705 | 1705 | copies.append(copied) |
|
1706 | 1706 | |
|
1707 | 1707 | return wanted |
|
1708 | 1708 | |
|
1709 | 1709 | class _followfilter(object): |
|
1710 | 1710 | def __init__(self, repo, onlyfirst=False): |
|
1711 | 1711 | self.repo = repo |
|
1712 | 1712 | self.startrev = nullrev |
|
1713 | 1713 | self.roots = set() |
|
1714 | 1714 | self.onlyfirst = onlyfirst |
|
1715 | 1715 | |
|
1716 | 1716 | def match(self, rev): |
|
1717 | 1717 | def realparents(rev): |
|
1718 | 1718 | if self.onlyfirst: |
|
1719 | 1719 | return self.repo.changelog.parentrevs(rev)[0:1] |
|
1720 | 1720 | else: |
|
1721 | 1721 | return filter(lambda x: x != nullrev, |
|
1722 | 1722 | self.repo.changelog.parentrevs(rev)) |
|
1723 | 1723 | |
|
1724 | 1724 | if self.startrev == nullrev: |
|
1725 | 1725 | self.startrev = rev |
|
1726 | 1726 | return True |
|
1727 | 1727 | |
|
1728 | 1728 | if rev > self.startrev: |
|
1729 | 1729 | # forward: all descendants |
|
1730 | 1730 | if not self.roots: |
|
1731 | 1731 | self.roots.add(self.startrev) |
|
1732 | 1732 | for parent in realparents(rev): |
|
1733 | 1733 | if parent in self.roots: |
|
1734 | 1734 | self.roots.add(rev) |
|
1735 | 1735 | return True |
|
1736 | 1736 | else: |
|
1737 | 1737 | # backwards: all parents |
|
1738 | 1738 | if not self.roots: |
|
1739 | 1739 | self.roots.update(realparents(self.startrev)) |
|
1740 | 1740 | if rev in self.roots: |
|
1741 | 1741 | self.roots.remove(rev) |
|
1742 | 1742 | self.roots.update(realparents(rev)) |
|
1743 | 1743 | return True |
|
1744 | 1744 | |
|
1745 | 1745 | return False |
|
1746 | 1746 | |
|
1747 | 1747 | def walkchangerevs(repo, match, opts, prepare): |
|
1748 | 1748 | '''Iterate over files and the revs in which they changed. |
|
1749 | 1749 | |
|
1750 | 1750 | Callers most commonly need to iterate backwards over the history |
|
1751 | 1751 | in which they are interested. Doing so has awful (quadratic-looking) |
|
1752 | 1752 | performance, so we use iterators in a "windowed" way. |
|
1753 | 1753 | |
|
1754 | 1754 | We walk a window of revisions in the desired order. Within the |
|
1755 | 1755 | window, we first walk forwards to gather data, then in the desired |
|
1756 | 1756 | order (usually backwards) to display it. |
|
1757 | 1757 | |
|
1758 | 1758 | This function returns an iterator yielding contexts. Before |
|
1759 | 1759 | yielding each context, the iterator will first call the prepare |
|
1760 | 1760 | function on each context in the window in forward order.''' |
|
1761 | 1761 | |
|
1762 | 1762 | follow = opts.get('follow') or opts.get('follow_first') |
|
1763 | 1763 | revs = _logrevs(repo, opts) |
|
1764 | 1764 | if not revs: |
|
1765 | 1765 | return [] |
|
1766 | 1766 | wanted = set() |
|
1767 | 1767 | slowpath = match.anypats() or ((match.isexact() or match.prefix()) and |
|
1768 | 1768 | opts.get('removed')) |
|
1769 | 1769 | fncache = {} |
|
1770 | 1770 | change = repo.changectx |
|
1771 | 1771 | |
|
1772 | 1772 | # First step is to fill wanted, the set of revisions that we want to yield. |
|
1773 | 1773 | # When it does not induce extra cost, we also fill fncache for revisions in |
|
1774 | 1774 | # wanted: a cache of filenames that were changed (ctx.files()) and that |
|
1775 | 1775 | # match the file filtering conditions. |
|
1776 | 1776 | |
|
1777 | 1777 | if match.always(): |
|
1778 | 1778 | # No files, no patterns. Display all revs. |
|
1779 | 1779 | wanted = revs |
|
1780 | 1780 | elif not slowpath: |
|
1781 | 1781 | # We only have to read through the filelog to find wanted revisions |
|
1782 | 1782 | |
|
1783 | 1783 | try: |
|
1784 | 1784 | wanted = walkfilerevs(repo, match, follow, revs, fncache) |
|
1785 | 1785 | except FileWalkError: |
|
1786 | 1786 | slowpath = True |
|
1787 | 1787 | |
|
1788 | 1788 | # We decided to fall back to the slowpath because at least one |
|
1789 | 1789 | # of the paths was not a file. Check to see if at least one of them |
|
1790 | 1790 | # existed in history, otherwise simply return |
|
1791 | 1791 | for path in match.files(): |
|
1792 | 1792 | if path == '.' or path in repo.store: |
|
1793 | 1793 | break |
|
1794 | 1794 | else: |
|
1795 | 1795 | return [] |
|
1796 | 1796 | |
|
1797 | 1797 | if slowpath: |
|
1798 | 1798 | # We have to read the changelog to match filenames against |
|
1799 | 1799 | # changed files |
|
1800 | 1800 | |
|
1801 | 1801 | if follow: |
|
1802 | 1802 | raise error.Abort(_('can only follow copies/renames for explicit ' |
|
1803 | 1803 | 'filenames')) |
|
1804 | 1804 | |
|
1805 | 1805 | # The slow path checks files modified in every changeset. |
|
1806 | 1806 | # This is really slow on large repos, so compute the set lazily. |
|
1807 | 1807 | class lazywantedset(object): |
|
1808 | 1808 | def __init__(self): |
|
1809 | 1809 | self.set = set() |
|
1810 | 1810 | self.revs = set(revs) |
|
1811 | 1811 | |
|
1812 | 1812 | # No need to worry about locality here because it will be accessed |
|
1813 | 1813 | # in the same order as the increasing window below. |
|
1814 | 1814 | def __contains__(self, value): |
|
1815 | 1815 | if value in self.set: |
|
1816 | 1816 | return True |
|
1817 | 1817 | elif not value in self.revs: |
|
1818 | 1818 | return False |
|
1819 | 1819 | else: |
|
1820 | 1820 | self.revs.discard(value) |
|
1821 | 1821 | ctx = change(value) |
|
1822 | 1822 | matches = filter(match, ctx.files()) |
|
1823 | 1823 | if matches: |
|
1824 | 1824 | fncache[value] = matches |
|
1825 | 1825 | self.set.add(value) |
|
1826 | 1826 | return True |
|
1827 | 1827 | return False |
|
1828 | 1828 | |
|
1829 | 1829 | def discard(self, value): |
|
1830 | 1830 | self.revs.discard(value) |
|
1831 | 1831 | self.set.discard(value) |
|
1832 | 1832 | |
|
1833 | 1833 | wanted = lazywantedset() |
|
1834 | 1834 | |
|
1835 | 1835 | # it might be worthwhile to do this in the iterator if the rev range |
|
1836 | 1836 | # is descending and the prune args are all within that range |
|
1837 | 1837 | for rev in opts.get('prune', ()): |
|
1838 | 1838 | rev = repo[rev].rev() |
|
1839 | 1839 | ff = _followfilter(repo) |
|
1840 | 1840 | stop = min(revs[0], revs[-1]) |
|
1841 | 1841 | for x in xrange(rev, stop - 1, -1): |
|
1842 | 1842 | if ff.match(x): |
|
1843 | 1843 | wanted = wanted - [x] |
|
1844 | 1844 | |
|
1845 | 1845 | # Now that wanted is correctly initialized, we can iterate over the |
|
1846 | 1846 | # revision range, yielding only revisions in wanted. |
|
1847 | 1847 | def iterate(): |
|
1848 | 1848 | if follow and match.always(): |
|
1849 | 1849 | ff = _followfilter(repo, onlyfirst=opts.get('follow_first')) |
|
1850 | 1850 | def want(rev): |
|
1851 | 1851 | return ff.match(rev) and rev in wanted |
|
1852 | 1852 | else: |
|
1853 | 1853 | def want(rev): |
|
1854 | 1854 | return rev in wanted |
|
1855 | 1855 | |
|
1856 | 1856 | it = iter(revs) |
|
1857 | 1857 | stopiteration = False |
|
1858 | 1858 | for windowsize in increasingwindows(): |
|
1859 | 1859 | nrevs = [] |
|
1860 | 1860 | for i in xrange(windowsize): |
|
1861 | 1861 | rev = next(it, None) |
|
1862 | 1862 | if rev is None: |
|
1863 | 1863 | stopiteration = True |
|
1864 | 1864 | break |
|
1865 | 1865 | elif want(rev): |
|
1866 | 1866 | nrevs.append(rev) |
|
1867 | 1867 | for rev in sorted(nrevs): |
|
1868 | 1868 | fns = fncache.get(rev) |
|
1869 | 1869 | ctx = change(rev) |
|
1870 | 1870 | if not fns: |
|
1871 | 1871 | def fns_generator(): |
|
1872 | 1872 | for f in ctx.files(): |
|
1873 | 1873 | if match(f): |
|
1874 | 1874 | yield f |
|
1875 | 1875 | fns = fns_generator() |
|
1876 | 1876 | prepare(ctx, fns) |
|
1877 | 1877 | for rev in nrevs: |
|
1878 | 1878 | yield change(rev) |
|
1879 | 1879 | |
|
1880 | 1880 | if stopiteration: |
|
1881 | 1881 | break |
|
1882 | 1882 | |
|
1883 | 1883 | return iterate() |
|
1884 | 1884 | |
|
1885 | 1885 | def _makefollowlogfilematcher(repo, files, followfirst): |
|
1886 | 1886 | # When displaying a revision with --patch --follow FILE, we have |
|
1887 | 1887 | # to know which file of the revision must be diffed. With |
|
1888 | 1888 | # --follow, we want the names of the ancestors of FILE in the |
|
1889 | 1889 | # revision, stored in "fcache". "fcache" is populated by |
|
1890 | 1890 | # reproducing the graph traversal already done by --follow revset |
|
1891 | 1891 | # and relating linkrevs to file names (which is not "correct" but |
|
1892 | 1892 | # good enough). |
|
1893 | 1893 | fcache = {} |
|
1894 | 1894 | fcacheready = [False] |
|
1895 | 1895 | pctx = repo['.'] |
|
1896 | 1896 | |
|
1897 | 1897 | def populate(): |
|
1898 | 1898 | for fn in files: |
|
1899 | 1899 | for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)): |
|
1900 | 1900 | for c in i: |
|
1901 | 1901 | fcache.setdefault(c.linkrev(), set()).add(c.path()) |
|
1902 | 1902 | |
|
1903 | 1903 | def filematcher(rev): |
|
1904 | 1904 | if not fcacheready[0]: |
|
1905 | 1905 | # Lazy initialization |
|
1906 | 1906 | fcacheready[0] = True |
|
1907 | 1907 | populate() |
|
1908 | 1908 | return scmutil.matchfiles(repo, fcache.get(rev, [])) |
|
1909 | 1909 | |
|
1910 | 1910 | return filematcher |
|
1911 | 1911 | |
|
1912 | 1912 | def _makenofollowlogfilematcher(repo, pats, opts): |
|
1913 | 1913 | '''hook for extensions to override the filematcher for non-follow cases''' |
|
1914 | 1914 | return None |
|
1915 | 1915 | |
|
1916 | 1916 | def _makelogrevset(repo, pats, opts, revs): |
|
1917 | 1917 | """Return (expr, filematcher) where expr is a revset string built |
|
1918 | 1918 | from log options and file patterns or None. If --stat or --patch |
|
1919 | 1919 | are not passed filematcher is None. Otherwise it is a callable |
|
1920 | 1920 | taking a revision number and returning a match objects filtering |
|
1921 | 1921 | the files to be detailed when displaying the revision. |
|
1922 | 1922 | """ |
|
1923 | 1923 | opt2revset = { |
|
1924 | 1924 | 'no_merges': ('not merge()', None), |
|
1925 | 1925 | 'only_merges': ('merge()', None), |
|
1926 | 1926 | '_ancestors': ('ancestors(%(val)s)', None), |
|
1927 | 1927 | '_fancestors': ('_firstancestors(%(val)s)', None), |
|
1928 | 1928 | '_descendants': ('descendants(%(val)s)', None), |
|
1929 | 1929 | '_fdescendants': ('_firstdescendants(%(val)s)', None), |
|
1930 | 1930 | '_matchfiles': ('_matchfiles(%(val)s)', None), |
|
1931 | 1931 | 'date': ('date(%(val)r)', None), |
|
1932 | 1932 | 'branch': ('branch(%(val)r)', ' or '), |
|
1933 | 1933 | '_patslog': ('filelog(%(val)r)', ' or '), |
|
1934 | 1934 | '_patsfollow': ('follow(%(val)r)', ' or '), |
|
1935 | 1935 | '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '), |
|
1936 | 1936 | 'keyword': ('keyword(%(val)r)', ' or '), |
|
1937 | 1937 | 'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '), |
|
1938 | 1938 | 'user': ('user(%(val)r)', ' or '), |
|
1939 | 1939 | } |
|
1940 | 1940 | |
|
1941 | 1941 | opts = dict(opts) |
|
1942 | 1942 | # follow or not follow? |
|
1943 | 1943 | follow = opts.get('follow') or opts.get('follow_first') |
|
1944 | 1944 | if opts.get('follow_first'): |
|
1945 | 1945 | followfirst = 1 |
|
1946 | 1946 | else: |
|
1947 | 1947 | followfirst = 0 |
|
1948 | 1948 | # --follow with FILE behavior depends on revs... |
|
1949 | 1949 | it = iter(revs) |
|
1950 | 1950 | startrev = it.next() |
|
1951 | 1951 | followdescendants = startrev < next(it, startrev) |
|
1952 | 1952 | |
|
1953 | 1953 | # branch and only_branch are really aliases and must be handled at |
|
1954 | 1954 | # the same time |
|
1955 | 1955 | opts['branch'] = opts.get('branch', []) + opts.get('only_branch', []) |
|
1956 | 1956 | opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']] |
|
1957 | 1957 | # pats/include/exclude are passed to match.match() directly in |
|
1958 | 1958 | # _matchfiles() revset but walkchangerevs() builds its matcher with |
|
1959 | 1959 | # scmutil.match(). The difference is input pats are globbed on |
|
1960 | 1960 | # platforms without shell expansion (windows). |
|
1961 | 1961 | wctx = repo[None] |
|
1962 | 1962 | match, pats = scmutil.matchandpats(wctx, pats, opts) |
|
1963 | 1963 | slowpath = match.anypats() or ((match.isexact() or match.prefix()) and |
|
1964 | 1964 | opts.get('removed')) |
|
1965 | 1965 | if not slowpath: |
|
1966 | 1966 | for f in match.files(): |
|
1967 | 1967 | if follow and f not in wctx: |
|
1968 | 1968 | # If the file exists, it may be a directory, so let it |
|
1969 | 1969 | # take the slow path. |
|
1970 | 1970 | if os.path.exists(repo.wjoin(f)): |
|
1971 | 1971 | slowpath = True |
|
1972 | 1972 | continue |
|
1973 | 1973 | else: |
|
1974 | 1974 | raise error.Abort(_('cannot follow file not in parent ' |
|
1975 | 1975 | 'revision: "%s"') % f) |
|
1976 | 1976 | filelog = repo.file(f) |
|
1977 | 1977 | if not filelog: |
|
1978 | 1978 | # A zero count may be a directory or deleted file, so |
|
1979 | 1979 | # try to find matching entries on the slow path. |
|
1980 | 1980 | if follow: |
|
1981 | 1981 | raise error.Abort( |
|
1982 | 1982 | _('cannot follow nonexistent file: "%s"') % f) |
|
1983 | 1983 | slowpath = True |
|
1984 | 1984 | |
|
1985 | 1985 | # We decided to fall back to the slowpath because at least one |
|
1986 | 1986 | # of the paths was not a file. Check to see if at least one of them |
|
1987 | 1987 | # existed in history - in that case, we'll continue down the |
|
1988 | 1988 | # slowpath; otherwise, we can turn off the slowpath |
|
1989 | 1989 | if slowpath: |
|
1990 | 1990 | for path in match.files(): |
|
1991 | 1991 | if path == '.' or path in repo.store: |
|
1992 | 1992 | break |
|
1993 | 1993 | else: |
|
1994 | 1994 | slowpath = False |
|
1995 | 1995 | |
|
1996 | 1996 | fpats = ('_patsfollow', '_patsfollowfirst') |
|
1997 | 1997 | fnopats = (('_ancestors', '_fancestors'), |
|
1998 | 1998 | ('_descendants', '_fdescendants')) |
|
1999 | 1999 | if slowpath: |
|
2000 | 2000 | # See walkchangerevs() slow path. |
|
2001 | 2001 | # |
|
2002 | 2002 | # pats/include/exclude cannot be represented as separate |
|
2003 | 2003 | # revset expressions as their filtering logic applies at file |
|
2004 | 2004 | # level. For instance "-I a -X a" matches a revision touching |
|
2005 | 2005 | # "a" and "b" while "file(a) and not file(b)" does |
|
2006 | 2006 | # not. Besides, filesets are evaluated against the working |
|
2007 | 2007 | # directory. |
|
2008 | 2008 | matchargs = ['r:', 'd:relpath'] |
|
2009 | 2009 | for p in pats: |
|
2010 | 2010 | matchargs.append('p:' + p) |
|
2011 | 2011 | for p in opts.get('include', []): |
|
2012 | 2012 | matchargs.append('i:' + p) |
|
2013 | 2013 | for p in opts.get('exclude', []): |
|
2014 | 2014 | matchargs.append('x:' + p) |
|
2015 | 2015 | matchargs = ','.join(('%r' % p) for p in matchargs) |
|
2016 | 2016 | opts['_matchfiles'] = matchargs |
|
2017 | 2017 | if follow: |
|
2018 | 2018 | opts[fnopats[0][followfirst]] = '.' |
|
2019 | 2019 | else: |
|
2020 | 2020 | if follow: |
|
2021 | 2021 | if pats: |
|
2022 | 2022 | # follow() revset interprets its file argument as a |
|
2023 | 2023 | # manifest entry, so use match.files(), not pats. |
|
2024 | 2024 | opts[fpats[followfirst]] = list(match.files()) |
|
2025 | 2025 | else: |
|
2026 | 2026 | op = fnopats[followdescendants][followfirst] |
|
2027 | 2027 | opts[op] = 'rev(%d)' % startrev |
|
2028 | 2028 | else: |
|
2029 | 2029 | opts['_patslog'] = list(pats) |
|
2030 | 2030 | |
|
2031 | 2031 | filematcher = None |
|
2032 | 2032 | if opts.get('patch') or opts.get('stat'): |
|
2033 | 2033 | # When following files, track renames via a special matcher. |
|
2034 | 2034 | # If we're forced to take the slowpath it means we're following |
|
2035 | 2035 | # at least one pattern/directory, so don't bother with rename tracking. |
|
2036 | 2036 | if follow and not match.always() and not slowpath: |
|
2037 | 2037 | # _makefollowlogfilematcher expects its files argument to be |
|
2038 | 2038 | # relative to the repo root, so use match.files(), not pats. |
|
2039 | 2039 | filematcher = _makefollowlogfilematcher(repo, match.files(), |
|
2040 | 2040 | followfirst) |
|
2041 | 2041 | else: |
|
2042 | 2042 | filematcher = _makenofollowlogfilematcher(repo, pats, opts) |
|
2043 | 2043 | if filematcher is None: |
|
2044 | 2044 | filematcher = lambda rev: match |
|
2045 | 2045 | |
|
2046 | 2046 | expr = [] |
|
2047 | 2047 | for op, val in sorted(opts.iteritems()): |
|
2048 | 2048 | if not val: |
|
2049 | 2049 | continue |
|
2050 | 2050 | if op not in opt2revset: |
|
2051 | 2051 | continue |
|
2052 | 2052 | revop, andor = opt2revset[op] |
|
2053 | 2053 | if '%(val)' not in revop: |
|
2054 | 2054 | expr.append(revop) |
|
2055 | 2055 | else: |
|
2056 | 2056 | if not isinstance(val, list): |
|
2057 | 2057 | e = revop % {'val': val} |
|
2058 | 2058 | else: |
|
2059 | 2059 | e = '(' + andor.join((revop % {'val': v}) for v in val) + ')' |
|
2060 | 2060 | expr.append(e) |
|
2061 | 2061 | |
|
2062 | 2062 | if expr: |
|
2063 | 2063 | expr = '(' + ' and '.join(expr) + ')' |
|
2064 | 2064 | else: |
|
2065 | 2065 | expr = None |
|
2066 | 2066 | return expr, filematcher |
|
2067 | 2067 | |
|
2068 | 2068 | def _logrevs(repo, opts): |
|
2069 | 2069 | # Default --rev value depends on --follow but --follow behavior |
|
2070 | 2070 | # depends on revisions resolved from --rev... |
|
2071 | 2071 | follow = opts.get('follow') or opts.get('follow_first') |
|
2072 | 2072 | if opts.get('rev'): |
|
2073 | 2073 | revs = scmutil.revrange(repo, opts['rev']) |
|
2074 | 2074 | elif follow and repo.dirstate.p1() == nullid: |
|
2075 | 2075 | revs = revset.baseset() |
|
2076 | 2076 | elif follow: |
|
2077 | 2077 | revs = repo.revs('reverse(:.)') |
|
2078 | 2078 | else: |
|
2079 | 2079 | revs = revset.spanset(repo) |
|
2080 | 2080 | revs.reverse() |
|
2081 | 2081 | return revs |
|
2082 | 2082 | |
|
2083 | 2083 | def getgraphlogrevs(repo, pats, opts): |
|
2084 | 2084 | """Return (revs, expr, filematcher) where revs is an iterable of |
|
2085 | 2085 | revision numbers, expr is a revset string built from log options |
|
2086 | 2086 | and file patterns or None, and used to filter 'revs'. If --stat or |
|
2087 | 2087 | --patch are not passed filematcher is None. Otherwise it is a |
|
2088 | 2088 | callable taking a revision number and returning a match objects |
|
2089 | 2089 | filtering the files to be detailed when displaying the revision. |
|
2090 | 2090 | """ |
|
2091 | 2091 | limit = loglimit(opts) |
|
2092 | 2092 | revs = _logrevs(repo, opts) |
|
2093 | 2093 | if not revs: |
|
2094 | 2094 | return revset.baseset(), None, None |
|
2095 | 2095 | expr, filematcher = _makelogrevset(repo, pats, opts, revs) |
|
2096 | 2096 | if opts.get('rev'): |
|
2097 | 2097 | # User-specified revs might be unsorted, but don't sort before |
|
2098 | 2098 | # _makelogrevset because it might depend on the order of revs |
|
2099 | 2099 | revs.sort(reverse=True) |
|
2100 | 2100 | if expr: |
|
2101 | 2101 | # Revset matchers often operate faster on revisions in changelog |
|
2102 | 2102 | # order, because most filters deal with the changelog. |
|
2103 | 2103 | revs.reverse() |
|
2104 | 2104 | matcher = revset.match(repo.ui, expr) |
|
2105 | 2105 | # Revset matches can reorder revisions. "A or B" typically returns |
|
2106 | 2106 | # returns the revision matching A then the revision matching B. Sort |
|
2107 | 2107 | # again to fix that. |
|
2108 | 2108 | revs = matcher(repo, revs) |
|
2109 | 2109 | revs.sort(reverse=True) |
|
2110 | 2110 | if limit is not None: |
|
2111 | 2111 | limitedrevs = [] |
|
2112 | 2112 | for idx, rev in enumerate(revs): |
|
2113 | 2113 | if idx >= limit: |
|
2114 | 2114 | break |
|
2115 | 2115 | limitedrevs.append(rev) |
|
2116 | 2116 | revs = revset.baseset(limitedrevs) |
|
2117 | 2117 | |
|
2118 | 2118 | return revs, expr, filematcher |
|
2119 | 2119 | |
|
2120 | 2120 | def getlogrevs(repo, pats, opts): |
|
2121 | 2121 | """Return (revs, expr, filematcher) where revs is an iterable of |
|
2122 | 2122 | revision numbers, expr is a revset string built from log options |
|
2123 | 2123 | and file patterns or None, and used to filter 'revs'. If --stat or |
|
2124 | 2124 | --patch are not passed filematcher is None. Otherwise it is a |
|
2125 | 2125 | callable taking a revision number and returning a match objects |
|
2126 | 2126 | filtering the files to be detailed when displaying the revision. |
|
2127 | 2127 | """ |
|
2128 | 2128 | limit = loglimit(opts) |
|
2129 | 2129 | revs = _logrevs(repo, opts) |
|
2130 | 2130 | if not revs: |
|
2131 | 2131 | return revset.baseset([]), None, None |
|
2132 | 2132 | expr, filematcher = _makelogrevset(repo, pats, opts, revs) |
|
2133 | 2133 | if expr: |
|
2134 | 2134 | # Revset matchers often operate faster on revisions in changelog |
|
2135 | 2135 | # order, because most filters deal with the changelog. |
|
2136 | 2136 | if not opts.get('rev'): |
|
2137 | 2137 | revs.reverse() |
|
2138 | 2138 | matcher = revset.match(repo.ui, expr) |
|
2139 | 2139 | # Revset matches can reorder revisions. "A or B" typically returns |
|
2140 | 2140 | # returns the revision matching A then the revision matching B. Sort |
|
2141 | 2141 | # again to fix that. |
|
2142 | 2142 | revs = matcher(repo, revs) |
|
2143 | 2143 | if not opts.get('rev'): |
|
2144 | 2144 | revs.sort(reverse=True) |
|
2145 | 2145 | if limit is not None: |
|
2146 | 2146 | limitedrevs = [] |
|
2147 | 2147 | for idx, r in enumerate(revs): |
|
2148 | 2148 | if limit <= idx: |
|
2149 | 2149 | break |
|
2150 | 2150 | limitedrevs.append(r) |
|
2151 | 2151 | revs = revset.baseset(limitedrevs) |
|
2152 | 2152 | |
|
2153 | 2153 | return revs, expr, filematcher |
|
2154 | 2154 | |
|
2155 | 2155 | def _graphnodeformatter(ui, displayer): |
|
2156 | 2156 | spec = ui.config('ui', 'graphnodetemplate') |
|
2157 | 2157 | if not spec: |
|
2158 | 2158 | return templatekw.showgraphnode # fast path for "{graphnode}" |
|
2159 | 2159 | |
|
2160 | 2160 | templ = formatter.gettemplater(ui, 'graphnode', spec) |
|
2161 | 2161 | cache = {} |
|
2162 | 2162 | if isinstance(displayer, changeset_templater): |
|
2163 | 2163 | cache = displayer.cache # reuse cache of slow templates |
|
2164 | 2164 | props = templatekw.keywords.copy() |
|
2165 | 2165 | props['templ'] = templ |
|
2166 | 2166 | props['cache'] = cache |
|
2167 | 2167 | def formatnode(repo, ctx): |
|
2168 | 2168 | props['ctx'] = ctx |
|
2169 | 2169 | props['repo'] = repo |
|
2170 | 2170 | props['revcache'] = {} |
|
2171 | 2171 | return templater.stringify(templ('graphnode', **props)) |
|
2172 | 2172 | return formatnode |
|
2173 | 2173 | |
|
2174 | 2174 | def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None, |
|
2175 | 2175 | filematcher=None): |
|
2176 | 2176 | formatnode = _graphnodeformatter(ui, displayer) |
|
2177 | 2177 | seen, state = [], graphmod.asciistate() |
|
2178 | 2178 | for rev, type, ctx, parents in dag: |
|
2179 | 2179 | char = formatnode(repo, ctx) |
|
2180 | 2180 | copies = None |
|
2181 | 2181 | if getrenamed and ctx.rev(): |
|
2182 | 2182 | copies = [] |
|
2183 | 2183 | for fn in ctx.files(): |
|
2184 | 2184 | rename = getrenamed(fn, ctx.rev()) |
|
2185 | 2185 | if rename: |
|
2186 | 2186 | copies.append((fn, rename[0])) |
|
2187 | 2187 | revmatchfn = None |
|
2188 | 2188 | if filematcher is not None: |
|
2189 | 2189 | revmatchfn = filematcher(ctx.rev()) |
|
2190 | 2190 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
2191 | 2191 | lines = displayer.hunk.pop(rev).split('\n') |
|
2192 | 2192 | if not lines[-1]: |
|
2193 | 2193 | del lines[-1] |
|
2194 | 2194 | displayer.flush(ctx) |
|
2195 | 2195 | edges = edgefn(type, char, lines, seen, rev, parents) |
|
2196 | 2196 | for type, char, lines, coldata in edges: |
|
2197 | 2197 | graphmod.ascii(ui, state, type, char, lines, coldata) |
|
2198 | 2198 | displayer.close() |
|
2199 | 2199 | |
|
2200 | 2200 | def graphlog(ui, repo, *pats, **opts): |
|
2201 | 2201 | # Parameters are identical to log command ones |
|
2202 | 2202 | revs, expr, filematcher = getgraphlogrevs(repo, pats, opts) |
|
2203 | 2203 | revdag = graphmod.dagwalker(repo, revs) |
|
2204 | 2204 | |
|
2205 | 2205 | getrenamed = None |
|
2206 | 2206 | if opts.get('copies'): |
|
2207 | 2207 | endrev = None |
|
2208 | 2208 | if opts.get('rev'): |
|
2209 | 2209 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 |
|
2210 | 2210 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
2211 | 2211 | displayer = show_changeset(ui, repo, opts, buffered=True) |
|
2212 | 2212 | displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed, |
|
2213 | 2213 | filematcher) |
|
2214 | 2214 | |
|
2215 | 2215 | def checkunsupportedgraphflags(pats, opts): |
|
2216 | 2216 | for op in ["newest_first"]: |
|
2217 | 2217 | if op in opts and opts[op]: |
|
2218 | 2218 | raise error.Abort(_("-G/--graph option is incompatible with --%s") |
|
2219 | 2219 | % op.replace("_", "-")) |
|
2220 | 2220 | |
|
2221 | 2221 | def graphrevs(repo, nodes, opts): |
|
2222 | 2222 | limit = loglimit(opts) |
|
2223 | 2223 | nodes.reverse() |
|
2224 | 2224 | if limit is not None: |
|
2225 | 2225 | nodes = nodes[:limit] |
|
2226 | 2226 | return graphmod.nodes(repo, nodes) |
|
2227 | 2227 | |
|
2228 | 2228 | def add(ui, repo, match, prefix, explicitonly, **opts): |
|
2229 | 2229 | join = lambda f: os.path.join(prefix, f) |
|
2230 | 2230 | bad = [] |
|
2231 | 2231 | |
|
2232 | 2232 | badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
|
2233 | 2233 | names = [] |
|
2234 | 2234 | wctx = repo[None] |
|
2235 | 2235 | cca = None |
|
2236 | 2236 | abort, warn = scmutil.checkportabilityalert(ui) |
|
2237 | 2237 | if abort or warn: |
|
2238 | 2238 | cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate) |
|
2239 | 2239 | |
|
2240 | 2240 | badmatch = matchmod.badmatch(match, badfn) |
|
2241 | 2241 | dirstate = repo.dirstate |
|
2242 | 2242 | # We don't want to just call wctx.walk here, since it would return a lot of |
|
2243 | 2243 | # clean files, which we aren't interested in and takes time. |
|
2244 | 2244 | for f in sorted(dirstate.walk(badmatch, sorted(wctx.substate), |
|
2245 | 2245 | True, False, full=False)): |
|
2246 | 2246 | exact = match.exact(f) |
|
2247 | 2247 | if exact or not explicitonly and f not in wctx and repo.wvfs.lexists(f): |
|
2248 | 2248 | if cca: |
|
2249 | 2249 | cca(f) |
|
2250 | 2250 | names.append(f) |
|
2251 | 2251 | if ui.verbose or not exact: |
|
2252 | 2252 | ui.status(_('adding %s\n') % match.rel(f)) |
|
2253 | 2253 | |
|
2254 | 2254 | for subpath in sorted(wctx.substate): |
|
2255 | 2255 | sub = wctx.sub(subpath) |
|
2256 | 2256 | try: |
|
2257 | 2257 | submatch = matchmod.narrowmatcher(subpath, match) |
|
2258 | 2258 | if opts.get('subrepos'): |
|
2259 | 2259 | bad.extend(sub.add(ui, submatch, prefix, False, **opts)) |
|
2260 | 2260 | else: |
|
2261 | 2261 | bad.extend(sub.add(ui, submatch, prefix, True, **opts)) |
|
2262 | 2262 | except error.LookupError: |
|
2263 | 2263 | ui.status(_("skipping missing subrepository: %s\n") |
|
2264 | 2264 | % join(subpath)) |
|
2265 | 2265 | |
|
2266 | 2266 | if not opts.get('dry_run'): |
|
2267 | 2267 | rejected = wctx.add(names, prefix) |
|
2268 | 2268 | bad.extend(f for f in rejected if f in match.files()) |
|
2269 | 2269 | return bad |
|
2270 | 2270 | |
|
2271 | 2271 | def forget(ui, repo, match, prefix, explicitonly): |
|
2272 | 2272 | join = lambda f: os.path.join(prefix, f) |
|
2273 | 2273 | bad = [] |
|
2274 | 2274 | badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
|
2275 | 2275 | wctx = repo[None] |
|
2276 | 2276 | forgot = [] |
|
2277 | 2277 | |
|
2278 | 2278 | s = repo.status(match=matchmod.badmatch(match, badfn), clean=True) |
|
2279 | 2279 | forget = sorted(s[0] + s[1] + s[3] + s[6]) |
|
2280 | 2280 | if explicitonly: |
|
2281 | 2281 | forget = [f for f in forget if match.exact(f)] |
|
2282 | 2282 | |
|
2283 | 2283 | for subpath in sorted(wctx.substate): |
|
2284 | 2284 | sub = wctx.sub(subpath) |
|
2285 | 2285 | try: |
|
2286 | 2286 | submatch = matchmod.narrowmatcher(subpath, match) |
|
2287 | 2287 | subbad, subforgot = sub.forget(submatch, prefix) |
|
2288 | 2288 | bad.extend([subpath + '/' + f for f in subbad]) |
|
2289 | 2289 | forgot.extend([subpath + '/' + f for f in subforgot]) |
|
2290 | 2290 | except error.LookupError: |
|
2291 | 2291 | ui.status(_("skipping missing subrepository: %s\n") |
|
2292 | 2292 | % join(subpath)) |
|
2293 | 2293 | |
|
2294 | 2294 | if not explicitonly: |
|
2295 | 2295 | for f in match.files(): |
|
2296 | 2296 | if f not in repo.dirstate and not repo.wvfs.isdir(f): |
|
2297 | 2297 | if f not in forgot: |
|
2298 | 2298 | if repo.wvfs.exists(f): |
|
2299 | 2299 | # Don't complain if the exact case match wasn't given. |
|
2300 | 2300 | # But don't do this until after checking 'forgot', so |
|
2301 | 2301 | # that subrepo files aren't normalized, and this op is |
|
2302 | 2302 | # purely from data cached by the status walk above. |
|
2303 | 2303 | if repo.dirstate.normalize(f) in repo.dirstate: |
|
2304 | 2304 | continue |
|
2305 | 2305 | ui.warn(_('not removing %s: ' |
|
2306 | 2306 | 'file is already untracked\n') |
|
2307 | 2307 | % match.rel(f)) |
|
2308 | 2308 | bad.append(f) |
|
2309 | 2309 | |
|
2310 | 2310 | for f in forget: |
|
2311 | 2311 | if ui.verbose or not match.exact(f): |
|
2312 | 2312 | ui.status(_('removing %s\n') % match.rel(f)) |
|
2313 | 2313 | |
|
2314 | 2314 | rejected = wctx.forget(forget, prefix) |
|
2315 | 2315 | bad.extend(f for f in rejected if f in match.files()) |
|
2316 | 2316 | forgot.extend(f for f in forget if f not in rejected) |
|
2317 | 2317 | return bad, forgot |
|
2318 | 2318 | |
|
2319 | 2319 | def files(ui, ctx, m, fm, fmt, subrepos): |
|
2320 | 2320 | rev = ctx.rev() |
|
2321 | 2321 | ret = 1 |
|
2322 | 2322 | ds = ctx.repo().dirstate |
|
2323 | 2323 | |
|
2324 | 2324 | for f in ctx.matches(m): |
|
2325 | 2325 | if rev is None and ds[f] == 'r': |
|
2326 | 2326 | continue |
|
2327 | 2327 | fm.startitem() |
|
2328 | 2328 | if ui.verbose: |
|
2329 | 2329 | fc = ctx[f] |
|
2330 | 2330 | fm.write('size flags', '% 10d % 1s ', fc.size(), fc.flags()) |
|
2331 | 2331 | fm.data(abspath=f) |
|
2332 | 2332 | fm.write('path', fmt, m.rel(f)) |
|
2333 | 2333 | ret = 0 |
|
2334 | 2334 | |
|
2335 | 2335 | for subpath in sorted(ctx.substate): |
|
2336 | 2336 | def matchessubrepo(subpath): |
|
2337 | 2337 | return (m.always() or m.exact(subpath) |
|
2338 | 2338 | or any(f.startswith(subpath + '/') for f in m.files())) |
|
2339 | 2339 | |
|
2340 | 2340 | if subrepos or matchessubrepo(subpath): |
|
2341 | 2341 | sub = ctx.sub(subpath) |
|
2342 | 2342 | try: |
|
2343 | 2343 | submatch = matchmod.narrowmatcher(subpath, m) |
|
2344 | 2344 | if sub.printfiles(ui, submatch, fm, fmt, subrepos) == 0: |
|
2345 | 2345 | ret = 0 |
|
2346 | 2346 | except error.LookupError: |
|
2347 | 2347 | ui.status(_("skipping missing subrepository: %s\n") |
|
2348 | 2348 | % m.abs(subpath)) |
|
2349 | 2349 | |
|
2350 | 2350 | return ret |
|
2351 | 2351 | |
|
2352 | 2352 | def remove(ui, repo, m, prefix, after, force, subrepos): |
|
2353 | 2353 | join = lambda f: os.path.join(prefix, f) |
|
2354 | 2354 | ret = 0 |
|
2355 | 2355 | s = repo.status(match=m, clean=True) |
|
2356 | 2356 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
|
2357 | 2357 | |
|
2358 | 2358 | wctx = repo[None] |
|
2359 | 2359 | |
|
2360 | 2360 | for subpath in sorted(wctx.substate): |
|
2361 | 2361 | def matchessubrepo(matcher, subpath): |
|
2362 | 2362 | if matcher.exact(subpath): |
|
2363 | 2363 | return True |
|
2364 | 2364 | for f in matcher.files(): |
|
2365 | 2365 | if f.startswith(subpath): |
|
2366 | 2366 | return True |
|
2367 | 2367 | return False |
|
2368 | 2368 | |
|
2369 | 2369 | if subrepos or matchessubrepo(m, subpath): |
|
2370 | 2370 | sub = wctx.sub(subpath) |
|
2371 | 2371 | try: |
|
2372 | 2372 | submatch = matchmod.narrowmatcher(subpath, m) |
|
2373 | 2373 | if sub.removefiles(submatch, prefix, after, force, subrepos): |
|
2374 | 2374 | ret = 1 |
|
2375 | 2375 | except error.LookupError: |
|
2376 | 2376 | ui.status(_("skipping missing subrepository: %s\n") |
|
2377 | 2377 | % join(subpath)) |
|
2378 | 2378 | |
|
2379 | 2379 | # warn about failure to delete explicit files/dirs |
|
2380 | 2380 | deleteddirs = util.dirs(deleted) |
|
2381 | 2381 | for f in m.files(): |
|
2382 | 2382 | def insubrepo(): |
|
2383 | 2383 | for subpath in wctx.substate: |
|
2384 | 2384 | if f.startswith(subpath): |
|
2385 | 2385 | return True |
|
2386 | 2386 | return False |
|
2387 | 2387 | |
|
2388 | 2388 | isdir = f in deleteddirs or wctx.hasdir(f) |
|
2389 | 2389 | if f in repo.dirstate or isdir or f == '.' or insubrepo(): |
|
2390 | 2390 | continue |
|
2391 | 2391 | |
|
2392 | 2392 | if repo.wvfs.exists(f): |
|
2393 | 2393 | if repo.wvfs.isdir(f): |
|
2394 | 2394 | ui.warn(_('not removing %s: no tracked files\n') |
|
2395 | 2395 | % m.rel(f)) |
|
2396 | 2396 | else: |
|
2397 | 2397 | ui.warn(_('not removing %s: file is untracked\n') |
|
2398 | 2398 | % m.rel(f)) |
|
2399 | 2399 | # missing files will generate a warning elsewhere |
|
2400 | 2400 | ret = 1 |
|
2401 | 2401 | |
|
2402 | 2402 | if force: |
|
2403 | 2403 | list = modified + deleted + clean + added |
|
2404 | 2404 | elif after: |
|
2405 | 2405 | list = deleted |
|
2406 | 2406 | for f in modified + added + clean: |
|
2407 | 2407 | ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) |
|
2408 | 2408 | ret = 1 |
|
2409 | 2409 | else: |
|
2410 | 2410 | list = deleted + clean |
|
2411 | 2411 | for f in modified: |
|
2412 | 2412 | ui.warn(_('not removing %s: file is modified (use -f' |
|
2413 | 2413 | ' to force removal)\n') % m.rel(f)) |
|
2414 | 2414 | ret = 1 |
|
2415 | 2415 | for f in added: |
|
2416 | 2416 | ui.warn(_('not removing %s: file has been marked for add' |
|
2417 | 2417 | ' (use forget to undo)\n') % m.rel(f)) |
|
2418 | 2418 | ret = 1 |
|
2419 | 2419 | |
|
2420 | 2420 | for f in sorted(list): |
|
2421 | 2421 | if ui.verbose or not m.exact(f): |
|
2422 | 2422 | ui.status(_('removing %s\n') % m.rel(f)) |
|
2423 | 2423 | |
|
2424 | 2424 | with repo.wlock(): |
|
2425 | 2425 | if not after: |
|
2426 | 2426 | for f in list: |
|
2427 | 2427 | if f in added: |
|
2428 | 2428 | continue # we never unlink added files on remove |
|
2429 | 2429 | util.unlinkpath(repo.wjoin(f), ignoremissing=True) |
|
2430 | 2430 | repo[None].forget(list) |
|
2431 | 2431 | |
|
2432 | 2432 | return ret |
|
2433 | 2433 | |
|
2434 | 2434 | def cat(ui, repo, ctx, matcher, prefix, **opts): |
|
2435 | 2435 | err = 1 |
|
2436 | 2436 | |
|
2437 | 2437 | def write(path): |
|
2438 | 2438 | fp = makefileobj(repo, opts.get('output'), ctx.node(), |
|
2439 | 2439 | pathname=os.path.join(prefix, path)) |
|
2440 | 2440 | data = ctx[path].data() |
|
2441 | 2441 | if opts.get('decode'): |
|
2442 | 2442 | data = repo.wwritedata(path, data) |
|
2443 | 2443 | fp.write(data) |
|
2444 | 2444 | fp.close() |
|
2445 | 2445 | |
|
2446 | 2446 | # Automation often uses hg cat on single files, so special case it |
|
2447 | 2447 | # for performance to avoid the cost of parsing the manifest. |
|
2448 | 2448 | if len(matcher.files()) == 1 and not matcher.anypats(): |
|
2449 | 2449 | file = matcher.files()[0] |
|
2450 | 2450 | mf = repo.manifest |
|
2451 | 2451 | mfnode = ctx.manifestnode() |
|
2452 | 2452 | if mfnode and mf.find(mfnode, file)[0]: |
|
2453 | 2453 | write(file) |
|
2454 | 2454 | return 0 |
|
2455 | 2455 | |
|
2456 | 2456 | # Don't warn about "missing" files that are really in subrepos |
|
2457 | 2457 | def badfn(path, msg): |
|
2458 | 2458 | for subpath in ctx.substate: |
|
2459 | 2459 | if path.startswith(subpath): |
|
2460 | 2460 | return |
|
2461 | 2461 | matcher.bad(path, msg) |
|
2462 | 2462 | |
|
2463 | 2463 | for abs in ctx.walk(matchmod.badmatch(matcher, badfn)): |
|
2464 | 2464 | write(abs) |
|
2465 | 2465 | err = 0 |
|
2466 | 2466 | |
|
2467 | 2467 | for subpath in sorted(ctx.substate): |
|
2468 | 2468 | sub = ctx.sub(subpath) |
|
2469 | 2469 | try: |
|
2470 | 2470 | submatch = matchmod.narrowmatcher(subpath, matcher) |
|
2471 | 2471 | |
|
2472 | 2472 | if not sub.cat(submatch, os.path.join(prefix, sub._path), |
|
2473 | 2473 | **opts): |
|
2474 | 2474 | err = 0 |
|
2475 | 2475 | except error.RepoLookupError: |
|
2476 | 2476 | ui.status(_("skipping missing subrepository: %s\n") |
|
2477 | 2477 | % os.path.join(prefix, subpath)) |
|
2478 | 2478 | |
|
2479 | 2479 | return err |
|
2480 | 2480 | |
|
2481 | 2481 | def commit(ui, repo, commitfunc, pats, opts): |
|
2482 | 2482 | '''commit the specified files or all outstanding changes''' |
|
2483 | 2483 | date = opts.get('date') |
|
2484 | 2484 | if date: |
|
2485 | 2485 | opts['date'] = util.parsedate(date) |
|
2486 | 2486 | message = logmessage(ui, opts) |
|
2487 | 2487 | matcher = scmutil.match(repo[None], pats, opts) |
|
2488 | 2488 | |
|
2489 | 2489 | # extract addremove carefully -- this function can be called from a command |
|
2490 | 2490 | # that doesn't support addremove |
|
2491 | 2491 | if opts.get('addremove'): |
|
2492 | 2492 | if scmutil.addremove(repo, matcher, "", opts) != 0: |
|
2493 | 2493 | raise error.Abort( |
|
2494 | 2494 | _("failed to mark all new/missing files as added/removed")) |
|
2495 | 2495 | |
|
2496 | 2496 | return commitfunc(ui, repo, message, matcher, opts) |
|
2497 | 2497 | |
|
2498 | 2498 | def amend(ui, repo, commitfunc, old, extra, pats, opts): |
|
2499 | 2499 | # avoid cycle context -> subrepo -> cmdutil |
|
2500 | 2500 | import context |
|
2501 | 2501 | |
|
2502 | 2502 | # amend will reuse the existing user if not specified, but the obsolete |
|
2503 | 2503 | # marker creation requires that the current user's name is specified. |
|
2504 | 2504 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
2505 | 2505 | ui.username() # raise exception if username not set |
|
2506 | 2506 | |
|
2507 | 2507 | ui.note(_('amending changeset %s\n') % old) |
|
2508 | 2508 | base = old.p1() |
|
2509 | 2509 | createmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt) |
|
2510 | 2510 | |
|
2511 | 2511 | wlock = lock = newid = None |
|
2512 | 2512 | try: |
|
2513 | 2513 | wlock = repo.wlock() |
|
2514 | 2514 | lock = repo.lock() |
|
2515 | 2515 | with repo.transaction('amend') as tr: |
|
2516 | 2516 | # See if we got a message from -m or -l, if not, open the editor |
|
2517 | 2517 | # with the message of the changeset to amend |
|
2518 | 2518 | message = logmessage(ui, opts) |
|
2519 | 2519 | # ensure logfile does not conflict with later enforcement of the |
|
2520 | 2520 | # message. potential logfile content has been processed by |
|
2521 | 2521 | # `logmessage` anyway. |
|
2522 | 2522 | opts.pop('logfile') |
|
2523 | 2523 | # First, do a regular commit to record all changes in the working |
|
2524 | 2524 | # directory (if there are any) |
|
2525 | 2525 | ui.callhooks = False |
|
2526 | 2526 | activebookmark = repo._bookmarks.active |
|
2527 | 2527 | try: |
|
2528 | 2528 | repo._bookmarks.active = None |
|
2529 | 2529 | opts['message'] = 'temporary amend commit for %s' % old |
|
2530 | 2530 | node = commit(ui, repo, commitfunc, pats, opts) |
|
2531 | 2531 | finally: |
|
2532 | 2532 | repo._bookmarks.active = activebookmark |
|
2533 | 2533 | repo._bookmarks.recordchange(tr) |
|
2534 | 2534 | ui.callhooks = True |
|
2535 | 2535 | ctx = repo[node] |
|
2536 | 2536 | |
|
2537 | 2537 | # Participating changesets: |
|
2538 | 2538 | # |
|
2539 | 2539 | # node/ctx o - new (intermediate) commit that contains changes |
|
2540 | 2540 | # | from working dir to go into amending commit |
|
2541 | 2541 | # | (or a workingctx if there were no changes) |
|
2542 | 2542 | # | |
|
2543 | 2543 | # old o - changeset to amend |
|
2544 | 2544 | # | |
|
2545 | 2545 | # base o - parent of amending changeset |
|
2546 | 2546 | |
|
2547 | 2547 | # Update extra dict from amended commit (e.g. to preserve graft |
|
2548 | 2548 | # source) |
|
2549 | 2549 | extra.update(old.extra()) |
|
2550 | 2550 | |
|
2551 | 2551 | # Also update it from the intermediate commit or from the wctx |
|
2552 | 2552 | extra.update(ctx.extra()) |
|
2553 | 2553 | |
|
2554 | 2554 | if len(old.parents()) > 1: |
|
2555 | 2555 | # ctx.files() isn't reliable for merges, so fall back to the |
|
2556 | 2556 | # slower repo.status() method |
|
2557 | 2557 | files = set([fn for st in repo.status(base, old)[:3] |
|
2558 | 2558 | for fn in st]) |
|
2559 | 2559 | else: |
|
2560 | 2560 | files = set(old.files()) |
|
2561 | 2561 | |
|
2562 | 2562 | # Second, we use either the commit we just did, or if there were no |
|
2563 | 2563 | # changes the parent of the working directory as the version of the |
|
2564 | 2564 | # files in the final amend commit |
|
2565 | 2565 | if node: |
|
2566 | 2566 | ui.note(_('copying changeset %s to %s\n') % (ctx, base)) |
|
2567 | 2567 | |
|
2568 | 2568 | user = ctx.user() |
|
2569 | 2569 | date = ctx.date() |
|
2570 | 2570 | # Recompute copies (avoid recording a -> b -> a) |
|
2571 | 2571 | copied = copies.pathcopies(base, ctx) |
|
2572 | 2572 | if old.p2: |
|
2573 | 2573 | copied.update(copies.pathcopies(old.p2(), ctx)) |
|
2574 | 2574 | |
|
2575 | 2575 | # Prune files which were reverted by the updates: if old |
|
2576 | 2576 | # introduced file X and our intermediate commit, node, |
|
2577 | 2577 | # renamed that file, then those two files are the same and |
|
2578 | 2578 | # we can discard X from our list of files. Likewise if X |
|
2579 | 2579 | # was deleted, it's no longer relevant |
|
2580 | 2580 | files.update(ctx.files()) |
|
2581 | 2581 | |
|
2582 | 2582 | def samefile(f): |
|
2583 | 2583 | if f in ctx.manifest(): |
|
2584 | 2584 | a = ctx.filectx(f) |
|
2585 | 2585 | if f in base.manifest(): |
|
2586 | 2586 | b = base.filectx(f) |
|
2587 | 2587 | return (not a.cmp(b) |
|
2588 | 2588 | and a.flags() == b.flags()) |
|
2589 | 2589 | else: |
|
2590 | 2590 | return False |
|
2591 | 2591 | else: |
|
2592 | 2592 | return f not in base.manifest() |
|
2593 | 2593 | files = [f for f in files if not samefile(f)] |
|
2594 | 2594 | |
|
2595 | 2595 | def filectxfn(repo, ctx_, path): |
|
2596 | 2596 | try: |
|
2597 | 2597 | fctx = ctx[path] |
|
2598 | 2598 | flags = fctx.flags() |
|
2599 | 2599 | mctx = context.memfilectx(repo, |
|
2600 | 2600 | fctx.path(), fctx.data(), |
|
2601 | 2601 | islink='l' in flags, |
|
2602 | 2602 | isexec='x' in flags, |
|
2603 | 2603 | copied=copied.get(path)) |
|
2604 | 2604 | return mctx |
|
2605 | 2605 | except KeyError: |
|
2606 | 2606 | return None |
|
2607 | 2607 | else: |
|
2608 | 2608 | ui.note(_('copying changeset %s to %s\n') % (old, base)) |
|
2609 | 2609 | |
|
2610 | 2610 | # Use version of files as in the old cset |
|
2611 | 2611 | def filectxfn(repo, ctx_, path): |
|
2612 | 2612 | try: |
|
2613 | 2613 | return old.filectx(path) |
|
2614 | 2614 | except KeyError: |
|
2615 | 2615 | return None |
|
2616 | 2616 | |
|
2617 | 2617 | user = opts.get('user') or old.user() |
|
2618 | 2618 | date = opts.get('date') or old.date() |
|
2619 | 2619 | editform = mergeeditform(old, 'commit.amend') |
|
2620 | 2620 | editor = getcommiteditor(editform=editform, **opts) |
|
2621 | 2621 | if not message: |
|
2622 | 2622 | editor = getcommiteditor(edit=True, editform=editform) |
|
2623 | 2623 | message = old.description() |
|
2624 | 2624 | |
|
2625 | 2625 | pureextra = extra.copy() |
|
2626 | if 'amend_source' in pureextra: | |
|
2627 | del pureextra['amend_source'] | |
|
2628 | pureoldextra = old.extra() | |
|
2629 | if 'amend_source' in pureoldextra: | |
|
2630 | del pureoldextra['amend_source'] | |
|
2631 | 2626 | extra['amend_source'] = old.hex() |
|
2632 | 2627 | |
|
2633 | 2628 | new = context.memctx(repo, |
|
2634 | 2629 | parents=[base.node(), old.p2().node()], |
|
2635 | 2630 | text=message, |
|
2636 | 2631 | files=files, |
|
2637 | 2632 | filectxfn=filectxfn, |
|
2638 | 2633 | user=user, |
|
2639 | 2634 | date=date, |
|
2640 | 2635 | extra=extra, |
|
2641 | 2636 | editor=editor) |
|
2642 | 2637 | |
|
2643 | 2638 | newdesc = changelog.stripdesc(new.description()) |
|
2644 | 2639 | if ((not node) |
|
2645 | 2640 | and newdesc == old.description() |
|
2646 | 2641 | and user == old.user() |
|
2647 | 2642 | and date == old.date() |
|
2648 |
and pureextra == |
|
|
2643 | and pureextra == old.extra()): | |
|
2649 | 2644 | # nothing changed. continuing here would create a new node |
|
2650 | 2645 | # anyway because of the amend_source noise. |
|
2651 | 2646 | # |
|
2652 | 2647 | # This not what we expect from amend. |
|
2653 | 2648 | return old.node() |
|
2654 | 2649 | |
|
2655 | 2650 | ph = repo.ui.config('phases', 'new-commit', phases.draft) |
|
2656 | 2651 | try: |
|
2657 | 2652 | if opts.get('secret'): |
|
2658 | 2653 | commitphase = 'secret' |
|
2659 | 2654 | else: |
|
2660 | 2655 | commitphase = old.phase() |
|
2661 | 2656 | repo.ui.setconfig('phases', 'new-commit', commitphase, 'amend') |
|
2662 | 2657 | newid = repo.commitctx(new) |
|
2663 | 2658 | finally: |
|
2664 | 2659 | repo.ui.setconfig('phases', 'new-commit', ph, 'amend') |
|
2665 | 2660 | if newid != old.node(): |
|
2666 | 2661 | # Reroute the working copy parent to the new changeset |
|
2667 | 2662 | repo.setparents(newid, nullid) |
|
2668 | 2663 | |
|
2669 | 2664 | # Move bookmarks from old parent to amend commit |
|
2670 | 2665 | bms = repo.nodebookmarks(old.node()) |
|
2671 | 2666 | if bms: |
|
2672 | 2667 | marks = repo._bookmarks |
|
2673 | 2668 | for bm in bms: |
|
2674 | 2669 | ui.debug('moving bookmarks %r from %s to %s\n' % |
|
2675 | 2670 | (marks, old.hex(), hex(newid))) |
|
2676 | 2671 | marks[bm] = newid |
|
2677 | 2672 | marks.recordchange(tr) |
|
2678 | 2673 | #commit the whole amend process |
|
2679 | 2674 | if createmarkers: |
|
2680 | 2675 | # mark the new changeset as successor of the rewritten one |
|
2681 | 2676 | new = repo[newid] |
|
2682 | 2677 | obs = [(old, (new,))] |
|
2683 | 2678 | if node: |
|
2684 | 2679 | obs.append((ctx, ())) |
|
2685 | 2680 | |
|
2686 | 2681 | obsolete.createmarkers(repo, obs) |
|
2687 | 2682 | if not createmarkers and newid != old.node(): |
|
2688 | 2683 | # Strip the intermediate commit (if there was one) and the amended |
|
2689 | 2684 | # commit |
|
2690 | 2685 | if node: |
|
2691 | 2686 | ui.note(_('stripping intermediate changeset %s\n') % ctx) |
|
2692 | 2687 | ui.note(_('stripping amended changeset %s\n') % old) |
|
2693 | 2688 | repair.strip(ui, repo, old.node(), topic='amend-backup') |
|
2694 | 2689 | finally: |
|
2695 | 2690 | lockmod.release(lock, wlock) |
|
2696 | 2691 | return newid |
|
2697 | 2692 | |
|
2698 | 2693 | def commiteditor(repo, ctx, subs, editform=''): |
|
2699 | 2694 | if ctx.description(): |
|
2700 | 2695 | return ctx.description() |
|
2701 | 2696 | return commitforceeditor(repo, ctx, subs, editform=editform, |
|
2702 | 2697 | unchangedmessagedetection=True) |
|
2703 | 2698 | |
|
2704 | 2699 | def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None, |
|
2705 | 2700 | editform='', unchangedmessagedetection=False): |
|
2706 | 2701 | if not extramsg: |
|
2707 | 2702 | extramsg = _("Leave message empty to abort commit.") |
|
2708 | 2703 | |
|
2709 | 2704 | forms = [e for e in editform.split('.') if e] |
|
2710 | 2705 | forms.insert(0, 'changeset') |
|
2711 | 2706 | templatetext = None |
|
2712 | 2707 | while forms: |
|
2713 | 2708 | tmpl = repo.ui.config('committemplate', '.'.join(forms)) |
|
2714 | 2709 | if tmpl: |
|
2715 | 2710 | templatetext = committext = buildcommittemplate( |
|
2716 | 2711 | repo, ctx, subs, extramsg, tmpl) |
|
2717 | 2712 | break |
|
2718 | 2713 | forms.pop() |
|
2719 | 2714 | else: |
|
2720 | 2715 | committext = buildcommittext(repo, ctx, subs, extramsg) |
|
2721 | 2716 | |
|
2722 | 2717 | # run editor in the repository root |
|
2723 | 2718 | olddir = os.getcwd() |
|
2724 | 2719 | os.chdir(repo.root) |
|
2725 | 2720 | |
|
2726 | 2721 | # make in-memory changes visible to external process |
|
2727 | 2722 | tr = repo.currenttransaction() |
|
2728 | 2723 | repo.dirstate.write(tr) |
|
2729 | 2724 | pending = tr and tr.writepending() and repo.root |
|
2730 | 2725 | |
|
2731 | 2726 | editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(), |
|
2732 | 2727 | editform=editform, pending=pending) |
|
2733 | 2728 | text = re.sub("(?m)^HG:.*(\n|$)", "", editortext) |
|
2734 | 2729 | os.chdir(olddir) |
|
2735 | 2730 | |
|
2736 | 2731 | if finishdesc: |
|
2737 | 2732 | text = finishdesc(text) |
|
2738 | 2733 | if not text.strip(): |
|
2739 | 2734 | raise error.Abort(_("empty commit message")) |
|
2740 | 2735 | if unchangedmessagedetection and editortext == templatetext: |
|
2741 | 2736 | raise error.Abort(_("commit message unchanged")) |
|
2742 | 2737 | |
|
2743 | 2738 | return text |
|
2744 | 2739 | |
|
2745 | 2740 | def buildcommittemplate(repo, ctx, subs, extramsg, tmpl): |
|
2746 | 2741 | ui = repo.ui |
|
2747 | 2742 | tmpl, mapfile = gettemplate(ui, tmpl, None) |
|
2748 | 2743 | |
|
2749 | 2744 | try: |
|
2750 | 2745 | t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False) |
|
2751 | 2746 | except SyntaxError as inst: |
|
2752 | 2747 | raise error.Abort(inst.args[0]) |
|
2753 | 2748 | |
|
2754 | 2749 | for k, v in repo.ui.configitems('committemplate'): |
|
2755 | 2750 | if k != 'changeset': |
|
2756 | 2751 | t.t.cache[k] = v |
|
2757 | 2752 | |
|
2758 | 2753 | if not extramsg: |
|
2759 | 2754 | extramsg = '' # ensure that extramsg is string |
|
2760 | 2755 | |
|
2761 | 2756 | ui.pushbuffer() |
|
2762 | 2757 | t.show(ctx, extramsg=extramsg) |
|
2763 | 2758 | return ui.popbuffer() |
|
2764 | 2759 | |
|
2765 | 2760 | def hgprefix(msg): |
|
2766 | 2761 | return "\n".join(["HG: %s" % a for a in msg.split("\n") if a]) |
|
2767 | 2762 | |
|
2768 | 2763 | def buildcommittext(repo, ctx, subs, extramsg): |
|
2769 | 2764 | edittext = [] |
|
2770 | 2765 | modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
|
2771 | 2766 | if ctx.description(): |
|
2772 | 2767 | edittext.append(ctx.description()) |
|
2773 | 2768 | edittext.append("") |
|
2774 | 2769 | edittext.append("") # Empty line between message and comments. |
|
2775 | 2770 | edittext.append(hgprefix(_("Enter commit message." |
|
2776 | 2771 | " Lines beginning with 'HG:' are removed."))) |
|
2777 | 2772 | edittext.append(hgprefix(extramsg)) |
|
2778 | 2773 | edittext.append("HG: --") |
|
2779 | 2774 | edittext.append(hgprefix(_("user: %s") % ctx.user())) |
|
2780 | 2775 | if ctx.p2(): |
|
2781 | 2776 | edittext.append(hgprefix(_("branch merge"))) |
|
2782 | 2777 | if ctx.branch(): |
|
2783 | 2778 | edittext.append(hgprefix(_("branch '%s'") % ctx.branch())) |
|
2784 | 2779 | if bookmarks.isactivewdirparent(repo): |
|
2785 | 2780 | edittext.append(hgprefix(_("bookmark '%s'") % repo._activebookmark)) |
|
2786 | 2781 | edittext.extend([hgprefix(_("subrepo %s") % s) for s in subs]) |
|
2787 | 2782 | edittext.extend([hgprefix(_("added %s") % f) for f in added]) |
|
2788 | 2783 | edittext.extend([hgprefix(_("changed %s") % f) for f in modified]) |
|
2789 | 2784 | edittext.extend([hgprefix(_("removed %s") % f) for f in removed]) |
|
2790 | 2785 | if not added and not modified and not removed: |
|
2791 | 2786 | edittext.append(hgprefix(_("no files changed"))) |
|
2792 | 2787 | edittext.append("") |
|
2793 | 2788 | |
|
2794 | 2789 | return "\n".join(edittext) |
|
2795 | 2790 | |
|
2796 | 2791 | def commitstatus(repo, node, branch, bheads=None, opts=None): |
|
2797 | 2792 | if opts is None: |
|
2798 | 2793 | opts = {} |
|
2799 | 2794 | ctx = repo[node] |
|
2800 | 2795 | parents = ctx.parents() |
|
2801 | 2796 | |
|
2802 | 2797 | if (not opts.get('amend') and bheads and node not in bheads and not |
|
2803 | 2798 | [x for x in parents if x.node() in bheads and x.branch() == branch]): |
|
2804 | 2799 | repo.ui.status(_('created new head\n')) |
|
2805 | 2800 | # The message is not printed for initial roots. For the other |
|
2806 | 2801 | # changesets, it is printed in the following situations: |
|
2807 | 2802 | # |
|
2808 | 2803 | # Par column: for the 2 parents with ... |
|
2809 | 2804 | # N: null or no parent |
|
2810 | 2805 | # B: parent is on another named branch |
|
2811 | 2806 | # C: parent is a regular non head changeset |
|
2812 | 2807 | # H: parent was a branch head of the current branch |
|
2813 | 2808 | # Msg column: whether we print "created new head" message |
|
2814 | 2809 | # In the following, it is assumed that there already exists some |
|
2815 | 2810 | # initial branch heads of the current branch, otherwise nothing is |
|
2816 | 2811 | # printed anyway. |
|
2817 | 2812 | # |
|
2818 | 2813 | # Par Msg Comment |
|
2819 | 2814 | # N N y additional topo root |
|
2820 | 2815 | # |
|
2821 | 2816 | # B N y additional branch root |
|
2822 | 2817 | # C N y additional topo head |
|
2823 | 2818 | # H N n usual case |
|
2824 | 2819 | # |
|
2825 | 2820 | # B B y weird additional branch root |
|
2826 | 2821 | # C B y branch merge |
|
2827 | 2822 | # H B n merge with named branch |
|
2828 | 2823 | # |
|
2829 | 2824 | # C C y additional head from merge |
|
2830 | 2825 | # C H n merge with a head |
|
2831 | 2826 | # |
|
2832 | 2827 | # H H n head merge: head count decreases |
|
2833 | 2828 | |
|
2834 | 2829 | if not opts.get('close_branch'): |
|
2835 | 2830 | for r in parents: |
|
2836 | 2831 | if r.closesbranch() and r.branch() == branch: |
|
2837 | 2832 | repo.ui.status(_('reopening closed branch head %d\n') % r) |
|
2838 | 2833 | |
|
2839 | 2834 | if repo.ui.debugflag: |
|
2840 | 2835 | repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex())) |
|
2841 | 2836 | elif repo.ui.verbose: |
|
2842 | 2837 | repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx)) |
|
2843 | 2838 | |
|
2844 | 2839 | def postcommitstatus(repo, pats, opts): |
|
2845 | 2840 | return repo.status(match=scmutil.match(repo[None], pats, opts)) |
|
2846 | 2841 | |
|
2847 | 2842 | def revert(ui, repo, ctx, parents, *pats, **opts): |
|
2848 | 2843 | parent, p2 = parents |
|
2849 | 2844 | node = ctx.node() |
|
2850 | 2845 | |
|
2851 | 2846 | mf = ctx.manifest() |
|
2852 | 2847 | if node == p2: |
|
2853 | 2848 | parent = p2 |
|
2854 | 2849 | if node == parent: |
|
2855 | 2850 | pmf = mf |
|
2856 | 2851 | else: |
|
2857 | 2852 | pmf = None |
|
2858 | 2853 | |
|
2859 | 2854 | # need all matching names in dirstate and manifest of target rev, |
|
2860 | 2855 | # so have to walk both. do not print errors if files exist in one |
|
2861 | 2856 | # but not other. in both cases, filesets should be evaluated against |
|
2862 | 2857 | # workingctx to get consistent result (issue4497). this means 'set:**' |
|
2863 | 2858 | # cannot be used to select missing files from target rev. |
|
2864 | 2859 | |
|
2865 | 2860 | # `names` is a mapping for all elements in working copy and target revision |
|
2866 | 2861 | # The mapping is in the form: |
|
2867 | 2862 | # <asb path in repo> -> (<path from CWD>, <exactly specified by matcher?>) |
|
2868 | 2863 | names = {} |
|
2869 | 2864 | |
|
2870 | 2865 | with repo.wlock(): |
|
2871 | 2866 | ## filling of the `names` mapping |
|
2872 | 2867 | # walk dirstate to fill `names` |
|
2873 | 2868 | |
|
2874 | 2869 | interactive = opts.get('interactive', False) |
|
2875 | 2870 | wctx = repo[None] |
|
2876 | 2871 | m = scmutil.match(wctx, pats, opts) |
|
2877 | 2872 | |
|
2878 | 2873 | # we'll need this later |
|
2879 | 2874 | targetsubs = sorted(s for s in wctx.substate if m(s)) |
|
2880 | 2875 | |
|
2881 | 2876 | if not m.always(): |
|
2882 | 2877 | for abs in repo.walk(matchmod.badmatch(m, lambda x, y: False)): |
|
2883 | 2878 | names[abs] = m.rel(abs), m.exact(abs) |
|
2884 | 2879 | |
|
2885 | 2880 | # walk target manifest to fill `names` |
|
2886 | 2881 | |
|
2887 | 2882 | def badfn(path, msg): |
|
2888 | 2883 | if path in names: |
|
2889 | 2884 | return |
|
2890 | 2885 | if path in ctx.substate: |
|
2891 | 2886 | return |
|
2892 | 2887 | path_ = path + '/' |
|
2893 | 2888 | for f in names: |
|
2894 | 2889 | if f.startswith(path_): |
|
2895 | 2890 | return |
|
2896 | 2891 | ui.warn("%s: %s\n" % (m.rel(path), msg)) |
|
2897 | 2892 | |
|
2898 | 2893 | for abs in ctx.walk(matchmod.badmatch(m, badfn)): |
|
2899 | 2894 | if abs not in names: |
|
2900 | 2895 | names[abs] = m.rel(abs), m.exact(abs) |
|
2901 | 2896 | |
|
2902 | 2897 | # Find status of all file in `names`. |
|
2903 | 2898 | m = scmutil.matchfiles(repo, names) |
|
2904 | 2899 | |
|
2905 | 2900 | changes = repo.status(node1=node, match=m, |
|
2906 | 2901 | unknown=True, ignored=True, clean=True) |
|
2907 | 2902 | else: |
|
2908 | 2903 | changes = repo.status(node1=node, match=m) |
|
2909 | 2904 | for kind in changes: |
|
2910 | 2905 | for abs in kind: |
|
2911 | 2906 | names[abs] = m.rel(abs), m.exact(abs) |
|
2912 | 2907 | |
|
2913 | 2908 | m = scmutil.matchfiles(repo, names) |
|
2914 | 2909 | |
|
2915 | 2910 | modified = set(changes.modified) |
|
2916 | 2911 | added = set(changes.added) |
|
2917 | 2912 | removed = set(changes.removed) |
|
2918 | 2913 | _deleted = set(changes.deleted) |
|
2919 | 2914 | unknown = set(changes.unknown) |
|
2920 | 2915 | unknown.update(changes.ignored) |
|
2921 | 2916 | clean = set(changes.clean) |
|
2922 | 2917 | modadded = set() |
|
2923 | 2918 | |
|
2924 | 2919 | # split between files known in target manifest and the others |
|
2925 | 2920 | smf = set(mf) |
|
2926 | 2921 | |
|
2927 | 2922 | # determine the exact nature of the deleted changesets |
|
2928 | 2923 | deladded = _deleted - smf |
|
2929 | 2924 | deleted = _deleted - deladded |
|
2930 | 2925 | |
|
2931 | 2926 | # We need to account for the state of the file in the dirstate, |
|
2932 | 2927 | # even when we revert against something else than parent. This will |
|
2933 | 2928 | # slightly alter the behavior of revert (doing back up or not, delete |
|
2934 | 2929 | # or just forget etc). |
|
2935 | 2930 | if parent == node: |
|
2936 | 2931 | dsmodified = modified |
|
2937 | 2932 | dsadded = added |
|
2938 | 2933 | dsremoved = removed |
|
2939 | 2934 | # store all local modifications, useful later for rename detection |
|
2940 | 2935 | localchanges = dsmodified | dsadded |
|
2941 | 2936 | modified, added, removed = set(), set(), set() |
|
2942 | 2937 | else: |
|
2943 | 2938 | changes = repo.status(node1=parent, match=m) |
|
2944 | 2939 | dsmodified = set(changes.modified) |
|
2945 | 2940 | dsadded = set(changes.added) |
|
2946 | 2941 | dsremoved = set(changes.removed) |
|
2947 | 2942 | # store all local modifications, useful later for rename detection |
|
2948 | 2943 | localchanges = dsmodified | dsadded |
|
2949 | 2944 | |
|
2950 | 2945 | # only take into account for removes between wc and target |
|
2951 | 2946 | clean |= dsremoved - removed |
|
2952 | 2947 | dsremoved &= removed |
|
2953 | 2948 | # distinct between dirstate remove and other |
|
2954 | 2949 | removed -= dsremoved |
|
2955 | 2950 | |
|
2956 | 2951 | modadded = added & dsmodified |
|
2957 | 2952 | added -= modadded |
|
2958 | 2953 | |
|
2959 | 2954 | # tell newly modified apart. |
|
2960 | 2955 | dsmodified &= modified |
|
2961 | 2956 | dsmodified |= modified & dsadded # dirstate added may needs backup |
|
2962 | 2957 | modified -= dsmodified |
|
2963 | 2958 | |
|
2964 | 2959 | # We need to wait for some post-processing to update this set |
|
2965 | 2960 | # before making the distinction. The dirstate will be used for |
|
2966 | 2961 | # that purpose. |
|
2967 | 2962 | dsadded = added |
|
2968 | 2963 | |
|
2969 | 2964 | # in case of merge, files that are actually added can be reported as |
|
2970 | 2965 | # modified, we need to post process the result |
|
2971 | 2966 | if p2 != nullid: |
|
2972 | 2967 | if pmf is None: |
|
2973 | 2968 | # only need parent manifest in the merge case, |
|
2974 | 2969 | # so do not read by default |
|
2975 | 2970 | pmf = repo[parent].manifest() |
|
2976 | 2971 | mergeadd = dsmodified - set(pmf) |
|
2977 | 2972 | dsadded |= mergeadd |
|
2978 | 2973 | dsmodified -= mergeadd |
|
2979 | 2974 | |
|
2980 | 2975 | # if f is a rename, update `names` to also revert the source |
|
2981 | 2976 | cwd = repo.getcwd() |
|
2982 | 2977 | for f in localchanges: |
|
2983 | 2978 | src = repo.dirstate.copied(f) |
|
2984 | 2979 | # XXX should we check for rename down to target node? |
|
2985 | 2980 | if src and src not in names and repo.dirstate[src] == 'r': |
|
2986 | 2981 | dsremoved.add(src) |
|
2987 | 2982 | names[src] = (repo.pathto(src, cwd), True) |
|
2988 | 2983 | |
|
2989 | 2984 | # distinguish between file to forget and the other |
|
2990 | 2985 | added = set() |
|
2991 | 2986 | for abs in dsadded: |
|
2992 | 2987 | if repo.dirstate[abs] != 'a': |
|
2993 | 2988 | added.add(abs) |
|
2994 | 2989 | dsadded -= added |
|
2995 | 2990 | |
|
2996 | 2991 | for abs in deladded: |
|
2997 | 2992 | if repo.dirstate[abs] == 'a': |
|
2998 | 2993 | dsadded.add(abs) |
|
2999 | 2994 | deladded -= dsadded |
|
3000 | 2995 | |
|
3001 | 2996 | # For files marked as removed, we check if an unknown file is present at |
|
3002 | 2997 | # the same path. If a such file exists it may need to be backed up. |
|
3003 | 2998 | # Making the distinction at this stage helps have simpler backup |
|
3004 | 2999 | # logic. |
|
3005 | 3000 | removunk = set() |
|
3006 | 3001 | for abs in removed: |
|
3007 | 3002 | target = repo.wjoin(abs) |
|
3008 | 3003 | if os.path.lexists(target): |
|
3009 | 3004 | removunk.add(abs) |
|
3010 | 3005 | removed -= removunk |
|
3011 | 3006 | |
|
3012 | 3007 | dsremovunk = set() |
|
3013 | 3008 | for abs in dsremoved: |
|
3014 | 3009 | target = repo.wjoin(abs) |
|
3015 | 3010 | if os.path.lexists(target): |
|
3016 | 3011 | dsremovunk.add(abs) |
|
3017 | 3012 | dsremoved -= dsremovunk |
|
3018 | 3013 | |
|
3019 | 3014 | # action to be actually performed by revert |
|
3020 | 3015 | # (<list of file>, message>) tuple |
|
3021 | 3016 | actions = {'revert': ([], _('reverting %s\n')), |
|
3022 | 3017 | 'add': ([], _('adding %s\n')), |
|
3023 | 3018 | 'remove': ([], _('removing %s\n')), |
|
3024 | 3019 | 'drop': ([], _('removing %s\n')), |
|
3025 | 3020 | 'forget': ([], _('forgetting %s\n')), |
|
3026 | 3021 | 'undelete': ([], _('undeleting %s\n')), |
|
3027 | 3022 | 'noop': (None, _('no changes needed to %s\n')), |
|
3028 | 3023 | 'unknown': (None, _('file not managed: %s\n')), |
|
3029 | 3024 | } |
|
3030 | 3025 | |
|
3031 | 3026 | # "constant" that convey the backup strategy. |
|
3032 | 3027 | # All set to `discard` if `no-backup` is set do avoid checking |
|
3033 | 3028 | # no_backup lower in the code. |
|
3034 | 3029 | # These values are ordered for comparison purposes |
|
3035 | 3030 | backup = 2 # unconditionally do backup |
|
3036 | 3031 | check = 1 # check if the existing file differs from target |
|
3037 | 3032 | discard = 0 # never do backup |
|
3038 | 3033 | if opts.get('no_backup'): |
|
3039 | 3034 | backup = check = discard |
|
3040 | 3035 | |
|
3041 | 3036 | backupanddel = actions['remove'] |
|
3042 | 3037 | if not opts.get('no_backup'): |
|
3043 | 3038 | backupanddel = actions['drop'] |
|
3044 | 3039 | |
|
3045 | 3040 | disptable = ( |
|
3046 | 3041 | # dispatch table: |
|
3047 | 3042 | # file state |
|
3048 | 3043 | # action |
|
3049 | 3044 | # make backup |
|
3050 | 3045 | |
|
3051 | 3046 | ## Sets that results that will change file on disk |
|
3052 | 3047 | # Modified compared to target, no local change |
|
3053 | 3048 | (modified, actions['revert'], discard), |
|
3054 | 3049 | # Modified compared to target, but local file is deleted |
|
3055 | 3050 | (deleted, actions['revert'], discard), |
|
3056 | 3051 | # Modified compared to target, local change |
|
3057 | 3052 | (dsmodified, actions['revert'], backup), |
|
3058 | 3053 | # Added since target |
|
3059 | 3054 | (added, actions['remove'], discard), |
|
3060 | 3055 | # Added in working directory |
|
3061 | 3056 | (dsadded, actions['forget'], discard), |
|
3062 | 3057 | # Added since target, have local modification |
|
3063 | 3058 | (modadded, backupanddel, backup), |
|
3064 | 3059 | # Added since target but file is missing in working directory |
|
3065 | 3060 | (deladded, actions['drop'], discard), |
|
3066 | 3061 | # Removed since target, before working copy parent |
|
3067 | 3062 | (removed, actions['add'], discard), |
|
3068 | 3063 | # Same as `removed` but an unknown file exists at the same path |
|
3069 | 3064 | (removunk, actions['add'], check), |
|
3070 | 3065 | # Removed since targe, marked as such in working copy parent |
|
3071 | 3066 | (dsremoved, actions['undelete'], discard), |
|
3072 | 3067 | # Same as `dsremoved` but an unknown file exists at the same path |
|
3073 | 3068 | (dsremovunk, actions['undelete'], check), |
|
3074 | 3069 | ## the following sets does not result in any file changes |
|
3075 | 3070 | # File with no modification |
|
3076 | 3071 | (clean, actions['noop'], discard), |
|
3077 | 3072 | # Existing file, not tracked anywhere |
|
3078 | 3073 | (unknown, actions['unknown'], discard), |
|
3079 | 3074 | ) |
|
3080 | 3075 | |
|
3081 | 3076 | for abs, (rel, exact) in sorted(names.items()): |
|
3082 | 3077 | # target file to be touch on disk (relative to cwd) |
|
3083 | 3078 | target = repo.wjoin(abs) |
|
3084 | 3079 | # search the entry in the dispatch table. |
|
3085 | 3080 | # if the file is in any of these sets, it was touched in the working |
|
3086 | 3081 | # directory parent and we are sure it needs to be reverted. |
|
3087 | 3082 | for table, (xlist, msg), dobackup in disptable: |
|
3088 | 3083 | if abs not in table: |
|
3089 | 3084 | continue |
|
3090 | 3085 | if xlist is not None: |
|
3091 | 3086 | xlist.append(abs) |
|
3092 | 3087 | if dobackup and (backup <= dobackup |
|
3093 | 3088 | or wctx[abs].cmp(ctx[abs])): |
|
3094 | 3089 | bakname = scmutil.origpath(ui, repo, rel) |
|
3095 | 3090 | ui.note(_('saving current version of %s as %s\n') % |
|
3096 | 3091 | (rel, bakname)) |
|
3097 | 3092 | if not opts.get('dry_run'): |
|
3098 | 3093 | if interactive: |
|
3099 | 3094 | util.copyfile(target, bakname) |
|
3100 | 3095 | else: |
|
3101 | 3096 | util.rename(target, bakname) |
|
3102 | 3097 | if ui.verbose or not exact: |
|
3103 | 3098 | if not isinstance(msg, basestring): |
|
3104 | 3099 | msg = msg(abs) |
|
3105 | 3100 | ui.status(msg % rel) |
|
3106 | 3101 | elif exact: |
|
3107 | 3102 | ui.warn(msg % rel) |
|
3108 | 3103 | break |
|
3109 | 3104 | |
|
3110 | 3105 | if not opts.get('dry_run'): |
|
3111 | 3106 | needdata = ('revert', 'add', 'undelete') |
|
3112 | 3107 | _revertprefetch(repo, ctx, *[actions[name][0] for name in needdata]) |
|
3113 | 3108 | _performrevert(repo, parents, ctx, actions, interactive) |
|
3114 | 3109 | |
|
3115 | 3110 | if targetsubs: |
|
3116 | 3111 | # Revert the subrepos on the revert list |
|
3117 | 3112 | for sub in targetsubs: |
|
3118 | 3113 | try: |
|
3119 | 3114 | wctx.sub(sub).revert(ctx.substate[sub], *pats, **opts) |
|
3120 | 3115 | except KeyError: |
|
3121 | 3116 | raise error.Abort("subrepository '%s' does not exist in %s!" |
|
3122 | 3117 | % (sub, short(ctx.node()))) |
|
3123 | 3118 | |
|
3124 | 3119 | def _revertprefetch(repo, ctx, *files): |
|
3125 | 3120 | """Let extension changing the storage layer prefetch content""" |
|
3126 | 3121 | pass |
|
3127 | 3122 | |
|
3128 | 3123 | def _performrevert(repo, parents, ctx, actions, interactive=False): |
|
3129 | 3124 | """function that actually perform all the actions computed for revert |
|
3130 | 3125 | |
|
3131 | 3126 | This is an independent function to let extension to plug in and react to |
|
3132 | 3127 | the imminent revert. |
|
3133 | 3128 | |
|
3134 | 3129 | Make sure you have the working directory locked when calling this function. |
|
3135 | 3130 | """ |
|
3136 | 3131 | parent, p2 = parents |
|
3137 | 3132 | node = ctx.node() |
|
3138 | 3133 | def checkout(f): |
|
3139 | 3134 | fc = ctx[f] |
|
3140 | 3135 | repo.wwrite(f, fc.data(), fc.flags()) |
|
3141 | 3136 | |
|
3142 | 3137 | audit_path = pathutil.pathauditor(repo.root) |
|
3143 | 3138 | for f in actions['forget'][0]: |
|
3144 | 3139 | repo.dirstate.drop(f) |
|
3145 | 3140 | for f in actions['remove'][0]: |
|
3146 | 3141 | audit_path(f) |
|
3147 | 3142 | try: |
|
3148 | 3143 | util.unlinkpath(repo.wjoin(f)) |
|
3149 | 3144 | except OSError: |
|
3150 | 3145 | pass |
|
3151 | 3146 | repo.dirstate.remove(f) |
|
3152 | 3147 | for f in actions['drop'][0]: |
|
3153 | 3148 | audit_path(f) |
|
3154 | 3149 | repo.dirstate.remove(f) |
|
3155 | 3150 | |
|
3156 | 3151 | normal = None |
|
3157 | 3152 | if node == parent: |
|
3158 | 3153 | # We're reverting to our parent. If possible, we'd like status |
|
3159 | 3154 | # to report the file as clean. We have to use normallookup for |
|
3160 | 3155 | # merges to avoid losing information about merged/dirty files. |
|
3161 | 3156 | if p2 != nullid: |
|
3162 | 3157 | normal = repo.dirstate.normallookup |
|
3163 | 3158 | else: |
|
3164 | 3159 | normal = repo.dirstate.normal |
|
3165 | 3160 | |
|
3166 | 3161 | newlyaddedandmodifiedfiles = set() |
|
3167 | 3162 | if interactive: |
|
3168 | 3163 | # Prompt the user for changes to revert |
|
3169 | 3164 | torevert = [repo.wjoin(f) for f in actions['revert'][0]] |
|
3170 | 3165 | m = scmutil.match(ctx, torevert, {}) |
|
3171 | 3166 | diffopts = patch.difffeatureopts(repo.ui, whitespace=True) |
|
3172 | 3167 | diffopts.nodates = True |
|
3173 | 3168 | diffopts.git = True |
|
3174 | 3169 | reversehunks = repo.ui.configbool('experimental', |
|
3175 | 3170 | 'revertalternateinteractivemode', |
|
3176 | 3171 | True) |
|
3177 | 3172 | if reversehunks: |
|
3178 | 3173 | diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts) |
|
3179 | 3174 | else: |
|
3180 | 3175 | diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts) |
|
3181 | 3176 | originalchunks = patch.parsepatch(diff) |
|
3182 | 3177 | |
|
3183 | 3178 | try: |
|
3184 | 3179 | |
|
3185 | 3180 | chunks, opts = recordfilter(repo.ui, originalchunks) |
|
3186 | 3181 | if reversehunks: |
|
3187 | 3182 | chunks = patch.reversehunks(chunks) |
|
3188 | 3183 | |
|
3189 | 3184 | except patch.PatchError as err: |
|
3190 | 3185 | raise error.Abort(_('error parsing patch: %s') % err) |
|
3191 | 3186 | |
|
3192 | 3187 | newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) |
|
3193 | 3188 | # Apply changes |
|
3194 | 3189 | fp = cStringIO.StringIO() |
|
3195 | 3190 | for c in chunks: |
|
3196 | 3191 | c.write(fp) |
|
3197 | 3192 | dopatch = fp.tell() |
|
3198 | 3193 | fp.seek(0) |
|
3199 | 3194 | if dopatch: |
|
3200 | 3195 | try: |
|
3201 | 3196 | patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None) |
|
3202 | 3197 | except patch.PatchError as err: |
|
3203 | 3198 | raise error.Abort(str(err)) |
|
3204 | 3199 | del fp |
|
3205 | 3200 | else: |
|
3206 | 3201 | for f in actions['revert'][0]: |
|
3207 | 3202 | checkout(f) |
|
3208 | 3203 | if normal: |
|
3209 | 3204 | normal(f) |
|
3210 | 3205 | |
|
3211 | 3206 | for f in actions['add'][0]: |
|
3212 | 3207 | # Don't checkout modified files, they are already created by the diff |
|
3213 | 3208 | if f not in newlyaddedandmodifiedfiles: |
|
3214 | 3209 | checkout(f) |
|
3215 | 3210 | repo.dirstate.add(f) |
|
3216 | 3211 | |
|
3217 | 3212 | normal = repo.dirstate.normallookup |
|
3218 | 3213 | if node == parent and p2 == nullid: |
|
3219 | 3214 | normal = repo.dirstate.normal |
|
3220 | 3215 | for f in actions['undelete'][0]: |
|
3221 | 3216 | checkout(f) |
|
3222 | 3217 | normal(f) |
|
3223 | 3218 | |
|
3224 | 3219 | copied = copies.pathcopies(repo[parent], ctx) |
|
3225 | 3220 | |
|
3226 | 3221 | for f in actions['add'][0] + actions['undelete'][0] + actions['revert'][0]: |
|
3227 | 3222 | if f in copied: |
|
3228 | 3223 | repo.dirstate.copy(copied[f], f) |
|
3229 | 3224 | |
|
3230 | 3225 | def command(table): |
|
3231 | 3226 | """Returns a function object to be used as a decorator for making commands. |
|
3232 | 3227 | |
|
3233 | 3228 | This function receives a command table as its argument. The table should |
|
3234 | 3229 | be a dict. |
|
3235 | 3230 | |
|
3236 | 3231 | The returned function can be used as a decorator for adding commands |
|
3237 | 3232 | to that command table. This function accepts multiple arguments to define |
|
3238 | 3233 | a command. |
|
3239 | 3234 | |
|
3240 | 3235 | The first argument is the command name. |
|
3241 | 3236 | |
|
3242 | 3237 | The options argument is an iterable of tuples defining command arguments. |
|
3243 | 3238 | See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple. |
|
3244 | 3239 | |
|
3245 | 3240 | The synopsis argument defines a short, one line summary of how to use the |
|
3246 | 3241 | command. This shows up in the help output. |
|
3247 | 3242 | |
|
3248 | 3243 | The norepo argument defines whether the command does not require a |
|
3249 | 3244 | local repository. Most commands operate against a repository, thus the |
|
3250 | 3245 | default is False. |
|
3251 | 3246 | |
|
3252 | 3247 | The optionalrepo argument defines whether the command optionally requires |
|
3253 | 3248 | a local repository. |
|
3254 | 3249 | |
|
3255 | 3250 | The inferrepo argument defines whether to try to find a repository from the |
|
3256 | 3251 | command line arguments. If True, arguments will be examined for potential |
|
3257 | 3252 | repository locations. See ``findrepo()``. If a repository is found, it |
|
3258 | 3253 | will be used. |
|
3259 | 3254 | """ |
|
3260 | 3255 | def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False, |
|
3261 | 3256 | inferrepo=False): |
|
3262 | 3257 | def decorator(func): |
|
3263 | 3258 | if synopsis: |
|
3264 | 3259 | table[name] = func, list(options), synopsis |
|
3265 | 3260 | else: |
|
3266 | 3261 | table[name] = func, list(options) |
|
3267 | 3262 | |
|
3268 | 3263 | if norepo: |
|
3269 | 3264 | # Avoid import cycle. |
|
3270 | 3265 | import commands |
|
3271 | 3266 | commands.norepo += ' %s' % ' '.join(parsealiases(name)) |
|
3272 | 3267 | |
|
3273 | 3268 | if optionalrepo: |
|
3274 | 3269 | import commands |
|
3275 | 3270 | commands.optionalrepo += ' %s' % ' '.join(parsealiases(name)) |
|
3276 | 3271 | |
|
3277 | 3272 | if inferrepo: |
|
3278 | 3273 | import commands |
|
3279 | 3274 | commands.inferrepo += ' %s' % ' '.join(parsealiases(name)) |
|
3280 | 3275 | |
|
3281 | 3276 | return func |
|
3282 | 3277 | return decorator |
|
3283 | 3278 | |
|
3284 | 3279 | return cmd |
|
3285 | 3280 | |
|
3286 | 3281 | # a list of (ui, repo, otherpeer, opts, missing) functions called by |
|
3287 | 3282 | # commands.outgoing. "missing" is "missing" of the result of |
|
3288 | 3283 | # "findcommonoutgoing()" |
|
3289 | 3284 | outgoinghooks = util.hooks() |
|
3290 | 3285 | |
|
3291 | 3286 | # a list of (ui, repo) functions called by commands.summary |
|
3292 | 3287 | summaryhooks = util.hooks() |
|
3293 | 3288 | |
|
3294 | 3289 | # a list of (ui, repo, opts, changes) functions called by commands.summary. |
|
3295 | 3290 | # |
|
3296 | 3291 | # functions should return tuple of booleans below, if 'changes' is None: |
|
3297 | 3292 | # (whether-incomings-are-needed, whether-outgoings-are-needed) |
|
3298 | 3293 | # |
|
3299 | 3294 | # otherwise, 'changes' is a tuple of tuples below: |
|
3300 | 3295 | # - (sourceurl, sourcebranch, sourcepeer, incoming) |
|
3301 | 3296 | # - (desturl, destbranch, destpeer, outgoing) |
|
3302 | 3297 | summaryremotehooks = util.hooks() |
|
3303 | 3298 | |
|
3304 | 3299 | # A list of state files kept by multistep operations like graft. |
|
3305 | 3300 | # Since graft cannot be aborted, it is considered 'clearable' by update. |
|
3306 | 3301 | # note: bisect is intentionally excluded |
|
3307 | 3302 | # (state file, clearable, allowcommit, error, hint) |
|
3308 | 3303 | unfinishedstates = [ |
|
3309 | 3304 | ('graftstate', True, False, _('graft in progress'), |
|
3310 | 3305 | _("use 'hg graft --continue' or 'hg update' to abort")), |
|
3311 | 3306 | ('updatestate', True, False, _('last update was interrupted'), |
|
3312 | 3307 | _("use 'hg update' to get a consistent checkout")) |
|
3313 | 3308 | ] |
|
3314 | 3309 | |
|
3315 | 3310 | def checkunfinished(repo, commit=False): |
|
3316 | 3311 | '''Look for an unfinished multistep operation, like graft, and abort |
|
3317 | 3312 | if found. It's probably good to check this right before |
|
3318 | 3313 | bailifchanged(). |
|
3319 | 3314 | ''' |
|
3320 | 3315 | for f, clearable, allowcommit, msg, hint in unfinishedstates: |
|
3321 | 3316 | if commit and allowcommit: |
|
3322 | 3317 | continue |
|
3323 | 3318 | if repo.vfs.exists(f): |
|
3324 | 3319 | raise error.Abort(msg, hint=hint) |
|
3325 | 3320 | |
|
3326 | 3321 | def clearunfinished(repo): |
|
3327 | 3322 | '''Check for unfinished operations (as above), and clear the ones |
|
3328 | 3323 | that are clearable. |
|
3329 | 3324 | ''' |
|
3330 | 3325 | for f, clearable, allowcommit, msg, hint in unfinishedstates: |
|
3331 | 3326 | if not clearable and repo.vfs.exists(f): |
|
3332 | 3327 | raise error.Abort(msg, hint=hint) |
|
3333 | 3328 | for f, clearable, allowcommit, msg, hint in unfinishedstates: |
|
3334 | 3329 | if clearable and repo.vfs.exists(f): |
|
3335 | 3330 | util.unlink(repo.join(f)) |
|
3336 | 3331 | |
|
3337 | 3332 | afterresolvedstates = [ |
|
3338 | 3333 | ('graftstate', |
|
3339 | 3334 | _('hg graft --continue')), |
|
3340 | 3335 | ] |
|
3341 | 3336 | |
|
3342 | 3337 | def checkafterresolved(repo): |
|
3343 | 3338 | contmsg = _("continue: %s\n") |
|
3344 | 3339 | for f, msg in afterresolvedstates: |
|
3345 | 3340 | if repo.vfs.exists(f): |
|
3346 | 3341 | repo.ui.warn(contmsg % msg) |
|
3347 | 3342 | return |
|
3348 | 3343 | repo.ui.note(contmsg % _("hg commit")) |
|
3349 | 3344 | |
|
3350 | 3345 | class dirstateguard(object): |
|
3351 | 3346 | '''Restore dirstate at unexpected failure. |
|
3352 | 3347 | |
|
3353 | 3348 | At the construction, this class does: |
|
3354 | 3349 | |
|
3355 | 3350 | - write current ``repo.dirstate`` out, and |
|
3356 | 3351 | - save ``.hg/dirstate`` into the backup file |
|
3357 | 3352 | |
|
3358 | 3353 | This restores ``.hg/dirstate`` from backup file, if ``release()`` |
|
3359 | 3354 | is invoked before ``close()``. |
|
3360 | 3355 | |
|
3361 | 3356 | This just removes the backup file at ``close()`` before ``release()``. |
|
3362 | 3357 | ''' |
|
3363 | 3358 | |
|
3364 | 3359 | def __init__(self, repo, name): |
|
3365 | 3360 | self._repo = repo |
|
3366 | 3361 | self._suffix = '.backup.%s.%d' % (name, id(self)) |
|
3367 | 3362 | repo.dirstate._savebackup(repo.currenttransaction(), self._suffix) |
|
3368 | 3363 | self._active = True |
|
3369 | 3364 | self._closed = False |
|
3370 | 3365 | |
|
3371 | 3366 | def __del__(self): |
|
3372 | 3367 | if self._active: # still active |
|
3373 | 3368 | # this may occur, even if this class is used correctly: |
|
3374 | 3369 | # for example, releasing other resources like transaction |
|
3375 | 3370 | # may raise exception before ``dirstateguard.release`` in |
|
3376 | 3371 | # ``release(tr, ....)``. |
|
3377 | 3372 | self._abort() |
|
3378 | 3373 | |
|
3379 | 3374 | def close(self): |
|
3380 | 3375 | if not self._active: # already inactivated |
|
3381 | 3376 | msg = (_("can't close already inactivated backup: dirstate%s") |
|
3382 | 3377 | % self._suffix) |
|
3383 | 3378 | raise error.Abort(msg) |
|
3384 | 3379 | |
|
3385 | 3380 | self._repo.dirstate._clearbackup(self._repo.currenttransaction(), |
|
3386 | 3381 | self._suffix) |
|
3387 | 3382 | self._active = False |
|
3388 | 3383 | self._closed = True |
|
3389 | 3384 | |
|
3390 | 3385 | def _abort(self): |
|
3391 | 3386 | self._repo.dirstate._restorebackup(self._repo.currenttransaction(), |
|
3392 | 3387 | self._suffix) |
|
3393 | 3388 | self._active = False |
|
3394 | 3389 | |
|
3395 | 3390 | def release(self): |
|
3396 | 3391 | if not self._closed: |
|
3397 | 3392 | if not self._active: # already inactivated |
|
3398 | 3393 | msg = (_("can't release already inactivated backup:" |
|
3399 | 3394 | " dirstate%s") |
|
3400 | 3395 | % self._suffix) |
|
3401 | 3396 | raise error.Abort(msg) |
|
3402 | 3397 | self._abort() |
@@ -1,7042 +1,7039 | |||
|
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 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import hex, bin, nullhex, nullid, nullrev, short |
|
9 | 9 | from lock import release |
|
10 | 10 | from i18n import _ |
|
11 | 11 | import os, re, difflib, time, tempfile, errno, shlex |
|
12 | 12 | import sys, socket |
|
13 | 13 | import hg, scmutil, util, revlog, copies, error, bookmarks |
|
14 | 14 | import patch, help, encoding, templatekw, discovery |
|
15 | 15 | import archival, changegroup, cmdutil, hbisect |
|
16 | 16 | import sshserver, hgweb |
|
17 | 17 | import extensions |
|
18 | 18 | import merge as mergemod |
|
19 | 19 | import minirst, revset, fileset |
|
20 | 20 | import dagparser, context, simplemerge, graphmod, copies |
|
21 | 21 | import random, operator |
|
22 | 22 | import setdiscovery, treediscovery, dagutil, pvec, localrepo, destutil |
|
23 | 23 | import phases, obsolete, exchange, bundle2, repair, lock as lockmod |
|
24 | 24 | import ui as uimod |
|
25 | 25 | import streamclone |
|
26 | 26 | import commandserver |
|
27 | 27 | |
|
28 | 28 | table = {} |
|
29 | 29 | |
|
30 | 30 | command = cmdutil.command(table) |
|
31 | 31 | |
|
32 | 32 | # Space delimited list of commands that don't require local repositories. |
|
33 | 33 | # This should be populated by passing norepo=True into the @command decorator. |
|
34 | 34 | norepo = '' |
|
35 | 35 | # Space delimited list of commands that optionally require local repositories. |
|
36 | 36 | # This should be populated by passing optionalrepo=True into the @command |
|
37 | 37 | # decorator. |
|
38 | 38 | optionalrepo = '' |
|
39 | 39 | # Space delimited list of commands that will examine arguments looking for |
|
40 | 40 | # a repository. This should be populated by passing inferrepo=True into the |
|
41 | 41 | # @command decorator. |
|
42 | 42 | inferrepo = '' |
|
43 | 43 | |
|
44 | 44 | # label constants |
|
45 | 45 | # until 3.5, bookmarks.current was the advertised name, not |
|
46 | 46 | # bookmarks.active, so we must use both to avoid breaking old |
|
47 | 47 | # custom styles |
|
48 | 48 | activebookmarklabel = 'bookmarks.active bookmarks.current' |
|
49 | 49 | |
|
50 | 50 | # common command options |
|
51 | 51 | |
|
52 | 52 | globalopts = [ |
|
53 | 53 | ('R', 'repository', '', |
|
54 | 54 | _('repository root directory or name of overlay bundle file'), |
|
55 | 55 | _('REPO')), |
|
56 | 56 | ('', 'cwd', '', |
|
57 | 57 | _('change working directory'), _('DIR')), |
|
58 | 58 | ('y', 'noninteractive', None, |
|
59 | 59 | _('do not prompt, automatically pick the first choice for all prompts')), |
|
60 | 60 | ('q', 'quiet', None, _('suppress output')), |
|
61 | 61 | ('v', 'verbose', None, _('enable additional output')), |
|
62 | 62 | ('', 'config', [], |
|
63 | 63 | _('set/override config option (use \'section.name=value\')'), |
|
64 | 64 | _('CONFIG')), |
|
65 | 65 | ('', 'debug', None, _('enable debugging output')), |
|
66 | 66 | ('', 'debugger', None, _('start debugger')), |
|
67 | 67 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
68 | 68 | _('ENCODE')), |
|
69 | 69 | ('', 'encodingmode', encoding.encodingmode, |
|
70 | 70 | _('set the charset encoding mode'), _('MODE')), |
|
71 | 71 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
72 | 72 | ('', 'time', None, _('time how long the command takes')), |
|
73 | 73 | ('', 'profile', None, _('print command execution profile')), |
|
74 | 74 | ('', 'version', None, _('output version information and exit')), |
|
75 | 75 | ('h', 'help', None, _('display help and exit')), |
|
76 | 76 | ('', 'hidden', False, _('consider hidden changesets')), |
|
77 | 77 | ] |
|
78 | 78 | |
|
79 | 79 | dryrunopts = [('n', 'dry-run', None, |
|
80 | 80 | _('do not perform actions, just print output'))] |
|
81 | 81 | |
|
82 | 82 | remoteopts = [ |
|
83 | 83 | ('e', 'ssh', '', |
|
84 | 84 | _('specify ssh command to use'), _('CMD')), |
|
85 | 85 | ('', 'remotecmd', '', |
|
86 | 86 | _('specify hg command to run on the remote side'), _('CMD')), |
|
87 | 87 | ('', 'insecure', None, |
|
88 | 88 | _('do not verify server certificate (ignoring web.cacerts config)')), |
|
89 | 89 | ] |
|
90 | 90 | |
|
91 | 91 | walkopts = [ |
|
92 | 92 | ('I', 'include', [], |
|
93 | 93 | _('include names matching the given patterns'), _('PATTERN')), |
|
94 | 94 | ('X', 'exclude', [], |
|
95 | 95 | _('exclude names matching the given patterns'), _('PATTERN')), |
|
96 | 96 | ] |
|
97 | 97 | |
|
98 | 98 | commitopts = [ |
|
99 | 99 | ('m', 'message', '', |
|
100 | 100 | _('use text as commit message'), _('TEXT')), |
|
101 | 101 | ('l', 'logfile', '', |
|
102 | 102 | _('read commit message from file'), _('FILE')), |
|
103 | 103 | ] |
|
104 | 104 | |
|
105 | 105 | commitopts2 = [ |
|
106 | 106 | ('d', 'date', '', |
|
107 | 107 | _('record the specified date as commit date'), _('DATE')), |
|
108 | 108 | ('u', 'user', '', |
|
109 | 109 | _('record the specified user as committer'), _('USER')), |
|
110 | 110 | ] |
|
111 | 111 | |
|
112 | 112 | # hidden for now |
|
113 | 113 | formatteropts = [ |
|
114 | 114 | ('T', 'template', '', |
|
115 | 115 | _('display with template (EXPERIMENTAL)'), _('TEMPLATE')), |
|
116 | 116 | ] |
|
117 | 117 | |
|
118 | 118 | templateopts = [ |
|
119 | 119 | ('', 'style', '', |
|
120 | 120 | _('display using template map file (DEPRECATED)'), _('STYLE')), |
|
121 | 121 | ('T', 'template', '', |
|
122 | 122 | _('display with template'), _('TEMPLATE')), |
|
123 | 123 | ] |
|
124 | 124 | |
|
125 | 125 | logopts = [ |
|
126 | 126 | ('p', 'patch', None, _('show patch')), |
|
127 | 127 | ('g', 'git', None, _('use git extended diff format')), |
|
128 | 128 | ('l', 'limit', '', |
|
129 | 129 | _('limit number of changes displayed'), _('NUM')), |
|
130 | 130 | ('M', 'no-merges', None, _('do not show merges')), |
|
131 | 131 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
132 | 132 | ('G', 'graph', None, _("show the revision DAG")), |
|
133 | 133 | ] + templateopts |
|
134 | 134 | |
|
135 | 135 | diffopts = [ |
|
136 | 136 | ('a', 'text', None, _('treat all files as text')), |
|
137 | 137 | ('g', 'git', None, _('use git extended diff format')), |
|
138 | 138 | ('', 'nodates', None, _('omit dates from diff headers')) |
|
139 | 139 | ] |
|
140 | 140 | |
|
141 | 141 | diffwsopts = [ |
|
142 | 142 | ('w', 'ignore-all-space', None, |
|
143 | 143 | _('ignore white space when comparing lines')), |
|
144 | 144 | ('b', 'ignore-space-change', None, |
|
145 | 145 | _('ignore changes in the amount of white space')), |
|
146 | 146 | ('B', 'ignore-blank-lines', None, |
|
147 | 147 | _('ignore changes whose lines are all blank')), |
|
148 | 148 | ] |
|
149 | 149 | |
|
150 | 150 | diffopts2 = [ |
|
151 | 151 | ('', 'noprefix', None, _('omit a/ and b/ prefixes from filenames')), |
|
152 | 152 | ('p', 'show-function', None, _('show which function each change is in')), |
|
153 | 153 | ('', 'reverse', None, _('produce a diff that undoes the changes')), |
|
154 | 154 | ] + diffwsopts + [ |
|
155 | 155 | ('U', 'unified', '', |
|
156 | 156 | _('number of lines of context to show'), _('NUM')), |
|
157 | 157 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
158 | 158 | ('', 'root', '', _('produce diffs relative to subdirectory'), _('DIR')), |
|
159 | 159 | ] |
|
160 | 160 | |
|
161 | 161 | mergetoolopts = [ |
|
162 | 162 | ('t', 'tool', '', _('specify merge tool')), |
|
163 | 163 | ] |
|
164 | 164 | |
|
165 | 165 | similarityopts = [ |
|
166 | 166 | ('s', 'similarity', '', |
|
167 | 167 | _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) |
|
168 | 168 | ] |
|
169 | 169 | |
|
170 | 170 | subrepoopts = [ |
|
171 | 171 | ('S', 'subrepos', None, |
|
172 | 172 | _('recurse into subrepositories')) |
|
173 | 173 | ] |
|
174 | 174 | |
|
175 | 175 | debugrevlogopts = [ |
|
176 | 176 | ('c', 'changelog', False, _('open changelog')), |
|
177 | 177 | ('m', 'manifest', False, _('open manifest')), |
|
178 | 178 | ('', 'dir', False, _('open directory manifest')), |
|
179 | 179 | ] |
|
180 | 180 | |
|
181 | 181 | # Commands start here, listed alphabetically |
|
182 | 182 | |
|
183 | 183 | @command('^add', |
|
184 | 184 | walkopts + subrepoopts + dryrunopts, |
|
185 | 185 | _('[OPTION]... [FILE]...'), |
|
186 | 186 | inferrepo=True) |
|
187 | 187 | def add(ui, repo, *pats, **opts): |
|
188 | 188 | """add the specified files on the next commit |
|
189 | 189 | |
|
190 | 190 | Schedule files to be version controlled and added to the |
|
191 | 191 | repository. |
|
192 | 192 | |
|
193 | 193 | The files will be added to the repository at the next commit. To |
|
194 | 194 | undo an add before that, see :hg:`forget`. |
|
195 | 195 | |
|
196 | 196 | If no names are given, add all files to the repository (except |
|
197 | 197 | files matching ``.hgignore``). |
|
198 | 198 | |
|
199 | 199 | .. container:: verbose |
|
200 | 200 | |
|
201 | 201 | Examples: |
|
202 | 202 | |
|
203 | 203 | - New (unknown) files are added |
|
204 | 204 | automatically by :hg:`add`:: |
|
205 | 205 | |
|
206 | 206 | $ ls |
|
207 | 207 | foo.c |
|
208 | 208 | $ hg status |
|
209 | 209 | ? foo.c |
|
210 | 210 | $ hg add |
|
211 | 211 | adding foo.c |
|
212 | 212 | $ hg status |
|
213 | 213 | A foo.c |
|
214 | 214 | |
|
215 | 215 | - Specific files to be added can be specified:: |
|
216 | 216 | |
|
217 | 217 | $ ls |
|
218 | 218 | bar.c foo.c |
|
219 | 219 | $ hg status |
|
220 | 220 | ? bar.c |
|
221 | 221 | ? foo.c |
|
222 | 222 | $ hg add bar.c |
|
223 | 223 | $ hg status |
|
224 | 224 | A bar.c |
|
225 | 225 | ? foo.c |
|
226 | 226 | |
|
227 | 227 | Returns 0 if all files are successfully added. |
|
228 | 228 | """ |
|
229 | 229 | |
|
230 | 230 | m = scmutil.match(repo[None], pats, opts) |
|
231 | 231 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) |
|
232 | 232 | return rejected and 1 or 0 |
|
233 | 233 | |
|
234 | 234 | @command('addremove', |
|
235 | 235 | similarityopts + subrepoopts + walkopts + dryrunopts, |
|
236 | 236 | _('[OPTION]... [FILE]...'), |
|
237 | 237 | inferrepo=True) |
|
238 | 238 | def addremove(ui, repo, *pats, **opts): |
|
239 | 239 | """add all new files, delete all missing files |
|
240 | 240 | |
|
241 | 241 | Add all new files and remove all missing files from the |
|
242 | 242 | repository. |
|
243 | 243 | |
|
244 | 244 | Unless names are given, new files are ignored if they match any of |
|
245 | 245 | the patterns in ``.hgignore``. As with add, these changes take |
|
246 | 246 | effect at the next commit. |
|
247 | 247 | |
|
248 | 248 | Use the -s/--similarity option to detect renamed files. This |
|
249 | 249 | option takes a percentage between 0 (disabled) and 100 (files must |
|
250 | 250 | be identical) as its parameter. With a parameter greater than 0, |
|
251 | 251 | this compares every removed file with every added file and records |
|
252 | 252 | those similar enough as renames. Detecting renamed files this way |
|
253 | 253 | can be expensive. After using this option, :hg:`status -C` can be |
|
254 | 254 | used to check which files were identified as moved or renamed. If |
|
255 | 255 | not specified, -s/--similarity defaults to 100 and only renames of |
|
256 | 256 | identical files are detected. |
|
257 | 257 | |
|
258 | 258 | .. container:: verbose |
|
259 | 259 | |
|
260 | 260 | Examples: |
|
261 | 261 | |
|
262 | 262 | - A number of files (bar.c and foo.c) are new, |
|
263 | 263 | while foobar.c has been removed (without using :hg:`remove`) |
|
264 | 264 | from the repository:: |
|
265 | 265 | |
|
266 | 266 | $ ls |
|
267 | 267 | bar.c foo.c |
|
268 | 268 | $ hg status |
|
269 | 269 | ! foobar.c |
|
270 | 270 | ? bar.c |
|
271 | 271 | ? foo.c |
|
272 | 272 | $ hg addremove |
|
273 | 273 | adding bar.c |
|
274 | 274 | adding foo.c |
|
275 | 275 | removing foobar.c |
|
276 | 276 | $ hg status |
|
277 | 277 | A bar.c |
|
278 | 278 | A foo.c |
|
279 | 279 | R foobar.c |
|
280 | 280 | |
|
281 | 281 | - A file foobar.c was moved to foo.c without using :hg:`rename`. |
|
282 | 282 | Afterwards, it was edited slightly:: |
|
283 | 283 | |
|
284 | 284 | $ ls |
|
285 | 285 | foo.c |
|
286 | 286 | $ hg status |
|
287 | 287 | ! foobar.c |
|
288 | 288 | ? foo.c |
|
289 | 289 | $ hg addremove --similarity 90 |
|
290 | 290 | removing foobar.c |
|
291 | 291 | adding foo.c |
|
292 | 292 | recording removal of foobar.c as rename to foo.c (94% similar) |
|
293 | 293 | $ hg status -C |
|
294 | 294 | A foo.c |
|
295 | 295 | foobar.c |
|
296 | 296 | R foobar.c |
|
297 | 297 | |
|
298 | 298 | Returns 0 if all files are successfully added. |
|
299 | 299 | """ |
|
300 | 300 | try: |
|
301 | 301 | sim = float(opts.get('similarity') or 100) |
|
302 | 302 | except ValueError: |
|
303 | 303 | raise error.Abort(_('similarity must be a number')) |
|
304 | 304 | if sim < 0 or sim > 100: |
|
305 | 305 | raise error.Abort(_('similarity must be between 0 and 100')) |
|
306 | 306 | matcher = scmutil.match(repo[None], pats, opts) |
|
307 | 307 | return scmutil.addremove(repo, matcher, "", opts, similarity=sim / 100.0) |
|
308 | 308 | |
|
309 | 309 | @command('^annotate|blame', |
|
310 | 310 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
311 | 311 | ('', 'follow', None, |
|
312 | 312 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
313 | 313 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
314 | 314 | ('a', 'text', None, _('treat all files as text')), |
|
315 | 315 | ('u', 'user', None, _('list the author (long with -v)')), |
|
316 | 316 | ('f', 'file', None, _('list the filename')), |
|
317 | 317 | ('d', 'date', None, _('list the date (short with -q)')), |
|
318 | 318 | ('n', 'number', None, _('list the revision number (default)')), |
|
319 | 319 | ('c', 'changeset', None, _('list the changeset')), |
|
320 | 320 | ('l', 'line-number', None, _('show line number at the first appearance')) |
|
321 | 321 | ] + diffwsopts + walkopts + formatteropts, |
|
322 | 322 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), |
|
323 | 323 | inferrepo=True) |
|
324 | 324 | def annotate(ui, repo, *pats, **opts): |
|
325 | 325 | """show changeset information by line for each file |
|
326 | 326 | |
|
327 | 327 | List changes in files, showing the revision id responsible for |
|
328 | 328 | each line. |
|
329 | 329 | |
|
330 | 330 | This command is useful for discovering when a change was made and |
|
331 | 331 | by whom. |
|
332 | 332 | |
|
333 | 333 | If you include --file, --user, or --date, the revision number is |
|
334 | 334 | suppressed unless you also include --number. |
|
335 | 335 | |
|
336 | 336 | Without the -a/--text option, annotate will avoid processing files |
|
337 | 337 | it detects as binary. With -a, annotate will annotate the file |
|
338 | 338 | anyway, although the results will probably be neither useful |
|
339 | 339 | nor desirable. |
|
340 | 340 | |
|
341 | 341 | Returns 0 on success. |
|
342 | 342 | """ |
|
343 | 343 | if not pats: |
|
344 | 344 | raise error.Abort(_('at least one filename or pattern is required')) |
|
345 | 345 | |
|
346 | 346 | if opts.get('follow'): |
|
347 | 347 | # --follow is deprecated and now just an alias for -f/--file |
|
348 | 348 | # to mimic the behavior of Mercurial before version 1.5 |
|
349 | 349 | opts['file'] = True |
|
350 | 350 | |
|
351 | 351 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
352 | 352 | |
|
353 | 353 | fm = ui.formatter('annotate', opts) |
|
354 | 354 | if ui.quiet: |
|
355 | 355 | datefunc = util.shortdate |
|
356 | 356 | else: |
|
357 | 357 | datefunc = util.datestr |
|
358 | 358 | if ctx.rev() is None: |
|
359 | 359 | def hexfn(node): |
|
360 | 360 | if node is None: |
|
361 | 361 | return None |
|
362 | 362 | else: |
|
363 | 363 | return fm.hexfunc(node) |
|
364 | 364 | if opts.get('changeset'): |
|
365 | 365 | # omit "+" suffix which is appended to node hex |
|
366 | 366 | def formatrev(rev): |
|
367 | 367 | if rev is None: |
|
368 | 368 | return '%d' % ctx.p1().rev() |
|
369 | 369 | else: |
|
370 | 370 | return '%d' % rev |
|
371 | 371 | else: |
|
372 | 372 | def formatrev(rev): |
|
373 | 373 | if rev is None: |
|
374 | 374 | return '%d+' % ctx.p1().rev() |
|
375 | 375 | else: |
|
376 | 376 | return '%d ' % rev |
|
377 | 377 | def formathex(hex): |
|
378 | 378 | if hex is None: |
|
379 | 379 | return '%s+' % fm.hexfunc(ctx.p1().node()) |
|
380 | 380 | else: |
|
381 | 381 | return '%s ' % hex |
|
382 | 382 | else: |
|
383 | 383 | hexfn = fm.hexfunc |
|
384 | 384 | formatrev = formathex = str |
|
385 | 385 | |
|
386 | 386 | opmap = [('user', ' ', lambda x: x[0].user(), ui.shortuser), |
|
387 | 387 | ('number', ' ', lambda x: x[0].rev(), formatrev), |
|
388 | 388 | ('changeset', ' ', lambda x: hexfn(x[0].node()), formathex), |
|
389 | 389 | ('date', ' ', lambda x: x[0].date(), util.cachefunc(datefunc)), |
|
390 | 390 | ('file', ' ', lambda x: x[0].path(), str), |
|
391 | 391 | ('line_number', ':', lambda x: x[1], str), |
|
392 | 392 | ] |
|
393 | 393 | fieldnamemap = {'number': 'rev', 'changeset': 'node'} |
|
394 | 394 | |
|
395 | 395 | if (not opts.get('user') and not opts.get('changeset') |
|
396 | 396 | and not opts.get('date') and not opts.get('file')): |
|
397 | 397 | opts['number'] = True |
|
398 | 398 | |
|
399 | 399 | linenumber = opts.get('line_number') is not None |
|
400 | 400 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
401 | 401 | raise error.Abort(_('at least one of -n/-c is required for -l')) |
|
402 | 402 | |
|
403 | 403 | if fm: |
|
404 | 404 | def makefunc(get, fmt): |
|
405 | 405 | return get |
|
406 | 406 | else: |
|
407 | 407 | def makefunc(get, fmt): |
|
408 | 408 | return lambda x: fmt(get(x)) |
|
409 | 409 | funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap |
|
410 | 410 | if opts.get(op)] |
|
411 | 411 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column |
|
412 | 412 | fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap |
|
413 | 413 | if opts.get(op)) |
|
414 | 414 | |
|
415 | 415 | def bad(x, y): |
|
416 | 416 | raise error.Abort("%s: %s" % (x, y)) |
|
417 | 417 | |
|
418 | 418 | m = scmutil.match(ctx, pats, opts, badfn=bad) |
|
419 | 419 | |
|
420 | 420 | follow = not opts.get('no_follow') |
|
421 | 421 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', |
|
422 | 422 | whitespace=True) |
|
423 | 423 | for abs in ctx.walk(m): |
|
424 | 424 | fctx = ctx[abs] |
|
425 | 425 | if not opts.get('text') and util.binary(fctx.data()): |
|
426 | 426 | fm.plain(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
427 | 427 | continue |
|
428 | 428 | |
|
429 | 429 | lines = fctx.annotate(follow=follow, linenumber=linenumber, |
|
430 | 430 | diffopts=diffopts) |
|
431 | 431 | formats = [] |
|
432 | 432 | pieces = [] |
|
433 | 433 | |
|
434 | 434 | for f, sep in funcmap: |
|
435 | 435 | l = [f(n) for n, dummy in lines] |
|
436 | 436 | if l: |
|
437 | 437 | if fm: |
|
438 | 438 | formats.append(['%s' for x in l]) |
|
439 | 439 | else: |
|
440 | 440 | sizes = [encoding.colwidth(x) for x in l] |
|
441 | 441 | ml = max(sizes) |
|
442 | 442 | formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) |
|
443 | 443 | pieces.append(l) |
|
444 | 444 | |
|
445 | 445 | for f, p, l in zip(zip(*formats), zip(*pieces), lines): |
|
446 | 446 | fm.startitem() |
|
447 | 447 | fm.write(fields, "".join(f), *p) |
|
448 | 448 | fm.write('line', ": %s", l[1]) |
|
449 | 449 | |
|
450 | 450 | if lines and not lines[-1][1].endswith('\n'): |
|
451 | 451 | fm.plain('\n') |
|
452 | 452 | |
|
453 | 453 | fm.end() |
|
454 | 454 | |
|
455 | 455 | @command('archive', |
|
456 | 456 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
457 | 457 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
458 | 458 | _('PREFIX')), |
|
459 | 459 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
460 | 460 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
461 | 461 | ] + subrepoopts + walkopts, |
|
462 | 462 | _('[OPTION]... DEST')) |
|
463 | 463 | def archive(ui, repo, dest, **opts): |
|
464 | 464 | '''create an unversioned archive of a repository revision |
|
465 | 465 | |
|
466 | 466 | By default, the revision used is the parent of the working |
|
467 | 467 | directory; use -r/--rev to specify a different revision. |
|
468 | 468 | |
|
469 | 469 | The archive type is automatically detected based on file |
|
470 | 470 | extension (to override, use -t/--type). |
|
471 | 471 | |
|
472 | 472 | .. container:: verbose |
|
473 | 473 | |
|
474 | 474 | Examples: |
|
475 | 475 | |
|
476 | 476 | - create a zip file containing the 1.0 release:: |
|
477 | 477 | |
|
478 | 478 | hg archive -r 1.0 project-1.0.zip |
|
479 | 479 | |
|
480 | 480 | - create a tarball excluding .hg files:: |
|
481 | 481 | |
|
482 | 482 | hg archive project.tar.gz -X ".hg*" |
|
483 | 483 | |
|
484 | 484 | Valid types are: |
|
485 | 485 | |
|
486 | 486 | :``files``: a directory full of files (default) |
|
487 | 487 | :``tar``: tar archive, uncompressed |
|
488 | 488 | :``tbz2``: tar archive, compressed using bzip2 |
|
489 | 489 | :``tgz``: tar archive, compressed using gzip |
|
490 | 490 | :``uzip``: zip archive, uncompressed |
|
491 | 491 | :``zip``: zip archive, compressed using deflate |
|
492 | 492 | |
|
493 | 493 | The exact name of the destination archive or directory is given |
|
494 | 494 | using a format string; see :hg:`help export` for details. |
|
495 | 495 | |
|
496 | 496 | Each member added to an archive file has a directory prefix |
|
497 | 497 | prepended. Use -p/--prefix to specify a format string for the |
|
498 | 498 | prefix. The default is the basename of the archive, with suffixes |
|
499 | 499 | removed. |
|
500 | 500 | |
|
501 | 501 | Returns 0 on success. |
|
502 | 502 | ''' |
|
503 | 503 | |
|
504 | 504 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
505 | 505 | if not ctx: |
|
506 | 506 | raise error.Abort(_('no working directory: please specify a revision')) |
|
507 | 507 | node = ctx.node() |
|
508 | 508 | dest = cmdutil.makefilename(repo, dest, node) |
|
509 | 509 | if os.path.realpath(dest) == repo.root: |
|
510 | 510 | raise error.Abort(_('repository root cannot be destination')) |
|
511 | 511 | |
|
512 | 512 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
513 | 513 | prefix = opts.get('prefix') |
|
514 | 514 | |
|
515 | 515 | if dest == '-': |
|
516 | 516 | if kind == 'files': |
|
517 | 517 | raise error.Abort(_('cannot archive plain files to stdout')) |
|
518 | 518 | dest = cmdutil.makefileobj(repo, dest) |
|
519 | 519 | if not prefix: |
|
520 | 520 | prefix = os.path.basename(repo.root) + '-%h' |
|
521 | 521 | |
|
522 | 522 | prefix = cmdutil.makefilename(repo, prefix, node) |
|
523 | 523 | matchfn = scmutil.match(ctx, [], opts) |
|
524 | 524 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
525 | 525 | matchfn, prefix, subrepos=opts.get('subrepos')) |
|
526 | 526 | |
|
527 | 527 | @command('backout', |
|
528 | 528 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
529 | 529 | ('', 'commit', None, |
|
530 | 530 | _('commit if no conflicts were encountered (DEPRECATED)')), |
|
531 | 531 | ('', 'no-commit', None, _('do not commit')), |
|
532 | 532 | ('', 'parent', '', |
|
533 | 533 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), |
|
534 | 534 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
535 | 535 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
536 | 536 | ] + mergetoolopts + walkopts + commitopts + commitopts2, |
|
537 | 537 | _('[OPTION]... [-r] REV')) |
|
538 | 538 | def backout(ui, repo, node=None, rev=None, **opts): |
|
539 | 539 | '''reverse effect of earlier changeset |
|
540 | 540 | |
|
541 | 541 | Prepare a new changeset with the effect of REV undone in the |
|
542 | 542 | current working directory. If no conflicts were encountered, |
|
543 | 543 | it will be committed immediately. |
|
544 | 544 | |
|
545 | 545 | If REV is the parent of the working directory, then this new changeset |
|
546 | 546 | is committed automatically (unless --no-commit is specified). |
|
547 | 547 | |
|
548 | 548 | .. note:: |
|
549 | 549 | |
|
550 | 550 | :hg:`backout` cannot be used to fix either an unwanted or |
|
551 | 551 | incorrect merge. |
|
552 | 552 | |
|
553 | 553 | .. container:: verbose |
|
554 | 554 | |
|
555 | 555 | Examples: |
|
556 | 556 | |
|
557 | 557 | - Reverse the effect of the parent of the working directory. |
|
558 | 558 | This backout will be committed immediately:: |
|
559 | 559 | |
|
560 | 560 | hg backout -r . |
|
561 | 561 | |
|
562 | 562 | - Reverse the effect of previous bad revision 23:: |
|
563 | 563 | |
|
564 | 564 | hg backout -r 23 |
|
565 | 565 | |
|
566 | 566 | - Reverse the effect of previous bad revision 23 and |
|
567 | 567 | leave changes uncommitted:: |
|
568 | 568 | |
|
569 | 569 | hg backout -r 23 --no-commit |
|
570 | 570 | hg commit -m "Backout revision 23" |
|
571 | 571 | |
|
572 | 572 | By default, the pending changeset will have one parent, |
|
573 | 573 | maintaining a linear history. With --merge, the pending |
|
574 | 574 | changeset will instead have two parents: the old parent of the |
|
575 | 575 | working directory and a new child of REV that simply undoes REV. |
|
576 | 576 | |
|
577 | 577 | Before version 1.7, the behavior without --merge was equivalent |
|
578 | 578 | to specifying --merge followed by :hg:`update --clean .` to |
|
579 | 579 | cancel the merge and leave the child of REV as a head to be |
|
580 | 580 | merged separately. |
|
581 | 581 | |
|
582 | 582 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
583 | 583 | |
|
584 | 584 | See :hg:`help revert` for a way to restore files to the state |
|
585 | 585 | of another revision. |
|
586 | 586 | |
|
587 | 587 | Returns 0 on success, 1 if nothing to backout or there are unresolved |
|
588 | 588 | files. |
|
589 | 589 | ''' |
|
590 | 590 | wlock = lock = None |
|
591 | 591 | try: |
|
592 | 592 | wlock = repo.wlock() |
|
593 | 593 | lock = repo.lock() |
|
594 | 594 | return _dobackout(ui, repo, node, rev, **opts) |
|
595 | 595 | finally: |
|
596 | 596 | release(lock, wlock) |
|
597 | 597 | |
|
598 | 598 | def _dobackout(ui, repo, node=None, rev=None, **opts): |
|
599 | 599 | if opts.get('commit') and opts.get('no_commit'): |
|
600 | 600 | raise error.Abort(_("cannot use --commit with --no-commit")) |
|
601 | 601 | if opts.get('merge') and opts.get('no_commit'): |
|
602 | 602 | raise error.Abort(_("cannot use --merge with --no-commit")) |
|
603 | 603 | |
|
604 | 604 | if rev and node: |
|
605 | 605 | raise error.Abort(_("please specify just one revision")) |
|
606 | 606 | |
|
607 | 607 | if not rev: |
|
608 | 608 | rev = node |
|
609 | 609 | |
|
610 | 610 | if not rev: |
|
611 | 611 | raise error.Abort(_("please specify a revision to backout")) |
|
612 | 612 | |
|
613 | 613 | date = opts.get('date') |
|
614 | 614 | if date: |
|
615 | 615 | opts['date'] = util.parsedate(date) |
|
616 | 616 | |
|
617 | 617 | cmdutil.checkunfinished(repo) |
|
618 | 618 | cmdutil.bailifchanged(repo) |
|
619 | 619 | node = scmutil.revsingle(repo, rev).node() |
|
620 | 620 | |
|
621 | 621 | op1, op2 = repo.dirstate.parents() |
|
622 | 622 | if not repo.changelog.isancestor(node, op1): |
|
623 | 623 | raise error.Abort(_('cannot backout change that is not an ancestor')) |
|
624 | 624 | |
|
625 | 625 | p1, p2 = repo.changelog.parents(node) |
|
626 | 626 | if p1 == nullid: |
|
627 | 627 | raise error.Abort(_('cannot backout a change with no parents')) |
|
628 | 628 | if p2 != nullid: |
|
629 | 629 | if not opts.get('parent'): |
|
630 | 630 | raise error.Abort(_('cannot backout a merge changeset')) |
|
631 | 631 | p = repo.lookup(opts['parent']) |
|
632 | 632 | if p not in (p1, p2): |
|
633 | 633 | raise error.Abort(_('%s is not a parent of %s') % |
|
634 | 634 | (short(p), short(node))) |
|
635 | 635 | parent = p |
|
636 | 636 | else: |
|
637 | 637 | if opts.get('parent'): |
|
638 | 638 | raise error.Abort(_('cannot use --parent on non-merge changeset')) |
|
639 | 639 | parent = p1 |
|
640 | 640 | |
|
641 | 641 | # the backout should appear on the same branch |
|
642 | 642 | branch = repo.dirstate.branch() |
|
643 | 643 | bheads = repo.branchheads(branch) |
|
644 | 644 | rctx = scmutil.revsingle(repo, hex(parent)) |
|
645 | 645 | if not opts.get('merge') and op1 != node: |
|
646 | 646 | dsguard = cmdutil.dirstateguard(repo, 'backout') |
|
647 | 647 | try: |
|
648 | 648 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
649 | 649 | 'backout') |
|
650 | 650 | stats = mergemod.update(repo, parent, True, True, node, False) |
|
651 | 651 | repo.setparents(op1, op2) |
|
652 | 652 | dsguard.close() |
|
653 | 653 | hg._showstats(repo, stats) |
|
654 | 654 | if stats[3]: |
|
655 | 655 | repo.ui.status(_("use 'hg resolve' to retry unresolved " |
|
656 | 656 | "file merges\n")) |
|
657 | 657 | return 1 |
|
658 | 658 | finally: |
|
659 | 659 | ui.setconfig('ui', 'forcemerge', '', '') |
|
660 | 660 | lockmod.release(dsguard) |
|
661 | 661 | else: |
|
662 | 662 | hg.clean(repo, node, show_stats=False) |
|
663 | 663 | repo.dirstate.setbranch(branch) |
|
664 | 664 | cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) |
|
665 | 665 | |
|
666 | 666 | if opts.get('no_commit'): |
|
667 | 667 | msg = _("changeset %s backed out, " |
|
668 | 668 | "don't forget to commit.\n") |
|
669 | 669 | ui.status(msg % short(node)) |
|
670 | 670 | return 0 |
|
671 | 671 | |
|
672 | 672 | def commitfunc(ui, repo, message, match, opts): |
|
673 | 673 | editform = 'backout' |
|
674 | 674 | e = cmdutil.getcommiteditor(editform=editform, **opts) |
|
675 | 675 | if not message: |
|
676 | 676 | # we don't translate commit messages |
|
677 | 677 | message = "Backed out changeset %s" % short(node) |
|
678 | 678 | e = cmdutil.getcommiteditor(edit=True, editform=editform) |
|
679 | 679 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
680 | 680 | match, editor=e) |
|
681 | 681 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) |
|
682 | 682 | if not newnode: |
|
683 | 683 | ui.status(_("nothing changed\n")) |
|
684 | 684 | return 1 |
|
685 | 685 | cmdutil.commitstatus(repo, newnode, branch, bheads) |
|
686 | 686 | |
|
687 | 687 | def nice(node): |
|
688 | 688 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
689 | 689 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
690 | 690 | (nice(repo.changelog.tip()), nice(node))) |
|
691 | 691 | if opts.get('merge') and op1 != node: |
|
692 | 692 | hg.clean(repo, op1, show_stats=False) |
|
693 | 693 | ui.status(_('merging with changeset %s\n') |
|
694 | 694 | % nice(repo.changelog.tip())) |
|
695 | 695 | try: |
|
696 | 696 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
697 | 697 | 'backout') |
|
698 | 698 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
699 | 699 | finally: |
|
700 | 700 | ui.setconfig('ui', 'forcemerge', '', '') |
|
701 | 701 | return 0 |
|
702 | 702 | |
|
703 | 703 | @command('bisect', |
|
704 | 704 | [('r', 'reset', False, _('reset bisect state')), |
|
705 | 705 | ('g', 'good', False, _('mark changeset good')), |
|
706 | 706 | ('b', 'bad', False, _('mark changeset bad')), |
|
707 | 707 | ('s', 'skip', False, _('skip testing changeset')), |
|
708 | 708 | ('e', 'extend', False, _('extend the bisect range')), |
|
709 | 709 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
710 | 710 | ('U', 'noupdate', False, _('do not update to target'))], |
|
711 | 711 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
712 | 712 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
713 | 713 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
714 | 714 | noupdate=None): |
|
715 | 715 | """subdivision search of changesets |
|
716 | 716 | |
|
717 | 717 | This command helps to find changesets which introduce problems. To |
|
718 | 718 | use, mark the earliest changeset you know exhibits the problem as |
|
719 | 719 | bad, then mark the latest changeset which is free from the problem |
|
720 | 720 | as good. Bisect will update your working directory to a revision |
|
721 | 721 | for testing (unless the -U/--noupdate option is specified). Once |
|
722 | 722 | you have performed tests, mark the working directory as good or |
|
723 | 723 | bad, and bisect will either update to another candidate changeset |
|
724 | 724 | or announce that it has found the bad revision. |
|
725 | 725 | |
|
726 | 726 | As a shortcut, you can also use the revision argument to mark a |
|
727 | 727 | revision as good or bad without checking it out first. |
|
728 | 728 | |
|
729 | 729 | If you supply a command, it will be used for automatic bisection. |
|
730 | 730 | The environment variable HG_NODE will contain the ID of the |
|
731 | 731 | changeset being tested. The exit status of the command will be |
|
732 | 732 | used to mark revisions as good or bad: status 0 means good, 125 |
|
733 | 733 | means to skip the revision, 127 (command not found) will abort the |
|
734 | 734 | bisection, and any other non-zero exit status means the revision |
|
735 | 735 | is bad. |
|
736 | 736 | |
|
737 | 737 | .. container:: verbose |
|
738 | 738 | |
|
739 | 739 | Some examples: |
|
740 | 740 | |
|
741 | 741 | - start a bisection with known bad revision 34, and good revision 12:: |
|
742 | 742 | |
|
743 | 743 | hg bisect --bad 34 |
|
744 | 744 | hg bisect --good 12 |
|
745 | 745 | |
|
746 | 746 | - advance the current bisection by marking current revision as good or |
|
747 | 747 | bad:: |
|
748 | 748 | |
|
749 | 749 | hg bisect --good |
|
750 | 750 | hg bisect --bad |
|
751 | 751 | |
|
752 | 752 | - mark the current revision, or a known revision, to be skipped (e.g. if |
|
753 | 753 | that revision is not usable because of another issue):: |
|
754 | 754 | |
|
755 | 755 | hg bisect --skip |
|
756 | 756 | hg bisect --skip 23 |
|
757 | 757 | |
|
758 | 758 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: |
|
759 | 759 | |
|
760 | 760 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" |
|
761 | 761 | |
|
762 | 762 | - forget the current bisection:: |
|
763 | 763 | |
|
764 | 764 | hg bisect --reset |
|
765 | 765 | |
|
766 | 766 | - use 'make && make tests' to automatically find the first broken |
|
767 | 767 | revision:: |
|
768 | 768 | |
|
769 | 769 | hg bisect --reset |
|
770 | 770 | hg bisect --bad 34 |
|
771 | 771 | hg bisect --good 12 |
|
772 | 772 | hg bisect --command "make && make tests" |
|
773 | 773 | |
|
774 | 774 | - see all changesets whose states are already known in the current |
|
775 | 775 | bisection:: |
|
776 | 776 | |
|
777 | 777 | hg log -r "bisect(pruned)" |
|
778 | 778 | |
|
779 | 779 | - see the changeset currently being bisected (especially useful |
|
780 | 780 | if running with -U/--noupdate):: |
|
781 | 781 | |
|
782 | 782 | hg log -r "bisect(current)" |
|
783 | 783 | |
|
784 | 784 | - see all changesets that took part in the current bisection:: |
|
785 | 785 | |
|
786 | 786 | hg log -r "bisect(range)" |
|
787 | 787 | |
|
788 | 788 | - you can even get a nice graph:: |
|
789 | 789 | |
|
790 | 790 | hg log --graph -r "bisect(range)" |
|
791 | 791 | |
|
792 | 792 | See :hg:`help revsets` for more about the `bisect()` keyword. |
|
793 | 793 | |
|
794 | 794 | Returns 0 on success. |
|
795 | 795 | """ |
|
796 | 796 | def extendbisectrange(nodes, good): |
|
797 | 797 | # bisect is incomplete when it ends on a merge node and |
|
798 | 798 | # one of the parent was not checked. |
|
799 | 799 | parents = repo[nodes[0]].parents() |
|
800 | 800 | if len(parents) > 1: |
|
801 | 801 | if good: |
|
802 | 802 | side = state['bad'] |
|
803 | 803 | else: |
|
804 | 804 | side = state['good'] |
|
805 | 805 | num = len(set(i.node() for i in parents) & set(side)) |
|
806 | 806 | if num == 1: |
|
807 | 807 | return parents[0].ancestor(parents[1]) |
|
808 | 808 | return None |
|
809 | 809 | |
|
810 | 810 | def print_result(nodes, good): |
|
811 | 811 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
812 | 812 | if len(nodes) == 1: |
|
813 | 813 | # narrowed it down to a single revision |
|
814 | 814 | if good: |
|
815 | 815 | ui.write(_("The first good revision is:\n")) |
|
816 | 816 | else: |
|
817 | 817 | ui.write(_("The first bad revision is:\n")) |
|
818 | 818 | displayer.show(repo[nodes[0]]) |
|
819 | 819 | extendnode = extendbisectrange(nodes, good) |
|
820 | 820 | if extendnode is not None: |
|
821 | 821 | ui.write(_('Not all ancestors of this changeset have been' |
|
822 | 822 | ' checked.\nUse bisect --extend to continue the ' |
|
823 | 823 | 'bisection from\nthe common ancestor, %s.\n') |
|
824 | 824 | % extendnode) |
|
825 | 825 | else: |
|
826 | 826 | # multiple possible revisions |
|
827 | 827 | if good: |
|
828 | 828 | ui.write(_("Due to skipped revisions, the first " |
|
829 | 829 | "good revision could be any of:\n")) |
|
830 | 830 | else: |
|
831 | 831 | ui.write(_("Due to skipped revisions, the first " |
|
832 | 832 | "bad revision could be any of:\n")) |
|
833 | 833 | for n in nodes: |
|
834 | 834 | displayer.show(repo[n]) |
|
835 | 835 | displayer.close() |
|
836 | 836 | |
|
837 | 837 | def check_state(state, interactive=True): |
|
838 | 838 | if not state['good'] or not state['bad']: |
|
839 | 839 | if (good or bad or skip or reset) and interactive: |
|
840 | 840 | return |
|
841 | 841 | if not state['good']: |
|
842 | 842 | raise error.Abort(_('cannot bisect (no known good revisions)')) |
|
843 | 843 | else: |
|
844 | 844 | raise error.Abort(_('cannot bisect (no known bad revisions)')) |
|
845 | 845 | return True |
|
846 | 846 | |
|
847 | 847 | # backward compatibility |
|
848 | 848 | if rev in "good bad reset init".split(): |
|
849 | 849 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
850 | 850 | cmd, rev, extra = rev, extra, None |
|
851 | 851 | if cmd == "good": |
|
852 | 852 | good = True |
|
853 | 853 | elif cmd == "bad": |
|
854 | 854 | bad = True |
|
855 | 855 | else: |
|
856 | 856 | reset = True |
|
857 | 857 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: |
|
858 | 858 | raise error.Abort(_('incompatible arguments')) |
|
859 | 859 | |
|
860 | 860 | cmdutil.checkunfinished(repo) |
|
861 | 861 | |
|
862 | 862 | if reset: |
|
863 | 863 | p = repo.join("bisect.state") |
|
864 | 864 | if os.path.exists(p): |
|
865 | 865 | os.unlink(p) |
|
866 | 866 | return |
|
867 | 867 | |
|
868 | 868 | state = hbisect.load_state(repo) |
|
869 | 869 | |
|
870 | 870 | if command: |
|
871 | 871 | changesets = 1 |
|
872 | 872 | if noupdate: |
|
873 | 873 | try: |
|
874 | 874 | node = state['current'][0] |
|
875 | 875 | except LookupError: |
|
876 | 876 | raise error.Abort(_('current bisect revision is unknown - ' |
|
877 | 877 | 'start a new bisect to fix')) |
|
878 | 878 | else: |
|
879 | 879 | node, p2 = repo.dirstate.parents() |
|
880 | 880 | if p2 != nullid: |
|
881 | 881 | raise error.Abort(_('current bisect revision is a merge')) |
|
882 | 882 | try: |
|
883 | 883 | while changesets: |
|
884 | 884 | # update state |
|
885 | 885 | state['current'] = [node] |
|
886 | 886 | hbisect.save_state(repo, state) |
|
887 | 887 | status = ui.system(command, environ={'HG_NODE': hex(node)}) |
|
888 | 888 | if status == 125: |
|
889 | 889 | transition = "skip" |
|
890 | 890 | elif status == 0: |
|
891 | 891 | transition = "good" |
|
892 | 892 | # status < 0 means process was killed |
|
893 | 893 | elif status == 127: |
|
894 | 894 | raise error.Abort(_("failed to execute %s") % command) |
|
895 | 895 | elif status < 0: |
|
896 | 896 | raise error.Abort(_("%s killed") % command) |
|
897 | 897 | else: |
|
898 | 898 | transition = "bad" |
|
899 | 899 | ctx = scmutil.revsingle(repo, rev, node) |
|
900 | 900 | rev = None # clear for future iterations |
|
901 | 901 | state[transition].append(ctx.node()) |
|
902 | 902 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
903 | 903 | check_state(state, interactive=False) |
|
904 | 904 | # bisect |
|
905 | 905 | nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) |
|
906 | 906 | # update to next check |
|
907 | 907 | node = nodes[0] |
|
908 | 908 | if not noupdate: |
|
909 | 909 | cmdutil.bailifchanged(repo) |
|
910 | 910 | hg.clean(repo, node, show_stats=False) |
|
911 | 911 | finally: |
|
912 | 912 | state['current'] = [node] |
|
913 | 913 | hbisect.save_state(repo, state) |
|
914 | 914 | print_result(nodes, bgood) |
|
915 | 915 | return |
|
916 | 916 | |
|
917 | 917 | # update state |
|
918 | 918 | |
|
919 | 919 | if rev: |
|
920 | 920 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] |
|
921 | 921 | else: |
|
922 | 922 | nodes = [repo.lookup('.')] |
|
923 | 923 | |
|
924 | 924 | if good or bad or skip: |
|
925 | 925 | if good: |
|
926 | 926 | state['good'] += nodes |
|
927 | 927 | elif bad: |
|
928 | 928 | state['bad'] += nodes |
|
929 | 929 | elif skip: |
|
930 | 930 | state['skip'] += nodes |
|
931 | 931 | hbisect.save_state(repo, state) |
|
932 | 932 | |
|
933 | 933 | if not check_state(state): |
|
934 | 934 | return |
|
935 | 935 | |
|
936 | 936 | # actually bisect |
|
937 | 937 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
938 | 938 | if extend: |
|
939 | 939 | if not changesets: |
|
940 | 940 | extendnode = extendbisectrange(nodes, good) |
|
941 | 941 | if extendnode is not None: |
|
942 | 942 | ui.write(_("Extending search to changeset %d:%s\n") |
|
943 | 943 | % (extendnode.rev(), extendnode)) |
|
944 | 944 | state['current'] = [extendnode.node()] |
|
945 | 945 | hbisect.save_state(repo, state) |
|
946 | 946 | if noupdate: |
|
947 | 947 | return |
|
948 | 948 | cmdutil.bailifchanged(repo) |
|
949 | 949 | return hg.clean(repo, extendnode.node()) |
|
950 | 950 | raise error.Abort(_("nothing to extend")) |
|
951 | 951 | |
|
952 | 952 | if changesets == 0: |
|
953 | 953 | print_result(nodes, good) |
|
954 | 954 | else: |
|
955 | 955 | assert len(nodes) == 1 # only a single node can be tested next |
|
956 | 956 | node = nodes[0] |
|
957 | 957 | # compute the approximate number of remaining tests |
|
958 | 958 | tests, size = 0, 2 |
|
959 | 959 | while size <= changesets: |
|
960 | 960 | tests, size = tests + 1, size * 2 |
|
961 | 961 | rev = repo.changelog.rev(node) |
|
962 | 962 | ui.write(_("Testing changeset %d:%s " |
|
963 | 963 | "(%d changesets remaining, ~%d tests)\n") |
|
964 | 964 | % (rev, short(node), changesets, tests)) |
|
965 | 965 | state['current'] = [node] |
|
966 | 966 | hbisect.save_state(repo, state) |
|
967 | 967 | if not noupdate: |
|
968 | 968 | cmdutil.bailifchanged(repo) |
|
969 | 969 | return hg.clean(repo, node) |
|
970 | 970 | |
|
971 | 971 | @command('bookmarks|bookmark', |
|
972 | 972 | [('f', 'force', False, _('force')), |
|
973 | 973 | ('r', 'rev', '', _('revision for bookmark action'), _('REV')), |
|
974 | 974 | ('d', 'delete', False, _('delete a given bookmark')), |
|
975 | 975 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), |
|
976 | 976 | ('i', 'inactive', False, _('mark a bookmark inactive')), |
|
977 | 977 | ] + formatteropts, |
|
978 | 978 | _('hg bookmarks [OPTIONS]... [NAME]...')) |
|
979 | 979 | def bookmark(ui, repo, *names, **opts): |
|
980 | 980 | '''create a new bookmark or list existing bookmarks |
|
981 | 981 | |
|
982 | 982 | Bookmarks are labels on changesets to help track lines of development. |
|
983 | 983 | Bookmarks are unversioned and can be moved, renamed and deleted. |
|
984 | 984 | Deleting or moving a bookmark has no effect on the associated changesets. |
|
985 | 985 | |
|
986 | 986 | Creating or updating to a bookmark causes it to be marked as 'active'. |
|
987 | 987 | The active bookmark is indicated with a '*'. |
|
988 | 988 | When a commit is made, the active bookmark will advance to the new commit. |
|
989 | 989 | A plain :hg:`update` will also advance an active bookmark, if possible. |
|
990 | 990 | Updating away from a bookmark will cause it to be deactivated. |
|
991 | 991 | |
|
992 | 992 | Bookmarks can be pushed and pulled between repositories (see |
|
993 | 993 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has |
|
994 | 994 | diverged, a new 'divergent bookmark' of the form 'name@path' will |
|
995 | 995 | be created. Using :hg:`merge` will resolve the divergence. |
|
996 | 996 | |
|
997 | 997 | A bookmark named '@' has the special property that :hg:`clone` will |
|
998 | 998 | check it out by default if it exists. |
|
999 | 999 | |
|
1000 | 1000 | .. container:: verbose |
|
1001 | 1001 | |
|
1002 | 1002 | Examples: |
|
1003 | 1003 | |
|
1004 | 1004 | - create an active bookmark for a new line of development:: |
|
1005 | 1005 | |
|
1006 | 1006 | hg book new-feature |
|
1007 | 1007 | |
|
1008 | 1008 | - create an inactive bookmark as a place marker:: |
|
1009 | 1009 | |
|
1010 | 1010 | hg book -i reviewed |
|
1011 | 1011 | |
|
1012 | 1012 | - create an inactive bookmark on another changeset:: |
|
1013 | 1013 | |
|
1014 | 1014 | hg book -r .^ tested |
|
1015 | 1015 | |
|
1016 | 1016 | - rename bookmark turkey to dinner:: |
|
1017 | 1017 | |
|
1018 | 1018 | hg book -m turkey dinner |
|
1019 | 1019 | |
|
1020 | 1020 | - move the '@' bookmark from another branch:: |
|
1021 | 1021 | |
|
1022 | 1022 | hg book -f @ |
|
1023 | 1023 | ''' |
|
1024 | 1024 | force = opts.get('force') |
|
1025 | 1025 | rev = opts.get('rev') |
|
1026 | 1026 | delete = opts.get('delete') |
|
1027 | 1027 | rename = opts.get('rename') |
|
1028 | 1028 | inactive = opts.get('inactive') |
|
1029 | 1029 | |
|
1030 | 1030 | def checkformat(mark): |
|
1031 | 1031 | mark = mark.strip() |
|
1032 | 1032 | if not mark: |
|
1033 | 1033 | raise error.Abort(_("bookmark names cannot consist entirely of " |
|
1034 | 1034 | "whitespace")) |
|
1035 | 1035 | scmutil.checknewlabel(repo, mark, 'bookmark') |
|
1036 | 1036 | return mark |
|
1037 | 1037 | |
|
1038 | 1038 | def checkconflict(repo, mark, cur, force=False, target=None): |
|
1039 | 1039 | if mark in marks and not force: |
|
1040 | 1040 | if target: |
|
1041 | 1041 | if marks[mark] == target and target == cur: |
|
1042 | 1042 | # re-activating a bookmark |
|
1043 | 1043 | return |
|
1044 | 1044 | anc = repo.changelog.ancestors([repo[target].rev()]) |
|
1045 | 1045 | bmctx = repo[marks[mark]] |
|
1046 | 1046 | divs = [repo[b].node() for b in marks |
|
1047 | 1047 | if b.split('@', 1)[0] == mark.split('@', 1)[0]] |
|
1048 | 1048 | |
|
1049 | 1049 | # allow resolving a single divergent bookmark even if moving |
|
1050 | 1050 | # the bookmark across branches when a revision is specified |
|
1051 | 1051 | # that contains a divergent bookmark |
|
1052 | 1052 | if bmctx.rev() not in anc and target in divs: |
|
1053 | 1053 | bookmarks.deletedivergent(repo, [target], mark) |
|
1054 | 1054 | return |
|
1055 | 1055 | |
|
1056 | 1056 | deletefrom = [b for b in divs |
|
1057 | 1057 | if repo[b].rev() in anc or b == target] |
|
1058 | 1058 | bookmarks.deletedivergent(repo, deletefrom, mark) |
|
1059 | 1059 | if bookmarks.validdest(repo, bmctx, repo[target]): |
|
1060 | 1060 | ui.status(_("moving bookmark '%s' forward from %s\n") % |
|
1061 | 1061 | (mark, short(bmctx.node()))) |
|
1062 | 1062 | return |
|
1063 | 1063 | raise error.Abort(_("bookmark '%s' already exists " |
|
1064 | 1064 | "(use -f to force)") % mark) |
|
1065 | 1065 | if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) |
|
1066 | 1066 | and not force): |
|
1067 | 1067 | raise error.Abort( |
|
1068 | 1068 | _("a bookmark cannot have the name of an existing branch")) |
|
1069 | 1069 | |
|
1070 | 1070 | if delete and rename: |
|
1071 | 1071 | raise error.Abort(_("--delete and --rename are incompatible")) |
|
1072 | 1072 | if delete and rev: |
|
1073 | 1073 | raise error.Abort(_("--rev is incompatible with --delete")) |
|
1074 | 1074 | if rename and rev: |
|
1075 | 1075 | raise error.Abort(_("--rev is incompatible with --rename")) |
|
1076 | 1076 | if not names and (delete or rev): |
|
1077 | 1077 | raise error.Abort(_("bookmark name required")) |
|
1078 | 1078 | |
|
1079 | 1079 | if delete or rename or names or inactive: |
|
1080 | 1080 | wlock = lock = tr = None |
|
1081 | 1081 | try: |
|
1082 | 1082 | wlock = repo.wlock() |
|
1083 | 1083 | lock = repo.lock() |
|
1084 | 1084 | cur = repo.changectx('.').node() |
|
1085 | 1085 | marks = repo._bookmarks |
|
1086 | 1086 | if delete: |
|
1087 | 1087 | tr = repo.transaction('bookmark') |
|
1088 | 1088 | for mark in names: |
|
1089 | 1089 | if mark not in marks: |
|
1090 | 1090 | raise error.Abort(_("bookmark '%s' does not exist") % |
|
1091 | 1091 | mark) |
|
1092 | 1092 | if mark == repo._activebookmark: |
|
1093 | 1093 | bookmarks.deactivate(repo) |
|
1094 | 1094 | del marks[mark] |
|
1095 | 1095 | |
|
1096 | 1096 | elif rename: |
|
1097 | 1097 | tr = repo.transaction('bookmark') |
|
1098 | 1098 | if not names: |
|
1099 | 1099 | raise error.Abort(_("new bookmark name required")) |
|
1100 | 1100 | elif len(names) > 1: |
|
1101 | 1101 | raise error.Abort(_("only one new bookmark name allowed")) |
|
1102 | 1102 | mark = checkformat(names[0]) |
|
1103 | 1103 | if rename not in marks: |
|
1104 | 1104 | raise error.Abort(_("bookmark '%s' does not exist") |
|
1105 | 1105 | % rename) |
|
1106 | 1106 | checkconflict(repo, mark, cur, force) |
|
1107 | 1107 | marks[mark] = marks[rename] |
|
1108 | 1108 | if repo._activebookmark == rename and not inactive: |
|
1109 | 1109 | bookmarks.activate(repo, mark) |
|
1110 | 1110 | del marks[rename] |
|
1111 | 1111 | elif names: |
|
1112 | 1112 | tr = repo.transaction('bookmark') |
|
1113 | 1113 | newact = None |
|
1114 | 1114 | for mark in names: |
|
1115 | 1115 | mark = checkformat(mark) |
|
1116 | 1116 | if newact is None: |
|
1117 | 1117 | newact = mark |
|
1118 | 1118 | if inactive and mark == repo._activebookmark: |
|
1119 | 1119 | bookmarks.deactivate(repo) |
|
1120 | 1120 | return |
|
1121 | 1121 | tgt = cur |
|
1122 | 1122 | if rev: |
|
1123 | 1123 | tgt = scmutil.revsingle(repo, rev).node() |
|
1124 | 1124 | checkconflict(repo, mark, cur, force, tgt) |
|
1125 | 1125 | marks[mark] = tgt |
|
1126 | 1126 | if not inactive and cur == marks[newact] and not rev: |
|
1127 | 1127 | bookmarks.activate(repo, newact) |
|
1128 | 1128 | elif cur != tgt and newact == repo._activebookmark: |
|
1129 | 1129 | bookmarks.deactivate(repo) |
|
1130 | 1130 | elif inactive: |
|
1131 | 1131 | if len(marks) == 0: |
|
1132 | 1132 | ui.status(_("no bookmarks set\n")) |
|
1133 | 1133 | elif not repo._activebookmark: |
|
1134 | 1134 | ui.status(_("no active bookmark\n")) |
|
1135 | 1135 | else: |
|
1136 | 1136 | bookmarks.deactivate(repo) |
|
1137 | 1137 | if tr is not None: |
|
1138 | 1138 | marks.recordchange(tr) |
|
1139 | 1139 | tr.close() |
|
1140 | 1140 | finally: |
|
1141 | 1141 | lockmod.release(tr, lock, wlock) |
|
1142 | 1142 | else: # show bookmarks |
|
1143 | 1143 | fm = ui.formatter('bookmarks', opts) |
|
1144 | 1144 | hexfn = fm.hexfunc |
|
1145 | 1145 | marks = repo._bookmarks |
|
1146 | 1146 | if len(marks) == 0 and not fm: |
|
1147 | 1147 | ui.status(_("no bookmarks set\n")) |
|
1148 | 1148 | for bmark, n in sorted(marks.iteritems()): |
|
1149 | 1149 | active = repo._activebookmark |
|
1150 | 1150 | if bmark == active: |
|
1151 | 1151 | prefix, label = '*', activebookmarklabel |
|
1152 | 1152 | else: |
|
1153 | 1153 | prefix, label = ' ', '' |
|
1154 | 1154 | |
|
1155 | 1155 | fm.startitem() |
|
1156 | 1156 | if not ui.quiet: |
|
1157 | 1157 | fm.plain(' %s ' % prefix, label=label) |
|
1158 | 1158 | fm.write('bookmark', '%s', bmark, label=label) |
|
1159 | 1159 | pad = " " * (25 - encoding.colwidth(bmark)) |
|
1160 | 1160 | fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s', |
|
1161 | 1161 | repo.changelog.rev(n), hexfn(n), label=label) |
|
1162 | 1162 | fm.data(active=(bmark == active)) |
|
1163 | 1163 | fm.plain('\n') |
|
1164 | 1164 | fm.end() |
|
1165 | 1165 | |
|
1166 | 1166 | @command('branch', |
|
1167 | 1167 | [('f', 'force', None, |
|
1168 | 1168 | _('set branch name even if it shadows an existing branch')), |
|
1169 | 1169 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
1170 | 1170 | _('[-fC] [NAME]')) |
|
1171 | 1171 | def branch(ui, repo, label=None, **opts): |
|
1172 | 1172 | """set or show the current branch name |
|
1173 | 1173 | |
|
1174 | 1174 | .. note:: |
|
1175 | 1175 | |
|
1176 | 1176 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
1177 | 1177 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
1178 | 1178 | information about named branches and bookmarks. |
|
1179 | 1179 | |
|
1180 | 1180 | With no argument, show the current branch name. With one argument, |
|
1181 | 1181 | set the working directory branch name (the branch will not exist |
|
1182 | 1182 | in the repository until the next commit). Standard practice |
|
1183 | 1183 | recommends that primary development take place on the 'default' |
|
1184 | 1184 | branch. |
|
1185 | 1185 | |
|
1186 | 1186 | Unless -f/--force is specified, branch will not let you set a |
|
1187 | 1187 | branch name that already exists. |
|
1188 | 1188 | |
|
1189 | 1189 | Use -C/--clean to reset the working directory branch to that of |
|
1190 | 1190 | the parent of the working directory, negating a previous branch |
|
1191 | 1191 | change. |
|
1192 | 1192 | |
|
1193 | 1193 | Use the command :hg:`update` to switch to an existing branch. Use |
|
1194 | 1194 | :hg:`commit --close-branch` to mark this branch head as closed. |
|
1195 | 1195 | When all heads of a branch are closed, the branch will be |
|
1196 | 1196 | considered closed. |
|
1197 | 1197 | |
|
1198 | 1198 | Returns 0 on success. |
|
1199 | 1199 | """ |
|
1200 | 1200 | if label: |
|
1201 | 1201 | label = label.strip() |
|
1202 | 1202 | |
|
1203 | 1203 | if not opts.get('clean') and not label: |
|
1204 | 1204 | ui.write("%s\n" % repo.dirstate.branch()) |
|
1205 | 1205 | return |
|
1206 | 1206 | |
|
1207 | 1207 | with repo.wlock(): |
|
1208 | 1208 | if opts.get('clean'): |
|
1209 | 1209 | label = repo[None].p1().branch() |
|
1210 | 1210 | repo.dirstate.setbranch(label) |
|
1211 | 1211 | ui.status(_('reset working directory to branch %s\n') % label) |
|
1212 | 1212 | elif label: |
|
1213 | 1213 | if not opts.get('force') and label in repo.branchmap(): |
|
1214 | 1214 | if label not in [p.branch() for p in repo[None].parents()]: |
|
1215 | 1215 | raise error.Abort(_('a branch of the same name already' |
|
1216 | 1216 | ' exists'), |
|
1217 | 1217 | # i18n: "it" refers to an existing branch |
|
1218 | 1218 | hint=_("use 'hg update' to switch to it")) |
|
1219 | 1219 | scmutil.checknewlabel(repo, label, 'branch') |
|
1220 | 1220 | repo.dirstate.setbranch(label) |
|
1221 | 1221 | ui.status(_('marked working directory as branch %s\n') % label) |
|
1222 | 1222 | |
|
1223 | 1223 | # find any open named branches aside from default |
|
1224 | 1224 | others = [n for n, h, t, c in repo.branchmap().iterbranches() |
|
1225 | 1225 | if n != "default" and not c] |
|
1226 | 1226 | if not others: |
|
1227 | 1227 | ui.status(_('(branches are permanent and global, ' |
|
1228 | 1228 | 'did you want a bookmark?)\n')) |
|
1229 | 1229 | |
|
1230 | 1230 | @command('branches', |
|
1231 | 1231 | [('a', 'active', False, |
|
1232 | 1232 | _('show only branches that have unmerged heads (DEPRECATED)')), |
|
1233 | 1233 | ('c', 'closed', False, _('show normal and closed branches')), |
|
1234 | 1234 | ] + formatteropts, |
|
1235 | 1235 | _('[-ac]')) |
|
1236 | 1236 | def branches(ui, repo, active=False, closed=False, **opts): |
|
1237 | 1237 | """list repository named branches |
|
1238 | 1238 | |
|
1239 | 1239 | List the repository's named branches, indicating which ones are |
|
1240 | 1240 | inactive. If -c/--closed is specified, also list branches which have |
|
1241 | 1241 | been marked closed (see :hg:`commit --close-branch`). |
|
1242 | 1242 | |
|
1243 | 1243 | Use the command :hg:`update` to switch to an existing branch. |
|
1244 | 1244 | |
|
1245 | 1245 | Returns 0. |
|
1246 | 1246 | """ |
|
1247 | 1247 | |
|
1248 | 1248 | fm = ui.formatter('branches', opts) |
|
1249 | 1249 | hexfunc = fm.hexfunc |
|
1250 | 1250 | |
|
1251 | 1251 | allheads = set(repo.heads()) |
|
1252 | 1252 | branches = [] |
|
1253 | 1253 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): |
|
1254 | 1254 | isactive = not isclosed and bool(set(heads) & allheads) |
|
1255 | 1255 | branches.append((tag, repo[tip], isactive, not isclosed)) |
|
1256 | 1256 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), |
|
1257 | 1257 | reverse=True) |
|
1258 | 1258 | |
|
1259 | 1259 | for tag, ctx, isactive, isopen in branches: |
|
1260 | 1260 | if active and not isactive: |
|
1261 | 1261 | continue |
|
1262 | 1262 | if isactive: |
|
1263 | 1263 | label = 'branches.active' |
|
1264 | 1264 | notice = '' |
|
1265 | 1265 | elif not isopen: |
|
1266 | 1266 | if not closed: |
|
1267 | 1267 | continue |
|
1268 | 1268 | label = 'branches.closed' |
|
1269 | 1269 | notice = _(' (closed)') |
|
1270 | 1270 | else: |
|
1271 | 1271 | label = 'branches.inactive' |
|
1272 | 1272 | notice = _(' (inactive)') |
|
1273 | 1273 | current = (tag == repo.dirstate.branch()) |
|
1274 | 1274 | if current: |
|
1275 | 1275 | label = 'branches.current' |
|
1276 | 1276 | |
|
1277 | 1277 | fm.startitem() |
|
1278 | 1278 | fm.write('branch', '%s', tag, label=label) |
|
1279 | 1279 | rev = ctx.rev() |
|
1280 | 1280 | padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0) |
|
1281 | 1281 | fmt = ' ' * padsize + ' %d:%s' |
|
1282 | 1282 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), |
|
1283 | 1283 | label='log.changeset changeset.%s' % ctx.phasestr()) |
|
1284 | 1284 | fm.data(active=isactive, closed=not isopen, current=current) |
|
1285 | 1285 | if not ui.quiet: |
|
1286 | 1286 | fm.plain(notice) |
|
1287 | 1287 | fm.plain('\n') |
|
1288 | 1288 | fm.end() |
|
1289 | 1289 | |
|
1290 | 1290 | @command('bundle', |
|
1291 | 1291 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
1292 | 1292 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
1293 | 1293 | _('REV')), |
|
1294 | 1294 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
1295 | 1295 | _('BRANCH')), |
|
1296 | 1296 | ('', 'base', [], |
|
1297 | 1297 | _('a base changeset assumed to be available at the destination'), |
|
1298 | 1298 | _('REV')), |
|
1299 | 1299 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
1300 | 1300 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
1301 | 1301 | ] + remoteopts, |
|
1302 | 1302 | _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
1303 | 1303 | def bundle(ui, repo, fname, dest=None, **opts): |
|
1304 | 1304 | """create a changegroup file |
|
1305 | 1305 | |
|
1306 | 1306 | Generate a changegroup file collecting changesets to be added |
|
1307 | 1307 | to a repository. |
|
1308 | 1308 | |
|
1309 | 1309 | To create a bundle containing all changesets, use -a/--all |
|
1310 | 1310 | (or --base null). Otherwise, hg assumes the destination will have |
|
1311 | 1311 | all the nodes you specify with --base parameters. Otherwise, hg |
|
1312 | 1312 | will assume the repository has all the nodes in destination, or |
|
1313 | 1313 | default-push/default if no destination is specified. |
|
1314 | 1314 | |
|
1315 | 1315 | You can change bundle format with the -t/--type option. You can |
|
1316 | 1316 | specify a compression, a bundle version or both using a dash |
|
1317 | 1317 | (comp-version). The available compression methods are: none, bzip2, |
|
1318 | 1318 | and gzip (by default, bundles are compressed using bzip2). The |
|
1319 | 1319 | available formats are: v1, v2 (default to most suitable). |
|
1320 | 1320 | |
|
1321 | 1321 | The bundle file can then be transferred using conventional means |
|
1322 | 1322 | and applied to another repository with the unbundle or pull |
|
1323 | 1323 | command. This is useful when direct push and pull are not |
|
1324 | 1324 | available or when exporting an entire repository is undesirable. |
|
1325 | 1325 | |
|
1326 | 1326 | Applying bundles preserves all changeset contents including |
|
1327 | 1327 | permissions, copy/rename information, and revision history. |
|
1328 | 1328 | |
|
1329 | 1329 | Returns 0 on success, 1 if no changes found. |
|
1330 | 1330 | """ |
|
1331 | 1331 | revs = None |
|
1332 | 1332 | if 'rev' in opts: |
|
1333 | 1333 | revstrings = opts['rev'] |
|
1334 | 1334 | revs = scmutil.revrange(repo, revstrings) |
|
1335 | 1335 | if revstrings and not revs: |
|
1336 | 1336 | raise error.Abort(_('no commits to bundle')) |
|
1337 | 1337 | |
|
1338 | 1338 | bundletype = opts.get('type', 'bzip2').lower() |
|
1339 | 1339 | try: |
|
1340 | 1340 | bcompression, cgversion, params = exchange.parsebundlespec( |
|
1341 | 1341 | repo, bundletype, strict=False) |
|
1342 | 1342 | except error.UnsupportedBundleSpecification as e: |
|
1343 | 1343 | raise error.Abort(str(e), |
|
1344 | 1344 | hint=_('see "hg help bundle" for supported ' |
|
1345 | 1345 | 'values for --type')) |
|
1346 | 1346 | |
|
1347 | 1347 | # Packed bundles are a pseudo bundle format for now. |
|
1348 | 1348 | if cgversion == 's1': |
|
1349 | 1349 | raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'), |
|
1350 | 1350 | hint=_('use "hg debugcreatestreamclonebundle"')) |
|
1351 | 1351 | |
|
1352 | 1352 | if opts.get('all'): |
|
1353 | 1353 | if dest: |
|
1354 | 1354 | raise error.Abort(_("--all is incompatible with specifying " |
|
1355 | 1355 | "a destination")) |
|
1356 | 1356 | if opts.get('base'): |
|
1357 | 1357 | ui.warn(_("ignoring --base because --all was specified\n")) |
|
1358 | 1358 | base = ['null'] |
|
1359 | 1359 | else: |
|
1360 | 1360 | base = scmutil.revrange(repo, opts.get('base')) |
|
1361 | 1361 | # TODO: get desired bundlecaps from command line. |
|
1362 | 1362 | bundlecaps = None |
|
1363 | 1363 | if base: |
|
1364 | 1364 | if dest: |
|
1365 | 1365 | raise error.Abort(_("--base is incompatible with specifying " |
|
1366 | 1366 | "a destination")) |
|
1367 | 1367 | common = [repo.lookup(rev) for rev in base] |
|
1368 | 1368 | heads = revs and map(repo.lookup, revs) or revs |
|
1369 | 1369 | cg = changegroup.getchangegroup(repo, 'bundle', heads=heads, |
|
1370 | 1370 | common=common, bundlecaps=bundlecaps, |
|
1371 | 1371 | version=cgversion) |
|
1372 | 1372 | outgoing = None |
|
1373 | 1373 | else: |
|
1374 | 1374 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1375 | 1375 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
1376 | 1376 | other = hg.peer(repo, opts, dest) |
|
1377 | 1377 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) |
|
1378 | 1378 | heads = revs and map(repo.lookup, revs) or revs |
|
1379 | 1379 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
1380 | 1380 | onlyheads=heads, |
|
1381 | 1381 | force=opts.get('force'), |
|
1382 | 1382 | portable=True) |
|
1383 | 1383 | cg = changegroup.getlocalchangegroup(repo, 'bundle', outgoing, |
|
1384 | 1384 | bundlecaps, version=cgversion) |
|
1385 | 1385 | if not cg: |
|
1386 | 1386 | scmutil.nochangesfound(ui, repo, outgoing and outgoing.excluded) |
|
1387 | 1387 | return 1 |
|
1388 | 1388 | |
|
1389 | 1389 | if cgversion == '01': #bundle1 |
|
1390 | 1390 | if bcompression is None: |
|
1391 | 1391 | bcompression = 'UN' |
|
1392 | 1392 | bversion = 'HG10' + bcompression |
|
1393 | 1393 | bcompression = None |
|
1394 | 1394 | else: |
|
1395 | 1395 | assert cgversion == '02' |
|
1396 | 1396 | bversion = 'HG20' |
|
1397 | 1397 | |
|
1398 | 1398 | |
|
1399 | 1399 | changegroup.writebundle(ui, cg, fname, bversion, compression=bcompression) |
|
1400 | 1400 | |
|
1401 | 1401 | @command('cat', |
|
1402 | 1402 | [('o', 'output', '', |
|
1403 | 1403 | _('print output to file with formatted name'), _('FORMAT')), |
|
1404 | 1404 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
1405 | 1405 | ('', 'decode', None, _('apply any matching decode filter')), |
|
1406 | 1406 | ] + walkopts, |
|
1407 | 1407 | _('[OPTION]... FILE...'), |
|
1408 | 1408 | inferrepo=True) |
|
1409 | 1409 | def cat(ui, repo, file1, *pats, **opts): |
|
1410 | 1410 | """output the current or given revision of files |
|
1411 | 1411 | |
|
1412 | 1412 | Print the specified files as they were at the given revision. If |
|
1413 | 1413 | no revision is given, the parent of the working directory is used. |
|
1414 | 1414 | |
|
1415 | 1415 | Output may be to a file, in which case the name of the file is |
|
1416 | 1416 | given using a format string. The formatting rules as follows: |
|
1417 | 1417 | |
|
1418 | 1418 | :``%%``: literal "%" character |
|
1419 | 1419 | :``%s``: basename of file being printed |
|
1420 | 1420 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1421 | 1421 | :``%p``: root-relative path name of file being printed |
|
1422 | 1422 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1423 | 1423 | :``%R``: changeset revision number |
|
1424 | 1424 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1425 | 1425 | :``%r``: zero-padded changeset revision number |
|
1426 | 1426 | :``%b``: basename of the exporting repository |
|
1427 | 1427 | |
|
1428 | 1428 | Returns 0 on success. |
|
1429 | 1429 | """ |
|
1430 | 1430 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1431 | 1431 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1432 | 1432 | |
|
1433 | 1433 | return cmdutil.cat(ui, repo, ctx, m, '', **opts) |
|
1434 | 1434 | |
|
1435 | 1435 | @command('^clone', |
|
1436 | 1436 | [('U', 'noupdate', None, _('the clone will include an empty working ' |
|
1437 | 1437 | 'directory (only a repository)')), |
|
1438 | 1438 | ('u', 'updaterev', '', _('revision, tag, or branch to check out'), |
|
1439 | 1439 | _('REV')), |
|
1440 | 1440 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), |
|
1441 | 1441 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), |
|
1442 | 1442 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1443 | 1443 | ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), |
|
1444 | 1444 | ] + remoteopts, |
|
1445 | 1445 | _('[OPTION]... SOURCE [DEST]'), |
|
1446 | 1446 | norepo=True) |
|
1447 | 1447 | def clone(ui, source, dest=None, **opts): |
|
1448 | 1448 | """make a copy of an existing repository |
|
1449 | 1449 | |
|
1450 | 1450 | Create a copy of an existing repository in a new directory. |
|
1451 | 1451 | |
|
1452 | 1452 | If no destination directory name is specified, it defaults to the |
|
1453 | 1453 | basename of the source. |
|
1454 | 1454 | |
|
1455 | 1455 | The location of the source is added to the new repository's |
|
1456 | 1456 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1457 | 1457 | |
|
1458 | 1458 | Only local paths and ``ssh://`` URLs are supported as |
|
1459 | 1459 | destinations. For ``ssh://`` destinations, no working directory or |
|
1460 | 1460 | ``.hg/hgrc`` will be created on the remote side. |
|
1461 | 1461 | |
|
1462 | 1462 | If the source repository has a bookmark called '@' set, that |
|
1463 | 1463 | revision will be checked out in the new repository by default. |
|
1464 | 1464 | |
|
1465 | 1465 | To check out a particular version, use -u/--update, or |
|
1466 | 1466 | -U/--noupdate to create a clone with no working directory. |
|
1467 | 1467 | |
|
1468 | 1468 | To pull only a subset of changesets, specify one or more revisions |
|
1469 | 1469 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1470 | 1470 | resulting clone will contain only the specified changesets and |
|
1471 | 1471 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1472 | 1472 | --pull, even for local source repositories. |
|
1473 | 1473 | |
|
1474 | 1474 | .. note:: |
|
1475 | 1475 | |
|
1476 | 1476 | Specifying a tag will include the tagged changeset but not the |
|
1477 | 1477 | changeset containing the tag. |
|
1478 | 1478 | |
|
1479 | 1479 | .. container:: verbose |
|
1480 | 1480 | |
|
1481 | 1481 | For efficiency, hardlinks are used for cloning whenever the |
|
1482 | 1482 | source and destination are on the same filesystem (note this |
|
1483 | 1483 | applies only to the repository data, not to the working |
|
1484 | 1484 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1485 | 1485 | incorrectly, but do not report errors. In these cases, use the |
|
1486 | 1486 | --pull option to avoid hardlinking. |
|
1487 | 1487 | |
|
1488 | 1488 | In some cases, you can clone repositories and the working |
|
1489 | 1489 | directory using full hardlinks with :: |
|
1490 | 1490 | |
|
1491 | 1491 | $ cp -al REPO REPOCLONE |
|
1492 | 1492 | |
|
1493 | 1493 | This is the fastest way to clone, but it is not always safe. The |
|
1494 | 1494 | operation is not atomic (making sure REPO is not modified during |
|
1495 | 1495 | the operation is up to you) and you have to make sure your |
|
1496 | 1496 | editor breaks hardlinks (Emacs and most Linux Kernel tools do |
|
1497 | 1497 | so). Also, this is not compatible with certain extensions that |
|
1498 | 1498 | place their metadata under the .hg directory, such as mq. |
|
1499 | 1499 | |
|
1500 | 1500 | Mercurial will update the working directory to the first applicable |
|
1501 | 1501 | revision from this list: |
|
1502 | 1502 | |
|
1503 | 1503 | a) null if -U or the source repository has no changesets |
|
1504 | 1504 | b) if -u . and the source repository is local, the first parent of |
|
1505 | 1505 | the source repository's working directory |
|
1506 | 1506 | c) the changeset specified with -u (if a branch name, this means the |
|
1507 | 1507 | latest head of that branch) |
|
1508 | 1508 | d) the changeset specified with -r |
|
1509 | 1509 | e) the tipmost head specified with -b |
|
1510 | 1510 | f) the tipmost head specified with the url#branch source syntax |
|
1511 | 1511 | g) the revision marked with the '@' bookmark, if present |
|
1512 | 1512 | h) the tipmost head of the default branch |
|
1513 | 1513 | i) tip |
|
1514 | 1514 | |
|
1515 | 1515 | When cloning from servers that support it, Mercurial may fetch |
|
1516 | 1516 | pre-generated data from a server-advertised URL. When this is done, |
|
1517 | 1517 | hooks operating on incoming changesets and changegroups may fire twice, |
|
1518 | 1518 | once for the bundle fetched from the URL and another for any additional |
|
1519 | 1519 | data not fetched from this URL. In addition, if an error occurs, the |
|
1520 | 1520 | repository may be rolled back to a partial clone. This behavior may |
|
1521 | 1521 | change in future releases. See :hg:`help -e clonebundles` for more. |
|
1522 | 1522 | |
|
1523 | 1523 | Examples: |
|
1524 | 1524 | |
|
1525 | 1525 | - clone a remote repository to a new directory named hg/:: |
|
1526 | 1526 | |
|
1527 | 1527 | hg clone http://selenic.com/hg |
|
1528 | 1528 | |
|
1529 | 1529 | - create a lightweight local clone:: |
|
1530 | 1530 | |
|
1531 | 1531 | hg clone project/ project-feature/ |
|
1532 | 1532 | |
|
1533 | 1533 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1534 | 1534 | |
|
1535 | 1535 | hg clone ssh://user@server//home/projects/alpha/ |
|
1536 | 1536 | |
|
1537 | 1537 | - do a high-speed clone over a LAN while checking out a |
|
1538 | 1538 | specified version:: |
|
1539 | 1539 | |
|
1540 | 1540 | hg clone --uncompressed http://server/repo -u 1.5 |
|
1541 | 1541 | |
|
1542 | 1542 | - create a repository without changesets after a particular revision:: |
|
1543 | 1543 | |
|
1544 | 1544 | hg clone -r 04e544 experimental/ good/ |
|
1545 | 1545 | |
|
1546 | 1546 | - clone (and track) a particular named branch:: |
|
1547 | 1547 | |
|
1548 | 1548 | hg clone http://selenic.com/hg#stable |
|
1549 | 1549 | |
|
1550 | 1550 | See :hg:`help urls` for details on specifying URLs. |
|
1551 | 1551 | |
|
1552 | 1552 | Returns 0 on success. |
|
1553 | 1553 | """ |
|
1554 | 1554 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1555 | 1555 | raise error.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1556 | 1556 | |
|
1557 | 1557 | r = hg.clone(ui, opts, source, dest, |
|
1558 | 1558 | pull=opts.get('pull'), |
|
1559 | 1559 | stream=opts.get('uncompressed'), |
|
1560 | 1560 | rev=opts.get('rev'), |
|
1561 | 1561 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1562 | 1562 | branch=opts.get('branch'), |
|
1563 | 1563 | shareopts=opts.get('shareopts')) |
|
1564 | 1564 | |
|
1565 | 1565 | return r is None |
|
1566 | 1566 | |
|
1567 | 1567 | @command('^commit|ci', |
|
1568 | 1568 | [('A', 'addremove', None, |
|
1569 | 1569 | _('mark new/missing files as added/removed before committing')), |
|
1570 | 1570 | ('', 'close-branch', None, |
|
1571 | 1571 | _('mark a branch head as closed')), |
|
1572 | 1572 | ('', 'amend', None, _('amend the parent of the working directory')), |
|
1573 | 1573 | ('s', 'secret', None, _('use the secret phase for committing')), |
|
1574 | 1574 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
1575 | 1575 | ('i', 'interactive', None, _('use interactive mode')), |
|
1576 | 1576 | ] + walkopts + commitopts + commitopts2 + subrepoopts, |
|
1577 | 1577 | _('[OPTION]... [FILE]...'), |
|
1578 | 1578 | inferrepo=True) |
|
1579 | 1579 | def commit(ui, repo, *pats, **opts): |
|
1580 | 1580 | """commit the specified files or all outstanding changes |
|
1581 | 1581 | |
|
1582 | 1582 | Commit changes to the given files into the repository. Unlike a |
|
1583 | 1583 | centralized SCM, this operation is a local operation. See |
|
1584 | 1584 | :hg:`push` for a way to actively distribute your changes. |
|
1585 | 1585 | |
|
1586 | 1586 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1587 | 1587 | will be committed. |
|
1588 | 1588 | |
|
1589 | 1589 | If you are committing the result of a merge, do not provide any |
|
1590 | 1590 | filenames or -I/-X filters. |
|
1591 | 1591 | |
|
1592 | 1592 | If no commit message is specified, Mercurial starts your |
|
1593 | 1593 | configured editor where you can enter a message. In case your |
|
1594 | 1594 | commit fails, you will find a backup of your message in |
|
1595 | 1595 | ``.hg/last-message.txt``. |
|
1596 | 1596 | |
|
1597 | 1597 | The --close-branch flag can be used to mark the current branch |
|
1598 | 1598 | head closed. When all heads of a branch are closed, the branch |
|
1599 | 1599 | will be considered closed and no longer listed. |
|
1600 | 1600 | |
|
1601 | 1601 | The --amend flag can be used to amend the parent of the |
|
1602 | 1602 | working directory with a new commit that contains the changes |
|
1603 | 1603 | in the parent in addition to those currently reported by :hg:`status`, |
|
1604 | 1604 | if there are any. The old commit is stored in a backup bundle in |
|
1605 | 1605 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` |
|
1606 | 1606 | on how to restore it). |
|
1607 | 1607 | |
|
1608 | 1608 | Message, user and date are taken from the amended commit unless |
|
1609 | 1609 | specified. When a message isn't specified on the command line, |
|
1610 | 1610 | the editor will open with the message of the amended commit. |
|
1611 | 1611 | |
|
1612 | 1612 | It is not possible to amend public changesets (see :hg:`help phases`) |
|
1613 | 1613 | or changesets that have children. |
|
1614 | 1614 | |
|
1615 | 1615 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1616 | 1616 | |
|
1617 | 1617 | Returns 0 on success, 1 if nothing changed. |
|
1618 | 1618 | |
|
1619 | 1619 | .. container:: verbose |
|
1620 | 1620 | |
|
1621 | 1621 | Examples: |
|
1622 | 1622 | |
|
1623 | 1623 | - commit all files ending in .py:: |
|
1624 | 1624 | |
|
1625 | 1625 | hg commit --include "set:**.py" |
|
1626 | 1626 | |
|
1627 | 1627 | - commit all non-binary files:: |
|
1628 | 1628 | |
|
1629 | 1629 | hg commit --exclude "set:binary()" |
|
1630 | 1630 | |
|
1631 | 1631 | - amend the current commit and set the date to now:: |
|
1632 | 1632 | |
|
1633 | 1633 | hg commit --amend --date now |
|
1634 | 1634 | """ |
|
1635 | 1635 | wlock = lock = None |
|
1636 | 1636 | try: |
|
1637 | 1637 | wlock = repo.wlock() |
|
1638 | 1638 | lock = repo.lock() |
|
1639 | 1639 | return _docommit(ui, repo, *pats, **opts) |
|
1640 | 1640 | finally: |
|
1641 | 1641 | release(lock, wlock) |
|
1642 | 1642 | |
|
1643 | 1643 | def _docommit(ui, repo, *pats, **opts): |
|
1644 | 1644 | if opts.get('interactive'): |
|
1645 | 1645 | opts.pop('interactive') |
|
1646 | 1646 | cmdutil.dorecord(ui, repo, commit, None, False, |
|
1647 | 1647 | cmdutil.recordfilter, *pats, **opts) |
|
1648 | 1648 | return |
|
1649 | 1649 | |
|
1650 | 1650 | if opts.get('subrepos'): |
|
1651 | 1651 | if opts.get('amend'): |
|
1652 | 1652 | raise error.Abort(_('cannot amend with --subrepos')) |
|
1653 | 1653 | # Let --subrepos on the command line override config setting. |
|
1654 | 1654 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') |
|
1655 | 1655 | |
|
1656 | 1656 | cmdutil.checkunfinished(repo, commit=True) |
|
1657 | 1657 | |
|
1658 | 1658 | branch = repo[None].branch() |
|
1659 | 1659 | bheads = repo.branchheads(branch) |
|
1660 | 1660 | |
|
1661 | 1661 | extra = {} |
|
1662 | 1662 | if opts.get('close_branch'): |
|
1663 | 1663 | extra['close'] = 1 |
|
1664 | 1664 | |
|
1665 | 1665 | if not bheads: |
|
1666 | 1666 | raise error.Abort(_('can only close branch heads')) |
|
1667 | 1667 | elif opts.get('amend'): |
|
1668 | 1668 | if repo[None].parents()[0].p1().branch() != branch and \ |
|
1669 | 1669 | repo[None].parents()[0].p2().branch() != branch: |
|
1670 | 1670 | raise error.Abort(_('can only close branch heads')) |
|
1671 | 1671 | |
|
1672 | 1672 | if opts.get('amend'): |
|
1673 | 1673 | if ui.configbool('ui', 'commitsubrepos'): |
|
1674 | 1674 | raise error.Abort(_('cannot amend with ui.commitsubrepos enabled')) |
|
1675 | 1675 | |
|
1676 | 1676 | old = repo['.'] |
|
1677 | 1677 | if not old.mutable(): |
|
1678 | 1678 | raise error.Abort(_('cannot amend public changesets')) |
|
1679 | 1679 | if len(repo[None].parents()) > 1: |
|
1680 | 1680 | raise error.Abort(_('cannot amend while merging')) |
|
1681 | 1681 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
|
1682 | 1682 | if not allowunstable and old.children(): |
|
1683 | 1683 | raise error.Abort(_('cannot amend changeset with children')) |
|
1684 | 1684 | |
|
1685 | newextra = extra.copy() | |
|
1686 | newextra['branch'] = branch | |
|
1687 | extra = newextra | |
|
1688 | 1685 | # commitfunc is used only for temporary amend commit by cmdutil.amend |
|
1689 | 1686 | def commitfunc(ui, repo, message, match, opts): |
|
1690 | 1687 | return repo.commit(message, |
|
1691 | 1688 | opts.get('user') or old.user(), |
|
1692 | 1689 | opts.get('date') or old.date(), |
|
1693 | 1690 | match, |
|
1694 | 1691 | extra=extra) |
|
1695 | 1692 | |
|
1696 | 1693 | node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) |
|
1697 | 1694 | if node == old.node(): |
|
1698 | 1695 | ui.status(_("nothing changed\n")) |
|
1699 | 1696 | return 1 |
|
1700 | 1697 | else: |
|
1701 | 1698 | def commitfunc(ui, repo, message, match, opts): |
|
1702 | 1699 | backup = ui.backupconfig('phases', 'new-commit') |
|
1703 | 1700 | baseui = repo.baseui |
|
1704 | 1701 | basebackup = baseui.backupconfig('phases', 'new-commit') |
|
1705 | 1702 | try: |
|
1706 | 1703 | if opts.get('secret'): |
|
1707 | 1704 | ui.setconfig('phases', 'new-commit', 'secret', 'commit') |
|
1708 | 1705 | # Propagate to subrepos |
|
1709 | 1706 | baseui.setconfig('phases', 'new-commit', 'secret', 'commit') |
|
1710 | 1707 | |
|
1711 | 1708 | editform = cmdutil.mergeeditform(repo[None], 'commit.normal') |
|
1712 | 1709 | editor = cmdutil.getcommiteditor(editform=editform, **opts) |
|
1713 | 1710 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
1714 | 1711 | match, |
|
1715 | 1712 | editor=editor, |
|
1716 | 1713 | extra=extra) |
|
1717 | 1714 | finally: |
|
1718 | 1715 | ui.restoreconfig(backup) |
|
1719 | 1716 | repo.baseui.restoreconfig(basebackup) |
|
1720 | 1717 | |
|
1721 | 1718 | |
|
1722 | 1719 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1723 | 1720 | |
|
1724 | 1721 | if not node: |
|
1725 | 1722 | stat = cmdutil.postcommitstatus(repo, pats, opts) |
|
1726 | 1723 | if stat[3]: |
|
1727 | 1724 | ui.status(_("nothing changed (%d missing files, see " |
|
1728 | 1725 | "'hg status')\n") % len(stat[3])) |
|
1729 | 1726 | else: |
|
1730 | 1727 | ui.status(_("nothing changed\n")) |
|
1731 | 1728 | return 1 |
|
1732 | 1729 | |
|
1733 | 1730 | cmdutil.commitstatus(repo, node, branch, bheads, opts) |
|
1734 | 1731 | |
|
1735 | 1732 | @command('config|showconfig|debugconfig', |
|
1736 | 1733 | [('u', 'untrusted', None, _('show untrusted configuration options')), |
|
1737 | 1734 | ('e', 'edit', None, _('edit user config')), |
|
1738 | 1735 | ('l', 'local', None, _('edit repository config')), |
|
1739 | 1736 | ('g', 'global', None, _('edit global config'))], |
|
1740 | 1737 | _('[-u] [NAME]...'), |
|
1741 | 1738 | optionalrepo=True) |
|
1742 | 1739 | def config(ui, repo, *values, **opts): |
|
1743 | 1740 | """show combined config settings from all hgrc files |
|
1744 | 1741 | |
|
1745 | 1742 | With no arguments, print names and values of all config items. |
|
1746 | 1743 | |
|
1747 | 1744 | With one argument of the form section.name, print just the value |
|
1748 | 1745 | of that config item. |
|
1749 | 1746 | |
|
1750 | 1747 | With multiple arguments, print names and values of all config |
|
1751 | 1748 | items with matching section names. |
|
1752 | 1749 | |
|
1753 | 1750 | With --edit, start an editor on the user-level config file. With |
|
1754 | 1751 | --global, edit the system-wide config file. With --local, edit the |
|
1755 | 1752 | repository-level config file. |
|
1756 | 1753 | |
|
1757 | 1754 | With --debug, the source (filename and line number) is printed |
|
1758 | 1755 | for each config item. |
|
1759 | 1756 | |
|
1760 | 1757 | See :hg:`help config` for more information about config files. |
|
1761 | 1758 | |
|
1762 | 1759 | Returns 0 on success, 1 if NAME does not exist. |
|
1763 | 1760 | |
|
1764 | 1761 | """ |
|
1765 | 1762 | |
|
1766 | 1763 | if opts.get('edit') or opts.get('local') or opts.get('global'): |
|
1767 | 1764 | if opts.get('local') and opts.get('global'): |
|
1768 | 1765 | raise error.Abort(_("can't use --local and --global together")) |
|
1769 | 1766 | |
|
1770 | 1767 | if opts.get('local'): |
|
1771 | 1768 | if not repo: |
|
1772 | 1769 | raise error.Abort(_("can't use --local outside a repository")) |
|
1773 | 1770 | paths = [repo.join('hgrc')] |
|
1774 | 1771 | elif opts.get('global'): |
|
1775 | 1772 | paths = scmutil.systemrcpath() |
|
1776 | 1773 | else: |
|
1777 | 1774 | paths = scmutil.userrcpath() |
|
1778 | 1775 | |
|
1779 | 1776 | for f in paths: |
|
1780 | 1777 | if os.path.exists(f): |
|
1781 | 1778 | break |
|
1782 | 1779 | else: |
|
1783 | 1780 | if opts.get('global'): |
|
1784 | 1781 | samplehgrc = uimod.samplehgrcs['global'] |
|
1785 | 1782 | elif opts.get('local'): |
|
1786 | 1783 | samplehgrc = uimod.samplehgrcs['local'] |
|
1787 | 1784 | else: |
|
1788 | 1785 | samplehgrc = uimod.samplehgrcs['user'] |
|
1789 | 1786 | |
|
1790 | 1787 | f = paths[0] |
|
1791 | 1788 | fp = open(f, "w") |
|
1792 | 1789 | fp.write(samplehgrc) |
|
1793 | 1790 | fp.close() |
|
1794 | 1791 | |
|
1795 | 1792 | editor = ui.geteditor() |
|
1796 | 1793 | ui.system("%s \"%s\"" % (editor, f), |
|
1797 | 1794 | onerr=error.Abort, errprefix=_("edit failed")) |
|
1798 | 1795 | return |
|
1799 | 1796 | |
|
1800 | 1797 | for f in scmutil.rcpath(): |
|
1801 | 1798 | ui.debug('read config from: %s\n' % f) |
|
1802 | 1799 | untrusted = bool(opts.get('untrusted')) |
|
1803 | 1800 | if values: |
|
1804 | 1801 | sections = [v for v in values if '.' not in v] |
|
1805 | 1802 | items = [v for v in values if '.' in v] |
|
1806 | 1803 | if len(items) > 1 or items and sections: |
|
1807 | 1804 | raise error.Abort(_('only one config item permitted')) |
|
1808 | 1805 | matched = False |
|
1809 | 1806 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
1810 | 1807 | value = str(value).replace('\n', '\\n') |
|
1811 | 1808 | sectname = section + '.' + name |
|
1812 | 1809 | if values: |
|
1813 | 1810 | for v in values: |
|
1814 | 1811 | if v == section: |
|
1815 | 1812 | ui.debug('%s: ' % |
|
1816 | 1813 | ui.configsource(section, name, untrusted)) |
|
1817 | 1814 | ui.write('%s=%s\n' % (sectname, value)) |
|
1818 | 1815 | matched = True |
|
1819 | 1816 | elif v == sectname: |
|
1820 | 1817 | ui.debug('%s: ' % |
|
1821 | 1818 | ui.configsource(section, name, untrusted)) |
|
1822 | 1819 | ui.write(value, '\n') |
|
1823 | 1820 | matched = True |
|
1824 | 1821 | else: |
|
1825 | 1822 | ui.debug('%s: ' % |
|
1826 | 1823 | ui.configsource(section, name, untrusted)) |
|
1827 | 1824 | ui.write('%s=%s\n' % (sectname, value)) |
|
1828 | 1825 | matched = True |
|
1829 | 1826 | if matched: |
|
1830 | 1827 | return 0 |
|
1831 | 1828 | return 1 |
|
1832 | 1829 | |
|
1833 | 1830 | @command('copy|cp', |
|
1834 | 1831 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1835 | 1832 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1836 | 1833 | ] + walkopts + dryrunopts, |
|
1837 | 1834 | _('[OPTION]... [SOURCE]... DEST')) |
|
1838 | 1835 | def copy(ui, repo, *pats, **opts): |
|
1839 | 1836 | """mark files as copied for the next commit |
|
1840 | 1837 | |
|
1841 | 1838 | Mark dest as having copies of source files. If dest is a |
|
1842 | 1839 | directory, copies are put in that directory. If dest is a file, |
|
1843 | 1840 | the source must be a single file. |
|
1844 | 1841 | |
|
1845 | 1842 | By default, this command copies the contents of files as they |
|
1846 | 1843 | exist in the working directory. If invoked with -A/--after, the |
|
1847 | 1844 | operation is recorded, but no copying is performed. |
|
1848 | 1845 | |
|
1849 | 1846 | This command takes effect with the next commit. To undo a copy |
|
1850 | 1847 | before that, see :hg:`revert`. |
|
1851 | 1848 | |
|
1852 | 1849 | Returns 0 on success, 1 if errors are encountered. |
|
1853 | 1850 | """ |
|
1854 | 1851 | with repo.wlock(False): |
|
1855 | 1852 | return cmdutil.copy(ui, repo, pats, opts) |
|
1856 | 1853 | |
|
1857 | 1854 | @command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True) |
|
1858 | 1855 | def debugancestor(ui, repo, *args): |
|
1859 | 1856 | """find the ancestor revision of two revisions in a given index""" |
|
1860 | 1857 | if len(args) == 3: |
|
1861 | 1858 | index, rev1, rev2 = args |
|
1862 | 1859 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) |
|
1863 | 1860 | lookup = r.lookup |
|
1864 | 1861 | elif len(args) == 2: |
|
1865 | 1862 | if not repo: |
|
1866 | 1863 | raise error.Abort(_("there is no Mercurial repository here " |
|
1867 | 1864 | "(.hg not found)")) |
|
1868 | 1865 | rev1, rev2 = args |
|
1869 | 1866 | r = repo.changelog |
|
1870 | 1867 | lookup = repo.lookup |
|
1871 | 1868 | else: |
|
1872 | 1869 | raise error.Abort(_('either two or three arguments required')) |
|
1873 | 1870 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
1874 | 1871 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1875 | 1872 | |
|
1876 | 1873 | @command('debugbuilddag', |
|
1877 | 1874 | [('m', 'mergeable-file', None, _('add single file mergeable changes')), |
|
1878 | 1875 | ('o', 'overwritten-file', None, _('add single file all revs overwrite')), |
|
1879 | 1876 | ('n', 'new-file', None, _('add new file at each rev'))], |
|
1880 | 1877 | _('[OPTION]... [TEXT]')) |
|
1881 | 1878 | def debugbuilddag(ui, repo, text=None, |
|
1882 | 1879 | mergeable_file=False, |
|
1883 | 1880 | overwritten_file=False, |
|
1884 | 1881 | new_file=False): |
|
1885 | 1882 | """builds a repo with a given DAG from scratch in the current empty repo |
|
1886 | 1883 | |
|
1887 | 1884 | The description of the DAG is read from stdin if not given on the |
|
1888 | 1885 | command line. |
|
1889 | 1886 | |
|
1890 | 1887 | Elements: |
|
1891 | 1888 | |
|
1892 | 1889 | - "+n" is a linear run of n nodes based on the current default parent |
|
1893 | 1890 | - "." is a single node based on the current default parent |
|
1894 | 1891 | - "$" resets the default parent to null (implied at the start); |
|
1895 | 1892 | otherwise the default parent is always the last node created |
|
1896 | 1893 | - "<p" sets the default parent to the backref p |
|
1897 | 1894 | - "*p" is a fork at parent p, which is a backref |
|
1898 | 1895 | - "*p1/p2" is a merge of parents p1 and p2, which are backrefs |
|
1899 | 1896 | - "/p2" is a merge of the preceding node and p2 |
|
1900 | 1897 | - ":tag" defines a local tag for the preceding node |
|
1901 | 1898 | - "@branch" sets the named branch for subsequent nodes |
|
1902 | 1899 | - "#...\\n" is a comment up to the end of the line |
|
1903 | 1900 | |
|
1904 | 1901 | Whitespace between the above elements is ignored. |
|
1905 | 1902 | |
|
1906 | 1903 | A backref is either |
|
1907 | 1904 | |
|
1908 | 1905 | - a number n, which references the node curr-n, where curr is the current |
|
1909 | 1906 | node, or |
|
1910 | 1907 | - the name of a local tag you placed earlier using ":tag", or |
|
1911 | 1908 | - empty to denote the default parent. |
|
1912 | 1909 | |
|
1913 | 1910 | All string valued-elements are either strictly alphanumeric, or must |
|
1914 | 1911 | be enclosed in double quotes ("..."), with "\\" as escape character. |
|
1915 | 1912 | """ |
|
1916 | 1913 | |
|
1917 | 1914 | if text is None: |
|
1918 | 1915 | ui.status(_("reading DAG from stdin\n")) |
|
1919 | 1916 | text = ui.fin.read() |
|
1920 | 1917 | |
|
1921 | 1918 | cl = repo.changelog |
|
1922 | 1919 | if len(cl) > 0: |
|
1923 | 1920 | raise error.Abort(_('repository is not empty')) |
|
1924 | 1921 | |
|
1925 | 1922 | # determine number of revs in DAG |
|
1926 | 1923 | total = 0 |
|
1927 | 1924 | for type, data in dagparser.parsedag(text): |
|
1928 | 1925 | if type == 'n': |
|
1929 | 1926 | total += 1 |
|
1930 | 1927 | |
|
1931 | 1928 | if mergeable_file: |
|
1932 | 1929 | linesperrev = 2 |
|
1933 | 1930 | # make a file with k lines per rev |
|
1934 | 1931 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] |
|
1935 | 1932 | initialmergedlines.append("") |
|
1936 | 1933 | |
|
1937 | 1934 | tags = [] |
|
1938 | 1935 | |
|
1939 | 1936 | lock = tr = None |
|
1940 | 1937 | try: |
|
1941 | 1938 | lock = repo.lock() |
|
1942 | 1939 | tr = repo.transaction("builddag") |
|
1943 | 1940 | |
|
1944 | 1941 | at = -1 |
|
1945 | 1942 | atbranch = 'default' |
|
1946 | 1943 | nodeids = [] |
|
1947 | 1944 | id = 0 |
|
1948 | 1945 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1949 | 1946 | for type, data in dagparser.parsedag(text): |
|
1950 | 1947 | if type == 'n': |
|
1951 | 1948 | ui.note(('node %s\n' % str(data))) |
|
1952 | 1949 | id, ps = data |
|
1953 | 1950 | |
|
1954 | 1951 | files = [] |
|
1955 | 1952 | fctxs = {} |
|
1956 | 1953 | |
|
1957 | 1954 | p2 = None |
|
1958 | 1955 | if mergeable_file: |
|
1959 | 1956 | fn = "mf" |
|
1960 | 1957 | p1 = repo[ps[0]] |
|
1961 | 1958 | if len(ps) > 1: |
|
1962 | 1959 | p2 = repo[ps[1]] |
|
1963 | 1960 | pa = p1.ancestor(p2) |
|
1964 | 1961 | base, local, other = [x[fn].data() for x in (pa, p1, |
|
1965 | 1962 | p2)] |
|
1966 | 1963 | m3 = simplemerge.Merge3Text(base, local, other) |
|
1967 | 1964 | ml = [l.strip() for l in m3.merge_lines()] |
|
1968 | 1965 | ml.append("") |
|
1969 | 1966 | elif at > 0: |
|
1970 | 1967 | ml = p1[fn].data().split("\n") |
|
1971 | 1968 | else: |
|
1972 | 1969 | ml = initialmergedlines |
|
1973 | 1970 | ml[id * linesperrev] += " r%i" % id |
|
1974 | 1971 | mergedtext = "\n".join(ml) |
|
1975 | 1972 | files.append(fn) |
|
1976 | 1973 | fctxs[fn] = context.memfilectx(repo, fn, mergedtext) |
|
1977 | 1974 | |
|
1978 | 1975 | if overwritten_file: |
|
1979 | 1976 | fn = "of" |
|
1980 | 1977 | files.append(fn) |
|
1981 | 1978 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) |
|
1982 | 1979 | |
|
1983 | 1980 | if new_file: |
|
1984 | 1981 | fn = "nf%i" % id |
|
1985 | 1982 | files.append(fn) |
|
1986 | 1983 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) |
|
1987 | 1984 | if len(ps) > 1: |
|
1988 | 1985 | if not p2: |
|
1989 | 1986 | p2 = repo[ps[1]] |
|
1990 | 1987 | for fn in p2: |
|
1991 | 1988 | if fn.startswith("nf"): |
|
1992 | 1989 | files.append(fn) |
|
1993 | 1990 | fctxs[fn] = p2[fn] |
|
1994 | 1991 | |
|
1995 | 1992 | def fctxfn(repo, cx, path): |
|
1996 | 1993 | return fctxs.get(path) |
|
1997 | 1994 | |
|
1998 | 1995 | if len(ps) == 0 or ps[0] < 0: |
|
1999 | 1996 | pars = [None, None] |
|
2000 | 1997 | elif len(ps) == 1: |
|
2001 | 1998 | pars = [nodeids[ps[0]], None] |
|
2002 | 1999 | else: |
|
2003 | 2000 | pars = [nodeids[p] for p in ps] |
|
2004 | 2001 | cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, |
|
2005 | 2002 | date=(id, 0), |
|
2006 | 2003 | user="debugbuilddag", |
|
2007 | 2004 | extra={'branch': atbranch}) |
|
2008 | 2005 | nodeid = repo.commitctx(cx) |
|
2009 | 2006 | nodeids.append(nodeid) |
|
2010 | 2007 | at = id |
|
2011 | 2008 | elif type == 'l': |
|
2012 | 2009 | id, name = data |
|
2013 | 2010 | ui.note(('tag %s\n' % name)) |
|
2014 | 2011 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) |
|
2015 | 2012 | elif type == 'a': |
|
2016 | 2013 | ui.note(('branch %s\n' % data)) |
|
2017 | 2014 | atbranch = data |
|
2018 | 2015 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
2019 | 2016 | tr.close() |
|
2020 | 2017 | |
|
2021 | 2018 | if tags: |
|
2022 | 2019 | repo.vfs.write("localtags", "".join(tags)) |
|
2023 | 2020 | finally: |
|
2024 | 2021 | ui.progress(_('building'), None) |
|
2025 | 2022 | release(tr, lock) |
|
2026 | 2023 | |
|
2027 | 2024 | @command('debugbundle', |
|
2028 | 2025 | [('a', 'all', None, _('show all details')), |
|
2029 | 2026 | ('', 'spec', None, _('print the bundlespec of the bundle'))], |
|
2030 | 2027 | _('FILE'), |
|
2031 | 2028 | norepo=True) |
|
2032 | 2029 | def debugbundle(ui, bundlepath, all=None, spec=None, **opts): |
|
2033 | 2030 | """lists the contents of a bundle""" |
|
2034 | 2031 | with hg.openpath(ui, bundlepath) as f: |
|
2035 | 2032 | if spec: |
|
2036 | 2033 | spec = exchange.getbundlespec(ui, f) |
|
2037 | 2034 | ui.write('%s\n' % spec) |
|
2038 | 2035 | return |
|
2039 | 2036 | |
|
2040 | 2037 | gen = exchange.readbundle(ui, f, bundlepath) |
|
2041 | 2038 | if isinstance(gen, bundle2.unbundle20): |
|
2042 | 2039 | return _debugbundle2(ui, gen, all=all, **opts) |
|
2043 | 2040 | if all: |
|
2044 | 2041 | ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n")) |
|
2045 | 2042 | |
|
2046 | 2043 | def showchunks(named): |
|
2047 | 2044 | ui.write("\n%s\n" % named) |
|
2048 | 2045 | chain = None |
|
2049 | 2046 | while True: |
|
2050 | 2047 | chunkdata = gen.deltachunk(chain) |
|
2051 | 2048 | if not chunkdata: |
|
2052 | 2049 | break |
|
2053 | 2050 | node = chunkdata['node'] |
|
2054 | 2051 | p1 = chunkdata['p1'] |
|
2055 | 2052 | p2 = chunkdata['p2'] |
|
2056 | 2053 | cs = chunkdata['cs'] |
|
2057 | 2054 | deltabase = chunkdata['deltabase'] |
|
2058 | 2055 | delta = chunkdata['delta'] |
|
2059 | 2056 | ui.write("%s %s %s %s %s %s\n" % |
|
2060 | 2057 | (hex(node), hex(p1), hex(p2), |
|
2061 | 2058 | hex(cs), hex(deltabase), len(delta))) |
|
2062 | 2059 | chain = node |
|
2063 | 2060 | |
|
2064 | 2061 | chunkdata = gen.changelogheader() |
|
2065 | 2062 | showchunks("changelog") |
|
2066 | 2063 | chunkdata = gen.manifestheader() |
|
2067 | 2064 | showchunks("manifest") |
|
2068 | 2065 | while True: |
|
2069 | 2066 | chunkdata = gen.filelogheader() |
|
2070 | 2067 | if not chunkdata: |
|
2071 | 2068 | break |
|
2072 | 2069 | fname = chunkdata['filename'] |
|
2073 | 2070 | showchunks(fname) |
|
2074 | 2071 | else: |
|
2075 | 2072 | if isinstance(gen, bundle2.unbundle20): |
|
2076 | 2073 | raise error.Abort(_('use debugbundle2 for this file')) |
|
2077 | 2074 | chunkdata = gen.changelogheader() |
|
2078 | 2075 | chain = None |
|
2079 | 2076 | while True: |
|
2080 | 2077 | chunkdata = gen.deltachunk(chain) |
|
2081 | 2078 | if not chunkdata: |
|
2082 | 2079 | break |
|
2083 | 2080 | node = chunkdata['node'] |
|
2084 | 2081 | ui.write("%s\n" % hex(node)) |
|
2085 | 2082 | chain = node |
|
2086 | 2083 | |
|
2087 | 2084 | def _debugbundle2(ui, gen, **opts): |
|
2088 | 2085 | """lists the contents of a bundle2""" |
|
2089 | 2086 | if not isinstance(gen, bundle2.unbundle20): |
|
2090 | 2087 | raise error.Abort(_('not a bundle2 file')) |
|
2091 | 2088 | ui.write(('Stream params: %s\n' % repr(gen.params))) |
|
2092 | 2089 | for part in gen.iterparts(): |
|
2093 | 2090 | ui.write('%s -- %r\n' % (part.type, repr(part.params))) |
|
2094 | 2091 | if part.type == 'changegroup': |
|
2095 | 2092 | version = part.params.get('version', '01') |
|
2096 | 2093 | cg = changegroup.getunbundler(version, part, 'UN') |
|
2097 | 2094 | chunkdata = cg.changelogheader() |
|
2098 | 2095 | chain = None |
|
2099 | 2096 | while True: |
|
2100 | 2097 | chunkdata = cg.deltachunk(chain) |
|
2101 | 2098 | if not chunkdata: |
|
2102 | 2099 | break |
|
2103 | 2100 | node = chunkdata['node'] |
|
2104 | 2101 | ui.write(" %s\n" % hex(node)) |
|
2105 | 2102 | chain = node |
|
2106 | 2103 | |
|
2107 | 2104 | @command('debugcreatestreamclonebundle', [], 'FILE') |
|
2108 | 2105 | def debugcreatestreamclonebundle(ui, repo, fname): |
|
2109 | 2106 | """create a stream clone bundle file |
|
2110 | 2107 | |
|
2111 | 2108 | Stream bundles are special bundles that are essentially archives of |
|
2112 | 2109 | revlog files. They are commonly used for cloning very quickly. |
|
2113 | 2110 | """ |
|
2114 | 2111 | requirements, gen = streamclone.generatebundlev1(repo) |
|
2115 | 2112 | changegroup.writechunks(ui, gen, fname) |
|
2116 | 2113 | |
|
2117 | 2114 | ui.write(_('bundle requirements: %s\n') % ', '.join(sorted(requirements))) |
|
2118 | 2115 | |
|
2119 | 2116 | @command('debugapplystreamclonebundle', [], 'FILE') |
|
2120 | 2117 | def debugapplystreamclonebundle(ui, repo, fname): |
|
2121 | 2118 | """apply a stream clone bundle file""" |
|
2122 | 2119 | f = hg.openpath(ui, fname) |
|
2123 | 2120 | gen = exchange.readbundle(ui, f, fname) |
|
2124 | 2121 | gen.apply(repo) |
|
2125 | 2122 | |
|
2126 | 2123 | @command('debugcheckstate', [], '') |
|
2127 | 2124 | def debugcheckstate(ui, repo): |
|
2128 | 2125 | """validate the correctness of the current dirstate""" |
|
2129 | 2126 | parent1, parent2 = repo.dirstate.parents() |
|
2130 | 2127 | m1 = repo[parent1].manifest() |
|
2131 | 2128 | m2 = repo[parent2].manifest() |
|
2132 | 2129 | errors = 0 |
|
2133 | 2130 | for f in repo.dirstate: |
|
2134 | 2131 | state = repo.dirstate[f] |
|
2135 | 2132 | if state in "nr" and f not in m1: |
|
2136 | 2133 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
2137 | 2134 | errors += 1 |
|
2138 | 2135 | if state in "a" and f in m1: |
|
2139 | 2136 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
2140 | 2137 | errors += 1 |
|
2141 | 2138 | if state in "m" and f not in m1 and f not in m2: |
|
2142 | 2139 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
2143 | 2140 | (f, state)) |
|
2144 | 2141 | errors += 1 |
|
2145 | 2142 | for f in m1: |
|
2146 | 2143 | state = repo.dirstate[f] |
|
2147 | 2144 | if state not in "nrm": |
|
2148 | 2145 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
2149 | 2146 | errors += 1 |
|
2150 | 2147 | if errors: |
|
2151 | 2148 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
2152 | 2149 | raise error.Abort(error) |
|
2153 | 2150 | |
|
2154 | 2151 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) |
|
2155 | 2152 | def debugcommands(ui, cmd='', *args): |
|
2156 | 2153 | """list all available commands and options""" |
|
2157 | 2154 | for cmd, vals in sorted(table.iteritems()): |
|
2158 | 2155 | cmd = cmd.split('|')[0].strip('^') |
|
2159 | 2156 | opts = ', '.join([i[1] for i in vals[1]]) |
|
2160 | 2157 | ui.write('%s: %s\n' % (cmd, opts)) |
|
2161 | 2158 | |
|
2162 | 2159 | @command('debugcomplete', |
|
2163 | 2160 | [('o', 'options', None, _('show the command options'))], |
|
2164 | 2161 | _('[-o] CMD'), |
|
2165 | 2162 | norepo=True) |
|
2166 | 2163 | def debugcomplete(ui, cmd='', **opts): |
|
2167 | 2164 | """returns the completion list associated with the given command""" |
|
2168 | 2165 | |
|
2169 | 2166 | if opts.get('options'): |
|
2170 | 2167 | options = [] |
|
2171 | 2168 | otables = [globalopts] |
|
2172 | 2169 | if cmd: |
|
2173 | 2170 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
2174 | 2171 | otables.append(entry[1]) |
|
2175 | 2172 | for t in otables: |
|
2176 | 2173 | for o in t: |
|
2177 | 2174 | if "(DEPRECATED)" in o[3]: |
|
2178 | 2175 | continue |
|
2179 | 2176 | if o[0]: |
|
2180 | 2177 | options.append('-%s' % o[0]) |
|
2181 | 2178 | options.append('--%s' % o[1]) |
|
2182 | 2179 | ui.write("%s\n" % "\n".join(options)) |
|
2183 | 2180 | return |
|
2184 | 2181 | |
|
2185 | 2182 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) |
|
2186 | 2183 | if ui.verbose: |
|
2187 | 2184 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
2188 | 2185 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
2189 | 2186 | |
|
2190 | 2187 | @command('debugdag', |
|
2191 | 2188 | [('t', 'tags', None, _('use tags as labels')), |
|
2192 | 2189 | ('b', 'branches', None, _('annotate with branch names')), |
|
2193 | 2190 | ('', 'dots', None, _('use dots for runs')), |
|
2194 | 2191 | ('s', 'spaces', None, _('separate elements by spaces'))], |
|
2195 | 2192 | _('[OPTION]... [FILE [REV]...]'), |
|
2196 | 2193 | optionalrepo=True) |
|
2197 | 2194 | def debugdag(ui, repo, file_=None, *revs, **opts): |
|
2198 | 2195 | """format the changelog or an index DAG as a concise textual description |
|
2199 | 2196 | |
|
2200 | 2197 | If you pass a revlog index, the revlog's DAG is emitted. If you list |
|
2201 | 2198 | revision numbers, they get labeled in the output as rN. |
|
2202 | 2199 | |
|
2203 | 2200 | Otherwise, the changelog DAG of the current repo is emitted. |
|
2204 | 2201 | """ |
|
2205 | 2202 | spaces = opts.get('spaces') |
|
2206 | 2203 | dots = opts.get('dots') |
|
2207 | 2204 | if file_: |
|
2208 | 2205 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
2209 | 2206 | revs = set((int(r) for r in revs)) |
|
2210 | 2207 | def events(): |
|
2211 | 2208 | for r in rlog: |
|
2212 | 2209 | yield 'n', (r, list(p for p in rlog.parentrevs(r) |
|
2213 | 2210 | if p != -1)) |
|
2214 | 2211 | if r in revs: |
|
2215 | 2212 | yield 'l', (r, "r%i" % r) |
|
2216 | 2213 | elif repo: |
|
2217 | 2214 | cl = repo.changelog |
|
2218 | 2215 | tags = opts.get('tags') |
|
2219 | 2216 | branches = opts.get('branches') |
|
2220 | 2217 | if tags: |
|
2221 | 2218 | labels = {} |
|
2222 | 2219 | for l, n in repo.tags().items(): |
|
2223 | 2220 | labels.setdefault(cl.rev(n), []).append(l) |
|
2224 | 2221 | def events(): |
|
2225 | 2222 | b = "default" |
|
2226 | 2223 | for r in cl: |
|
2227 | 2224 | if branches: |
|
2228 | 2225 | newb = cl.read(cl.node(r))[5]['branch'] |
|
2229 | 2226 | if newb != b: |
|
2230 | 2227 | yield 'a', newb |
|
2231 | 2228 | b = newb |
|
2232 | 2229 | yield 'n', (r, list(p for p in cl.parentrevs(r) |
|
2233 | 2230 | if p != -1)) |
|
2234 | 2231 | if tags: |
|
2235 | 2232 | ls = labels.get(r) |
|
2236 | 2233 | if ls: |
|
2237 | 2234 | for l in ls: |
|
2238 | 2235 | yield 'l', (r, l) |
|
2239 | 2236 | else: |
|
2240 | 2237 | raise error.Abort(_('need repo for changelog dag')) |
|
2241 | 2238 | |
|
2242 | 2239 | for line in dagparser.dagtextlines(events(), |
|
2243 | 2240 | addspaces=spaces, |
|
2244 | 2241 | wraplabels=True, |
|
2245 | 2242 | wrapannotations=True, |
|
2246 | 2243 | wrapnonlinear=dots, |
|
2247 | 2244 | usedots=dots, |
|
2248 | 2245 | maxlinewidth=70): |
|
2249 | 2246 | ui.write(line) |
|
2250 | 2247 | ui.write("\n") |
|
2251 | 2248 | |
|
2252 | 2249 | @command('debugdata', debugrevlogopts, _('-c|-m|FILE REV')) |
|
2253 | 2250 | def debugdata(ui, repo, file_, rev=None, **opts): |
|
2254 | 2251 | """dump the contents of a data file revision""" |
|
2255 | 2252 | if opts.get('changelog') or opts.get('manifest'): |
|
2256 | 2253 | file_, rev = None, file_ |
|
2257 | 2254 | elif rev is None: |
|
2258 | 2255 | raise error.CommandError('debugdata', _('invalid arguments')) |
|
2259 | 2256 | r = cmdutil.openrevlog(repo, 'debugdata', file_, opts) |
|
2260 | 2257 | try: |
|
2261 | 2258 | ui.write(r.revision(r.lookup(rev))) |
|
2262 | 2259 | except KeyError: |
|
2263 | 2260 | raise error.Abort(_('invalid revision identifier %s') % rev) |
|
2264 | 2261 | |
|
2265 | 2262 | @command('debugdate', |
|
2266 | 2263 | [('e', 'extended', None, _('try extended date formats'))], |
|
2267 | 2264 | _('[-e] DATE [RANGE]'), |
|
2268 | 2265 | norepo=True, optionalrepo=True) |
|
2269 | 2266 | def debugdate(ui, date, range=None, **opts): |
|
2270 | 2267 | """parse and display a date""" |
|
2271 | 2268 | if opts["extended"]: |
|
2272 | 2269 | d = util.parsedate(date, util.extendeddateformats) |
|
2273 | 2270 | else: |
|
2274 | 2271 | d = util.parsedate(date) |
|
2275 | 2272 | ui.write(("internal: %s %s\n") % d) |
|
2276 | 2273 | ui.write(("standard: %s\n") % util.datestr(d)) |
|
2277 | 2274 | if range: |
|
2278 | 2275 | m = util.matchdate(range) |
|
2279 | 2276 | ui.write(("match: %s\n") % m(d[0])) |
|
2280 | 2277 | |
|
2281 | 2278 | @command('debugdiscovery', |
|
2282 | 2279 | [('', 'old', None, _('use old-style discovery')), |
|
2283 | 2280 | ('', 'nonheads', None, |
|
2284 | 2281 | _('use old-style discovery with non-heads included')), |
|
2285 | 2282 | ] + remoteopts, |
|
2286 | 2283 | _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) |
|
2287 | 2284 | def debugdiscovery(ui, repo, remoteurl="default", **opts): |
|
2288 | 2285 | """runs the changeset discovery protocol in isolation""" |
|
2289 | 2286 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), |
|
2290 | 2287 | opts.get('branch')) |
|
2291 | 2288 | remote = hg.peer(repo, opts, remoteurl) |
|
2292 | 2289 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) |
|
2293 | 2290 | |
|
2294 | 2291 | # make sure tests are repeatable |
|
2295 | 2292 | random.seed(12323) |
|
2296 | 2293 | |
|
2297 | 2294 | def doit(localheads, remoteheads, remote=remote): |
|
2298 | 2295 | if opts.get('old'): |
|
2299 | 2296 | if localheads: |
|
2300 | 2297 | raise error.Abort('cannot use localheads with old style ' |
|
2301 | 2298 | 'discovery') |
|
2302 | 2299 | if not util.safehasattr(remote, 'branches'): |
|
2303 | 2300 | # enable in-client legacy support |
|
2304 | 2301 | remote = localrepo.locallegacypeer(remote.local()) |
|
2305 | 2302 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, |
|
2306 | 2303 | force=True) |
|
2307 | 2304 | common = set(common) |
|
2308 | 2305 | if not opts.get('nonheads'): |
|
2309 | 2306 | ui.write(("unpruned common: %s\n") % |
|
2310 | 2307 | " ".join(sorted(short(n) for n in common))) |
|
2311 | 2308 | dag = dagutil.revlogdag(repo.changelog) |
|
2312 | 2309 | all = dag.ancestorset(dag.internalizeall(common)) |
|
2313 | 2310 | common = dag.externalizeall(dag.headsetofconnecteds(all)) |
|
2314 | 2311 | else: |
|
2315 | 2312 | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) |
|
2316 | 2313 | common = set(common) |
|
2317 | 2314 | rheads = set(hds) |
|
2318 | 2315 | lheads = set(repo.heads()) |
|
2319 | 2316 | ui.write(("common heads: %s\n") % |
|
2320 | 2317 | " ".join(sorted(short(n) for n in common))) |
|
2321 | 2318 | if lheads <= common: |
|
2322 | 2319 | ui.write(("local is subset\n")) |
|
2323 | 2320 | elif rheads <= common: |
|
2324 | 2321 | ui.write(("remote is subset\n")) |
|
2325 | 2322 | |
|
2326 | 2323 | serverlogs = opts.get('serverlog') |
|
2327 | 2324 | if serverlogs: |
|
2328 | 2325 | for filename in serverlogs: |
|
2329 | 2326 | with open(filename, 'r') as logfile: |
|
2330 | 2327 | line = logfile.readline() |
|
2331 | 2328 | while line: |
|
2332 | 2329 | parts = line.strip().split(';') |
|
2333 | 2330 | op = parts[1] |
|
2334 | 2331 | if op == 'cg': |
|
2335 | 2332 | pass |
|
2336 | 2333 | elif op == 'cgss': |
|
2337 | 2334 | doit(parts[2].split(' '), parts[3].split(' ')) |
|
2338 | 2335 | elif op == 'unb': |
|
2339 | 2336 | doit(parts[3].split(' '), parts[2].split(' ')) |
|
2340 | 2337 | line = logfile.readline() |
|
2341 | 2338 | else: |
|
2342 | 2339 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, |
|
2343 | 2340 | opts.get('remote_head')) |
|
2344 | 2341 | localrevs = opts.get('local_head') |
|
2345 | 2342 | doit(localrevs, remoterevs) |
|
2346 | 2343 | |
|
2347 | 2344 | @command('debugextensions', formatteropts, [], norepo=True) |
|
2348 | 2345 | def debugextensions(ui, **opts): |
|
2349 | 2346 | '''show information about active extensions''' |
|
2350 | 2347 | exts = extensions.extensions(ui) |
|
2351 | 2348 | fm = ui.formatter('debugextensions', opts) |
|
2352 | 2349 | for extname, extmod in sorted(exts, key=operator.itemgetter(0)): |
|
2353 | 2350 | extsource = extmod.__file__ |
|
2354 | 2351 | exttestedwith = getattr(extmod, 'testedwith', None) |
|
2355 | 2352 | if exttestedwith is not None: |
|
2356 | 2353 | exttestedwith = exttestedwith.split() |
|
2357 | 2354 | extbuglink = getattr(extmod, 'buglink', None) |
|
2358 | 2355 | |
|
2359 | 2356 | fm.startitem() |
|
2360 | 2357 | |
|
2361 | 2358 | if ui.quiet or ui.verbose: |
|
2362 | 2359 | fm.write('name', '%s\n', extname) |
|
2363 | 2360 | else: |
|
2364 | 2361 | fm.write('name', '%s', extname) |
|
2365 | 2362 | if not exttestedwith: |
|
2366 | 2363 | fm.plain(_(' (untested!)\n')) |
|
2367 | 2364 | else: |
|
2368 | 2365 | if exttestedwith == ['internal'] or \ |
|
2369 | 2366 | util.version() in exttestedwith: |
|
2370 | 2367 | fm.plain('\n') |
|
2371 | 2368 | else: |
|
2372 | 2369 | lasttestedversion = exttestedwith[-1] |
|
2373 | 2370 | fm.plain(' (%s!)\n' % lasttestedversion) |
|
2374 | 2371 | |
|
2375 | 2372 | fm.condwrite(ui.verbose and extsource, 'source', |
|
2376 | 2373 | _(' location: %s\n'), extsource or "") |
|
2377 | 2374 | |
|
2378 | 2375 | fm.condwrite(ui.verbose and exttestedwith, 'testedwith', |
|
2379 | 2376 | _(' tested with: %s\n'), ' '.join(exttestedwith or [])) |
|
2380 | 2377 | |
|
2381 | 2378 | fm.condwrite(ui.verbose and extbuglink, 'buglink', |
|
2382 | 2379 | _(' bug reporting: %s\n'), extbuglink or "") |
|
2383 | 2380 | |
|
2384 | 2381 | fm.end() |
|
2385 | 2382 | |
|
2386 | 2383 | @command('debugfileset', |
|
2387 | 2384 | [('r', 'rev', '', _('apply the filespec on this revision'), _('REV'))], |
|
2388 | 2385 | _('[-r REV] FILESPEC')) |
|
2389 | 2386 | def debugfileset(ui, repo, expr, **opts): |
|
2390 | 2387 | '''parse and apply a fileset specification''' |
|
2391 | 2388 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
2392 | 2389 | if ui.verbose: |
|
2393 | 2390 | tree = fileset.parse(expr) |
|
2394 | 2391 | ui.note(fileset.prettyformat(tree), "\n") |
|
2395 | 2392 | |
|
2396 | 2393 | for f in ctx.getfileset(expr): |
|
2397 | 2394 | ui.write("%s\n" % f) |
|
2398 | 2395 | |
|
2399 | 2396 | @command('debugfsinfo', [], _('[PATH]'), norepo=True) |
|
2400 | 2397 | def debugfsinfo(ui, path="."): |
|
2401 | 2398 | """show information detected about current filesystem""" |
|
2402 | 2399 | util.writefile('.debugfsinfo', '') |
|
2403 | 2400 | ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no')) |
|
2404 | 2401 | ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no')) |
|
2405 | 2402 | ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no')) |
|
2406 | 2403 | ui.write(('case-sensitive: %s\n') % (util.checkcase('.debugfsinfo') |
|
2407 | 2404 | and 'yes' or 'no')) |
|
2408 | 2405 | os.unlink('.debugfsinfo') |
|
2409 | 2406 | |
|
2410 | 2407 | @command('debuggetbundle', |
|
2411 | 2408 | [('H', 'head', [], _('id of head node'), _('ID')), |
|
2412 | 2409 | ('C', 'common', [], _('id of common node'), _('ID')), |
|
2413 | 2410 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], |
|
2414 | 2411 | _('REPO FILE [-H|-C ID]...'), |
|
2415 | 2412 | norepo=True) |
|
2416 | 2413 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): |
|
2417 | 2414 | """retrieves a bundle from a repo |
|
2418 | 2415 | |
|
2419 | 2416 | Every ID must be a full-length hex node id string. Saves the bundle to the |
|
2420 | 2417 | given file. |
|
2421 | 2418 | """ |
|
2422 | 2419 | repo = hg.peer(ui, opts, repopath) |
|
2423 | 2420 | if not repo.capable('getbundle'): |
|
2424 | 2421 | raise error.Abort("getbundle() not supported by target repository") |
|
2425 | 2422 | args = {} |
|
2426 | 2423 | if common: |
|
2427 | 2424 | args['common'] = [bin(s) for s in common] |
|
2428 | 2425 | if head: |
|
2429 | 2426 | args['heads'] = [bin(s) for s in head] |
|
2430 | 2427 | # TODO: get desired bundlecaps from command line. |
|
2431 | 2428 | args['bundlecaps'] = None |
|
2432 | 2429 | bundle = repo.getbundle('debug', **args) |
|
2433 | 2430 | |
|
2434 | 2431 | bundletype = opts.get('type', 'bzip2').lower() |
|
2435 | 2432 | btypes = {'none': 'HG10UN', |
|
2436 | 2433 | 'bzip2': 'HG10BZ', |
|
2437 | 2434 | 'gzip': 'HG10GZ', |
|
2438 | 2435 | 'bundle2': 'HG20'} |
|
2439 | 2436 | bundletype = btypes.get(bundletype) |
|
2440 | 2437 | if bundletype not in changegroup.bundletypes: |
|
2441 | 2438 | raise error.Abort(_('unknown bundle type specified with --type')) |
|
2442 | 2439 | changegroup.writebundle(ui, bundle, bundlepath, bundletype) |
|
2443 | 2440 | |
|
2444 | 2441 | @command('debugignore', [], '[FILE]') |
|
2445 | 2442 | def debugignore(ui, repo, *files, **opts): |
|
2446 | 2443 | """display the combined ignore pattern and information about ignored files |
|
2447 | 2444 | |
|
2448 | 2445 | With no argument display the combined ignore pattern. |
|
2449 | 2446 | |
|
2450 | 2447 | Given space separated file names, shows if the given file is ignored and |
|
2451 | 2448 | if so, show the ignore rule (file and line number) that matched it. |
|
2452 | 2449 | """ |
|
2453 | 2450 | ignore = repo.dirstate._ignore |
|
2454 | 2451 | if not files: |
|
2455 | 2452 | # Show all the patterns |
|
2456 | 2453 | includepat = getattr(ignore, 'includepat', None) |
|
2457 | 2454 | if includepat is not None: |
|
2458 | 2455 | ui.write("%s\n" % includepat) |
|
2459 | 2456 | else: |
|
2460 | 2457 | raise error.Abort(_("no ignore patterns found")) |
|
2461 | 2458 | else: |
|
2462 | 2459 | for f in files: |
|
2463 | 2460 | ignored = None |
|
2464 | 2461 | ignoredata = None |
|
2465 | 2462 | if f != '.': |
|
2466 | 2463 | if ignore(f): |
|
2467 | 2464 | ignored = f |
|
2468 | 2465 | ignoredata = repo.dirstate._ignorefileandline(f) |
|
2469 | 2466 | else: |
|
2470 | 2467 | for p in util.finddirs(f): |
|
2471 | 2468 | if ignore(p): |
|
2472 | 2469 | ignored = p |
|
2473 | 2470 | ignoredata = repo.dirstate._ignorefileandline(p) |
|
2474 | 2471 | break |
|
2475 | 2472 | if ignored: |
|
2476 | 2473 | if ignored == f: |
|
2477 | 2474 | ui.write("%s is ignored\n" % f) |
|
2478 | 2475 | else: |
|
2479 | 2476 | ui.write("%s is ignored because of containing folder %s\n" |
|
2480 | 2477 | % (f, ignored)) |
|
2481 | 2478 | ignorefile, lineno, line = ignoredata |
|
2482 | 2479 | ui.write("(ignore rule in %s, line %d: '%s')\n" |
|
2483 | 2480 | % (ignorefile, lineno, line)) |
|
2484 | 2481 | else: |
|
2485 | 2482 | ui.write("%s is not ignored\n" % f) |
|
2486 | 2483 | |
|
2487 | 2484 | @command('debugindex', debugrevlogopts + |
|
2488 | 2485 | [('f', 'format', 0, _('revlog format'), _('FORMAT'))], |
|
2489 | 2486 | _('[-f FORMAT] -c|-m|FILE'), |
|
2490 | 2487 | optionalrepo=True) |
|
2491 | 2488 | def debugindex(ui, repo, file_=None, **opts): |
|
2492 | 2489 | """dump the contents of an index file""" |
|
2493 | 2490 | r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) |
|
2494 | 2491 | format = opts.get('format', 0) |
|
2495 | 2492 | if format not in (0, 1): |
|
2496 | 2493 | raise error.Abort(_("unknown format %d") % format) |
|
2497 | 2494 | |
|
2498 | 2495 | generaldelta = r.version & revlog.REVLOGGENERALDELTA |
|
2499 | 2496 | if generaldelta: |
|
2500 | 2497 | basehdr = ' delta' |
|
2501 | 2498 | else: |
|
2502 | 2499 | basehdr = ' base' |
|
2503 | 2500 | |
|
2504 | 2501 | if ui.debugflag: |
|
2505 | 2502 | shortfn = hex |
|
2506 | 2503 | else: |
|
2507 | 2504 | shortfn = short |
|
2508 | 2505 | |
|
2509 | 2506 | # There might not be anything in r, so have a sane default |
|
2510 | 2507 | idlen = 12 |
|
2511 | 2508 | for i in r: |
|
2512 | 2509 | idlen = len(shortfn(r.node(i))) |
|
2513 | 2510 | break |
|
2514 | 2511 | |
|
2515 | 2512 | if format == 0: |
|
2516 | 2513 | ui.write(" rev offset length " + basehdr + " linkrev" |
|
2517 | 2514 | " %s %s p2\n" % ("nodeid".ljust(idlen), "p1".ljust(idlen))) |
|
2518 | 2515 | elif format == 1: |
|
2519 | 2516 | ui.write(" rev flag offset length" |
|
2520 | 2517 | " size " + basehdr + " link p1 p2" |
|
2521 | 2518 | " %s\n" % "nodeid".rjust(idlen)) |
|
2522 | 2519 | |
|
2523 | 2520 | for i in r: |
|
2524 | 2521 | node = r.node(i) |
|
2525 | 2522 | if generaldelta: |
|
2526 | 2523 | base = r.deltaparent(i) |
|
2527 | 2524 | else: |
|
2528 | 2525 | base = r.chainbase(i) |
|
2529 | 2526 | if format == 0: |
|
2530 | 2527 | try: |
|
2531 | 2528 | pp = r.parents(node) |
|
2532 | 2529 | except Exception: |
|
2533 | 2530 | pp = [nullid, nullid] |
|
2534 | 2531 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
2535 | 2532 | i, r.start(i), r.length(i), base, r.linkrev(i), |
|
2536 | 2533 | shortfn(node), shortfn(pp[0]), shortfn(pp[1]))) |
|
2537 | 2534 | elif format == 1: |
|
2538 | 2535 | pr = r.parentrevs(i) |
|
2539 | 2536 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( |
|
2540 | 2537 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), |
|
2541 | 2538 | base, r.linkrev(i), pr[0], pr[1], shortfn(node))) |
|
2542 | 2539 | |
|
2543 | 2540 | @command('debugindexdot', debugrevlogopts, |
|
2544 | 2541 | _('-c|-m|FILE'), optionalrepo=True) |
|
2545 | 2542 | def debugindexdot(ui, repo, file_=None, **opts): |
|
2546 | 2543 | """dump an index DAG as a graphviz dot file""" |
|
2547 | 2544 | r = cmdutil.openrevlog(repo, 'debugindexdot', file_, opts) |
|
2548 | 2545 | ui.write(("digraph G {\n")) |
|
2549 | 2546 | for i in r: |
|
2550 | 2547 | node = r.node(i) |
|
2551 | 2548 | pp = r.parents(node) |
|
2552 | 2549 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
2553 | 2550 | if pp[1] != nullid: |
|
2554 | 2551 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
2555 | 2552 | ui.write("}\n") |
|
2556 | 2553 | |
|
2557 | 2554 | @command('debugdeltachain', |
|
2558 | 2555 | debugrevlogopts + formatteropts, |
|
2559 | 2556 | _('-c|-m|FILE'), |
|
2560 | 2557 | optionalrepo=True) |
|
2561 | 2558 | def debugdeltachain(ui, repo, file_=None, **opts): |
|
2562 | 2559 | """dump information about delta chains in a revlog |
|
2563 | 2560 | |
|
2564 | 2561 | Output can be templatized. Available template keywords are: |
|
2565 | 2562 | |
|
2566 | 2563 | rev revision number |
|
2567 | 2564 | chainid delta chain identifier (numbered by unique base) |
|
2568 | 2565 | chainlen delta chain length to this revision |
|
2569 | 2566 | prevrev previous revision in delta chain |
|
2570 | 2567 | deltatype role of delta / how it was computed |
|
2571 | 2568 | compsize compressed size of revision |
|
2572 | 2569 | uncompsize uncompressed size of revision |
|
2573 | 2570 | chainsize total size of compressed revisions in chain |
|
2574 | 2571 | chainratio total chain size divided by uncompressed revision size |
|
2575 | 2572 | (new delta chains typically start at ratio 2.00) |
|
2576 | 2573 | lindist linear distance from base revision in delta chain to end |
|
2577 | 2574 | of this revision |
|
2578 | 2575 | extradist total size of revisions not part of this delta chain from |
|
2579 | 2576 | base of delta chain to end of this revision; a measurement |
|
2580 | 2577 | of how much extra data we need to read/seek across to read |
|
2581 | 2578 | the delta chain for this revision |
|
2582 | 2579 | extraratio extradist divided by chainsize; another representation of |
|
2583 | 2580 | how much unrelated data is needed to load this delta chain |
|
2584 | 2581 | """ |
|
2585 | 2582 | r = cmdutil.openrevlog(repo, 'debugdeltachain', file_, opts) |
|
2586 | 2583 | index = r.index |
|
2587 | 2584 | generaldelta = r.version & revlog.REVLOGGENERALDELTA |
|
2588 | 2585 | |
|
2589 | 2586 | def revinfo(rev): |
|
2590 | 2587 | e = index[rev] |
|
2591 | 2588 | compsize = e[1] |
|
2592 | 2589 | uncompsize = e[2] |
|
2593 | 2590 | chainsize = 0 |
|
2594 | 2591 | |
|
2595 | 2592 | if generaldelta: |
|
2596 | 2593 | if e[3] == e[5]: |
|
2597 | 2594 | deltatype = 'p1' |
|
2598 | 2595 | elif e[3] == e[6]: |
|
2599 | 2596 | deltatype = 'p2' |
|
2600 | 2597 | elif e[3] == rev - 1: |
|
2601 | 2598 | deltatype = 'prev' |
|
2602 | 2599 | elif e[3] == rev: |
|
2603 | 2600 | deltatype = 'base' |
|
2604 | 2601 | else: |
|
2605 | 2602 | deltatype = 'other' |
|
2606 | 2603 | else: |
|
2607 | 2604 | if e[3] == rev: |
|
2608 | 2605 | deltatype = 'base' |
|
2609 | 2606 | else: |
|
2610 | 2607 | deltatype = 'prev' |
|
2611 | 2608 | |
|
2612 | 2609 | chain = r._deltachain(rev)[0] |
|
2613 | 2610 | for iterrev in chain: |
|
2614 | 2611 | e = index[iterrev] |
|
2615 | 2612 | chainsize += e[1] |
|
2616 | 2613 | |
|
2617 | 2614 | return compsize, uncompsize, deltatype, chain, chainsize |
|
2618 | 2615 | |
|
2619 | 2616 | fm = ui.formatter('debugdeltachain', opts) |
|
2620 | 2617 | |
|
2621 | 2618 | fm.plain(' rev chain# chainlen prev delta ' |
|
2622 | 2619 | 'size rawsize chainsize ratio lindist extradist ' |
|
2623 | 2620 | 'extraratio\n') |
|
2624 | 2621 | |
|
2625 | 2622 | chainbases = {} |
|
2626 | 2623 | for rev in r: |
|
2627 | 2624 | comp, uncomp, deltatype, chain, chainsize = revinfo(rev) |
|
2628 | 2625 | chainbase = chain[0] |
|
2629 | 2626 | chainid = chainbases.setdefault(chainbase, len(chainbases) + 1) |
|
2630 | 2627 | basestart = r.start(chainbase) |
|
2631 | 2628 | revstart = r.start(rev) |
|
2632 | 2629 | lineardist = revstart + comp - basestart |
|
2633 | 2630 | extradist = lineardist - chainsize |
|
2634 | 2631 | try: |
|
2635 | 2632 | prevrev = chain[-2] |
|
2636 | 2633 | except IndexError: |
|
2637 | 2634 | prevrev = -1 |
|
2638 | 2635 | |
|
2639 | 2636 | chainratio = float(chainsize) / float(uncomp) |
|
2640 | 2637 | extraratio = float(extradist) / float(chainsize) |
|
2641 | 2638 | |
|
2642 | 2639 | fm.startitem() |
|
2643 | 2640 | fm.write('rev chainid chainlen prevrev deltatype compsize ' |
|
2644 | 2641 | 'uncompsize chainsize chainratio lindist extradist ' |
|
2645 | 2642 | 'extraratio', |
|
2646 | 2643 | '%7d %7d %8d %8d %7s %10d %10d %10d %9.5f %9d %9d %10.5f\n', |
|
2647 | 2644 | rev, chainid, len(chain), prevrev, deltatype, comp, |
|
2648 | 2645 | uncomp, chainsize, chainratio, lineardist, extradist, |
|
2649 | 2646 | extraratio, |
|
2650 | 2647 | rev=rev, chainid=chainid, chainlen=len(chain), |
|
2651 | 2648 | prevrev=prevrev, deltatype=deltatype, compsize=comp, |
|
2652 | 2649 | uncompsize=uncomp, chainsize=chainsize, |
|
2653 | 2650 | chainratio=chainratio, lindist=lineardist, |
|
2654 | 2651 | extradist=extradist, extraratio=extraratio) |
|
2655 | 2652 | |
|
2656 | 2653 | fm.end() |
|
2657 | 2654 | |
|
2658 | 2655 | @command('debuginstall', [], '', norepo=True) |
|
2659 | 2656 | def debuginstall(ui): |
|
2660 | 2657 | '''test Mercurial installation |
|
2661 | 2658 | |
|
2662 | 2659 | Returns 0 on success. |
|
2663 | 2660 | ''' |
|
2664 | 2661 | |
|
2665 | 2662 | def writetemp(contents): |
|
2666 | 2663 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
2667 | 2664 | f = os.fdopen(fd, "wb") |
|
2668 | 2665 | f.write(contents) |
|
2669 | 2666 | f.close() |
|
2670 | 2667 | return name |
|
2671 | 2668 | |
|
2672 | 2669 | problems = 0 |
|
2673 | 2670 | |
|
2674 | 2671 | # encoding |
|
2675 | 2672 | ui.status(_("checking encoding (%s)...\n") % encoding.encoding) |
|
2676 | 2673 | try: |
|
2677 | 2674 | encoding.fromlocal("test") |
|
2678 | 2675 | except error.Abort as inst: |
|
2679 | 2676 | ui.write(" %s\n" % inst) |
|
2680 | 2677 | ui.write(_(" (check that your locale is properly set)\n")) |
|
2681 | 2678 | problems += 1 |
|
2682 | 2679 | |
|
2683 | 2680 | # Python |
|
2684 | 2681 | ui.status(_("checking Python executable (%s)\n") % sys.executable) |
|
2685 | 2682 | ui.status(_("checking Python version (%s)\n") |
|
2686 | 2683 | % ("%s.%s.%s" % sys.version_info[:3])) |
|
2687 | 2684 | ui.status(_("checking Python lib (%s)...\n") |
|
2688 | 2685 | % os.path.dirname(os.__file__)) |
|
2689 | 2686 | |
|
2690 | 2687 | # compiled modules |
|
2691 | 2688 | ui.status(_("checking installed modules (%s)...\n") |
|
2692 | 2689 | % os.path.dirname(__file__)) |
|
2693 | 2690 | try: |
|
2694 | 2691 | import bdiff, mpatch, base85, osutil |
|
2695 | 2692 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes |
|
2696 | 2693 | except Exception as inst: |
|
2697 | 2694 | ui.write(" %s\n" % inst) |
|
2698 | 2695 | ui.write(_(" One or more extensions could not be found")) |
|
2699 | 2696 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
2700 | 2697 | problems += 1 |
|
2701 | 2698 | |
|
2702 | 2699 | # templates |
|
2703 | 2700 | import templater |
|
2704 | 2701 | p = templater.templatepaths() |
|
2705 | 2702 | ui.status(_("checking templates (%s)...\n") % ' '.join(p)) |
|
2706 | 2703 | if p: |
|
2707 | 2704 | m = templater.templatepath("map-cmdline.default") |
|
2708 | 2705 | if m: |
|
2709 | 2706 | # template found, check if it is working |
|
2710 | 2707 | try: |
|
2711 | 2708 | templater.templater(m) |
|
2712 | 2709 | except Exception as inst: |
|
2713 | 2710 | ui.write(" %s\n" % inst) |
|
2714 | 2711 | p = None |
|
2715 | 2712 | else: |
|
2716 | 2713 | ui.write(_(" template 'default' not found\n")) |
|
2717 | 2714 | p = None |
|
2718 | 2715 | else: |
|
2719 | 2716 | ui.write(_(" no template directories found\n")) |
|
2720 | 2717 | if not p: |
|
2721 | 2718 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
2722 | 2719 | problems += 1 |
|
2723 | 2720 | |
|
2724 | 2721 | # editor |
|
2725 | 2722 | ui.status(_("checking commit editor...\n")) |
|
2726 | 2723 | editor = ui.geteditor() |
|
2727 | 2724 | editor = util.expandpath(editor) |
|
2728 | 2725 | cmdpath = util.findexe(shlex.split(editor)[0]) |
|
2729 | 2726 | if not cmdpath: |
|
2730 | 2727 | if editor == 'vi': |
|
2731 | 2728 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
2732 | 2729 | ui.write(_(" (specify a commit editor in your configuration" |
|
2733 | 2730 | " file)\n")) |
|
2734 | 2731 | else: |
|
2735 | 2732 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
2736 | 2733 | ui.write(_(" (specify a commit editor in your configuration" |
|
2737 | 2734 | " file)\n")) |
|
2738 | 2735 | problems += 1 |
|
2739 | 2736 | |
|
2740 | 2737 | # check username |
|
2741 | 2738 | ui.status(_("checking username...\n")) |
|
2742 | 2739 | try: |
|
2743 | 2740 | ui.username() |
|
2744 | 2741 | except error.Abort as e: |
|
2745 | 2742 | ui.write(" %s\n" % e) |
|
2746 | 2743 | ui.write(_(" (specify a username in your configuration file)\n")) |
|
2747 | 2744 | problems += 1 |
|
2748 | 2745 | |
|
2749 | 2746 | if not problems: |
|
2750 | 2747 | ui.status(_("no problems detected\n")) |
|
2751 | 2748 | else: |
|
2752 | 2749 | ui.write(_("%s problems detected," |
|
2753 | 2750 | " please check your install!\n") % problems) |
|
2754 | 2751 | |
|
2755 | 2752 | return problems |
|
2756 | 2753 | |
|
2757 | 2754 | @command('debugknown', [], _('REPO ID...'), norepo=True) |
|
2758 | 2755 | def debugknown(ui, repopath, *ids, **opts): |
|
2759 | 2756 | """test whether node ids are known to a repo |
|
2760 | 2757 | |
|
2761 | 2758 | Every ID must be a full-length hex node id string. Returns a list of 0s |
|
2762 | 2759 | and 1s indicating unknown/known. |
|
2763 | 2760 | """ |
|
2764 | 2761 | repo = hg.peer(ui, opts, repopath) |
|
2765 | 2762 | if not repo.capable('known'): |
|
2766 | 2763 | raise error.Abort("known() not supported by target repository") |
|
2767 | 2764 | flags = repo.known([bin(s) for s in ids]) |
|
2768 | 2765 | ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) |
|
2769 | 2766 | |
|
2770 | 2767 | @command('debuglabelcomplete', [], _('LABEL...')) |
|
2771 | 2768 | def debuglabelcomplete(ui, repo, *args): |
|
2772 | 2769 | '''backwards compatibility with old bash completion scripts (DEPRECATED)''' |
|
2773 | 2770 | debugnamecomplete(ui, repo, *args) |
|
2774 | 2771 | |
|
2775 | 2772 | @command('debugmergestate', [], '') |
|
2776 | 2773 | def debugmergestate(ui, repo, *args): |
|
2777 | 2774 | """print merge state |
|
2778 | 2775 | |
|
2779 | 2776 | Use --verbose to print out information about whether v1 or v2 merge state |
|
2780 | 2777 | was chosen.""" |
|
2781 | 2778 | def _hashornull(h): |
|
2782 | 2779 | if h == nullhex: |
|
2783 | 2780 | return 'null' |
|
2784 | 2781 | else: |
|
2785 | 2782 | return h |
|
2786 | 2783 | |
|
2787 | 2784 | def printrecords(version): |
|
2788 | 2785 | ui.write(('* version %s records\n') % version) |
|
2789 | 2786 | if version == 1: |
|
2790 | 2787 | records = v1records |
|
2791 | 2788 | else: |
|
2792 | 2789 | records = v2records |
|
2793 | 2790 | |
|
2794 | 2791 | for rtype, record in records: |
|
2795 | 2792 | # pretty print some record types |
|
2796 | 2793 | if rtype == 'L': |
|
2797 | 2794 | ui.write(('local: %s\n') % record) |
|
2798 | 2795 | elif rtype == 'O': |
|
2799 | 2796 | ui.write(('other: %s\n') % record) |
|
2800 | 2797 | elif rtype == 'm': |
|
2801 | 2798 | driver, mdstate = record.split('\0', 1) |
|
2802 | 2799 | ui.write(('merge driver: %s (state "%s")\n') |
|
2803 | 2800 | % (driver, mdstate)) |
|
2804 | 2801 | elif rtype in 'FDC': |
|
2805 | 2802 | r = record.split('\0') |
|
2806 | 2803 | f, state, hash, lfile, afile, anode, ofile = r[0:7] |
|
2807 | 2804 | if version == 1: |
|
2808 | 2805 | onode = 'not stored in v1 format' |
|
2809 | 2806 | flags = r[7] |
|
2810 | 2807 | else: |
|
2811 | 2808 | onode, flags = r[7:9] |
|
2812 | 2809 | ui.write(('file: %s (record type "%s", state "%s", hash %s)\n') |
|
2813 | 2810 | % (f, rtype, state, _hashornull(hash))) |
|
2814 | 2811 | ui.write((' local path: %s (flags "%s")\n') % (lfile, flags)) |
|
2815 | 2812 | ui.write((' ancestor path: %s (node %s)\n') |
|
2816 | 2813 | % (afile, _hashornull(anode))) |
|
2817 | 2814 | ui.write((' other path: %s (node %s)\n') |
|
2818 | 2815 | % (ofile, _hashornull(onode))) |
|
2819 | 2816 | else: |
|
2820 | 2817 | ui.write(('unrecognized entry: %s\t%s\n') |
|
2821 | 2818 | % (rtype, record.replace('\0', '\t'))) |
|
2822 | 2819 | |
|
2823 | 2820 | # Avoid mergestate.read() since it may raise an exception for unsupported |
|
2824 | 2821 | # merge state records. We shouldn't be doing this, but this is OK since this |
|
2825 | 2822 | # command is pretty low-level. |
|
2826 | 2823 | ms = mergemod.mergestate(repo) |
|
2827 | 2824 | |
|
2828 | 2825 | # sort so that reasonable information is on top |
|
2829 | 2826 | v1records = ms._readrecordsv1() |
|
2830 | 2827 | v2records = ms._readrecordsv2() |
|
2831 | 2828 | order = 'LOm' |
|
2832 | 2829 | def key(r): |
|
2833 | 2830 | idx = order.find(r[0]) |
|
2834 | 2831 | if idx == -1: |
|
2835 | 2832 | return (1, r[1]) |
|
2836 | 2833 | else: |
|
2837 | 2834 | return (0, idx) |
|
2838 | 2835 | v1records.sort(key=key) |
|
2839 | 2836 | v2records.sort(key=key) |
|
2840 | 2837 | |
|
2841 | 2838 | if not v1records and not v2records: |
|
2842 | 2839 | ui.write(('no merge state found\n')) |
|
2843 | 2840 | elif not v2records: |
|
2844 | 2841 | ui.note(('no version 2 merge state\n')) |
|
2845 | 2842 | printrecords(1) |
|
2846 | 2843 | elif ms._v1v2match(v1records, v2records): |
|
2847 | 2844 | ui.note(('v1 and v2 states match: using v2\n')) |
|
2848 | 2845 | printrecords(2) |
|
2849 | 2846 | else: |
|
2850 | 2847 | ui.note(('v1 and v2 states mismatch: using v1\n')) |
|
2851 | 2848 | printrecords(1) |
|
2852 | 2849 | if ui.verbose: |
|
2853 | 2850 | printrecords(2) |
|
2854 | 2851 | |
|
2855 | 2852 | @command('debugnamecomplete', [], _('NAME...')) |
|
2856 | 2853 | def debugnamecomplete(ui, repo, *args): |
|
2857 | 2854 | '''complete "names" - tags, open branch names, bookmark names''' |
|
2858 | 2855 | |
|
2859 | 2856 | names = set() |
|
2860 | 2857 | # since we previously only listed open branches, we will handle that |
|
2861 | 2858 | # specially (after this for loop) |
|
2862 | 2859 | for name, ns in repo.names.iteritems(): |
|
2863 | 2860 | if name != 'branches': |
|
2864 | 2861 | names.update(ns.listnames(repo)) |
|
2865 | 2862 | names.update(tag for (tag, heads, tip, closed) |
|
2866 | 2863 | in repo.branchmap().iterbranches() if not closed) |
|
2867 | 2864 | completions = set() |
|
2868 | 2865 | if not args: |
|
2869 | 2866 | args = [''] |
|
2870 | 2867 | for a in args: |
|
2871 | 2868 | completions.update(n for n in names if n.startswith(a)) |
|
2872 | 2869 | ui.write('\n'.join(sorted(completions))) |
|
2873 | 2870 | ui.write('\n') |
|
2874 | 2871 | |
|
2875 | 2872 | @command('debuglocks', |
|
2876 | 2873 | [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')), |
|
2877 | 2874 | ('W', 'force-wlock', None, |
|
2878 | 2875 | _('free the working state lock (DANGEROUS)'))], |
|
2879 | 2876 | _('[OPTION]...')) |
|
2880 | 2877 | def debuglocks(ui, repo, **opts): |
|
2881 | 2878 | """show or modify state of locks |
|
2882 | 2879 | |
|
2883 | 2880 | By default, this command will show which locks are held. This |
|
2884 | 2881 | includes the user and process holding the lock, the amount of time |
|
2885 | 2882 | the lock has been held, and the machine name where the process is |
|
2886 | 2883 | running if it's not local. |
|
2887 | 2884 | |
|
2888 | 2885 | Locks protect the integrity of Mercurial's data, so should be |
|
2889 | 2886 | treated with care. System crashes or other interruptions may cause |
|
2890 | 2887 | locks to not be properly released, though Mercurial will usually |
|
2891 | 2888 | detect and remove such stale locks automatically. |
|
2892 | 2889 | |
|
2893 | 2890 | However, detecting stale locks may not always be possible (for |
|
2894 | 2891 | instance, on a shared filesystem). Removing locks may also be |
|
2895 | 2892 | blocked by filesystem permissions. |
|
2896 | 2893 | |
|
2897 | 2894 | Returns 0 if no locks are held. |
|
2898 | 2895 | |
|
2899 | 2896 | """ |
|
2900 | 2897 | |
|
2901 | 2898 | if opts.get('force_lock'): |
|
2902 | 2899 | repo.svfs.unlink('lock') |
|
2903 | 2900 | if opts.get('force_wlock'): |
|
2904 | 2901 | repo.vfs.unlink('wlock') |
|
2905 | 2902 | if opts.get('force_lock') or opts.get('force_lock'): |
|
2906 | 2903 | return 0 |
|
2907 | 2904 | |
|
2908 | 2905 | now = time.time() |
|
2909 | 2906 | held = 0 |
|
2910 | 2907 | |
|
2911 | 2908 | def report(vfs, name, method): |
|
2912 | 2909 | # this causes stale locks to get reaped for more accurate reporting |
|
2913 | 2910 | try: |
|
2914 | 2911 | l = method(False) |
|
2915 | 2912 | except error.LockHeld: |
|
2916 | 2913 | l = None |
|
2917 | 2914 | |
|
2918 | 2915 | if l: |
|
2919 | 2916 | l.release() |
|
2920 | 2917 | else: |
|
2921 | 2918 | try: |
|
2922 | 2919 | stat = vfs.lstat(name) |
|
2923 | 2920 | age = now - stat.st_mtime |
|
2924 | 2921 | user = util.username(stat.st_uid) |
|
2925 | 2922 | locker = vfs.readlock(name) |
|
2926 | 2923 | if ":" in locker: |
|
2927 | 2924 | host, pid = locker.split(':') |
|
2928 | 2925 | if host == socket.gethostname(): |
|
2929 | 2926 | locker = 'user %s, process %s' % (user, pid) |
|
2930 | 2927 | else: |
|
2931 | 2928 | locker = 'user %s, process %s, host %s' \ |
|
2932 | 2929 | % (user, pid, host) |
|
2933 | 2930 | ui.write("%-6s %s (%ds)\n" % (name + ":", locker, age)) |
|
2934 | 2931 | return 1 |
|
2935 | 2932 | except OSError as e: |
|
2936 | 2933 | if e.errno != errno.ENOENT: |
|
2937 | 2934 | raise |
|
2938 | 2935 | |
|
2939 | 2936 | ui.write("%-6s free\n" % (name + ":")) |
|
2940 | 2937 | return 0 |
|
2941 | 2938 | |
|
2942 | 2939 | held += report(repo.svfs, "lock", repo.lock) |
|
2943 | 2940 | held += report(repo.vfs, "wlock", repo.wlock) |
|
2944 | 2941 | |
|
2945 | 2942 | return held |
|
2946 | 2943 | |
|
2947 | 2944 | @command('debugobsolete', |
|
2948 | 2945 | [('', 'flags', 0, _('markers flag')), |
|
2949 | 2946 | ('', 'record-parents', False, |
|
2950 | 2947 | _('record parent information for the precursor')), |
|
2951 | 2948 | ('r', 'rev', [], _('display markers relevant to REV')), |
|
2952 | 2949 | ] + commitopts2, |
|
2953 | 2950 | _('[OBSOLETED [REPLACEMENT ...]]')) |
|
2954 | 2951 | def debugobsolete(ui, repo, precursor=None, *successors, **opts): |
|
2955 | 2952 | """create arbitrary obsolete marker |
|
2956 | 2953 | |
|
2957 | 2954 | With no arguments, displays the list of obsolescence markers.""" |
|
2958 | 2955 | |
|
2959 | 2956 | def parsenodeid(s): |
|
2960 | 2957 | try: |
|
2961 | 2958 | # We do not use revsingle/revrange functions here to accept |
|
2962 | 2959 | # arbitrary node identifiers, possibly not present in the |
|
2963 | 2960 | # local repository. |
|
2964 | 2961 | n = bin(s) |
|
2965 | 2962 | if len(n) != len(nullid): |
|
2966 | 2963 | raise TypeError() |
|
2967 | 2964 | return n |
|
2968 | 2965 | except TypeError: |
|
2969 | 2966 | raise error.Abort('changeset references must be full hexadecimal ' |
|
2970 | 2967 | 'node identifiers') |
|
2971 | 2968 | |
|
2972 | 2969 | if precursor is not None: |
|
2973 | 2970 | if opts['rev']: |
|
2974 | 2971 | raise error.Abort('cannot select revision when creating marker') |
|
2975 | 2972 | metadata = {} |
|
2976 | 2973 | metadata['user'] = opts['user'] or ui.username() |
|
2977 | 2974 | succs = tuple(parsenodeid(succ) for succ in successors) |
|
2978 | 2975 | l = repo.lock() |
|
2979 | 2976 | try: |
|
2980 | 2977 | tr = repo.transaction('debugobsolete') |
|
2981 | 2978 | try: |
|
2982 | 2979 | date = opts.get('date') |
|
2983 | 2980 | if date: |
|
2984 | 2981 | date = util.parsedate(date) |
|
2985 | 2982 | else: |
|
2986 | 2983 | date = None |
|
2987 | 2984 | prec = parsenodeid(precursor) |
|
2988 | 2985 | parents = None |
|
2989 | 2986 | if opts['record_parents']: |
|
2990 | 2987 | if prec not in repo.unfiltered(): |
|
2991 | 2988 | raise error.Abort('cannot used --record-parents on ' |
|
2992 | 2989 | 'unknown changesets') |
|
2993 | 2990 | parents = repo.unfiltered()[prec].parents() |
|
2994 | 2991 | parents = tuple(p.node() for p in parents) |
|
2995 | 2992 | repo.obsstore.create(tr, prec, succs, opts['flags'], |
|
2996 | 2993 | parents=parents, date=date, |
|
2997 | 2994 | metadata=metadata) |
|
2998 | 2995 | tr.close() |
|
2999 | 2996 | except ValueError as exc: |
|
3000 | 2997 | raise error.Abort(_('bad obsmarker input: %s') % exc) |
|
3001 | 2998 | finally: |
|
3002 | 2999 | tr.release() |
|
3003 | 3000 | finally: |
|
3004 | 3001 | l.release() |
|
3005 | 3002 | else: |
|
3006 | 3003 | if opts['rev']: |
|
3007 | 3004 | revs = scmutil.revrange(repo, opts['rev']) |
|
3008 | 3005 | nodes = [repo[r].node() for r in revs] |
|
3009 | 3006 | markers = list(obsolete.getmarkers(repo, nodes=nodes)) |
|
3010 | 3007 | markers.sort(key=lambda x: x._data) |
|
3011 | 3008 | else: |
|
3012 | 3009 | markers = obsolete.getmarkers(repo) |
|
3013 | 3010 | |
|
3014 | 3011 | for m in markers: |
|
3015 | 3012 | cmdutil.showmarker(ui, m) |
|
3016 | 3013 | |
|
3017 | 3014 | @command('debugpathcomplete', |
|
3018 | 3015 | [('f', 'full', None, _('complete an entire path')), |
|
3019 | 3016 | ('n', 'normal', None, _('show only normal files')), |
|
3020 | 3017 | ('a', 'added', None, _('show only added files')), |
|
3021 | 3018 | ('r', 'removed', None, _('show only removed files'))], |
|
3022 | 3019 | _('FILESPEC...')) |
|
3023 | 3020 | def debugpathcomplete(ui, repo, *specs, **opts): |
|
3024 | 3021 | '''complete part or all of a tracked path |
|
3025 | 3022 | |
|
3026 | 3023 | This command supports shells that offer path name completion. It |
|
3027 | 3024 | currently completes only files already known to the dirstate. |
|
3028 | 3025 | |
|
3029 | 3026 | Completion extends only to the next path segment unless |
|
3030 | 3027 | --full is specified, in which case entire paths are used.''' |
|
3031 | 3028 | |
|
3032 | 3029 | def complete(path, acceptable): |
|
3033 | 3030 | dirstate = repo.dirstate |
|
3034 | 3031 | spec = os.path.normpath(os.path.join(os.getcwd(), path)) |
|
3035 | 3032 | rootdir = repo.root + os.sep |
|
3036 | 3033 | if spec != repo.root and not spec.startswith(rootdir): |
|
3037 | 3034 | return [], [] |
|
3038 | 3035 | if os.path.isdir(spec): |
|
3039 | 3036 | spec += '/' |
|
3040 | 3037 | spec = spec[len(rootdir):] |
|
3041 | 3038 | fixpaths = os.sep != '/' |
|
3042 | 3039 | if fixpaths: |
|
3043 | 3040 | spec = spec.replace(os.sep, '/') |
|
3044 | 3041 | speclen = len(spec) |
|
3045 | 3042 | fullpaths = opts['full'] |
|
3046 | 3043 | files, dirs = set(), set() |
|
3047 | 3044 | adddir, addfile = dirs.add, files.add |
|
3048 | 3045 | for f, st in dirstate.iteritems(): |
|
3049 | 3046 | if f.startswith(spec) and st[0] in acceptable: |
|
3050 | 3047 | if fixpaths: |
|
3051 | 3048 | f = f.replace('/', os.sep) |
|
3052 | 3049 | if fullpaths: |
|
3053 | 3050 | addfile(f) |
|
3054 | 3051 | continue |
|
3055 | 3052 | s = f.find(os.sep, speclen) |
|
3056 | 3053 | if s >= 0: |
|
3057 | 3054 | adddir(f[:s]) |
|
3058 | 3055 | else: |
|
3059 | 3056 | addfile(f) |
|
3060 | 3057 | return files, dirs |
|
3061 | 3058 | |
|
3062 | 3059 | acceptable = '' |
|
3063 | 3060 | if opts['normal']: |
|
3064 | 3061 | acceptable += 'nm' |
|
3065 | 3062 | if opts['added']: |
|
3066 | 3063 | acceptable += 'a' |
|
3067 | 3064 | if opts['removed']: |
|
3068 | 3065 | acceptable += 'r' |
|
3069 | 3066 | cwd = repo.getcwd() |
|
3070 | 3067 | if not specs: |
|
3071 | 3068 | specs = ['.'] |
|
3072 | 3069 | |
|
3073 | 3070 | files, dirs = set(), set() |
|
3074 | 3071 | for spec in specs: |
|
3075 | 3072 | f, d = complete(spec, acceptable or 'nmar') |
|
3076 | 3073 | files.update(f) |
|
3077 | 3074 | dirs.update(d) |
|
3078 | 3075 | files.update(dirs) |
|
3079 | 3076 | ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files))) |
|
3080 | 3077 | ui.write('\n') |
|
3081 | 3078 | |
|
3082 | 3079 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True) |
|
3083 | 3080 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): |
|
3084 | 3081 | '''access the pushkey key/value protocol |
|
3085 | 3082 | |
|
3086 | 3083 | With two args, list the keys in the given namespace. |
|
3087 | 3084 | |
|
3088 | 3085 | With five args, set a key to new if it currently is set to old. |
|
3089 | 3086 | Reports success or failure. |
|
3090 | 3087 | ''' |
|
3091 | 3088 | |
|
3092 | 3089 | target = hg.peer(ui, {}, repopath) |
|
3093 | 3090 | if keyinfo: |
|
3094 | 3091 | key, old, new = keyinfo |
|
3095 | 3092 | r = target.pushkey(namespace, key, old, new) |
|
3096 | 3093 | ui.status(str(r) + '\n') |
|
3097 | 3094 | return not r |
|
3098 | 3095 | else: |
|
3099 | 3096 | for k, v in sorted(target.listkeys(namespace).iteritems()): |
|
3100 | 3097 | ui.write("%s\t%s\n" % (k.encode('string-escape'), |
|
3101 | 3098 | v.encode('string-escape'))) |
|
3102 | 3099 | |
|
3103 | 3100 | @command('debugpvec', [], _('A B')) |
|
3104 | 3101 | def debugpvec(ui, repo, a, b=None): |
|
3105 | 3102 | ca = scmutil.revsingle(repo, a) |
|
3106 | 3103 | cb = scmutil.revsingle(repo, b) |
|
3107 | 3104 | pa = pvec.ctxpvec(ca) |
|
3108 | 3105 | pb = pvec.ctxpvec(cb) |
|
3109 | 3106 | if pa == pb: |
|
3110 | 3107 | rel = "=" |
|
3111 | 3108 | elif pa > pb: |
|
3112 | 3109 | rel = ">" |
|
3113 | 3110 | elif pa < pb: |
|
3114 | 3111 | rel = "<" |
|
3115 | 3112 | elif pa | pb: |
|
3116 | 3113 | rel = "|" |
|
3117 | 3114 | ui.write(_("a: %s\n") % pa) |
|
3118 | 3115 | ui.write(_("b: %s\n") % pb) |
|
3119 | 3116 | ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth)) |
|
3120 | 3117 | ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") % |
|
3121 | 3118 | (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec), |
|
3122 | 3119 | pa.distance(pb), rel)) |
|
3123 | 3120 | |
|
3124 | 3121 | @command('debugrebuilddirstate|debugrebuildstate', |
|
3125 | 3122 | [('r', 'rev', '', _('revision to rebuild to'), _('REV')), |
|
3126 | 3123 | ('', 'minimal', None, _('only rebuild files that are inconsistent with ' |
|
3127 | 3124 | 'the working copy parent')), |
|
3128 | 3125 | ], |
|
3129 | 3126 | _('[-r REV]')) |
|
3130 | 3127 | def debugrebuilddirstate(ui, repo, rev, **opts): |
|
3131 | 3128 | """rebuild the dirstate as it would look like for the given revision |
|
3132 | 3129 | |
|
3133 | 3130 | If no revision is specified the first current parent will be used. |
|
3134 | 3131 | |
|
3135 | 3132 | The dirstate will be set to the files of the given revision. |
|
3136 | 3133 | The actual working directory content or existing dirstate |
|
3137 | 3134 | information such as adds or removes is not considered. |
|
3138 | 3135 | |
|
3139 | 3136 | ``minimal`` will only rebuild the dirstate status for files that claim to be |
|
3140 | 3137 | tracked but are not in the parent manifest, or that exist in the parent |
|
3141 | 3138 | manifest but are not in the dirstate. It will not change adds, removes, or |
|
3142 | 3139 | modified files that are in the working copy parent. |
|
3143 | 3140 | |
|
3144 | 3141 | One use of this command is to make the next :hg:`status` invocation |
|
3145 | 3142 | check the actual file content. |
|
3146 | 3143 | """ |
|
3147 | 3144 | ctx = scmutil.revsingle(repo, rev) |
|
3148 | 3145 | with repo.wlock(): |
|
3149 | 3146 | dirstate = repo.dirstate |
|
3150 | 3147 | changedfiles = None |
|
3151 | 3148 | # See command doc for what minimal does. |
|
3152 | 3149 | if opts.get('minimal'): |
|
3153 | 3150 | manifestfiles = set(ctx.manifest().keys()) |
|
3154 | 3151 | dirstatefiles = set(dirstate) |
|
3155 | 3152 | manifestonly = manifestfiles - dirstatefiles |
|
3156 | 3153 | dsonly = dirstatefiles - manifestfiles |
|
3157 | 3154 | dsnotadded = set(f for f in dsonly if dirstate[f] != 'a') |
|
3158 | 3155 | changedfiles = manifestonly | dsnotadded |
|
3159 | 3156 | |
|
3160 | 3157 | dirstate.rebuild(ctx.node(), ctx.manifest(), changedfiles) |
|
3161 | 3158 | |
|
3162 | 3159 | @command('debugrebuildfncache', [], '') |
|
3163 | 3160 | def debugrebuildfncache(ui, repo): |
|
3164 | 3161 | """rebuild the fncache file""" |
|
3165 | 3162 | repair.rebuildfncache(ui, repo) |
|
3166 | 3163 | |
|
3167 | 3164 | @command('debugrename', |
|
3168 | 3165 | [('r', 'rev', '', _('revision to debug'), _('REV'))], |
|
3169 | 3166 | _('[-r REV] FILE')) |
|
3170 | 3167 | def debugrename(ui, repo, file1, *pats, **opts): |
|
3171 | 3168 | """dump rename information""" |
|
3172 | 3169 | |
|
3173 | 3170 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
3174 | 3171 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
3175 | 3172 | for abs in ctx.walk(m): |
|
3176 | 3173 | fctx = ctx[abs] |
|
3177 | 3174 | o = fctx.filelog().renamed(fctx.filenode()) |
|
3178 | 3175 | rel = m.rel(abs) |
|
3179 | 3176 | if o: |
|
3180 | 3177 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
3181 | 3178 | else: |
|
3182 | 3179 | ui.write(_("%s not renamed\n") % rel) |
|
3183 | 3180 | |
|
3184 | 3181 | @command('debugrevlog', debugrevlogopts + |
|
3185 | 3182 | [('d', 'dump', False, _('dump index data'))], |
|
3186 | 3183 | _('-c|-m|FILE'), |
|
3187 | 3184 | optionalrepo=True) |
|
3188 | 3185 | def debugrevlog(ui, repo, file_=None, **opts): |
|
3189 | 3186 | """show data and statistics about a revlog""" |
|
3190 | 3187 | r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts) |
|
3191 | 3188 | |
|
3192 | 3189 | if opts.get("dump"): |
|
3193 | 3190 | numrevs = len(r) |
|
3194 | 3191 | ui.write("# rev p1rev p2rev start end deltastart base p1 p2" |
|
3195 | 3192 | " rawsize totalsize compression heads chainlen\n") |
|
3196 | 3193 | ts = 0 |
|
3197 | 3194 | heads = set() |
|
3198 | 3195 | |
|
3199 | 3196 | for rev in xrange(numrevs): |
|
3200 | 3197 | dbase = r.deltaparent(rev) |
|
3201 | 3198 | if dbase == -1: |
|
3202 | 3199 | dbase = rev |
|
3203 | 3200 | cbase = r.chainbase(rev) |
|
3204 | 3201 | clen = r.chainlen(rev) |
|
3205 | 3202 | p1, p2 = r.parentrevs(rev) |
|
3206 | 3203 | rs = r.rawsize(rev) |
|
3207 | 3204 | ts = ts + rs |
|
3208 | 3205 | heads -= set(r.parentrevs(rev)) |
|
3209 | 3206 | heads.add(rev) |
|
3210 | 3207 | ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d " |
|
3211 | 3208 | "%11d %5d %8d\n" % |
|
3212 | 3209 | (rev, p1, p2, r.start(rev), r.end(rev), |
|
3213 | 3210 | r.start(dbase), r.start(cbase), |
|
3214 | 3211 | r.start(p1), r.start(p2), |
|
3215 | 3212 | rs, ts, ts / r.end(rev), len(heads), clen)) |
|
3216 | 3213 | return 0 |
|
3217 | 3214 | |
|
3218 | 3215 | v = r.version |
|
3219 | 3216 | format = v & 0xFFFF |
|
3220 | 3217 | flags = [] |
|
3221 | 3218 | gdelta = False |
|
3222 | 3219 | if v & revlog.REVLOGNGINLINEDATA: |
|
3223 | 3220 | flags.append('inline') |
|
3224 | 3221 | if v & revlog.REVLOGGENERALDELTA: |
|
3225 | 3222 | gdelta = True |
|
3226 | 3223 | flags.append('generaldelta') |
|
3227 | 3224 | if not flags: |
|
3228 | 3225 | flags = ['(none)'] |
|
3229 | 3226 | |
|
3230 | 3227 | nummerges = 0 |
|
3231 | 3228 | numfull = 0 |
|
3232 | 3229 | numprev = 0 |
|
3233 | 3230 | nump1 = 0 |
|
3234 | 3231 | nump2 = 0 |
|
3235 | 3232 | numother = 0 |
|
3236 | 3233 | nump1prev = 0 |
|
3237 | 3234 | nump2prev = 0 |
|
3238 | 3235 | chainlengths = [] |
|
3239 | 3236 | |
|
3240 | 3237 | datasize = [None, 0, 0L] |
|
3241 | 3238 | fullsize = [None, 0, 0L] |
|
3242 | 3239 | deltasize = [None, 0, 0L] |
|
3243 | 3240 | |
|
3244 | 3241 | def addsize(size, l): |
|
3245 | 3242 | if l[0] is None or size < l[0]: |
|
3246 | 3243 | l[0] = size |
|
3247 | 3244 | if size > l[1]: |
|
3248 | 3245 | l[1] = size |
|
3249 | 3246 | l[2] += size |
|
3250 | 3247 | |
|
3251 | 3248 | numrevs = len(r) |
|
3252 | 3249 | for rev in xrange(numrevs): |
|
3253 | 3250 | p1, p2 = r.parentrevs(rev) |
|
3254 | 3251 | delta = r.deltaparent(rev) |
|
3255 | 3252 | if format > 0: |
|
3256 | 3253 | addsize(r.rawsize(rev), datasize) |
|
3257 | 3254 | if p2 != nullrev: |
|
3258 | 3255 | nummerges += 1 |
|
3259 | 3256 | size = r.length(rev) |
|
3260 | 3257 | if delta == nullrev: |
|
3261 | 3258 | chainlengths.append(0) |
|
3262 | 3259 | numfull += 1 |
|
3263 | 3260 | addsize(size, fullsize) |
|
3264 | 3261 | else: |
|
3265 | 3262 | chainlengths.append(chainlengths[delta] + 1) |
|
3266 | 3263 | addsize(size, deltasize) |
|
3267 | 3264 | if delta == rev - 1: |
|
3268 | 3265 | numprev += 1 |
|
3269 | 3266 | if delta == p1: |
|
3270 | 3267 | nump1prev += 1 |
|
3271 | 3268 | elif delta == p2: |
|
3272 | 3269 | nump2prev += 1 |
|
3273 | 3270 | elif delta == p1: |
|
3274 | 3271 | nump1 += 1 |
|
3275 | 3272 | elif delta == p2: |
|
3276 | 3273 | nump2 += 1 |
|
3277 | 3274 | elif delta != nullrev: |
|
3278 | 3275 | numother += 1 |
|
3279 | 3276 | |
|
3280 | 3277 | # Adjust size min value for empty cases |
|
3281 | 3278 | for size in (datasize, fullsize, deltasize): |
|
3282 | 3279 | if size[0] is None: |
|
3283 | 3280 | size[0] = 0 |
|
3284 | 3281 | |
|
3285 | 3282 | numdeltas = numrevs - numfull |
|
3286 | 3283 | numoprev = numprev - nump1prev - nump2prev |
|
3287 | 3284 | totalrawsize = datasize[2] |
|
3288 | 3285 | datasize[2] /= numrevs |
|
3289 | 3286 | fulltotal = fullsize[2] |
|
3290 | 3287 | fullsize[2] /= numfull |
|
3291 | 3288 | deltatotal = deltasize[2] |
|
3292 | 3289 | if numrevs - numfull > 0: |
|
3293 | 3290 | deltasize[2] /= numrevs - numfull |
|
3294 | 3291 | totalsize = fulltotal + deltatotal |
|
3295 | 3292 | avgchainlen = sum(chainlengths) / numrevs |
|
3296 | 3293 | maxchainlen = max(chainlengths) |
|
3297 | 3294 | compratio = 1 |
|
3298 | 3295 | if totalsize: |
|
3299 | 3296 | compratio = totalrawsize / totalsize |
|
3300 | 3297 | |
|
3301 | 3298 | basedfmtstr = '%%%dd\n' |
|
3302 | 3299 | basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' |
|
3303 | 3300 | |
|
3304 | 3301 | def dfmtstr(max): |
|
3305 | 3302 | return basedfmtstr % len(str(max)) |
|
3306 | 3303 | def pcfmtstr(max, padding=0): |
|
3307 | 3304 | return basepcfmtstr % (len(str(max)), ' ' * padding) |
|
3308 | 3305 | |
|
3309 | 3306 | def pcfmt(value, total): |
|
3310 | 3307 | if total: |
|
3311 | 3308 | return (value, 100 * float(value) / total) |
|
3312 | 3309 | else: |
|
3313 | 3310 | return value, 100.0 |
|
3314 | 3311 | |
|
3315 | 3312 | ui.write(('format : %d\n') % format) |
|
3316 | 3313 | ui.write(('flags : %s\n') % ', '.join(flags)) |
|
3317 | 3314 | |
|
3318 | 3315 | ui.write('\n') |
|
3319 | 3316 | fmt = pcfmtstr(totalsize) |
|
3320 | 3317 | fmt2 = dfmtstr(totalsize) |
|
3321 | 3318 | ui.write(('revisions : ') + fmt2 % numrevs) |
|
3322 | 3319 | ui.write((' merges : ') + fmt % pcfmt(nummerges, numrevs)) |
|
3323 | 3320 | ui.write((' normal : ') + fmt % pcfmt(numrevs - nummerges, numrevs)) |
|
3324 | 3321 | ui.write(('revisions : ') + fmt2 % numrevs) |
|
3325 | 3322 | ui.write((' full : ') + fmt % pcfmt(numfull, numrevs)) |
|
3326 | 3323 | ui.write((' deltas : ') + fmt % pcfmt(numdeltas, numrevs)) |
|
3327 | 3324 | ui.write(('revision size : ') + fmt2 % totalsize) |
|
3328 | 3325 | ui.write((' full : ') + fmt % pcfmt(fulltotal, totalsize)) |
|
3329 | 3326 | ui.write((' deltas : ') + fmt % pcfmt(deltatotal, totalsize)) |
|
3330 | 3327 | |
|
3331 | 3328 | ui.write('\n') |
|
3332 | 3329 | fmt = dfmtstr(max(avgchainlen, compratio)) |
|
3333 | 3330 | ui.write(('avg chain length : ') + fmt % avgchainlen) |
|
3334 | 3331 | ui.write(('max chain length : ') + fmt % maxchainlen) |
|
3335 | 3332 | ui.write(('compression ratio : ') + fmt % compratio) |
|
3336 | 3333 | |
|
3337 | 3334 | if format > 0: |
|
3338 | 3335 | ui.write('\n') |
|
3339 | 3336 | ui.write(('uncompressed data size (min/max/avg) : %d / %d / %d\n') |
|
3340 | 3337 | % tuple(datasize)) |
|
3341 | 3338 | ui.write(('full revision size (min/max/avg) : %d / %d / %d\n') |
|
3342 | 3339 | % tuple(fullsize)) |
|
3343 | 3340 | ui.write(('delta size (min/max/avg) : %d / %d / %d\n') |
|
3344 | 3341 | % tuple(deltasize)) |
|
3345 | 3342 | |
|
3346 | 3343 | if numdeltas > 0: |
|
3347 | 3344 | ui.write('\n') |
|
3348 | 3345 | fmt = pcfmtstr(numdeltas) |
|
3349 | 3346 | fmt2 = pcfmtstr(numdeltas, 4) |
|
3350 | 3347 | ui.write(('deltas against prev : ') + fmt % pcfmt(numprev, numdeltas)) |
|
3351 | 3348 | if numprev > 0: |
|
3352 | 3349 | ui.write((' where prev = p1 : ') + fmt2 % pcfmt(nump1prev, |
|
3353 | 3350 | numprev)) |
|
3354 | 3351 | ui.write((' where prev = p2 : ') + fmt2 % pcfmt(nump2prev, |
|
3355 | 3352 | numprev)) |
|
3356 | 3353 | ui.write((' other : ') + fmt2 % pcfmt(numoprev, |
|
3357 | 3354 | numprev)) |
|
3358 | 3355 | if gdelta: |
|
3359 | 3356 | ui.write(('deltas against p1 : ') |
|
3360 | 3357 | + fmt % pcfmt(nump1, numdeltas)) |
|
3361 | 3358 | ui.write(('deltas against p2 : ') |
|
3362 | 3359 | + fmt % pcfmt(nump2, numdeltas)) |
|
3363 | 3360 | ui.write(('deltas against other : ') + fmt % pcfmt(numother, |
|
3364 | 3361 | numdeltas)) |
|
3365 | 3362 | |
|
3366 | 3363 | @command('debugrevspec', |
|
3367 | 3364 | [('', 'optimize', None, _('print parsed tree after optimizing'))], |
|
3368 | 3365 | ('REVSPEC')) |
|
3369 | 3366 | def debugrevspec(ui, repo, expr, **opts): |
|
3370 | 3367 | """parse and apply a revision specification |
|
3371 | 3368 | |
|
3372 | 3369 | Use --verbose to print the parsed tree before and after aliases |
|
3373 | 3370 | expansion. |
|
3374 | 3371 | """ |
|
3375 | 3372 | if ui.verbose: |
|
3376 | 3373 | tree = revset.parse(expr, lookup=repo.__contains__) |
|
3377 | 3374 | ui.note(revset.prettyformat(tree), "\n") |
|
3378 | 3375 | newtree = revset.findaliases(ui, tree) |
|
3379 | 3376 | if newtree != tree: |
|
3380 | 3377 | ui.note(revset.prettyformat(newtree), "\n") |
|
3381 | 3378 | tree = newtree |
|
3382 | 3379 | newtree = revset.foldconcat(tree) |
|
3383 | 3380 | if newtree != tree: |
|
3384 | 3381 | ui.note(revset.prettyformat(newtree), "\n") |
|
3385 | 3382 | if opts["optimize"]: |
|
3386 | 3383 | weight, optimizedtree = revset.optimize(newtree, True) |
|
3387 | 3384 | ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n") |
|
3388 | 3385 | func = revset.match(ui, expr, repo) |
|
3389 | 3386 | revs = func(repo) |
|
3390 | 3387 | if ui.verbose: |
|
3391 | 3388 | ui.note("* set:\n", revset.prettyformatset(revs), "\n") |
|
3392 | 3389 | for c in revs: |
|
3393 | 3390 | ui.write("%s\n" % c) |
|
3394 | 3391 | |
|
3395 | 3392 | @command('debugsetparents', [], _('REV1 [REV2]')) |
|
3396 | 3393 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
3397 | 3394 | """manually set the parents of the current working directory |
|
3398 | 3395 | |
|
3399 | 3396 | This is useful for writing repository conversion tools, but should |
|
3400 | 3397 | be used with care. For example, neither the working directory nor the |
|
3401 | 3398 | dirstate is updated, so file status may be incorrect after running this |
|
3402 | 3399 | command. |
|
3403 | 3400 | |
|
3404 | 3401 | Returns 0 on success. |
|
3405 | 3402 | """ |
|
3406 | 3403 | |
|
3407 | 3404 | r1 = scmutil.revsingle(repo, rev1).node() |
|
3408 | 3405 | r2 = scmutil.revsingle(repo, rev2, 'null').node() |
|
3409 | 3406 | |
|
3410 | 3407 | with repo.wlock(): |
|
3411 | 3408 | repo.dirstate.beginparentchange() |
|
3412 | 3409 | repo.setparents(r1, r2) |
|
3413 | 3410 | repo.dirstate.endparentchange() |
|
3414 | 3411 | |
|
3415 | 3412 | @command('debugdirstate|debugstate', |
|
3416 | 3413 | [('', 'nodates', None, _('do not display the saved mtime')), |
|
3417 | 3414 | ('', 'datesort', None, _('sort by saved mtime'))], |
|
3418 | 3415 | _('[OPTION]...')) |
|
3419 | 3416 | def debugstate(ui, repo, **opts): |
|
3420 | 3417 | """show the contents of the current dirstate""" |
|
3421 | 3418 | |
|
3422 | 3419 | nodates = opts.get('nodates') |
|
3423 | 3420 | datesort = opts.get('datesort') |
|
3424 | 3421 | |
|
3425 | 3422 | timestr = "" |
|
3426 | 3423 | if datesort: |
|
3427 | 3424 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename |
|
3428 | 3425 | else: |
|
3429 | 3426 | keyfunc = None # sort by filename |
|
3430 | 3427 | for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): |
|
3431 | 3428 | if ent[3] == -1: |
|
3432 | 3429 | timestr = 'unset ' |
|
3433 | 3430 | elif nodates: |
|
3434 | 3431 | timestr = 'set ' |
|
3435 | 3432 | else: |
|
3436 | 3433 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", |
|
3437 | 3434 | time.localtime(ent[3])) |
|
3438 | 3435 | if ent[1] & 0o20000: |
|
3439 | 3436 | mode = 'lnk' |
|
3440 | 3437 | else: |
|
3441 | 3438 | mode = '%3o' % (ent[1] & 0o777 & ~util.umask) |
|
3442 | 3439 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
3443 | 3440 | for f in repo.dirstate.copies(): |
|
3444 | 3441 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
3445 | 3442 | |
|
3446 | 3443 | @command('debugsub', |
|
3447 | 3444 | [('r', 'rev', '', |
|
3448 | 3445 | _('revision to check'), _('REV'))], |
|
3449 | 3446 | _('[-r REV] [REV]')) |
|
3450 | 3447 | def debugsub(ui, repo, rev=None): |
|
3451 | 3448 | ctx = scmutil.revsingle(repo, rev, None) |
|
3452 | 3449 | for k, v in sorted(ctx.substate.items()): |
|
3453 | 3450 | ui.write(('path %s\n') % k) |
|
3454 | 3451 | ui.write((' source %s\n') % v[0]) |
|
3455 | 3452 | ui.write((' revision %s\n') % v[1]) |
|
3456 | 3453 | |
|
3457 | 3454 | @command('debugsuccessorssets', |
|
3458 | 3455 | [], |
|
3459 | 3456 | _('[REV]')) |
|
3460 | 3457 | def debugsuccessorssets(ui, repo, *revs): |
|
3461 | 3458 | """show set of successors for revision |
|
3462 | 3459 | |
|
3463 | 3460 | A successors set of changeset A is a consistent group of revisions that |
|
3464 | 3461 | succeed A. It contains non-obsolete changesets only. |
|
3465 | 3462 | |
|
3466 | 3463 | In most cases a changeset A has a single successors set containing a single |
|
3467 | 3464 | successor (changeset A replaced by A'). |
|
3468 | 3465 | |
|
3469 | 3466 | A changeset that is made obsolete with no successors are called "pruned". |
|
3470 | 3467 | Such changesets have no successors sets at all. |
|
3471 | 3468 | |
|
3472 | 3469 | A changeset that has been "split" will have a successors set containing |
|
3473 | 3470 | more than one successor. |
|
3474 | 3471 | |
|
3475 | 3472 | A changeset that has been rewritten in multiple different ways is called |
|
3476 | 3473 | "divergent". Such changesets have multiple successor sets (each of which |
|
3477 | 3474 | may also be split, i.e. have multiple successors). |
|
3478 | 3475 | |
|
3479 | 3476 | Results are displayed as follows:: |
|
3480 | 3477 | |
|
3481 | 3478 | <rev1> |
|
3482 | 3479 | <successors-1A> |
|
3483 | 3480 | <rev2> |
|
3484 | 3481 | <successors-2A> |
|
3485 | 3482 | <successors-2B1> <successors-2B2> <successors-2B3> |
|
3486 | 3483 | |
|
3487 | 3484 | Here rev2 has two possible (i.e. divergent) successors sets. The first |
|
3488 | 3485 | holds one element, whereas the second holds three (i.e. the changeset has |
|
3489 | 3486 | been split). |
|
3490 | 3487 | """ |
|
3491 | 3488 | # passed to successorssets caching computation from one call to another |
|
3492 | 3489 | cache = {} |
|
3493 | 3490 | ctx2str = str |
|
3494 | 3491 | node2str = short |
|
3495 | 3492 | if ui.debug(): |
|
3496 | 3493 | def ctx2str(ctx): |
|
3497 | 3494 | return ctx.hex() |
|
3498 | 3495 | node2str = hex |
|
3499 | 3496 | for rev in scmutil.revrange(repo, revs): |
|
3500 | 3497 | ctx = repo[rev] |
|
3501 | 3498 | ui.write('%s\n'% ctx2str(ctx)) |
|
3502 | 3499 | for succsset in obsolete.successorssets(repo, ctx.node(), cache): |
|
3503 | 3500 | if succsset: |
|
3504 | 3501 | ui.write(' ') |
|
3505 | 3502 | ui.write(node2str(succsset[0])) |
|
3506 | 3503 | for node in succsset[1:]: |
|
3507 | 3504 | ui.write(' ') |
|
3508 | 3505 | ui.write(node2str(node)) |
|
3509 | 3506 | ui.write('\n') |
|
3510 | 3507 | |
|
3511 | 3508 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True) |
|
3512 | 3509 | def debugwalk(ui, repo, *pats, **opts): |
|
3513 | 3510 | """show how files match on given patterns""" |
|
3514 | 3511 | m = scmutil.match(repo[None], pats, opts) |
|
3515 | 3512 | items = list(repo.walk(m)) |
|
3516 | 3513 | if not items: |
|
3517 | 3514 | return |
|
3518 | 3515 | f = lambda fn: fn |
|
3519 | 3516 | if ui.configbool('ui', 'slash') and os.sep != '/': |
|
3520 | 3517 | f = lambda fn: util.normpath(fn) |
|
3521 | 3518 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
3522 | 3519 | max([len(abs) for abs in items]), |
|
3523 | 3520 | max([len(m.rel(abs)) for abs in items])) |
|
3524 | 3521 | for abs in items: |
|
3525 | 3522 | line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '') |
|
3526 | 3523 | ui.write("%s\n" % line.rstrip()) |
|
3527 | 3524 | |
|
3528 | 3525 | @command('debugwireargs', |
|
3529 | 3526 | [('', 'three', '', 'three'), |
|
3530 | 3527 | ('', 'four', '', 'four'), |
|
3531 | 3528 | ('', 'five', '', 'five'), |
|
3532 | 3529 | ] + remoteopts, |
|
3533 | 3530 | _('REPO [OPTIONS]... [ONE [TWO]]'), |
|
3534 | 3531 | norepo=True) |
|
3535 | 3532 | def debugwireargs(ui, repopath, *vals, **opts): |
|
3536 | 3533 | repo = hg.peer(ui, opts, repopath) |
|
3537 | 3534 | for opt in remoteopts: |
|
3538 | 3535 | del opts[opt[1]] |
|
3539 | 3536 | args = {} |
|
3540 | 3537 | for k, v in opts.iteritems(): |
|
3541 | 3538 | if v: |
|
3542 | 3539 | args[k] = v |
|
3543 | 3540 | # run twice to check that we don't mess up the stream for the next command |
|
3544 | 3541 | res1 = repo.debugwireargs(*vals, **args) |
|
3545 | 3542 | res2 = repo.debugwireargs(*vals, **args) |
|
3546 | 3543 | ui.write("%s\n" % res1) |
|
3547 | 3544 | if res1 != res2: |
|
3548 | 3545 | ui.warn("%s\n" % res2) |
|
3549 | 3546 | |
|
3550 | 3547 | @command('^diff', |
|
3551 | 3548 | [('r', 'rev', [], _('revision'), _('REV')), |
|
3552 | 3549 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
3553 | 3550 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
3554 | 3551 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), |
|
3555 | 3552 | inferrepo=True) |
|
3556 | 3553 | def diff(ui, repo, *pats, **opts): |
|
3557 | 3554 | """diff repository (or selected files) |
|
3558 | 3555 | |
|
3559 | 3556 | Show differences between revisions for the specified files. |
|
3560 | 3557 | |
|
3561 | 3558 | Differences between files are shown using the unified diff format. |
|
3562 | 3559 | |
|
3563 | 3560 | .. note:: |
|
3564 | 3561 | |
|
3565 | 3562 | :hg:`diff` may generate unexpected results for merges, as it will |
|
3566 | 3563 | default to comparing against the working directory's first |
|
3567 | 3564 | parent changeset if no revisions are specified. |
|
3568 | 3565 | |
|
3569 | 3566 | When two revision arguments are given, then changes are shown |
|
3570 | 3567 | between those revisions. If only one revision is specified then |
|
3571 | 3568 | that revision is compared to the working directory, and, when no |
|
3572 | 3569 | revisions are specified, the working directory files are compared |
|
3573 | 3570 | to its first parent. |
|
3574 | 3571 | |
|
3575 | 3572 | Alternatively you can specify -c/--change with a revision to see |
|
3576 | 3573 | the changes in that changeset relative to its first parent. |
|
3577 | 3574 | |
|
3578 | 3575 | Without the -a/--text option, diff will avoid generating diffs of |
|
3579 | 3576 | files it detects as binary. With -a, diff will generate a diff |
|
3580 | 3577 | anyway, probably with undesirable results. |
|
3581 | 3578 | |
|
3582 | 3579 | Use the -g/--git option to generate diffs in the git extended diff |
|
3583 | 3580 | format. For more information, read :hg:`help diffs`. |
|
3584 | 3581 | |
|
3585 | 3582 | .. container:: verbose |
|
3586 | 3583 | |
|
3587 | 3584 | Examples: |
|
3588 | 3585 | |
|
3589 | 3586 | - compare a file in the current working directory to its parent:: |
|
3590 | 3587 | |
|
3591 | 3588 | hg diff foo.c |
|
3592 | 3589 | |
|
3593 | 3590 | - compare two historical versions of a directory, with rename info:: |
|
3594 | 3591 | |
|
3595 | 3592 | hg diff --git -r 1.0:1.2 lib/ |
|
3596 | 3593 | |
|
3597 | 3594 | - get change stats relative to the last change on some date:: |
|
3598 | 3595 | |
|
3599 | 3596 | hg diff --stat -r "date('may 2')" |
|
3600 | 3597 | |
|
3601 | 3598 | - diff all newly-added files that contain a keyword:: |
|
3602 | 3599 | |
|
3603 | 3600 | hg diff "set:added() and grep(GNU)" |
|
3604 | 3601 | |
|
3605 | 3602 | - compare a revision and its parents:: |
|
3606 | 3603 | |
|
3607 | 3604 | hg diff -c 9353 # compare against first parent |
|
3608 | 3605 | hg diff -r 9353^:9353 # same using revset syntax |
|
3609 | 3606 | hg diff -r 9353^2:9353 # compare against the second parent |
|
3610 | 3607 | |
|
3611 | 3608 | Returns 0 on success. |
|
3612 | 3609 | """ |
|
3613 | 3610 | |
|
3614 | 3611 | revs = opts.get('rev') |
|
3615 | 3612 | change = opts.get('change') |
|
3616 | 3613 | stat = opts.get('stat') |
|
3617 | 3614 | reverse = opts.get('reverse') |
|
3618 | 3615 | |
|
3619 | 3616 | if revs and change: |
|
3620 | 3617 | msg = _('cannot specify --rev and --change at the same time') |
|
3621 | 3618 | raise error.Abort(msg) |
|
3622 | 3619 | elif change: |
|
3623 | 3620 | node2 = scmutil.revsingle(repo, change, None).node() |
|
3624 | 3621 | node1 = repo[node2].p1().node() |
|
3625 | 3622 | else: |
|
3626 | 3623 | node1, node2 = scmutil.revpair(repo, revs) |
|
3627 | 3624 | |
|
3628 | 3625 | if reverse: |
|
3629 | 3626 | node1, node2 = node2, node1 |
|
3630 | 3627 | |
|
3631 | 3628 | diffopts = patch.diffallopts(ui, opts) |
|
3632 | 3629 | m = scmutil.match(repo[node2], pats, opts) |
|
3633 | 3630 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
3634 | 3631 | listsubrepos=opts.get('subrepos'), |
|
3635 | 3632 | root=opts.get('root')) |
|
3636 | 3633 | |
|
3637 | 3634 | @command('^export', |
|
3638 | 3635 | [('o', 'output', '', |
|
3639 | 3636 | _('print output to file with formatted name'), _('FORMAT')), |
|
3640 | 3637 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
3641 | 3638 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
3642 | 3639 | ] + diffopts, |
|
3643 | 3640 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...')) |
|
3644 | 3641 | def export(ui, repo, *changesets, **opts): |
|
3645 | 3642 | """dump the header and diffs for one or more changesets |
|
3646 | 3643 | |
|
3647 | 3644 | Print the changeset header and diffs for one or more revisions. |
|
3648 | 3645 | If no revision is given, the parent of the working directory is used. |
|
3649 | 3646 | |
|
3650 | 3647 | The information shown in the changeset header is: author, date, |
|
3651 | 3648 | branch name (if non-default), changeset hash, parent(s) and commit |
|
3652 | 3649 | comment. |
|
3653 | 3650 | |
|
3654 | 3651 | .. note:: |
|
3655 | 3652 | |
|
3656 | 3653 | :hg:`export` may generate unexpected diff output for merge |
|
3657 | 3654 | changesets, as it will compare the merge changeset against its |
|
3658 | 3655 | first parent only. |
|
3659 | 3656 | |
|
3660 | 3657 | Output may be to a file, in which case the name of the file is |
|
3661 | 3658 | given using a format string. The formatting rules are as follows: |
|
3662 | 3659 | |
|
3663 | 3660 | :``%%``: literal "%" character |
|
3664 | 3661 | :``%H``: changeset hash (40 hexadecimal digits) |
|
3665 | 3662 | :``%N``: number of patches being generated |
|
3666 | 3663 | :``%R``: changeset revision number |
|
3667 | 3664 | :``%b``: basename of the exporting repository |
|
3668 | 3665 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
3669 | 3666 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
3670 | 3667 | :``%n``: zero-padded sequence number, starting at 1 |
|
3671 | 3668 | :``%r``: zero-padded changeset revision number |
|
3672 | 3669 | |
|
3673 | 3670 | Without the -a/--text option, export will avoid generating diffs |
|
3674 | 3671 | of files it detects as binary. With -a, export will generate a |
|
3675 | 3672 | diff anyway, probably with undesirable results. |
|
3676 | 3673 | |
|
3677 | 3674 | Use the -g/--git option to generate diffs in the git extended diff |
|
3678 | 3675 | format. See :hg:`help diffs` for more information. |
|
3679 | 3676 | |
|
3680 | 3677 | With the --switch-parent option, the diff will be against the |
|
3681 | 3678 | second parent. It can be useful to review a merge. |
|
3682 | 3679 | |
|
3683 | 3680 | .. container:: verbose |
|
3684 | 3681 | |
|
3685 | 3682 | Examples: |
|
3686 | 3683 | |
|
3687 | 3684 | - use export and import to transplant a bugfix to the current |
|
3688 | 3685 | branch:: |
|
3689 | 3686 | |
|
3690 | 3687 | hg export -r 9353 | hg import - |
|
3691 | 3688 | |
|
3692 | 3689 | - export all the changesets between two revisions to a file with |
|
3693 | 3690 | rename information:: |
|
3694 | 3691 | |
|
3695 | 3692 | hg export --git -r 123:150 > changes.txt |
|
3696 | 3693 | |
|
3697 | 3694 | - split outgoing changes into a series of patches with |
|
3698 | 3695 | descriptive names:: |
|
3699 | 3696 | |
|
3700 | 3697 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
3701 | 3698 | |
|
3702 | 3699 | Returns 0 on success. |
|
3703 | 3700 | """ |
|
3704 | 3701 | changesets += tuple(opts.get('rev', [])) |
|
3705 | 3702 | if not changesets: |
|
3706 | 3703 | changesets = ['.'] |
|
3707 | 3704 | revs = scmutil.revrange(repo, changesets) |
|
3708 | 3705 | if not revs: |
|
3709 | 3706 | raise error.Abort(_("export requires at least one changeset")) |
|
3710 | 3707 | if len(revs) > 1: |
|
3711 | 3708 | ui.note(_('exporting patches:\n')) |
|
3712 | 3709 | else: |
|
3713 | 3710 | ui.note(_('exporting patch:\n')) |
|
3714 | 3711 | cmdutil.export(repo, revs, template=opts.get('output'), |
|
3715 | 3712 | switch_parent=opts.get('switch_parent'), |
|
3716 | 3713 | opts=patch.diffallopts(ui, opts)) |
|
3717 | 3714 | |
|
3718 | 3715 | @command('files', |
|
3719 | 3716 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3720 | 3717 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3721 | 3718 | ] + walkopts + formatteropts + subrepoopts, |
|
3722 | 3719 | _('[OPTION]... [PATTERN]...')) |
|
3723 | 3720 | def files(ui, repo, *pats, **opts): |
|
3724 | 3721 | """list tracked files |
|
3725 | 3722 | |
|
3726 | 3723 | Print files under Mercurial control in the working directory or |
|
3727 | 3724 | specified revision whose names match the given patterns (excluding |
|
3728 | 3725 | removed files). |
|
3729 | 3726 | |
|
3730 | 3727 | If no patterns are given to match, this command prints the names |
|
3731 | 3728 | of all files under Mercurial control in the working directory. |
|
3732 | 3729 | |
|
3733 | 3730 | .. container:: verbose |
|
3734 | 3731 | |
|
3735 | 3732 | Examples: |
|
3736 | 3733 | |
|
3737 | 3734 | - list all files under the current directory:: |
|
3738 | 3735 | |
|
3739 | 3736 | hg files . |
|
3740 | 3737 | |
|
3741 | 3738 | - shows sizes and flags for current revision:: |
|
3742 | 3739 | |
|
3743 | 3740 | hg files -vr . |
|
3744 | 3741 | |
|
3745 | 3742 | - list all files named README:: |
|
3746 | 3743 | |
|
3747 | 3744 | hg files -I "**/README" |
|
3748 | 3745 | |
|
3749 | 3746 | - list all binary files:: |
|
3750 | 3747 | |
|
3751 | 3748 | hg files "set:binary()" |
|
3752 | 3749 | |
|
3753 | 3750 | - find files containing a regular expression:: |
|
3754 | 3751 | |
|
3755 | 3752 | hg files "set:grep('bob')" |
|
3756 | 3753 | |
|
3757 | 3754 | - search tracked file contents with xargs and grep:: |
|
3758 | 3755 | |
|
3759 | 3756 | hg files -0 | xargs -0 grep foo |
|
3760 | 3757 | |
|
3761 | 3758 | See :hg:`help patterns` and :hg:`help filesets` for more information |
|
3762 | 3759 | on specifying file patterns. |
|
3763 | 3760 | |
|
3764 | 3761 | Returns 0 if a match is found, 1 otherwise. |
|
3765 | 3762 | |
|
3766 | 3763 | """ |
|
3767 | 3764 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
3768 | 3765 | |
|
3769 | 3766 | end = '\n' |
|
3770 | 3767 | if opts.get('print0'): |
|
3771 | 3768 | end = '\0' |
|
3772 | 3769 | fm = ui.formatter('files', opts) |
|
3773 | 3770 | fmt = '%s' + end |
|
3774 | 3771 | |
|
3775 | 3772 | m = scmutil.match(ctx, pats, opts) |
|
3776 | 3773 | ret = cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) |
|
3777 | 3774 | |
|
3778 | 3775 | fm.end() |
|
3779 | 3776 | |
|
3780 | 3777 | return ret |
|
3781 | 3778 | |
|
3782 | 3779 | @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) |
|
3783 | 3780 | def forget(ui, repo, *pats, **opts): |
|
3784 | 3781 | """forget the specified files on the next commit |
|
3785 | 3782 | |
|
3786 | 3783 | Mark the specified files so they will no longer be tracked |
|
3787 | 3784 | after the next commit. |
|
3788 | 3785 | |
|
3789 | 3786 | This only removes files from the current branch, not from the |
|
3790 | 3787 | entire project history, and it does not delete them from the |
|
3791 | 3788 | working directory. |
|
3792 | 3789 | |
|
3793 | 3790 | To delete the file from the working directory, see :hg:`remove`. |
|
3794 | 3791 | |
|
3795 | 3792 | To undo a forget before the next commit, see :hg:`add`. |
|
3796 | 3793 | |
|
3797 | 3794 | .. container:: verbose |
|
3798 | 3795 | |
|
3799 | 3796 | Examples: |
|
3800 | 3797 | |
|
3801 | 3798 | - forget newly-added binary files:: |
|
3802 | 3799 | |
|
3803 | 3800 | hg forget "set:added() and binary()" |
|
3804 | 3801 | |
|
3805 | 3802 | - forget files that would be excluded by .hgignore:: |
|
3806 | 3803 | |
|
3807 | 3804 | hg forget "set:hgignore()" |
|
3808 | 3805 | |
|
3809 | 3806 | Returns 0 on success. |
|
3810 | 3807 | """ |
|
3811 | 3808 | |
|
3812 | 3809 | if not pats: |
|
3813 | 3810 | raise error.Abort(_('no files specified')) |
|
3814 | 3811 | |
|
3815 | 3812 | m = scmutil.match(repo[None], pats, opts) |
|
3816 | 3813 | rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] |
|
3817 | 3814 | return rejected and 1 or 0 |
|
3818 | 3815 | |
|
3819 | 3816 | @command( |
|
3820 | 3817 | 'graft', |
|
3821 | 3818 | [('r', 'rev', [], _('revisions to graft'), _('REV')), |
|
3822 | 3819 | ('c', 'continue', False, _('resume interrupted graft')), |
|
3823 | 3820 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
3824 | 3821 | ('', 'log', None, _('append graft info to log message')), |
|
3825 | 3822 | ('f', 'force', False, _('force graft')), |
|
3826 | 3823 | ('D', 'currentdate', False, |
|
3827 | 3824 | _('record the current date as commit date')), |
|
3828 | 3825 | ('U', 'currentuser', False, |
|
3829 | 3826 | _('record the current user as committer'), _('DATE'))] |
|
3830 | 3827 | + commitopts2 + mergetoolopts + dryrunopts, |
|
3831 | 3828 | _('[OPTION]... [-r REV]... REV...')) |
|
3832 | 3829 | def graft(ui, repo, *revs, **opts): |
|
3833 | 3830 | '''copy changes from other branches onto the current branch |
|
3834 | 3831 | |
|
3835 | 3832 | This command uses Mercurial's merge logic to copy individual |
|
3836 | 3833 | changes from other branches without merging branches in the |
|
3837 | 3834 | history graph. This is sometimes known as 'backporting' or |
|
3838 | 3835 | 'cherry-picking'. By default, graft will copy user, date, and |
|
3839 | 3836 | description from the source changesets. |
|
3840 | 3837 | |
|
3841 | 3838 | Changesets that are ancestors of the current revision, that have |
|
3842 | 3839 | already been grafted, or that are merges will be skipped. |
|
3843 | 3840 | |
|
3844 | 3841 | If --log is specified, log messages will have a comment appended |
|
3845 | 3842 | of the form:: |
|
3846 | 3843 | |
|
3847 | 3844 | (grafted from CHANGESETHASH) |
|
3848 | 3845 | |
|
3849 | 3846 | If --force is specified, revisions will be grafted even if they |
|
3850 | 3847 | are already ancestors of or have been grafted to the destination. |
|
3851 | 3848 | This is useful when the revisions have since been backed out. |
|
3852 | 3849 | |
|
3853 | 3850 | If a graft merge results in conflicts, the graft process is |
|
3854 | 3851 | interrupted so that the current merge can be manually resolved. |
|
3855 | 3852 | Once all conflicts are addressed, the graft process can be |
|
3856 | 3853 | continued with the -c/--continue option. |
|
3857 | 3854 | |
|
3858 | 3855 | .. note:: |
|
3859 | 3856 | |
|
3860 | 3857 | The -c/--continue option does not reapply earlier options, except |
|
3861 | 3858 | for --force. |
|
3862 | 3859 | |
|
3863 | 3860 | .. container:: verbose |
|
3864 | 3861 | |
|
3865 | 3862 | Examples: |
|
3866 | 3863 | |
|
3867 | 3864 | - copy a single change to the stable branch and edit its description:: |
|
3868 | 3865 | |
|
3869 | 3866 | hg update stable |
|
3870 | 3867 | hg graft --edit 9393 |
|
3871 | 3868 | |
|
3872 | 3869 | - graft a range of changesets with one exception, updating dates:: |
|
3873 | 3870 | |
|
3874 | 3871 | hg graft -D "2085::2093 and not 2091" |
|
3875 | 3872 | |
|
3876 | 3873 | - continue a graft after resolving conflicts:: |
|
3877 | 3874 | |
|
3878 | 3875 | hg graft -c |
|
3879 | 3876 | |
|
3880 | 3877 | - show the source of a grafted changeset:: |
|
3881 | 3878 | |
|
3882 | 3879 | hg log --debug -r . |
|
3883 | 3880 | |
|
3884 | 3881 | - show revisions sorted by date:: |
|
3885 | 3882 | |
|
3886 | 3883 | hg log -r 'sort(all(), date)' |
|
3887 | 3884 | |
|
3888 | 3885 | See :hg:`help revisions` and :hg:`help revsets` for more about |
|
3889 | 3886 | specifying revisions. |
|
3890 | 3887 | |
|
3891 | 3888 | Returns 0 on successful completion. |
|
3892 | 3889 | ''' |
|
3893 | 3890 | with repo.wlock(): |
|
3894 | 3891 | return _dograft(ui, repo, *revs, **opts) |
|
3895 | 3892 | |
|
3896 | 3893 | def _dograft(ui, repo, *revs, **opts): |
|
3897 | 3894 | if revs and opts['rev']: |
|
3898 | 3895 | ui.warn(_('warning: inconsistent use of --rev might give unexpected ' |
|
3899 | 3896 | 'revision ordering!\n')) |
|
3900 | 3897 | |
|
3901 | 3898 | revs = list(revs) |
|
3902 | 3899 | revs.extend(opts['rev']) |
|
3903 | 3900 | |
|
3904 | 3901 | if not opts.get('user') and opts.get('currentuser'): |
|
3905 | 3902 | opts['user'] = ui.username() |
|
3906 | 3903 | if not opts.get('date') and opts.get('currentdate'): |
|
3907 | 3904 | opts['date'] = "%d %d" % util.makedate() |
|
3908 | 3905 | |
|
3909 | 3906 | editor = cmdutil.getcommiteditor(editform='graft', **opts) |
|
3910 | 3907 | |
|
3911 | 3908 | cont = False |
|
3912 | 3909 | if opts['continue']: |
|
3913 | 3910 | cont = True |
|
3914 | 3911 | if revs: |
|
3915 | 3912 | raise error.Abort(_("can't specify --continue and revisions")) |
|
3916 | 3913 | # read in unfinished revisions |
|
3917 | 3914 | try: |
|
3918 | 3915 | nodes = repo.vfs.read('graftstate').splitlines() |
|
3919 | 3916 | revs = [repo[node].rev() for node in nodes] |
|
3920 | 3917 | except IOError as inst: |
|
3921 | 3918 | if inst.errno != errno.ENOENT: |
|
3922 | 3919 | raise |
|
3923 | 3920 | raise error.Abort(_("no graft state found, can't continue")) |
|
3924 | 3921 | else: |
|
3925 | 3922 | cmdutil.checkunfinished(repo) |
|
3926 | 3923 | cmdutil.bailifchanged(repo) |
|
3927 | 3924 | if not revs: |
|
3928 | 3925 | raise error.Abort(_('no revisions specified')) |
|
3929 | 3926 | revs = scmutil.revrange(repo, revs) |
|
3930 | 3927 | |
|
3931 | 3928 | skipped = set() |
|
3932 | 3929 | # check for merges |
|
3933 | 3930 | for rev in repo.revs('%ld and merge()', revs): |
|
3934 | 3931 | ui.warn(_('skipping ungraftable merge revision %s\n') % rev) |
|
3935 | 3932 | skipped.add(rev) |
|
3936 | 3933 | revs = [r for r in revs if r not in skipped] |
|
3937 | 3934 | if not revs: |
|
3938 | 3935 | return -1 |
|
3939 | 3936 | |
|
3940 | 3937 | # Don't check in the --continue case, in effect retaining --force across |
|
3941 | 3938 | # --continues. That's because without --force, any revisions we decided to |
|
3942 | 3939 | # skip would have been filtered out here, so they wouldn't have made their |
|
3943 | 3940 | # way to the graftstate. With --force, any revisions we would have otherwise |
|
3944 | 3941 | # skipped would not have been filtered out, and if they hadn't been applied |
|
3945 | 3942 | # already, they'd have been in the graftstate. |
|
3946 | 3943 | if not (cont or opts.get('force')): |
|
3947 | 3944 | # check for ancestors of dest branch |
|
3948 | 3945 | crev = repo['.'].rev() |
|
3949 | 3946 | ancestors = repo.changelog.ancestors([crev], inclusive=True) |
|
3950 | 3947 | # Cannot use x.remove(y) on smart set, this has to be a list. |
|
3951 | 3948 | # XXX make this lazy in the future |
|
3952 | 3949 | revs = list(revs) |
|
3953 | 3950 | # don't mutate while iterating, create a copy |
|
3954 | 3951 | for rev in list(revs): |
|
3955 | 3952 | if rev in ancestors: |
|
3956 | 3953 | ui.warn(_('skipping ancestor revision %d:%s\n') % |
|
3957 | 3954 | (rev, repo[rev])) |
|
3958 | 3955 | # XXX remove on list is slow |
|
3959 | 3956 | revs.remove(rev) |
|
3960 | 3957 | if not revs: |
|
3961 | 3958 | return -1 |
|
3962 | 3959 | |
|
3963 | 3960 | # analyze revs for earlier grafts |
|
3964 | 3961 | ids = {} |
|
3965 | 3962 | for ctx in repo.set("%ld", revs): |
|
3966 | 3963 | ids[ctx.hex()] = ctx.rev() |
|
3967 | 3964 | n = ctx.extra().get('source') |
|
3968 | 3965 | if n: |
|
3969 | 3966 | ids[n] = ctx.rev() |
|
3970 | 3967 | |
|
3971 | 3968 | # check ancestors for earlier grafts |
|
3972 | 3969 | ui.debug('scanning for duplicate grafts\n') |
|
3973 | 3970 | |
|
3974 | 3971 | for rev in repo.changelog.findmissingrevs(revs, [crev]): |
|
3975 | 3972 | ctx = repo[rev] |
|
3976 | 3973 | n = ctx.extra().get('source') |
|
3977 | 3974 | if n in ids: |
|
3978 | 3975 | try: |
|
3979 | 3976 | r = repo[n].rev() |
|
3980 | 3977 | except error.RepoLookupError: |
|
3981 | 3978 | r = None |
|
3982 | 3979 | if r in revs: |
|
3983 | 3980 | ui.warn(_('skipping revision %d:%s ' |
|
3984 | 3981 | '(already grafted to %d:%s)\n') |
|
3985 | 3982 | % (r, repo[r], rev, ctx)) |
|
3986 | 3983 | revs.remove(r) |
|
3987 | 3984 | elif ids[n] in revs: |
|
3988 | 3985 | if r is None: |
|
3989 | 3986 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
3990 | 3987 | '(%d:%s also has unknown origin %s)\n') |
|
3991 | 3988 | % (ids[n], repo[ids[n]], rev, ctx, n[:12])) |
|
3992 | 3989 | else: |
|
3993 | 3990 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
3994 | 3991 | '(%d:%s also has origin %d:%s)\n') |
|
3995 | 3992 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) |
|
3996 | 3993 | revs.remove(ids[n]) |
|
3997 | 3994 | elif ctx.hex() in ids: |
|
3998 | 3995 | r = ids[ctx.hex()] |
|
3999 | 3996 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
4000 | 3997 | '(was grafted from %d:%s)\n') % |
|
4001 | 3998 | (r, repo[r], rev, ctx)) |
|
4002 | 3999 | revs.remove(r) |
|
4003 | 4000 | if not revs: |
|
4004 | 4001 | return -1 |
|
4005 | 4002 | |
|
4006 | 4003 | for pos, ctx in enumerate(repo.set("%ld", revs)): |
|
4007 | 4004 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, |
|
4008 | 4005 | ctx.description().split('\n', 1)[0]) |
|
4009 | 4006 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
|
4010 | 4007 | if names: |
|
4011 | 4008 | desc += ' (%s)' % ' '.join(names) |
|
4012 | 4009 | ui.status(_('grafting %s\n') % desc) |
|
4013 | 4010 | if opts.get('dry_run'): |
|
4014 | 4011 | continue |
|
4015 | 4012 | |
|
4016 | 4013 | extra = ctx.extra().copy() |
|
4017 | 4014 | del extra['branch'] |
|
4018 | 4015 | source = extra.get('source') |
|
4019 | 4016 | if source: |
|
4020 | 4017 | extra['intermediate-source'] = ctx.hex() |
|
4021 | 4018 | else: |
|
4022 | 4019 | extra['source'] = ctx.hex() |
|
4023 | 4020 | user = ctx.user() |
|
4024 | 4021 | if opts.get('user'): |
|
4025 | 4022 | user = opts['user'] |
|
4026 | 4023 | date = ctx.date() |
|
4027 | 4024 | if opts.get('date'): |
|
4028 | 4025 | date = opts['date'] |
|
4029 | 4026 | message = ctx.description() |
|
4030 | 4027 | if opts.get('log'): |
|
4031 | 4028 | message += '\n(grafted from %s)' % ctx.hex() |
|
4032 | 4029 | |
|
4033 | 4030 | # we don't merge the first commit when continuing |
|
4034 | 4031 | if not cont: |
|
4035 | 4032 | # perform the graft merge with p1(rev) as 'ancestor' |
|
4036 | 4033 | try: |
|
4037 | 4034 | # ui.forcemerge is an internal variable, do not document |
|
4038 | 4035 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
4039 | 4036 | 'graft') |
|
4040 | 4037 | stats = mergemod.graft(repo, ctx, ctx.p1(), |
|
4041 | 4038 | ['local', 'graft']) |
|
4042 | 4039 | finally: |
|
4043 | 4040 | repo.ui.setconfig('ui', 'forcemerge', '', 'graft') |
|
4044 | 4041 | # report any conflicts |
|
4045 | 4042 | if stats and stats[3] > 0: |
|
4046 | 4043 | # write out state for --continue |
|
4047 | 4044 | nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] |
|
4048 | 4045 | repo.vfs.write('graftstate', ''.join(nodelines)) |
|
4049 | 4046 | extra = '' |
|
4050 | 4047 | if opts.get('user'): |
|
4051 | 4048 | extra += ' --user %s' % opts['user'] |
|
4052 | 4049 | if opts.get('date'): |
|
4053 | 4050 | extra += ' --date %s' % opts['date'] |
|
4054 | 4051 | if opts.get('log'): |
|
4055 | 4052 | extra += ' --log' |
|
4056 | 4053 | hint=_('use hg resolve and hg graft --continue%s') % extra |
|
4057 | 4054 | raise error.Abort( |
|
4058 | 4055 | _("unresolved conflicts, can't continue"), |
|
4059 | 4056 | hint=hint) |
|
4060 | 4057 | else: |
|
4061 | 4058 | cont = False |
|
4062 | 4059 | |
|
4063 | 4060 | # commit |
|
4064 | 4061 | node = repo.commit(text=message, user=user, |
|
4065 | 4062 | date=date, extra=extra, editor=editor) |
|
4066 | 4063 | if node is None: |
|
4067 | 4064 | ui.warn( |
|
4068 | 4065 | _('note: graft of %d:%s created no changes to commit\n') % |
|
4069 | 4066 | (ctx.rev(), ctx)) |
|
4070 | 4067 | |
|
4071 | 4068 | # remove state when we complete successfully |
|
4072 | 4069 | if not opts.get('dry_run'): |
|
4073 | 4070 | util.unlinkpath(repo.join('graftstate'), ignoremissing=True) |
|
4074 | 4071 | |
|
4075 | 4072 | return 0 |
|
4076 | 4073 | |
|
4077 | 4074 | @command('grep', |
|
4078 | 4075 | [('0', 'print0', None, _('end fields with NUL')), |
|
4079 | 4076 | ('', 'all', None, _('print all revisions that match')), |
|
4080 | 4077 | ('a', 'text', None, _('treat all files as text')), |
|
4081 | 4078 | ('f', 'follow', None, |
|
4082 | 4079 | _('follow changeset history,' |
|
4083 | 4080 | ' or file history across copies and renames')), |
|
4084 | 4081 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
4085 | 4082 | ('l', 'files-with-matches', None, |
|
4086 | 4083 | _('print only filenames and revisions that match')), |
|
4087 | 4084 | ('n', 'line-number', None, _('print matching line numbers')), |
|
4088 | 4085 | ('r', 'rev', [], |
|
4089 | 4086 | _('only search files changed within revision range'), _('REV')), |
|
4090 | 4087 | ('u', 'user', None, _('list the author (long with -v)')), |
|
4091 | 4088 | ('d', 'date', None, _('list the date (short with -q)')), |
|
4092 | 4089 | ] + walkopts, |
|
4093 | 4090 | _('[OPTION]... PATTERN [FILE]...'), |
|
4094 | 4091 | inferrepo=True) |
|
4095 | 4092 | def grep(ui, repo, pattern, *pats, **opts): |
|
4096 | 4093 | """search for a pattern in specified files and revisions |
|
4097 | 4094 | |
|
4098 | 4095 | Search revisions of files for a regular expression. |
|
4099 | 4096 | |
|
4100 | 4097 | This command behaves differently than Unix grep. It only accepts |
|
4101 | 4098 | Python/Perl regexps. It searches repository history, not the |
|
4102 | 4099 | working directory. It always prints the revision number in which a |
|
4103 | 4100 | match appears. |
|
4104 | 4101 | |
|
4105 | 4102 | By default, grep only prints output for the first revision of a |
|
4106 | 4103 | file in which it finds a match. To get it to print every revision |
|
4107 | 4104 | that contains a change in match status ("-" for a match that |
|
4108 | 4105 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
4109 | 4106 | use the --all flag. |
|
4110 | 4107 | |
|
4111 | 4108 | Returns 0 if a match is found, 1 otherwise. |
|
4112 | 4109 | """ |
|
4113 | 4110 | reflags = re.M |
|
4114 | 4111 | if opts.get('ignore_case'): |
|
4115 | 4112 | reflags |= re.I |
|
4116 | 4113 | try: |
|
4117 | 4114 | regexp = util.re.compile(pattern, reflags) |
|
4118 | 4115 | except re.error as inst: |
|
4119 | 4116 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
4120 | 4117 | return 1 |
|
4121 | 4118 | sep, eol = ':', '\n' |
|
4122 | 4119 | if opts.get('print0'): |
|
4123 | 4120 | sep = eol = '\0' |
|
4124 | 4121 | |
|
4125 | 4122 | getfile = util.lrucachefunc(repo.file) |
|
4126 | 4123 | |
|
4127 | 4124 | def matchlines(body): |
|
4128 | 4125 | begin = 0 |
|
4129 | 4126 | linenum = 0 |
|
4130 | 4127 | while begin < len(body): |
|
4131 | 4128 | match = regexp.search(body, begin) |
|
4132 | 4129 | if not match: |
|
4133 | 4130 | break |
|
4134 | 4131 | mstart, mend = match.span() |
|
4135 | 4132 | linenum += body.count('\n', begin, mstart) + 1 |
|
4136 | 4133 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
4137 | 4134 | begin = body.find('\n', mend) + 1 or len(body) + 1 |
|
4138 | 4135 | lend = begin - 1 |
|
4139 | 4136 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
4140 | 4137 | |
|
4141 | 4138 | class linestate(object): |
|
4142 | 4139 | def __init__(self, line, linenum, colstart, colend): |
|
4143 | 4140 | self.line = line |
|
4144 | 4141 | self.linenum = linenum |
|
4145 | 4142 | self.colstart = colstart |
|
4146 | 4143 | self.colend = colend |
|
4147 | 4144 | |
|
4148 | 4145 | def __hash__(self): |
|
4149 | 4146 | return hash((self.linenum, self.line)) |
|
4150 | 4147 | |
|
4151 | 4148 | def __eq__(self, other): |
|
4152 | 4149 | return self.line == other.line |
|
4153 | 4150 | |
|
4154 | 4151 | def __iter__(self): |
|
4155 | 4152 | yield (self.line[:self.colstart], '') |
|
4156 | 4153 | yield (self.line[self.colstart:self.colend], 'grep.match') |
|
4157 | 4154 | rest = self.line[self.colend:] |
|
4158 | 4155 | while rest != '': |
|
4159 | 4156 | match = regexp.search(rest) |
|
4160 | 4157 | if not match: |
|
4161 | 4158 | yield (rest, '') |
|
4162 | 4159 | break |
|
4163 | 4160 | mstart, mend = match.span() |
|
4164 | 4161 | yield (rest[:mstart], '') |
|
4165 | 4162 | yield (rest[mstart:mend], 'grep.match') |
|
4166 | 4163 | rest = rest[mend:] |
|
4167 | 4164 | |
|
4168 | 4165 | matches = {} |
|
4169 | 4166 | copies = {} |
|
4170 | 4167 | def grepbody(fn, rev, body): |
|
4171 | 4168 | matches[rev].setdefault(fn, []) |
|
4172 | 4169 | m = matches[rev][fn] |
|
4173 | 4170 | for lnum, cstart, cend, line in matchlines(body): |
|
4174 | 4171 | s = linestate(line, lnum, cstart, cend) |
|
4175 | 4172 | m.append(s) |
|
4176 | 4173 | |
|
4177 | 4174 | def difflinestates(a, b): |
|
4178 | 4175 | sm = difflib.SequenceMatcher(None, a, b) |
|
4179 | 4176 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
4180 | 4177 | if tag == 'insert': |
|
4181 | 4178 | for i in xrange(blo, bhi): |
|
4182 | 4179 | yield ('+', b[i]) |
|
4183 | 4180 | elif tag == 'delete': |
|
4184 | 4181 | for i in xrange(alo, ahi): |
|
4185 | 4182 | yield ('-', a[i]) |
|
4186 | 4183 | elif tag == 'replace': |
|
4187 | 4184 | for i in xrange(alo, ahi): |
|
4188 | 4185 | yield ('-', a[i]) |
|
4189 | 4186 | for i in xrange(blo, bhi): |
|
4190 | 4187 | yield ('+', b[i]) |
|
4191 | 4188 | |
|
4192 | 4189 | def display(fn, ctx, pstates, states): |
|
4193 | 4190 | rev = ctx.rev() |
|
4194 | 4191 | if ui.quiet: |
|
4195 | 4192 | datefunc = util.shortdate |
|
4196 | 4193 | else: |
|
4197 | 4194 | datefunc = util.datestr |
|
4198 | 4195 | found = False |
|
4199 | 4196 | @util.cachefunc |
|
4200 | 4197 | def binary(): |
|
4201 | 4198 | flog = getfile(fn) |
|
4202 | 4199 | return util.binary(flog.read(ctx.filenode(fn))) |
|
4203 | 4200 | |
|
4204 | 4201 | if opts.get('all'): |
|
4205 | 4202 | iter = difflinestates(pstates, states) |
|
4206 | 4203 | else: |
|
4207 | 4204 | iter = [('', l) for l in states] |
|
4208 | 4205 | for change, l in iter: |
|
4209 | 4206 | cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')] |
|
4210 | 4207 | |
|
4211 | 4208 | if opts.get('line_number'): |
|
4212 | 4209 | cols.append((str(l.linenum), 'grep.linenumber')) |
|
4213 | 4210 | if opts.get('all'): |
|
4214 | 4211 | cols.append((change, 'grep.change')) |
|
4215 | 4212 | if opts.get('user'): |
|
4216 | 4213 | cols.append((ui.shortuser(ctx.user()), 'grep.user')) |
|
4217 | 4214 | if opts.get('date'): |
|
4218 | 4215 | cols.append((datefunc(ctx.date()), 'grep.date')) |
|
4219 | 4216 | for col, label in cols[:-1]: |
|
4220 | 4217 | ui.write(col, label=label) |
|
4221 | 4218 | ui.write(sep, label='grep.sep') |
|
4222 | 4219 | ui.write(cols[-1][0], label=cols[-1][1]) |
|
4223 | 4220 | if not opts.get('files_with_matches'): |
|
4224 | 4221 | ui.write(sep, label='grep.sep') |
|
4225 | 4222 | if not opts.get('text') and binary(): |
|
4226 | 4223 | ui.write(" Binary file matches") |
|
4227 | 4224 | else: |
|
4228 | 4225 | for s, label in l: |
|
4229 | 4226 | ui.write(s, label=label) |
|
4230 | 4227 | ui.write(eol) |
|
4231 | 4228 | found = True |
|
4232 | 4229 | if opts.get('files_with_matches'): |
|
4233 | 4230 | break |
|
4234 | 4231 | return found |
|
4235 | 4232 | |
|
4236 | 4233 | skip = {} |
|
4237 | 4234 | revfiles = {} |
|
4238 | 4235 | matchfn = scmutil.match(repo[None], pats, opts) |
|
4239 | 4236 | found = False |
|
4240 | 4237 | follow = opts.get('follow') |
|
4241 | 4238 | |
|
4242 | 4239 | def prep(ctx, fns): |
|
4243 | 4240 | rev = ctx.rev() |
|
4244 | 4241 | pctx = ctx.p1() |
|
4245 | 4242 | parent = pctx.rev() |
|
4246 | 4243 | matches.setdefault(rev, {}) |
|
4247 | 4244 | matches.setdefault(parent, {}) |
|
4248 | 4245 | files = revfiles.setdefault(rev, []) |
|
4249 | 4246 | for fn in fns: |
|
4250 | 4247 | flog = getfile(fn) |
|
4251 | 4248 | try: |
|
4252 | 4249 | fnode = ctx.filenode(fn) |
|
4253 | 4250 | except error.LookupError: |
|
4254 | 4251 | continue |
|
4255 | 4252 | |
|
4256 | 4253 | copied = flog.renamed(fnode) |
|
4257 | 4254 | copy = follow and copied and copied[0] |
|
4258 | 4255 | if copy: |
|
4259 | 4256 | copies.setdefault(rev, {})[fn] = copy |
|
4260 | 4257 | if fn in skip: |
|
4261 | 4258 | if copy: |
|
4262 | 4259 | skip[copy] = True |
|
4263 | 4260 | continue |
|
4264 | 4261 | files.append(fn) |
|
4265 | 4262 | |
|
4266 | 4263 | if fn not in matches[rev]: |
|
4267 | 4264 | grepbody(fn, rev, flog.read(fnode)) |
|
4268 | 4265 | |
|
4269 | 4266 | pfn = copy or fn |
|
4270 | 4267 | if pfn not in matches[parent]: |
|
4271 | 4268 | try: |
|
4272 | 4269 | fnode = pctx.filenode(pfn) |
|
4273 | 4270 | grepbody(pfn, parent, flog.read(fnode)) |
|
4274 | 4271 | except error.LookupError: |
|
4275 | 4272 | pass |
|
4276 | 4273 | |
|
4277 | 4274 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
4278 | 4275 | rev = ctx.rev() |
|
4279 | 4276 | parent = ctx.p1().rev() |
|
4280 | 4277 | for fn in sorted(revfiles.get(rev, [])): |
|
4281 | 4278 | states = matches[rev][fn] |
|
4282 | 4279 | copy = copies.get(rev, {}).get(fn) |
|
4283 | 4280 | if fn in skip: |
|
4284 | 4281 | if copy: |
|
4285 | 4282 | skip[copy] = True |
|
4286 | 4283 | continue |
|
4287 | 4284 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
4288 | 4285 | if pstates or states: |
|
4289 | 4286 | r = display(fn, ctx, pstates, states) |
|
4290 | 4287 | found = found or r |
|
4291 | 4288 | if r and not opts.get('all'): |
|
4292 | 4289 | skip[fn] = True |
|
4293 | 4290 | if copy: |
|
4294 | 4291 | skip[copy] = True |
|
4295 | 4292 | del matches[rev] |
|
4296 | 4293 | del revfiles[rev] |
|
4297 | 4294 | |
|
4298 | 4295 | return not found |
|
4299 | 4296 | |
|
4300 | 4297 | @command('heads', |
|
4301 | 4298 | [('r', 'rev', '', |
|
4302 | 4299 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
4303 | 4300 | ('t', 'topo', False, _('show topological heads only')), |
|
4304 | 4301 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
4305 | 4302 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
4306 | 4303 | ] + templateopts, |
|
4307 | 4304 | _('[-ct] [-r STARTREV] [REV]...')) |
|
4308 | 4305 | def heads(ui, repo, *branchrevs, **opts): |
|
4309 | 4306 | """show branch heads |
|
4310 | 4307 | |
|
4311 | 4308 | With no arguments, show all open branch heads in the repository. |
|
4312 | 4309 | Branch heads are changesets that have no descendants on the |
|
4313 | 4310 | same branch. They are where development generally takes place and |
|
4314 | 4311 | are the usual targets for update and merge operations. |
|
4315 | 4312 | |
|
4316 | 4313 | If one or more REVs are given, only open branch heads on the |
|
4317 | 4314 | branches associated with the specified changesets are shown. This |
|
4318 | 4315 | means that you can use :hg:`heads .` to see the heads on the |
|
4319 | 4316 | currently checked-out branch. |
|
4320 | 4317 | |
|
4321 | 4318 | If -c/--closed is specified, also show branch heads marked closed |
|
4322 | 4319 | (see :hg:`commit --close-branch`). |
|
4323 | 4320 | |
|
4324 | 4321 | If STARTREV is specified, only those heads that are descendants of |
|
4325 | 4322 | STARTREV will be displayed. |
|
4326 | 4323 | |
|
4327 | 4324 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
4328 | 4325 | topological heads (changesets with no children) will be shown. |
|
4329 | 4326 | |
|
4330 | 4327 | Returns 0 if matching heads are found, 1 if not. |
|
4331 | 4328 | """ |
|
4332 | 4329 | |
|
4333 | 4330 | start = None |
|
4334 | 4331 | if 'rev' in opts: |
|
4335 | 4332 | start = scmutil.revsingle(repo, opts['rev'], None).node() |
|
4336 | 4333 | |
|
4337 | 4334 | if opts.get('topo'): |
|
4338 | 4335 | heads = [repo[h] for h in repo.heads(start)] |
|
4339 | 4336 | else: |
|
4340 | 4337 | heads = [] |
|
4341 | 4338 | for branch in repo.branchmap(): |
|
4342 | 4339 | heads += repo.branchheads(branch, start, opts.get('closed')) |
|
4343 | 4340 | heads = [repo[h] for h in heads] |
|
4344 | 4341 | |
|
4345 | 4342 | if branchrevs: |
|
4346 | 4343 | branches = set(repo[br].branch() for br in branchrevs) |
|
4347 | 4344 | heads = [h for h in heads if h.branch() in branches] |
|
4348 | 4345 | |
|
4349 | 4346 | if opts.get('active') and branchrevs: |
|
4350 | 4347 | dagheads = repo.heads(start) |
|
4351 | 4348 | heads = [h for h in heads if h.node() in dagheads] |
|
4352 | 4349 | |
|
4353 | 4350 | if branchrevs: |
|
4354 | 4351 | haveheads = set(h.branch() for h in heads) |
|
4355 | 4352 | if branches - haveheads: |
|
4356 | 4353 | headless = ', '.join(b for b in branches - haveheads) |
|
4357 | 4354 | msg = _('no open branch heads found on branches %s') |
|
4358 | 4355 | if opts.get('rev'): |
|
4359 | 4356 | msg += _(' (started at %s)') % opts['rev'] |
|
4360 | 4357 | ui.warn((msg + '\n') % headless) |
|
4361 | 4358 | |
|
4362 | 4359 | if not heads: |
|
4363 | 4360 | return 1 |
|
4364 | 4361 | |
|
4365 | 4362 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
4366 | 4363 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4367 | 4364 | for ctx in heads: |
|
4368 | 4365 | displayer.show(ctx) |
|
4369 | 4366 | displayer.close() |
|
4370 | 4367 | |
|
4371 | 4368 | @command('help', |
|
4372 | 4369 | [('e', 'extension', None, _('show only help for extensions')), |
|
4373 | 4370 | ('c', 'command', None, _('show only help for commands')), |
|
4374 | 4371 | ('k', 'keyword', None, _('show topics matching keyword')), |
|
4375 | 4372 | ('s', 'system', [], _('show help for specific platform(s)')), |
|
4376 | 4373 | ], |
|
4377 | 4374 | _('[-ecks] [TOPIC]'), |
|
4378 | 4375 | norepo=True) |
|
4379 | 4376 | def help_(ui, name=None, **opts): |
|
4380 | 4377 | """show help for a given topic or a help overview |
|
4381 | 4378 | |
|
4382 | 4379 | With no arguments, print a list of commands with short help messages. |
|
4383 | 4380 | |
|
4384 | 4381 | Given a topic, extension, or command name, print help for that |
|
4385 | 4382 | topic. |
|
4386 | 4383 | |
|
4387 | 4384 | Returns 0 if successful. |
|
4388 | 4385 | """ |
|
4389 | 4386 | |
|
4390 | 4387 | textwidth = min(ui.termwidth(), 80) - 2 |
|
4391 | 4388 | |
|
4392 | 4389 | keep = opts.get('system') or [] |
|
4393 | 4390 | if len(keep) == 0: |
|
4394 | 4391 | if sys.platform.startswith('win'): |
|
4395 | 4392 | keep.append('windows') |
|
4396 | 4393 | elif sys.platform == 'OpenVMS': |
|
4397 | 4394 | keep.append('vms') |
|
4398 | 4395 | elif sys.platform == 'plan9': |
|
4399 | 4396 | keep.append('plan9') |
|
4400 | 4397 | else: |
|
4401 | 4398 | keep.append('unix') |
|
4402 | 4399 | keep.append(sys.platform.lower()) |
|
4403 | 4400 | if ui.verbose: |
|
4404 | 4401 | keep.append('verbose') |
|
4405 | 4402 | |
|
4406 | 4403 | section = None |
|
4407 | 4404 | subtopic = None |
|
4408 | 4405 | if name and '.' in name: |
|
4409 | 4406 | name, section = name.split('.', 1) |
|
4410 | 4407 | section = section.lower() |
|
4411 | 4408 | if '.' in section: |
|
4412 | 4409 | subtopic, section = section.split('.', 1) |
|
4413 | 4410 | else: |
|
4414 | 4411 | subtopic = section |
|
4415 | 4412 | |
|
4416 | 4413 | text = help.help_(ui, name, subtopic=subtopic, **opts) |
|
4417 | 4414 | |
|
4418 | 4415 | formatted, pruned = minirst.format(text, textwidth, keep=keep, |
|
4419 | 4416 | section=section) |
|
4420 | 4417 | |
|
4421 | 4418 | # We could have been given a weird ".foo" section without a name |
|
4422 | 4419 | # to look for, or we could have simply failed to found "foo.bar" |
|
4423 | 4420 | # because bar isn't a section of foo |
|
4424 | 4421 | if section and not (formatted and name): |
|
4425 | 4422 | raise error.Abort(_("help section not found")) |
|
4426 | 4423 | |
|
4427 | 4424 | if 'verbose' in pruned: |
|
4428 | 4425 | keep.append('omitted') |
|
4429 | 4426 | else: |
|
4430 | 4427 | keep.append('notomitted') |
|
4431 | 4428 | formatted, pruned = minirst.format(text, textwidth, keep=keep, |
|
4432 | 4429 | section=section) |
|
4433 | 4430 | ui.write(formatted) |
|
4434 | 4431 | |
|
4435 | 4432 | |
|
4436 | 4433 | @command('identify|id', |
|
4437 | 4434 | [('r', 'rev', '', |
|
4438 | 4435 | _('identify the specified revision'), _('REV')), |
|
4439 | 4436 | ('n', 'num', None, _('show local revision number')), |
|
4440 | 4437 | ('i', 'id', None, _('show global revision id')), |
|
4441 | 4438 | ('b', 'branch', None, _('show branch')), |
|
4442 | 4439 | ('t', 'tags', None, _('show tags')), |
|
4443 | 4440 | ('B', 'bookmarks', None, _('show bookmarks')), |
|
4444 | 4441 | ] + remoteopts, |
|
4445 | 4442 | _('[-nibtB] [-r REV] [SOURCE]'), |
|
4446 | 4443 | optionalrepo=True) |
|
4447 | 4444 | def identify(ui, repo, source=None, rev=None, |
|
4448 | 4445 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): |
|
4449 | 4446 | """identify the working directory or specified revision |
|
4450 | 4447 | |
|
4451 | 4448 | Print a summary identifying the repository state at REV using one or |
|
4452 | 4449 | two parent hash identifiers, followed by a "+" if the working |
|
4453 | 4450 | directory has uncommitted changes, the branch name (if not default), |
|
4454 | 4451 | a list of tags, and a list of bookmarks. |
|
4455 | 4452 | |
|
4456 | 4453 | When REV is not given, print a summary of the current state of the |
|
4457 | 4454 | repository. |
|
4458 | 4455 | |
|
4459 | 4456 | Specifying a path to a repository root or Mercurial bundle will |
|
4460 | 4457 | cause lookup to operate on that repository/bundle. |
|
4461 | 4458 | |
|
4462 | 4459 | .. container:: verbose |
|
4463 | 4460 | |
|
4464 | 4461 | Examples: |
|
4465 | 4462 | |
|
4466 | 4463 | - generate a build identifier for the working directory:: |
|
4467 | 4464 | |
|
4468 | 4465 | hg id --id > build-id.dat |
|
4469 | 4466 | |
|
4470 | 4467 | - find the revision corresponding to a tag:: |
|
4471 | 4468 | |
|
4472 | 4469 | hg id -n -r 1.3 |
|
4473 | 4470 | |
|
4474 | 4471 | - check the most recent revision of a remote repository:: |
|
4475 | 4472 | |
|
4476 | 4473 | hg id -r tip http://selenic.com/hg/ |
|
4477 | 4474 | |
|
4478 | 4475 | See :hg:`log` for generating more information about specific revisions, |
|
4479 | 4476 | including full hash identifiers. |
|
4480 | 4477 | |
|
4481 | 4478 | Returns 0 if successful. |
|
4482 | 4479 | """ |
|
4483 | 4480 | |
|
4484 | 4481 | if not repo and not source: |
|
4485 | 4482 | raise error.Abort(_("there is no Mercurial repository here " |
|
4486 | 4483 | "(.hg not found)")) |
|
4487 | 4484 | |
|
4488 | 4485 | if ui.debugflag: |
|
4489 | 4486 | hexfunc = hex |
|
4490 | 4487 | else: |
|
4491 | 4488 | hexfunc = short |
|
4492 | 4489 | default = not (num or id or branch or tags or bookmarks) |
|
4493 | 4490 | output = [] |
|
4494 | 4491 | revs = [] |
|
4495 | 4492 | |
|
4496 | 4493 | if source: |
|
4497 | 4494 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
4498 | 4495 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo |
|
4499 | 4496 | repo = peer.local() |
|
4500 | 4497 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) |
|
4501 | 4498 | |
|
4502 | 4499 | if not repo: |
|
4503 | 4500 | if num or branch or tags: |
|
4504 | 4501 | raise error.Abort( |
|
4505 | 4502 | _("can't query remote revision number, branch, or tags")) |
|
4506 | 4503 | if not rev and revs: |
|
4507 | 4504 | rev = revs[0] |
|
4508 | 4505 | if not rev: |
|
4509 | 4506 | rev = "tip" |
|
4510 | 4507 | |
|
4511 | 4508 | remoterev = peer.lookup(rev) |
|
4512 | 4509 | if default or id: |
|
4513 | 4510 | output = [hexfunc(remoterev)] |
|
4514 | 4511 | |
|
4515 | 4512 | def getbms(): |
|
4516 | 4513 | bms = [] |
|
4517 | 4514 | |
|
4518 | 4515 | if 'bookmarks' in peer.listkeys('namespaces'): |
|
4519 | 4516 | hexremoterev = hex(remoterev) |
|
4520 | 4517 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() |
|
4521 | 4518 | if bmr == hexremoterev] |
|
4522 | 4519 | |
|
4523 | 4520 | return sorted(bms) |
|
4524 | 4521 | |
|
4525 | 4522 | if bookmarks: |
|
4526 | 4523 | output.extend(getbms()) |
|
4527 | 4524 | elif default and not ui.quiet: |
|
4528 | 4525 | # multiple bookmarks for a single parent separated by '/' |
|
4529 | 4526 | bm = '/'.join(getbms()) |
|
4530 | 4527 | if bm: |
|
4531 | 4528 | output.append(bm) |
|
4532 | 4529 | else: |
|
4533 | 4530 | ctx = scmutil.revsingle(repo, rev, None) |
|
4534 | 4531 | |
|
4535 | 4532 | if ctx.rev() is None: |
|
4536 | 4533 | ctx = repo[None] |
|
4537 | 4534 | parents = ctx.parents() |
|
4538 | 4535 | taglist = [] |
|
4539 | 4536 | for p in parents: |
|
4540 | 4537 | taglist.extend(p.tags()) |
|
4541 | 4538 | |
|
4542 | 4539 | changed = "" |
|
4543 | 4540 | if default or id or num: |
|
4544 | 4541 | if (any(repo.status()) |
|
4545 | 4542 | or any(ctx.sub(s).dirty() for s in ctx.substate)): |
|
4546 | 4543 | changed = '+' |
|
4547 | 4544 | if default or id: |
|
4548 | 4545 | output = ["%s%s" % |
|
4549 | 4546 | ('+'.join([hexfunc(p.node()) for p in parents]), changed)] |
|
4550 | 4547 | if num: |
|
4551 | 4548 | output.append("%s%s" % |
|
4552 | 4549 | ('+'.join([str(p.rev()) for p in parents]), changed)) |
|
4553 | 4550 | else: |
|
4554 | 4551 | if default or id: |
|
4555 | 4552 | output = [hexfunc(ctx.node())] |
|
4556 | 4553 | if num: |
|
4557 | 4554 | output.append(str(ctx.rev())) |
|
4558 | 4555 | taglist = ctx.tags() |
|
4559 | 4556 | |
|
4560 | 4557 | if default and not ui.quiet: |
|
4561 | 4558 | b = ctx.branch() |
|
4562 | 4559 | if b != 'default': |
|
4563 | 4560 | output.append("(%s)" % b) |
|
4564 | 4561 | |
|
4565 | 4562 | # multiple tags for a single parent separated by '/' |
|
4566 | 4563 | t = '/'.join(taglist) |
|
4567 | 4564 | if t: |
|
4568 | 4565 | output.append(t) |
|
4569 | 4566 | |
|
4570 | 4567 | # multiple bookmarks for a single parent separated by '/' |
|
4571 | 4568 | bm = '/'.join(ctx.bookmarks()) |
|
4572 | 4569 | if bm: |
|
4573 | 4570 | output.append(bm) |
|
4574 | 4571 | else: |
|
4575 | 4572 | if branch: |
|
4576 | 4573 | output.append(ctx.branch()) |
|
4577 | 4574 | |
|
4578 | 4575 | if tags: |
|
4579 | 4576 | output.extend(taglist) |
|
4580 | 4577 | |
|
4581 | 4578 | if bookmarks: |
|
4582 | 4579 | output.extend(ctx.bookmarks()) |
|
4583 | 4580 | |
|
4584 | 4581 | ui.write("%s\n" % ' '.join(output)) |
|
4585 | 4582 | |
|
4586 | 4583 | @command('import|patch', |
|
4587 | 4584 | [('p', 'strip', 1, |
|
4588 | 4585 | _('directory strip option for patch. This has the same ' |
|
4589 | 4586 | 'meaning as the corresponding patch option'), _('NUM')), |
|
4590 | 4587 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), |
|
4591 | 4588 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
4592 | 4589 | ('f', 'force', None, |
|
4593 | 4590 | _('skip check for outstanding uncommitted changes (DEPRECATED)')), |
|
4594 | 4591 | ('', 'no-commit', None, |
|
4595 | 4592 | _("don't commit, just update the working directory")), |
|
4596 | 4593 | ('', 'bypass', None, |
|
4597 | 4594 | _("apply patch without touching the working directory")), |
|
4598 | 4595 | ('', 'partial', None, |
|
4599 | 4596 | _('commit even if some hunks fail')), |
|
4600 | 4597 | ('', 'exact', None, |
|
4601 | 4598 | _('apply patch to the nodes from which it was generated')), |
|
4602 | 4599 | ('', 'prefix', '', |
|
4603 | 4600 | _('apply patch to subdirectory'), _('DIR')), |
|
4604 | 4601 | ('', 'import-branch', None, |
|
4605 | 4602 | _('use any branch information in patch (implied by --exact)'))] + |
|
4606 | 4603 | commitopts + commitopts2 + similarityopts, |
|
4607 | 4604 | _('[OPTION]... PATCH...')) |
|
4608 | 4605 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
4609 | 4606 | """import an ordered set of patches |
|
4610 | 4607 | |
|
4611 | 4608 | Import a list of patches and commit them individually (unless |
|
4612 | 4609 | --no-commit is specified). |
|
4613 | 4610 | |
|
4614 | 4611 | To read a patch from standard input, use "-" as the patch name. If |
|
4615 | 4612 | a URL is specified, the patch will be downloaded from there. |
|
4616 | 4613 | |
|
4617 | 4614 | Import first applies changes to the working directory (unless |
|
4618 | 4615 | --bypass is specified), import will abort if there are outstanding |
|
4619 | 4616 | changes. |
|
4620 | 4617 | |
|
4621 | 4618 | Use --bypass to apply and commit patches directly to the |
|
4622 | 4619 | repository, without affecting the working directory. Without |
|
4623 | 4620 | --exact, patches will be applied on top of the working directory |
|
4624 | 4621 | parent revision. |
|
4625 | 4622 | |
|
4626 | 4623 | You can import a patch straight from a mail message. Even patches |
|
4627 | 4624 | as attachments work (to use the body part, it must have type |
|
4628 | 4625 | text/plain or text/x-patch). From and Subject headers of email |
|
4629 | 4626 | message are used as default committer and commit message. All |
|
4630 | 4627 | text/plain body parts before first diff are added to the commit |
|
4631 | 4628 | message. |
|
4632 | 4629 | |
|
4633 | 4630 | If the imported patch was generated by :hg:`export`, user and |
|
4634 | 4631 | description from patch override values from message headers and |
|
4635 | 4632 | body. Values given on command line with -m/--message and -u/--user |
|
4636 | 4633 | override these. |
|
4637 | 4634 | |
|
4638 | 4635 | If --exact is specified, import will set the working directory to |
|
4639 | 4636 | the parent of each patch before applying it, and will abort if the |
|
4640 | 4637 | resulting changeset has a different ID than the one recorded in |
|
4641 | 4638 | the patch. This may happen due to character set problems or other |
|
4642 | 4639 | deficiencies in the text patch format. |
|
4643 | 4640 | |
|
4644 | 4641 | Use --partial to ensure a changeset will be created from the patch |
|
4645 | 4642 | even if some hunks fail to apply. Hunks that fail to apply will be |
|
4646 | 4643 | written to a <target-file>.rej file. Conflicts can then be resolved |
|
4647 | 4644 | by hand before :hg:`commit --amend` is run to update the created |
|
4648 | 4645 | changeset. This flag exists to let people import patches that |
|
4649 | 4646 | partially apply without losing the associated metadata (author, |
|
4650 | 4647 | date, description, ...). |
|
4651 | 4648 | |
|
4652 | 4649 | .. note:: |
|
4653 | 4650 | |
|
4654 | 4651 | When no hunks apply cleanly, :hg:`import --partial` will create |
|
4655 | 4652 | an empty changeset, importing only the patch metadata. |
|
4656 | 4653 | |
|
4657 | 4654 | With -s/--similarity, hg will attempt to discover renames and |
|
4658 | 4655 | copies in the patch in the same way as :hg:`addremove`. |
|
4659 | 4656 | |
|
4660 | 4657 | It is possible to use external patch programs to perform the patch |
|
4661 | 4658 | by setting the ``ui.patch`` configuration option. For the default |
|
4662 | 4659 | internal tool, the fuzz can also be configured via ``patch.fuzz``. |
|
4663 | 4660 | See :hg:`help config` for more information about configuration |
|
4664 | 4661 | files and how to use these options. |
|
4665 | 4662 | |
|
4666 | 4663 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4667 | 4664 | |
|
4668 | 4665 | .. container:: verbose |
|
4669 | 4666 | |
|
4670 | 4667 | Examples: |
|
4671 | 4668 | |
|
4672 | 4669 | - import a traditional patch from a website and detect renames:: |
|
4673 | 4670 | |
|
4674 | 4671 | hg import -s 80 http://example.com/bugfix.patch |
|
4675 | 4672 | |
|
4676 | 4673 | - import a changeset from an hgweb server:: |
|
4677 | 4674 | |
|
4678 | 4675 | hg import http://www.selenic.com/hg/rev/5ca8c111e9aa |
|
4679 | 4676 | |
|
4680 | 4677 | - import all the patches in an Unix-style mbox:: |
|
4681 | 4678 | |
|
4682 | 4679 | hg import incoming-patches.mbox |
|
4683 | 4680 | |
|
4684 | 4681 | - attempt to exactly restore an exported changeset (not always |
|
4685 | 4682 | possible):: |
|
4686 | 4683 | |
|
4687 | 4684 | hg import --exact proposed-fix.patch |
|
4688 | 4685 | |
|
4689 | 4686 | - use an external tool to apply a patch which is too fuzzy for |
|
4690 | 4687 | the default internal tool. |
|
4691 | 4688 | |
|
4692 | 4689 | hg import --config ui.patch="patch --merge" fuzzy.patch |
|
4693 | 4690 | |
|
4694 | 4691 | - change the default fuzzing from 2 to a less strict 7 |
|
4695 | 4692 | |
|
4696 | 4693 | hg import --config ui.fuzz=7 fuzz.patch |
|
4697 | 4694 | |
|
4698 | 4695 | Returns 0 on success, 1 on partial success (see --partial). |
|
4699 | 4696 | """ |
|
4700 | 4697 | |
|
4701 | 4698 | if not patch1: |
|
4702 | 4699 | raise error.Abort(_('need at least one patch to import')) |
|
4703 | 4700 | |
|
4704 | 4701 | patches = (patch1,) + patches |
|
4705 | 4702 | |
|
4706 | 4703 | date = opts.get('date') |
|
4707 | 4704 | if date: |
|
4708 | 4705 | opts['date'] = util.parsedate(date) |
|
4709 | 4706 | |
|
4710 | 4707 | exact = opts.get('exact') |
|
4711 | 4708 | update = not opts.get('bypass') |
|
4712 | 4709 | if not update and opts.get('no_commit'): |
|
4713 | 4710 | raise error.Abort(_('cannot use --no-commit with --bypass')) |
|
4714 | 4711 | try: |
|
4715 | 4712 | sim = float(opts.get('similarity') or 0) |
|
4716 | 4713 | except ValueError: |
|
4717 | 4714 | raise error.Abort(_('similarity must be a number')) |
|
4718 | 4715 | if sim < 0 or sim > 100: |
|
4719 | 4716 | raise error.Abort(_('similarity must be between 0 and 100')) |
|
4720 | 4717 | if sim and not update: |
|
4721 | 4718 | raise error.Abort(_('cannot use --similarity with --bypass')) |
|
4722 | 4719 | if exact: |
|
4723 | 4720 | if opts.get('edit'): |
|
4724 | 4721 | raise error.Abort(_('cannot use --exact with --edit')) |
|
4725 | 4722 | if opts.get('prefix'): |
|
4726 | 4723 | raise error.Abort(_('cannot use --exact with --prefix')) |
|
4727 | 4724 | |
|
4728 | 4725 | base = opts["base"] |
|
4729 | 4726 | wlock = dsguard = lock = tr = None |
|
4730 | 4727 | msgs = [] |
|
4731 | 4728 | ret = 0 |
|
4732 | 4729 | |
|
4733 | 4730 | |
|
4734 | 4731 | try: |
|
4735 | 4732 | wlock = repo.wlock() |
|
4736 | 4733 | |
|
4737 | 4734 | if update: |
|
4738 | 4735 | cmdutil.checkunfinished(repo) |
|
4739 | 4736 | if (exact or not opts.get('force')): |
|
4740 | 4737 | cmdutil.bailifchanged(repo) |
|
4741 | 4738 | |
|
4742 | 4739 | if not opts.get('no_commit'): |
|
4743 | 4740 | lock = repo.lock() |
|
4744 | 4741 | tr = repo.transaction('import') |
|
4745 | 4742 | else: |
|
4746 | 4743 | dsguard = cmdutil.dirstateguard(repo, 'import') |
|
4747 | 4744 | parents = repo[None].parents() |
|
4748 | 4745 | for patchurl in patches: |
|
4749 | 4746 | if patchurl == '-': |
|
4750 | 4747 | ui.status(_('applying patch from stdin\n')) |
|
4751 | 4748 | patchfile = ui.fin |
|
4752 | 4749 | patchurl = 'stdin' # for error message |
|
4753 | 4750 | else: |
|
4754 | 4751 | patchurl = os.path.join(base, patchurl) |
|
4755 | 4752 | ui.status(_('applying %s\n') % patchurl) |
|
4756 | 4753 | patchfile = hg.openpath(ui, patchurl) |
|
4757 | 4754 | |
|
4758 | 4755 | haspatch = False |
|
4759 | 4756 | for hunk in patch.split(patchfile): |
|
4760 | 4757 | (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, |
|
4761 | 4758 | parents, opts, |
|
4762 | 4759 | msgs, hg.clean) |
|
4763 | 4760 | if msg: |
|
4764 | 4761 | haspatch = True |
|
4765 | 4762 | ui.note(msg + '\n') |
|
4766 | 4763 | if update or exact: |
|
4767 | 4764 | parents = repo[None].parents() |
|
4768 | 4765 | else: |
|
4769 | 4766 | parents = [repo[node]] |
|
4770 | 4767 | if rej: |
|
4771 | 4768 | ui.write_err(_("patch applied partially\n")) |
|
4772 | 4769 | ui.write_err(_("(fix the .rej files and run " |
|
4773 | 4770 | "`hg commit --amend`)\n")) |
|
4774 | 4771 | ret = 1 |
|
4775 | 4772 | break |
|
4776 | 4773 | |
|
4777 | 4774 | if not haspatch: |
|
4778 | 4775 | raise error.Abort(_('%s: no diffs found') % patchurl) |
|
4779 | 4776 | |
|
4780 | 4777 | if tr: |
|
4781 | 4778 | tr.close() |
|
4782 | 4779 | if msgs: |
|
4783 | 4780 | repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
4784 | 4781 | if dsguard: |
|
4785 | 4782 | dsguard.close() |
|
4786 | 4783 | return ret |
|
4787 | 4784 | finally: |
|
4788 | 4785 | if tr: |
|
4789 | 4786 | tr.release() |
|
4790 | 4787 | release(lock, dsguard, wlock) |
|
4791 | 4788 | |
|
4792 | 4789 | @command('incoming|in', |
|
4793 | 4790 | [('f', 'force', None, |
|
4794 | 4791 | _('run even if remote repository is unrelated')), |
|
4795 | 4792 | ('n', 'newest-first', None, _('show newest record first')), |
|
4796 | 4793 | ('', 'bundle', '', |
|
4797 | 4794 | _('file to store the bundles into'), _('FILE')), |
|
4798 | 4795 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
4799 | 4796 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
4800 | 4797 | ('b', 'branch', [], |
|
4801 | 4798 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
4802 | 4799 | ] + logopts + remoteopts + subrepoopts, |
|
4803 | 4800 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
4804 | 4801 | def incoming(ui, repo, source="default", **opts): |
|
4805 | 4802 | """show new changesets found in source |
|
4806 | 4803 | |
|
4807 | 4804 | Show new changesets found in the specified path/URL or the default |
|
4808 | 4805 | pull location. These are the changesets that would have been pulled |
|
4809 | 4806 | if a pull at the time you issued this command. |
|
4810 | 4807 | |
|
4811 | 4808 | See pull for valid source format details. |
|
4812 | 4809 | |
|
4813 | 4810 | .. container:: verbose |
|
4814 | 4811 | |
|
4815 | 4812 | With -B/--bookmarks, the result of bookmark comparison between |
|
4816 | 4813 | local and remote repositories is displayed. With -v/--verbose, |
|
4817 | 4814 | status is also displayed for each bookmark like below:: |
|
4818 | 4815 | |
|
4819 | 4816 | BM1 01234567890a added |
|
4820 | 4817 | BM2 1234567890ab advanced |
|
4821 | 4818 | BM3 234567890abc diverged |
|
4822 | 4819 | BM4 34567890abcd changed |
|
4823 | 4820 | |
|
4824 | 4821 | The action taken locally when pulling depends on the |
|
4825 | 4822 | status of each bookmark: |
|
4826 | 4823 | |
|
4827 | 4824 | :``added``: pull will create it |
|
4828 | 4825 | :``advanced``: pull will update it |
|
4829 | 4826 | :``diverged``: pull will create a divergent bookmark |
|
4830 | 4827 | :``changed``: result depends on remote changesets |
|
4831 | 4828 | |
|
4832 | 4829 | From the point of view of pulling behavior, bookmark |
|
4833 | 4830 | existing only in the remote repository are treated as ``added``, |
|
4834 | 4831 | even if it is in fact locally deleted. |
|
4835 | 4832 | |
|
4836 | 4833 | .. container:: verbose |
|
4837 | 4834 | |
|
4838 | 4835 | For remote repository, using --bundle avoids downloading the |
|
4839 | 4836 | changesets twice if the incoming is followed by a pull. |
|
4840 | 4837 | |
|
4841 | 4838 | Examples: |
|
4842 | 4839 | |
|
4843 | 4840 | - show incoming changes with patches and full description:: |
|
4844 | 4841 | |
|
4845 | 4842 | hg incoming -vp |
|
4846 | 4843 | |
|
4847 | 4844 | - show incoming changes excluding merges, store a bundle:: |
|
4848 | 4845 | |
|
4849 | 4846 | hg in -vpM --bundle incoming.hg |
|
4850 | 4847 | hg pull incoming.hg |
|
4851 | 4848 | |
|
4852 | 4849 | - briefly list changes inside a bundle:: |
|
4853 | 4850 | |
|
4854 | 4851 | hg in changes.hg -T "{desc|firstline}\\n" |
|
4855 | 4852 | |
|
4856 | 4853 | Returns 0 if there are incoming changes, 1 otherwise. |
|
4857 | 4854 | """ |
|
4858 | 4855 | if opts.get('graph'): |
|
4859 | 4856 | cmdutil.checkunsupportedgraphflags([], opts) |
|
4860 | 4857 | def display(other, chlist, displayer): |
|
4861 | 4858 | revdag = cmdutil.graphrevs(other, chlist, opts) |
|
4862 | 4859 | cmdutil.displaygraph(ui, repo, revdag, displayer, |
|
4863 | 4860 | graphmod.asciiedges) |
|
4864 | 4861 | |
|
4865 | 4862 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) |
|
4866 | 4863 | return 0 |
|
4867 | 4864 | |
|
4868 | 4865 | if opts.get('bundle') and opts.get('subrepos'): |
|
4869 | 4866 | raise error.Abort(_('cannot combine --bundle and --subrepos')) |
|
4870 | 4867 | |
|
4871 | 4868 | if opts.get('bookmarks'): |
|
4872 | 4869 | source, branches = hg.parseurl(ui.expandpath(source), |
|
4873 | 4870 | opts.get('branch')) |
|
4874 | 4871 | other = hg.peer(repo, opts, source) |
|
4875 | 4872 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
4876 | 4873 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
4877 | 4874 | return 0 |
|
4878 | 4875 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
4879 | 4876 | return bookmarks.incoming(ui, repo, other) |
|
4880 | 4877 | |
|
4881 | 4878 | repo._subtoppath = ui.expandpath(source) |
|
4882 | 4879 | try: |
|
4883 | 4880 | return hg.incoming(ui, repo, source, opts) |
|
4884 | 4881 | finally: |
|
4885 | 4882 | del repo._subtoppath |
|
4886 | 4883 | |
|
4887 | 4884 | |
|
4888 | 4885 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), |
|
4889 | 4886 | norepo=True) |
|
4890 | 4887 | def init(ui, dest=".", **opts): |
|
4891 | 4888 | """create a new repository in the given directory |
|
4892 | 4889 | |
|
4893 | 4890 | Initialize a new repository in the given directory. If the given |
|
4894 | 4891 | directory does not exist, it will be created. |
|
4895 | 4892 | |
|
4896 | 4893 | If no directory is given, the current directory is used. |
|
4897 | 4894 | |
|
4898 | 4895 | It is possible to specify an ``ssh://`` URL as the destination. |
|
4899 | 4896 | See :hg:`help urls` for more information. |
|
4900 | 4897 | |
|
4901 | 4898 | Returns 0 on success. |
|
4902 | 4899 | """ |
|
4903 | 4900 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
4904 | 4901 | |
|
4905 | 4902 | @command('locate', |
|
4906 | 4903 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
4907 | 4904 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
4908 | 4905 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
4909 | 4906 | ] + walkopts, |
|
4910 | 4907 | _('[OPTION]... [PATTERN]...')) |
|
4911 | 4908 | def locate(ui, repo, *pats, **opts): |
|
4912 | 4909 | """locate files matching specific patterns (DEPRECATED) |
|
4913 | 4910 | |
|
4914 | 4911 | Print files under Mercurial control in the working directory whose |
|
4915 | 4912 | names match the given patterns. |
|
4916 | 4913 | |
|
4917 | 4914 | By default, this command searches all directories in the working |
|
4918 | 4915 | directory. To search just the current directory and its |
|
4919 | 4916 | subdirectories, use "--include .". |
|
4920 | 4917 | |
|
4921 | 4918 | If no patterns are given to match, this command prints the names |
|
4922 | 4919 | of all files under Mercurial control in the working directory. |
|
4923 | 4920 | |
|
4924 | 4921 | If you want to feed the output of this command into the "xargs" |
|
4925 | 4922 | command, use the -0 option to both this command and "xargs". This |
|
4926 | 4923 | will avoid the problem of "xargs" treating single filenames that |
|
4927 | 4924 | contain whitespace as multiple filenames. |
|
4928 | 4925 | |
|
4929 | 4926 | See :hg:`help files` for a more versatile command. |
|
4930 | 4927 | |
|
4931 | 4928 | Returns 0 if a match is found, 1 otherwise. |
|
4932 | 4929 | """ |
|
4933 | 4930 | if opts.get('print0'): |
|
4934 | 4931 | end = '\0' |
|
4935 | 4932 | else: |
|
4936 | 4933 | end = '\n' |
|
4937 | 4934 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() |
|
4938 | 4935 | |
|
4939 | 4936 | ret = 1 |
|
4940 | 4937 | ctx = repo[rev] |
|
4941 | 4938 | m = scmutil.match(ctx, pats, opts, default='relglob', |
|
4942 | 4939 | badfn=lambda x, y: False) |
|
4943 | 4940 | |
|
4944 | 4941 | for abs in ctx.matches(m): |
|
4945 | 4942 | if opts.get('fullpath'): |
|
4946 | 4943 | ui.write(repo.wjoin(abs), end) |
|
4947 | 4944 | else: |
|
4948 | 4945 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
4949 | 4946 | ret = 0 |
|
4950 | 4947 | |
|
4951 | 4948 | return ret |
|
4952 | 4949 | |
|
4953 | 4950 | @command('^log|history', |
|
4954 | 4951 | [('f', 'follow', None, |
|
4955 | 4952 | _('follow changeset history, or file history across copies and renames')), |
|
4956 | 4953 | ('', 'follow-first', None, |
|
4957 | 4954 | _('only follow the first parent of merge changesets (DEPRECATED)')), |
|
4958 | 4955 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
4959 | 4956 | ('C', 'copies', None, _('show copied files')), |
|
4960 | 4957 | ('k', 'keyword', [], |
|
4961 | 4958 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
4962 | 4959 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), |
|
4963 | 4960 | ('', 'removed', None, _('include revisions where files were removed')), |
|
4964 | 4961 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), |
|
4965 | 4962 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
4966 | 4963 | ('', 'only-branch', [], |
|
4967 | 4964 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
4968 | 4965 | _('BRANCH')), |
|
4969 | 4966 | ('b', 'branch', [], |
|
4970 | 4967 | _('show changesets within the given named branch'), _('BRANCH')), |
|
4971 | 4968 | ('P', 'prune', [], |
|
4972 | 4969 | _('do not display revision or any of its ancestors'), _('REV')), |
|
4973 | 4970 | ] + logopts + walkopts, |
|
4974 | 4971 | _('[OPTION]... [FILE]'), |
|
4975 | 4972 | inferrepo=True) |
|
4976 | 4973 | def log(ui, repo, *pats, **opts): |
|
4977 | 4974 | """show revision history of entire repository or files |
|
4978 | 4975 | |
|
4979 | 4976 | Print the revision history of the specified files or the entire |
|
4980 | 4977 | project. |
|
4981 | 4978 | |
|
4982 | 4979 | If no revision range is specified, the default is ``tip:0`` unless |
|
4983 | 4980 | --follow is set, in which case the working directory parent is |
|
4984 | 4981 | used as the starting revision. |
|
4985 | 4982 | |
|
4986 | 4983 | File history is shown without following rename or copy history of |
|
4987 | 4984 | files. Use -f/--follow with a filename to follow history across |
|
4988 | 4985 | renames and copies. --follow without a filename will only show |
|
4989 | 4986 | ancestors or descendants of the starting revision. |
|
4990 | 4987 | |
|
4991 | 4988 | By default this command prints revision number and changeset id, |
|
4992 | 4989 | tags, non-trivial parents, user, date and time, and a summary for |
|
4993 | 4990 | each commit. When the -v/--verbose switch is used, the list of |
|
4994 | 4991 | changed files and full commit message are shown. |
|
4995 | 4992 | |
|
4996 | 4993 | With --graph the revisions are shown as an ASCII art DAG with the most |
|
4997 | 4994 | recent changeset at the top. |
|
4998 | 4995 | 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, |
|
4999 | 4996 | and '+' represents a fork where the changeset from the lines below is a |
|
5000 | 4997 | parent of the 'o' merge on the same line. |
|
5001 | 4998 | |
|
5002 | 4999 | .. note:: |
|
5003 | 5000 | |
|
5004 | 5001 | :hg:`log --patch` may generate unexpected diff output for merge |
|
5005 | 5002 | changesets, as it will only compare the merge changeset against |
|
5006 | 5003 | its first parent. Also, only files different from BOTH parents |
|
5007 | 5004 | will appear in files:. |
|
5008 | 5005 | |
|
5009 | 5006 | .. note:: |
|
5010 | 5007 | |
|
5011 | 5008 | For performance reasons, :hg:`log FILE` may omit duplicate changes |
|
5012 | 5009 | made on branches and will not show removals or mode changes. To |
|
5013 | 5010 | see all such changes, use the --removed switch. |
|
5014 | 5011 | |
|
5015 | 5012 | .. container:: verbose |
|
5016 | 5013 | |
|
5017 | 5014 | Some examples: |
|
5018 | 5015 | |
|
5019 | 5016 | - changesets with full descriptions and file lists:: |
|
5020 | 5017 | |
|
5021 | 5018 | hg log -v |
|
5022 | 5019 | |
|
5023 | 5020 | - changesets ancestral to the working directory:: |
|
5024 | 5021 | |
|
5025 | 5022 | hg log -f |
|
5026 | 5023 | |
|
5027 | 5024 | - last 10 commits on the current branch:: |
|
5028 | 5025 | |
|
5029 | 5026 | hg log -l 10 -b . |
|
5030 | 5027 | |
|
5031 | 5028 | - changesets showing all modifications of a file, including removals:: |
|
5032 | 5029 | |
|
5033 | 5030 | hg log --removed file.c |
|
5034 | 5031 | |
|
5035 | 5032 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
5036 | 5033 | |
|
5037 | 5034 | hg log -Mp lib/ |
|
5038 | 5035 | |
|
5039 | 5036 | - all revision numbers that match a keyword:: |
|
5040 | 5037 | |
|
5041 | 5038 | hg log -k bug --template "{rev}\\n" |
|
5042 | 5039 | |
|
5043 | 5040 | - the full hash identifier of the working directory parent:: |
|
5044 | 5041 | |
|
5045 | 5042 | hg log -r . --template "{node}\\n" |
|
5046 | 5043 | |
|
5047 | 5044 | - list available log templates:: |
|
5048 | 5045 | |
|
5049 | 5046 | hg log -T list |
|
5050 | 5047 | |
|
5051 | 5048 | - check if a given changeset is included in a tagged release:: |
|
5052 | 5049 | |
|
5053 | 5050 | hg log -r "a21ccf and ancestor(1.9)" |
|
5054 | 5051 | |
|
5055 | 5052 | - find all changesets by some user in a date range:: |
|
5056 | 5053 | |
|
5057 | 5054 | hg log -k alice -d "may 2008 to jul 2008" |
|
5058 | 5055 | |
|
5059 | 5056 | - summary of all changesets after the last tag:: |
|
5060 | 5057 | |
|
5061 | 5058 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
5062 | 5059 | |
|
5063 | 5060 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5064 | 5061 | |
|
5065 | 5062 | See :hg:`help revisions` and :hg:`help revsets` for more about |
|
5066 | 5063 | specifying and ordering revisions. |
|
5067 | 5064 | |
|
5068 | 5065 | See :hg:`help templates` for more about pre-packaged styles and |
|
5069 | 5066 | specifying custom templates. |
|
5070 | 5067 | |
|
5071 | 5068 | Returns 0 on success. |
|
5072 | 5069 | |
|
5073 | 5070 | """ |
|
5074 | 5071 | if opts.get('follow') and opts.get('rev'): |
|
5075 | 5072 | opts['rev'] = [revset.formatspec('reverse(::%lr)', opts.get('rev'))] |
|
5076 | 5073 | del opts['follow'] |
|
5077 | 5074 | |
|
5078 | 5075 | if opts.get('graph'): |
|
5079 | 5076 | return cmdutil.graphlog(ui, repo, *pats, **opts) |
|
5080 | 5077 | |
|
5081 | 5078 | revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) |
|
5082 | 5079 | limit = cmdutil.loglimit(opts) |
|
5083 | 5080 | count = 0 |
|
5084 | 5081 | |
|
5085 | 5082 | getrenamed = None |
|
5086 | 5083 | if opts.get('copies'): |
|
5087 | 5084 | endrev = None |
|
5088 | 5085 | if opts.get('rev'): |
|
5089 | 5086 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 |
|
5090 | 5087 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
5091 | 5088 | |
|
5092 | 5089 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
5093 | 5090 | for rev in revs: |
|
5094 | 5091 | if count == limit: |
|
5095 | 5092 | break |
|
5096 | 5093 | ctx = repo[rev] |
|
5097 | 5094 | copies = None |
|
5098 | 5095 | if getrenamed is not None and rev: |
|
5099 | 5096 | copies = [] |
|
5100 | 5097 | for fn in ctx.files(): |
|
5101 | 5098 | rename = getrenamed(fn, rev) |
|
5102 | 5099 | if rename: |
|
5103 | 5100 | copies.append((fn, rename[0])) |
|
5104 | 5101 | if filematcher: |
|
5105 | 5102 | revmatchfn = filematcher(ctx.rev()) |
|
5106 | 5103 | else: |
|
5107 | 5104 | revmatchfn = None |
|
5108 | 5105 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
5109 | 5106 | if displayer.flush(ctx): |
|
5110 | 5107 | count += 1 |
|
5111 | 5108 | |
|
5112 | 5109 | displayer.close() |
|
5113 | 5110 | |
|
5114 | 5111 | @command('manifest', |
|
5115 | 5112 | [('r', 'rev', '', _('revision to display'), _('REV')), |
|
5116 | 5113 | ('', 'all', False, _("list files from all revisions"))] |
|
5117 | 5114 | + formatteropts, |
|
5118 | 5115 | _('[-r REV]')) |
|
5119 | 5116 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
5120 | 5117 | """output the current or given revision of the project manifest |
|
5121 | 5118 | |
|
5122 | 5119 | Print a list of version controlled files for the given revision. |
|
5123 | 5120 | If no revision is given, the first parent of the working directory |
|
5124 | 5121 | is used, or the null revision if no revision is checked out. |
|
5125 | 5122 | |
|
5126 | 5123 | With -v, print file permissions, symlink and executable bits. |
|
5127 | 5124 | With --debug, print file revision hashes. |
|
5128 | 5125 | |
|
5129 | 5126 | If option --all is specified, the list of all files from all revisions |
|
5130 | 5127 | is printed. This includes deleted and renamed files. |
|
5131 | 5128 | |
|
5132 | 5129 | Returns 0 on success. |
|
5133 | 5130 | """ |
|
5134 | 5131 | |
|
5135 | 5132 | fm = ui.formatter('manifest', opts) |
|
5136 | 5133 | |
|
5137 | 5134 | if opts.get('all'): |
|
5138 | 5135 | if rev or node: |
|
5139 | 5136 | raise error.Abort(_("can't specify a revision with --all")) |
|
5140 | 5137 | |
|
5141 | 5138 | res = [] |
|
5142 | 5139 | prefix = "data/" |
|
5143 | 5140 | suffix = ".i" |
|
5144 | 5141 | plen = len(prefix) |
|
5145 | 5142 | slen = len(suffix) |
|
5146 | 5143 | with repo.lock(): |
|
5147 | 5144 | for fn, b, size in repo.store.datafiles(): |
|
5148 | 5145 | if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: |
|
5149 | 5146 | res.append(fn[plen:-slen]) |
|
5150 | 5147 | for f in res: |
|
5151 | 5148 | fm.startitem() |
|
5152 | 5149 | fm.write("path", '%s\n', f) |
|
5153 | 5150 | fm.end() |
|
5154 | 5151 | return |
|
5155 | 5152 | |
|
5156 | 5153 | if rev and node: |
|
5157 | 5154 | raise error.Abort(_("please specify just one revision")) |
|
5158 | 5155 | |
|
5159 | 5156 | if not node: |
|
5160 | 5157 | node = rev |
|
5161 | 5158 | |
|
5162 | 5159 | char = {'l': '@', 'x': '*', '': ''} |
|
5163 | 5160 | mode = {'l': '644', 'x': '755', '': '644'} |
|
5164 | 5161 | ctx = scmutil.revsingle(repo, node) |
|
5165 | 5162 | mf = ctx.manifest() |
|
5166 | 5163 | for f in ctx: |
|
5167 | 5164 | fm.startitem() |
|
5168 | 5165 | fl = ctx[f].flags() |
|
5169 | 5166 | fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) |
|
5170 | 5167 | fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) |
|
5171 | 5168 | fm.write('path', '%s\n', f) |
|
5172 | 5169 | fm.end() |
|
5173 | 5170 | |
|
5174 | 5171 | @command('^merge', |
|
5175 | 5172 | [('f', 'force', None, |
|
5176 | 5173 | _('force a merge including outstanding changes (DEPRECATED)')), |
|
5177 | 5174 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
5178 | 5175 | ('P', 'preview', None, |
|
5179 | 5176 | _('review revisions to merge (no merge is performed)')) |
|
5180 | 5177 | ] + mergetoolopts, |
|
5181 | 5178 | _('[-P] [-f] [[-r] REV]')) |
|
5182 | 5179 | def merge(ui, repo, node=None, **opts): |
|
5183 | 5180 | """merge another revision into working directory |
|
5184 | 5181 | |
|
5185 | 5182 | The current working directory is updated with all changes made in |
|
5186 | 5183 | the requested revision since the last common predecessor revision. |
|
5187 | 5184 | |
|
5188 | 5185 | Files that changed between either parent are marked as changed for |
|
5189 | 5186 | the next commit and a commit must be performed before any further |
|
5190 | 5187 | updates to the repository are allowed. The next commit will have |
|
5191 | 5188 | two parents. |
|
5192 | 5189 | |
|
5193 | 5190 | ``--tool`` can be used to specify the merge tool used for file |
|
5194 | 5191 | merges. It overrides the HGMERGE environment variable and your |
|
5195 | 5192 | configuration files. See :hg:`help merge-tools` for options. |
|
5196 | 5193 | |
|
5197 | 5194 | If no revision is specified, the working directory's parent is a |
|
5198 | 5195 | head revision, and the current branch contains exactly one other |
|
5199 | 5196 | head, the other head is merged with by default. Otherwise, an |
|
5200 | 5197 | explicit revision with which to merge with must be provided. |
|
5201 | 5198 | |
|
5202 | 5199 | See :hg:`help resolve` for information on handling file conflicts. |
|
5203 | 5200 | |
|
5204 | 5201 | To undo an uncommitted merge, use :hg:`update --clean .` which |
|
5205 | 5202 | will check out a clean copy of the original merge parent, losing |
|
5206 | 5203 | all changes. |
|
5207 | 5204 | |
|
5208 | 5205 | Returns 0 on success, 1 if there are unresolved files. |
|
5209 | 5206 | """ |
|
5210 | 5207 | |
|
5211 | 5208 | if opts.get('rev') and node: |
|
5212 | 5209 | raise error.Abort(_("please specify just one revision")) |
|
5213 | 5210 | if not node: |
|
5214 | 5211 | node = opts.get('rev') |
|
5215 | 5212 | |
|
5216 | 5213 | if node: |
|
5217 | 5214 | node = scmutil.revsingle(repo, node).node() |
|
5218 | 5215 | |
|
5219 | 5216 | if not node: |
|
5220 | 5217 | node = repo[destutil.destmerge(repo)].node() |
|
5221 | 5218 | |
|
5222 | 5219 | if opts.get('preview'): |
|
5223 | 5220 | # find nodes that are ancestors of p2 but not of p1 |
|
5224 | 5221 | p1 = repo.lookup('.') |
|
5225 | 5222 | p2 = repo.lookup(node) |
|
5226 | 5223 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
5227 | 5224 | |
|
5228 | 5225 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
5229 | 5226 | for node in nodes: |
|
5230 | 5227 | displayer.show(repo[node]) |
|
5231 | 5228 | displayer.close() |
|
5232 | 5229 | return 0 |
|
5233 | 5230 | |
|
5234 | 5231 | try: |
|
5235 | 5232 | # ui.forcemerge is an internal variable, do not document |
|
5236 | 5233 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge') |
|
5237 | 5234 | return hg.merge(repo, node, force=opts.get('force')) |
|
5238 | 5235 | finally: |
|
5239 | 5236 | ui.setconfig('ui', 'forcemerge', '', 'merge') |
|
5240 | 5237 | |
|
5241 | 5238 | @command('outgoing|out', |
|
5242 | 5239 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
5243 | 5240 | ('r', 'rev', [], |
|
5244 | 5241 | _('a changeset intended to be included in the destination'), _('REV')), |
|
5245 | 5242 | ('n', 'newest-first', None, _('show newest record first')), |
|
5246 | 5243 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
5247 | 5244 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
5248 | 5245 | _('BRANCH')), |
|
5249 | 5246 | ] + logopts + remoteopts + subrepoopts, |
|
5250 | 5247 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
5251 | 5248 | def outgoing(ui, repo, dest=None, **opts): |
|
5252 | 5249 | """show changesets not found in the destination |
|
5253 | 5250 | |
|
5254 | 5251 | Show changesets not found in the specified destination repository |
|
5255 | 5252 | or the default push location. These are the changesets that would |
|
5256 | 5253 | be pushed if a push was requested. |
|
5257 | 5254 | |
|
5258 | 5255 | See pull for details of valid destination formats. |
|
5259 | 5256 | |
|
5260 | 5257 | .. container:: verbose |
|
5261 | 5258 | |
|
5262 | 5259 | With -B/--bookmarks, the result of bookmark comparison between |
|
5263 | 5260 | local and remote repositories is displayed. With -v/--verbose, |
|
5264 | 5261 | status is also displayed for each bookmark like below:: |
|
5265 | 5262 | |
|
5266 | 5263 | BM1 01234567890a added |
|
5267 | 5264 | BM2 deleted |
|
5268 | 5265 | BM3 234567890abc advanced |
|
5269 | 5266 | BM4 34567890abcd diverged |
|
5270 | 5267 | BM5 4567890abcde changed |
|
5271 | 5268 | |
|
5272 | 5269 | The action taken when pushing depends on the |
|
5273 | 5270 | status of each bookmark: |
|
5274 | 5271 | |
|
5275 | 5272 | :``added``: push with ``-B`` will create it |
|
5276 | 5273 | :``deleted``: push with ``-B`` will delete it |
|
5277 | 5274 | :``advanced``: push will update it |
|
5278 | 5275 | :``diverged``: push with ``-B`` will update it |
|
5279 | 5276 | :``changed``: push with ``-B`` will update it |
|
5280 | 5277 | |
|
5281 | 5278 | From the point of view of pushing behavior, bookmarks |
|
5282 | 5279 | existing only in the remote repository are treated as |
|
5283 | 5280 | ``deleted``, even if it is in fact added remotely. |
|
5284 | 5281 | |
|
5285 | 5282 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
5286 | 5283 | """ |
|
5287 | 5284 | if opts.get('graph'): |
|
5288 | 5285 | cmdutil.checkunsupportedgraphflags([], opts) |
|
5289 | 5286 | o, other = hg._outgoing(ui, repo, dest, opts) |
|
5290 | 5287 | if not o: |
|
5291 | 5288 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
5292 | 5289 | return |
|
5293 | 5290 | |
|
5294 | 5291 | revdag = cmdutil.graphrevs(repo, o, opts) |
|
5295 | 5292 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
5296 | 5293 | cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) |
|
5297 | 5294 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
5298 | 5295 | return 0 |
|
5299 | 5296 | |
|
5300 | 5297 | if opts.get('bookmarks'): |
|
5301 | 5298 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
5302 | 5299 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
5303 | 5300 | other = hg.peer(repo, opts, dest) |
|
5304 | 5301 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
5305 | 5302 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
5306 | 5303 | return 0 |
|
5307 | 5304 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
5308 | 5305 | return bookmarks.outgoing(ui, repo, other) |
|
5309 | 5306 | |
|
5310 | 5307 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') |
|
5311 | 5308 | try: |
|
5312 | 5309 | return hg.outgoing(ui, repo, dest, opts) |
|
5313 | 5310 | finally: |
|
5314 | 5311 | del repo._subtoppath |
|
5315 | 5312 | |
|
5316 | 5313 | @command('parents', |
|
5317 | 5314 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
5318 | 5315 | ] + templateopts, |
|
5319 | 5316 | _('[-r REV] [FILE]'), |
|
5320 | 5317 | inferrepo=True) |
|
5321 | 5318 | def parents(ui, repo, file_=None, **opts): |
|
5322 | 5319 | """show the parents of the working directory or revision (DEPRECATED) |
|
5323 | 5320 | |
|
5324 | 5321 | Print the working directory's parent revisions. If a revision is |
|
5325 | 5322 | given via -r/--rev, the parent of that revision will be printed. |
|
5326 | 5323 | If a file argument is given, the revision in which the file was |
|
5327 | 5324 | last changed (before the working directory revision or the |
|
5328 | 5325 | argument to --rev if given) is printed. |
|
5329 | 5326 | |
|
5330 | 5327 | This command is equivalent to:: |
|
5331 | 5328 | |
|
5332 | 5329 | hg log -r "p1()+p2()" or |
|
5333 | 5330 | hg log -r "p1(REV)+p2(REV)" or |
|
5334 | 5331 | hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or |
|
5335 | 5332 | hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" |
|
5336 | 5333 | |
|
5337 | 5334 | See :hg:`summary` and :hg:`help revsets` for related information. |
|
5338 | 5335 | |
|
5339 | 5336 | Returns 0 on success. |
|
5340 | 5337 | """ |
|
5341 | 5338 | |
|
5342 | 5339 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
5343 | 5340 | |
|
5344 | 5341 | if file_: |
|
5345 | 5342 | m = scmutil.match(ctx, (file_,), opts) |
|
5346 | 5343 | if m.anypats() or len(m.files()) != 1: |
|
5347 | 5344 | raise error.Abort(_('can only specify an explicit filename')) |
|
5348 | 5345 | file_ = m.files()[0] |
|
5349 | 5346 | filenodes = [] |
|
5350 | 5347 | for cp in ctx.parents(): |
|
5351 | 5348 | if not cp: |
|
5352 | 5349 | continue |
|
5353 | 5350 | try: |
|
5354 | 5351 | filenodes.append(cp.filenode(file_)) |
|
5355 | 5352 | except error.LookupError: |
|
5356 | 5353 | pass |
|
5357 | 5354 | if not filenodes: |
|
5358 | 5355 | raise error.Abort(_("'%s' not found in manifest!") % file_) |
|
5359 | 5356 | p = [] |
|
5360 | 5357 | for fn in filenodes: |
|
5361 | 5358 | fctx = repo.filectx(file_, fileid=fn) |
|
5362 | 5359 | p.append(fctx.node()) |
|
5363 | 5360 | else: |
|
5364 | 5361 | p = [cp.node() for cp in ctx.parents()] |
|
5365 | 5362 | |
|
5366 | 5363 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
5367 | 5364 | for n in p: |
|
5368 | 5365 | if n != nullid: |
|
5369 | 5366 | displayer.show(repo[n]) |
|
5370 | 5367 | displayer.close() |
|
5371 | 5368 | |
|
5372 | 5369 | @command('paths', formatteropts, _('[NAME]'), optionalrepo=True) |
|
5373 | 5370 | def paths(ui, repo, search=None, **opts): |
|
5374 | 5371 | """show aliases for remote repositories |
|
5375 | 5372 | |
|
5376 | 5373 | Show definition of symbolic path name NAME. If no name is given, |
|
5377 | 5374 | show definition of all available names. |
|
5378 | 5375 | |
|
5379 | 5376 | Option -q/--quiet suppresses all output when searching for NAME |
|
5380 | 5377 | and shows only the path names when listing all definitions. |
|
5381 | 5378 | |
|
5382 | 5379 | Path names are defined in the [paths] section of your |
|
5383 | 5380 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
5384 | 5381 | repository, ``.hg/hgrc`` is used, too. |
|
5385 | 5382 | |
|
5386 | 5383 | The path names ``default`` and ``default-push`` have a special |
|
5387 | 5384 | meaning. When performing a push or pull operation, they are used |
|
5388 | 5385 | as fallbacks if no location is specified on the command-line. |
|
5389 | 5386 | When ``default-push`` is set, it will be used for push and |
|
5390 | 5387 | ``default`` will be used for pull; otherwise ``default`` is used |
|
5391 | 5388 | as the fallback for both. When cloning a repository, the clone |
|
5392 | 5389 | source is written as ``default`` in ``.hg/hgrc``. |
|
5393 | 5390 | |
|
5394 | 5391 | .. note:: |
|
5395 | 5392 | |
|
5396 | 5393 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
5397 | 5394 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` |
|
5398 | 5395 | and :hg:`bundle`) operations. |
|
5399 | 5396 | |
|
5400 | 5397 | See :hg:`help urls` for more information. |
|
5401 | 5398 | |
|
5402 | 5399 | Returns 0 on success. |
|
5403 | 5400 | """ |
|
5404 | 5401 | if search: |
|
5405 | 5402 | pathitems = [(name, path) for name, path in ui.paths.iteritems() |
|
5406 | 5403 | if name == search] |
|
5407 | 5404 | else: |
|
5408 | 5405 | pathitems = sorted(ui.paths.iteritems()) |
|
5409 | 5406 | |
|
5410 | 5407 | fm = ui.formatter('paths', opts) |
|
5411 | 5408 | if fm: |
|
5412 | 5409 | hidepassword = str |
|
5413 | 5410 | else: |
|
5414 | 5411 | hidepassword = util.hidepassword |
|
5415 | 5412 | if ui.quiet: |
|
5416 | 5413 | namefmt = '%s\n' |
|
5417 | 5414 | else: |
|
5418 | 5415 | namefmt = '%s = ' |
|
5419 | 5416 | showsubopts = not search and not ui.quiet |
|
5420 | 5417 | |
|
5421 | 5418 | for name, path in pathitems: |
|
5422 | 5419 | fm.startitem() |
|
5423 | 5420 | fm.condwrite(not search, 'name', namefmt, name) |
|
5424 | 5421 | fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc)) |
|
5425 | 5422 | for subopt, value in sorted(path.suboptions.items()): |
|
5426 | 5423 | assert subopt not in ('name', 'url') |
|
5427 | 5424 | if showsubopts: |
|
5428 | 5425 | fm.plain('%s:%s = ' % (name, subopt)) |
|
5429 | 5426 | fm.condwrite(showsubopts, subopt, '%s\n', value) |
|
5430 | 5427 | |
|
5431 | 5428 | fm.end() |
|
5432 | 5429 | |
|
5433 | 5430 | if search and not pathitems: |
|
5434 | 5431 | if not ui.quiet: |
|
5435 | 5432 | ui.warn(_("not found!\n")) |
|
5436 | 5433 | return 1 |
|
5437 | 5434 | else: |
|
5438 | 5435 | return 0 |
|
5439 | 5436 | |
|
5440 | 5437 | @command('phase', |
|
5441 | 5438 | [('p', 'public', False, _('set changeset phase to public')), |
|
5442 | 5439 | ('d', 'draft', False, _('set changeset phase to draft')), |
|
5443 | 5440 | ('s', 'secret', False, _('set changeset phase to secret')), |
|
5444 | 5441 | ('f', 'force', False, _('allow to move boundary backward')), |
|
5445 | 5442 | ('r', 'rev', [], _('target revision'), _('REV')), |
|
5446 | 5443 | ], |
|
5447 | 5444 | _('[-p|-d|-s] [-f] [-r] [REV...]')) |
|
5448 | 5445 | def phase(ui, repo, *revs, **opts): |
|
5449 | 5446 | """set or show the current phase name |
|
5450 | 5447 | |
|
5451 | 5448 | With no argument, show the phase name of the current revision(s). |
|
5452 | 5449 | |
|
5453 | 5450 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
5454 | 5451 | phase value of the specified revisions. |
|
5455 | 5452 | |
|
5456 | 5453 | Unless -f/--force is specified, :hg:`phase` won't move changeset from a |
|
5457 | 5454 | lower phase to an higher phase. Phases are ordered as follows:: |
|
5458 | 5455 | |
|
5459 | 5456 | public < draft < secret |
|
5460 | 5457 | |
|
5461 | 5458 | Returns 0 on success, 1 if some phases could not be changed. |
|
5462 | 5459 | |
|
5463 | 5460 | (For more information about the phases concept, see :hg:`help phases`.) |
|
5464 | 5461 | """ |
|
5465 | 5462 | # search for a unique phase argument |
|
5466 | 5463 | targetphase = None |
|
5467 | 5464 | for idx, name in enumerate(phases.phasenames): |
|
5468 | 5465 | if opts[name]: |
|
5469 | 5466 | if targetphase is not None: |
|
5470 | 5467 | raise error.Abort(_('only one phase can be specified')) |
|
5471 | 5468 | targetphase = idx |
|
5472 | 5469 | |
|
5473 | 5470 | # look for specified revision |
|
5474 | 5471 | revs = list(revs) |
|
5475 | 5472 | revs.extend(opts['rev']) |
|
5476 | 5473 | if not revs: |
|
5477 | 5474 | # display both parents as the second parent phase can influence |
|
5478 | 5475 | # the phase of a merge commit |
|
5479 | 5476 | revs = [c.rev() for c in repo[None].parents()] |
|
5480 | 5477 | |
|
5481 | 5478 | revs = scmutil.revrange(repo, revs) |
|
5482 | 5479 | |
|
5483 | 5480 | lock = None |
|
5484 | 5481 | ret = 0 |
|
5485 | 5482 | if targetphase is None: |
|
5486 | 5483 | # display |
|
5487 | 5484 | for r in revs: |
|
5488 | 5485 | ctx = repo[r] |
|
5489 | 5486 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
5490 | 5487 | else: |
|
5491 | 5488 | tr = None |
|
5492 | 5489 | lock = repo.lock() |
|
5493 | 5490 | try: |
|
5494 | 5491 | tr = repo.transaction("phase") |
|
5495 | 5492 | # set phase |
|
5496 | 5493 | if not revs: |
|
5497 | 5494 | raise error.Abort(_('empty revision set')) |
|
5498 | 5495 | nodes = [repo[r].node() for r in revs] |
|
5499 | 5496 | # moving revision from public to draft may hide them |
|
5500 | 5497 | # We have to check result on an unfiltered repository |
|
5501 | 5498 | unfi = repo.unfiltered() |
|
5502 | 5499 | getphase = unfi._phasecache.phase |
|
5503 | 5500 | olddata = [getphase(unfi, r) for r in unfi] |
|
5504 | 5501 | phases.advanceboundary(repo, tr, targetphase, nodes) |
|
5505 | 5502 | if opts['force']: |
|
5506 | 5503 | phases.retractboundary(repo, tr, targetphase, nodes) |
|
5507 | 5504 | tr.close() |
|
5508 | 5505 | finally: |
|
5509 | 5506 | if tr is not None: |
|
5510 | 5507 | tr.release() |
|
5511 | 5508 | lock.release() |
|
5512 | 5509 | getphase = unfi._phasecache.phase |
|
5513 | 5510 | newdata = [getphase(unfi, r) for r in unfi] |
|
5514 | 5511 | changes = sum(newdata[r] != olddata[r] for r in unfi) |
|
5515 | 5512 | cl = unfi.changelog |
|
5516 | 5513 | rejected = [n for n in nodes |
|
5517 | 5514 | if newdata[cl.rev(n)] < targetphase] |
|
5518 | 5515 | if rejected: |
|
5519 | 5516 | ui.warn(_('cannot move %i changesets to a higher ' |
|
5520 | 5517 | 'phase, use --force\n') % len(rejected)) |
|
5521 | 5518 | ret = 1 |
|
5522 | 5519 | if changes: |
|
5523 | 5520 | msg = _('phase changed for %i changesets\n') % changes |
|
5524 | 5521 | if ret: |
|
5525 | 5522 | ui.status(msg) |
|
5526 | 5523 | else: |
|
5527 | 5524 | ui.note(msg) |
|
5528 | 5525 | else: |
|
5529 | 5526 | ui.warn(_('no phases changed\n')) |
|
5530 | 5527 | return ret |
|
5531 | 5528 | |
|
5532 | 5529 | def postincoming(ui, repo, modheads, optupdate, checkout): |
|
5533 | 5530 | if modheads == 0: |
|
5534 | 5531 | return |
|
5535 | 5532 | if optupdate: |
|
5536 | 5533 | try: |
|
5537 | 5534 | brev = checkout |
|
5538 | 5535 | movemarkfrom = None |
|
5539 | 5536 | if not checkout: |
|
5540 | 5537 | updata = destutil.destupdate(repo) |
|
5541 | 5538 | checkout, movemarkfrom, brev = updata |
|
5542 | 5539 | ret = hg.update(repo, checkout) |
|
5543 | 5540 | except error.UpdateAbort as inst: |
|
5544 | 5541 | msg = _("not updating: %s") % str(inst) |
|
5545 | 5542 | hint = inst.hint |
|
5546 | 5543 | raise error.UpdateAbort(msg, hint=hint) |
|
5547 | 5544 | if not ret and movemarkfrom: |
|
5548 | 5545 | if movemarkfrom == repo['.'].node(): |
|
5549 | 5546 | pass # no-op update |
|
5550 | 5547 | elif bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
5551 | 5548 | ui.status(_("updating bookmark %s\n") % repo._activebookmark) |
|
5552 | 5549 | return ret |
|
5553 | 5550 | if modheads > 1: |
|
5554 | 5551 | currentbranchheads = len(repo.branchheads()) |
|
5555 | 5552 | if currentbranchheads == modheads: |
|
5556 | 5553 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
5557 | 5554 | elif currentbranchheads > 1: |
|
5558 | 5555 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " |
|
5559 | 5556 | "merge)\n")) |
|
5560 | 5557 | else: |
|
5561 | 5558 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
5562 | 5559 | else: |
|
5563 | 5560 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
5564 | 5561 | |
|
5565 | 5562 | @command('^pull', |
|
5566 | 5563 | [('u', 'update', None, |
|
5567 | 5564 | _('update to new branch head if changesets were pulled')), |
|
5568 | 5565 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
5569 | 5566 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
5570 | 5567 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
5571 | 5568 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
5572 | 5569 | _('BRANCH')), |
|
5573 | 5570 | ] + remoteopts, |
|
5574 | 5571 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
5575 | 5572 | def pull(ui, repo, source="default", **opts): |
|
5576 | 5573 | """pull changes from the specified source |
|
5577 | 5574 | |
|
5578 | 5575 | Pull changes from a remote repository to a local one. |
|
5579 | 5576 | |
|
5580 | 5577 | This finds all changes from the repository at the specified path |
|
5581 | 5578 | or URL and adds them to a local repository (the current one unless |
|
5582 | 5579 | -R is specified). By default, this does not update the copy of the |
|
5583 | 5580 | project in the working directory. |
|
5584 | 5581 | |
|
5585 | 5582 | Use :hg:`incoming` if you want to see what would have been added |
|
5586 | 5583 | by a pull at the time you issued this command. If you then decide |
|
5587 | 5584 | to add those changes to the repository, you should use :hg:`pull |
|
5588 | 5585 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
5589 | 5586 | |
|
5590 | 5587 | If SOURCE is omitted, the 'default' path will be used. |
|
5591 | 5588 | See :hg:`help urls` for more information. |
|
5592 | 5589 | |
|
5593 | 5590 | Returns 0 on success, 1 if an update had unresolved files. |
|
5594 | 5591 | """ |
|
5595 | 5592 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
5596 | 5593 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
5597 | 5594 | other = hg.peer(repo, opts, source) |
|
5598 | 5595 | try: |
|
5599 | 5596 | revs, checkout = hg.addbranchrevs(repo, other, branches, |
|
5600 | 5597 | opts.get('rev')) |
|
5601 | 5598 | |
|
5602 | 5599 | |
|
5603 | 5600 | pullopargs = {} |
|
5604 | 5601 | if opts.get('bookmark'): |
|
5605 | 5602 | if not revs: |
|
5606 | 5603 | revs = [] |
|
5607 | 5604 | # The list of bookmark used here is not the one used to actually |
|
5608 | 5605 | # update the bookmark name. This can result in the revision pulled |
|
5609 | 5606 | # not ending up with the name of the bookmark because of a race |
|
5610 | 5607 | # condition on the server. (See issue 4689 for details) |
|
5611 | 5608 | remotebookmarks = other.listkeys('bookmarks') |
|
5612 | 5609 | pullopargs['remotebookmarks'] = remotebookmarks |
|
5613 | 5610 | for b in opts['bookmark']: |
|
5614 | 5611 | if b not in remotebookmarks: |
|
5615 | 5612 | raise error.Abort(_('remote bookmark %s not found!') % b) |
|
5616 | 5613 | revs.append(remotebookmarks[b]) |
|
5617 | 5614 | |
|
5618 | 5615 | if revs: |
|
5619 | 5616 | try: |
|
5620 | 5617 | # When 'rev' is a bookmark name, we cannot guarantee that it |
|
5621 | 5618 | # will be updated with that name because of a race condition |
|
5622 | 5619 | # server side. (See issue 4689 for details) |
|
5623 | 5620 | oldrevs = revs |
|
5624 | 5621 | revs = [] # actually, nodes |
|
5625 | 5622 | for r in oldrevs: |
|
5626 | 5623 | node = other.lookup(r) |
|
5627 | 5624 | revs.append(node) |
|
5628 | 5625 | if r == checkout: |
|
5629 | 5626 | checkout = node |
|
5630 | 5627 | except error.CapabilityError: |
|
5631 | 5628 | err = _("other repository doesn't support revision lookup, " |
|
5632 | 5629 | "so a rev cannot be specified.") |
|
5633 | 5630 | raise error.Abort(err) |
|
5634 | 5631 | |
|
5635 | 5632 | pullopargs.update(opts.get('opargs', {})) |
|
5636 | 5633 | modheads = exchange.pull(repo, other, heads=revs, |
|
5637 | 5634 | force=opts.get('force'), |
|
5638 | 5635 | bookmarks=opts.get('bookmark', ()), |
|
5639 | 5636 | opargs=pullopargs).cgresult |
|
5640 | 5637 | if checkout: |
|
5641 | 5638 | checkout = str(repo.changelog.rev(checkout)) |
|
5642 | 5639 | repo._subtoppath = source |
|
5643 | 5640 | try: |
|
5644 | 5641 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) |
|
5645 | 5642 | |
|
5646 | 5643 | finally: |
|
5647 | 5644 | del repo._subtoppath |
|
5648 | 5645 | |
|
5649 | 5646 | finally: |
|
5650 | 5647 | other.close() |
|
5651 | 5648 | return ret |
|
5652 | 5649 | |
|
5653 | 5650 | @command('^push', |
|
5654 | 5651 | [('f', 'force', None, _('force push')), |
|
5655 | 5652 | ('r', 'rev', [], |
|
5656 | 5653 | _('a changeset intended to be included in the destination'), |
|
5657 | 5654 | _('REV')), |
|
5658 | 5655 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
5659 | 5656 | ('b', 'branch', [], |
|
5660 | 5657 | _('a specific branch you would like to push'), _('BRANCH')), |
|
5661 | 5658 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
5662 | 5659 | ] + remoteopts, |
|
5663 | 5660 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
5664 | 5661 | def push(ui, repo, dest=None, **opts): |
|
5665 | 5662 | """push changes to the specified destination |
|
5666 | 5663 | |
|
5667 | 5664 | Push changesets from the local repository to the specified |
|
5668 | 5665 | destination. |
|
5669 | 5666 | |
|
5670 | 5667 | This operation is symmetrical to pull: it is identical to a pull |
|
5671 | 5668 | in the destination repository from the current one. |
|
5672 | 5669 | |
|
5673 | 5670 | By default, push will not allow creation of new heads at the |
|
5674 | 5671 | destination, since multiple heads would make it unclear which head |
|
5675 | 5672 | to use. In this situation, it is recommended to pull and merge |
|
5676 | 5673 | before pushing. |
|
5677 | 5674 | |
|
5678 | 5675 | Use --new-branch if you want to allow push to create a new named |
|
5679 | 5676 | branch that is not present at the destination. This allows you to |
|
5680 | 5677 | only create a new branch without forcing other changes. |
|
5681 | 5678 | |
|
5682 | 5679 | .. note:: |
|
5683 | 5680 | |
|
5684 | 5681 | Extra care should be taken with the -f/--force option, |
|
5685 | 5682 | which will push all new heads on all branches, an action which will |
|
5686 | 5683 | almost always cause confusion for collaborators. |
|
5687 | 5684 | |
|
5688 | 5685 | If -r/--rev is used, the specified revision and all its ancestors |
|
5689 | 5686 | will be pushed to the remote repository. |
|
5690 | 5687 | |
|
5691 | 5688 | If -B/--bookmark is used, the specified bookmarked revision, its |
|
5692 | 5689 | ancestors, and the bookmark will be pushed to the remote |
|
5693 | 5690 | repository. |
|
5694 | 5691 | |
|
5695 | 5692 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
5696 | 5693 | URLs. If DESTINATION is omitted, a default path will be used. |
|
5697 | 5694 | |
|
5698 | 5695 | Returns 0 if push was successful, 1 if nothing to push. |
|
5699 | 5696 | """ |
|
5700 | 5697 | |
|
5701 | 5698 | if opts.get('bookmark'): |
|
5702 | 5699 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') |
|
5703 | 5700 | for b in opts['bookmark']: |
|
5704 | 5701 | # translate -B options to -r so changesets get pushed |
|
5705 | 5702 | if b in repo._bookmarks: |
|
5706 | 5703 | opts.setdefault('rev', []).append(b) |
|
5707 | 5704 | else: |
|
5708 | 5705 | # if we try to push a deleted bookmark, translate it to null |
|
5709 | 5706 | # this lets simultaneous -r, -b options continue working |
|
5710 | 5707 | opts.setdefault('rev', []).append("null") |
|
5711 | 5708 | |
|
5712 | 5709 | path = ui.paths.getpath(dest, default=('default-push', 'default')) |
|
5713 | 5710 | if not path: |
|
5714 | 5711 | raise error.Abort(_('default repository not configured!'), |
|
5715 | 5712 | hint=_('see the "path" section in "hg help config"')) |
|
5716 | 5713 | dest = path.pushloc or path.loc |
|
5717 | 5714 | branches = (path.branch, opts.get('branch') or []) |
|
5718 | 5715 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
5719 | 5716 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
5720 | 5717 | other = hg.peer(repo, opts, dest) |
|
5721 | 5718 | |
|
5722 | 5719 | if revs: |
|
5723 | 5720 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] |
|
5724 | 5721 | if not revs: |
|
5725 | 5722 | raise error.Abort(_("specified revisions evaluate to an empty set"), |
|
5726 | 5723 | hint=_("use different revision arguments")) |
|
5727 | 5724 | |
|
5728 | 5725 | repo._subtoppath = dest |
|
5729 | 5726 | try: |
|
5730 | 5727 | # push subrepos depth-first for coherent ordering |
|
5731 | 5728 | c = repo[''] |
|
5732 | 5729 | subs = c.substate # only repos that are committed |
|
5733 | 5730 | for s in sorted(subs): |
|
5734 | 5731 | result = c.sub(s).push(opts) |
|
5735 | 5732 | if result == 0: |
|
5736 | 5733 | return not result |
|
5737 | 5734 | finally: |
|
5738 | 5735 | del repo._subtoppath |
|
5739 | 5736 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, |
|
5740 | 5737 | newbranch=opts.get('new_branch'), |
|
5741 | 5738 | bookmarks=opts.get('bookmark', ()), |
|
5742 | 5739 | opargs=opts.get('opargs')) |
|
5743 | 5740 | |
|
5744 | 5741 | result = not pushop.cgresult |
|
5745 | 5742 | |
|
5746 | 5743 | if pushop.bkresult is not None: |
|
5747 | 5744 | if pushop.bkresult == 2: |
|
5748 | 5745 | result = 2 |
|
5749 | 5746 | elif not result and pushop.bkresult: |
|
5750 | 5747 | result = 2 |
|
5751 | 5748 | |
|
5752 | 5749 | return result |
|
5753 | 5750 | |
|
5754 | 5751 | @command('recover', []) |
|
5755 | 5752 | def recover(ui, repo): |
|
5756 | 5753 | """roll back an interrupted transaction |
|
5757 | 5754 | |
|
5758 | 5755 | Recover from an interrupted commit or pull. |
|
5759 | 5756 | |
|
5760 | 5757 | This command tries to fix the repository status after an |
|
5761 | 5758 | interrupted operation. It should only be necessary when Mercurial |
|
5762 | 5759 | suggests it. |
|
5763 | 5760 | |
|
5764 | 5761 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
5765 | 5762 | """ |
|
5766 | 5763 | if repo.recover(): |
|
5767 | 5764 | return hg.verify(repo) |
|
5768 | 5765 | return 1 |
|
5769 | 5766 | |
|
5770 | 5767 | @command('^remove|rm', |
|
5771 | 5768 | [('A', 'after', None, _('record delete for missing files')), |
|
5772 | 5769 | ('f', 'force', None, |
|
5773 | 5770 | _('remove (and delete) file even if added or modified')), |
|
5774 | 5771 | ] + subrepoopts + walkopts, |
|
5775 | 5772 | _('[OPTION]... FILE...'), |
|
5776 | 5773 | inferrepo=True) |
|
5777 | 5774 | def remove(ui, repo, *pats, **opts): |
|
5778 | 5775 | """remove the specified files on the next commit |
|
5779 | 5776 | |
|
5780 | 5777 | Schedule the indicated files for removal from the current branch. |
|
5781 | 5778 | |
|
5782 | 5779 | This command schedules the files to be removed at the next commit. |
|
5783 | 5780 | To undo a remove before that, see :hg:`revert`. To undo added |
|
5784 | 5781 | files, see :hg:`forget`. |
|
5785 | 5782 | |
|
5786 | 5783 | .. container:: verbose |
|
5787 | 5784 | |
|
5788 | 5785 | -A/--after can be used to remove only files that have already |
|
5789 | 5786 | been deleted, -f/--force can be used to force deletion, and -Af |
|
5790 | 5787 | can be used to remove files from the next revision without |
|
5791 | 5788 | deleting them from the working directory. |
|
5792 | 5789 | |
|
5793 | 5790 | The following table details the behavior of remove for different |
|
5794 | 5791 | file states (columns) and option combinations (rows). The file |
|
5795 | 5792 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
5796 | 5793 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
5797 | 5794 | (from branch) and Delete (from disk): |
|
5798 | 5795 | |
|
5799 | 5796 | ========= == == == == |
|
5800 | 5797 | opt/state A C M ! |
|
5801 | 5798 | ========= == == == == |
|
5802 | 5799 | none W RD W R |
|
5803 | 5800 | -f R RD RD R |
|
5804 | 5801 | -A W W W R |
|
5805 | 5802 | -Af R R R R |
|
5806 | 5803 | ========= == == == == |
|
5807 | 5804 | |
|
5808 | 5805 | .. note:: |
|
5809 | 5806 | |
|
5810 | 5807 | :hg:`remove` never deletes files in Added [A] state from the |
|
5811 | 5808 | working directory, not even if ``--force`` is specified. |
|
5812 | 5809 | |
|
5813 | 5810 | Returns 0 on success, 1 if any warnings encountered. |
|
5814 | 5811 | """ |
|
5815 | 5812 | |
|
5816 | 5813 | after, force = opts.get('after'), opts.get('force') |
|
5817 | 5814 | if not pats and not after: |
|
5818 | 5815 | raise error.Abort(_('no files specified')) |
|
5819 | 5816 | |
|
5820 | 5817 | m = scmutil.match(repo[None], pats, opts) |
|
5821 | 5818 | subrepos = opts.get('subrepos') |
|
5822 | 5819 | return cmdutil.remove(ui, repo, m, "", after, force, subrepos) |
|
5823 | 5820 | |
|
5824 | 5821 | @command('rename|move|mv', |
|
5825 | 5822 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
5826 | 5823 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
5827 | 5824 | ] + walkopts + dryrunopts, |
|
5828 | 5825 | _('[OPTION]... SOURCE... DEST')) |
|
5829 | 5826 | def rename(ui, repo, *pats, **opts): |
|
5830 | 5827 | """rename files; equivalent of copy + remove |
|
5831 | 5828 | |
|
5832 | 5829 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
5833 | 5830 | is a directory, copies are put in that directory. If dest is a |
|
5834 | 5831 | file, there can only be one source. |
|
5835 | 5832 | |
|
5836 | 5833 | By default, this command copies the contents of files as they |
|
5837 | 5834 | exist in the working directory. If invoked with -A/--after, the |
|
5838 | 5835 | operation is recorded, but no copying is performed. |
|
5839 | 5836 | |
|
5840 | 5837 | This command takes effect at the next commit. To undo a rename |
|
5841 | 5838 | before that, see :hg:`revert`. |
|
5842 | 5839 | |
|
5843 | 5840 | Returns 0 on success, 1 if errors are encountered. |
|
5844 | 5841 | """ |
|
5845 | 5842 | with repo.wlock(False): |
|
5846 | 5843 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
5847 | 5844 | |
|
5848 | 5845 | @command('resolve', |
|
5849 | 5846 | [('a', 'all', None, _('select all unresolved files')), |
|
5850 | 5847 | ('l', 'list', None, _('list state of files needing merge')), |
|
5851 | 5848 | ('m', 'mark', None, _('mark files as resolved')), |
|
5852 | 5849 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
5853 | 5850 | ('n', 'no-status', None, _('hide status prefix'))] |
|
5854 | 5851 | + mergetoolopts + walkopts + formatteropts, |
|
5855 | 5852 | _('[OPTION]... [FILE]...'), |
|
5856 | 5853 | inferrepo=True) |
|
5857 | 5854 | def resolve(ui, repo, *pats, **opts): |
|
5858 | 5855 | """redo merges or set/view the merge status of files |
|
5859 | 5856 | |
|
5860 | 5857 | Merges with unresolved conflicts are often the result of |
|
5861 | 5858 | non-interactive merging using the ``internal:merge`` configuration |
|
5862 | 5859 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
5863 | 5860 | command is used to manage the files involved in a merge, after |
|
5864 | 5861 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
5865 | 5862 | working directory must have two parents). See :hg:`help |
|
5866 | 5863 | merge-tools` for information on configuring merge tools. |
|
5867 | 5864 | |
|
5868 | 5865 | The resolve command can be used in the following ways: |
|
5869 | 5866 | |
|
5870 | 5867 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
5871 | 5868 | files, discarding any previous merge attempts. Re-merging is not |
|
5872 | 5869 | performed for files already marked as resolved. Use ``--all/-a`` |
|
5873 | 5870 | to select all unresolved files. ``--tool`` can be used to specify |
|
5874 | 5871 | the merge tool used for the given files. It overrides the HGMERGE |
|
5875 | 5872 | environment variable and your configuration files. Previous file |
|
5876 | 5873 | contents are saved with a ``.orig`` suffix. |
|
5877 | 5874 | |
|
5878 | 5875 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
5879 | 5876 | (e.g. after having manually fixed-up the files). The default is |
|
5880 | 5877 | to mark all unresolved files. |
|
5881 | 5878 | |
|
5882 | 5879 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
5883 | 5880 | default is to mark all resolved files. |
|
5884 | 5881 | |
|
5885 | 5882 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
5886 | 5883 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
5887 | 5884 | |
|
5888 | 5885 | .. note:: |
|
5889 | 5886 | |
|
5890 | 5887 | Mercurial will not let you commit files with unresolved merge |
|
5891 | 5888 | conflicts. You must use :hg:`resolve -m ...` before you can |
|
5892 | 5889 | commit after a conflicting merge. |
|
5893 | 5890 | |
|
5894 | 5891 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
5895 | 5892 | """ |
|
5896 | 5893 | |
|
5897 | 5894 | all, mark, unmark, show, nostatus = \ |
|
5898 | 5895 | [opts.get(o) for o in 'all mark unmark list no_status'.split()] |
|
5899 | 5896 | |
|
5900 | 5897 | if (show and (mark or unmark)) or (mark and unmark): |
|
5901 | 5898 | raise error.Abort(_("too many options specified")) |
|
5902 | 5899 | if pats and all: |
|
5903 | 5900 | raise error.Abort(_("can't specify --all and patterns")) |
|
5904 | 5901 | if not (all or pats or show or mark or unmark): |
|
5905 | 5902 | raise error.Abort(_('no files or directories specified'), |
|
5906 | 5903 | hint=('use --all to re-merge all unresolved files')) |
|
5907 | 5904 | |
|
5908 | 5905 | if show: |
|
5909 | 5906 | fm = ui.formatter('resolve', opts) |
|
5910 | 5907 | ms = mergemod.mergestate.read(repo) |
|
5911 | 5908 | m = scmutil.match(repo[None], pats, opts) |
|
5912 | 5909 | for f in ms: |
|
5913 | 5910 | if not m(f): |
|
5914 | 5911 | continue |
|
5915 | 5912 | l = 'resolve.' + {'u': 'unresolved', 'r': 'resolved', |
|
5916 | 5913 | 'd': 'driverresolved'}[ms[f]] |
|
5917 | 5914 | fm.startitem() |
|
5918 | 5915 | fm.condwrite(not nostatus, 'status', '%s ', ms[f].upper(), label=l) |
|
5919 | 5916 | fm.write('path', '%s\n', f, label=l) |
|
5920 | 5917 | fm.end() |
|
5921 | 5918 | return 0 |
|
5922 | 5919 | |
|
5923 | 5920 | with repo.wlock(): |
|
5924 | 5921 | ms = mergemod.mergestate.read(repo) |
|
5925 | 5922 | |
|
5926 | 5923 | if not (ms.active() or repo.dirstate.p2() != nullid): |
|
5927 | 5924 | raise error.Abort( |
|
5928 | 5925 | _('resolve command not applicable when not merging')) |
|
5929 | 5926 | |
|
5930 | 5927 | wctx = repo[None] |
|
5931 | 5928 | |
|
5932 | 5929 | if ms.mergedriver and ms.mdstate() == 'u': |
|
5933 | 5930 | proceed = mergemod.driverpreprocess(repo, ms, wctx) |
|
5934 | 5931 | ms.commit() |
|
5935 | 5932 | # allow mark and unmark to go through |
|
5936 | 5933 | if not mark and not unmark and not proceed: |
|
5937 | 5934 | return 1 |
|
5938 | 5935 | |
|
5939 | 5936 | m = scmutil.match(wctx, pats, opts) |
|
5940 | 5937 | ret = 0 |
|
5941 | 5938 | didwork = False |
|
5942 | 5939 | runconclude = False |
|
5943 | 5940 | |
|
5944 | 5941 | tocomplete = [] |
|
5945 | 5942 | for f in ms: |
|
5946 | 5943 | if not m(f): |
|
5947 | 5944 | continue |
|
5948 | 5945 | |
|
5949 | 5946 | didwork = True |
|
5950 | 5947 | |
|
5951 | 5948 | # don't let driver-resolved files be marked, and run the conclude |
|
5952 | 5949 | # step if asked to resolve |
|
5953 | 5950 | if ms[f] == "d": |
|
5954 | 5951 | exact = m.exact(f) |
|
5955 | 5952 | if mark: |
|
5956 | 5953 | if exact: |
|
5957 | 5954 | ui.warn(_('not marking %s as it is driver-resolved\n') |
|
5958 | 5955 | % f) |
|
5959 | 5956 | elif unmark: |
|
5960 | 5957 | if exact: |
|
5961 | 5958 | ui.warn(_('not unmarking %s as it is driver-resolved\n') |
|
5962 | 5959 | % f) |
|
5963 | 5960 | else: |
|
5964 | 5961 | runconclude = True |
|
5965 | 5962 | continue |
|
5966 | 5963 | |
|
5967 | 5964 | if mark: |
|
5968 | 5965 | ms.mark(f, "r") |
|
5969 | 5966 | elif unmark: |
|
5970 | 5967 | ms.mark(f, "u") |
|
5971 | 5968 | else: |
|
5972 | 5969 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
5973 | 5970 | a = repo.wjoin(f) |
|
5974 | 5971 | try: |
|
5975 | 5972 | util.copyfile(a, a + ".resolve") |
|
5976 | 5973 | except (IOError, OSError) as inst: |
|
5977 | 5974 | if inst.errno != errno.ENOENT: |
|
5978 | 5975 | raise |
|
5979 | 5976 | |
|
5980 | 5977 | try: |
|
5981 | 5978 | # preresolve file |
|
5982 | 5979 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
5983 | 5980 | 'resolve') |
|
5984 | 5981 | complete, r = ms.preresolve(f, wctx) |
|
5985 | 5982 | if not complete: |
|
5986 | 5983 | tocomplete.append(f) |
|
5987 | 5984 | elif r: |
|
5988 | 5985 | ret = 1 |
|
5989 | 5986 | finally: |
|
5990 | 5987 | ui.setconfig('ui', 'forcemerge', '', 'resolve') |
|
5991 | 5988 | ms.commit() |
|
5992 | 5989 | |
|
5993 | 5990 | # replace filemerge's .orig file with our resolve file, but only |
|
5994 | 5991 | # for merges that are complete |
|
5995 | 5992 | if complete: |
|
5996 | 5993 | try: |
|
5997 | 5994 | util.rename(a + ".resolve", |
|
5998 | 5995 | scmutil.origpath(ui, repo, a)) |
|
5999 | 5996 | except OSError as inst: |
|
6000 | 5997 | if inst.errno != errno.ENOENT: |
|
6001 | 5998 | raise |
|
6002 | 5999 | |
|
6003 | 6000 | for f in tocomplete: |
|
6004 | 6001 | try: |
|
6005 | 6002 | # resolve file |
|
6006 | 6003 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
6007 | 6004 | 'resolve') |
|
6008 | 6005 | r = ms.resolve(f, wctx) |
|
6009 | 6006 | if r: |
|
6010 | 6007 | ret = 1 |
|
6011 | 6008 | finally: |
|
6012 | 6009 | ui.setconfig('ui', 'forcemerge', '', 'resolve') |
|
6013 | 6010 | ms.commit() |
|
6014 | 6011 | |
|
6015 | 6012 | # replace filemerge's .orig file with our resolve file |
|
6016 | 6013 | a = repo.wjoin(f) |
|
6017 | 6014 | try: |
|
6018 | 6015 | util.rename(a + ".resolve", scmutil.origpath(ui, repo, a)) |
|
6019 | 6016 | except OSError as inst: |
|
6020 | 6017 | if inst.errno != errno.ENOENT: |
|
6021 | 6018 | raise |
|
6022 | 6019 | |
|
6023 | 6020 | ms.commit() |
|
6024 | 6021 | ms.recordactions() |
|
6025 | 6022 | |
|
6026 | 6023 | if not didwork and pats: |
|
6027 | 6024 | ui.warn(_("arguments do not match paths that need resolving\n")) |
|
6028 | 6025 | elif ms.mergedriver and ms.mdstate() != 's': |
|
6029 | 6026 | # run conclude step when either a driver-resolved file is requested |
|
6030 | 6027 | # or there are no driver-resolved files |
|
6031 | 6028 | # we can't use 'ret' to determine whether any files are unresolved |
|
6032 | 6029 | # because we might not have tried to resolve some |
|
6033 | 6030 | if ((runconclude or not list(ms.driverresolved())) |
|
6034 | 6031 | and not list(ms.unresolved())): |
|
6035 | 6032 | proceed = mergemod.driverconclude(repo, ms, wctx) |
|
6036 | 6033 | ms.commit() |
|
6037 | 6034 | if not proceed: |
|
6038 | 6035 | return 1 |
|
6039 | 6036 | |
|
6040 | 6037 | # Nudge users into finishing an unfinished operation |
|
6041 | 6038 | unresolvedf = list(ms.unresolved()) |
|
6042 | 6039 | driverresolvedf = list(ms.driverresolved()) |
|
6043 | 6040 | if not unresolvedf and not driverresolvedf: |
|
6044 | 6041 | ui.status(_('(no more unresolved files)\n')) |
|
6045 | 6042 | cmdutil.checkafterresolved(repo) |
|
6046 | 6043 | elif not unresolvedf: |
|
6047 | 6044 | ui.status(_('(no more unresolved files -- ' |
|
6048 | 6045 | 'run "hg resolve --all" to conclude)\n')) |
|
6049 | 6046 | |
|
6050 | 6047 | return ret |
|
6051 | 6048 | |
|
6052 | 6049 | @command('revert', |
|
6053 | 6050 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
6054 | 6051 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
6055 | 6052 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
6056 | 6053 | ('C', 'no-backup', None, _('do not save backup copies of files')), |
|
6057 | 6054 | ('i', 'interactive', None, |
|
6058 | 6055 | _('interactively select the changes (EXPERIMENTAL)')), |
|
6059 | 6056 | ] + walkopts + dryrunopts, |
|
6060 | 6057 | _('[OPTION]... [-r REV] [NAME]...')) |
|
6061 | 6058 | def revert(ui, repo, *pats, **opts): |
|
6062 | 6059 | """restore files to their checkout state |
|
6063 | 6060 | |
|
6064 | 6061 | .. note:: |
|
6065 | 6062 | |
|
6066 | 6063 | To check out earlier revisions, you should use :hg:`update REV`. |
|
6067 | 6064 | To cancel an uncommitted merge (and lose your changes), |
|
6068 | 6065 | use :hg:`update --clean .`. |
|
6069 | 6066 | |
|
6070 | 6067 | With no revision specified, revert the specified files or directories |
|
6071 | 6068 | to the contents they had in the parent of the working directory. |
|
6072 | 6069 | This restores the contents of files to an unmodified |
|
6073 | 6070 | state and unschedules adds, removes, copies, and renames. If the |
|
6074 | 6071 | working directory has two parents, you must explicitly specify a |
|
6075 | 6072 | revision. |
|
6076 | 6073 | |
|
6077 | 6074 | Using the -r/--rev or -d/--date options, revert the given files or |
|
6078 | 6075 | directories to their states as of a specific revision. Because |
|
6079 | 6076 | revert does not change the working directory parents, this will |
|
6080 | 6077 | cause these files to appear modified. This can be helpful to "back |
|
6081 | 6078 | out" some or all of an earlier change. See :hg:`backout` for a |
|
6082 | 6079 | related method. |
|
6083 | 6080 | |
|
6084 | 6081 | Modified files are saved with a .orig suffix before reverting. |
|
6085 | 6082 | To disable these backups, use --no-backup. |
|
6086 | 6083 | |
|
6087 | 6084 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
6088 | 6085 | |
|
6089 | 6086 | See :hg:`help backout` for a way to reverse the effect of an |
|
6090 | 6087 | earlier changeset. |
|
6091 | 6088 | |
|
6092 | 6089 | Returns 0 on success. |
|
6093 | 6090 | """ |
|
6094 | 6091 | |
|
6095 | 6092 | if opts.get("date"): |
|
6096 | 6093 | if opts.get("rev"): |
|
6097 | 6094 | raise error.Abort(_("you can't specify a revision and a date")) |
|
6098 | 6095 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
6099 | 6096 | |
|
6100 | 6097 | parent, p2 = repo.dirstate.parents() |
|
6101 | 6098 | if not opts.get('rev') and p2 != nullid: |
|
6102 | 6099 | # revert after merge is a trap for new users (issue2915) |
|
6103 | 6100 | raise error.Abort(_('uncommitted merge with no revision specified'), |
|
6104 | 6101 | hint=_('use "hg update" or see "hg help revert"')) |
|
6105 | 6102 | |
|
6106 | 6103 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
6107 | 6104 | |
|
6108 | 6105 | if (not (pats or opts.get('include') or opts.get('exclude') or |
|
6109 | 6106 | opts.get('all') or opts.get('interactive'))): |
|
6110 | 6107 | msg = _("no files or directories specified") |
|
6111 | 6108 | if p2 != nullid: |
|
6112 | 6109 | hint = _("uncommitted merge, use --all to discard all changes," |
|
6113 | 6110 | " or 'hg update -C .' to abort the merge") |
|
6114 | 6111 | raise error.Abort(msg, hint=hint) |
|
6115 | 6112 | dirty = any(repo.status()) |
|
6116 | 6113 | node = ctx.node() |
|
6117 | 6114 | if node != parent: |
|
6118 | 6115 | if dirty: |
|
6119 | 6116 | hint = _("uncommitted changes, use --all to discard all" |
|
6120 | 6117 | " changes, or 'hg update %s' to update") % ctx.rev() |
|
6121 | 6118 | else: |
|
6122 | 6119 | hint = _("use --all to revert all files," |
|
6123 | 6120 | " or 'hg update %s' to update") % ctx.rev() |
|
6124 | 6121 | elif dirty: |
|
6125 | 6122 | hint = _("uncommitted changes, use --all to discard all changes") |
|
6126 | 6123 | else: |
|
6127 | 6124 | hint = _("use --all to revert all files") |
|
6128 | 6125 | raise error.Abort(msg, hint=hint) |
|
6129 | 6126 | |
|
6130 | 6127 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) |
|
6131 | 6128 | |
|
6132 | 6129 | @command('rollback', dryrunopts + |
|
6133 | 6130 | [('f', 'force', False, _('ignore safety measures'))]) |
|
6134 | 6131 | def rollback(ui, repo, **opts): |
|
6135 | 6132 | """roll back the last transaction (DANGEROUS) (DEPRECATED) |
|
6136 | 6133 | |
|
6137 | 6134 | Please use :hg:`commit --amend` instead of rollback to correct |
|
6138 | 6135 | mistakes in the last commit. |
|
6139 | 6136 | |
|
6140 | 6137 | This command should be used with care. There is only one level of |
|
6141 | 6138 | rollback, and there is no way to undo a rollback. It will also |
|
6142 | 6139 | restore the dirstate at the time of the last transaction, losing |
|
6143 | 6140 | any dirstate changes since that time. This command does not alter |
|
6144 | 6141 | the working directory. |
|
6145 | 6142 | |
|
6146 | 6143 | Transactions are used to encapsulate the effects of all commands |
|
6147 | 6144 | that create new changesets or propagate existing changesets into a |
|
6148 | 6145 | repository. |
|
6149 | 6146 | |
|
6150 | 6147 | .. container:: verbose |
|
6151 | 6148 | |
|
6152 | 6149 | For example, the following commands are transactional, and their |
|
6153 | 6150 | effects can be rolled back: |
|
6154 | 6151 | |
|
6155 | 6152 | - commit |
|
6156 | 6153 | - import |
|
6157 | 6154 | - pull |
|
6158 | 6155 | - push (with this repository as the destination) |
|
6159 | 6156 | - unbundle |
|
6160 | 6157 | |
|
6161 | 6158 | To avoid permanent data loss, rollback will refuse to rollback a |
|
6162 | 6159 | commit transaction if it isn't checked out. Use --force to |
|
6163 | 6160 | override this protection. |
|
6164 | 6161 | |
|
6165 | 6162 | This command is not intended for use on public repositories. Once |
|
6166 | 6163 | changes are visible for pull by other users, rolling a transaction |
|
6167 | 6164 | back locally is ineffective (someone else may already have pulled |
|
6168 | 6165 | the changes). Furthermore, a race is possible with readers of the |
|
6169 | 6166 | repository; for example an in-progress pull from the repository |
|
6170 | 6167 | may fail if a rollback is performed. |
|
6171 | 6168 | |
|
6172 | 6169 | Returns 0 on success, 1 if no rollback data is available. |
|
6173 | 6170 | """ |
|
6174 | 6171 | return repo.rollback(dryrun=opts.get('dry_run'), |
|
6175 | 6172 | force=opts.get('force')) |
|
6176 | 6173 | |
|
6177 | 6174 | @command('root', []) |
|
6178 | 6175 | def root(ui, repo): |
|
6179 | 6176 | """print the root (top) of the current working directory |
|
6180 | 6177 | |
|
6181 | 6178 | Print the root directory of the current repository. |
|
6182 | 6179 | |
|
6183 | 6180 | Returns 0 on success. |
|
6184 | 6181 | """ |
|
6185 | 6182 | ui.write(repo.root + "\n") |
|
6186 | 6183 | |
|
6187 | 6184 | @command('^serve', |
|
6188 | 6185 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
6189 | 6186 | _('FILE')), |
|
6190 | 6187 | ('d', 'daemon', None, _('run server in background')), |
|
6191 | 6188 | ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('FILE')), |
|
6192 | 6189 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
6193 | 6190 | # use string type, then we can check if something was passed |
|
6194 | 6191 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
6195 | 6192 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
6196 | 6193 | _('ADDR')), |
|
6197 | 6194 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
6198 | 6195 | _('PREFIX')), |
|
6199 | 6196 | ('n', 'name', '', |
|
6200 | 6197 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
6201 | 6198 | ('', 'web-conf', '', |
|
6202 | 6199 | _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')), |
|
6203 | 6200 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
6204 | 6201 | _('FILE')), |
|
6205 | 6202 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
6206 | 6203 | ('', 'stdio', None, _('for remote clients')), |
|
6207 | 6204 | ('', 'cmdserver', '', _('for remote clients'), _('MODE')), |
|
6208 | 6205 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
6209 | 6206 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
6210 | 6207 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
6211 | 6208 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))], |
|
6212 | 6209 | _('[OPTION]...'), |
|
6213 | 6210 | optionalrepo=True) |
|
6214 | 6211 | def serve(ui, repo, **opts): |
|
6215 | 6212 | """start stand-alone webserver |
|
6216 | 6213 | |
|
6217 | 6214 | Start a local HTTP repository browser and pull server. You can use |
|
6218 | 6215 | this for ad-hoc sharing and browsing of repositories. It is |
|
6219 | 6216 | recommended to use a real web server to serve a repository for |
|
6220 | 6217 | longer periods of time. |
|
6221 | 6218 | |
|
6222 | 6219 | Please note that the server does not implement access control. |
|
6223 | 6220 | This means that, by default, anybody can read from the server and |
|
6224 | 6221 | nobody can write to it by default. Set the ``web.allow_push`` |
|
6225 | 6222 | option to ``*`` to allow everybody to push to the server. You |
|
6226 | 6223 | should use a real web server if you need to authenticate users. |
|
6227 | 6224 | |
|
6228 | 6225 | By default, the server logs accesses to stdout and errors to |
|
6229 | 6226 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
6230 | 6227 | files. |
|
6231 | 6228 | |
|
6232 | 6229 | To have the server choose a free port number to listen on, specify |
|
6233 | 6230 | a port number of 0; in this case, the server will print the port |
|
6234 | 6231 | number it uses. |
|
6235 | 6232 | |
|
6236 | 6233 | Returns 0 on success. |
|
6237 | 6234 | """ |
|
6238 | 6235 | |
|
6239 | 6236 | if opts["stdio"] and opts["cmdserver"]: |
|
6240 | 6237 | raise error.Abort(_("cannot use --stdio with --cmdserver")) |
|
6241 | 6238 | |
|
6242 | 6239 | if opts["stdio"]: |
|
6243 | 6240 | if repo is None: |
|
6244 | 6241 | raise error.RepoError(_("there is no Mercurial repository here" |
|
6245 | 6242 | " (.hg not found)")) |
|
6246 | 6243 | s = sshserver.sshserver(ui, repo) |
|
6247 | 6244 | s.serve_forever() |
|
6248 | 6245 | |
|
6249 | 6246 | if opts["cmdserver"]: |
|
6250 | 6247 | service = commandserver.createservice(ui, repo, opts) |
|
6251 | 6248 | else: |
|
6252 | 6249 | service = hgweb.createservice(ui, repo, opts) |
|
6253 | 6250 | return cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
6254 | 6251 | |
|
6255 | 6252 | @command('^status|st', |
|
6256 | 6253 | [('A', 'all', None, _('show status of all files')), |
|
6257 | 6254 | ('m', 'modified', None, _('show only modified files')), |
|
6258 | 6255 | ('a', 'added', None, _('show only added files')), |
|
6259 | 6256 | ('r', 'removed', None, _('show only removed files')), |
|
6260 | 6257 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
6261 | 6258 | ('c', 'clean', None, _('show only files without changes')), |
|
6262 | 6259 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
6263 | 6260 | ('i', 'ignored', None, _('show only ignored files')), |
|
6264 | 6261 | ('n', 'no-status', None, _('hide status prefix')), |
|
6265 | 6262 | ('C', 'copies', None, _('show source of copied files')), |
|
6266 | 6263 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
6267 | 6264 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
6268 | 6265 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
6269 | 6266 | ] + walkopts + subrepoopts + formatteropts, |
|
6270 | 6267 | _('[OPTION]... [FILE]...'), |
|
6271 | 6268 | inferrepo=True) |
|
6272 | 6269 | def status(ui, repo, *pats, **opts): |
|
6273 | 6270 | """show changed files in the working directory |
|
6274 | 6271 | |
|
6275 | 6272 | Show status of files in the repository. If names are given, only |
|
6276 | 6273 | files that match are shown. Files that are clean or ignored or |
|
6277 | 6274 | the source of a copy/move operation, are not listed unless |
|
6278 | 6275 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
6279 | 6276 | Unless options described with "show only ..." are given, the |
|
6280 | 6277 | options -mardu are used. |
|
6281 | 6278 | |
|
6282 | 6279 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
6283 | 6280 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
6284 | 6281 | |
|
6285 | 6282 | .. note:: |
|
6286 | 6283 | |
|
6287 | 6284 | :hg:`status` may appear to disagree with diff if permissions have |
|
6288 | 6285 | changed or a merge has occurred. The standard diff format does |
|
6289 | 6286 | not report permission changes and diff only reports changes |
|
6290 | 6287 | relative to one merge parent. |
|
6291 | 6288 | |
|
6292 | 6289 | If one revision is given, it is used as the base revision. |
|
6293 | 6290 | If two revisions are given, the differences between them are |
|
6294 | 6291 | shown. The --change option can also be used as a shortcut to list |
|
6295 | 6292 | the changed files of a revision from its first parent. |
|
6296 | 6293 | |
|
6297 | 6294 | The codes used to show the status of files are:: |
|
6298 | 6295 | |
|
6299 | 6296 | M = modified |
|
6300 | 6297 | A = added |
|
6301 | 6298 | R = removed |
|
6302 | 6299 | C = clean |
|
6303 | 6300 | ! = missing (deleted by non-hg command, but still tracked) |
|
6304 | 6301 | ? = not tracked |
|
6305 | 6302 | I = ignored |
|
6306 | 6303 | = origin of the previous file (with --copies) |
|
6307 | 6304 | |
|
6308 | 6305 | .. container:: verbose |
|
6309 | 6306 | |
|
6310 | 6307 | Examples: |
|
6311 | 6308 | |
|
6312 | 6309 | - show changes in the working directory relative to a |
|
6313 | 6310 | changeset:: |
|
6314 | 6311 | |
|
6315 | 6312 | hg status --rev 9353 |
|
6316 | 6313 | |
|
6317 | 6314 | - show changes in the working directory relative to the |
|
6318 | 6315 | current directory (see :hg:`help patterns` for more information):: |
|
6319 | 6316 | |
|
6320 | 6317 | hg status re: |
|
6321 | 6318 | |
|
6322 | 6319 | - show all changes including copies in an existing changeset:: |
|
6323 | 6320 | |
|
6324 | 6321 | hg status --copies --change 9353 |
|
6325 | 6322 | |
|
6326 | 6323 | - get a NUL separated list of added files, suitable for xargs:: |
|
6327 | 6324 | |
|
6328 | 6325 | hg status -an0 |
|
6329 | 6326 | |
|
6330 | 6327 | Returns 0 on success. |
|
6331 | 6328 | """ |
|
6332 | 6329 | |
|
6333 | 6330 | revs = opts.get('rev') |
|
6334 | 6331 | change = opts.get('change') |
|
6335 | 6332 | |
|
6336 | 6333 | if revs and change: |
|
6337 | 6334 | msg = _('cannot specify --rev and --change at the same time') |
|
6338 | 6335 | raise error.Abort(msg) |
|
6339 | 6336 | elif change: |
|
6340 | 6337 | node2 = scmutil.revsingle(repo, change, None).node() |
|
6341 | 6338 | node1 = repo[node2].p1().node() |
|
6342 | 6339 | else: |
|
6343 | 6340 | node1, node2 = scmutil.revpair(repo, revs) |
|
6344 | 6341 | |
|
6345 | 6342 | if pats: |
|
6346 | 6343 | cwd = repo.getcwd() |
|
6347 | 6344 | else: |
|
6348 | 6345 | cwd = '' |
|
6349 | 6346 | |
|
6350 | 6347 | if opts.get('print0'): |
|
6351 | 6348 | end = '\0' |
|
6352 | 6349 | else: |
|
6353 | 6350 | end = '\n' |
|
6354 | 6351 | copy = {} |
|
6355 | 6352 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
6356 | 6353 | show = [k for k in states if opts.get(k)] |
|
6357 | 6354 | if opts.get('all'): |
|
6358 | 6355 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
6359 | 6356 | if not show: |
|
6360 | 6357 | if ui.quiet: |
|
6361 | 6358 | show = states[:4] |
|
6362 | 6359 | else: |
|
6363 | 6360 | show = states[:5] |
|
6364 | 6361 | |
|
6365 | 6362 | m = scmutil.match(repo[node2], pats, opts) |
|
6366 | 6363 | stat = repo.status(node1, node2, m, |
|
6367 | 6364 | 'ignored' in show, 'clean' in show, 'unknown' in show, |
|
6368 | 6365 | opts.get('subrepos')) |
|
6369 | 6366 | changestates = zip(states, 'MAR!?IC', stat) |
|
6370 | 6367 | |
|
6371 | 6368 | if (opts.get('all') or opts.get('copies') |
|
6372 | 6369 | or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): |
|
6373 | 6370 | copy = copies.pathcopies(repo[node1], repo[node2], m) |
|
6374 | 6371 | |
|
6375 | 6372 | fm = ui.formatter('status', opts) |
|
6376 | 6373 | fmt = '%s' + end |
|
6377 | 6374 | showchar = not opts.get('no_status') |
|
6378 | 6375 | |
|
6379 | 6376 | for state, char, files in changestates: |
|
6380 | 6377 | if state in show: |
|
6381 | 6378 | label = 'status.' + state |
|
6382 | 6379 | for f in files: |
|
6383 | 6380 | fm.startitem() |
|
6384 | 6381 | fm.condwrite(showchar, 'status', '%s ', char, label=label) |
|
6385 | 6382 | fm.write('path', fmt, repo.pathto(f, cwd), label=label) |
|
6386 | 6383 | if f in copy: |
|
6387 | 6384 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), |
|
6388 | 6385 | label='status.copied') |
|
6389 | 6386 | fm.end() |
|
6390 | 6387 | |
|
6391 | 6388 | @command('^summary|sum', |
|
6392 | 6389 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') |
|
6393 | 6390 | def summary(ui, repo, **opts): |
|
6394 | 6391 | """summarize working directory state |
|
6395 | 6392 | |
|
6396 | 6393 | This generates a brief summary of the working directory state, |
|
6397 | 6394 | including parents, branch, commit status, phase and available updates. |
|
6398 | 6395 | |
|
6399 | 6396 | With the --remote option, this will check the default paths for |
|
6400 | 6397 | incoming and outgoing changes. This can be time-consuming. |
|
6401 | 6398 | |
|
6402 | 6399 | Returns 0 on success. |
|
6403 | 6400 | """ |
|
6404 | 6401 | |
|
6405 | 6402 | ctx = repo[None] |
|
6406 | 6403 | parents = ctx.parents() |
|
6407 | 6404 | pnode = parents[0].node() |
|
6408 | 6405 | marks = [] |
|
6409 | 6406 | |
|
6410 | 6407 | for p in parents: |
|
6411 | 6408 | # label with log.changeset (instead of log.parent) since this |
|
6412 | 6409 | # shows a working directory parent *changeset*: |
|
6413 | 6410 | # i18n: column positioning for "hg summary" |
|
6414 | 6411 | ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), |
|
6415 | 6412 | label='log.changeset changeset.%s' % p.phasestr()) |
|
6416 | 6413 | ui.write(' '.join(p.tags()), label='log.tag') |
|
6417 | 6414 | if p.bookmarks(): |
|
6418 | 6415 | marks.extend(p.bookmarks()) |
|
6419 | 6416 | if p.rev() == -1: |
|
6420 | 6417 | if not len(repo): |
|
6421 | 6418 | ui.write(_(' (empty repository)')) |
|
6422 | 6419 | else: |
|
6423 | 6420 | ui.write(_(' (no revision checked out)')) |
|
6424 | 6421 | ui.write('\n') |
|
6425 | 6422 | if p.description(): |
|
6426 | 6423 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
6427 | 6424 | label='log.summary') |
|
6428 | 6425 | |
|
6429 | 6426 | branch = ctx.branch() |
|
6430 | 6427 | bheads = repo.branchheads(branch) |
|
6431 | 6428 | # i18n: column positioning for "hg summary" |
|
6432 | 6429 | m = _('branch: %s\n') % branch |
|
6433 | 6430 | if branch != 'default': |
|
6434 | 6431 | ui.write(m, label='log.branch') |
|
6435 | 6432 | else: |
|
6436 | 6433 | ui.status(m, label='log.branch') |
|
6437 | 6434 | |
|
6438 | 6435 | if marks: |
|
6439 | 6436 | active = repo._activebookmark |
|
6440 | 6437 | # i18n: column positioning for "hg summary" |
|
6441 | 6438 | ui.write(_('bookmarks:'), label='log.bookmark') |
|
6442 | 6439 | if active is not None: |
|
6443 | 6440 | if active in marks: |
|
6444 | 6441 | ui.write(' *' + active, label=activebookmarklabel) |
|
6445 | 6442 | marks.remove(active) |
|
6446 | 6443 | else: |
|
6447 | 6444 | ui.write(' [%s]' % active, label=activebookmarklabel) |
|
6448 | 6445 | for m in marks: |
|
6449 | 6446 | ui.write(' ' + m, label='log.bookmark') |
|
6450 | 6447 | ui.write('\n', label='log.bookmark') |
|
6451 | 6448 | |
|
6452 | 6449 | status = repo.status(unknown=True) |
|
6453 | 6450 | |
|
6454 | 6451 | c = repo.dirstate.copies() |
|
6455 | 6452 | copied, renamed = [], [] |
|
6456 | 6453 | for d, s in c.iteritems(): |
|
6457 | 6454 | if s in status.removed: |
|
6458 | 6455 | status.removed.remove(s) |
|
6459 | 6456 | renamed.append(d) |
|
6460 | 6457 | else: |
|
6461 | 6458 | copied.append(d) |
|
6462 | 6459 | if d in status.added: |
|
6463 | 6460 | status.added.remove(d) |
|
6464 | 6461 | |
|
6465 | 6462 | try: |
|
6466 | 6463 | ms = mergemod.mergestate.read(repo) |
|
6467 | 6464 | except error.UnsupportedMergeRecords as e: |
|
6468 | 6465 | s = ' '.join(e.recordtypes) |
|
6469 | 6466 | ui.warn( |
|
6470 | 6467 | _('warning: merge state has unsupported record types: %s\n') % s) |
|
6471 | 6468 | unresolved = 0 |
|
6472 | 6469 | else: |
|
6473 | 6470 | unresolved = [f for f in ms if ms[f] == 'u'] |
|
6474 | 6471 | |
|
6475 | 6472 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
6476 | 6473 | |
|
6477 | 6474 | labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), |
|
6478 | 6475 | (ui.label(_('%d added'), 'status.added'), status.added), |
|
6479 | 6476 | (ui.label(_('%d removed'), 'status.removed'), status.removed), |
|
6480 | 6477 | (ui.label(_('%d renamed'), 'status.copied'), renamed), |
|
6481 | 6478 | (ui.label(_('%d copied'), 'status.copied'), copied), |
|
6482 | 6479 | (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), |
|
6483 | 6480 | (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), |
|
6484 | 6481 | (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), |
|
6485 | 6482 | (ui.label(_('%d subrepos'), 'status.modified'), subs)] |
|
6486 | 6483 | t = [] |
|
6487 | 6484 | for l, s in labels: |
|
6488 | 6485 | if s: |
|
6489 | 6486 | t.append(l % len(s)) |
|
6490 | 6487 | |
|
6491 | 6488 | t = ', '.join(t) |
|
6492 | 6489 | cleanworkdir = False |
|
6493 | 6490 | |
|
6494 | 6491 | if repo.vfs.exists('graftstate'): |
|
6495 | 6492 | t += _(' (graft in progress)') |
|
6496 | 6493 | if repo.vfs.exists('updatestate'): |
|
6497 | 6494 | t += _(' (interrupted update)') |
|
6498 | 6495 | elif len(parents) > 1: |
|
6499 | 6496 | t += _(' (merge)') |
|
6500 | 6497 | elif branch != parents[0].branch(): |
|
6501 | 6498 | t += _(' (new branch)') |
|
6502 | 6499 | elif (parents[0].closesbranch() and |
|
6503 | 6500 | pnode in repo.branchheads(branch, closed=True)): |
|
6504 | 6501 | t += _(' (head closed)') |
|
6505 | 6502 | elif not (status.modified or status.added or status.removed or renamed or |
|
6506 | 6503 | copied or subs): |
|
6507 | 6504 | t += _(' (clean)') |
|
6508 | 6505 | cleanworkdir = True |
|
6509 | 6506 | elif pnode not in bheads: |
|
6510 | 6507 | t += _(' (new branch head)') |
|
6511 | 6508 | |
|
6512 | 6509 | if parents: |
|
6513 | 6510 | pendingphase = max(p.phase() for p in parents) |
|
6514 | 6511 | else: |
|
6515 | 6512 | pendingphase = phases.public |
|
6516 | 6513 | |
|
6517 | 6514 | if pendingphase > phases.newcommitphase(ui): |
|
6518 | 6515 | t += ' (%s)' % phases.phasenames[pendingphase] |
|
6519 | 6516 | |
|
6520 | 6517 | if cleanworkdir: |
|
6521 | 6518 | # i18n: column positioning for "hg summary" |
|
6522 | 6519 | ui.status(_('commit: %s\n') % t.strip()) |
|
6523 | 6520 | else: |
|
6524 | 6521 | # i18n: column positioning for "hg summary" |
|
6525 | 6522 | ui.write(_('commit: %s\n') % t.strip()) |
|
6526 | 6523 | |
|
6527 | 6524 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
6528 | 6525 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], |
|
6529 | 6526 | bheads)) |
|
6530 | 6527 | |
|
6531 | 6528 | if new == 0: |
|
6532 | 6529 | # i18n: column positioning for "hg summary" |
|
6533 | 6530 | ui.status(_('update: (current)\n')) |
|
6534 | 6531 | elif pnode not in bheads: |
|
6535 | 6532 | # i18n: column positioning for "hg summary" |
|
6536 | 6533 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
6537 | 6534 | else: |
|
6538 | 6535 | # i18n: column positioning for "hg summary" |
|
6539 | 6536 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
6540 | 6537 | (new, len(bheads))) |
|
6541 | 6538 | |
|
6542 | 6539 | t = [] |
|
6543 | 6540 | draft = len(repo.revs('draft()')) |
|
6544 | 6541 | if draft: |
|
6545 | 6542 | t.append(_('%d draft') % draft) |
|
6546 | 6543 | secret = len(repo.revs('secret()')) |
|
6547 | 6544 | if secret: |
|
6548 | 6545 | t.append(_('%d secret') % secret) |
|
6549 | 6546 | |
|
6550 | 6547 | if draft or secret: |
|
6551 | 6548 | ui.status(_('phases: %s\n') % ', '.join(t)) |
|
6552 | 6549 | |
|
6553 | 6550 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
6554 | 6551 | for trouble in ("unstable", "divergent", "bumped"): |
|
6555 | 6552 | numtrouble = len(repo.revs(trouble + "()")) |
|
6556 | 6553 | # We write all the possibilities to ease translation |
|
6557 | 6554 | troublemsg = { |
|
6558 | 6555 | "unstable": _("unstable: %d changesets"), |
|
6559 | 6556 | "divergent": _("divergent: %d changesets"), |
|
6560 | 6557 | "bumped": _("bumped: %d changesets"), |
|
6561 | 6558 | } |
|
6562 | 6559 | if numtrouble > 0: |
|
6563 | 6560 | ui.status(troublemsg[trouble] % numtrouble + "\n") |
|
6564 | 6561 | |
|
6565 | 6562 | cmdutil.summaryhooks(ui, repo) |
|
6566 | 6563 | |
|
6567 | 6564 | if opts.get('remote'): |
|
6568 | 6565 | needsincoming, needsoutgoing = True, True |
|
6569 | 6566 | else: |
|
6570 | 6567 | needsincoming, needsoutgoing = False, False |
|
6571 | 6568 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): |
|
6572 | 6569 | if i: |
|
6573 | 6570 | needsincoming = True |
|
6574 | 6571 | if o: |
|
6575 | 6572 | needsoutgoing = True |
|
6576 | 6573 | if not needsincoming and not needsoutgoing: |
|
6577 | 6574 | return |
|
6578 | 6575 | |
|
6579 | 6576 | def getincoming(): |
|
6580 | 6577 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
6581 | 6578 | sbranch = branches[0] |
|
6582 | 6579 | try: |
|
6583 | 6580 | other = hg.peer(repo, {}, source) |
|
6584 | 6581 | except error.RepoError: |
|
6585 | 6582 | if opts.get('remote'): |
|
6586 | 6583 | raise |
|
6587 | 6584 | return source, sbranch, None, None, None |
|
6588 | 6585 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) |
|
6589 | 6586 | if revs: |
|
6590 | 6587 | revs = [other.lookup(rev) for rev in revs] |
|
6591 | 6588 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
6592 | 6589 | repo.ui.pushbuffer() |
|
6593 | 6590 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) |
|
6594 | 6591 | repo.ui.popbuffer() |
|
6595 | 6592 | return source, sbranch, other, commoninc, commoninc[1] |
|
6596 | 6593 | |
|
6597 | 6594 | if needsincoming: |
|
6598 | 6595 | source, sbranch, sother, commoninc, incoming = getincoming() |
|
6599 | 6596 | else: |
|
6600 | 6597 | source = sbranch = sother = commoninc = incoming = None |
|
6601 | 6598 | |
|
6602 | 6599 | def getoutgoing(): |
|
6603 | 6600 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
6604 | 6601 | dbranch = branches[0] |
|
6605 | 6602 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
6606 | 6603 | if source != dest: |
|
6607 | 6604 | try: |
|
6608 | 6605 | dother = hg.peer(repo, {}, dest) |
|
6609 | 6606 | except error.RepoError: |
|
6610 | 6607 | if opts.get('remote'): |
|
6611 | 6608 | raise |
|
6612 | 6609 | return dest, dbranch, None, None |
|
6613 | 6610 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
6614 | 6611 | elif sother is None: |
|
6615 | 6612 | # there is no explicit destination peer, but source one is invalid |
|
6616 | 6613 | return dest, dbranch, None, None |
|
6617 | 6614 | else: |
|
6618 | 6615 | dother = sother |
|
6619 | 6616 | if (source != dest or (sbranch is not None and sbranch != dbranch)): |
|
6620 | 6617 | common = None |
|
6621 | 6618 | else: |
|
6622 | 6619 | common = commoninc |
|
6623 | 6620 | if revs: |
|
6624 | 6621 | revs = [repo.lookup(rev) for rev in revs] |
|
6625 | 6622 | repo.ui.pushbuffer() |
|
6626 | 6623 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, |
|
6627 | 6624 | commoninc=common) |
|
6628 | 6625 | repo.ui.popbuffer() |
|
6629 | 6626 | return dest, dbranch, dother, outgoing |
|
6630 | 6627 | |
|
6631 | 6628 | if needsoutgoing: |
|
6632 | 6629 | dest, dbranch, dother, outgoing = getoutgoing() |
|
6633 | 6630 | else: |
|
6634 | 6631 | dest = dbranch = dother = outgoing = None |
|
6635 | 6632 | |
|
6636 | 6633 | if opts.get('remote'): |
|
6637 | 6634 | t = [] |
|
6638 | 6635 | if incoming: |
|
6639 | 6636 | t.append(_('1 or more incoming')) |
|
6640 | 6637 | o = outgoing.missing |
|
6641 | 6638 | if o: |
|
6642 | 6639 | t.append(_('%d outgoing') % len(o)) |
|
6643 | 6640 | other = dother or sother |
|
6644 | 6641 | if 'bookmarks' in other.listkeys('namespaces'): |
|
6645 | 6642 | counts = bookmarks.summary(repo, other) |
|
6646 | 6643 | if counts[0] > 0: |
|
6647 | 6644 | t.append(_('%d incoming bookmarks') % counts[0]) |
|
6648 | 6645 | if counts[1] > 0: |
|
6649 | 6646 | t.append(_('%d outgoing bookmarks') % counts[1]) |
|
6650 | 6647 | |
|
6651 | 6648 | if t: |
|
6652 | 6649 | # i18n: column positioning for "hg summary" |
|
6653 | 6650 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
6654 | 6651 | else: |
|
6655 | 6652 | # i18n: column positioning for "hg summary" |
|
6656 | 6653 | ui.status(_('remote: (synced)\n')) |
|
6657 | 6654 | |
|
6658 | 6655 | cmdutil.summaryremotehooks(ui, repo, opts, |
|
6659 | 6656 | ((source, sbranch, sother, commoninc), |
|
6660 | 6657 | (dest, dbranch, dother, outgoing))) |
|
6661 | 6658 | |
|
6662 | 6659 | @command('tag', |
|
6663 | 6660 | [('f', 'force', None, _('force tag')), |
|
6664 | 6661 | ('l', 'local', None, _('make the tag local')), |
|
6665 | 6662 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
6666 | 6663 | ('', 'remove', None, _('remove a tag')), |
|
6667 | 6664 | # -l/--local is already there, commitopts cannot be used |
|
6668 | 6665 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
6669 | 6666 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), |
|
6670 | 6667 | ] + commitopts2, |
|
6671 | 6668 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
6672 | 6669 | def tag(ui, repo, name1, *names, **opts): |
|
6673 | 6670 | """add one or more tags for the current or given revision |
|
6674 | 6671 | |
|
6675 | 6672 | Name a particular revision using <name>. |
|
6676 | 6673 | |
|
6677 | 6674 | Tags are used to name particular revisions of the repository and are |
|
6678 | 6675 | very useful to compare different revisions, to go back to significant |
|
6679 | 6676 | earlier versions or to mark branch points as releases, etc. Changing |
|
6680 | 6677 | an existing tag is normally disallowed; use -f/--force to override. |
|
6681 | 6678 | |
|
6682 | 6679 | If no revision is given, the parent of the working directory is |
|
6683 | 6680 | used. |
|
6684 | 6681 | |
|
6685 | 6682 | To facilitate version control, distribution, and merging of tags, |
|
6686 | 6683 | they are stored as a file named ".hgtags" which is managed similarly |
|
6687 | 6684 | to other project files and can be hand-edited if necessary. This |
|
6688 | 6685 | also means that tagging creates a new commit. The file |
|
6689 | 6686 | ".hg/localtags" is used for local tags (not shared among |
|
6690 | 6687 | repositories). |
|
6691 | 6688 | |
|
6692 | 6689 | Tag commits are usually made at the head of a branch. If the parent |
|
6693 | 6690 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
6694 | 6691 | -f/--force to force the tag commit to be based on a non-head |
|
6695 | 6692 | changeset. |
|
6696 | 6693 | |
|
6697 | 6694 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
6698 | 6695 | |
|
6699 | 6696 | Since tag names have priority over branch names during revision |
|
6700 | 6697 | lookup, using an existing branch name as a tag name is discouraged. |
|
6701 | 6698 | |
|
6702 | 6699 | Returns 0 on success. |
|
6703 | 6700 | """ |
|
6704 | 6701 | wlock = lock = None |
|
6705 | 6702 | try: |
|
6706 | 6703 | wlock = repo.wlock() |
|
6707 | 6704 | lock = repo.lock() |
|
6708 | 6705 | rev_ = "." |
|
6709 | 6706 | names = [t.strip() for t in (name1,) + names] |
|
6710 | 6707 | if len(names) != len(set(names)): |
|
6711 | 6708 | raise error.Abort(_('tag names must be unique')) |
|
6712 | 6709 | for n in names: |
|
6713 | 6710 | scmutil.checknewlabel(repo, n, 'tag') |
|
6714 | 6711 | if not n: |
|
6715 | 6712 | raise error.Abort(_('tag names cannot consist entirely of ' |
|
6716 | 6713 | 'whitespace')) |
|
6717 | 6714 | if opts.get('rev') and opts.get('remove'): |
|
6718 | 6715 | raise error.Abort(_("--rev and --remove are incompatible")) |
|
6719 | 6716 | if opts.get('rev'): |
|
6720 | 6717 | rev_ = opts['rev'] |
|
6721 | 6718 | message = opts.get('message') |
|
6722 | 6719 | if opts.get('remove'): |
|
6723 | 6720 | if opts.get('local'): |
|
6724 | 6721 | expectedtype = 'local' |
|
6725 | 6722 | else: |
|
6726 | 6723 | expectedtype = 'global' |
|
6727 | 6724 | |
|
6728 | 6725 | for n in names: |
|
6729 | 6726 | if not repo.tagtype(n): |
|
6730 | 6727 | raise error.Abort(_("tag '%s' does not exist") % n) |
|
6731 | 6728 | if repo.tagtype(n) != expectedtype: |
|
6732 | 6729 | if expectedtype == 'global': |
|
6733 | 6730 | raise error.Abort(_("tag '%s' is not a global tag") % n) |
|
6734 | 6731 | else: |
|
6735 | 6732 | raise error.Abort(_("tag '%s' is not a local tag") % n) |
|
6736 | 6733 | rev_ = 'null' |
|
6737 | 6734 | if not message: |
|
6738 | 6735 | # we don't translate commit messages |
|
6739 | 6736 | message = 'Removed tag %s' % ', '.join(names) |
|
6740 | 6737 | elif not opts.get('force'): |
|
6741 | 6738 | for n in names: |
|
6742 | 6739 | if n in repo.tags(): |
|
6743 | 6740 | raise error.Abort(_("tag '%s' already exists " |
|
6744 | 6741 | "(use -f to force)") % n) |
|
6745 | 6742 | if not opts.get('local'): |
|
6746 | 6743 | p1, p2 = repo.dirstate.parents() |
|
6747 | 6744 | if p2 != nullid: |
|
6748 | 6745 | raise error.Abort(_('uncommitted merge')) |
|
6749 | 6746 | bheads = repo.branchheads() |
|
6750 | 6747 | if not opts.get('force') and bheads and p1 not in bheads: |
|
6751 | 6748 | raise error.Abort(_('not at a branch head (use -f to force)')) |
|
6752 | 6749 | r = scmutil.revsingle(repo, rev_).node() |
|
6753 | 6750 | |
|
6754 | 6751 | if not message: |
|
6755 | 6752 | # we don't translate commit messages |
|
6756 | 6753 | message = ('Added tag %s for changeset %s' % |
|
6757 | 6754 | (', '.join(names), short(r))) |
|
6758 | 6755 | |
|
6759 | 6756 | date = opts.get('date') |
|
6760 | 6757 | if date: |
|
6761 | 6758 | date = util.parsedate(date) |
|
6762 | 6759 | |
|
6763 | 6760 | if opts.get('remove'): |
|
6764 | 6761 | editform = 'tag.remove' |
|
6765 | 6762 | else: |
|
6766 | 6763 | editform = 'tag.add' |
|
6767 | 6764 | editor = cmdutil.getcommiteditor(editform=editform, **opts) |
|
6768 | 6765 | |
|
6769 | 6766 | # don't allow tagging the null rev |
|
6770 | 6767 | if (not opts.get('remove') and |
|
6771 | 6768 | scmutil.revsingle(repo, rev_).rev() == nullrev): |
|
6772 | 6769 | raise error.Abort(_("cannot tag null revision")) |
|
6773 | 6770 | |
|
6774 | 6771 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date, |
|
6775 | 6772 | editor=editor) |
|
6776 | 6773 | finally: |
|
6777 | 6774 | release(lock, wlock) |
|
6778 | 6775 | |
|
6779 | 6776 | @command('tags', formatteropts, '') |
|
6780 | 6777 | def tags(ui, repo, **opts): |
|
6781 | 6778 | """list repository tags |
|
6782 | 6779 | |
|
6783 | 6780 | This lists both regular and local tags. When the -v/--verbose |
|
6784 | 6781 | switch is used, a third column "local" is printed for local tags. |
|
6785 | 6782 | When the -q/--quiet switch is used, only the tag name is printed. |
|
6786 | 6783 | |
|
6787 | 6784 | Returns 0 on success. |
|
6788 | 6785 | """ |
|
6789 | 6786 | |
|
6790 | 6787 | fm = ui.formatter('tags', opts) |
|
6791 | 6788 | hexfunc = fm.hexfunc |
|
6792 | 6789 | tagtype = "" |
|
6793 | 6790 | |
|
6794 | 6791 | for t, n in reversed(repo.tagslist()): |
|
6795 | 6792 | hn = hexfunc(n) |
|
6796 | 6793 | label = 'tags.normal' |
|
6797 | 6794 | tagtype = '' |
|
6798 | 6795 | if repo.tagtype(t) == 'local': |
|
6799 | 6796 | label = 'tags.local' |
|
6800 | 6797 | tagtype = 'local' |
|
6801 | 6798 | |
|
6802 | 6799 | fm.startitem() |
|
6803 | 6800 | fm.write('tag', '%s', t, label=label) |
|
6804 | 6801 | fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' |
|
6805 | 6802 | fm.condwrite(not ui.quiet, 'rev node', fmt, |
|
6806 | 6803 | repo.changelog.rev(n), hn, label=label) |
|
6807 | 6804 | fm.condwrite(ui.verbose and tagtype, 'type', ' %s', |
|
6808 | 6805 | tagtype, label=label) |
|
6809 | 6806 | fm.plain('\n') |
|
6810 | 6807 | fm.end() |
|
6811 | 6808 | |
|
6812 | 6809 | @command('tip', |
|
6813 | 6810 | [('p', 'patch', None, _('show patch')), |
|
6814 | 6811 | ('g', 'git', None, _('use git extended diff format')), |
|
6815 | 6812 | ] + templateopts, |
|
6816 | 6813 | _('[-p] [-g]')) |
|
6817 | 6814 | def tip(ui, repo, **opts): |
|
6818 | 6815 | """show the tip revision (DEPRECATED) |
|
6819 | 6816 | |
|
6820 | 6817 | The tip revision (usually just called the tip) is the changeset |
|
6821 | 6818 | most recently added to the repository (and therefore the most |
|
6822 | 6819 | recently changed head). |
|
6823 | 6820 | |
|
6824 | 6821 | If you have just made a commit, that commit will be the tip. If |
|
6825 | 6822 | you have just pulled changes from another repository, the tip of |
|
6826 | 6823 | that repository becomes the current tip. The "tip" tag is special |
|
6827 | 6824 | and cannot be renamed or assigned to a different changeset. |
|
6828 | 6825 | |
|
6829 | 6826 | This command is deprecated, please use :hg:`heads` instead. |
|
6830 | 6827 | |
|
6831 | 6828 | Returns 0 on success. |
|
6832 | 6829 | """ |
|
6833 | 6830 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
6834 | 6831 | displayer.show(repo['tip']) |
|
6835 | 6832 | displayer.close() |
|
6836 | 6833 | |
|
6837 | 6834 | @command('unbundle', |
|
6838 | 6835 | [('u', 'update', None, |
|
6839 | 6836 | _('update to new branch head if changesets were unbundled'))], |
|
6840 | 6837 | _('[-u] FILE...')) |
|
6841 | 6838 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
6842 | 6839 | """apply one or more changegroup files |
|
6843 | 6840 | |
|
6844 | 6841 | Apply one or more compressed changegroup files generated by the |
|
6845 | 6842 | bundle command. |
|
6846 | 6843 | |
|
6847 | 6844 | Returns 0 on success, 1 if an update has unresolved files. |
|
6848 | 6845 | """ |
|
6849 | 6846 | fnames = (fname1,) + fnames |
|
6850 | 6847 | |
|
6851 | 6848 | with repo.lock(): |
|
6852 | 6849 | for fname in fnames: |
|
6853 | 6850 | f = hg.openpath(ui, fname) |
|
6854 | 6851 | gen = exchange.readbundle(ui, f, fname) |
|
6855 | 6852 | if isinstance(gen, bundle2.unbundle20): |
|
6856 | 6853 | tr = repo.transaction('unbundle') |
|
6857 | 6854 | try: |
|
6858 | 6855 | op = bundle2.applybundle(repo, gen, tr, source='unbundle', |
|
6859 | 6856 | url='bundle:' + fname) |
|
6860 | 6857 | tr.close() |
|
6861 | 6858 | except error.BundleUnknownFeatureError as exc: |
|
6862 | 6859 | raise error.Abort(_('%s: unknown bundle feature, %s') |
|
6863 | 6860 | % (fname, exc), |
|
6864 | 6861 | hint=_("see https://mercurial-scm.org/" |
|
6865 | 6862 | "wiki/BundleFeature for more " |
|
6866 | 6863 | "information")) |
|
6867 | 6864 | finally: |
|
6868 | 6865 | if tr: |
|
6869 | 6866 | tr.release() |
|
6870 | 6867 | changes = [r.get('return', 0) |
|
6871 | 6868 | for r in op.records['changegroup']] |
|
6872 | 6869 | modheads = changegroup.combineresults(changes) |
|
6873 | 6870 | elif isinstance(gen, streamclone.streamcloneapplier): |
|
6874 | 6871 | raise error.Abort( |
|
6875 | 6872 | _('packed bundles cannot be applied with ' |
|
6876 | 6873 | '"hg unbundle"'), |
|
6877 | 6874 | hint=_('use "hg debugapplystreamclonebundle"')) |
|
6878 | 6875 | else: |
|
6879 | 6876 | modheads = gen.apply(repo, 'unbundle', 'bundle:' + fname) |
|
6880 | 6877 | |
|
6881 | 6878 | return postincoming(ui, repo, modheads, opts.get('update'), None) |
|
6882 | 6879 | |
|
6883 | 6880 | @command('^update|up|checkout|co', |
|
6884 | 6881 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
6885 | 6882 | ('c', 'check', None, |
|
6886 | 6883 | _('update across branches if no uncommitted changes')), |
|
6887 | 6884 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
6888 | 6885 | ('r', 'rev', '', _('revision'), _('REV')) |
|
6889 | 6886 | ] + mergetoolopts, |
|
6890 | 6887 | _('[-c] [-C] [-d DATE] [[-r] REV]')) |
|
6891 | 6888 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False, |
|
6892 | 6889 | tool=None): |
|
6893 | 6890 | """update working directory (or switch revisions) |
|
6894 | 6891 | |
|
6895 | 6892 | Update the repository's working directory to the specified |
|
6896 | 6893 | changeset. If no changeset is specified, update to the tip of the |
|
6897 | 6894 | current named branch and move the active bookmark (see :hg:`help |
|
6898 | 6895 | bookmarks`). |
|
6899 | 6896 | |
|
6900 | 6897 | Update sets the working directory's parent revision to the specified |
|
6901 | 6898 | changeset (see :hg:`help parents`). |
|
6902 | 6899 | |
|
6903 | 6900 | If the changeset is not a descendant or ancestor of the working |
|
6904 | 6901 | directory's parent, the update is aborted. With the -c/--check |
|
6905 | 6902 | option, the working directory is checked for uncommitted changes; if |
|
6906 | 6903 | none are found, the working directory is updated to the specified |
|
6907 | 6904 | changeset. |
|
6908 | 6905 | |
|
6909 | 6906 | .. container:: verbose |
|
6910 | 6907 | |
|
6911 | 6908 | The following rules apply when the working directory contains |
|
6912 | 6909 | uncommitted changes: |
|
6913 | 6910 | |
|
6914 | 6911 | 1. If neither -c/--check nor -C/--clean is specified, and if |
|
6915 | 6912 | the requested changeset is an ancestor or descendant of |
|
6916 | 6913 | the working directory's parent, the uncommitted changes |
|
6917 | 6914 | are merged into the requested changeset and the merged |
|
6918 | 6915 | result is left uncommitted. If the requested changeset is |
|
6919 | 6916 | not an ancestor or descendant (that is, it is on another |
|
6920 | 6917 | branch), the update is aborted and the uncommitted changes |
|
6921 | 6918 | are preserved. |
|
6922 | 6919 | |
|
6923 | 6920 | 2. With the -c/--check option, the update is aborted and the |
|
6924 | 6921 | uncommitted changes are preserved. |
|
6925 | 6922 | |
|
6926 | 6923 | 3. With the -C/--clean option, uncommitted changes are discarded and |
|
6927 | 6924 | the working directory is updated to the requested changeset. |
|
6928 | 6925 | |
|
6929 | 6926 | To cancel an uncommitted merge (and lose your changes), use |
|
6930 | 6927 | :hg:`update --clean .`. |
|
6931 | 6928 | |
|
6932 | 6929 | Use null as the changeset to remove the working directory (like |
|
6933 | 6930 | :hg:`clone -U`). |
|
6934 | 6931 | |
|
6935 | 6932 | If you want to revert just one file to an older revision, use |
|
6936 | 6933 | :hg:`revert [-r REV] NAME`. |
|
6937 | 6934 | |
|
6938 | 6935 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
6939 | 6936 | |
|
6940 | 6937 | Returns 0 on success, 1 if there are unresolved files. |
|
6941 | 6938 | """ |
|
6942 | 6939 | movemarkfrom = None |
|
6943 | 6940 | if rev and node: |
|
6944 | 6941 | raise error.Abort(_("please specify just one revision")) |
|
6945 | 6942 | |
|
6946 | 6943 | if rev is None or rev == '': |
|
6947 | 6944 | rev = node |
|
6948 | 6945 | |
|
6949 | 6946 | with repo.wlock(): |
|
6950 | 6947 | cmdutil.clearunfinished(repo) |
|
6951 | 6948 | |
|
6952 | 6949 | if date: |
|
6953 | 6950 | if rev is not None: |
|
6954 | 6951 | raise error.Abort(_("you can't specify a revision and a date")) |
|
6955 | 6952 | rev = cmdutil.finddate(ui, repo, date) |
|
6956 | 6953 | |
|
6957 | 6954 | # if we defined a bookmark, we have to remember the original name |
|
6958 | 6955 | brev = rev |
|
6959 | 6956 | rev = scmutil.revsingle(repo, rev, rev).rev() |
|
6960 | 6957 | |
|
6961 | 6958 | if check and clean: |
|
6962 | 6959 | raise error.Abort(_("cannot specify both -c/--check and -C/--clean") |
|
6963 | 6960 | ) |
|
6964 | 6961 | |
|
6965 | 6962 | if check: |
|
6966 | 6963 | cmdutil.bailifchanged(repo, merge=False) |
|
6967 | 6964 | if rev is None: |
|
6968 | 6965 | updata = destutil.destupdate(repo, clean=clean, check=check) |
|
6969 | 6966 | rev, movemarkfrom, brev = updata |
|
6970 | 6967 | |
|
6971 | 6968 | repo.ui.setconfig('ui', 'forcemerge', tool, 'update') |
|
6972 | 6969 | |
|
6973 | 6970 | if clean: |
|
6974 | 6971 | ret = hg.clean(repo, rev) |
|
6975 | 6972 | else: |
|
6976 | 6973 | ret = hg.update(repo, rev) |
|
6977 | 6974 | |
|
6978 | 6975 | if not ret and movemarkfrom: |
|
6979 | 6976 | if movemarkfrom == repo['.'].node(): |
|
6980 | 6977 | pass # no-op update |
|
6981 | 6978 | elif bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
6982 | 6979 | ui.status(_("updating bookmark %s\n") % repo._activebookmark) |
|
6983 | 6980 | else: |
|
6984 | 6981 | # this can happen with a non-linear update |
|
6985 | 6982 | ui.status(_("(leaving bookmark %s)\n") % |
|
6986 | 6983 | repo._activebookmark) |
|
6987 | 6984 | bookmarks.deactivate(repo) |
|
6988 | 6985 | elif brev in repo._bookmarks: |
|
6989 | 6986 | bookmarks.activate(repo, brev) |
|
6990 | 6987 | ui.status(_("(activating bookmark %s)\n") % brev) |
|
6991 | 6988 | elif brev: |
|
6992 | 6989 | if repo._activebookmark: |
|
6993 | 6990 | ui.status(_("(leaving bookmark %s)\n") % |
|
6994 | 6991 | repo._activebookmark) |
|
6995 | 6992 | bookmarks.deactivate(repo) |
|
6996 | 6993 | |
|
6997 | 6994 | return ret |
|
6998 | 6995 | |
|
6999 | 6996 | @command('verify', []) |
|
7000 | 6997 | def verify(ui, repo): |
|
7001 | 6998 | """verify the integrity of the repository |
|
7002 | 6999 | |
|
7003 | 7000 | Verify the integrity of the current repository. |
|
7004 | 7001 | |
|
7005 | 7002 | This will perform an extensive check of the repository's |
|
7006 | 7003 | integrity, validating the hashes and checksums of each entry in |
|
7007 | 7004 | the changelog, manifest, and tracked files, as well as the |
|
7008 | 7005 | integrity of their crosslinks and indices. |
|
7009 | 7006 | |
|
7010 | 7007 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption |
|
7011 | 7008 | for more information about recovery from corruption of the |
|
7012 | 7009 | repository. |
|
7013 | 7010 | |
|
7014 | 7011 | Returns 0 on success, 1 if errors are encountered. |
|
7015 | 7012 | """ |
|
7016 | 7013 | return hg.verify(repo) |
|
7017 | 7014 | |
|
7018 | 7015 | @command('version', [], norepo=True) |
|
7019 | 7016 | def version_(ui): |
|
7020 | 7017 | """output version and copyright information""" |
|
7021 | 7018 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
7022 | 7019 | % util.version()) |
|
7023 | 7020 | ui.status(_( |
|
7024 | 7021 | "(see https://mercurial-scm.org for more information)\n" |
|
7025 | 7022 | "\nCopyright (C) 2005-2016 Matt Mackall and others\n" |
|
7026 | 7023 | "This is free software; see the source for copying conditions. " |
|
7027 | 7024 | "There is NO\nwarranty; " |
|
7028 | 7025 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
7029 | 7026 | )) |
|
7030 | 7027 | |
|
7031 | 7028 | ui.note(_("\nEnabled extensions:\n\n")) |
|
7032 | 7029 | if ui.verbose: |
|
7033 | 7030 | # format names and versions into columns |
|
7034 | 7031 | names = [] |
|
7035 | 7032 | vers = [] |
|
7036 | 7033 | for name, module in extensions.extensions(): |
|
7037 | 7034 | names.append(name) |
|
7038 | 7035 | vers.append(extensions.moduleversion(module)) |
|
7039 | 7036 | if names: |
|
7040 | 7037 | maxnamelen = max(len(n) for n in names) |
|
7041 | 7038 | for i, name in enumerate(names): |
|
7042 | 7039 | ui.write(" %-*s %s\n" % (maxnamelen, name, vers[i])) |
General Comments 0
You need to be logged in to leave comments.
Login now