##// END OF EJS Templates
import: add --partial flag to create a changeset despite failed hunks...
Pierre-Yves David -
r21553:bee0e1cf default
parent child Browse files
Show More
@@ -1,2501 +1,2511 b''
1 # cmdutil.py - help for command processing in mercurial
1 # cmdutil.py - help for command processing in mercurial
2 #
2 #
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from node import hex, nullid, nullrev, short
8 from node import hex, nullid, nullrev, short
9 from i18n import _
9 from i18n import _
10 import os, sys, errno, re, tempfile
10 import os, sys, errno, re, tempfile
11 import util, scmutil, templater, patch, error, templatekw, revlog, copies
11 import util, scmutil, templater, patch, error, templatekw, revlog, copies
12 import match as matchmod
12 import match as matchmod
13 import context, repair, graphmod, revset, phases, obsolete, pathutil
13 import context, repair, graphmod, revset, phases, obsolete, pathutil
14 import changelog
14 import changelog
15 import bookmarks
15 import bookmarks
16 import lock as lockmod
16 import lock as lockmod
17
17
18 def parsealiases(cmd):
18 def parsealiases(cmd):
19 return cmd.lstrip("^").split("|")
19 return cmd.lstrip("^").split("|")
20
20
21 def findpossible(cmd, table, strict=False):
21 def findpossible(cmd, table, strict=False):
22 """
22 """
23 Return cmd -> (aliases, command table entry)
23 Return cmd -> (aliases, command table entry)
24 for each matching command.
24 for each matching command.
25 Return debug commands (or their aliases) only if no normal command matches.
25 Return debug commands (or their aliases) only if no normal command matches.
26 """
26 """
27 choice = {}
27 choice = {}
28 debugchoice = {}
28 debugchoice = {}
29
29
30 if cmd in table:
30 if cmd in table:
31 # short-circuit exact matches, "log" alias beats "^log|history"
31 # short-circuit exact matches, "log" alias beats "^log|history"
32 keys = [cmd]
32 keys = [cmd]
33 else:
33 else:
34 keys = table.keys()
34 keys = table.keys()
35
35
36 for e in keys:
36 for e in keys:
37 aliases = parsealiases(e)
37 aliases = parsealiases(e)
38 found = None
38 found = None
39 if cmd in aliases:
39 if cmd in aliases:
40 found = cmd
40 found = cmd
41 elif not strict:
41 elif not strict:
42 for a in aliases:
42 for a in aliases:
43 if a.startswith(cmd):
43 if a.startswith(cmd):
44 found = a
44 found = a
45 break
45 break
46 if found is not None:
46 if found is not None:
47 if aliases[0].startswith("debug") or found.startswith("debug"):
47 if aliases[0].startswith("debug") or found.startswith("debug"):
48 debugchoice[found] = (aliases, table[e])
48 debugchoice[found] = (aliases, table[e])
49 else:
49 else:
50 choice[found] = (aliases, table[e])
50 choice[found] = (aliases, table[e])
51
51
52 if not choice and debugchoice:
52 if not choice and debugchoice:
53 choice = debugchoice
53 choice = debugchoice
54
54
55 return choice
55 return choice
56
56
57 def findcmd(cmd, table, strict=True):
57 def findcmd(cmd, table, strict=True):
58 """Return (aliases, command table entry) for command string."""
58 """Return (aliases, command table entry) for command string."""
59 choice = findpossible(cmd, table, strict)
59 choice = findpossible(cmd, table, strict)
60
60
61 if cmd in choice:
61 if cmd in choice:
62 return choice[cmd]
62 return choice[cmd]
63
63
64 if len(choice) > 1:
64 if len(choice) > 1:
65 clist = choice.keys()
65 clist = choice.keys()
66 clist.sort()
66 clist.sort()
67 raise error.AmbiguousCommand(cmd, clist)
67 raise error.AmbiguousCommand(cmd, clist)
68
68
69 if choice:
69 if choice:
70 return choice.values()[0]
70 return choice.values()[0]
71
71
72 raise error.UnknownCommand(cmd)
72 raise error.UnknownCommand(cmd)
73
73
74 def findrepo(p):
74 def findrepo(p):
75 while not os.path.isdir(os.path.join(p, ".hg")):
75 while not os.path.isdir(os.path.join(p, ".hg")):
76 oldp, p = p, os.path.dirname(p)
76 oldp, p = p, os.path.dirname(p)
77 if p == oldp:
77 if p == oldp:
78 return None
78 return None
79
79
80 return p
80 return p
81
81
82 def bailifchanged(repo):
82 def bailifchanged(repo):
83 if repo.dirstate.p2() != nullid:
83 if repo.dirstate.p2() != nullid:
84 raise util.Abort(_('outstanding uncommitted merge'))
84 raise util.Abort(_('outstanding uncommitted merge'))
85 modified, added, removed, deleted = repo.status()[:4]
85 modified, added, removed, deleted = repo.status()[:4]
86 if modified or added or removed or deleted:
86 if modified or added or removed or deleted:
87 raise util.Abort(_('uncommitted changes'))
87 raise util.Abort(_('uncommitted changes'))
88 ctx = repo[None]
88 ctx = repo[None]
89 for s in sorted(ctx.substate):
89 for s in sorted(ctx.substate):
90 if ctx.sub(s).dirty():
90 if ctx.sub(s).dirty():
91 raise util.Abort(_("uncommitted changes in subrepo %s") % s)
91 raise util.Abort(_("uncommitted changes in subrepo %s") % s)
92
92
93 def logmessage(ui, opts):
93 def logmessage(ui, opts):
94 """ get the log message according to -m and -l option """
94 """ get the log message according to -m and -l option """
95 message = opts.get('message')
95 message = opts.get('message')
96 logfile = opts.get('logfile')
96 logfile = opts.get('logfile')
97
97
98 if message and logfile:
98 if message and logfile:
99 raise util.Abort(_('options --message and --logfile are mutually '
99 raise util.Abort(_('options --message and --logfile are mutually '
100 'exclusive'))
100 'exclusive'))
101 if not message and logfile:
101 if not message and logfile:
102 try:
102 try:
103 if logfile == '-':
103 if logfile == '-':
104 message = ui.fin.read()
104 message = ui.fin.read()
105 else:
105 else:
106 message = '\n'.join(util.readfile(logfile).splitlines())
106 message = '\n'.join(util.readfile(logfile).splitlines())
107 except IOError, inst:
107 except IOError, inst:
108 raise util.Abort(_("can't read commit message '%s': %s") %
108 raise util.Abort(_("can't read commit message '%s': %s") %
109 (logfile, inst.strerror))
109 (logfile, inst.strerror))
110 return message
110 return message
111
111
112 def getcommiteditor(edit=False, finishdesc=None, extramsg=None, **opts):
112 def getcommiteditor(edit=False, finishdesc=None, extramsg=None, **opts):
113 """get appropriate commit message editor according to '--edit' option
113 """get appropriate commit message editor according to '--edit' option
114
114
115 'finishdesc' is a function to be called with edited commit message
115 'finishdesc' is a function to be called with edited commit message
116 (= 'description' of the new changeset) just after editing, but
116 (= 'description' of the new changeset) just after editing, but
117 before checking empty-ness. It should return actual text to be
117 before checking empty-ness. It should return actual text to be
118 stored into history. This allows to change description before
118 stored into history. This allows to change description before
119 storing.
119 storing.
120
120
121 'extramsg' is a extra message to be shown in the editor instead of
121 'extramsg' is a extra message to be shown in the editor instead of
122 'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
122 'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
123 is automatically added.
123 is automatically added.
124
124
125 'getcommiteditor' returns 'commitforceeditor' regardless of
125 'getcommiteditor' returns 'commitforceeditor' regardless of
126 'edit', if one of 'finishdesc' or 'extramsg' is specified, because
126 'edit', if one of 'finishdesc' or 'extramsg' is specified, because
127 they are specific for usage in MQ.
127 they are specific for usage in MQ.
128 """
128 """
129 if edit or finishdesc or extramsg:
129 if edit or finishdesc or extramsg:
130 return lambda r, c, s: commitforceeditor(r, c, s,
130 return lambda r, c, s: commitforceeditor(r, c, s,
131 finishdesc=finishdesc,
131 finishdesc=finishdesc,
132 extramsg=extramsg)
132 extramsg=extramsg)
133 else:
133 else:
134 return commiteditor
134 return commiteditor
135
135
136 def loglimit(opts):
136 def loglimit(opts):
137 """get the log limit according to option -l/--limit"""
137 """get the log limit according to option -l/--limit"""
138 limit = opts.get('limit')
138 limit = opts.get('limit')
139 if limit:
139 if limit:
140 try:
140 try:
141 limit = int(limit)
141 limit = int(limit)
142 except ValueError:
142 except ValueError:
143 raise util.Abort(_('limit must be a positive integer'))
143 raise util.Abort(_('limit must be a positive integer'))
144 if limit <= 0:
144 if limit <= 0:
145 raise util.Abort(_('limit must be positive'))
145 raise util.Abort(_('limit must be positive'))
146 else:
146 else:
147 limit = None
147 limit = None
148 return limit
148 return limit
149
149
150 def makefilename(repo, pat, node, desc=None,
150 def makefilename(repo, pat, node, desc=None,
151 total=None, seqno=None, revwidth=None, pathname=None):
151 total=None, seqno=None, revwidth=None, pathname=None):
152 node_expander = {
152 node_expander = {
153 'H': lambda: hex(node),
153 'H': lambda: hex(node),
154 'R': lambda: str(repo.changelog.rev(node)),
154 'R': lambda: str(repo.changelog.rev(node)),
155 'h': lambda: short(node),
155 'h': lambda: short(node),
156 'm': lambda: re.sub('[^\w]', '_', str(desc))
156 'm': lambda: re.sub('[^\w]', '_', str(desc))
157 }
157 }
158 expander = {
158 expander = {
159 '%': lambda: '%',
159 '%': lambda: '%',
160 'b': lambda: os.path.basename(repo.root),
160 'b': lambda: os.path.basename(repo.root),
161 }
161 }
162
162
163 try:
163 try:
164 if node:
164 if node:
165 expander.update(node_expander)
165 expander.update(node_expander)
166 if node:
166 if node:
167 expander['r'] = (lambda:
167 expander['r'] = (lambda:
168 str(repo.changelog.rev(node)).zfill(revwidth or 0))
168 str(repo.changelog.rev(node)).zfill(revwidth or 0))
169 if total is not None:
169 if total is not None:
170 expander['N'] = lambda: str(total)
170 expander['N'] = lambda: str(total)
171 if seqno is not None:
171 if seqno is not None:
172 expander['n'] = lambda: str(seqno)
172 expander['n'] = lambda: str(seqno)
173 if total is not None and seqno is not None:
173 if total is not None and seqno is not None:
174 expander['n'] = lambda: str(seqno).zfill(len(str(total)))
174 expander['n'] = lambda: str(seqno).zfill(len(str(total)))
175 if pathname is not None:
175 if pathname is not None:
176 expander['s'] = lambda: os.path.basename(pathname)
176 expander['s'] = lambda: os.path.basename(pathname)
177 expander['d'] = lambda: os.path.dirname(pathname) or '.'
177 expander['d'] = lambda: os.path.dirname(pathname) or '.'
178 expander['p'] = lambda: pathname
178 expander['p'] = lambda: pathname
179
179
180 newname = []
180 newname = []
181 patlen = len(pat)
181 patlen = len(pat)
182 i = 0
182 i = 0
183 while i < patlen:
183 while i < patlen:
184 c = pat[i]
184 c = pat[i]
185 if c == '%':
185 if c == '%':
186 i += 1
186 i += 1
187 c = pat[i]
187 c = pat[i]
188 c = expander[c]()
188 c = expander[c]()
189 newname.append(c)
189 newname.append(c)
190 i += 1
190 i += 1
191 return ''.join(newname)
191 return ''.join(newname)
192 except KeyError, inst:
192 except KeyError, inst:
193 raise util.Abort(_("invalid format spec '%%%s' in output filename") %
193 raise util.Abort(_("invalid format spec '%%%s' in output filename") %
194 inst.args[0])
194 inst.args[0])
195
195
196 def makefileobj(repo, pat, node=None, desc=None, total=None,
196 def makefileobj(repo, pat, node=None, desc=None, total=None,
197 seqno=None, revwidth=None, mode='wb', modemap=None,
197 seqno=None, revwidth=None, mode='wb', modemap=None,
198 pathname=None):
198 pathname=None):
199
199
200 writable = mode not in ('r', 'rb')
200 writable = mode not in ('r', 'rb')
201
201
202 if not pat or pat == '-':
202 if not pat or pat == '-':
203 fp = writable and repo.ui.fout or repo.ui.fin
203 fp = writable and repo.ui.fout or repo.ui.fin
204 if util.safehasattr(fp, 'fileno'):
204 if util.safehasattr(fp, 'fileno'):
205 return os.fdopen(os.dup(fp.fileno()), mode)
205 return os.fdopen(os.dup(fp.fileno()), mode)
206 else:
206 else:
207 # if this fp can't be duped properly, return
207 # if this fp can't be duped properly, return
208 # a dummy object that can be closed
208 # a dummy object that can be closed
209 class wrappedfileobj(object):
209 class wrappedfileobj(object):
210 noop = lambda x: None
210 noop = lambda x: None
211 def __init__(self, f):
211 def __init__(self, f):
212 self.f = f
212 self.f = f
213 def __getattr__(self, attr):
213 def __getattr__(self, attr):
214 if attr == 'close':
214 if attr == 'close':
215 return self.noop
215 return self.noop
216 else:
216 else:
217 return getattr(self.f, attr)
217 return getattr(self.f, attr)
218
218
219 return wrappedfileobj(fp)
219 return wrappedfileobj(fp)
220 if util.safehasattr(pat, 'write') and writable:
220 if util.safehasattr(pat, 'write') and writable:
221 return pat
221 return pat
222 if util.safehasattr(pat, 'read') and 'r' in mode:
222 if util.safehasattr(pat, 'read') and 'r' in mode:
223 return pat
223 return pat
224 fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname)
224 fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname)
225 if modemap is not None:
225 if modemap is not None:
226 mode = modemap.get(fn, mode)
226 mode = modemap.get(fn, mode)
227 if mode == 'wb':
227 if mode == 'wb':
228 modemap[fn] = 'ab'
228 modemap[fn] = 'ab'
229 return open(fn, mode)
229 return open(fn, mode)
230
230
231 def openrevlog(repo, cmd, file_, opts):
231 def openrevlog(repo, cmd, file_, opts):
232 """opens the changelog, manifest, a filelog or a given revlog"""
232 """opens the changelog, manifest, a filelog or a given revlog"""
233 cl = opts['changelog']
233 cl = opts['changelog']
234 mf = opts['manifest']
234 mf = opts['manifest']
235 msg = None
235 msg = None
236 if cl and mf:
236 if cl and mf:
237 msg = _('cannot specify --changelog and --manifest at the same time')
237 msg = _('cannot specify --changelog and --manifest at the same time')
238 elif cl or mf:
238 elif cl or mf:
239 if file_:
239 if file_:
240 msg = _('cannot specify filename with --changelog or --manifest')
240 msg = _('cannot specify filename with --changelog or --manifest')
241 elif not repo:
241 elif not repo:
242 msg = _('cannot specify --changelog or --manifest '
242 msg = _('cannot specify --changelog or --manifest '
243 'without a repository')
243 'without a repository')
244 if msg:
244 if msg:
245 raise util.Abort(msg)
245 raise util.Abort(msg)
246
246
247 r = None
247 r = None
248 if repo:
248 if repo:
249 if cl:
249 if cl:
250 r = repo.unfiltered().changelog
250 r = repo.unfiltered().changelog
251 elif mf:
251 elif mf:
252 r = repo.manifest
252 r = repo.manifest
253 elif file_:
253 elif file_:
254 filelog = repo.file(file_)
254 filelog = repo.file(file_)
255 if len(filelog):
255 if len(filelog):
256 r = filelog
256 r = filelog
257 if not r:
257 if not r:
258 if not file_:
258 if not file_:
259 raise error.CommandError(cmd, _('invalid arguments'))
259 raise error.CommandError(cmd, _('invalid arguments'))
260 if not os.path.isfile(file_):
260 if not os.path.isfile(file_):
261 raise util.Abort(_("revlog '%s' not found") % file_)
261 raise util.Abort(_("revlog '%s' not found") % file_)
262 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
262 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
263 file_[:-2] + ".i")
263 file_[:-2] + ".i")
264 return r
264 return r
265
265
266 def copy(ui, repo, pats, opts, rename=False):
266 def copy(ui, repo, pats, opts, rename=False):
267 # called with the repo lock held
267 # called with the repo lock held
268 #
268 #
269 # hgsep => pathname that uses "/" to separate directories
269 # hgsep => pathname that uses "/" to separate directories
270 # ossep => pathname that uses os.sep to separate directories
270 # ossep => pathname that uses os.sep to separate directories
271 cwd = repo.getcwd()
271 cwd = repo.getcwd()
272 targets = {}
272 targets = {}
273 after = opts.get("after")
273 after = opts.get("after")
274 dryrun = opts.get("dry_run")
274 dryrun = opts.get("dry_run")
275 wctx = repo[None]
275 wctx = repo[None]
276
276
277 def walkpat(pat):
277 def walkpat(pat):
278 srcs = []
278 srcs = []
279 badstates = after and '?' or '?r'
279 badstates = after and '?' or '?r'
280 m = scmutil.match(repo[None], [pat], opts, globbed=True)
280 m = scmutil.match(repo[None], [pat], opts, globbed=True)
281 for abs in repo.walk(m):
281 for abs in repo.walk(m):
282 state = repo.dirstate[abs]
282 state = repo.dirstate[abs]
283 rel = m.rel(abs)
283 rel = m.rel(abs)
284 exact = m.exact(abs)
284 exact = m.exact(abs)
285 if state in badstates:
285 if state in badstates:
286 if exact and state == '?':
286 if exact and state == '?':
287 ui.warn(_('%s: not copying - file is not managed\n') % rel)
287 ui.warn(_('%s: not copying - file is not managed\n') % rel)
288 if exact and state == 'r':
288 if exact and state == 'r':
289 ui.warn(_('%s: not copying - file has been marked for'
289 ui.warn(_('%s: not copying - file has been marked for'
290 ' remove\n') % rel)
290 ' remove\n') % rel)
291 continue
291 continue
292 # abs: hgsep
292 # abs: hgsep
293 # rel: ossep
293 # rel: ossep
294 srcs.append((abs, rel, exact))
294 srcs.append((abs, rel, exact))
295 return srcs
295 return srcs
296
296
297 # abssrc: hgsep
297 # abssrc: hgsep
298 # relsrc: ossep
298 # relsrc: ossep
299 # otarget: ossep
299 # otarget: ossep
300 def copyfile(abssrc, relsrc, otarget, exact):
300 def copyfile(abssrc, relsrc, otarget, exact):
301 abstarget = pathutil.canonpath(repo.root, cwd, otarget)
301 abstarget = pathutil.canonpath(repo.root, cwd, otarget)
302 if '/' in abstarget:
302 if '/' in abstarget:
303 # We cannot normalize abstarget itself, this would prevent
303 # We cannot normalize abstarget itself, this would prevent
304 # case only renames, like a => A.
304 # case only renames, like a => A.
305 abspath, absname = abstarget.rsplit('/', 1)
305 abspath, absname = abstarget.rsplit('/', 1)
306 abstarget = repo.dirstate.normalize(abspath) + '/' + absname
306 abstarget = repo.dirstate.normalize(abspath) + '/' + absname
307 reltarget = repo.pathto(abstarget, cwd)
307 reltarget = repo.pathto(abstarget, cwd)
308 target = repo.wjoin(abstarget)
308 target = repo.wjoin(abstarget)
309 src = repo.wjoin(abssrc)
309 src = repo.wjoin(abssrc)
310 state = repo.dirstate[abstarget]
310 state = repo.dirstate[abstarget]
311
311
312 scmutil.checkportable(ui, abstarget)
312 scmutil.checkportable(ui, abstarget)
313
313
314 # check for collisions
314 # check for collisions
315 prevsrc = targets.get(abstarget)
315 prevsrc = targets.get(abstarget)
316 if prevsrc is not None:
316 if prevsrc is not None:
317 ui.warn(_('%s: not overwriting - %s collides with %s\n') %
317 ui.warn(_('%s: not overwriting - %s collides with %s\n') %
318 (reltarget, repo.pathto(abssrc, cwd),
318 (reltarget, repo.pathto(abssrc, cwd),
319 repo.pathto(prevsrc, cwd)))
319 repo.pathto(prevsrc, cwd)))
320 return
320 return
321
321
322 # check for overwrites
322 # check for overwrites
323 exists = os.path.lexists(target)
323 exists = os.path.lexists(target)
324 samefile = False
324 samefile = False
325 if exists and abssrc != abstarget:
325 if exists and abssrc != abstarget:
326 if (repo.dirstate.normalize(abssrc) ==
326 if (repo.dirstate.normalize(abssrc) ==
327 repo.dirstate.normalize(abstarget)):
327 repo.dirstate.normalize(abstarget)):
328 if not rename:
328 if not rename:
329 ui.warn(_("%s: can't copy - same file\n") % reltarget)
329 ui.warn(_("%s: can't copy - same file\n") % reltarget)
330 return
330 return
331 exists = False
331 exists = False
332 samefile = True
332 samefile = True
333
333
334 if not after and exists or after and state in 'mn':
334 if not after and exists or after and state in 'mn':
335 if not opts['force']:
335 if not opts['force']:
336 ui.warn(_('%s: not overwriting - file exists\n') %
336 ui.warn(_('%s: not overwriting - file exists\n') %
337 reltarget)
337 reltarget)
338 return
338 return
339
339
340 if after:
340 if after:
341 if not exists:
341 if not exists:
342 if rename:
342 if rename:
343 ui.warn(_('%s: not recording move - %s does not exist\n') %
343 ui.warn(_('%s: not recording move - %s does not exist\n') %
344 (relsrc, reltarget))
344 (relsrc, reltarget))
345 else:
345 else:
346 ui.warn(_('%s: not recording copy - %s does not exist\n') %
346 ui.warn(_('%s: not recording copy - %s does not exist\n') %
347 (relsrc, reltarget))
347 (relsrc, reltarget))
348 return
348 return
349 elif not dryrun:
349 elif not dryrun:
350 try:
350 try:
351 if exists:
351 if exists:
352 os.unlink(target)
352 os.unlink(target)
353 targetdir = os.path.dirname(target) or '.'
353 targetdir = os.path.dirname(target) or '.'
354 if not os.path.isdir(targetdir):
354 if not os.path.isdir(targetdir):
355 os.makedirs(targetdir)
355 os.makedirs(targetdir)
356 if samefile:
356 if samefile:
357 tmp = target + "~hgrename"
357 tmp = target + "~hgrename"
358 os.rename(src, tmp)
358 os.rename(src, tmp)
359 os.rename(tmp, target)
359 os.rename(tmp, target)
360 else:
360 else:
361 util.copyfile(src, target)
361 util.copyfile(src, target)
362 srcexists = True
362 srcexists = True
363 except IOError, inst:
363 except IOError, inst:
364 if inst.errno == errno.ENOENT:
364 if inst.errno == errno.ENOENT:
365 ui.warn(_('%s: deleted in working copy\n') % relsrc)
365 ui.warn(_('%s: deleted in working copy\n') % relsrc)
366 srcexists = False
366 srcexists = False
367 else:
367 else:
368 ui.warn(_('%s: cannot copy - %s\n') %
368 ui.warn(_('%s: cannot copy - %s\n') %
369 (relsrc, inst.strerror))
369 (relsrc, inst.strerror))
370 return True # report a failure
370 return True # report a failure
371
371
372 if ui.verbose or not exact:
372 if ui.verbose or not exact:
373 if rename:
373 if rename:
374 ui.status(_('moving %s to %s\n') % (relsrc, reltarget))
374 ui.status(_('moving %s to %s\n') % (relsrc, reltarget))
375 else:
375 else:
376 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
376 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
377
377
378 targets[abstarget] = abssrc
378 targets[abstarget] = abssrc
379
379
380 # fix up dirstate
380 # fix up dirstate
381 scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
381 scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
382 dryrun=dryrun, cwd=cwd)
382 dryrun=dryrun, cwd=cwd)
383 if rename and not dryrun:
383 if rename and not dryrun:
384 if not after and srcexists and not samefile:
384 if not after and srcexists and not samefile:
385 util.unlinkpath(repo.wjoin(abssrc))
385 util.unlinkpath(repo.wjoin(abssrc))
386 wctx.forget([abssrc])
386 wctx.forget([abssrc])
387
387
388 # pat: ossep
388 # pat: ossep
389 # dest ossep
389 # dest ossep
390 # srcs: list of (hgsep, hgsep, ossep, bool)
390 # srcs: list of (hgsep, hgsep, ossep, bool)
391 # return: function that takes hgsep and returns ossep
391 # return: function that takes hgsep and returns ossep
392 def targetpathfn(pat, dest, srcs):
392 def targetpathfn(pat, dest, srcs):
393 if os.path.isdir(pat):
393 if os.path.isdir(pat):
394 abspfx = pathutil.canonpath(repo.root, cwd, pat)
394 abspfx = pathutil.canonpath(repo.root, cwd, pat)
395 abspfx = util.localpath(abspfx)
395 abspfx = util.localpath(abspfx)
396 if destdirexists:
396 if destdirexists:
397 striplen = len(os.path.split(abspfx)[0])
397 striplen = len(os.path.split(abspfx)[0])
398 else:
398 else:
399 striplen = len(abspfx)
399 striplen = len(abspfx)
400 if striplen:
400 if striplen:
401 striplen += len(os.sep)
401 striplen += len(os.sep)
402 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:])
402 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:])
403 elif destdirexists:
403 elif destdirexists:
404 res = lambda p: os.path.join(dest,
404 res = lambda p: os.path.join(dest,
405 os.path.basename(util.localpath(p)))
405 os.path.basename(util.localpath(p)))
406 else:
406 else:
407 res = lambda p: dest
407 res = lambda p: dest
408 return res
408 return res
409
409
410 # pat: ossep
410 # pat: ossep
411 # dest ossep
411 # dest ossep
412 # srcs: list of (hgsep, hgsep, ossep, bool)
412 # srcs: list of (hgsep, hgsep, ossep, bool)
413 # return: function that takes hgsep and returns ossep
413 # return: function that takes hgsep and returns ossep
414 def targetpathafterfn(pat, dest, srcs):
414 def targetpathafterfn(pat, dest, srcs):
415 if matchmod.patkind(pat):
415 if matchmod.patkind(pat):
416 # a mercurial pattern
416 # a mercurial pattern
417 res = lambda p: os.path.join(dest,
417 res = lambda p: os.path.join(dest,
418 os.path.basename(util.localpath(p)))
418 os.path.basename(util.localpath(p)))
419 else:
419 else:
420 abspfx = pathutil.canonpath(repo.root, cwd, pat)
420 abspfx = pathutil.canonpath(repo.root, cwd, pat)
421 if len(abspfx) < len(srcs[0][0]):
421 if len(abspfx) < len(srcs[0][0]):
422 # A directory. Either the target path contains the last
422 # A directory. Either the target path contains the last
423 # component of the source path or it does not.
423 # component of the source path or it does not.
424 def evalpath(striplen):
424 def evalpath(striplen):
425 score = 0
425 score = 0
426 for s in srcs:
426 for s in srcs:
427 t = os.path.join(dest, util.localpath(s[0])[striplen:])
427 t = os.path.join(dest, util.localpath(s[0])[striplen:])
428 if os.path.lexists(t):
428 if os.path.lexists(t):
429 score += 1
429 score += 1
430 return score
430 return score
431
431
432 abspfx = util.localpath(abspfx)
432 abspfx = util.localpath(abspfx)
433 striplen = len(abspfx)
433 striplen = len(abspfx)
434 if striplen:
434 if striplen:
435 striplen += len(os.sep)
435 striplen += len(os.sep)
436 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
436 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
437 score = evalpath(striplen)
437 score = evalpath(striplen)
438 striplen1 = len(os.path.split(abspfx)[0])
438 striplen1 = len(os.path.split(abspfx)[0])
439 if striplen1:
439 if striplen1:
440 striplen1 += len(os.sep)
440 striplen1 += len(os.sep)
441 if evalpath(striplen1) > score:
441 if evalpath(striplen1) > score:
442 striplen = striplen1
442 striplen = striplen1
443 res = lambda p: os.path.join(dest,
443 res = lambda p: os.path.join(dest,
444 util.localpath(p)[striplen:])
444 util.localpath(p)[striplen:])
445 else:
445 else:
446 # a file
446 # a file
447 if destdirexists:
447 if destdirexists:
448 res = lambda p: os.path.join(dest,
448 res = lambda p: os.path.join(dest,
449 os.path.basename(util.localpath(p)))
449 os.path.basename(util.localpath(p)))
450 else:
450 else:
451 res = lambda p: dest
451 res = lambda p: dest
452 return res
452 return res
453
453
454
454
455 pats = scmutil.expandpats(pats)
455 pats = scmutil.expandpats(pats)
456 if not pats:
456 if not pats:
457 raise util.Abort(_('no source or destination specified'))
457 raise util.Abort(_('no source or destination specified'))
458 if len(pats) == 1:
458 if len(pats) == 1:
459 raise util.Abort(_('no destination specified'))
459 raise util.Abort(_('no destination specified'))
460 dest = pats.pop()
460 dest = pats.pop()
461 destdirexists = os.path.isdir(dest) and not os.path.islink(dest)
461 destdirexists = os.path.isdir(dest) and not os.path.islink(dest)
462 if not destdirexists:
462 if not destdirexists:
463 if len(pats) > 1 or matchmod.patkind(pats[0]):
463 if len(pats) > 1 or matchmod.patkind(pats[0]):
464 raise util.Abort(_('with multiple sources, destination must be an '
464 raise util.Abort(_('with multiple sources, destination must be an '
465 'existing directory'))
465 'existing directory'))
466 if util.endswithsep(dest):
466 if util.endswithsep(dest):
467 raise util.Abort(_('destination %s is not a directory') % dest)
467 raise util.Abort(_('destination %s is not a directory') % dest)
468
468
469 tfn = targetpathfn
469 tfn = targetpathfn
470 if after:
470 if after:
471 tfn = targetpathafterfn
471 tfn = targetpathafterfn
472 copylist = []
472 copylist = []
473 for pat in pats:
473 for pat in pats:
474 srcs = walkpat(pat)
474 srcs = walkpat(pat)
475 if not srcs:
475 if not srcs:
476 continue
476 continue
477 copylist.append((tfn(pat, dest, srcs), srcs))
477 copylist.append((tfn(pat, dest, srcs), srcs))
478 if not copylist:
478 if not copylist:
479 raise util.Abort(_('no files to copy'))
479 raise util.Abort(_('no files to copy'))
480
480
481 errors = 0
481 errors = 0
482 for targetpath, srcs in copylist:
482 for targetpath, srcs in copylist:
483 for abssrc, relsrc, exact in srcs:
483 for abssrc, relsrc, exact in srcs:
484 if copyfile(abssrc, relsrc, targetpath(abssrc), exact):
484 if copyfile(abssrc, relsrc, targetpath(abssrc), exact):
485 errors += 1
485 errors += 1
486
486
487 if errors:
487 if errors:
488 ui.warn(_('(consider using --after)\n'))
488 ui.warn(_('(consider using --after)\n'))
489
489
490 return errors != 0
490 return errors != 0
491
491
492 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None,
492 def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None,
493 runargs=None, appendpid=False):
493 runargs=None, appendpid=False):
494 '''Run a command as a service.'''
494 '''Run a command as a service.'''
495
495
496 def writepid(pid):
496 def writepid(pid):
497 if opts['pid_file']:
497 if opts['pid_file']:
498 mode = appendpid and 'a' or 'w'
498 mode = appendpid and 'a' or 'w'
499 fp = open(opts['pid_file'], mode)
499 fp = open(opts['pid_file'], mode)
500 fp.write(str(pid) + '\n')
500 fp.write(str(pid) + '\n')
501 fp.close()
501 fp.close()
502
502
503 if opts['daemon'] and not opts['daemon_pipefds']:
503 if opts['daemon'] and not opts['daemon_pipefds']:
504 # Signal child process startup with file removal
504 # Signal child process startup with file removal
505 lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
505 lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
506 os.close(lockfd)
506 os.close(lockfd)
507 try:
507 try:
508 if not runargs:
508 if not runargs:
509 runargs = util.hgcmd() + sys.argv[1:]
509 runargs = util.hgcmd() + sys.argv[1:]
510 runargs.append('--daemon-pipefds=%s' % lockpath)
510 runargs.append('--daemon-pipefds=%s' % lockpath)
511 # Don't pass --cwd to the child process, because we've already
511 # Don't pass --cwd to the child process, because we've already
512 # changed directory.
512 # changed directory.
513 for i in xrange(1, len(runargs)):
513 for i in xrange(1, len(runargs)):
514 if runargs[i].startswith('--cwd='):
514 if runargs[i].startswith('--cwd='):
515 del runargs[i]
515 del runargs[i]
516 break
516 break
517 elif runargs[i].startswith('--cwd'):
517 elif runargs[i].startswith('--cwd'):
518 del runargs[i:i + 2]
518 del runargs[i:i + 2]
519 break
519 break
520 def condfn():
520 def condfn():
521 return not os.path.exists(lockpath)
521 return not os.path.exists(lockpath)
522 pid = util.rundetached(runargs, condfn)
522 pid = util.rundetached(runargs, condfn)
523 if pid < 0:
523 if pid < 0:
524 raise util.Abort(_('child process failed to start'))
524 raise util.Abort(_('child process failed to start'))
525 writepid(pid)
525 writepid(pid)
526 finally:
526 finally:
527 try:
527 try:
528 os.unlink(lockpath)
528 os.unlink(lockpath)
529 except OSError, e:
529 except OSError, e:
530 if e.errno != errno.ENOENT:
530 if e.errno != errno.ENOENT:
531 raise
531 raise
532 if parentfn:
532 if parentfn:
533 return parentfn(pid)
533 return parentfn(pid)
534 else:
534 else:
535 return
535 return
536
536
537 if initfn:
537 if initfn:
538 initfn()
538 initfn()
539
539
540 if not opts['daemon']:
540 if not opts['daemon']:
541 writepid(os.getpid())
541 writepid(os.getpid())
542
542
543 if opts['daemon_pipefds']:
543 if opts['daemon_pipefds']:
544 lockpath = opts['daemon_pipefds']
544 lockpath = opts['daemon_pipefds']
545 try:
545 try:
546 os.setsid()
546 os.setsid()
547 except AttributeError:
547 except AttributeError:
548 pass
548 pass
549 os.unlink(lockpath)
549 os.unlink(lockpath)
550 util.hidewindow()
550 util.hidewindow()
551 sys.stdout.flush()
551 sys.stdout.flush()
552 sys.stderr.flush()
552 sys.stderr.flush()
553
553
554 nullfd = os.open(os.devnull, os.O_RDWR)
554 nullfd = os.open(os.devnull, os.O_RDWR)
555 logfilefd = nullfd
555 logfilefd = nullfd
556 if logfile:
556 if logfile:
557 logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND)
557 logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND)
558 os.dup2(nullfd, 0)
558 os.dup2(nullfd, 0)
559 os.dup2(logfilefd, 1)
559 os.dup2(logfilefd, 1)
560 os.dup2(logfilefd, 2)
560 os.dup2(logfilefd, 2)
561 if nullfd not in (0, 1, 2):
561 if nullfd not in (0, 1, 2):
562 os.close(nullfd)
562 os.close(nullfd)
563 if logfile and logfilefd not in (0, 1, 2):
563 if logfile and logfilefd not in (0, 1, 2):
564 os.close(logfilefd)
564 os.close(logfilefd)
565
565
566 if runfn:
566 if runfn:
567 return runfn()
567 return runfn()
568
568
569 def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc):
569 def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc):
570 """Utility function used by commands.import to import a single patch
570 """Utility function used by commands.import to import a single patch
571
571
572 This function is explicitly defined here to help the evolve extension to
572 This function is explicitly defined here to help the evolve extension to
573 wrap this part of the import logic.
573 wrap this part of the import logic.
574
574
575 The API is currently a bit ugly because it a simple code translation from
575 The API is currently a bit ugly because it a simple code translation from
576 the import command. Feel free to make it better.
576 the import command. Feel free to make it better.
577
577
578 :hunk: a patch (as a binary string)
578 :hunk: a patch (as a binary string)
579 :parents: nodes that will be parent of the created commit
579 :parents: nodes that will be parent of the created commit
580 :opts: the full dict of option passed to the import command
580 :opts: the full dict of option passed to the import command
581 :msgs: list to save commit message to.
581 :msgs: list to save commit message to.
582 (used in case we need to save it when failing)
582 (used in case we need to save it when failing)
583 :updatefunc: a function that update a repo to a given node
583 :updatefunc: a function that update a repo to a given node
584 updatefunc(<repo>, <node>)
584 updatefunc(<repo>, <node>)
585 """
585 """
586 tmpname, message, user, date, branch, nodeid, p1, p2 = \
586 tmpname, message, user, date, branch, nodeid, p1, p2 = \
587 patch.extract(ui, hunk)
587 patch.extract(ui, hunk)
588
588
589 editor = getcommiteditor(**opts)
589 editor = getcommiteditor(**opts)
590 update = not opts.get('bypass')
590 update = not opts.get('bypass')
591 strip = opts["strip"]
591 strip = opts["strip"]
592 sim = float(opts.get('similarity') or 0)
592 sim = float(opts.get('similarity') or 0)
593 if not tmpname:
593 if not tmpname:
594 return (None, None)
594 return (None, None, False)
595 msg = _('applied to working directory')
595 msg = _('applied to working directory')
596
596
597 rejects = False
598
597 try:
599 try:
598 cmdline_message = logmessage(ui, opts)
600 cmdline_message = logmessage(ui, opts)
599 if cmdline_message:
601 if cmdline_message:
600 # pickup the cmdline msg
602 # pickup the cmdline msg
601 message = cmdline_message
603 message = cmdline_message
602 elif message:
604 elif message:
603 # pickup the patch msg
605 # pickup the patch msg
604 message = message.strip()
606 message = message.strip()
605 else:
607 else:
606 # launch the editor
608 # launch the editor
607 message = None
609 message = None
608 ui.debug('message:\n%s\n' % message)
610 ui.debug('message:\n%s\n' % message)
609
611
610 if len(parents) == 1:
612 if len(parents) == 1:
611 parents.append(repo[nullid])
613 parents.append(repo[nullid])
612 if opts.get('exact'):
614 if opts.get('exact'):
613 if not nodeid or not p1:
615 if not nodeid or not p1:
614 raise util.Abort(_('not a Mercurial patch'))
616 raise util.Abort(_('not a Mercurial patch'))
615 p1 = repo[p1]
617 p1 = repo[p1]
616 p2 = repo[p2 or nullid]
618 p2 = repo[p2 or nullid]
617 elif p2:
619 elif p2:
618 try:
620 try:
619 p1 = repo[p1]
621 p1 = repo[p1]
620 p2 = repo[p2]
622 p2 = repo[p2]
621 # Without any options, consider p2 only if the
623 # Without any options, consider p2 only if the
622 # patch is being applied on top of the recorded
624 # patch is being applied on top of the recorded
623 # first parent.
625 # first parent.
624 if p1 != parents[0]:
626 if p1 != parents[0]:
625 p1 = parents[0]
627 p1 = parents[0]
626 p2 = repo[nullid]
628 p2 = repo[nullid]
627 except error.RepoError:
629 except error.RepoError:
628 p1, p2 = parents
630 p1, p2 = parents
629 else:
631 else:
630 p1, p2 = parents
632 p1, p2 = parents
631
633
632 n = None
634 n = None
633 if update:
635 if update:
634 if p1 != parents[0]:
636 if p1 != parents[0]:
635 updatefunc(repo, p1.node())
637 updatefunc(repo, p1.node())
636 if p2 != parents[1]:
638 if p2 != parents[1]:
637 repo.setparents(p1.node(), p2.node())
639 repo.setparents(p1.node(), p2.node())
638
640
639 if opts.get('exact') or opts.get('import_branch'):
641 if opts.get('exact') or opts.get('import_branch'):
640 repo.dirstate.setbranch(branch or 'default')
642 repo.dirstate.setbranch(branch or 'default')
641
643
644 partial = opts.get('partial', False)
642 files = set()
645 files = set()
646 try:
643 patch.patch(ui, repo, tmpname, strip=strip, files=files,
647 patch.patch(ui, repo, tmpname, strip=strip, files=files,
644 eolmode=None, similarity=sim / 100.0)
648 eolmode=None, similarity=sim / 100.0)
649 except patch.PatchError, e:
650 if not partial:
651 raise util.Abort(str(e))
652 if partial:
653 rejects = True
654
645 files = list(files)
655 files = list(files)
646 if opts.get('no_commit'):
656 if opts.get('no_commit'):
647 if message:
657 if message:
648 msgs.append(message)
658 msgs.append(message)
649 else:
659 else:
650 if opts.get('exact') or p2:
660 if opts.get('exact') or p2:
651 # If you got here, you either use --force and know what
661 # If you got here, you either use --force and know what
652 # you are doing or used --exact or a merge patch while
662 # you are doing or used --exact or a merge patch while
653 # being updated to its first parent.
663 # being updated to its first parent.
654 m = None
664 m = None
655 else:
665 else:
656 m = scmutil.matchfiles(repo, files or [])
666 m = scmutil.matchfiles(repo, files or [])
657 n = repo.commit(message, opts.get('user') or user,
667 n = repo.commit(message, opts.get('user') or user,
658 opts.get('date') or date, match=m,
668 opts.get('date') or date, match=m,
659 editor=editor)
669 editor=editor, force=partial)
660 else:
670 else:
661 if opts.get('exact') or opts.get('import_branch'):
671 if opts.get('exact') or opts.get('import_branch'):
662 branch = branch or 'default'
672 branch = branch or 'default'
663 else:
673 else:
664 branch = p1.branch()
674 branch = p1.branch()
665 store = patch.filestore()
675 store = patch.filestore()
666 try:
676 try:
667 files = set()
677 files = set()
668 try:
678 try:
669 patch.patchrepo(ui, repo, p1, store, tmpname, strip,
679 patch.patchrepo(ui, repo, p1, store, tmpname, strip,
670 files, eolmode=None)
680 files, eolmode=None)
671 except patch.PatchError, e:
681 except patch.PatchError, e:
672 raise util.Abort(str(e))
682 raise util.Abort(str(e))
673 memctx = context.makememctx(repo, (p1.node(), p2.node()),
683 memctx = context.makememctx(repo, (p1.node(), p2.node()),
674 message,
684 message,
675 opts.get('user') or user,
685 opts.get('user') or user,
676 opts.get('date') or date,
686 opts.get('date') or date,
677 branch, files, store,
687 branch, files, store,
678 editor=getcommiteditor())
688 editor=getcommiteditor())
679 n = memctx.commit()
689 n = memctx.commit()
680 finally:
690 finally:
681 store.close()
691 store.close()
682 if opts.get('exact') and hex(n) != nodeid:
692 if opts.get('exact') and hex(n) != nodeid:
683 raise util.Abort(_('patch is damaged or loses information'))
693 raise util.Abort(_('patch is damaged or loses information'))
684 if n:
694 if n:
685 # i18n: refers to a short changeset id
695 # i18n: refers to a short changeset id
686 msg = _('created %s') % short(n)
696 msg = _('created %s') % short(n)
687 return (msg, n)
697 return (msg, n, rejects)
688 finally:
698 finally:
689 os.unlink(tmpname)
699 os.unlink(tmpname)
690
700
691 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
701 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
692 opts=None):
702 opts=None):
693 '''export changesets as hg patches.'''
703 '''export changesets as hg patches.'''
694
704
695 total = len(revs)
705 total = len(revs)
696 revwidth = max([len(str(rev)) for rev in revs])
706 revwidth = max([len(str(rev)) for rev in revs])
697 filemode = {}
707 filemode = {}
698
708
699 def single(rev, seqno, fp):
709 def single(rev, seqno, fp):
700 ctx = repo[rev]
710 ctx = repo[rev]
701 node = ctx.node()
711 node = ctx.node()
702 parents = [p.node() for p in ctx.parents() if p]
712 parents = [p.node() for p in ctx.parents() if p]
703 branch = ctx.branch()
713 branch = ctx.branch()
704 if switch_parent:
714 if switch_parent:
705 parents.reverse()
715 parents.reverse()
706 prev = (parents and parents[0]) or nullid
716 prev = (parents and parents[0]) or nullid
707
717
708 shouldclose = False
718 shouldclose = False
709 if not fp and len(template) > 0:
719 if not fp and len(template) > 0:
710 desc_lines = ctx.description().rstrip().split('\n')
720 desc_lines = ctx.description().rstrip().split('\n')
711 desc = desc_lines[0] #Commit always has a first line.
721 desc = desc_lines[0] #Commit always has a first line.
712 fp = makefileobj(repo, template, node, desc=desc, total=total,
722 fp = makefileobj(repo, template, node, desc=desc, total=total,
713 seqno=seqno, revwidth=revwidth, mode='wb',
723 seqno=seqno, revwidth=revwidth, mode='wb',
714 modemap=filemode)
724 modemap=filemode)
715 if fp != template:
725 if fp != template:
716 shouldclose = True
726 shouldclose = True
717 if fp and fp != sys.stdout and util.safehasattr(fp, 'name'):
727 if fp and fp != sys.stdout and util.safehasattr(fp, 'name'):
718 repo.ui.note("%s\n" % fp.name)
728 repo.ui.note("%s\n" % fp.name)
719
729
720 if not fp:
730 if not fp:
721 write = repo.ui.write
731 write = repo.ui.write
722 else:
732 else:
723 def write(s, **kw):
733 def write(s, **kw):
724 fp.write(s)
734 fp.write(s)
725
735
726
736
727 write("# HG changeset patch\n")
737 write("# HG changeset patch\n")
728 write("# User %s\n" % ctx.user())
738 write("# User %s\n" % ctx.user())
729 write("# Date %d %d\n" % ctx.date())
739 write("# Date %d %d\n" % ctx.date())
730 write("# %s\n" % util.datestr(ctx.date()))
740 write("# %s\n" % util.datestr(ctx.date()))
731 if branch and branch != 'default':
741 if branch and branch != 'default':
732 write("# Branch %s\n" % branch)
742 write("# Branch %s\n" % branch)
733 write("# Node ID %s\n" % hex(node))
743 write("# Node ID %s\n" % hex(node))
734 write("# Parent %s\n" % hex(prev))
744 write("# Parent %s\n" % hex(prev))
735 if len(parents) > 1:
745 if len(parents) > 1:
736 write("# Parent %s\n" % hex(parents[1]))
746 write("# Parent %s\n" % hex(parents[1]))
737 write(ctx.description().rstrip())
747 write(ctx.description().rstrip())
738 write("\n\n")
748 write("\n\n")
739
749
740 for chunk, label in patch.diffui(repo, prev, node, opts=opts):
750 for chunk, label in patch.diffui(repo, prev, node, opts=opts):
741 write(chunk, label=label)
751 write(chunk, label=label)
742
752
743 if shouldclose:
753 if shouldclose:
744 fp.close()
754 fp.close()
745
755
746 for seqno, rev in enumerate(revs):
756 for seqno, rev in enumerate(revs):
747 single(rev, seqno + 1, fp)
757 single(rev, seqno + 1, fp)
748
758
749 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
759 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
750 changes=None, stat=False, fp=None, prefix='',
760 changes=None, stat=False, fp=None, prefix='',
751 listsubrepos=False):
761 listsubrepos=False):
752 '''show diff or diffstat.'''
762 '''show diff or diffstat.'''
753 if fp is None:
763 if fp is None:
754 write = ui.write
764 write = ui.write
755 else:
765 else:
756 def write(s, **kw):
766 def write(s, **kw):
757 fp.write(s)
767 fp.write(s)
758
768
759 if stat:
769 if stat:
760 diffopts = diffopts.copy(context=0)
770 diffopts = diffopts.copy(context=0)
761 width = 80
771 width = 80
762 if not ui.plain():
772 if not ui.plain():
763 width = ui.termwidth()
773 width = ui.termwidth()
764 chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
774 chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
765 prefix=prefix)
775 prefix=prefix)
766 for chunk, label in patch.diffstatui(util.iterlines(chunks),
776 for chunk, label in patch.diffstatui(util.iterlines(chunks),
767 width=width,
777 width=width,
768 git=diffopts.git):
778 git=diffopts.git):
769 write(chunk, label=label)
779 write(chunk, label=label)
770 else:
780 else:
771 for chunk, label in patch.diffui(repo, node1, node2, match,
781 for chunk, label in patch.diffui(repo, node1, node2, match,
772 changes, diffopts, prefix=prefix):
782 changes, diffopts, prefix=prefix):
773 write(chunk, label=label)
783 write(chunk, label=label)
774
784
775 if listsubrepos:
785 if listsubrepos:
776 ctx1 = repo[node1]
786 ctx1 = repo[node1]
777 ctx2 = repo[node2]
787 ctx2 = repo[node2]
778 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
788 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
779 tempnode2 = node2
789 tempnode2 = node2
780 try:
790 try:
781 if node2 is not None:
791 if node2 is not None:
782 tempnode2 = ctx2.substate[subpath][1]
792 tempnode2 = ctx2.substate[subpath][1]
783 except KeyError:
793 except KeyError:
784 # A subrepo that existed in node1 was deleted between node1 and
794 # A subrepo that existed in node1 was deleted between node1 and
785 # node2 (inclusive). Thus, ctx2's substate won't contain that
795 # node2 (inclusive). Thus, ctx2's substate won't contain that
786 # subpath. The best we can do is to ignore it.
796 # subpath. The best we can do is to ignore it.
787 tempnode2 = None
797 tempnode2 = None
788 submatch = matchmod.narrowmatcher(subpath, match)
798 submatch = matchmod.narrowmatcher(subpath, match)
789 sub.diff(ui, diffopts, tempnode2, submatch, changes=changes,
799 sub.diff(ui, diffopts, tempnode2, submatch, changes=changes,
790 stat=stat, fp=fp, prefix=prefix)
800 stat=stat, fp=fp, prefix=prefix)
791
801
792 class changeset_printer(object):
802 class changeset_printer(object):
793 '''show changeset information when templating not requested.'''
803 '''show changeset information when templating not requested.'''
794
804
795 def __init__(self, ui, repo, patch, diffopts, buffered):
805 def __init__(self, ui, repo, patch, diffopts, buffered):
796 self.ui = ui
806 self.ui = ui
797 self.repo = repo
807 self.repo = repo
798 self.buffered = buffered
808 self.buffered = buffered
799 self.patch = patch
809 self.patch = patch
800 self.diffopts = diffopts
810 self.diffopts = diffopts
801 self.header = {}
811 self.header = {}
802 self.hunk = {}
812 self.hunk = {}
803 self.lastheader = None
813 self.lastheader = None
804 self.footer = None
814 self.footer = None
805
815
806 def flush(self, rev):
816 def flush(self, rev):
807 if rev in self.header:
817 if rev in self.header:
808 h = self.header[rev]
818 h = self.header[rev]
809 if h != self.lastheader:
819 if h != self.lastheader:
810 self.lastheader = h
820 self.lastheader = h
811 self.ui.write(h)
821 self.ui.write(h)
812 del self.header[rev]
822 del self.header[rev]
813 if rev in self.hunk:
823 if rev in self.hunk:
814 self.ui.write(self.hunk[rev])
824 self.ui.write(self.hunk[rev])
815 del self.hunk[rev]
825 del self.hunk[rev]
816 return 1
826 return 1
817 return 0
827 return 0
818
828
819 def close(self):
829 def close(self):
820 if self.footer:
830 if self.footer:
821 self.ui.write(self.footer)
831 self.ui.write(self.footer)
822
832
823 def show(self, ctx, copies=None, matchfn=None, **props):
833 def show(self, ctx, copies=None, matchfn=None, **props):
824 if self.buffered:
834 if self.buffered:
825 self.ui.pushbuffer()
835 self.ui.pushbuffer()
826 self._show(ctx, copies, matchfn, props)
836 self._show(ctx, copies, matchfn, props)
827 self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True)
837 self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True)
828 else:
838 else:
829 self._show(ctx, copies, matchfn, props)
839 self._show(ctx, copies, matchfn, props)
830
840
831 def _show(self, ctx, copies, matchfn, props):
841 def _show(self, ctx, copies, matchfn, props):
832 '''show a single changeset or file revision'''
842 '''show a single changeset or file revision'''
833 changenode = ctx.node()
843 changenode = ctx.node()
834 rev = ctx.rev()
844 rev = ctx.rev()
835
845
836 if self.ui.quiet:
846 if self.ui.quiet:
837 self.ui.write("%d:%s\n" % (rev, short(changenode)),
847 self.ui.write("%d:%s\n" % (rev, short(changenode)),
838 label='log.node')
848 label='log.node')
839 return
849 return
840
850
841 log = self.repo.changelog
851 log = self.repo.changelog
842 date = util.datestr(ctx.date())
852 date = util.datestr(ctx.date())
843
853
844 hexfunc = self.ui.debugflag and hex or short
854 hexfunc = self.ui.debugflag and hex or short
845
855
846 parents = [(p, hexfunc(log.node(p)))
856 parents = [(p, hexfunc(log.node(p)))
847 for p in self._meaningful_parentrevs(log, rev)]
857 for p in self._meaningful_parentrevs(log, rev)]
848
858
849 # i18n: column positioning for "hg log"
859 # i18n: column positioning for "hg log"
850 self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode)),
860 self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode)),
851 label='log.changeset changeset.%s' % ctx.phasestr())
861 label='log.changeset changeset.%s' % ctx.phasestr())
852
862
853 branch = ctx.branch()
863 branch = ctx.branch()
854 # don't show the default branch name
864 # don't show the default branch name
855 if branch != 'default':
865 if branch != 'default':
856 # i18n: column positioning for "hg log"
866 # i18n: column positioning for "hg log"
857 self.ui.write(_("branch: %s\n") % branch,
867 self.ui.write(_("branch: %s\n") % branch,
858 label='log.branch')
868 label='log.branch')
859 for bookmark in self.repo.nodebookmarks(changenode):
869 for bookmark in self.repo.nodebookmarks(changenode):
860 # i18n: column positioning for "hg log"
870 # i18n: column positioning for "hg log"
861 self.ui.write(_("bookmark: %s\n") % bookmark,
871 self.ui.write(_("bookmark: %s\n") % bookmark,
862 label='log.bookmark')
872 label='log.bookmark')
863 for tag in self.repo.nodetags(changenode):
873 for tag in self.repo.nodetags(changenode):
864 # i18n: column positioning for "hg log"
874 # i18n: column positioning for "hg log"
865 self.ui.write(_("tag: %s\n") % tag,
875 self.ui.write(_("tag: %s\n") % tag,
866 label='log.tag')
876 label='log.tag')
867 if self.ui.debugflag and ctx.phase():
877 if self.ui.debugflag and ctx.phase():
868 # i18n: column positioning for "hg log"
878 # i18n: column positioning for "hg log"
869 self.ui.write(_("phase: %s\n") % _(ctx.phasestr()),
879 self.ui.write(_("phase: %s\n") % _(ctx.phasestr()),
870 label='log.phase')
880 label='log.phase')
871 for parent in parents:
881 for parent in parents:
872 # i18n: column positioning for "hg log"
882 # i18n: column positioning for "hg log"
873 self.ui.write(_("parent: %d:%s\n") % parent,
883 self.ui.write(_("parent: %d:%s\n") % parent,
874 label='log.parent changeset.%s' % ctx.phasestr())
884 label='log.parent changeset.%s' % ctx.phasestr())
875
885
876 if self.ui.debugflag:
886 if self.ui.debugflag:
877 mnode = ctx.manifestnode()
887 mnode = ctx.manifestnode()
878 # i18n: column positioning for "hg log"
888 # i18n: column positioning for "hg log"
879 self.ui.write(_("manifest: %d:%s\n") %
889 self.ui.write(_("manifest: %d:%s\n") %
880 (self.repo.manifest.rev(mnode), hex(mnode)),
890 (self.repo.manifest.rev(mnode), hex(mnode)),
881 label='ui.debug log.manifest')
891 label='ui.debug log.manifest')
882 # i18n: column positioning for "hg log"
892 # i18n: column positioning for "hg log"
883 self.ui.write(_("user: %s\n") % ctx.user(),
893 self.ui.write(_("user: %s\n") % ctx.user(),
884 label='log.user')
894 label='log.user')
885 # i18n: column positioning for "hg log"
895 # i18n: column positioning for "hg log"
886 self.ui.write(_("date: %s\n") % date,
896 self.ui.write(_("date: %s\n") % date,
887 label='log.date')
897 label='log.date')
888
898
889 if self.ui.debugflag:
899 if self.ui.debugflag:
890 files = self.repo.status(log.parents(changenode)[0], changenode)[:3]
900 files = self.repo.status(log.parents(changenode)[0], changenode)[:3]
891 for key, value in zip([# i18n: column positioning for "hg log"
901 for key, value in zip([# i18n: column positioning for "hg log"
892 _("files:"),
902 _("files:"),
893 # i18n: column positioning for "hg log"
903 # i18n: column positioning for "hg log"
894 _("files+:"),
904 _("files+:"),
895 # i18n: column positioning for "hg log"
905 # i18n: column positioning for "hg log"
896 _("files-:")], files):
906 _("files-:")], files):
897 if value:
907 if value:
898 self.ui.write("%-12s %s\n" % (key, " ".join(value)),
908 self.ui.write("%-12s %s\n" % (key, " ".join(value)),
899 label='ui.debug log.files')
909 label='ui.debug log.files')
900 elif ctx.files() and self.ui.verbose:
910 elif ctx.files() and self.ui.verbose:
901 # i18n: column positioning for "hg log"
911 # i18n: column positioning for "hg log"
902 self.ui.write(_("files: %s\n") % " ".join(ctx.files()),
912 self.ui.write(_("files: %s\n") % " ".join(ctx.files()),
903 label='ui.note log.files')
913 label='ui.note log.files')
904 if copies and self.ui.verbose:
914 if copies and self.ui.verbose:
905 copies = ['%s (%s)' % c for c in copies]
915 copies = ['%s (%s)' % c for c in copies]
906 # i18n: column positioning for "hg log"
916 # i18n: column positioning for "hg log"
907 self.ui.write(_("copies: %s\n") % ' '.join(copies),
917 self.ui.write(_("copies: %s\n") % ' '.join(copies),
908 label='ui.note log.copies')
918 label='ui.note log.copies')
909
919
910 extra = ctx.extra()
920 extra = ctx.extra()
911 if extra and self.ui.debugflag:
921 if extra and self.ui.debugflag:
912 for key, value in sorted(extra.items()):
922 for key, value in sorted(extra.items()):
913 # i18n: column positioning for "hg log"
923 # i18n: column positioning for "hg log"
914 self.ui.write(_("extra: %s=%s\n")
924 self.ui.write(_("extra: %s=%s\n")
915 % (key, value.encode('string_escape')),
925 % (key, value.encode('string_escape')),
916 label='ui.debug log.extra')
926 label='ui.debug log.extra')
917
927
918 description = ctx.description().strip()
928 description = ctx.description().strip()
919 if description:
929 if description:
920 if self.ui.verbose:
930 if self.ui.verbose:
921 self.ui.write(_("description:\n"),
931 self.ui.write(_("description:\n"),
922 label='ui.note log.description')
932 label='ui.note log.description')
923 self.ui.write(description,
933 self.ui.write(description,
924 label='ui.note log.description')
934 label='ui.note log.description')
925 self.ui.write("\n\n")
935 self.ui.write("\n\n")
926 else:
936 else:
927 # i18n: column positioning for "hg log"
937 # i18n: column positioning for "hg log"
928 self.ui.write(_("summary: %s\n") %
938 self.ui.write(_("summary: %s\n") %
929 description.splitlines()[0],
939 description.splitlines()[0],
930 label='log.summary')
940 label='log.summary')
931 self.ui.write("\n")
941 self.ui.write("\n")
932
942
933 self.showpatch(changenode, matchfn)
943 self.showpatch(changenode, matchfn)
934
944
935 def showpatch(self, node, matchfn):
945 def showpatch(self, node, matchfn):
936 if not matchfn:
946 if not matchfn:
937 matchfn = self.patch
947 matchfn = self.patch
938 if matchfn:
948 if matchfn:
939 stat = self.diffopts.get('stat')
949 stat = self.diffopts.get('stat')
940 diff = self.diffopts.get('patch')
950 diff = self.diffopts.get('patch')
941 diffopts = patch.diffopts(self.ui, self.diffopts)
951 diffopts = patch.diffopts(self.ui, self.diffopts)
942 prev = self.repo.changelog.parents(node)[0]
952 prev = self.repo.changelog.parents(node)[0]
943 if stat:
953 if stat:
944 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
954 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
945 match=matchfn, stat=True)
955 match=matchfn, stat=True)
946 if diff:
956 if diff:
947 if stat:
957 if stat:
948 self.ui.write("\n")
958 self.ui.write("\n")
949 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
959 diffordiffstat(self.ui, self.repo, diffopts, prev, node,
950 match=matchfn, stat=False)
960 match=matchfn, stat=False)
951 self.ui.write("\n")
961 self.ui.write("\n")
952
962
953 def _meaningful_parentrevs(self, log, rev):
963 def _meaningful_parentrevs(self, log, rev):
954 """Return list of meaningful (or all if debug) parentrevs for rev.
964 """Return list of meaningful (or all if debug) parentrevs for rev.
955
965
956 For merges (two non-nullrev revisions) both parents are meaningful.
966 For merges (two non-nullrev revisions) both parents are meaningful.
957 Otherwise the first parent revision is considered meaningful if it
967 Otherwise the first parent revision is considered meaningful if it
958 is not the preceding revision.
968 is not the preceding revision.
959 """
969 """
960 parents = log.parentrevs(rev)
970 parents = log.parentrevs(rev)
961 if not self.ui.debugflag and parents[1] == nullrev:
971 if not self.ui.debugflag and parents[1] == nullrev:
962 if parents[0] >= rev - 1:
972 if parents[0] >= rev - 1:
963 parents = []
973 parents = []
964 else:
974 else:
965 parents = [parents[0]]
975 parents = [parents[0]]
966 return parents
976 return parents
967
977
968
978
969 class changeset_templater(changeset_printer):
979 class changeset_templater(changeset_printer):
970 '''format changeset information.'''
980 '''format changeset information.'''
971
981
972 def __init__(self, ui, repo, patch, diffopts, tmpl, mapfile, buffered):
982 def __init__(self, ui, repo, patch, diffopts, tmpl, mapfile, buffered):
973 changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered)
983 changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered)
974 formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
984 formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
975 defaulttempl = {
985 defaulttempl = {
976 'parent': '{rev}:{node|formatnode} ',
986 'parent': '{rev}:{node|formatnode} ',
977 'manifest': '{rev}:{node|formatnode}',
987 'manifest': '{rev}:{node|formatnode}',
978 'file_copy': '{name} ({source})',
988 'file_copy': '{name} ({source})',
979 'extra': '{key}={value|stringescape}'
989 'extra': '{key}={value|stringescape}'
980 }
990 }
981 # filecopy is preserved for compatibility reasons
991 # filecopy is preserved for compatibility reasons
982 defaulttempl['filecopy'] = defaulttempl['file_copy']
992 defaulttempl['filecopy'] = defaulttempl['file_copy']
983 self.t = templater.templater(mapfile, {'formatnode': formatnode},
993 self.t = templater.templater(mapfile, {'formatnode': formatnode},
984 cache=defaulttempl)
994 cache=defaulttempl)
985 if tmpl:
995 if tmpl:
986 self.t.cache['changeset'] = tmpl
996 self.t.cache['changeset'] = tmpl
987
997
988 self.cache = {}
998 self.cache = {}
989
999
990 def _meaningful_parentrevs(self, ctx):
1000 def _meaningful_parentrevs(self, ctx):
991 """Return list of meaningful (or all if debug) parentrevs for rev.
1001 """Return list of meaningful (or all if debug) parentrevs for rev.
992 """
1002 """
993 parents = ctx.parents()
1003 parents = ctx.parents()
994 if len(parents) > 1:
1004 if len(parents) > 1:
995 return parents
1005 return parents
996 if self.ui.debugflag:
1006 if self.ui.debugflag:
997 return [parents[0], self.repo['null']]
1007 return [parents[0], self.repo['null']]
998 if parents[0].rev() >= ctx.rev() - 1:
1008 if parents[0].rev() >= ctx.rev() - 1:
999 return []
1009 return []
1000 return parents
1010 return parents
1001
1011
1002 def _show(self, ctx, copies, matchfn, props):
1012 def _show(self, ctx, copies, matchfn, props):
1003 '''show a single changeset or file revision'''
1013 '''show a single changeset or file revision'''
1004
1014
1005 showlist = templatekw.showlist
1015 showlist = templatekw.showlist
1006
1016
1007 # showparents() behaviour depends on ui trace level which
1017 # showparents() behaviour depends on ui trace level which
1008 # causes unexpected behaviours at templating level and makes
1018 # causes unexpected behaviours at templating level and makes
1009 # it harder to extract it in a standalone function. Its
1019 # it harder to extract it in a standalone function. Its
1010 # behaviour cannot be changed so leave it here for now.
1020 # behaviour cannot be changed so leave it here for now.
1011 def showparents(**args):
1021 def showparents(**args):
1012 ctx = args['ctx']
1022 ctx = args['ctx']
1013 parents = [[('rev', p.rev()), ('node', p.hex())]
1023 parents = [[('rev', p.rev()), ('node', p.hex())]
1014 for p in self._meaningful_parentrevs(ctx)]
1024 for p in self._meaningful_parentrevs(ctx)]
1015 return showlist('parent', parents, **args)
1025 return showlist('parent', parents, **args)
1016
1026
1017 props = props.copy()
1027 props = props.copy()
1018 props.update(templatekw.keywords)
1028 props.update(templatekw.keywords)
1019 props['parents'] = showparents
1029 props['parents'] = showparents
1020 props['templ'] = self.t
1030 props['templ'] = self.t
1021 props['ctx'] = ctx
1031 props['ctx'] = ctx
1022 props['repo'] = self.repo
1032 props['repo'] = self.repo
1023 props['revcache'] = {'copies': copies}
1033 props['revcache'] = {'copies': copies}
1024 props['cache'] = self.cache
1034 props['cache'] = self.cache
1025
1035
1026 # find correct templates for current mode
1036 # find correct templates for current mode
1027
1037
1028 tmplmodes = [
1038 tmplmodes = [
1029 (True, None),
1039 (True, None),
1030 (self.ui.verbose, 'verbose'),
1040 (self.ui.verbose, 'verbose'),
1031 (self.ui.quiet, 'quiet'),
1041 (self.ui.quiet, 'quiet'),
1032 (self.ui.debugflag, 'debug'),
1042 (self.ui.debugflag, 'debug'),
1033 ]
1043 ]
1034
1044
1035 types = {'header': '', 'footer':'', 'changeset': 'changeset'}
1045 types = {'header': '', 'footer':'', 'changeset': 'changeset'}
1036 for mode, postfix in tmplmodes:
1046 for mode, postfix in tmplmodes:
1037 for type in types:
1047 for type in types:
1038 cur = postfix and ('%s_%s' % (type, postfix)) or type
1048 cur = postfix and ('%s_%s' % (type, postfix)) or type
1039 if mode and cur in self.t:
1049 if mode and cur in self.t:
1040 types[type] = cur
1050 types[type] = cur
1041
1051
1042 try:
1052 try:
1043
1053
1044 # write header
1054 # write header
1045 if types['header']:
1055 if types['header']:
1046 h = templater.stringify(self.t(types['header'], **props))
1056 h = templater.stringify(self.t(types['header'], **props))
1047 if self.buffered:
1057 if self.buffered:
1048 self.header[ctx.rev()] = h
1058 self.header[ctx.rev()] = h
1049 else:
1059 else:
1050 if self.lastheader != h:
1060 if self.lastheader != h:
1051 self.lastheader = h
1061 self.lastheader = h
1052 self.ui.write(h)
1062 self.ui.write(h)
1053
1063
1054 # write changeset metadata, then patch if requested
1064 # write changeset metadata, then patch if requested
1055 key = types['changeset']
1065 key = types['changeset']
1056 self.ui.write(templater.stringify(self.t(key, **props)))
1066 self.ui.write(templater.stringify(self.t(key, **props)))
1057 self.showpatch(ctx.node(), matchfn)
1067 self.showpatch(ctx.node(), matchfn)
1058
1068
1059 if types['footer']:
1069 if types['footer']:
1060 if not self.footer:
1070 if not self.footer:
1061 self.footer = templater.stringify(self.t(types['footer'],
1071 self.footer = templater.stringify(self.t(types['footer'],
1062 **props))
1072 **props))
1063
1073
1064 except KeyError, inst:
1074 except KeyError, inst:
1065 msg = _("%s: no key named '%s'")
1075 msg = _("%s: no key named '%s'")
1066 raise util.Abort(msg % (self.t.mapfile, inst.args[0]))
1076 raise util.Abort(msg % (self.t.mapfile, inst.args[0]))
1067 except SyntaxError, inst:
1077 except SyntaxError, inst:
1068 raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0]))
1078 raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0]))
1069
1079
1070 def gettemplate(ui, tmpl, style):
1080 def gettemplate(ui, tmpl, style):
1071 """
1081 """
1072 Find the template matching the given template spec or style.
1082 Find the template matching the given template spec or style.
1073 """
1083 """
1074
1084
1075 # ui settings
1085 # ui settings
1076 if not tmpl and not style:
1086 if not tmpl and not style:
1077 tmpl = ui.config('ui', 'logtemplate')
1087 tmpl = ui.config('ui', 'logtemplate')
1078 if tmpl:
1088 if tmpl:
1079 try:
1089 try:
1080 tmpl = templater.parsestring(tmpl)
1090 tmpl = templater.parsestring(tmpl)
1081 except SyntaxError:
1091 except SyntaxError:
1082 tmpl = templater.parsestring(tmpl, quoted=False)
1092 tmpl = templater.parsestring(tmpl, quoted=False)
1083 return tmpl, None
1093 return tmpl, None
1084 else:
1094 else:
1085 style = util.expandpath(ui.config('ui', 'style', ''))
1095 style = util.expandpath(ui.config('ui', 'style', ''))
1086
1096
1087 if style:
1097 if style:
1088 mapfile = style
1098 mapfile = style
1089 if not os.path.split(mapfile)[0]:
1099 if not os.path.split(mapfile)[0]:
1090 mapname = (templater.templatepath('map-cmdline.' + mapfile)
1100 mapname = (templater.templatepath('map-cmdline.' + mapfile)
1091 or templater.templatepath(mapfile))
1101 or templater.templatepath(mapfile))
1092 if mapname:
1102 if mapname:
1093 mapfile = mapname
1103 mapfile = mapname
1094 return None, mapfile
1104 return None, mapfile
1095
1105
1096 if not tmpl:
1106 if not tmpl:
1097 return None, None
1107 return None, None
1098
1108
1099 # looks like a literal template?
1109 # looks like a literal template?
1100 if '{' in tmpl:
1110 if '{' in tmpl:
1101 return tmpl, None
1111 return tmpl, None
1102
1112
1103 # perhaps a stock style?
1113 # perhaps a stock style?
1104 if not os.path.split(tmpl)[0]:
1114 if not os.path.split(tmpl)[0]:
1105 mapname = (templater.templatepath('map-cmdline.' + tmpl)
1115 mapname = (templater.templatepath('map-cmdline.' + tmpl)
1106 or templater.templatepath(tmpl))
1116 or templater.templatepath(tmpl))
1107 if mapname and os.path.isfile(mapname):
1117 if mapname and os.path.isfile(mapname):
1108 return None, mapname
1118 return None, mapname
1109
1119
1110 # perhaps it's a reference to [templates]
1120 # perhaps it's a reference to [templates]
1111 t = ui.config('templates', tmpl)
1121 t = ui.config('templates', tmpl)
1112 if t:
1122 if t:
1113 try:
1123 try:
1114 tmpl = templater.parsestring(t)
1124 tmpl = templater.parsestring(t)
1115 except SyntaxError:
1125 except SyntaxError:
1116 tmpl = templater.parsestring(t, quoted=False)
1126 tmpl = templater.parsestring(t, quoted=False)
1117 return tmpl, None
1127 return tmpl, None
1118
1128
1119 # perhaps it's a path to a map or a template
1129 # perhaps it's a path to a map or a template
1120 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
1130 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
1121 # is it a mapfile for a style?
1131 # is it a mapfile for a style?
1122 if os.path.basename(tmpl).startswith("map-"):
1132 if os.path.basename(tmpl).startswith("map-"):
1123 return None, os.path.realpath(tmpl)
1133 return None, os.path.realpath(tmpl)
1124 tmpl = open(tmpl).read()
1134 tmpl = open(tmpl).read()
1125 return tmpl, None
1135 return tmpl, None
1126
1136
1127 # constant string?
1137 # constant string?
1128 return tmpl, None
1138 return tmpl, None
1129
1139
1130 def show_changeset(ui, repo, opts, buffered=False):
1140 def show_changeset(ui, repo, opts, buffered=False):
1131 """show one changeset using template or regular display.
1141 """show one changeset using template or regular display.
1132
1142
1133 Display format will be the first non-empty hit of:
1143 Display format will be the first non-empty hit of:
1134 1. option 'template'
1144 1. option 'template'
1135 2. option 'style'
1145 2. option 'style'
1136 3. [ui] setting 'logtemplate'
1146 3. [ui] setting 'logtemplate'
1137 4. [ui] setting 'style'
1147 4. [ui] setting 'style'
1138 If all of these values are either the unset or the empty string,
1148 If all of these values are either the unset or the empty string,
1139 regular display via changeset_printer() is done.
1149 regular display via changeset_printer() is done.
1140 """
1150 """
1141 # options
1151 # options
1142 patch = None
1152 patch = None
1143 if opts.get('patch') or opts.get('stat'):
1153 if opts.get('patch') or opts.get('stat'):
1144 patch = scmutil.matchall(repo)
1154 patch = scmutil.matchall(repo)
1145
1155
1146 tmpl, mapfile = gettemplate(ui, opts.get('template'), opts.get('style'))
1156 tmpl, mapfile = gettemplate(ui, opts.get('template'), opts.get('style'))
1147
1157
1148 if not tmpl and not mapfile:
1158 if not tmpl and not mapfile:
1149 return changeset_printer(ui, repo, patch, opts, buffered)
1159 return changeset_printer(ui, repo, patch, opts, buffered)
1150
1160
1151 try:
1161 try:
1152 t = changeset_templater(ui, repo, patch, opts, tmpl, mapfile, buffered)
1162 t = changeset_templater(ui, repo, patch, opts, tmpl, mapfile, buffered)
1153 except SyntaxError, inst:
1163 except SyntaxError, inst:
1154 raise util.Abort(inst.args[0])
1164 raise util.Abort(inst.args[0])
1155 return t
1165 return t
1156
1166
1157 def showmarker(ui, marker):
1167 def showmarker(ui, marker):
1158 """utility function to display obsolescence marker in a readable way
1168 """utility function to display obsolescence marker in a readable way
1159
1169
1160 To be used by debug function."""
1170 To be used by debug function."""
1161 ui.write(hex(marker.precnode()))
1171 ui.write(hex(marker.precnode()))
1162 for repl in marker.succnodes():
1172 for repl in marker.succnodes():
1163 ui.write(' ')
1173 ui.write(' ')
1164 ui.write(hex(repl))
1174 ui.write(hex(repl))
1165 ui.write(' %X ' % marker._data[2])
1175 ui.write(' %X ' % marker._data[2])
1166 ui.write('{%s}' % (', '.join('%r: %r' % t for t in
1176 ui.write('{%s}' % (', '.join('%r: %r' % t for t in
1167 sorted(marker.metadata().items()))))
1177 sorted(marker.metadata().items()))))
1168 ui.write('\n')
1178 ui.write('\n')
1169
1179
1170 def finddate(ui, repo, date):
1180 def finddate(ui, repo, date):
1171 """Find the tipmost changeset that matches the given date spec"""
1181 """Find the tipmost changeset that matches the given date spec"""
1172
1182
1173 df = util.matchdate(date)
1183 df = util.matchdate(date)
1174 m = scmutil.matchall(repo)
1184 m = scmutil.matchall(repo)
1175 results = {}
1185 results = {}
1176
1186
1177 def prep(ctx, fns):
1187 def prep(ctx, fns):
1178 d = ctx.date()
1188 d = ctx.date()
1179 if df(d[0]):
1189 if df(d[0]):
1180 results[ctx.rev()] = d
1190 results[ctx.rev()] = d
1181
1191
1182 for ctx in walkchangerevs(repo, m, {'rev': None}, prep):
1192 for ctx in walkchangerevs(repo, m, {'rev': None}, prep):
1183 rev = ctx.rev()
1193 rev = ctx.rev()
1184 if rev in results:
1194 if rev in results:
1185 ui.status(_("found revision %s from %s\n") %
1195 ui.status(_("found revision %s from %s\n") %
1186 (rev, util.datestr(results[rev])))
1196 (rev, util.datestr(results[rev])))
1187 return str(rev)
1197 return str(rev)
1188
1198
1189 raise util.Abort(_("revision matching date not found"))
1199 raise util.Abort(_("revision matching date not found"))
1190
1200
1191 def increasingwindows(windowsize=8, sizelimit=512):
1201 def increasingwindows(windowsize=8, sizelimit=512):
1192 while True:
1202 while True:
1193 yield windowsize
1203 yield windowsize
1194 if windowsize < sizelimit:
1204 if windowsize < sizelimit:
1195 windowsize *= 2
1205 windowsize *= 2
1196
1206
1197 class FileWalkError(Exception):
1207 class FileWalkError(Exception):
1198 pass
1208 pass
1199
1209
1200 def walkfilerevs(repo, match, follow, revs, fncache):
1210 def walkfilerevs(repo, match, follow, revs, fncache):
1201 '''Walks the file history for the matched files.
1211 '''Walks the file history for the matched files.
1202
1212
1203 Returns the changeset revs that are involved in the file history.
1213 Returns the changeset revs that are involved in the file history.
1204
1214
1205 Throws FileWalkError if the file history can't be walked using
1215 Throws FileWalkError if the file history can't be walked using
1206 filelogs alone.
1216 filelogs alone.
1207 '''
1217 '''
1208 wanted = set()
1218 wanted = set()
1209 copies = []
1219 copies = []
1210 minrev, maxrev = min(revs), max(revs)
1220 minrev, maxrev = min(revs), max(revs)
1211 def filerevgen(filelog, last):
1221 def filerevgen(filelog, last):
1212 """
1222 """
1213 Only files, no patterns. Check the history of each file.
1223 Only files, no patterns. Check the history of each file.
1214
1224
1215 Examines filelog entries within minrev, maxrev linkrev range
1225 Examines filelog entries within minrev, maxrev linkrev range
1216 Returns an iterator yielding (linkrev, parentlinkrevs, copied)
1226 Returns an iterator yielding (linkrev, parentlinkrevs, copied)
1217 tuples in backwards order
1227 tuples in backwards order
1218 """
1228 """
1219 cl_count = len(repo)
1229 cl_count = len(repo)
1220 revs = []
1230 revs = []
1221 for j in xrange(0, last + 1):
1231 for j in xrange(0, last + 1):
1222 linkrev = filelog.linkrev(j)
1232 linkrev = filelog.linkrev(j)
1223 if linkrev < minrev:
1233 if linkrev < minrev:
1224 continue
1234 continue
1225 # only yield rev for which we have the changelog, it can
1235 # only yield rev for which we have the changelog, it can
1226 # happen while doing "hg log" during a pull or commit
1236 # happen while doing "hg log" during a pull or commit
1227 if linkrev >= cl_count:
1237 if linkrev >= cl_count:
1228 break
1238 break
1229
1239
1230 parentlinkrevs = []
1240 parentlinkrevs = []
1231 for p in filelog.parentrevs(j):
1241 for p in filelog.parentrevs(j):
1232 if p != nullrev:
1242 if p != nullrev:
1233 parentlinkrevs.append(filelog.linkrev(p))
1243 parentlinkrevs.append(filelog.linkrev(p))
1234 n = filelog.node(j)
1244 n = filelog.node(j)
1235 revs.append((linkrev, parentlinkrevs,
1245 revs.append((linkrev, parentlinkrevs,
1236 follow and filelog.renamed(n)))
1246 follow and filelog.renamed(n)))
1237
1247
1238 return reversed(revs)
1248 return reversed(revs)
1239 def iterfiles():
1249 def iterfiles():
1240 pctx = repo['.']
1250 pctx = repo['.']
1241 for filename in match.files():
1251 for filename in match.files():
1242 if follow:
1252 if follow:
1243 if filename not in pctx:
1253 if filename not in pctx:
1244 raise util.Abort(_('cannot follow file not in parent '
1254 raise util.Abort(_('cannot follow file not in parent '
1245 'revision: "%s"') % filename)
1255 'revision: "%s"') % filename)
1246 yield filename, pctx[filename].filenode()
1256 yield filename, pctx[filename].filenode()
1247 else:
1257 else:
1248 yield filename, None
1258 yield filename, None
1249 for filename_node in copies:
1259 for filename_node in copies:
1250 yield filename_node
1260 yield filename_node
1251
1261
1252 for file_, node in iterfiles():
1262 for file_, node in iterfiles():
1253 filelog = repo.file(file_)
1263 filelog = repo.file(file_)
1254 if not len(filelog):
1264 if not len(filelog):
1255 if node is None:
1265 if node is None:
1256 # A zero count may be a directory or deleted file, so
1266 # A zero count may be a directory or deleted file, so
1257 # try to find matching entries on the slow path.
1267 # try to find matching entries on the slow path.
1258 if follow:
1268 if follow:
1259 raise util.Abort(
1269 raise util.Abort(
1260 _('cannot follow nonexistent file: "%s"') % file_)
1270 _('cannot follow nonexistent file: "%s"') % file_)
1261 raise FileWalkError("Cannot walk via filelog")
1271 raise FileWalkError("Cannot walk via filelog")
1262 else:
1272 else:
1263 continue
1273 continue
1264
1274
1265 if node is None:
1275 if node is None:
1266 last = len(filelog) - 1
1276 last = len(filelog) - 1
1267 else:
1277 else:
1268 last = filelog.rev(node)
1278 last = filelog.rev(node)
1269
1279
1270
1280
1271 # keep track of all ancestors of the file
1281 # keep track of all ancestors of the file
1272 ancestors = set([filelog.linkrev(last)])
1282 ancestors = set([filelog.linkrev(last)])
1273
1283
1274 # iterate from latest to oldest revision
1284 # iterate from latest to oldest revision
1275 for rev, flparentlinkrevs, copied in filerevgen(filelog, last):
1285 for rev, flparentlinkrevs, copied in filerevgen(filelog, last):
1276 if not follow:
1286 if not follow:
1277 if rev > maxrev:
1287 if rev > maxrev:
1278 continue
1288 continue
1279 else:
1289 else:
1280 # Note that last might not be the first interesting
1290 # Note that last might not be the first interesting
1281 # rev to us:
1291 # rev to us:
1282 # if the file has been changed after maxrev, we'll
1292 # if the file has been changed after maxrev, we'll
1283 # have linkrev(last) > maxrev, and we still need
1293 # have linkrev(last) > maxrev, and we still need
1284 # to explore the file graph
1294 # to explore the file graph
1285 if rev not in ancestors:
1295 if rev not in ancestors:
1286 continue
1296 continue
1287 # XXX insert 1327 fix here
1297 # XXX insert 1327 fix here
1288 if flparentlinkrevs:
1298 if flparentlinkrevs:
1289 ancestors.update(flparentlinkrevs)
1299 ancestors.update(flparentlinkrevs)
1290
1300
1291 fncache.setdefault(rev, []).append(file_)
1301 fncache.setdefault(rev, []).append(file_)
1292 wanted.add(rev)
1302 wanted.add(rev)
1293 if copied:
1303 if copied:
1294 copies.append(copied)
1304 copies.append(copied)
1295
1305
1296 return wanted
1306 return wanted
1297
1307
1298 def walkchangerevs(repo, match, opts, prepare):
1308 def walkchangerevs(repo, match, opts, prepare):
1299 '''Iterate over files and the revs in which they changed.
1309 '''Iterate over files and the revs in which they changed.
1300
1310
1301 Callers most commonly need to iterate backwards over the history
1311 Callers most commonly need to iterate backwards over the history
1302 in which they are interested. Doing so has awful (quadratic-looking)
1312 in which they are interested. Doing so has awful (quadratic-looking)
1303 performance, so we use iterators in a "windowed" way.
1313 performance, so we use iterators in a "windowed" way.
1304
1314
1305 We walk a window of revisions in the desired order. Within the
1315 We walk a window of revisions in the desired order. Within the
1306 window, we first walk forwards to gather data, then in the desired
1316 window, we first walk forwards to gather data, then in the desired
1307 order (usually backwards) to display it.
1317 order (usually backwards) to display it.
1308
1318
1309 This function returns an iterator yielding contexts. Before
1319 This function returns an iterator yielding contexts. Before
1310 yielding each context, the iterator will first call the prepare
1320 yielding each context, the iterator will first call the prepare
1311 function on each context in the window in forward order.'''
1321 function on each context in the window in forward order.'''
1312
1322
1313 follow = opts.get('follow') or opts.get('follow_first')
1323 follow = opts.get('follow') or opts.get('follow_first')
1314
1324
1315 if opts.get('rev'):
1325 if opts.get('rev'):
1316 revs = scmutil.revrange(repo, opts.get('rev'))
1326 revs = scmutil.revrange(repo, opts.get('rev'))
1317 elif follow:
1327 elif follow:
1318 revs = repo.revs('reverse(:.)')
1328 revs = repo.revs('reverse(:.)')
1319 else:
1329 else:
1320 revs = revset.spanset(repo)
1330 revs = revset.spanset(repo)
1321 revs.reverse()
1331 revs.reverse()
1322 if not revs:
1332 if not revs:
1323 return []
1333 return []
1324 wanted = set()
1334 wanted = set()
1325 slowpath = match.anypats() or (match.files() and opts.get('removed'))
1335 slowpath = match.anypats() or (match.files() and opts.get('removed'))
1326 fncache = {}
1336 fncache = {}
1327 change = repo.changectx
1337 change = repo.changectx
1328
1338
1329 # First step is to fill wanted, the set of revisions that we want to yield.
1339 # First step is to fill wanted, the set of revisions that we want to yield.
1330 # When it does not induce extra cost, we also fill fncache for revisions in
1340 # When it does not induce extra cost, we also fill fncache for revisions in
1331 # wanted: a cache of filenames that were changed (ctx.files()) and that
1341 # wanted: a cache of filenames that were changed (ctx.files()) and that
1332 # match the file filtering conditions.
1342 # match the file filtering conditions.
1333
1343
1334 if not slowpath and not match.files():
1344 if not slowpath and not match.files():
1335 # No files, no patterns. Display all revs.
1345 # No files, no patterns. Display all revs.
1336 wanted = revs
1346 wanted = revs
1337
1347
1338 if not slowpath and match.files():
1348 if not slowpath and match.files():
1339 # We only have to read through the filelog to find wanted revisions
1349 # We only have to read through the filelog to find wanted revisions
1340
1350
1341 try:
1351 try:
1342 wanted = walkfilerevs(repo, match, follow, revs, fncache)
1352 wanted = walkfilerevs(repo, match, follow, revs, fncache)
1343 except FileWalkError:
1353 except FileWalkError:
1344 slowpath = True
1354 slowpath = True
1345
1355
1346 # We decided to fall back to the slowpath because at least one
1356 # We decided to fall back to the slowpath because at least one
1347 # of the paths was not a file. Check to see if at least one of them
1357 # of the paths was not a file. Check to see if at least one of them
1348 # existed in history, otherwise simply return
1358 # existed in history, otherwise simply return
1349 for path in match.files():
1359 for path in match.files():
1350 if path == '.' or path in repo.store:
1360 if path == '.' or path in repo.store:
1351 break
1361 break
1352 else:
1362 else:
1353 return []
1363 return []
1354
1364
1355 if slowpath:
1365 if slowpath:
1356 # We have to read the changelog to match filenames against
1366 # We have to read the changelog to match filenames against
1357 # changed files
1367 # changed files
1358
1368
1359 if follow:
1369 if follow:
1360 raise util.Abort(_('can only follow copies/renames for explicit '
1370 raise util.Abort(_('can only follow copies/renames for explicit '
1361 'filenames'))
1371 'filenames'))
1362
1372
1363 # The slow path checks files modified in every changeset.
1373 # The slow path checks files modified in every changeset.
1364 # This is really slow on large repos, so compute the set lazily.
1374 # This is really slow on large repos, so compute the set lazily.
1365 class lazywantedset(object):
1375 class lazywantedset(object):
1366 def __init__(self):
1376 def __init__(self):
1367 self.set = set()
1377 self.set = set()
1368 self.revs = set(revs)
1378 self.revs = set(revs)
1369
1379
1370 # No need to worry about locality here because it will be accessed
1380 # No need to worry about locality here because it will be accessed
1371 # in the same order as the increasing window below.
1381 # in the same order as the increasing window below.
1372 def __contains__(self, value):
1382 def __contains__(self, value):
1373 if value in self.set:
1383 if value in self.set:
1374 return True
1384 return True
1375 elif not value in self.revs:
1385 elif not value in self.revs:
1376 return False
1386 return False
1377 else:
1387 else:
1378 self.revs.discard(value)
1388 self.revs.discard(value)
1379 ctx = change(value)
1389 ctx = change(value)
1380 matches = filter(match, ctx.files())
1390 matches = filter(match, ctx.files())
1381 if matches:
1391 if matches:
1382 fncache[value] = matches
1392 fncache[value] = matches
1383 self.set.add(value)
1393 self.set.add(value)
1384 return True
1394 return True
1385 return False
1395 return False
1386
1396
1387 def discard(self, value):
1397 def discard(self, value):
1388 self.revs.discard(value)
1398 self.revs.discard(value)
1389 self.set.discard(value)
1399 self.set.discard(value)
1390
1400
1391 wanted = lazywantedset()
1401 wanted = lazywantedset()
1392
1402
1393 class followfilter(object):
1403 class followfilter(object):
1394 def __init__(self, onlyfirst=False):
1404 def __init__(self, onlyfirst=False):
1395 self.startrev = nullrev
1405 self.startrev = nullrev
1396 self.roots = set()
1406 self.roots = set()
1397 self.onlyfirst = onlyfirst
1407 self.onlyfirst = onlyfirst
1398
1408
1399 def match(self, rev):
1409 def match(self, rev):
1400 def realparents(rev):
1410 def realparents(rev):
1401 if self.onlyfirst:
1411 if self.onlyfirst:
1402 return repo.changelog.parentrevs(rev)[0:1]
1412 return repo.changelog.parentrevs(rev)[0:1]
1403 else:
1413 else:
1404 return filter(lambda x: x != nullrev,
1414 return filter(lambda x: x != nullrev,
1405 repo.changelog.parentrevs(rev))
1415 repo.changelog.parentrevs(rev))
1406
1416
1407 if self.startrev == nullrev:
1417 if self.startrev == nullrev:
1408 self.startrev = rev
1418 self.startrev = rev
1409 return True
1419 return True
1410
1420
1411 if rev > self.startrev:
1421 if rev > self.startrev:
1412 # forward: all descendants
1422 # forward: all descendants
1413 if not self.roots:
1423 if not self.roots:
1414 self.roots.add(self.startrev)
1424 self.roots.add(self.startrev)
1415 for parent in realparents(rev):
1425 for parent in realparents(rev):
1416 if parent in self.roots:
1426 if parent in self.roots:
1417 self.roots.add(rev)
1427 self.roots.add(rev)
1418 return True
1428 return True
1419 else:
1429 else:
1420 # backwards: all parents
1430 # backwards: all parents
1421 if not self.roots:
1431 if not self.roots:
1422 self.roots.update(realparents(self.startrev))
1432 self.roots.update(realparents(self.startrev))
1423 if rev in self.roots:
1433 if rev in self.roots:
1424 self.roots.remove(rev)
1434 self.roots.remove(rev)
1425 self.roots.update(realparents(rev))
1435 self.roots.update(realparents(rev))
1426 return True
1436 return True
1427
1437
1428 return False
1438 return False
1429
1439
1430 # it might be worthwhile to do this in the iterator if the rev range
1440 # it might be worthwhile to do this in the iterator if the rev range
1431 # is descending and the prune args are all within that range
1441 # is descending and the prune args are all within that range
1432 for rev in opts.get('prune', ()):
1442 for rev in opts.get('prune', ()):
1433 rev = repo[rev].rev()
1443 rev = repo[rev].rev()
1434 ff = followfilter()
1444 ff = followfilter()
1435 stop = min(revs[0], revs[-1])
1445 stop = min(revs[0], revs[-1])
1436 for x in xrange(rev, stop - 1, -1):
1446 for x in xrange(rev, stop - 1, -1):
1437 if ff.match(x):
1447 if ff.match(x):
1438 wanted = wanted - [x]
1448 wanted = wanted - [x]
1439
1449
1440 # Now that wanted is correctly initialized, we can iterate over the
1450 # Now that wanted is correctly initialized, we can iterate over the
1441 # revision range, yielding only revisions in wanted.
1451 # revision range, yielding only revisions in wanted.
1442 def iterate():
1452 def iterate():
1443 if follow and not match.files():
1453 if follow and not match.files():
1444 ff = followfilter(onlyfirst=opts.get('follow_first'))
1454 ff = followfilter(onlyfirst=opts.get('follow_first'))
1445 def want(rev):
1455 def want(rev):
1446 return ff.match(rev) and rev in wanted
1456 return ff.match(rev) and rev in wanted
1447 else:
1457 else:
1448 def want(rev):
1458 def want(rev):
1449 return rev in wanted
1459 return rev in wanted
1450
1460
1451 it = iter(revs)
1461 it = iter(revs)
1452 stopiteration = False
1462 stopiteration = False
1453 for windowsize in increasingwindows():
1463 for windowsize in increasingwindows():
1454 nrevs = []
1464 nrevs = []
1455 for i in xrange(windowsize):
1465 for i in xrange(windowsize):
1456 try:
1466 try:
1457 rev = it.next()
1467 rev = it.next()
1458 if want(rev):
1468 if want(rev):
1459 nrevs.append(rev)
1469 nrevs.append(rev)
1460 except (StopIteration):
1470 except (StopIteration):
1461 stopiteration = True
1471 stopiteration = True
1462 break
1472 break
1463 for rev in sorted(nrevs):
1473 for rev in sorted(nrevs):
1464 fns = fncache.get(rev)
1474 fns = fncache.get(rev)
1465 ctx = change(rev)
1475 ctx = change(rev)
1466 if not fns:
1476 if not fns:
1467 def fns_generator():
1477 def fns_generator():
1468 for f in ctx.files():
1478 for f in ctx.files():
1469 if match(f):
1479 if match(f):
1470 yield f
1480 yield f
1471 fns = fns_generator()
1481 fns = fns_generator()
1472 prepare(ctx, fns)
1482 prepare(ctx, fns)
1473 for rev in nrevs:
1483 for rev in nrevs:
1474 yield change(rev)
1484 yield change(rev)
1475
1485
1476 if stopiteration:
1486 if stopiteration:
1477 break
1487 break
1478
1488
1479 return iterate()
1489 return iterate()
1480
1490
1481 def _makelogfilematcher(repo, pats, followfirst):
1491 def _makelogfilematcher(repo, pats, followfirst):
1482 # When displaying a revision with --patch --follow FILE, we have
1492 # When displaying a revision with --patch --follow FILE, we have
1483 # to know which file of the revision must be diffed. With
1493 # to know which file of the revision must be diffed. With
1484 # --follow, we want the names of the ancestors of FILE in the
1494 # --follow, we want the names of the ancestors of FILE in the
1485 # revision, stored in "fcache". "fcache" is populated by
1495 # revision, stored in "fcache". "fcache" is populated by
1486 # reproducing the graph traversal already done by --follow revset
1496 # reproducing the graph traversal already done by --follow revset
1487 # and relating linkrevs to file names (which is not "correct" but
1497 # and relating linkrevs to file names (which is not "correct" but
1488 # good enough).
1498 # good enough).
1489 fcache = {}
1499 fcache = {}
1490 fcacheready = [False]
1500 fcacheready = [False]
1491 pctx = repo['.']
1501 pctx = repo['.']
1492 wctx = repo[None]
1502 wctx = repo[None]
1493
1503
1494 def populate():
1504 def populate():
1495 for fn in pats:
1505 for fn in pats:
1496 for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)):
1506 for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)):
1497 for c in i:
1507 for c in i:
1498 fcache.setdefault(c.linkrev(), set()).add(c.path())
1508 fcache.setdefault(c.linkrev(), set()).add(c.path())
1499
1509
1500 def filematcher(rev):
1510 def filematcher(rev):
1501 if not fcacheready[0]:
1511 if not fcacheready[0]:
1502 # Lazy initialization
1512 # Lazy initialization
1503 fcacheready[0] = True
1513 fcacheready[0] = True
1504 populate()
1514 populate()
1505 return scmutil.match(wctx, fcache.get(rev, []), default='path')
1515 return scmutil.match(wctx, fcache.get(rev, []), default='path')
1506
1516
1507 return filematcher
1517 return filematcher
1508
1518
1509 def _makelogrevset(repo, pats, opts, revs):
1519 def _makelogrevset(repo, pats, opts, revs):
1510 """Return (expr, filematcher) where expr is a revset string built
1520 """Return (expr, filematcher) where expr is a revset string built
1511 from log options and file patterns or None. If --stat or --patch
1521 from log options and file patterns or None. If --stat or --patch
1512 are not passed filematcher is None. Otherwise it is a callable
1522 are not passed filematcher is None. Otherwise it is a callable
1513 taking a revision number and returning a match objects filtering
1523 taking a revision number and returning a match objects filtering
1514 the files to be detailed when displaying the revision.
1524 the files to be detailed when displaying the revision.
1515 """
1525 """
1516 opt2revset = {
1526 opt2revset = {
1517 'no_merges': ('not merge()', None),
1527 'no_merges': ('not merge()', None),
1518 'only_merges': ('merge()', None),
1528 'only_merges': ('merge()', None),
1519 '_ancestors': ('ancestors(%(val)s)', None),
1529 '_ancestors': ('ancestors(%(val)s)', None),
1520 '_fancestors': ('_firstancestors(%(val)s)', None),
1530 '_fancestors': ('_firstancestors(%(val)s)', None),
1521 '_descendants': ('descendants(%(val)s)', None),
1531 '_descendants': ('descendants(%(val)s)', None),
1522 '_fdescendants': ('_firstdescendants(%(val)s)', None),
1532 '_fdescendants': ('_firstdescendants(%(val)s)', None),
1523 '_matchfiles': ('_matchfiles(%(val)s)', None),
1533 '_matchfiles': ('_matchfiles(%(val)s)', None),
1524 'date': ('date(%(val)r)', None),
1534 'date': ('date(%(val)r)', None),
1525 'branch': ('branch(%(val)r)', ' or '),
1535 'branch': ('branch(%(val)r)', ' or '),
1526 '_patslog': ('filelog(%(val)r)', ' or '),
1536 '_patslog': ('filelog(%(val)r)', ' or '),
1527 '_patsfollow': ('follow(%(val)r)', ' or '),
1537 '_patsfollow': ('follow(%(val)r)', ' or '),
1528 '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
1538 '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
1529 'keyword': ('keyword(%(val)r)', ' or '),
1539 'keyword': ('keyword(%(val)r)', ' or '),
1530 'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '),
1540 'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '),
1531 'user': ('user(%(val)r)', ' or '),
1541 'user': ('user(%(val)r)', ' or '),
1532 }
1542 }
1533
1543
1534 opts = dict(opts)
1544 opts = dict(opts)
1535 # follow or not follow?
1545 # follow or not follow?
1536 follow = opts.get('follow') or opts.get('follow_first')
1546 follow = opts.get('follow') or opts.get('follow_first')
1537 followfirst = opts.get('follow_first') and 1 or 0
1547 followfirst = opts.get('follow_first') and 1 or 0
1538 # --follow with FILE behaviour depends on revs...
1548 # --follow with FILE behaviour depends on revs...
1539 it = iter(revs)
1549 it = iter(revs)
1540 startrev = it.next()
1550 startrev = it.next()
1541 try:
1551 try:
1542 followdescendants = startrev < it.next()
1552 followdescendants = startrev < it.next()
1543 except (StopIteration):
1553 except (StopIteration):
1544 followdescendants = False
1554 followdescendants = False
1545
1555
1546 # branch and only_branch are really aliases and must be handled at
1556 # branch and only_branch are really aliases and must be handled at
1547 # the same time
1557 # the same time
1548 opts['branch'] = opts.get('branch', []) + opts.get('only_branch', [])
1558 opts['branch'] = opts.get('branch', []) + opts.get('only_branch', [])
1549 opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
1559 opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
1550 # pats/include/exclude are passed to match.match() directly in
1560 # pats/include/exclude are passed to match.match() directly in
1551 # _matchfiles() revset but walkchangerevs() builds its matcher with
1561 # _matchfiles() revset but walkchangerevs() builds its matcher with
1552 # scmutil.match(). The difference is input pats are globbed on
1562 # scmutil.match(). The difference is input pats are globbed on
1553 # platforms without shell expansion (windows).
1563 # platforms without shell expansion (windows).
1554 pctx = repo[None]
1564 pctx = repo[None]
1555 match, pats = scmutil.matchandpats(pctx, pats, opts)
1565 match, pats = scmutil.matchandpats(pctx, pats, opts)
1556 slowpath = match.anypats() or (match.files() and opts.get('removed'))
1566 slowpath = match.anypats() or (match.files() and opts.get('removed'))
1557 if not slowpath:
1567 if not slowpath:
1558 for f in match.files():
1568 for f in match.files():
1559 if follow and f not in pctx:
1569 if follow and f not in pctx:
1560 raise util.Abort(_('cannot follow file not in parent '
1570 raise util.Abort(_('cannot follow file not in parent '
1561 'revision: "%s"') % f)
1571 'revision: "%s"') % f)
1562 filelog = repo.file(f)
1572 filelog = repo.file(f)
1563 if not filelog:
1573 if not filelog:
1564 # A zero count may be a directory or deleted file, so
1574 # A zero count may be a directory or deleted file, so
1565 # try to find matching entries on the slow path.
1575 # try to find matching entries on the slow path.
1566 if follow:
1576 if follow:
1567 raise util.Abort(
1577 raise util.Abort(
1568 _('cannot follow nonexistent file: "%s"') % f)
1578 _('cannot follow nonexistent file: "%s"') % f)
1569 slowpath = True
1579 slowpath = True
1570
1580
1571 # We decided to fall back to the slowpath because at least one
1581 # We decided to fall back to the slowpath because at least one
1572 # of the paths was not a file. Check to see if at least one of them
1582 # of the paths was not a file. Check to see if at least one of them
1573 # existed in history - in that case, we'll continue down the
1583 # existed in history - in that case, we'll continue down the
1574 # slowpath; otherwise, we can turn off the slowpath
1584 # slowpath; otherwise, we can turn off the slowpath
1575 if slowpath:
1585 if slowpath:
1576 for path in match.files():
1586 for path in match.files():
1577 if path == '.' or path in repo.store:
1587 if path == '.' or path in repo.store:
1578 break
1588 break
1579 else:
1589 else:
1580 slowpath = False
1590 slowpath = False
1581
1591
1582 if slowpath:
1592 if slowpath:
1583 # See walkchangerevs() slow path.
1593 # See walkchangerevs() slow path.
1584 #
1594 #
1585 if follow:
1595 if follow:
1586 raise util.Abort(_('can only follow copies/renames for explicit '
1596 raise util.Abort(_('can only follow copies/renames for explicit '
1587 'filenames'))
1597 'filenames'))
1588 # pats/include/exclude cannot be represented as separate
1598 # pats/include/exclude cannot be represented as separate
1589 # revset expressions as their filtering logic applies at file
1599 # revset expressions as their filtering logic applies at file
1590 # level. For instance "-I a -X a" matches a revision touching
1600 # level. For instance "-I a -X a" matches a revision touching
1591 # "a" and "b" while "file(a) and not file(b)" does
1601 # "a" and "b" while "file(a) and not file(b)" does
1592 # not. Besides, filesets are evaluated against the working
1602 # not. Besides, filesets are evaluated against the working
1593 # directory.
1603 # directory.
1594 matchargs = ['r:', 'd:relpath']
1604 matchargs = ['r:', 'd:relpath']
1595 for p in pats:
1605 for p in pats:
1596 matchargs.append('p:' + p)
1606 matchargs.append('p:' + p)
1597 for p in opts.get('include', []):
1607 for p in opts.get('include', []):
1598 matchargs.append('i:' + p)
1608 matchargs.append('i:' + p)
1599 for p in opts.get('exclude', []):
1609 for p in opts.get('exclude', []):
1600 matchargs.append('x:' + p)
1610 matchargs.append('x:' + p)
1601 matchargs = ','.join(('%r' % p) for p in matchargs)
1611 matchargs = ','.join(('%r' % p) for p in matchargs)
1602 opts['_matchfiles'] = matchargs
1612 opts['_matchfiles'] = matchargs
1603 else:
1613 else:
1604 if follow:
1614 if follow:
1605 fpats = ('_patsfollow', '_patsfollowfirst')
1615 fpats = ('_patsfollow', '_patsfollowfirst')
1606 fnopats = (('_ancestors', '_fancestors'),
1616 fnopats = (('_ancestors', '_fancestors'),
1607 ('_descendants', '_fdescendants'))
1617 ('_descendants', '_fdescendants'))
1608 if pats:
1618 if pats:
1609 # follow() revset interprets its file argument as a
1619 # follow() revset interprets its file argument as a
1610 # manifest entry, so use match.files(), not pats.
1620 # manifest entry, so use match.files(), not pats.
1611 opts[fpats[followfirst]] = list(match.files())
1621 opts[fpats[followfirst]] = list(match.files())
1612 else:
1622 else:
1613 opts[fnopats[followdescendants][followfirst]] = str(startrev)
1623 opts[fnopats[followdescendants][followfirst]] = str(startrev)
1614 else:
1624 else:
1615 opts['_patslog'] = list(pats)
1625 opts['_patslog'] = list(pats)
1616
1626
1617 filematcher = None
1627 filematcher = None
1618 if opts.get('patch') or opts.get('stat'):
1628 if opts.get('patch') or opts.get('stat'):
1619 if follow:
1629 if follow:
1620 filematcher = _makelogfilematcher(repo, pats, followfirst)
1630 filematcher = _makelogfilematcher(repo, pats, followfirst)
1621 else:
1631 else:
1622 filematcher = lambda rev: match
1632 filematcher = lambda rev: match
1623
1633
1624 expr = []
1634 expr = []
1625 for op, val in opts.iteritems():
1635 for op, val in opts.iteritems():
1626 if not val:
1636 if not val:
1627 continue
1637 continue
1628 if op not in opt2revset:
1638 if op not in opt2revset:
1629 continue
1639 continue
1630 revop, andor = opt2revset[op]
1640 revop, andor = opt2revset[op]
1631 if '%(val)' not in revop:
1641 if '%(val)' not in revop:
1632 expr.append(revop)
1642 expr.append(revop)
1633 else:
1643 else:
1634 if not isinstance(val, list):
1644 if not isinstance(val, list):
1635 e = revop % {'val': val}
1645 e = revop % {'val': val}
1636 else:
1646 else:
1637 e = '(' + andor.join((revop % {'val': v}) for v in val) + ')'
1647 e = '(' + andor.join((revop % {'val': v}) for v in val) + ')'
1638 expr.append(e)
1648 expr.append(e)
1639
1649
1640 if expr:
1650 if expr:
1641 expr = '(' + ' and '.join(expr) + ')'
1651 expr = '(' + ' and '.join(expr) + ')'
1642 else:
1652 else:
1643 expr = None
1653 expr = None
1644 return expr, filematcher
1654 return expr, filematcher
1645
1655
1646 def getgraphlogrevs(repo, pats, opts):
1656 def getgraphlogrevs(repo, pats, opts):
1647 """Return (revs, expr, filematcher) where revs is an iterable of
1657 """Return (revs, expr, filematcher) where revs is an iterable of
1648 revision numbers, expr is a revset string built from log options
1658 revision numbers, expr is a revset string built from log options
1649 and file patterns or None, and used to filter 'revs'. If --stat or
1659 and file patterns or None, and used to filter 'revs'. If --stat or
1650 --patch are not passed filematcher is None. Otherwise it is a
1660 --patch are not passed filematcher is None. Otherwise it is a
1651 callable taking a revision number and returning a match objects
1661 callable taking a revision number and returning a match objects
1652 filtering the files to be detailed when displaying the revision.
1662 filtering the files to be detailed when displaying the revision.
1653 """
1663 """
1654 if not len(repo):
1664 if not len(repo):
1655 return [], None, None
1665 return [], None, None
1656 limit = loglimit(opts)
1666 limit = loglimit(opts)
1657 # Default --rev value depends on --follow but --follow behaviour
1667 # Default --rev value depends on --follow but --follow behaviour
1658 # depends on revisions resolved from --rev...
1668 # depends on revisions resolved from --rev...
1659 follow = opts.get('follow') or opts.get('follow_first')
1669 follow = opts.get('follow') or opts.get('follow_first')
1660 possiblyunsorted = False # whether revs might need sorting
1670 possiblyunsorted = False # whether revs might need sorting
1661 if opts.get('rev'):
1671 if opts.get('rev'):
1662 revs = scmutil.revrange(repo, opts['rev'])
1672 revs = scmutil.revrange(repo, opts['rev'])
1663 # Don't sort here because _makelogrevset might depend on the
1673 # Don't sort here because _makelogrevset might depend on the
1664 # order of revs
1674 # order of revs
1665 possiblyunsorted = True
1675 possiblyunsorted = True
1666 else:
1676 else:
1667 if follow and len(repo) > 0:
1677 if follow and len(repo) > 0:
1668 revs = repo.revs('reverse(:.)')
1678 revs = repo.revs('reverse(:.)')
1669 else:
1679 else:
1670 revs = revset.spanset(repo)
1680 revs = revset.spanset(repo)
1671 revs.reverse()
1681 revs.reverse()
1672 if not revs:
1682 if not revs:
1673 return revset.baseset(), None, None
1683 return revset.baseset(), None, None
1674 expr, filematcher = _makelogrevset(repo, pats, opts, revs)
1684 expr, filematcher = _makelogrevset(repo, pats, opts, revs)
1675 if possiblyunsorted:
1685 if possiblyunsorted:
1676 revs.sort(reverse=True)
1686 revs.sort(reverse=True)
1677 if expr:
1687 if expr:
1678 # Revset matchers often operate faster on revisions in changelog
1688 # Revset matchers often operate faster on revisions in changelog
1679 # order, because most filters deal with the changelog.
1689 # order, because most filters deal with the changelog.
1680 revs.reverse()
1690 revs.reverse()
1681 matcher = revset.match(repo.ui, expr)
1691 matcher = revset.match(repo.ui, expr)
1682 # Revset matches can reorder revisions. "A or B" typically returns
1692 # Revset matches can reorder revisions. "A or B" typically returns
1683 # returns the revision matching A then the revision matching B. Sort
1693 # returns the revision matching A then the revision matching B. Sort
1684 # again to fix that.
1694 # again to fix that.
1685 revs = matcher(repo, revs)
1695 revs = matcher(repo, revs)
1686 revs.sort(reverse=True)
1696 revs.sort(reverse=True)
1687 if limit is not None:
1697 if limit is not None:
1688 limitedrevs = revset.baseset()
1698 limitedrevs = revset.baseset()
1689 for idx, rev in enumerate(revs):
1699 for idx, rev in enumerate(revs):
1690 if idx >= limit:
1700 if idx >= limit:
1691 break
1701 break
1692 limitedrevs.append(rev)
1702 limitedrevs.append(rev)
1693 revs = limitedrevs
1703 revs = limitedrevs
1694
1704
1695 return revs, expr, filematcher
1705 return revs, expr, filematcher
1696
1706
1697 def getlogrevs(repo, pats, opts):
1707 def getlogrevs(repo, pats, opts):
1698 """Return (revs, expr, filematcher) where revs is an iterable of
1708 """Return (revs, expr, filematcher) where revs is an iterable of
1699 revision numbers, expr is a revset string built from log options
1709 revision numbers, expr is a revset string built from log options
1700 and file patterns or None, and used to filter 'revs'. If --stat or
1710 and file patterns or None, and used to filter 'revs'. If --stat or
1701 --patch are not passed filematcher is None. Otherwise it is a
1711 --patch are not passed filematcher is None. Otherwise it is a
1702 callable taking a revision number and returning a match objects
1712 callable taking a revision number and returning a match objects
1703 filtering the files to be detailed when displaying the revision.
1713 filtering the files to be detailed when displaying the revision.
1704 """
1714 """
1705 limit = loglimit(opts)
1715 limit = loglimit(opts)
1706 # Default --rev value depends on --follow but --follow behaviour
1716 # Default --rev value depends on --follow but --follow behaviour
1707 # depends on revisions resolved from --rev...
1717 # depends on revisions resolved from --rev...
1708 follow = opts.get('follow') or opts.get('follow_first')
1718 follow = opts.get('follow') or opts.get('follow_first')
1709 if opts.get('rev'):
1719 if opts.get('rev'):
1710 revs = scmutil.revrange(repo, opts['rev'])
1720 revs = scmutil.revrange(repo, opts['rev'])
1711 elif follow:
1721 elif follow:
1712 revs = revset.baseset(repo.revs('reverse(:.)'))
1722 revs = revset.baseset(repo.revs('reverse(:.)'))
1713 else:
1723 else:
1714 revs = revset.spanset(repo)
1724 revs = revset.spanset(repo)
1715 revs.reverse()
1725 revs.reverse()
1716 if not revs:
1726 if not revs:
1717 return revset.baseset([]), None, None
1727 return revset.baseset([]), None, None
1718 expr, filematcher = _makelogrevset(repo, pats, opts, revs)
1728 expr, filematcher = _makelogrevset(repo, pats, opts, revs)
1719 if expr:
1729 if expr:
1720 # Revset matchers often operate faster on revisions in changelog
1730 # Revset matchers often operate faster on revisions in changelog
1721 # order, because most filters deal with the changelog.
1731 # order, because most filters deal with the changelog.
1722 if not opts.get('rev'):
1732 if not opts.get('rev'):
1723 revs.reverse()
1733 revs.reverse()
1724 matcher = revset.match(repo.ui, expr)
1734 matcher = revset.match(repo.ui, expr)
1725 # Revset matches can reorder revisions. "A or B" typically returns
1735 # Revset matches can reorder revisions. "A or B" typically returns
1726 # returns the revision matching A then the revision matching B. Sort
1736 # returns the revision matching A then the revision matching B. Sort
1727 # again to fix that.
1737 # again to fix that.
1728 revs = matcher(repo, revs)
1738 revs = matcher(repo, revs)
1729 if not opts.get('rev'):
1739 if not opts.get('rev'):
1730 revs.sort(reverse=True)
1740 revs.sort(reverse=True)
1731 if limit is not None:
1741 if limit is not None:
1732 count = 0
1742 count = 0
1733 limitedrevs = revset.baseset([])
1743 limitedrevs = revset.baseset([])
1734 it = iter(revs)
1744 it = iter(revs)
1735 while count < limit:
1745 while count < limit:
1736 try:
1746 try:
1737 limitedrevs.append(it.next())
1747 limitedrevs.append(it.next())
1738 except (StopIteration):
1748 except (StopIteration):
1739 break
1749 break
1740 count += 1
1750 count += 1
1741 revs = limitedrevs
1751 revs = limitedrevs
1742
1752
1743 return revs, expr, filematcher
1753 return revs, expr, filematcher
1744
1754
1745 def displaygraph(ui, dag, displayer, showparents, edgefn, getrenamed=None,
1755 def displaygraph(ui, dag, displayer, showparents, edgefn, getrenamed=None,
1746 filematcher=None):
1756 filematcher=None):
1747 seen, state = [], graphmod.asciistate()
1757 seen, state = [], graphmod.asciistate()
1748 for rev, type, ctx, parents in dag:
1758 for rev, type, ctx, parents in dag:
1749 char = 'o'
1759 char = 'o'
1750 if ctx.node() in showparents:
1760 if ctx.node() in showparents:
1751 char = '@'
1761 char = '@'
1752 elif ctx.obsolete():
1762 elif ctx.obsolete():
1753 char = 'x'
1763 char = 'x'
1754 copies = None
1764 copies = None
1755 if getrenamed and ctx.rev():
1765 if getrenamed and ctx.rev():
1756 copies = []
1766 copies = []
1757 for fn in ctx.files():
1767 for fn in ctx.files():
1758 rename = getrenamed(fn, ctx.rev())
1768 rename = getrenamed(fn, ctx.rev())
1759 if rename:
1769 if rename:
1760 copies.append((fn, rename[0]))
1770 copies.append((fn, rename[0]))
1761 revmatchfn = None
1771 revmatchfn = None
1762 if filematcher is not None:
1772 if filematcher is not None:
1763 revmatchfn = filematcher(ctx.rev())
1773 revmatchfn = filematcher(ctx.rev())
1764 displayer.show(ctx, copies=copies, matchfn=revmatchfn)
1774 displayer.show(ctx, copies=copies, matchfn=revmatchfn)
1765 lines = displayer.hunk.pop(rev).split('\n')
1775 lines = displayer.hunk.pop(rev).split('\n')
1766 if not lines[-1]:
1776 if not lines[-1]:
1767 del lines[-1]
1777 del lines[-1]
1768 displayer.flush(rev)
1778 displayer.flush(rev)
1769 edges = edgefn(type, char, lines, seen, rev, parents)
1779 edges = edgefn(type, char, lines, seen, rev, parents)
1770 for type, char, lines, coldata in edges:
1780 for type, char, lines, coldata in edges:
1771 graphmod.ascii(ui, state, type, char, lines, coldata)
1781 graphmod.ascii(ui, state, type, char, lines, coldata)
1772 displayer.close()
1782 displayer.close()
1773
1783
1774 def graphlog(ui, repo, *pats, **opts):
1784 def graphlog(ui, repo, *pats, **opts):
1775 # Parameters are identical to log command ones
1785 # Parameters are identical to log command ones
1776 revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
1786 revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
1777 revdag = graphmod.dagwalker(repo, revs)
1787 revdag = graphmod.dagwalker(repo, revs)
1778
1788
1779 getrenamed = None
1789 getrenamed = None
1780 if opts.get('copies'):
1790 if opts.get('copies'):
1781 endrev = None
1791 endrev = None
1782 if opts.get('rev'):
1792 if opts.get('rev'):
1783 endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1
1793 endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1
1784 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
1794 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
1785 displayer = show_changeset(ui, repo, opts, buffered=True)
1795 displayer = show_changeset(ui, repo, opts, buffered=True)
1786 showparents = [ctx.node() for ctx in repo[None].parents()]
1796 showparents = [ctx.node() for ctx in repo[None].parents()]
1787 displaygraph(ui, revdag, displayer, showparents,
1797 displaygraph(ui, revdag, displayer, showparents,
1788 graphmod.asciiedges, getrenamed, filematcher)
1798 graphmod.asciiedges, getrenamed, filematcher)
1789
1799
1790 def checkunsupportedgraphflags(pats, opts):
1800 def checkunsupportedgraphflags(pats, opts):
1791 for op in ["newest_first"]:
1801 for op in ["newest_first"]:
1792 if op in opts and opts[op]:
1802 if op in opts and opts[op]:
1793 raise util.Abort(_("-G/--graph option is incompatible with --%s")
1803 raise util.Abort(_("-G/--graph option is incompatible with --%s")
1794 % op.replace("_", "-"))
1804 % op.replace("_", "-"))
1795
1805
1796 def graphrevs(repo, nodes, opts):
1806 def graphrevs(repo, nodes, opts):
1797 limit = loglimit(opts)
1807 limit = loglimit(opts)
1798 nodes.reverse()
1808 nodes.reverse()
1799 if limit is not None:
1809 if limit is not None:
1800 nodes = nodes[:limit]
1810 nodes = nodes[:limit]
1801 return graphmod.nodes(repo, nodes)
1811 return graphmod.nodes(repo, nodes)
1802
1812
1803 def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly):
1813 def add(ui, repo, match, dryrun, listsubrepos, prefix, explicitonly):
1804 join = lambda f: os.path.join(prefix, f)
1814 join = lambda f: os.path.join(prefix, f)
1805 bad = []
1815 bad = []
1806 oldbad = match.bad
1816 oldbad = match.bad
1807 match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
1817 match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
1808 names = []
1818 names = []
1809 wctx = repo[None]
1819 wctx = repo[None]
1810 cca = None
1820 cca = None
1811 abort, warn = scmutil.checkportabilityalert(ui)
1821 abort, warn = scmutil.checkportabilityalert(ui)
1812 if abort or warn:
1822 if abort or warn:
1813 cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate)
1823 cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate)
1814 for f in repo.walk(match):
1824 for f in repo.walk(match):
1815 exact = match.exact(f)
1825 exact = match.exact(f)
1816 if exact or not explicitonly and f not in repo.dirstate:
1826 if exact or not explicitonly and f not in repo.dirstate:
1817 if cca:
1827 if cca:
1818 cca(f)
1828 cca(f)
1819 names.append(f)
1829 names.append(f)
1820 if ui.verbose or not exact:
1830 if ui.verbose or not exact:
1821 ui.status(_('adding %s\n') % match.rel(join(f)))
1831 ui.status(_('adding %s\n') % match.rel(join(f)))
1822
1832
1823 for subpath in sorted(wctx.substate):
1833 for subpath in sorted(wctx.substate):
1824 sub = wctx.sub(subpath)
1834 sub = wctx.sub(subpath)
1825 try:
1835 try:
1826 submatch = matchmod.narrowmatcher(subpath, match)
1836 submatch = matchmod.narrowmatcher(subpath, match)
1827 if listsubrepos:
1837 if listsubrepos:
1828 bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
1838 bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
1829 False))
1839 False))
1830 else:
1840 else:
1831 bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
1841 bad.extend(sub.add(ui, submatch, dryrun, listsubrepos, prefix,
1832 True))
1842 True))
1833 except error.LookupError:
1843 except error.LookupError:
1834 ui.status(_("skipping missing subrepository: %s\n")
1844 ui.status(_("skipping missing subrepository: %s\n")
1835 % join(subpath))
1845 % join(subpath))
1836
1846
1837 if not dryrun:
1847 if not dryrun:
1838 rejected = wctx.add(names, prefix)
1848 rejected = wctx.add(names, prefix)
1839 bad.extend(f for f in rejected if f in match.files())
1849 bad.extend(f for f in rejected if f in match.files())
1840 return bad
1850 return bad
1841
1851
1842 def forget(ui, repo, match, prefix, explicitonly):
1852 def forget(ui, repo, match, prefix, explicitonly):
1843 join = lambda f: os.path.join(prefix, f)
1853 join = lambda f: os.path.join(prefix, f)
1844 bad = []
1854 bad = []
1845 oldbad = match.bad
1855 oldbad = match.bad
1846 match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
1856 match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
1847 wctx = repo[None]
1857 wctx = repo[None]
1848 forgot = []
1858 forgot = []
1849 s = repo.status(match=match, clean=True)
1859 s = repo.status(match=match, clean=True)
1850 forget = sorted(s[0] + s[1] + s[3] + s[6])
1860 forget = sorted(s[0] + s[1] + s[3] + s[6])
1851 if explicitonly:
1861 if explicitonly:
1852 forget = [f for f in forget if match.exact(f)]
1862 forget = [f for f in forget if match.exact(f)]
1853
1863
1854 for subpath in sorted(wctx.substate):
1864 for subpath in sorted(wctx.substate):
1855 sub = wctx.sub(subpath)
1865 sub = wctx.sub(subpath)
1856 try:
1866 try:
1857 submatch = matchmod.narrowmatcher(subpath, match)
1867 submatch = matchmod.narrowmatcher(subpath, match)
1858 subbad, subforgot = sub.forget(ui, submatch, prefix)
1868 subbad, subforgot = sub.forget(ui, submatch, prefix)
1859 bad.extend([subpath + '/' + f for f in subbad])
1869 bad.extend([subpath + '/' + f for f in subbad])
1860 forgot.extend([subpath + '/' + f for f in subforgot])
1870 forgot.extend([subpath + '/' + f for f in subforgot])
1861 except error.LookupError:
1871 except error.LookupError:
1862 ui.status(_("skipping missing subrepository: %s\n")
1872 ui.status(_("skipping missing subrepository: %s\n")
1863 % join(subpath))
1873 % join(subpath))
1864
1874
1865 if not explicitonly:
1875 if not explicitonly:
1866 for f in match.files():
1876 for f in match.files():
1867 if f not in repo.dirstate and not os.path.isdir(match.rel(join(f))):
1877 if f not in repo.dirstate and not os.path.isdir(match.rel(join(f))):
1868 if f not in forgot:
1878 if f not in forgot:
1869 if os.path.exists(match.rel(join(f))):
1879 if os.path.exists(match.rel(join(f))):
1870 ui.warn(_('not removing %s: '
1880 ui.warn(_('not removing %s: '
1871 'file is already untracked\n')
1881 'file is already untracked\n')
1872 % match.rel(join(f)))
1882 % match.rel(join(f)))
1873 bad.append(f)
1883 bad.append(f)
1874
1884
1875 for f in forget:
1885 for f in forget:
1876 if ui.verbose or not match.exact(f):
1886 if ui.verbose or not match.exact(f):
1877 ui.status(_('removing %s\n') % match.rel(join(f)))
1887 ui.status(_('removing %s\n') % match.rel(join(f)))
1878
1888
1879 rejected = wctx.forget(forget, prefix)
1889 rejected = wctx.forget(forget, prefix)
1880 bad.extend(f for f in rejected if f in match.files())
1890 bad.extend(f for f in rejected if f in match.files())
1881 forgot.extend(forget)
1891 forgot.extend(forget)
1882 return bad, forgot
1892 return bad, forgot
1883
1893
1884 def cat(ui, repo, ctx, matcher, prefix, **opts):
1894 def cat(ui, repo, ctx, matcher, prefix, **opts):
1885 err = 1
1895 err = 1
1886
1896
1887 def write(path):
1897 def write(path):
1888 fp = makefileobj(repo, opts.get('output'), ctx.node(),
1898 fp = makefileobj(repo, opts.get('output'), ctx.node(),
1889 pathname=os.path.join(prefix, path))
1899 pathname=os.path.join(prefix, path))
1890 data = ctx[path].data()
1900 data = ctx[path].data()
1891 if opts.get('decode'):
1901 if opts.get('decode'):
1892 data = repo.wwritedata(path, data)
1902 data = repo.wwritedata(path, data)
1893 fp.write(data)
1903 fp.write(data)
1894 fp.close()
1904 fp.close()
1895
1905
1896 # Automation often uses hg cat on single files, so special case it
1906 # Automation often uses hg cat on single files, so special case it
1897 # for performance to avoid the cost of parsing the manifest.
1907 # for performance to avoid the cost of parsing the manifest.
1898 if len(matcher.files()) == 1 and not matcher.anypats():
1908 if len(matcher.files()) == 1 and not matcher.anypats():
1899 file = matcher.files()[0]
1909 file = matcher.files()[0]
1900 mf = repo.manifest
1910 mf = repo.manifest
1901 mfnode = ctx._changeset[0]
1911 mfnode = ctx._changeset[0]
1902 if mf.find(mfnode, file)[0]:
1912 if mf.find(mfnode, file)[0]:
1903 write(file)
1913 write(file)
1904 return 0
1914 return 0
1905
1915
1906 # Don't warn about "missing" files that are really in subrepos
1916 # Don't warn about "missing" files that are really in subrepos
1907 bad = matcher.bad
1917 bad = matcher.bad
1908
1918
1909 def badfn(path, msg):
1919 def badfn(path, msg):
1910 for subpath in ctx.substate:
1920 for subpath in ctx.substate:
1911 if path.startswith(subpath):
1921 if path.startswith(subpath):
1912 return
1922 return
1913 bad(path, msg)
1923 bad(path, msg)
1914
1924
1915 matcher.bad = badfn
1925 matcher.bad = badfn
1916
1926
1917 for abs in ctx.walk(matcher):
1927 for abs in ctx.walk(matcher):
1918 write(abs)
1928 write(abs)
1919 err = 0
1929 err = 0
1920
1930
1921 matcher.bad = bad
1931 matcher.bad = bad
1922
1932
1923 for subpath in sorted(ctx.substate):
1933 for subpath in sorted(ctx.substate):
1924 sub = ctx.sub(subpath)
1934 sub = ctx.sub(subpath)
1925 try:
1935 try:
1926 submatch = matchmod.narrowmatcher(subpath, matcher)
1936 submatch = matchmod.narrowmatcher(subpath, matcher)
1927
1937
1928 if not sub.cat(ui, submatch, os.path.join(prefix, sub._path),
1938 if not sub.cat(ui, submatch, os.path.join(prefix, sub._path),
1929 **opts):
1939 **opts):
1930 err = 0
1940 err = 0
1931 except error.RepoLookupError:
1941 except error.RepoLookupError:
1932 ui.status(_("skipping missing subrepository: %s\n")
1942 ui.status(_("skipping missing subrepository: %s\n")
1933 % os.path.join(prefix, subpath))
1943 % os.path.join(prefix, subpath))
1934
1944
1935 return err
1945 return err
1936
1946
1937 def duplicatecopies(repo, rev, fromrev):
1947 def duplicatecopies(repo, rev, fromrev):
1938 '''reproduce copies from fromrev to rev in the dirstate'''
1948 '''reproduce copies from fromrev to rev in the dirstate'''
1939 for dst, src in copies.pathcopies(repo[fromrev], repo[rev]).iteritems():
1949 for dst, src in copies.pathcopies(repo[fromrev], repo[rev]).iteritems():
1940 # copies.pathcopies returns backward renames, so dst might not
1950 # copies.pathcopies returns backward renames, so dst might not
1941 # actually be in the dirstate
1951 # actually be in the dirstate
1942 if repo.dirstate[dst] in "nma":
1952 if repo.dirstate[dst] in "nma":
1943 repo.dirstate.copy(src, dst)
1953 repo.dirstate.copy(src, dst)
1944
1954
1945 def commit(ui, repo, commitfunc, pats, opts):
1955 def commit(ui, repo, commitfunc, pats, opts):
1946 '''commit the specified files or all outstanding changes'''
1956 '''commit the specified files or all outstanding changes'''
1947 date = opts.get('date')
1957 date = opts.get('date')
1948 if date:
1958 if date:
1949 opts['date'] = util.parsedate(date)
1959 opts['date'] = util.parsedate(date)
1950 message = logmessage(ui, opts)
1960 message = logmessage(ui, opts)
1951
1961
1952 # extract addremove carefully -- this function can be called from a command
1962 # extract addremove carefully -- this function can be called from a command
1953 # that doesn't support addremove
1963 # that doesn't support addremove
1954 if opts.get('addremove'):
1964 if opts.get('addremove'):
1955 scmutil.addremove(repo, pats, opts)
1965 scmutil.addremove(repo, pats, opts)
1956
1966
1957 return commitfunc(ui, repo, message,
1967 return commitfunc(ui, repo, message,
1958 scmutil.match(repo[None], pats, opts), opts)
1968 scmutil.match(repo[None], pats, opts), opts)
1959
1969
1960 def amend(ui, repo, commitfunc, old, extra, pats, opts):
1970 def amend(ui, repo, commitfunc, old, extra, pats, opts):
1961 ui.note(_('amending changeset %s\n') % old)
1971 ui.note(_('amending changeset %s\n') % old)
1962 base = old.p1()
1972 base = old.p1()
1963
1973
1964 wlock = lock = newid = None
1974 wlock = lock = newid = None
1965 try:
1975 try:
1966 wlock = repo.wlock()
1976 wlock = repo.wlock()
1967 lock = repo.lock()
1977 lock = repo.lock()
1968 tr = repo.transaction('amend')
1978 tr = repo.transaction('amend')
1969 try:
1979 try:
1970 # See if we got a message from -m or -l, if not, open the editor
1980 # See if we got a message from -m or -l, if not, open the editor
1971 # with the message of the changeset to amend
1981 # with the message of the changeset to amend
1972 message = logmessage(ui, opts)
1982 message = logmessage(ui, opts)
1973 # ensure logfile does not conflict with later enforcement of the
1983 # ensure logfile does not conflict with later enforcement of the
1974 # message. potential logfile content has been processed by
1984 # message. potential logfile content has been processed by
1975 # `logmessage` anyway.
1985 # `logmessage` anyway.
1976 opts.pop('logfile')
1986 opts.pop('logfile')
1977 # First, do a regular commit to record all changes in the working
1987 # First, do a regular commit to record all changes in the working
1978 # directory (if there are any)
1988 # directory (if there are any)
1979 ui.callhooks = False
1989 ui.callhooks = False
1980 currentbookmark = repo._bookmarkcurrent
1990 currentbookmark = repo._bookmarkcurrent
1981 try:
1991 try:
1982 repo._bookmarkcurrent = None
1992 repo._bookmarkcurrent = None
1983 opts['message'] = 'temporary amend commit for %s' % old
1993 opts['message'] = 'temporary amend commit for %s' % old
1984 node = commit(ui, repo, commitfunc, pats, opts)
1994 node = commit(ui, repo, commitfunc, pats, opts)
1985 finally:
1995 finally:
1986 repo._bookmarkcurrent = currentbookmark
1996 repo._bookmarkcurrent = currentbookmark
1987 ui.callhooks = True
1997 ui.callhooks = True
1988 ctx = repo[node]
1998 ctx = repo[node]
1989
1999
1990 # Participating changesets:
2000 # Participating changesets:
1991 #
2001 #
1992 # node/ctx o - new (intermediate) commit that contains changes
2002 # node/ctx o - new (intermediate) commit that contains changes
1993 # | from working dir to go into amending commit
2003 # | from working dir to go into amending commit
1994 # | (or a workingctx if there were no changes)
2004 # | (or a workingctx if there were no changes)
1995 # |
2005 # |
1996 # old o - changeset to amend
2006 # old o - changeset to amend
1997 # |
2007 # |
1998 # base o - parent of amending changeset
2008 # base o - parent of amending changeset
1999
2009
2000 # Update extra dict from amended commit (e.g. to preserve graft
2010 # Update extra dict from amended commit (e.g. to preserve graft
2001 # source)
2011 # source)
2002 extra.update(old.extra())
2012 extra.update(old.extra())
2003
2013
2004 # Also update it from the intermediate commit or from the wctx
2014 # Also update it from the intermediate commit or from the wctx
2005 extra.update(ctx.extra())
2015 extra.update(ctx.extra())
2006
2016
2007 if len(old.parents()) > 1:
2017 if len(old.parents()) > 1:
2008 # ctx.files() isn't reliable for merges, so fall back to the
2018 # ctx.files() isn't reliable for merges, so fall back to the
2009 # slower repo.status() method
2019 # slower repo.status() method
2010 files = set([fn for st in repo.status(base, old)[:3]
2020 files = set([fn for st in repo.status(base, old)[:3]
2011 for fn in st])
2021 for fn in st])
2012 else:
2022 else:
2013 files = set(old.files())
2023 files = set(old.files())
2014
2024
2015 # Second, we use either the commit we just did, or if there were no
2025 # Second, we use either the commit we just did, or if there were no
2016 # changes the parent of the working directory as the version of the
2026 # changes the parent of the working directory as the version of the
2017 # files in the final amend commit
2027 # files in the final amend commit
2018 if node:
2028 if node:
2019 ui.note(_('copying changeset %s to %s\n') % (ctx, base))
2029 ui.note(_('copying changeset %s to %s\n') % (ctx, base))
2020
2030
2021 user = ctx.user()
2031 user = ctx.user()
2022 date = ctx.date()
2032 date = ctx.date()
2023 # Recompute copies (avoid recording a -> b -> a)
2033 # Recompute copies (avoid recording a -> b -> a)
2024 copied = copies.pathcopies(base, ctx)
2034 copied = copies.pathcopies(base, ctx)
2025
2035
2026 # Prune files which were reverted by the updates: if old
2036 # Prune files which were reverted by the updates: if old
2027 # introduced file X and our intermediate commit, node,
2037 # introduced file X and our intermediate commit, node,
2028 # renamed that file, then those two files are the same and
2038 # renamed that file, then those two files are the same and
2029 # we can discard X from our list of files. Likewise if X
2039 # we can discard X from our list of files. Likewise if X
2030 # was deleted, it's no longer relevant
2040 # was deleted, it's no longer relevant
2031 files.update(ctx.files())
2041 files.update(ctx.files())
2032
2042
2033 def samefile(f):
2043 def samefile(f):
2034 if f in ctx.manifest():
2044 if f in ctx.manifest():
2035 a = ctx.filectx(f)
2045 a = ctx.filectx(f)
2036 if f in base.manifest():
2046 if f in base.manifest():
2037 b = base.filectx(f)
2047 b = base.filectx(f)
2038 return (not a.cmp(b)
2048 return (not a.cmp(b)
2039 and a.flags() == b.flags())
2049 and a.flags() == b.flags())
2040 else:
2050 else:
2041 return False
2051 return False
2042 else:
2052 else:
2043 return f not in base.manifest()
2053 return f not in base.manifest()
2044 files = [f for f in files if not samefile(f)]
2054 files = [f for f in files if not samefile(f)]
2045
2055
2046 def filectxfn(repo, ctx_, path):
2056 def filectxfn(repo, ctx_, path):
2047 try:
2057 try:
2048 fctx = ctx[path]
2058 fctx = ctx[path]
2049 flags = fctx.flags()
2059 flags = fctx.flags()
2050 mctx = context.memfilectx(fctx.path(), fctx.data(),
2060 mctx = context.memfilectx(fctx.path(), fctx.data(),
2051 islink='l' in flags,
2061 islink='l' in flags,
2052 isexec='x' in flags,
2062 isexec='x' in flags,
2053 copied=copied.get(path))
2063 copied=copied.get(path))
2054 return mctx
2064 return mctx
2055 except KeyError:
2065 except KeyError:
2056 raise IOError
2066 raise IOError
2057 else:
2067 else:
2058 ui.note(_('copying changeset %s to %s\n') % (old, base))
2068 ui.note(_('copying changeset %s to %s\n') % (old, base))
2059
2069
2060 # Use version of files as in the old cset
2070 # Use version of files as in the old cset
2061 def filectxfn(repo, ctx_, path):
2071 def filectxfn(repo, ctx_, path):
2062 try:
2072 try:
2063 return old.filectx(path)
2073 return old.filectx(path)
2064 except KeyError:
2074 except KeyError:
2065 raise IOError
2075 raise IOError
2066
2076
2067 user = opts.get('user') or old.user()
2077 user = opts.get('user') or old.user()
2068 date = opts.get('date') or old.date()
2078 date = opts.get('date') or old.date()
2069 editor = getcommiteditor(**opts)
2079 editor = getcommiteditor(**opts)
2070 if not message:
2080 if not message:
2071 editor = getcommiteditor(edit=True)
2081 editor = getcommiteditor(edit=True)
2072 message = old.description()
2082 message = old.description()
2073
2083
2074 pureextra = extra.copy()
2084 pureextra = extra.copy()
2075 extra['amend_source'] = old.hex()
2085 extra['amend_source'] = old.hex()
2076
2086
2077 new = context.memctx(repo,
2087 new = context.memctx(repo,
2078 parents=[base.node(), old.p2().node()],
2088 parents=[base.node(), old.p2().node()],
2079 text=message,
2089 text=message,
2080 files=files,
2090 files=files,
2081 filectxfn=filectxfn,
2091 filectxfn=filectxfn,
2082 user=user,
2092 user=user,
2083 date=date,
2093 date=date,
2084 extra=extra,
2094 extra=extra,
2085 editor=editor)
2095 editor=editor)
2086
2096
2087 newdesc = changelog.stripdesc(new.description())
2097 newdesc = changelog.stripdesc(new.description())
2088 if ((not node)
2098 if ((not node)
2089 and newdesc == old.description()
2099 and newdesc == old.description()
2090 and user == old.user()
2100 and user == old.user()
2091 and date == old.date()
2101 and date == old.date()
2092 and pureextra == old.extra()):
2102 and pureextra == old.extra()):
2093 # nothing changed. continuing here would create a new node
2103 # nothing changed. continuing here would create a new node
2094 # anyway because of the amend_source noise.
2104 # anyway because of the amend_source noise.
2095 #
2105 #
2096 # This not what we expect from amend.
2106 # This not what we expect from amend.
2097 return old.node()
2107 return old.node()
2098
2108
2099 ph = repo.ui.config('phases', 'new-commit', phases.draft)
2109 ph = repo.ui.config('phases', 'new-commit', phases.draft)
2100 try:
2110 try:
2101 if opts.get('secret'):
2111 if opts.get('secret'):
2102 commitphase = 'secret'
2112 commitphase = 'secret'
2103 else:
2113 else:
2104 commitphase = old.phase()
2114 commitphase = old.phase()
2105 repo.ui.setconfig('phases', 'new-commit', commitphase, 'amend')
2115 repo.ui.setconfig('phases', 'new-commit', commitphase, 'amend')
2106 newid = repo.commitctx(new)
2116 newid = repo.commitctx(new)
2107 finally:
2117 finally:
2108 repo.ui.setconfig('phases', 'new-commit', ph, 'amend')
2118 repo.ui.setconfig('phases', 'new-commit', ph, 'amend')
2109 if newid != old.node():
2119 if newid != old.node():
2110 # Reroute the working copy parent to the new changeset
2120 # Reroute the working copy parent to the new changeset
2111 repo.setparents(newid, nullid)
2121 repo.setparents(newid, nullid)
2112
2122
2113 # Move bookmarks from old parent to amend commit
2123 # Move bookmarks from old parent to amend commit
2114 bms = repo.nodebookmarks(old.node())
2124 bms = repo.nodebookmarks(old.node())
2115 if bms:
2125 if bms:
2116 marks = repo._bookmarks
2126 marks = repo._bookmarks
2117 for bm in bms:
2127 for bm in bms:
2118 marks[bm] = newid
2128 marks[bm] = newid
2119 marks.write()
2129 marks.write()
2120 #commit the whole amend process
2130 #commit the whole amend process
2121 if obsolete._enabled and newid != old.node():
2131 if obsolete._enabled and newid != old.node():
2122 # mark the new changeset as successor of the rewritten one
2132 # mark the new changeset as successor of the rewritten one
2123 new = repo[newid]
2133 new = repo[newid]
2124 obs = [(old, (new,))]
2134 obs = [(old, (new,))]
2125 if node:
2135 if node:
2126 obs.append((ctx, ()))
2136 obs.append((ctx, ()))
2127
2137
2128 obsolete.createmarkers(repo, obs)
2138 obsolete.createmarkers(repo, obs)
2129 tr.close()
2139 tr.close()
2130 finally:
2140 finally:
2131 tr.release()
2141 tr.release()
2132 if (not obsolete._enabled) and newid != old.node():
2142 if (not obsolete._enabled) and newid != old.node():
2133 # Strip the intermediate commit (if there was one) and the amended
2143 # Strip the intermediate commit (if there was one) and the amended
2134 # commit
2144 # commit
2135 if node:
2145 if node:
2136 ui.note(_('stripping intermediate changeset %s\n') % ctx)
2146 ui.note(_('stripping intermediate changeset %s\n') % ctx)
2137 ui.note(_('stripping amended changeset %s\n') % old)
2147 ui.note(_('stripping amended changeset %s\n') % old)
2138 repair.strip(ui, repo, old.node(), topic='amend-backup')
2148 repair.strip(ui, repo, old.node(), topic='amend-backup')
2139 finally:
2149 finally:
2140 if newid is None:
2150 if newid is None:
2141 repo.dirstate.invalidate()
2151 repo.dirstate.invalidate()
2142 lockmod.release(lock, wlock)
2152 lockmod.release(lock, wlock)
2143 return newid
2153 return newid
2144
2154
2145 def commiteditor(repo, ctx, subs):
2155 def commiteditor(repo, ctx, subs):
2146 if ctx.description():
2156 if ctx.description():
2147 return ctx.description()
2157 return ctx.description()
2148 return commitforceeditor(repo, ctx, subs)
2158 return commitforceeditor(repo, ctx, subs)
2149
2159
2150 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
2160 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
2151 edittext = []
2161 edittext = []
2152 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
2162 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
2153 if ctx.description():
2163 if ctx.description():
2154 edittext.append(ctx.description())
2164 edittext.append(ctx.description())
2155 edittext.append("")
2165 edittext.append("")
2156 edittext.append("") # Empty line between message and comments.
2166 edittext.append("") # Empty line between message and comments.
2157 edittext.append(_("HG: Enter commit message."
2167 edittext.append(_("HG: Enter commit message."
2158 " Lines beginning with 'HG:' are removed."))
2168 " Lines beginning with 'HG:' are removed."))
2159 if extramsg:
2169 if extramsg:
2160 edittext.append("HG: %s" % extramsg)
2170 edittext.append("HG: %s" % extramsg)
2161 else:
2171 else:
2162 edittext.append(_("HG: Leave message empty to abort commit."))
2172 edittext.append(_("HG: Leave message empty to abort commit."))
2163 edittext.append("HG: --")
2173 edittext.append("HG: --")
2164 edittext.append(_("HG: user: %s") % ctx.user())
2174 edittext.append(_("HG: user: %s") % ctx.user())
2165 if ctx.p2():
2175 if ctx.p2():
2166 edittext.append(_("HG: branch merge"))
2176 edittext.append(_("HG: branch merge"))
2167 if ctx.branch():
2177 if ctx.branch():
2168 edittext.append(_("HG: branch '%s'") % ctx.branch())
2178 edittext.append(_("HG: branch '%s'") % ctx.branch())
2169 if bookmarks.iscurrent(repo):
2179 if bookmarks.iscurrent(repo):
2170 edittext.append(_("HG: bookmark '%s'") % repo._bookmarkcurrent)
2180 edittext.append(_("HG: bookmark '%s'") % repo._bookmarkcurrent)
2171 edittext.extend([_("HG: subrepo %s") % s for s in subs])
2181 edittext.extend([_("HG: subrepo %s") % s for s in subs])
2172 edittext.extend([_("HG: added %s") % f for f in added])
2182 edittext.extend([_("HG: added %s") % f for f in added])
2173 edittext.extend([_("HG: changed %s") % f for f in modified])
2183 edittext.extend([_("HG: changed %s") % f for f in modified])
2174 edittext.extend([_("HG: removed %s") % f for f in removed])
2184 edittext.extend([_("HG: removed %s") % f for f in removed])
2175 if not added and not modified and not removed:
2185 if not added and not modified and not removed:
2176 edittext.append(_("HG: no files changed"))
2186 edittext.append(_("HG: no files changed"))
2177 edittext.append("")
2187 edittext.append("")
2178 # run editor in the repository root
2188 # run editor in the repository root
2179 olddir = os.getcwd()
2189 olddir = os.getcwd()
2180 os.chdir(repo.root)
2190 os.chdir(repo.root)
2181 text = repo.ui.edit("\n".join(edittext), ctx.user(), ctx.extra())
2191 text = repo.ui.edit("\n".join(edittext), ctx.user(), ctx.extra())
2182 text = re.sub("(?m)^HG:.*(\n|$)", "", text)
2192 text = re.sub("(?m)^HG:.*(\n|$)", "", text)
2183 os.chdir(olddir)
2193 os.chdir(olddir)
2184
2194
2185 if finishdesc:
2195 if finishdesc:
2186 text = finishdesc(text)
2196 text = finishdesc(text)
2187 if not text.strip():
2197 if not text.strip():
2188 raise util.Abort(_("empty commit message"))
2198 raise util.Abort(_("empty commit message"))
2189
2199
2190 return text
2200 return text
2191
2201
2192 def commitstatus(repo, node, branch, bheads=None, opts={}):
2202 def commitstatus(repo, node, branch, bheads=None, opts={}):
2193 ctx = repo[node]
2203 ctx = repo[node]
2194 parents = ctx.parents()
2204 parents = ctx.parents()
2195
2205
2196 if (not opts.get('amend') and bheads and node not in bheads and not
2206 if (not opts.get('amend') and bheads and node not in bheads and not
2197 [x for x in parents if x.node() in bheads and x.branch() == branch]):
2207 [x for x in parents if x.node() in bheads and x.branch() == branch]):
2198 repo.ui.status(_('created new head\n'))
2208 repo.ui.status(_('created new head\n'))
2199 # The message is not printed for initial roots. For the other
2209 # The message is not printed for initial roots. For the other
2200 # changesets, it is printed in the following situations:
2210 # changesets, it is printed in the following situations:
2201 #
2211 #
2202 # Par column: for the 2 parents with ...
2212 # Par column: for the 2 parents with ...
2203 # N: null or no parent
2213 # N: null or no parent
2204 # B: parent is on another named branch
2214 # B: parent is on another named branch
2205 # C: parent is a regular non head changeset
2215 # C: parent is a regular non head changeset
2206 # H: parent was a branch head of the current branch
2216 # H: parent was a branch head of the current branch
2207 # Msg column: whether we print "created new head" message
2217 # Msg column: whether we print "created new head" message
2208 # In the following, it is assumed that there already exists some
2218 # In the following, it is assumed that there already exists some
2209 # initial branch heads of the current branch, otherwise nothing is
2219 # initial branch heads of the current branch, otherwise nothing is
2210 # printed anyway.
2220 # printed anyway.
2211 #
2221 #
2212 # Par Msg Comment
2222 # Par Msg Comment
2213 # N N y additional topo root
2223 # N N y additional topo root
2214 #
2224 #
2215 # B N y additional branch root
2225 # B N y additional branch root
2216 # C N y additional topo head
2226 # C N y additional topo head
2217 # H N n usual case
2227 # H N n usual case
2218 #
2228 #
2219 # B B y weird additional branch root
2229 # B B y weird additional branch root
2220 # C B y branch merge
2230 # C B y branch merge
2221 # H B n merge with named branch
2231 # H B n merge with named branch
2222 #
2232 #
2223 # C C y additional head from merge
2233 # C C y additional head from merge
2224 # C H n merge with a head
2234 # C H n merge with a head
2225 #
2235 #
2226 # H H n head merge: head count decreases
2236 # H H n head merge: head count decreases
2227
2237
2228 if not opts.get('close_branch'):
2238 if not opts.get('close_branch'):
2229 for r in parents:
2239 for r in parents:
2230 if r.closesbranch() and r.branch() == branch:
2240 if r.closesbranch() and r.branch() == branch:
2231 repo.ui.status(_('reopening closed branch head %d\n') % r)
2241 repo.ui.status(_('reopening closed branch head %d\n') % r)
2232
2242
2233 if repo.ui.debugflag:
2243 if repo.ui.debugflag:
2234 repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex()))
2244 repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex()))
2235 elif repo.ui.verbose:
2245 elif repo.ui.verbose:
2236 repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx))
2246 repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx))
2237
2247
2238 def revert(ui, repo, ctx, parents, *pats, **opts):
2248 def revert(ui, repo, ctx, parents, *pats, **opts):
2239 parent, p2 = parents
2249 parent, p2 = parents
2240 node = ctx.node()
2250 node = ctx.node()
2241
2251
2242 mf = ctx.manifest()
2252 mf = ctx.manifest()
2243 if node == parent:
2253 if node == parent:
2244 pmf = mf
2254 pmf = mf
2245 else:
2255 else:
2246 pmf = None
2256 pmf = None
2247
2257
2248 # need all matching names in dirstate and manifest of target rev,
2258 # need all matching names in dirstate and manifest of target rev,
2249 # so have to walk both. do not print errors if files exist in one
2259 # so have to walk both. do not print errors if files exist in one
2250 # but not other.
2260 # but not other.
2251
2261
2252 names = {}
2262 names = {}
2253
2263
2254 wlock = repo.wlock()
2264 wlock = repo.wlock()
2255 try:
2265 try:
2256 # walk dirstate.
2266 # walk dirstate.
2257
2267
2258 m = scmutil.match(repo[None], pats, opts)
2268 m = scmutil.match(repo[None], pats, opts)
2259 m.bad = lambda x, y: False
2269 m.bad = lambda x, y: False
2260 for abs in repo.walk(m):
2270 for abs in repo.walk(m):
2261 names[abs] = m.rel(abs), m.exact(abs)
2271 names[abs] = m.rel(abs), m.exact(abs)
2262
2272
2263 # walk target manifest.
2273 # walk target manifest.
2264
2274
2265 def badfn(path, msg):
2275 def badfn(path, msg):
2266 if path in names:
2276 if path in names:
2267 return
2277 return
2268 if path in ctx.substate:
2278 if path in ctx.substate:
2269 return
2279 return
2270 path_ = path + '/'
2280 path_ = path + '/'
2271 for f in names:
2281 for f in names:
2272 if f.startswith(path_):
2282 if f.startswith(path_):
2273 return
2283 return
2274 ui.warn("%s: %s\n" % (m.rel(path), msg))
2284 ui.warn("%s: %s\n" % (m.rel(path), msg))
2275
2285
2276 m = scmutil.match(ctx, pats, opts)
2286 m = scmutil.match(ctx, pats, opts)
2277 m.bad = badfn
2287 m.bad = badfn
2278 for abs in ctx.walk(m):
2288 for abs in ctx.walk(m):
2279 if abs not in names:
2289 if abs not in names:
2280 names[abs] = m.rel(abs), m.exact(abs)
2290 names[abs] = m.rel(abs), m.exact(abs)
2281
2291
2282 # get the list of subrepos that must be reverted
2292 # get the list of subrepos that must be reverted
2283 targetsubs = sorted(s for s in ctx.substate if m(s))
2293 targetsubs = sorted(s for s in ctx.substate if m(s))
2284 m = scmutil.matchfiles(repo, names)
2294 m = scmutil.matchfiles(repo, names)
2285 changes = repo.status(match=m)[:4]
2295 changes = repo.status(match=m)[:4]
2286 modified, added, removed, deleted = map(set, changes)
2296 modified, added, removed, deleted = map(set, changes)
2287
2297
2288 # if f is a rename, also revert the source
2298 # if f is a rename, also revert the source
2289 cwd = repo.getcwd()
2299 cwd = repo.getcwd()
2290 for f in added:
2300 for f in added:
2291 src = repo.dirstate.copied(f)
2301 src = repo.dirstate.copied(f)
2292 if src and src not in names and repo.dirstate[src] == 'r':
2302 if src and src not in names and repo.dirstate[src] == 'r':
2293 removed.add(src)
2303 removed.add(src)
2294 names[src] = (repo.pathto(src, cwd), True)
2304 names[src] = (repo.pathto(src, cwd), True)
2295
2305
2296 def removeforget(abs):
2306 def removeforget(abs):
2297 if repo.dirstate[abs] == 'a':
2307 if repo.dirstate[abs] == 'a':
2298 return _('forgetting %s\n')
2308 return _('forgetting %s\n')
2299 return _('removing %s\n')
2309 return _('removing %s\n')
2300
2310
2301 revert = ([], _('reverting %s\n'))
2311 revert = ([], _('reverting %s\n'))
2302 add = ([], _('adding %s\n'))
2312 add = ([], _('adding %s\n'))
2303 remove = ([], removeforget)
2313 remove = ([], removeforget)
2304 undelete = ([], _('undeleting %s\n'))
2314 undelete = ([], _('undeleting %s\n'))
2305
2315
2306 disptable = (
2316 disptable = (
2307 # dispatch table:
2317 # dispatch table:
2308 # file state
2318 # file state
2309 # action if in target manifest
2319 # action if in target manifest
2310 # action if not in target manifest
2320 # action if not in target manifest
2311 # make backup if in target manifest
2321 # make backup if in target manifest
2312 # make backup if not in target manifest
2322 # make backup if not in target manifest
2313 (modified, revert, remove, True, True),
2323 (modified, revert, remove, True, True),
2314 (added, revert, remove, True, False),
2324 (added, revert, remove, True, False),
2315 (removed, undelete, None, True, False),
2325 (removed, undelete, None, True, False),
2316 (deleted, revert, remove, False, False),
2326 (deleted, revert, remove, False, False),
2317 )
2327 )
2318
2328
2319 for abs, (rel, exact) in sorted(names.items()):
2329 for abs, (rel, exact) in sorted(names.items()):
2320 mfentry = mf.get(abs)
2330 mfentry = mf.get(abs)
2321 target = repo.wjoin(abs)
2331 target = repo.wjoin(abs)
2322 def handle(xlist, dobackup):
2332 def handle(xlist, dobackup):
2323 xlist[0].append(abs)
2333 xlist[0].append(abs)
2324 if (dobackup and not opts.get('no_backup') and
2334 if (dobackup and not opts.get('no_backup') and
2325 os.path.lexists(target) and
2335 os.path.lexists(target) and
2326 abs in ctx and repo[None][abs].cmp(ctx[abs])):
2336 abs in ctx and repo[None][abs].cmp(ctx[abs])):
2327 bakname = "%s.orig" % rel
2337 bakname = "%s.orig" % rel
2328 ui.note(_('saving current version of %s as %s\n') %
2338 ui.note(_('saving current version of %s as %s\n') %
2329 (rel, bakname))
2339 (rel, bakname))
2330 if not opts.get('dry_run'):
2340 if not opts.get('dry_run'):
2331 util.rename(target, bakname)
2341 util.rename(target, bakname)
2332 if ui.verbose or not exact:
2342 if ui.verbose or not exact:
2333 msg = xlist[1]
2343 msg = xlist[1]
2334 if not isinstance(msg, basestring):
2344 if not isinstance(msg, basestring):
2335 msg = msg(abs)
2345 msg = msg(abs)
2336 ui.status(msg % rel)
2346 ui.status(msg % rel)
2337 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2347 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2338 if abs not in table:
2348 if abs not in table:
2339 continue
2349 continue
2340 # file has changed in dirstate
2350 # file has changed in dirstate
2341 if mfentry:
2351 if mfentry:
2342 handle(hitlist, backuphit)
2352 handle(hitlist, backuphit)
2343 elif misslist is not None:
2353 elif misslist is not None:
2344 handle(misslist, backupmiss)
2354 handle(misslist, backupmiss)
2345 break
2355 break
2346 else:
2356 else:
2347 if abs not in repo.dirstate:
2357 if abs not in repo.dirstate:
2348 if mfentry:
2358 if mfentry:
2349 handle(add, True)
2359 handle(add, True)
2350 elif exact:
2360 elif exact:
2351 ui.warn(_('file not managed: %s\n') % rel)
2361 ui.warn(_('file not managed: %s\n') % rel)
2352 continue
2362 continue
2353 # file has not changed in dirstate
2363 # file has not changed in dirstate
2354 if node == parent:
2364 if node == parent:
2355 if exact:
2365 if exact:
2356 ui.warn(_('no changes needed to %s\n') % rel)
2366 ui.warn(_('no changes needed to %s\n') % rel)
2357 continue
2367 continue
2358 if pmf is None:
2368 if pmf is None:
2359 # only need parent manifest in this unlikely case,
2369 # only need parent manifest in this unlikely case,
2360 # so do not read by default
2370 # so do not read by default
2361 pmf = repo[parent].manifest()
2371 pmf = repo[parent].manifest()
2362 if abs in pmf and mfentry:
2372 if abs in pmf and mfentry:
2363 # if version of file is same in parent and target
2373 # if version of file is same in parent and target
2364 # manifests, do nothing
2374 # manifests, do nothing
2365 if (pmf[abs] != mfentry or
2375 if (pmf[abs] != mfentry or
2366 pmf.flags(abs) != mf.flags(abs)):
2376 pmf.flags(abs) != mf.flags(abs)):
2367 handle(revert, False)
2377 handle(revert, False)
2368 else:
2378 else:
2369 handle(remove, False)
2379 handle(remove, False)
2370 if not opts.get('dry_run'):
2380 if not opts.get('dry_run'):
2371 _performrevert(repo, parents, ctx, revert, add, remove, undelete)
2381 _performrevert(repo, parents, ctx, revert, add, remove, undelete)
2372
2382
2373 if targetsubs:
2383 if targetsubs:
2374 # Revert the subrepos on the revert list
2384 # Revert the subrepos on the revert list
2375 for sub in targetsubs:
2385 for sub in targetsubs:
2376 ctx.sub(sub).revert(ui, ctx.substate[sub], *pats, **opts)
2386 ctx.sub(sub).revert(ui, ctx.substate[sub], *pats, **opts)
2377 finally:
2387 finally:
2378 wlock.release()
2388 wlock.release()
2379
2389
2380 def _performrevert(repo, parents, ctx, revert, add, remove, undelete):
2390 def _performrevert(repo, parents, ctx, revert, add, remove, undelete):
2381 """function that actually perform all the action computed for revert
2391 """function that actually perform all the action computed for revert
2382
2392
2383 This is an independent function to let extension to plug in and react to
2393 This is an independent function to let extension to plug in and react to
2384 the imminent revert.
2394 the imminent revert.
2385
2395
2386 Make sure you have the working directory locked when calling this function.
2396 Make sure you have the working directory locked when calling this function.
2387 """
2397 """
2388 parent, p2 = parents
2398 parent, p2 = parents
2389 node = ctx.node()
2399 node = ctx.node()
2390 def checkout(f):
2400 def checkout(f):
2391 fc = ctx[f]
2401 fc = ctx[f]
2392 repo.wwrite(f, fc.data(), fc.flags())
2402 repo.wwrite(f, fc.data(), fc.flags())
2393
2403
2394 audit_path = pathutil.pathauditor(repo.root)
2404 audit_path = pathutil.pathauditor(repo.root)
2395 for f in remove[0]:
2405 for f in remove[0]:
2396 if repo.dirstate[f] == 'a':
2406 if repo.dirstate[f] == 'a':
2397 repo.dirstate.drop(f)
2407 repo.dirstate.drop(f)
2398 continue
2408 continue
2399 audit_path(f)
2409 audit_path(f)
2400 try:
2410 try:
2401 util.unlinkpath(repo.wjoin(f))
2411 util.unlinkpath(repo.wjoin(f))
2402 except OSError:
2412 except OSError:
2403 pass
2413 pass
2404 repo.dirstate.remove(f)
2414 repo.dirstate.remove(f)
2405
2415
2406 normal = None
2416 normal = None
2407 if node == parent:
2417 if node == parent:
2408 # We're reverting to our parent. If possible, we'd like status
2418 # We're reverting to our parent. If possible, we'd like status
2409 # to report the file as clean. We have to use normallookup for
2419 # to report the file as clean. We have to use normallookup for
2410 # merges to avoid losing information about merged/dirty files.
2420 # merges to avoid losing information about merged/dirty files.
2411 if p2 != nullid:
2421 if p2 != nullid:
2412 normal = repo.dirstate.normallookup
2422 normal = repo.dirstate.normallookup
2413 else:
2423 else:
2414 normal = repo.dirstate.normal
2424 normal = repo.dirstate.normal
2415 for f in revert[0]:
2425 for f in revert[0]:
2416 checkout(f)
2426 checkout(f)
2417 if normal:
2427 if normal:
2418 normal(f)
2428 normal(f)
2419
2429
2420 for f in add[0]:
2430 for f in add[0]:
2421 checkout(f)
2431 checkout(f)
2422 repo.dirstate.add(f)
2432 repo.dirstate.add(f)
2423
2433
2424 normal = repo.dirstate.normallookup
2434 normal = repo.dirstate.normallookup
2425 if node == parent and p2 == nullid:
2435 if node == parent and p2 == nullid:
2426 normal = repo.dirstate.normal
2436 normal = repo.dirstate.normal
2427 for f in undelete[0]:
2437 for f in undelete[0]:
2428 checkout(f)
2438 checkout(f)
2429 normal(f)
2439 normal(f)
2430
2440
2431 copied = copies.pathcopies(repo[parent], ctx)
2441 copied = copies.pathcopies(repo[parent], ctx)
2432
2442
2433 for f in add[0] + undelete[0] + revert[0]:
2443 for f in add[0] + undelete[0] + revert[0]:
2434 if f in copied:
2444 if f in copied:
2435 repo.dirstate.copy(copied[f], f)
2445 repo.dirstate.copy(copied[f], f)
2436
2446
2437 def command(table):
2447 def command(table):
2438 '''returns a function object bound to table which can be used as
2448 '''returns a function object bound to table which can be used as
2439 a decorator for populating table as a command table'''
2449 a decorator for populating table as a command table'''
2440
2450
2441 def cmd(name, options=(), synopsis=None):
2451 def cmd(name, options=(), synopsis=None):
2442 def decorator(func):
2452 def decorator(func):
2443 if synopsis:
2453 if synopsis:
2444 table[name] = func, list(options), synopsis
2454 table[name] = func, list(options), synopsis
2445 else:
2455 else:
2446 table[name] = func, list(options)
2456 table[name] = func, list(options)
2447 return func
2457 return func
2448 return decorator
2458 return decorator
2449
2459
2450 return cmd
2460 return cmd
2451
2461
2452 # a list of (ui, repo, otherpeer, opts, missing) functions called by
2462 # a list of (ui, repo, otherpeer, opts, missing) functions called by
2453 # commands.outgoing. "missing" is "missing" of the result of
2463 # commands.outgoing. "missing" is "missing" of the result of
2454 # "findcommonoutgoing()"
2464 # "findcommonoutgoing()"
2455 outgoinghooks = util.hooks()
2465 outgoinghooks = util.hooks()
2456
2466
2457 # a list of (ui, repo) functions called by commands.summary
2467 # a list of (ui, repo) functions called by commands.summary
2458 summaryhooks = util.hooks()
2468 summaryhooks = util.hooks()
2459
2469
2460 # a list of (ui, repo, opts, changes) functions called by commands.summary.
2470 # a list of (ui, repo, opts, changes) functions called by commands.summary.
2461 #
2471 #
2462 # functions should return tuple of booleans below, if 'changes' is None:
2472 # functions should return tuple of booleans below, if 'changes' is None:
2463 # (whether-incomings-are-needed, whether-outgoings-are-needed)
2473 # (whether-incomings-are-needed, whether-outgoings-are-needed)
2464 #
2474 #
2465 # otherwise, 'changes' is a tuple of tuples below:
2475 # otherwise, 'changes' is a tuple of tuples below:
2466 # - (sourceurl, sourcebranch, sourcepeer, incoming)
2476 # - (sourceurl, sourcebranch, sourcepeer, incoming)
2467 # - (desturl, destbranch, destpeer, outgoing)
2477 # - (desturl, destbranch, destpeer, outgoing)
2468 summaryremotehooks = util.hooks()
2478 summaryremotehooks = util.hooks()
2469
2479
2470 # A list of state files kept by multistep operations like graft.
2480 # A list of state files kept by multistep operations like graft.
2471 # Since graft cannot be aborted, it is considered 'clearable' by update.
2481 # Since graft cannot be aborted, it is considered 'clearable' by update.
2472 # note: bisect is intentionally excluded
2482 # note: bisect is intentionally excluded
2473 # (state file, clearable, allowcommit, error, hint)
2483 # (state file, clearable, allowcommit, error, hint)
2474 unfinishedstates = [
2484 unfinishedstates = [
2475 ('graftstate', True, False, _('graft in progress'),
2485 ('graftstate', True, False, _('graft in progress'),
2476 _("use 'hg graft --continue' or 'hg update' to abort")),
2486 _("use 'hg graft --continue' or 'hg update' to abort")),
2477 ('updatestate', True, False, _('last update was interrupted'),
2487 ('updatestate', True, False, _('last update was interrupted'),
2478 _("use 'hg update' to get a consistent checkout"))
2488 _("use 'hg update' to get a consistent checkout"))
2479 ]
2489 ]
2480
2490
2481 def checkunfinished(repo, commit=False):
2491 def checkunfinished(repo, commit=False):
2482 '''Look for an unfinished multistep operation, like graft, and abort
2492 '''Look for an unfinished multistep operation, like graft, and abort
2483 if found. It's probably good to check this right before
2493 if found. It's probably good to check this right before
2484 bailifchanged().
2494 bailifchanged().
2485 '''
2495 '''
2486 for f, clearable, allowcommit, msg, hint in unfinishedstates:
2496 for f, clearable, allowcommit, msg, hint in unfinishedstates:
2487 if commit and allowcommit:
2497 if commit and allowcommit:
2488 continue
2498 continue
2489 if repo.vfs.exists(f):
2499 if repo.vfs.exists(f):
2490 raise util.Abort(msg, hint=hint)
2500 raise util.Abort(msg, hint=hint)
2491
2501
2492 def clearunfinished(repo):
2502 def clearunfinished(repo):
2493 '''Check for unfinished operations (as above), and clear the ones
2503 '''Check for unfinished operations (as above), and clear the ones
2494 that are clearable.
2504 that are clearable.
2495 '''
2505 '''
2496 for f, clearable, allowcommit, msg, hint in unfinishedstates:
2506 for f, clearable, allowcommit, msg, hint in unfinishedstates:
2497 if not clearable and repo.vfs.exists(f):
2507 if not clearable and repo.vfs.exists(f):
2498 raise util.Abort(msg, hint=hint)
2508 raise util.Abort(msg, hint=hint)
2499 for f, clearable, allowcommit, msg, hint in unfinishedstates:
2509 for f, clearable, allowcommit, msg, hint in unfinishedstates:
2500 if clearable and repo.vfs.exists(f):
2510 if clearable and repo.vfs.exists(f):
2501 util.unlink(repo.join(f))
2511 util.unlink(repo.join(f))
@@ -1,5944 +1,5965 b''
1 # commands.py - command processing for mercurial
1 # commands.py - command processing for mercurial
2 #
2 #
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from node import hex, bin, nullid, nullrev, short
8 from node import hex, bin, nullid, nullrev, short
9 from lock import release
9 from lock import release
10 from i18n import _
10 from i18n import _
11 import os, re, difflib, time, tempfile, errno
11 import os, re, difflib, time, tempfile, errno
12 import sys
12 import sys
13 import hg, scmutil, util, revlog, copies, error, bookmarks
13 import hg, scmutil, util, revlog, copies, error, bookmarks
14 import patch, help, encoding, templatekw, discovery
14 import patch, help, encoding, templatekw, discovery
15 import archival, changegroup, cmdutil, hbisect
15 import archival, changegroup, cmdutil, hbisect
16 import sshserver, hgweb, commandserver
16 import sshserver, hgweb, commandserver
17 from hgweb import server as hgweb_server
17 from hgweb import server as hgweb_server
18 import merge as mergemod
18 import merge as mergemod
19 import minirst, revset, fileset
19 import minirst, revset, fileset
20 import dagparser, context, simplemerge, graphmod
20 import dagparser, context, simplemerge, graphmod
21 import random
21 import random
22 import setdiscovery, treediscovery, dagutil, pvec, localrepo
22 import setdiscovery, treediscovery, dagutil, pvec, localrepo
23 import phases, obsolete, exchange
23 import phases, obsolete, exchange
24
24
25 table = {}
25 table = {}
26
26
27 command = cmdutil.command(table)
27 command = cmdutil.command(table)
28
28
29 # common command options
29 # common command options
30
30
31 globalopts = [
31 globalopts = [
32 ('R', 'repository', '',
32 ('R', 'repository', '',
33 _('repository root directory or name of overlay bundle file'),
33 _('repository root directory or name of overlay bundle file'),
34 _('REPO')),
34 _('REPO')),
35 ('', 'cwd', '',
35 ('', 'cwd', '',
36 _('change working directory'), _('DIR')),
36 _('change working directory'), _('DIR')),
37 ('y', 'noninteractive', None,
37 ('y', 'noninteractive', None,
38 _('do not prompt, automatically pick the first choice for all prompts')),
38 _('do not prompt, automatically pick the first choice for all prompts')),
39 ('q', 'quiet', None, _('suppress output')),
39 ('q', 'quiet', None, _('suppress output')),
40 ('v', 'verbose', None, _('enable additional output')),
40 ('v', 'verbose', None, _('enable additional output')),
41 ('', 'config', [],
41 ('', 'config', [],
42 _('set/override config option (use \'section.name=value\')'),
42 _('set/override config option (use \'section.name=value\')'),
43 _('CONFIG')),
43 _('CONFIG')),
44 ('', 'debug', None, _('enable debugging output')),
44 ('', 'debug', None, _('enable debugging output')),
45 ('', 'debugger', None, _('start debugger')),
45 ('', 'debugger', None, _('start debugger')),
46 ('', 'encoding', encoding.encoding, _('set the charset encoding'),
46 ('', 'encoding', encoding.encoding, _('set the charset encoding'),
47 _('ENCODE')),
47 _('ENCODE')),
48 ('', 'encodingmode', encoding.encodingmode,
48 ('', 'encodingmode', encoding.encodingmode,
49 _('set the charset encoding mode'), _('MODE')),
49 _('set the charset encoding mode'), _('MODE')),
50 ('', 'traceback', None, _('always print a traceback on exception')),
50 ('', 'traceback', None, _('always print a traceback on exception')),
51 ('', 'time', None, _('time how long the command takes')),
51 ('', 'time', None, _('time how long the command takes')),
52 ('', 'profile', None, _('print command execution profile')),
52 ('', 'profile', None, _('print command execution profile')),
53 ('', 'version', None, _('output version information and exit')),
53 ('', 'version', None, _('output version information and exit')),
54 ('h', 'help', None, _('display help and exit')),
54 ('h', 'help', None, _('display help and exit')),
55 ('', 'hidden', False, _('consider hidden changesets')),
55 ('', 'hidden', False, _('consider hidden changesets')),
56 ]
56 ]
57
57
58 dryrunopts = [('n', 'dry-run', None,
58 dryrunopts = [('n', 'dry-run', None,
59 _('do not perform actions, just print output'))]
59 _('do not perform actions, just print output'))]
60
60
61 remoteopts = [
61 remoteopts = [
62 ('e', 'ssh', '',
62 ('e', 'ssh', '',
63 _('specify ssh command to use'), _('CMD')),
63 _('specify ssh command to use'), _('CMD')),
64 ('', 'remotecmd', '',
64 ('', 'remotecmd', '',
65 _('specify hg command to run on the remote side'), _('CMD')),
65 _('specify hg command to run on the remote side'), _('CMD')),
66 ('', 'insecure', None,
66 ('', 'insecure', None,
67 _('do not verify server certificate (ignoring web.cacerts config)')),
67 _('do not verify server certificate (ignoring web.cacerts config)')),
68 ]
68 ]
69
69
70 walkopts = [
70 walkopts = [
71 ('I', 'include', [],
71 ('I', 'include', [],
72 _('include names matching the given patterns'), _('PATTERN')),
72 _('include names matching the given patterns'), _('PATTERN')),
73 ('X', 'exclude', [],
73 ('X', 'exclude', [],
74 _('exclude names matching the given patterns'), _('PATTERN')),
74 _('exclude names matching the given patterns'), _('PATTERN')),
75 ]
75 ]
76
76
77 commitopts = [
77 commitopts = [
78 ('m', 'message', '',
78 ('m', 'message', '',
79 _('use text as commit message'), _('TEXT')),
79 _('use text as commit message'), _('TEXT')),
80 ('l', 'logfile', '',
80 ('l', 'logfile', '',
81 _('read commit message from file'), _('FILE')),
81 _('read commit message from file'), _('FILE')),
82 ]
82 ]
83
83
84 commitopts2 = [
84 commitopts2 = [
85 ('d', 'date', '',
85 ('d', 'date', '',
86 _('record the specified date as commit date'), _('DATE')),
86 _('record the specified date as commit date'), _('DATE')),
87 ('u', 'user', '',
87 ('u', 'user', '',
88 _('record the specified user as committer'), _('USER')),
88 _('record the specified user as committer'), _('USER')),
89 ]
89 ]
90
90
91 templateopts = [
91 templateopts = [
92 ('', 'style', '',
92 ('', 'style', '',
93 _('display using template map file (DEPRECATED)'), _('STYLE')),
93 _('display using template map file (DEPRECATED)'), _('STYLE')),
94 ('T', 'template', '',
94 ('T', 'template', '',
95 _('display with template'), _('TEMPLATE')),
95 _('display with template'), _('TEMPLATE')),
96 ]
96 ]
97
97
98 logopts = [
98 logopts = [
99 ('p', 'patch', None, _('show patch')),
99 ('p', 'patch', None, _('show patch')),
100 ('g', 'git', None, _('use git extended diff format')),
100 ('g', 'git', None, _('use git extended diff format')),
101 ('l', 'limit', '',
101 ('l', 'limit', '',
102 _('limit number of changes displayed'), _('NUM')),
102 _('limit number of changes displayed'), _('NUM')),
103 ('M', 'no-merges', None, _('do not show merges')),
103 ('M', 'no-merges', None, _('do not show merges')),
104 ('', 'stat', None, _('output diffstat-style summary of changes')),
104 ('', 'stat', None, _('output diffstat-style summary of changes')),
105 ('G', 'graph', None, _("show the revision DAG")),
105 ('G', 'graph', None, _("show the revision DAG")),
106 ] + templateopts
106 ] + templateopts
107
107
108 diffopts = [
108 diffopts = [
109 ('a', 'text', None, _('treat all files as text')),
109 ('a', 'text', None, _('treat all files as text')),
110 ('g', 'git', None, _('use git extended diff format')),
110 ('g', 'git', None, _('use git extended diff format')),
111 ('', 'nodates', None, _('omit dates from diff headers'))
111 ('', 'nodates', None, _('omit dates from diff headers'))
112 ]
112 ]
113
113
114 diffwsopts = [
114 diffwsopts = [
115 ('w', 'ignore-all-space', None,
115 ('w', 'ignore-all-space', None,
116 _('ignore white space when comparing lines')),
116 _('ignore white space when comparing lines')),
117 ('b', 'ignore-space-change', None,
117 ('b', 'ignore-space-change', None,
118 _('ignore changes in the amount of white space')),
118 _('ignore changes in the amount of white space')),
119 ('B', 'ignore-blank-lines', None,
119 ('B', 'ignore-blank-lines', None,
120 _('ignore changes whose lines are all blank')),
120 _('ignore changes whose lines are all blank')),
121 ]
121 ]
122
122
123 diffopts2 = [
123 diffopts2 = [
124 ('p', 'show-function', None, _('show which function each change is in')),
124 ('p', 'show-function', None, _('show which function each change is in')),
125 ('', 'reverse', None, _('produce a diff that undoes the changes')),
125 ('', 'reverse', None, _('produce a diff that undoes the changes')),
126 ] + diffwsopts + [
126 ] + diffwsopts + [
127 ('U', 'unified', '',
127 ('U', 'unified', '',
128 _('number of lines of context to show'), _('NUM')),
128 _('number of lines of context to show'), _('NUM')),
129 ('', 'stat', None, _('output diffstat-style summary of changes')),
129 ('', 'stat', None, _('output diffstat-style summary of changes')),
130 ]
130 ]
131
131
132 mergetoolopts = [
132 mergetoolopts = [
133 ('t', 'tool', '', _('specify merge tool')),
133 ('t', 'tool', '', _('specify merge tool')),
134 ]
134 ]
135
135
136 similarityopts = [
136 similarityopts = [
137 ('s', 'similarity', '',
137 ('s', 'similarity', '',
138 _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY'))
138 _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY'))
139 ]
139 ]
140
140
141 subrepoopts = [
141 subrepoopts = [
142 ('S', 'subrepos', None,
142 ('S', 'subrepos', None,
143 _('recurse into subrepositories'))
143 _('recurse into subrepositories'))
144 ]
144 ]
145
145
146 # Commands start here, listed alphabetically
146 # Commands start here, listed alphabetically
147
147
148 @command('^add',
148 @command('^add',
149 walkopts + subrepoopts + dryrunopts,
149 walkopts + subrepoopts + dryrunopts,
150 _('[OPTION]... [FILE]...'))
150 _('[OPTION]... [FILE]...'))
151 def add(ui, repo, *pats, **opts):
151 def add(ui, repo, *pats, **opts):
152 """add the specified files on the next commit
152 """add the specified files on the next commit
153
153
154 Schedule files to be version controlled and added to the
154 Schedule files to be version controlled and added to the
155 repository.
155 repository.
156
156
157 The files will be added to the repository at the next commit. To
157 The files will be added to the repository at the next commit. To
158 undo an add before that, see :hg:`forget`.
158 undo an add before that, see :hg:`forget`.
159
159
160 If no names are given, add all files to the repository.
160 If no names are given, add all files to the repository.
161
161
162 .. container:: verbose
162 .. container:: verbose
163
163
164 An example showing how new (unknown) files are added
164 An example showing how new (unknown) files are added
165 automatically by :hg:`add`::
165 automatically by :hg:`add`::
166
166
167 $ ls
167 $ ls
168 foo.c
168 foo.c
169 $ hg status
169 $ hg status
170 ? foo.c
170 ? foo.c
171 $ hg add
171 $ hg add
172 adding foo.c
172 adding foo.c
173 $ hg status
173 $ hg status
174 A foo.c
174 A foo.c
175
175
176 Returns 0 if all files are successfully added.
176 Returns 0 if all files are successfully added.
177 """
177 """
178
178
179 m = scmutil.match(repo[None], pats, opts)
179 m = scmutil.match(repo[None], pats, opts)
180 rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'),
180 rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'),
181 opts.get('subrepos'), prefix="", explicitonly=False)
181 opts.get('subrepos'), prefix="", explicitonly=False)
182 return rejected and 1 or 0
182 return rejected and 1 or 0
183
183
184 @command('addremove',
184 @command('addremove',
185 similarityopts + walkopts + dryrunopts,
185 similarityopts + walkopts + dryrunopts,
186 _('[OPTION]... [FILE]...'))
186 _('[OPTION]... [FILE]...'))
187 def addremove(ui, repo, *pats, **opts):
187 def addremove(ui, repo, *pats, **opts):
188 """add all new files, delete all missing files
188 """add all new files, delete all missing files
189
189
190 Add all new files and remove all missing files from the
190 Add all new files and remove all missing files from the
191 repository.
191 repository.
192
192
193 New files are ignored if they match any of the patterns in
193 New files are ignored if they match any of the patterns in
194 ``.hgignore``. As with add, these changes take effect at the next
194 ``.hgignore``. As with add, these changes take effect at the next
195 commit.
195 commit.
196
196
197 Use the -s/--similarity option to detect renamed files. This
197 Use the -s/--similarity option to detect renamed files. This
198 option takes a percentage between 0 (disabled) and 100 (files must
198 option takes a percentage between 0 (disabled) and 100 (files must
199 be identical) as its parameter. With a parameter greater than 0,
199 be identical) as its parameter. With a parameter greater than 0,
200 this compares every removed file with every added file and records
200 this compares every removed file with every added file and records
201 those similar enough as renames. Detecting renamed files this way
201 those similar enough as renames. Detecting renamed files this way
202 can be expensive. After using this option, :hg:`status -C` can be
202 can be expensive. After using this option, :hg:`status -C` can be
203 used to check which files were identified as moved or renamed. If
203 used to check which files were identified as moved or renamed. If
204 not specified, -s/--similarity defaults to 100 and only renames of
204 not specified, -s/--similarity defaults to 100 and only renames of
205 identical files are detected.
205 identical files are detected.
206
206
207 Returns 0 if all files are successfully added.
207 Returns 0 if all files are successfully added.
208 """
208 """
209 try:
209 try:
210 sim = float(opts.get('similarity') or 100)
210 sim = float(opts.get('similarity') or 100)
211 except ValueError:
211 except ValueError:
212 raise util.Abort(_('similarity must be a number'))
212 raise util.Abort(_('similarity must be a number'))
213 if sim < 0 or sim > 100:
213 if sim < 0 or sim > 100:
214 raise util.Abort(_('similarity must be between 0 and 100'))
214 raise util.Abort(_('similarity must be between 0 and 100'))
215 return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0)
215 return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0)
216
216
217 @command('^annotate|blame',
217 @command('^annotate|blame',
218 [('r', 'rev', '', _('annotate the specified revision'), _('REV')),
218 [('r', 'rev', '', _('annotate the specified revision'), _('REV')),
219 ('', 'follow', None,
219 ('', 'follow', None,
220 _('follow copies/renames and list the filename (DEPRECATED)')),
220 _('follow copies/renames and list the filename (DEPRECATED)')),
221 ('', 'no-follow', None, _("don't follow copies and renames")),
221 ('', 'no-follow', None, _("don't follow copies and renames")),
222 ('a', 'text', None, _('treat all files as text')),
222 ('a', 'text', None, _('treat all files as text')),
223 ('u', 'user', None, _('list the author (long with -v)')),
223 ('u', 'user', None, _('list the author (long with -v)')),
224 ('f', 'file', None, _('list the filename')),
224 ('f', 'file', None, _('list the filename')),
225 ('d', 'date', None, _('list the date (short with -q)')),
225 ('d', 'date', None, _('list the date (short with -q)')),
226 ('n', 'number', None, _('list the revision number (default)')),
226 ('n', 'number', None, _('list the revision number (default)')),
227 ('c', 'changeset', None, _('list the changeset')),
227 ('c', 'changeset', None, _('list the changeset')),
228 ('l', 'line-number', None, _('show line number at the first appearance'))
228 ('l', 'line-number', None, _('show line number at the first appearance'))
229 ] + diffwsopts + walkopts,
229 ] + diffwsopts + walkopts,
230 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'))
230 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'))
231 def annotate(ui, repo, *pats, **opts):
231 def annotate(ui, repo, *pats, **opts):
232 """show changeset information by line for each file
232 """show changeset information by line for each file
233
233
234 List changes in files, showing the revision id responsible for
234 List changes in files, showing the revision id responsible for
235 each line
235 each line
236
236
237 This command is useful for discovering when a change was made and
237 This command is useful for discovering when a change was made and
238 by whom.
238 by whom.
239
239
240 Without the -a/--text option, annotate will avoid processing files
240 Without the -a/--text option, annotate will avoid processing files
241 it detects as binary. With -a, annotate will annotate the file
241 it detects as binary. With -a, annotate will annotate the file
242 anyway, although the results will probably be neither useful
242 anyway, although the results will probably be neither useful
243 nor desirable.
243 nor desirable.
244
244
245 Returns 0 on success.
245 Returns 0 on success.
246 """
246 """
247 if opts.get('follow'):
247 if opts.get('follow'):
248 # --follow is deprecated and now just an alias for -f/--file
248 # --follow is deprecated and now just an alias for -f/--file
249 # to mimic the behavior of Mercurial before version 1.5
249 # to mimic the behavior of Mercurial before version 1.5
250 opts['file'] = True
250 opts['file'] = True
251
251
252 datefunc = ui.quiet and util.shortdate or util.datestr
252 datefunc = ui.quiet and util.shortdate or util.datestr
253 getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
253 getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
254
254
255 if not pats:
255 if not pats:
256 raise util.Abort(_('at least one filename or pattern is required'))
256 raise util.Abort(_('at least one filename or pattern is required'))
257
257
258 hexfn = ui.debugflag and hex or short
258 hexfn = ui.debugflag and hex or short
259
259
260 opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())),
260 opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())),
261 ('number', ' ', lambda x: str(x[0].rev())),
261 ('number', ' ', lambda x: str(x[0].rev())),
262 ('changeset', ' ', lambda x: hexfn(x[0].node())),
262 ('changeset', ' ', lambda x: hexfn(x[0].node())),
263 ('date', ' ', getdate),
263 ('date', ' ', getdate),
264 ('file', ' ', lambda x: x[0].path()),
264 ('file', ' ', lambda x: x[0].path()),
265 ('line_number', ':', lambda x: str(x[1])),
265 ('line_number', ':', lambda x: str(x[1])),
266 ]
266 ]
267
267
268 if (not opts.get('user') and not opts.get('changeset')
268 if (not opts.get('user') and not opts.get('changeset')
269 and not opts.get('date') and not opts.get('file')):
269 and not opts.get('date') and not opts.get('file')):
270 opts['number'] = True
270 opts['number'] = True
271
271
272 linenumber = opts.get('line_number') is not None
272 linenumber = opts.get('line_number') is not None
273 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
273 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
274 raise util.Abort(_('at least one of -n/-c is required for -l'))
274 raise util.Abort(_('at least one of -n/-c is required for -l'))
275
275
276 funcmap = [(func, sep) for op, sep, func in opmap if opts.get(op)]
276 funcmap = [(func, sep) for op, sep, func in opmap if opts.get(op)]
277 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
277 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
278
278
279 def bad(x, y):
279 def bad(x, y):
280 raise util.Abort("%s: %s" % (x, y))
280 raise util.Abort("%s: %s" % (x, y))
281
281
282 ctx = scmutil.revsingle(repo, opts.get('rev'))
282 ctx = scmutil.revsingle(repo, opts.get('rev'))
283 m = scmutil.match(ctx, pats, opts)
283 m = scmutil.match(ctx, pats, opts)
284 m.bad = bad
284 m.bad = bad
285 follow = not opts.get('no_follow')
285 follow = not opts.get('no_follow')
286 diffopts = patch.diffopts(ui, opts, section='annotate')
286 diffopts = patch.diffopts(ui, opts, section='annotate')
287 for abs in ctx.walk(m):
287 for abs in ctx.walk(m):
288 fctx = ctx[abs]
288 fctx = ctx[abs]
289 if not opts.get('text') and util.binary(fctx.data()):
289 if not opts.get('text') and util.binary(fctx.data()):
290 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
290 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
291 continue
291 continue
292
292
293 lines = fctx.annotate(follow=follow, linenumber=linenumber,
293 lines = fctx.annotate(follow=follow, linenumber=linenumber,
294 diffopts=diffopts)
294 diffopts=diffopts)
295 pieces = []
295 pieces = []
296
296
297 for f, sep in funcmap:
297 for f, sep in funcmap:
298 l = [f(n) for n, dummy in lines]
298 l = [f(n) for n, dummy in lines]
299 if l:
299 if l:
300 sized = [(x, encoding.colwidth(x)) for x in l]
300 sized = [(x, encoding.colwidth(x)) for x in l]
301 ml = max([w for x, w in sized])
301 ml = max([w for x, w in sized])
302 pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x)
302 pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x)
303 for x, w in sized])
303 for x, w in sized])
304
304
305 if pieces:
305 if pieces:
306 for p, l in zip(zip(*pieces), lines):
306 for p, l in zip(zip(*pieces), lines):
307 ui.write("%s: %s" % ("".join(p), l[1]))
307 ui.write("%s: %s" % ("".join(p), l[1]))
308
308
309 if lines and not lines[-1][1].endswith('\n'):
309 if lines and not lines[-1][1].endswith('\n'):
310 ui.write('\n')
310 ui.write('\n')
311
311
312 @command('archive',
312 @command('archive',
313 [('', 'no-decode', None, _('do not pass files through decoders')),
313 [('', 'no-decode', None, _('do not pass files through decoders')),
314 ('p', 'prefix', '', _('directory prefix for files in archive'),
314 ('p', 'prefix', '', _('directory prefix for files in archive'),
315 _('PREFIX')),
315 _('PREFIX')),
316 ('r', 'rev', '', _('revision to distribute'), _('REV')),
316 ('r', 'rev', '', _('revision to distribute'), _('REV')),
317 ('t', 'type', '', _('type of distribution to create'), _('TYPE')),
317 ('t', 'type', '', _('type of distribution to create'), _('TYPE')),
318 ] + subrepoopts + walkopts,
318 ] + subrepoopts + walkopts,
319 _('[OPTION]... DEST'))
319 _('[OPTION]... DEST'))
320 def archive(ui, repo, dest, **opts):
320 def archive(ui, repo, dest, **opts):
321 '''create an unversioned archive of a repository revision
321 '''create an unversioned archive of a repository revision
322
322
323 By default, the revision used is the parent of the working
323 By default, the revision used is the parent of the working
324 directory; use -r/--rev to specify a different revision.
324 directory; use -r/--rev to specify a different revision.
325
325
326 The archive type is automatically detected based on file
326 The archive type is automatically detected based on file
327 extension (or override using -t/--type).
327 extension (or override using -t/--type).
328
328
329 .. container:: verbose
329 .. container:: verbose
330
330
331 Examples:
331 Examples:
332
332
333 - create a zip file containing the 1.0 release::
333 - create a zip file containing the 1.0 release::
334
334
335 hg archive -r 1.0 project-1.0.zip
335 hg archive -r 1.0 project-1.0.zip
336
336
337 - create a tarball excluding .hg files::
337 - create a tarball excluding .hg files::
338
338
339 hg archive project.tar.gz -X ".hg*"
339 hg archive project.tar.gz -X ".hg*"
340
340
341 Valid types are:
341 Valid types are:
342
342
343 :``files``: a directory full of files (default)
343 :``files``: a directory full of files (default)
344 :``tar``: tar archive, uncompressed
344 :``tar``: tar archive, uncompressed
345 :``tbz2``: tar archive, compressed using bzip2
345 :``tbz2``: tar archive, compressed using bzip2
346 :``tgz``: tar archive, compressed using gzip
346 :``tgz``: tar archive, compressed using gzip
347 :``uzip``: zip archive, uncompressed
347 :``uzip``: zip archive, uncompressed
348 :``zip``: zip archive, compressed using deflate
348 :``zip``: zip archive, compressed using deflate
349
349
350 The exact name of the destination archive or directory is given
350 The exact name of the destination archive or directory is given
351 using a format string; see :hg:`help export` for details.
351 using a format string; see :hg:`help export` for details.
352
352
353 Each member added to an archive file has a directory prefix
353 Each member added to an archive file has a directory prefix
354 prepended. Use -p/--prefix to specify a format string for the
354 prepended. Use -p/--prefix to specify a format string for the
355 prefix. The default is the basename of the archive, with suffixes
355 prefix. The default is the basename of the archive, with suffixes
356 removed.
356 removed.
357
357
358 Returns 0 on success.
358 Returns 0 on success.
359 '''
359 '''
360
360
361 ctx = scmutil.revsingle(repo, opts.get('rev'))
361 ctx = scmutil.revsingle(repo, opts.get('rev'))
362 if not ctx:
362 if not ctx:
363 raise util.Abort(_('no working directory: please specify a revision'))
363 raise util.Abort(_('no working directory: please specify a revision'))
364 node = ctx.node()
364 node = ctx.node()
365 dest = cmdutil.makefilename(repo, dest, node)
365 dest = cmdutil.makefilename(repo, dest, node)
366 if os.path.realpath(dest) == repo.root:
366 if os.path.realpath(dest) == repo.root:
367 raise util.Abort(_('repository root cannot be destination'))
367 raise util.Abort(_('repository root cannot be destination'))
368
368
369 kind = opts.get('type') or archival.guesskind(dest) or 'files'
369 kind = opts.get('type') or archival.guesskind(dest) or 'files'
370 prefix = opts.get('prefix')
370 prefix = opts.get('prefix')
371
371
372 if dest == '-':
372 if dest == '-':
373 if kind == 'files':
373 if kind == 'files':
374 raise util.Abort(_('cannot archive plain files to stdout'))
374 raise util.Abort(_('cannot archive plain files to stdout'))
375 dest = cmdutil.makefileobj(repo, dest)
375 dest = cmdutil.makefileobj(repo, dest)
376 if not prefix:
376 if not prefix:
377 prefix = os.path.basename(repo.root) + '-%h'
377 prefix = os.path.basename(repo.root) + '-%h'
378
378
379 prefix = cmdutil.makefilename(repo, prefix, node)
379 prefix = cmdutil.makefilename(repo, prefix, node)
380 matchfn = scmutil.match(ctx, [], opts)
380 matchfn = scmutil.match(ctx, [], opts)
381 archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
381 archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
382 matchfn, prefix, subrepos=opts.get('subrepos'))
382 matchfn, prefix, subrepos=opts.get('subrepos'))
383
383
384 @command('backout',
384 @command('backout',
385 [('', 'merge', None, _('merge with old dirstate parent after backout')),
385 [('', 'merge', None, _('merge with old dirstate parent after backout')),
386 ('', 'parent', '',
386 ('', 'parent', '',
387 _('parent to choose when backing out merge (DEPRECATED)'), _('REV')),
387 _('parent to choose when backing out merge (DEPRECATED)'), _('REV')),
388 ('r', 'rev', '', _('revision to backout'), _('REV')),
388 ('r', 'rev', '', _('revision to backout'), _('REV')),
389 ] + mergetoolopts + walkopts + commitopts + commitopts2,
389 ] + mergetoolopts + walkopts + commitopts + commitopts2,
390 _('[OPTION]... [-r] REV'))
390 _('[OPTION]... [-r] REV'))
391 def backout(ui, repo, node=None, rev=None, **opts):
391 def backout(ui, repo, node=None, rev=None, **opts):
392 '''reverse effect of earlier changeset
392 '''reverse effect of earlier changeset
393
393
394 Prepare a new changeset with the effect of REV undone in the
394 Prepare a new changeset with the effect of REV undone in the
395 current working directory.
395 current working directory.
396
396
397 If REV is the parent of the working directory, then this new changeset
397 If REV is the parent of the working directory, then this new changeset
398 is committed automatically. Otherwise, hg needs to merge the
398 is committed automatically. Otherwise, hg needs to merge the
399 changes and the merged result is left uncommitted.
399 changes and the merged result is left uncommitted.
400
400
401 .. note::
401 .. note::
402
402
403 backout cannot be used to fix either an unwanted or
403 backout cannot be used to fix either an unwanted or
404 incorrect merge.
404 incorrect merge.
405
405
406 .. container:: verbose
406 .. container:: verbose
407
407
408 By default, the pending changeset will have one parent,
408 By default, the pending changeset will have one parent,
409 maintaining a linear history. With --merge, the pending
409 maintaining a linear history. With --merge, the pending
410 changeset will instead have two parents: the old parent of the
410 changeset will instead have two parents: the old parent of the
411 working directory and a new child of REV that simply undoes REV.
411 working directory and a new child of REV that simply undoes REV.
412
412
413 Before version 1.7, the behavior without --merge was equivalent
413 Before version 1.7, the behavior without --merge was equivalent
414 to specifying --merge followed by :hg:`update --clean .` to
414 to specifying --merge followed by :hg:`update --clean .` to
415 cancel the merge and leave the child of REV as a head to be
415 cancel the merge and leave the child of REV as a head to be
416 merged separately.
416 merged separately.
417
417
418 See :hg:`help dates` for a list of formats valid for -d/--date.
418 See :hg:`help dates` for a list of formats valid for -d/--date.
419
419
420 Returns 0 on success, 1 if nothing to backout or there are unresolved
420 Returns 0 on success, 1 if nothing to backout or there are unresolved
421 files.
421 files.
422 '''
422 '''
423 if rev and node:
423 if rev and node:
424 raise util.Abort(_("please specify just one revision"))
424 raise util.Abort(_("please specify just one revision"))
425
425
426 if not rev:
426 if not rev:
427 rev = node
427 rev = node
428
428
429 if not rev:
429 if not rev:
430 raise util.Abort(_("please specify a revision to backout"))
430 raise util.Abort(_("please specify a revision to backout"))
431
431
432 date = opts.get('date')
432 date = opts.get('date')
433 if date:
433 if date:
434 opts['date'] = util.parsedate(date)
434 opts['date'] = util.parsedate(date)
435
435
436 cmdutil.checkunfinished(repo)
436 cmdutil.checkunfinished(repo)
437 cmdutil.bailifchanged(repo)
437 cmdutil.bailifchanged(repo)
438 node = scmutil.revsingle(repo, rev).node()
438 node = scmutil.revsingle(repo, rev).node()
439
439
440 op1, op2 = repo.dirstate.parents()
440 op1, op2 = repo.dirstate.parents()
441 if node not in repo.changelog.commonancestorsheads(op1, node):
441 if node not in repo.changelog.commonancestorsheads(op1, node):
442 raise util.Abort(_('cannot backout change that is not an ancestor'))
442 raise util.Abort(_('cannot backout change that is not an ancestor'))
443
443
444 p1, p2 = repo.changelog.parents(node)
444 p1, p2 = repo.changelog.parents(node)
445 if p1 == nullid:
445 if p1 == nullid:
446 raise util.Abort(_('cannot backout a change with no parents'))
446 raise util.Abort(_('cannot backout a change with no parents'))
447 if p2 != nullid:
447 if p2 != nullid:
448 if not opts.get('parent'):
448 if not opts.get('parent'):
449 raise util.Abort(_('cannot backout a merge changeset'))
449 raise util.Abort(_('cannot backout a merge changeset'))
450 p = repo.lookup(opts['parent'])
450 p = repo.lookup(opts['parent'])
451 if p not in (p1, p2):
451 if p not in (p1, p2):
452 raise util.Abort(_('%s is not a parent of %s') %
452 raise util.Abort(_('%s is not a parent of %s') %
453 (short(p), short(node)))
453 (short(p), short(node)))
454 parent = p
454 parent = p
455 else:
455 else:
456 if opts.get('parent'):
456 if opts.get('parent'):
457 raise util.Abort(_('cannot use --parent on non-merge changeset'))
457 raise util.Abort(_('cannot use --parent on non-merge changeset'))
458 parent = p1
458 parent = p1
459
459
460 # the backout should appear on the same branch
460 # the backout should appear on the same branch
461 wlock = repo.wlock()
461 wlock = repo.wlock()
462 try:
462 try:
463 branch = repo.dirstate.branch()
463 branch = repo.dirstate.branch()
464 bheads = repo.branchheads(branch)
464 bheads = repo.branchheads(branch)
465 rctx = scmutil.revsingle(repo, hex(parent))
465 rctx = scmutil.revsingle(repo, hex(parent))
466 if not opts.get('merge') and op1 != node:
466 if not opts.get('merge') and op1 != node:
467 try:
467 try:
468 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
468 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
469 'backout')
469 'backout')
470 stats = mergemod.update(repo, parent, True, True, False,
470 stats = mergemod.update(repo, parent, True, True, False,
471 node, False)
471 node, False)
472 repo.setparents(op1, op2)
472 repo.setparents(op1, op2)
473 hg._showstats(repo, stats)
473 hg._showstats(repo, stats)
474 if stats[3]:
474 if stats[3]:
475 repo.ui.status(_("use 'hg resolve' to retry unresolved "
475 repo.ui.status(_("use 'hg resolve' to retry unresolved "
476 "file merges\n"))
476 "file merges\n"))
477 else:
477 else:
478 msg = _("changeset %s backed out, "
478 msg = _("changeset %s backed out, "
479 "don't forget to commit.\n")
479 "don't forget to commit.\n")
480 ui.status(msg % short(node))
480 ui.status(msg % short(node))
481 return stats[3] > 0
481 return stats[3] > 0
482 finally:
482 finally:
483 ui.setconfig('ui', 'forcemerge', '', '')
483 ui.setconfig('ui', 'forcemerge', '', '')
484 else:
484 else:
485 hg.clean(repo, node, show_stats=False)
485 hg.clean(repo, node, show_stats=False)
486 repo.dirstate.setbranch(branch)
486 repo.dirstate.setbranch(branch)
487 cmdutil.revert(ui, repo, rctx, repo.dirstate.parents())
487 cmdutil.revert(ui, repo, rctx, repo.dirstate.parents())
488
488
489
489
490 def commitfunc(ui, repo, message, match, opts):
490 def commitfunc(ui, repo, message, match, opts):
491 e = cmdutil.getcommiteditor()
491 e = cmdutil.getcommiteditor()
492 if not message:
492 if not message:
493 # we don't translate commit messages
493 # we don't translate commit messages
494 message = "Backed out changeset %s" % short(node)
494 message = "Backed out changeset %s" % short(node)
495 e = cmdutil.getcommiteditor(edit=True)
495 e = cmdutil.getcommiteditor(edit=True)
496 return repo.commit(message, opts.get('user'), opts.get('date'),
496 return repo.commit(message, opts.get('user'), opts.get('date'),
497 match, editor=e)
497 match, editor=e)
498 newnode = cmdutil.commit(ui, repo, commitfunc, [], opts)
498 newnode = cmdutil.commit(ui, repo, commitfunc, [], opts)
499 if not newnode:
499 if not newnode:
500 ui.status(_("nothing changed\n"))
500 ui.status(_("nothing changed\n"))
501 return 1
501 return 1
502 cmdutil.commitstatus(repo, newnode, branch, bheads)
502 cmdutil.commitstatus(repo, newnode, branch, bheads)
503
503
504 def nice(node):
504 def nice(node):
505 return '%d:%s' % (repo.changelog.rev(node), short(node))
505 return '%d:%s' % (repo.changelog.rev(node), short(node))
506 ui.status(_('changeset %s backs out changeset %s\n') %
506 ui.status(_('changeset %s backs out changeset %s\n') %
507 (nice(repo.changelog.tip()), nice(node)))
507 (nice(repo.changelog.tip()), nice(node)))
508 if opts.get('merge') and op1 != node:
508 if opts.get('merge') and op1 != node:
509 hg.clean(repo, op1, show_stats=False)
509 hg.clean(repo, op1, show_stats=False)
510 ui.status(_('merging with changeset %s\n')
510 ui.status(_('merging with changeset %s\n')
511 % nice(repo.changelog.tip()))
511 % nice(repo.changelog.tip()))
512 try:
512 try:
513 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
513 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
514 'backout')
514 'backout')
515 return hg.merge(repo, hex(repo.changelog.tip()))
515 return hg.merge(repo, hex(repo.changelog.tip()))
516 finally:
516 finally:
517 ui.setconfig('ui', 'forcemerge', '', '')
517 ui.setconfig('ui', 'forcemerge', '', '')
518 finally:
518 finally:
519 wlock.release()
519 wlock.release()
520 return 0
520 return 0
521
521
522 @command('bisect',
522 @command('bisect',
523 [('r', 'reset', False, _('reset bisect state')),
523 [('r', 'reset', False, _('reset bisect state')),
524 ('g', 'good', False, _('mark changeset good')),
524 ('g', 'good', False, _('mark changeset good')),
525 ('b', 'bad', False, _('mark changeset bad')),
525 ('b', 'bad', False, _('mark changeset bad')),
526 ('s', 'skip', False, _('skip testing changeset')),
526 ('s', 'skip', False, _('skip testing changeset')),
527 ('e', 'extend', False, _('extend the bisect range')),
527 ('e', 'extend', False, _('extend the bisect range')),
528 ('c', 'command', '', _('use command to check changeset state'), _('CMD')),
528 ('c', 'command', '', _('use command to check changeset state'), _('CMD')),
529 ('U', 'noupdate', False, _('do not update to target'))],
529 ('U', 'noupdate', False, _('do not update to target'))],
530 _("[-gbsr] [-U] [-c CMD] [REV]"))
530 _("[-gbsr] [-U] [-c CMD] [REV]"))
531 def bisect(ui, repo, rev=None, extra=None, command=None,
531 def bisect(ui, repo, rev=None, extra=None, command=None,
532 reset=None, good=None, bad=None, skip=None, extend=None,
532 reset=None, good=None, bad=None, skip=None, extend=None,
533 noupdate=None):
533 noupdate=None):
534 """subdivision search of changesets
534 """subdivision search of changesets
535
535
536 This command helps to find changesets which introduce problems. To
536 This command helps to find changesets which introduce problems. To
537 use, mark the earliest changeset you know exhibits the problem as
537 use, mark the earliest changeset you know exhibits the problem as
538 bad, then mark the latest changeset which is free from the problem
538 bad, then mark the latest changeset which is free from the problem
539 as good. Bisect will update your working directory to a revision
539 as good. Bisect will update your working directory to a revision
540 for testing (unless the -U/--noupdate option is specified). Once
540 for testing (unless the -U/--noupdate option is specified). Once
541 you have performed tests, mark the working directory as good or
541 you have performed tests, mark the working directory as good or
542 bad, and bisect will either update to another candidate changeset
542 bad, and bisect will either update to another candidate changeset
543 or announce that it has found the bad revision.
543 or announce that it has found the bad revision.
544
544
545 As a shortcut, you can also use the revision argument to mark a
545 As a shortcut, you can also use the revision argument to mark a
546 revision as good or bad without checking it out first.
546 revision as good or bad without checking it out first.
547
547
548 If you supply a command, it will be used for automatic bisection.
548 If you supply a command, it will be used for automatic bisection.
549 The environment variable HG_NODE will contain the ID of the
549 The environment variable HG_NODE will contain the ID of the
550 changeset being tested. The exit status of the command will be
550 changeset being tested. The exit status of the command will be
551 used to mark revisions as good or bad: status 0 means good, 125
551 used to mark revisions as good or bad: status 0 means good, 125
552 means to skip the revision, 127 (command not found) will abort the
552 means to skip the revision, 127 (command not found) will abort the
553 bisection, and any other non-zero exit status means the revision
553 bisection, and any other non-zero exit status means the revision
554 is bad.
554 is bad.
555
555
556 .. container:: verbose
556 .. container:: verbose
557
557
558 Some examples:
558 Some examples:
559
559
560 - start a bisection with known bad revision 34, and good revision 12::
560 - start a bisection with known bad revision 34, and good revision 12::
561
561
562 hg bisect --bad 34
562 hg bisect --bad 34
563 hg bisect --good 12
563 hg bisect --good 12
564
564
565 - advance the current bisection by marking current revision as good or
565 - advance the current bisection by marking current revision as good or
566 bad::
566 bad::
567
567
568 hg bisect --good
568 hg bisect --good
569 hg bisect --bad
569 hg bisect --bad
570
570
571 - mark the current revision, or a known revision, to be skipped (e.g. if
571 - mark the current revision, or a known revision, to be skipped (e.g. if
572 that revision is not usable because of another issue)::
572 that revision is not usable because of another issue)::
573
573
574 hg bisect --skip
574 hg bisect --skip
575 hg bisect --skip 23
575 hg bisect --skip 23
576
576
577 - skip all revisions that do not touch directories ``foo`` or ``bar``::
577 - skip all revisions that do not touch directories ``foo`` or ``bar``::
578
578
579 hg bisect --skip "!( file('path:foo') & file('path:bar') )"
579 hg bisect --skip "!( file('path:foo') & file('path:bar') )"
580
580
581 - forget the current bisection::
581 - forget the current bisection::
582
582
583 hg bisect --reset
583 hg bisect --reset
584
584
585 - use 'make && make tests' to automatically find the first broken
585 - use 'make && make tests' to automatically find the first broken
586 revision::
586 revision::
587
587
588 hg bisect --reset
588 hg bisect --reset
589 hg bisect --bad 34
589 hg bisect --bad 34
590 hg bisect --good 12
590 hg bisect --good 12
591 hg bisect --command "make && make tests"
591 hg bisect --command "make && make tests"
592
592
593 - see all changesets whose states are already known in the current
593 - see all changesets whose states are already known in the current
594 bisection::
594 bisection::
595
595
596 hg log -r "bisect(pruned)"
596 hg log -r "bisect(pruned)"
597
597
598 - see the changeset currently being bisected (especially useful
598 - see the changeset currently being bisected (especially useful
599 if running with -U/--noupdate)::
599 if running with -U/--noupdate)::
600
600
601 hg log -r "bisect(current)"
601 hg log -r "bisect(current)"
602
602
603 - see all changesets that took part in the current bisection::
603 - see all changesets that took part in the current bisection::
604
604
605 hg log -r "bisect(range)"
605 hg log -r "bisect(range)"
606
606
607 - you can even get a nice graph::
607 - you can even get a nice graph::
608
608
609 hg log --graph -r "bisect(range)"
609 hg log --graph -r "bisect(range)"
610
610
611 See :hg:`help revsets` for more about the `bisect()` keyword.
611 See :hg:`help revsets` for more about the `bisect()` keyword.
612
612
613 Returns 0 on success.
613 Returns 0 on success.
614 """
614 """
615 def extendbisectrange(nodes, good):
615 def extendbisectrange(nodes, good):
616 # bisect is incomplete when it ends on a merge node and
616 # bisect is incomplete when it ends on a merge node and
617 # one of the parent was not checked.
617 # one of the parent was not checked.
618 parents = repo[nodes[0]].parents()
618 parents = repo[nodes[0]].parents()
619 if len(parents) > 1:
619 if len(parents) > 1:
620 side = good and state['bad'] or state['good']
620 side = good and state['bad'] or state['good']
621 num = len(set(i.node() for i in parents) & set(side))
621 num = len(set(i.node() for i in parents) & set(side))
622 if num == 1:
622 if num == 1:
623 return parents[0].ancestor(parents[1])
623 return parents[0].ancestor(parents[1])
624 return None
624 return None
625
625
626 def print_result(nodes, good):
626 def print_result(nodes, good):
627 displayer = cmdutil.show_changeset(ui, repo, {})
627 displayer = cmdutil.show_changeset(ui, repo, {})
628 if len(nodes) == 1:
628 if len(nodes) == 1:
629 # narrowed it down to a single revision
629 # narrowed it down to a single revision
630 if good:
630 if good:
631 ui.write(_("The first good revision is:\n"))
631 ui.write(_("The first good revision is:\n"))
632 else:
632 else:
633 ui.write(_("The first bad revision is:\n"))
633 ui.write(_("The first bad revision is:\n"))
634 displayer.show(repo[nodes[0]])
634 displayer.show(repo[nodes[0]])
635 extendnode = extendbisectrange(nodes, good)
635 extendnode = extendbisectrange(nodes, good)
636 if extendnode is not None:
636 if extendnode is not None:
637 ui.write(_('Not all ancestors of this changeset have been'
637 ui.write(_('Not all ancestors of this changeset have been'
638 ' checked.\nUse bisect --extend to continue the '
638 ' checked.\nUse bisect --extend to continue the '
639 'bisection from\nthe common ancestor, %s.\n')
639 'bisection from\nthe common ancestor, %s.\n')
640 % extendnode)
640 % extendnode)
641 else:
641 else:
642 # multiple possible revisions
642 # multiple possible revisions
643 if good:
643 if good:
644 ui.write(_("Due to skipped revisions, the first "
644 ui.write(_("Due to skipped revisions, the first "
645 "good revision could be any of:\n"))
645 "good revision could be any of:\n"))
646 else:
646 else:
647 ui.write(_("Due to skipped revisions, the first "
647 ui.write(_("Due to skipped revisions, the first "
648 "bad revision could be any of:\n"))
648 "bad revision could be any of:\n"))
649 for n in nodes:
649 for n in nodes:
650 displayer.show(repo[n])
650 displayer.show(repo[n])
651 displayer.close()
651 displayer.close()
652
652
653 def check_state(state, interactive=True):
653 def check_state(state, interactive=True):
654 if not state['good'] or not state['bad']:
654 if not state['good'] or not state['bad']:
655 if (good or bad or skip or reset) and interactive:
655 if (good or bad or skip or reset) and interactive:
656 return
656 return
657 if not state['good']:
657 if not state['good']:
658 raise util.Abort(_('cannot bisect (no known good revisions)'))
658 raise util.Abort(_('cannot bisect (no known good revisions)'))
659 else:
659 else:
660 raise util.Abort(_('cannot bisect (no known bad revisions)'))
660 raise util.Abort(_('cannot bisect (no known bad revisions)'))
661 return True
661 return True
662
662
663 # backward compatibility
663 # backward compatibility
664 if rev in "good bad reset init".split():
664 if rev in "good bad reset init".split():
665 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
665 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
666 cmd, rev, extra = rev, extra, None
666 cmd, rev, extra = rev, extra, None
667 if cmd == "good":
667 if cmd == "good":
668 good = True
668 good = True
669 elif cmd == "bad":
669 elif cmd == "bad":
670 bad = True
670 bad = True
671 else:
671 else:
672 reset = True
672 reset = True
673 elif extra or good + bad + skip + reset + extend + bool(command) > 1:
673 elif extra or good + bad + skip + reset + extend + bool(command) > 1:
674 raise util.Abort(_('incompatible arguments'))
674 raise util.Abort(_('incompatible arguments'))
675
675
676 cmdutil.checkunfinished(repo)
676 cmdutil.checkunfinished(repo)
677
677
678 if reset:
678 if reset:
679 p = repo.join("bisect.state")
679 p = repo.join("bisect.state")
680 if os.path.exists(p):
680 if os.path.exists(p):
681 os.unlink(p)
681 os.unlink(p)
682 return
682 return
683
683
684 state = hbisect.load_state(repo)
684 state = hbisect.load_state(repo)
685
685
686 if command:
686 if command:
687 changesets = 1
687 changesets = 1
688 if noupdate:
688 if noupdate:
689 try:
689 try:
690 node = state['current'][0]
690 node = state['current'][0]
691 except LookupError:
691 except LookupError:
692 raise util.Abort(_('current bisect revision is unknown - '
692 raise util.Abort(_('current bisect revision is unknown - '
693 'start a new bisect to fix'))
693 'start a new bisect to fix'))
694 else:
694 else:
695 node, p2 = repo.dirstate.parents()
695 node, p2 = repo.dirstate.parents()
696 if p2 != nullid:
696 if p2 != nullid:
697 raise util.Abort(_('current bisect revision is a merge'))
697 raise util.Abort(_('current bisect revision is a merge'))
698 try:
698 try:
699 while changesets:
699 while changesets:
700 # update state
700 # update state
701 state['current'] = [node]
701 state['current'] = [node]
702 hbisect.save_state(repo, state)
702 hbisect.save_state(repo, state)
703 status = util.system(command,
703 status = util.system(command,
704 environ={'HG_NODE': hex(node)},
704 environ={'HG_NODE': hex(node)},
705 out=ui.fout)
705 out=ui.fout)
706 if status == 125:
706 if status == 125:
707 transition = "skip"
707 transition = "skip"
708 elif status == 0:
708 elif status == 0:
709 transition = "good"
709 transition = "good"
710 # status < 0 means process was killed
710 # status < 0 means process was killed
711 elif status == 127:
711 elif status == 127:
712 raise util.Abort(_("failed to execute %s") % command)
712 raise util.Abort(_("failed to execute %s") % command)
713 elif status < 0:
713 elif status < 0:
714 raise util.Abort(_("%s killed") % command)
714 raise util.Abort(_("%s killed") % command)
715 else:
715 else:
716 transition = "bad"
716 transition = "bad"
717 ctx = scmutil.revsingle(repo, rev, node)
717 ctx = scmutil.revsingle(repo, rev, node)
718 rev = None # clear for future iterations
718 rev = None # clear for future iterations
719 state[transition].append(ctx.node())
719 state[transition].append(ctx.node())
720 ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition))
720 ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition))
721 check_state(state, interactive=False)
721 check_state(state, interactive=False)
722 # bisect
722 # bisect
723 nodes, changesets, bgood = hbisect.bisect(repo.changelog, state)
723 nodes, changesets, bgood = hbisect.bisect(repo.changelog, state)
724 # update to next check
724 # update to next check
725 node = nodes[0]
725 node = nodes[0]
726 if not noupdate:
726 if not noupdate:
727 cmdutil.bailifchanged(repo)
727 cmdutil.bailifchanged(repo)
728 hg.clean(repo, node, show_stats=False)
728 hg.clean(repo, node, show_stats=False)
729 finally:
729 finally:
730 state['current'] = [node]
730 state['current'] = [node]
731 hbisect.save_state(repo, state)
731 hbisect.save_state(repo, state)
732 print_result(nodes, bgood)
732 print_result(nodes, bgood)
733 return
733 return
734
734
735 # update state
735 # update state
736
736
737 if rev:
737 if rev:
738 nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])]
738 nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])]
739 else:
739 else:
740 nodes = [repo.lookup('.')]
740 nodes = [repo.lookup('.')]
741
741
742 if good or bad or skip:
742 if good or bad or skip:
743 if good:
743 if good:
744 state['good'] += nodes
744 state['good'] += nodes
745 elif bad:
745 elif bad:
746 state['bad'] += nodes
746 state['bad'] += nodes
747 elif skip:
747 elif skip:
748 state['skip'] += nodes
748 state['skip'] += nodes
749 hbisect.save_state(repo, state)
749 hbisect.save_state(repo, state)
750
750
751 if not check_state(state):
751 if not check_state(state):
752 return
752 return
753
753
754 # actually bisect
754 # actually bisect
755 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
755 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
756 if extend:
756 if extend:
757 if not changesets:
757 if not changesets:
758 extendnode = extendbisectrange(nodes, good)
758 extendnode = extendbisectrange(nodes, good)
759 if extendnode is not None:
759 if extendnode is not None:
760 ui.write(_("Extending search to changeset %d:%s\n")
760 ui.write(_("Extending search to changeset %d:%s\n")
761 % (extendnode.rev(), extendnode))
761 % (extendnode.rev(), extendnode))
762 state['current'] = [extendnode.node()]
762 state['current'] = [extendnode.node()]
763 hbisect.save_state(repo, state)
763 hbisect.save_state(repo, state)
764 if noupdate:
764 if noupdate:
765 return
765 return
766 cmdutil.bailifchanged(repo)
766 cmdutil.bailifchanged(repo)
767 return hg.clean(repo, extendnode.node())
767 return hg.clean(repo, extendnode.node())
768 raise util.Abort(_("nothing to extend"))
768 raise util.Abort(_("nothing to extend"))
769
769
770 if changesets == 0:
770 if changesets == 0:
771 print_result(nodes, good)
771 print_result(nodes, good)
772 else:
772 else:
773 assert len(nodes) == 1 # only a single node can be tested next
773 assert len(nodes) == 1 # only a single node can be tested next
774 node = nodes[0]
774 node = nodes[0]
775 # compute the approximate number of remaining tests
775 # compute the approximate number of remaining tests
776 tests, size = 0, 2
776 tests, size = 0, 2
777 while size <= changesets:
777 while size <= changesets:
778 tests, size = tests + 1, size * 2
778 tests, size = tests + 1, size * 2
779 rev = repo.changelog.rev(node)
779 rev = repo.changelog.rev(node)
780 ui.write(_("Testing changeset %d:%s "
780 ui.write(_("Testing changeset %d:%s "
781 "(%d changesets remaining, ~%d tests)\n")
781 "(%d changesets remaining, ~%d tests)\n")
782 % (rev, short(node), changesets, tests))
782 % (rev, short(node), changesets, tests))
783 state['current'] = [node]
783 state['current'] = [node]
784 hbisect.save_state(repo, state)
784 hbisect.save_state(repo, state)
785 if not noupdate:
785 if not noupdate:
786 cmdutil.bailifchanged(repo)
786 cmdutil.bailifchanged(repo)
787 return hg.clean(repo, node)
787 return hg.clean(repo, node)
788
788
789 @command('bookmarks|bookmark',
789 @command('bookmarks|bookmark',
790 [('f', 'force', False, _('force')),
790 [('f', 'force', False, _('force')),
791 ('r', 'rev', '', _('revision'), _('REV')),
791 ('r', 'rev', '', _('revision'), _('REV')),
792 ('d', 'delete', False, _('delete a given bookmark')),
792 ('d', 'delete', False, _('delete a given bookmark')),
793 ('m', 'rename', '', _('rename a given bookmark'), _('NAME')),
793 ('m', 'rename', '', _('rename a given bookmark'), _('NAME')),
794 ('i', 'inactive', False, _('mark a bookmark inactive'))],
794 ('i', 'inactive', False, _('mark a bookmark inactive'))],
795 _('hg bookmarks [OPTIONS]... [NAME]...'))
795 _('hg bookmarks [OPTIONS]... [NAME]...'))
796 def bookmark(ui, repo, *names, **opts):
796 def bookmark(ui, repo, *names, **opts):
797 '''track a line of development with movable markers
797 '''track a line of development with movable markers
798
798
799 Bookmarks are pointers to certain commits that move when committing.
799 Bookmarks are pointers to certain commits that move when committing.
800 Bookmarks are local. They can be renamed, copied and deleted. It is
800 Bookmarks are local. They can be renamed, copied and deleted. It is
801 possible to use :hg:`merge NAME` to merge from a given bookmark, and
801 possible to use :hg:`merge NAME` to merge from a given bookmark, and
802 :hg:`update NAME` to update to a given bookmark.
802 :hg:`update NAME` to update to a given bookmark.
803
803
804 You can use :hg:`bookmark NAME` to set a bookmark on the working
804 You can use :hg:`bookmark NAME` to set a bookmark on the working
805 directory's parent revision with the given name. If you specify
805 directory's parent revision with the given name. If you specify
806 a revision using -r REV (where REV may be an existing bookmark),
806 a revision using -r REV (where REV may be an existing bookmark),
807 the bookmark is assigned to that revision.
807 the bookmark is assigned to that revision.
808
808
809 Bookmarks can be pushed and pulled between repositories (see :hg:`help
809 Bookmarks can be pushed and pulled between repositories (see :hg:`help
810 push` and :hg:`help pull`). This requires both the local and remote
810 push` and :hg:`help pull`). This requires both the local and remote
811 repositories to support bookmarks. For versions prior to 1.8, this means
811 repositories to support bookmarks. For versions prior to 1.8, this means
812 the bookmarks extension must be enabled.
812 the bookmarks extension must be enabled.
813
813
814 If you set a bookmark called '@', new clones of the repository will
814 If you set a bookmark called '@', new clones of the repository will
815 have that revision checked out (and the bookmark made active) by
815 have that revision checked out (and the bookmark made active) by
816 default.
816 default.
817
817
818 With -i/--inactive, the new bookmark will not be made the active
818 With -i/--inactive, the new bookmark will not be made the active
819 bookmark. If -r/--rev is given, the new bookmark will not be made
819 bookmark. If -r/--rev is given, the new bookmark will not be made
820 active even if -i/--inactive is not given. If no NAME is given, the
820 active even if -i/--inactive is not given. If no NAME is given, the
821 current active bookmark will be marked inactive.
821 current active bookmark will be marked inactive.
822 '''
822 '''
823 force = opts.get('force')
823 force = opts.get('force')
824 rev = opts.get('rev')
824 rev = opts.get('rev')
825 delete = opts.get('delete')
825 delete = opts.get('delete')
826 rename = opts.get('rename')
826 rename = opts.get('rename')
827 inactive = opts.get('inactive')
827 inactive = opts.get('inactive')
828
828
829 def checkformat(mark):
829 def checkformat(mark):
830 mark = mark.strip()
830 mark = mark.strip()
831 if not mark:
831 if not mark:
832 raise util.Abort(_("bookmark names cannot consist entirely of "
832 raise util.Abort(_("bookmark names cannot consist entirely of "
833 "whitespace"))
833 "whitespace"))
834 scmutil.checknewlabel(repo, mark, 'bookmark')
834 scmutil.checknewlabel(repo, mark, 'bookmark')
835 return mark
835 return mark
836
836
837 def checkconflict(repo, mark, cur, force=False, target=None):
837 def checkconflict(repo, mark, cur, force=False, target=None):
838 if mark in marks and not force:
838 if mark in marks and not force:
839 if target:
839 if target:
840 if marks[mark] == target and target == cur:
840 if marks[mark] == target and target == cur:
841 # re-activating a bookmark
841 # re-activating a bookmark
842 return
842 return
843 anc = repo.changelog.ancestors([repo[target].rev()])
843 anc = repo.changelog.ancestors([repo[target].rev()])
844 bmctx = repo[marks[mark]]
844 bmctx = repo[marks[mark]]
845 divs = [repo[b].node() for b in marks
845 divs = [repo[b].node() for b in marks
846 if b.split('@', 1)[0] == mark.split('@', 1)[0]]
846 if b.split('@', 1)[0] == mark.split('@', 1)[0]]
847
847
848 # allow resolving a single divergent bookmark even if moving
848 # allow resolving a single divergent bookmark even if moving
849 # the bookmark across branches when a revision is specified
849 # the bookmark across branches when a revision is specified
850 # that contains a divergent bookmark
850 # that contains a divergent bookmark
851 if bmctx.rev() not in anc and target in divs:
851 if bmctx.rev() not in anc and target in divs:
852 bookmarks.deletedivergent(repo, [target], mark)
852 bookmarks.deletedivergent(repo, [target], mark)
853 return
853 return
854
854
855 deletefrom = [b for b in divs
855 deletefrom = [b for b in divs
856 if repo[b].rev() in anc or b == target]
856 if repo[b].rev() in anc or b == target]
857 bookmarks.deletedivergent(repo, deletefrom, mark)
857 bookmarks.deletedivergent(repo, deletefrom, mark)
858 if bookmarks.validdest(repo, bmctx, repo[target]):
858 if bookmarks.validdest(repo, bmctx, repo[target]):
859 ui.status(_("moving bookmark '%s' forward from %s\n") %
859 ui.status(_("moving bookmark '%s' forward from %s\n") %
860 (mark, short(bmctx.node())))
860 (mark, short(bmctx.node())))
861 return
861 return
862 raise util.Abort(_("bookmark '%s' already exists "
862 raise util.Abort(_("bookmark '%s' already exists "
863 "(use -f to force)") % mark)
863 "(use -f to force)") % mark)
864 if ((mark in repo.branchmap() or mark == repo.dirstate.branch())
864 if ((mark in repo.branchmap() or mark == repo.dirstate.branch())
865 and not force):
865 and not force):
866 raise util.Abort(
866 raise util.Abort(
867 _("a bookmark cannot have the name of an existing branch"))
867 _("a bookmark cannot have the name of an existing branch"))
868
868
869 if delete and rename:
869 if delete and rename:
870 raise util.Abort(_("--delete and --rename are incompatible"))
870 raise util.Abort(_("--delete and --rename are incompatible"))
871 if delete and rev:
871 if delete and rev:
872 raise util.Abort(_("--rev is incompatible with --delete"))
872 raise util.Abort(_("--rev is incompatible with --delete"))
873 if rename and rev:
873 if rename and rev:
874 raise util.Abort(_("--rev is incompatible with --rename"))
874 raise util.Abort(_("--rev is incompatible with --rename"))
875 if not names and (delete or rev):
875 if not names and (delete or rev):
876 raise util.Abort(_("bookmark name required"))
876 raise util.Abort(_("bookmark name required"))
877
877
878 if delete or rename or names or inactive:
878 if delete or rename or names or inactive:
879 wlock = repo.wlock()
879 wlock = repo.wlock()
880 try:
880 try:
881 cur = repo.changectx('.').node()
881 cur = repo.changectx('.').node()
882 marks = repo._bookmarks
882 marks = repo._bookmarks
883 if delete:
883 if delete:
884 for mark in names:
884 for mark in names:
885 if mark not in marks:
885 if mark not in marks:
886 raise util.Abort(_("bookmark '%s' does not exist") %
886 raise util.Abort(_("bookmark '%s' does not exist") %
887 mark)
887 mark)
888 if mark == repo._bookmarkcurrent:
888 if mark == repo._bookmarkcurrent:
889 bookmarks.unsetcurrent(repo)
889 bookmarks.unsetcurrent(repo)
890 del marks[mark]
890 del marks[mark]
891 marks.write()
891 marks.write()
892
892
893 elif rename:
893 elif rename:
894 if not names:
894 if not names:
895 raise util.Abort(_("new bookmark name required"))
895 raise util.Abort(_("new bookmark name required"))
896 elif len(names) > 1:
896 elif len(names) > 1:
897 raise util.Abort(_("only one new bookmark name allowed"))
897 raise util.Abort(_("only one new bookmark name allowed"))
898 mark = checkformat(names[0])
898 mark = checkformat(names[0])
899 if rename not in marks:
899 if rename not in marks:
900 raise util.Abort(_("bookmark '%s' does not exist") % rename)
900 raise util.Abort(_("bookmark '%s' does not exist") % rename)
901 checkconflict(repo, mark, cur, force)
901 checkconflict(repo, mark, cur, force)
902 marks[mark] = marks[rename]
902 marks[mark] = marks[rename]
903 if repo._bookmarkcurrent == rename and not inactive:
903 if repo._bookmarkcurrent == rename and not inactive:
904 bookmarks.setcurrent(repo, mark)
904 bookmarks.setcurrent(repo, mark)
905 del marks[rename]
905 del marks[rename]
906 marks.write()
906 marks.write()
907
907
908 elif names:
908 elif names:
909 newact = None
909 newact = None
910 for mark in names:
910 for mark in names:
911 mark = checkformat(mark)
911 mark = checkformat(mark)
912 if newact is None:
912 if newact is None:
913 newact = mark
913 newact = mark
914 if inactive and mark == repo._bookmarkcurrent:
914 if inactive and mark == repo._bookmarkcurrent:
915 bookmarks.unsetcurrent(repo)
915 bookmarks.unsetcurrent(repo)
916 return
916 return
917 tgt = cur
917 tgt = cur
918 if rev:
918 if rev:
919 tgt = scmutil.revsingle(repo, rev).node()
919 tgt = scmutil.revsingle(repo, rev).node()
920 checkconflict(repo, mark, cur, force, tgt)
920 checkconflict(repo, mark, cur, force, tgt)
921 marks[mark] = tgt
921 marks[mark] = tgt
922 if not inactive and cur == marks[newact] and not rev:
922 if not inactive and cur == marks[newact] and not rev:
923 bookmarks.setcurrent(repo, newact)
923 bookmarks.setcurrent(repo, newact)
924 elif cur != tgt and newact == repo._bookmarkcurrent:
924 elif cur != tgt and newact == repo._bookmarkcurrent:
925 bookmarks.unsetcurrent(repo)
925 bookmarks.unsetcurrent(repo)
926 marks.write()
926 marks.write()
927
927
928 elif inactive:
928 elif inactive:
929 if len(marks) == 0:
929 if len(marks) == 0:
930 ui.status(_("no bookmarks set\n"))
930 ui.status(_("no bookmarks set\n"))
931 elif not repo._bookmarkcurrent:
931 elif not repo._bookmarkcurrent:
932 ui.status(_("no active bookmark\n"))
932 ui.status(_("no active bookmark\n"))
933 else:
933 else:
934 bookmarks.unsetcurrent(repo)
934 bookmarks.unsetcurrent(repo)
935 finally:
935 finally:
936 wlock.release()
936 wlock.release()
937 else: # show bookmarks
937 else: # show bookmarks
938 hexfn = ui.debugflag and hex or short
938 hexfn = ui.debugflag and hex or short
939 marks = repo._bookmarks
939 marks = repo._bookmarks
940 if len(marks) == 0:
940 if len(marks) == 0:
941 ui.status(_("no bookmarks set\n"))
941 ui.status(_("no bookmarks set\n"))
942 else:
942 else:
943 for bmark, n in sorted(marks.iteritems()):
943 for bmark, n in sorted(marks.iteritems()):
944 current = repo._bookmarkcurrent
944 current = repo._bookmarkcurrent
945 if bmark == current:
945 if bmark == current:
946 prefix, label = '*', 'bookmarks.current'
946 prefix, label = '*', 'bookmarks.current'
947 else:
947 else:
948 prefix, label = ' ', ''
948 prefix, label = ' ', ''
949
949
950 if ui.quiet:
950 if ui.quiet:
951 ui.write("%s\n" % bmark, label=label)
951 ui.write("%s\n" % bmark, label=label)
952 else:
952 else:
953 ui.write(" %s %-25s %d:%s\n" % (
953 ui.write(" %s %-25s %d:%s\n" % (
954 prefix, bmark, repo.changelog.rev(n), hexfn(n)),
954 prefix, bmark, repo.changelog.rev(n), hexfn(n)),
955 label=label)
955 label=label)
956
956
957 @command('branch',
957 @command('branch',
958 [('f', 'force', None,
958 [('f', 'force', None,
959 _('set branch name even if it shadows an existing branch')),
959 _('set branch name even if it shadows an existing branch')),
960 ('C', 'clean', None, _('reset branch name to parent branch name'))],
960 ('C', 'clean', None, _('reset branch name to parent branch name'))],
961 _('[-fC] [NAME]'))
961 _('[-fC] [NAME]'))
962 def branch(ui, repo, label=None, **opts):
962 def branch(ui, repo, label=None, **opts):
963 """set or show the current branch name
963 """set or show the current branch name
964
964
965 .. note::
965 .. note::
966
966
967 Branch names are permanent and global. Use :hg:`bookmark` to create a
967 Branch names are permanent and global. Use :hg:`bookmark` to create a
968 light-weight bookmark instead. See :hg:`help glossary` for more
968 light-weight bookmark instead. See :hg:`help glossary` for more
969 information about named branches and bookmarks.
969 information about named branches and bookmarks.
970
970
971 With no argument, show the current branch name. With one argument,
971 With no argument, show the current branch name. With one argument,
972 set the working directory branch name (the branch will not exist
972 set the working directory branch name (the branch will not exist
973 in the repository until the next commit). Standard practice
973 in the repository until the next commit). Standard practice
974 recommends that primary development take place on the 'default'
974 recommends that primary development take place on the 'default'
975 branch.
975 branch.
976
976
977 Unless -f/--force is specified, branch will not let you set a
977 Unless -f/--force is specified, branch will not let you set a
978 branch name that already exists, even if it's inactive.
978 branch name that already exists, even if it's inactive.
979
979
980 Use -C/--clean to reset the working directory branch to that of
980 Use -C/--clean to reset the working directory branch to that of
981 the parent of the working directory, negating a previous branch
981 the parent of the working directory, negating a previous branch
982 change.
982 change.
983
983
984 Use the command :hg:`update` to switch to an existing branch. Use
984 Use the command :hg:`update` to switch to an existing branch. Use
985 :hg:`commit --close-branch` to mark this branch as closed.
985 :hg:`commit --close-branch` to mark this branch as closed.
986
986
987 Returns 0 on success.
987 Returns 0 on success.
988 """
988 """
989 if label:
989 if label:
990 label = label.strip()
990 label = label.strip()
991
991
992 if not opts.get('clean') and not label:
992 if not opts.get('clean') and not label:
993 ui.write("%s\n" % repo.dirstate.branch())
993 ui.write("%s\n" % repo.dirstate.branch())
994 return
994 return
995
995
996 wlock = repo.wlock()
996 wlock = repo.wlock()
997 try:
997 try:
998 if opts.get('clean'):
998 if opts.get('clean'):
999 label = repo[None].p1().branch()
999 label = repo[None].p1().branch()
1000 repo.dirstate.setbranch(label)
1000 repo.dirstate.setbranch(label)
1001 ui.status(_('reset working directory to branch %s\n') % label)
1001 ui.status(_('reset working directory to branch %s\n') % label)
1002 elif label:
1002 elif label:
1003 if not opts.get('force') and label in repo.branchmap():
1003 if not opts.get('force') and label in repo.branchmap():
1004 if label not in [p.branch() for p in repo.parents()]:
1004 if label not in [p.branch() for p in repo.parents()]:
1005 raise util.Abort(_('a branch of the same name already'
1005 raise util.Abort(_('a branch of the same name already'
1006 ' exists'),
1006 ' exists'),
1007 # i18n: "it" refers to an existing branch
1007 # i18n: "it" refers to an existing branch
1008 hint=_("use 'hg update' to switch to it"))
1008 hint=_("use 'hg update' to switch to it"))
1009 scmutil.checknewlabel(repo, label, 'branch')
1009 scmutil.checknewlabel(repo, label, 'branch')
1010 repo.dirstate.setbranch(label)
1010 repo.dirstate.setbranch(label)
1011 ui.status(_('marked working directory as branch %s\n') % label)
1011 ui.status(_('marked working directory as branch %s\n') % label)
1012 ui.status(_('(branches are permanent and global, '
1012 ui.status(_('(branches are permanent and global, '
1013 'did you want a bookmark?)\n'))
1013 'did you want a bookmark?)\n'))
1014 finally:
1014 finally:
1015 wlock.release()
1015 wlock.release()
1016
1016
1017 @command('branches',
1017 @command('branches',
1018 [('a', 'active', False, _('show only branches that have unmerged heads')),
1018 [('a', 'active', False, _('show only branches that have unmerged heads')),
1019 ('c', 'closed', False, _('show normal and closed branches'))],
1019 ('c', 'closed', False, _('show normal and closed branches'))],
1020 _('[-ac]'))
1020 _('[-ac]'))
1021 def branches(ui, repo, active=False, closed=False):
1021 def branches(ui, repo, active=False, closed=False):
1022 """list repository named branches
1022 """list repository named branches
1023
1023
1024 List the repository's named branches, indicating which ones are
1024 List the repository's named branches, indicating which ones are
1025 inactive. If -c/--closed is specified, also list branches which have
1025 inactive. If -c/--closed is specified, also list branches which have
1026 been marked closed (see :hg:`commit --close-branch`).
1026 been marked closed (see :hg:`commit --close-branch`).
1027
1027
1028 If -a/--active is specified, only show active branches. A branch
1028 If -a/--active is specified, only show active branches. A branch
1029 is considered active if it contains repository heads.
1029 is considered active if it contains repository heads.
1030
1030
1031 Use the command :hg:`update` to switch to an existing branch.
1031 Use the command :hg:`update` to switch to an existing branch.
1032
1032
1033 Returns 0.
1033 Returns 0.
1034 """
1034 """
1035
1035
1036 hexfunc = ui.debugflag and hex or short
1036 hexfunc = ui.debugflag and hex or short
1037
1037
1038 allheads = set(repo.heads())
1038 allheads = set(repo.heads())
1039 branches = []
1039 branches = []
1040 for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
1040 for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
1041 isactive = not isclosed and bool(set(heads) & allheads)
1041 isactive = not isclosed and bool(set(heads) & allheads)
1042 branches.append((tag, repo[tip], isactive, not isclosed))
1042 branches.append((tag, repo[tip], isactive, not isclosed))
1043 branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]),
1043 branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]),
1044 reverse=True)
1044 reverse=True)
1045
1045
1046 for tag, ctx, isactive, isopen in branches:
1046 for tag, ctx, isactive, isopen in branches:
1047 if (not active) or isactive:
1047 if (not active) or isactive:
1048 if isactive:
1048 if isactive:
1049 label = 'branches.active'
1049 label = 'branches.active'
1050 notice = ''
1050 notice = ''
1051 elif not isopen:
1051 elif not isopen:
1052 if not closed:
1052 if not closed:
1053 continue
1053 continue
1054 label = 'branches.closed'
1054 label = 'branches.closed'
1055 notice = _(' (closed)')
1055 notice = _(' (closed)')
1056 else:
1056 else:
1057 label = 'branches.inactive'
1057 label = 'branches.inactive'
1058 notice = _(' (inactive)')
1058 notice = _(' (inactive)')
1059 if tag == repo.dirstate.branch():
1059 if tag == repo.dirstate.branch():
1060 label = 'branches.current'
1060 label = 'branches.current'
1061 rev = str(ctx.rev()).rjust(31 - encoding.colwidth(tag))
1061 rev = str(ctx.rev()).rjust(31 - encoding.colwidth(tag))
1062 rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())),
1062 rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())),
1063 'log.changeset changeset.%s' % ctx.phasestr())
1063 'log.changeset changeset.%s' % ctx.phasestr())
1064 labeledtag = ui.label(tag, label)
1064 labeledtag = ui.label(tag, label)
1065 if ui.quiet:
1065 if ui.quiet:
1066 ui.write("%s\n" % labeledtag)
1066 ui.write("%s\n" % labeledtag)
1067 else:
1067 else:
1068 ui.write("%s %s%s\n" % (labeledtag, rev, notice))
1068 ui.write("%s %s%s\n" % (labeledtag, rev, notice))
1069
1069
1070 @command('bundle',
1070 @command('bundle',
1071 [('f', 'force', None, _('run even when the destination is unrelated')),
1071 [('f', 'force', None, _('run even when the destination is unrelated')),
1072 ('r', 'rev', [], _('a changeset intended to be added to the destination'),
1072 ('r', 'rev', [], _('a changeset intended to be added to the destination'),
1073 _('REV')),
1073 _('REV')),
1074 ('b', 'branch', [], _('a specific branch you would like to bundle'),
1074 ('b', 'branch', [], _('a specific branch you would like to bundle'),
1075 _('BRANCH')),
1075 _('BRANCH')),
1076 ('', 'base', [],
1076 ('', 'base', [],
1077 _('a base changeset assumed to be available at the destination'),
1077 _('a base changeset assumed to be available at the destination'),
1078 _('REV')),
1078 _('REV')),
1079 ('a', 'all', None, _('bundle all changesets in the repository')),
1079 ('a', 'all', None, _('bundle all changesets in the repository')),
1080 ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')),
1080 ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')),
1081 ] + remoteopts,
1081 ] + remoteopts,
1082 _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]'))
1082 _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]'))
1083 def bundle(ui, repo, fname, dest=None, **opts):
1083 def bundle(ui, repo, fname, dest=None, **opts):
1084 """create a changegroup file
1084 """create a changegroup file
1085
1085
1086 Generate a compressed changegroup file collecting changesets not
1086 Generate a compressed changegroup file collecting changesets not
1087 known to be in another repository.
1087 known to be in another repository.
1088
1088
1089 If you omit the destination repository, then hg assumes the
1089 If you omit the destination repository, then hg assumes the
1090 destination will have all the nodes you specify with --base
1090 destination will have all the nodes you specify with --base
1091 parameters. To create a bundle containing all changesets, use
1091 parameters. To create a bundle containing all changesets, use
1092 -a/--all (or --base null).
1092 -a/--all (or --base null).
1093
1093
1094 You can change compression method with the -t/--type option.
1094 You can change compression method with the -t/--type option.
1095 The available compression methods are: none, bzip2, and
1095 The available compression methods are: none, bzip2, and
1096 gzip (by default, bundles are compressed using bzip2).
1096 gzip (by default, bundles are compressed using bzip2).
1097
1097
1098 The bundle file can then be transferred using conventional means
1098 The bundle file can then be transferred using conventional means
1099 and applied to another repository with the unbundle or pull
1099 and applied to another repository with the unbundle or pull
1100 command. This is useful when direct push and pull are not
1100 command. This is useful when direct push and pull are not
1101 available or when exporting an entire repository is undesirable.
1101 available or when exporting an entire repository is undesirable.
1102
1102
1103 Applying bundles preserves all changeset contents including
1103 Applying bundles preserves all changeset contents including
1104 permissions, copy/rename information, and revision history.
1104 permissions, copy/rename information, and revision history.
1105
1105
1106 Returns 0 on success, 1 if no changes found.
1106 Returns 0 on success, 1 if no changes found.
1107 """
1107 """
1108 revs = None
1108 revs = None
1109 if 'rev' in opts:
1109 if 'rev' in opts:
1110 revs = scmutil.revrange(repo, opts['rev'])
1110 revs = scmutil.revrange(repo, opts['rev'])
1111
1111
1112 bundletype = opts.get('type', 'bzip2').lower()
1112 bundletype = opts.get('type', 'bzip2').lower()
1113 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
1113 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
1114 bundletype = btypes.get(bundletype)
1114 bundletype = btypes.get(bundletype)
1115 if bundletype not in changegroup.bundletypes:
1115 if bundletype not in changegroup.bundletypes:
1116 raise util.Abort(_('unknown bundle type specified with --type'))
1116 raise util.Abort(_('unknown bundle type specified with --type'))
1117
1117
1118 if opts.get('all'):
1118 if opts.get('all'):
1119 base = ['null']
1119 base = ['null']
1120 else:
1120 else:
1121 base = scmutil.revrange(repo, opts.get('base'))
1121 base = scmutil.revrange(repo, opts.get('base'))
1122 # TODO: get desired bundlecaps from command line.
1122 # TODO: get desired bundlecaps from command line.
1123 bundlecaps = None
1123 bundlecaps = None
1124 if base:
1124 if base:
1125 if dest:
1125 if dest:
1126 raise util.Abort(_("--base is incompatible with specifying "
1126 raise util.Abort(_("--base is incompatible with specifying "
1127 "a destination"))
1127 "a destination"))
1128 common = [repo.lookup(rev) for rev in base]
1128 common = [repo.lookup(rev) for rev in base]
1129 heads = revs and map(repo.lookup, revs) or revs
1129 heads = revs and map(repo.lookup, revs) or revs
1130 cg = changegroup.getbundle(repo, 'bundle', heads=heads, common=common,
1130 cg = changegroup.getbundle(repo, 'bundle', heads=heads, common=common,
1131 bundlecaps=bundlecaps)
1131 bundlecaps=bundlecaps)
1132 outgoing = None
1132 outgoing = None
1133 else:
1133 else:
1134 dest = ui.expandpath(dest or 'default-push', dest or 'default')
1134 dest = ui.expandpath(dest or 'default-push', dest or 'default')
1135 dest, branches = hg.parseurl(dest, opts.get('branch'))
1135 dest, branches = hg.parseurl(dest, opts.get('branch'))
1136 other = hg.peer(repo, opts, dest)
1136 other = hg.peer(repo, opts, dest)
1137 revs, checkout = hg.addbranchrevs(repo, repo, branches, revs)
1137 revs, checkout = hg.addbranchrevs(repo, repo, branches, revs)
1138 heads = revs and map(repo.lookup, revs) or revs
1138 heads = revs and map(repo.lookup, revs) or revs
1139 outgoing = discovery.findcommonoutgoing(repo, other,
1139 outgoing = discovery.findcommonoutgoing(repo, other,
1140 onlyheads=heads,
1140 onlyheads=heads,
1141 force=opts.get('force'),
1141 force=opts.get('force'),
1142 portable=True)
1142 portable=True)
1143 cg = changegroup.getlocalbundle(repo, 'bundle', outgoing, bundlecaps)
1143 cg = changegroup.getlocalbundle(repo, 'bundle', outgoing, bundlecaps)
1144 if not cg:
1144 if not cg:
1145 scmutil.nochangesfound(ui, repo, outgoing and outgoing.excluded)
1145 scmutil.nochangesfound(ui, repo, outgoing and outgoing.excluded)
1146 return 1
1146 return 1
1147
1147
1148 changegroup.writebundle(cg, fname, bundletype)
1148 changegroup.writebundle(cg, fname, bundletype)
1149
1149
1150 @command('cat',
1150 @command('cat',
1151 [('o', 'output', '',
1151 [('o', 'output', '',
1152 _('print output to file with formatted name'), _('FORMAT')),
1152 _('print output to file with formatted name'), _('FORMAT')),
1153 ('r', 'rev', '', _('print the given revision'), _('REV')),
1153 ('r', 'rev', '', _('print the given revision'), _('REV')),
1154 ('', 'decode', None, _('apply any matching decode filter')),
1154 ('', 'decode', None, _('apply any matching decode filter')),
1155 ] + walkopts,
1155 ] + walkopts,
1156 _('[OPTION]... FILE...'))
1156 _('[OPTION]... FILE...'))
1157 def cat(ui, repo, file1, *pats, **opts):
1157 def cat(ui, repo, file1, *pats, **opts):
1158 """output the current or given revision of files
1158 """output the current or given revision of files
1159
1159
1160 Print the specified files as they were at the given revision. If
1160 Print the specified files as they were at the given revision. If
1161 no revision is given, the parent of the working directory is used.
1161 no revision is given, the parent of the working directory is used.
1162
1162
1163 Output may be to a file, in which case the name of the file is
1163 Output may be to a file, in which case the name of the file is
1164 given using a format string. The formatting rules as follows:
1164 given using a format string. The formatting rules as follows:
1165
1165
1166 :``%%``: literal "%" character
1166 :``%%``: literal "%" character
1167 :``%s``: basename of file being printed
1167 :``%s``: basename of file being printed
1168 :``%d``: dirname of file being printed, or '.' if in repository root
1168 :``%d``: dirname of file being printed, or '.' if in repository root
1169 :``%p``: root-relative path name of file being printed
1169 :``%p``: root-relative path name of file being printed
1170 :``%H``: changeset hash (40 hexadecimal digits)
1170 :``%H``: changeset hash (40 hexadecimal digits)
1171 :``%R``: changeset revision number
1171 :``%R``: changeset revision number
1172 :``%h``: short-form changeset hash (12 hexadecimal digits)
1172 :``%h``: short-form changeset hash (12 hexadecimal digits)
1173 :``%r``: zero-padded changeset revision number
1173 :``%r``: zero-padded changeset revision number
1174 :``%b``: basename of the exporting repository
1174 :``%b``: basename of the exporting repository
1175
1175
1176 Returns 0 on success.
1176 Returns 0 on success.
1177 """
1177 """
1178 ctx = scmutil.revsingle(repo, opts.get('rev'))
1178 ctx = scmutil.revsingle(repo, opts.get('rev'))
1179 m = scmutil.match(ctx, (file1,) + pats, opts)
1179 m = scmutil.match(ctx, (file1,) + pats, opts)
1180
1180
1181 return cmdutil.cat(ui, repo, ctx, m, '', **opts)
1181 return cmdutil.cat(ui, repo, ctx, m, '', **opts)
1182
1182
1183 @command('^clone',
1183 @command('^clone',
1184 [('U', 'noupdate', None,
1184 [('U', 'noupdate', None,
1185 _('the clone will include an empty working copy (only a repository)')),
1185 _('the clone will include an empty working copy (only a repository)')),
1186 ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')),
1186 ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')),
1187 ('r', 'rev', [], _('include the specified changeset'), _('REV')),
1187 ('r', 'rev', [], _('include the specified changeset'), _('REV')),
1188 ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')),
1188 ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')),
1189 ('', 'pull', None, _('use pull protocol to copy metadata')),
1189 ('', 'pull', None, _('use pull protocol to copy metadata')),
1190 ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')),
1190 ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')),
1191 ] + remoteopts,
1191 ] + remoteopts,
1192 _('[OPTION]... SOURCE [DEST]'))
1192 _('[OPTION]... SOURCE [DEST]'))
1193 def clone(ui, source, dest=None, **opts):
1193 def clone(ui, source, dest=None, **opts):
1194 """make a copy of an existing repository
1194 """make a copy of an existing repository
1195
1195
1196 Create a copy of an existing repository in a new directory.
1196 Create a copy of an existing repository in a new directory.
1197
1197
1198 If no destination directory name is specified, it defaults to the
1198 If no destination directory name is specified, it defaults to the
1199 basename of the source.
1199 basename of the source.
1200
1200
1201 The location of the source is added to the new repository's
1201 The location of the source is added to the new repository's
1202 ``.hg/hgrc`` file, as the default to be used for future pulls.
1202 ``.hg/hgrc`` file, as the default to be used for future pulls.
1203
1203
1204 Only local paths and ``ssh://`` URLs are supported as
1204 Only local paths and ``ssh://`` URLs are supported as
1205 destinations. For ``ssh://`` destinations, no working directory or
1205 destinations. For ``ssh://`` destinations, no working directory or
1206 ``.hg/hgrc`` will be created on the remote side.
1206 ``.hg/hgrc`` will be created on the remote side.
1207
1207
1208 To pull only a subset of changesets, specify one or more revisions
1208 To pull only a subset of changesets, specify one or more revisions
1209 identifiers with -r/--rev or branches with -b/--branch. The
1209 identifiers with -r/--rev or branches with -b/--branch. The
1210 resulting clone will contain only the specified changesets and
1210 resulting clone will contain only the specified changesets and
1211 their ancestors. These options (or 'clone src#rev dest') imply
1211 their ancestors. These options (or 'clone src#rev dest') imply
1212 --pull, even for local source repositories. Note that specifying a
1212 --pull, even for local source repositories. Note that specifying a
1213 tag will include the tagged changeset but not the changeset
1213 tag will include the tagged changeset but not the changeset
1214 containing the tag.
1214 containing the tag.
1215
1215
1216 If the source repository has a bookmark called '@' set, that
1216 If the source repository has a bookmark called '@' set, that
1217 revision will be checked out in the new repository by default.
1217 revision will be checked out in the new repository by default.
1218
1218
1219 To check out a particular version, use -u/--update, or
1219 To check out a particular version, use -u/--update, or
1220 -U/--noupdate to create a clone with no working directory.
1220 -U/--noupdate to create a clone with no working directory.
1221
1221
1222 .. container:: verbose
1222 .. container:: verbose
1223
1223
1224 For efficiency, hardlinks are used for cloning whenever the
1224 For efficiency, hardlinks are used for cloning whenever the
1225 source and destination are on the same filesystem (note this
1225 source and destination are on the same filesystem (note this
1226 applies only to the repository data, not to the working
1226 applies only to the repository data, not to the working
1227 directory). Some filesystems, such as AFS, implement hardlinking
1227 directory). Some filesystems, such as AFS, implement hardlinking
1228 incorrectly, but do not report errors. In these cases, use the
1228 incorrectly, but do not report errors. In these cases, use the
1229 --pull option to avoid hardlinking.
1229 --pull option to avoid hardlinking.
1230
1230
1231 In some cases, you can clone repositories and the working
1231 In some cases, you can clone repositories and the working
1232 directory using full hardlinks with ::
1232 directory using full hardlinks with ::
1233
1233
1234 $ cp -al REPO REPOCLONE
1234 $ cp -al REPO REPOCLONE
1235
1235
1236 This is the fastest way to clone, but it is not always safe. The
1236 This is the fastest way to clone, but it is not always safe. The
1237 operation is not atomic (making sure REPO is not modified during
1237 operation is not atomic (making sure REPO is not modified during
1238 the operation is up to you) and you have to make sure your
1238 the operation is up to you) and you have to make sure your
1239 editor breaks hardlinks (Emacs and most Linux Kernel tools do
1239 editor breaks hardlinks (Emacs and most Linux Kernel tools do
1240 so). Also, this is not compatible with certain extensions that
1240 so). Also, this is not compatible with certain extensions that
1241 place their metadata under the .hg directory, such as mq.
1241 place their metadata under the .hg directory, such as mq.
1242
1242
1243 Mercurial will update the working directory to the first applicable
1243 Mercurial will update the working directory to the first applicable
1244 revision from this list:
1244 revision from this list:
1245
1245
1246 a) null if -U or the source repository has no changesets
1246 a) null if -U or the source repository has no changesets
1247 b) if -u . and the source repository is local, the first parent of
1247 b) if -u . and the source repository is local, the first parent of
1248 the source repository's working directory
1248 the source repository's working directory
1249 c) the changeset specified with -u (if a branch name, this means the
1249 c) the changeset specified with -u (if a branch name, this means the
1250 latest head of that branch)
1250 latest head of that branch)
1251 d) the changeset specified with -r
1251 d) the changeset specified with -r
1252 e) the tipmost head specified with -b
1252 e) the tipmost head specified with -b
1253 f) the tipmost head specified with the url#branch source syntax
1253 f) the tipmost head specified with the url#branch source syntax
1254 g) the revision marked with the '@' bookmark, if present
1254 g) the revision marked with the '@' bookmark, if present
1255 h) the tipmost head of the default branch
1255 h) the tipmost head of the default branch
1256 i) tip
1256 i) tip
1257
1257
1258 Examples:
1258 Examples:
1259
1259
1260 - clone a remote repository to a new directory named hg/::
1260 - clone a remote repository to a new directory named hg/::
1261
1261
1262 hg clone http://selenic.com/hg
1262 hg clone http://selenic.com/hg
1263
1263
1264 - create a lightweight local clone::
1264 - create a lightweight local clone::
1265
1265
1266 hg clone project/ project-feature/
1266 hg clone project/ project-feature/
1267
1267
1268 - clone from an absolute path on an ssh server (note double-slash)::
1268 - clone from an absolute path on an ssh server (note double-slash)::
1269
1269
1270 hg clone ssh://user@server//home/projects/alpha/
1270 hg clone ssh://user@server//home/projects/alpha/
1271
1271
1272 - do a high-speed clone over a LAN while checking out a
1272 - do a high-speed clone over a LAN while checking out a
1273 specified version::
1273 specified version::
1274
1274
1275 hg clone --uncompressed http://server/repo -u 1.5
1275 hg clone --uncompressed http://server/repo -u 1.5
1276
1276
1277 - create a repository without changesets after a particular revision::
1277 - create a repository without changesets after a particular revision::
1278
1278
1279 hg clone -r 04e544 experimental/ good/
1279 hg clone -r 04e544 experimental/ good/
1280
1280
1281 - clone (and track) a particular named branch::
1281 - clone (and track) a particular named branch::
1282
1282
1283 hg clone http://selenic.com/hg#stable
1283 hg clone http://selenic.com/hg#stable
1284
1284
1285 See :hg:`help urls` for details on specifying URLs.
1285 See :hg:`help urls` for details on specifying URLs.
1286
1286
1287 Returns 0 on success.
1287 Returns 0 on success.
1288 """
1288 """
1289 if opts.get('noupdate') and opts.get('updaterev'):
1289 if opts.get('noupdate') and opts.get('updaterev'):
1290 raise util.Abort(_("cannot specify both --noupdate and --updaterev"))
1290 raise util.Abort(_("cannot specify both --noupdate and --updaterev"))
1291
1291
1292 r = hg.clone(ui, opts, source, dest,
1292 r = hg.clone(ui, opts, source, dest,
1293 pull=opts.get('pull'),
1293 pull=opts.get('pull'),
1294 stream=opts.get('uncompressed'),
1294 stream=opts.get('uncompressed'),
1295 rev=opts.get('rev'),
1295 rev=opts.get('rev'),
1296 update=opts.get('updaterev') or not opts.get('noupdate'),
1296 update=opts.get('updaterev') or not opts.get('noupdate'),
1297 branch=opts.get('branch'))
1297 branch=opts.get('branch'))
1298
1298
1299 return r is None
1299 return r is None
1300
1300
1301 @command('^commit|ci',
1301 @command('^commit|ci',
1302 [('A', 'addremove', None,
1302 [('A', 'addremove', None,
1303 _('mark new/missing files as added/removed before committing')),
1303 _('mark new/missing files as added/removed before committing')),
1304 ('', 'close-branch', None,
1304 ('', 'close-branch', None,
1305 _('mark a branch as closed, hiding it from the branch list')),
1305 _('mark a branch as closed, hiding it from the branch list')),
1306 ('', 'amend', None, _('amend the parent of the working dir')),
1306 ('', 'amend', None, _('amend the parent of the working dir')),
1307 ('s', 'secret', None, _('use the secret phase for committing')),
1307 ('s', 'secret', None, _('use the secret phase for committing')),
1308 ('e', 'edit', None,
1308 ('e', 'edit', None,
1309 _('further edit commit message already specified')),
1309 _('further edit commit message already specified')),
1310 ] + walkopts + commitopts + commitopts2 + subrepoopts,
1310 ] + walkopts + commitopts + commitopts2 + subrepoopts,
1311 _('[OPTION]... [FILE]...'))
1311 _('[OPTION]... [FILE]...'))
1312 def commit(ui, repo, *pats, **opts):
1312 def commit(ui, repo, *pats, **opts):
1313 """commit the specified files or all outstanding changes
1313 """commit the specified files or all outstanding changes
1314
1314
1315 Commit changes to the given files into the repository. Unlike a
1315 Commit changes to the given files into the repository. Unlike a
1316 centralized SCM, this operation is a local operation. See
1316 centralized SCM, this operation is a local operation. See
1317 :hg:`push` for a way to actively distribute your changes.
1317 :hg:`push` for a way to actively distribute your changes.
1318
1318
1319 If a list of files is omitted, all changes reported by :hg:`status`
1319 If a list of files is omitted, all changes reported by :hg:`status`
1320 will be committed.
1320 will be committed.
1321
1321
1322 If you are committing the result of a merge, do not provide any
1322 If you are committing the result of a merge, do not provide any
1323 filenames or -I/-X filters.
1323 filenames or -I/-X filters.
1324
1324
1325 If no commit message is specified, Mercurial starts your
1325 If no commit message is specified, Mercurial starts your
1326 configured editor where you can enter a message. In case your
1326 configured editor where you can enter a message. In case your
1327 commit fails, you will find a backup of your message in
1327 commit fails, you will find a backup of your message in
1328 ``.hg/last-message.txt``.
1328 ``.hg/last-message.txt``.
1329
1329
1330 The --amend flag can be used to amend the parent of the
1330 The --amend flag can be used to amend the parent of the
1331 working directory with a new commit that contains the changes
1331 working directory with a new commit that contains the changes
1332 in the parent in addition to those currently reported by :hg:`status`,
1332 in the parent in addition to those currently reported by :hg:`status`,
1333 if there are any. The old commit is stored in a backup bundle in
1333 if there are any. The old commit is stored in a backup bundle in
1334 ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle`
1334 ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle`
1335 on how to restore it).
1335 on how to restore it).
1336
1336
1337 Message, user and date are taken from the amended commit unless
1337 Message, user and date are taken from the amended commit unless
1338 specified. When a message isn't specified on the command line,
1338 specified. When a message isn't specified on the command line,
1339 the editor will open with the message of the amended commit.
1339 the editor will open with the message of the amended commit.
1340
1340
1341 It is not possible to amend public changesets (see :hg:`help phases`)
1341 It is not possible to amend public changesets (see :hg:`help phases`)
1342 or changesets that have children.
1342 or changesets that have children.
1343
1343
1344 See :hg:`help dates` for a list of formats valid for -d/--date.
1344 See :hg:`help dates` for a list of formats valid for -d/--date.
1345
1345
1346 Returns 0 on success, 1 if nothing changed.
1346 Returns 0 on success, 1 if nothing changed.
1347 """
1347 """
1348 if opts.get('subrepos'):
1348 if opts.get('subrepos'):
1349 if opts.get('amend'):
1349 if opts.get('amend'):
1350 raise util.Abort(_('cannot amend with --subrepos'))
1350 raise util.Abort(_('cannot amend with --subrepos'))
1351 # Let --subrepos on the command line override config setting.
1351 # Let --subrepos on the command line override config setting.
1352 ui.setconfig('ui', 'commitsubrepos', True, 'commit')
1352 ui.setconfig('ui', 'commitsubrepos', True, 'commit')
1353
1353
1354 # Save this for restoring it later
1354 # Save this for restoring it later
1355 oldcommitphase = ui.config('phases', 'new-commit')
1355 oldcommitphase = ui.config('phases', 'new-commit')
1356
1356
1357 cmdutil.checkunfinished(repo, commit=True)
1357 cmdutil.checkunfinished(repo, commit=True)
1358
1358
1359 branch = repo[None].branch()
1359 branch = repo[None].branch()
1360 bheads = repo.branchheads(branch)
1360 bheads = repo.branchheads(branch)
1361
1361
1362 extra = {}
1362 extra = {}
1363 if opts.get('close_branch'):
1363 if opts.get('close_branch'):
1364 extra['close'] = 1
1364 extra['close'] = 1
1365
1365
1366 if not bheads:
1366 if not bheads:
1367 raise util.Abort(_('can only close branch heads'))
1367 raise util.Abort(_('can only close branch heads'))
1368 elif opts.get('amend'):
1368 elif opts.get('amend'):
1369 if repo.parents()[0].p1().branch() != branch and \
1369 if repo.parents()[0].p1().branch() != branch and \
1370 repo.parents()[0].p2().branch() != branch:
1370 repo.parents()[0].p2().branch() != branch:
1371 raise util.Abort(_('can only close branch heads'))
1371 raise util.Abort(_('can only close branch heads'))
1372
1372
1373 if opts.get('amend'):
1373 if opts.get('amend'):
1374 if ui.configbool('ui', 'commitsubrepos'):
1374 if ui.configbool('ui', 'commitsubrepos'):
1375 raise util.Abort(_('cannot amend with ui.commitsubrepos enabled'))
1375 raise util.Abort(_('cannot amend with ui.commitsubrepos enabled'))
1376
1376
1377 old = repo['.']
1377 old = repo['.']
1378 if old.phase() == phases.public:
1378 if old.phase() == phases.public:
1379 raise util.Abort(_('cannot amend public changesets'))
1379 raise util.Abort(_('cannot amend public changesets'))
1380 if len(repo[None].parents()) > 1:
1380 if len(repo[None].parents()) > 1:
1381 raise util.Abort(_('cannot amend while merging'))
1381 raise util.Abort(_('cannot amend while merging'))
1382 if (not obsolete._enabled) and old.children():
1382 if (not obsolete._enabled) and old.children():
1383 raise util.Abort(_('cannot amend changeset with children'))
1383 raise util.Abort(_('cannot amend changeset with children'))
1384
1384
1385 # commitfunc is used only for temporary amend commit by cmdutil.amend
1385 # commitfunc is used only for temporary amend commit by cmdutil.amend
1386 def commitfunc(ui, repo, message, match, opts):
1386 def commitfunc(ui, repo, message, match, opts):
1387 return repo.commit(message,
1387 return repo.commit(message,
1388 opts.get('user') or old.user(),
1388 opts.get('user') or old.user(),
1389 opts.get('date') or old.date(),
1389 opts.get('date') or old.date(),
1390 match,
1390 match,
1391 extra=extra)
1391 extra=extra)
1392
1392
1393 current = repo._bookmarkcurrent
1393 current = repo._bookmarkcurrent
1394 marks = old.bookmarks()
1394 marks = old.bookmarks()
1395 node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts)
1395 node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts)
1396 if node == old.node():
1396 if node == old.node():
1397 ui.status(_("nothing changed\n"))
1397 ui.status(_("nothing changed\n"))
1398 return 1
1398 return 1
1399 elif marks:
1399 elif marks:
1400 ui.debug('moving bookmarks %r from %s to %s\n' %
1400 ui.debug('moving bookmarks %r from %s to %s\n' %
1401 (marks, old.hex(), hex(node)))
1401 (marks, old.hex(), hex(node)))
1402 newmarks = repo._bookmarks
1402 newmarks = repo._bookmarks
1403 for bm in marks:
1403 for bm in marks:
1404 newmarks[bm] = node
1404 newmarks[bm] = node
1405 if bm == current:
1405 if bm == current:
1406 bookmarks.setcurrent(repo, bm)
1406 bookmarks.setcurrent(repo, bm)
1407 newmarks.write()
1407 newmarks.write()
1408 else:
1408 else:
1409 def commitfunc(ui, repo, message, match, opts):
1409 def commitfunc(ui, repo, message, match, opts):
1410 try:
1410 try:
1411 if opts.get('secret'):
1411 if opts.get('secret'):
1412 ui.setconfig('phases', 'new-commit', 'secret', 'commit')
1412 ui.setconfig('phases', 'new-commit', 'secret', 'commit')
1413 # Propagate to subrepos
1413 # Propagate to subrepos
1414 repo.baseui.setconfig('phases', 'new-commit', 'secret',
1414 repo.baseui.setconfig('phases', 'new-commit', 'secret',
1415 'commit')
1415 'commit')
1416
1416
1417 return repo.commit(message, opts.get('user'), opts.get('date'),
1417 return repo.commit(message, opts.get('user'), opts.get('date'),
1418 match,
1418 match,
1419 editor=cmdutil.getcommiteditor(**opts),
1419 editor=cmdutil.getcommiteditor(**opts),
1420 extra=extra)
1420 extra=extra)
1421 finally:
1421 finally:
1422 ui.setconfig('phases', 'new-commit', oldcommitphase, 'commit')
1422 ui.setconfig('phases', 'new-commit', oldcommitphase, 'commit')
1423 repo.baseui.setconfig('phases', 'new-commit', oldcommitphase,
1423 repo.baseui.setconfig('phases', 'new-commit', oldcommitphase,
1424 'commit')
1424 'commit')
1425
1425
1426
1426
1427 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
1427 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
1428
1428
1429 if not node:
1429 if not node:
1430 stat = repo.status(match=scmutil.match(repo[None], pats, opts))
1430 stat = repo.status(match=scmutil.match(repo[None], pats, opts))
1431 if stat[3]:
1431 if stat[3]:
1432 ui.status(_("nothing changed (%d missing files, see "
1432 ui.status(_("nothing changed (%d missing files, see "
1433 "'hg status')\n") % len(stat[3]))
1433 "'hg status')\n") % len(stat[3]))
1434 else:
1434 else:
1435 ui.status(_("nothing changed\n"))
1435 ui.status(_("nothing changed\n"))
1436 return 1
1436 return 1
1437
1437
1438 cmdutil.commitstatus(repo, node, branch, bheads, opts)
1438 cmdutil.commitstatus(repo, node, branch, bheads, opts)
1439
1439
1440 @command('config|showconfig|debugconfig',
1440 @command('config|showconfig|debugconfig',
1441 [('u', 'untrusted', None, _('show untrusted configuration options')),
1441 [('u', 'untrusted', None, _('show untrusted configuration options')),
1442 ('e', 'edit', None, _('edit user config')),
1442 ('e', 'edit', None, _('edit user config')),
1443 ('l', 'local', None, _('edit repository config')),
1443 ('l', 'local', None, _('edit repository config')),
1444 ('g', 'global', None, _('edit global config'))],
1444 ('g', 'global', None, _('edit global config'))],
1445 _('[-u] [NAME]...'))
1445 _('[-u] [NAME]...'))
1446 def config(ui, repo, *values, **opts):
1446 def config(ui, repo, *values, **opts):
1447 """show combined config settings from all hgrc files
1447 """show combined config settings from all hgrc files
1448
1448
1449 With no arguments, print names and values of all config items.
1449 With no arguments, print names and values of all config items.
1450
1450
1451 With one argument of the form section.name, print just the value
1451 With one argument of the form section.name, print just the value
1452 of that config item.
1452 of that config item.
1453
1453
1454 With multiple arguments, print names and values of all config
1454 With multiple arguments, print names and values of all config
1455 items with matching section names.
1455 items with matching section names.
1456
1456
1457 With --edit, start an editor on the user-level config file. With
1457 With --edit, start an editor on the user-level config file. With
1458 --global, edit the system-wide config file. With --local, edit the
1458 --global, edit the system-wide config file. With --local, edit the
1459 repository-level config file.
1459 repository-level config file.
1460
1460
1461 With --debug, the source (filename and line number) is printed
1461 With --debug, the source (filename and line number) is printed
1462 for each config item.
1462 for each config item.
1463
1463
1464 See :hg:`help config` for more information about config files.
1464 See :hg:`help config` for more information about config files.
1465
1465
1466 Returns 0 on success.
1466 Returns 0 on success.
1467
1467
1468 """
1468 """
1469
1469
1470 if opts.get('edit') or opts.get('local') or opts.get('global'):
1470 if opts.get('edit') or opts.get('local') or opts.get('global'):
1471 if opts.get('local') and opts.get('global'):
1471 if opts.get('local') and opts.get('global'):
1472 raise util.Abort(_("can't use --local and --global together"))
1472 raise util.Abort(_("can't use --local and --global together"))
1473
1473
1474 if opts.get('local'):
1474 if opts.get('local'):
1475 if not repo:
1475 if not repo:
1476 raise util.Abort(_("can't use --local outside a repository"))
1476 raise util.Abort(_("can't use --local outside a repository"))
1477 paths = [repo.join('hgrc')]
1477 paths = [repo.join('hgrc')]
1478 elif opts.get('global'):
1478 elif opts.get('global'):
1479 paths = scmutil.systemrcpath()
1479 paths = scmutil.systemrcpath()
1480 else:
1480 else:
1481 paths = scmutil.userrcpath()
1481 paths = scmutil.userrcpath()
1482
1482
1483 for f in paths:
1483 for f in paths:
1484 if os.path.exists(f):
1484 if os.path.exists(f):
1485 break
1485 break
1486 else:
1486 else:
1487 f = paths[0]
1487 f = paths[0]
1488 fp = open(f, "w")
1488 fp = open(f, "w")
1489 fp.write(
1489 fp.write(
1490 '# example config (see "hg help config" for more info)\n'
1490 '# example config (see "hg help config" for more info)\n'
1491 '\n'
1491 '\n'
1492 '[ui]\n'
1492 '[ui]\n'
1493 '# name and email, e.g.\n'
1493 '# name and email, e.g.\n'
1494 '# username = Jane Doe <jdoe@example.com>\n'
1494 '# username = Jane Doe <jdoe@example.com>\n'
1495 'username =\n'
1495 'username =\n'
1496 '\n'
1496 '\n'
1497 '[extensions]\n'
1497 '[extensions]\n'
1498 '# uncomment these lines to enable some popular extensions\n'
1498 '# uncomment these lines to enable some popular extensions\n'
1499 '# (see "hg help extensions" for more info)\n'
1499 '# (see "hg help extensions" for more info)\n'
1500 '# pager =\n'
1500 '# pager =\n'
1501 '# progress =\n'
1501 '# progress =\n'
1502 '# color =\n')
1502 '# color =\n')
1503 fp.close()
1503 fp.close()
1504
1504
1505 editor = ui.geteditor()
1505 editor = ui.geteditor()
1506 util.system("%s \"%s\"" % (editor, f),
1506 util.system("%s \"%s\"" % (editor, f),
1507 onerr=util.Abort, errprefix=_("edit failed"),
1507 onerr=util.Abort, errprefix=_("edit failed"),
1508 out=ui.fout)
1508 out=ui.fout)
1509 return
1509 return
1510
1510
1511 for f in scmutil.rcpath():
1511 for f in scmutil.rcpath():
1512 ui.debug('read config from: %s\n' % f)
1512 ui.debug('read config from: %s\n' % f)
1513 untrusted = bool(opts.get('untrusted'))
1513 untrusted = bool(opts.get('untrusted'))
1514 if values:
1514 if values:
1515 sections = [v for v in values if '.' not in v]
1515 sections = [v for v in values if '.' not in v]
1516 items = [v for v in values if '.' in v]
1516 items = [v for v in values if '.' in v]
1517 if len(items) > 1 or items and sections:
1517 if len(items) > 1 or items and sections:
1518 raise util.Abort(_('only one config item permitted'))
1518 raise util.Abort(_('only one config item permitted'))
1519 for section, name, value in ui.walkconfig(untrusted=untrusted):
1519 for section, name, value in ui.walkconfig(untrusted=untrusted):
1520 value = str(value).replace('\n', '\\n')
1520 value = str(value).replace('\n', '\\n')
1521 sectname = section + '.' + name
1521 sectname = section + '.' + name
1522 if values:
1522 if values:
1523 for v in values:
1523 for v in values:
1524 if v == section:
1524 if v == section:
1525 ui.debug('%s: ' %
1525 ui.debug('%s: ' %
1526 ui.configsource(section, name, untrusted))
1526 ui.configsource(section, name, untrusted))
1527 ui.write('%s=%s\n' % (sectname, value))
1527 ui.write('%s=%s\n' % (sectname, value))
1528 elif v == sectname:
1528 elif v == sectname:
1529 ui.debug('%s: ' %
1529 ui.debug('%s: ' %
1530 ui.configsource(section, name, untrusted))
1530 ui.configsource(section, name, untrusted))
1531 ui.write(value, '\n')
1531 ui.write(value, '\n')
1532 else:
1532 else:
1533 ui.debug('%s: ' %
1533 ui.debug('%s: ' %
1534 ui.configsource(section, name, untrusted))
1534 ui.configsource(section, name, untrusted))
1535 ui.write('%s=%s\n' % (sectname, value))
1535 ui.write('%s=%s\n' % (sectname, value))
1536
1536
1537 @command('copy|cp',
1537 @command('copy|cp',
1538 [('A', 'after', None, _('record a copy that has already occurred')),
1538 [('A', 'after', None, _('record a copy that has already occurred')),
1539 ('f', 'force', None, _('forcibly copy over an existing managed file')),
1539 ('f', 'force', None, _('forcibly copy over an existing managed file')),
1540 ] + walkopts + dryrunopts,
1540 ] + walkopts + dryrunopts,
1541 _('[OPTION]... [SOURCE]... DEST'))
1541 _('[OPTION]... [SOURCE]... DEST'))
1542 def copy(ui, repo, *pats, **opts):
1542 def copy(ui, repo, *pats, **opts):
1543 """mark files as copied for the next commit
1543 """mark files as copied for the next commit
1544
1544
1545 Mark dest as having copies of source files. If dest is a
1545 Mark dest as having copies of source files. If dest is a
1546 directory, copies are put in that directory. If dest is a file,
1546 directory, copies are put in that directory. If dest is a file,
1547 the source must be a single file.
1547 the source must be a single file.
1548
1548
1549 By default, this command copies the contents of files as they
1549 By default, this command copies the contents of files as they
1550 exist in the working directory. If invoked with -A/--after, the
1550 exist in the working directory. If invoked with -A/--after, the
1551 operation is recorded, but no copying is performed.
1551 operation is recorded, but no copying is performed.
1552
1552
1553 This command takes effect with the next commit. To undo a copy
1553 This command takes effect with the next commit. To undo a copy
1554 before that, see :hg:`revert`.
1554 before that, see :hg:`revert`.
1555
1555
1556 Returns 0 on success, 1 if errors are encountered.
1556 Returns 0 on success, 1 if errors are encountered.
1557 """
1557 """
1558 wlock = repo.wlock(False)
1558 wlock = repo.wlock(False)
1559 try:
1559 try:
1560 return cmdutil.copy(ui, repo, pats, opts)
1560 return cmdutil.copy(ui, repo, pats, opts)
1561 finally:
1561 finally:
1562 wlock.release()
1562 wlock.release()
1563
1563
1564 @command('debugancestor', [], _('[INDEX] REV1 REV2'))
1564 @command('debugancestor', [], _('[INDEX] REV1 REV2'))
1565 def debugancestor(ui, repo, *args):
1565 def debugancestor(ui, repo, *args):
1566 """find the ancestor revision of two revisions in a given index"""
1566 """find the ancestor revision of two revisions in a given index"""
1567 if len(args) == 3:
1567 if len(args) == 3:
1568 index, rev1, rev2 = args
1568 index, rev1, rev2 = args
1569 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index)
1569 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index)
1570 lookup = r.lookup
1570 lookup = r.lookup
1571 elif len(args) == 2:
1571 elif len(args) == 2:
1572 if not repo:
1572 if not repo:
1573 raise util.Abort(_("there is no Mercurial repository here "
1573 raise util.Abort(_("there is no Mercurial repository here "
1574 "(.hg not found)"))
1574 "(.hg not found)"))
1575 rev1, rev2 = args
1575 rev1, rev2 = args
1576 r = repo.changelog
1576 r = repo.changelog
1577 lookup = repo.lookup
1577 lookup = repo.lookup
1578 else:
1578 else:
1579 raise util.Abort(_('either two or three arguments required'))
1579 raise util.Abort(_('either two or three arguments required'))
1580 a = r.ancestor(lookup(rev1), lookup(rev2))
1580 a = r.ancestor(lookup(rev1), lookup(rev2))
1581 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
1581 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
1582
1582
1583 @command('debugbuilddag',
1583 @command('debugbuilddag',
1584 [('m', 'mergeable-file', None, _('add single file mergeable changes')),
1584 [('m', 'mergeable-file', None, _('add single file mergeable changes')),
1585 ('o', 'overwritten-file', None, _('add single file all revs overwrite')),
1585 ('o', 'overwritten-file', None, _('add single file all revs overwrite')),
1586 ('n', 'new-file', None, _('add new file at each rev'))],
1586 ('n', 'new-file', None, _('add new file at each rev'))],
1587 _('[OPTION]... [TEXT]'))
1587 _('[OPTION]... [TEXT]'))
1588 def debugbuilddag(ui, repo, text=None,
1588 def debugbuilddag(ui, repo, text=None,
1589 mergeable_file=False,
1589 mergeable_file=False,
1590 overwritten_file=False,
1590 overwritten_file=False,
1591 new_file=False):
1591 new_file=False):
1592 """builds a repo with a given DAG from scratch in the current empty repo
1592 """builds a repo with a given DAG from scratch in the current empty repo
1593
1593
1594 The description of the DAG is read from stdin if not given on the
1594 The description of the DAG is read from stdin if not given on the
1595 command line.
1595 command line.
1596
1596
1597 Elements:
1597 Elements:
1598
1598
1599 - "+n" is a linear run of n nodes based on the current default parent
1599 - "+n" is a linear run of n nodes based on the current default parent
1600 - "." is a single node based on the current default parent
1600 - "." is a single node based on the current default parent
1601 - "$" resets the default parent to null (implied at the start);
1601 - "$" resets the default parent to null (implied at the start);
1602 otherwise the default parent is always the last node created
1602 otherwise the default parent is always the last node created
1603 - "<p" sets the default parent to the backref p
1603 - "<p" sets the default parent to the backref p
1604 - "*p" is a fork at parent p, which is a backref
1604 - "*p" is a fork at parent p, which is a backref
1605 - "*p1/p2" is a merge of parents p1 and p2, which are backrefs
1605 - "*p1/p2" is a merge of parents p1 and p2, which are backrefs
1606 - "/p2" is a merge of the preceding node and p2
1606 - "/p2" is a merge of the preceding node and p2
1607 - ":tag" defines a local tag for the preceding node
1607 - ":tag" defines a local tag for the preceding node
1608 - "@branch" sets the named branch for subsequent nodes
1608 - "@branch" sets the named branch for subsequent nodes
1609 - "#...\\n" is a comment up to the end of the line
1609 - "#...\\n" is a comment up to the end of the line
1610
1610
1611 Whitespace between the above elements is ignored.
1611 Whitespace between the above elements is ignored.
1612
1612
1613 A backref is either
1613 A backref is either
1614
1614
1615 - a number n, which references the node curr-n, where curr is the current
1615 - a number n, which references the node curr-n, where curr is the current
1616 node, or
1616 node, or
1617 - the name of a local tag you placed earlier using ":tag", or
1617 - the name of a local tag you placed earlier using ":tag", or
1618 - empty to denote the default parent.
1618 - empty to denote the default parent.
1619
1619
1620 All string valued-elements are either strictly alphanumeric, or must
1620 All string valued-elements are either strictly alphanumeric, or must
1621 be enclosed in double quotes ("..."), with "\\" as escape character.
1621 be enclosed in double quotes ("..."), with "\\" as escape character.
1622 """
1622 """
1623
1623
1624 if text is None:
1624 if text is None:
1625 ui.status(_("reading DAG from stdin\n"))
1625 ui.status(_("reading DAG from stdin\n"))
1626 text = ui.fin.read()
1626 text = ui.fin.read()
1627
1627
1628 cl = repo.changelog
1628 cl = repo.changelog
1629 if len(cl) > 0:
1629 if len(cl) > 0:
1630 raise util.Abort(_('repository is not empty'))
1630 raise util.Abort(_('repository is not empty'))
1631
1631
1632 # determine number of revs in DAG
1632 # determine number of revs in DAG
1633 total = 0
1633 total = 0
1634 for type, data in dagparser.parsedag(text):
1634 for type, data in dagparser.parsedag(text):
1635 if type == 'n':
1635 if type == 'n':
1636 total += 1
1636 total += 1
1637
1637
1638 if mergeable_file:
1638 if mergeable_file:
1639 linesperrev = 2
1639 linesperrev = 2
1640 # make a file with k lines per rev
1640 # make a file with k lines per rev
1641 initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)]
1641 initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)]
1642 initialmergedlines.append("")
1642 initialmergedlines.append("")
1643
1643
1644 tags = []
1644 tags = []
1645
1645
1646 lock = tr = None
1646 lock = tr = None
1647 try:
1647 try:
1648 lock = repo.lock()
1648 lock = repo.lock()
1649 tr = repo.transaction("builddag")
1649 tr = repo.transaction("builddag")
1650
1650
1651 at = -1
1651 at = -1
1652 atbranch = 'default'
1652 atbranch = 'default'
1653 nodeids = []
1653 nodeids = []
1654 id = 0
1654 id = 0
1655 ui.progress(_('building'), id, unit=_('revisions'), total=total)
1655 ui.progress(_('building'), id, unit=_('revisions'), total=total)
1656 for type, data in dagparser.parsedag(text):
1656 for type, data in dagparser.parsedag(text):
1657 if type == 'n':
1657 if type == 'n':
1658 ui.note(('node %s\n' % str(data)))
1658 ui.note(('node %s\n' % str(data)))
1659 id, ps = data
1659 id, ps = data
1660
1660
1661 files = []
1661 files = []
1662 fctxs = {}
1662 fctxs = {}
1663
1663
1664 p2 = None
1664 p2 = None
1665 if mergeable_file:
1665 if mergeable_file:
1666 fn = "mf"
1666 fn = "mf"
1667 p1 = repo[ps[0]]
1667 p1 = repo[ps[0]]
1668 if len(ps) > 1:
1668 if len(ps) > 1:
1669 p2 = repo[ps[1]]
1669 p2 = repo[ps[1]]
1670 pa = p1.ancestor(p2)
1670 pa = p1.ancestor(p2)
1671 base, local, other = [x[fn].data() for x in (pa, p1,
1671 base, local, other = [x[fn].data() for x in (pa, p1,
1672 p2)]
1672 p2)]
1673 m3 = simplemerge.Merge3Text(base, local, other)
1673 m3 = simplemerge.Merge3Text(base, local, other)
1674 ml = [l.strip() for l in m3.merge_lines()]
1674 ml = [l.strip() for l in m3.merge_lines()]
1675 ml.append("")
1675 ml.append("")
1676 elif at > 0:
1676 elif at > 0:
1677 ml = p1[fn].data().split("\n")
1677 ml = p1[fn].data().split("\n")
1678 else:
1678 else:
1679 ml = initialmergedlines
1679 ml = initialmergedlines
1680 ml[id * linesperrev] += " r%i" % id
1680 ml[id * linesperrev] += " r%i" % id
1681 mergedtext = "\n".join(ml)
1681 mergedtext = "\n".join(ml)
1682 files.append(fn)
1682 files.append(fn)
1683 fctxs[fn] = context.memfilectx(fn, mergedtext)
1683 fctxs[fn] = context.memfilectx(fn, mergedtext)
1684
1684
1685 if overwritten_file:
1685 if overwritten_file:
1686 fn = "of"
1686 fn = "of"
1687 files.append(fn)
1687 files.append(fn)
1688 fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
1688 fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
1689
1689
1690 if new_file:
1690 if new_file:
1691 fn = "nf%i" % id
1691 fn = "nf%i" % id
1692 files.append(fn)
1692 files.append(fn)
1693 fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
1693 fctxs[fn] = context.memfilectx(fn, "r%i\n" % id)
1694 if len(ps) > 1:
1694 if len(ps) > 1:
1695 if not p2:
1695 if not p2:
1696 p2 = repo[ps[1]]
1696 p2 = repo[ps[1]]
1697 for fn in p2:
1697 for fn in p2:
1698 if fn.startswith("nf"):
1698 if fn.startswith("nf"):
1699 files.append(fn)
1699 files.append(fn)
1700 fctxs[fn] = p2[fn]
1700 fctxs[fn] = p2[fn]
1701
1701
1702 def fctxfn(repo, cx, path):
1702 def fctxfn(repo, cx, path):
1703 return fctxs.get(path)
1703 return fctxs.get(path)
1704
1704
1705 if len(ps) == 0 or ps[0] < 0:
1705 if len(ps) == 0 or ps[0] < 0:
1706 pars = [None, None]
1706 pars = [None, None]
1707 elif len(ps) == 1:
1707 elif len(ps) == 1:
1708 pars = [nodeids[ps[0]], None]
1708 pars = [nodeids[ps[0]], None]
1709 else:
1709 else:
1710 pars = [nodeids[p] for p in ps]
1710 pars = [nodeids[p] for p in ps]
1711 cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn,
1711 cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn,
1712 date=(id, 0),
1712 date=(id, 0),
1713 user="debugbuilddag",
1713 user="debugbuilddag",
1714 extra={'branch': atbranch})
1714 extra={'branch': atbranch})
1715 nodeid = repo.commitctx(cx)
1715 nodeid = repo.commitctx(cx)
1716 nodeids.append(nodeid)
1716 nodeids.append(nodeid)
1717 at = id
1717 at = id
1718 elif type == 'l':
1718 elif type == 'l':
1719 id, name = data
1719 id, name = data
1720 ui.note(('tag %s\n' % name))
1720 ui.note(('tag %s\n' % name))
1721 tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name))
1721 tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name))
1722 elif type == 'a':
1722 elif type == 'a':
1723 ui.note(('branch %s\n' % data))
1723 ui.note(('branch %s\n' % data))
1724 atbranch = data
1724 atbranch = data
1725 ui.progress(_('building'), id, unit=_('revisions'), total=total)
1725 ui.progress(_('building'), id, unit=_('revisions'), total=total)
1726 tr.close()
1726 tr.close()
1727
1727
1728 if tags:
1728 if tags:
1729 repo.opener.write("localtags", "".join(tags))
1729 repo.opener.write("localtags", "".join(tags))
1730 finally:
1730 finally:
1731 ui.progress(_('building'), None)
1731 ui.progress(_('building'), None)
1732 release(tr, lock)
1732 release(tr, lock)
1733
1733
1734 @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE'))
1734 @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE'))
1735 def debugbundle(ui, bundlepath, all=None, **opts):
1735 def debugbundle(ui, bundlepath, all=None, **opts):
1736 """lists the contents of a bundle"""
1736 """lists the contents of a bundle"""
1737 f = hg.openpath(ui, bundlepath)
1737 f = hg.openpath(ui, bundlepath)
1738 try:
1738 try:
1739 gen = exchange.readbundle(ui, f, bundlepath)
1739 gen = exchange.readbundle(ui, f, bundlepath)
1740 if all:
1740 if all:
1741 ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
1741 ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
1742
1742
1743 def showchunks(named):
1743 def showchunks(named):
1744 ui.write("\n%s\n" % named)
1744 ui.write("\n%s\n" % named)
1745 chain = None
1745 chain = None
1746 while True:
1746 while True:
1747 chunkdata = gen.deltachunk(chain)
1747 chunkdata = gen.deltachunk(chain)
1748 if not chunkdata:
1748 if not chunkdata:
1749 break
1749 break
1750 node = chunkdata['node']
1750 node = chunkdata['node']
1751 p1 = chunkdata['p1']
1751 p1 = chunkdata['p1']
1752 p2 = chunkdata['p2']
1752 p2 = chunkdata['p2']
1753 cs = chunkdata['cs']
1753 cs = chunkdata['cs']
1754 deltabase = chunkdata['deltabase']
1754 deltabase = chunkdata['deltabase']
1755 delta = chunkdata['delta']
1755 delta = chunkdata['delta']
1756 ui.write("%s %s %s %s %s %s\n" %
1756 ui.write("%s %s %s %s %s %s\n" %
1757 (hex(node), hex(p1), hex(p2),
1757 (hex(node), hex(p1), hex(p2),
1758 hex(cs), hex(deltabase), len(delta)))
1758 hex(cs), hex(deltabase), len(delta)))
1759 chain = node
1759 chain = node
1760
1760
1761 chunkdata = gen.changelogheader()
1761 chunkdata = gen.changelogheader()
1762 showchunks("changelog")
1762 showchunks("changelog")
1763 chunkdata = gen.manifestheader()
1763 chunkdata = gen.manifestheader()
1764 showchunks("manifest")
1764 showchunks("manifest")
1765 while True:
1765 while True:
1766 chunkdata = gen.filelogheader()
1766 chunkdata = gen.filelogheader()
1767 if not chunkdata:
1767 if not chunkdata:
1768 break
1768 break
1769 fname = chunkdata['filename']
1769 fname = chunkdata['filename']
1770 showchunks(fname)
1770 showchunks(fname)
1771 else:
1771 else:
1772 chunkdata = gen.changelogheader()
1772 chunkdata = gen.changelogheader()
1773 chain = None
1773 chain = None
1774 while True:
1774 while True:
1775 chunkdata = gen.deltachunk(chain)
1775 chunkdata = gen.deltachunk(chain)
1776 if not chunkdata:
1776 if not chunkdata:
1777 break
1777 break
1778 node = chunkdata['node']
1778 node = chunkdata['node']
1779 ui.write("%s\n" % hex(node))
1779 ui.write("%s\n" % hex(node))
1780 chain = node
1780 chain = node
1781 finally:
1781 finally:
1782 f.close()
1782 f.close()
1783
1783
1784 @command('debugcheckstate', [], '')
1784 @command('debugcheckstate', [], '')
1785 def debugcheckstate(ui, repo):
1785 def debugcheckstate(ui, repo):
1786 """validate the correctness of the current dirstate"""
1786 """validate the correctness of the current dirstate"""
1787 parent1, parent2 = repo.dirstate.parents()
1787 parent1, parent2 = repo.dirstate.parents()
1788 m1 = repo[parent1].manifest()
1788 m1 = repo[parent1].manifest()
1789 m2 = repo[parent2].manifest()
1789 m2 = repo[parent2].manifest()
1790 errors = 0
1790 errors = 0
1791 for f in repo.dirstate:
1791 for f in repo.dirstate:
1792 state = repo.dirstate[f]
1792 state = repo.dirstate[f]
1793 if state in "nr" and f not in m1:
1793 if state in "nr" and f not in m1:
1794 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
1794 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
1795 errors += 1
1795 errors += 1
1796 if state in "a" and f in m1:
1796 if state in "a" and f in m1:
1797 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
1797 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
1798 errors += 1
1798 errors += 1
1799 if state in "m" and f not in m1 and f not in m2:
1799 if state in "m" and f not in m1 and f not in m2:
1800 ui.warn(_("%s in state %s, but not in either manifest\n") %
1800 ui.warn(_("%s in state %s, but not in either manifest\n") %
1801 (f, state))
1801 (f, state))
1802 errors += 1
1802 errors += 1
1803 for f in m1:
1803 for f in m1:
1804 state = repo.dirstate[f]
1804 state = repo.dirstate[f]
1805 if state not in "nrm":
1805 if state not in "nrm":
1806 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
1806 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
1807 errors += 1
1807 errors += 1
1808 if errors:
1808 if errors:
1809 error = _(".hg/dirstate inconsistent with current parent's manifest")
1809 error = _(".hg/dirstate inconsistent with current parent's manifest")
1810 raise util.Abort(error)
1810 raise util.Abort(error)
1811
1811
1812 @command('debugcommands', [], _('[COMMAND]'))
1812 @command('debugcommands', [], _('[COMMAND]'))
1813 def debugcommands(ui, cmd='', *args):
1813 def debugcommands(ui, cmd='', *args):
1814 """list all available commands and options"""
1814 """list all available commands and options"""
1815 for cmd, vals in sorted(table.iteritems()):
1815 for cmd, vals in sorted(table.iteritems()):
1816 cmd = cmd.split('|')[0].strip('^')
1816 cmd = cmd.split('|')[0].strip('^')
1817 opts = ', '.join([i[1] for i in vals[1]])
1817 opts = ', '.join([i[1] for i in vals[1]])
1818 ui.write('%s: %s\n' % (cmd, opts))
1818 ui.write('%s: %s\n' % (cmd, opts))
1819
1819
1820 @command('debugcomplete',
1820 @command('debugcomplete',
1821 [('o', 'options', None, _('show the command options'))],
1821 [('o', 'options', None, _('show the command options'))],
1822 _('[-o] CMD'))
1822 _('[-o] CMD'))
1823 def debugcomplete(ui, cmd='', **opts):
1823 def debugcomplete(ui, cmd='', **opts):
1824 """returns the completion list associated with the given command"""
1824 """returns the completion list associated with the given command"""
1825
1825
1826 if opts.get('options'):
1826 if opts.get('options'):
1827 options = []
1827 options = []
1828 otables = [globalopts]
1828 otables = [globalopts]
1829 if cmd:
1829 if cmd:
1830 aliases, entry = cmdutil.findcmd(cmd, table, False)
1830 aliases, entry = cmdutil.findcmd(cmd, table, False)
1831 otables.append(entry[1])
1831 otables.append(entry[1])
1832 for t in otables:
1832 for t in otables:
1833 for o in t:
1833 for o in t:
1834 if "(DEPRECATED)" in o[3]:
1834 if "(DEPRECATED)" in o[3]:
1835 continue
1835 continue
1836 if o[0]:
1836 if o[0]:
1837 options.append('-%s' % o[0])
1837 options.append('-%s' % o[0])
1838 options.append('--%s' % o[1])
1838 options.append('--%s' % o[1])
1839 ui.write("%s\n" % "\n".join(options))
1839 ui.write("%s\n" % "\n".join(options))
1840 return
1840 return
1841
1841
1842 cmdlist = cmdutil.findpossible(cmd, table)
1842 cmdlist = cmdutil.findpossible(cmd, table)
1843 if ui.verbose:
1843 if ui.verbose:
1844 cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
1844 cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
1845 ui.write("%s\n" % "\n".join(sorted(cmdlist)))
1845 ui.write("%s\n" % "\n".join(sorted(cmdlist)))
1846
1846
1847 @command('debugdag',
1847 @command('debugdag',
1848 [('t', 'tags', None, _('use tags as labels')),
1848 [('t', 'tags', None, _('use tags as labels')),
1849 ('b', 'branches', None, _('annotate with branch names')),
1849 ('b', 'branches', None, _('annotate with branch names')),
1850 ('', 'dots', None, _('use dots for runs')),
1850 ('', 'dots', None, _('use dots for runs')),
1851 ('s', 'spaces', None, _('separate elements by spaces'))],
1851 ('s', 'spaces', None, _('separate elements by spaces'))],
1852 _('[OPTION]... [FILE [REV]...]'))
1852 _('[OPTION]... [FILE [REV]...]'))
1853 def debugdag(ui, repo, file_=None, *revs, **opts):
1853 def debugdag(ui, repo, file_=None, *revs, **opts):
1854 """format the changelog or an index DAG as a concise textual description
1854 """format the changelog or an index DAG as a concise textual description
1855
1855
1856 If you pass a revlog index, the revlog's DAG is emitted. If you list
1856 If you pass a revlog index, the revlog's DAG is emitted. If you list
1857 revision numbers, they get labeled in the output as rN.
1857 revision numbers, they get labeled in the output as rN.
1858
1858
1859 Otherwise, the changelog DAG of the current repo is emitted.
1859 Otherwise, the changelog DAG of the current repo is emitted.
1860 """
1860 """
1861 spaces = opts.get('spaces')
1861 spaces = opts.get('spaces')
1862 dots = opts.get('dots')
1862 dots = opts.get('dots')
1863 if file_:
1863 if file_:
1864 rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
1864 rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
1865 revs = set((int(r) for r in revs))
1865 revs = set((int(r) for r in revs))
1866 def events():
1866 def events():
1867 for r in rlog:
1867 for r in rlog:
1868 yield 'n', (r, list(set(p for p in rlog.parentrevs(r)
1868 yield 'n', (r, list(set(p for p in rlog.parentrevs(r)
1869 if p != -1)))
1869 if p != -1)))
1870 if r in revs:
1870 if r in revs:
1871 yield 'l', (r, "r%i" % r)
1871 yield 'l', (r, "r%i" % r)
1872 elif repo:
1872 elif repo:
1873 cl = repo.changelog
1873 cl = repo.changelog
1874 tags = opts.get('tags')
1874 tags = opts.get('tags')
1875 branches = opts.get('branches')
1875 branches = opts.get('branches')
1876 if tags:
1876 if tags:
1877 labels = {}
1877 labels = {}
1878 for l, n in repo.tags().items():
1878 for l, n in repo.tags().items():
1879 labels.setdefault(cl.rev(n), []).append(l)
1879 labels.setdefault(cl.rev(n), []).append(l)
1880 def events():
1880 def events():
1881 b = "default"
1881 b = "default"
1882 for r in cl:
1882 for r in cl:
1883 if branches:
1883 if branches:
1884 newb = cl.read(cl.node(r))[5]['branch']
1884 newb = cl.read(cl.node(r))[5]['branch']
1885 if newb != b:
1885 if newb != b:
1886 yield 'a', newb
1886 yield 'a', newb
1887 b = newb
1887 b = newb
1888 yield 'n', (r, list(set(p for p in cl.parentrevs(r)
1888 yield 'n', (r, list(set(p for p in cl.parentrevs(r)
1889 if p != -1)))
1889 if p != -1)))
1890 if tags:
1890 if tags:
1891 ls = labels.get(r)
1891 ls = labels.get(r)
1892 if ls:
1892 if ls:
1893 for l in ls:
1893 for l in ls:
1894 yield 'l', (r, l)
1894 yield 'l', (r, l)
1895 else:
1895 else:
1896 raise util.Abort(_('need repo for changelog dag'))
1896 raise util.Abort(_('need repo for changelog dag'))
1897
1897
1898 for line in dagparser.dagtextlines(events(),
1898 for line in dagparser.dagtextlines(events(),
1899 addspaces=spaces,
1899 addspaces=spaces,
1900 wraplabels=True,
1900 wraplabels=True,
1901 wrapannotations=True,
1901 wrapannotations=True,
1902 wrapnonlinear=dots,
1902 wrapnonlinear=dots,
1903 usedots=dots,
1903 usedots=dots,
1904 maxlinewidth=70):
1904 maxlinewidth=70):
1905 ui.write(line)
1905 ui.write(line)
1906 ui.write("\n")
1906 ui.write("\n")
1907
1907
1908 @command('debugdata',
1908 @command('debugdata',
1909 [('c', 'changelog', False, _('open changelog')),
1909 [('c', 'changelog', False, _('open changelog')),
1910 ('m', 'manifest', False, _('open manifest'))],
1910 ('m', 'manifest', False, _('open manifest'))],
1911 _('-c|-m|FILE REV'))
1911 _('-c|-m|FILE REV'))
1912 def debugdata(ui, repo, file_, rev=None, **opts):
1912 def debugdata(ui, repo, file_, rev=None, **opts):
1913 """dump the contents of a data file revision"""
1913 """dump the contents of a data file revision"""
1914 if opts.get('changelog') or opts.get('manifest'):
1914 if opts.get('changelog') or opts.get('manifest'):
1915 file_, rev = None, file_
1915 file_, rev = None, file_
1916 elif rev is None:
1916 elif rev is None:
1917 raise error.CommandError('debugdata', _('invalid arguments'))
1917 raise error.CommandError('debugdata', _('invalid arguments'))
1918 r = cmdutil.openrevlog(repo, 'debugdata', file_, opts)
1918 r = cmdutil.openrevlog(repo, 'debugdata', file_, opts)
1919 try:
1919 try:
1920 ui.write(r.revision(r.lookup(rev)))
1920 ui.write(r.revision(r.lookup(rev)))
1921 except KeyError:
1921 except KeyError:
1922 raise util.Abort(_('invalid revision identifier %s') % rev)
1922 raise util.Abort(_('invalid revision identifier %s') % rev)
1923
1923
1924 @command('debugdate',
1924 @command('debugdate',
1925 [('e', 'extended', None, _('try extended date formats'))],
1925 [('e', 'extended', None, _('try extended date formats'))],
1926 _('[-e] DATE [RANGE]'))
1926 _('[-e] DATE [RANGE]'))
1927 def debugdate(ui, date, range=None, **opts):
1927 def debugdate(ui, date, range=None, **opts):
1928 """parse and display a date"""
1928 """parse and display a date"""
1929 if opts["extended"]:
1929 if opts["extended"]:
1930 d = util.parsedate(date, util.extendeddateformats)
1930 d = util.parsedate(date, util.extendeddateformats)
1931 else:
1931 else:
1932 d = util.parsedate(date)
1932 d = util.parsedate(date)
1933 ui.write(("internal: %s %s\n") % d)
1933 ui.write(("internal: %s %s\n") % d)
1934 ui.write(("standard: %s\n") % util.datestr(d))
1934 ui.write(("standard: %s\n") % util.datestr(d))
1935 if range:
1935 if range:
1936 m = util.matchdate(range)
1936 m = util.matchdate(range)
1937 ui.write(("match: %s\n") % m(d[0]))
1937 ui.write(("match: %s\n") % m(d[0]))
1938
1938
1939 @command('debugdiscovery',
1939 @command('debugdiscovery',
1940 [('', 'old', None, _('use old-style discovery')),
1940 [('', 'old', None, _('use old-style discovery')),
1941 ('', 'nonheads', None,
1941 ('', 'nonheads', None,
1942 _('use old-style discovery with non-heads included')),
1942 _('use old-style discovery with non-heads included')),
1943 ] + remoteopts,
1943 ] + remoteopts,
1944 _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]'))
1944 _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]'))
1945 def debugdiscovery(ui, repo, remoteurl="default", **opts):
1945 def debugdiscovery(ui, repo, remoteurl="default", **opts):
1946 """runs the changeset discovery protocol in isolation"""
1946 """runs the changeset discovery protocol in isolation"""
1947 remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl),
1947 remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl),
1948 opts.get('branch'))
1948 opts.get('branch'))
1949 remote = hg.peer(repo, opts, remoteurl)
1949 remote = hg.peer(repo, opts, remoteurl)
1950 ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl))
1950 ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl))
1951
1951
1952 # make sure tests are repeatable
1952 # make sure tests are repeatable
1953 random.seed(12323)
1953 random.seed(12323)
1954
1954
1955 def doit(localheads, remoteheads, remote=remote):
1955 def doit(localheads, remoteheads, remote=remote):
1956 if opts.get('old'):
1956 if opts.get('old'):
1957 if localheads:
1957 if localheads:
1958 raise util.Abort('cannot use localheads with old style '
1958 raise util.Abort('cannot use localheads with old style '
1959 'discovery')
1959 'discovery')
1960 if not util.safehasattr(remote, 'branches'):
1960 if not util.safehasattr(remote, 'branches'):
1961 # enable in-client legacy support
1961 # enable in-client legacy support
1962 remote = localrepo.locallegacypeer(remote.local())
1962 remote = localrepo.locallegacypeer(remote.local())
1963 common, _in, hds = treediscovery.findcommonincoming(repo, remote,
1963 common, _in, hds = treediscovery.findcommonincoming(repo, remote,
1964 force=True)
1964 force=True)
1965 common = set(common)
1965 common = set(common)
1966 if not opts.get('nonheads'):
1966 if not opts.get('nonheads'):
1967 ui.write(("unpruned common: %s\n") %
1967 ui.write(("unpruned common: %s\n") %
1968 " ".join(sorted(short(n) for n in common)))
1968 " ".join(sorted(short(n) for n in common)))
1969 dag = dagutil.revlogdag(repo.changelog)
1969 dag = dagutil.revlogdag(repo.changelog)
1970 all = dag.ancestorset(dag.internalizeall(common))
1970 all = dag.ancestorset(dag.internalizeall(common))
1971 common = dag.externalizeall(dag.headsetofconnecteds(all))
1971 common = dag.externalizeall(dag.headsetofconnecteds(all))
1972 else:
1972 else:
1973 common, any, hds = setdiscovery.findcommonheads(ui, repo, remote)
1973 common, any, hds = setdiscovery.findcommonheads(ui, repo, remote)
1974 common = set(common)
1974 common = set(common)
1975 rheads = set(hds)
1975 rheads = set(hds)
1976 lheads = set(repo.heads())
1976 lheads = set(repo.heads())
1977 ui.write(("common heads: %s\n") %
1977 ui.write(("common heads: %s\n") %
1978 " ".join(sorted(short(n) for n in common)))
1978 " ".join(sorted(short(n) for n in common)))
1979 if lheads <= common:
1979 if lheads <= common:
1980 ui.write(("local is subset\n"))
1980 ui.write(("local is subset\n"))
1981 elif rheads <= common:
1981 elif rheads <= common:
1982 ui.write(("remote is subset\n"))
1982 ui.write(("remote is subset\n"))
1983
1983
1984 serverlogs = opts.get('serverlog')
1984 serverlogs = opts.get('serverlog')
1985 if serverlogs:
1985 if serverlogs:
1986 for filename in serverlogs:
1986 for filename in serverlogs:
1987 logfile = open(filename, 'r')
1987 logfile = open(filename, 'r')
1988 try:
1988 try:
1989 line = logfile.readline()
1989 line = logfile.readline()
1990 while line:
1990 while line:
1991 parts = line.strip().split(';')
1991 parts = line.strip().split(';')
1992 op = parts[1]
1992 op = parts[1]
1993 if op == 'cg':
1993 if op == 'cg':
1994 pass
1994 pass
1995 elif op == 'cgss':
1995 elif op == 'cgss':
1996 doit(parts[2].split(' '), parts[3].split(' '))
1996 doit(parts[2].split(' '), parts[3].split(' '))
1997 elif op == 'unb':
1997 elif op == 'unb':
1998 doit(parts[3].split(' '), parts[2].split(' '))
1998 doit(parts[3].split(' '), parts[2].split(' '))
1999 line = logfile.readline()
1999 line = logfile.readline()
2000 finally:
2000 finally:
2001 logfile.close()
2001 logfile.close()
2002
2002
2003 else:
2003 else:
2004 remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches,
2004 remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches,
2005 opts.get('remote_head'))
2005 opts.get('remote_head'))
2006 localrevs = opts.get('local_head')
2006 localrevs = opts.get('local_head')
2007 doit(localrevs, remoterevs)
2007 doit(localrevs, remoterevs)
2008
2008
2009 @command('debugfileset',
2009 @command('debugfileset',
2010 [('r', 'rev', '', _('apply the filespec on this revision'), _('REV'))],
2010 [('r', 'rev', '', _('apply the filespec on this revision'), _('REV'))],
2011 _('[-r REV] FILESPEC'))
2011 _('[-r REV] FILESPEC'))
2012 def debugfileset(ui, repo, expr, **opts):
2012 def debugfileset(ui, repo, expr, **opts):
2013 '''parse and apply a fileset specification'''
2013 '''parse and apply a fileset specification'''
2014 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
2014 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
2015 if ui.verbose:
2015 if ui.verbose:
2016 tree = fileset.parse(expr)[0]
2016 tree = fileset.parse(expr)[0]
2017 ui.note(tree, "\n")
2017 ui.note(tree, "\n")
2018
2018
2019 for f in ctx.getfileset(expr):
2019 for f in ctx.getfileset(expr):
2020 ui.write("%s\n" % f)
2020 ui.write("%s\n" % f)
2021
2021
2022 @command('debugfsinfo', [], _('[PATH]'))
2022 @command('debugfsinfo', [], _('[PATH]'))
2023 def debugfsinfo(ui, path="."):
2023 def debugfsinfo(ui, path="."):
2024 """show information detected about current filesystem"""
2024 """show information detected about current filesystem"""
2025 util.writefile('.debugfsinfo', '')
2025 util.writefile('.debugfsinfo', '')
2026 ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
2026 ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
2027 ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no'))
2027 ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no'))
2028 ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
2028 ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
2029 ui.write(('case-sensitive: %s\n') % (util.checkcase('.debugfsinfo')
2029 ui.write(('case-sensitive: %s\n') % (util.checkcase('.debugfsinfo')
2030 and 'yes' or 'no'))
2030 and 'yes' or 'no'))
2031 os.unlink('.debugfsinfo')
2031 os.unlink('.debugfsinfo')
2032
2032
2033 @command('debuggetbundle',
2033 @command('debuggetbundle',
2034 [('H', 'head', [], _('id of head node'), _('ID')),
2034 [('H', 'head', [], _('id of head node'), _('ID')),
2035 ('C', 'common', [], _('id of common node'), _('ID')),
2035 ('C', 'common', [], _('id of common node'), _('ID')),
2036 ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))],
2036 ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))],
2037 _('REPO FILE [-H|-C ID]...'))
2037 _('REPO FILE [-H|-C ID]...'))
2038 def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
2038 def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
2039 """retrieves a bundle from a repo
2039 """retrieves a bundle from a repo
2040
2040
2041 Every ID must be a full-length hex node id string. Saves the bundle to the
2041 Every ID must be a full-length hex node id string. Saves the bundle to the
2042 given file.
2042 given file.
2043 """
2043 """
2044 repo = hg.peer(ui, opts, repopath)
2044 repo = hg.peer(ui, opts, repopath)
2045 if not repo.capable('getbundle'):
2045 if not repo.capable('getbundle'):
2046 raise util.Abort("getbundle() not supported by target repository")
2046 raise util.Abort("getbundle() not supported by target repository")
2047 args = {}
2047 args = {}
2048 if common:
2048 if common:
2049 args['common'] = [bin(s) for s in common]
2049 args['common'] = [bin(s) for s in common]
2050 if head:
2050 if head:
2051 args['heads'] = [bin(s) for s in head]
2051 args['heads'] = [bin(s) for s in head]
2052 # TODO: get desired bundlecaps from command line.
2052 # TODO: get desired bundlecaps from command line.
2053 args['bundlecaps'] = None
2053 args['bundlecaps'] = None
2054 bundle = repo.getbundle('debug', **args)
2054 bundle = repo.getbundle('debug', **args)
2055
2055
2056 bundletype = opts.get('type', 'bzip2').lower()
2056 bundletype = opts.get('type', 'bzip2').lower()
2057 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
2057 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
2058 bundletype = btypes.get(bundletype)
2058 bundletype = btypes.get(bundletype)
2059 if bundletype not in changegroup.bundletypes:
2059 if bundletype not in changegroup.bundletypes:
2060 raise util.Abort(_('unknown bundle type specified with --type'))
2060 raise util.Abort(_('unknown bundle type specified with --type'))
2061 changegroup.writebundle(bundle, bundlepath, bundletype)
2061 changegroup.writebundle(bundle, bundlepath, bundletype)
2062
2062
2063 @command('debugignore', [], '')
2063 @command('debugignore', [], '')
2064 def debugignore(ui, repo, *values, **opts):
2064 def debugignore(ui, repo, *values, **opts):
2065 """display the combined ignore pattern"""
2065 """display the combined ignore pattern"""
2066 ignore = repo.dirstate._ignore
2066 ignore = repo.dirstate._ignore
2067 includepat = getattr(ignore, 'includepat', None)
2067 includepat = getattr(ignore, 'includepat', None)
2068 if includepat is not None:
2068 if includepat is not None:
2069 ui.write("%s\n" % includepat)
2069 ui.write("%s\n" % includepat)
2070 else:
2070 else:
2071 raise util.Abort(_("no ignore patterns found"))
2071 raise util.Abort(_("no ignore patterns found"))
2072
2072
2073 @command('debugindex',
2073 @command('debugindex',
2074 [('c', 'changelog', False, _('open changelog')),
2074 [('c', 'changelog', False, _('open changelog')),
2075 ('m', 'manifest', False, _('open manifest')),
2075 ('m', 'manifest', False, _('open manifest')),
2076 ('f', 'format', 0, _('revlog format'), _('FORMAT'))],
2076 ('f', 'format', 0, _('revlog format'), _('FORMAT'))],
2077 _('[-f FORMAT] -c|-m|FILE'))
2077 _('[-f FORMAT] -c|-m|FILE'))
2078 def debugindex(ui, repo, file_=None, **opts):
2078 def debugindex(ui, repo, file_=None, **opts):
2079 """dump the contents of an index file"""
2079 """dump the contents of an index file"""
2080 r = cmdutil.openrevlog(repo, 'debugindex', file_, opts)
2080 r = cmdutil.openrevlog(repo, 'debugindex', file_, opts)
2081 format = opts.get('format', 0)
2081 format = opts.get('format', 0)
2082 if format not in (0, 1):
2082 if format not in (0, 1):
2083 raise util.Abort(_("unknown format %d") % format)
2083 raise util.Abort(_("unknown format %d") % format)
2084
2084
2085 generaldelta = r.version & revlog.REVLOGGENERALDELTA
2085 generaldelta = r.version & revlog.REVLOGGENERALDELTA
2086 if generaldelta:
2086 if generaldelta:
2087 basehdr = ' delta'
2087 basehdr = ' delta'
2088 else:
2088 else:
2089 basehdr = ' base'
2089 basehdr = ' base'
2090
2090
2091 if format == 0:
2091 if format == 0:
2092 ui.write(" rev offset length " + basehdr + " linkrev"
2092 ui.write(" rev offset length " + basehdr + " linkrev"
2093 " nodeid p1 p2\n")
2093 " nodeid p1 p2\n")
2094 elif format == 1:
2094 elif format == 1:
2095 ui.write(" rev flag offset length"
2095 ui.write(" rev flag offset length"
2096 " size " + basehdr + " link p1 p2"
2096 " size " + basehdr + " link p1 p2"
2097 " nodeid\n")
2097 " nodeid\n")
2098
2098
2099 for i in r:
2099 for i in r:
2100 node = r.node(i)
2100 node = r.node(i)
2101 if generaldelta:
2101 if generaldelta:
2102 base = r.deltaparent(i)
2102 base = r.deltaparent(i)
2103 else:
2103 else:
2104 base = r.chainbase(i)
2104 base = r.chainbase(i)
2105 if format == 0:
2105 if format == 0:
2106 try:
2106 try:
2107 pp = r.parents(node)
2107 pp = r.parents(node)
2108 except Exception:
2108 except Exception:
2109 pp = [nullid, nullid]
2109 pp = [nullid, nullid]
2110 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
2110 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
2111 i, r.start(i), r.length(i), base, r.linkrev(i),
2111 i, r.start(i), r.length(i), base, r.linkrev(i),
2112 short(node), short(pp[0]), short(pp[1])))
2112 short(node), short(pp[0]), short(pp[1])))
2113 elif format == 1:
2113 elif format == 1:
2114 pr = r.parentrevs(i)
2114 pr = r.parentrevs(i)
2115 ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % (
2115 ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % (
2116 i, r.flags(i), r.start(i), r.length(i), r.rawsize(i),
2116 i, r.flags(i), r.start(i), r.length(i), r.rawsize(i),
2117 base, r.linkrev(i), pr[0], pr[1], short(node)))
2117 base, r.linkrev(i), pr[0], pr[1], short(node)))
2118
2118
2119 @command('debugindexdot', [], _('FILE'))
2119 @command('debugindexdot', [], _('FILE'))
2120 def debugindexdot(ui, repo, file_):
2120 def debugindexdot(ui, repo, file_):
2121 """dump an index DAG as a graphviz dot file"""
2121 """dump an index DAG as a graphviz dot file"""
2122 r = None
2122 r = None
2123 if repo:
2123 if repo:
2124 filelog = repo.file(file_)
2124 filelog = repo.file(file_)
2125 if len(filelog):
2125 if len(filelog):
2126 r = filelog
2126 r = filelog
2127 if not r:
2127 if not r:
2128 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
2128 r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_)
2129 ui.write(("digraph G {\n"))
2129 ui.write(("digraph G {\n"))
2130 for i in r:
2130 for i in r:
2131 node = r.node(i)
2131 node = r.node(i)
2132 pp = r.parents(node)
2132 pp = r.parents(node)
2133 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
2133 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
2134 if pp[1] != nullid:
2134 if pp[1] != nullid:
2135 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
2135 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
2136 ui.write("}\n")
2136 ui.write("}\n")
2137
2137
2138 @command('debuginstall', [], '')
2138 @command('debuginstall', [], '')
2139 def debuginstall(ui):
2139 def debuginstall(ui):
2140 '''test Mercurial installation
2140 '''test Mercurial installation
2141
2141
2142 Returns 0 on success.
2142 Returns 0 on success.
2143 '''
2143 '''
2144
2144
2145 def writetemp(contents):
2145 def writetemp(contents):
2146 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
2146 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
2147 f = os.fdopen(fd, "wb")
2147 f = os.fdopen(fd, "wb")
2148 f.write(contents)
2148 f.write(contents)
2149 f.close()
2149 f.close()
2150 return name
2150 return name
2151
2151
2152 problems = 0
2152 problems = 0
2153
2153
2154 # encoding
2154 # encoding
2155 ui.status(_("checking encoding (%s)...\n") % encoding.encoding)
2155 ui.status(_("checking encoding (%s)...\n") % encoding.encoding)
2156 try:
2156 try:
2157 encoding.fromlocal("test")
2157 encoding.fromlocal("test")
2158 except util.Abort, inst:
2158 except util.Abort, inst:
2159 ui.write(" %s\n" % inst)
2159 ui.write(" %s\n" % inst)
2160 ui.write(_(" (check that your locale is properly set)\n"))
2160 ui.write(_(" (check that your locale is properly set)\n"))
2161 problems += 1
2161 problems += 1
2162
2162
2163 # Python
2163 # Python
2164 ui.status(_("checking Python executable (%s)\n") % sys.executable)
2164 ui.status(_("checking Python executable (%s)\n") % sys.executable)
2165 ui.status(_("checking Python version (%s)\n")
2165 ui.status(_("checking Python version (%s)\n")
2166 % ("%s.%s.%s" % sys.version_info[:3]))
2166 % ("%s.%s.%s" % sys.version_info[:3]))
2167 ui.status(_("checking Python lib (%s)...\n")
2167 ui.status(_("checking Python lib (%s)...\n")
2168 % os.path.dirname(os.__file__))
2168 % os.path.dirname(os.__file__))
2169
2169
2170 # compiled modules
2170 # compiled modules
2171 ui.status(_("checking installed modules (%s)...\n")
2171 ui.status(_("checking installed modules (%s)...\n")
2172 % os.path.dirname(__file__))
2172 % os.path.dirname(__file__))
2173 try:
2173 try:
2174 import bdiff, mpatch, base85, osutil
2174 import bdiff, mpatch, base85, osutil
2175 dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
2175 dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
2176 except Exception, inst:
2176 except Exception, inst:
2177 ui.write(" %s\n" % inst)
2177 ui.write(" %s\n" % inst)
2178 ui.write(_(" One or more extensions could not be found"))
2178 ui.write(_(" One or more extensions could not be found"))
2179 ui.write(_(" (check that you compiled the extensions)\n"))
2179 ui.write(_(" (check that you compiled the extensions)\n"))
2180 problems += 1
2180 problems += 1
2181
2181
2182 # templates
2182 # templates
2183 import templater
2183 import templater
2184 p = templater.templatepath()
2184 p = templater.templatepath()
2185 ui.status(_("checking templates (%s)...\n") % ' '.join(p))
2185 ui.status(_("checking templates (%s)...\n") % ' '.join(p))
2186 if p:
2186 if p:
2187 m = templater.templatepath("map-cmdline.default")
2187 m = templater.templatepath("map-cmdline.default")
2188 if m:
2188 if m:
2189 # template found, check if it is working
2189 # template found, check if it is working
2190 try:
2190 try:
2191 templater.templater(m)
2191 templater.templater(m)
2192 except Exception, inst:
2192 except Exception, inst:
2193 ui.write(" %s\n" % inst)
2193 ui.write(" %s\n" % inst)
2194 p = None
2194 p = None
2195 else:
2195 else:
2196 ui.write(_(" template 'default' not found\n"))
2196 ui.write(_(" template 'default' not found\n"))
2197 p = None
2197 p = None
2198 else:
2198 else:
2199 ui.write(_(" no template directories found\n"))
2199 ui.write(_(" no template directories found\n"))
2200 if not p:
2200 if not p:
2201 ui.write(_(" (templates seem to have been installed incorrectly)\n"))
2201 ui.write(_(" (templates seem to have been installed incorrectly)\n"))
2202 problems += 1
2202 problems += 1
2203
2203
2204 # editor
2204 # editor
2205 ui.status(_("checking commit editor...\n"))
2205 ui.status(_("checking commit editor...\n"))
2206 editor = ui.geteditor()
2206 editor = ui.geteditor()
2207 cmdpath = util.findexe(editor) or util.findexe(editor.split()[0])
2207 cmdpath = util.findexe(editor) or util.findexe(editor.split()[0])
2208 if not cmdpath:
2208 if not cmdpath:
2209 if editor == 'vi':
2209 if editor == 'vi':
2210 ui.write(_(" No commit editor set and can't find vi in PATH\n"))
2210 ui.write(_(" No commit editor set and can't find vi in PATH\n"))
2211 ui.write(_(" (specify a commit editor in your configuration"
2211 ui.write(_(" (specify a commit editor in your configuration"
2212 " file)\n"))
2212 " file)\n"))
2213 else:
2213 else:
2214 ui.write(_(" Can't find editor '%s' in PATH\n") % editor)
2214 ui.write(_(" Can't find editor '%s' in PATH\n") % editor)
2215 ui.write(_(" (specify a commit editor in your configuration"
2215 ui.write(_(" (specify a commit editor in your configuration"
2216 " file)\n"))
2216 " file)\n"))
2217 problems += 1
2217 problems += 1
2218
2218
2219 # check username
2219 # check username
2220 ui.status(_("checking username...\n"))
2220 ui.status(_("checking username...\n"))
2221 try:
2221 try:
2222 ui.username()
2222 ui.username()
2223 except util.Abort, e:
2223 except util.Abort, e:
2224 ui.write(" %s\n" % e)
2224 ui.write(" %s\n" % e)
2225 ui.write(_(" (specify a username in your configuration file)\n"))
2225 ui.write(_(" (specify a username in your configuration file)\n"))
2226 problems += 1
2226 problems += 1
2227
2227
2228 if not problems:
2228 if not problems:
2229 ui.status(_("no problems detected\n"))
2229 ui.status(_("no problems detected\n"))
2230 else:
2230 else:
2231 ui.write(_("%s problems detected,"
2231 ui.write(_("%s problems detected,"
2232 " please check your install!\n") % problems)
2232 " please check your install!\n") % problems)
2233
2233
2234 return problems
2234 return problems
2235
2235
2236 @command('debugknown', [], _('REPO ID...'))
2236 @command('debugknown', [], _('REPO ID...'))
2237 def debugknown(ui, repopath, *ids, **opts):
2237 def debugknown(ui, repopath, *ids, **opts):
2238 """test whether node ids are known to a repo
2238 """test whether node ids are known to a repo
2239
2239
2240 Every ID must be a full-length hex node id string. Returns a list of 0s
2240 Every ID must be a full-length hex node id string. Returns a list of 0s
2241 and 1s indicating unknown/known.
2241 and 1s indicating unknown/known.
2242 """
2242 """
2243 repo = hg.peer(ui, opts, repopath)
2243 repo = hg.peer(ui, opts, repopath)
2244 if not repo.capable('known'):
2244 if not repo.capable('known'):
2245 raise util.Abort("known() not supported by target repository")
2245 raise util.Abort("known() not supported by target repository")
2246 flags = repo.known([bin(s) for s in ids])
2246 flags = repo.known([bin(s) for s in ids])
2247 ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags])))
2247 ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags])))
2248
2248
2249 @command('debuglabelcomplete', [], _('LABEL...'))
2249 @command('debuglabelcomplete', [], _('LABEL...'))
2250 def debuglabelcomplete(ui, repo, *args):
2250 def debuglabelcomplete(ui, repo, *args):
2251 '''complete "labels" - tags, open branch names, bookmark names'''
2251 '''complete "labels" - tags, open branch names, bookmark names'''
2252
2252
2253 labels = set()
2253 labels = set()
2254 labels.update(t[0] for t in repo.tagslist())
2254 labels.update(t[0] for t in repo.tagslist())
2255 labels.update(repo._bookmarks.keys())
2255 labels.update(repo._bookmarks.keys())
2256 labels.update(tag for (tag, heads, tip, closed)
2256 labels.update(tag for (tag, heads, tip, closed)
2257 in repo.branchmap().iterbranches() if not closed)
2257 in repo.branchmap().iterbranches() if not closed)
2258 completions = set()
2258 completions = set()
2259 if not args:
2259 if not args:
2260 args = ['']
2260 args = ['']
2261 for a in args:
2261 for a in args:
2262 completions.update(l for l in labels if l.startswith(a))
2262 completions.update(l for l in labels if l.startswith(a))
2263 ui.write('\n'.join(sorted(completions)))
2263 ui.write('\n'.join(sorted(completions)))
2264 ui.write('\n')
2264 ui.write('\n')
2265
2265
2266 @command('debugobsolete',
2266 @command('debugobsolete',
2267 [('', 'flags', 0, _('markers flag')),
2267 [('', 'flags', 0, _('markers flag')),
2268 ] + commitopts2,
2268 ] + commitopts2,
2269 _('[OBSOLETED [REPLACEMENT] [REPL... ]'))
2269 _('[OBSOLETED [REPLACEMENT] [REPL... ]'))
2270 def debugobsolete(ui, repo, precursor=None, *successors, **opts):
2270 def debugobsolete(ui, repo, precursor=None, *successors, **opts):
2271 """create arbitrary obsolete marker
2271 """create arbitrary obsolete marker
2272
2272
2273 With no arguments, displays the list of obsolescence markers."""
2273 With no arguments, displays the list of obsolescence markers."""
2274 def parsenodeid(s):
2274 def parsenodeid(s):
2275 try:
2275 try:
2276 # We do not use revsingle/revrange functions here to accept
2276 # We do not use revsingle/revrange functions here to accept
2277 # arbitrary node identifiers, possibly not present in the
2277 # arbitrary node identifiers, possibly not present in the
2278 # local repository.
2278 # local repository.
2279 n = bin(s)
2279 n = bin(s)
2280 if len(n) != len(nullid):
2280 if len(n) != len(nullid):
2281 raise TypeError()
2281 raise TypeError()
2282 return n
2282 return n
2283 except TypeError:
2283 except TypeError:
2284 raise util.Abort('changeset references must be full hexadecimal '
2284 raise util.Abort('changeset references must be full hexadecimal '
2285 'node identifiers')
2285 'node identifiers')
2286
2286
2287 if precursor is not None:
2287 if precursor is not None:
2288 metadata = {}
2288 metadata = {}
2289 if 'date' in opts:
2289 if 'date' in opts:
2290 metadata['date'] = opts['date']
2290 metadata['date'] = opts['date']
2291 metadata['user'] = opts['user'] or ui.username()
2291 metadata['user'] = opts['user'] or ui.username()
2292 succs = tuple(parsenodeid(succ) for succ in successors)
2292 succs = tuple(parsenodeid(succ) for succ in successors)
2293 l = repo.lock()
2293 l = repo.lock()
2294 try:
2294 try:
2295 tr = repo.transaction('debugobsolete')
2295 tr = repo.transaction('debugobsolete')
2296 try:
2296 try:
2297 repo.obsstore.create(tr, parsenodeid(precursor), succs,
2297 repo.obsstore.create(tr, parsenodeid(precursor), succs,
2298 opts['flags'], metadata)
2298 opts['flags'], metadata)
2299 tr.close()
2299 tr.close()
2300 finally:
2300 finally:
2301 tr.release()
2301 tr.release()
2302 finally:
2302 finally:
2303 l.release()
2303 l.release()
2304 else:
2304 else:
2305 for m in obsolete.allmarkers(repo):
2305 for m in obsolete.allmarkers(repo):
2306 cmdutil.showmarker(ui, m)
2306 cmdutil.showmarker(ui, m)
2307
2307
2308 @command('debugpathcomplete',
2308 @command('debugpathcomplete',
2309 [('f', 'full', None, _('complete an entire path')),
2309 [('f', 'full', None, _('complete an entire path')),
2310 ('n', 'normal', None, _('show only normal files')),
2310 ('n', 'normal', None, _('show only normal files')),
2311 ('a', 'added', None, _('show only added files')),
2311 ('a', 'added', None, _('show only added files')),
2312 ('r', 'removed', None, _('show only removed files'))],
2312 ('r', 'removed', None, _('show only removed files'))],
2313 _('FILESPEC...'))
2313 _('FILESPEC...'))
2314 def debugpathcomplete(ui, repo, *specs, **opts):
2314 def debugpathcomplete(ui, repo, *specs, **opts):
2315 '''complete part or all of a tracked path
2315 '''complete part or all of a tracked path
2316
2316
2317 This command supports shells that offer path name completion. It
2317 This command supports shells that offer path name completion. It
2318 currently completes only files already known to the dirstate.
2318 currently completes only files already known to the dirstate.
2319
2319
2320 Completion extends only to the next path segment unless
2320 Completion extends only to the next path segment unless
2321 --full is specified, in which case entire paths are used.'''
2321 --full is specified, in which case entire paths are used.'''
2322
2322
2323 def complete(path, acceptable):
2323 def complete(path, acceptable):
2324 dirstate = repo.dirstate
2324 dirstate = repo.dirstate
2325 spec = os.path.normpath(os.path.join(os.getcwd(), path))
2325 spec = os.path.normpath(os.path.join(os.getcwd(), path))
2326 rootdir = repo.root + os.sep
2326 rootdir = repo.root + os.sep
2327 if spec != repo.root and not spec.startswith(rootdir):
2327 if spec != repo.root and not spec.startswith(rootdir):
2328 return [], []
2328 return [], []
2329 if os.path.isdir(spec):
2329 if os.path.isdir(spec):
2330 spec += '/'
2330 spec += '/'
2331 spec = spec[len(rootdir):]
2331 spec = spec[len(rootdir):]
2332 fixpaths = os.sep != '/'
2332 fixpaths = os.sep != '/'
2333 if fixpaths:
2333 if fixpaths:
2334 spec = spec.replace(os.sep, '/')
2334 spec = spec.replace(os.sep, '/')
2335 speclen = len(spec)
2335 speclen = len(spec)
2336 fullpaths = opts['full']
2336 fullpaths = opts['full']
2337 files, dirs = set(), set()
2337 files, dirs = set(), set()
2338 adddir, addfile = dirs.add, files.add
2338 adddir, addfile = dirs.add, files.add
2339 for f, st in dirstate.iteritems():
2339 for f, st in dirstate.iteritems():
2340 if f.startswith(spec) and st[0] in acceptable:
2340 if f.startswith(spec) and st[0] in acceptable:
2341 if fixpaths:
2341 if fixpaths:
2342 f = f.replace('/', os.sep)
2342 f = f.replace('/', os.sep)
2343 if fullpaths:
2343 if fullpaths:
2344 addfile(f)
2344 addfile(f)
2345 continue
2345 continue
2346 s = f.find(os.sep, speclen)
2346 s = f.find(os.sep, speclen)
2347 if s >= 0:
2347 if s >= 0:
2348 adddir(f[:s])
2348 adddir(f[:s])
2349 else:
2349 else:
2350 addfile(f)
2350 addfile(f)
2351 return files, dirs
2351 return files, dirs
2352
2352
2353 acceptable = ''
2353 acceptable = ''
2354 if opts['normal']:
2354 if opts['normal']:
2355 acceptable += 'nm'
2355 acceptable += 'nm'
2356 if opts['added']:
2356 if opts['added']:
2357 acceptable += 'a'
2357 acceptable += 'a'
2358 if opts['removed']:
2358 if opts['removed']:
2359 acceptable += 'r'
2359 acceptable += 'r'
2360 cwd = repo.getcwd()
2360 cwd = repo.getcwd()
2361 if not specs:
2361 if not specs:
2362 specs = ['.']
2362 specs = ['.']
2363
2363
2364 files, dirs = set(), set()
2364 files, dirs = set(), set()
2365 for spec in specs:
2365 for spec in specs:
2366 f, d = complete(spec, acceptable or 'nmar')
2366 f, d = complete(spec, acceptable or 'nmar')
2367 files.update(f)
2367 files.update(f)
2368 dirs.update(d)
2368 dirs.update(d)
2369 files.update(dirs)
2369 files.update(dirs)
2370 ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
2370 ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
2371 ui.write('\n')
2371 ui.write('\n')
2372
2372
2373 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'))
2373 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'))
2374 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
2374 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
2375 '''access the pushkey key/value protocol
2375 '''access the pushkey key/value protocol
2376
2376
2377 With two args, list the keys in the given namespace.
2377 With two args, list the keys in the given namespace.
2378
2378
2379 With five args, set a key to new if it currently is set to old.
2379 With five args, set a key to new if it currently is set to old.
2380 Reports success or failure.
2380 Reports success or failure.
2381 '''
2381 '''
2382
2382
2383 target = hg.peer(ui, {}, repopath)
2383 target = hg.peer(ui, {}, repopath)
2384 if keyinfo:
2384 if keyinfo:
2385 key, old, new = keyinfo
2385 key, old, new = keyinfo
2386 r = target.pushkey(namespace, key, old, new)
2386 r = target.pushkey(namespace, key, old, new)
2387 ui.status(str(r) + '\n')
2387 ui.status(str(r) + '\n')
2388 return not r
2388 return not r
2389 else:
2389 else:
2390 for k, v in sorted(target.listkeys(namespace).iteritems()):
2390 for k, v in sorted(target.listkeys(namespace).iteritems()):
2391 ui.write("%s\t%s\n" % (k.encode('string-escape'),
2391 ui.write("%s\t%s\n" % (k.encode('string-escape'),
2392 v.encode('string-escape')))
2392 v.encode('string-escape')))
2393
2393
2394 @command('debugpvec', [], _('A B'))
2394 @command('debugpvec', [], _('A B'))
2395 def debugpvec(ui, repo, a, b=None):
2395 def debugpvec(ui, repo, a, b=None):
2396 ca = scmutil.revsingle(repo, a)
2396 ca = scmutil.revsingle(repo, a)
2397 cb = scmutil.revsingle(repo, b)
2397 cb = scmutil.revsingle(repo, b)
2398 pa = pvec.ctxpvec(ca)
2398 pa = pvec.ctxpvec(ca)
2399 pb = pvec.ctxpvec(cb)
2399 pb = pvec.ctxpvec(cb)
2400 if pa == pb:
2400 if pa == pb:
2401 rel = "="
2401 rel = "="
2402 elif pa > pb:
2402 elif pa > pb:
2403 rel = ">"
2403 rel = ">"
2404 elif pa < pb:
2404 elif pa < pb:
2405 rel = "<"
2405 rel = "<"
2406 elif pa | pb:
2406 elif pa | pb:
2407 rel = "|"
2407 rel = "|"
2408 ui.write(_("a: %s\n") % pa)
2408 ui.write(_("a: %s\n") % pa)
2409 ui.write(_("b: %s\n") % pb)
2409 ui.write(_("b: %s\n") % pb)
2410 ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth))
2410 ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth))
2411 ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") %
2411 ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") %
2412 (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec),
2412 (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec),
2413 pa.distance(pb), rel))
2413 pa.distance(pb), rel))
2414
2414
2415 @command('debugrebuilddirstate|debugrebuildstate',
2415 @command('debugrebuilddirstate|debugrebuildstate',
2416 [('r', 'rev', '', _('revision to rebuild to'), _('REV'))],
2416 [('r', 'rev', '', _('revision to rebuild to'), _('REV'))],
2417 _('[-r REV]'))
2417 _('[-r REV]'))
2418 def debugrebuilddirstate(ui, repo, rev):
2418 def debugrebuilddirstate(ui, repo, rev):
2419 """rebuild the dirstate as it would look like for the given revision
2419 """rebuild the dirstate as it would look like for the given revision
2420
2420
2421 If no revision is specified the first current parent will be used.
2421 If no revision is specified the first current parent will be used.
2422
2422
2423 The dirstate will be set to the files of the given revision.
2423 The dirstate will be set to the files of the given revision.
2424 The actual working directory content or existing dirstate
2424 The actual working directory content or existing dirstate
2425 information such as adds or removes is not considered.
2425 information such as adds or removes is not considered.
2426
2426
2427 One use of this command is to make the next :hg:`status` invocation
2427 One use of this command is to make the next :hg:`status` invocation
2428 check the actual file content.
2428 check the actual file content.
2429 """
2429 """
2430 ctx = scmutil.revsingle(repo, rev)
2430 ctx = scmutil.revsingle(repo, rev)
2431 wlock = repo.wlock()
2431 wlock = repo.wlock()
2432 try:
2432 try:
2433 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
2433 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
2434 finally:
2434 finally:
2435 wlock.release()
2435 wlock.release()
2436
2436
2437 @command('debugrename',
2437 @command('debugrename',
2438 [('r', 'rev', '', _('revision to debug'), _('REV'))],
2438 [('r', 'rev', '', _('revision to debug'), _('REV'))],
2439 _('[-r REV] FILE'))
2439 _('[-r REV] FILE'))
2440 def debugrename(ui, repo, file1, *pats, **opts):
2440 def debugrename(ui, repo, file1, *pats, **opts):
2441 """dump rename information"""
2441 """dump rename information"""
2442
2442
2443 ctx = scmutil.revsingle(repo, opts.get('rev'))
2443 ctx = scmutil.revsingle(repo, opts.get('rev'))
2444 m = scmutil.match(ctx, (file1,) + pats, opts)
2444 m = scmutil.match(ctx, (file1,) + pats, opts)
2445 for abs in ctx.walk(m):
2445 for abs in ctx.walk(m):
2446 fctx = ctx[abs]
2446 fctx = ctx[abs]
2447 o = fctx.filelog().renamed(fctx.filenode())
2447 o = fctx.filelog().renamed(fctx.filenode())
2448 rel = m.rel(abs)
2448 rel = m.rel(abs)
2449 if o:
2449 if o:
2450 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
2450 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
2451 else:
2451 else:
2452 ui.write(_("%s not renamed\n") % rel)
2452 ui.write(_("%s not renamed\n") % rel)
2453
2453
2454 @command('debugrevlog',
2454 @command('debugrevlog',
2455 [('c', 'changelog', False, _('open changelog')),
2455 [('c', 'changelog', False, _('open changelog')),
2456 ('m', 'manifest', False, _('open manifest')),
2456 ('m', 'manifest', False, _('open manifest')),
2457 ('d', 'dump', False, _('dump index data'))],
2457 ('d', 'dump', False, _('dump index data'))],
2458 _('-c|-m|FILE'))
2458 _('-c|-m|FILE'))
2459 def debugrevlog(ui, repo, file_=None, **opts):
2459 def debugrevlog(ui, repo, file_=None, **opts):
2460 """show data and statistics about a revlog"""
2460 """show data and statistics about a revlog"""
2461 r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts)
2461 r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts)
2462
2462
2463 if opts.get("dump"):
2463 if opts.get("dump"):
2464 numrevs = len(r)
2464 numrevs = len(r)
2465 ui.write("# rev p1rev p2rev start end deltastart base p1 p2"
2465 ui.write("# rev p1rev p2rev start end deltastart base p1 p2"
2466 " rawsize totalsize compression heads\n")
2466 " rawsize totalsize compression heads\n")
2467 ts = 0
2467 ts = 0
2468 heads = set()
2468 heads = set()
2469 for rev in xrange(numrevs):
2469 for rev in xrange(numrevs):
2470 dbase = r.deltaparent(rev)
2470 dbase = r.deltaparent(rev)
2471 if dbase == -1:
2471 if dbase == -1:
2472 dbase = rev
2472 dbase = rev
2473 cbase = r.chainbase(rev)
2473 cbase = r.chainbase(rev)
2474 p1, p2 = r.parentrevs(rev)
2474 p1, p2 = r.parentrevs(rev)
2475 rs = r.rawsize(rev)
2475 rs = r.rawsize(rev)
2476 ts = ts + rs
2476 ts = ts + rs
2477 heads -= set(r.parentrevs(rev))
2477 heads -= set(r.parentrevs(rev))
2478 heads.add(rev)
2478 heads.add(rev)
2479 ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d %11d %5d\n" %
2479 ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d %11d %5d\n" %
2480 (rev, p1, p2, r.start(rev), r.end(rev),
2480 (rev, p1, p2, r.start(rev), r.end(rev),
2481 r.start(dbase), r.start(cbase),
2481 r.start(dbase), r.start(cbase),
2482 r.start(p1), r.start(p2),
2482 r.start(p1), r.start(p2),
2483 rs, ts, ts / r.end(rev), len(heads)))
2483 rs, ts, ts / r.end(rev), len(heads)))
2484 return 0
2484 return 0
2485
2485
2486 v = r.version
2486 v = r.version
2487 format = v & 0xFFFF
2487 format = v & 0xFFFF
2488 flags = []
2488 flags = []
2489 gdelta = False
2489 gdelta = False
2490 if v & revlog.REVLOGNGINLINEDATA:
2490 if v & revlog.REVLOGNGINLINEDATA:
2491 flags.append('inline')
2491 flags.append('inline')
2492 if v & revlog.REVLOGGENERALDELTA:
2492 if v & revlog.REVLOGGENERALDELTA:
2493 gdelta = True
2493 gdelta = True
2494 flags.append('generaldelta')
2494 flags.append('generaldelta')
2495 if not flags:
2495 if not flags:
2496 flags = ['(none)']
2496 flags = ['(none)']
2497
2497
2498 nummerges = 0
2498 nummerges = 0
2499 numfull = 0
2499 numfull = 0
2500 numprev = 0
2500 numprev = 0
2501 nump1 = 0
2501 nump1 = 0
2502 nump2 = 0
2502 nump2 = 0
2503 numother = 0
2503 numother = 0
2504 nump1prev = 0
2504 nump1prev = 0
2505 nump2prev = 0
2505 nump2prev = 0
2506 chainlengths = []
2506 chainlengths = []
2507
2507
2508 datasize = [None, 0, 0L]
2508 datasize = [None, 0, 0L]
2509 fullsize = [None, 0, 0L]
2509 fullsize = [None, 0, 0L]
2510 deltasize = [None, 0, 0L]
2510 deltasize = [None, 0, 0L]
2511
2511
2512 def addsize(size, l):
2512 def addsize(size, l):
2513 if l[0] is None or size < l[0]:
2513 if l[0] is None or size < l[0]:
2514 l[0] = size
2514 l[0] = size
2515 if size > l[1]:
2515 if size > l[1]:
2516 l[1] = size
2516 l[1] = size
2517 l[2] += size
2517 l[2] += size
2518
2518
2519 numrevs = len(r)
2519 numrevs = len(r)
2520 for rev in xrange(numrevs):
2520 for rev in xrange(numrevs):
2521 p1, p2 = r.parentrevs(rev)
2521 p1, p2 = r.parentrevs(rev)
2522 delta = r.deltaparent(rev)
2522 delta = r.deltaparent(rev)
2523 if format > 0:
2523 if format > 0:
2524 addsize(r.rawsize(rev), datasize)
2524 addsize(r.rawsize(rev), datasize)
2525 if p2 != nullrev:
2525 if p2 != nullrev:
2526 nummerges += 1
2526 nummerges += 1
2527 size = r.length(rev)
2527 size = r.length(rev)
2528 if delta == nullrev:
2528 if delta == nullrev:
2529 chainlengths.append(0)
2529 chainlengths.append(0)
2530 numfull += 1
2530 numfull += 1
2531 addsize(size, fullsize)
2531 addsize(size, fullsize)
2532 else:
2532 else:
2533 chainlengths.append(chainlengths[delta] + 1)
2533 chainlengths.append(chainlengths[delta] + 1)
2534 addsize(size, deltasize)
2534 addsize(size, deltasize)
2535 if delta == rev - 1:
2535 if delta == rev - 1:
2536 numprev += 1
2536 numprev += 1
2537 if delta == p1:
2537 if delta == p1:
2538 nump1prev += 1
2538 nump1prev += 1
2539 elif delta == p2:
2539 elif delta == p2:
2540 nump2prev += 1
2540 nump2prev += 1
2541 elif delta == p1:
2541 elif delta == p1:
2542 nump1 += 1
2542 nump1 += 1
2543 elif delta == p2:
2543 elif delta == p2:
2544 nump2 += 1
2544 nump2 += 1
2545 elif delta != nullrev:
2545 elif delta != nullrev:
2546 numother += 1
2546 numother += 1
2547
2547
2548 # Adjust size min value for empty cases
2548 # Adjust size min value for empty cases
2549 for size in (datasize, fullsize, deltasize):
2549 for size in (datasize, fullsize, deltasize):
2550 if size[0] is None:
2550 if size[0] is None:
2551 size[0] = 0
2551 size[0] = 0
2552
2552
2553 numdeltas = numrevs - numfull
2553 numdeltas = numrevs - numfull
2554 numoprev = numprev - nump1prev - nump2prev
2554 numoprev = numprev - nump1prev - nump2prev
2555 totalrawsize = datasize[2]
2555 totalrawsize = datasize[2]
2556 datasize[2] /= numrevs
2556 datasize[2] /= numrevs
2557 fulltotal = fullsize[2]
2557 fulltotal = fullsize[2]
2558 fullsize[2] /= numfull
2558 fullsize[2] /= numfull
2559 deltatotal = deltasize[2]
2559 deltatotal = deltasize[2]
2560 if numrevs - numfull > 0:
2560 if numrevs - numfull > 0:
2561 deltasize[2] /= numrevs - numfull
2561 deltasize[2] /= numrevs - numfull
2562 totalsize = fulltotal + deltatotal
2562 totalsize = fulltotal + deltatotal
2563 avgchainlen = sum(chainlengths) / numrevs
2563 avgchainlen = sum(chainlengths) / numrevs
2564 compratio = totalrawsize / totalsize
2564 compratio = totalrawsize / totalsize
2565
2565
2566 basedfmtstr = '%%%dd\n'
2566 basedfmtstr = '%%%dd\n'
2567 basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n'
2567 basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n'
2568
2568
2569 def dfmtstr(max):
2569 def dfmtstr(max):
2570 return basedfmtstr % len(str(max))
2570 return basedfmtstr % len(str(max))
2571 def pcfmtstr(max, padding=0):
2571 def pcfmtstr(max, padding=0):
2572 return basepcfmtstr % (len(str(max)), ' ' * padding)
2572 return basepcfmtstr % (len(str(max)), ' ' * padding)
2573
2573
2574 def pcfmt(value, total):
2574 def pcfmt(value, total):
2575 return (value, 100 * float(value) / total)
2575 return (value, 100 * float(value) / total)
2576
2576
2577 ui.write(('format : %d\n') % format)
2577 ui.write(('format : %d\n') % format)
2578 ui.write(('flags : %s\n') % ', '.join(flags))
2578 ui.write(('flags : %s\n') % ', '.join(flags))
2579
2579
2580 ui.write('\n')
2580 ui.write('\n')
2581 fmt = pcfmtstr(totalsize)
2581 fmt = pcfmtstr(totalsize)
2582 fmt2 = dfmtstr(totalsize)
2582 fmt2 = dfmtstr(totalsize)
2583 ui.write(('revisions : ') + fmt2 % numrevs)
2583 ui.write(('revisions : ') + fmt2 % numrevs)
2584 ui.write((' merges : ') + fmt % pcfmt(nummerges, numrevs))
2584 ui.write((' merges : ') + fmt % pcfmt(nummerges, numrevs))
2585 ui.write((' normal : ') + fmt % pcfmt(numrevs - nummerges, numrevs))
2585 ui.write((' normal : ') + fmt % pcfmt(numrevs - nummerges, numrevs))
2586 ui.write(('revisions : ') + fmt2 % numrevs)
2586 ui.write(('revisions : ') + fmt2 % numrevs)
2587 ui.write((' full : ') + fmt % pcfmt(numfull, numrevs))
2587 ui.write((' full : ') + fmt % pcfmt(numfull, numrevs))
2588 ui.write((' deltas : ') + fmt % pcfmt(numdeltas, numrevs))
2588 ui.write((' deltas : ') + fmt % pcfmt(numdeltas, numrevs))
2589 ui.write(('revision size : ') + fmt2 % totalsize)
2589 ui.write(('revision size : ') + fmt2 % totalsize)
2590 ui.write((' full : ') + fmt % pcfmt(fulltotal, totalsize))
2590 ui.write((' full : ') + fmt % pcfmt(fulltotal, totalsize))
2591 ui.write((' deltas : ') + fmt % pcfmt(deltatotal, totalsize))
2591 ui.write((' deltas : ') + fmt % pcfmt(deltatotal, totalsize))
2592
2592
2593 ui.write('\n')
2593 ui.write('\n')
2594 fmt = dfmtstr(max(avgchainlen, compratio))
2594 fmt = dfmtstr(max(avgchainlen, compratio))
2595 ui.write(('avg chain length : ') + fmt % avgchainlen)
2595 ui.write(('avg chain length : ') + fmt % avgchainlen)
2596 ui.write(('compression ratio : ') + fmt % compratio)
2596 ui.write(('compression ratio : ') + fmt % compratio)
2597
2597
2598 if format > 0:
2598 if format > 0:
2599 ui.write('\n')
2599 ui.write('\n')
2600 ui.write(('uncompressed data size (min/max/avg) : %d / %d / %d\n')
2600 ui.write(('uncompressed data size (min/max/avg) : %d / %d / %d\n')
2601 % tuple(datasize))
2601 % tuple(datasize))
2602 ui.write(('full revision size (min/max/avg) : %d / %d / %d\n')
2602 ui.write(('full revision size (min/max/avg) : %d / %d / %d\n')
2603 % tuple(fullsize))
2603 % tuple(fullsize))
2604 ui.write(('delta size (min/max/avg) : %d / %d / %d\n')
2604 ui.write(('delta size (min/max/avg) : %d / %d / %d\n')
2605 % tuple(deltasize))
2605 % tuple(deltasize))
2606
2606
2607 if numdeltas > 0:
2607 if numdeltas > 0:
2608 ui.write('\n')
2608 ui.write('\n')
2609 fmt = pcfmtstr(numdeltas)
2609 fmt = pcfmtstr(numdeltas)
2610 fmt2 = pcfmtstr(numdeltas, 4)
2610 fmt2 = pcfmtstr(numdeltas, 4)
2611 ui.write(('deltas against prev : ') + fmt % pcfmt(numprev, numdeltas))
2611 ui.write(('deltas against prev : ') + fmt % pcfmt(numprev, numdeltas))
2612 if numprev > 0:
2612 if numprev > 0:
2613 ui.write((' where prev = p1 : ') + fmt2 % pcfmt(nump1prev,
2613 ui.write((' where prev = p1 : ') + fmt2 % pcfmt(nump1prev,
2614 numprev))
2614 numprev))
2615 ui.write((' where prev = p2 : ') + fmt2 % pcfmt(nump2prev,
2615 ui.write((' where prev = p2 : ') + fmt2 % pcfmt(nump2prev,
2616 numprev))
2616 numprev))
2617 ui.write((' other : ') + fmt2 % pcfmt(numoprev,
2617 ui.write((' other : ') + fmt2 % pcfmt(numoprev,
2618 numprev))
2618 numprev))
2619 if gdelta:
2619 if gdelta:
2620 ui.write(('deltas against p1 : ')
2620 ui.write(('deltas against p1 : ')
2621 + fmt % pcfmt(nump1, numdeltas))
2621 + fmt % pcfmt(nump1, numdeltas))
2622 ui.write(('deltas against p2 : ')
2622 ui.write(('deltas against p2 : ')
2623 + fmt % pcfmt(nump2, numdeltas))
2623 + fmt % pcfmt(nump2, numdeltas))
2624 ui.write(('deltas against other : ') + fmt % pcfmt(numother,
2624 ui.write(('deltas against other : ') + fmt % pcfmt(numother,
2625 numdeltas))
2625 numdeltas))
2626
2626
2627 @command('debugrevspec',
2627 @command('debugrevspec',
2628 [('', 'optimize', None, _('print parsed tree after optimizing'))],
2628 [('', 'optimize', None, _('print parsed tree after optimizing'))],
2629 ('REVSPEC'))
2629 ('REVSPEC'))
2630 def debugrevspec(ui, repo, expr, **opts):
2630 def debugrevspec(ui, repo, expr, **opts):
2631 """parse and apply a revision specification
2631 """parse and apply a revision specification
2632
2632
2633 Use --verbose to print the parsed tree before and after aliases
2633 Use --verbose to print the parsed tree before and after aliases
2634 expansion.
2634 expansion.
2635 """
2635 """
2636 if ui.verbose:
2636 if ui.verbose:
2637 tree = revset.parse(expr)[0]
2637 tree = revset.parse(expr)[0]
2638 ui.note(revset.prettyformat(tree), "\n")
2638 ui.note(revset.prettyformat(tree), "\n")
2639 newtree = revset.findaliases(ui, tree)
2639 newtree = revset.findaliases(ui, tree)
2640 if newtree != tree:
2640 if newtree != tree:
2641 ui.note(revset.prettyformat(newtree), "\n")
2641 ui.note(revset.prettyformat(newtree), "\n")
2642 if opts["optimize"]:
2642 if opts["optimize"]:
2643 weight, optimizedtree = revset.optimize(newtree, True)
2643 weight, optimizedtree = revset.optimize(newtree, True)
2644 ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n")
2644 ui.note("* optimized:\n", revset.prettyformat(optimizedtree), "\n")
2645 func = revset.match(ui, expr)
2645 func = revset.match(ui, expr)
2646 for c in func(repo, revset.spanset(repo)):
2646 for c in func(repo, revset.spanset(repo)):
2647 ui.write("%s\n" % c)
2647 ui.write("%s\n" % c)
2648
2648
2649 @command('debugsetparents', [], _('REV1 [REV2]'))
2649 @command('debugsetparents', [], _('REV1 [REV2]'))
2650 def debugsetparents(ui, repo, rev1, rev2=None):
2650 def debugsetparents(ui, repo, rev1, rev2=None):
2651 """manually set the parents of the current working directory
2651 """manually set the parents of the current working directory
2652
2652
2653 This is useful for writing repository conversion tools, but should
2653 This is useful for writing repository conversion tools, but should
2654 be used with care.
2654 be used with care.
2655
2655
2656 Returns 0 on success.
2656 Returns 0 on success.
2657 """
2657 """
2658
2658
2659 r1 = scmutil.revsingle(repo, rev1).node()
2659 r1 = scmutil.revsingle(repo, rev1).node()
2660 r2 = scmutil.revsingle(repo, rev2, 'null').node()
2660 r2 = scmutil.revsingle(repo, rev2, 'null').node()
2661
2661
2662 wlock = repo.wlock()
2662 wlock = repo.wlock()
2663 try:
2663 try:
2664 repo.setparents(r1, r2)
2664 repo.setparents(r1, r2)
2665 finally:
2665 finally:
2666 wlock.release()
2666 wlock.release()
2667
2667
2668 @command('debugdirstate|debugstate',
2668 @command('debugdirstate|debugstate',
2669 [('', 'nodates', None, _('do not display the saved mtime')),
2669 [('', 'nodates', None, _('do not display the saved mtime')),
2670 ('', 'datesort', None, _('sort by saved mtime'))],
2670 ('', 'datesort', None, _('sort by saved mtime'))],
2671 _('[OPTION]...'))
2671 _('[OPTION]...'))
2672 def debugstate(ui, repo, nodates=None, datesort=None):
2672 def debugstate(ui, repo, nodates=None, datesort=None):
2673 """show the contents of the current dirstate"""
2673 """show the contents of the current dirstate"""
2674 timestr = ""
2674 timestr = ""
2675 showdate = not nodates
2675 showdate = not nodates
2676 if datesort:
2676 if datesort:
2677 keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename
2677 keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename
2678 else:
2678 else:
2679 keyfunc = None # sort by filename
2679 keyfunc = None # sort by filename
2680 for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc):
2680 for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc):
2681 if showdate:
2681 if showdate:
2682 if ent[3] == -1:
2682 if ent[3] == -1:
2683 # Pad or slice to locale representation
2683 # Pad or slice to locale representation
2684 locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ",
2684 locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ",
2685 time.localtime(0)))
2685 time.localtime(0)))
2686 timestr = 'unset'
2686 timestr = 'unset'
2687 timestr = (timestr[:locale_len] +
2687 timestr = (timestr[:locale_len] +
2688 ' ' * (locale_len - len(timestr)))
2688 ' ' * (locale_len - len(timestr)))
2689 else:
2689 else:
2690 timestr = time.strftime("%Y-%m-%d %H:%M:%S ",
2690 timestr = time.strftime("%Y-%m-%d %H:%M:%S ",
2691 time.localtime(ent[3]))
2691 time.localtime(ent[3]))
2692 if ent[1] & 020000:
2692 if ent[1] & 020000:
2693 mode = 'lnk'
2693 mode = 'lnk'
2694 else:
2694 else:
2695 mode = '%3o' % (ent[1] & 0777 & ~util.umask)
2695 mode = '%3o' % (ent[1] & 0777 & ~util.umask)
2696 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
2696 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
2697 for f in repo.dirstate.copies():
2697 for f in repo.dirstate.copies():
2698 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
2698 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
2699
2699
2700 @command('debugsub',
2700 @command('debugsub',
2701 [('r', 'rev', '',
2701 [('r', 'rev', '',
2702 _('revision to check'), _('REV'))],
2702 _('revision to check'), _('REV'))],
2703 _('[-r REV] [REV]'))
2703 _('[-r REV] [REV]'))
2704 def debugsub(ui, repo, rev=None):
2704 def debugsub(ui, repo, rev=None):
2705 ctx = scmutil.revsingle(repo, rev, None)
2705 ctx = scmutil.revsingle(repo, rev, None)
2706 for k, v in sorted(ctx.substate.items()):
2706 for k, v in sorted(ctx.substate.items()):
2707 ui.write(('path %s\n') % k)
2707 ui.write(('path %s\n') % k)
2708 ui.write((' source %s\n') % v[0])
2708 ui.write((' source %s\n') % v[0])
2709 ui.write((' revision %s\n') % v[1])
2709 ui.write((' revision %s\n') % v[1])
2710
2710
2711 @command('debugsuccessorssets',
2711 @command('debugsuccessorssets',
2712 [],
2712 [],
2713 _('[REV]'))
2713 _('[REV]'))
2714 def debugsuccessorssets(ui, repo, *revs):
2714 def debugsuccessorssets(ui, repo, *revs):
2715 """show set of successors for revision
2715 """show set of successors for revision
2716
2716
2717 A successors set of changeset A is a consistent group of revisions that
2717 A successors set of changeset A is a consistent group of revisions that
2718 succeed A. It contains non-obsolete changesets only.
2718 succeed A. It contains non-obsolete changesets only.
2719
2719
2720 In most cases a changeset A has a single successors set containing a single
2720 In most cases a changeset A has a single successors set containing a single
2721 successor (changeset A replaced by A').
2721 successor (changeset A replaced by A').
2722
2722
2723 A changeset that is made obsolete with no successors are called "pruned".
2723 A changeset that is made obsolete with no successors are called "pruned".
2724 Such changesets have no successors sets at all.
2724 Such changesets have no successors sets at all.
2725
2725
2726 A changeset that has been "split" will have a successors set containing
2726 A changeset that has been "split" will have a successors set containing
2727 more than one successor.
2727 more than one successor.
2728
2728
2729 A changeset that has been rewritten in multiple different ways is called
2729 A changeset that has been rewritten in multiple different ways is called
2730 "divergent". Such changesets have multiple successor sets (each of which
2730 "divergent". Such changesets have multiple successor sets (each of which
2731 may also be split, i.e. have multiple successors).
2731 may also be split, i.e. have multiple successors).
2732
2732
2733 Results are displayed as follows::
2733 Results are displayed as follows::
2734
2734
2735 <rev1>
2735 <rev1>
2736 <successors-1A>
2736 <successors-1A>
2737 <rev2>
2737 <rev2>
2738 <successors-2A>
2738 <successors-2A>
2739 <successors-2B1> <successors-2B2> <successors-2B3>
2739 <successors-2B1> <successors-2B2> <successors-2B3>
2740
2740
2741 Here rev2 has two possible (i.e. divergent) successors sets. The first
2741 Here rev2 has two possible (i.e. divergent) successors sets. The first
2742 holds one element, whereas the second holds three (i.e. the changeset has
2742 holds one element, whereas the second holds three (i.e. the changeset has
2743 been split).
2743 been split).
2744 """
2744 """
2745 # passed to successorssets caching computation from one call to another
2745 # passed to successorssets caching computation from one call to another
2746 cache = {}
2746 cache = {}
2747 ctx2str = str
2747 ctx2str = str
2748 node2str = short
2748 node2str = short
2749 if ui.debug():
2749 if ui.debug():
2750 def ctx2str(ctx):
2750 def ctx2str(ctx):
2751 return ctx.hex()
2751 return ctx.hex()
2752 node2str = hex
2752 node2str = hex
2753 for rev in scmutil.revrange(repo, revs):
2753 for rev in scmutil.revrange(repo, revs):
2754 ctx = repo[rev]
2754 ctx = repo[rev]
2755 ui.write('%s\n'% ctx2str(ctx))
2755 ui.write('%s\n'% ctx2str(ctx))
2756 for succsset in obsolete.successorssets(repo, ctx.node(), cache):
2756 for succsset in obsolete.successorssets(repo, ctx.node(), cache):
2757 if succsset:
2757 if succsset:
2758 ui.write(' ')
2758 ui.write(' ')
2759 ui.write(node2str(succsset[0]))
2759 ui.write(node2str(succsset[0]))
2760 for node in succsset[1:]:
2760 for node in succsset[1:]:
2761 ui.write(' ')
2761 ui.write(' ')
2762 ui.write(node2str(node))
2762 ui.write(node2str(node))
2763 ui.write('\n')
2763 ui.write('\n')
2764
2764
2765 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'))
2765 @command('debugwalk', walkopts, _('[OPTION]... [FILE]...'))
2766 def debugwalk(ui, repo, *pats, **opts):
2766 def debugwalk(ui, repo, *pats, **opts):
2767 """show how files match on given patterns"""
2767 """show how files match on given patterns"""
2768 m = scmutil.match(repo[None], pats, opts)
2768 m = scmutil.match(repo[None], pats, opts)
2769 items = list(repo.walk(m))
2769 items = list(repo.walk(m))
2770 if not items:
2770 if not items:
2771 return
2771 return
2772 f = lambda fn: fn
2772 f = lambda fn: fn
2773 if ui.configbool('ui', 'slash') and os.sep != '/':
2773 if ui.configbool('ui', 'slash') and os.sep != '/':
2774 f = lambda fn: util.normpath(fn)
2774 f = lambda fn: util.normpath(fn)
2775 fmt = 'f %%-%ds %%-%ds %%s' % (
2775 fmt = 'f %%-%ds %%-%ds %%s' % (
2776 max([len(abs) for abs in items]),
2776 max([len(abs) for abs in items]),
2777 max([len(m.rel(abs)) for abs in items]))
2777 max([len(m.rel(abs)) for abs in items]))
2778 for abs in items:
2778 for abs in items:
2779 line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '')
2779 line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '')
2780 ui.write("%s\n" % line.rstrip())
2780 ui.write("%s\n" % line.rstrip())
2781
2781
2782 @command('debugwireargs',
2782 @command('debugwireargs',
2783 [('', 'three', '', 'three'),
2783 [('', 'three', '', 'three'),
2784 ('', 'four', '', 'four'),
2784 ('', 'four', '', 'four'),
2785 ('', 'five', '', 'five'),
2785 ('', 'five', '', 'five'),
2786 ] + remoteopts,
2786 ] + remoteopts,
2787 _('REPO [OPTIONS]... [ONE [TWO]]'))
2787 _('REPO [OPTIONS]... [ONE [TWO]]'))
2788 def debugwireargs(ui, repopath, *vals, **opts):
2788 def debugwireargs(ui, repopath, *vals, **opts):
2789 repo = hg.peer(ui, opts, repopath)
2789 repo = hg.peer(ui, opts, repopath)
2790 for opt in remoteopts:
2790 for opt in remoteopts:
2791 del opts[opt[1]]
2791 del opts[opt[1]]
2792 args = {}
2792 args = {}
2793 for k, v in opts.iteritems():
2793 for k, v in opts.iteritems():
2794 if v:
2794 if v:
2795 args[k] = v
2795 args[k] = v
2796 # run twice to check that we don't mess up the stream for the next command
2796 # run twice to check that we don't mess up the stream for the next command
2797 res1 = repo.debugwireargs(*vals, **args)
2797 res1 = repo.debugwireargs(*vals, **args)
2798 res2 = repo.debugwireargs(*vals, **args)
2798 res2 = repo.debugwireargs(*vals, **args)
2799 ui.write("%s\n" % res1)
2799 ui.write("%s\n" % res1)
2800 if res1 != res2:
2800 if res1 != res2:
2801 ui.warn("%s\n" % res2)
2801 ui.warn("%s\n" % res2)
2802
2802
2803 @command('^diff',
2803 @command('^diff',
2804 [('r', 'rev', [], _('revision'), _('REV')),
2804 [('r', 'rev', [], _('revision'), _('REV')),
2805 ('c', 'change', '', _('change made by revision'), _('REV'))
2805 ('c', 'change', '', _('change made by revision'), _('REV'))
2806 ] + diffopts + diffopts2 + walkopts + subrepoopts,
2806 ] + diffopts + diffopts2 + walkopts + subrepoopts,
2807 _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'))
2807 _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'))
2808 def diff(ui, repo, *pats, **opts):
2808 def diff(ui, repo, *pats, **opts):
2809 """diff repository (or selected files)
2809 """diff repository (or selected files)
2810
2810
2811 Show differences between revisions for the specified files.
2811 Show differences between revisions for the specified files.
2812
2812
2813 Differences between files are shown using the unified diff format.
2813 Differences between files are shown using the unified diff format.
2814
2814
2815 .. note::
2815 .. note::
2816
2816
2817 diff may generate unexpected results for merges, as it will
2817 diff may generate unexpected results for merges, as it will
2818 default to comparing against the working directory's first
2818 default to comparing against the working directory's first
2819 parent changeset if no revisions are specified.
2819 parent changeset if no revisions are specified.
2820
2820
2821 When two revision arguments are given, then changes are shown
2821 When two revision arguments are given, then changes are shown
2822 between those revisions. If only one revision is specified then
2822 between those revisions. If only one revision is specified then
2823 that revision is compared to the working directory, and, when no
2823 that revision is compared to the working directory, and, when no
2824 revisions are specified, the working directory files are compared
2824 revisions are specified, the working directory files are compared
2825 to its parent.
2825 to its parent.
2826
2826
2827 Alternatively you can specify -c/--change with a revision to see
2827 Alternatively you can specify -c/--change with a revision to see
2828 the changes in that changeset relative to its first parent.
2828 the changes in that changeset relative to its first parent.
2829
2829
2830 Without the -a/--text option, diff will avoid generating diffs of
2830 Without the -a/--text option, diff will avoid generating diffs of
2831 files it detects as binary. With -a, diff will generate a diff
2831 files it detects as binary. With -a, diff will generate a diff
2832 anyway, probably with undesirable results.
2832 anyway, probably with undesirable results.
2833
2833
2834 Use the -g/--git option to generate diffs in the git extended diff
2834 Use the -g/--git option to generate diffs in the git extended diff
2835 format. For more information, read :hg:`help diffs`.
2835 format. For more information, read :hg:`help diffs`.
2836
2836
2837 .. container:: verbose
2837 .. container:: verbose
2838
2838
2839 Examples:
2839 Examples:
2840
2840
2841 - compare a file in the current working directory to its parent::
2841 - compare a file in the current working directory to its parent::
2842
2842
2843 hg diff foo.c
2843 hg diff foo.c
2844
2844
2845 - compare two historical versions of a directory, with rename info::
2845 - compare two historical versions of a directory, with rename info::
2846
2846
2847 hg diff --git -r 1.0:1.2 lib/
2847 hg diff --git -r 1.0:1.2 lib/
2848
2848
2849 - get change stats relative to the last change on some date::
2849 - get change stats relative to the last change on some date::
2850
2850
2851 hg diff --stat -r "date('may 2')"
2851 hg diff --stat -r "date('may 2')"
2852
2852
2853 - diff all newly-added files that contain a keyword::
2853 - diff all newly-added files that contain a keyword::
2854
2854
2855 hg diff "set:added() and grep(GNU)"
2855 hg diff "set:added() and grep(GNU)"
2856
2856
2857 - compare a revision and its parents::
2857 - compare a revision and its parents::
2858
2858
2859 hg diff -c 9353 # compare against first parent
2859 hg diff -c 9353 # compare against first parent
2860 hg diff -r 9353^:9353 # same using revset syntax
2860 hg diff -r 9353^:9353 # same using revset syntax
2861 hg diff -r 9353^2:9353 # compare against the second parent
2861 hg diff -r 9353^2:9353 # compare against the second parent
2862
2862
2863 Returns 0 on success.
2863 Returns 0 on success.
2864 """
2864 """
2865
2865
2866 revs = opts.get('rev')
2866 revs = opts.get('rev')
2867 change = opts.get('change')
2867 change = opts.get('change')
2868 stat = opts.get('stat')
2868 stat = opts.get('stat')
2869 reverse = opts.get('reverse')
2869 reverse = opts.get('reverse')
2870
2870
2871 if revs and change:
2871 if revs and change:
2872 msg = _('cannot specify --rev and --change at the same time')
2872 msg = _('cannot specify --rev and --change at the same time')
2873 raise util.Abort(msg)
2873 raise util.Abort(msg)
2874 elif change:
2874 elif change:
2875 node2 = scmutil.revsingle(repo, change, None).node()
2875 node2 = scmutil.revsingle(repo, change, None).node()
2876 node1 = repo[node2].p1().node()
2876 node1 = repo[node2].p1().node()
2877 else:
2877 else:
2878 node1, node2 = scmutil.revpair(repo, revs)
2878 node1, node2 = scmutil.revpair(repo, revs)
2879
2879
2880 if reverse:
2880 if reverse:
2881 node1, node2 = node2, node1
2881 node1, node2 = node2, node1
2882
2882
2883 diffopts = patch.diffopts(ui, opts)
2883 diffopts = patch.diffopts(ui, opts)
2884 m = scmutil.match(repo[node2], pats, opts)
2884 m = scmutil.match(repo[node2], pats, opts)
2885 cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat,
2885 cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat,
2886 listsubrepos=opts.get('subrepos'))
2886 listsubrepos=opts.get('subrepos'))
2887
2887
2888 @command('^export',
2888 @command('^export',
2889 [('o', 'output', '',
2889 [('o', 'output', '',
2890 _('print output to file with formatted name'), _('FORMAT')),
2890 _('print output to file with formatted name'), _('FORMAT')),
2891 ('', 'switch-parent', None, _('diff against the second parent')),
2891 ('', 'switch-parent', None, _('diff against the second parent')),
2892 ('r', 'rev', [], _('revisions to export'), _('REV')),
2892 ('r', 'rev', [], _('revisions to export'), _('REV')),
2893 ] + diffopts,
2893 ] + diffopts,
2894 _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'))
2894 _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'))
2895 def export(ui, repo, *changesets, **opts):
2895 def export(ui, repo, *changesets, **opts):
2896 """dump the header and diffs for one or more changesets
2896 """dump the header and diffs for one or more changesets
2897
2897
2898 Print the changeset header and diffs for one or more revisions.
2898 Print the changeset header and diffs for one or more revisions.
2899 If no revision is given, the parent of the working directory is used.
2899 If no revision is given, the parent of the working directory is used.
2900
2900
2901 The information shown in the changeset header is: author, date,
2901 The information shown in the changeset header is: author, date,
2902 branch name (if non-default), changeset hash, parent(s) and commit
2902 branch name (if non-default), changeset hash, parent(s) and commit
2903 comment.
2903 comment.
2904
2904
2905 .. note::
2905 .. note::
2906
2906
2907 export may generate unexpected diff output for merge
2907 export may generate unexpected diff output for merge
2908 changesets, as it will compare the merge changeset against its
2908 changesets, as it will compare the merge changeset against its
2909 first parent only.
2909 first parent only.
2910
2910
2911 Output may be to a file, in which case the name of the file is
2911 Output may be to a file, in which case the name of the file is
2912 given using a format string. The formatting rules are as follows:
2912 given using a format string. The formatting rules are as follows:
2913
2913
2914 :``%%``: literal "%" character
2914 :``%%``: literal "%" character
2915 :``%H``: changeset hash (40 hexadecimal digits)
2915 :``%H``: changeset hash (40 hexadecimal digits)
2916 :``%N``: number of patches being generated
2916 :``%N``: number of patches being generated
2917 :``%R``: changeset revision number
2917 :``%R``: changeset revision number
2918 :``%b``: basename of the exporting repository
2918 :``%b``: basename of the exporting repository
2919 :``%h``: short-form changeset hash (12 hexadecimal digits)
2919 :``%h``: short-form changeset hash (12 hexadecimal digits)
2920 :``%m``: first line of the commit message (only alphanumeric characters)
2920 :``%m``: first line of the commit message (only alphanumeric characters)
2921 :``%n``: zero-padded sequence number, starting at 1
2921 :``%n``: zero-padded sequence number, starting at 1
2922 :``%r``: zero-padded changeset revision number
2922 :``%r``: zero-padded changeset revision number
2923
2923
2924 Without the -a/--text option, export will avoid generating diffs
2924 Without the -a/--text option, export will avoid generating diffs
2925 of files it detects as binary. With -a, export will generate a
2925 of files it detects as binary. With -a, export will generate a
2926 diff anyway, probably with undesirable results.
2926 diff anyway, probably with undesirable results.
2927
2927
2928 Use the -g/--git option to generate diffs in the git extended diff
2928 Use the -g/--git option to generate diffs in the git extended diff
2929 format. See :hg:`help diffs` for more information.
2929 format. See :hg:`help diffs` for more information.
2930
2930
2931 With the --switch-parent option, the diff will be against the
2931 With the --switch-parent option, the diff will be against the
2932 second parent. It can be useful to review a merge.
2932 second parent. It can be useful to review a merge.
2933
2933
2934 .. container:: verbose
2934 .. container:: verbose
2935
2935
2936 Examples:
2936 Examples:
2937
2937
2938 - use export and import to transplant a bugfix to the current
2938 - use export and import to transplant a bugfix to the current
2939 branch::
2939 branch::
2940
2940
2941 hg export -r 9353 | hg import -
2941 hg export -r 9353 | hg import -
2942
2942
2943 - export all the changesets between two revisions to a file with
2943 - export all the changesets between two revisions to a file with
2944 rename information::
2944 rename information::
2945
2945
2946 hg export --git -r 123:150 > changes.txt
2946 hg export --git -r 123:150 > changes.txt
2947
2947
2948 - split outgoing changes into a series of patches with
2948 - split outgoing changes into a series of patches with
2949 descriptive names::
2949 descriptive names::
2950
2950
2951 hg export -r "outgoing()" -o "%n-%m.patch"
2951 hg export -r "outgoing()" -o "%n-%m.patch"
2952
2952
2953 Returns 0 on success.
2953 Returns 0 on success.
2954 """
2954 """
2955 changesets += tuple(opts.get('rev', []))
2955 changesets += tuple(opts.get('rev', []))
2956 if not changesets:
2956 if not changesets:
2957 changesets = ['.']
2957 changesets = ['.']
2958 revs = scmutil.revrange(repo, changesets)
2958 revs = scmutil.revrange(repo, changesets)
2959 if not revs:
2959 if not revs:
2960 raise util.Abort(_("export requires at least one changeset"))
2960 raise util.Abort(_("export requires at least one changeset"))
2961 if len(revs) > 1:
2961 if len(revs) > 1:
2962 ui.note(_('exporting patches:\n'))
2962 ui.note(_('exporting patches:\n'))
2963 else:
2963 else:
2964 ui.note(_('exporting patch:\n'))
2964 ui.note(_('exporting patch:\n'))
2965 cmdutil.export(repo, revs, template=opts.get('output'),
2965 cmdutil.export(repo, revs, template=opts.get('output'),
2966 switch_parent=opts.get('switch_parent'),
2966 switch_parent=opts.get('switch_parent'),
2967 opts=patch.diffopts(ui, opts))
2967 opts=patch.diffopts(ui, opts))
2968
2968
2969 @command('^forget', walkopts, _('[OPTION]... FILE...'))
2969 @command('^forget', walkopts, _('[OPTION]... FILE...'))
2970 def forget(ui, repo, *pats, **opts):
2970 def forget(ui, repo, *pats, **opts):
2971 """forget the specified files on the next commit
2971 """forget the specified files on the next commit
2972
2972
2973 Mark the specified files so they will no longer be tracked
2973 Mark the specified files so they will no longer be tracked
2974 after the next commit.
2974 after the next commit.
2975
2975
2976 This only removes files from the current branch, not from the
2976 This only removes files from the current branch, not from the
2977 entire project history, and it does not delete them from the
2977 entire project history, and it does not delete them from the
2978 working directory.
2978 working directory.
2979
2979
2980 To undo a forget before the next commit, see :hg:`add`.
2980 To undo a forget before the next commit, see :hg:`add`.
2981
2981
2982 .. container:: verbose
2982 .. container:: verbose
2983
2983
2984 Examples:
2984 Examples:
2985
2985
2986 - forget newly-added binary files::
2986 - forget newly-added binary files::
2987
2987
2988 hg forget "set:added() and binary()"
2988 hg forget "set:added() and binary()"
2989
2989
2990 - forget files that would be excluded by .hgignore::
2990 - forget files that would be excluded by .hgignore::
2991
2991
2992 hg forget "set:hgignore()"
2992 hg forget "set:hgignore()"
2993
2993
2994 Returns 0 on success.
2994 Returns 0 on success.
2995 """
2995 """
2996
2996
2997 if not pats:
2997 if not pats:
2998 raise util.Abort(_('no files specified'))
2998 raise util.Abort(_('no files specified'))
2999
2999
3000 m = scmutil.match(repo[None], pats, opts)
3000 m = scmutil.match(repo[None], pats, opts)
3001 rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0]
3001 rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0]
3002 return rejected and 1 or 0
3002 return rejected and 1 or 0
3003
3003
3004 @command(
3004 @command(
3005 'graft',
3005 'graft',
3006 [('r', 'rev', [], _('revisions to graft'), _('REV')),
3006 [('r', 'rev', [], _('revisions to graft'), _('REV')),
3007 ('c', 'continue', False, _('resume interrupted graft')),
3007 ('c', 'continue', False, _('resume interrupted graft')),
3008 ('e', 'edit', False, _('invoke editor on commit messages')),
3008 ('e', 'edit', False, _('invoke editor on commit messages')),
3009 ('', 'log', None, _('append graft info to log message')),
3009 ('', 'log', None, _('append graft info to log message')),
3010 ('D', 'currentdate', False,
3010 ('D', 'currentdate', False,
3011 _('record the current date as commit date')),
3011 _('record the current date as commit date')),
3012 ('U', 'currentuser', False,
3012 ('U', 'currentuser', False,
3013 _('record the current user as committer'), _('DATE'))]
3013 _('record the current user as committer'), _('DATE'))]
3014 + commitopts2 + mergetoolopts + dryrunopts,
3014 + commitopts2 + mergetoolopts + dryrunopts,
3015 _('[OPTION]... [-r] REV...'))
3015 _('[OPTION]... [-r] REV...'))
3016 def graft(ui, repo, *revs, **opts):
3016 def graft(ui, repo, *revs, **opts):
3017 '''copy changes from other branches onto the current branch
3017 '''copy changes from other branches onto the current branch
3018
3018
3019 This command uses Mercurial's merge logic to copy individual
3019 This command uses Mercurial's merge logic to copy individual
3020 changes from other branches without merging branches in the
3020 changes from other branches without merging branches in the
3021 history graph. This is sometimes known as 'backporting' or
3021 history graph. This is sometimes known as 'backporting' or
3022 'cherry-picking'. By default, graft will copy user, date, and
3022 'cherry-picking'. By default, graft will copy user, date, and
3023 description from the source changesets.
3023 description from the source changesets.
3024
3024
3025 Changesets that are ancestors of the current revision, that have
3025 Changesets that are ancestors of the current revision, that have
3026 already been grafted, or that are merges will be skipped.
3026 already been grafted, or that are merges will be skipped.
3027
3027
3028 If --log is specified, log messages will have a comment appended
3028 If --log is specified, log messages will have a comment appended
3029 of the form::
3029 of the form::
3030
3030
3031 (grafted from CHANGESETHASH)
3031 (grafted from CHANGESETHASH)
3032
3032
3033 If a graft merge results in conflicts, the graft process is
3033 If a graft merge results in conflicts, the graft process is
3034 interrupted so that the current merge can be manually resolved.
3034 interrupted so that the current merge can be manually resolved.
3035 Once all conflicts are addressed, the graft process can be
3035 Once all conflicts are addressed, the graft process can be
3036 continued with the -c/--continue option.
3036 continued with the -c/--continue option.
3037
3037
3038 .. note::
3038 .. note::
3039
3039
3040 The -c/--continue option does not reapply earlier options.
3040 The -c/--continue option does not reapply earlier options.
3041
3041
3042 .. container:: verbose
3042 .. container:: verbose
3043
3043
3044 Examples:
3044 Examples:
3045
3045
3046 - copy a single change to the stable branch and edit its description::
3046 - copy a single change to the stable branch and edit its description::
3047
3047
3048 hg update stable
3048 hg update stable
3049 hg graft --edit 9393
3049 hg graft --edit 9393
3050
3050
3051 - graft a range of changesets with one exception, updating dates::
3051 - graft a range of changesets with one exception, updating dates::
3052
3052
3053 hg graft -D "2085::2093 and not 2091"
3053 hg graft -D "2085::2093 and not 2091"
3054
3054
3055 - continue a graft after resolving conflicts::
3055 - continue a graft after resolving conflicts::
3056
3056
3057 hg graft -c
3057 hg graft -c
3058
3058
3059 - show the source of a grafted changeset::
3059 - show the source of a grafted changeset::
3060
3060
3061 hg log --debug -r .
3061 hg log --debug -r .
3062
3062
3063 Returns 0 on successful completion.
3063 Returns 0 on successful completion.
3064 '''
3064 '''
3065
3065
3066 revs = list(revs)
3066 revs = list(revs)
3067 revs.extend(opts['rev'])
3067 revs.extend(opts['rev'])
3068
3068
3069 if not opts.get('user') and opts.get('currentuser'):
3069 if not opts.get('user') and opts.get('currentuser'):
3070 opts['user'] = ui.username()
3070 opts['user'] = ui.username()
3071 if not opts.get('date') and opts.get('currentdate'):
3071 if not opts.get('date') and opts.get('currentdate'):
3072 opts['date'] = "%d %d" % util.makedate()
3072 opts['date'] = "%d %d" % util.makedate()
3073
3073
3074 editor = cmdutil.getcommiteditor(**opts)
3074 editor = cmdutil.getcommiteditor(**opts)
3075
3075
3076 cont = False
3076 cont = False
3077 if opts['continue']:
3077 if opts['continue']:
3078 cont = True
3078 cont = True
3079 if revs:
3079 if revs:
3080 raise util.Abort(_("can't specify --continue and revisions"))
3080 raise util.Abort(_("can't specify --continue and revisions"))
3081 # read in unfinished revisions
3081 # read in unfinished revisions
3082 try:
3082 try:
3083 nodes = repo.opener.read('graftstate').splitlines()
3083 nodes = repo.opener.read('graftstate').splitlines()
3084 revs = [repo[node].rev() for node in nodes]
3084 revs = [repo[node].rev() for node in nodes]
3085 except IOError, inst:
3085 except IOError, inst:
3086 if inst.errno != errno.ENOENT:
3086 if inst.errno != errno.ENOENT:
3087 raise
3087 raise
3088 raise util.Abort(_("no graft state found, can't continue"))
3088 raise util.Abort(_("no graft state found, can't continue"))
3089 else:
3089 else:
3090 cmdutil.checkunfinished(repo)
3090 cmdutil.checkunfinished(repo)
3091 cmdutil.bailifchanged(repo)
3091 cmdutil.bailifchanged(repo)
3092 if not revs:
3092 if not revs:
3093 raise util.Abort(_('no revisions specified'))
3093 raise util.Abort(_('no revisions specified'))
3094 revs = scmutil.revrange(repo, revs)
3094 revs = scmutil.revrange(repo, revs)
3095
3095
3096 # check for merges
3096 # check for merges
3097 for rev in repo.revs('%ld and merge()', revs):
3097 for rev in repo.revs('%ld and merge()', revs):
3098 ui.warn(_('skipping ungraftable merge revision %s\n') % rev)
3098 ui.warn(_('skipping ungraftable merge revision %s\n') % rev)
3099 revs.remove(rev)
3099 revs.remove(rev)
3100 if not revs:
3100 if not revs:
3101 return -1
3101 return -1
3102
3102
3103 # check for ancestors of dest branch
3103 # check for ancestors of dest branch
3104 crev = repo['.'].rev()
3104 crev = repo['.'].rev()
3105 ancestors = repo.changelog.ancestors([crev], inclusive=True)
3105 ancestors = repo.changelog.ancestors([crev], inclusive=True)
3106 # Cannot use x.remove(y) on smart set, this has to be a list.
3106 # Cannot use x.remove(y) on smart set, this has to be a list.
3107 # XXX make this lazy in the future
3107 # XXX make this lazy in the future
3108 revs = list(revs)
3108 revs = list(revs)
3109 # don't mutate while iterating, create a copy
3109 # don't mutate while iterating, create a copy
3110 for rev in list(revs):
3110 for rev in list(revs):
3111 if rev in ancestors:
3111 if rev in ancestors:
3112 ui.warn(_('skipping ancestor revision %s\n') % rev)
3112 ui.warn(_('skipping ancestor revision %s\n') % rev)
3113 # XXX remove on list is slow
3113 # XXX remove on list is slow
3114 revs.remove(rev)
3114 revs.remove(rev)
3115 if not revs:
3115 if not revs:
3116 return -1
3116 return -1
3117
3117
3118 # analyze revs for earlier grafts
3118 # analyze revs for earlier grafts
3119 ids = {}
3119 ids = {}
3120 for ctx in repo.set("%ld", revs):
3120 for ctx in repo.set("%ld", revs):
3121 ids[ctx.hex()] = ctx.rev()
3121 ids[ctx.hex()] = ctx.rev()
3122 n = ctx.extra().get('source')
3122 n = ctx.extra().get('source')
3123 if n:
3123 if n:
3124 ids[n] = ctx.rev()
3124 ids[n] = ctx.rev()
3125
3125
3126 # check ancestors for earlier grafts
3126 # check ancestors for earlier grafts
3127 ui.debug('scanning for duplicate grafts\n')
3127 ui.debug('scanning for duplicate grafts\n')
3128
3128
3129 for rev in repo.changelog.findmissingrevs(revs, [crev]):
3129 for rev in repo.changelog.findmissingrevs(revs, [crev]):
3130 ctx = repo[rev]
3130 ctx = repo[rev]
3131 n = ctx.extra().get('source')
3131 n = ctx.extra().get('source')
3132 if n in ids:
3132 if n in ids:
3133 r = repo[n].rev()
3133 r = repo[n].rev()
3134 if r in revs:
3134 if r in revs:
3135 ui.warn(_('skipping revision %s (already grafted to %s)\n')
3135 ui.warn(_('skipping revision %s (already grafted to %s)\n')
3136 % (r, rev))
3136 % (r, rev))
3137 revs.remove(r)
3137 revs.remove(r)
3138 elif ids[n] in revs:
3138 elif ids[n] in revs:
3139 ui.warn(_('skipping already grafted revision %s '
3139 ui.warn(_('skipping already grafted revision %s '
3140 '(%s also has origin %d)\n') % (ids[n], rev, r))
3140 '(%s also has origin %d)\n') % (ids[n], rev, r))
3141 revs.remove(ids[n])
3141 revs.remove(ids[n])
3142 elif ctx.hex() in ids:
3142 elif ctx.hex() in ids:
3143 r = ids[ctx.hex()]
3143 r = ids[ctx.hex()]
3144 ui.warn(_('skipping already grafted revision %s '
3144 ui.warn(_('skipping already grafted revision %s '
3145 '(was grafted from %d)\n') % (r, rev))
3145 '(was grafted from %d)\n') % (r, rev))
3146 revs.remove(r)
3146 revs.remove(r)
3147 if not revs:
3147 if not revs:
3148 return -1
3148 return -1
3149
3149
3150 wlock = repo.wlock()
3150 wlock = repo.wlock()
3151 try:
3151 try:
3152 current = repo['.']
3152 current = repo['.']
3153 for pos, ctx in enumerate(repo.set("%ld", revs)):
3153 for pos, ctx in enumerate(repo.set("%ld", revs)):
3154
3154
3155 ui.status(_('grafting revision %s\n') % ctx.rev())
3155 ui.status(_('grafting revision %s\n') % ctx.rev())
3156 if opts.get('dry_run'):
3156 if opts.get('dry_run'):
3157 continue
3157 continue
3158
3158
3159 source = ctx.extra().get('source')
3159 source = ctx.extra().get('source')
3160 if not source:
3160 if not source:
3161 source = ctx.hex()
3161 source = ctx.hex()
3162 extra = {'source': source}
3162 extra = {'source': source}
3163 user = ctx.user()
3163 user = ctx.user()
3164 if opts.get('user'):
3164 if opts.get('user'):
3165 user = opts['user']
3165 user = opts['user']
3166 date = ctx.date()
3166 date = ctx.date()
3167 if opts.get('date'):
3167 if opts.get('date'):
3168 date = opts['date']
3168 date = opts['date']
3169 message = ctx.description()
3169 message = ctx.description()
3170 if opts.get('log'):
3170 if opts.get('log'):
3171 message += '\n(grafted from %s)' % ctx.hex()
3171 message += '\n(grafted from %s)' % ctx.hex()
3172
3172
3173 # we don't merge the first commit when continuing
3173 # we don't merge the first commit when continuing
3174 if not cont:
3174 if not cont:
3175 # perform the graft merge with p1(rev) as 'ancestor'
3175 # perform the graft merge with p1(rev) as 'ancestor'
3176 try:
3176 try:
3177 # ui.forcemerge is an internal variable, do not document
3177 # ui.forcemerge is an internal variable, do not document
3178 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
3178 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
3179 'graft')
3179 'graft')
3180 stats = mergemod.update(repo, ctx.node(), True, True, False,
3180 stats = mergemod.update(repo, ctx.node(), True, True, False,
3181 ctx.p1().node(),
3181 ctx.p1().node(),
3182 labels=['local', 'graft'])
3182 labels=['local', 'graft'])
3183 finally:
3183 finally:
3184 repo.ui.setconfig('ui', 'forcemerge', '', 'graft')
3184 repo.ui.setconfig('ui', 'forcemerge', '', 'graft')
3185 # report any conflicts
3185 # report any conflicts
3186 if stats and stats[3] > 0:
3186 if stats and stats[3] > 0:
3187 # write out state for --continue
3187 # write out state for --continue
3188 nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]]
3188 nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]]
3189 repo.opener.write('graftstate', ''.join(nodelines))
3189 repo.opener.write('graftstate', ''.join(nodelines))
3190 raise util.Abort(
3190 raise util.Abort(
3191 _("unresolved conflicts, can't continue"),
3191 _("unresolved conflicts, can't continue"),
3192 hint=_('use hg resolve and hg graft --continue'))
3192 hint=_('use hg resolve and hg graft --continue'))
3193 else:
3193 else:
3194 cont = False
3194 cont = False
3195
3195
3196 # drop the second merge parent
3196 # drop the second merge parent
3197 repo.setparents(current.node(), nullid)
3197 repo.setparents(current.node(), nullid)
3198 repo.dirstate.write()
3198 repo.dirstate.write()
3199 # fix up dirstate for copies and renames
3199 # fix up dirstate for copies and renames
3200 cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev())
3200 cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev())
3201
3201
3202 # commit
3202 # commit
3203 node = repo.commit(text=message, user=user,
3203 node = repo.commit(text=message, user=user,
3204 date=date, extra=extra, editor=editor)
3204 date=date, extra=extra, editor=editor)
3205 if node is None:
3205 if node is None:
3206 ui.status(_('graft for revision %s is empty\n') % ctx.rev())
3206 ui.status(_('graft for revision %s is empty\n') % ctx.rev())
3207 else:
3207 else:
3208 current = repo[node]
3208 current = repo[node]
3209 finally:
3209 finally:
3210 wlock.release()
3210 wlock.release()
3211
3211
3212 # remove state when we complete successfully
3212 # remove state when we complete successfully
3213 if not opts.get('dry_run'):
3213 if not opts.get('dry_run'):
3214 util.unlinkpath(repo.join('graftstate'), ignoremissing=True)
3214 util.unlinkpath(repo.join('graftstate'), ignoremissing=True)
3215
3215
3216 return 0
3216 return 0
3217
3217
3218 @command('grep',
3218 @command('grep',
3219 [('0', 'print0', None, _('end fields with NUL')),
3219 [('0', 'print0', None, _('end fields with NUL')),
3220 ('', 'all', None, _('print all revisions that match')),
3220 ('', 'all', None, _('print all revisions that match')),
3221 ('a', 'text', None, _('treat all files as text')),
3221 ('a', 'text', None, _('treat all files as text')),
3222 ('f', 'follow', None,
3222 ('f', 'follow', None,
3223 _('follow changeset history,'
3223 _('follow changeset history,'
3224 ' or file history across copies and renames')),
3224 ' or file history across copies and renames')),
3225 ('i', 'ignore-case', None, _('ignore case when matching')),
3225 ('i', 'ignore-case', None, _('ignore case when matching')),
3226 ('l', 'files-with-matches', None,
3226 ('l', 'files-with-matches', None,
3227 _('print only filenames and revisions that match')),
3227 _('print only filenames and revisions that match')),
3228 ('n', 'line-number', None, _('print matching line numbers')),
3228 ('n', 'line-number', None, _('print matching line numbers')),
3229 ('r', 'rev', [],
3229 ('r', 'rev', [],
3230 _('only search files changed within revision range'), _('REV')),
3230 _('only search files changed within revision range'), _('REV')),
3231 ('u', 'user', None, _('list the author (long with -v)')),
3231 ('u', 'user', None, _('list the author (long with -v)')),
3232 ('d', 'date', None, _('list the date (short with -q)')),
3232 ('d', 'date', None, _('list the date (short with -q)')),
3233 ] + walkopts,
3233 ] + walkopts,
3234 _('[OPTION]... PATTERN [FILE]...'))
3234 _('[OPTION]... PATTERN [FILE]...'))
3235 def grep(ui, repo, pattern, *pats, **opts):
3235 def grep(ui, repo, pattern, *pats, **opts):
3236 """search for a pattern in specified files and revisions
3236 """search for a pattern in specified files and revisions
3237
3237
3238 Search revisions of files for a regular expression.
3238 Search revisions of files for a regular expression.
3239
3239
3240 This command behaves differently than Unix grep. It only accepts
3240 This command behaves differently than Unix grep. It only accepts
3241 Python/Perl regexps. It searches repository history, not the
3241 Python/Perl regexps. It searches repository history, not the
3242 working directory. It always prints the revision number in which a
3242 working directory. It always prints the revision number in which a
3243 match appears.
3243 match appears.
3244
3244
3245 By default, grep only prints output for the first revision of a
3245 By default, grep only prints output for the first revision of a
3246 file in which it finds a match. To get it to print every revision
3246 file in which it finds a match. To get it to print every revision
3247 that contains a change in match status ("-" for a match that
3247 that contains a change in match status ("-" for a match that
3248 becomes a non-match, or "+" for a non-match that becomes a match),
3248 becomes a non-match, or "+" for a non-match that becomes a match),
3249 use the --all flag.
3249 use the --all flag.
3250
3250
3251 Returns 0 if a match is found, 1 otherwise.
3251 Returns 0 if a match is found, 1 otherwise.
3252 """
3252 """
3253 reflags = re.M
3253 reflags = re.M
3254 if opts.get('ignore_case'):
3254 if opts.get('ignore_case'):
3255 reflags |= re.I
3255 reflags |= re.I
3256 try:
3256 try:
3257 regexp = util.compilere(pattern, reflags)
3257 regexp = util.compilere(pattern, reflags)
3258 except re.error, inst:
3258 except re.error, inst:
3259 ui.warn(_("grep: invalid match pattern: %s\n") % inst)
3259 ui.warn(_("grep: invalid match pattern: %s\n") % inst)
3260 return 1
3260 return 1
3261 sep, eol = ':', '\n'
3261 sep, eol = ':', '\n'
3262 if opts.get('print0'):
3262 if opts.get('print0'):
3263 sep = eol = '\0'
3263 sep = eol = '\0'
3264
3264
3265 getfile = util.lrucachefunc(repo.file)
3265 getfile = util.lrucachefunc(repo.file)
3266
3266
3267 def matchlines(body):
3267 def matchlines(body):
3268 begin = 0
3268 begin = 0
3269 linenum = 0
3269 linenum = 0
3270 while begin < len(body):
3270 while begin < len(body):
3271 match = regexp.search(body, begin)
3271 match = regexp.search(body, begin)
3272 if not match:
3272 if not match:
3273 break
3273 break
3274 mstart, mend = match.span()
3274 mstart, mend = match.span()
3275 linenum += body.count('\n', begin, mstart) + 1
3275 linenum += body.count('\n', begin, mstart) + 1
3276 lstart = body.rfind('\n', begin, mstart) + 1 or begin
3276 lstart = body.rfind('\n', begin, mstart) + 1 or begin
3277 begin = body.find('\n', mend) + 1 or len(body) + 1
3277 begin = body.find('\n', mend) + 1 or len(body) + 1
3278 lend = begin - 1
3278 lend = begin - 1
3279 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
3279 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
3280
3280
3281 class linestate(object):
3281 class linestate(object):
3282 def __init__(self, line, linenum, colstart, colend):
3282 def __init__(self, line, linenum, colstart, colend):
3283 self.line = line
3283 self.line = line
3284 self.linenum = linenum
3284 self.linenum = linenum
3285 self.colstart = colstart
3285 self.colstart = colstart
3286 self.colend = colend
3286 self.colend = colend
3287
3287
3288 def __hash__(self):
3288 def __hash__(self):
3289 return hash((self.linenum, self.line))
3289 return hash((self.linenum, self.line))
3290
3290
3291 def __eq__(self, other):
3291 def __eq__(self, other):
3292 return self.line == other.line
3292 return self.line == other.line
3293
3293
3294 def __iter__(self):
3294 def __iter__(self):
3295 yield (self.line[:self.colstart], '')
3295 yield (self.line[:self.colstart], '')
3296 yield (self.line[self.colstart:self.colend], 'grep.match')
3296 yield (self.line[self.colstart:self.colend], 'grep.match')
3297 rest = self.line[self.colend:]
3297 rest = self.line[self.colend:]
3298 while rest != '':
3298 while rest != '':
3299 match = regexp.search(rest)
3299 match = regexp.search(rest)
3300 if not match:
3300 if not match:
3301 yield (rest, '')
3301 yield (rest, '')
3302 break
3302 break
3303 mstart, mend = match.span()
3303 mstart, mend = match.span()
3304 yield (rest[:mstart], '')
3304 yield (rest[:mstart], '')
3305 yield (rest[mstart:mend], 'grep.match')
3305 yield (rest[mstart:mend], 'grep.match')
3306 rest = rest[mend:]
3306 rest = rest[mend:]
3307
3307
3308 matches = {}
3308 matches = {}
3309 copies = {}
3309 copies = {}
3310 def grepbody(fn, rev, body):
3310 def grepbody(fn, rev, body):
3311 matches[rev].setdefault(fn, [])
3311 matches[rev].setdefault(fn, [])
3312 m = matches[rev][fn]
3312 m = matches[rev][fn]
3313 for lnum, cstart, cend, line in matchlines(body):
3313 for lnum, cstart, cend, line in matchlines(body):
3314 s = linestate(line, lnum, cstart, cend)
3314 s = linestate(line, lnum, cstart, cend)
3315 m.append(s)
3315 m.append(s)
3316
3316
3317 def difflinestates(a, b):
3317 def difflinestates(a, b):
3318 sm = difflib.SequenceMatcher(None, a, b)
3318 sm = difflib.SequenceMatcher(None, a, b)
3319 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
3319 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
3320 if tag == 'insert':
3320 if tag == 'insert':
3321 for i in xrange(blo, bhi):
3321 for i in xrange(blo, bhi):
3322 yield ('+', b[i])
3322 yield ('+', b[i])
3323 elif tag == 'delete':
3323 elif tag == 'delete':
3324 for i in xrange(alo, ahi):
3324 for i in xrange(alo, ahi):
3325 yield ('-', a[i])
3325 yield ('-', a[i])
3326 elif tag == 'replace':
3326 elif tag == 'replace':
3327 for i in xrange(alo, ahi):
3327 for i in xrange(alo, ahi):
3328 yield ('-', a[i])
3328 yield ('-', a[i])
3329 for i in xrange(blo, bhi):
3329 for i in xrange(blo, bhi):
3330 yield ('+', b[i])
3330 yield ('+', b[i])
3331
3331
3332 def display(fn, ctx, pstates, states):
3332 def display(fn, ctx, pstates, states):
3333 rev = ctx.rev()
3333 rev = ctx.rev()
3334 datefunc = ui.quiet and util.shortdate or util.datestr
3334 datefunc = ui.quiet and util.shortdate or util.datestr
3335 found = False
3335 found = False
3336 @util.cachefunc
3336 @util.cachefunc
3337 def binary():
3337 def binary():
3338 flog = getfile(fn)
3338 flog = getfile(fn)
3339 return util.binary(flog.read(ctx.filenode(fn)))
3339 return util.binary(flog.read(ctx.filenode(fn)))
3340
3340
3341 if opts.get('all'):
3341 if opts.get('all'):
3342 iter = difflinestates(pstates, states)
3342 iter = difflinestates(pstates, states)
3343 else:
3343 else:
3344 iter = [('', l) for l in states]
3344 iter = [('', l) for l in states]
3345 for change, l in iter:
3345 for change, l in iter:
3346 cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')]
3346 cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')]
3347
3347
3348 if opts.get('line_number'):
3348 if opts.get('line_number'):
3349 cols.append((str(l.linenum), 'grep.linenumber'))
3349 cols.append((str(l.linenum), 'grep.linenumber'))
3350 if opts.get('all'):
3350 if opts.get('all'):
3351 cols.append((change, 'grep.change'))
3351 cols.append((change, 'grep.change'))
3352 if opts.get('user'):
3352 if opts.get('user'):
3353 cols.append((ui.shortuser(ctx.user()), 'grep.user'))
3353 cols.append((ui.shortuser(ctx.user()), 'grep.user'))
3354 if opts.get('date'):
3354 if opts.get('date'):
3355 cols.append((datefunc(ctx.date()), 'grep.date'))
3355 cols.append((datefunc(ctx.date()), 'grep.date'))
3356 for col, label in cols[:-1]:
3356 for col, label in cols[:-1]:
3357 ui.write(col, label=label)
3357 ui.write(col, label=label)
3358 ui.write(sep, label='grep.sep')
3358 ui.write(sep, label='grep.sep')
3359 ui.write(cols[-1][0], label=cols[-1][1])
3359 ui.write(cols[-1][0], label=cols[-1][1])
3360 if not opts.get('files_with_matches'):
3360 if not opts.get('files_with_matches'):
3361 ui.write(sep, label='grep.sep')
3361 ui.write(sep, label='grep.sep')
3362 if not opts.get('text') and binary():
3362 if not opts.get('text') and binary():
3363 ui.write(" Binary file matches")
3363 ui.write(" Binary file matches")
3364 else:
3364 else:
3365 for s, label in l:
3365 for s, label in l:
3366 ui.write(s, label=label)
3366 ui.write(s, label=label)
3367 ui.write(eol)
3367 ui.write(eol)
3368 found = True
3368 found = True
3369 if opts.get('files_with_matches'):
3369 if opts.get('files_with_matches'):
3370 break
3370 break
3371 return found
3371 return found
3372
3372
3373 skip = {}
3373 skip = {}
3374 revfiles = {}
3374 revfiles = {}
3375 matchfn = scmutil.match(repo[None], pats, opts)
3375 matchfn = scmutil.match(repo[None], pats, opts)
3376 found = False
3376 found = False
3377 follow = opts.get('follow')
3377 follow = opts.get('follow')
3378
3378
3379 def prep(ctx, fns):
3379 def prep(ctx, fns):
3380 rev = ctx.rev()
3380 rev = ctx.rev()
3381 pctx = ctx.p1()
3381 pctx = ctx.p1()
3382 parent = pctx.rev()
3382 parent = pctx.rev()
3383 matches.setdefault(rev, {})
3383 matches.setdefault(rev, {})
3384 matches.setdefault(parent, {})
3384 matches.setdefault(parent, {})
3385 files = revfiles.setdefault(rev, [])
3385 files = revfiles.setdefault(rev, [])
3386 for fn in fns:
3386 for fn in fns:
3387 flog = getfile(fn)
3387 flog = getfile(fn)
3388 try:
3388 try:
3389 fnode = ctx.filenode(fn)
3389 fnode = ctx.filenode(fn)
3390 except error.LookupError:
3390 except error.LookupError:
3391 continue
3391 continue
3392
3392
3393 copied = flog.renamed(fnode)
3393 copied = flog.renamed(fnode)
3394 copy = follow and copied and copied[0]
3394 copy = follow and copied and copied[0]
3395 if copy:
3395 if copy:
3396 copies.setdefault(rev, {})[fn] = copy
3396 copies.setdefault(rev, {})[fn] = copy
3397 if fn in skip:
3397 if fn in skip:
3398 if copy:
3398 if copy:
3399 skip[copy] = True
3399 skip[copy] = True
3400 continue
3400 continue
3401 files.append(fn)
3401 files.append(fn)
3402
3402
3403 if fn not in matches[rev]:
3403 if fn not in matches[rev]:
3404 grepbody(fn, rev, flog.read(fnode))
3404 grepbody(fn, rev, flog.read(fnode))
3405
3405
3406 pfn = copy or fn
3406 pfn = copy or fn
3407 if pfn not in matches[parent]:
3407 if pfn not in matches[parent]:
3408 try:
3408 try:
3409 fnode = pctx.filenode(pfn)
3409 fnode = pctx.filenode(pfn)
3410 grepbody(pfn, parent, flog.read(fnode))
3410 grepbody(pfn, parent, flog.read(fnode))
3411 except error.LookupError:
3411 except error.LookupError:
3412 pass
3412 pass
3413
3413
3414 for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
3414 for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
3415 rev = ctx.rev()
3415 rev = ctx.rev()
3416 parent = ctx.p1().rev()
3416 parent = ctx.p1().rev()
3417 for fn in sorted(revfiles.get(rev, [])):
3417 for fn in sorted(revfiles.get(rev, [])):
3418 states = matches[rev][fn]
3418 states = matches[rev][fn]
3419 copy = copies.get(rev, {}).get(fn)
3419 copy = copies.get(rev, {}).get(fn)
3420 if fn in skip:
3420 if fn in skip:
3421 if copy:
3421 if copy:
3422 skip[copy] = True
3422 skip[copy] = True
3423 continue
3423 continue
3424 pstates = matches.get(parent, {}).get(copy or fn, [])
3424 pstates = matches.get(parent, {}).get(copy or fn, [])
3425 if pstates or states:
3425 if pstates or states:
3426 r = display(fn, ctx, pstates, states)
3426 r = display(fn, ctx, pstates, states)
3427 found = found or r
3427 found = found or r
3428 if r and not opts.get('all'):
3428 if r and not opts.get('all'):
3429 skip[fn] = True
3429 skip[fn] = True
3430 if copy:
3430 if copy:
3431 skip[copy] = True
3431 skip[copy] = True
3432 del matches[rev]
3432 del matches[rev]
3433 del revfiles[rev]
3433 del revfiles[rev]
3434
3434
3435 return not found
3435 return not found
3436
3436
3437 @command('heads',
3437 @command('heads',
3438 [('r', 'rev', '',
3438 [('r', 'rev', '',
3439 _('show only heads which are descendants of STARTREV'), _('STARTREV')),
3439 _('show only heads which are descendants of STARTREV'), _('STARTREV')),
3440 ('t', 'topo', False, _('show topological heads only')),
3440 ('t', 'topo', False, _('show topological heads only')),
3441 ('a', 'active', False, _('show active branchheads only (DEPRECATED)')),
3441 ('a', 'active', False, _('show active branchheads only (DEPRECATED)')),
3442 ('c', 'closed', False, _('show normal and closed branch heads')),
3442 ('c', 'closed', False, _('show normal and closed branch heads')),
3443 ] + templateopts,
3443 ] + templateopts,
3444 _('[-ct] [-r STARTREV] [REV]...'))
3444 _('[-ct] [-r STARTREV] [REV]...'))
3445 def heads(ui, repo, *branchrevs, **opts):
3445 def heads(ui, repo, *branchrevs, **opts):
3446 """show branch heads
3446 """show branch heads
3447
3447
3448 With no arguments, show all open branch heads in the repository.
3448 With no arguments, show all open branch heads in the repository.
3449 Branch heads are changesets that have no descendants on the
3449 Branch heads are changesets that have no descendants on the
3450 same branch. They are where development generally takes place and
3450 same branch. They are where development generally takes place and
3451 are the usual targets for update and merge operations.
3451 are the usual targets for update and merge operations.
3452
3452
3453 If one or more REVs are given, only open branch heads on the
3453 If one or more REVs are given, only open branch heads on the
3454 branches associated with the specified changesets are shown. This
3454 branches associated with the specified changesets are shown. This
3455 means that you can use :hg:`heads .` to see the heads on the
3455 means that you can use :hg:`heads .` to see the heads on the
3456 currently checked-out branch.
3456 currently checked-out branch.
3457
3457
3458 If -c/--closed is specified, also show branch heads marked closed
3458 If -c/--closed is specified, also show branch heads marked closed
3459 (see :hg:`commit --close-branch`).
3459 (see :hg:`commit --close-branch`).
3460
3460
3461 If STARTREV is specified, only those heads that are descendants of
3461 If STARTREV is specified, only those heads that are descendants of
3462 STARTREV will be displayed.
3462 STARTREV will be displayed.
3463
3463
3464 If -t/--topo is specified, named branch mechanics will be ignored and only
3464 If -t/--topo is specified, named branch mechanics will be ignored and only
3465 topological heads (changesets with no children) will be shown.
3465 topological heads (changesets with no children) will be shown.
3466
3466
3467 Returns 0 if matching heads are found, 1 if not.
3467 Returns 0 if matching heads are found, 1 if not.
3468 """
3468 """
3469
3469
3470 start = None
3470 start = None
3471 if 'rev' in opts:
3471 if 'rev' in opts:
3472 start = scmutil.revsingle(repo, opts['rev'], None).node()
3472 start = scmutil.revsingle(repo, opts['rev'], None).node()
3473
3473
3474 if opts.get('topo'):
3474 if opts.get('topo'):
3475 heads = [repo[h] for h in repo.heads(start)]
3475 heads = [repo[h] for h in repo.heads(start)]
3476 else:
3476 else:
3477 heads = []
3477 heads = []
3478 for branch in repo.branchmap():
3478 for branch in repo.branchmap():
3479 heads += repo.branchheads(branch, start, opts.get('closed'))
3479 heads += repo.branchheads(branch, start, opts.get('closed'))
3480 heads = [repo[h] for h in heads]
3480 heads = [repo[h] for h in heads]
3481
3481
3482 if branchrevs:
3482 if branchrevs:
3483 branches = set(repo[br].branch() for br in branchrevs)
3483 branches = set(repo[br].branch() for br in branchrevs)
3484 heads = [h for h in heads if h.branch() in branches]
3484 heads = [h for h in heads if h.branch() in branches]
3485
3485
3486 if opts.get('active') and branchrevs:
3486 if opts.get('active') and branchrevs:
3487 dagheads = repo.heads(start)
3487 dagheads = repo.heads(start)
3488 heads = [h for h in heads if h.node() in dagheads]
3488 heads = [h for h in heads if h.node() in dagheads]
3489
3489
3490 if branchrevs:
3490 if branchrevs:
3491 haveheads = set(h.branch() for h in heads)
3491 haveheads = set(h.branch() for h in heads)
3492 if branches - haveheads:
3492 if branches - haveheads:
3493 headless = ', '.join(b for b in branches - haveheads)
3493 headless = ', '.join(b for b in branches - haveheads)
3494 msg = _('no open branch heads found on branches %s')
3494 msg = _('no open branch heads found on branches %s')
3495 if opts.get('rev'):
3495 if opts.get('rev'):
3496 msg += _(' (started at %s)') % opts['rev']
3496 msg += _(' (started at %s)') % opts['rev']
3497 ui.warn((msg + '\n') % headless)
3497 ui.warn((msg + '\n') % headless)
3498
3498
3499 if not heads:
3499 if not heads:
3500 return 1
3500 return 1
3501
3501
3502 heads = sorted(heads, key=lambda x: -x.rev())
3502 heads = sorted(heads, key=lambda x: -x.rev())
3503 displayer = cmdutil.show_changeset(ui, repo, opts)
3503 displayer = cmdutil.show_changeset(ui, repo, opts)
3504 for ctx in heads:
3504 for ctx in heads:
3505 displayer.show(ctx)
3505 displayer.show(ctx)
3506 displayer.close()
3506 displayer.close()
3507
3507
3508 @command('help',
3508 @command('help',
3509 [('e', 'extension', None, _('show only help for extensions')),
3509 [('e', 'extension', None, _('show only help for extensions')),
3510 ('c', 'command', None, _('show only help for commands')),
3510 ('c', 'command', None, _('show only help for commands')),
3511 ('k', 'keyword', '', _('show topics matching keyword')),
3511 ('k', 'keyword', '', _('show topics matching keyword')),
3512 ],
3512 ],
3513 _('[-ec] [TOPIC]'))
3513 _('[-ec] [TOPIC]'))
3514 def help_(ui, name=None, **opts):
3514 def help_(ui, name=None, **opts):
3515 """show help for a given topic or a help overview
3515 """show help for a given topic or a help overview
3516
3516
3517 With no arguments, print a list of commands with short help messages.
3517 With no arguments, print a list of commands with short help messages.
3518
3518
3519 Given a topic, extension, or command name, print help for that
3519 Given a topic, extension, or command name, print help for that
3520 topic.
3520 topic.
3521
3521
3522 Returns 0 if successful.
3522 Returns 0 if successful.
3523 """
3523 """
3524
3524
3525 textwidth = min(ui.termwidth(), 80) - 2
3525 textwidth = min(ui.termwidth(), 80) - 2
3526
3526
3527 keep = ui.verbose and ['verbose'] or []
3527 keep = ui.verbose and ['verbose'] or []
3528 text = help.help_(ui, name, **opts)
3528 text = help.help_(ui, name, **opts)
3529
3529
3530 formatted, pruned = minirst.format(text, textwidth, keep=keep)
3530 formatted, pruned = minirst.format(text, textwidth, keep=keep)
3531 if 'verbose' in pruned:
3531 if 'verbose' in pruned:
3532 keep.append('omitted')
3532 keep.append('omitted')
3533 else:
3533 else:
3534 keep.append('notomitted')
3534 keep.append('notomitted')
3535 formatted, pruned = minirst.format(text, textwidth, keep=keep)
3535 formatted, pruned = minirst.format(text, textwidth, keep=keep)
3536 ui.write(formatted)
3536 ui.write(formatted)
3537
3537
3538
3538
3539 @command('identify|id',
3539 @command('identify|id',
3540 [('r', 'rev', '',
3540 [('r', 'rev', '',
3541 _('identify the specified revision'), _('REV')),
3541 _('identify the specified revision'), _('REV')),
3542 ('n', 'num', None, _('show local revision number')),
3542 ('n', 'num', None, _('show local revision number')),
3543 ('i', 'id', None, _('show global revision id')),
3543 ('i', 'id', None, _('show global revision id')),
3544 ('b', 'branch', None, _('show branch')),
3544 ('b', 'branch', None, _('show branch')),
3545 ('t', 'tags', None, _('show tags')),
3545 ('t', 'tags', None, _('show tags')),
3546 ('B', 'bookmarks', None, _('show bookmarks')),
3546 ('B', 'bookmarks', None, _('show bookmarks')),
3547 ] + remoteopts,
3547 ] + remoteopts,
3548 _('[-nibtB] [-r REV] [SOURCE]'))
3548 _('[-nibtB] [-r REV] [SOURCE]'))
3549 def identify(ui, repo, source=None, rev=None,
3549 def identify(ui, repo, source=None, rev=None,
3550 num=None, id=None, branch=None, tags=None, bookmarks=None, **opts):
3550 num=None, id=None, branch=None, tags=None, bookmarks=None, **opts):
3551 """identify the working copy or specified revision
3551 """identify the working copy or specified revision
3552
3552
3553 Print a summary identifying the repository state at REV using one or
3553 Print a summary identifying the repository state at REV using one or
3554 two parent hash identifiers, followed by a "+" if the working
3554 two parent hash identifiers, followed by a "+" if the working
3555 directory has uncommitted changes, the branch name (if not default),
3555 directory has uncommitted changes, the branch name (if not default),
3556 a list of tags, and a list of bookmarks.
3556 a list of tags, and a list of bookmarks.
3557
3557
3558 When REV is not given, print a summary of the current state of the
3558 When REV is not given, print a summary of the current state of the
3559 repository.
3559 repository.
3560
3560
3561 Specifying a path to a repository root or Mercurial bundle will
3561 Specifying a path to a repository root or Mercurial bundle will
3562 cause lookup to operate on that repository/bundle.
3562 cause lookup to operate on that repository/bundle.
3563
3563
3564 .. container:: verbose
3564 .. container:: verbose
3565
3565
3566 Examples:
3566 Examples:
3567
3567
3568 - generate a build identifier for the working directory::
3568 - generate a build identifier for the working directory::
3569
3569
3570 hg id --id > build-id.dat
3570 hg id --id > build-id.dat
3571
3571
3572 - find the revision corresponding to a tag::
3572 - find the revision corresponding to a tag::
3573
3573
3574 hg id -n -r 1.3
3574 hg id -n -r 1.3
3575
3575
3576 - check the most recent revision of a remote repository::
3576 - check the most recent revision of a remote repository::
3577
3577
3578 hg id -r tip http://selenic.com/hg/
3578 hg id -r tip http://selenic.com/hg/
3579
3579
3580 Returns 0 if successful.
3580 Returns 0 if successful.
3581 """
3581 """
3582
3582
3583 if not repo and not source:
3583 if not repo and not source:
3584 raise util.Abort(_("there is no Mercurial repository here "
3584 raise util.Abort(_("there is no Mercurial repository here "
3585 "(.hg not found)"))
3585 "(.hg not found)"))
3586
3586
3587 hexfunc = ui.debugflag and hex or short
3587 hexfunc = ui.debugflag and hex or short
3588 default = not (num or id or branch or tags or bookmarks)
3588 default = not (num or id or branch or tags or bookmarks)
3589 output = []
3589 output = []
3590 revs = []
3590 revs = []
3591
3591
3592 if source:
3592 if source:
3593 source, branches = hg.parseurl(ui.expandpath(source))
3593 source, branches = hg.parseurl(ui.expandpath(source))
3594 peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo
3594 peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo
3595 repo = peer.local()
3595 repo = peer.local()
3596 revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
3596 revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
3597
3597
3598 if not repo:
3598 if not repo:
3599 if num or branch or tags:
3599 if num or branch or tags:
3600 raise util.Abort(
3600 raise util.Abort(
3601 _("can't query remote revision number, branch, or tags"))
3601 _("can't query remote revision number, branch, or tags"))
3602 if not rev and revs:
3602 if not rev and revs:
3603 rev = revs[0]
3603 rev = revs[0]
3604 if not rev:
3604 if not rev:
3605 rev = "tip"
3605 rev = "tip"
3606
3606
3607 remoterev = peer.lookup(rev)
3607 remoterev = peer.lookup(rev)
3608 if default or id:
3608 if default or id:
3609 output = [hexfunc(remoterev)]
3609 output = [hexfunc(remoterev)]
3610
3610
3611 def getbms():
3611 def getbms():
3612 bms = []
3612 bms = []
3613
3613
3614 if 'bookmarks' in peer.listkeys('namespaces'):
3614 if 'bookmarks' in peer.listkeys('namespaces'):
3615 hexremoterev = hex(remoterev)
3615 hexremoterev = hex(remoterev)
3616 bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems()
3616 bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems()
3617 if bmr == hexremoterev]
3617 if bmr == hexremoterev]
3618
3618
3619 return sorted(bms)
3619 return sorted(bms)
3620
3620
3621 if bookmarks:
3621 if bookmarks:
3622 output.extend(getbms())
3622 output.extend(getbms())
3623 elif default and not ui.quiet:
3623 elif default and not ui.quiet:
3624 # multiple bookmarks for a single parent separated by '/'
3624 # multiple bookmarks for a single parent separated by '/'
3625 bm = '/'.join(getbms())
3625 bm = '/'.join(getbms())
3626 if bm:
3626 if bm:
3627 output.append(bm)
3627 output.append(bm)
3628 else:
3628 else:
3629 if not rev:
3629 if not rev:
3630 ctx = repo[None]
3630 ctx = repo[None]
3631 parents = ctx.parents()
3631 parents = ctx.parents()
3632 changed = ""
3632 changed = ""
3633 if default or id or num:
3633 if default or id or num:
3634 if (util.any(repo.status())
3634 if (util.any(repo.status())
3635 or util.any(ctx.sub(s).dirty() for s in ctx.substate)):
3635 or util.any(ctx.sub(s).dirty() for s in ctx.substate)):
3636 changed = '+'
3636 changed = '+'
3637 if default or id:
3637 if default or id:
3638 output = ["%s%s" %
3638 output = ["%s%s" %
3639 ('+'.join([hexfunc(p.node()) for p in parents]), changed)]
3639 ('+'.join([hexfunc(p.node()) for p in parents]), changed)]
3640 if num:
3640 if num:
3641 output.append("%s%s" %
3641 output.append("%s%s" %
3642 ('+'.join([str(p.rev()) for p in parents]), changed))
3642 ('+'.join([str(p.rev()) for p in parents]), changed))
3643 else:
3643 else:
3644 ctx = scmutil.revsingle(repo, rev)
3644 ctx = scmutil.revsingle(repo, rev)
3645 if default or id:
3645 if default or id:
3646 output = [hexfunc(ctx.node())]
3646 output = [hexfunc(ctx.node())]
3647 if num:
3647 if num:
3648 output.append(str(ctx.rev()))
3648 output.append(str(ctx.rev()))
3649
3649
3650 if default and not ui.quiet:
3650 if default and not ui.quiet:
3651 b = ctx.branch()
3651 b = ctx.branch()
3652 if b != 'default':
3652 if b != 'default':
3653 output.append("(%s)" % b)
3653 output.append("(%s)" % b)
3654
3654
3655 # multiple tags for a single parent separated by '/'
3655 # multiple tags for a single parent separated by '/'
3656 t = '/'.join(ctx.tags())
3656 t = '/'.join(ctx.tags())
3657 if t:
3657 if t:
3658 output.append(t)
3658 output.append(t)
3659
3659
3660 # multiple bookmarks for a single parent separated by '/'
3660 # multiple bookmarks for a single parent separated by '/'
3661 bm = '/'.join(ctx.bookmarks())
3661 bm = '/'.join(ctx.bookmarks())
3662 if bm:
3662 if bm:
3663 output.append(bm)
3663 output.append(bm)
3664 else:
3664 else:
3665 if branch:
3665 if branch:
3666 output.append(ctx.branch())
3666 output.append(ctx.branch())
3667
3667
3668 if tags:
3668 if tags:
3669 output.extend(ctx.tags())
3669 output.extend(ctx.tags())
3670
3670
3671 if bookmarks:
3671 if bookmarks:
3672 output.extend(ctx.bookmarks())
3672 output.extend(ctx.bookmarks())
3673
3673
3674 ui.write("%s\n" % ' '.join(output))
3674 ui.write("%s\n" % ' '.join(output))
3675
3675
3676 @command('import|patch',
3676 @command('import|patch',
3677 [('p', 'strip', 1,
3677 [('p', 'strip', 1,
3678 _('directory strip option for patch. This has the same '
3678 _('directory strip option for patch. This has the same '
3679 'meaning as the corresponding patch option'), _('NUM')),
3679 'meaning as the corresponding patch option'), _('NUM')),
3680 ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')),
3680 ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')),
3681 ('e', 'edit', False, _('invoke editor on commit messages')),
3681 ('e', 'edit', False, _('invoke editor on commit messages')),
3682 ('f', 'force', None,
3682 ('f', 'force', None,
3683 _('skip check for outstanding uncommitted changes (DEPRECATED)')),
3683 _('skip check for outstanding uncommitted changes (DEPRECATED)')),
3684 ('', 'no-commit', None,
3684 ('', 'no-commit', None,
3685 _("don't commit, just update the working directory")),
3685 _("don't commit, just update the working directory")),
3686 ('', 'bypass', None,
3686 ('', 'bypass', None,
3687 _("apply patch without touching the working directory")),
3687 _("apply patch without touching the working directory")),
3688 ('', 'partial', None,
3689 _('commit even if some hunks fail')),
3688 ('', 'exact', None,
3690 ('', 'exact', None,
3689 _('apply patch to the nodes from which it was generated')),
3691 _('apply patch to the nodes from which it was generated')),
3690 ('', 'import-branch', None,
3692 ('', 'import-branch', None,
3691 _('use any branch information in patch (implied by --exact)'))] +
3693 _('use any branch information in patch (implied by --exact)'))] +
3692 commitopts + commitopts2 + similarityopts,
3694 commitopts + commitopts2 + similarityopts,
3693 _('[OPTION]... PATCH...'))
3695 _('[OPTION]... PATCH...'))
3694 def import_(ui, repo, patch1=None, *patches, **opts):
3696 def import_(ui, repo, patch1=None, *patches, **opts):
3695 """import an ordered set of patches
3697 """import an ordered set of patches
3696
3698
3697 Import a list of patches and commit them individually (unless
3699 Import a list of patches and commit them individually (unless
3698 --no-commit is specified).
3700 --no-commit is specified).
3699
3701
3700 Because import first applies changes to the working directory,
3702 Because import first applies changes to the working directory,
3701 import will abort if there are outstanding changes.
3703 import will abort if there are outstanding changes.
3702
3704
3703 You can import a patch straight from a mail message. Even patches
3705 You can import a patch straight from a mail message. Even patches
3704 as attachments work (to use the body part, it must have type
3706 as attachments work (to use the body part, it must have type
3705 text/plain or text/x-patch). From and Subject headers of email
3707 text/plain or text/x-patch). From and Subject headers of email
3706 message are used as default committer and commit message. All
3708 message are used as default committer and commit message. All
3707 text/plain body parts before first diff are added to commit
3709 text/plain body parts before first diff are added to commit
3708 message.
3710 message.
3709
3711
3710 If the imported patch was generated by :hg:`export`, user and
3712 If the imported patch was generated by :hg:`export`, user and
3711 description from patch override values from message headers and
3713 description from patch override values from message headers and
3712 body. Values given on command line with -m/--message and -u/--user
3714 body. Values given on command line with -m/--message and -u/--user
3713 override these.
3715 override these.
3714
3716
3715 If --exact is specified, import will set the working directory to
3717 If --exact is specified, import will set the working directory to
3716 the parent of each patch before applying it, and will abort if the
3718 the parent of each patch before applying it, and will abort if the
3717 resulting changeset has a different ID than the one recorded in
3719 resulting changeset has a different ID than the one recorded in
3718 the patch. This may happen due to character set problems or other
3720 the patch. This may happen due to character set problems or other
3719 deficiencies in the text patch format.
3721 deficiencies in the text patch format.
3720
3722
3721 Use --bypass to apply and commit patches directly to the
3723 Use --bypass to apply and commit patches directly to the
3722 repository, not touching the working directory. Without --exact,
3724 repository, not touching the working directory. Without --exact,
3723 patches will be applied on top of the working directory parent
3725 patches will be applied on top of the working directory parent
3724 revision.
3726 revision.
3725
3727
3726 With -s/--similarity, hg will attempt to discover renames and
3728 With -s/--similarity, hg will attempt to discover renames and
3727 copies in the patch in the same way as :hg:`addremove`.
3729 copies in the patch in the same way as :hg:`addremove`.
3728
3730
3731 Use --partial to ensure a changeset will be created from the patch
3732 even if some hunks fail to apply. Hunks that fail to apply will be
3733 written to a <target-file>.rej file. Conflicts can then be resolved
3734 by hand before :hg:`commit --amend` is run to update the created
3735 changeset. This flag exists to let people import patches that
3736 partially apply without losing the associated metadata (author,
3737 date, description, ...), Note that when none of the hunk applies
3738 cleanly, :hg:`import --partial` will create an empty changeset,
3739 importing only the patch metadata.
3740
3729 To read a patch from standard input, use "-" as the patch name. If
3741 To read a patch from standard input, use "-" as the patch name. If
3730 a URL is specified, the patch will be downloaded from it.
3742 a URL is specified, the patch will be downloaded from it.
3731 See :hg:`help dates` for a list of formats valid for -d/--date.
3743 See :hg:`help dates` for a list of formats valid for -d/--date.
3732
3744
3733 .. container:: verbose
3745 .. container:: verbose
3734
3746
3735 Examples:
3747 Examples:
3736
3748
3737 - import a traditional patch from a website and detect renames::
3749 - import a traditional patch from a website and detect renames::
3738
3750
3739 hg import -s 80 http://example.com/bugfix.patch
3751 hg import -s 80 http://example.com/bugfix.patch
3740
3752
3741 - import a changeset from an hgweb server::
3753 - import a changeset from an hgweb server::
3742
3754
3743 hg import http://www.selenic.com/hg/rev/5ca8c111e9aa
3755 hg import http://www.selenic.com/hg/rev/5ca8c111e9aa
3744
3756
3745 - import all the patches in an Unix-style mbox::
3757 - import all the patches in an Unix-style mbox::
3746
3758
3747 hg import incoming-patches.mbox
3759 hg import incoming-patches.mbox
3748
3760
3749 - attempt to exactly restore an exported changeset (not always
3761 - attempt to exactly restore an exported changeset (not always
3750 possible)::
3762 possible)::
3751
3763
3752 hg import --exact proposed-fix.patch
3764 hg import --exact proposed-fix.patch
3753
3765
3754 Returns 0 on success.
3766 Returns 0 on success, 1 on partial success (see --partial).
3755 """
3767 """
3756
3768
3757 if not patch1:
3769 if not patch1:
3758 raise util.Abort(_('need at least one patch to import'))
3770 raise util.Abort(_('need at least one patch to import'))
3759
3771
3760 patches = (patch1,) + patches
3772 patches = (patch1,) + patches
3761
3773
3762 date = opts.get('date')
3774 date = opts.get('date')
3763 if date:
3775 if date:
3764 opts['date'] = util.parsedate(date)
3776 opts['date'] = util.parsedate(date)
3765
3777
3766 update = not opts.get('bypass')
3778 update = not opts.get('bypass')
3767 if not update and opts.get('no_commit'):
3779 if not update and opts.get('no_commit'):
3768 raise util.Abort(_('cannot use --no-commit with --bypass'))
3780 raise util.Abort(_('cannot use --no-commit with --bypass'))
3769 try:
3781 try:
3770 sim = float(opts.get('similarity') or 0)
3782 sim = float(opts.get('similarity') or 0)
3771 except ValueError:
3783 except ValueError:
3772 raise util.Abort(_('similarity must be a number'))
3784 raise util.Abort(_('similarity must be a number'))
3773 if sim < 0 or sim > 100:
3785 if sim < 0 or sim > 100:
3774 raise util.Abort(_('similarity must be between 0 and 100'))
3786 raise util.Abort(_('similarity must be between 0 and 100'))
3775 if sim and not update:
3787 if sim and not update:
3776 raise util.Abort(_('cannot use --similarity with --bypass'))
3788 raise util.Abort(_('cannot use --similarity with --bypass'))
3777
3789
3778 if update:
3790 if update:
3779 cmdutil.checkunfinished(repo)
3791 cmdutil.checkunfinished(repo)
3780 if (opts.get('exact') or not opts.get('force')) and update:
3792 if (opts.get('exact') or not opts.get('force')) and update:
3781 cmdutil.bailifchanged(repo)
3793 cmdutil.bailifchanged(repo)
3782
3794
3783 base = opts["base"]
3795 base = opts["base"]
3784 wlock = lock = tr = None
3796 wlock = lock = tr = None
3785 msgs = []
3797 msgs = []
3798 ret = 0
3786
3799
3787
3800
3788 try:
3801 try:
3789 try:
3802 try:
3790 wlock = repo.wlock()
3803 wlock = repo.wlock()
3791 if not opts.get('no_commit'):
3804 if not opts.get('no_commit'):
3792 lock = repo.lock()
3805 lock = repo.lock()
3793 tr = repo.transaction('import')
3806 tr = repo.transaction('import')
3794 parents = repo.parents()
3807 parents = repo.parents()
3795 for patchurl in patches:
3808 for patchurl in patches:
3796 if patchurl == '-':
3809 if patchurl == '-':
3797 ui.status(_('applying patch from stdin\n'))
3810 ui.status(_('applying patch from stdin\n'))
3798 patchfile = ui.fin
3811 patchfile = ui.fin
3799 patchurl = 'stdin' # for error message
3812 patchurl = 'stdin' # for error message
3800 else:
3813 else:
3801 patchurl = os.path.join(base, patchurl)
3814 patchurl = os.path.join(base, patchurl)
3802 ui.status(_('applying %s\n') % patchurl)
3815 ui.status(_('applying %s\n') % patchurl)
3803 patchfile = hg.openpath(ui, patchurl)
3816 patchfile = hg.openpath(ui, patchurl)
3804
3817
3805 haspatch = False
3818 haspatch = False
3806 for hunk in patch.split(patchfile):
3819 for hunk in patch.split(patchfile):
3807 (msg, node) = cmdutil.tryimportone(ui, repo, hunk, parents,
3820 (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk,
3808 opts, msgs, hg.clean)
3821 parents, opts,
3822 msgs, hg.clean)
3809 if msg:
3823 if msg:
3810 haspatch = True
3824 haspatch = True
3811 ui.note(msg + '\n')
3825 ui.note(msg + '\n')
3812 if update or opts.get('exact'):
3826 if update or opts.get('exact'):
3813 parents = repo.parents()
3827 parents = repo.parents()
3814 else:
3828 else:
3815 parents = [repo[node]]
3829 parents = [repo[node]]
3830 if rej:
3831 ui.write_err(_("patch applied partially\n"))
3832 ui.write_err(("(fix the .rej files and run "
3833 "`hg commit --amend`)\n"))
3834 ret = 1
3835 break
3816
3836
3817 if not haspatch:
3837 if not haspatch:
3818 raise util.Abort(_('%s: no diffs found') % patchurl)
3838 raise util.Abort(_('%s: no diffs found') % patchurl)
3819
3839
3820 if tr:
3840 if tr:
3821 tr.close()
3841 tr.close()
3822 if msgs:
3842 if msgs:
3823 repo.savecommitmessage('\n* * *\n'.join(msgs))
3843 repo.savecommitmessage('\n* * *\n'.join(msgs))
3844 return ret
3824 except: # re-raises
3845 except: # re-raises
3825 # wlock.release() indirectly calls dirstate.write(): since
3846 # wlock.release() indirectly calls dirstate.write(): since
3826 # we're crashing, we do not want to change the working dir
3847 # we're crashing, we do not want to change the working dir
3827 # parent after all, so make sure it writes nothing
3848 # parent after all, so make sure it writes nothing
3828 repo.dirstate.invalidate()
3849 repo.dirstate.invalidate()
3829 raise
3850 raise
3830 finally:
3851 finally:
3831 if tr:
3852 if tr:
3832 tr.release()
3853 tr.release()
3833 release(lock, wlock)
3854 release(lock, wlock)
3834
3855
3835 @command('incoming|in',
3856 @command('incoming|in',
3836 [('f', 'force', None,
3857 [('f', 'force', None,
3837 _('run even if remote repository is unrelated')),
3858 _('run even if remote repository is unrelated')),
3838 ('n', 'newest-first', None, _('show newest record first')),
3859 ('n', 'newest-first', None, _('show newest record first')),
3839 ('', 'bundle', '',
3860 ('', 'bundle', '',
3840 _('file to store the bundles into'), _('FILE')),
3861 _('file to store the bundles into'), _('FILE')),
3841 ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')),
3862 ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')),
3842 ('B', 'bookmarks', False, _("compare bookmarks")),
3863 ('B', 'bookmarks', False, _("compare bookmarks")),
3843 ('b', 'branch', [],
3864 ('b', 'branch', [],
3844 _('a specific branch you would like to pull'), _('BRANCH')),
3865 _('a specific branch you would like to pull'), _('BRANCH')),
3845 ] + logopts + remoteopts + subrepoopts,
3866 ] + logopts + remoteopts + subrepoopts,
3846 _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]'))
3867 _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]'))
3847 def incoming(ui, repo, source="default", **opts):
3868 def incoming(ui, repo, source="default", **opts):
3848 """show new changesets found in source
3869 """show new changesets found in source
3849
3870
3850 Show new changesets found in the specified path/URL or the default
3871 Show new changesets found in the specified path/URL or the default
3851 pull location. These are the changesets that would have been pulled
3872 pull location. These are the changesets that would have been pulled
3852 if a pull at the time you issued this command.
3873 if a pull at the time you issued this command.
3853
3874
3854 For remote repository, using --bundle avoids downloading the
3875 For remote repository, using --bundle avoids downloading the
3855 changesets twice if the incoming is followed by a pull.
3876 changesets twice if the incoming is followed by a pull.
3856
3877
3857 See pull for valid source format details.
3878 See pull for valid source format details.
3858
3879
3859 .. container:: verbose
3880 .. container:: verbose
3860
3881
3861 Examples:
3882 Examples:
3862
3883
3863 - show incoming changes with patches and full description::
3884 - show incoming changes with patches and full description::
3864
3885
3865 hg incoming -vp
3886 hg incoming -vp
3866
3887
3867 - show incoming changes excluding merges, store a bundle::
3888 - show incoming changes excluding merges, store a bundle::
3868
3889
3869 hg in -vpM --bundle incoming.hg
3890 hg in -vpM --bundle incoming.hg
3870 hg pull incoming.hg
3891 hg pull incoming.hg
3871
3892
3872 - briefly list changes inside a bundle::
3893 - briefly list changes inside a bundle::
3873
3894
3874 hg in changes.hg -T "{desc|firstline}\\n"
3895 hg in changes.hg -T "{desc|firstline}\\n"
3875
3896
3876 Returns 0 if there are incoming changes, 1 otherwise.
3897 Returns 0 if there are incoming changes, 1 otherwise.
3877 """
3898 """
3878 if opts.get('graph'):
3899 if opts.get('graph'):
3879 cmdutil.checkunsupportedgraphflags([], opts)
3900 cmdutil.checkunsupportedgraphflags([], opts)
3880 def display(other, chlist, displayer):
3901 def display(other, chlist, displayer):
3881 revdag = cmdutil.graphrevs(other, chlist, opts)
3902 revdag = cmdutil.graphrevs(other, chlist, opts)
3882 showparents = [ctx.node() for ctx in repo[None].parents()]
3903 showparents = [ctx.node() for ctx in repo[None].parents()]
3883 cmdutil.displaygraph(ui, revdag, displayer, showparents,
3904 cmdutil.displaygraph(ui, revdag, displayer, showparents,
3884 graphmod.asciiedges)
3905 graphmod.asciiedges)
3885
3906
3886 hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True)
3907 hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True)
3887 return 0
3908 return 0
3888
3909
3889 if opts.get('bundle') and opts.get('subrepos'):
3910 if opts.get('bundle') and opts.get('subrepos'):
3890 raise util.Abort(_('cannot combine --bundle and --subrepos'))
3911 raise util.Abort(_('cannot combine --bundle and --subrepos'))
3891
3912
3892 if opts.get('bookmarks'):
3913 if opts.get('bookmarks'):
3893 source, branches = hg.parseurl(ui.expandpath(source),
3914 source, branches = hg.parseurl(ui.expandpath(source),
3894 opts.get('branch'))
3915 opts.get('branch'))
3895 other = hg.peer(repo, opts, source)
3916 other = hg.peer(repo, opts, source)
3896 if 'bookmarks' not in other.listkeys('namespaces'):
3917 if 'bookmarks' not in other.listkeys('namespaces'):
3897 ui.warn(_("remote doesn't support bookmarks\n"))
3918 ui.warn(_("remote doesn't support bookmarks\n"))
3898 return 0
3919 return 0
3899 ui.status(_('comparing with %s\n') % util.hidepassword(source))
3920 ui.status(_('comparing with %s\n') % util.hidepassword(source))
3900 return bookmarks.diff(ui, repo, other)
3921 return bookmarks.diff(ui, repo, other)
3901
3922
3902 repo._subtoppath = ui.expandpath(source)
3923 repo._subtoppath = ui.expandpath(source)
3903 try:
3924 try:
3904 return hg.incoming(ui, repo, source, opts)
3925 return hg.incoming(ui, repo, source, opts)
3905 finally:
3926 finally:
3906 del repo._subtoppath
3927 del repo._subtoppath
3907
3928
3908
3929
3909 @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'))
3930 @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'))
3910 def init(ui, dest=".", **opts):
3931 def init(ui, dest=".", **opts):
3911 """create a new repository in the given directory
3932 """create a new repository in the given directory
3912
3933
3913 Initialize a new repository in the given directory. If the given
3934 Initialize a new repository in the given directory. If the given
3914 directory does not exist, it will be created.
3935 directory does not exist, it will be created.
3915
3936
3916 If no directory is given, the current directory is used.
3937 If no directory is given, the current directory is used.
3917
3938
3918 It is possible to specify an ``ssh://`` URL as the destination.
3939 It is possible to specify an ``ssh://`` URL as the destination.
3919 See :hg:`help urls` for more information.
3940 See :hg:`help urls` for more information.
3920
3941
3921 Returns 0 on success.
3942 Returns 0 on success.
3922 """
3943 """
3923 hg.peer(ui, opts, ui.expandpath(dest), create=True)
3944 hg.peer(ui, opts, ui.expandpath(dest), create=True)
3924
3945
3925 @command('locate',
3946 @command('locate',
3926 [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')),
3947 [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')),
3927 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
3948 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
3928 ('f', 'fullpath', None, _('print complete paths from the filesystem root')),
3949 ('f', 'fullpath', None, _('print complete paths from the filesystem root')),
3929 ] + walkopts,
3950 ] + walkopts,
3930 _('[OPTION]... [PATTERN]...'))
3951 _('[OPTION]... [PATTERN]...'))
3931 def locate(ui, repo, *pats, **opts):
3952 def locate(ui, repo, *pats, **opts):
3932 """locate files matching specific patterns
3953 """locate files matching specific patterns
3933
3954
3934 Print files under Mercurial control in the working directory whose
3955 Print files under Mercurial control in the working directory whose
3935 names match the given patterns.
3956 names match the given patterns.
3936
3957
3937 By default, this command searches all directories in the working
3958 By default, this command searches all directories in the working
3938 directory. To search just the current directory and its
3959 directory. To search just the current directory and its
3939 subdirectories, use "--include .".
3960 subdirectories, use "--include .".
3940
3961
3941 If no patterns are given to match, this command prints the names
3962 If no patterns are given to match, this command prints the names
3942 of all files under Mercurial control in the working directory.
3963 of all files under Mercurial control in the working directory.
3943
3964
3944 If you want to feed the output of this command into the "xargs"
3965 If you want to feed the output of this command into the "xargs"
3945 command, use the -0 option to both this command and "xargs". This
3966 command, use the -0 option to both this command and "xargs". This
3946 will avoid the problem of "xargs" treating single filenames that
3967 will avoid the problem of "xargs" treating single filenames that
3947 contain whitespace as multiple filenames.
3968 contain whitespace as multiple filenames.
3948
3969
3949 Returns 0 if a match is found, 1 otherwise.
3970 Returns 0 if a match is found, 1 otherwise.
3950 """
3971 """
3951 end = opts.get('print0') and '\0' or '\n'
3972 end = opts.get('print0') and '\0' or '\n'
3952 rev = scmutil.revsingle(repo, opts.get('rev'), None).node()
3973 rev = scmutil.revsingle(repo, opts.get('rev'), None).node()
3953
3974
3954 ret = 1
3975 ret = 1
3955 m = scmutil.match(repo[rev], pats, opts, default='relglob')
3976 m = scmutil.match(repo[rev], pats, opts, default='relglob')
3956 m.bad = lambda x, y: False
3977 m.bad = lambda x, y: False
3957 for abs in repo[rev].walk(m):
3978 for abs in repo[rev].walk(m):
3958 if not rev and abs not in repo.dirstate:
3979 if not rev and abs not in repo.dirstate:
3959 continue
3980 continue
3960 if opts.get('fullpath'):
3981 if opts.get('fullpath'):
3961 ui.write(repo.wjoin(abs), end)
3982 ui.write(repo.wjoin(abs), end)
3962 else:
3983 else:
3963 ui.write(((pats and m.rel(abs)) or abs), end)
3984 ui.write(((pats and m.rel(abs)) or abs), end)
3964 ret = 0
3985 ret = 0
3965
3986
3966 return ret
3987 return ret
3967
3988
3968 @command('^log|history',
3989 @command('^log|history',
3969 [('f', 'follow', None,
3990 [('f', 'follow', None,
3970 _('follow changeset history, or file history across copies and renames')),
3991 _('follow changeset history, or file history across copies and renames')),
3971 ('', 'follow-first', None,
3992 ('', 'follow-first', None,
3972 _('only follow the first parent of merge changesets (DEPRECATED)')),
3993 _('only follow the first parent of merge changesets (DEPRECATED)')),
3973 ('d', 'date', '', _('show revisions matching date spec'), _('DATE')),
3994 ('d', 'date', '', _('show revisions matching date spec'), _('DATE')),
3974 ('C', 'copies', None, _('show copied files')),
3995 ('C', 'copies', None, _('show copied files')),
3975 ('k', 'keyword', [],
3996 ('k', 'keyword', [],
3976 _('do case-insensitive search for a given text'), _('TEXT')),
3997 _('do case-insensitive search for a given text'), _('TEXT')),
3977 ('r', 'rev', [], _('show the specified revision or range'), _('REV')),
3998 ('r', 'rev', [], _('show the specified revision or range'), _('REV')),
3978 ('', 'removed', None, _('include revisions where files were removed')),
3999 ('', 'removed', None, _('include revisions where files were removed')),
3979 ('m', 'only-merges', None, _('show only merges (DEPRECATED)')),
4000 ('m', 'only-merges', None, _('show only merges (DEPRECATED)')),
3980 ('u', 'user', [], _('revisions committed by user'), _('USER')),
4001 ('u', 'user', [], _('revisions committed by user'), _('USER')),
3981 ('', 'only-branch', [],
4002 ('', 'only-branch', [],
3982 _('show only changesets within the given named branch (DEPRECATED)'),
4003 _('show only changesets within the given named branch (DEPRECATED)'),
3983 _('BRANCH')),
4004 _('BRANCH')),
3984 ('b', 'branch', [],
4005 ('b', 'branch', [],
3985 _('show changesets within the given named branch'), _('BRANCH')),
4006 _('show changesets within the given named branch'), _('BRANCH')),
3986 ('P', 'prune', [],
4007 ('P', 'prune', [],
3987 _('do not display revision or any of its ancestors'), _('REV')),
4008 _('do not display revision or any of its ancestors'), _('REV')),
3988 ] + logopts + walkopts,
4009 ] + logopts + walkopts,
3989 _('[OPTION]... [FILE]'))
4010 _('[OPTION]... [FILE]'))
3990 def log(ui, repo, *pats, **opts):
4011 def log(ui, repo, *pats, **opts):
3991 """show revision history of entire repository or files
4012 """show revision history of entire repository or files
3992
4013
3993 Print the revision history of the specified files or the entire
4014 Print the revision history of the specified files or the entire
3994 project.
4015 project.
3995
4016
3996 If no revision range is specified, the default is ``tip:0`` unless
4017 If no revision range is specified, the default is ``tip:0`` unless
3997 --follow is set, in which case the working directory parent is
4018 --follow is set, in which case the working directory parent is
3998 used as the starting revision.
4019 used as the starting revision.
3999
4020
4000 File history is shown without following rename or copy history of
4021 File history is shown without following rename or copy history of
4001 files. Use -f/--follow with a filename to follow history across
4022 files. Use -f/--follow with a filename to follow history across
4002 renames and copies. --follow without a filename will only show
4023 renames and copies. --follow without a filename will only show
4003 ancestors or descendants of the starting revision.
4024 ancestors or descendants of the starting revision.
4004
4025
4005 By default this command prints revision number and changeset id,
4026 By default this command prints revision number and changeset id,
4006 tags, non-trivial parents, user, date and time, and a summary for
4027 tags, non-trivial parents, user, date and time, and a summary for
4007 each commit. When the -v/--verbose switch is used, the list of
4028 each commit. When the -v/--verbose switch is used, the list of
4008 changed files and full commit message are shown.
4029 changed files and full commit message are shown.
4009
4030
4010 With --graph the revisions are shown as an ASCII art DAG with the most
4031 With --graph the revisions are shown as an ASCII art DAG with the most
4011 recent changeset at the top.
4032 recent changeset at the top.
4012 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete,
4033 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete,
4013 and '+' represents a fork where the changeset from the lines below is a
4034 and '+' represents a fork where the changeset from the lines below is a
4014 parent of the 'o' merge on the same line.
4035 parent of the 'o' merge on the same line.
4015
4036
4016 .. note::
4037 .. note::
4017
4038
4018 log -p/--patch may generate unexpected diff output for merge
4039 log -p/--patch may generate unexpected diff output for merge
4019 changesets, as it will only compare the merge changeset against
4040 changesets, as it will only compare the merge changeset against
4020 its first parent. Also, only files different from BOTH parents
4041 its first parent. Also, only files different from BOTH parents
4021 will appear in files:.
4042 will appear in files:.
4022
4043
4023 .. note::
4044 .. note::
4024
4045
4025 for performance reasons, log FILE may omit duplicate changes
4046 for performance reasons, log FILE may omit duplicate changes
4026 made on branches and will not show deletions. To see all
4047 made on branches and will not show deletions. To see all
4027 changes including duplicates and deletions, use the --removed
4048 changes including duplicates and deletions, use the --removed
4028 switch.
4049 switch.
4029
4050
4030 .. container:: verbose
4051 .. container:: verbose
4031
4052
4032 Some examples:
4053 Some examples:
4033
4054
4034 - changesets with full descriptions and file lists::
4055 - changesets with full descriptions and file lists::
4035
4056
4036 hg log -v
4057 hg log -v
4037
4058
4038 - changesets ancestral to the working directory::
4059 - changesets ancestral to the working directory::
4039
4060
4040 hg log -f
4061 hg log -f
4041
4062
4042 - last 10 commits on the current branch::
4063 - last 10 commits on the current branch::
4043
4064
4044 hg log -l 10 -b .
4065 hg log -l 10 -b .
4045
4066
4046 - changesets showing all modifications of a file, including removals::
4067 - changesets showing all modifications of a file, including removals::
4047
4068
4048 hg log --removed file.c
4069 hg log --removed file.c
4049
4070
4050 - all changesets that touch a directory, with diffs, excluding merges::
4071 - all changesets that touch a directory, with diffs, excluding merges::
4051
4072
4052 hg log -Mp lib/
4073 hg log -Mp lib/
4053
4074
4054 - all revision numbers that match a keyword::
4075 - all revision numbers that match a keyword::
4055
4076
4056 hg log -k bug --template "{rev}\\n"
4077 hg log -k bug --template "{rev}\\n"
4057
4078
4058 - check if a given changeset is included is a tagged release::
4079 - check if a given changeset is included is a tagged release::
4059
4080
4060 hg log -r "a21ccf and ancestor(1.9)"
4081 hg log -r "a21ccf and ancestor(1.9)"
4061
4082
4062 - find all changesets by some user in a date range::
4083 - find all changesets by some user in a date range::
4063
4084
4064 hg log -k alice -d "may 2008 to jul 2008"
4085 hg log -k alice -d "may 2008 to jul 2008"
4065
4086
4066 - summary of all changesets after the last tag::
4087 - summary of all changesets after the last tag::
4067
4088
4068 hg log -r "last(tagged())::" --template "{desc|firstline}\\n"
4089 hg log -r "last(tagged())::" --template "{desc|firstline}\\n"
4069
4090
4070 See :hg:`help dates` for a list of formats valid for -d/--date.
4091 See :hg:`help dates` for a list of formats valid for -d/--date.
4071
4092
4072 See :hg:`help revisions` and :hg:`help revsets` for more about
4093 See :hg:`help revisions` and :hg:`help revsets` for more about
4073 specifying revisions.
4094 specifying revisions.
4074
4095
4075 See :hg:`help templates` for more about pre-packaged styles and
4096 See :hg:`help templates` for more about pre-packaged styles and
4076 specifying custom templates.
4097 specifying custom templates.
4077
4098
4078 Returns 0 on success.
4099 Returns 0 on success.
4079 """
4100 """
4080 if opts.get('graph'):
4101 if opts.get('graph'):
4081 return cmdutil.graphlog(ui, repo, *pats, **opts)
4102 return cmdutil.graphlog(ui, repo, *pats, **opts)
4082
4103
4083 revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts)
4104 revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts)
4084 limit = cmdutil.loglimit(opts)
4105 limit = cmdutil.loglimit(opts)
4085 count = 0
4106 count = 0
4086
4107
4087 getrenamed = None
4108 getrenamed = None
4088 if opts.get('copies'):
4109 if opts.get('copies'):
4089 endrev = None
4110 endrev = None
4090 if opts.get('rev'):
4111 if opts.get('rev'):
4091 endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1
4112 endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1
4092 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
4113 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
4093
4114
4094 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
4115 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
4095 for rev in revs:
4116 for rev in revs:
4096 if count == limit:
4117 if count == limit:
4097 break
4118 break
4098 ctx = repo[rev]
4119 ctx = repo[rev]
4099 copies = None
4120 copies = None
4100 if getrenamed is not None and rev:
4121 if getrenamed is not None and rev:
4101 copies = []
4122 copies = []
4102 for fn in ctx.files():
4123 for fn in ctx.files():
4103 rename = getrenamed(fn, rev)
4124 rename = getrenamed(fn, rev)
4104 if rename:
4125 if rename:
4105 copies.append((fn, rename[0]))
4126 copies.append((fn, rename[0]))
4106 revmatchfn = filematcher and filematcher(ctx.rev()) or None
4127 revmatchfn = filematcher and filematcher(ctx.rev()) or None
4107 displayer.show(ctx, copies=copies, matchfn=revmatchfn)
4128 displayer.show(ctx, copies=copies, matchfn=revmatchfn)
4108 if displayer.flush(rev):
4129 if displayer.flush(rev):
4109 count += 1
4130 count += 1
4110
4131
4111 displayer.close()
4132 displayer.close()
4112
4133
4113 @command('manifest',
4134 @command('manifest',
4114 [('r', 'rev', '', _('revision to display'), _('REV')),
4135 [('r', 'rev', '', _('revision to display'), _('REV')),
4115 ('', 'all', False, _("list files from all revisions"))],
4136 ('', 'all', False, _("list files from all revisions"))],
4116 _('[-r REV]'))
4137 _('[-r REV]'))
4117 def manifest(ui, repo, node=None, rev=None, **opts):
4138 def manifest(ui, repo, node=None, rev=None, **opts):
4118 """output the current or given revision of the project manifest
4139 """output the current or given revision of the project manifest
4119
4140
4120 Print a list of version controlled files for the given revision.
4141 Print a list of version controlled files for the given revision.
4121 If no revision is given, the first parent of the working directory
4142 If no revision is given, the first parent of the working directory
4122 is used, or the null revision if no revision is checked out.
4143 is used, or the null revision if no revision is checked out.
4123
4144
4124 With -v, print file permissions, symlink and executable bits.
4145 With -v, print file permissions, symlink and executable bits.
4125 With --debug, print file revision hashes.
4146 With --debug, print file revision hashes.
4126
4147
4127 If option --all is specified, the list of all files from all revisions
4148 If option --all is specified, the list of all files from all revisions
4128 is printed. This includes deleted and renamed files.
4149 is printed. This includes deleted and renamed files.
4129
4150
4130 Returns 0 on success.
4151 Returns 0 on success.
4131 """
4152 """
4132
4153
4133 fm = ui.formatter('manifest', opts)
4154 fm = ui.formatter('manifest', opts)
4134
4155
4135 if opts.get('all'):
4156 if opts.get('all'):
4136 if rev or node:
4157 if rev or node:
4137 raise util.Abort(_("can't specify a revision with --all"))
4158 raise util.Abort(_("can't specify a revision with --all"))
4138
4159
4139 res = []
4160 res = []
4140 prefix = "data/"
4161 prefix = "data/"
4141 suffix = ".i"
4162 suffix = ".i"
4142 plen = len(prefix)
4163 plen = len(prefix)
4143 slen = len(suffix)
4164 slen = len(suffix)
4144 lock = repo.lock()
4165 lock = repo.lock()
4145 try:
4166 try:
4146 for fn, b, size in repo.store.datafiles():
4167 for fn, b, size in repo.store.datafiles():
4147 if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix:
4168 if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix:
4148 res.append(fn[plen:-slen])
4169 res.append(fn[plen:-slen])
4149 finally:
4170 finally:
4150 lock.release()
4171 lock.release()
4151 for f in res:
4172 for f in res:
4152 fm.startitem()
4173 fm.startitem()
4153 fm.write("path", '%s\n', f)
4174 fm.write("path", '%s\n', f)
4154 fm.end()
4175 fm.end()
4155 return
4176 return
4156
4177
4157 if rev and node:
4178 if rev and node:
4158 raise util.Abort(_("please specify just one revision"))
4179 raise util.Abort(_("please specify just one revision"))
4159
4180
4160 if not node:
4181 if not node:
4161 node = rev
4182 node = rev
4162
4183
4163 char = {'l': '@', 'x': '*', '': ''}
4184 char = {'l': '@', 'x': '*', '': ''}
4164 mode = {'l': '644', 'x': '755', '': '644'}
4185 mode = {'l': '644', 'x': '755', '': '644'}
4165 ctx = scmutil.revsingle(repo, node)
4186 ctx = scmutil.revsingle(repo, node)
4166 mf = ctx.manifest()
4187 mf = ctx.manifest()
4167 for f in ctx:
4188 for f in ctx:
4168 fm.startitem()
4189 fm.startitem()
4169 fl = ctx[f].flags()
4190 fl = ctx[f].flags()
4170 fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f]))
4191 fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f]))
4171 fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl])
4192 fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl])
4172 fm.write('path', '%s\n', f)
4193 fm.write('path', '%s\n', f)
4173 fm.end()
4194 fm.end()
4174
4195
4175 @command('^merge',
4196 @command('^merge',
4176 [('f', 'force', None,
4197 [('f', 'force', None,
4177 _('force a merge including outstanding changes (DEPRECATED)')),
4198 _('force a merge including outstanding changes (DEPRECATED)')),
4178 ('r', 'rev', '', _('revision to merge'), _('REV')),
4199 ('r', 'rev', '', _('revision to merge'), _('REV')),
4179 ('P', 'preview', None,
4200 ('P', 'preview', None,
4180 _('review revisions to merge (no merge is performed)'))
4201 _('review revisions to merge (no merge is performed)'))
4181 ] + mergetoolopts,
4202 ] + mergetoolopts,
4182 _('[-P] [-f] [[-r] REV]'))
4203 _('[-P] [-f] [[-r] REV]'))
4183 def merge(ui, repo, node=None, **opts):
4204 def merge(ui, repo, node=None, **opts):
4184 """merge working directory with another revision
4205 """merge working directory with another revision
4185
4206
4186 The current working directory is updated with all changes made in
4207 The current working directory is updated with all changes made in
4187 the requested revision since the last common predecessor revision.
4208 the requested revision since the last common predecessor revision.
4188
4209
4189 Files that changed between either parent are marked as changed for
4210 Files that changed between either parent are marked as changed for
4190 the next commit and a commit must be performed before any further
4211 the next commit and a commit must be performed before any further
4191 updates to the repository are allowed. The next commit will have
4212 updates to the repository are allowed. The next commit will have
4192 two parents.
4213 two parents.
4193
4214
4194 ``--tool`` can be used to specify the merge tool used for file
4215 ``--tool`` can be used to specify the merge tool used for file
4195 merges. It overrides the HGMERGE environment variable and your
4216 merges. It overrides the HGMERGE environment variable and your
4196 configuration files. See :hg:`help merge-tools` for options.
4217 configuration files. See :hg:`help merge-tools` for options.
4197
4218
4198 If no revision is specified, the working directory's parent is a
4219 If no revision is specified, the working directory's parent is a
4199 head revision, and the current branch contains exactly one other
4220 head revision, and the current branch contains exactly one other
4200 head, the other head is merged with by default. Otherwise, an
4221 head, the other head is merged with by default. Otherwise, an
4201 explicit revision with which to merge with must be provided.
4222 explicit revision with which to merge with must be provided.
4202
4223
4203 :hg:`resolve` must be used to resolve unresolved files.
4224 :hg:`resolve` must be used to resolve unresolved files.
4204
4225
4205 To undo an uncommitted merge, use :hg:`update --clean .` which
4226 To undo an uncommitted merge, use :hg:`update --clean .` which
4206 will check out a clean copy of the original merge parent, losing
4227 will check out a clean copy of the original merge parent, losing
4207 all changes.
4228 all changes.
4208
4229
4209 Returns 0 on success, 1 if there are unresolved files.
4230 Returns 0 on success, 1 if there are unresolved files.
4210 """
4231 """
4211
4232
4212 if opts.get('rev') and node:
4233 if opts.get('rev') and node:
4213 raise util.Abort(_("please specify just one revision"))
4234 raise util.Abort(_("please specify just one revision"))
4214 if not node:
4235 if not node:
4215 node = opts.get('rev')
4236 node = opts.get('rev')
4216
4237
4217 if node:
4238 if node:
4218 node = scmutil.revsingle(repo, node).node()
4239 node = scmutil.revsingle(repo, node).node()
4219
4240
4220 if not node and repo._bookmarkcurrent:
4241 if not node and repo._bookmarkcurrent:
4221 bmheads = repo.bookmarkheads(repo._bookmarkcurrent)
4242 bmheads = repo.bookmarkheads(repo._bookmarkcurrent)
4222 curhead = repo[repo._bookmarkcurrent].node()
4243 curhead = repo[repo._bookmarkcurrent].node()
4223 if len(bmheads) == 2:
4244 if len(bmheads) == 2:
4224 if curhead == bmheads[0]:
4245 if curhead == bmheads[0]:
4225 node = bmheads[1]
4246 node = bmheads[1]
4226 else:
4247 else:
4227 node = bmheads[0]
4248 node = bmheads[0]
4228 elif len(bmheads) > 2:
4249 elif len(bmheads) > 2:
4229 raise util.Abort(_("multiple matching bookmarks to merge - "
4250 raise util.Abort(_("multiple matching bookmarks to merge - "
4230 "please merge with an explicit rev or bookmark"),
4251 "please merge with an explicit rev or bookmark"),
4231 hint=_("run 'hg heads' to see all heads"))
4252 hint=_("run 'hg heads' to see all heads"))
4232 elif len(bmheads) <= 1:
4253 elif len(bmheads) <= 1:
4233 raise util.Abort(_("no matching bookmark to merge - "
4254 raise util.Abort(_("no matching bookmark to merge - "
4234 "please merge with an explicit rev or bookmark"),
4255 "please merge with an explicit rev or bookmark"),
4235 hint=_("run 'hg heads' to see all heads"))
4256 hint=_("run 'hg heads' to see all heads"))
4236
4257
4237 if not node and not repo._bookmarkcurrent:
4258 if not node and not repo._bookmarkcurrent:
4238 branch = repo[None].branch()
4259 branch = repo[None].branch()
4239 bheads = repo.branchheads(branch)
4260 bheads = repo.branchheads(branch)
4240 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
4261 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
4241
4262
4242 if len(nbhs) > 2:
4263 if len(nbhs) > 2:
4243 raise util.Abort(_("branch '%s' has %d heads - "
4264 raise util.Abort(_("branch '%s' has %d heads - "
4244 "please merge with an explicit rev")
4265 "please merge with an explicit rev")
4245 % (branch, len(bheads)),
4266 % (branch, len(bheads)),
4246 hint=_("run 'hg heads .' to see heads"))
4267 hint=_("run 'hg heads .' to see heads"))
4247
4268
4248 parent = repo.dirstate.p1()
4269 parent = repo.dirstate.p1()
4249 if len(nbhs) <= 1:
4270 if len(nbhs) <= 1:
4250 if len(bheads) > 1:
4271 if len(bheads) > 1:
4251 raise util.Abort(_("heads are bookmarked - "
4272 raise util.Abort(_("heads are bookmarked - "
4252 "please merge with an explicit rev"),
4273 "please merge with an explicit rev"),
4253 hint=_("run 'hg heads' to see all heads"))
4274 hint=_("run 'hg heads' to see all heads"))
4254 if len(repo.heads()) > 1:
4275 if len(repo.heads()) > 1:
4255 raise util.Abort(_("branch '%s' has one head - "
4276 raise util.Abort(_("branch '%s' has one head - "
4256 "please merge with an explicit rev")
4277 "please merge with an explicit rev")
4257 % branch,
4278 % branch,
4258 hint=_("run 'hg heads' to see all heads"))
4279 hint=_("run 'hg heads' to see all heads"))
4259 msg, hint = _('nothing to merge'), None
4280 msg, hint = _('nothing to merge'), None
4260 if parent != repo.lookup(branch):
4281 if parent != repo.lookup(branch):
4261 hint = _("use 'hg update' instead")
4282 hint = _("use 'hg update' instead")
4262 raise util.Abort(msg, hint=hint)
4283 raise util.Abort(msg, hint=hint)
4263
4284
4264 if parent not in bheads:
4285 if parent not in bheads:
4265 raise util.Abort(_('working directory not at a head revision'),
4286 raise util.Abort(_('working directory not at a head revision'),
4266 hint=_("use 'hg update' or merge with an "
4287 hint=_("use 'hg update' or merge with an "
4267 "explicit revision"))
4288 "explicit revision"))
4268 if parent == nbhs[0]:
4289 if parent == nbhs[0]:
4269 node = nbhs[-1]
4290 node = nbhs[-1]
4270 else:
4291 else:
4271 node = nbhs[0]
4292 node = nbhs[0]
4272
4293
4273 if opts.get('preview'):
4294 if opts.get('preview'):
4274 # find nodes that are ancestors of p2 but not of p1
4295 # find nodes that are ancestors of p2 but not of p1
4275 p1 = repo.lookup('.')
4296 p1 = repo.lookup('.')
4276 p2 = repo.lookup(node)
4297 p2 = repo.lookup(node)
4277 nodes = repo.changelog.findmissing(common=[p1], heads=[p2])
4298 nodes = repo.changelog.findmissing(common=[p1], heads=[p2])
4278
4299
4279 displayer = cmdutil.show_changeset(ui, repo, opts)
4300 displayer = cmdutil.show_changeset(ui, repo, opts)
4280 for node in nodes:
4301 for node in nodes:
4281 displayer.show(repo[node])
4302 displayer.show(repo[node])
4282 displayer.close()
4303 displayer.close()
4283 return 0
4304 return 0
4284
4305
4285 try:
4306 try:
4286 # ui.forcemerge is an internal variable, do not document
4307 # ui.forcemerge is an internal variable, do not document
4287 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge')
4308 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge')
4288 return hg.merge(repo, node, force=opts.get('force'))
4309 return hg.merge(repo, node, force=opts.get('force'))
4289 finally:
4310 finally:
4290 ui.setconfig('ui', 'forcemerge', '', 'merge')
4311 ui.setconfig('ui', 'forcemerge', '', 'merge')
4291
4312
4292 @command('outgoing|out',
4313 @command('outgoing|out',
4293 [('f', 'force', None, _('run even when the destination is unrelated')),
4314 [('f', 'force', None, _('run even when the destination is unrelated')),
4294 ('r', 'rev', [],
4315 ('r', 'rev', [],
4295 _('a changeset intended to be included in the destination'), _('REV')),
4316 _('a changeset intended to be included in the destination'), _('REV')),
4296 ('n', 'newest-first', None, _('show newest record first')),
4317 ('n', 'newest-first', None, _('show newest record first')),
4297 ('B', 'bookmarks', False, _('compare bookmarks')),
4318 ('B', 'bookmarks', False, _('compare bookmarks')),
4298 ('b', 'branch', [], _('a specific branch you would like to push'),
4319 ('b', 'branch', [], _('a specific branch you would like to push'),
4299 _('BRANCH')),
4320 _('BRANCH')),
4300 ] + logopts + remoteopts + subrepoopts,
4321 ] + logopts + remoteopts + subrepoopts,
4301 _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]'))
4322 _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]'))
4302 def outgoing(ui, repo, dest=None, **opts):
4323 def outgoing(ui, repo, dest=None, **opts):
4303 """show changesets not found in the destination
4324 """show changesets not found in the destination
4304
4325
4305 Show changesets not found in the specified destination repository
4326 Show changesets not found in the specified destination repository
4306 or the default push location. These are the changesets that would
4327 or the default push location. These are the changesets that would
4307 be pushed if a push was requested.
4328 be pushed if a push was requested.
4308
4329
4309 See pull for details of valid destination formats.
4330 See pull for details of valid destination formats.
4310
4331
4311 Returns 0 if there are outgoing changes, 1 otherwise.
4332 Returns 0 if there are outgoing changes, 1 otherwise.
4312 """
4333 """
4313 if opts.get('graph'):
4334 if opts.get('graph'):
4314 cmdutil.checkunsupportedgraphflags([], opts)
4335 cmdutil.checkunsupportedgraphflags([], opts)
4315 o, other = hg._outgoing(ui, repo, dest, opts)
4336 o, other = hg._outgoing(ui, repo, dest, opts)
4316 if not o:
4337 if not o:
4317 cmdutil.outgoinghooks(ui, repo, other, opts, o)
4338 cmdutil.outgoinghooks(ui, repo, other, opts, o)
4318 return
4339 return
4319
4340
4320 revdag = cmdutil.graphrevs(repo, o, opts)
4341 revdag = cmdutil.graphrevs(repo, o, opts)
4321 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
4342 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
4322 showparents = [ctx.node() for ctx in repo[None].parents()]
4343 showparents = [ctx.node() for ctx in repo[None].parents()]
4323 cmdutil.displaygraph(ui, revdag, displayer, showparents,
4344 cmdutil.displaygraph(ui, revdag, displayer, showparents,
4324 graphmod.asciiedges)
4345 graphmod.asciiedges)
4325 cmdutil.outgoinghooks(ui, repo, other, opts, o)
4346 cmdutil.outgoinghooks(ui, repo, other, opts, o)
4326 return 0
4347 return 0
4327
4348
4328 if opts.get('bookmarks'):
4349 if opts.get('bookmarks'):
4329 dest = ui.expandpath(dest or 'default-push', dest or 'default')
4350 dest = ui.expandpath(dest or 'default-push', dest or 'default')
4330 dest, branches = hg.parseurl(dest, opts.get('branch'))
4351 dest, branches = hg.parseurl(dest, opts.get('branch'))
4331 other = hg.peer(repo, opts, dest)
4352 other = hg.peer(repo, opts, dest)
4332 if 'bookmarks' not in other.listkeys('namespaces'):
4353 if 'bookmarks' not in other.listkeys('namespaces'):
4333 ui.warn(_("remote doesn't support bookmarks\n"))
4354 ui.warn(_("remote doesn't support bookmarks\n"))
4334 return 0
4355 return 0
4335 ui.status(_('comparing with %s\n') % util.hidepassword(dest))
4356 ui.status(_('comparing with %s\n') % util.hidepassword(dest))
4336 return bookmarks.diff(ui, other, repo)
4357 return bookmarks.diff(ui, other, repo)
4337
4358
4338 repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default')
4359 repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default')
4339 try:
4360 try:
4340 return hg.outgoing(ui, repo, dest, opts)
4361 return hg.outgoing(ui, repo, dest, opts)
4341 finally:
4362 finally:
4342 del repo._subtoppath
4363 del repo._subtoppath
4343
4364
4344 @command('parents',
4365 @command('parents',
4345 [('r', 'rev', '', _('show parents of the specified revision'), _('REV')),
4366 [('r', 'rev', '', _('show parents of the specified revision'), _('REV')),
4346 ] + templateopts,
4367 ] + templateopts,
4347 _('[-r REV] [FILE]'))
4368 _('[-r REV] [FILE]'))
4348 def parents(ui, repo, file_=None, **opts):
4369 def parents(ui, repo, file_=None, **opts):
4349 """show the parents of the working directory or revision
4370 """show the parents of the working directory or revision
4350
4371
4351 Print the working directory's parent revisions. If a revision is
4372 Print the working directory's parent revisions. If a revision is
4352 given via -r/--rev, the parent of that revision will be printed.
4373 given via -r/--rev, the parent of that revision will be printed.
4353 If a file argument is given, the revision in which the file was
4374 If a file argument is given, the revision in which the file was
4354 last changed (before the working directory revision or the
4375 last changed (before the working directory revision or the
4355 argument to --rev if given) is printed.
4376 argument to --rev if given) is printed.
4356
4377
4357 Returns 0 on success.
4378 Returns 0 on success.
4358 """
4379 """
4359
4380
4360 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
4381 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
4361
4382
4362 if file_:
4383 if file_:
4363 m = scmutil.match(ctx, (file_,), opts)
4384 m = scmutil.match(ctx, (file_,), opts)
4364 if m.anypats() or len(m.files()) != 1:
4385 if m.anypats() or len(m.files()) != 1:
4365 raise util.Abort(_('can only specify an explicit filename'))
4386 raise util.Abort(_('can only specify an explicit filename'))
4366 file_ = m.files()[0]
4387 file_ = m.files()[0]
4367 filenodes = []
4388 filenodes = []
4368 for cp in ctx.parents():
4389 for cp in ctx.parents():
4369 if not cp:
4390 if not cp:
4370 continue
4391 continue
4371 try:
4392 try:
4372 filenodes.append(cp.filenode(file_))
4393 filenodes.append(cp.filenode(file_))
4373 except error.LookupError:
4394 except error.LookupError:
4374 pass
4395 pass
4375 if not filenodes:
4396 if not filenodes:
4376 raise util.Abort(_("'%s' not found in manifest!") % file_)
4397 raise util.Abort(_("'%s' not found in manifest!") % file_)
4377 p = []
4398 p = []
4378 for fn in filenodes:
4399 for fn in filenodes:
4379 fctx = repo.filectx(file_, fileid=fn)
4400 fctx = repo.filectx(file_, fileid=fn)
4380 p.append(fctx.node())
4401 p.append(fctx.node())
4381 else:
4402 else:
4382 p = [cp.node() for cp in ctx.parents()]
4403 p = [cp.node() for cp in ctx.parents()]
4383
4404
4384 displayer = cmdutil.show_changeset(ui, repo, opts)
4405 displayer = cmdutil.show_changeset(ui, repo, opts)
4385 for n in p:
4406 for n in p:
4386 if n != nullid:
4407 if n != nullid:
4387 displayer.show(repo[n])
4408 displayer.show(repo[n])
4388 displayer.close()
4409 displayer.close()
4389
4410
4390 @command('paths', [], _('[NAME]'))
4411 @command('paths', [], _('[NAME]'))
4391 def paths(ui, repo, search=None):
4412 def paths(ui, repo, search=None):
4392 """show aliases for remote repositories
4413 """show aliases for remote repositories
4393
4414
4394 Show definition of symbolic path name NAME. If no name is given,
4415 Show definition of symbolic path name NAME. If no name is given,
4395 show definition of all available names.
4416 show definition of all available names.
4396
4417
4397 Option -q/--quiet suppresses all output when searching for NAME
4418 Option -q/--quiet suppresses all output when searching for NAME
4398 and shows only the path names when listing all definitions.
4419 and shows only the path names when listing all definitions.
4399
4420
4400 Path names are defined in the [paths] section of your
4421 Path names are defined in the [paths] section of your
4401 configuration file and in ``/etc/mercurial/hgrc``. If run inside a
4422 configuration file and in ``/etc/mercurial/hgrc``. If run inside a
4402 repository, ``.hg/hgrc`` is used, too.
4423 repository, ``.hg/hgrc`` is used, too.
4403
4424
4404 The path names ``default`` and ``default-push`` have a special
4425 The path names ``default`` and ``default-push`` have a special
4405 meaning. When performing a push or pull operation, they are used
4426 meaning. When performing a push or pull operation, they are used
4406 as fallbacks if no location is specified on the command-line.
4427 as fallbacks if no location is specified on the command-line.
4407 When ``default-push`` is set, it will be used for push and
4428 When ``default-push`` is set, it will be used for push and
4408 ``default`` will be used for pull; otherwise ``default`` is used
4429 ``default`` will be used for pull; otherwise ``default`` is used
4409 as the fallback for both. When cloning a repository, the clone
4430 as the fallback for both. When cloning a repository, the clone
4410 source is written as ``default`` in ``.hg/hgrc``. Note that
4431 source is written as ``default`` in ``.hg/hgrc``. Note that
4411 ``default`` and ``default-push`` apply to all inbound (e.g.
4432 ``default`` and ``default-push`` apply to all inbound (e.g.
4412 :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and
4433 :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and
4413 :hg:`bundle`) operations.
4434 :hg:`bundle`) operations.
4414
4435
4415 See :hg:`help urls` for more information.
4436 See :hg:`help urls` for more information.
4416
4437
4417 Returns 0 on success.
4438 Returns 0 on success.
4418 """
4439 """
4419 if search:
4440 if search:
4420 for name, path in ui.configitems("paths"):
4441 for name, path in ui.configitems("paths"):
4421 if name == search:
4442 if name == search:
4422 ui.status("%s\n" % util.hidepassword(path))
4443 ui.status("%s\n" % util.hidepassword(path))
4423 return
4444 return
4424 if not ui.quiet:
4445 if not ui.quiet:
4425 ui.warn(_("not found!\n"))
4446 ui.warn(_("not found!\n"))
4426 return 1
4447 return 1
4427 else:
4448 else:
4428 for name, path in ui.configitems("paths"):
4449 for name, path in ui.configitems("paths"):
4429 if ui.quiet:
4450 if ui.quiet:
4430 ui.write("%s\n" % name)
4451 ui.write("%s\n" % name)
4431 else:
4452 else:
4432 ui.write("%s = %s\n" % (name, util.hidepassword(path)))
4453 ui.write("%s = %s\n" % (name, util.hidepassword(path)))
4433
4454
4434 @command('phase',
4455 @command('phase',
4435 [('p', 'public', False, _('set changeset phase to public')),
4456 [('p', 'public', False, _('set changeset phase to public')),
4436 ('d', 'draft', False, _('set changeset phase to draft')),
4457 ('d', 'draft', False, _('set changeset phase to draft')),
4437 ('s', 'secret', False, _('set changeset phase to secret')),
4458 ('s', 'secret', False, _('set changeset phase to secret')),
4438 ('f', 'force', False, _('allow to move boundary backward')),
4459 ('f', 'force', False, _('allow to move boundary backward')),
4439 ('r', 'rev', [], _('target revision'), _('REV')),
4460 ('r', 'rev', [], _('target revision'), _('REV')),
4440 ],
4461 ],
4441 _('[-p|-d|-s] [-f] [-r] REV...'))
4462 _('[-p|-d|-s] [-f] [-r] REV...'))
4442 def phase(ui, repo, *revs, **opts):
4463 def phase(ui, repo, *revs, **opts):
4443 """set or show the current phase name
4464 """set or show the current phase name
4444
4465
4445 With no argument, show the phase name of specified revisions.
4466 With no argument, show the phase name of specified revisions.
4446
4467
4447 With one of -p/--public, -d/--draft or -s/--secret, change the
4468 With one of -p/--public, -d/--draft or -s/--secret, change the
4448 phase value of the specified revisions.
4469 phase value of the specified revisions.
4449
4470
4450 Unless -f/--force is specified, :hg:`phase` won't move changeset from a
4471 Unless -f/--force is specified, :hg:`phase` won't move changeset from a
4451 lower phase to an higher phase. Phases are ordered as follows::
4472 lower phase to an higher phase. Phases are ordered as follows::
4452
4473
4453 public < draft < secret
4474 public < draft < secret
4454
4475
4455 Returns 0 on success, 1 if no phases were changed or some could not
4476 Returns 0 on success, 1 if no phases were changed or some could not
4456 be changed.
4477 be changed.
4457 """
4478 """
4458 # search for a unique phase argument
4479 # search for a unique phase argument
4459 targetphase = None
4480 targetphase = None
4460 for idx, name in enumerate(phases.phasenames):
4481 for idx, name in enumerate(phases.phasenames):
4461 if opts[name]:
4482 if opts[name]:
4462 if targetphase is not None:
4483 if targetphase is not None:
4463 raise util.Abort(_('only one phase can be specified'))
4484 raise util.Abort(_('only one phase can be specified'))
4464 targetphase = idx
4485 targetphase = idx
4465
4486
4466 # look for specified revision
4487 # look for specified revision
4467 revs = list(revs)
4488 revs = list(revs)
4468 revs.extend(opts['rev'])
4489 revs.extend(opts['rev'])
4469 if not revs:
4490 if not revs:
4470 raise util.Abort(_('no revisions specified'))
4491 raise util.Abort(_('no revisions specified'))
4471
4492
4472 revs = scmutil.revrange(repo, revs)
4493 revs = scmutil.revrange(repo, revs)
4473
4494
4474 lock = None
4495 lock = None
4475 ret = 0
4496 ret = 0
4476 if targetphase is None:
4497 if targetphase is None:
4477 # display
4498 # display
4478 for r in revs:
4499 for r in revs:
4479 ctx = repo[r]
4500 ctx = repo[r]
4480 ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr()))
4501 ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr()))
4481 else:
4502 else:
4482 lock = repo.lock()
4503 lock = repo.lock()
4483 try:
4504 try:
4484 # set phase
4505 # set phase
4485 if not revs:
4506 if not revs:
4486 raise util.Abort(_('empty revision set'))
4507 raise util.Abort(_('empty revision set'))
4487 nodes = [repo[r].node() for r in revs]
4508 nodes = [repo[r].node() for r in revs]
4488 olddata = repo._phasecache.getphaserevs(repo)[:]
4509 olddata = repo._phasecache.getphaserevs(repo)[:]
4489 phases.advanceboundary(repo, targetphase, nodes)
4510 phases.advanceboundary(repo, targetphase, nodes)
4490 if opts['force']:
4511 if opts['force']:
4491 phases.retractboundary(repo, targetphase, nodes)
4512 phases.retractboundary(repo, targetphase, nodes)
4492 finally:
4513 finally:
4493 lock.release()
4514 lock.release()
4494 # moving revision from public to draft may hide them
4515 # moving revision from public to draft may hide them
4495 # We have to check result on an unfiltered repository
4516 # We have to check result on an unfiltered repository
4496 unfi = repo.unfiltered()
4517 unfi = repo.unfiltered()
4497 newdata = repo._phasecache.getphaserevs(unfi)
4518 newdata = repo._phasecache.getphaserevs(unfi)
4498 changes = sum(o != newdata[i] for i, o in enumerate(olddata))
4519 changes = sum(o != newdata[i] for i, o in enumerate(olddata))
4499 cl = unfi.changelog
4520 cl = unfi.changelog
4500 rejected = [n for n in nodes
4521 rejected = [n for n in nodes
4501 if newdata[cl.rev(n)] < targetphase]
4522 if newdata[cl.rev(n)] < targetphase]
4502 if rejected:
4523 if rejected:
4503 ui.warn(_('cannot move %i changesets to a higher '
4524 ui.warn(_('cannot move %i changesets to a higher '
4504 'phase, use --force\n') % len(rejected))
4525 'phase, use --force\n') % len(rejected))
4505 ret = 1
4526 ret = 1
4506 if changes:
4527 if changes:
4507 msg = _('phase changed for %i changesets\n') % changes
4528 msg = _('phase changed for %i changesets\n') % changes
4508 if ret:
4529 if ret:
4509 ui.status(msg)
4530 ui.status(msg)
4510 else:
4531 else:
4511 ui.note(msg)
4532 ui.note(msg)
4512 else:
4533 else:
4513 ui.warn(_('no phases changed\n'))
4534 ui.warn(_('no phases changed\n'))
4514 ret = 1
4535 ret = 1
4515 return ret
4536 return ret
4516
4537
4517 def postincoming(ui, repo, modheads, optupdate, checkout):
4538 def postincoming(ui, repo, modheads, optupdate, checkout):
4518 if modheads == 0:
4539 if modheads == 0:
4519 return
4540 return
4520 if optupdate:
4541 if optupdate:
4521 checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout)
4542 checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout)
4522 try:
4543 try:
4523 ret = hg.update(repo, checkout)
4544 ret = hg.update(repo, checkout)
4524 except util.Abort, inst:
4545 except util.Abort, inst:
4525 ui.warn(_("not updating: %s\n") % str(inst))
4546 ui.warn(_("not updating: %s\n") % str(inst))
4526 if inst.hint:
4547 if inst.hint:
4527 ui.warn(_("(%s)\n") % inst.hint)
4548 ui.warn(_("(%s)\n") % inst.hint)
4528 return 0
4549 return 0
4529 if not ret and not checkout:
4550 if not ret and not checkout:
4530 if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
4551 if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
4531 ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent)
4552 ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent)
4532 return ret
4553 return ret
4533 if modheads > 1:
4554 if modheads > 1:
4534 currentbranchheads = len(repo.branchheads())
4555 currentbranchheads = len(repo.branchheads())
4535 if currentbranchheads == modheads:
4556 if currentbranchheads == modheads:
4536 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
4557 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
4537 elif currentbranchheads > 1:
4558 elif currentbranchheads > 1:
4538 ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to "
4559 ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to "
4539 "merge)\n"))
4560 "merge)\n"))
4540 else:
4561 else:
4541 ui.status(_("(run 'hg heads' to see heads)\n"))
4562 ui.status(_("(run 'hg heads' to see heads)\n"))
4542 else:
4563 else:
4543 ui.status(_("(run 'hg update' to get a working copy)\n"))
4564 ui.status(_("(run 'hg update' to get a working copy)\n"))
4544
4565
4545 @command('^pull',
4566 @command('^pull',
4546 [('u', 'update', None,
4567 [('u', 'update', None,
4547 _('update to new branch head if changesets were pulled')),
4568 _('update to new branch head if changesets were pulled')),
4548 ('f', 'force', None, _('run even when remote repository is unrelated')),
4569 ('f', 'force', None, _('run even when remote repository is unrelated')),
4549 ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')),
4570 ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')),
4550 ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')),
4571 ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')),
4551 ('b', 'branch', [], _('a specific branch you would like to pull'),
4572 ('b', 'branch', [], _('a specific branch you would like to pull'),
4552 _('BRANCH')),
4573 _('BRANCH')),
4553 ] + remoteopts,
4574 ] + remoteopts,
4554 _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]'))
4575 _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]'))
4555 def pull(ui, repo, source="default", **opts):
4576 def pull(ui, repo, source="default", **opts):
4556 """pull changes from the specified source
4577 """pull changes from the specified source
4557
4578
4558 Pull changes from a remote repository to a local one.
4579 Pull changes from a remote repository to a local one.
4559
4580
4560 This finds all changes from the repository at the specified path
4581 This finds all changes from the repository at the specified path
4561 or URL and adds them to a local repository (the current one unless
4582 or URL and adds them to a local repository (the current one unless
4562 -R is specified). By default, this does not update the copy of the
4583 -R is specified). By default, this does not update the copy of the
4563 project in the working directory.
4584 project in the working directory.
4564
4585
4565 Use :hg:`incoming` if you want to see what would have been added
4586 Use :hg:`incoming` if you want to see what would have been added
4566 by a pull at the time you issued this command. If you then decide
4587 by a pull at the time you issued this command. If you then decide
4567 to add those changes to the repository, you should use :hg:`pull
4588 to add those changes to the repository, you should use :hg:`pull
4568 -r X` where ``X`` is the last changeset listed by :hg:`incoming`.
4589 -r X` where ``X`` is the last changeset listed by :hg:`incoming`.
4569
4590
4570 If SOURCE is omitted, the 'default' path will be used.
4591 If SOURCE is omitted, the 'default' path will be used.
4571 See :hg:`help urls` for more information.
4592 See :hg:`help urls` for more information.
4572
4593
4573 Returns 0 on success, 1 if an update had unresolved files.
4594 Returns 0 on success, 1 if an update had unresolved files.
4574 """
4595 """
4575 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
4596 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
4576 other = hg.peer(repo, opts, source)
4597 other = hg.peer(repo, opts, source)
4577 try:
4598 try:
4578 ui.status(_('pulling from %s\n') % util.hidepassword(source))
4599 ui.status(_('pulling from %s\n') % util.hidepassword(source))
4579 revs, checkout = hg.addbranchrevs(repo, other, branches,
4600 revs, checkout = hg.addbranchrevs(repo, other, branches,
4580 opts.get('rev'))
4601 opts.get('rev'))
4581
4602
4582 remotebookmarks = other.listkeys('bookmarks')
4603 remotebookmarks = other.listkeys('bookmarks')
4583
4604
4584 if opts.get('bookmark'):
4605 if opts.get('bookmark'):
4585 if not revs:
4606 if not revs:
4586 revs = []
4607 revs = []
4587 for b in opts['bookmark']:
4608 for b in opts['bookmark']:
4588 if b not in remotebookmarks:
4609 if b not in remotebookmarks:
4589 raise util.Abort(_('remote bookmark %s not found!') % b)
4610 raise util.Abort(_('remote bookmark %s not found!') % b)
4590 revs.append(remotebookmarks[b])
4611 revs.append(remotebookmarks[b])
4591
4612
4592 if revs:
4613 if revs:
4593 try:
4614 try:
4594 revs = [other.lookup(rev) for rev in revs]
4615 revs = [other.lookup(rev) for rev in revs]
4595 except error.CapabilityError:
4616 except error.CapabilityError:
4596 err = _("other repository doesn't support revision lookup, "
4617 err = _("other repository doesn't support revision lookup, "
4597 "so a rev cannot be specified.")
4618 "so a rev cannot be specified.")
4598 raise util.Abort(err)
4619 raise util.Abort(err)
4599
4620
4600 modheads = repo.pull(other, heads=revs, force=opts.get('force'))
4621 modheads = repo.pull(other, heads=revs, force=opts.get('force'))
4601 bookmarks.updatefromremote(ui, repo, remotebookmarks, source)
4622 bookmarks.updatefromremote(ui, repo, remotebookmarks, source)
4602 if checkout:
4623 if checkout:
4603 checkout = str(repo.changelog.rev(other.lookup(checkout)))
4624 checkout = str(repo.changelog.rev(other.lookup(checkout)))
4604 repo._subtoppath = source
4625 repo._subtoppath = source
4605 try:
4626 try:
4606 ret = postincoming(ui, repo, modheads, opts.get('update'), checkout)
4627 ret = postincoming(ui, repo, modheads, opts.get('update'), checkout)
4607
4628
4608 finally:
4629 finally:
4609 del repo._subtoppath
4630 del repo._subtoppath
4610
4631
4611 # update specified bookmarks
4632 # update specified bookmarks
4612 if opts.get('bookmark'):
4633 if opts.get('bookmark'):
4613 marks = repo._bookmarks
4634 marks = repo._bookmarks
4614 for b in opts['bookmark']:
4635 for b in opts['bookmark']:
4615 # explicit pull overrides local bookmark if any
4636 # explicit pull overrides local bookmark if any
4616 ui.status(_("importing bookmark %s\n") % b)
4637 ui.status(_("importing bookmark %s\n") % b)
4617 marks[b] = repo[remotebookmarks[b]].node()
4638 marks[b] = repo[remotebookmarks[b]].node()
4618 marks.write()
4639 marks.write()
4619 finally:
4640 finally:
4620 other.close()
4641 other.close()
4621 return ret
4642 return ret
4622
4643
4623 @command('^push',
4644 @command('^push',
4624 [('f', 'force', None, _('force push')),
4645 [('f', 'force', None, _('force push')),
4625 ('r', 'rev', [],
4646 ('r', 'rev', [],
4626 _('a changeset intended to be included in the destination'),
4647 _('a changeset intended to be included in the destination'),
4627 _('REV')),
4648 _('REV')),
4628 ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')),
4649 ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')),
4629 ('b', 'branch', [],
4650 ('b', 'branch', [],
4630 _('a specific branch you would like to push'), _('BRANCH')),
4651 _('a specific branch you would like to push'), _('BRANCH')),
4631 ('', 'new-branch', False, _('allow pushing a new branch')),
4652 ('', 'new-branch', False, _('allow pushing a new branch')),
4632 ] + remoteopts,
4653 ] + remoteopts,
4633 _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]'))
4654 _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]'))
4634 def push(ui, repo, dest=None, **opts):
4655 def push(ui, repo, dest=None, **opts):
4635 """push changes to the specified destination
4656 """push changes to the specified destination
4636
4657
4637 Push changesets from the local repository to the specified
4658 Push changesets from the local repository to the specified
4638 destination.
4659 destination.
4639
4660
4640 This operation is symmetrical to pull: it is identical to a pull
4661 This operation is symmetrical to pull: it is identical to a pull
4641 in the destination repository from the current one.
4662 in the destination repository from the current one.
4642
4663
4643 By default, push will not allow creation of new heads at the
4664 By default, push will not allow creation of new heads at the
4644 destination, since multiple heads would make it unclear which head
4665 destination, since multiple heads would make it unclear which head
4645 to use. In this situation, it is recommended to pull and merge
4666 to use. In this situation, it is recommended to pull and merge
4646 before pushing.
4667 before pushing.
4647
4668
4648 Use --new-branch if you want to allow push to create a new named
4669 Use --new-branch if you want to allow push to create a new named
4649 branch that is not present at the destination. This allows you to
4670 branch that is not present at the destination. This allows you to
4650 only create a new branch without forcing other changes.
4671 only create a new branch without forcing other changes.
4651
4672
4652 .. note::
4673 .. note::
4653
4674
4654 Extra care should be taken with the -f/--force option,
4675 Extra care should be taken with the -f/--force option,
4655 which will push all new heads on all branches, an action which will
4676 which will push all new heads on all branches, an action which will
4656 almost always cause confusion for collaborators.
4677 almost always cause confusion for collaborators.
4657
4678
4658 If -r/--rev is used, the specified revision and all its ancestors
4679 If -r/--rev is used, the specified revision and all its ancestors
4659 will be pushed to the remote repository.
4680 will be pushed to the remote repository.
4660
4681
4661 If -B/--bookmark is used, the specified bookmarked revision, its
4682 If -B/--bookmark is used, the specified bookmarked revision, its
4662 ancestors, and the bookmark will be pushed to the remote
4683 ancestors, and the bookmark will be pushed to the remote
4663 repository.
4684 repository.
4664
4685
4665 Please see :hg:`help urls` for important details about ``ssh://``
4686 Please see :hg:`help urls` for important details about ``ssh://``
4666 URLs. If DESTINATION is omitted, a default path will be used.
4687 URLs. If DESTINATION is omitted, a default path will be used.
4667
4688
4668 Returns 0 if push was successful, 1 if nothing to push.
4689 Returns 0 if push was successful, 1 if nothing to push.
4669 """
4690 """
4670
4691
4671 if opts.get('bookmark'):
4692 if opts.get('bookmark'):
4672 ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push')
4693 ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push')
4673 for b in opts['bookmark']:
4694 for b in opts['bookmark']:
4674 # translate -B options to -r so changesets get pushed
4695 # translate -B options to -r so changesets get pushed
4675 if b in repo._bookmarks:
4696 if b in repo._bookmarks:
4676 opts.setdefault('rev', []).append(b)
4697 opts.setdefault('rev', []).append(b)
4677 else:
4698 else:
4678 # if we try to push a deleted bookmark, translate it to null
4699 # if we try to push a deleted bookmark, translate it to null
4679 # this lets simultaneous -r, -b options continue working
4700 # this lets simultaneous -r, -b options continue working
4680 opts.setdefault('rev', []).append("null")
4701 opts.setdefault('rev', []).append("null")
4681
4702
4682 dest = ui.expandpath(dest or 'default-push', dest or 'default')
4703 dest = ui.expandpath(dest or 'default-push', dest or 'default')
4683 dest, branches = hg.parseurl(dest, opts.get('branch'))
4704 dest, branches = hg.parseurl(dest, opts.get('branch'))
4684 ui.status(_('pushing to %s\n') % util.hidepassword(dest))
4705 ui.status(_('pushing to %s\n') % util.hidepassword(dest))
4685 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
4706 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
4686 try:
4707 try:
4687 other = hg.peer(repo, opts, dest)
4708 other = hg.peer(repo, opts, dest)
4688 except error.RepoError:
4709 except error.RepoError:
4689 if dest == "default-push":
4710 if dest == "default-push":
4690 raise util.Abort(_("default repository not configured!"),
4711 raise util.Abort(_("default repository not configured!"),
4691 hint=_('see the "path" section in "hg help config"'))
4712 hint=_('see the "path" section in "hg help config"'))
4692 else:
4713 else:
4693 raise
4714 raise
4694
4715
4695 if revs:
4716 if revs:
4696 revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)]
4717 revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)]
4697
4718
4698 repo._subtoppath = dest
4719 repo._subtoppath = dest
4699 try:
4720 try:
4700 # push subrepos depth-first for coherent ordering
4721 # push subrepos depth-first for coherent ordering
4701 c = repo['']
4722 c = repo['']
4702 subs = c.substate # only repos that are committed
4723 subs = c.substate # only repos that are committed
4703 for s in sorted(subs):
4724 for s in sorted(subs):
4704 result = c.sub(s).push(opts)
4725 result = c.sub(s).push(opts)
4705 if result == 0:
4726 if result == 0:
4706 return not result
4727 return not result
4707 finally:
4728 finally:
4708 del repo._subtoppath
4729 del repo._subtoppath
4709 result = repo.push(other, opts.get('force'), revs=revs,
4730 result = repo.push(other, opts.get('force'), revs=revs,
4710 newbranch=opts.get('new_branch'))
4731 newbranch=opts.get('new_branch'))
4711
4732
4712 result = not result
4733 result = not result
4713
4734
4714 if opts.get('bookmark'):
4735 if opts.get('bookmark'):
4715 bresult = bookmarks.pushtoremote(ui, repo, other, opts['bookmark'])
4736 bresult = bookmarks.pushtoremote(ui, repo, other, opts['bookmark'])
4716 if bresult == 2:
4737 if bresult == 2:
4717 return 2
4738 return 2
4718 if not result and bresult:
4739 if not result and bresult:
4719 result = 2
4740 result = 2
4720
4741
4721 return result
4742 return result
4722
4743
4723 @command('recover', [])
4744 @command('recover', [])
4724 def recover(ui, repo):
4745 def recover(ui, repo):
4725 """roll back an interrupted transaction
4746 """roll back an interrupted transaction
4726
4747
4727 Recover from an interrupted commit or pull.
4748 Recover from an interrupted commit or pull.
4728
4749
4729 This command tries to fix the repository status after an
4750 This command tries to fix the repository status after an
4730 interrupted operation. It should only be necessary when Mercurial
4751 interrupted operation. It should only be necessary when Mercurial
4731 suggests it.
4752 suggests it.
4732
4753
4733 Returns 0 if successful, 1 if nothing to recover or verify fails.
4754 Returns 0 if successful, 1 if nothing to recover or verify fails.
4734 """
4755 """
4735 if repo.recover():
4756 if repo.recover():
4736 return hg.verify(repo)
4757 return hg.verify(repo)
4737 return 1
4758 return 1
4738
4759
4739 @command('^remove|rm',
4760 @command('^remove|rm',
4740 [('A', 'after', None, _('record delete for missing files')),
4761 [('A', 'after', None, _('record delete for missing files')),
4741 ('f', 'force', None,
4762 ('f', 'force', None,
4742 _('remove (and delete) file even if added or modified')),
4763 _('remove (and delete) file even if added or modified')),
4743 ] + walkopts,
4764 ] + walkopts,
4744 _('[OPTION]... FILE...'))
4765 _('[OPTION]... FILE...'))
4745 def remove(ui, repo, *pats, **opts):
4766 def remove(ui, repo, *pats, **opts):
4746 """remove the specified files on the next commit
4767 """remove the specified files on the next commit
4747
4768
4748 Schedule the indicated files for removal from the current branch.
4769 Schedule the indicated files for removal from the current branch.
4749
4770
4750 This command schedules the files to be removed at the next commit.
4771 This command schedules the files to be removed at the next commit.
4751 To undo a remove before that, see :hg:`revert`. To undo added
4772 To undo a remove before that, see :hg:`revert`. To undo added
4752 files, see :hg:`forget`.
4773 files, see :hg:`forget`.
4753
4774
4754 .. container:: verbose
4775 .. container:: verbose
4755
4776
4756 -A/--after can be used to remove only files that have already
4777 -A/--after can be used to remove only files that have already
4757 been deleted, -f/--force can be used to force deletion, and -Af
4778 been deleted, -f/--force can be used to force deletion, and -Af
4758 can be used to remove files from the next revision without
4779 can be used to remove files from the next revision without
4759 deleting them from the working directory.
4780 deleting them from the working directory.
4760
4781
4761 The following table details the behavior of remove for different
4782 The following table details the behavior of remove for different
4762 file states (columns) and option combinations (rows). The file
4783 file states (columns) and option combinations (rows). The file
4763 states are Added [A], Clean [C], Modified [M] and Missing [!]
4784 states are Added [A], Clean [C], Modified [M] and Missing [!]
4764 (as reported by :hg:`status`). The actions are Warn, Remove
4785 (as reported by :hg:`status`). The actions are Warn, Remove
4765 (from branch) and Delete (from disk):
4786 (from branch) and Delete (from disk):
4766
4787
4767 ========= == == == ==
4788 ========= == == == ==
4768 opt/state A C M !
4789 opt/state A C M !
4769 ========= == == == ==
4790 ========= == == == ==
4770 none W RD W R
4791 none W RD W R
4771 -f R RD RD R
4792 -f R RD RD R
4772 -A W W W R
4793 -A W W W R
4773 -Af R R R R
4794 -Af R R R R
4774 ========= == == == ==
4795 ========= == == == ==
4775
4796
4776 Note that remove never deletes files in Added [A] state from the
4797 Note that remove never deletes files in Added [A] state from the
4777 working directory, not even if option --force is specified.
4798 working directory, not even if option --force is specified.
4778
4799
4779 Returns 0 on success, 1 if any warnings encountered.
4800 Returns 0 on success, 1 if any warnings encountered.
4780 """
4801 """
4781
4802
4782 ret = 0
4803 ret = 0
4783 after, force = opts.get('after'), opts.get('force')
4804 after, force = opts.get('after'), opts.get('force')
4784 if not pats and not after:
4805 if not pats and not after:
4785 raise util.Abort(_('no files specified'))
4806 raise util.Abort(_('no files specified'))
4786
4807
4787 m = scmutil.match(repo[None], pats, opts)
4808 m = scmutil.match(repo[None], pats, opts)
4788 s = repo.status(match=m, clean=True)
4809 s = repo.status(match=m, clean=True)
4789 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
4810 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
4790
4811
4791 # warn about failure to delete explicit files/dirs
4812 # warn about failure to delete explicit files/dirs
4792 wctx = repo[None]
4813 wctx = repo[None]
4793 for f in m.files():
4814 for f in m.files():
4794 if f in repo.dirstate or f in wctx.dirs():
4815 if f in repo.dirstate or f in wctx.dirs():
4795 continue
4816 continue
4796 if os.path.exists(m.rel(f)):
4817 if os.path.exists(m.rel(f)):
4797 if os.path.isdir(m.rel(f)):
4818 if os.path.isdir(m.rel(f)):
4798 ui.warn(_('not removing %s: no tracked files\n') % m.rel(f))
4819 ui.warn(_('not removing %s: no tracked files\n') % m.rel(f))
4799 else:
4820 else:
4800 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
4821 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
4801 # missing files will generate a warning elsewhere
4822 # missing files will generate a warning elsewhere
4802 ret = 1
4823 ret = 1
4803
4824
4804 if force:
4825 if force:
4805 list = modified + deleted + clean + added
4826 list = modified + deleted + clean + added
4806 elif after:
4827 elif after:
4807 list = deleted
4828 list = deleted
4808 for f in modified + added + clean:
4829 for f in modified + added + clean:
4809 ui.warn(_('not removing %s: file still exists\n') % m.rel(f))
4830 ui.warn(_('not removing %s: file still exists\n') % m.rel(f))
4810 ret = 1
4831 ret = 1
4811 else:
4832 else:
4812 list = deleted + clean
4833 list = deleted + clean
4813 for f in modified:
4834 for f in modified:
4814 ui.warn(_('not removing %s: file is modified (use -f'
4835 ui.warn(_('not removing %s: file is modified (use -f'
4815 ' to force removal)\n') % m.rel(f))
4836 ' to force removal)\n') % m.rel(f))
4816 ret = 1
4837 ret = 1
4817 for f in added:
4838 for f in added:
4818 ui.warn(_('not removing %s: file has been marked for add'
4839 ui.warn(_('not removing %s: file has been marked for add'
4819 ' (use forget to undo)\n') % m.rel(f))
4840 ' (use forget to undo)\n') % m.rel(f))
4820 ret = 1
4841 ret = 1
4821
4842
4822 for f in sorted(list):
4843 for f in sorted(list):
4823 if ui.verbose or not m.exact(f):
4844 if ui.verbose or not m.exact(f):
4824 ui.status(_('removing %s\n') % m.rel(f))
4845 ui.status(_('removing %s\n') % m.rel(f))
4825
4846
4826 wlock = repo.wlock()
4847 wlock = repo.wlock()
4827 try:
4848 try:
4828 if not after:
4849 if not after:
4829 for f in list:
4850 for f in list:
4830 if f in added:
4851 if f in added:
4831 continue # we never unlink added files on remove
4852 continue # we never unlink added files on remove
4832 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
4853 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
4833 repo[None].forget(list)
4854 repo[None].forget(list)
4834 finally:
4855 finally:
4835 wlock.release()
4856 wlock.release()
4836
4857
4837 return ret
4858 return ret
4838
4859
4839 @command('rename|move|mv',
4860 @command('rename|move|mv',
4840 [('A', 'after', None, _('record a rename that has already occurred')),
4861 [('A', 'after', None, _('record a rename that has already occurred')),
4841 ('f', 'force', None, _('forcibly copy over an existing managed file')),
4862 ('f', 'force', None, _('forcibly copy over an existing managed file')),
4842 ] + walkopts + dryrunopts,
4863 ] + walkopts + dryrunopts,
4843 _('[OPTION]... SOURCE... DEST'))
4864 _('[OPTION]... SOURCE... DEST'))
4844 def rename(ui, repo, *pats, **opts):
4865 def rename(ui, repo, *pats, **opts):
4845 """rename files; equivalent of copy + remove
4866 """rename files; equivalent of copy + remove
4846
4867
4847 Mark dest as copies of sources; mark sources for deletion. If dest
4868 Mark dest as copies of sources; mark sources for deletion. If dest
4848 is a directory, copies are put in that directory. If dest is a
4869 is a directory, copies are put in that directory. If dest is a
4849 file, there can only be one source.
4870 file, there can only be one source.
4850
4871
4851 By default, this command copies the contents of files as they
4872 By default, this command copies the contents of files as they
4852 exist in the working directory. If invoked with -A/--after, the
4873 exist in the working directory. If invoked with -A/--after, the
4853 operation is recorded, but no copying is performed.
4874 operation is recorded, but no copying is performed.
4854
4875
4855 This command takes effect at the next commit. To undo a rename
4876 This command takes effect at the next commit. To undo a rename
4856 before that, see :hg:`revert`.
4877 before that, see :hg:`revert`.
4857
4878
4858 Returns 0 on success, 1 if errors are encountered.
4879 Returns 0 on success, 1 if errors are encountered.
4859 """
4880 """
4860 wlock = repo.wlock(False)
4881 wlock = repo.wlock(False)
4861 try:
4882 try:
4862 return cmdutil.copy(ui, repo, pats, opts, rename=True)
4883 return cmdutil.copy(ui, repo, pats, opts, rename=True)
4863 finally:
4884 finally:
4864 wlock.release()
4885 wlock.release()
4865
4886
4866 @command('resolve',
4887 @command('resolve',
4867 [('a', 'all', None, _('select all unresolved files')),
4888 [('a', 'all', None, _('select all unresolved files')),
4868 ('l', 'list', None, _('list state of files needing merge')),
4889 ('l', 'list', None, _('list state of files needing merge')),
4869 ('m', 'mark', None, _('mark files as resolved')),
4890 ('m', 'mark', None, _('mark files as resolved')),
4870 ('u', 'unmark', None, _('mark files as unresolved')),
4891 ('u', 'unmark', None, _('mark files as unresolved')),
4871 ('n', 'no-status', None, _('hide status prefix'))]
4892 ('n', 'no-status', None, _('hide status prefix'))]
4872 + mergetoolopts + walkopts,
4893 + mergetoolopts + walkopts,
4873 _('[OPTION]... [FILE]...'))
4894 _('[OPTION]... [FILE]...'))
4874 def resolve(ui, repo, *pats, **opts):
4895 def resolve(ui, repo, *pats, **opts):
4875 """redo merges or set/view the merge status of files
4896 """redo merges or set/view the merge status of files
4876
4897
4877 Merges with unresolved conflicts are often the result of
4898 Merges with unresolved conflicts are often the result of
4878 non-interactive merging using the ``internal:merge`` configuration
4899 non-interactive merging using the ``internal:merge`` configuration
4879 setting, or a command-line merge tool like ``diff3``. The resolve
4900 setting, or a command-line merge tool like ``diff3``. The resolve
4880 command is used to manage the files involved in a merge, after
4901 command is used to manage the files involved in a merge, after
4881 :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the
4902 :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the
4882 working directory must have two parents). See :hg:`help
4903 working directory must have two parents). See :hg:`help
4883 merge-tools` for information on configuring merge tools.
4904 merge-tools` for information on configuring merge tools.
4884
4905
4885 The resolve command can be used in the following ways:
4906 The resolve command can be used in the following ways:
4886
4907
4887 - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified
4908 - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified
4888 files, discarding any previous merge attempts. Re-merging is not
4909 files, discarding any previous merge attempts. Re-merging is not
4889 performed for files already marked as resolved. Use ``--all/-a``
4910 performed for files already marked as resolved. Use ``--all/-a``
4890 to select all unresolved files. ``--tool`` can be used to specify
4911 to select all unresolved files. ``--tool`` can be used to specify
4891 the merge tool used for the given files. It overrides the HGMERGE
4912 the merge tool used for the given files. It overrides the HGMERGE
4892 environment variable and your configuration files. Previous file
4913 environment variable and your configuration files. Previous file
4893 contents are saved with a ``.orig`` suffix.
4914 contents are saved with a ``.orig`` suffix.
4894
4915
4895 - :hg:`resolve -m [FILE]`: mark a file as having been resolved
4916 - :hg:`resolve -m [FILE]`: mark a file as having been resolved
4896 (e.g. after having manually fixed-up the files). The default is
4917 (e.g. after having manually fixed-up the files). The default is
4897 to mark all unresolved files.
4918 to mark all unresolved files.
4898
4919
4899 - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The
4920 - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The
4900 default is to mark all resolved files.
4921 default is to mark all resolved files.
4901
4922
4902 - :hg:`resolve -l`: list files which had or still have conflicts.
4923 - :hg:`resolve -l`: list files which had or still have conflicts.
4903 In the printed list, ``U`` = unresolved and ``R`` = resolved.
4924 In the printed list, ``U`` = unresolved and ``R`` = resolved.
4904
4925
4905 Note that Mercurial will not let you commit files with unresolved
4926 Note that Mercurial will not let you commit files with unresolved
4906 merge conflicts. You must use :hg:`resolve -m ...` before you can
4927 merge conflicts. You must use :hg:`resolve -m ...` before you can
4907 commit after a conflicting merge.
4928 commit after a conflicting merge.
4908
4929
4909 Returns 0 on success, 1 if any files fail a resolve attempt.
4930 Returns 0 on success, 1 if any files fail a resolve attempt.
4910 """
4931 """
4911
4932
4912 all, mark, unmark, show, nostatus = \
4933 all, mark, unmark, show, nostatus = \
4913 [opts.get(o) for o in 'all mark unmark list no_status'.split()]
4934 [opts.get(o) for o in 'all mark unmark list no_status'.split()]
4914
4935
4915 if (show and (mark or unmark)) or (mark and unmark):
4936 if (show and (mark or unmark)) or (mark and unmark):
4916 raise util.Abort(_("too many options specified"))
4937 raise util.Abort(_("too many options specified"))
4917 if pats and all:
4938 if pats and all:
4918 raise util.Abort(_("can't specify --all and patterns"))
4939 raise util.Abort(_("can't specify --all and patterns"))
4919 if not (all or pats or show or mark or unmark):
4940 if not (all or pats or show or mark or unmark):
4920 raise util.Abort(_('no files or directories specified; '
4941 raise util.Abort(_('no files or directories specified; '
4921 'use --all to remerge all files'))
4942 'use --all to remerge all files'))
4922
4943
4923 ms = mergemod.mergestate(repo)
4944 ms = mergemod.mergestate(repo)
4924
4945
4925 if not ms.active() and not show:
4946 if not ms.active() and not show:
4926 raise util.Abort(_('resolve command not applicable when not merging'))
4947 raise util.Abort(_('resolve command not applicable when not merging'))
4927
4948
4928 m = scmutil.match(repo[None], pats, opts)
4949 m = scmutil.match(repo[None], pats, opts)
4929 ret = 0
4950 ret = 0
4930
4951
4931 didwork = False
4952 didwork = False
4932 for f in ms:
4953 for f in ms:
4933 if not m(f):
4954 if not m(f):
4934 continue
4955 continue
4935
4956
4936 didwork = True
4957 didwork = True
4937
4958
4938 if show:
4959 if show:
4939 if nostatus:
4960 if nostatus:
4940 ui.write("%s\n" % f)
4961 ui.write("%s\n" % f)
4941 else:
4962 else:
4942 ui.write("%s %s\n" % (ms[f].upper(), f),
4963 ui.write("%s %s\n" % (ms[f].upper(), f),
4943 label='resolve.' +
4964 label='resolve.' +
4944 {'u': 'unresolved', 'r': 'resolved'}[ms[f]])
4965 {'u': 'unresolved', 'r': 'resolved'}[ms[f]])
4945 elif mark:
4966 elif mark:
4946 ms.mark(f, "r")
4967 ms.mark(f, "r")
4947 elif unmark:
4968 elif unmark:
4948 ms.mark(f, "u")
4969 ms.mark(f, "u")
4949 else:
4970 else:
4950 wctx = repo[None]
4971 wctx = repo[None]
4951
4972
4952 # backup pre-resolve (merge uses .orig for its own purposes)
4973 # backup pre-resolve (merge uses .orig for its own purposes)
4953 a = repo.wjoin(f)
4974 a = repo.wjoin(f)
4954 util.copyfile(a, a + ".resolve")
4975 util.copyfile(a, a + ".resolve")
4955
4976
4956 try:
4977 try:
4957 # resolve file
4978 # resolve file
4958 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
4979 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
4959 'resolve')
4980 'resolve')
4960 if ms.resolve(f, wctx):
4981 if ms.resolve(f, wctx):
4961 ret = 1
4982 ret = 1
4962 finally:
4983 finally:
4963 ui.setconfig('ui', 'forcemerge', '', 'resolve')
4984 ui.setconfig('ui', 'forcemerge', '', 'resolve')
4964 ms.commit()
4985 ms.commit()
4965
4986
4966 # replace filemerge's .orig file with our resolve file
4987 # replace filemerge's .orig file with our resolve file
4967 util.rename(a + ".resolve", a + ".orig")
4988 util.rename(a + ".resolve", a + ".orig")
4968
4989
4969 ms.commit()
4990 ms.commit()
4970
4991
4971 if not didwork and pats:
4992 if not didwork and pats:
4972 ui.warn(_("arguments do not match paths that need resolved\n"))
4993 ui.warn(_("arguments do not match paths that need resolved\n"))
4973
4994
4974 # Nudge users into finishing an unfinished operation. We don't print
4995 # Nudge users into finishing an unfinished operation. We don't print
4975 # this with the list/show operation because we want list/show to remain
4996 # this with the list/show operation because we want list/show to remain
4976 # machine readable.
4997 # machine readable.
4977 if not list(ms.unresolved()) and not show:
4998 if not list(ms.unresolved()) and not show:
4978 ui.status(_('no more unresolved files\n'))
4999 ui.status(_('no more unresolved files\n'))
4979
5000
4980 return ret
5001 return ret
4981
5002
4982 @command('revert',
5003 @command('revert',
4983 [('a', 'all', None, _('revert all changes when no arguments given')),
5004 [('a', 'all', None, _('revert all changes when no arguments given')),
4984 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
5005 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
4985 ('r', 'rev', '', _('revert to the specified revision'), _('REV')),
5006 ('r', 'rev', '', _('revert to the specified revision'), _('REV')),
4986 ('C', 'no-backup', None, _('do not save backup copies of files')),
5007 ('C', 'no-backup', None, _('do not save backup copies of files')),
4987 ] + walkopts + dryrunopts,
5008 ] + walkopts + dryrunopts,
4988 _('[OPTION]... [-r REV] [NAME]...'))
5009 _('[OPTION]... [-r REV] [NAME]...'))
4989 def revert(ui, repo, *pats, **opts):
5010 def revert(ui, repo, *pats, **opts):
4990 """restore files to their checkout state
5011 """restore files to their checkout state
4991
5012
4992 .. note::
5013 .. note::
4993
5014
4994 To check out earlier revisions, you should use :hg:`update REV`.
5015 To check out earlier revisions, you should use :hg:`update REV`.
4995 To cancel an uncommitted merge (and lose your changes),
5016 To cancel an uncommitted merge (and lose your changes),
4996 use :hg:`update --clean .`.
5017 use :hg:`update --clean .`.
4997
5018
4998 With no revision specified, revert the specified files or directories
5019 With no revision specified, revert the specified files or directories
4999 to the contents they had in the parent of the working directory.
5020 to the contents they had in the parent of the working directory.
5000 This restores the contents of files to an unmodified
5021 This restores the contents of files to an unmodified
5001 state and unschedules adds, removes, copies, and renames. If the
5022 state and unschedules adds, removes, copies, and renames. If the
5002 working directory has two parents, you must explicitly specify a
5023 working directory has two parents, you must explicitly specify a
5003 revision.
5024 revision.
5004
5025
5005 Using the -r/--rev or -d/--date options, revert the given files or
5026 Using the -r/--rev or -d/--date options, revert the given files or
5006 directories to their states as of a specific revision. Because
5027 directories to their states as of a specific revision. Because
5007 revert does not change the working directory parents, this will
5028 revert does not change the working directory parents, this will
5008 cause these files to appear modified. This can be helpful to "back
5029 cause these files to appear modified. This can be helpful to "back
5009 out" some or all of an earlier change. See :hg:`backout` for a
5030 out" some or all of an earlier change. See :hg:`backout` for a
5010 related method.
5031 related method.
5011
5032
5012 Modified files are saved with a .orig suffix before reverting.
5033 Modified files are saved with a .orig suffix before reverting.
5013 To disable these backups, use --no-backup.
5034 To disable these backups, use --no-backup.
5014
5035
5015 See :hg:`help dates` for a list of formats valid for -d/--date.
5036 See :hg:`help dates` for a list of formats valid for -d/--date.
5016
5037
5017 Returns 0 on success.
5038 Returns 0 on success.
5018 """
5039 """
5019
5040
5020 if opts.get("date"):
5041 if opts.get("date"):
5021 if opts.get("rev"):
5042 if opts.get("rev"):
5022 raise util.Abort(_("you can't specify a revision and a date"))
5043 raise util.Abort(_("you can't specify a revision and a date"))
5023 opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
5044 opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
5024
5045
5025 parent, p2 = repo.dirstate.parents()
5046 parent, p2 = repo.dirstate.parents()
5026 if not opts.get('rev') and p2 != nullid:
5047 if not opts.get('rev') and p2 != nullid:
5027 # revert after merge is a trap for new users (issue2915)
5048 # revert after merge is a trap for new users (issue2915)
5028 raise util.Abort(_('uncommitted merge with no revision specified'),
5049 raise util.Abort(_('uncommitted merge with no revision specified'),
5029 hint=_('use "hg update" or see "hg help revert"'))
5050 hint=_('use "hg update" or see "hg help revert"'))
5030
5051
5031 ctx = scmutil.revsingle(repo, opts.get('rev'))
5052 ctx = scmutil.revsingle(repo, opts.get('rev'))
5032
5053
5033 if not pats and not opts.get('all'):
5054 if not pats and not opts.get('all'):
5034 msg = _("no files or directories specified")
5055 msg = _("no files or directories specified")
5035 if p2 != nullid:
5056 if p2 != nullid:
5036 hint = _("uncommitted merge, use --all to discard all changes,"
5057 hint = _("uncommitted merge, use --all to discard all changes,"
5037 " or 'hg update -C .' to abort the merge")
5058 " or 'hg update -C .' to abort the merge")
5038 raise util.Abort(msg, hint=hint)
5059 raise util.Abort(msg, hint=hint)
5039 dirty = util.any(repo.status())
5060 dirty = util.any(repo.status())
5040 node = ctx.node()
5061 node = ctx.node()
5041 if node != parent:
5062 if node != parent:
5042 if dirty:
5063 if dirty:
5043 hint = _("uncommitted changes, use --all to discard all"
5064 hint = _("uncommitted changes, use --all to discard all"
5044 " changes, or 'hg update %s' to update") % ctx.rev()
5065 " changes, or 'hg update %s' to update") % ctx.rev()
5045 else:
5066 else:
5046 hint = _("use --all to revert all files,"
5067 hint = _("use --all to revert all files,"
5047 " or 'hg update %s' to update") % ctx.rev()
5068 " or 'hg update %s' to update") % ctx.rev()
5048 elif dirty:
5069 elif dirty:
5049 hint = _("uncommitted changes, use --all to discard all changes")
5070 hint = _("uncommitted changes, use --all to discard all changes")
5050 else:
5071 else:
5051 hint = _("use --all to revert all files")
5072 hint = _("use --all to revert all files")
5052 raise util.Abort(msg, hint=hint)
5073 raise util.Abort(msg, hint=hint)
5053
5074
5054 return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts)
5075 return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts)
5055
5076
5056 @command('rollback', dryrunopts +
5077 @command('rollback', dryrunopts +
5057 [('f', 'force', False, _('ignore safety measures'))])
5078 [('f', 'force', False, _('ignore safety measures'))])
5058 def rollback(ui, repo, **opts):
5079 def rollback(ui, repo, **opts):
5059 """roll back the last transaction (DANGEROUS) (DEPRECATED)
5080 """roll back the last transaction (DANGEROUS) (DEPRECATED)
5060
5081
5061 Please use :hg:`commit --amend` instead of rollback to correct
5082 Please use :hg:`commit --amend` instead of rollback to correct
5062 mistakes in the last commit.
5083 mistakes in the last commit.
5063
5084
5064 This command should be used with care. There is only one level of
5085 This command should be used with care. There is only one level of
5065 rollback, and there is no way to undo a rollback. It will also
5086 rollback, and there is no way to undo a rollback. It will also
5066 restore the dirstate at the time of the last transaction, losing
5087 restore the dirstate at the time of the last transaction, losing
5067 any dirstate changes since that time. This command does not alter
5088 any dirstate changes since that time. This command does not alter
5068 the working directory.
5089 the working directory.
5069
5090
5070 Transactions are used to encapsulate the effects of all commands
5091 Transactions are used to encapsulate the effects of all commands
5071 that create new changesets or propagate existing changesets into a
5092 that create new changesets or propagate existing changesets into a
5072 repository.
5093 repository.
5073
5094
5074 .. container:: verbose
5095 .. container:: verbose
5075
5096
5076 For example, the following commands are transactional, and their
5097 For example, the following commands are transactional, and their
5077 effects can be rolled back:
5098 effects can be rolled back:
5078
5099
5079 - commit
5100 - commit
5080 - import
5101 - import
5081 - pull
5102 - pull
5082 - push (with this repository as the destination)
5103 - push (with this repository as the destination)
5083 - unbundle
5104 - unbundle
5084
5105
5085 To avoid permanent data loss, rollback will refuse to rollback a
5106 To avoid permanent data loss, rollback will refuse to rollback a
5086 commit transaction if it isn't checked out. Use --force to
5107 commit transaction if it isn't checked out. Use --force to
5087 override this protection.
5108 override this protection.
5088
5109
5089 This command is not intended for use on public repositories. Once
5110 This command is not intended for use on public repositories. Once
5090 changes are visible for pull by other users, rolling a transaction
5111 changes are visible for pull by other users, rolling a transaction
5091 back locally is ineffective (someone else may already have pulled
5112 back locally is ineffective (someone else may already have pulled
5092 the changes). Furthermore, a race is possible with readers of the
5113 the changes). Furthermore, a race is possible with readers of the
5093 repository; for example an in-progress pull from the repository
5114 repository; for example an in-progress pull from the repository
5094 may fail if a rollback is performed.
5115 may fail if a rollback is performed.
5095
5116
5096 Returns 0 on success, 1 if no rollback data is available.
5117 Returns 0 on success, 1 if no rollback data is available.
5097 """
5118 """
5098 return repo.rollback(dryrun=opts.get('dry_run'),
5119 return repo.rollback(dryrun=opts.get('dry_run'),
5099 force=opts.get('force'))
5120 force=opts.get('force'))
5100
5121
5101 @command('root', [])
5122 @command('root', [])
5102 def root(ui, repo):
5123 def root(ui, repo):
5103 """print the root (top) of the current working directory
5124 """print the root (top) of the current working directory
5104
5125
5105 Print the root directory of the current repository.
5126 Print the root directory of the current repository.
5106
5127
5107 Returns 0 on success.
5128 Returns 0 on success.
5108 """
5129 """
5109 ui.write(repo.root + "\n")
5130 ui.write(repo.root + "\n")
5110
5131
5111 @command('^serve',
5132 @command('^serve',
5112 [('A', 'accesslog', '', _('name of access log file to write to'),
5133 [('A', 'accesslog', '', _('name of access log file to write to'),
5113 _('FILE')),
5134 _('FILE')),
5114 ('d', 'daemon', None, _('run server in background')),
5135 ('d', 'daemon', None, _('run server in background')),
5115 ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('NUM')),
5136 ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('NUM')),
5116 ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')),
5137 ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')),
5117 # use string type, then we can check if something was passed
5138 # use string type, then we can check if something was passed
5118 ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')),
5139 ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')),
5119 ('a', 'address', '', _('address to listen on (default: all interfaces)'),
5140 ('a', 'address', '', _('address to listen on (default: all interfaces)'),
5120 _('ADDR')),
5141 _('ADDR')),
5121 ('', 'prefix', '', _('prefix path to serve from (default: server root)'),
5142 ('', 'prefix', '', _('prefix path to serve from (default: server root)'),
5122 _('PREFIX')),
5143 _('PREFIX')),
5123 ('n', 'name', '',
5144 ('n', 'name', '',
5124 _('name to show in web pages (default: working directory)'), _('NAME')),
5145 _('name to show in web pages (default: working directory)'), _('NAME')),
5125 ('', 'web-conf', '',
5146 ('', 'web-conf', '',
5126 _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')),
5147 _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')),
5127 ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'),
5148 ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'),
5128 _('FILE')),
5149 _('FILE')),
5129 ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')),
5150 ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')),
5130 ('', 'stdio', None, _('for remote clients')),
5151 ('', 'stdio', None, _('for remote clients')),
5131 ('', 'cmdserver', '', _('for remote clients'), _('MODE')),
5152 ('', 'cmdserver', '', _('for remote clients'), _('MODE')),
5132 ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')),
5153 ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')),
5133 ('', 'style', '', _('template style to use'), _('STYLE')),
5154 ('', 'style', '', _('template style to use'), _('STYLE')),
5134 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
5155 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
5135 ('', 'certificate', '', _('SSL certificate file'), _('FILE'))],
5156 ('', 'certificate', '', _('SSL certificate file'), _('FILE'))],
5136 _('[OPTION]...'))
5157 _('[OPTION]...'))
5137 def serve(ui, repo, **opts):
5158 def serve(ui, repo, **opts):
5138 """start stand-alone webserver
5159 """start stand-alone webserver
5139
5160
5140 Start a local HTTP repository browser and pull server. You can use
5161 Start a local HTTP repository browser and pull server. You can use
5141 this for ad-hoc sharing and browsing of repositories. It is
5162 this for ad-hoc sharing and browsing of repositories. It is
5142 recommended to use a real web server to serve a repository for
5163 recommended to use a real web server to serve a repository for
5143 longer periods of time.
5164 longer periods of time.
5144
5165
5145 Please note that the server does not implement access control.
5166 Please note that the server does not implement access control.
5146 This means that, by default, anybody can read from the server and
5167 This means that, by default, anybody can read from the server and
5147 nobody can write to it by default. Set the ``web.allow_push``
5168 nobody can write to it by default. Set the ``web.allow_push``
5148 option to ``*`` to allow everybody to push to the server. You
5169 option to ``*`` to allow everybody to push to the server. You
5149 should use a real web server if you need to authenticate users.
5170 should use a real web server if you need to authenticate users.
5150
5171
5151 By default, the server logs accesses to stdout and errors to
5172 By default, the server logs accesses to stdout and errors to
5152 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
5173 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
5153 files.
5174 files.
5154
5175
5155 To have the server choose a free port number to listen on, specify
5176 To have the server choose a free port number to listen on, specify
5156 a port number of 0; in this case, the server will print the port
5177 a port number of 0; in this case, the server will print the port
5157 number it uses.
5178 number it uses.
5158
5179
5159 Returns 0 on success.
5180 Returns 0 on success.
5160 """
5181 """
5161
5182
5162 if opts["stdio"] and opts["cmdserver"]:
5183 if opts["stdio"] and opts["cmdserver"]:
5163 raise util.Abort(_("cannot use --stdio with --cmdserver"))
5184 raise util.Abort(_("cannot use --stdio with --cmdserver"))
5164
5185
5165 def checkrepo():
5186 def checkrepo():
5166 if repo is None:
5187 if repo is None:
5167 raise error.RepoError(_("there is no Mercurial repository here"
5188 raise error.RepoError(_("there is no Mercurial repository here"
5168 " (.hg not found)"))
5189 " (.hg not found)"))
5169
5190
5170 if opts["stdio"]:
5191 if opts["stdio"]:
5171 checkrepo()
5192 checkrepo()
5172 s = sshserver.sshserver(ui, repo)
5193 s = sshserver.sshserver(ui, repo)
5173 s.serve_forever()
5194 s.serve_forever()
5174
5195
5175 if opts["cmdserver"]:
5196 if opts["cmdserver"]:
5176 s = commandserver.server(ui, repo, opts["cmdserver"])
5197 s = commandserver.server(ui, repo, opts["cmdserver"])
5177 return s.serve()
5198 return s.serve()
5178
5199
5179 # this way we can check if something was given in the command-line
5200 # this way we can check if something was given in the command-line
5180 if opts.get('port'):
5201 if opts.get('port'):
5181 opts['port'] = util.getport(opts.get('port'))
5202 opts['port'] = util.getport(opts.get('port'))
5182
5203
5183 baseui = repo and repo.baseui or ui
5204 baseui = repo and repo.baseui or ui
5184 optlist = ("name templates style address port prefix ipv6"
5205 optlist = ("name templates style address port prefix ipv6"
5185 " accesslog errorlog certificate encoding")
5206 " accesslog errorlog certificate encoding")
5186 for o in optlist.split():
5207 for o in optlist.split():
5187 val = opts.get(o, '')
5208 val = opts.get(o, '')
5188 if val in (None, ''): # should check against default options instead
5209 if val in (None, ''): # should check against default options instead
5189 continue
5210 continue
5190 baseui.setconfig("web", o, val, 'serve')
5211 baseui.setconfig("web", o, val, 'serve')
5191 if repo and repo.ui != baseui:
5212 if repo and repo.ui != baseui:
5192 repo.ui.setconfig("web", o, val, 'serve')
5213 repo.ui.setconfig("web", o, val, 'serve')
5193
5214
5194 o = opts.get('web_conf') or opts.get('webdir_conf')
5215 o = opts.get('web_conf') or opts.get('webdir_conf')
5195 if not o:
5216 if not o:
5196 if not repo:
5217 if not repo:
5197 raise error.RepoError(_("there is no Mercurial repository"
5218 raise error.RepoError(_("there is no Mercurial repository"
5198 " here (.hg not found)"))
5219 " here (.hg not found)"))
5199 o = repo
5220 o = repo
5200
5221
5201 app = hgweb.hgweb(o, baseui=baseui)
5222 app = hgweb.hgweb(o, baseui=baseui)
5202 service = httpservice(ui, app, opts)
5223 service = httpservice(ui, app, opts)
5203 cmdutil.service(opts, initfn=service.init, runfn=service.run)
5224 cmdutil.service(opts, initfn=service.init, runfn=service.run)
5204
5225
5205 class httpservice(object):
5226 class httpservice(object):
5206 def __init__(self, ui, app, opts):
5227 def __init__(self, ui, app, opts):
5207 self.ui = ui
5228 self.ui = ui
5208 self.app = app
5229 self.app = app
5209 self.opts = opts
5230 self.opts = opts
5210
5231
5211 def init(self):
5232 def init(self):
5212 util.setsignalhandler()
5233 util.setsignalhandler()
5213 self.httpd = hgweb_server.create_server(self.ui, self.app)
5234 self.httpd = hgweb_server.create_server(self.ui, self.app)
5214
5235
5215 if self.opts['port'] and not self.ui.verbose:
5236 if self.opts['port'] and not self.ui.verbose:
5216 return
5237 return
5217
5238
5218 if self.httpd.prefix:
5239 if self.httpd.prefix:
5219 prefix = self.httpd.prefix.strip('/') + '/'
5240 prefix = self.httpd.prefix.strip('/') + '/'
5220 else:
5241 else:
5221 prefix = ''
5242 prefix = ''
5222
5243
5223 port = ':%d' % self.httpd.port
5244 port = ':%d' % self.httpd.port
5224 if port == ':80':
5245 if port == ':80':
5225 port = ''
5246 port = ''
5226
5247
5227 bindaddr = self.httpd.addr
5248 bindaddr = self.httpd.addr
5228 if bindaddr == '0.0.0.0':
5249 if bindaddr == '0.0.0.0':
5229 bindaddr = '*'
5250 bindaddr = '*'
5230 elif ':' in bindaddr: # IPv6
5251 elif ':' in bindaddr: # IPv6
5231 bindaddr = '[%s]' % bindaddr
5252 bindaddr = '[%s]' % bindaddr
5232
5253
5233 fqaddr = self.httpd.fqaddr
5254 fqaddr = self.httpd.fqaddr
5234 if ':' in fqaddr:
5255 if ':' in fqaddr:
5235 fqaddr = '[%s]' % fqaddr
5256 fqaddr = '[%s]' % fqaddr
5236 if self.opts['port']:
5257 if self.opts['port']:
5237 write = self.ui.status
5258 write = self.ui.status
5238 else:
5259 else:
5239 write = self.ui.write
5260 write = self.ui.write
5240 write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
5261 write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
5241 (fqaddr, port, prefix, bindaddr, self.httpd.port))
5262 (fqaddr, port, prefix, bindaddr, self.httpd.port))
5242
5263
5243 def run(self):
5264 def run(self):
5244 self.httpd.serve_forever()
5265 self.httpd.serve_forever()
5245
5266
5246
5267
5247 @command('^status|st',
5268 @command('^status|st',
5248 [('A', 'all', None, _('show status of all files')),
5269 [('A', 'all', None, _('show status of all files')),
5249 ('m', 'modified', None, _('show only modified files')),
5270 ('m', 'modified', None, _('show only modified files')),
5250 ('a', 'added', None, _('show only added files')),
5271 ('a', 'added', None, _('show only added files')),
5251 ('r', 'removed', None, _('show only removed files')),
5272 ('r', 'removed', None, _('show only removed files')),
5252 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
5273 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
5253 ('c', 'clean', None, _('show only files without changes')),
5274 ('c', 'clean', None, _('show only files without changes')),
5254 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
5275 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
5255 ('i', 'ignored', None, _('show only ignored files')),
5276 ('i', 'ignored', None, _('show only ignored files')),
5256 ('n', 'no-status', None, _('hide status prefix')),
5277 ('n', 'no-status', None, _('hide status prefix')),
5257 ('C', 'copies', None, _('show source of copied files')),
5278 ('C', 'copies', None, _('show source of copied files')),
5258 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
5279 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
5259 ('', 'rev', [], _('show difference from revision'), _('REV')),
5280 ('', 'rev', [], _('show difference from revision'), _('REV')),
5260 ('', 'change', '', _('list the changed files of a revision'), _('REV')),
5281 ('', 'change', '', _('list the changed files of a revision'), _('REV')),
5261 ] + walkopts + subrepoopts,
5282 ] + walkopts + subrepoopts,
5262 _('[OPTION]... [FILE]...'))
5283 _('[OPTION]... [FILE]...'))
5263 def status(ui, repo, *pats, **opts):
5284 def status(ui, repo, *pats, **opts):
5264 """show changed files in the working directory
5285 """show changed files in the working directory
5265
5286
5266 Show status of files in the repository. If names are given, only
5287 Show status of files in the repository. If names are given, only
5267 files that match are shown. Files that are clean or ignored or
5288 files that match are shown. Files that are clean or ignored or
5268 the source of a copy/move operation, are not listed unless
5289 the source of a copy/move operation, are not listed unless
5269 -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
5290 -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
5270 Unless options described with "show only ..." are given, the
5291 Unless options described with "show only ..." are given, the
5271 options -mardu are used.
5292 options -mardu are used.
5272
5293
5273 Option -q/--quiet hides untracked (unknown and ignored) files
5294 Option -q/--quiet hides untracked (unknown and ignored) files
5274 unless explicitly requested with -u/--unknown or -i/--ignored.
5295 unless explicitly requested with -u/--unknown or -i/--ignored.
5275
5296
5276 .. note::
5297 .. note::
5277
5298
5278 status may appear to disagree with diff if permissions have
5299 status may appear to disagree with diff if permissions have
5279 changed or a merge has occurred. The standard diff format does
5300 changed or a merge has occurred. The standard diff format does
5280 not report permission changes and diff only reports changes
5301 not report permission changes and diff only reports changes
5281 relative to one merge parent.
5302 relative to one merge parent.
5282
5303
5283 If one revision is given, it is used as the base revision.
5304 If one revision is given, it is used as the base revision.
5284 If two revisions are given, the differences between them are
5305 If two revisions are given, the differences between them are
5285 shown. The --change option can also be used as a shortcut to list
5306 shown. The --change option can also be used as a shortcut to list
5286 the changed files of a revision from its first parent.
5307 the changed files of a revision from its first parent.
5287
5308
5288 The codes used to show the status of files are::
5309 The codes used to show the status of files are::
5289
5310
5290 M = modified
5311 M = modified
5291 A = added
5312 A = added
5292 R = removed
5313 R = removed
5293 C = clean
5314 C = clean
5294 ! = missing (deleted by non-hg command, but still tracked)
5315 ! = missing (deleted by non-hg command, but still tracked)
5295 ? = not tracked
5316 ? = not tracked
5296 I = ignored
5317 I = ignored
5297 = origin of the previous file (with --copies)
5318 = origin of the previous file (with --copies)
5298
5319
5299 .. container:: verbose
5320 .. container:: verbose
5300
5321
5301 Examples:
5322 Examples:
5302
5323
5303 - show changes in the working directory relative to a
5324 - show changes in the working directory relative to a
5304 changeset::
5325 changeset::
5305
5326
5306 hg status --rev 9353
5327 hg status --rev 9353
5307
5328
5308 - show all changes including copies in an existing changeset::
5329 - show all changes including copies in an existing changeset::
5309
5330
5310 hg status --copies --change 9353
5331 hg status --copies --change 9353
5311
5332
5312 - get a NUL separated list of added files, suitable for xargs::
5333 - get a NUL separated list of added files, suitable for xargs::
5313
5334
5314 hg status -an0
5335 hg status -an0
5315
5336
5316 Returns 0 on success.
5337 Returns 0 on success.
5317 """
5338 """
5318
5339
5319 revs = opts.get('rev')
5340 revs = opts.get('rev')
5320 change = opts.get('change')
5341 change = opts.get('change')
5321
5342
5322 if revs and change:
5343 if revs and change:
5323 msg = _('cannot specify --rev and --change at the same time')
5344 msg = _('cannot specify --rev and --change at the same time')
5324 raise util.Abort(msg)
5345 raise util.Abort(msg)
5325 elif change:
5346 elif change:
5326 node2 = scmutil.revsingle(repo, change, None).node()
5347 node2 = scmutil.revsingle(repo, change, None).node()
5327 node1 = repo[node2].p1().node()
5348 node1 = repo[node2].p1().node()
5328 else:
5349 else:
5329 node1, node2 = scmutil.revpair(repo, revs)
5350 node1, node2 = scmutil.revpair(repo, revs)
5330
5351
5331 cwd = (pats and repo.getcwd()) or ''
5352 cwd = (pats and repo.getcwd()) or ''
5332 end = opts.get('print0') and '\0' or '\n'
5353 end = opts.get('print0') and '\0' or '\n'
5333 copy = {}
5354 copy = {}
5334 states = 'modified added removed deleted unknown ignored clean'.split()
5355 states = 'modified added removed deleted unknown ignored clean'.split()
5335 show = [k for k in states if opts.get(k)]
5356 show = [k for k in states if opts.get(k)]
5336 if opts.get('all'):
5357 if opts.get('all'):
5337 show += ui.quiet and (states[:4] + ['clean']) or states
5358 show += ui.quiet and (states[:4] + ['clean']) or states
5338 if not show:
5359 if not show:
5339 show = ui.quiet and states[:4] or states[:5]
5360 show = ui.quiet and states[:4] or states[:5]
5340
5361
5341 stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts),
5362 stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts),
5342 'ignored' in show, 'clean' in show, 'unknown' in show,
5363 'ignored' in show, 'clean' in show, 'unknown' in show,
5343 opts.get('subrepos'))
5364 opts.get('subrepos'))
5344 changestates = zip(states, 'MAR!?IC', stat)
5365 changestates = zip(states, 'MAR!?IC', stat)
5345
5366
5346 if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
5367 if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
5347 copy = copies.pathcopies(repo[node1], repo[node2])
5368 copy = copies.pathcopies(repo[node1], repo[node2])
5348
5369
5349 fm = ui.formatter('status', opts)
5370 fm = ui.formatter('status', opts)
5350 fmt = '%s' + end
5371 fmt = '%s' + end
5351 showchar = not opts.get('no_status')
5372 showchar = not opts.get('no_status')
5352
5373
5353 for state, char, files in changestates:
5374 for state, char, files in changestates:
5354 if state in show:
5375 if state in show:
5355 label = 'status.' + state
5376 label = 'status.' + state
5356 for f in files:
5377 for f in files:
5357 fm.startitem()
5378 fm.startitem()
5358 fm.condwrite(showchar, 'status', '%s ', char, label=label)
5379 fm.condwrite(showchar, 'status', '%s ', char, label=label)
5359 fm.write('path', fmt, repo.pathto(f, cwd), label=label)
5380 fm.write('path', fmt, repo.pathto(f, cwd), label=label)
5360 if f in copy:
5381 if f in copy:
5361 fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd),
5382 fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd),
5362 label='status.copied')
5383 label='status.copied')
5363 fm.end()
5384 fm.end()
5364
5385
5365 @command('^summary|sum',
5386 @command('^summary|sum',
5366 [('', 'remote', None, _('check for push and pull'))], '[--remote]')
5387 [('', 'remote', None, _('check for push and pull'))], '[--remote]')
5367 def summary(ui, repo, **opts):
5388 def summary(ui, repo, **opts):
5368 """summarize working directory state
5389 """summarize working directory state
5369
5390
5370 This generates a brief summary of the working directory state,
5391 This generates a brief summary of the working directory state,
5371 including parents, branch, commit status, and available updates.
5392 including parents, branch, commit status, and available updates.
5372
5393
5373 With the --remote option, this will check the default paths for
5394 With the --remote option, this will check the default paths for
5374 incoming and outgoing changes. This can be time-consuming.
5395 incoming and outgoing changes. This can be time-consuming.
5375
5396
5376 Returns 0 on success.
5397 Returns 0 on success.
5377 """
5398 """
5378
5399
5379 ctx = repo[None]
5400 ctx = repo[None]
5380 parents = ctx.parents()
5401 parents = ctx.parents()
5381 pnode = parents[0].node()
5402 pnode = parents[0].node()
5382 marks = []
5403 marks = []
5383
5404
5384 for p in parents:
5405 for p in parents:
5385 # label with log.changeset (instead of log.parent) since this
5406 # label with log.changeset (instead of log.parent) since this
5386 # shows a working directory parent *changeset*:
5407 # shows a working directory parent *changeset*:
5387 # i18n: column positioning for "hg summary"
5408 # i18n: column positioning for "hg summary"
5388 ui.write(_('parent: %d:%s ') % (p.rev(), str(p)),
5409 ui.write(_('parent: %d:%s ') % (p.rev(), str(p)),
5389 label='log.changeset changeset.%s' % p.phasestr())
5410 label='log.changeset changeset.%s' % p.phasestr())
5390 ui.write(' '.join(p.tags()), label='log.tag')
5411 ui.write(' '.join(p.tags()), label='log.tag')
5391 if p.bookmarks():
5412 if p.bookmarks():
5392 marks.extend(p.bookmarks())
5413 marks.extend(p.bookmarks())
5393 if p.rev() == -1:
5414 if p.rev() == -1:
5394 if not len(repo):
5415 if not len(repo):
5395 ui.write(_(' (empty repository)'))
5416 ui.write(_(' (empty repository)'))
5396 else:
5417 else:
5397 ui.write(_(' (no revision checked out)'))
5418 ui.write(_(' (no revision checked out)'))
5398 ui.write('\n')
5419 ui.write('\n')
5399 if p.description():
5420 if p.description():
5400 ui.status(' ' + p.description().splitlines()[0].strip() + '\n',
5421 ui.status(' ' + p.description().splitlines()[0].strip() + '\n',
5401 label='log.summary')
5422 label='log.summary')
5402
5423
5403 branch = ctx.branch()
5424 branch = ctx.branch()
5404 bheads = repo.branchheads(branch)
5425 bheads = repo.branchheads(branch)
5405 # i18n: column positioning for "hg summary"
5426 # i18n: column positioning for "hg summary"
5406 m = _('branch: %s\n') % branch
5427 m = _('branch: %s\n') % branch
5407 if branch != 'default':
5428 if branch != 'default':
5408 ui.write(m, label='log.branch')
5429 ui.write(m, label='log.branch')
5409 else:
5430 else:
5410 ui.status(m, label='log.branch')
5431 ui.status(m, label='log.branch')
5411
5432
5412 if marks:
5433 if marks:
5413 current = repo._bookmarkcurrent
5434 current = repo._bookmarkcurrent
5414 # i18n: column positioning for "hg summary"
5435 # i18n: column positioning for "hg summary"
5415 ui.write(_('bookmarks:'), label='log.bookmark')
5436 ui.write(_('bookmarks:'), label='log.bookmark')
5416 if current is not None:
5437 if current is not None:
5417 if current in marks:
5438 if current in marks:
5418 ui.write(' *' + current, label='bookmarks.current')
5439 ui.write(' *' + current, label='bookmarks.current')
5419 marks.remove(current)
5440 marks.remove(current)
5420 else:
5441 else:
5421 ui.write(' [%s]' % current, label='bookmarks.current')
5442 ui.write(' [%s]' % current, label='bookmarks.current')
5422 for m in marks:
5443 for m in marks:
5423 ui.write(' ' + m, label='log.bookmark')
5444 ui.write(' ' + m, label='log.bookmark')
5424 ui.write('\n', label='log.bookmark')
5445 ui.write('\n', label='log.bookmark')
5425
5446
5426 st = list(repo.status(unknown=True))[:6]
5447 st = list(repo.status(unknown=True))[:6]
5427
5448
5428 c = repo.dirstate.copies()
5449 c = repo.dirstate.copies()
5429 copied, renamed = [], []
5450 copied, renamed = [], []
5430 for d, s in c.iteritems():
5451 for d, s in c.iteritems():
5431 if s in st[2]:
5452 if s in st[2]:
5432 st[2].remove(s)
5453 st[2].remove(s)
5433 renamed.append(d)
5454 renamed.append(d)
5434 else:
5455 else:
5435 copied.append(d)
5456 copied.append(d)
5436 if d in st[1]:
5457 if d in st[1]:
5437 st[1].remove(d)
5458 st[1].remove(d)
5438 st.insert(3, renamed)
5459 st.insert(3, renamed)
5439 st.insert(4, copied)
5460 st.insert(4, copied)
5440
5461
5441 ms = mergemod.mergestate(repo)
5462 ms = mergemod.mergestate(repo)
5442 st.append([f for f in ms if ms[f] == 'u'])
5463 st.append([f for f in ms if ms[f] == 'u'])
5443
5464
5444 subs = [s for s in ctx.substate if ctx.sub(s).dirty()]
5465 subs = [s for s in ctx.substate if ctx.sub(s).dirty()]
5445 st.append(subs)
5466 st.append(subs)
5446
5467
5447 labels = [ui.label(_('%d modified'), 'status.modified'),
5468 labels = [ui.label(_('%d modified'), 'status.modified'),
5448 ui.label(_('%d added'), 'status.added'),
5469 ui.label(_('%d added'), 'status.added'),
5449 ui.label(_('%d removed'), 'status.removed'),
5470 ui.label(_('%d removed'), 'status.removed'),
5450 ui.label(_('%d renamed'), 'status.copied'),
5471 ui.label(_('%d renamed'), 'status.copied'),
5451 ui.label(_('%d copied'), 'status.copied'),
5472 ui.label(_('%d copied'), 'status.copied'),
5452 ui.label(_('%d deleted'), 'status.deleted'),
5473 ui.label(_('%d deleted'), 'status.deleted'),
5453 ui.label(_('%d unknown'), 'status.unknown'),
5474 ui.label(_('%d unknown'), 'status.unknown'),
5454 ui.label(_('%d ignored'), 'status.ignored'),
5475 ui.label(_('%d ignored'), 'status.ignored'),
5455 ui.label(_('%d unresolved'), 'resolve.unresolved'),
5476 ui.label(_('%d unresolved'), 'resolve.unresolved'),
5456 ui.label(_('%d subrepos'), 'status.modified')]
5477 ui.label(_('%d subrepos'), 'status.modified')]
5457 t = []
5478 t = []
5458 for s, l in zip(st, labels):
5479 for s, l in zip(st, labels):
5459 if s:
5480 if s:
5460 t.append(l % len(s))
5481 t.append(l % len(s))
5461
5482
5462 t = ', '.join(t)
5483 t = ', '.join(t)
5463 cleanworkdir = False
5484 cleanworkdir = False
5464
5485
5465 if repo.vfs.exists('updatestate'):
5486 if repo.vfs.exists('updatestate'):
5466 t += _(' (interrupted update)')
5487 t += _(' (interrupted update)')
5467 elif len(parents) > 1:
5488 elif len(parents) > 1:
5468 t += _(' (merge)')
5489 t += _(' (merge)')
5469 elif branch != parents[0].branch():
5490 elif branch != parents[0].branch():
5470 t += _(' (new branch)')
5491 t += _(' (new branch)')
5471 elif (parents[0].closesbranch() and
5492 elif (parents[0].closesbranch() and
5472 pnode in repo.branchheads(branch, closed=True)):
5493 pnode in repo.branchheads(branch, closed=True)):
5473 t += _(' (head closed)')
5494 t += _(' (head closed)')
5474 elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]):
5495 elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]):
5475 t += _(' (clean)')
5496 t += _(' (clean)')
5476 cleanworkdir = True
5497 cleanworkdir = True
5477 elif pnode not in bheads:
5498 elif pnode not in bheads:
5478 t += _(' (new branch head)')
5499 t += _(' (new branch head)')
5479
5500
5480 if cleanworkdir:
5501 if cleanworkdir:
5481 # i18n: column positioning for "hg summary"
5502 # i18n: column positioning for "hg summary"
5482 ui.status(_('commit: %s\n') % t.strip())
5503 ui.status(_('commit: %s\n') % t.strip())
5483 else:
5504 else:
5484 # i18n: column positioning for "hg summary"
5505 # i18n: column positioning for "hg summary"
5485 ui.write(_('commit: %s\n') % t.strip())
5506 ui.write(_('commit: %s\n') % t.strip())
5486
5507
5487 # all ancestors of branch heads - all ancestors of parent = new csets
5508 # all ancestors of branch heads - all ancestors of parent = new csets
5488 new = len(repo.changelog.findmissing([ctx.node() for ctx in parents],
5509 new = len(repo.changelog.findmissing([ctx.node() for ctx in parents],
5489 bheads))
5510 bheads))
5490
5511
5491 if new == 0:
5512 if new == 0:
5492 # i18n: column positioning for "hg summary"
5513 # i18n: column positioning for "hg summary"
5493 ui.status(_('update: (current)\n'))
5514 ui.status(_('update: (current)\n'))
5494 elif pnode not in bheads:
5515 elif pnode not in bheads:
5495 # i18n: column positioning for "hg summary"
5516 # i18n: column positioning for "hg summary"
5496 ui.write(_('update: %d new changesets (update)\n') % new)
5517 ui.write(_('update: %d new changesets (update)\n') % new)
5497 else:
5518 else:
5498 # i18n: column positioning for "hg summary"
5519 # i18n: column positioning for "hg summary"
5499 ui.write(_('update: %d new changesets, %d branch heads (merge)\n') %
5520 ui.write(_('update: %d new changesets, %d branch heads (merge)\n') %
5500 (new, len(bheads)))
5521 (new, len(bheads)))
5501
5522
5502 cmdutil.summaryhooks(ui, repo)
5523 cmdutil.summaryhooks(ui, repo)
5503
5524
5504 if opts.get('remote'):
5525 if opts.get('remote'):
5505 needsincoming, needsoutgoing = True, True
5526 needsincoming, needsoutgoing = True, True
5506 else:
5527 else:
5507 needsincoming, needsoutgoing = False, False
5528 needsincoming, needsoutgoing = False, False
5508 for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None):
5529 for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None):
5509 if i:
5530 if i:
5510 needsincoming = True
5531 needsincoming = True
5511 if o:
5532 if o:
5512 needsoutgoing = True
5533 needsoutgoing = True
5513 if not needsincoming and not needsoutgoing:
5534 if not needsincoming and not needsoutgoing:
5514 return
5535 return
5515
5536
5516 def getincoming():
5537 def getincoming():
5517 source, branches = hg.parseurl(ui.expandpath('default'))
5538 source, branches = hg.parseurl(ui.expandpath('default'))
5518 sbranch = branches[0]
5539 sbranch = branches[0]
5519 try:
5540 try:
5520 other = hg.peer(repo, {}, source)
5541 other = hg.peer(repo, {}, source)
5521 except error.RepoError:
5542 except error.RepoError:
5522 if opts.get('remote'):
5543 if opts.get('remote'):
5523 raise
5544 raise
5524 return source, sbranch, None, None, None
5545 return source, sbranch, None, None, None
5525 revs, checkout = hg.addbranchrevs(repo, other, branches, None)
5546 revs, checkout = hg.addbranchrevs(repo, other, branches, None)
5526 if revs:
5547 if revs:
5527 revs = [other.lookup(rev) for rev in revs]
5548 revs = [other.lookup(rev) for rev in revs]
5528 ui.debug('comparing with %s\n' % util.hidepassword(source))
5549 ui.debug('comparing with %s\n' % util.hidepassword(source))
5529 repo.ui.pushbuffer()
5550 repo.ui.pushbuffer()
5530 commoninc = discovery.findcommonincoming(repo, other, heads=revs)
5551 commoninc = discovery.findcommonincoming(repo, other, heads=revs)
5531 repo.ui.popbuffer()
5552 repo.ui.popbuffer()
5532 return source, sbranch, other, commoninc, commoninc[1]
5553 return source, sbranch, other, commoninc, commoninc[1]
5533
5554
5534 if needsincoming:
5555 if needsincoming:
5535 source, sbranch, sother, commoninc, incoming = getincoming()
5556 source, sbranch, sother, commoninc, incoming = getincoming()
5536 else:
5557 else:
5537 source = sbranch = sother = commoninc = incoming = None
5558 source = sbranch = sother = commoninc = incoming = None
5538
5559
5539 def getoutgoing():
5560 def getoutgoing():
5540 dest, branches = hg.parseurl(ui.expandpath('default-push', 'default'))
5561 dest, branches = hg.parseurl(ui.expandpath('default-push', 'default'))
5541 dbranch = branches[0]
5562 dbranch = branches[0]
5542 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
5563 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
5543 if source != dest:
5564 if source != dest:
5544 try:
5565 try:
5545 dother = hg.peer(repo, {}, dest)
5566 dother = hg.peer(repo, {}, dest)
5546 except error.RepoError:
5567 except error.RepoError:
5547 if opts.get('remote'):
5568 if opts.get('remote'):
5548 raise
5569 raise
5549 return dest, dbranch, None, None
5570 return dest, dbranch, None, None
5550 ui.debug('comparing with %s\n' % util.hidepassword(dest))
5571 ui.debug('comparing with %s\n' % util.hidepassword(dest))
5551 elif sother is None:
5572 elif sother is None:
5552 # there is no explicit destination peer, but source one is invalid
5573 # there is no explicit destination peer, but source one is invalid
5553 return dest, dbranch, None, None
5574 return dest, dbranch, None, None
5554 else:
5575 else:
5555 dother = sother
5576 dother = sother
5556 if (source != dest or (sbranch is not None and sbranch != dbranch)):
5577 if (source != dest or (sbranch is not None and sbranch != dbranch)):
5557 common = None
5578 common = None
5558 else:
5579 else:
5559 common = commoninc
5580 common = commoninc
5560 if revs:
5581 if revs:
5561 revs = [repo.lookup(rev) for rev in revs]
5582 revs = [repo.lookup(rev) for rev in revs]
5562 repo.ui.pushbuffer()
5583 repo.ui.pushbuffer()
5563 outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs,
5584 outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs,
5564 commoninc=common)
5585 commoninc=common)
5565 repo.ui.popbuffer()
5586 repo.ui.popbuffer()
5566 return dest, dbranch, dother, outgoing
5587 return dest, dbranch, dother, outgoing
5567
5588
5568 if needsoutgoing:
5589 if needsoutgoing:
5569 dest, dbranch, dother, outgoing = getoutgoing()
5590 dest, dbranch, dother, outgoing = getoutgoing()
5570 else:
5591 else:
5571 dest = dbranch = dother = outgoing = None
5592 dest = dbranch = dother = outgoing = None
5572
5593
5573 if opts.get('remote'):
5594 if opts.get('remote'):
5574 t = []
5595 t = []
5575 if incoming:
5596 if incoming:
5576 t.append(_('1 or more incoming'))
5597 t.append(_('1 or more incoming'))
5577 o = outgoing.missing
5598 o = outgoing.missing
5578 if o:
5599 if o:
5579 t.append(_('%d outgoing') % len(o))
5600 t.append(_('%d outgoing') % len(o))
5580 other = dother or sother
5601 other = dother or sother
5581 if 'bookmarks' in other.listkeys('namespaces'):
5602 if 'bookmarks' in other.listkeys('namespaces'):
5582 lmarks = repo.listkeys('bookmarks')
5603 lmarks = repo.listkeys('bookmarks')
5583 rmarks = other.listkeys('bookmarks')
5604 rmarks = other.listkeys('bookmarks')
5584 diff = set(rmarks) - set(lmarks)
5605 diff = set(rmarks) - set(lmarks)
5585 if len(diff) > 0:
5606 if len(diff) > 0:
5586 t.append(_('%d incoming bookmarks') % len(diff))
5607 t.append(_('%d incoming bookmarks') % len(diff))
5587 diff = set(lmarks) - set(rmarks)
5608 diff = set(lmarks) - set(rmarks)
5588 if len(diff) > 0:
5609 if len(diff) > 0:
5589 t.append(_('%d outgoing bookmarks') % len(diff))
5610 t.append(_('%d outgoing bookmarks') % len(diff))
5590
5611
5591 if t:
5612 if t:
5592 # i18n: column positioning for "hg summary"
5613 # i18n: column positioning for "hg summary"
5593 ui.write(_('remote: %s\n') % (', '.join(t)))
5614 ui.write(_('remote: %s\n') % (', '.join(t)))
5594 else:
5615 else:
5595 # i18n: column positioning for "hg summary"
5616 # i18n: column positioning for "hg summary"
5596 ui.status(_('remote: (synced)\n'))
5617 ui.status(_('remote: (synced)\n'))
5597
5618
5598 cmdutil.summaryremotehooks(ui, repo, opts,
5619 cmdutil.summaryremotehooks(ui, repo, opts,
5599 ((source, sbranch, sother, commoninc),
5620 ((source, sbranch, sother, commoninc),
5600 (dest, dbranch, dother, outgoing)))
5621 (dest, dbranch, dother, outgoing)))
5601
5622
5602 @command('tag',
5623 @command('tag',
5603 [('f', 'force', None, _('force tag')),
5624 [('f', 'force', None, _('force tag')),
5604 ('l', 'local', None, _('make the tag local')),
5625 ('l', 'local', None, _('make the tag local')),
5605 ('r', 'rev', '', _('revision to tag'), _('REV')),
5626 ('r', 'rev', '', _('revision to tag'), _('REV')),
5606 ('', 'remove', None, _('remove a tag')),
5627 ('', 'remove', None, _('remove a tag')),
5607 # -l/--local is already there, commitopts cannot be used
5628 # -l/--local is already there, commitopts cannot be used
5608 ('e', 'edit', None, _('edit commit message')),
5629 ('e', 'edit', None, _('edit commit message')),
5609 ('m', 'message', '', _('use <text> as commit message'), _('TEXT')),
5630 ('m', 'message', '', _('use <text> as commit message'), _('TEXT')),
5610 ] + commitopts2,
5631 ] + commitopts2,
5611 _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...'))
5632 _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...'))
5612 def tag(ui, repo, name1, *names, **opts):
5633 def tag(ui, repo, name1, *names, **opts):
5613 """add one or more tags for the current or given revision
5634 """add one or more tags for the current or given revision
5614
5635
5615 Name a particular revision using <name>.
5636 Name a particular revision using <name>.
5616
5637
5617 Tags are used to name particular revisions of the repository and are
5638 Tags are used to name particular revisions of the repository and are
5618 very useful to compare different revisions, to go back to significant
5639 very useful to compare different revisions, to go back to significant
5619 earlier versions or to mark branch points as releases, etc. Changing
5640 earlier versions or to mark branch points as releases, etc. Changing
5620 an existing tag is normally disallowed; use -f/--force to override.
5641 an existing tag is normally disallowed; use -f/--force to override.
5621
5642
5622 If no revision is given, the parent of the working directory is
5643 If no revision is given, the parent of the working directory is
5623 used.
5644 used.
5624
5645
5625 To facilitate version control, distribution, and merging of tags,
5646 To facilitate version control, distribution, and merging of tags,
5626 they are stored as a file named ".hgtags" which is managed similarly
5647 they are stored as a file named ".hgtags" which is managed similarly
5627 to other project files and can be hand-edited if necessary. This
5648 to other project files and can be hand-edited if necessary. This
5628 also means that tagging creates a new commit. The file
5649 also means that tagging creates a new commit. The file
5629 ".hg/localtags" is used for local tags (not shared among
5650 ".hg/localtags" is used for local tags (not shared among
5630 repositories).
5651 repositories).
5631
5652
5632 Tag commits are usually made at the head of a branch. If the parent
5653 Tag commits are usually made at the head of a branch. If the parent
5633 of the working directory is not a branch head, :hg:`tag` aborts; use
5654 of the working directory is not a branch head, :hg:`tag` aborts; use
5634 -f/--force to force the tag commit to be based on a non-head
5655 -f/--force to force the tag commit to be based on a non-head
5635 changeset.
5656 changeset.
5636
5657
5637 See :hg:`help dates` for a list of formats valid for -d/--date.
5658 See :hg:`help dates` for a list of formats valid for -d/--date.
5638
5659
5639 Since tag names have priority over branch names during revision
5660 Since tag names have priority over branch names during revision
5640 lookup, using an existing branch name as a tag name is discouraged.
5661 lookup, using an existing branch name as a tag name is discouraged.
5641
5662
5642 Returns 0 on success.
5663 Returns 0 on success.
5643 """
5664 """
5644 wlock = lock = None
5665 wlock = lock = None
5645 try:
5666 try:
5646 wlock = repo.wlock()
5667 wlock = repo.wlock()
5647 lock = repo.lock()
5668 lock = repo.lock()
5648 rev_ = "."
5669 rev_ = "."
5649 names = [t.strip() for t in (name1,) + names]
5670 names = [t.strip() for t in (name1,) + names]
5650 if len(names) != len(set(names)):
5671 if len(names) != len(set(names)):
5651 raise util.Abort(_('tag names must be unique'))
5672 raise util.Abort(_('tag names must be unique'))
5652 for n in names:
5673 for n in names:
5653 scmutil.checknewlabel(repo, n, 'tag')
5674 scmutil.checknewlabel(repo, n, 'tag')
5654 if not n:
5675 if not n:
5655 raise util.Abort(_('tag names cannot consist entirely of '
5676 raise util.Abort(_('tag names cannot consist entirely of '
5656 'whitespace'))
5677 'whitespace'))
5657 if opts.get('rev') and opts.get('remove'):
5678 if opts.get('rev') and opts.get('remove'):
5658 raise util.Abort(_("--rev and --remove are incompatible"))
5679 raise util.Abort(_("--rev and --remove are incompatible"))
5659 if opts.get('rev'):
5680 if opts.get('rev'):
5660 rev_ = opts['rev']
5681 rev_ = opts['rev']
5661 message = opts.get('message')
5682 message = opts.get('message')
5662 if opts.get('remove'):
5683 if opts.get('remove'):
5663 expectedtype = opts.get('local') and 'local' or 'global'
5684 expectedtype = opts.get('local') and 'local' or 'global'
5664 for n in names:
5685 for n in names:
5665 if not repo.tagtype(n):
5686 if not repo.tagtype(n):
5666 raise util.Abort(_("tag '%s' does not exist") % n)
5687 raise util.Abort(_("tag '%s' does not exist") % n)
5667 if repo.tagtype(n) != expectedtype:
5688 if repo.tagtype(n) != expectedtype:
5668 if expectedtype == 'global':
5689 if expectedtype == 'global':
5669 raise util.Abort(_("tag '%s' is not a global tag") % n)
5690 raise util.Abort(_("tag '%s' is not a global tag") % n)
5670 else:
5691 else:
5671 raise util.Abort(_("tag '%s' is not a local tag") % n)
5692 raise util.Abort(_("tag '%s' is not a local tag") % n)
5672 rev_ = nullid
5693 rev_ = nullid
5673 if not message:
5694 if not message:
5674 # we don't translate commit messages
5695 # we don't translate commit messages
5675 message = 'Removed tag %s' % ', '.join(names)
5696 message = 'Removed tag %s' % ', '.join(names)
5676 elif not opts.get('force'):
5697 elif not opts.get('force'):
5677 for n in names:
5698 for n in names:
5678 if n in repo.tags():
5699 if n in repo.tags():
5679 raise util.Abort(_("tag '%s' already exists "
5700 raise util.Abort(_("tag '%s' already exists "
5680 "(use -f to force)") % n)
5701 "(use -f to force)") % n)
5681 if not opts.get('local'):
5702 if not opts.get('local'):
5682 p1, p2 = repo.dirstate.parents()
5703 p1, p2 = repo.dirstate.parents()
5683 if p2 != nullid:
5704 if p2 != nullid:
5684 raise util.Abort(_('uncommitted merge'))
5705 raise util.Abort(_('uncommitted merge'))
5685 bheads = repo.branchheads()
5706 bheads = repo.branchheads()
5686 if not opts.get('force') and bheads and p1 not in bheads:
5707 if not opts.get('force') and bheads and p1 not in bheads:
5687 raise util.Abort(_('not at a branch head (use -f to force)'))
5708 raise util.Abort(_('not at a branch head (use -f to force)'))
5688 r = scmutil.revsingle(repo, rev_).node()
5709 r = scmutil.revsingle(repo, rev_).node()
5689
5710
5690 if not message:
5711 if not message:
5691 # we don't translate commit messages
5712 # we don't translate commit messages
5692 message = ('Added tag %s for changeset %s' %
5713 message = ('Added tag %s for changeset %s' %
5693 (', '.join(names), short(r)))
5714 (', '.join(names), short(r)))
5694
5715
5695 date = opts.get('date')
5716 date = opts.get('date')
5696 if date:
5717 if date:
5697 date = util.parsedate(date)
5718 date = util.parsedate(date)
5698
5719
5699 editor = cmdutil.getcommiteditor(**opts)
5720 editor = cmdutil.getcommiteditor(**opts)
5700
5721
5701 # don't allow tagging the null rev
5722 # don't allow tagging the null rev
5702 if (not opts.get('remove') and
5723 if (not opts.get('remove') and
5703 scmutil.revsingle(repo, rev_).rev() == nullrev):
5724 scmutil.revsingle(repo, rev_).rev() == nullrev):
5704 raise util.Abort(_("cannot tag null revision"))
5725 raise util.Abort(_("cannot tag null revision"))
5705
5726
5706 repo.tag(names, r, message, opts.get('local'), opts.get('user'), date,
5727 repo.tag(names, r, message, opts.get('local'), opts.get('user'), date,
5707 editor=editor)
5728 editor=editor)
5708 finally:
5729 finally:
5709 release(lock, wlock)
5730 release(lock, wlock)
5710
5731
5711 @command('tags', [], '')
5732 @command('tags', [], '')
5712 def tags(ui, repo, **opts):
5733 def tags(ui, repo, **opts):
5713 """list repository tags
5734 """list repository tags
5714
5735
5715 This lists both regular and local tags. When the -v/--verbose
5736 This lists both regular and local tags. When the -v/--verbose
5716 switch is used, a third column "local" is printed for local tags.
5737 switch is used, a third column "local" is printed for local tags.
5717
5738
5718 Returns 0 on success.
5739 Returns 0 on success.
5719 """
5740 """
5720
5741
5721 fm = ui.formatter('tags', opts)
5742 fm = ui.formatter('tags', opts)
5722 hexfunc = ui.debugflag and hex or short
5743 hexfunc = ui.debugflag and hex or short
5723 tagtype = ""
5744 tagtype = ""
5724
5745
5725 for t, n in reversed(repo.tagslist()):
5746 for t, n in reversed(repo.tagslist()):
5726 hn = hexfunc(n)
5747 hn = hexfunc(n)
5727 label = 'tags.normal'
5748 label = 'tags.normal'
5728 tagtype = ''
5749 tagtype = ''
5729 if repo.tagtype(t) == 'local':
5750 if repo.tagtype(t) == 'local':
5730 label = 'tags.local'
5751 label = 'tags.local'
5731 tagtype = 'local'
5752 tagtype = 'local'
5732
5753
5733 fm.startitem()
5754 fm.startitem()
5734 fm.write('tag', '%s', t, label=label)
5755 fm.write('tag', '%s', t, label=label)
5735 fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
5756 fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
5736 fm.condwrite(not ui.quiet, 'rev id', fmt,
5757 fm.condwrite(not ui.quiet, 'rev id', fmt,
5737 repo.changelog.rev(n), hn, label=label)
5758 repo.changelog.rev(n), hn, label=label)
5738 fm.condwrite(ui.verbose and tagtype, 'type', ' %s',
5759 fm.condwrite(ui.verbose and tagtype, 'type', ' %s',
5739 tagtype, label=label)
5760 tagtype, label=label)
5740 fm.plain('\n')
5761 fm.plain('\n')
5741 fm.end()
5762 fm.end()
5742
5763
5743 @command('tip',
5764 @command('tip',
5744 [('p', 'patch', None, _('show patch')),
5765 [('p', 'patch', None, _('show patch')),
5745 ('g', 'git', None, _('use git extended diff format')),
5766 ('g', 'git', None, _('use git extended diff format')),
5746 ] + templateopts,
5767 ] + templateopts,
5747 _('[-p] [-g]'))
5768 _('[-p] [-g]'))
5748 def tip(ui, repo, **opts):
5769 def tip(ui, repo, **opts):
5749 """show the tip revision (DEPRECATED)
5770 """show the tip revision (DEPRECATED)
5750
5771
5751 The tip revision (usually just called the tip) is the changeset
5772 The tip revision (usually just called the tip) is the changeset
5752 most recently added to the repository (and therefore the most
5773 most recently added to the repository (and therefore the most
5753 recently changed head).
5774 recently changed head).
5754
5775
5755 If you have just made a commit, that commit will be the tip. If
5776 If you have just made a commit, that commit will be the tip. If
5756 you have just pulled changes from another repository, the tip of
5777 you have just pulled changes from another repository, the tip of
5757 that repository becomes the current tip. The "tip" tag is special
5778 that repository becomes the current tip. The "tip" tag is special
5758 and cannot be renamed or assigned to a different changeset.
5779 and cannot be renamed or assigned to a different changeset.
5759
5780
5760 This command is deprecated, please use :hg:`heads` instead.
5781 This command is deprecated, please use :hg:`heads` instead.
5761
5782
5762 Returns 0 on success.
5783 Returns 0 on success.
5763 """
5784 """
5764 displayer = cmdutil.show_changeset(ui, repo, opts)
5785 displayer = cmdutil.show_changeset(ui, repo, opts)
5765 displayer.show(repo['tip'])
5786 displayer.show(repo['tip'])
5766 displayer.close()
5787 displayer.close()
5767
5788
5768 @command('unbundle',
5789 @command('unbundle',
5769 [('u', 'update', None,
5790 [('u', 'update', None,
5770 _('update to new branch head if changesets were unbundled'))],
5791 _('update to new branch head if changesets were unbundled'))],
5771 _('[-u] FILE...'))
5792 _('[-u] FILE...'))
5772 def unbundle(ui, repo, fname1, *fnames, **opts):
5793 def unbundle(ui, repo, fname1, *fnames, **opts):
5773 """apply one or more changegroup files
5794 """apply one or more changegroup files
5774
5795
5775 Apply one or more compressed changegroup files generated by the
5796 Apply one or more compressed changegroup files generated by the
5776 bundle command.
5797 bundle command.
5777
5798
5778 Returns 0 on success, 1 if an update has unresolved files.
5799 Returns 0 on success, 1 if an update has unresolved files.
5779 """
5800 """
5780 fnames = (fname1,) + fnames
5801 fnames = (fname1,) + fnames
5781
5802
5782 lock = repo.lock()
5803 lock = repo.lock()
5783 wc = repo['.']
5804 wc = repo['.']
5784 try:
5805 try:
5785 for fname in fnames:
5806 for fname in fnames:
5786 f = hg.openpath(ui, fname)
5807 f = hg.openpath(ui, fname)
5787 gen = exchange.readbundle(ui, f, fname)
5808 gen = exchange.readbundle(ui, f, fname)
5788 modheads = changegroup.addchangegroup(repo, gen, 'unbundle',
5809 modheads = changegroup.addchangegroup(repo, gen, 'unbundle',
5789 'bundle:' + fname)
5810 'bundle:' + fname)
5790 finally:
5811 finally:
5791 lock.release()
5812 lock.release()
5792 bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch())
5813 bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch())
5793 return postincoming(ui, repo, modheads, opts.get('update'), None)
5814 return postincoming(ui, repo, modheads, opts.get('update'), None)
5794
5815
5795 @command('^update|up|checkout|co',
5816 @command('^update|up|checkout|co',
5796 [('C', 'clean', None, _('discard uncommitted changes (no backup)')),
5817 [('C', 'clean', None, _('discard uncommitted changes (no backup)')),
5797 ('c', 'check', None,
5818 ('c', 'check', None,
5798 _('update across branches if no uncommitted changes')),
5819 _('update across branches if no uncommitted changes')),
5799 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
5820 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
5800 ('r', 'rev', '', _('revision'), _('REV'))
5821 ('r', 'rev', '', _('revision'), _('REV'))
5801 ] + mergetoolopts,
5822 ] + mergetoolopts,
5802 _('[-c] [-C] [-d DATE] [[-r] REV]'))
5823 _('[-c] [-C] [-d DATE] [[-r] REV]'))
5803 def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False,
5824 def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False,
5804 tool=None):
5825 tool=None):
5805 """update working directory (or switch revisions)
5826 """update working directory (or switch revisions)
5806
5827
5807 Update the repository's working directory to the specified
5828 Update the repository's working directory to the specified
5808 changeset. If no changeset is specified, update to the tip of the
5829 changeset. If no changeset is specified, update to the tip of the
5809 current named branch and move the current bookmark (see :hg:`help
5830 current named branch and move the current bookmark (see :hg:`help
5810 bookmarks`).
5831 bookmarks`).
5811
5832
5812 Update sets the working directory's parent revision to the specified
5833 Update sets the working directory's parent revision to the specified
5813 changeset (see :hg:`help parents`).
5834 changeset (see :hg:`help parents`).
5814
5835
5815 If the changeset is not a descendant or ancestor of the working
5836 If the changeset is not a descendant or ancestor of the working
5816 directory's parent, the update is aborted. With the -c/--check
5837 directory's parent, the update is aborted. With the -c/--check
5817 option, the working directory is checked for uncommitted changes; if
5838 option, the working directory is checked for uncommitted changes; if
5818 none are found, the working directory is updated to the specified
5839 none are found, the working directory is updated to the specified
5819 changeset.
5840 changeset.
5820
5841
5821 .. container:: verbose
5842 .. container:: verbose
5822
5843
5823 The following rules apply when the working directory contains
5844 The following rules apply when the working directory contains
5824 uncommitted changes:
5845 uncommitted changes:
5825
5846
5826 1. If neither -c/--check nor -C/--clean is specified, and if
5847 1. If neither -c/--check nor -C/--clean is specified, and if
5827 the requested changeset is an ancestor or descendant of
5848 the requested changeset is an ancestor or descendant of
5828 the working directory's parent, the uncommitted changes
5849 the working directory's parent, the uncommitted changes
5829 are merged into the requested changeset and the merged
5850 are merged into the requested changeset and the merged
5830 result is left uncommitted. If the requested changeset is
5851 result is left uncommitted. If the requested changeset is
5831 not an ancestor or descendant (that is, it is on another
5852 not an ancestor or descendant (that is, it is on another
5832 branch), the update is aborted and the uncommitted changes
5853 branch), the update is aborted and the uncommitted changes
5833 are preserved.
5854 are preserved.
5834
5855
5835 2. With the -c/--check option, the update is aborted and the
5856 2. With the -c/--check option, the update is aborted and the
5836 uncommitted changes are preserved.
5857 uncommitted changes are preserved.
5837
5858
5838 3. With the -C/--clean option, uncommitted changes are discarded and
5859 3. With the -C/--clean option, uncommitted changes are discarded and
5839 the working directory is updated to the requested changeset.
5860 the working directory is updated to the requested changeset.
5840
5861
5841 To cancel an uncommitted merge (and lose your changes), use
5862 To cancel an uncommitted merge (and lose your changes), use
5842 :hg:`update --clean .`.
5863 :hg:`update --clean .`.
5843
5864
5844 Use null as the changeset to remove the working directory (like
5865 Use null as the changeset to remove the working directory (like
5845 :hg:`clone -U`).
5866 :hg:`clone -U`).
5846
5867
5847 If you want to revert just one file to an older revision, use
5868 If you want to revert just one file to an older revision, use
5848 :hg:`revert [-r REV] NAME`.
5869 :hg:`revert [-r REV] NAME`.
5849
5870
5850 See :hg:`help dates` for a list of formats valid for -d/--date.
5871 See :hg:`help dates` for a list of formats valid for -d/--date.
5851
5872
5852 Returns 0 on success, 1 if there are unresolved files.
5873 Returns 0 on success, 1 if there are unresolved files.
5853 """
5874 """
5854 if rev and node:
5875 if rev and node:
5855 raise util.Abort(_("please specify just one revision"))
5876 raise util.Abort(_("please specify just one revision"))
5856
5877
5857 if rev is None or rev == '':
5878 if rev is None or rev == '':
5858 rev = node
5879 rev = node
5859
5880
5860 cmdutil.clearunfinished(repo)
5881 cmdutil.clearunfinished(repo)
5861
5882
5862 # with no argument, we also move the current bookmark, if any
5883 # with no argument, we also move the current bookmark, if any
5863 rev, movemarkfrom = bookmarks.calculateupdate(ui, repo, rev)
5884 rev, movemarkfrom = bookmarks.calculateupdate(ui, repo, rev)
5864
5885
5865 # if we defined a bookmark, we have to remember the original bookmark name
5886 # if we defined a bookmark, we have to remember the original bookmark name
5866 brev = rev
5887 brev = rev
5867 rev = scmutil.revsingle(repo, rev, rev).rev()
5888 rev = scmutil.revsingle(repo, rev, rev).rev()
5868
5889
5869 if check and clean:
5890 if check and clean:
5870 raise util.Abort(_("cannot specify both -c/--check and -C/--clean"))
5891 raise util.Abort(_("cannot specify both -c/--check and -C/--clean"))
5871
5892
5872 if date:
5893 if date:
5873 if rev is not None:
5894 if rev is not None:
5874 raise util.Abort(_("you can't specify a revision and a date"))
5895 raise util.Abort(_("you can't specify a revision and a date"))
5875 rev = cmdutil.finddate(ui, repo, date)
5896 rev = cmdutil.finddate(ui, repo, date)
5876
5897
5877 if check:
5898 if check:
5878 c = repo[None]
5899 c = repo[None]
5879 if c.dirty(merge=False, branch=False, missing=True):
5900 if c.dirty(merge=False, branch=False, missing=True):
5880 raise util.Abort(_("uncommitted changes"))
5901 raise util.Abort(_("uncommitted changes"))
5881 if rev is None:
5902 if rev is None:
5882 rev = repo[repo[None].branch()].rev()
5903 rev = repo[repo[None].branch()].rev()
5883 mergemod._checkunknown(repo, repo[None], repo[rev])
5904 mergemod._checkunknown(repo, repo[None], repo[rev])
5884
5905
5885 repo.ui.setconfig('ui', 'forcemerge', tool, 'update')
5906 repo.ui.setconfig('ui', 'forcemerge', tool, 'update')
5886
5907
5887 if clean:
5908 if clean:
5888 ret = hg.clean(repo, rev)
5909 ret = hg.clean(repo, rev)
5889 else:
5910 else:
5890 ret = hg.update(repo, rev)
5911 ret = hg.update(repo, rev)
5891
5912
5892 if not ret and movemarkfrom:
5913 if not ret and movemarkfrom:
5893 if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
5914 if bookmarks.update(repo, [movemarkfrom], repo['.'].node()):
5894 ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent)
5915 ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent)
5895 elif brev in repo._bookmarks:
5916 elif brev in repo._bookmarks:
5896 bookmarks.setcurrent(repo, brev)
5917 bookmarks.setcurrent(repo, brev)
5897 ui.status(_("(activating bookmark %s)\n") % brev)
5918 ui.status(_("(activating bookmark %s)\n") % brev)
5898 elif brev:
5919 elif brev:
5899 if repo._bookmarkcurrent:
5920 if repo._bookmarkcurrent:
5900 ui.status(_("(leaving bookmark %s)\n") %
5921 ui.status(_("(leaving bookmark %s)\n") %
5901 repo._bookmarkcurrent)
5922 repo._bookmarkcurrent)
5902 bookmarks.unsetcurrent(repo)
5923 bookmarks.unsetcurrent(repo)
5903
5924
5904 return ret
5925 return ret
5905
5926
5906 @command('verify', [])
5927 @command('verify', [])
5907 def verify(ui, repo):
5928 def verify(ui, repo):
5908 """verify the integrity of the repository
5929 """verify the integrity of the repository
5909
5930
5910 Verify the integrity of the current repository.
5931 Verify the integrity of the current repository.
5911
5932
5912 This will perform an extensive check of the repository's
5933 This will perform an extensive check of the repository's
5913 integrity, validating the hashes and checksums of each entry in
5934 integrity, validating the hashes and checksums of each entry in
5914 the changelog, manifest, and tracked files, as well as the
5935 the changelog, manifest, and tracked files, as well as the
5915 integrity of their crosslinks and indices.
5936 integrity of their crosslinks and indices.
5916
5937
5917 Please see http://mercurial.selenic.com/wiki/RepositoryCorruption
5938 Please see http://mercurial.selenic.com/wiki/RepositoryCorruption
5918 for more information about recovery from corruption of the
5939 for more information about recovery from corruption of the
5919 repository.
5940 repository.
5920
5941
5921 Returns 0 on success, 1 if errors are encountered.
5942 Returns 0 on success, 1 if errors are encountered.
5922 """
5943 """
5923 return hg.verify(repo)
5944 return hg.verify(repo)
5924
5945
5925 @command('version', [])
5946 @command('version', [])
5926 def version_(ui):
5947 def version_(ui):
5927 """output version and copyright information"""
5948 """output version and copyright information"""
5928 ui.write(_("Mercurial Distributed SCM (version %s)\n")
5949 ui.write(_("Mercurial Distributed SCM (version %s)\n")
5929 % util.version())
5950 % util.version())
5930 ui.status(_(
5951 ui.status(_(
5931 "(see http://mercurial.selenic.com for more information)\n"
5952 "(see http://mercurial.selenic.com for more information)\n"
5932 "\nCopyright (C) 2005-2014 Matt Mackall and others\n"
5953 "\nCopyright (C) 2005-2014 Matt Mackall and others\n"
5933 "This is free software; see the source for copying conditions. "
5954 "This is free software; see the source for copying conditions. "
5934 "There is NO\nwarranty; "
5955 "There is NO\nwarranty; "
5935 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
5956 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
5936 ))
5957 ))
5937
5958
5938 norepo = ("clone init version help debugcommands debugcomplete"
5959 norepo = ("clone init version help debugcommands debugcomplete"
5939 " debugdate debuginstall debugfsinfo debugpushkey debugwireargs"
5960 " debugdate debuginstall debugfsinfo debugpushkey debugwireargs"
5940 " debugknown debuggetbundle debugbundle")
5961 " debugknown debuggetbundle debugbundle")
5941 optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
5962 optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
5942 " debugdata debugindex debugindexdot debugrevlog")
5963 " debugdata debugindex debugindexdot debugrevlog")
5943 inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
5964 inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
5944 " remove resolve status debugwalk")
5965 " remove resolve status debugwalk")
@@ -1,1931 +1,1928 b''
1 # patch.py - patch file parsing routines
1 # patch.py - patch file parsing routines
2 #
2 #
3 # Copyright 2006 Brendan Cully <brendan@kublai.com>
3 # Copyright 2006 Brendan Cully <brendan@kublai.com>
4 # Copyright 2007 Chris Mason <chris.mason@oracle.com>
4 # Copyright 2007 Chris Mason <chris.mason@oracle.com>
5 #
5 #
6 # This software may be used and distributed according to the terms of the
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9 import cStringIO, email, os, errno, re, posixpath
9 import cStringIO, email, os, errno, re, posixpath
10 import tempfile, zlib, shutil
10 import tempfile, zlib, shutil
11 # On python2.4 you have to import these by name or they fail to
11 # On python2.4 you have to import these by name or they fail to
12 # load. This was not a problem on Python 2.7.
12 # load. This was not a problem on Python 2.7.
13 import email.Generator
13 import email.Generator
14 import email.Parser
14 import email.Parser
15
15
16 from i18n import _
16 from i18n import _
17 from node import hex, short
17 from node import hex, short
18 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
18 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error
19
19
20 gitre = re.compile('diff --git a/(.*) b/(.*)')
20 gitre = re.compile('diff --git a/(.*) b/(.*)')
21
21
22 class PatchError(Exception):
22 class PatchError(Exception):
23 pass
23 pass
24
24
25
25
26 # public functions
26 # public functions
27
27
28 def split(stream):
28 def split(stream):
29 '''return an iterator of individual patches from a stream'''
29 '''return an iterator of individual patches from a stream'''
30 def isheader(line, inheader):
30 def isheader(line, inheader):
31 if inheader and line[0] in (' ', '\t'):
31 if inheader and line[0] in (' ', '\t'):
32 # continuation
32 # continuation
33 return True
33 return True
34 if line[0] in (' ', '-', '+'):
34 if line[0] in (' ', '-', '+'):
35 # diff line - don't check for header pattern in there
35 # diff line - don't check for header pattern in there
36 return False
36 return False
37 l = line.split(': ', 1)
37 l = line.split(': ', 1)
38 return len(l) == 2 and ' ' not in l[0]
38 return len(l) == 2 and ' ' not in l[0]
39
39
40 def chunk(lines):
40 def chunk(lines):
41 return cStringIO.StringIO(''.join(lines))
41 return cStringIO.StringIO(''.join(lines))
42
42
43 def hgsplit(stream, cur):
43 def hgsplit(stream, cur):
44 inheader = True
44 inheader = True
45
45
46 for line in stream:
46 for line in stream:
47 if not line.strip():
47 if not line.strip():
48 inheader = False
48 inheader = False
49 if not inheader and line.startswith('# HG changeset patch'):
49 if not inheader and line.startswith('# HG changeset patch'):
50 yield chunk(cur)
50 yield chunk(cur)
51 cur = []
51 cur = []
52 inheader = True
52 inheader = True
53
53
54 cur.append(line)
54 cur.append(line)
55
55
56 if cur:
56 if cur:
57 yield chunk(cur)
57 yield chunk(cur)
58
58
59 def mboxsplit(stream, cur):
59 def mboxsplit(stream, cur):
60 for line in stream:
60 for line in stream:
61 if line.startswith('From '):
61 if line.startswith('From '):
62 for c in split(chunk(cur[1:])):
62 for c in split(chunk(cur[1:])):
63 yield c
63 yield c
64 cur = []
64 cur = []
65
65
66 cur.append(line)
66 cur.append(line)
67
67
68 if cur:
68 if cur:
69 for c in split(chunk(cur[1:])):
69 for c in split(chunk(cur[1:])):
70 yield c
70 yield c
71
71
72 def mimesplit(stream, cur):
72 def mimesplit(stream, cur):
73 def msgfp(m):
73 def msgfp(m):
74 fp = cStringIO.StringIO()
74 fp = cStringIO.StringIO()
75 g = email.Generator.Generator(fp, mangle_from_=False)
75 g = email.Generator.Generator(fp, mangle_from_=False)
76 g.flatten(m)
76 g.flatten(m)
77 fp.seek(0)
77 fp.seek(0)
78 return fp
78 return fp
79
79
80 for line in stream:
80 for line in stream:
81 cur.append(line)
81 cur.append(line)
82 c = chunk(cur)
82 c = chunk(cur)
83
83
84 m = email.Parser.Parser().parse(c)
84 m = email.Parser.Parser().parse(c)
85 if not m.is_multipart():
85 if not m.is_multipart():
86 yield msgfp(m)
86 yield msgfp(m)
87 else:
87 else:
88 ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
88 ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
89 for part in m.walk():
89 for part in m.walk():
90 ct = part.get_content_type()
90 ct = part.get_content_type()
91 if ct not in ok_types:
91 if ct not in ok_types:
92 continue
92 continue
93 yield msgfp(part)
93 yield msgfp(part)
94
94
95 def headersplit(stream, cur):
95 def headersplit(stream, cur):
96 inheader = False
96 inheader = False
97
97
98 for line in stream:
98 for line in stream:
99 if not inheader and isheader(line, inheader):
99 if not inheader and isheader(line, inheader):
100 yield chunk(cur)
100 yield chunk(cur)
101 cur = []
101 cur = []
102 inheader = True
102 inheader = True
103 if inheader and not isheader(line, inheader):
103 if inheader and not isheader(line, inheader):
104 inheader = False
104 inheader = False
105
105
106 cur.append(line)
106 cur.append(line)
107
107
108 if cur:
108 if cur:
109 yield chunk(cur)
109 yield chunk(cur)
110
110
111 def remainder(cur):
111 def remainder(cur):
112 yield chunk(cur)
112 yield chunk(cur)
113
113
114 class fiter(object):
114 class fiter(object):
115 def __init__(self, fp):
115 def __init__(self, fp):
116 self.fp = fp
116 self.fp = fp
117
117
118 def __iter__(self):
118 def __iter__(self):
119 return self
119 return self
120
120
121 def next(self):
121 def next(self):
122 l = self.fp.readline()
122 l = self.fp.readline()
123 if not l:
123 if not l:
124 raise StopIteration
124 raise StopIteration
125 return l
125 return l
126
126
127 inheader = False
127 inheader = False
128 cur = []
128 cur = []
129
129
130 mimeheaders = ['content-type']
130 mimeheaders = ['content-type']
131
131
132 if not util.safehasattr(stream, 'next'):
132 if not util.safehasattr(stream, 'next'):
133 # http responses, for example, have readline but not next
133 # http responses, for example, have readline but not next
134 stream = fiter(stream)
134 stream = fiter(stream)
135
135
136 for line in stream:
136 for line in stream:
137 cur.append(line)
137 cur.append(line)
138 if line.startswith('# HG changeset patch'):
138 if line.startswith('# HG changeset patch'):
139 return hgsplit(stream, cur)
139 return hgsplit(stream, cur)
140 elif line.startswith('From '):
140 elif line.startswith('From '):
141 return mboxsplit(stream, cur)
141 return mboxsplit(stream, cur)
142 elif isheader(line, inheader):
142 elif isheader(line, inheader):
143 inheader = True
143 inheader = True
144 if line.split(':', 1)[0].lower() in mimeheaders:
144 if line.split(':', 1)[0].lower() in mimeheaders:
145 # let email parser handle this
145 # let email parser handle this
146 return mimesplit(stream, cur)
146 return mimesplit(stream, cur)
147 elif line.startswith('--- ') and inheader:
147 elif line.startswith('--- ') and inheader:
148 # No evil headers seen by diff start, split by hand
148 # No evil headers seen by diff start, split by hand
149 return headersplit(stream, cur)
149 return headersplit(stream, cur)
150 # Not enough info, keep reading
150 # Not enough info, keep reading
151
151
152 # if we are here, we have a very plain patch
152 # if we are here, we have a very plain patch
153 return remainder(cur)
153 return remainder(cur)
154
154
155 def extract(ui, fileobj):
155 def extract(ui, fileobj):
156 '''extract patch from data read from fileobj.
156 '''extract patch from data read from fileobj.
157
157
158 patch can be a normal patch or contained in an email message.
158 patch can be a normal patch or contained in an email message.
159
159
160 return tuple (filename, message, user, date, branch, node, p1, p2).
160 return tuple (filename, message, user, date, branch, node, p1, p2).
161 Any item in the returned tuple can be None. If filename is None,
161 Any item in the returned tuple can be None. If filename is None,
162 fileobj did not contain a patch. Caller must unlink filename when done.'''
162 fileobj did not contain a patch. Caller must unlink filename when done.'''
163
163
164 # attempt to detect the start of a patch
164 # attempt to detect the start of a patch
165 # (this heuristic is borrowed from quilt)
165 # (this heuristic is borrowed from quilt)
166 diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |'
166 diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |'
167 r'retrieving revision [0-9]+(\.[0-9]+)*$|'
167 r'retrieving revision [0-9]+(\.[0-9]+)*$|'
168 r'---[ \t].*?^\+\+\+[ \t]|'
168 r'---[ \t].*?^\+\+\+[ \t]|'
169 r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL)
169 r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL)
170
170
171 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
171 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
172 tmpfp = os.fdopen(fd, 'w')
172 tmpfp = os.fdopen(fd, 'w')
173 try:
173 try:
174 msg = email.Parser.Parser().parse(fileobj)
174 msg = email.Parser.Parser().parse(fileobj)
175
175
176 subject = msg['Subject']
176 subject = msg['Subject']
177 user = msg['From']
177 user = msg['From']
178 if not subject and not user:
178 if not subject and not user:
179 # Not an email, restore parsed headers if any
179 # Not an email, restore parsed headers if any
180 subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n'
180 subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n'
181
181
182 # should try to parse msg['Date']
182 # should try to parse msg['Date']
183 date = None
183 date = None
184 nodeid = None
184 nodeid = None
185 branch = None
185 branch = None
186 parents = []
186 parents = []
187
187
188 if subject:
188 if subject:
189 if subject.startswith('[PATCH'):
189 if subject.startswith('[PATCH'):
190 pend = subject.find(']')
190 pend = subject.find(']')
191 if pend >= 0:
191 if pend >= 0:
192 subject = subject[pend + 1:].lstrip()
192 subject = subject[pend + 1:].lstrip()
193 subject = re.sub(r'\n[ \t]+', ' ', subject)
193 subject = re.sub(r'\n[ \t]+', ' ', subject)
194 ui.debug('Subject: %s\n' % subject)
194 ui.debug('Subject: %s\n' % subject)
195 if user:
195 if user:
196 ui.debug('From: %s\n' % user)
196 ui.debug('From: %s\n' % user)
197 diffs_seen = 0
197 diffs_seen = 0
198 ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
198 ok_types = ('text/plain', 'text/x-diff', 'text/x-patch')
199 message = ''
199 message = ''
200 for part in msg.walk():
200 for part in msg.walk():
201 content_type = part.get_content_type()
201 content_type = part.get_content_type()
202 ui.debug('Content-Type: %s\n' % content_type)
202 ui.debug('Content-Type: %s\n' % content_type)
203 if content_type not in ok_types:
203 if content_type not in ok_types:
204 continue
204 continue
205 payload = part.get_payload(decode=True)
205 payload = part.get_payload(decode=True)
206 m = diffre.search(payload)
206 m = diffre.search(payload)
207 if m:
207 if m:
208 hgpatch = False
208 hgpatch = False
209 hgpatchheader = False
209 hgpatchheader = False
210 ignoretext = False
210 ignoretext = False
211
211
212 ui.debug('found patch at byte %d\n' % m.start(0))
212 ui.debug('found patch at byte %d\n' % m.start(0))
213 diffs_seen += 1
213 diffs_seen += 1
214 cfp = cStringIO.StringIO()
214 cfp = cStringIO.StringIO()
215 for line in payload[:m.start(0)].splitlines():
215 for line in payload[:m.start(0)].splitlines():
216 if line.startswith('# HG changeset patch') and not hgpatch:
216 if line.startswith('# HG changeset patch') and not hgpatch:
217 ui.debug('patch generated by hg export\n')
217 ui.debug('patch generated by hg export\n')
218 hgpatch = True
218 hgpatch = True
219 hgpatchheader = True
219 hgpatchheader = True
220 # drop earlier commit message content
220 # drop earlier commit message content
221 cfp.seek(0)
221 cfp.seek(0)
222 cfp.truncate()
222 cfp.truncate()
223 subject = None
223 subject = None
224 elif hgpatchheader:
224 elif hgpatchheader:
225 if line.startswith('# User '):
225 if line.startswith('# User '):
226 user = line[7:]
226 user = line[7:]
227 ui.debug('From: %s\n' % user)
227 ui.debug('From: %s\n' % user)
228 elif line.startswith("# Date "):
228 elif line.startswith("# Date "):
229 date = line[7:]
229 date = line[7:]
230 elif line.startswith("# Branch "):
230 elif line.startswith("# Branch "):
231 branch = line[9:]
231 branch = line[9:]
232 elif line.startswith("# Node ID "):
232 elif line.startswith("# Node ID "):
233 nodeid = line[10:]
233 nodeid = line[10:]
234 elif line.startswith("# Parent "):
234 elif line.startswith("# Parent "):
235 parents.append(line[9:].lstrip())
235 parents.append(line[9:].lstrip())
236 elif not line.startswith("# "):
236 elif not line.startswith("# "):
237 hgpatchheader = False
237 hgpatchheader = False
238 elif line == '---':
238 elif line == '---':
239 ignoretext = True
239 ignoretext = True
240 if not hgpatchheader and not ignoretext:
240 if not hgpatchheader and not ignoretext:
241 cfp.write(line)
241 cfp.write(line)
242 cfp.write('\n')
242 cfp.write('\n')
243 message = cfp.getvalue()
243 message = cfp.getvalue()
244 if tmpfp:
244 if tmpfp:
245 tmpfp.write(payload)
245 tmpfp.write(payload)
246 if not payload.endswith('\n'):
246 if not payload.endswith('\n'):
247 tmpfp.write('\n')
247 tmpfp.write('\n')
248 elif not diffs_seen and message and content_type == 'text/plain':
248 elif not diffs_seen and message and content_type == 'text/plain':
249 message += '\n' + payload
249 message += '\n' + payload
250 except: # re-raises
250 except: # re-raises
251 tmpfp.close()
251 tmpfp.close()
252 os.unlink(tmpname)
252 os.unlink(tmpname)
253 raise
253 raise
254
254
255 if subject and not message.startswith(subject):
255 if subject and not message.startswith(subject):
256 message = '%s\n%s' % (subject, message)
256 message = '%s\n%s' % (subject, message)
257 tmpfp.close()
257 tmpfp.close()
258 if not diffs_seen:
258 if not diffs_seen:
259 os.unlink(tmpname)
259 os.unlink(tmpname)
260 return None, message, user, date, branch, None, None, None
260 return None, message, user, date, branch, None, None, None
261 p1 = parents and parents.pop(0) or None
261 p1 = parents and parents.pop(0) or None
262 p2 = parents and parents.pop(0) or None
262 p2 = parents and parents.pop(0) or None
263 return tmpname, message, user, date, branch, nodeid, p1, p2
263 return tmpname, message, user, date, branch, nodeid, p1, p2
264
264
265 class patchmeta(object):
265 class patchmeta(object):
266 """Patched file metadata
266 """Patched file metadata
267
267
268 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY
268 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY
269 or COPY. 'path' is patched file path. 'oldpath' is set to the
269 or COPY. 'path' is patched file path. 'oldpath' is set to the
270 origin file when 'op' is either COPY or RENAME, None otherwise. If
270 origin file when 'op' is either COPY or RENAME, None otherwise. If
271 file mode is changed, 'mode' is a tuple (islink, isexec) where
271 file mode is changed, 'mode' is a tuple (islink, isexec) where
272 'islink' is True if the file is a symlink and 'isexec' is True if
272 'islink' is True if the file is a symlink and 'isexec' is True if
273 the file is executable. Otherwise, 'mode' is None.
273 the file is executable. Otherwise, 'mode' is None.
274 """
274 """
275 def __init__(self, path):
275 def __init__(self, path):
276 self.path = path
276 self.path = path
277 self.oldpath = None
277 self.oldpath = None
278 self.mode = None
278 self.mode = None
279 self.op = 'MODIFY'
279 self.op = 'MODIFY'
280 self.binary = False
280 self.binary = False
281
281
282 def setmode(self, mode):
282 def setmode(self, mode):
283 islink = mode & 020000
283 islink = mode & 020000
284 isexec = mode & 0100
284 isexec = mode & 0100
285 self.mode = (islink, isexec)
285 self.mode = (islink, isexec)
286
286
287 def copy(self):
287 def copy(self):
288 other = patchmeta(self.path)
288 other = patchmeta(self.path)
289 other.oldpath = self.oldpath
289 other.oldpath = self.oldpath
290 other.mode = self.mode
290 other.mode = self.mode
291 other.op = self.op
291 other.op = self.op
292 other.binary = self.binary
292 other.binary = self.binary
293 return other
293 return other
294
294
295 def _ispatchinga(self, afile):
295 def _ispatchinga(self, afile):
296 if afile == '/dev/null':
296 if afile == '/dev/null':
297 return self.op == 'ADD'
297 return self.op == 'ADD'
298 return afile == 'a/' + (self.oldpath or self.path)
298 return afile == 'a/' + (self.oldpath or self.path)
299
299
300 def _ispatchingb(self, bfile):
300 def _ispatchingb(self, bfile):
301 if bfile == '/dev/null':
301 if bfile == '/dev/null':
302 return self.op == 'DELETE'
302 return self.op == 'DELETE'
303 return bfile == 'b/' + self.path
303 return bfile == 'b/' + self.path
304
304
305 def ispatching(self, afile, bfile):
305 def ispatching(self, afile, bfile):
306 return self._ispatchinga(afile) and self._ispatchingb(bfile)
306 return self._ispatchinga(afile) and self._ispatchingb(bfile)
307
307
308 def __repr__(self):
308 def __repr__(self):
309 return "<patchmeta %s %r>" % (self.op, self.path)
309 return "<patchmeta %s %r>" % (self.op, self.path)
310
310
311 def readgitpatch(lr):
311 def readgitpatch(lr):
312 """extract git-style metadata about patches from <patchname>"""
312 """extract git-style metadata about patches from <patchname>"""
313
313
314 # Filter patch for git information
314 # Filter patch for git information
315 gp = None
315 gp = None
316 gitpatches = []
316 gitpatches = []
317 for line in lr:
317 for line in lr:
318 line = line.rstrip(' \r\n')
318 line = line.rstrip(' \r\n')
319 if line.startswith('diff --git a/'):
319 if line.startswith('diff --git a/'):
320 m = gitre.match(line)
320 m = gitre.match(line)
321 if m:
321 if m:
322 if gp:
322 if gp:
323 gitpatches.append(gp)
323 gitpatches.append(gp)
324 dst = m.group(2)
324 dst = m.group(2)
325 gp = patchmeta(dst)
325 gp = patchmeta(dst)
326 elif gp:
326 elif gp:
327 if line.startswith('--- '):
327 if line.startswith('--- '):
328 gitpatches.append(gp)
328 gitpatches.append(gp)
329 gp = None
329 gp = None
330 continue
330 continue
331 if line.startswith('rename from '):
331 if line.startswith('rename from '):
332 gp.op = 'RENAME'
332 gp.op = 'RENAME'
333 gp.oldpath = line[12:]
333 gp.oldpath = line[12:]
334 elif line.startswith('rename to '):
334 elif line.startswith('rename to '):
335 gp.path = line[10:]
335 gp.path = line[10:]
336 elif line.startswith('copy from '):
336 elif line.startswith('copy from '):
337 gp.op = 'COPY'
337 gp.op = 'COPY'
338 gp.oldpath = line[10:]
338 gp.oldpath = line[10:]
339 elif line.startswith('copy to '):
339 elif line.startswith('copy to '):
340 gp.path = line[8:]
340 gp.path = line[8:]
341 elif line.startswith('deleted file'):
341 elif line.startswith('deleted file'):
342 gp.op = 'DELETE'
342 gp.op = 'DELETE'
343 elif line.startswith('new file mode '):
343 elif line.startswith('new file mode '):
344 gp.op = 'ADD'
344 gp.op = 'ADD'
345 gp.setmode(int(line[-6:], 8))
345 gp.setmode(int(line[-6:], 8))
346 elif line.startswith('new mode '):
346 elif line.startswith('new mode '):
347 gp.setmode(int(line[-6:], 8))
347 gp.setmode(int(line[-6:], 8))
348 elif line.startswith('GIT binary patch'):
348 elif line.startswith('GIT binary patch'):
349 gp.binary = True
349 gp.binary = True
350 if gp:
350 if gp:
351 gitpatches.append(gp)
351 gitpatches.append(gp)
352
352
353 return gitpatches
353 return gitpatches
354
354
355 class linereader(object):
355 class linereader(object):
356 # simple class to allow pushing lines back into the input stream
356 # simple class to allow pushing lines back into the input stream
357 def __init__(self, fp):
357 def __init__(self, fp):
358 self.fp = fp
358 self.fp = fp
359 self.buf = []
359 self.buf = []
360
360
361 def push(self, line):
361 def push(self, line):
362 if line is not None:
362 if line is not None:
363 self.buf.append(line)
363 self.buf.append(line)
364
364
365 def readline(self):
365 def readline(self):
366 if self.buf:
366 if self.buf:
367 l = self.buf[0]
367 l = self.buf[0]
368 del self.buf[0]
368 del self.buf[0]
369 return l
369 return l
370 return self.fp.readline()
370 return self.fp.readline()
371
371
372 def __iter__(self):
372 def __iter__(self):
373 while True:
373 while True:
374 l = self.readline()
374 l = self.readline()
375 if not l:
375 if not l:
376 break
376 break
377 yield l
377 yield l
378
378
379 class abstractbackend(object):
379 class abstractbackend(object):
380 def __init__(self, ui):
380 def __init__(self, ui):
381 self.ui = ui
381 self.ui = ui
382
382
383 def getfile(self, fname):
383 def getfile(self, fname):
384 """Return target file data and flags as a (data, (islink,
384 """Return target file data and flags as a (data, (islink,
385 isexec)) tuple.
385 isexec)) tuple.
386 """
386 """
387 raise NotImplementedError
387 raise NotImplementedError
388
388
389 def setfile(self, fname, data, mode, copysource):
389 def setfile(self, fname, data, mode, copysource):
390 """Write data to target file fname and set its mode. mode is a
390 """Write data to target file fname and set its mode. mode is a
391 (islink, isexec) tuple. If data is None, the file content should
391 (islink, isexec) tuple. If data is None, the file content should
392 be left unchanged. If the file is modified after being copied,
392 be left unchanged. If the file is modified after being copied,
393 copysource is set to the original file name.
393 copysource is set to the original file name.
394 """
394 """
395 raise NotImplementedError
395 raise NotImplementedError
396
396
397 def unlink(self, fname):
397 def unlink(self, fname):
398 """Unlink target file."""
398 """Unlink target file."""
399 raise NotImplementedError
399 raise NotImplementedError
400
400
401 def writerej(self, fname, failed, total, lines):
401 def writerej(self, fname, failed, total, lines):
402 """Write rejected lines for fname. total is the number of hunks
402 """Write rejected lines for fname. total is the number of hunks
403 which failed to apply and total the total number of hunks for this
403 which failed to apply and total the total number of hunks for this
404 files.
404 files.
405 """
405 """
406 pass
406 pass
407
407
408 def exists(self, fname):
408 def exists(self, fname):
409 raise NotImplementedError
409 raise NotImplementedError
410
410
411 class fsbackend(abstractbackend):
411 class fsbackend(abstractbackend):
412 def __init__(self, ui, basedir):
412 def __init__(self, ui, basedir):
413 super(fsbackend, self).__init__(ui)
413 super(fsbackend, self).__init__(ui)
414 self.opener = scmutil.opener(basedir)
414 self.opener = scmutil.opener(basedir)
415
415
416 def _join(self, f):
416 def _join(self, f):
417 return os.path.join(self.opener.base, f)
417 return os.path.join(self.opener.base, f)
418
418
419 def getfile(self, fname):
419 def getfile(self, fname):
420 path = self._join(fname)
420 path = self._join(fname)
421 if os.path.islink(path):
421 if os.path.islink(path):
422 return (os.readlink(path), (True, False))
422 return (os.readlink(path), (True, False))
423 isexec = False
423 isexec = False
424 try:
424 try:
425 isexec = os.lstat(path).st_mode & 0100 != 0
425 isexec = os.lstat(path).st_mode & 0100 != 0
426 except OSError, e:
426 except OSError, e:
427 if e.errno != errno.ENOENT:
427 if e.errno != errno.ENOENT:
428 raise
428 raise
429 return (self.opener.read(fname), (False, isexec))
429 return (self.opener.read(fname), (False, isexec))
430
430
431 def setfile(self, fname, data, mode, copysource):
431 def setfile(self, fname, data, mode, copysource):
432 islink, isexec = mode
432 islink, isexec = mode
433 if data is None:
433 if data is None:
434 util.setflags(self._join(fname), islink, isexec)
434 util.setflags(self._join(fname), islink, isexec)
435 return
435 return
436 if islink:
436 if islink:
437 self.opener.symlink(data, fname)
437 self.opener.symlink(data, fname)
438 else:
438 else:
439 self.opener.write(fname, data)
439 self.opener.write(fname, data)
440 if isexec:
440 if isexec:
441 util.setflags(self._join(fname), False, True)
441 util.setflags(self._join(fname), False, True)
442
442
443 def unlink(self, fname):
443 def unlink(self, fname):
444 util.unlinkpath(self._join(fname), ignoremissing=True)
444 util.unlinkpath(self._join(fname), ignoremissing=True)
445
445
446 def writerej(self, fname, failed, total, lines):
446 def writerej(self, fname, failed, total, lines):
447 fname = fname + ".rej"
447 fname = fname + ".rej"
448 self.ui.warn(
448 self.ui.warn(
449 _("%d out of %d hunks FAILED -- saving rejects to file %s\n") %
449 _("%d out of %d hunks FAILED -- saving rejects to file %s\n") %
450 (failed, total, fname))
450 (failed, total, fname))
451 fp = self.opener(fname, 'w')
451 fp = self.opener(fname, 'w')
452 fp.writelines(lines)
452 fp.writelines(lines)
453 fp.close()
453 fp.close()
454
454
455 def exists(self, fname):
455 def exists(self, fname):
456 return os.path.lexists(self._join(fname))
456 return os.path.lexists(self._join(fname))
457
457
458 class workingbackend(fsbackend):
458 class workingbackend(fsbackend):
459 def __init__(self, ui, repo, similarity):
459 def __init__(self, ui, repo, similarity):
460 super(workingbackend, self).__init__(ui, repo.root)
460 super(workingbackend, self).__init__(ui, repo.root)
461 self.repo = repo
461 self.repo = repo
462 self.similarity = similarity
462 self.similarity = similarity
463 self.removed = set()
463 self.removed = set()
464 self.changed = set()
464 self.changed = set()
465 self.copied = []
465 self.copied = []
466
466
467 def _checkknown(self, fname):
467 def _checkknown(self, fname):
468 if self.repo.dirstate[fname] == '?' and self.exists(fname):
468 if self.repo.dirstate[fname] == '?' and self.exists(fname):
469 raise PatchError(_('cannot patch %s: file is not tracked') % fname)
469 raise PatchError(_('cannot patch %s: file is not tracked') % fname)
470
470
471 def setfile(self, fname, data, mode, copysource):
471 def setfile(self, fname, data, mode, copysource):
472 self._checkknown(fname)
472 self._checkknown(fname)
473 super(workingbackend, self).setfile(fname, data, mode, copysource)
473 super(workingbackend, self).setfile(fname, data, mode, copysource)
474 if copysource is not None:
474 if copysource is not None:
475 self.copied.append((copysource, fname))
475 self.copied.append((copysource, fname))
476 self.changed.add(fname)
476 self.changed.add(fname)
477
477
478 def unlink(self, fname):
478 def unlink(self, fname):
479 self._checkknown(fname)
479 self._checkknown(fname)
480 super(workingbackend, self).unlink(fname)
480 super(workingbackend, self).unlink(fname)
481 self.removed.add(fname)
481 self.removed.add(fname)
482 self.changed.add(fname)
482 self.changed.add(fname)
483
483
484 def close(self):
484 def close(self):
485 wctx = self.repo[None]
485 wctx = self.repo[None]
486 changed = set(self.changed)
486 changed = set(self.changed)
487 for src, dst in self.copied:
487 for src, dst in self.copied:
488 scmutil.dirstatecopy(self.ui, self.repo, wctx, src, dst)
488 scmutil.dirstatecopy(self.ui, self.repo, wctx, src, dst)
489 if self.removed:
489 if self.removed:
490 wctx.forget(sorted(self.removed))
490 wctx.forget(sorted(self.removed))
491 for f in self.removed:
491 for f in self.removed:
492 if f not in self.repo.dirstate:
492 if f not in self.repo.dirstate:
493 # File was deleted and no longer belongs to the
493 # File was deleted and no longer belongs to the
494 # dirstate, it was probably marked added then
494 # dirstate, it was probably marked added then
495 # deleted, and should not be considered by
495 # deleted, and should not be considered by
496 # marktouched().
496 # marktouched().
497 changed.discard(f)
497 changed.discard(f)
498 if changed:
498 if changed:
499 scmutil.marktouched(self.repo, changed, self.similarity)
499 scmutil.marktouched(self.repo, changed, self.similarity)
500 return sorted(self.changed)
500 return sorted(self.changed)
501
501
502 class filestore(object):
502 class filestore(object):
503 def __init__(self, maxsize=None):
503 def __init__(self, maxsize=None):
504 self.opener = None
504 self.opener = None
505 self.files = {}
505 self.files = {}
506 self.created = 0
506 self.created = 0
507 self.maxsize = maxsize
507 self.maxsize = maxsize
508 if self.maxsize is None:
508 if self.maxsize is None:
509 self.maxsize = 4*(2**20)
509 self.maxsize = 4*(2**20)
510 self.size = 0
510 self.size = 0
511 self.data = {}
511 self.data = {}
512
512
513 def setfile(self, fname, data, mode, copied=None):
513 def setfile(self, fname, data, mode, copied=None):
514 if self.maxsize < 0 or (len(data) + self.size) <= self.maxsize:
514 if self.maxsize < 0 or (len(data) + self.size) <= self.maxsize:
515 self.data[fname] = (data, mode, copied)
515 self.data[fname] = (data, mode, copied)
516 self.size += len(data)
516 self.size += len(data)
517 else:
517 else:
518 if self.opener is None:
518 if self.opener is None:
519 root = tempfile.mkdtemp(prefix='hg-patch-')
519 root = tempfile.mkdtemp(prefix='hg-patch-')
520 self.opener = scmutil.opener(root)
520 self.opener = scmutil.opener(root)
521 # Avoid filename issues with these simple names
521 # Avoid filename issues with these simple names
522 fn = str(self.created)
522 fn = str(self.created)
523 self.opener.write(fn, data)
523 self.opener.write(fn, data)
524 self.created += 1
524 self.created += 1
525 self.files[fname] = (fn, mode, copied)
525 self.files[fname] = (fn, mode, copied)
526
526
527 def getfile(self, fname):
527 def getfile(self, fname):
528 if fname in self.data:
528 if fname in self.data:
529 return self.data[fname]
529 return self.data[fname]
530 if not self.opener or fname not in self.files:
530 if not self.opener or fname not in self.files:
531 raise IOError
531 raise IOError
532 fn, mode, copied = self.files[fname]
532 fn, mode, copied = self.files[fname]
533 return self.opener.read(fn), mode, copied
533 return self.opener.read(fn), mode, copied
534
534
535 def close(self):
535 def close(self):
536 if self.opener:
536 if self.opener:
537 shutil.rmtree(self.opener.base)
537 shutil.rmtree(self.opener.base)
538
538
539 class repobackend(abstractbackend):
539 class repobackend(abstractbackend):
540 def __init__(self, ui, repo, ctx, store):
540 def __init__(self, ui, repo, ctx, store):
541 super(repobackend, self).__init__(ui)
541 super(repobackend, self).__init__(ui)
542 self.repo = repo
542 self.repo = repo
543 self.ctx = ctx
543 self.ctx = ctx
544 self.store = store
544 self.store = store
545 self.changed = set()
545 self.changed = set()
546 self.removed = set()
546 self.removed = set()
547 self.copied = {}
547 self.copied = {}
548
548
549 def _checkknown(self, fname):
549 def _checkknown(self, fname):
550 if fname not in self.ctx:
550 if fname not in self.ctx:
551 raise PatchError(_('cannot patch %s: file is not tracked') % fname)
551 raise PatchError(_('cannot patch %s: file is not tracked') % fname)
552
552
553 def getfile(self, fname):
553 def getfile(self, fname):
554 try:
554 try:
555 fctx = self.ctx[fname]
555 fctx = self.ctx[fname]
556 except error.LookupError:
556 except error.LookupError:
557 raise IOError
557 raise IOError
558 flags = fctx.flags()
558 flags = fctx.flags()
559 return fctx.data(), ('l' in flags, 'x' in flags)
559 return fctx.data(), ('l' in flags, 'x' in flags)
560
560
561 def setfile(self, fname, data, mode, copysource):
561 def setfile(self, fname, data, mode, copysource):
562 if copysource:
562 if copysource:
563 self._checkknown(copysource)
563 self._checkknown(copysource)
564 if data is None:
564 if data is None:
565 data = self.ctx[fname].data()
565 data = self.ctx[fname].data()
566 self.store.setfile(fname, data, mode, copysource)
566 self.store.setfile(fname, data, mode, copysource)
567 self.changed.add(fname)
567 self.changed.add(fname)
568 if copysource:
568 if copysource:
569 self.copied[fname] = copysource
569 self.copied[fname] = copysource
570
570
571 def unlink(self, fname):
571 def unlink(self, fname):
572 self._checkknown(fname)
572 self._checkknown(fname)
573 self.removed.add(fname)
573 self.removed.add(fname)
574
574
575 def exists(self, fname):
575 def exists(self, fname):
576 return fname in self.ctx
576 return fname in self.ctx
577
577
578 def close(self):
578 def close(self):
579 return self.changed | self.removed
579 return self.changed | self.removed
580
580
581 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1
581 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1
582 unidesc = re.compile('@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@')
582 unidesc = re.compile('@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@')
583 contextdesc = re.compile('(?:---|\*\*\*) (\d+)(?:,(\d+))? (?:---|\*\*\*)')
583 contextdesc = re.compile('(?:---|\*\*\*) (\d+)(?:,(\d+))? (?:---|\*\*\*)')
584 eolmodes = ['strict', 'crlf', 'lf', 'auto']
584 eolmodes = ['strict', 'crlf', 'lf', 'auto']
585
585
586 class patchfile(object):
586 class patchfile(object):
587 def __init__(self, ui, gp, backend, store, eolmode='strict'):
587 def __init__(self, ui, gp, backend, store, eolmode='strict'):
588 self.fname = gp.path
588 self.fname = gp.path
589 self.eolmode = eolmode
589 self.eolmode = eolmode
590 self.eol = None
590 self.eol = None
591 self.backend = backend
591 self.backend = backend
592 self.ui = ui
592 self.ui = ui
593 self.lines = []
593 self.lines = []
594 self.exists = False
594 self.exists = False
595 self.missing = True
595 self.missing = True
596 self.mode = gp.mode
596 self.mode = gp.mode
597 self.copysource = gp.oldpath
597 self.copysource = gp.oldpath
598 self.create = gp.op in ('ADD', 'COPY', 'RENAME')
598 self.create = gp.op in ('ADD', 'COPY', 'RENAME')
599 self.remove = gp.op == 'DELETE'
599 self.remove = gp.op == 'DELETE'
600 try:
600 try:
601 if self.copysource is None:
601 if self.copysource is None:
602 data, mode = backend.getfile(self.fname)
602 data, mode = backend.getfile(self.fname)
603 self.exists = True
603 self.exists = True
604 else:
604 else:
605 data, mode = store.getfile(self.copysource)[:2]
605 data, mode = store.getfile(self.copysource)[:2]
606 self.exists = backend.exists(self.fname)
606 self.exists = backend.exists(self.fname)
607 self.missing = False
607 self.missing = False
608 if data:
608 if data:
609 self.lines = mdiff.splitnewlines(data)
609 self.lines = mdiff.splitnewlines(data)
610 if self.mode is None:
610 if self.mode is None:
611 self.mode = mode
611 self.mode = mode
612 if self.lines:
612 if self.lines:
613 # Normalize line endings
613 # Normalize line endings
614 if self.lines[0].endswith('\r\n'):
614 if self.lines[0].endswith('\r\n'):
615 self.eol = '\r\n'
615 self.eol = '\r\n'
616 elif self.lines[0].endswith('\n'):
616 elif self.lines[0].endswith('\n'):
617 self.eol = '\n'
617 self.eol = '\n'
618 if eolmode != 'strict':
618 if eolmode != 'strict':
619 nlines = []
619 nlines = []
620 for l in self.lines:
620 for l in self.lines:
621 if l.endswith('\r\n'):
621 if l.endswith('\r\n'):
622 l = l[:-2] + '\n'
622 l = l[:-2] + '\n'
623 nlines.append(l)
623 nlines.append(l)
624 self.lines = nlines
624 self.lines = nlines
625 except IOError:
625 except IOError:
626 if self.create:
626 if self.create:
627 self.missing = False
627 self.missing = False
628 if self.mode is None:
628 if self.mode is None:
629 self.mode = (False, False)
629 self.mode = (False, False)
630 if self.missing:
630 if self.missing:
631 self.ui.warn(_("unable to find '%s' for patching\n") % self.fname)
631 self.ui.warn(_("unable to find '%s' for patching\n") % self.fname)
632
632
633 self.hash = {}
633 self.hash = {}
634 self.dirty = 0
634 self.dirty = 0
635 self.offset = 0
635 self.offset = 0
636 self.skew = 0
636 self.skew = 0
637 self.rej = []
637 self.rej = []
638 self.fileprinted = False
638 self.fileprinted = False
639 self.printfile(False)
639 self.printfile(False)
640 self.hunks = 0
640 self.hunks = 0
641
641
642 def writelines(self, fname, lines, mode):
642 def writelines(self, fname, lines, mode):
643 if self.eolmode == 'auto':
643 if self.eolmode == 'auto':
644 eol = self.eol
644 eol = self.eol
645 elif self.eolmode == 'crlf':
645 elif self.eolmode == 'crlf':
646 eol = '\r\n'
646 eol = '\r\n'
647 else:
647 else:
648 eol = '\n'
648 eol = '\n'
649
649
650 if self.eolmode != 'strict' and eol and eol != '\n':
650 if self.eolmode != 'strict' and eol and eol != '\n':
651 rawlines = []
651 rawlines = []
652 for l in lines:
652 for l in lines:
653 if l and l[-1] == '\n':
653 if l and l[-1] == '\n':
654 l = l[:-1] + eol
654 l = l[:-1] + eol
655 rawlines.append(l)
655 rawlines.append(l)
656 lines = rawlines
656 lines = rawlines
657
657
658 self.backend.setfile(fname, ''.join(lines), mode, self.copysource)
658 self.backend.setfile(fname, ''.join(lines), mode, self.copysource)
659
659
660 def printfile(self, warn):
660 def printfile(self, warn):
661 if self.fileprinted:
661 if self.fileprinted:
662 return
662 return
663 if warn or self.ui.verbose:
663 if warn or self.ui.verbose:
664 self.fileprinted = True
664 self.fileprinted = True
665 s = _("patching file %s\n") % self.fname
665 s = _("patching file %s\n") % self.fname
666 if warn:
666 if warn:
667 self.ui.warn(s)
667 self.ui.warn(s)
668 else:
668 else:
669 self.ui.note(s)
669 self.ui.note(s)
670
670
671
671
672 def findlines(self, l, linenum):
672 def findlines(self, l, linenum):
673 # looks through the hash and finds candidate lines. The
673 # looks through the hash and finds candidate lines. The
674 # result is a list of line numbers sorted based on distance
674 # result is a list of line numbers sorted based on distance
675 # from linenum
675 # from linenum
676
676
677 cand = self.hash.get(l, [])
677 cand = self.hash.get(l, [])
678 if len(cand) > 1:
678 if len(cand) > 1:
679 # resort our list of potentials forward then back.
679 # resort our list of potentials forward then back.
680 cand.sort(key=lambda x: abs(x - linenum))
680 cand.sort(key=lambda x: abs(x - linenum))
681 return cand
681 return cand
682
682
683 def write_rej(self):
683 def write_rej(self):
684 # our rejects are a little different from patch(1). This always
684 # our rejects are a little different from patch(1). This always
685 # creates rejects in the same form as the original patch. A file
685 # creates rejects in the same form as the original patch. A file
686 # header is inserted so that you can run the reject through patch again
686 # header is inserted so that you can run the reject through patch again
687 # without having to type the filename.
687 # without having to type the filename.
688 if not self.rej:
688 if not self.rej:
689 return
689 return
690 base = os.path.basename(self.fname)
690 base = os.path.basename(self.fname)
691 lines = ["--- %s\n+++ %s\n" % (base, base)]
691 lines = ["--- %s\n+++ %s\n" % (base, base)]
692 for x in self.rej:
692 for x in self.rej:
693 for l in x.hunk:
693 for l in x.hunk:
694 lines.append(l)
694 lines.append(l)
695 if l[-1] != '\n':
695 if l[-1] != '\n':
696 lines.append("\n\ No newline at end of file\n")
696 lines.append("\n\ No newline at end of file\n")
697 self.backend.writerej(self.fname, len(self.rej), self.hunks, lines)
697 self.backend.writerej(self.fname, len(self.rej), self.hunks, lines)
698
698
699 def apply(self, h):
699 def apply(self, h):
700 if not h.complete():
700 if not h.complete():
701 raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") %
701 raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") %
702 (h.number, h.desc, len(h.a), h.lena, len(h.b),
702 (h.number, h.desc, len(h.a), h.lena, len(h.b),
703 h.lenb))
703 h.lenb))
704
704
705 self.hunks += 1
705 self.hunks += 1
706
706
707 if self.missing:
707 if self.missing:
708 self.rej.append(h)
708 self.rej.append(h)
709 return -1
709 return -1
710
710
711 if self.exists and self.create:
711 if self.exists and self.create:
712 if self.copysource:
712 if self.copysource:
713 self.ui.warn(_("cannot create %s: destination already "
713 self.ui.warn(_("cannot create %s: destination already "
714 "exists\n") % self.fname)
714 "exists\n") % self.fname)
715 else:
715 else:
716 self.ui.warn(_("file %s already exists\n") % self.fname)
716 self.ui.warn(_("file %s already exists\n") % self.fname)
717 self.rej.append(h)
717 self.rej.append(h)
718 return -1
718 return -1
719
719
720 if isinstance(h, binhunk):
720 if isinstance(h, binhunk):
721 if self.remove:
721 if self.remove:
722 self.backend.unlink(self.fname)
722 self.backend.unlink(self.fname)
723 else:
723 else:
724 l = h.new(self.lines)
724 l = h.new(self.lines)
725 self.lines[:] = l
725 self.lines[:] = l
726 self.offset += len(l)
726 self.offset += len(l)
727 self.dirty = True
727 self.dirty = True
728 return 0
728 return 0
729
729
730 horig = h
730 horig = h
731 if (self.eolmode in ('crlf', 'lf')
731 if (self.eolmode in ('crlf', 'lf')
732 or self.eolmode == 'auto' and self.eol):
732 or self.eolmode == 'auto' and self.eol):
733 # If new eols are going to be normalized, then normalize
733 # If new eols are going to be normalized, then normalize
734 # hunk data before patching. Otherwise, preserve input
734 # hunk data before patching. Otherwise, preserve input
735 # line-endings.
735 # line-endings.
736 h = h.getnormalized()
736 h = h.getnormalized()
737
737
738 # fast case first, no offsets, no fuzz
738 # fast case first, no offsets, no fuzz
739 old, oldstart, new, newstart = h.fuzzit(0, False)
739 old, oldstart, new, newstart = h.fuzzit(0, False)
740 oldstart += self.offset
740 oldstart += self.offset
741 orig_start = oldstart
741 orig_start = oldstart
742 # if there's skew we want to emit the "(offset %d lines)" even
742 # if there's skew we want to emit the "(offset %d lines)" even
743 # when the hunk cleanly applies at start + skew, so skip the
743 # when the hunk cleanly applies at start + skew, so skip the
744 # fast case code
744 # fast case code
745 if (self.skew == 0 and
745 if (self.skew == 0 and
746 diffhelpers.testhunk(old, self.lines, oldstart) == 0):
746 diffhelpers.testhunk(old, self.lines, oldstart) == 0):
747 if self.remove:
747 if self.remove:
748 self.backend.unlink(self.fname)
748 self.backend.unlink(self.fname)
749 else:
749 else:
750 self.lines[oldstart:oldstart + len(old)] = new
750 self.lines[oldstart:oldstart + len(old)] = new
751 self.offset += len(new) - len(old)
751 self.offset += len(new) - len(old)
752 self.dirty = True
752 self.dirty = True
753 return 0
753 return 0
754
754
755 # ok, we couldn't match the hunk. Lets look for offsets and fuzz it
755 # ok, we couldn't match the hunk. Lets look for offsets and fuzz it
756 self.hash = {}
756 self.hash = {}
757 for x, s in enumerate(self.lines):
757 for x, s in enumerate(self.lines):
758 self.hash.setdefault(s, []).append(x)
758 self.hash.setdefault(s, []).append(x)
759
759
760 for fuzzlen in xrange(3):
760 for fuzzlen in xrange(3):
761 for toponly in [True, False]:
761 for toponly in [True, False]:
762 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
762 old, oldstart, new, newstart = h.fuzzit(fuzzlen, toponly)
763 oldstart = oldstart + self.offset + self.skew
763 oldstart = oldstart + self.offset + self.skew
764 oldstart = min(oldstart, len(self.lines))
764 oldstart = min(oldstart, len(self.lines))
765 if old:
765 if old:
766 cand = self.findlines(old[0][1:], oldstart)
766 cand = self.findlines(old[0][1:], oldstart)
767 else:
767 else:
768 # Only adding lines with no or fuzzed context, just
768 # Only adding lines with no or fuzzed context, just
769 # take the skew in account
769 # take the skew in account
770 cand = [oldstart]
770 cand = [oldstart]
771
771
772 for l in cand:
772 for l in cand:
773 if not old or diffhelpers.testhunk(old, self.lines, l) == 0:
773 if not old or diffhelpers.testhunk(old, self.lines, l) == 0:
774 self.lines[l : l + len(old)] = new
774 self.lines[l : l + len(old)] = new
775 self.offset += len(new) - len(old)
775 self.offset += len(new) - len(old)
776 self.skew = l - orig_start
776 self.skew = l - orig_start
777 self.dirty = True
777 self.dirty = True
778 offset = l - orig_start - fuzzlen
778 offset = l - orig_start - fuzzlen
779 if fuzzlen:
779 if fuzzlen:
780 msg = _("Hunk #%d succeeded at %d "
780 msg = _("Hunk #%d succeeded at %d "
781 "with fuzz %d "
781 "with fuzz %d "
782 "(offset %d lines).\n")
782 "(offset %d lines).\n")
783 self.printfile(True)
783 self.printfile(True)
784 self.ui.warn(msg %
784 self.ui.warn(msg %
785 (h.number, l + 1, fuzzlen, offset))
785 (h.number, l + 1, fuzzlen, offset))
786 else:
786 else:
787 msg = _("Hunk #%d succeeded at %d "
787 msg = _("Hunk #%d succeeded at %d "
788 "(offset %d lines).\n")
788 "(offset %d lines).\n")
789 self.ui.note(msg % (h.number, l + 1, offset))
789 self.ui.note(msg % (h.number, l + 1, offset))
790 return fuzzlen
790 return fuzzlen
791 self.printfile(True)
791 self.printfile(True)
792 self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start))
792 self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start))
793 self.rej.append(horig)
793 self.rej.append(horig)
794 return -1
794 return -1
795
795
796 def close(self):
796 def close(self):
797 if self.dirty:
797 if self.dirty:
798 self.writelines(self.fname, self.lines, self.mode)
798 self.writelines(self.fname, self.lines, self.mode)
799 self.write_rej()
799 self.write_rej()
800 return len(self.rej)
800 return len(self.rej)
801
801
802 class hunk(object):
802 class hunk(object):
803 def __init__(self, desc, num, lr, context):
803 def __init__(self, desc, num, lr, context):
804 self.number = num
804 self.number = num
805 self.desc = desc
805 self.desc = desc
806 self.hunk = [desc]
806 self.hunk = [desc]
807 self.a = []
807 self.a = []
808 self.b = []
808 self.b = []
809 self.starta = self.lena = None
809 self.starta = self.lena = None
810 self.startb = self.lenb = None
810 self.startb = self.lenb = None
811 if lr is not None:
811 if lr is not None:
812 if context:
812 if context:
813 self.read_context_hunk(lr)
813 self.read_context_hunk(lr)
814 else:
814 else:
815 self.read_unified_hunk(lr)
815 self.read_unified_hunk(lr)
816
816
817 def getnormalized(self):
817 def getnormalized(self):
818 """Return a copy with line endings normalized to LF."""
818 """Return a copy with line endings normalized to LF."""
819
819
820 def normalize(lines):
820 def normalize(lines):
821 nlines = []
821 nlines = []
822 for line in lines:
822 for line in lines:
823 if line.endswith('\r\n'):
823 if line.endswith('\r\n'):
824 line = line[:-2] + '\n'
824 line = line[:-2] + '\n'
825 nlines.append(line)
825 nlines.append(line)
826 return nlines
826 return nlines
827
827
828 # Dummy object, it is rebuilt manually
828 # Dummy object, it is rebuilt manually
829 nh = hunk(self.desc, self.number, None, None)
829 nh = hunk(self.desc, self.number, None, None)
830 nh.number = self.number
830 nh.number = self.number
831 nh.desc = self.desc
831 nh.desc = self.desc
832 nh.hunk = self.hunk
832 nh.hunk = self.hunk
833 nh.a = normalize(self.a)
833 nh.a = normalize(self.a)
834 nh.b = normalize(self.b)
834 nh.b = normalize(self.b)
835 nh.starta = self.starta
835 nh.starta = self.starta
836 nh.startb = self.startb
836 nh.startb = self.startb
837 nh.lena = self.lena
837 nh.lena = self.lena
838 nh.lenb = self.lenb
838 nh.lenb = self.lenb
839 return nh
839 return nh
840
840
841 def read_unified_hunk(self, lr):
841 def read_unified_hunk(self, lr):
842 m = unidesc.match(self.desc)
842 m = unidesc.match(self.desc)
843 if not m:
843 if not m:
844 raise PatchError(_("bad hunk #%d") % self.number)
844 raise PatchError(_("bad hunk #%d") % self.number)
845 self.starta, self.lena, self.startb, self.lenb = m.groups()
845 self.starta, self.lena, self.startb, self.lenb = m.groups()
846 if self.lena is None:
846 if self.lena is None:
847 self.lena = 1
847 self.lena = 1
848 else:
848 else:
849 self.lena = int(self.lena)
849 self.lena = int(self.lena)
850 if self.lenb is None:
850 if self.lenb is None:
851 self.lenb = 1
851 self.lenb = 1
852 else:
852 else:
853 self.lenb = int(self.lenb)
853 self.lenb = int(self.lenb)
854 self.starta = int(self.starta)
854 self.starta = int(self.starta)
855 self.startb = int(self.startb)
855 self.startb = int(self.startb)
856 diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a,
856 diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a,
857 self.b)
857 self.b)
858 # if we hit eof before finishing out the hunk, the last line will
858 # if we hit eof before finishing out the hunk, the last line will
859 # be zero length. Lets try to fix it up.
859 # be zero length. Lets try to fix it up.
860 while len(self.hunk[-1]) == 0:
860 while len(self.hunk[-1]) == 0:
861 del self.hunk[-1]
861 del self.hunk[-1]
862 del self.a[-1]
862 del self.a[-1]
863 del self.b[-1]
863 del self.b[-1]
864 self.lena -= 1
864 self.lena -= 1
865 self.lenb -= 1
865 self.lenb -= 1
866 self._fixnewline(lr)
866 self._fixnewline(lr)
867
867
868 def read_context_hunk(self, lr):
868 def read_context_hunk(self, lr):
869 self.desc = lr.readline()
869 self.desc = lr.readline()
870 m = contextdesc.match(self.desc)
870 m = contextdesc.match(self.desc)
871 if not m:
871 if not m:
872 raise PatchError(_("bad hunk #%d") % self.number)
872 raise PatchError(_("bad hunk #%d") % self.number)
873 self.starta, aend = m.groups()
873 self.starta, aend = m.groups()
874 self.starta = int(self.starta)
874 self.starta = int(self.starta)
875 if aend is None:
875 if aend is None:
876 aend = self.starta
876 aend = self.starta
877 self.lena = int(aend) - self.starta
877 self.lena = int(aend) - self.starta
878 if self.starta:
878 if self.starta:
879 self.lena += 1
879 self.lena += 1
880 for x in xrange(self.lena):
880 for x in xrange(self.lena):
881 l = lr.readline()
881 l = lr.readline()
882 if l.startswith('---'):
882 if l.startswith('---'):
883 # lines addition, old block is empty
883 # lines addition, old block is empty
884 lr.push(l)
884 lr.push(l)
885 break
885 break
886 s = l[2:]
886 s = l[2:]
887 if l.startswith('- ') or l.startswith('! '):
887 if l.startswith('- ') or l.startswith('! '):
888 u = '-' + s
888 u = '-' + s
889 elif l.startswith(' '):
889 elif l.startswith(' '):
890 u = ' ' + s
890 u = ' ' + s
891 else:
891 else:
892 raise PatchError(_("bad hunk #%d old text line %d") %
892 raise PatchError(_("bad hunk #%d old text line %d") %
893 (self.number, x))
893 (self.number, x))
894 self.a.append(u)
894 self.a.append(u)
895 self.hunk.append(u)
895 self.hunk.append(u)
896
896
897 l = lr.readline()
897 l = lr.readline()
898 if l.startswith('\ '):
898 if l.startswith('\ '):
899 s = self.a[-1][:-1]
899 s = self.a[-1][:-1]
900 self.a[-1] = s
900 self.a[-1] = s
901 self.hunk[-1] = s
901 self.hunk[-1] = s
902 l = lr.readline()
902 l = lr.readline()
903 m = contextdesc.match(l)
903 m = contextdesc.match(l)
904 if not m:
904 if not m:
905 raise PatchError(_("bad hunk #%d") % self.number)
905 raise PatchError(_("bad hunk #%d") % self.number)
906 self.startb, bend = m.groups()
906 self.startb, bend = m.groups()
907 self.startb = int(self.startb)
907 self.startb = int(self.startb)
908 if bend is None:
908 if bend is None:
909 bend = self.startb
909 bend = self.startb
910 self.lenb = int(bend) - self.startb
910 self.lenb = int(bend) - self.startb
911 if self.startb:
911 if self.startb:
912 self.lenb += 1
912 self.lenb += 1
913 hunki = 1
913 hunki = 1
914 for x in xrange(self.lenb):
914 for x in xrange(self.lenb):
915 l = lr.readline()
915 l = lr.readline()
916 if l.startswith('\ '):
916 if l.startswith('\ '):
917 # XXX: the only way to hit this is with an invalid line range.
917 # XXX: the only way to hit this is with an invalid line range.
918 # The no-eol marker is not counted in the line range, but I
918 # The no-eol marker is not counted in the line range, but I
919 # guess there are diff(1) out there which behave differently.
919 # guess there are diff(1) out there which behave differently.
920 s = self.b[-1][:-1]
920 s = self.b[-1][:-1]
921 self.b[-1] = s
921 self.b[-1] = s
922 self.hunk[hunki - 1] = s
922 self.hunk[hunki - 1] = s
923 continue
923 continue
924 if not l:
924 if not l:
925 # line deletions, new block is empty and we hit EOF
925 # line deletions, new block is empty and we hit EOF
926 lr.push(l)
926 lr.push(l)
927 break
927 break
928 s = l[2:]
928 s = l[2:]
929 if l.startswith('+ ') or l.startswith('! '):
929 if l.startswith('+ ') or l.startswith('! '):
930 u = '+' + s
930 u = '+' + s
931 elif l.startswith(' '):
931 elif l.startswith(' '):
932 u = ' ' + s
932 u = ' ' + s
933 elif len(self.b) == 0:
933 elif len(self.b) == 0:
934 # line deletions, new block is empty
934 # line deletions, new block is empty
935 lr.push(l)
935 lr.push(l)
936 break
936 break
937 else:
937 else:
938 raise PatchError(_("bad hunk #%d old text line %d") %
938 raise PatchError(_("bad hunk #%d old text line %d") %
939 (self.number, x))
939 (self.number, x))
940 self.b.append(s)
940 self.b.append(s)
941 while True:
941 while True:
942 if hunki >= len(self.hunk):
942 if hunki >= len(self.hunk):
943 h = ""
943 h = ""
944 else:
944 else:
945 h = self.hunk[hunki]
945 h = self.hunk[hunki]
946 hunki += 1
946 hunki += 1
947 if h == u:
947 if h == u:
948 break
948 break
949 elif h.startswith('-'):
949 elif h.startswith('-'):
950 continue
950 continue
951 else:
951 else:
952 self.hunk.insert(hunki - 1, u)
952 self.hunk.insert(hunki - 1, u)
953 break
953 break
954
954
955 if not self.a:
955 if not self.a:
956 # this happens when lines were only added to the hunk
956 # this happens when lines were only added to the hunk
957 for x in self.hunk:
957 for x in self.hunk:
958 if x.startswith('-') or x.startswith(' '):
958 if x.startswith('-') or x.startswith(' '):
959 self.a.append(x)
959 self.a.append(x)
960 if not self.b:
960 if not self.b:
961 # this happens when lines were only deleted from the hunk
961 # this happens when lines were only deleted from the hunk
962 for x in self.hunk:
962 for x in self.hunk:
963 if x.startswith('+') or x.startswith(' '):
963 if x.startswith('+') or x.startswith(' '):
964 self.b.append(x[1:])
964 self.b.append(x[1:])
965 # @@ -start,len +start,len @@
965 # @@ -start,len +start,len @@
966 self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena,
966 self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena,
967 self.startb, self.lenb)
967 self.startb, self.lenb)
968 self.hunk[0] = self.desc
968 self.hunk[0] = self.desc
969 self._fixnewline(lr)
969 self._fixnewline(lr)
970
970
971 def _fixnewline(self, lr):
971 def _fixnewline(self, lr):
972 l = lr.readline()
972 l = lr.readline()
973 if l.startswith('\ '):
973 if l.startswith('\ '):
974 diffhelpers.fix_newline(self.hunk, self.a, self.b)
974 diffhelpers.fix_newline(self.hunk, self.a, self.b)
975 else:
975 else:
976 lr.push(l)
976 lr.push(l)
977
977
978 def complete(self):
978 def complete(self):
979 return len(self.a) == self.lena and len(self.b) == self.lenb
979 return len(self.a) == self.lena and len(self.b) == self.lenb
980
980
981 def _fuzzit(self, old, new, fuzz, toponly):
981 def _fuzzit(self, old, new, fuzz, toponly):
982 # this removes context lines from the top and bottom of list 'l'. It
982 # this removes context lines from the top and bottom of list 'l'. It
983 # checks the hunk to make sure only context lines are removed, and then
983 # checks the hunk to make sure only context lines are removed, and then
984 # returns a new shortened list of lines.
984 # returns a new shortened list of lines.
985 fuzz = min(fuzz, len(old))
985 fuzz = min(fuzz, len(old))
986 if fuzz:
986 if fuzz:
987 top = 0
987 top = 0
988 bot = 0
988 bot = 0
989 hlen = len(self.hunk)
989 hlen = len(self.hunk)
990 for x in xrange(hlen - 1):
990 for x in xrange(hlen - 1):
991 # the hunk starts with the @@ line, so use x+1
991 # the hunk starts with the @@ line, so use x+1
992 if self.hunk[x + 1][0] == ' ':
992 if self.hunk[x + 1][0] == ' ':
993 top += 1
993 top += 1
994 else:
994 else:
995 break
995 break
996 if not toponly:
996 if not toponly:
997 for x in xrange(hlen - 1):
997 for x in xrange(hlen - 1):
998 if self.hunk[hlen - bot - 1][0] == ' ':
998 if self.hunk[hlen - bot - 1][0] == ' ':
999 bot += 1
999 bot += 1
1000 else:
1000 else:
1001 break
1001 break
1002
1002
1003 bot = min(fuzz, bot)
1003 bot = min(fuzz, bot)
1004 top = min(fuzz, top)
1004 top = min(fuzz, top)
1005 return old[top:len(old) - bot], new[top:len(new) - bot], top
1005 return old[top:len(old) - bot], new[top:len(new) - bot], top
1006 return old, new, 0
1006 return old, new, 0
1007
1007
1008 def fuzzit(self, fuzz, toponly):
1008 def fuzzit(self, fuzz, toponly):
1009 old, new, top = self._fuzzit(self.a, self.b, fuzz, toponly)
1009 old, new, top = self._fuzzit(self.a, self.b, fuzz, toponly)
1010 oldstart = self.starta + top
1010 oldstart = self.starta + top
1011 newstart = self.startb + top
1011 newstart = self.startb + top
1012 # zero length hunk ranges already have their start decremented
1012 # zero length hunk ranges already have their start decremented
1013 if self.lena and oldstart > 0:
1013 if self.lena and oldstart > 0:
1014 oldstart -= 1
1014 oldstart -= 1
1015 if self.lenb and newstart > 0:
1015 if self.lenb and newstart > 0:
1016 newstart -= 1
1016 newstart -= 1
1017 return old, oldstart, new, newstart
1017 return old, oldstart, new, newstart
1018
1018
1019 class binhunk(object):
1019 class binhunk(object):
1020 'A binary patch file.'
1020 'A binary patch file.'
1021 def __init__(self, lr, fname):
1021 def __init__(self, lr, fname):
1022 self.text = None
1022 self.text = None
1023 self.delta = False
1023 self.delta = False
1024 self.hunk = ['GIT binary patch\n']
1024 self.hunk = ['GIT binary patch\n']
1025 self._fname = fname
1025 self._fname = fname
1026 self._read(lr)
1026 self._read(lr)
1027
1027
1028 def complete(self):
1028 def complete(self):
1029 return self.text is not None
1029 return self.text is not None
1030
1030
1031 def new(self, lines):
1031 def new(self, lines):
1032 if self.delta:
1032 if self.delta:
1033 return [applybindelta(self.text, ''.join(lines))]
1033 return [applybindelta(self.text, ''.join(lines))]
1034 return [self.text]
1034 return [self.text]
1035
1035
1036 def _read(self, lr):
1036 def _read(self, lr):
1037 def getline(lr, hunk):
1037 def getline(lr, hunk):
1038 l = lr.readline()
1038 l = lr.readline()
1039 hunk.append(l)
1039 hunk.append(l)
1040 return l.rstrip('\r\n')
1040 return l.rstrip('\r\n')
1041
1041
1042 size = 0
1042 size = 0
1043 while True:
1043 while True:
1044 line = getline(lr, self.hunk)
1044 line = getline(lr, self.hunk)
1045 if not line:
1045 if not line:
1046 raise PatchError(_('could not extract "%s" binary data')
1046 raise PatchError(_('could not extract "%s" binary data')
1047 % self._fname)
1047 % self._fname)
1048 if line.startswith('literal '):
1048 if line.startswith('literal '):
1049 size = int(line[8:].rstrip())
1049 size = int(line[8:].rstrip())
1050 break
1050 break
1051 if line.startswith('delta '):
1051 if line.startswith('delta '):
1052 size = int(line[6:].rstrip())
1052 size = int(line[6:].rstrip())
1053 self.delta = True
1053 self.delta = True
1054 break
1054 break
1055 dec = []
1055 dec = []
1056 line = getline(lr, self.hunk)
1056 line = getline(lr, self.hunk)
1057 while len(line) > 1:
1057 while len(line) > 1:
1058 l = line[0]
1058 l = line[0]
1059 if l <= 'Z' and l >= 'A':
1059 if l <= 'Z' and l >= 'A':
1060 l = ord(l) - ord('A') + 1
1060 l = ord(l) - ord('A') + 1
1061 else:
1061 else:
1062 l = ord(l) - ord('a') + 27
1062 l = ord(l) - ord('a') + 27
1063 try:
1063 try:
1064 dec.append(base85.b85decode(line[1:])[:l])
1064 dec.append(base85.b85decode(line[1:])[:l])
1065 except ValueError, e:
1065 except ValueError, e:
1066 raise PatchError(_('could not decode "%s" binary patch: %s')
1066 raise PatchError(_('could not decode "%s" binary patch: %s')
1067 % (self._fname, str(e)))
1067 % (self._fname, str(e)))
1068 line = getline(lr, self.hunk)
1068 line = getline(lr, self.hunk)
1069 text = zlib.decompress(''.join(dec))
1069 text = zlib.decompress(''.join(dec))
1070 if len(text) != size:
1070 if len(text) != size:
1071 raise PatchError(_('"%s" length is %d bytes, should be %d')
1071 raise PatchError(_('"%s" length is %d bytes, should be %d')
1072 % (self._fname, len(text), size))
1072 % (self._fname, len(text), size))
1073 self.text = text
1073 self.text = text
1074
1074
1075 def parsefilename(str):
1075 def parsefilename(str):
1076 # --- filename \t|space stuff
1076 # --- filename \t|space stuff
1077 s = str[4:].rstrip('\r\n')
1077 s = str[4:].rstrip('\r\n')
1078 i = s.find('\t')
1078 i = s.find('\t')
1079 if i < 0:
1079 if i < 0:
1080 i = s.find(' ')
1080 i = s.find(' ')
1081 if i < 0:
1081 if i < 0:
1082 return s
1082 return s
1083 return s[:i]
1083 return s[:i]
1084
1084
1085 def pathstrip(path, strip):
1085 def pathstrip(path, strip):
1086 pathlen = len(path)
1086 pathlen = len(path)
1087 i = 0
1087 i = 0
1088 if strip == 0:
1088 if strip == 0:
1089 return '', path.rstrip()
1089 return '', path.rstrip()
1090 count = strip
1090 count = strip
1091 while count > 0:
1091 while count > 0:
1092 i = path.find('/', i)
1092 i = path.find('/', i)
1093 if i == -1:
1093 if i == -1:
1094 raise PatchError(_("unable to strip away %d of %d dirs from %s") %
1094 raise PatchError(_("unable to strip away %d of %d dirs from %s") %
1095 (count, strip, path))
1095 (count, strip, path))
1096 i += 1
1096 i += 1
1097 # consume '//' in the path
1097 # consume '//' in the path
1098 while i < pathlen - 1 and path[i] == '/':
1098 while i < pathlen - 1 and path[i] == '/':
1099 i += 1
1099 i += 1
1100 count -= 1
1100 count -= 1
1101 return path[:i].lstrip(), path[i:].rstrip()
1101 return path[:i].lstrip(), path[i:].rstrip()
1102
1102
1103 def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip):
1103 def makepatchmeta(backend, afile_orig, bfile_orig, hunk, strip):
1104 nulla = afile_orig == "/dev/null"
1104 nulla = afile_orig == "/dev/null"
1105 nullb = bfile_orig == "/dev/null"
1105 nullb = bfile_orig == "/dev/null"
1106 create = nulla and hunk.starta == 0 and hunk.lena == 0
1106 create = nulla and hunk.starta == 0 and hunk.lena == 0
1107 remove = nullb and hunk.startb == 0 and hunk.lenb == 0
1107 remove = nullb and hunk.startb == 0 and hunk.lenb == 0
1108 abase, afile = pathstrip(afile_orig, strip)
1108 abase, afile = pathstrip(afile_orig, strip)
1109 gooda = not nulla and backend.exists(afile)
1109 gooda = not nulla and backend.exists(afile)
1110 bbase, bfile = pathstrip(bfile_orig, strip)
1110 bbase, bfile = pathstrip(bfile_orig, strip)
1111 if afile == bfile:
1111 if afile == bfile:
1112 goodb = gooda
1112 goodb = gooda
1113 else:
1113 else:
1114 goodb = not nullb and backend.exists(bfile)
1114 goodb = not nullb and backend.exists(bfile)
1115 missing = not goodb and not gooda and not create
1115 missing = not goodb and not gooda and not create
1116
1116
1117 # some diff programs apparently produce patches where the afile is
1117 # some diff programs apparently produce patches where the afile is
1118 # not /dev/null, but afile starts with bfile
1118 # not /dev/null, but afile starts with bfile
1119 abasedir = afile[:afile.rfind('/') + 1]
1119 abasedir = afile[:afile.rfind('/') + 1]
1120 bbasedir = bfile[:bfile.rfind('/') + 1]
1120 bbasedir = bfile[:bfile.rfind('/') + 1]
1121 if (missing and abasedir == bbasedir and afile.startswith(bfile)
1121 if (missing and abasedir == bbasedir and afile.startswith(bfile)
1122 and hunk.starta == 0 and hunk.lena == 0):
1122 and hunk.starta == 0 and hunk.lena == 0):
1123 create = True
1123 create = True
1124 missing = False
1124 missing = False
1125
1125
1126 # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the
1126 # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the
1127 # diff is between a file and its backup. In this case, the original
1127 # diff is between a file and its backup. In this case, the original
1128 # file should be patched (see original mpatch code).
1128 # file should be patched (see original mpatch code).
1129 isbackup = (abase == bbase and bfile.startswith(afile))
1129 isbackup = (abase == bbase and bfile.startswith(afile))
1130 fname = None
1130 fname = None
1131 if not missing:
1131 if not missing:
1132 if gooda and goodb:
1132 if gooda and goodb:
1133 fname = isbackup and afile or bfile
1133 fname = isbackup and afile or bfile
1134 elif gooda:
1134 elif gooda:
1135 fname = afile
1135 fname = afile
1136
1136
1137 if not fname:
1137 if not fname:
1138 if not nullb:
1138 if not nullb:
1139 fname = isbackup and afile or bfile
1139 fname = isbackup and afile or bfile
1140 elif not nulla:
1140 elif not nulla:
1141 fname = afile
1141 fname = afile
1142 else:
1142 else:
1143 raise PatchError(_("undefined source and destination files"))
1143 raise PatchError(_("undefined source and destination files"))
1144
1144
1145 gp = patchmeta(fname)
1145 gp = patchmeta(fname)
1146 if create:
1146 if create:
1147 gp.op = 'ADD'
1147 gp.op = 'ADD'
1148 elif remove:
1148 elif remove:
1149 gp.op = 'DELETE'
1149 gp.op = 'DELETE'
1150 return gp
1150 return gp
1151
1151
1152 def scangitpatch(lr, firstline):
1152 def scangitpatch(lr, firstline):
1153 """
1153 """
1154 Git patches can emit:
1154 Git patches can emit:
1155 - rename a to b
1155 - rename a to b
1156 - change b
1156 - change b
1157 - copy a to c
1157 - copy a to c
1158 - change c
1158 - change c
1159
1159
1160 We cannot apply this sequence as-is, the renamed 'a' could not be
1160 We cannot apply this sequence as-is, the renamed 'a' could not be
1161 found for it would have been renamed already. And we cannot copy
1161 found for it would have been renamed already. And we cannot copy
1162 from 'b' instead because 'b' would have been changed already. So
1162 from 'b' instead because 'b' would have been changed already. So
1163 we scan the git patch for copy and rename commands so we can
1163 we scan the git patch for copy and rename commands so we can
1164 perform the copies ahead of time.
1164 perform the copies ahead of time.
1165 """
1165 """
1166 pos = 0
1166 pos = 0
1167 try:
1167 try:
1168 pos = lr.fp.tell()
1168 pos = lr.fp.tell()
1169 fp = lr.fp
1169 fp = lr.fp
1170 except IOError:
1170 except IOError:
1171 fp = cStringIO.StringIO(lr.fp.read())
1171 fp = cStringIO.StringIO(lr.fp.read())
1172 gitlr = linereader(fp)
1172 gitlr = linereader(fp)
1173 gitlr.push(firstline)
1173 gitlr.push(firstline)
1174 gitpatches = readgitpatch(gitlr)
1174 gitpatches = readgitpatch(gitlr)
1175 fp.seek(pos)
1175 fp.seek(pos)
1176 return gitpatches
1176 return gitpatches
1177
1177
1178 def iterhunks(fp):
1178 def iterhunks(fp):
1179 """Read a patch and yield the following events:
1179 """Read a patch and yield the following events:
1180 - ("file", afile, bfile, firsthunk): select a new target file.
1180 - ("file", afile, bfile, firsthunk): select a new target file.
1181 - ("hunk", hunk): a new hunk is ready to be applied, follows a
1181 - ("hunk", hunk): a new hunk is ready to be applied, follows a
1182 "file" event.
1182 "file" event.
1183 - ("git", gitchanges): current diff is in git format, gitchanges
1183 - ("git", gitchanges): current diff is in git format, gitchanges
1184 maps filenames to gitpatch records. Unique event.
1184 maps filenames to gitpatch records. Unique event.
1185 """
1185 """
1186 afile = ""
1186 afile = ""
1187 bfile = ""
1187 bfile = ""
1188 state = None
1188 state = None
1189 hunknum = 0
1189 hunknum = 0
1190 emitfile = newfile = False
1190 emitfile = newfile = False
1191 gitpatches = None
1191 gitpatches = None
1192
1192
1193 # our states
1193 # our states
1194 BFILE = 1
1194 BFILE = 1
1195 context = None
1195 context = None
1196 lr = linereader(fp)
1196 lr = linereader(fp)
1197
1197
1198 while True:
1198 while True:
1199 x = lr.readline()
1199 x = lr.readline()
1200 if not x:
1200 if not x:
1201 break
1201 break
1202 if state == BFILE and (
1202 if state == BFILE and (
1203 (not context and x[0] == '@')
1203 (not context and x[0] == '@')
1204 or (context is not False and x.startswith('***************'))
1204 or (context is not False and x.startswith('***************'))
1205 or x.startswith('GIT binary patch')):
1205 or x.startswith('GIT binary patch')):
1206 gp = None
1206 gp = None
1207 if (gitpatches and
1207 if (gitpatches and
1208 gitpatches[-1].ispatching(afile, bfile)):
1208 gitpatches[-1].ispatching(afile, bfile)):
1209 gp = gitpatches.pop()
1209 gp = gitpatches.pop()
1210 if x.startswith('GIT binary patch'):
1210 if x.startswith('GIT binary patch'):
1211 h = binhunk(lr, gp.path)
1211 h = binhunk(lr, gp.path)
1212 else:
1212 else:
1213 if context is None and x.startswith('***************'):
1213 if context is None and x.startswith('***************'):
1214 context = True
1214 context = True
1215 h = hunk(x, hunknum + 1, lr, context)
1215 h = hunk(x, hunknum + 1, lr, context)
1216 hunknum += 1
1216 hunknum += 1
1217 if emitfile:
1217 if emitfile:
1218 emitfile = False
1218 emitfile = False
1219 yield 'file', (afile, bfile, h, gp and gp.copy() or None)
1219 yield 'file', (afile, bfile, h, gp and gp.copy() or None)
1220 yield 'hunk', h
1220 yield 'hunk', h
1221 elif x.startswith('diff --git a/'):
1221 elif x.startswith('diff --git a/'):
1222 m = gitre.match(x.rstrip(' \r\n'))
1222 m = gitre.match(x.rstrip(' \r\n'))
1223 if not m:
1223 if not m:
1224 continue
1224 continue
1225 if gitpatches is None:
1225 if gitpatches is None:
1226 # scan whole input for git metadata
1226 # scan whole input for git metadata
1227 gitpatches = scangitpatch(lr, x)
1227 gitpatches = scangitpatch(lr, x)
1228 yield 'git', [g.copy() for g in gitpatches
1228 yield 'git', [g.copy() for g in gitpatches
1229 if g.op in ('COPY', 'RENAME')]
1229 if g.op in ('COPY', 'RENAME')]
1230 gitpatches.reverse()
1230 gitpatches.reverse()
1231 afile = 'a/' + m.group(1)
1231 afile = 'a/' + m.group(1)
1232 bfile = 'b/' + m.group(2)
1232 bfile = 'b/' + m.group(2)
1233 while gitpatches and not gitpatches[-1].ispatching(afile, bfile):
1233 while gitpatches and not gitpatches[-1].ispatching(afile, bfile):
1234 gp = gitpatches.pop()
1234 gp = gitpatches.pop()
1235 yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy())
1235 yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy())
1236 if not gitpatches:
1236 if not gitpatches:
1237 raise PatchError(_('failed to synchronize metadata for "%s"')
1237 raise PatchError(_('failed to synchronize metadata for "%s"')
1238 % afile[2:])
1238 % afile[2:])
1239 gp = gitpatches[-1]
1239 gp = gitpatches[-1]
1240 newfile = True
1240 newfile = True
1241 elif x.startswith('---'):
1241 elif x.startswith('---'):
1242 # check for a unified diff
1242 # check for a unified diff
1243 l2 = lr.readline()
1243 l2 = lr.readline()
1244 if not l2.startswith('+++'):
1244 if not l2.startswith('+++'):
1245 lr.push(l2)
1245 lr.push(l2)
1246 continue
1246 continue
1247 newfile = True
1247 newfile = True
1248 context = False
1248 context = False
1249 afile = parsefilename(x)
1249 afile = parsefilename(x)
1250 bfile = parsefilename(l2)
1250 bfile = parsefilename(l2)
1251 elif x.startswith('***'):
1251 elif x.startswith('***'):
1252 # check for a context diff
1252 # check for a context diff
1253 l2 = lr.readline()
1253 l2 = lr.readline()
1254 if not l2.startswith('---'):
1254 if not l2.startswith('---'):
1255 lr.push(l2)
1255 lr.push(l2)
1256 continue
1256 continue
1257 l3 = lr.readline()
1257 l3 = lr.readline()
1258 lr.push(l3)
1258 lr.push(l3)
1259 if not l3.startswith("***************"):
1259 if not l3.startswith("***************"):
1260 lr.push(l2)
1260 lr.push(l2)
1261 continue
1261 continue
1262 newfile = True
1262 newfile = True
1263 context = True
1263 context = True
1264 afile = parsefilename(x)
1264 afile = parsefilename(x)
1265 bfile = parsefilename(l2)
1265 bfile = parsefilename(l2)
1266
1266
1267 if newfile:
1267 if newfile:
1268 newfile = False
1268 newfile = False
1269 emitfile = True
1269 emitfile = True
1270 state = BFILE
1270 state = BFILE
1271 hunknum = 0
1271 hunknum = 0
1272
1272
1273 while gitpatches:
1273 while gitpatches:
1274 gp = gitpatches.pop()
1274 gp = gitpatches.pop()
1275 yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy())
1275 yield 'file', ('a/' + gp.path, 'b/' + gp.path, None, gp.copy())
1276
1276
1277 def applybindelta(binchunk, data):
1277 def applybindelta(binchunk, data):
1278 """Apply a binary delta hunk
1278 """Apply a binary delta hunk
1279 The algorithm used is the algorithm from git's patch-delta.c
1279 The algorithm used is the algorithm from git's patch-delta.c
1280 """
1280 """
1281 def deltahead(binchunk):
1281 def deltahead(binchunk):
1282 i = 0
1282 i = 0
1283 for c in binchunk:
1283 for c in binchunk:
1284 i += 1
1284 i += 1
1285 if not (ord(c) & 0x80):
1285 if not (ord(c) & 0x80):
1286 return i
1286 return i
1287 return i
1287 return i
1288 out = ""
1288 out = ""
1289 s = deltahead(binchunk)
1289 s = deltahead(binchunk)
1290 binchunk = binchunk[s:]
1290 binchunk = binchunk[s:]
1291 s = deltahead(binchunk)
1291 s = deltahead(binchunk)
1292 binchunk = binchunk[s:]
1292 binchunk = binchunk[s:]
1293 i = 0
1293 i = 0
1294 while i < len(binchunk):
1294 while i < len(binchunk):
1295 cmd = ord(binchunk[i])
1295 cmd = ord(binchunk[i])
1296 i += 1
1296 i += 1
1297 if (cmd & 0x80):
1297 if (cmd & 0x80):
1298 offset = 0
1298 offset = 0
1299 size = 0
1299 size = 0
1300 if (cmd & 0x01):
1300 if (cmd & 0x01):
1301 offset = ord(binchunk[i])
1301 offset = ord(binchunk[i])
1302 i += 1
1302 i += 1
1303 if (cmd & 0x02):
1303 if (cmd & 0x02):
1304 offset |= ord(binchunk[i]) << 8
1304 offset |= ord(binchunk[i]) << 8
1305 i += 1
1305 i += 1
1306 if (cmd & 0x04):
1306 if (cmd & 0x04):
1307 offset |= ord(binchunk[i]) << 16
1307 offset |= ord(binchunk[i]) << 16
1308 i += 1
1308 i += 1
1309 if (cmd & 0x08):
1309 if (cmd & 0x08):
1310 offset |= ord(binchunk[i]) << 24
1310 offset |= ord(binchunk[i]) << 24
1311 i += 1
1311 i += 1
1312 if (cmd & 0x10):
1312 if (cmd & 0x10):
1313 size = ord(binchunk[i])
1313 size = ord(binchunk[i])
1314 i += 1
1314 i += 1
1315 if (cmd & 0x20):
1315 if (cmd & 0x20):
1316 size |= ord(binchunk[i]) << 8
1316 size |= ord(binchunk[i]) << 8
1317 i += 1
1317 i += 1
1318 if (cmd & 0x40):
1318 if (cmd & 0x40):
1319 size |= ord(binchunk[i]) << 16
1319 size |= ord(binchunk[i]) << 16
1320 i += 1
1320 i += 1
1321 if size == 0:
1321 if size == 0:
1322 size = 0x10000
1322 size = 0x10000
1323 offset_end = offset + size
1323 offset_end = offset + size
1324 out += data[offset:offset_end]
1324 out += data[offset:offset_end]
1325 elif cmd != 0:
1325 elif cmd != 0:
1326 offset_end = i + cmd
1326 offset_end = i + cmd
1327 out += binchunk[i:offset_end]
1327 out += binchunk[i:offset_end]
1328 i += cmd
1328 i += cmd
1329 else:
1329 else:
1330 raise PatchError(_('unexpected delta opcode 0'))
1330 raise PatchError(_('unexpected delta opcode 0'))
1331 return out
1331 return out
1332
1332
1333 def applydiff(ui, fp, backend, store, strip=1, eolmode='strict'):
1333 def applydiff(ui, fp, backend, store, strip=1, eolmode='strict'):
1334 """Reads a patch from fp and tries to apply it.
1334 """Reads a patch from fp and tries to apply it.
1335
1335
1336 Returns 0 for a clean patch, -1 if any rejects were found and 1 if
1336 Returns 0 for a clean patch, -1 if any rejects were found and 1 if
1337 there was any fuzz.
1337 there was any fuzz.
1338
1338
1339 If 'eolmode' is 'strict', the patch content and patched file are
1339 If 'eolmode' is 'strict', the patch content and patched file are
1340 read in binary mode. Otherwise, line endings are ignored when
1340 read in binary mode. Otherwise, line endings are ignored when
1341 patching then normalized according to 'eolmode'.
1341 patching then normalized according to 'eolmode'.
1342 """
1342 """
1343 return _applydiff(ui, fp, patchfile, backend, store, strip=strip,
1343 return _applydiff(ui, fp, patchfile, backend, store, strip=strip,
1344 eolmode=eolmode)
1344 eolmode=eolmode)
1345
1345
1346 def _applydiff(ui, fp, patcher, backend, store, strip=1,
1346 def _applydiff(ui, fp, patcher, backend, store, strip=1,
1347 eolmode='strict'):
1347 eolmode='strict'):
1348
1348
1349 def pstrip(p):
1349 def pstrip(p):
1350 return pathstrip(p, strip - 1)[1]
1350 return pathstrip(p, strip - 1)[1]
1351
1351
1352 rejects = 0
1352 rejects = 0
1353 err = 0
1353 err = 0
1354 current_file = None
1354 current_file = None
1355
1355
1356 for state, values in iterhunks(fp):
1356 for state, values in iterhunks(fp):
1357 if state == 'hunk':
1357 if state == 'hunk':
1358 if not current_file:
1358 if not current_file:
1359 continue
1359 continue
1360 ret = current_file.apply(values)
1360 ret = current_file.apply(values)
1361 if ret > 0:
1361 if ret > 0:
1362 err = 1
1362 err = 1
1363 elif state == 'file':
1363 elif state == 'file':
1364 if current_file:
1364 if current_file:
1365 rejects += current_file.close()
1365 rejects += current_file.close()
1366 current_file = None
1366 current_file = None
1367 afile, bfile, first_hunk, gp = values
1367 afile, bfile, first_hunk, gp = values
1368 if gp:
1368 if gp:
1369 gp.path = pstrip(gp.path)
1369 gp.path = pstrip(gp.path)
1370 if gp.oldpath:
1370 if gp.oldpath:
1371 gp.oldpath = pstrip(gp.oldpath)
1371 gp.oldpath = pstrip(gp.oldpath)
1372 else:
1372 else:
1373 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip)
1373 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip)
1374 if gp.op == 'RENAME':
1374 if gp.op == 'RENAME':
1375 backend.unlink(gp.oldpath)
1375 backend.unlink(gp.oldpath)
1376 if not first_hunk:
1376 if not first_hunk:
1377 if gp.op == 'DELETE':
1377 if gp.op == 'DELETE':
1378 backend.unlink(gp.path)
1378 backend.unlink(gp.path)
1379 continue
1379 continue
1380 data, mode = None, None
1380 data, mode = None, None
1381 if gp.op in ('RENAME', 'COPY'):
1381 if gp.op in ('RENAME', 'COPY'):
1382 data, mode = store.getfile(gp.oldpath)[:2]
1382 data, mode = store.getfile(gp.oldpath)[:2]
1383 if gp.mode:
1383 if gp.mode:
1384 mode = gp.mode
1384 mode = gp.mode
1385 if gp.op == 'ADD':
1385 if gp.op == 'ADD':
1386 # Added files without content have no hunk and
1386 # Added files without content have no hunk and
1387 # must be created
1387 # must be created
1388 data = ''
1388 data = ''
1389 if data or mode:
1389 if data or mode:
1390 if (gp.op in ('ADD', 'RENAME', 'COPY')
1390 if (gp.op in ('ADD', 'RENAME', 'COPY')
1391 and backend.exists(gp.path)):
1391 and backend.exists(gp.path)):
1392 raise PatchError(_("cannot create %s: destination "
1392 raise PatchError(_("cannot create %s: destination "
1393 "already exists") % gp.path)
1393 "already exists") % gp.path)
1394 backend.setfile(gp.path, data, mode, gp.oldpath)
1394 backend.setfile(gp.path, data, mode, gp.oldpath)
1395 continue
1395 continue
1396 try:
1396 try:
1397 current_file = patcher(ui, gp, backend, store,
1397 current_file = patcher(ui, gp, backend, store,
1398 eolmode=eolmode)
1398 eolmode=eolmode)
1399 except PatchError, inst:
1399 except PatchError, inst:
1400 ui.warn(str(inst) + '\n')
1400 ui.warn(str(inst) + '\n')
1401 current_file = None
1401 current_file = None
1402 rejects += 1
1402 rejects += 1
1403 continue
1403 continue
1404 elif state == 'git':
1404 elif state == 'git':
1405 for gp in values:
1405 for gp in values:
1406 path = pstrip(gp.oldpath)
1406 path = pstrip(gp.oldpath)
1407 try:
1407 try:
1408 data, mode = backend.getfile(path)
1408 data, mode = backend.getfile(path)
1409 except IOError, e:
1409 except IOError, e:
1410 if e.errno != errno.ENOENT:
1410 if e.errno != errno.ENOENT:
1411 raise
1411 raise
1412 # The error ignored here will trigger a getfile()
1412 # The error ignored here will trigger a getfile()
1413 # error in a place more appropriate for error
1413 # error in a place more appropriate for error
1414 # handling, and will not interrupt the patching
1414 # handling, and will not interrupt the patching
1415 # process.
1415 # process.
1416 else:
1416 else:
1417 store.setfile(path, data, mode)
1417 store.setfile(path, data, mode)
1418 else:
1418 else:
1419 raise util.Abort(_('unsupported parser state: %s') % state)
1419 raise util.Abort(_('unsupported parser state: %s') % state)
1420
1420
1421 if current_file:
1421 if current_file:
1422 rejects += current_file.close()
1422 rejects += current_file.close()
1423
1423
1424 if rejects:
1424 if rejects:
1425 return -1
1425 return -1
1426 return err
1426 return err
1427
1427
1428 def _externalpatch(ui, repo, patcher, patchname, strip, files,
1428 def _externalpatch(ui, repo, patcher, patchname, strip, files,
1429 similarity):
1429 similarity):
1430 """use <patcher> to apply <patchname> to the working directory.
1430 """use <patcher> to apply <patchname> to the working directory.
1431 returns whether patch was applied with fuzz factor."""
1431 returns whether patch was applied with fuzz factor."""
1432
1432
1433 fuzz = False
1433 fuzz = False
1434 args = []
1434 args = []
1435 cwd = repo.root
1435 cwd = repo.root
1436 if cwd:
1436 if cwd:
1437 args.append('-d %s' % util.shellquote(cwd))
1437 args.append('-d %s' % util.shellquote(cwd))
1438 fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip,
1438 fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip,
1439 util.shellquote(patchname)))
1439 util.shellquote(patchname)))
1440 try:
1440 try:
1441 for line in fp:
1441 for line in fp:
1442 line = line.rstrip()
1442 line = line.rstrip()
1443 ui.note(line + '\n')
1443 ui.note(line + '\n')
1444 if line.startswith('patching file '):
1444 if line.startswith('patching file '):
1445 pf = util.parsepatchoutput(line)
1445 pf = util.parsepatchoutput(line)
1446 printed_file = False
1446 printed_file = False
1447 files.add(pf)
1447 files.add(pf)
1448 elif line.find('with fuzz') >= 0:
1448 elif line.find('with fuzz') >= 0:
1449 fuzz = True
1449 fuzz = True
1450 if not printed_file:
1450 if not printed_file:
1451 ui.warn(pf + '\n')
1451 ui.warn(pf + '\n')
1452 printed_file = True
1452 printed_file = True
1453 ui.warn(line + '\n')
1453 ui.warn(line + '\n')
1454 elif line.find('saving rejects to file') >= 0:
1454 elif line.find('saving rejects to file') >= 0:
1455 ui.warn(line + '\n')
1455 ui.warn(line + '\n')
1456 elif line.find('FAILED') >= 0:
1456 elif line.find('FAILED') >= 0:
1457 if not printed_file:
1457 if not printed_file:
1458 ui.warn(pf + '\n')
1458 ui.warn(pf + '\n')
1459 printed_file = True
1459 printed_file = True
1460 ui.warn(line + '\n')
1460 ui.warn(line + '\n')
1461 finally:
1461 finally:
1462 if files:
1462 if files:
1463 scmutil.marktouched(repo, files, similarity)
1463 scmutil.marktouched(repo, files, similarity)
1464 code = fp.close()
1464 code = fp.close()
1465 if code:
1465 if code:
1466 raise PatchError(_("patch command failed: %s") %
1466 raise PatchError(_("patch command failed: %s") %
1467 util.explainexit(code)[0])
1467 util.explainexit(code)[0])
1468 return fuzz
1468 return fuzz
1469
1469
1470 def patchbackend(ui, backend, patchobj, strip, files=None, eolmode='strict'):
1470 def patchbackend(ui, backend, patchobj, strip, files=None, eolmode='strict'):
1471 if files is None:
1471 if files is None:
1472 files = set()
1472 files = set()
1473 if eolmode is None:
1473 if eolmode is None:
1474 eolmode = ui.config('patch', 'eol', 'strict')
1474 eolmode = ui.config('patch', 'eol', 'strict')
1475 if eolmode.lower() not in eolmodes:
1475 if eolmode.lower() not in eolmodes:
1476 raise util.Abort(_('unsupported line endings type: %s') % eolmode)
1476 raise util.Abort(_('unsupported line endings type: %s') % eolmode)
1477 eolmode = eolmode.lower()
1477 eolmode = eolmode.lower()
1478
1478
1479 store = filestore()
1479 store = filestore()
1480 try:
1480 try:
1481 fp = open(patchobj, 'rb')
1481 fp = open(patchobj, 'rb')
1482 except TypeError:
1482 except TypeError:
1483 fp = patchobj
1483 fp = patchobj
1484 try:
1484 try:
1485 ret = applydiff(ui, fp, backend, store, strip=strip,
1485 ret = applydiff(ui, fp, backend, store, strip=strip,
1486 eolmode=eolmode)
1486 eolmode=eolmode)
1487 finally:
1487 finally:
1488 if fp != patchobj:
1488 if fp != patchobj:
1489 fp.close()
1489 fp.close()
1490 files.update(backend.close())
1490 files.update(backend.close())
1491 store.close()
1491 store.close()
1492 if ret < 0:
1492 if ret < 0:
1493 raise PatchError(_('patch failed to apply'))
1493 raise PatchError(_('patch failed to apply'))
1494 return ret > 0
1494 return ret > 0
1495
1495
1496 def internalpatch(ui, repo, patchobj, strip, files=None, eolmode='strict',
1496 def internalpatch(ui, repo, patchobj, strip, files=None, eolmode='strict',
1497 similarity=0):
1497 similarity=0):
1498 """use builtin patch to apply <patchobj> to the working directory.
1498 """use builtin patch to apply <patchobj> to the working directory.
1499 returns whether patch was applied with fuzz factor."""
1499 returns whether patch was applied with fuzz factor."""
1500 backend = workingbackend(ui, repo, similarity)
1500 backend = workingbackend(ui, repo, similarity)
1501 return patchbackend(ui, backend, patchobj, strip, files, eolmode)
1501 return patchbackend(ui, backend, patchobj, strip, files, eolmode)
1502
1502
1503 def patchrepo(ui, repo, ctx, store, patchobj, strip, files=None,
1503 def patchrepo(ui, repo, ctx, store, patchobj, strip, files=None,
1504 eolmode='strict'):
1504 eolmode='strict'):
1505 backend = repobackend(ui, repo, ctx, store)
1505 backend = repobackend(ui, repo, ctx, store)
1506 return patchbackend(ui, backend, patchobj, strip, files, eolmode)
1506 return patchbackend(ui, backend, patchobj, strip, files, eolmode)
1507
1507
1508 def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict',
1508 def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict',
1509 similarity=0):
1509 similarity=0):
1510 """Apply <patchname> to the working directory.
1510 """Apply <patchname> to the working directory.
1511
1511
1512 'eolmode' specifies how end of lines should be handled. It can be:
1512 'eolmode' specifies how end of lines should be handled. It can be:
1513 - 'strict': inputs are read in binary mode, EOLs are preserved
1513 - 'strict': inputs are read in binary mode, EOLs are preserved
1514 - 'crlf': EOLs are ignored when patching and reset to CRLF
1514 - 'crlf': EOLs are ignored when patching and reset to CRLF
1515 - 'lf': EOLs are ignored when patching and reset to LF
1515 - 'lf': EOLs are ignored when patching and reset to LF
1516 - None: get it from user settings, default to 'strict'
1516 - None: get it from user settings, default to 'strict'
1517 'eolmode' is ignored when using an external patcher program.
1517 'eolmode' is ignored when using an external patcher program.
1518
1518
1519 Returns whether patch was applied with fuzz factor.
1519 Returns whether patch was applied with fuzz factor.
1520 """
1520 """
1521 patcher = ui.config('ui', 'patch')
1521 patcher = ui.config('ui', 'patch')
1522 if files is None:
1522 if files is None:
1523 files = set()
1523 files = set()
1524 try:
1525 if patcher:
1524 if patcher:
1526 return _externalpatch(ui, repo, patcher, patchname, strip,
1525 return _externalpatch(ui, repo, patcher, patchname, strip,
1527 files, similarity)
1526 files, similarity)
1528 return internalpatch(ui, repo, patchname, strip, files, eolmode,
1527 return internalpatch(ui, repo, patchname, strip, files, eolmode,
1529 similarity)
1528 similarity)
1530 except PatchError, err:
1531 raise util.Abort(str(err))
1532
1529
1533 def changedfiles(ui, repo, patchpath, strip=1):
1530 def changedfiles(ui, repo, patchpath, strip=1):
1534 backend = fsbackend(ui, repo.root)
1531 backend = fsbackend(ui, repo.root)
1535 fp = open(patchpath, 'rb')
1532 fp = open(patchpath, 'rb')
1536 try:
1533 try:
1537 changed = set()
1534 changed = set()
1538 for state, values in iterhunks(fp):
1535 for state, values in iterhunks(fp):
1539 if state == 'file':
1536 if state == 'file':
1540 afile, bfile, first_hunk, gp = values
1537 afile, bfile, first_hunk, gp = values
1541 if gp:
1538 if gp:
1542 gp.path = pathstrip(gp.path, strip - 1)[1]
1539 gp.path = pathstrip(gp.path, strip - 1)[1]
1543 if gp.oldpath:
1540 if gp.oldpath:
1544 gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1]
1541 gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1]
1545 else:
1542 else:
1546 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip)
1543 gp = makepatchmeta(backend, afile, bfile, first_hunk, strip)
1547 changed.add(gp.path)
1544 changed.add(gp.path)
1548 if gp.op == 'RENAME':
1545 if gp.op == 'RENAME':
1549 changed.add(gp.oldpath)
1546 changed.add(gp.oldpath)
1550 elif state not in ('hunk', 'git'):
1547 elif state not in ('hunk', 'git'):
1551 raise util.Abort(_('unsupported parser state: %s') % state)
1548 raise util.Abort(_('unsupported parser state: %s') % state)
1552 return changed
1549 return changed
1553 finally:
1550 finally:
1554 fp.close()
1551 fp.close()
1555
1552
1556 class GitDiffRequired(Exception):
1553 class GitDiffRequired(Exception):
1557 pass
1554 pass
1558
1555
1559 def diffopts(ui, opts=None, untrusted=False, section='diff'):
1556 def diffopts(ui, opts=None, untrusted=False, section='diff'):
1560 def get(key, name=None, getter=ui.configbool):
1557 def get(key, name=None, getter=ui.configbool):
1561 return ((opts and opts.get(key)) or
1558 return ((opts and opts.get(key)) or
1562 getter(section, name or key, None, untrusted=untrusted))
1559 getter(section, name or key, None, untrusted=untrusted))
1563 return mdiff.diffopts(
1560 return mdiff.diffopts(
1564 text=opts and opts.get('text'),
1561 text=opts and opts.get('text'),
1565 git=get('git'),
1562 git=get('git'),
1566 nodates=get('nodates'),
1563 nodates=get('nodates'),
1567 showfunc=get('show_function', 'showfunc'),
1564 showfunc=get('show_function', 'showfunc'),
1568 ignorews=get('ignore_all_space', 'ignorews'),
1565 ignorews=get('ignore_all_space', 'ignorews'),
1569 ignorewsamount=get('ignore_space_change', 'ignorewsamount'),
1566 ignorewsamount=get('ignore_space_change', 'ignorewsamount'),
1570 ignoreblanklines=get('ignore_blank_lines', 'ignoreblanklines'),
1567 ignoreblanklines=get('ignore_blank_lines', 'ignoreblanklines'),
1571 context=get('unified', getter=ui.config))
1568 context=get('unified', getter=ui.config))
1572
1569
1573 def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None,
1570 def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None,
1574 losedatafn=None, prefix=''):
1571 losedatafn=None, prefix=''):
1575 '''yields diff of changes to files between two nodes, or node and
1572 '''yields diff of changes to files between two nodes, or node and
1576 working directory.
1573 working directory.
1577
1574
1578 if node1 is None, use first dirstate parent instead.
1575 if node1 is None, use first dirstate parent instead.
1579 if node2 is None, compare node1 with working directory.
1576 if node2 is None, compare node1 with working directory.
1580
1577
1581 losedatafn(**kwarg) is a callable run when opts.upgrade=True and
1578 losedatafn(**kwarg) is a callable run when opts.upgrade=True and
1582 every time some change cannot be represented with the current
1579 every time some change cannot be represented with the current
1583 patch format. Return False to upgrade to git patch format, True to
1580 patch format. Return False to upgrade to git patch format, True to
1584 accept the loss or raise an exception to abort the diff. It is
1581 accept the loss or raise an exception to abort the diff. It is
1585 called with the name of current file being diffed as 'fn'. If set
1582 called with the name of current file being diffed as 'fn'. If set
1586 to None, patches will always be upgraded to git format when
1583 to None, patches will always be upgraded to git format when
1587 necessary.
1584 necessary.
1588
1585
1589 prefix is a filename prefix that is prepended to all filenames on
1586 prefix is a filename prefix that is prepended to all filenames on
1590 display (used for subrepos).
1587 display (used for subrepos).
1591 '''
1588 '''
1592
1589
1593 if opts is None:
1590 if opts is None:
1594 opts = mdiff.defaultopts
1591 opts = mdiff.defaultopts
1595
1592
1596 if not node1 and not node2:
1593 if not node1 and not node2:
1597 node1 = repo.dirstate.p1()
1594 node1 = repo.dirstate.p1()
1598
1595
1599 def lrugetfilectx():
1596 def lrugetfilectx():
1600 cache = {}
1597 cache = {}
1601 order = util.deque()
1598 order = util.deque()
1602 def getfilectx(f, ctx):
1599 def getfilectx(f, ctx):
1603 fctx = ctx.filectx(f, filelog=cache.get(f))
1600 fctx = ctx.filectx(f, filelog=cache.get(f))
1604 if f not in cache:
1601 if f not in cache:
1605 if len(cache) > 20:
1602 if len(cache) > 20:
1606 del cache[order.popleft()]
1603 del cache[order.popleft()]
1607 cache[f] = fctx.filelog()
1604 cache[f] = fctx.filelog()
1608 else:
1605 else:
1609 order.remove(f)
1606 order.remove(f)
1610 order.append(f)
1607 order.append(f)
1611 return fctx
1608 return fctx
1612 return getfilectx
1609 return getfilectx
1613 getfilectx = lrugetfilectx()
1610 getfilectx = lrugetfilectx()
1614
1611
1615 ctx1 = repo[node1]
1612 ctx1 = repo[node1]
1616 ctx2 = repo[node2]
1613 ctx2 = repo[node2]
1617
1614
1618 if not changes:
1615 if not changes:
1619 changes = repo.status(ctx1, ctx2, match=match)
1616 changes = repo.status(ctx1, ctx2, match=match)
1620 modified, added, removed = changes[:3]
1617 modified, added, removed = changes[:3]
1621
1618
1622 if not modified and not added and not removed:
1619 if not modified and not added and not removed:
1623 return []
1620 return []
1624
1621
1625 revs = None
1622 revs = None
1626 hexfunc = repo.ui.debugflag and hex or short
1623 hexfunc = repo.ui.debugflag and hex or short
1627 revs = [hexfunc(node) for node in [node1, node2] if node]
1624 revs = [hexfunc(node) for node in [node1, node2] if node]
1628
1625
1629 copy = {}
1626 copy = {}
1630 if opts.git or opts.upgrade:
1627 if opts.git or opts.upgrade:
1631 copy = copies.pathcopies(ctx1, ctx2)
1628 copy = copies.pathcopies(ctx1, ctx2)
1632
1629
1633 def difffn(opts, losedata):
1630 def difffn(opts, losedata):
1634 return trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
1631 return trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
1635 copy, getfilectx, opts, losedata, prefix)
1632 copy, getfilectx, opts, losedata, prefix)
1636 if opts.upgrade and not opts.git:
1633 if opts.upgrade and not opts.git:
1637 try:
1634 try:
1638 def losedata(fn):
1635 def losedata(fn):
1639 if not losedatafn or not losedatafn(fn=fn):
1636 if not losedatafn or not losedatafn(fn=fn):
1640 raise GitDiffRequired
1637 raise GitDiffRequired
1641 # Buffer the whole output until we are sure it can be generated
1638 # Buffer the whole output until we are sure it can be generated
1642 return list(difffn(opts.copy(git=False), losedata))
1639 return list(difffn(opts.copy(git=False), losedata))
1643 except GitDiffRequired:
1640 except GitDiffRequired:
1644 return difffn(opts.copy(git=True), None)
1641 return difffn(opts.copy(git=True), None)
1645 else:
1642 else:
1646 return difffn(opts, None)
1643 return difffn(opts, None)
1647
1644
1648 def difflabel(func, *args, **kw):
1645 def difflabel(func, *args, **kw):
1649 '''yields 2-tuples of (output, label) based on the output of func()'''
1646 '''yields 2-tuples of (output, label) based on the output of func()'''
1650 headprefixes = [('diff', 'diff.diffline'),
1647 headprefixes = [('diff', 'diff.diffline'),
1651 ('copy', 'diff.extended'),
1648 ('copy', 'diff.extended'),
1652 ('rename', 'diff.extended'),
1649 ('rename', 'diff.extended'),
1653 ('old', 'diff.extended'),
1650 ('old', 'diff.extended'),
1654 ('new', 'diff.extended'),
1651 ('new', 'diff.extended'),
1655 ('deleted', 'diff.extended'),
1652 ('deleted', 'diff.extended'),
1656 ('---', 'diff.file_a'),
1653 ('---', 'diff.file_a'),
1657 ('+++', 'diff.file_b')]
1654 ('+++', 'diff.file_b')]
1658 textprefixes = [('@', 'diff.hunk'),
1655 textprefixes = [('@', 'diff.hunk'),
1659 ('-', 'diff.deleted'),
1656 ('-', 'diff.deleted'),
1660 ('+', 'diff.inserted')]
1657 ('+', 'diff.inserted')]
1661 head = False
1658 head = False
1662 for chunk in func(*args, **kw):
1659 for chunk in func(*args, **kw):
1663 lines = chunk.split('\n')
1660 lines = chunk.split('\n')
1664 for i, line in enumerate(lines):
1661 for i, line in enumerate(lines):
1665 if i != 0:
1662 if i != 0:
1666 yield ('\n', '')
1663 yield ('\n', '')
1667 if head:
1664 if head:
1668 if line.startswith('@'):
1665 if line.startswith('@'):
1669 head = False
1666 head = False
1670 else:
1667 else:
1671 if line and line[0] not in ' +-@\\':
1668 if line and line[0] not in ' +-@\\':
1672 head = True
1669 head = True
1673 stripline = line
1670 stripline = line
1674 if not head and line and line[0] in '+-':
1671 if not head and line and line[0] in '+-':
1675 # highlight trailing whitespace, but only in changed lines
1672 # highlight trailing whitespace, but only in changed lines
1676 stripline = line.rstrip()
1673 stripline = line.rstrip()
1677 prefixes = textprefixes
1674 prefixes = textprefixes
1678 if head:
1675 if head:
1679 prefixes = headprefixes
1676 prefixes = headprefixes
1680 for prefix, label in prefixes:
1677 for prefix, label in prefixes:
1681 if stripline.startswith(prefix):
1678 if stripline.startswith(prefix):
1682 yield (stripline, label)
1679 yield (stripline, label)
1683 break
1680 break
1684 else:
1681 else:
1685 yield (line, '')
1682 yield (line, '')
1686 if line != stripline:
1683 if line != stripline:
1687 yield (line[len(stripline):], 'diff.trailingwhitespace')
1684 yield (line[len(stripline):], 'diff.trailingwhitespace')
1688
1685
1689 def diffui(*args, **kw):
1686 def diffui(*args, **kw):
1690 '''like diff(), but yields 2-tuples of (output, label) for ui.write()'''
1687 '''like diff(), but yields 2-tuples of (output, label) for ui.write()'''
1691 return difflabel(diff, *args, **kw)
1688 return difflabel(diff, *args, **kw)
1692
1689
1693 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
1690 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
1694 copy, getfilectx, opts, losedatafn, prefix):
1691 copy, getfilectx, opts, losedatafn, prefix):
1695
1692
1696 def join(f):
1693 def join(f):
1697 return posixpath.join(prefix, f)
1694 return posixpath.join(prefix, f)
1698
1695
1699 def addmodehdr(header, omode, nmode):
1696 def addmodehdr(header, omode, nmode):
1700 if omode != nmode:
1697 if omode != nmode:
1701 header.append('old mode %s\n' % omode)
1698 header.append('old mode %s\n' % omode)
1702 header.append('new mode %s\n' % nmode)
1699 header.append('new mode %s\n' % nmode)
1703
1700
1704 def addindexmeta(meta, revs):
1701 def addindexmeta(meta, revs):
1705 if opts.git:
1702 if opts.git:
1706 i = len(revs)
1703 i = len(revs)
1707 if i==2:
1704 if i==2:
1708 meta.append('index %s..%s\n' % tuple(revs))
1705 meta.append('index %s..%s\n' % tuple(revs))
1709 elif i==3:
1706 elif i==3:
1710 meta.append('index %s,%s..%s\n' % tuple(revs))
1707 meta.append('index %s,%s..%s\n' % tuple(revs))
1711
1708
1712 def gitindex(text):
1709 def gitindex(text):
1713 if not text:
1710 if not text:
1714 text = ""
1711 text = ""
1715 l = len(text)
1712 l = len(text)
1716 s = util.sha1('blob %d\0' % l)
1713 s = util.sha1('blob %d\0' % l)
1717 s.update(text)
1714 s.update(text)
1718 return s.hexdigest()
1715 return s.hexdigest()
1719
1716
1720 def diffline(a, b, revs):
1717 def diffline(a, b, revs):
1721 if opts.git:
1718 if opts.git:
1722 line = 'diff --git a/%s b/%s\n' % (a, b)
1719 line = 'diff --git a/%s b/%s\n' % (a, b)
1723 elif not repo.ui.quiet:
1720 elif not repo.ui.quiet:
1724 if revs:
1721 if revs:
1725 revinfo = ' '.join(["-r %s" % rev for rev in revs])
1722 revinfo = ' '.join(["-r %s" % rev for rev in revs])
1726 line = 'diff %s %s\n' % (revinfo, a)
1723 line = 'diff %s %s\n' % (revinfo, a)
1727 else:
1724 else:
1728 line = 'diff %s\n' % a
1725 line = 'diff %s\n' % a
1729 else:
1726 else:
1730 line = ''
1727 line = ''
1731 return line
1728 return line
1732
1729
1733 date1 = util.datestr(ctx1.date())
1730 date1 = util.datestr(ctx1.date())
1734 man1 = ctx1.manifest()
1731 man1 = ctx1.manifest()
1735
1732
1736 gone = set()
1733 gone = set()
1737 gitmode = {'l': '120000', 'x': '100755', '': '100644'}
1734 gitmode = {'l': '120000', 'x': '100755', '': '100644'}
1738
1735
1739 copyto = dict([(v, k) for k, v in copy.items()])
1736 copyto = dict([(v, k) for k, v in copy.items()])
1740
1737
1741 if opts.git:
1738 if opts.git:
1742 revs = None
1739 revs = None
1743
1740
1744 for f in sorted(modified + added + removed):
1741 for f in sorted(modified + added + removed):
1745 to = None
1742 to = None
1746 tn = None
1743 tn = None
1747 dodiff = True
1744 dodiff = True
1748 header = []
1745 header = []
1749 if f in man1:
1746 if f in man1:
1750 to = getfilectx(f, ctx1).data()
1747 to = getfilectx(f, ctx1).data()
1751 if f not in removed:
1748 if f not in removed:
1752 tn = getfilectx(f, ctx2).data()
1749 tn = getfilectx(f, ctx2).data()
1753 a, b = f, f
1750 a, b = f, f
1754 if opts.git or losedatafn:
1751 if opts.git or losedatafn:
1755 if f in added or (f in modified and to is None):
1752 if f in added or (f in modified and to is None):
1756 mode = gitmode[ctx2.flags(f)]
1753 mode = gitmode[ctx2.flags(f)]
1757 if f in copy or f in copyto:
1754 if f in copy or f in copyto:
1758 if opts.git:
1755 if opts.git:
1759 if f in copy:
1756 if f in copy:
1760 a = copy[f]
1757 a = copy[f]
1761 else:
1758 else:
1762 a = copyto[f]
1759 a = copyto[f]
1763 omode = gitmode[man1.flags(a)]
1760 omode = gitmode[man1.flags(a)]
1764 addmodehdr(header, omode, mode)
1761 addmodehdr(header, omode, mode)
1765 if a in removed and a not in gone:
1762 if a in removed and a not in gone:
1766 op = 'rename'
1763 op = 'rename'
1767 gone.add(a)
1764 gone.add(a)
1768 else:
1765 else:
1769 op = 'copy'
1766 op = 'copy'
1770 header.append('%s from %s\n' % (op, join(a)))
1767 header.append('%s from %s\n' % (op, join(a)))
1771 header.append('%s to %s\n' % (op, join(f)))
1768 header.append('%s to %s\n' % (op, join(f)))
1772 to = getfilectx(a, ctx1).data()
1769 to = getfilectx(a, ctx1).data()
1773 else:
1770 else:
1774 losedatafn(f)
1771 losedatafn(f)
1775 else:
1772 else:
1776 if opts.git:
1773 if opts.git:
1777 header.append('new file mode %s\n' % mode)
1774 header.append('new file mode %s\n' % mode)
1778 elif ctx2.flags(f):
1775 elif ctx2.flags(f):
1779 losedatafn(f)
1776 losedatafn(f)
1780 # In theory, if tn was copied or renamed we should check
1777 # In theory, if tn was copied or renamed we should check
1781 # if the source is binary too but the copy record already
1778 # if the source is binary too but the copy record already
1782 # forces git mode.
1779 # forces git mode.
1783 if util.binary(tn):
1780 if util.binary(tn):
1784 if opts.git:
1781 if opts.git:
1785 dodiff = 'binary'
1782 dodiff = 'binary'
1786 else:
1783 else:
1787 losedatafn(f)
1784 losedatafn(f)
1788 if not opts.git and not tn:
1785 if not opts.git and not tn:
1789 # regular diffs cannot represent new empty file
1786 # regular diffs cannot represent new empty file
1790 losedatafn(f)
1787 losedatafn(f)
1791 elif f in removed or (f in modified and tn is None):
1788 elif f in removed or (f in modified and tn is None):
1792 if opts.git:
1789 if opts.git:
1793 # have we already reported a copy above?
1790 # have we already reported a copy above?
1794 if ((f in copy and copy[f] in added
1791 if ((f in copy and copy[f] in added
1795 and copyto[copy[f]] == f) or
1792 and copyto[copy[f]] == f) or
1796 (f in copyto and copyto[f] in added
1793 (f in copyto and copyto[f] in added
1797 and copy[copyto[f]] == f)):
1794 and copy[copyto[f]] == f)):
1798 dodiff = False
1795 dodiff = False
1799 else:
1796 else:
1800 header.append('deleted file mode %s\n' %
1797 header.append('deleted file mode %s\n' %
1801 gitmode[man1.flags(f)])
1798 gitmode[man1.flags(f)])
1802 if util.binary(to):
1799 if util.binary(to):
1803 dodiff = 'binary'
1800 dodiff = 'binary'
1804 elif not to or util.binary(to):
1801 elif not to or util.binary(to):
1805 # regular diffs cannot represent empty file deletion
1802 # regular diffs cannot represent empty file deletion
1806 losedatafn(f)
1803 losedatafn(f)
1807 else:
1804 else:
1808 oflag = man1.flags(f)
1805 oflag = man1.flags(f)
1809 nflag = ctx2.flags(f)
1806 nflag = ctx2.flags(f)
1810 binary = util.binary(to) or util.binary(tn)
1807 binary = util.binary(to) or util.binary(tn)
1811 if opts.git:
1808 if opts.git:
1812 addmodehdr(header, gitmode[oflag], gitmode[nflag])
1809 addmodehdr(header, gitmode[oflag], gitmode[nflag])
1813 if binary:
1810 if binary:
1814 dodiff = 'binary'
1811 dodiff = 'binary'
1815 elif binary or nflag != oflag:
1812 elif binary or nflag != oflag:
1816 losedatafn(f)
1813 losedatafn(f)
1817
1814
1818 if dodiff:
1815 if dodiff:
1819 if opts.git or revs:
1816 if opts.git or revs:
1820 header.insert(0, diffline(join(a), join(b), revs))
1817 header.insert(0, diffline(join(a), join(b), revs))
1821 if dodiff == 'binary':
1818 if dodiff == 'binary':
1822 text = mdiff.b85diff(to, tn)
1819 text = mdiff.b85diff(to, tn)
1823 if text:
1820 if text:
1824 addindexmeta(header, [gitindex(to), gitindex(tn)])
1821 addindexmeta(header, [gitindex(to), gitindex(tn)])
1825 else:
1822 else:
1826 text = mdiff.unidiff(to, date1,
1823 text = mdiff.unidiff(to, date1,
1827 # ctx2 date may be dynamic
1824 # ctx2 date may be dynamic
1828 tn, util.datestr(ctx2.date()),
1825 tn, util.datestr(ctx2.date()),
1829 join(a), join(b), opts=opts)
1826 join(a), join(b), opts=opts)
1830 if header and (text or len(header) > 1):
1827 if header and (text or len(header) > 1):
1831 yield ''.join(header)
1828 yield ''.join(header)
1832 if text:
1829 if text:
1833 yield text
1830 yield text
1834
1831
1835 def diffstatsum(stats):
1832 def diffstatsum(stats):
1836 maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False
1833 maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False
1837 for f, a, r, b in stats:
1834 for f, a, r, b in stats:
1838 maxfile = max(maxfile, encoding.colwidth(f))
1835 maxfile = max(maxfile, encoding.colwidth(f))
1839 maxtotal = max(maxtotal, a + r)
1836 maxtotal = max(maxtotal, a + r)
1840 addtotal += a
1837 addtotal += a
1841 removetotal += r
1838 removetotal += r
1842 binary = binary or b
1839 binary = binary or b
1843
1840
1844 return maxfile, maxtotal, addtotal, removetotal, binary
1841 return maxfile, maxtotal, addtotal, removetotal, binary
1845
1842
1846 def diffstatdata(lines):
1843 def diffstatdata(lines):
1847 diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$')
1844 diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$')
1848
1845
1849 results = []
1846 results = []
1850 filename, adds, removes, isbinary = None, 0, 0, False
1847 filename, adds, removes, isbinary = None, 0, 0, False
1851
1848
1852 def addresult():
1849 def addresult():
1853 if filename:
1850 if filename:
1854 results.append((filename, adds, removes, isbinary))
1851 results.append((filename, adds, removes, isbinary))
1855
1852
1856 for line in lines:
1853 for line in lines:
1857 if line.startswith('diff'):
1854 if line.startswith('diff'):
1858 addresult()
1855 addresult()
1859 # set numbers to 0 anyway when starting new file
1856 # set numbers to 0 anyway when starting new file
1860 adds, removes, isbinary = 0, 0, False
1857 adds, removes, isbinary = 0, 0, False
1861 if line.startswith('diff --git a/'):
1858 if line.startswith('diff --git a/'):
1862 filename = gitre.search(line).group(2)
1859 filename = gitre.search(line).group(2)
1863 elif line.startswith('diff -r'):
1860 elif line.startswith('diff -r'):
1864 # format: "diff -r ... -r ... filename"
1861 # format: "diff -r ... -r ... filename"
1865 filename = diffre.search(line).group(1)
1862 filename = diffre.search(line).group(1)
1866 elif line.startswith('+') and not line.startswith('+++ '):
1863 elif line.startswith('+') and not line.startswith('+++ '):
1867 adds += 1
1864 adds += 1
1868 elif line.startswith('-') and not line.startswith('--- '):
1865 elif line.startswith('-') and not line.startswith('--- '):
1869 removes += 1
1866 removes += 1
1870 elif (line.startswith('GIT binary patch') or
1867 elif (line.startswith('GIT binary patch') or
1871 line.startswith('Binary file')):
1868 line.startswith('Binary file')):
1872 isbinary = True
1869 isbinary = True
1873 addresult()
1870 addresult()
1874 return results
1871 return results
1875
1872
1876 def diffstat(lines, width=80, git=False):
1873 def diffstat(lines, width=80, git=False):
1877 output = []
1874 output = []
1878 stats = diffstatdata(lines)
1875 stats = diffstatdata(lines)
1879 maxname, maxtotal, totaladds, totalremoves, hasbinary = diffstatsum(stats)
1876 maxname, maxtotal, totaladds, totalremoves, hasbinary = diffstatsum(stats)
1880
1877
1881 countwidth = len(str(maxtotal))
1878 countwidth = len(str(maxtotal))
1882 if hasbinary and countwidth < 3:
1879 if hasbinary and countwidth < 3:
1883 countwidth = 3
1880 countwidth = 3
1884 graphwidth = width - countwidth - maxname - 6
1881 graphwidth = width - countwidth - maxname - 6
1885 if graphwidth < 10:
1882 if graphwidth < 10:
1886 graphwidth = 10
1883 graphwidth = 10
1887
1884
1888 def scale(i):
1885 def scale(i):
1889 if maxtotal <= graphwidth:
1886 if maxtotal <= graphwidth:
1890 return i
1887 return i
1891 # If diffstat runs out of room it doesn't print anything,
1888 # If diffstat runs out of room it doesn't print anything,
1892 # which isn't very useful, so always print at least one + or -
1889 # which isn't very useful, so always print at least one + or -
1893 # if there were at least some changes.
1890 # if there were at least some changes.
1894 return max(i * graphwidth // maxtotal, int(bool(i)))
1891 return max(i * graphwidth // maxtotal, int(bool(i)))
1895
1892
1896 for filename, adds, removes, isbinary in stats:
1893 for filename, adds, removes, isbinary in stats:
1897 if isbinary:
1894 if isbinary:
1898 count = 'Bin'
1895 count = 'Bin'
1899 else:
1896 else:
1900 count = adds + removes
1897 count = adds + removes
1901 pluses = '+' * scale(adds)
1898 pluses = '+' * scale(adds)
1902 minuses = '-' * scale(removes)
1899 minuses = '-' * scale(removes)
1903 output.append(' %s%s | %*s %s%s\n' %
1900 output.append(' %s%s | %*s %s%s\n' %
1904 (filename, ' ' * (maxname - encoding.colwidth(filename)),
1901 (filename, ' ' * (maxname - encoding.colwidth(filename)),
1905 countwidth, count, pluses, minuses))
1902 countwidth, count, pluses, minuses))
1906
1903
1907 if stats:
1904 if stats:
1908 output.append(_(' %d files changed, %d insertions(+), '
1905 output.append(_(' %d files changed, %d insertions(+), '
1909 '%d deletions(-)\n')
1906 '%d deletions(-)\n')
1910 % (len(stats), totaladds, totalremoves))
1907 % (len(stats), totaladds, totalremoves))
1911
1908
1912 return ''.join(output)
1909 return ''.join(output)
1913
1910
1914 def diffstatui(*args, **kw):
1911 def diffstatui(*args, **kw):
1915 '''like diffstat(), but yields 2-tuples of (output, label) for
1912 '''like diffstat(), but yields 2-tuples of (output, label) for
1916 ui.write()
1913 ui.write()
1917 '''
1914 '''
1918
1915
1919 for line in diffstat(*args, **kw).splitlines():
1916 for line in diffstat(*args, **kw).splitlines():
1920 if line and line[-1] in '+-':
1917 if line and line[-1] in '+-':
1921 name, graph = line.rsplit(' ', 1)
1918 name, graph = line.rsplit(' ', 1)
1922 yield (name + ' ', '')
1919 yield (name + ' ', '')
1923 m = re.search(r'\++', graph)
1920 m = re.search(r'\++', graph)
1924 if m:
1921 if m:
1925 yield (m.group(0), 'diffstat.inserted')
1922 yield (m.group(0), 'diffstat.inserted')
1926 m = re.search(r'-+', graph)
1923 m = re.search(r'-+', graph)
1927 if m:
1924 if m:
1928 yield (m.group(0), 'diffstat.deleted')
1925 yield (m.group(0), 'diffstat.deleted')
1929 else:
1926 else:
1930 yield (line, '')
1927 yield (line, '')
1931 yield ('\n', '')
1928 yield ('\n', '')
@@ -1,332 +1,332 b''
1 Show all commands except debug commands
1 Show all commands except debug commands
2 $ hg debugcomplete
2 $ hg debugcomplete
3 add
3 add
4 addremove
4 addremove
5 annotate
5 annotate
6 archive
6 archive
7 backout
7 backout
8 bisect
8 bisect
9 bookmarks
9 bookmarks
10 branch
10 branch
11 branches
11 branches
12 bundle
12 bundle
13 cat
13 cat
14 clone
14 clone
15 commit
15 commit
16 config
16 config
17 copy
17 copy
18 diff
18 diff
19 export
19 export
20 forget
20 forget
21 graft
21 graft
22 grep
22 grep
23 heads
23 heads
24 help
24 help
25 identify
25 identify
26 import
26 import
27 incoming
27 incoming
28 init
28 init
29 locate
29 locate
30 log
30 log
31 manifest
31 manifest
32 merge
32 merge
33 outgoing
33 outgoing
34 parents
34 parents
35 paths
35 paths
36 phase
36 phase
37 pull
37 pull
38 push
38 push
39 recover
39 recover
40 remove
40 remove
41 rename
41 rename
42 resolve
42 resolve
43 revert
43 revert
44 rollback
44 rollback
45 root
45 root
46 serve
46 serve
47 status
47 status
48 summary
48 summary
49 tag
49 tag
50 tags
50 tags
51 tip
51 tip
52 unbundle
52 unbundle
53 update
53 update
54 verify
54 verify
55 version
55 version
56
56
57 Show all commands that start with "a"
57 Show all commands that start with "a"
58 $ hg debugcomplete a
58 $ hg debugcomplete a
59 add
59 add
60 addremove
60 addremove
61 annotate
61 annotate
62 archive
62 archive
63
63
64 Do not show debug commands if there are other candidates
64 Do not show debug commands if there are other candidates
65 $ hg debugcomplete d
65 $ hg debugcomplete d
66 diff
66 diff
67
67
68 Show debug commands if there are no other candidates
68 Show debug commands if there are no other candidates
69 $ hg debugcomplete debug
69 $ hg debugcomplete debug
70 debugancestor
70 debugancestor
71 debugbuilddag
71 debugbuilddag
72 debugbundle
72 debugbundle
73 debugcheckstate
73 debugcheckstate
74 debugcommands
74 debugcommands
75 debugcomplete
75 debugcomplete
76 debugconfig
76 debugconfig
77 debugdag
77 debugdag
78 debugdata
78 debugdata
79 debugdate
79 debugdate
80 debugdirstate
80 debugdirstate
81 debugdiscovery
81 debugdiscovery
82 debugfileset
82 debugfileset
83 debugfsinfo
83 debugfsinfo
84 debuggetbundle
84 debuggetbundle
85 debugignore
85 debugignore
86 debugindex
86 debugindex
87 debugindexdot
87 debugindexdot
88 debuginstall
88 debuginstall
89 debugknown
89 debugknown
90 debuglabelcomplete
90 debuglabelcomplete
91 debugobsolete
91 debugobsolete
92 debugpathcomplete
92 debugpathcomplete
93 debugpushkey
93 debugpushkey
94 debugpvec
94 debugpvec
95 debugrebuilddirstate
95 debugrebuilddirstate
96 debugrename
96 debugrename
97 debugrevlog
97 debugrevlog
98 debugrevspec
98 debugrevspec
99 debugsetparents
99 debugsetparents
100 debugsub
100 debugsub
101 debugsuccessorssets
101 debugsuccessorssets
102 debugwalk
102 debugwalk
103 debugwireargs
103 debugwireargs
104
104
105 Do not show the alias of a debug command if there are other candidates
105 Do not show the alias of a debug command if there are other candidates
106 (this should hide rawcommit)
106 (this should hide rawcommit)
107 $ hg debugcomplete r
107 $ hg debugcomplete r
108 recover
108 recover
109 remove
109 remove
110 rename
110 rename
111 resolve
111 resolve
112 revert
112 revert
113 rollback
113 rollback
114 root
114 root
115 Show the alias of a debug command if there are no other candidates
115 Show the alias of a debug command if there are no other candidates
116 $ hg debugcomplete rawc
116 $ hg debugcomplete rawc
117
117
118
118
119 Show the global options
119 Show the global options
120 $ hg debugcomplete --options | sort
120 $ hg debugcomplete --options | sort
121 --config
121 --config
122 --cwd
122 --cwd
123 --debug
123 --debug
124 --debugger
124 --debugger
125 --encoding
125 --encoding
126 --encodingmode
126 --encodingmode
127 --help
127 --help
128 --hidden
128 --hidden
129 --noninteractive
129 --noninteractive
130 --profile
130 --profile
131 --quiet
131 --quiet
132 --repository
132 --repository
133 --time
133 --time
134 --traceback
134 --traceback
135 --verbose
135 --verbose
136 --version
136 --version
137 -R
137 -R
138 -h
138 -h
139 -q
139 -q
140 -v
140 -v
141 -y
141 -y
142
142
143 Show the options for the "serve" command
143 Show the options for the "serve" command
144 $ hg debugcomplete --options serve | sort
144 $ hg debugcomplete --options serve | sort
145 --accesslog
145 --accesslog
146 --address
146 --address
147 --certificate
147 --certificate
148 --cmdserver
148 --cmdserver
149 --config
149 --config
150 --cwd
150 --cwd
151 --daemon
151 --daemon
152 --daemon-pipefds
152 --daemon-pipefds
153 --debug
153 --debug
154 --debugger
154 --debugger
155 --encoding
155 --encoding
156 --encodingmode
156 --encodingmode
157 --errorlog
157 --errorlog
158 --help
158 --help
159 --hidden
159 --hidden
160 --ipv6
160 --ipv6
161 --name
161 --name
162 --noninteractive
162 --noninteractive
163 --pid-file
163 --pid-file
164 --port
164 --port
165 --prefix
165 --prefix
166 --profile
166 --profile
167 --quiet
167 --quiet
168 --repository
168 --repository
169 --stdio
169 --stdio
170 --style
170 --style
171 --templates
171 --templates
172 --time
172 --time
173 --traceback
173 --traceback
174 --verbose
174 --verbose
175 --version
175 --version
176 --web-conf
176 --web-conf
177 -6
177 -6
178 -A
178 -A
179 -E
179 -E
180 -R
180 -R
181 -a
181 -a
182 -d
182 -d
183 -h
183 -h
184 -n
184 -n
185 -p
185 -p
186 -q
186 -q
187 -t
187 -t
188 -v
188 -v
189 -y
189 -y
190
190
191 Show an error if we use --options with an ambiguous abbreviation
191 Show an error if we use --options with an ambiguous abbreviation
192 $ hg debugcomplete --options s
192 $ hg debugcomplete --options s
193 hg: command 's' is ambiguous:
193 hg: command 's' is ambiguous:
194 serve showconfig status summary
194 serve showconfig status summary
195 [255]
195 [255]
196
196
197 Show all commands + options
197 Show all commands + options
198 $ hg debugcommands
198 $ hg debugcommands
199 add: include, exclude, subrepos, dry-run
199 add: include, exclude, subrepos, dry-run
200 annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude
200 annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude
201 clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
201 clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
202 commit: addremove, close-branch, amend, secret, edit, include, exclude, message, logfile, date, user, subrepos
202 commit: addremove, close-branch, amend, secret, edit, include, exclude, message, logfile, date, user, subrepos
203 diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
203 diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
204 export: output, switch-parent, rev, text, git, nodates
204 export: output, switch-parent, rev, text, git, nodates
205 forget: include, exclude
205 forget: include, exclude
206 init: ssh, remotecmd, insecure
206 init: ssh, remotecmd, insecure
207 log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude
207 log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude
208 merge: force, rev, preview, tool
208 merge: force, rev, preview, tool
209 pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
209 pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
210 push: force, rev, bookmark, branch, new-branch, ssh, remotecmd, insecure
210 push: force, rev, bookmark, branch, new-branch, ssh, remotecmd, insecure
211 remove: after, force, include, exclude
211 remove: after, force, include, exclude
212 serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate
212 serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate
213 status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, include, exclude, subrepos
213 status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, include, exclude, subrepos
214 summary: remote
214 summary: remote
215 update: clean, check, date, rev, tool
215 update: clean, check, date, rev, tool
216 addremove: similarity, include, exclude, dry-run
216 addremove: similarity, include, exclude, dry-run
217 archive: no-decode, prefix, rev, type, subrepos, include, exclude
217 archive: no-decode, prefix, rev, type, subrepos, include, exclude
218 backout: merge, parent, rev, tool, include, exclude, message, logfile, date, user
218 backout: merge, parent, rev, tool, include, exclude, message, logfile, date, user
219 bisect: reset, good, bad, skip, extend, command, noupdate
219 bisect: reset, good, bad, skip, extend, command, noupdate
220 bookmarks: force, rev, delete, rename, inactive
220 bookmarks: force, rev, delete, rename, inactive
221 branch: force, clean
221 branch: force, clean
222 branches: active, closed
222 branches: active, closed
223 bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
223 bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
224 cat: output, rev, decode, include, exclude
224 cat: output, rev, decode, include, exclude
225 config: untrusted, edit, local, global
225 config: untrusted, edit, local, global
226 copy: after, force, include, exclude, dry-run
226 copy: after, force, include, exclude, dry-run
227 debugancestor:
227 debugancestor:
228 debugbuilddag: mergeable-file, overwritten-file, new-file
228 debugbuilddag: mergeable-file, overwritten-file, new-file
229 debugbundle: all
229 debugbundle: all
230 debugcheckstate:
230 debugcheckstate:
231 debugcommands:
231 debugcommands:
232 debugcomplete: options
232 debugcomplete: options
233 debugdag: tags, branches, dots, spaces
233 debugdag: tags, branches, dots, spaces
234 debugdata: changelog, manifest
234 debugdata: changelog, manifest
235 debugdate: extended
235 debugdate: extended
236 debugdirstate: nodates, datesort
236 debugdirstate: nodates, datesort
237 debugdiscovery: old, nonheads, ssh, remotecmd, insecure
237 debugdiscovery: old, nonheads, ssh, remotecmd, insecure
238 debugfileset: rev
238 debugfileset: rev
239 debugfsinfo:
239 debugfsinfo:
240 debuggetbundle: head, common, type
240 debuggetbundle: head, common, type
241 debugignore:
241 debugignore:
242 debugindex: changelog, manifest, format
242 debugindex: changelog, manifest, format
243 debugindexdot:
243 debugindexdot:
244 debuginstall:
244 debuginstall:
245 debugknown:
245 debugknown:
246 debuglabelcomplete:
246 debuglabelcomplete:
247 debugobsolete: flags, date, user
247 debugobsolete: flags, date, user
248 debugpathcomplete: full, normal, added, removed
248 debugpathcomplete: full, normal, added, removed
249 debugpushkey:
249 debugpushkey:
250 debugpvec:
250 debugpvec:
251 debugrebuilddirstate: rev
251 debugrebuilddirstate: rev
252 debugrename: rev
252 debugrename: rev
253 debugrevlog: changelog, manifest, dump
253 debugrevlog: changelog, manifest, dump
254 debugrevspec: optimize
254 debugrevspec: optimize
255 debugsetparents:
255 debugsetparents:
256 debugsub: rev
256 debugsub: rev
257 debugsuccessorssets:
257 debugsuccessorssets:
258 debugwalk: include, exclude
258 debugwalk: include, exclude
259 debugwireargs: three, four, five, ssh, remotecmd, insecure
259 debugwireargs: three, four, five, ssh, remotecmd, insecure
260 graft: rev, continue, edit, log, currentdate, currentuser, date, user, tool, dry-run
260 graft: rev, continue, edit, log, currentdate, currentuser, date, user, tool, dry-run
261 grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
261 grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
262 heads: rev, topo, active, closed, style, template
262 heads: rev, topo, active, closed, style, template
263 help: extension, command, keyword
263 help: extension, command, keyword
264 identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
264 identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
265 import: strip, base, edit, force, no-commit, bypass, exact, import-branch, message, logfile, date, user, similarity
265 import: strip, base, edit, force, no-commit, bypass, partial, exact, import-branch, message, logfile, date, user, similarity
266 incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
266 incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
267 locate: rev, print0, fullpath, include, exclude
267 locate: rev, print0, fullpath, include, exclude
268 manifest: rev, all
268 manifest: rev, all
269 outgoing: force, rev, newest-first, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
269 outgoing: force, rev, newest-first, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos
270 parents: rev, style, template
270 parents: rev, style, template
271 paths:
271 paths:
272 phase: public, draft, secret, force, rev
272 phase: public, draft, secret, force, rev
273 recover:
273 recover:
274 rename: after, force, include, exclude, dry-run
274 rename: after, force, include, exclude, dry-run
275 resolve: all, list, mark, unmark, no-status, tool, include, exclude
275 resolve: all, list, mark, unmark, no-status, tool, include, exclude
276 revert: all, date, rev, no-backup, include, exclude, dry-run
276 revert: all, date, rev, no-backup, include, exclude, dry-run
277 rollback: dry-run, force
277 rollback: dry-run, force
278 root:
278 root:
279 tag: force, local, rev, remove, edit, message, date, user
279 tag: force, local, rev, remove, edit, message, date, user
280 tags:
280 tags:
281 tip: patch, git, style, template
281 tip: patch, git, style, template
282 unbundle: update
282 unbundle: update
283 verify:
283 verify:
284 version:
284 version:
285
285
286 $ hg init a
286 $ hg init a
287 $ cd a
287 $ cd a
288 $ echo fee > fee
288 $ echo fee > fee
289 $ hg ci -q -Amfee
289 $ hg ci -q -Amfee
290 $ hg tag fee
290 $ hg tag fee
291 $ mkdir fie
291 $ mkdir fie
292 $ echo dead > fie/dead
292 $ echo dead > fie/dead
293 $ echo live > fie/live
293 $ echo live > fie/live
294 $ hg bookmark fo
294 $ hg bookmark fo
295 $ hg branch -q fie
295 $ hg branch -q fie
296 $ hg ci -q -Amfie
296 $ hg ci -q -Amfie
297 $ echo fo > fo
297 $ echo fo > fo
298 $ hg branch -qf default
298 $ hg branch -qf default
299 $ hg ci -q -Amfo
299 $ hg ci -q -Amfo
300 $ echo Fum > Fum
300 $ echo Fum > Fum
301 $ hg ci -q -AmFum
301 $ hg ci -q -AmFum
302 $ hg bookmark Fum
302 $ hg bookmark Fum
303
303
304 Test debugpathcomplete
304 Test debugpathcomplete
305
305
306 $ hg debugpathcomplete f
306 $ hg debugpathcomplete f
307 fee
307 fee
308 fie
308 fie
309 fo
309 fo
310 $ hg debugpathcomplete -f f
310 $ hg debugpathcomplete -f f
311 fee
311 fee
312 fie/dead
312 fie/dead
313 fie/live
313 fie/live
314 fo
314 fo
315
315
316 $ hg rm Fum
316 $ hg rm Fum
317 $ hg debugpathcomplete -r F
317 $ hg debugpathcomplete -r F
318 Fum
318 Fum
319
319
320 Test debuglabelcomplete
320 Test debuglabelcomplete
321
321
322 $ hg debuglabelcomplete
322 $ hg debuglabelcomplete
323 Fum
323 Fum
324 default
324 default
325 fee
325 fee
326 fie
326 fie
327 fo
327 fo
328 tip
328 tip
329 $ hg debuglabelcomplete f
329 $ hg debuglabelcomplete f
330 fee
330 fee
331 fie
331 fie
332 fo
332 fo
@@ -1,1185 +1,1452 b''
1 $ hg init a
1 $ hg init a
2 $ mkdir a/d1
2 $ mkdir a/d1
3 $ mkdir a/d1/d2
3 $ mkdir a/d1/d2
4 $ echo line 1 > a/a
4 $ echo line 1 > a/a
5 $ echo line 1 > a/d1/d2/a
5 $ echo line 1 > a/d1/d2/a
6 $ hg --cwd a ci -Ama
6 $ hg --cwd a ci -Ama
7 adding a
7 adding a
8 adding d1/d2/a
8 adding d1/d2/a
9
9
10 $ echo line 2 >> a/a
10 $ echo line 2 >> a/a
11 $ hg --cwd a ci -u someone -d '1 0' -m'second change'
11 $ hg --cwd a ci -u someone -d '1 0' -m'second change'
12
12
13 import with no args:
13 import with no args:
14
14
15 $ hg --cwd a import
15 $ hg --cwd a import
16 abort: need at least one patch to import
16 abort: need at least one patch to import
17 [255]
17 [255]
18
18
19 generate patches for the test
19 generate patches for the test
20
20
21 $ hg --cwd a export tip > exported-tip.patch
21 $ hg --cwd a export tip > exported-tip.patch
22 $ hg --cwd a diff -r0:1 > diffed-tip.patch
22 $ hg --cwd a diff -r0:1 > diffed-tip.patch
23
23
24
24
25 import exported patch
25 import exported patch
26 (this also tests that editor is not invoked, if the patch contains the
26 (this also tests that editor is not invoked, if the patch contains the
27 commit message and '--edit' is not specified)
27 commit message and '--edit' is not specified)
28
28
29 $ hg clone -r0 a b
29 $ hg clone -r0 a b
30 adding changesets
30 adding changesets
31 adding manifests
31 adding manifests
32 adding file changes
32 adding file changes
33 added 1 changesets with 2 changes to 2 files
33 added 1 changesets with 2 changes to 2 files
34 updating to branch default
34 updating to branch default
35 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
35 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
36 $ HGEDITOR=cat hg --cwd b import ../exported-tip.patch
36 $ HGEDITOR=cat hg --cwd b import ../exported-tip.patch
37 applying ../exported-tip.patch
37 applying ../exported-tip.patch
38
38
39 message and committer and date should be same
39 message and committer and date should be same
40
40
41 $ hg --cwd b tip
41 $ hg --cwd b tip
42 changeset: 1:1d4bd90af0e4
42 changeset: 1:1d4bd90af0e4
43 tag: tip
43 tag: tip
44 user: someone
44 user: someone
45 date: Thu Jan 01 00:00:01 1970 +0000
45 date: Thu Jan 01 00:00:01 1970 +0000
46 summary: second change
46 summary: second change
47
47
48 $ rm -r b
48 $ rm -r b
49
49
50
50
51 import exported patch with external patcher
51 import exported patch with external patcher
52 (this also tests that editor is invoked, if the '--edit' is specified,
52 (this also tests that editor is invoked, if the '--edit' is specified,
53 regardless of the commit message in the patch)
53 regardless of the commit message in the patch)
54
54
55 $ cat > dummypatch.py <<EOF
55 $ cat > dummypatch.py <<EOF
56 > print 'patching file a'
56 > print 'patching file a'
57 > file('a', 'wb').write('line2\n')
57 > file('a', 'wb').write('line2\n')
58 > EOF
58 > EOF
59 $ hg clone -r0 a b
59 $ hg clone -r0 a b
60 adding changesets
60 adding changesets
61 adding manifests
61 adding manifests
62 adding file changes
62 adding file changes
63 added 1 changesets with 2 changes to 2 files
63 added 1 changesets with 2 changes to 2 files
64 updating to branch default
64 updating to branch default
65 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
65 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
66 $ HGEDITOR=cat hg --config ui.patch='python ../dummypatch.py' --cwd b import --edit ../exported-tip.patch
66 $ HGEDITOR=cat hg --config ui.patch='python ../dummypatch.py' --cwd b import --edit ../exported-tip.patch
67 applying ../exported-tip.patch
67 applying ../exported-tip.patch
68 second change
68 second change
69
69
70
70
71 HG: Enter commit message. Lines beginning with 'HG:' are removed.
71 HG: Enter commit message. Lines beginning with 'HG:' are removed.
72 HG: Leave message empty to abort commit.
72 HG: Leave message empty to abort commit.
73 HG: --
73 HG: --
74 HG: user: someone
74 HG: user: someone
75 HG: branch 'default'
75 HG: branch 'default'
76 HG: changed a
76 HG: changed a
77 $ cat b/a
77 $ cat b/a
78 line2
78 line2
79 $ rm -r b
79 $ rm -r b
80
80
81
81
82 import of plain diff should fail without message
82 import of plain diff should fail without message
83 (this also tests that editor is invoked, if the patch doesn't contain
83 (this also tests that editor is invoked, if the patch doesn't contain
84 the commit message, regardless of '--edit')
84 the commit message, regardless of '--edit')
85
85
86 $ hg clone -r0 a b
86 $ hg clone -r0 a b
87 adding changesets
87 adding changesets
88 adding manifests
88 adding manifests
89 adding file changes
89 adding file changes
90 added 1 changesets with 2 changes to 2 files
90 added 1 changesets with 2 changes to 2 files
91 updating to branch default
91 updating to branch default
92 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
92 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
93 $ HGEDITOR=cat hg --cwd b import ../diffed-tip.patch
93 $ HGEDITOR=cat hg --cwd b import ../diffed-tip.patch
94 applying ../diffed-tip.patch
94 applying ../diffed-tip.patch
95
95
96
96
97 HG: Enter commit message. Lines beginning with 'HG:' are removed.
97 HG: Enter commit message. Lines beginning with 'HG:' are removed.
98 HG: Leave message empty to abort commit.
98 HG: Leave message empty to abort commit.
99 HG: --
99 HG: --
100 HG: user: test
100 HG: user: test
101 HG: branch 'default'
101 HG: branch 'default'
102 HG: changed a
102 HG: changed a
103 abort: empty commit message
103 abort: empty commit message
104 [255]
104 [255]
105 $ rm -r b
105 $ rm -r b
106
106
107
107
108 import of plain diff should be ok with message
108 import of plain diff should be ok with message
109
109
110 $ hg clone -r0 a b
110 $ hg clone -r0 a b
111 adding changesets
111 adding changesets
112 adding manifests
112 adding manifests
113 adding file changes
113 adding file changes
114 added 1 changesets with 2 changes to 2 files
114 added 1 changesets with 2 changes to 2 files
115 updating to branch default
115 updating to branch default
116 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
116 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
117 $ hg --cwd b import -mpatch ../diffed-tip.patch
117 $ hg --cwd b import -mpatch ../diffed-tip.patch
118 applying ../diffed-tip.patch
118 applying ../diffed-tip.patch
119 $ rm -r b
119 $ rm -r b
120
120
121
121
122 import of plain diff with specific date and user
122 import of plain diff with specific date and user
123 (this also tests that editor is not invoked, if
123 (this also tests that editor is not invoked, if
124 '--message'/'--logfile' is specified and '--edit' is not)
124 '--message'/'--logfile' is specified and '--edit' is not)
125
125
126 $ hg clone -r0 a b
126 $ hg clone -r0 a b
127 adding changesets
127 adding changesets
128 adding manifests
128 adding manifests
129 adding file changes
129 adding file changes
130 added 1 changesets with 2 changes to 2 files
130 added 1 changesets with 2 changes to 2 files
131 updating to branch default
131 updating to branch default
132 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
132 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
133 $ hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../diffed-tip.patch
133 $ hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../diffed-tip.patch
134 applying ../diffed-tip.patch
134 applying ../diffed-tip.patch
135 $ hg -R b tip -pv
135 $ hg -R b tip -pv
136 changeset: 1:ca68f19f3a40
136 changeset: 1:ca68f19f3a40
137 tag: tip
137 tag: tip
138 user: user@nowhere.net
138 user: user@nowhere.net
139 date: Thu Jan 01 00:00:01 1970 +0000
139 date: Thu Jan 01 00:00:01 1970 +0000
140 files: a
140 files: a
141 description:
141 description:
142 patch
142 patch
143
143
144
144
145 diff -r 80971e65b431 -r ca68f19f3a40 a
145 diff -r 80971e65b431 -r ca68f19f3a40 a
146 --- a/a Thu Jan 01 00:00:00 1970 +0000
146 --- a/a Thu Jan 01 00:00:00 1970 +0000
147 +++ b/a Thu Jan 01 00:00:01 1970 +0000
147 +++ b/a Thu Jan 01 00:00:01 1970 +0000
148 @@ -1,1 +1,2 @@
148 @@ -1,1 +1,2 @@
149 line 1
149 line 1
150 +line 2
150 +line 2
151
151
152 $ rm -r b
152 $ rm -r b
153
153
154
154
155 import of plain diff should be ok with --no-commit
155 import of plain diff should be ok with --no-commit
156 (this also tests that editor is not invoked, if '--no-commit' is
156 (this also tests that editor is not invoked, if '--no-commit' is
157 specified, regardless of '--edit')
157 specified, regardless of '--edit')
158
158
159 $ hg clone -r0 a b
159 $ hg clone -r0 a b
160 adding changesets
160 adding changesets
161 adding manifests
161 adding manifests
162 adding file changes
162 adding file changes
163 added 1 changesets with 2 changes to 2 files
163 added 1 changesets with 2 changes to 2 files
164 updating to branch default
164 updating to branch default
165 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
165 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
166 $ HGEDITOR=cat hg --cwd b import --no-commit --edit ../diffed-tip.patch
166 $ HGEDITOR=cat hg --cwd b import --no-commit --edit ../diffed-tip.patch
167 applying ../diffed-tip.patch
167 applying ../diffed-tip.patch
168 $ hg --cwd b diff --nodates
168 $ hg --cwd b diff --nodates
169 diff -r 80971e65b431 a
169 diff -r 80971e65b431 a
170 --- a/a
170 --- a/a
171 +++ b/a
171 +++ b/a
172 @@ -1,1 +1,2 @@
172 @@ -1,1 +1,2 @@
173 line 1
173 line 1
174 +line 2
174 +line 2
175 $ rm -r b
175 $ rm -r b
176
176
177
177
178 import of malformed plain diff should fail
178 import of malformed plain diff should fail
179
179
180 $ hg clone -r0 a b
180 $ hg clone -r0 a b
181 adding changesets
181 adding changesets
182 adding manifests
182 adding manifests
183 adding file changes
183 adding file changes
184 added 1 changesets with 2 changes to 2 files
184 added 1 changesets with 2 changes to 2 files
185 updating to branch default
185 updating to branch default
186 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
186 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
187 $ sed 's/1,1/foo/' < diffed-tip.patch > broken.patch
187 $ sed 's/1,1/foo/' < diffed-tip.patch > broken.patch
188 $ hg --cwd b import -mpatch ../broken.patch
188 $ hg --cwd b import -mpatch ../broken.patch
189 applying ../broken.patch
189 applying ../broken.patch
190 abort: bad hunk #1
190 abort: bad hunk #1
191 [255]
191 [255]
192 $ rm -r b
192 $ rm -r b
193
193
194
194
195 hg -R repo import
195 hg -R repo import
196 put the clone in a subdir - having a directory named "a"
196 put the clone in a subdir - having a directory named "a"
197 used to hide a bug.
197 used to hide a bug.
198
198
199 $ mkdir dir
199 $ mkdir dir
200 $ hg clone -r0 a dir/b
200 $ hg clone -r0 a dir/b
201 adding changesets
201 adding changesets
202 adding manifests
202 adding manifests
203 adding file changes
203 adding file changes
204 added 1 changesets with 2 changes to 2 files
204 added 1 changesets with 2 changes to 2 files
205 updating to branch default
205 updating to branch default
206 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
206 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
207 $ cd dir
207 $ cd dir
208 $ hg -R b import ../exported-tip.patch
208 $ hg -R b import ../exported-tip.patch
209 applying ../exported-tip.patch
209 applying ../exported-tip.patch
210 $ cd ..
210 $ cd ..
211 $ rm -r dir
211 $ rm -r dir
212
212
213
213
214 import from stdin
214 import from stdin
215
215
216 $ hg clone -r0 a b
216 $ hg clone -r0 a b
217 adding changesets
217 adding changesets
218 adding manifests
218 adding manifests
219 adding file changes
219 adding file changes
220 added 1 changesets with 2 changes to 2 files
220 added 1 changesets with 2 changes to 2 files
221 updating to branch default
221 updating to branch default
222 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
222 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
223 $ hg --cwd b import - < exported-tip.patch
223 $ hg --cwd b import - < exported-tip.patch
224 applying patch from stdin
224 applying patch from stdin
225 $ rm -r b
225 $ rm -r b
226
226
227
227
228 import two patches in one stream
228 import two patches in one stream
229
229
230 $ hg init b
230 $ hg init b
231 $ hg --cwd a export 0:tip | hg --cwd b import -
231 $ hg --cwd a export 0:tip | hg --cwd b import -
232 applying patch from stdin
232 applying patch from stdin
233 $ hg --cwd a id
233 $ hg --cwd a id
234 1d4bd90af0e4 tip
234 1d4bd90af0e4 tip
235 $ hg --cwd b id
235 $ hg --cwd b id
236 1d4bd90af0e4 tip
236 1d4bd90af0e4 tip
237 $ rm -r b
237 $ rm -r b
238
238
239
239
240 override commit message
240 override commit message
241
241
242 $ hg clone -r0 a b
242 $ hg clone -r0 a b
243 adding changesets
243 adding changesets
244 adding manifests
244 adding manifests
245 adding file changes
245 adding file changes
246 added 1 changesets with 2 changes to 2 files
246 added 1 changesets with 2 changes to 2 files
247 updating to branch default
247 updating to branch default
248 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
248 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
249 $ hg --cwd b import -m 'override' - < exported-tip.patch
249 $ hg --cwd b import -m 'override' - < exported-tip.patch
250 applying patch from stdin
250 applying patch from stdin
251 $ hg --cwd b tip | grep override
251 $ hg --cwd b tip | grep override
252 summary: override
252 summary: override
253 $ rm -r b
253 $ rm -r b
254
254
255 $ cat > mkmsg.py <<EOF
255 $ cat > mkmsg.py <<EOF
256 > import email.Message, sys
256 > import email.Message, sys
257 > msg = email.Message.Message()
257 > msg = email.Message.Message()
258 > patch = open(sys.argv[1], 'rb').read()
258 > patch = open(sys.argv[1], 'rb').read()
259 > msg.set_payload('email commit message\n' + patch)
259 > msg.set_payload('email commit message\n' + patch)
260 > msg['Subject'] = 'email patch'
260 > msg['Subject'] = 'email patch'
261 > msg['From'] = 'email patcher'
261 > msg['From'] = 'email patcher'
262 > file(sys.argv[2], 'wb').write(msg.as_string())
262 > file(sys.argv[2], 'wb').write(msg.as_string())
263 > EOF
263 > EOF
264
264
265
265
266 plain diff in email, subject, message body
266 plain diff in email, subject, message body
267
267
268 $ hg clone -r0 a b
268 $ hg clone -r0 a b
269 adding changesets
269 adding changesets
270 adding manifests
270 adding manifests
271 adding file changes
271 adding file changes
272 added 1 changesets with 2 changes to 2 files
272 added 1 changesets with 2 changes to 2 files
273 updating to branch default
273 updating to branch default
274 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
274 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
275 $ python mkmsg.py diffed-tip.patch msg.patch
275 $ python mkmsg.py diffed-tip.patch msg.patch
276 $ hg --cwd b import ../msg.patch
276 $ hg --cwd b import ../msg.patch
277 applying ../msg.patch
277 applying ../msg.patch
278 $ hg --cwd b tip | grep email
278 $ hg --cwd b tip | grep email
279 user: email patcher
279 user: email patcher
280 summary: email patch
280 summary: email patch
281 $ rm -r b
281 $ rm -r b
282
282
283
283
284 plain diff in email, no subject, message body
284 plain diff in email, no subject, message body
285
285
286 $ hg clone -r0 a b
286 $ hg clone -r0 a b
287 adding changesets
287 adding changesets
288 adding manifests
288 adding manifests
289 adding file changes
289 adding file changes
290 added 1 changesets with 2 changes to 2 files
290 added 1 changesets with 2 changes to 2 files
291 updating to branch default
291 updating to branch default
292 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
292 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
293 $ grep -v '^Subject:' msg.patch | hg --cwd b import -
293 $ grep -v '^Subject:' msg.patch | hg --cwd b import -
294 applying patch from stdin
294 applying patch from stdin
295 $ rm -r b
295 $ rm -r b
296
296
297
297
298 plain diff in email, subject, no message body
298 plain diff in email, subject, no message body
299
299
300 $ hg clone -r0 a b
300 $ hg clone -r0 a b
301 adding changesets
301 adding changesets
302 adding manifests
302 adding manifests
303 adding file changes
303 adding file changes
304 added 1 changesets with 2 changes to 2 files
304 added 1 changesets with 2 changes to 2 files
305 updating to branch default
305 updating to branch default
306 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
306 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
307 $ grep -v '^email ' msg.patch | hg --cwd b import -
307 $ grep -v '^email ' msg.patch | hg --cwd b import -
308 applying patch from stdin
308 applying patch from stdin
309 $ rm -r b
309 $ rm -r b
310
310
311
311
312 plain diff in email, no subject, no message body, should fail
312 plain diff in email, no subject, no message body, should fail
313
313
314 $ hg clone -r0 a b
314 $ hg clone -r0 a b
315 adding changesets
315 adding changesets
316 adding manifests
316 adding manifests
317 adding file changes
317 adding file changes
318 added 1 changesets with 2 changes to 2 files
318 added 1 changesets with 2 changes to 2 files
319 updating to branch default
319 updating to branch default
320 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
320 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
321 $ egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
321 $ egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
322 applying patch from stdin
322 applying patch from stdin
323 abort: empty commit message
323 abort: empty commit message
324 [255]
324 [255]
325 $ rm -r b
325 $ rm -r b
326
326
327
327
328 hg export in email, should use patch header
328 hg export in email, should use patch header
329
329
330 $ hg clone -r0 a b
330 $ hg clone -r0 a b
331 adding changesets
331 adding changesets
332 adding manifests
332 adding manifests
333 adding file changes
333 adding file changes
334 added 1 changesets with 2 changes to 2 files
334 added 1 changesets with 2 changes to 2 files
335 updating to branch default
335 updating to branch default
336 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
336 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
337 $ python mkmsg.py exported-tip.patch msg.patch
337 $ python mkmsg.py exported-tip.patch msg.patch
338 $ cat msg.patch | hg --cwd b import -
338 $ cat msg.patch | hg --cwd b import -
339 applying patch from stdin
339 applying patch from stdin
340 $ hg --cwd b tip | grep second
340 $ hg --cwd b tip | grep second
341 summary: second change
341 summary: second change
342 $ rm -r b
342 $ rm -r b
343
343
344
344
345 subject: duplicate detection, removal of [PATCH]
345 subject: duplicate detection, removal of [PATCH]
346 The '---' tests the gitsendmail handling without proper mail headers
346 The '---' tests the gitsendmail handling without proper mail headers
347
347
348 $ cat > mkmsg2.py <<EOF
348 $ cat > mkmsg2.py <<EOF
349 > import email.Message, sys
349 > import email.Message, sys
350 > msg = email.Message.Message()
350 > msg = email.Message.Message()
351 > patch = open(sys.argv[1], 'rb').read()
351 > patch = open(sys.argv[1], 'rb').read()
352 > msg.set_payload('email patch\n\nnext line\n---\n' + patch)
352 > msg.set_payload('email patch\n\nnext line\n---\n' + patch)
353 > msg['Subject'] = '[PATCH] email patch'
353 > msg['Subject'] = '[PATCH] email patch'
354 > msg['From'] = 'email patcher'
354 > msg['From'] = 'email patcher'
355 > file(sys.argv[2], 'wb').write(msg.as_string())
355 > file(sys.argv[2], 'wb').write(msg.as_string())
356 > EOF
356 > EOF
357
357
358
358
359 plain diff in email, [PATCH] subject, message body with subject
359 plain diff in email, [PATCH] subject, message body with subject
360
360
361 $ hg clone -r0 a b
361 $ hg clone -r0 a b
362 adding changesets
362 adding changesets
363 adding manifests
363 adding manifests
364 adding file changes
364 adding file changes
365 added 1 changesets with 2 changes to 2 files
365 added 1 changesets with 2 changes to 2 files
366 updating to branch default
366 updating to branch default
367 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
367 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
368 $ python mkmsg2.py diffed-tip.patch msg.patch
368 $ python mkmsg2.py diffed-tip.patch msg.patch
369 $ cat msg.patch | hg --cwd b import -
369 $ cat msg.patch | hg --cwd b import -
370 applying patch from stdin
370 applying patch from stdin
371 $ hg --cwd b tip --template '{desc}\n'
371 $ hg --cwd b tip --template '{desc}\n'
372 email patch
372 email patch
373
373
374 next line
374 next line
375 $ rm -r b
375 $ rm -r b
376
376
377
377
378 Issue963: Parent of working dir incorrect after import of multiple
378 Issue963: Parent of working dir incorrect after import of multiple
379 patches and rollback
379 patches and rollback
380
380
381 We weren't backing up the correct dirstate file when importing many
381 We weren't backing up the correct dirstate file when importing many
382 patches: import patch1 patch2; rollback
382 patches: import patch1 patch2; rollback
383
383
384 $ echo line 3 >> a/a
384 $ echo line 3 >> a/a
385 $ hg --cwd a ci -m'third change'
385 $ hg --cwd a ci -m'third change'
386 $ hg --cwd a export -o '../patch%R' 1 2
386 $ hg --cwd a export -o '../patch%R' 1 2
387 $ hg clone -qr0 a b
387 $ hg clone -qr0 a b
388 $ hg --cwd b parents --template 'parent: {rev}\n'
388 $ hg --cwd b parents --template 'parent: {rev}\n'
389 parent: 0
389 parent: 0
390 $ hg --cwd b import -v ../patch1 ../patch2
390 $ hg --cwd b import -v ../patch1 ../patch2
391 applying ../patch1
391 applying ../patch1
392 patching file a
392 patching file a
393 a
393 a
394 created 1d4bd90af0e4
394 created 1d4bd90af0e4
395 applying ../patch2
395 applying ../patch2
396 patching file a
396 patching file a
397 a
397 a
398 created 6d019af21222
398 created 6d019af21222
399 $ hg --cwd b rollback
399 $ hg --cwd b rollback
400 repository tip rolled back to revision 0 (undo import)
400 repository tip rolled back to revision 0 (undo import)
401 working directory now based on revision 0
401 working directory now based on revision 0
402 $ hg --cwd b parents --template 'parent: {rev}\n'
402 $ hg --cwd b parents --template 'parent: {rev}\n'
403 parent: 0
403 parent: 0
404 $ rm -r b
404 $ rm -r b
405
405
406
406
407 importing a patch in a subdirectory failed at the commit stage
407 importing a patch in a subdirectory failed at the commit stage
408
408
409 $ echo line 2 >> a/d1/d2/a
409 $ echo line 2 >> a/d1/d2/a
410 $ hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
410 $ hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
411
411
412 hg import in a subdirectory
412 hg import in a subdirectory
413
413
414 $ hg clone -r0 a b
414 $ hg clone -r0 a b
415 adding changesets
415 adding changesets
416 adding manifests
416 adding manifests
417 adding file changes
417 adding file changes
418 added 1 changesets with 2 changes to 2 files
418 added 1 changesets with 2 changes to 2 files
419 updating to branch default
419 updating to branch default
420 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
420 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
421 $ hg --cwd a export tip > tmp
421 $ hg --cwd a export tip > tmp
422 $ sed -e 's/d1\/d2\///' < tmp > subdir-tip.patch
422 $ sed -e 's/d1\/d2\///' < tmp > subdir-tip.patch
423 $ dir=`pwd`
423 $ dir=`pwd`
424 $ cd b/d1/d2 2>&1 > /dev/null
424 $ cd b/d1/d2 2>&1 > /dev/null
425 $ hg import ../../../subdir-tip.patch
425 $ hg import ../../../subdir-tip.patch
426 applying ../../../subdir-tip.patch
426 applying ../../../subdir-tip.patch
427 $ cd "$dir"
427 $ cd "$dir"
428
428
429 message should be 'subdir change'
429 message should be 'subdir change'
430 committer should be 'someoneelse'
430 committer should be 'someoneelse'
431
431
432 $ hg --cwd b tip
432 $ hg --cwd b tip
433 changeset: 1:3577f5aea227
433 changeset: 1:3577f5aea227
434 tag: tip
434 tag: tip
435 user: someoneelse
435 user: someoneelse
436 date: Thu Jan 01 00:00:01 1970 +0000
436 date: Thu Jan 01 00:00:01 1970 +0000
437 summary: subdir change
437 summary: subdir change
438
438
439
439
440 should be empty
440 should be empty
441
441
442 $ hg --cwd b status
442 $ hg --cwd b status
443
443
444
444
445 Test fuzziness (ambiguous patch location, fuzz=2)
445 Test fuzziness (ambiguous patch location, fuzz=2)
446
446
447 $ hg init fuzzy
447 $ hg init fuzzy
448 $ cd fuzzy
448 $ cd fuzzy
449 $ echo line1 > a
449 $ echo line1 > a
450 $ echo line0 >> a
450 $ echo line0 >> a
451 $ echo line3 >> a
451 $ echo line3 >> a
452 $ hg ci -Am adda
452 $ hg ci -Am adda
453 adding a
453 adding a
454 $ echo line1 > a
454 $ echo line1 > a
455 $ echo line2 >> a
455 $ echo line2 >> a
456 $ echo line0 >> a
456 $ echo line0 >> a
457 $ echo line3 >> a
457 $ echo line3 >> a
458 $ hg ci -m change a
458 $ hg ci -m change a
459 $ hg export tip > fuzzy-tip.patch
459 $ hg export tip > fuzzy-tip.patch
460 $ hg up -C 0
460 $ hg up -C 0
461 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
461 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
462 $ echo line1 > a
462 $ echo line1 > a
463 $ echo line0 >> a
463 $ echo line0 >> a
464 $ echo line1 >> a
464 $ echo line1 >> a
465 $ echo line0 >> a
465 $ echo line0 >> a
466 $ hg ci -m brancha
466 $ hg ci -m brancha
467 created new head
467 created new head
468 $ hg import --no-commit -v fuzzy-tip.patch
468 $ hg import --no-commit -v fuzzy-tip.patch
469 applying fuzzy-tip.patch
469 applying fuzzy-tip.patch
470 patching file a
470 patching file a
471 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
471 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
472 applied to working directory
472 applied to working directory
473 $ hg revert -a
473 $ hg revert -a
474 reverting a
474 reverting a
475
475
476
476
477 import with --no-commit should have written .hg/last-message.txt
477 import with --no-commit should have written .hg/last-message.txt
478
478
479 $ cat .hg/last-message.txt
479 $ cat .hg/last-message.txt
480 change (no-eol)
480 change (no-eol)
481
481
482
482
483 test fuzziness with eol=auto
483 test fuzziness with eol=auto
484
484
485 $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
485 $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
486 applying fuzzy-tip.patch
486 applying fuzzy-tip.patch
487 patching file a
487 patching file a
488 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
488 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
489 applied to working directory
489 applied to working directory
490 $ cd ..
490 $ cd ..
491
491
492
492
493 Test hunk touching empty files (issue906)
493 Test hunk touching empty files (issue906)
494
494
495 $ hg init empty
495 $ hg init empty
496 $ cd empty
496 $ cd empty
497 $ touch a
497 $ touch a
498 $ touch b1
498 $ touch b1
499 $ touch c1
499 $ touch c1
500 $ echo d > d
500 $ echo d > d
501 $ hg ci -Am init
501 $ hg ci -Am init
502 adding a
502 adding a
503 adding b1
503 adding b1
504 adding c1
504 adding c1
505 adding d
505 adding d
506 $ echo a > a
506 $ echo a > a
507 $ echo b > b1
507 $ echo b > b1
508 $ hg mv b1 b2
508 $ hg mv b1 b2
509 $ echo c > c1
509 $ echo c > c1
510 $ hg copy c1 c2
510 $ hg copy c1 c2
511 $ rm d
511 $ rm d
512 $ touch d
512 $ touch d
513 $ hg diff --git
513 $ hg diff --git
514 diff --git a/a b/a
514 diff --git a/a b/a
515 --- a/a
515 --- a/a
516 +++ b/a
516 +++ b/a
517 @@ -0,0 +1,1 @@
517 @@ -0,0 +1,1 @@
518 +a
518 +a
519 diff --git a/b1 b/b2
519 diff --git a/b1 b/b2
520 rename from b1
520 rename from b1
521 rename to b2
521 rename to b2
522 --- a/b1
522 --- a/b1
523 +++ b/b2
523 +++ b/b2
524 @@ -0,0 +1,1 @@
524 @@ -0,0 +1,1 @@
525 +b
525 +b
526 diff --git a/c1 b/c1
526 diff --git a/c1 b/c1
527 --- a/c1
527 --- a/c1
528 +++ b/c1
528 +++ b/c1
529 @@ -0,0 +1,1 @@
529 @@ -0,0 +1,1 @@
530 +c
530 +c
531 diff --git a/c1 b/c2
531 diff --git a/c1 b/c2
532 copy from c1
532 copy from c1
533 copy to c2
533 copy to c2
534 --- a/c1
534 --- a/c1
535 +++ b/c2
535 +++ b/c2
536 @@ -0,0 +1,1 @@
536 @@ -0,0 +1,1 @@
537 +c
537 +c
538 diff --git a/d b/d
538 diff --git a/d b/d
539 --- a/d
539 --- a/d
540 +++ b/d
540 +++ b/d
541 @@ -1,1 +0,0 @@
541 @@ -1,1 +0,0 @@
542 -d
542 -d
543 $ hg ci -m empty
543 $ hg ci -m empty
544 $ hg export --git tip > empty.diff
544 $ hg export --git tip > empty.diff
545 $ hg up -C 0
545 $ hg up -C 0
546 4 files updated, 0 files merged, 2 files removed, 0 files unresolved
546 4 files updated, 0 files merged, 2 files removed, 0 files unresolved
547 $ hg import empty.diff
547 $ hg import empty.diff
548 applying empty.diff
548 applying empty.diff
549 $ for name in a b1 b2 c1 c2 d; do
549 $ for name in a b1 b2 c1 c2 d; do
550 > echo % $name file
550 > echo % $name file
551 > test -f $name && cat $name
551 > test -f $name && cat $name
552 > done
552 > done
553 % a file
553 % a file
554 a
554 a
555 % b1 file
555 % b1 file
556 % b2 file
556 % b2 file
557 b
557 b
558 % c1 file
558 % c1 file
559 c
559 c
560 % c2 file
560 % c2 file
561 c
561 c
562 % d file
562 % d file
563 $ cd ..
563 $ cd ..
564
564
565
565
566 Test importing a patch ending with a binary file removal
566 Test importing a patch ending with a binary file removal
567
567
568 $ hg init binaryremoval
568 $ hg init binaryremoval
569 $ cd binaryremoval
569 $ cd binaryremoval
570 $ echo a > a
570 $ echo a > a
571 $ python -c "file('b', 'wb').write('a\x00b')"
571 $ python -c "file('b', 'wb').write('a\x00b')"
572 $ hg ci -Am addall
572 $ hg ci -Am addall
573 adding a
573 adding a
574 adding b
574 adding b
575 $ hg rm a
575 $ hg rm a
576 $ hg rm b
576 $ hg rm b
577 $ hg st
577 $ hg st
578 R a
578 R a
579 R b
579 R b
580 $ hg ci -m remove
580 $ hg ci -m remove
581 $ hg export --git . > remove.diff
581 $ hg export --git . > remove.diff
582 $ cat remove.diff | grep git
582 $ cat remove.diff | grep git
583 diff --git a/a b/a
583 diff --git a/a b/a
584 diff --git a/b b/b
584 diff --git a/b b/b
585 $ hg up -C 0
585 $ hg up -C 0
586 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
586 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
587 $ hg import remove.diff
587 $ hg import remove.diff
588 applying remove.diff
588 applying remove.diff
589 $ hg manifest
589 $ hg manifest
590 $ cd ..
590 $ cd ..
591
591
592
592
593 Issue927: test update+rename with common name
593 Issue927: test update+rename with common name
594
594
595 $ hg init t
595 $ hg init t
596 $ cd t
596 $ cd t
597 $ touch a
597 $ touch a
598 $ hg ci -Am t
598 $ hg ci -Am t
599 adding a
599 adding a
600 $ echo a > a
600 $ echo a > a
601
601
602 Here, bfile.startswith(afile)
602 Here, bfile.startswith(afile)
603
603
604 $ hg copy a a2
604 $ hg copy a a2
605 $ hg ci -m copya
605 $ hg ci -m copya
606 $ hg export --git tip > copy.diff
606 $ hg export --git tip > copy.diff
607 $ hg up -C 0
607 $ hg up -C 0
608 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
608 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
609 $ hg import copy.diff
609 $ hg import copy.diff
610 applying copy.diff
610 applying copy.diff
611
611
612 a should contain an 'a'
612 a should contain an 'a'
613
613
614 $ cat a
614 $ cat a
615 a
615 a
616
616
617 and a2 should have duplicated it
617 and a2 should have duplicated it
618
618
619 $ cat a2
619 $ cat a2
620 a
620 a
621 $ cd ..
621 $ cd ..
622
622
623
623
624 test -p0
624 test -p0
625
625
626 $ hg init p0
626 $ hg init p0
627 $ cd p0
627 $ cd p0
628 $ echo a > a
628 $ echo a > a
629 $ hg ci -Am t
629 $ hg ci -Am t
630 adding a
630 adding a
631 $ hg import -p foo
631 $ hg import -p foo
632 abort: invalid value 'foo' for option -p, expected int
632 abort: invalid value 'foo' for option -p, expected int
633 [255]
633 [255]
634 $ hg import -p0 - << EOF
634 $ hg import -p0 - << EOF
635 > foobar
635 > foobar
636 > --- a Sat Apr 12 22:43:58 2008 -0400
636 > --- a Sat Apr 12 22:43:58 2008 -0400
637 > +++ a Sat Apr 12 22:44:05 2008 -0400
637 > +++ a Sat Apr 12 22:44:05 2008 -0400
638 > @@ -1,1 +1,1 @@
638 > @@ -1,1 +1,1 @@
639 > -a
639 > -a
640 > +bb
640 > +bb
641 > EOF
641 > EOF
642 applying patch from stdin
642 applying patch from stdin
643 $ hg status
643 $ hg status
644 $ cat a
644 $ cat a
645 bb
645 bb
646 $ cd ..
646 $ cd ..
647
647
648
648
649 test paths outside repo root
649 test paths outside repo root
650
650
651 $ mkdir outside
651 $ mkdir outside
652 $ touch outside/foo
652 $ touch outside/foo
653 $ hg init inside
653 $ hg init inside
654 $ cd inside
654 $ cd inside
655 $ hg import - <<EOF
655 $ hg import - <<EOF
656 > diff --git a/a b/b
656 > diff --git a/a b/b
657 > rename from ../outside/foo
657 > rename from ../outside/foo
658 > rename to bar
658 > rename to bar
659 > EOF
659 > EOF
660 applying patch from stdin
660 applying patch from stdin
661 abort: path contains illegal component: ../outside/foo (glob)
661 abort: path contains illegal component: ../outside/foo (glob)
662 [255]
662 [255]
663 $ cd ..
663 $ cd ..
664
664
665
665
666 test import with similarity and git and strip (issue295 et al.)
666 test import with similarity and git and strip (issue295 et al.)
667
667
668 $ hg init sim
668 $ hg init sim
669 $ cd sim
669 $ cd sim
670 $ echo 'this is a test' > a
670 $ echo 'this is a test' > a
671 $ hg ci -Ama
671 $ hg ci -Ama
672 adding a
672 adding a
673 $ cat > ../rename.diff <<EOF
673 $ cat > ../rename.diff <<EOF
674 > diff --git a/foo/a b/foo/a
674 > diff --git a/foo/a b/foo/a
675 > deleted file mode 100644
675 > deleted file mode 100644
676 > --- a/foo/a
676 > --- a/foo/a
677 > +++ /dev/null
677 > +++ /dev/null
678 > @@ -1,1 +0,0 @@
678 > @@ -1,1 +0,0 @@
679 > -this is a test
679 > -this is a test
680 > diff --git a/foo/b b/foo/b
680 > diff --git a/foo/b b/foo/b
681 > new file mode 100644
681 > new file mode 100644
682 > --- /dev/null
682 > --- /dev/null
683 > +++ b/foo/b
683 > +++ b/foo/b
684 > @@ -0,0 +1,2 @@
684 > @@ -0,0 +1,2 @@
685 > +this is a test
685 > +this is a test
686 > +foo
686 > +foo
687 > EOF
687 > EOF
688 $ hg import --no-commit -v -s 1 ../rename.diff -p2
688 $ hg import --no-commit -v -s 1 ../rename.diff -p2
689 applying ../rename.diff
689 applying ../rename.diff
690 patching file a
690 patching file a
691 patching file b
691 patching file b
692 adding b
692 adding b
693 recording removal of a as rename to b (88% similar)
693 recording removal of a as rename to b (88% similar)
694 applied to working directory
694 applied to working directory
695 $ hg st -C
695 $ hg st -C
696 A b
696 A b
697 a
697 a
698 R a
698 R a
699 $ hg revert -a
699 $ hg revert -a
700 undeleting a
700 undeleting a
701 forgetting b
701 forgetting b
702 $ rm b
702 $ rm b
703 $ hg import --no-commit -v -s 100 ../rename.diff -p2
703 $ hg import --no-commit -v -s 100 ../rename.diff -p2
704 applying ../rename.diff
704 applying ../rename.diff
705 patching file a
705 patching file a
706 patching file b
706 patching file b
707 adding b
707 adding b
708 applied to working directory
708 applied to working directory
709 $ hg st -C
709 $ hg st -C
710 A b
710 A b
711 R a
711 R a
712 $ cd ..
712 $ cd ..
713
713
714
714
715 Issue1495: add empty file from the end of patch
715 Issue1495: add empty file from the end of patch
716
716
717 $ hg init addemptyend
717 $ hg init addemptyend
718 $ cd addemptyend
718 $ cd addemptyend
719 $ touch a
719 $ touch a
720 $ hg addremove
720 $ hg addremove
721 adding a
721 adding a
722 $ hg ci -m "commit"
722 $ hg ci -m "commit"
723 $ cat > a.patch <<EOF
723 $ cat > a.patch <<EOF
724 > add a, b
724 > add a, b
725 > diff --git a/a b/a
725 > diff --git a/a b/a
726 > --- a/a
726 > --- a/a
727 > +++ b/a
727 > +++ b/a
728 > @@ -0,0 +1,1 @@
728 > @@ -0,0 +1,1 @@
729 > +a
729 > +a
730 > diff --git a/b b/b
730 > diff --git a/b b/b
731 > new file mode 100644
731 > new file mode 100644
732 > EOF
732 > EOF
733 $ hg import --no-commit a.patch
733 $ hg import --no-commit a.patch
734 applying a.patch
734 applying a.patch
735
735
736 apply a good patch followed by an empty patch (mainly to ensure
736 apply a good patch followed by an empty patch (mainly to ensure
737 that dirstate is *not* updated when import crashes)
737 that dirstate is *not* updated when import crashes)
738 $ hg update -q -C .
738 $ hg update -q -C .
739 $ rm b
739 $ rm b
740 $ touch empty.patch
740 $ touch empty.patch
741 $ hg import a.patch empty.patch
741 $ hg import a.patch empty.patch
742 applying a.patch
742 applying a.patch
743 applying empty.patch
743 applying empty.patch
744 transaction abort!
744 transaction abort!
745 rollback completed
745 rollback completed
746 abort: empty.patch: no diffs found
746 abort: empty.patch: no diffs found
747 [255]
747 [255]
748 $ hg tip --template '{rev} {desc|firstline}\n'
748 $ hg tip --template '{rev} {desc|firstline}\n'
749 0 commit
749 0 commit
750 $ hg -q status
750 $ hg -q status
751 M a
751 M a
752 $ cd ..
752 $ cd ..
753
753
754 create file when source is not /dev/null
754 create file when source is not /dev/null
755
755
756 $ cat > create.patch <<EOF
756 $ cat > create.patch <<EOF
757 > diff -Naur proj-orig/foo proj-new/foo
757 > diff -Naur proj-orig/foo proj-new/foo
758 > --- proj-orig/foo 1969-12-31 16:00:00.000000000 -0800
758 > --- proj-orig/foo 1969-12-31 16:00:00.000000000 -0800
759 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
759 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
760 > @@ -0,0 +1,1 @@
760 > @@ -0,0 +1,1 @@
761 > +a
761 > +a
762 > EOF
762 > EOF
763
763
764 some people have patches like the following too
764 some people have patches like the following too
765
765
766 $ cat > create2.patch <<EOF
766 $ cat > create2.patch <<EOF
767 > diff -Naur proj-orig/foo proj-new/foo
767 > diff -Naur proj-orig/foo proj-new/foo
768 > --- proj-orig/foo.orig 1969-12-31 16:00:00.000000000 -0800
768 > --- proj-orig/foo.orig 1969-12-31 16:00:00.000000000 -0800
769 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
769 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
770 > @@ -0,0 +1,1 @@
770 > @@ -0,0 +1,1 @@
771 > +a
771 > +a
772 > EOF
772 > EOF
773 $ hg init oddcreate
773 $ hg init oddcreate
774 $ cd oddcreate
774 $ cd oddcreate
775 $ hg import --no-commit ../create.patch
775 $ hg import --no-commit ../create.patch
776 applying ../create.patch
776 applying ../create.patch
777 $ cat foo
777 $ cat foo
778 a
778 a
779 $ rm foo
779 $ rm foo
780 $ hg revert foo
780 $ hg revert foo
781 $ hg import --no-commit ../create2.patch
781 $ hg import --no-commit ../create2.patch
782 applying ../create2.patch
782 applying ../create2.patch
783 $ cat foo
783 $ cat foo
784 a
784 a
785
785
786 $ cd ..
786 $ cd ..
787
787
788 Issue1859: first line mistaken for email headers
788 Issue1859: first line mistaken for email headers
789
789
790 $ hg init emailconfusion
790 $ hg init emailconfusion
791 $ cd emailconfusion
791 $ cd emailconfusion
792 $ cat > a.patch <<EOF
792 $ cat > a.patch <<EOF
793 > module: summary
793 > module: summary
794 >
794 >
795 > description
795 > description
796 >
796 >
797 >
797 >
798 > diff -r 000000000000 -r 9b4c1e343b55 test.txt
798 > diff -r 000000000000 -r 9b4c1e343b55 test.txt
799 > --- /dev/null
799 > --- /dev/null
800 > +++ b/a
800 > +++ b/a
801 > @@ -0,0 +1,1 @@
801 > @@ -0,0 +1,1 @@
802 > +a
802 > +a
803 > EOF
803 > EOF
804 $ hg import -d '0 0' a.patch
804 $ hg import -d '0 0' a.patch
805 applying a.patch
805 applying a.patch
806 $ hg parents -v
806 $ hg parents -v
807 changeset: 0:5a681217c0ad
807 changeset: 0:5a681217c0ad
808 tag: tip
808 tag: tip
809 user: test
809 user: test
810 date: Thu Jan 01 00:00:00 1970 +0000
810 date: Thu Jan 01 00:00:00 1970 +0000
811 files: a
811 files: a
812 description:
812 description:
813 module: summary
813 module: summary
814
814
815 description
815 description
816
816
817
817
818 $ cd ..
818 $ cd ..
819
819
820
820
821 in commit message
821 in commit message
822
822
823 $ hg init commitconfusion
823 $ hg init commitconfusion
824 $ cd commitconfusion
824 $ cd commitconfusion
825 $ cat > a.patch <<EOF
825 $ cat > a.patch <<EOF
826 > module: summary
826 > module: summary
827 >
827 >
828 > --- description
828 > --- description
829 >
829 >
830 > diff --git a/a b/a
830 > diff --git a/a b/a
831 > new file mode 100644
831 > new file mode 100644
832 > --- /dev/null
832 > --- /dev/null
833 > +++ b/a
833 > +++ b/a
834 > @@ -0,0 +1,1 @@
834 > @@ -0,0 +1,1 @@
835 > +a
835 > +a
836 > EOF
836 > EOF
837 > hg import -d '0 0' a.patch
837 > hg import -d '0 0' a.patch
838 > hg parents -v
838 > hg parents -v
839 > cd ..
839 > cd ..
840 >
840 >
841 > echo '% tricky header splitting'
841 > echo '% tricky header splitting'
842 > cat > trickyheaders.patch <<EOF
842 > cat > trickyheaders.patch <<EOF
843 > From: User A <user@a>
843 > From: User A <user@a>
844 > Subject: [PATCH] from: tricky!
844 > Subject: [PATCH] from: tricky!
845 >
845 >
846 > # HG changeset patch
846 > # HG changeset patch
847 > # User User B
847 > # User User B
848 > # Date 1266264441 18000
848 > # Date 1266264441 18000
849 > # Branch stable
849 > # Branch stable
850 > # Node ID f2be6a1170ac83bf31cb4ae0bad00d7678115bc0
850 > # Node ID f2be6a1170ac83bf31cb4ae0bad00d7678115bc0
851 > # Parent 0000000000000000000000000000000000000000
851 > # Parent 0000000000000000000000000000000000000000
852 > from: tricky!
852 > from: tricky!
853 >
853 >
854 > That is not a header.
854 > That is not a header.
855 >
855 >
856 > diff -r 000000000000 -r f2be6a1170ac foo
856 > diff -r 000000000000 -r f2be6a1170ac foo
857 > --- /dev/null
857 > --- /dev/null
858 > +++ b/foo
858 > +++ b/foo
859 > @@ -0,0 +1,1 @@
859 > @@ -0,0 +1,1 @@
860 > +foo
860 > +foo
861 > EOF
861 > EOF
862 applying a.patch
862 applying a.patch
863 changeset: 0:f34d9187897d
863 changeset: 0:f34d9187897d
864 tag: tip
864 tag: tip
865 user: test
865 user: test
866 date: Thu Jan 01 00:00:00 1970 +0000
866 date: Thu Jan 01 00:00:00 1970 +0000
867 files: a
867 files: a
868 description:
868 description:
869 module: summary
869 module: summary
870
870
871
871
872 % tricky header splitting
872 % tricky header splitting
873
873
874 $ hg init trickyheaders
874 $ hg init trickyheaders
875 $ cd trickyheaders
875 $ cd trickyheaders
876 $ hg import -d '0 0' ../trickyheaders.patch
876 $ hg import -d '0 0' ../trickyheaders.patch
877 applying ../trickyheaders.patch
877 applying ../trickyheaders.patch
878 $ hg export --git tip
878 $ hg export --git tip
879 # HG changeset patch
879 # HG changeset patch
880 # User User B
880 # User User B
881 # Date 0 0
881 # Date 0 0
882 # Thu Jan 01 00:00:00 1970 +0000
882 # Thu Jan 01 00:00:00 1970 +0000
883 # Node ID eb56ab91903632294ac504838508cb370c0901d2
883 # Node ID eb56ab91903632294ac504838508cb370c0901d2
884 # Parent 0000000000000000000000000000000000000000
884 # Parent 0000000000000000000000000000000000000000
885 from: tricky!
885 from: tricky!
886
886
887 That is not a header.
887 That is not a header.
888
888
889 diff --git a/foo b/foo
889 diff --git a/foo b/foo
890 new file mode 100644
890 new file mode 100644
891 --- /dev/null
891 --- /dev/null
892 +++ b/foo
892 +++ b/foo
893 @@ -0,0 +1,1 @@
893 @@ -0,0 +1,1 @@
894 +foo
894 +foo
895 $ cd ..
895 $ cd ..
896
896
897
897
898 Issue2102: hg export and hg import speak different languages
898 Issue2102: hg export and hg import speak different languages
899
899
900 $ hg init issue2102
900 $ hg init issue2102
901 $ cd issue2102
901 $ cd issue2102
902 $ mkdir -p src/cmd/gc
902 $ mkdir -p src/cmd/gc
903 $ touch src/cmd/gc/mksys.bash
903 $ touch src/cmd/gc/mksys.bash
904 $ hg ci -Am init
904 $ hg ci -Am init
905 adding src/cmd/gc/mksys.bash
905 adding src/cmd/gc/mksys.bash
906 $ hg import - <<EOF
906 $ hg import - <<EOF
907 > # HG changeset patch
907 > # HG changeset patch
908 > # User Rob Pike
908 > # User Rob Pike
909 > # Date 1216685449 25200
909 > # Date 1216685449 25200
910 > # Node ID 03aa2b206f499ad6eb50e6e207b9e710d6409c98
910 > # Node ID 03aa2b206f499ad6eb50e6e207b9e710d6409c98
911 > # Parent 93d10138ad8df586827ca90b4ddb5033e21a3a84
911 > # Parent 93d10138ad8df586827ca90b4ddb5033e21a3a84
912 > help management of empty pkg and lib directories in perforce
912 > help management of empty pkg and lib directories in perforce
913 >
913 >
914 > R=gri
914 > R=gri
915 > DELTA=4 (4 added, 0 deleted, 0 changed)
915 > DELTA=4 (4 added, 0 deleted, 0 changed)
916 > OCL=13328
916 > OCL=13328
917 > CL=13328
917 > CL=13328
918 >
918 >
919 > diff --git a/lib/place-holder b/lib/place-holder
919 > diff --git a/lib/place-holder b/lib/place-holder
920 > new file mode 100644
920 > new file mode 100644
921 > --- /dev/null
921 > --- /dev/null
922 > +++ b/lib/place-holder
922 > +++ b/lib/place-holder
923 > @@ -0,0 +1,2 @@
923 > @@ -0,0 +1,2 @@
924 > +perforce does not maintain empty directories.
924 > +perforce does not maintain empty directories.
925 > +this file helps.
925 > +this file helps.
926 > diff --git a/pkg/place-holder b/pkg/place-holder
926 > diff --git a/pkg/place-holder b/pkg/place-holder
927 > new file mode 100644
927 > new file mode 100644
928 > --- /dev/null
928 > --- /dev/null
929 > +++ b/pkg/place-holder
929 > +++ b/pkg/place-holder
930 > @@ -0,0 +1,2 @@
930 > @@ -0,0 +1,2 @@
931 > +perforce does not maintain empty directories.
931 > +perforce does not maintain empty directories.
932 > +this file helps.
932 > +this file helps.
933 > diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
933 > diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
934 > old mode 100644
934 > old mode 100644
935 > new mode 100755
935 > new mode 100755
936 > EOF
936 > EOF
937 applying patch from stdin
937 applying patch from stdin
938
938
939 #if execbit
939 #if execbit
940
940
941 $ hg sum
941 $ hg sum
942 parent: 1:d59915696727 tip
942 parent: 1:d59915696727 tip
943 help management of empty pkg and lib directories in perforce
943 help management of empty pkg and lib directories in perforce
944 branch: default
944 branch: default
945 commit: (clean)
945 commit: (clean)
946 update: (current)
946 update: (current)
947
947
948 $ hg diff --git -c tip
948 $ hg diff --git -c tip
949 diff --git a/lib/place-holder b/lib/place-holder
949 diff --git a/lib/place-holder b/lib/place-holder
950 new file mode 100644
950 new file mode 100644
951 --- /dev/null
951 --- /dev/null
952 +++ b/lib/place-holder
952 +++ b/lib/place-holder
953 @@ -0,0 +1,2 @@
953 @@ -0,0 +1,2 @@
954 +perforce does not maintain empty directories.
954 +perforce does not maintain empty directories.
955 +this file helps.
955 +this file helps.
956 diff --git a/pkg/place-holder b/pkg/place-holder
956 diff --git a/pkg/place-holder b/pkg/place-holder
957 new file mode 100644
957 new file mode 100644
958 --- /dev/null
958 --- /dev/null
959 +++ b/pkg/place-holder
959 +++ b/pkg/place-holder
960 @@ -0,0 +1,2 @@
960 @@ -0,0 +1,2 @@
961 +perforce does not maintain empty directories.
961 +perforce does not maintain empty directories.
962 +this file helps.
962 +this file helps.
963 diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
963 diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
964 old mode 100644
964 old mode 100644
965 new mode 100755
965 new mode 100755
966
966
967 #else
967 #else
968
968
969 $ hg sum
969 $ hg sum
970 parent: 1:28f089cc9ccc tip
970 parent: 1:28f089cc9ccc tip
971 help management of empty pkg and lib directories in perforce
971 help management of empty pkg and lib directories in perforce
972 branch: default
972 branch: default
973 commit: (clean)
973 commit: (clean)
974 update: (current)
974 update: (current)
975
975
976 $ hg diff --git -c tip
976 $ hg diff --git -c tip
977 diff --git a/lib/place-holder b/lib/place-holder
977 diff --git a/lib/place-holder b/lib/place-holder
978 new file mode 100644
978 new file mode 100644
979 --- /dev/null
979 --- /dev/null
980 +++ b/lib/place-holder
980 +++ b/lib/place-holder
981 @@ -0,0 +1,2 @@
981 @@ -0,0 +1,2 @@
982 +perforce does not maintain empty directories.
982 +perforce does not maintain empty directories.
983 +this file helps.
983 +this file helps.
984 diff --git a/pkg/place-holder b/pkg/place-holder
984 diff --git a/pkg/place-holder b/pkg/place-holder
985 new file mode 100644
985 new file mode 100644
986 --- /dev/null
986 --- /dev/null
987 +++ b/pkg/place-holder
987 +++ b/pkg/place-holder
988 @@ -0,0 +1,2 @@
988 @@ -0,0 +1,2 @@
989 +perforce does not maintain empty directories.
989 +perforce does not maintain empty directories.
990 +this file helps.
990 +this file helps.
991
991
992 /* The mode change for mksys.bash is missing here, because on platforms */
992 /* The mode change for mksys.bash is missing here, because on platforms */
993 /* that don't support execbits, mode changes in patches are ignored when */
993 /* that don't support execbits, mode changes in patches are ignored when */
994 /* they are imported. This is obviously also the reason for why the hash */
994 /* they are imported. This is obviously also the reason for why the hash */
995 /* in the created changeset is different to the one you see above the */
995 /* in the created changeset is different to the one you see above the */
996 /* #else clause */
996 /* #else clause */
997
997
998 #endif
998 #endif
999 $ cd ..
999 $ cd ..
1000
1000
1001
1001
1002 diff lines looking like headers
1002 diff lines looking like headers
1003
1003
1004 $ hg init difflineslikeheaders
1004 $ hg init difflineslikeheaders
1005 $ cd difflineslikeheaders
1005 $ cd difflineslikeheaders
1006 $ echo a >a
1006 $ echo a >a
1007 $ echo b >b
1007 $ echo b >b
1008 $ echo c >c
1008 $ echo c >c
1009 $ hg ci -Am1
1009 $ hg ci -Am1
1010 adding a
1010 adding a
1011 adding b
1011 adding b
1012 adding c
1012 adding c
1013
1013
1014 $ echo "key: value" >>a
1014 $ echo "key: value" >>a
1015 $ echo "key: value" >>b
1015 $ echo "key: value" >>b
1016 $ echo "foo" >>c
1016 $ echo "foo" >>c
1017 $ hg ci -m2
1017 $ hg ci -m2
1018
1018
1019 $ hg up -C 0
1019 $ hg up -C 0
1020 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
1020 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
1021 $ hg diff --git -c1 >want
1021 $ hg diff --git -c1 >want
1022 $ hg diff -c1 | hg import --no-commit -
1022 $ hg diff -c1 | hg import --no-commit -
1023 applying patch from stdin
1023 applying patch from stdin
1024 $ hg diff --git >have
1024 $ hg diff --git >have
1025 $ diff want have
1025 $ diff want have
1026 $ cd ..
1026 $ cd ..
1027
1027
1028 import a unified diff with no lines of context (diff -U0)
1028 import a unified diff with no lines of context (diff -U0)
1029
1029
1030 $ hg init diffzero
1030 $ hg init diffzero
1031 $ cd diffzero
1031 $ cd diffzero
1032 $ cat > f << EOF
1032 $ cat > f << EOF
1033 > c2
1033 > c2
1034 > c4
1034 > c4
1035 > c5
1035 > c5
1036 > EOF
1036 > EOF
1037 $ hg commit -Am0
1037 $ hg commit -Am0
1038 adding f
1038 adding f
1039
1039
1040 $ hg import --no-commit - << EOF
1040 $ hg import --no-commit - << EOF
1041 > # HG changeset patch
1041 > # HG changeset patch
1042 > # User test
1042 > # User test
1043 > # Date 0 0
1043 > # Date 0 0
1044 > # Node ID f4974ab632f3dee767567b0576c0ec9a4508575c
1044 > # Node ID f4974ab632f3dee767567b0576c0ec9a4508575c
1045 > # Parent 8679a12a975b819fae5f7ad3853a2886d143d794
1045 > # Parent 8679a12a975b819fae5f7ad3853a2886d143d794
1046 > 1
1046 > 1
1047 > diff -r 8679a12a975b -r f4974ab632f3 f
1047 > diff -r 8679a12a975b -r f4974ab632f3 f
1048 > --- a/f Thu Jan 01 00:00:00 1970 +0000
1048 > --- a/f Thu Jan 01 00:00:00 1970 +0000
1049 > +++ b/f Thu Jan 01 00:00:00 1970 +0000
1049 > +++ b/f Thu Jan 01 00:00:00 1970 +0000
1050 > @@ -0,0 +1,1 @@
1050 > @@ -0,0 +1,1 @@
1051 > +c1
1051 > +c1
1052 > @@ -1,0 +3,1 @@
1052 > @@ -1,0 +3,1 @@
1053 > +c3
1053 > +c3
1054 > @@ -3,1 +4,0 @@
1054 > @@ -3,1 +4,0 @@
1055 > -c5
1055 > -c5
1056 > EOF
1056 > EOF
1057 applying patch from stdin
1057 applying patch from stdin
1058
1058
1059 $ cat f
1059 $ cat f
1060 c1
1060 c1
1061 c2
1061 c2
1062 c3
1062 c3
1063 c4
1063 c4
1064
1064
1065 $ cd ..
1065 $ cd ..
1066
1066
1067 no segfault while importing a unified diff which start line is zero but chunk
1067 no segfault while importing a unified diff which start line is zero but chunk
1068 size is non-zero
1068 size is non-zero
1069
1069
1070 $ hg init startlinezero
1070 $ hg init startlinezero
1071 $ cd startlinezero
1071 $ cd startlinezero
1072 $ echo foo > foo
1072 $ echo foo > foo
1073 $ hg commit -Amfoo
1073 $ hg commit -Amfoo
1074 adding foo
1074 adding foo
1075
1075
1076 $ hg import --no-commit - << EOF
1076 $ hg import --no-commit - << EOF
1077 > diff a/foo b/foo
1077 > diff a/foo b/foo
1078 > --- a/foo
1078 > --- a/foo
1079 > +++ b/foo
1079 > +++ b/foo
1080 > @@ -0,1 +0,1 @@
1080 > @@ -0,1 +0,1 @@
1081 > foo
1081 > foo
1082 > EOF
1082 > EOF
1083 applying patch from stdin
1083 applying patch from stdin
1084
1084
1085 $ cd ..
1085 $ cd ..
1086
1086
1087 Test corner case involving fuzz and skew
1087 Test corner case involving fuzz and skew
1088
1088
1089 $ hg init morecornercases
1089 $ hg init morecornercases
1090 $ cd morecornercases
1090 $ cd morecornercases
1091
1091
1092 $ cat > 01-no-context-beginning-of-file.diff <<EOF
1092 $ cat > 01-no-context-beginning-of-file.diff <<EOF
1093 > diff --git a/a b/a
1093 > diff --git a/a b/a
1094 > --- a/a
1094 > --- a/a
1095 > +++ b/a
1095 > +++ b/a
1096 > @@ -1,0 +1,1 @@
1096 > @@ -1,0 +1,1 @@
1097 > +line
1097 > +line
1098 > EOF
1098 > EOF
1099
1099
1100 $ cat > 02-no-context-middle-of-file.diff <<EOF
1100 $ cat > 02-no-context-middle-of-file.diff <<EOF
1101 > diff --git a/a b/a
1101 > diff --git a/a b/a
1102 > --- a/a
1102 > --- a/a
1103 > +++ b/a
1103 > +++ b/a
1104 > @@ -1,1 +1,1 @@
1104 > @@ -1,1 +1,1 @@
1105 > -2
1105 > -2
1106 > +add some skew
1106 > +add some skew
1107 > @@ -2,0 +2,1 @@
1107 > @@ -2,0 +2,1 @@
1108 > +line
1108 > +line
1109 > EOF
1109 > EOF
1110
1110
1111 $ cat > 03-no-context-end-of-file.diff <<EOF
1111 $ cat > 03-no-context-end-of-file.diff <<EOF
1112 > diff --git a/a b/a
1112 > diff --git a/a b/a
1113 > --- a/a
1113 > --- a/a
1114 > +++ b/a
1114 > +++ b/a
1115 > @@ -10,0 +10,1 @@
1115 > @@ -10,0 +10,1 @@
1116 > +line
1116 > +line
1117 > EOF
1117 > EOF
1118
1118
1119 $ cat > 04-middle-of-file-completely-fuzzed.diff <<EOF
1119 $ cat > 04-middle-of-file-completely-fuzzed.diff <<EOF
1120 > diff --git a/a b/a
1120 > diff --git a/a b/a
1121 > --- a/a
1121 > --- a/a
1122 > +++ b/a
1122 > +++ b/a
1123 > @@ -1,1 +1,1 @@
1123 > @@ -1,1 +1,1 @@
1124 > -2
1124 > -2
1125 > +add some skew
1125 > +add some skew
1126 > @@ -2,2 +2,3 @@
1126 > @@ -2,2 +2,3 @@
1127 > not matching, should fuzz
1127 > not matching, should fuzz
1128 > ... a bit
1128 > ... a bit
1129 > +line
1129 > +line
1130 > EOF
1130 > EOF
1131
1131
1132 $ cat > a <<EOF
1132 $ cat > a <<EOF
1133 > 1
1133 > 1
1134 > 2
1134 > 2
1135 > 3
1135 > 3
1136 > 4
1136 > 4
1137 > EOF
1137 > EOF
1138 $ hg ci -Am adda a
1138 $ hg ci -Am adda a
1139 $ for p in *.diff; do
1139 $ for p in *.diff; do
1140 > hg import -v --no-commit $p
1140 > hg import -v --no-commit $p
1141 > cat a
1141 > cat a
1142 > hg revert -aqC a
1142 > hg revert -aqC a
1143 > # patch -p1 < $p
1143 > # patch -p1 < $p
1144 > # cat a
1144 > # cat a
1145 > # hg revert -aC a
1145 > # hg revert -aC a
1146 > done
1146 > done
1147 applying 01-no-context-beginning-of-file.diff
1147 applying 01-no-context-beginning-of-file.diff
1148 patching file a
1148 patching file a
1149 applied to working directory
1149 applied to working directory
1150 1
1150 1
1151 line
1151 line
1152 2
1152 2
1153 3
1153 3
1154 4
1154 4
1155 applying 02-no-context-middle-of-file.diff
1155 applying 02-no-context-middle-of-file.diff
1156 patching file a
1156 patching file a
1157 Hunk #1 succeeded at 2 (offset 1 lines).
1157 Hunk #1 succeeded at 2 (offset 1 lines).
1158 Hunk #2 succeeded at 4 (offset 1 lines).
1158 Hunk #2 succeeded at 4 (offset 1 lines).
1159 applied to working directory
1159 applied to working directory
1160 1
1160 1
1161 add some skew
1161 add some skew
1162 3
1162 3
1163 line
1163 line
1164 4
1164 4
1165 applying 03-no-context-end-of-file.diff
1165 applying 03-no-context-end-of-file.diff
1166 patching file a
1166 patching file a
1167 Hunk #1 succeeded at 5 (offset -6 lines).
1167 Hunk #1 succeeded at 5 (offset -6 lines).
1168 applied to working directory
1168 applied to working directory
1169 1
1169 1
1170 2
1170 2
1171 3
1171 3
1172 4
1172 4
1173 line
1173 line
1174 applying 04-middle-of-file-completely-fuzzed.diff
1174 applying 04-middle-of-file-completely-fuzzed.diff
1175 patching file a
1175 patching file a
1176 Hunk #1 succeeded at 2 (offset 1 lines).
1176 Hunk #1 succeeded at 2 (offset 1 lines).
1177 Hunk #2 succeeded at 5 with fuzz 2 (offset 1 lines).
1177 Hunk #2 succeeded at 5 with fuzz 2 (offset 1 lines).
1178 applied to working directory
1178 applied to working directory
1179 1
1179 1
1180 add some skew
1180 add some skew
1181 3
1181 3
1182 4
1182 4
1183 line
1183 line
1184 $ cd ..
1184
1185
1185 $ cd ..
1186 Test partial application
1187 ------------------------
1188
1189 prepare a stack of patches depending on each other
1190
1191 $ hg init partial
1192 $ cd partial
1193 $ cat << EOF > a
1194 > one
1195 > two
1196 > three
1197 > four
1198 > five
1199 > six
1200 > seven
1201 > EOF
1202 $ hg add a
1203 $ echo 'b' > b
1204 $ hg add b
1205 $ hg commit -m 'initial' -u Babar
1206 $ cat << EOF > a
1207 > one
1208 > two
1209 > 3
1210 > four
1211 > five
1212 > six
1213 > seven
1214 > EOF
1215 $ hg commit -m 'three' -u Celeste
1216 $ cat << EOF > a
1217 > one
1218 > two
1219 > 3
1220 > 4
1221 > five
1222 > six
1223 > seven
1224 > EOF
1225 $ hg commit -m 'four' -u Rataxes
1226 $ cat << EOF > a
1227 > one
1228 > two
1229 > 3
1230 > 4
1231 > 5
1232 > six
1233 > seven
1234 > EOF
1235 $ echo bb >> b
1236 $ hg commit -m 'five' -u Arthur
1237 $ echo 'Babar' > jungle
1238 $ hg add jungle
1239 $ hg ci -m 'jungle' -u Zephir
1240 $ echo 'Celeste' >> jungle
1241 $ hg ci -m 'extended jungle' -u Cornelius
1242 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1243 @ extended jungle [Cornelius] 1: +1/-0
1244 |
1245 o jungle [Zephir] 1: +1/-0
1246 |
1247 o five [Arthur] 2: +2/-1
1248 |
1249 o four [Rataxes] 1: +1/-1
1250 |
1251 o three [Celeste] 1: +1/-1
1252 |
1253 o initial [Babar] 2: +8/-0
1254
1255
1256 Importing with some success and some errors:
1257
1258 $ hg update --rev 'desc(initial)'
1259 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
1260 $ hg export --rev 'desc(five)' | hg import --partial -
1261 applying patch from stdin
1262 patching file a
1263 Hunk #1 FAILED at 1
1264 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1265 patch applied partially
1266 (fix the .rej files and run `hg commit --amend`)
1267 [1]
1268
1269 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1270 @ five [Arthur] 1: +1/-0
1271 |
1272 | o extended jungle [Cornelius] 1: +1/-0
1273 | |
1274 | o jungle [Zephir] 1: +1/-0
1275 | |
1276 | o five [Arthur] 2: +2/-1
1277 | |
1278 | o four [Rataxes] 1: +1/-1
1279 | |
1280 | o three [Celeste] 1: +1/-1
1281 |/
1282 o initial [Babar] 2: +8/-0
1283
1284 $ hg export
1285 # HG changeset patch
1286 # User Arthur
1287 # Date 0 0
1288 # Thu Jan 01 00:00:00 1970 +0000
1289 # Node ID 26e6446bb2526e2be1037935f5fca2b2706f1509
1290 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1291 five
1292
1293 diff -r 8e4f0351909e -r 26e6446bb252 b
1294 --- a/b Thu Jan 01 00:00:00 1970 +0000
1295 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1296 @@ -1,1 +1,2 @@
1297 b
1298 +bb
1299 $ hg status -c .
1300 C a
1301 C b
1302 $ ls
1303 a
1304 a.rej
1305 b
1306
1307 Importing with zero success:
1308
1309 $ hg update --rev 'desc(initial)'
1310 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1311 $ hg export --rev 'desc(four)' | hg import --partial -
1312 applying patch from stdin
1313 patching file a
1314 Hunk #1 FAILED at 0
1315 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1316 patch applied partially
1317 (fix the .rej files and run `hg commit --amend`)
1318 [1]
1319
1320 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1321 @ four [Rataxes] 0: +0/-0
1322 |
1323 | o five [Arthur] 1: +1/-0
1324 |/
1325 | o extended jungle [Cornelius] 1: +1/-0
1326 | |
1327 | o jungle [Zephir] 1: +1/-0
1328 | |
1329 | o five [Arthur] 2: +2/-1
1330 | |
1331 | o four [Rataxes] 1: +1/-1
1332 | |
1333 | o three [Celeste] 1: +1/-1
1334 |/
1335 o initial [Babar] 2: +8/-0
1336
1337 $ hg export
1338 # HG changeset patch
1339 # User Rataxes
1340 # Date 0 0
1341 # Thu Jan 01 00:00:00 1970 +0000
1342 # Node ID cb9b1847a74d9ad52e93becaf14b98dbcc274e1e
1343 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1344 four
1345
1346 $ hg status -c .
1347 C a
1348 C b
1349 $ ls
1350 a
1351 a.rej
1352 b
1353
1354 Importing with unknown file:
1355
1356 $ hg update --rev 'desc(initial)'
1357 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1358 $ hg export --rev 'desc("extended jungle")' | hg import --partial -
1359 applying patch from stdin
1360 unable to find 'jungle' for patching
1361 1 out of 1 hunks FAILED -- saving rejects to file jungle.rej
1362 patch applied partially
1363 (fix the .rej files and run `hg commit --amend`)
1364 [1]
1365
1366 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1367 @ extended jungle [Cornelius] 0: +0/-0
1368 |
1369 | o four [Rataxes] 0: +0/-0
1370 |/
1371 | o five [Arthur] 1: +1/-0
1372 |/
1373 | o extended jungle [Cornelius] 1: +1/-0
1374 | |
1375 | o jungle [Zephir] 1: +1/-0
1376 | |
1377 | o five [Arthur] 2: +2/-1
1378 | |
1379 | o four [Rataxes] 1: +1/-1
1380 | |
1381 | o three [Celeste] 1: +1/-1
1382 |/
1383 o initial [Babar] 2: +8/-0
1384
1385 $ hg export
1386 # HG changeset patch
1387 # User Cornelius
1388 # Date 0 0
1389 # Thu Jan 01 00:00:00 1970 +0000
1390 # Node ID 1fb1f86bef43c5a75918178f8d23c29fb0a7398d
1391 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1392 extended jungle
1393
1394 $ hg status -c .
1395 C a
1396 C b
1397 $ ls
1398 a
1399 a.rej
1400 b
1401 jungle.rej
1402
1403 Importing multiple failing patches:
1404
1405 $ hg update --rev 'desc(initial)'
1406 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1407 $ echo 'B' > b # just to make another commit
1408 $ hg commit -m "a new base"
1409 created new head
1410 $ hg export --rev 'desc("extended jungle") + desc("four")' | hg import --partial -
1411 applying patch from stdin
1412 patching file a
1413 Hunk #1 FAILED at 0
1414 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1415 patch applied partially
1416 (fix the .rej files and run `hg commit --amend`)
1417 [1]
1418 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1419 @ four [Rataxes] 0: +0/-0
1420 |
1421 o a new base [test] 1: +1/-1
1422 |
1423 | o extended jungle [Cornelius] 0: +0/-0
1424 |/
1425 | o four [Rataxes] 0: +0/-0
1426 |/
1427 | o five [Arthur] 1: +1/-0
1428 |/
1429 | o extended jungle [Cornelius] 1: +1/-0
1430 | |
1431 | o jungle [Zephir] 1: +1/-0
1432 | |
1433 | o five [Arthur] 2: +2/-1
1434 | |
1435 | o four [Rataxes] 1: +1/-1
1436 | |
1437 | o three [Celeste] 1: +1/-1
1438 |/
1439 o initial [Babar] 2: +8/-0
1440
1441 $ hg export
1442 # HG changeset patch
1443 # User Rataxes
1444 # Date 0 0
1445 # Thu Jan 01 00:00:00 1970 +0000
1446 # Node ID a9d7b6d0ffbb4eb12b7d5939250fcd42e8930a1d
1447 # Parent f59f8d2e95a8ca5b1b4ca64320140da85f3b44fd
1448 four
1449
1450 $ hg status -c .
1451 C a
1452 C b
General Comments 0
You need to be logged in to leave comments. Login now