##// END OF EJS Templates
refactor rawcommit
Matt Mackall -
r3653:d793e09e default
parent child Browse files
Show More
@@ -1,3132 +1,3126 b''
1 # commands.py - command processing for mercurial
1 # commands.py - command processing for mercurial
2 #
2 #
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from demandload import demandload
8 from demandload import demandload
9 from node import *
9 from node import *
10 from i18n import gettext as _
10 from i18n import gettext as _
11 demandload(globals(), "os re sys signal imp urllib pdb shlex")
11 demandload(globals(), "os re sys signal imp urllib pdb shlex")
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
13 demandload(globals(), "difflib patch tempfile time")
13 demandload(globals(), "difflib patch tempfile time")
14 demandload(globals(), "traceback errno version atexit bz2")
14 demandload(globals(), "traceback errno version atexit bz2")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
16
16
17 class UnknownCommand(Exception):
17 class UnknownCommand(Exception):
18 """Exception raised if command is not in the command table."""
18 """Exception raised if command is not in the command table."""
19 class AmbiguousCommand(Exception):
19 class AmbiguousCommand(Exception):
20 """Exception raised if command shortcut matches more than one command."""
20 """Exception raised if command shortcut matches more than one command."""
21
21
22 def bail_if_changed(repo):
22 def bail_if_changed(repo):
23 modified, added, removed, deleted = repo.status()[:4]
23 modified, added, removed, deleted = repo.status()[:4]
24 if modified or added or removed or deleted:
24 if modified or added or removed or deleted:
25 raise util.Abort(_("outstanding uncommitted changes"))
25 raise util.Abort(_("outstanding uncommitted changes"))
26
26
27 def relpath(repo, args):
27 def relpath(repo, args):
28 cwd = repo.getcwd()
28 cwd = repo.getcwd()
29 if cwd:
29 if cwd:
30 return [util.normpath(os.path.join(cwd, x)) for x in args]
30 return [util.normpath(os.path.join(cwd, x)) for x in args]
31 return args
31 return args
32
32
33 def logmessage(opts):
33 def logmessage(opts):
34 """ get the log message according to -m and -l option """
34 """ get the log message according to -m and -l option """
35 message = opts['message']
35 message = opts['message']
36 logfile = opts['logfile']
36 logfile = opts['logfile']
37
37
38 if message and logfile:
38 if message and logfile:
39 raise util.Abort(_('options --message and --logfile are mutually '
39 raise util.Abort(_('options --message and --logfile are mutually '
40 'exclusive'))
40 'exclusive'))
41 if not message and logfile:
41 if not message and logfile:
42 try:
42 try:
43 if logfile == '-':
43 if logfile == '-':
44 message = sys.stdin.read()
44 message = sys.stdin.read()
45 else:
45 else:
46 message = open(logfile).read()
46 message = open(logfile).read()
47 except IOError, inst:
47 except IOError, inst:
48 raise util.Abort(_("can't read commit message '%s': %s") %
48 raise util.Abort(_("can't read commit message '%s': %s") %
49 (logfile, inst.strerror))
49 (logfile, inst.strerror))
50 return message
50 return message
51
51
52 def write_bundle(cg, filename=None, compress=True):
52 def write_bundle(cg, filename=None, compress=True):
53 """Write a bundle file and return its filename.
53 """Write a bundle file and return its filename.
54
54
55 Existing files will not be overwritten.
55 Existing files will not be overwritten.
56 If no filename is specified, a temporary file is created.
56 If no filename is specified, a temporary file is created.
57 bz2 compression can be turned off.
57 bz2 compression can be turned off.
58 The bundle file will be deleted in case of errors.
58 The bundle file will be deleted in case of errors.
59 """
59 """
60 class nocompress(object):
60 class nocompress(object):
61 def compress(self, x):
61 def compress(self, x):
62 return x
62 return x
63 def flush(self):
63 def flush(self):
64 return ""
64 return ""
65
65
66 fh = None
66 fh = None
67 cleanup = None
67 cleanup = None
68 try:
68 try:
69 if filename:
69 if filename:
70 if os.path.exists(filename):
70 if os.path.exists(filename):
71 raise util.Abort(_("file '%s' already exists") % filename)
71 raise util.Abort(_("file '%s' already exists") % filename)
72 fh = open(filename, "wb")
72 fh = open(filename, "wb")
73 else:
73 else:
74 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
74 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
75 fh = os.fdopen(fd, "wb")
75 fh = os.fdopen(fd, "wb")
76 cleanup = filename
76 cleanup = filename
77
77
78 if compress:
78 if compress:
79 fh.write("HG10")
79 fh.write("HG10")
80 z = bz2.BZ2Compressor(9)
80 z = bz2.BZ2Compressor(9)
81 else:
81 else:
82 fh.write("HG10UN")
82 fh.write("HG10UN")
83 z = nocompress()
83 z = nocompress()
84 # parse the changegroup data, otherwise we will block
84 # parse the changegroup data, otherwise we will block
85 # in case of sshrepo because we don't know the end of the stream
85 # in case of sshrepo because we don't know the end of the stream
86
86
87 # an empty chunkiter is the end of the changegroup
87 # an empty chunkiter is the end of the changegroup
88 empty = False
88 empty = False
89 while not empty:
89 while not empty:
90 empty = True
90 empty = True
91 for chunk in changegroup.chunkiter(cg):
91 for chunk in changegroup.chunkiter(cg):
92 empty = False
92 empty = False
93 fh.write(z.compress(changegroup.genchunk(chunk)))
93 fh.write(z.compress(changegroup.genchunk(chunk)))
94 fh.write(z.compress(changegroup.closechunk()))
94 fh.write(z.compress(changegroup.closechunk()))
95 fh.write(z.flush())
95 fh.write(z.flush())
96 cleanup = None
96 cleanup = None
97 return filename
97 return filename
98 finally:
98 finally:
99 if fh is not None:
99 if fh is not None:
100 fh.close()
100 fh.close()
101 if cleanup is not None:
101 if cleanup is not None:
102 os.unlink(cleanup)
102 os.unlink(cleanup)
103
103
104 def setremoteconfig(ui, opts):
104 def setremoteconfig(ui, opts):
105 "copy remote options to ui tree"
105 "copy remote options to ui tree"
106 if opts.get('ssh'):
106 if opts.get('ssh'):
107 ui.setconfig("ui", "ssh", opts['ssh'])
107 ui.setconfig("ui", "ssh", opts['ssh'])
108 if opts.get('remotecmd'):
108 if opts.get('remotecmd'):
109 ui.setconfig("ui", "remotecmd", opts['remotecmd'])
109 ui.setconfig("ui", "remotecmd", opts['remotecmd'])
110
110
111 def help_(ui, name=None, with_version=False):
111 def help_(ui, name=None, with_version=False):
112 """show help for a command, extension, or list of commands
112 """show help for a command, extension, or list of commands
113
113
114 With no arguments, print a list of commands and short help.
114 With no arguments, print a list of commands and short help.
115
115
116 Given a command name, print help for that command.
116 Given a command name, print help for that command.
117
117
118 Given an extension name, print help for that extension, and the
118 Given an extension name, print help for that extension, and the
119 commands it provides."""
119 commands it provides."""
120 option_lists = []
120 option_lists = []
121
121
122 def helpcmd(name):
122 def helpcmd(name):
123 if with_version:
123 if with_version:
124 version_(ui)
124 version_(ui)
125 ui.write('\n')
125 ui.write('\n')
126 aliases, i = findcmd(ui, name)
126 aliases, i = findcmd(ui, name)
127 # synopsis
127 # synopsis
128 ui.write("%s\n\n" % i[2])
128 ui.write("%s\n\n" % i[2])
129
129
130 # description
130 # description
131 doc = i[0].__doc__
131 doc = i[0].__doc__
132 if not doc:
132 if not doc:
133 doc = _("(No help text available)")
133 doc = _("(No help text available)")
134 if ui.quiet:
134 if ui.quiet:
135 doc = doc.splitlines(0)[0]
135 doc = doc.splitlines(0)[0]
136 ui.write("%s\n" % doc.rstrip())
136 ui.write("%s\n" % doc.rstrip())
137
137
138 if not ui.quiet:
138 if not ui.quiet:
139 # aliases
139 # aliases
140 if len(aliases) > 1:
140 if len(aliases) > 1:
141 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
141 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
142
142
143 # options
143 # options
144 if i[1]:
144 if i[1]:
145 option_lists.append(("options", i[1]))
145 option_lists.append(("options", i[1]))
146
146
147 def helplist(select=None):
147 def helplist(select=None):
148 h = {}
148 h = {}
149 cmds = {}
149 cmds = {}
150 for c, e in table.items():
150 for c, e in table.items():
151 f = c.split("|", 1)[0]
151 f = c.split("|", 1)[0]
152 if select and not select(f):
152 if select and not select(f):
153 continue
153 continue
154 if name == "shortlist" and not f.startswith("^"):
154 if name == "shortlist" and not f.startswith("^"):
155 continue
155 continue
156 f = f.lstrip("^")
156 f = f.lstrip("^")
157 if not ui.debugflag and f.startswith("debug"):
157 if not ui.debugflag and f.startswith("debug"):
158 continue
158 continue
159 doc = e[0].__doc__
159 doc = e[0].__doc__
160 if not doc:
160 if not doc:
161 doc = _("(No help text available)")
161 doc = _("(No help text available)")
162 h[f] = doc.splitlines(0)[0].rstrip()
162 h[f] = doc.splitlines(0)[0].rstrip()
163 cmds[f] = c.lstrip("^")
163 cmds[f] = c.lstrip("^")
164
164
165 fns = h.keys()
165 fns = h.keys()
166 fns.sort()
166 fns.sort()
167 m = max(map(len, fns))
167 m = max(map(len, fns))
168 for f in fns:
168 for f in fns:
169 if ui.verbose:
169 if ui.verbose:
170 commands = cmds[f].replace("|",", ")
170 commands = cmds[f].replace("|",", ")
171 ui.write(" %s:\n %s\n"%(commands, h[f]))
171 ui.write(" %s:\n %s\n"%(commands, h[f]))
172 else:
172 else:
173 ui.write(' %-*s %s\n' % (m, f, h[f]))
173 ui.write(' %-*s %s\n' % (m, f, h[f]))
174
174
175 def helpext(name):
175 def helpext(name):
176 try:
176 try:
177 mod = findext(name)
177 mod = findext(name)
178 except KeyError:
178 except KeyError:
179 raise UnknownCommand(name)
179 raise UnknownCommand(name)
180
180
181 doc = (mod.__doc__ or _('No help text available')).splitlines(0)
181 doc = (mod.__doc__ or _('No help text available')).splitlines(0)
182 ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0]))
182 ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0]))
183 for d in doc[1:]:
183 for d in doc[1:]:
184 ui.write(d, '\n')
184 ui.write(d, '\n')
185
185
186 ui.status('\n')
186 ui.status('\n')
187 if ui.verbose:
187 if ui.verbose:
188 ui.status(_('list of commands:\n\n'))
188 ui.status(_('list of commands:\n\n'))
189 else:
189 else:
190 ui.status(_('list of commands (use "hg help -v %s" '
190 ui.status(_('list of commands (use "hg help -v %s" '
191 'to show aliases and global options):\n\n') % name)
191 'to show aliases and global options):\n\n') % name)
192
192
193 modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable])
193 modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable])
194 helplist(modcmds.has_key)
194 helplist(modcmds.has_key)
195
195
196 if name and name != 'shortlist':
196 if name and name != 'shortlist':
197 try:
197 try:
198 helpcmd(name)
198 helpcmd(name)
199 except UnknownCommand:
199 except UnknownCommand:
200 helpext(name)
200 helpext(name)
201
201
202 else:
202 else:
203 # program name
203 # program name
204 if ui.verbose or with_version:
204 if ui.verbose or with_version:
205 version_(ui)
205 version_(ui)
206 else:
206 else:
207 ui.status(_("Mercurial Distributed SCM\n"))
207 ui.status(_("Mercurial Distributed SCM\n"))
208 ui.status('\n')
208 ui.status('\n')
209
209
210 # list of commands
210 # list of commands
211 if name == "shortlist":
211 if name == "shortlist":
212 ui.status(_('basic commands (use "hg help" '
212 ui.status(_('basic commands (use "hg help" '
213 'for the full list or option "-v" for details):\n\n'))
213 'for the full list or option "-v" for details):\n\n'))
214 elif ui.verbose:
214 elif ui.verbose:
215 ui.status(_('list of commands:\n\n'))
215 ui.status(_('list of commands:\n\n'))
216 else:
216 else:
217 ui.status(_('list of commands (use "hg help -v" '
217 ui.status(_('list of commands (use "hg help -v" '
218 'to show aliases and global options):\n\n'))
218 'to show aliases and global options):\n\n'))
219
219
220 helplist()
220 helplist()
221
221
222 # global options
222 # global options
223 if ui.verbose:
223 if ui.verbose:
224 option_lists.append(("global options", globalopts))
224 option_lists.append(("global options", globalopts))
225
225
226 # list all option lists
226 # list all option lists
227 opt_output = []
227 opt_output = []
228 for title, options in option_lists:
228 for title, options in option_lists:
229 opt_output.append(("\n%s:\n" % title, None))
229 opt_output.append(("\n%s:\n" % title, None))
230 for shortopt, longopt, default, desc in options:
230 for shortopt, longopt, default, desc in options:
231 if "DEPRECATED" in desc and not ui.verbose: continue
231 if "DEPRECATED" in desc and not ui.verbose: continue
232 opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
232 opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
233 longopt and " --%s" % longopt),
233 longopt and " --%s" % longopt),
234 "%s%s" % (desc,
234 "%s%s" % (desc,
235 default
235 default
236 and _(" (default: %s)") % default
236 and _(" (default: %s)") % default
237 or "")))
237 or "")))
238
238
239 if opt_output:
239 if opt_output:
240 opts_len = max([len(line[0]) for line in opt_output if line[1]])
240 opts_len = max([len(line[0]) for line in opt_output if line[1]])
241 for first, second in opt_output:
241 for first, second in opt_output:
242 if second:
242 if second:
243 ui.write(" %-*s %s\n" % (opts_len, first, second))
243 ui.write(" %-*s %s\n" % (opts_len, first, second))
244 else:
244 else:
245 ui.write("%s\n" % first)
245 ui.write("%s\n" % first)
246
246
247 # Commands start here, listed alphabetically
247 # Commands start here, listed alphabetically
248
248
249 def add(ui, repo, *pats, **opts):
249 def add(ui, repo, *pats, **opts):
250 """add the specified files on the next commit
250 """add the specified files on the next commit
251
251
252 Schedule files to be version controlled and added to the repository.
252 Schedule files to be version controlled and added to the repository.
253
253
254 The files will be added to the repository at the next commit.
254 The files will be added to the repository at the next commit.
255
255
256 If no names are given, add all files in the repository.
256 If no names are given, add all files in the repository.
257 """
257 """
258
258
259 names = []
259 names = []
260 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
260 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
261 if exact:
261 if exact:
262 if ui.verbose:
262 if ui.verbose:
263 ui.status(_('adding %s\n') % rel)
263 ui.status(_('adding %s\n') % rel)
264 names.append(abs)
264 names.append(abs)
265 elif repo.dirstate.state(abs) == '?':
265 elif repo.dirstate.state(abs) == '?':
266 ui.status(_('adding %s\n') % rel)
266 ui.status(_('adding %s\n') % rel)
267 names.append(abs)
267 names.append(abs)
268 if not opts.get('dry_run'):
268 if not opts.get('dry_run'):
269 repo.add(names)
269 repo.add(names)
270
270
271 def addremove(ui, repo, *pats, **opts):
271 def addremove(ui, repo, *pats, **opts):
272 """add all new files, delete all missing files
272 """add all new files, delete all missing files
273
273
274 Add all new files and remove all missing files from the repository.
274 Add all new files and remove all missing files from the repository.
275
275
276 New files are ignored if they match any of the patterns in .hgignore. As
276 New files are ignored if they match any of the patterns in .hgignore. As
277 with add, these changes take effect at the next commit.
277 with add, these changes take effect at the next commit.
278
278
279 Use the -s option to detect renamed files. With a parameter > 0,
279 Use the -s option to detect renamed files. With a parameter > 0,
280 this compares every removed file with every added file and records
280 this compares every removed file with every added file and records
281 those similar enough as renames. This option takes a percentage
281 those similar enough as renames. This option takes a percentage
282 between 0 (disabled) and 100 (files must be identical) as its
282 between 0 (disabled) and 100 (files must be identical) as its
283 parameter. Detecting renamed files this way can be expensive.
283 parameter. Detecting renamed files this way can be expensive.
284 """
284 """
285 sim = float(opts.get('similarity') or 0)
285 sim = float(opts.get('similarity') or 0)
286 if sim < 0 or sim > 100:
286 if sim < 0 or sim > 100:
287 raise util.Abort(_('similarity must be between 0 and 100'))
287 raise util.Abort(_('similarity must be between 0 and 100'))
288 return cmdutil.addremove(repo, pats, opts, similarity=sim/100.)
288 return cmdutil.addremove(repo, pats, opts, similarity=sim/100.)
289
289
290 def annotate(ui, repo, *pats, **opts):
290 def annotate(ui, repo, *pats, **opts):
291 """show changeset information per file line
291 """show changeset information per file line
292
292
293 List changes in files, showing the revision id responsible for each line
293 List changes in files, showing the revision id responsible for each line
294
294
295 This command is useful to discover who did a change or when a change took
295 This command is useful to discover who did a change or when a change took
296 place.
296 place.
297
297
298 Without the -a option, annotate will avoid processing files it
298 Without the -a option, annotate will avoid processing files it
299 detects as binary. With -a, annotate will generate an annotation
299 detects as binary. With -a, annotate will generate an annotation
300 anyway, probably with undesirable results.
300 anyway, probably with undesirable results.
301 """
301 """
302 getdate = util.cachefunc(lambda x: util.datestr(x.date()))
302 getdate = util.cachefunc(lambda x: util.datestr(x.date()))
303
303
304 if not pats:
304 if not pats:
305 raise util.Abort(_('at least one file name or pattern required'))
305 raise util.Abort(_('at least one file name or pattern required'))
306
306
307 opmap = [['user', lambda x: ui.shortuser(x.user())],
307 opmap = [['user', lambda x: ui.shortuser(x.user())],
308 ['number', lambda x: str(x.rev())],
308 ['number', lambda x: str(x.rev())],
309 ['changeset', lambda x: short(x.node())],
309 ['changeset', lambda x: short(x.node())],
310 ['date', getdate], ['follow', lambda x: x.path()]]
310 ['date', getdate], ['follow', lambda x: x.path()]]
311 if (not opts['user'] and not opts['changeset'] and not opts['date']
311 if (not opts['user'] and not opts['changeset'] and not opts['date']
312 and not opts['follow']):
312 and not opts['follow']):
313 opts['number'] = 1
313 opts['number'] = 1
314
314
315 ctx = repo.changectx(opts['rev'])
315 ctx = repo.changectx(opts['rev'])
316
316
317 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
317 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
318 node=ctx.node()):
318 node=ctx.node()):
319 fctx = ctx.filectx(abs)
319 fctx = ctx.filectx(abs)
320 if not opts['text'] and util.binary(fctx.data()):
320 if not opts['text'] and util.binary(fctx.data()):
321 ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
321 ui.write(_("%s: binary file\n") % ((pats and rel) or abs))
322 continue
322 continue
323
323
324 lines = fctx.annotate(follow=opts.get('follow'))
324 lines = fctx.annotate(follow=opts.get('follow'))
325 pieces = []
325 pieces = []
326
326
327 for o, f in opmap:
327 for o, f in opmap:
328 if opts[o]:
328 if opts[o]:
329 l = [f(n) for n, dummy in lines]
329 l = [f(n) for n, dummy in lines]
330 if l:
330 if l:
331 m = max(map(len, l))
331 m = max(map(len, l))
332 pieces.append(["%*s" % (m, x) for x in l])
332 pieces.append(["%*s" % (m, x) for x in l])
333
333
334 if pieces:
334 if pieces:
335 for p, l in zip(zip(*pieces), lines):
335 for p, l in zip(zip(*pieces), lines):
336 ui.write("%s: %s" % (" ".join(p), l[1]))
336 ui.write("%s: %s" % (" ".join(p), l[1]))
337
337
338 def archive(ui, repo, dest, **opts):
338 def archive(ui, repo, dest, **opts):
339 '''create unversioned archive of a repository revision
339 '''create unversioned archive of a repository revision
340
340
341 By default, the revision used is the parent of the working
341 By default, the revision used is the parent of the working
342 directory; use "-r" to specify a different revision.
342 directory; use "-r" to specify a different revision.
343
343
344 To specify the type of archive to create, use "-t". Valid
344 To specify the type of archive to create, use "-t". Valid
345 types are:
345 types are:
346
346
347 "files" (default): a directory full of files
347 "files" (default): a directory full of files
348 "tar": tar archive, uncompressed
348 "tar": tar archive, uncompressed
349 "tbz2": tar archive, compressed using bzip2
349 "tbz2": tar archive, compressed using bzip2
350 "tgz": tar archive, compressed using gzip
350 "tgz": tar archive, compressed using gzip
351 "uzip": zip archive, uncompressed
351 "uzip": zip archive, uncompressed
352 "zip": zip archive, compressed using deflate
352 "zip": zip archive, compressed using deflate
353
353
354 The exact name of the destination archive or directory is given
354 The exact name of the destination archive or directory is given
355 using a format string; see "hg help export" for details.
355 using a format string; see "hg help export" for details.
356
356
357 Each member added to an archive file has a directory prefix
357 Each member added to an archive file has a directory prefix
358 prepended. Use "-p" to specify a format string for the prefix.
358 prepended. Use "-p" to specify a format string for the prefix.
359 The default is the basename of the archive, with suffixes removed.
359 The default is the basename of the archive, with suffixes removed.
360 '''
360 '''
361
361
362 node = repo.changectx(opts['rev']).node()
362 node = repo.changectx(opts['rev']).node()
363 dest = cmdutil.make_filename(repo, dest, node)
363 dest = cmdutil.make_filename(repo, dest, node)
364 if os.path.realpath(dest) == repo.root:
364 if os.path.realpath(dest) == repo.root:
365 raise util.Abort(_('repository root cannot be destination'))
365 raise util.Abort(_('repository root cannot be destination'))
366 dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts)
366 dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts)
367 kind = opts.get('type') or 'files'
367 kind = opts.get('type') or 'files'
368 prefix = opts['prefix']
368 prefix = opts['prefix']
369 if dest == '-':
369 if dest == '-':
370 if kind == 'files':
370 if kind == 'files':
371 raise util.Abort(_('cannot archive plain files to stdout'))
371 raise util.Abort(_('cannot archive plain files to stdout'))
372 dest = sys.stdout
372 dest = sys.stdout
373 if not prefix: prefix = os.path.basename(repo.root) + '-%h'
373 if not prefix: prefix = os.path.basename(repo.root) + '-%h'
374 prefix = cmdutil.make_filename(repo, prefix, node)
374 prefix = cmdutil.make_filename(repo, prefix, node)
375 archival.archive(repo, dest, node, kind, not opts['no_decode'],
375 archival.archive(repo, dest, node, kind, not opts['no_decode'],
376 matchfn, prefix)
376 matchfn, prefix)
377
377
378 def backout(ui, repo, rev, **opts):
378 def backout(ui, repo, rev, **opts):
379 '''reverse effect of earlier changeset
379 '''reverse effect of earlier changeset
380
380
381 Commit the backed out changes as a new changeset. The new
381 Commit the backed out changes as a new changeset. The new
382 changeset is a child of the backed out changeset.
382 changeset is a child of the backed out changeset.
383
383
384 If you back out a changeset other than the tip, a new head is
384 If you back out a changeset other than the tip, a new head is
385 created. This head is the parent of the working directory. If
385 created. This head is the parent of the working directory. If
386 you back out an old changeset, your working directory will appear
386 you back out an old changeset, your working directory will appear
387 old after the backout. You should merge the backout changeset
387 old after the backout. You should merge the backout changeset
388 with another head.
388 with another head.
389
389
390 The --merge option remembers the parent of the working directory
390 The --merge option remembers the parent of the working directory
391 before starting the backout, then merges the new head with that
391 before starting the backout, then merges the new head with that
392 changeset afterwards. This saves you from doing the merge by
392 changeset afterwards. This saves you from doing the merge by
393 hand. The result of this merge is not committed, as for a normal
393 hand. The result of this merge is not committed, as for a normal
394 merge.'''
394 merge.'''
395
395
396 bail_if_changed(repo)
396 bail_if_changed(repo)
397 op1, op2 = repo.dirstate.parents()
397 op1, op2 = repo.dirstate.parents()
398 if op2 != nullid:
398 if op2 != nullid:
399 raise util.Abort(_('outstanding uncommitted merge'))
399 raise util.Abort(_('outstanding uncommitted merge'))
400 node = repo.lookup(rev)
400 node = repo.lookup(rev)
401 p1, p2 = repo.changelog.parents(node)
401 p1, p2 = repo.changelog.parents(node)
402 if p1 == nullid:
402 if p1 == nullid:
403 raise util.Abort(_('cannot back out a change with no parents'))
403 raise util.Abort(_('cannot back out a change with no parents'))
404 if p2 != nullid:
404 if p2 != nullid:
405 if not opts['parent']:
405 if not opts['parent']:
406 raise util.Abort(_('cannot back out a merge changeset without '
406 raise util.Abort(_('cannot back out a merge changeset without '
407 '--parent'))
407 '--parent'))
408 p = repo.lookup(opts['parent'])
408 p = repo.lookup(opts['parent'])
409 if p not in (p1, p2):
409 if p not in (p1, p2):
410 raise util.Abort(_('%s is not a parent of %s' %
410 raise util.Abort(_('%s is not a parent of %s' %
411 (short(p), short(node))))
411 (short(p), short(node))))
412 parent = p
412 parent = p
413 else:
413 else:
414 if opts['parent']:
414 if opts['parent']:
415 raise util.Abort(_('cannot use --parent on non-merge changeset'))
415 raise util.Abort(_('cannot use --parent on non-merge changeset'))
416 parent = p1
416 parent = p1
417 hg.clean(repo, node, show_stats=False)
417 hg.clean(repo, node, show_stats=False)
418 revert_opts = opts.copy()
418 revert_opts = opts.copy()
419 revert_opts['all'] = True
419 revert_opts['all'] = True
420 revert_opts['rev'] = hex(parent)
420 revert_opts['rev'] = hex(parent)
421 revert(ui, repo, **revert_opts)
421 revert(ui, repo, **revert_opts)
422 commit_opts = opts.copy()
422 commit_opts = opts.copy()
423 commit_opts['addremove'] = False
423 commit_opts['addremove'] = False
424 if not commit_opts['message'] and not commit_opts['logfile']:
424 if not commit_opts['message'] and not commit_opts['logfile']:
425 commit_opts['message'] = _("Backed out changeset %s") % (hex(node))
425 commit_opts['message'] = _("Backed out changeset %s") % (hex(node))
426 commit_opts['force_editor'] = True
426 commit_opts['force_editor'] = True
427 commit(ui, repo, **commit_opts)
427 commit(ui, repo, **commit_opts)
428 def nice(node):
428 def nice(node):
429 return '%d:%s' % (repo.changelog.rev(node), short(node))
429 return '%d:%s' % (repo.changelog.rev(node), short(node))
430 ui.status(_('changeset %s backs out changeset %s\n') %
430 ui.status(_('changeset %s backs out changeset %s\n') %
431 (nice(repo.changelog.tip()), nice(node)))
431 (nice(repo.changelog.tip()), nice(node)))
432 if op1 != node:
432 if op1 != node:
433 if opts['merge']:
433 if opts['merge']:
434 ui.status(_('merging with changeset %s\n') % nice(op1))
434 ui.status(_('merging with changeset %s\n') % nice(op1))
435 n = _lookup(repo, hex(op1))
435 n = _lookup(repo, hex(op1))
436 hg.merge(repo, n)
436 hg.merge(repo, n)
437 else:
437 else:
438 ui.status(_('the backout changeset is a new head - '
438 ui.status(_('the backout changeset is a new head - '
439 'do not forget to merge\n'))
439 'do not forget to merge\n'))
440 ui.status(_('(use "backout --merge" '
440 ui.status(_('(use "backout --merge" '
441 'if you want to auto-merge)\n'))
441 'if you want to auto-merge)\n'))
442
442
443 def branch(ui, repo, label=None):
443 def branch(ui, repo, label=None):
444 """set or show the current branch name
444 """set or show the current branch name
445
445
446 With <name>, set the current branch name. Otherwise, show the
446 With <name>, set the current branch name. Otherwise, show the
447 current branch name.
447 current branch name.
448 """
448 """
449
449
450 if label is not None:
450 if label is not None:
451 repo.opener("branch", "w").write(label)
451 repo.opener("branch", "w").write(label)
452 else:
452 else:
453 b = repo.workingctx().branch()
453 b = repo.workingctx().branch()
454 if b:
454 if b:
455 ui.write("%s\n" % b)
455 ui.write("%s\n" % b)
456
456
457 def branches(ui, repo):
457 def branches(ui, repo):
458 """list repository named branches
458 """list repository named branches
459
459
460 List the repository's named branches.
460 List the repository's named branches.
461 """
461 """
462 b = repo.branchtags()
462 b = repo.branchtags()
463 l = [(-repo.changelog.rev(n), n, t) for t,n in b.items()]
463 l = [(-repo.changelog.rev(n), n, t) for t,n in b.items()]
464 l.sort()
464 l.sort()
465 for r, n, t in l:
465 for r, n, t in l:
466 hexfunc = ui.debugflag and hex or short
466 hexfunc = ui.debugflag and hex or short
467 if ui.quiet:
467 if ui.quiet:
468 ui.write("%s\n" % t)
468 ui.write("%s\n" % t)
469 else:
469 else:
470 ui.write("%-30s %s:%s\n" % (t, -r, hexfunc(n)))
470 ui.write("%-30s %s:%s\n" % (t, -r, hexfunc(n)))
471
471
472 def bundle(ui, repo, fname, dest=None, **opts):
472 def bundle(ui, repo, fname, dest=None, **opts):
473 """create a changegroup file
473 """create a changegroup file
474
474
475 Generate a compressed changegroup file collecting changesets not
475 Generate a compressed changegroup file collecting changesets not
476 found in the other repository.
476 found in the other repository.
477
477
478 If no destination repository is specified the destination is assumed
478 If no destination repository is specified the destination is assumed
479 to have all the nodes specified by one or more --base parameters.
479 to have all the nodes specified by one or more --base parameters.
480
480
481 The bundle file can then be transferred using conventional means and
481 The bundle file can then be transferred using conventional means and
482 applied to another repository with the unbundle or pull command.
482 applied to another repository with the unbundle or pull command.
483 This is useful when direct push and pull are not available or when
483 This is useful when direct push and pull are not available or when
484 exporting an entire repository is undesirable.
484 exporting an entire repository is undesirable.
485
485
486 Applying bundles preserves all changeset contents including
486 Applying bundles preserves all changeset contents including
487 permissions, copy/rename information, and revision history.
487 permissions, copy/rename information, and revision history.
488 """
488 """
489 revs = opts.get('rev') or None
489 revs = opts.get('rev') or None
490 if revs:
490 if revs:
491 revs = [repo.lookup(rev) for rev in revs]
491 revs = [repo.lookup(rev) for rev in revs]
492 base = opts.get('base')
492 base = opts.get('base')
493 if base:
493 if base:
494 if dest:
494 if dest:
495 raise util.Abort(_("--base is incompatible with specifiying "
495 raise util.Abort(_("--base is incompatible with specifiying "
496 "a destination"))
496 "a destination"))
497 base = [repo.lookup(rev) for rev in base]
497 base = [repo.lookup(rev) for rev in base]
498 # create the right base
498 # create the right base
499 # XXX: nodesbetween / changegroup* should be "fixed" instead
499 # XXX: nodesbetween / changegroup* should be "fixed" instead
500 o = []
500 o = []
501 has = {nullid: None}
501 has = {nullid: None}
502 for n in base:
502 for n in base:
503 has.update(repo.changelog.reachable(n))
503 has.update(repo.changelog.reachable(n))
504 if revs:
504 if revs:
505 visit = list(revs)
505 visit = list(revs)
506 else:
506 else:
507 visit = repo.changelog.heads()
507 visit = repo.changelog.heads()
508 seen = {}
508 seen = {}
509 while visit:
509 while visit:
510 n = visit.pop(0)
510 n = visit.pop(0)
511 parents = [p for p in repo.changelog.parents(n) if p not in has]
511 parents = [p for p in repo.changelog.parents(n) if p not in has]
512 if len(parents) == 0:
512 if len(parents) == 0:
513 o.insert(0, n)
513 o.insert(0, n)
514 else:
514 else:
515 for p in parents:
515 for p in parents:
516 if p not in seen:
516 if p not in seen:
517 seen[p] = 1
517 seen[p] = 1
518 visit.append(p)
518 visit.append(p)
519 else:
519 else:
520 setremoteconfig(ui, opts)
520 setremoteconfig(ui, opts)
521 dest = ui.expandpath(dest or 'default-push', dest or 'default')
521 dest = ui.expandpath(dest or 'default-push', dest or 'default')
522 other = hg.repository(ui, dest)
522 other = hg.repository(ui, dest)
523 o = repo.findoutgoing(other, force=opts['force'])
523 o = repo.findoutgoing(other, force=opts['force'])
524
524
525 if revs:
525 if revs:
526 cg = repo.changegroupsubset(o, revs, 'bundle')
526 cg = repo.changegroupsubset(o, revs, 'bundle')
527 else:
527 else:
528 cg = repo.changegroup(o, 'bundle')
528 cg = repo.changegroup(o, 'bundle')
529 write_bundle(cg, fname)
529 write_bundle(cg, fname)
530
530
531 def cat(ui, repo, file1, *pats, **opts):
531 def cat(ui, repo, file1, *pats, **opts):
532 """output the latest or given revisions of files
532 """output the latest or given revisions of files
533
533
534 Print the specified files as they were at the given revision.
534 Print the specified files as they were at the given revision.
535 If no revision is given then working dir parent is used, or tip
535 If no revision is given then working dir parent is used, or tip
536 if no revision is checked out.
536 if no revision is checked out.
537
537
538 Output may be to a file, in which case the name of the file is
538 Output may be to a file, in which case the name of the file is
539 given using a format string. The formatting rules are the same as
539 given using a format string. The formatting rules are the same as
540 for the export command, with the following additions:
540 for the export command, with the following additions:
541
541
542 %s basename of file being printed
542 %s basename of file being printed
543 %d dirname of file being printed, or '.' if in repo root
543 %d dirname of file being printed, or '.' if in repo root
544 %p root-relative path name of file being printed
544 %p root-relative path name of file being printed
545 """
545 """
546 ctx = repo.changectx(opts['rev'])
546 ctx = repo.changectx(opts['rev'])
547 for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
547 for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
548 ctx.node()):
548 ctx.node()):
549 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
549 fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs)
550 fp.write(ctx.filectx(abs).data())
550 fp.write(ctx.filectx(abs).data())
551
551
552 def clone(ui, source, dest=None, **opts):
552 def clone(ui, source, dest=None, **opts):
553 """make a copy of an existing repository
553 """make a copy of an existing repository
554
554
555 Create a copy of an existing repository in a new directory.
555 Create a copy of an existing repository in a new directory.
556
556
557 If no destination directory name is specified, it defaults to the
557 If no destination directory name is specified, it defaults to the
558 basename of the source.
558 basename of the source.
559
559
560 The location of the source is added to the new repository's
560 The location of the source is added to the new repository's
561 .hg/hgrc file, as the default to be used for future pulls.
561 .hg/hgrc file, as the default to be used for future pulls.
562
562
563 For efficiency, hardlinks are used for cloning whenever the source
563 For efficiency, hardlinks are used for cloning whenever the source
564 and destination are on the same filesystem (note this applies only
564 and destination are on the same filesystem (note this applies only
565 to the repository data, not to the checked out files). Some
565 to the repository data, not to the checked out files). Some
566 filesystems, such as AFS, implement hardlinking incorrectly, but
566 filesystems, such as AFS, implement hardlinking incorrectly, but
567 do not report errors. In these cases, use the --pull option to
567 do not report errors. In these cases, use the --pull option to
568 avoid hardlinking.
568 avoid hardlinking.
569
569
570 You can safely clone repositories and checked out files using full
570 You can safely clone repositories and checked out files using full
571 hardlinks with
571 hardlinks with
572
572
573 $ cp -al REPO REPOCLONE
573 $ cp -al REPO REPOCLONE
574
574
575 which is the fastest way to clone. However, the operation is not
575 which is the fastest way to clone. However, the operation is not
576 atomic (making sure REPO is not modified during the operation is
576 atomic (making sure REPO is not modified during the operation is
577 up to you) and you have to make sure your editor breaks hardlinks
577 up to you) and you have to make sure your editor breaks hardlinks
578 (Emacs and most Linux Kernel tools do so).
578 (Emacs and most Linux Kernel tools do so).
579
579
580 If you use the -r option to clone up to a specific revision, no
580 If you use the -r option to clone up to a specific revision, no
581 subsequent revisions will be present in the cloned repository.
581 subsequent revisions will be present in the cloned repository.
582 This option implies --pull, even on local repositories.
582 This option implies --pull, even on local repositories.
583
583
584 See pull for valid source format details.
584 See pull for valid source format details.
585
585
586 It is possible to specify an ssh:// URL as the destination, but no
586 It is possible to specify an ssh:// URL as the destination, but no
587 .hg/hgrc and working directory will be created on the remote side.
587 .hg/hgrc and working directory will be created on the remote side.
588 Look at the help text for the pull command for important details
588 Look at the help text for the pull command for important details
589 about ssh:// URLs.
589 about ssh:// URLs.
590 """
590 """
591 setremoteconfig(ui, opts)
591 setremoteconfig(ui, opts)
592 hg.clone(ui, ui.expandpath(source), dest,
592 hg.clone(ui, ui.expandpath(source), dest,
593 pull=opts['pull'],
593 pull=opts['pull'],
594 stream=opts['uncompressed'],
594 stream=opts['uncompressed'],
595 rev=opts['rev'],
595 rev=opts['rev'],
596 update=not opts['noupdate'])
596 update=not opts['noupdate'])
597
597
598 def commit(ui, repo, *pats, **opts):
598 def commit(ui, repo, *pats, **opts):
599 """commit the specified files or all outstanding changes
599 """commit the specified files or all outstanding changes
600
600
601 Commit changes to the given files into the repository.
601 Commit changes to the given files into the repository.
602
602
603 If a list of files is omitted, all changes reported by "hg status"
603 If a list of files is omitted, all changes reported by "hg status"
604 will be committed.
604 will be committed.
605
605
606 If no commit message is specified, the editor configured in your hgrc
606 If no commit message is specified, the editor configured in your hgrc
607 or in the EDITOR environment variable is started to enter a message.
607 or in the EDITOR environment variable is started to enter a message.
608 """
608 """
609 message = logmessage(opts)
609 message = logmessage(opts)
610
610
611 if opts['addremove']:
611 if opts['addremove']:
612 cmdutil.addremove(repo, pats, opts)
612 cmdutil.addremove(repo, pats, opts)
613 fns, match, anypats = cmdutil.matchpats(repo, pats, opts)
613 fns, match, anypats = cmdutil.matchpats(repo, pats, opts)
614 if pats:
614 if pats:
615 modified, added, removed = repo.status(files=fns, match=match)[:3]
615 modified, added, removed = repo.status(files=fns, match=match)[:3]
616 files = modified + added + removed
616 files = modified + added + removed
617 else:
617 else:
618 files = []
618 files = []
619 try:
619 try:
620 repo.commit(files, message, opts['user'], opts['date'], match,
620 repo.commit(files, message, opts['user'], opts['date'], match,
621 force_editor=opts.get('force_editor'))
621 force_editor=opts.get('force_editor'))
622 except ValueError, inst:
622 except ValueError, inst:
623 raise util.Abort(str(inst))
623 raise util.Abort(str(inst))
624
624
625 def docopy(ui, repo, pats, opts, wlock):
625 def docopy(ui, repo, pats, opts, wlock):
626 # called with the repo lock held
626 # called with the repo lock held
627 cwd = repo.getcwd()
627 cwd = repo.getcwd()
628 errors = 0
628 errors = 0
629 copied = []
629 copied = []
630 targets = {}
630 targets = {}
631
631
632 def okaytocopy(abs, rel, exact):
632 def okaytocopy(abs, rel, exact):
633 reasons = {'?': _('is not managed'),
633 reasons = {'?': _('is not managed'),
634 'a': _('has been marked for add'),
634 'a': _('has been marked for add'),
635 'r': _('has been marked for remove')}
635 'r': _('has been marked for remove')}
636 state = repo.dirstate.state(abs)
636 state = repo.dirstate.state(abs)
637 reason = reasons.get(state)
637 reason = reasons.get(state)
638 if reason:
638 if reason:
639 if state == 'a':
639 if state == 'a':
640 origsrc = repo.dirstate.copied(abs)
640 origsrc = repo.dirstate.copied(abs)
641 if origsrc is not None:
641 if origsrc is not None:
642 return origsrc
642 return origsrc
643 if exact:
643 if exact:
644 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
644 ui.warn(_('%s: not copying - file %s\n') % (rel, reason))
645 else:
645 else:
646 return abs
646 return abs
647
647
648 def copy(origsrc, abssrc, relsrc, target, exact):
648 def copy(origsrc, abssrc, relsrc, target, exact):
649 abstarget = util.canonpath(repo.root, cwd, target)
649 abstarget = util.canonpath(repo.root, cwd, target)
650 reltarget = util.pathto(cwd, abstarget)
650 reltarget = util.pathto(cwd, abstarget)
651 prevsrc = targets.get(abstarget)
651 prevsrc = targets.get(abstarget)
652 if prevsrc is not None:
652 if prevsrc is not None:
653 ui.warn(_('%s: not overwriting - %s collides with %s\n') %
653 ui.warn(_('%s: not overwriting - %s collides with %s\n') %
654 (reltarget, abssrc, prevsrc))
654 (reltarget, abssrc, prevsrc))
655 return
655 return
656 if (not opts['after'] and os.path.exists(reltarget) or
656 if (not opts['after'] and os.path.exists(reltarget) or
657 opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
657 opts['after'] and repo.dirstate.state(abstarget) not in '?r'):
658 if not opts['force']:
658 if not opts['force']:
659 ui.warn(_('%s: not overwriting - file exists\n') %
659 ui.warn(_('%s: not overwriting - file exists\n') %
660 reltarget)
660 reltarget)
661 return
661 return
662 if not opts['after'] and not opts.get('dry_run'):
662 if not opts['after'] and not opts.get('dry_run'):
663 os.unlink(reltarget)
663 os.unlink(reltarget)
664 if opts['after']:
664 if opts['after']:
665 if not os.path.exists(reltarget):
665 if not os.path.exists(reltarget):
666 return
666 return
667 else:
667 else:
668 targetdir = os.path.dirname(reltarget) or '.'
668 targetdir = os.path.dirname(reltarget) or '.'
669 if not os.path.isdir(targetdir) and not opts.get('dry_run'):
669 if not os.path.isdir(targetdir) and not opts.get('dry_run'):
670 os.makedirs(targetdir)
670 os.makedirs(targetdir)
671 try:
671 try:
672 restore = repo.dirstate.state(abstarget) == 'r'
672 restore = repo.dirstate.state(abstarget) == 'r'
673 if restore and not opts.get('dry_run'):
673 if restore and not opts.get('dry_run'):
674 repo.undelete([abstarget], wlock)
674 repo.undelete([abstarget], wlock)
675 try:
675 try:
676 if not opts.get('dry_run'):
676 if not opts.get('dry_run'):
677 util.copyfile(relsrc, reltarget)
677 util.copyfile(relsrc, reltarget)
678 restore = False
678 restore = False
679 finally:
679 finally:
680 if restore:
680 if restore:
681 repo.remove([abstarget], wlock)
681 repo.remove([abstarget], wlock)
682 except IOError, inst:
682 except IOError, inst:
683 if inst.errno == errno.ENOENT:
683 if inst.errno == errno.ENOENT:
684 ui.warn(_('%s: deleted in working copy\n') % relsrc)
684 ui.warn(_('%s: deleted in working copy\n') % relsrc)
685 else:
685 else:
686 ui.warn(_('%s: cannot copy - %s\n') %
686 ui.warn(_('%s: cannot copy - %s\n') %
687 (relsrc, inst.strerror))
687 (relsrc, inst.strerror))
688 errors += 1
688 errors += 1
689 return
689 return
690 if ui.verbose or not exact:
690 if ui.verbose or not exact:
691 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
691 ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
692 targets[abstarget] = abssrc
692 targets[abstarget] = abssrc
693 if abstarget != origsrc and not opts.get('dry_run'):
693 if abstarget != origsrc and not opts.get('dry_run'):
694 repo.copy(origsrc, abstarget, wlock)
694 repo.copy(origsrc, abstarget, wlock)
695 copied.append((abssrc, relsrc, exact))
695 copied.append((abssrc, relsrc, exact))
696
696
697 def targetpathfn(pat, dest, srcs):
697 def targetpathfn(pat, dest, srcs):
698 if os.path.isdir(pat):
698 if os.path.isdir(pat):
699 abspfx = util.canonpath(repo.root, cwd, pat)
699 abspfx = util.canonpath(repo.root, cwd, pat)
700 if destdirexists:
700 if destdirexists:
701 striplen = len(os.path.split(abspfx)[0])
701 striplen = len(os.path.split(abspfx)[0])
702 else:
702 else:
703 striplen = len(abspfx)
703 striplen = len(abspfx)
704 if striplen:
704 if striplen:
705 striplen += len(os.sep)
705 striplen += len(os.sep)
706 res = lambda p: os.path.join(dest, p[striplen:])
706 res = lambda p: os.path.join(dest, p[striplen:])
707 elif destdirexists:
707 elif destdirexists:
708 res = lambda p: os.path.join(dest, os.path.basename(p))
708 res = lambda p: os.path.join(dest, os.path.basename(p))
709 else:
709 else:
710 res = lambda p: dest
710 res = lambda p: dest
711 return res
711 return res
712
712
713 def targetpathafterfn(pat, dest, srcs):
713 def targetpathafterfn(pat, dest, srcs):
714 if util.patkind(pat, None)[0]:
714 if util.patkind(pat, None)[0]:
715 # a mercurial pattern
715 # a mercurial pattern
716 res = lambda p: os.path.join(dest, os.path.basename(p))
716 res = lambda p: os.path.join(dest, os.path.basename(p))
717 else:
717 else:
718 abspfx = util.canonpath(repo.root, cwd, pat)
718 abspfx = util.canonpath(repo.root, cwd, pat)
719 if len(abspfx) < len(srcs[0][0]):
719 if len(abspfx) < len(srcs[0][0]):
720 # A directory. Either the target path contains the last
720 # A directory. Either the target path contains the last
721 # component of the source path or it does not.
721 # component of the source path or it does not.
722 def evalpath(striplen):
722 def evalpath(striplen):
723 score = 0
723 score = 0
724 for s in srcs:
724 for s in srcs:
725 t = os.path.join(dest, s[0][striplen:])
725 t = os.path.join(dest, s[0][striplen:])
726 if os.path.exists(t):
726 if os.path.exists(t):
727 score += 1
727 score += 1
728 return score
728 return score
729
729
730 striplen = len(abspfx)
730 striplen = len(abspfx)
731 if striplen:
731 if striplen:
732 striplen += len(os.sep)
732 striplen += len(os.sep)
733 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
733 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
734 score = evalpath(striplen)
734 score = evalpath(striplen)
735 striplen1 = len(os.path.split(abspfx)[0])
735 striplen1 = len(os.path.split(abspfx)[0])
736 if striplen1:
736 if striplen1:
737 striplen1 += len(os.sep)
737 striplen1 += len(os.sep)
738 if evalpath(striplen1) > score:
738 if evalpath(striplen1) > score:
739 striplen = striplen1
739 striplen = striplen1
740 res = lambda p: os.path.join(dest, p[striplen:])
740 res = lambda p: os.path.join(dest, p[striplen:])
741 else:
741 else:
742 # a file
742 # a file
743 if destdirexists:
743 if destdirexists:
744 res = lambda p: os.path.join(dest, os.path.basename(p))
744 res = lambda p: os.path.join(dest, os.path.basename(p))
745 else:
745 else:
746 res = lambda p: dest
746 res = lambda p: dest
747 return res
747 return res
748
748
749
749
750 pats = list(pats)
750 pats = list(pats)
751 if not pats:
751 if not pats:
752 raise util.Abort(_('no source or destination specified'))
752 raise util.Abort(_('no source or destination specified'))
753 if len(pats) == 1:
753 if len(pats) == 1:
754 raise util.Abort(_('no destination specified'))
754 raise util.Abort(_('no destination specified'))
755 dest = pats.pop()
755 dest = pats.pop()
756 destdirexists = os.path.isdir(dest)
756 destdirexists = os.path.isdir(dest)
757 if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists:
757 if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists:
758 raise util.Abort(_('with multiple sources, destination must be an '
758 raise util.Abort(_('with multiple sources, destination must be an '
759 'existing directory'))
759 'existing directory'))
760 if opts['after']:
760 if opts['after']:
761 tfn = targetpathafterfn
761 tfn = targetpathafterfn
762 else:
762 else:
763 tfn = targetpathfn
763 tfn = targetpathfn
764 copylist = []
764 copylist = []
765 for pat in pats:
765 for pat in pats:
766 srcs = []
766 srcs = []
767 for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts):
767 for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts):
768 origsrc = okaytocopy(abssrc, relsrc, exact)
768 origsrc = okaytocopy(abssrc, relsrc, exact)
769 if origsrc:
769 if origsrc:
770 srcs.append((origsrc, abssrc, relsrc, exact))
770 srcs.append((origsrc, abssrc, relsrc, exact))
771 if not srcs:
771 if not srcs:
772 continue
772 continue
773 copylist.append((tfn(pat, dest, srcs), srcs))
773 copylist.append((tfn(pat, dest, srcs), srcs))
774 if not copylist:
774 if not copylist:
775 raise util.Abort(_('no files to copy'))
775 raise util.Abort(_('no files to copy'))
776
776
777 for targetpath, srcs in copylist:
777 for targetpath, srcs in copylist:
778 for origsrc, abssrc, relsrc, exact in srcs:
778 for origsrc, abssrc, relsrc, exact in srcs:
779 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact)
779 copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact)
780
780
781 if errors:
781 if errors:
782 ui.warn(_('(consider using --after)\n'))
782 ui.warn(_('(consider using --after)\n'))
783 return errors, copied
783 return errors, copied
784
784
785 def copy(ui, repo, *pats, **opts):
785 def copy(ui, repo, *pats, **opts):
786 """mark files as copied for the next commit
786 """mark files as copied for the next commit
787
787
788 Mark dest as having copies of source files. If dest is a
788 Mark dest as having copies of source files. If dest is a
789 directory, copies are put in that directory. If dest is a file,
789 directory, copies are put in that directory. If dest is a file,
790 there can only be one source.
790 there can only be one source.
791
791
792 By default, this command copies the contents of files as they
792 By default, this command copies the contents of files as they
793 stand in the working directory. If invoked with --after, the
793 stand in the working directory. If invoked with --after, the
794 operation is recorded, but no copying is performed.
794 operation is recorded, but no copying is performed.
795
795
796 This command takes effect in the next commit.
796 This command takes effect in the next commit.
797
797
798 NOTE: This command should be treated as experimental. While it
798 NOTE: This command should be treated as experimental. While it
799 should properly record copied files, this information is not yet
799 should properly record copied files, this information is not yet
800 fully used by merge, nor fully reported by log.
800 fully used by merge, nor fully reported by log.
801 """
801 """
802 wlock = repo.wlock(0)
802 wlock = repo.wlock(0)
803 errs, copied = docopy(ui, repo, pats, opts, wlock)
803 errs, copied = docopy(ui, repo, pats, opts, wlock)
804 return errs
804 return errs
805
805
806 def debugancestor(ui, index, rev1, rev2):
806 def debugancestor(ui, index, rev1, rev2):
807 """find the ancestor revision of two revisions in a given index"""
807 """find the ancestor revision of two revisions in a given index"""
808 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0)
808 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0)
809 a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
809 a = r.ancestor(r.lookup(rev1), r.lookup(rev2))
810 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
810 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
811
811
812 def debugcomplete(ui, cmd='', **opts):
812 def debugcomplete(ui, cmd='', **opts):
813 """returns the completion list associated with the given command"""
813 """returns the completion list associated with the given command"""
814
814
815 if opts['options']:
815 if opts['options']:
816 options = []
816 options = []
817 otables = [globalopts]
817 otables = [globalopts]
818 if cmd:
818 if cmd:
819 aliases, entry = findcmd(ui, cmd)
819 aliases, entry = findcmd(ui, cmd)
820 otables.append(entry[1])
820 otables.append(entry[1])
821 for t in otables:
821 for t in otables:
822 for o in t:
822 for o in t:
823 if o[0]:
823 if o[0]:
824 options.append('-%s' % o[0])
824 options.append('-%s' % o[0])
825 options.append('--%s' % o[1])
825 options.append('--%s' % o[1])
826 ui.write("%s\n" % "\n".join(options))
826 ui.write("%s\n" % "\n".join(options))
827 return
827 return
828
828
829 clist = findpossible(ui, cmd).keys()
829 clist = findpossible(ui, cmd).keys()
830 clist.sort()
830 clist.sort()
831 ui.write("%s\n" % "\n".join(clist))
831 ui.write("%s\n" % "\n".join(clist))
832
832
833 def debugrebuildstate(ui, repo, rev=None):
833 def debugrebuildstate(ui, repo, rev=None):
834 """rebuild the dirstate as it would look like for the given revision"""
834 """rebuild the dirstate as it would look like for the given revision"""
835 if not rev:
835 if not rev:
836 rev = repo.changelog.tip()
836 rev = repo.changelog.tip()
837 else:
837 else:
838 rev = repo.lookup(rev)
838 rev = repo.lookup(rev)
839 change = repo.changelog.read(rev)
839 change = repo.changelog.read(rev)
840 n = change[0]
840 n = change[0]
841 files = repo.manifest.read(n)
841 files = repo.manifest.read(n)
842 wlock = repo.wlock()
842 wlock = repo.wlock()
843 repo.dirstate.rebuild(rev, files)
843 repo.dirstate.rebuild(rev, files)
844
844
845 def debugcheckstate(ui, repo):
845 def debugcheckstate(ui, repo):
846 """validate the correctness of the current dirstate"""
846 """validate the correctness of the current dirstate"""
847 parent1, parent2 = repo.dirstate.parents()
847 parent1, parent2 = repo.dirstate.parents()
848 repo.dirstate.read()
848 repo.dirstate.read()
849 dc = repo.dirstate.map
849 dc = repo.dirstate.map
850 keys = dc.keys()
850 keys = dc.keys()
851 keys.sort()
851 keys.sort()
852 m1n = repo.changelog.read(parent1)[0]
852 m1n = repo.changelog.read(parent1)[0]
853 m2n = repo.changelog.read(parent2)[0]
853 m2n = repo.changelog.read(parent2)[0]
854 m1 = repo.manifest.read(m1n)
854 m1 = repo.manifest.read(m1n)
855 m2 = repo.manifest.read(m2n)
855 m2 = repo.manifest.read(m2n)
856 errors = 0
856 errors = 0
857 for f in dc:
857 for f in dc:
858 state = repo.dirstate.state(f)
858 state = repo.dirstate.state(f)
859 if state in "nr" and f not in m1:
859 if state in "nr" and f not in m1:
860 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
860 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
861 errors += 1
861 errors += 1
862 if state in "a" and f in m1:
862 if state in "a" and f in m1:
863 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
863 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
864 errors += 1
864 errors += 1
865 if state in "m" and f not in m1 and f not in m2:
865 if state in "m" and f not in m1 and f not in m2:
866 ui.warn(_("%s in state %s, but not in either manifest\n") %
866 ui.warn(_("%s in state %s, but not in either manifest\n") %
867 (f, state))
867 (f, state))
868 errors += 1
868 errors += 1
869 for f in m1:
869 for f in m1:
870 state = repo.dirstate.state(f)
870 state = repo.dirstate.state(f)
871 if state not in "nrm":
871 if state not in "nrm":
872 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
872 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
873 errors += 1
873 errors += 1
874 if errors:
874 if errors:
875 error = _(".hg/dirstate inconsistent with current parent's manifest")
875 error = _(".hg/dirstate inconsistent with current parent's manifest")
876 raise util.Abort(error)
876 raise util.Abort(error)
877
877
878 def showconfig(ui, repo, *values, **opts):
878 def showconfig(ui, repo, *values, **opts):
879 """show combined config settings from all hgrc files
879 """show combined config settings from all hgrc files
880
880
881 With no args, print names and values of all config items.
881 With no args, print names and values of all config items.
882
882
883 With one arg of the form section.name, print just the value of
883 With one arg of the form section.name, print just the value of
884 that config item.
884 that config item.
885
885
886 With multiple args, print names and values of all config items
886 With multiple args, print names and values of all config items
887 with matching section names."""
887 with matching section names."""
888
888
889 untrusted = bool(opts.get('untrusted'))
889 untrusted = bool(opts.get('untrusted'))
890 if values:
890 if values:
891 if len([v for v in values if '.' in v]) > 1:
891 if len([v for v in values if '.' in v]) > 1:
892 raise util.Abort(_('only one config item permitted'))
892 raise util.Abort(_('only one config item permitted'))
893 for section, name, value in ui.walkconfig(untrusted=untrusted):
893 for section, name, value in ui.walkconfig(untrusted=untrusted):
894 sectname = section + '.' + name
894 sectname = section + '.' + name
895 if values:
895 if values:
896 for v in values:
896 for v in values:
897 if v == section:
897 if v == section:
898 ui.write('%s=%s\n' % (sectname, value))
898 ui.write('%s=%s\n' % (sectname, value))
899 elif v == sectname:
899 elif v == sectname:
900 ui.write(value, '\n')
900 ui.write(value, '\n')
901 else:
901 else:
902 ui.write('%s=%s\n' % (sectname, value))
902 ui.write('%s=%s\n' % (sectname, value))
903
903
904 def debugsetparents(ui, repo, rev1, rev2=None):
904 def debugsetparents(ui, repo, rev1, rev2=None):
905 """manually set the parents of the current working directory
905 """manually set the parents of the current working directory
906
906
907 This is useful for writing repository conversion tools, but should
907 This is useful for writing repository conversion tools, but should
908 be used with care.
908 be used with care.
909 """
909 """
910
910
911 if not rev2:
911 if not rev2:
912 rev2 = hex(nullid)
912 rev2 = hex(nullid)
913
913
914 repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
914 repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
915
915
916 def debugstate(ui, repo):
916 def debugstate(ui, repo):
917 """show the contents of the current dirstate"""
917 """show the contents of the current dirstate"""
918 repo.dirstate.read()
918 repo.dirstate.read()
919 dc = repo.dirstate.map
919 dc = repo.dirstate.map
920 keys = dc.keys()
920 keys = dc.keys()
921 keys.sort()
921 keys.sort()
922 for file_ in keys:
922 for file_ in keys:
923 ui.write("%c %3o %10d %s %s\n"
923 ui.write("%c %3o %10d %s %s\n"
924 % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2],
924 % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2],
925 time.strftime("%x %X",
925 time.strftime("%x %X",
926 time.localtime(dc[file_][3])), file_))
926 time.localtime(dc[file_][3])), file_))
927 for f in repo.dirstate.copies():
927 for f in repo.dirstate.copies():
928 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
928 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
929
929
930 def debugdata(ui, file_, rev):
930 def debugdata(ui, file_, rev):
931 """dump the contents of an data file revision"""
931 """dump the contents of an data file revision"""
932 r = revlog.revlog(util.opener(os.getcwd(), audit=False),
932 r = revlog.revlog(util.opener(os.getcwd(), audit=False),
933 file_[:-2] + ".i", file_, 0)
933 file_[:-2] + ".i", file_, 0)
934 try:
934 try:
935 ui.write(r.revision(r.lookup(rev)))
935 ui.write(r.revision(r.lookup(rev)))
936 except KeyError:
936 except KeyError:
937 raise util.Abort(_('invalid revision identifier %s') % rev)
937 raise util.Abort(_('invalid revision identifier %s') % rev)
938
938
939 def debugindex(ui, file_):
939 def debugindex(ui, file_):
940 """dump the contents of an index file"""
940 """dump the contents of an index file"""
941 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0)
941 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0)
942 ui.write(" rev offset length base linkrev" +
942 ui.write(" rev offset length base linkrev" +
943 " nodeid p1 p2\n")
943 " nodeid p1 p2\n")
944 for i in xrange(r.count()):
944 for i in xrange(r.count()):
945 node = r.node(i)
945 node = r.node(i)
946 pp = r.parents(node)
946 pp = r.parents(node)
947 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
947 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
948 i, r.start(i), r.length(i), r.base(i), r.linkrev(node),
948 i, r.start(i), r.length(i), r.base(i), r.linkrev(node),
949 short(node), short(pp[0]), short(pp[1])))
949 short(node), short(pp[0]), short(pp[1])))
950
950
951 def debugindexdot(ui, file_):
951 def debugindexdot(ui, file_):
952 """dump an index DAG as a .dot file"""
952 """dump an index DAG as a .dot file"""
953 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0)
953 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0)
954 ui.write("digraph G {\n")
954 ui.write("digraph G {\n")
955 for i in xrange(r.count()):
955 for i in xrange(r.count()):
956 node = r.node(i)
956 node = r.node(i)
957 pp = r.parents(node)
957 pp = r.parents(node)
958 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
958 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
959 if pp[1] != nullid:
959 if pp[1] != nullid:
960 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
960 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
961 ui.write("}\n")
961 ui.write("}\n")
962
962
963 def debugrename(ui, repo, file1, *pats, **opts):
963 def debugrename(ui, repo, file1, *pats, **opts):
964 """dump rename information"""
964 """dump rename information"""
965
965
966 ctx = repo.changectx(opts.get('rev', 'tip'))
966 ctx = repo.changectx(opts.get('rev', 'tip'))
967 for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
967 for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts,
968 ctx.node()):
968 ctx.node()):
969 m = ctx.filectx(abs).renamed()
969 m = ctx.filectx(abs).renamed()
970 if m:
970 if m:
971 ui.write(_("%s renamed from %s:%s\n") % (rel, m[0], hex(m[1])))
971 ui.write(_("%s renamed from %s:%s\n") % (rel, m[0], hex(m[1])))
972 else:
972 else:
973 ui.write(_("%s not renamed\n") % rel)
973 ui.write(_("%s not renamed\n") % rel)
974
974
975 def debugwalk(ui, repo, *pats, **opts):
975 def debugwalk(ui, repo, *pats, **opts):
976 """show how files match on given patterns"""
976 """show how files match on given patterns"""
977 items = list(cmdutil.walk(repo, pats, opts))
977 items = list(cmdutil.walk(repo, pats, opts))
978 if not items:
978 if not items:
979 return
979 return
980 fmt = '%%s %%-%ds %%-%ds %%s' % (
980 fmt = '%%s %%-%ds %%-%ds %%s' % (
981 max([len(abs) for (src, abs, rel, exact) in items]),
981 max([len(abs) for (src, abs, rel, exact) in items]),
982 max([len(rel) for (src, abs, rel, exact) in items]))
982 max([len(rel) for (src, abs, rel, exact) in items]))
983 for src, abs, rel, exact in items:
983 for src, abs, rel, exact in items:
984 line = fmt % (src, abs, rel, exact and 'exact' or '')
984 line = fmt % (src, abs, rel, exact and 'exact' or '')
985 ui.write("%s\n" % line.rstrip())
985 ui.write("%s\n" % line.rstrip())
986
986
987 def diff(ui, repo, *pats, **opts):
987 def diff(ui, repo, *pats, **opts):
988 """diff repository (or selected files)
988 """diff repository (or selected files)
989
989
990 Show differences between revisions for the specified files.
990 Show differences between revisions for the specified files.
991
991
992 Differences between files are shown using the unified diff format.
992 Differences between files are shown using the unified diff format.
993
993
994 When two revision arguments are given, then changes are shown
994 When two revision arguments are given, then changes are shown
995 between those revisions. If only one revision is specified then
995 between those revisions. If only one revision is specified then
996 that revision is compared to the working directory, and, when no
996 that revision is compared to the working directory, and, when no
997 revisions are specified, the working directory files are compared
997 revisions are specified, the working directory files are compared
998 to its parent.
998 to its parent.
999
999
1000 Without the -a option, diff will avoid generating diffs of files
1000 Without the -a option, diff will avoid generating diffs of files
1001 it detects as binary. With -a, diff will generate a diff anyway,
1001 it detects as binary. With -a, diff will generate a diff anyway,
1002 probably with undesirable results.
1002 probably with undesirable results.
1003 """
1003 """
1004 node1, node2 = cmdutil.revpair(ui, repo, opts['rev'])
1004 node1, node2 = cmdutil.revpair(ui, repo, opts['rev'])
1005
1005
1006 fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
1006 fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
1007
1007
1008 patch.diff(repo, node1, node2, fns, match=matchfn,
1008 patch.diff(repo, node1, node2, fns, match=matchfn,
1009 opts=patch.diffopts(ui, opts))
1009 opts=patch.diffopts(ui, opts))
1010
1010
1011 def export(ui, repo, *changesets, **opts):
1011 def export(ui, repo, *changesets, **opts):
1012 """dump the header and diffs for one or more changesets
1012 """dump the header and diffs for one or more changesets
1013
1013
1014 Print the changeset header and diffs for one or more revisions.
1014 Print the changeset header and diffs for one or more revisions.
1015
1015
1016 The information shown in the changeset header is: author,
1016 The information shown in the changeset header is: author,
1017 changeset hash, parent and commit comment.
1017 changeset hash, parent and commit comment.
1018
1018
1019 Output may be to a file, in which case the name of the file is
1019 Output may be to a file, in which case the name of the file is
1020 given using a format string. The formatting rules are as follows:
1020 given using a format string. The formatting rules are as follows:
1021
1021
1022 %% literal "%" character
1022 %% literal "%" character
1023 %H changeset hash (40 bytes of hexadecimal)
1023 %H changeset hash (40 bytes of hexadecimal)
1024 %N number of patches being generated
1024 %N number of patches being generated
1025 %R changeset revision number
1025 %R changeset revision number
1026 %b basename of the exporting repository
1026 %b basename of the exporting repository
1027 %h short-form changeset hash (12 bytes of hexadecimal)
1027 %h short-form changeset hash (12 bytes of hexadecimal)
1028 %n zero-padded sequence number, starting at 1
1028 %n zero-padded sequence number, starting at 1
1029 %r zero-padded changeset revision number
1029 %r zero-padded changeset revision number
1030
1030
1031 Without the -a option, export will avoid generating diffs of files
1031 Without the -a option, export will avoid generating diffs of files
1032 it detects as binary. With -a, export will generate a diff anyway,
1032 it detects as binary. With -a, export will generate a diff anyway,
1033 probably with undesirable results.
1033 probably with undesirable results.
1034
1034
1035 With the --switch-parent option, the diff will be against the second
1035 With the --switch-parent option, the diff will be against the second
1036 parent. It can be useful to review a merge.
1036 parent. It can be useful to review a merge.
1037 """
1037 """
1038 if not changesets:
1038 if not changesets:
1039 raise util.Abort(_("export requires at least one changeset"))
1039 raise util.Abort(_("export requires at least one changeset"))
1040 revs = cmdutil.revrange(ui, repo, changesets)
1040 revs = cmdutil.revrange(ui, repo, changesets)
1041 if len(revs) > 1:
1041 if len(revs) > 1:
1042 ui.note(_('exporting patches:\n'))
1042 ui.note(_('exporting patches:\n'))
1043 else:
1043 else:
1044 ui.note(_('exporting patch:\n'))
1044 ui.note(_('exporting patch:\n'))
1045 patch.export(repo, map(repo.lookup, revs), template=opts['output'],
1045 patch.export(repo, map(repo.lookup, revs), template=opts['output'],
1046 switch_parent=opts['switch_parent'],
1046 switch_parent=opts['switch_parent'],
1047 opts=patch.diffopts(ui, opts))
1047 opts=patch.diffopts(ui, opts))
1048
1048
1049 def grep(ui, repo, pattern, *pats, **opts):
1049 def grep(ui, repo, pattern, *pats, **opts):
1050 """search for a pattern in specified files and revisions
1050 """search for a pattern in specified files and revisions
1051
1051
1052 Search revisions of files for a regular expression.
1052 Search revisions of files for a regular expression.
1053
1053
1054 This command behaves differently than Unix grep. It only accepts
1054 This command behaves differently than Unix grep. It only accepts
1055 Python/Perl regexps. It searches repository history, not the
1055 Python/Perl regexps. It searches repository history, not the
1056 working directory. It always prints the revision number in which
1056 working directory. It always prints the revision number in which
1057 a match appears.
1057 a match appears.
1058
1058
1059 By default, grep only prints output for the first revision of a
1059 By default, grep only prints output for the first revision of a
1060 file in which it finds a match. To get it to print every revision
1060 file in which it finds a match. To get it to print every revision
1061 that contains a change in match status ("-" for a match that
1061 that contains a change in match status ("-" for a match that
1062 becomes a non-match, or "+" for a non-match that becomes a match),
1062 becomes a non-match, or "+" for a non-match that becomes a match),
1063 use the --all flag.
1063 use the --all flag.
1064 """
1064 """
1065 reflags = 0
1065 reflags = 0
1066 if opts['ignore_case']:
1066 if opts['ignore_case']:
1067 reflags |= re.I
1067 reflags |= re.I
1068 regexp = re.compile(pattern, reflags)
1068 regexp = re.compile(pattern, reflags)
1069 sep, eol = ':', '\n'
1069 sep, eol = ':', '\n'
1070 if opts['print0']:
1070 if opts['print0']:
1071 sep = eol = '\0'
1071 sep = eol = '\0'
1072
1072
1073 fcache = {}
1073 fcache = {}
1074 def getfile(fn):
1074 def getfile(fn):
1075 if fn not in fcache:
1075 if fn not in fcache:
1076 fcache[fn] = repo.file(fn)
1076 fcache[fn] = repo.file(fn)
1077 return fcache[fn]
1077 return fcache[fn]
1078
1078
1079 def matchlines(body):
1079 def matchlines(body):
1080 begin = 0
1080 begin = 0
1081 linenum = 0
1081 linenum = 0
1082 while True:
1082 while True:
1083 match = regexp.search(body, begin)
1083 match = regexp.search(body, begin)
1084 if not match:
1084 if not match:
1085 break
1085 break
1086 mstart, mend = match.span()
1086 mstart, mend = match.span()
1087 linenum += body.count('\n', begin, mstart) + 1
1087 linenum += body.count('\n', begin, mstart) + 1
1088 lstart = body.rfind('\n', begin, mstart) + 1 or begin
1088 lstart = body.rfind('\n', begin, mstart) + 1 or begin
1089 lend = body.find('\n', mend)
1089 lend = body.find('\n', mend)
1090 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
1090 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
1091 begin = lend + 1
1091 begin = lend + 1
1092
1092
1093 class linestate(object):
1093 class linestate(object):
1094 def __init__(self, line, linenum, colstart, colend):
1094 def __init__(self, line, linenum, colstart, colend):
1095 self.line = line
1095 self.line = line
1096 self.linenum = linenum
1096 self.linenum = linenum
1097 self.colstart = colstart
1097 self.colstart = colstart
1098 self.colend = colend
1098 self.colend = colend
1099
1099
1100 def __eq__(self, other):
1100 def __eq__(self, other):
1101 return self.line == other.line
1101 return self.line == other.line
1102
1102
1103 matches = {}
1103 matches = {}
1104 copies = {}
1104 copies = {}
1105 def grepbody(fn, rev, body):
1105 def grepbody(fn, rev, body):
1106 matches[rev].setdefault(fn, [])
1106 matches[rev].setdefault(fn, [])
1107 m = matches[rev][fn]
1107 m = matches[rev][fn]
1108 for lnum, cstart, cend, line in matchlines(body):
1108 for lnum, cstart, cend, line in matchlines(body):
1109 s = linestate(line, lnum, cstart, cend)
1109 s = linestate(line, lnum, cstart, cend)
1110 m.append(s)
1110 m.append(s)
1111
1111
1112 def difflinestates(a, b):
1112 def difflinestates(a, b):
1113 sm = difflib.SequenceMatcher(None, a, b)
1113 sm = difflib.SequenceMatcher(None, a, b)
1114 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
1114 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
1115 if tag == 'insert':
1115 if tag == 'insert':
1116 for i in xrange(blo, bhi):
1116 for i in xrange(blo, bhi):
1117 yield ('+', b[i])
1117 yield ('+', b[i])
1118 elif tag == 'delete':
1118 elif tag == 'delete':
1119 for i in xrange(alo, ahi):
1119 for i in xrange(alo, ahi):
1120 yield ('-', a[i])
1120 yield ('-', a[i])
1121 elif tag == 'replace':
1121 elif tag == 'replace':
1122 for i in xrange(alo, ahi):
1122 for i in xrange(alo, ahi):
1123 yield ('-', a[i])
1123 yield ('-', a[i])
1124 for i in xrange(blo, bhi):
1124 for i in xrange(blo, bhi):
1125 yield ('+', b[i])
1125 yield ('+', b[i])
1126
1126
1127 prev = {}
1127 prev = {}
1128 def display(fn, rev, states, prevstates):
1128 def display(fn, rev, states, prevstates):
1129 counts = {'-': 0, '+': 0}
1129 counts = {'-': 0, '+': 0}
1130 filerevmatches = {}
1130 filerevmatches = {}
1131 if incrementing or not opts['all']:
1131 if incrementing or not opts['all']:
1132 a, b, r = prevstates, states, rev
1132 a, b, r = prevstates, states, rev
1133 else:
1133 else:
1134 a, b, r = states, prevstates, prev.get(fn, -1)
1134 a, b, r = states, prevstates, prev.get(fn, -1)
1135 for change, l in difflinestates(a, b):
1135 for change, l in difflinestates(a, b):
1136 cols = [fn, str(r)]
1136 cols = [fn, str(r)]
1137 if opts['line_number']:
1137 if opts['line_number']:
1138 cols.append(str(l.linenum))
1138 cols.append(str(l.linenum))
1139 if opts['all']:
1139 if opts['all']:
1140 cols.append(change)
1140 cols.append(change)
1141 if opts['user']:
1141 if opts['user']:
1142 cols.append(ui.shortuser(get(r)[1]))
1142 cols.append(ui.shortuser(get(r)[1]))
1143 if opts['files_with_matches']:
1143 if opts['files_with_matches']:
1144 c = (fn, r)
1144 c = (fn, r)
1145 if c in filerevmatches:
1145 if c in filerevmatches:
1146 continue
1146 continue
1147 filerevmatches[c] = 1
1147 filerevmatches[c] = 1
1148 else:
1148 else:
1149 cols.append(l.line)
1149 cols.append(l.line)
1150 ui.write(sep.join(cols), eol)
1150 ui.write(sep.join(cols), eol)
1151 counts[change] += 1
1151 counts[change] += 1
1152 return counts['+'], counts['-']
1152 return counts['+'], counts['-']
1153
1153
1154 fstate = {}
1154 fstate = {}
1155 skip = {}
1155 skip = {}
1156 get = util.cachefunc(lambda r:repo.changectx(r).changeset())
1156 get = util.cachefunc(lambda r:repo.changectx(r).changeset())
1157 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1157 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1158 count = 0
1158 count = 0
1159 incrementing = False
1159 incrementing = False
1160 follow = opts.get('follow')
1160 follow = opts.get('follow')
1161 for st, rev, fns in changeiter:
1161 for st, rev, fns in changeiter:
1162 if st == 'window':
1162 if st == 'window':
1163 incrementing = rev
1163 incrementing = rev
1164 matches.clear()
1164 matches.clear()
1165 elif st == 'add':
1165 elif st == 'add':
1166 mf = repo.changectx(rev).manifest()
1166 mf = repo.changectx(rev).manifest()
1167 matches[rev] = {}
1167 matches[rev] = {}
1168 for fn in fns:
1168 for fn in fns:
1169 if fn in skip:
1169 if fn in skip:
1170 continue
1170 continue
1171 fstate.setdefault(fn, {})
1171 fstate.setdefault(fn, {})
1172 try:
1172 try:
1173 grepbody(fn, rev, getfile(fn).read(mf[fn]))
1173 grepbody(fn, rev, getfile(fn).read(mf[fn]))
1174 if follow:
1174 if follow:
1175 copied = getfile(fn).renamed(mf[fn])
1175 copied = getfile(fn).renamed(mf[fn])
1176 if copied:
1176 if copied:
1177 copies.setdefault(rev, {})[fn] = copied[0]
1177 copies.setdefault(rev, {})[fn] = copied[0]
1178 except KeyError:
1178 except KeyError:
1179 pass
1179 pass
1180 elif st == 'iter':
1180 elif st == 'iter':
1181 states = matches[rev].items()
1181 states = matches[rev].items()
1182 states.sort()
1182 states.sort()
1183 for fn, m in states:
1183 for fn, m in states:
1184 copy = copies.get(rev, {}).get(fn)
1184 copy = copies.get(rev, {}).get(fn)
1185 if fn in skip:
1185 if fn in skip:
1186 if copy:
1186 if copy:
1187 skip[copy] = True
1187 skip[copy] = True
1188 continue
1188 continue
1189 if incrementing or not opts['all'] or fstate[fn]:
1189 if incrementing or not opts['all'] or fstate[fn]:
1190 pos, neg = display(fn, rev, m, fstate[fn])
1190 pos, neg = display(fn, rev, m, fstate[fn])
1191 count += pos + neg
1191 count += pos + neg
1192 if pos and not opts['all']:
1192 if pos and not opts['all']:
1193 skip[fn] = True
1193 skip[fn] = True
1194 if copy:
1194 if copy:
1195 skip[copy] = True
1195 skip[copy] = True
1196 fstate[fn] = m
1196 fstate[fn] = m
1197 if copy:
1197 if copy:
1198 fstate[copy] = m
1198 fstate[copy] = m
1199 prev[fn] = rev
1199 prev[fn] = rev
1200
1200
1201 if not incrementing:
1201 if not incrementing:
1202 fstate = fstate.items()
1202 fstate = fstate.items()
1203 fstate.sort()
1203 fstate.sort()
1204 for fn, state in fstate:
1204 for fn, state in fstate:
1205 if fn in skip:
1205 if fn in skip:
1206 continue
1206 continue
1207 if fn not in copies.get(prev[fn], {}):
1207 if fn not in copies.get(prev[fn], {}):
1208 display(fn, rev, {}, state)
1208 display(fn, rev, {}, state)
1209 return (count == 0 and 1) or 0
1209 return (count == 0 and 1) or 0
1210
1210
1211 def heads(ui, repo, **opts):
1211 def heads(ui, repo, **opts):
1212 """show current repository heads
1212 """show current repository heads
1213
1213
1214 Show all repository head changesets.
1214 Show all repository head changesets.
1215
1215
1216 Repository "heads" are changesets that don't have children
1216 Repository "heads" are changesets that don't have children
1217 changesets. They are where development generally takes place and
1217 changesets. They are where development generally takes place and
1218 are the usual targets for update and merge operations.
1218 are the usual targets for update and merge operations.
1219 """
1219 """
1220 if opts['rev']:
1220 if opts['rev']:
1221 heads = repo.heads(repo.lookup(opts['rev']))
1221 heads = repo.heads(repo.lookup(opts['rev']))
1222 else:
1222 else:
1223 heads = repo.heads()
1223 heads = repo.heads()
1224 displayer = cmdutil.show_changeset(ui, repo, opts)
1224 displayer = cmdutil.show_changeset(ui, repo, opts)
1225 for n in heads:
1225 for n in heads:
1226 displayer.show(changenode=n)
1226 displayer.show(changenode=n)
1227
1227
1228 def identify(ui, repo):
1228 def identify(ui, repo):
1229 """print information about the working copy
1229 """print information about the working copy
1230
1230
1231 Print a short summary of the current state of the repo.
1231 Print a short summary of the current state of the repo.
1232
1232
1233 This summary identifies the repository state using one or two parent
1233 This summary identifies the repository state using one or two parent
1234 hash identifiers, followed by a "+" if there are uncommitted changes
1234 hash identifiers, followed by a "+" if there are uncommitted changes
1235 in the working directory, followed by a list of tags for this revision.
1235 in the working directory, followed by a list of tags for this revision.
1236 """
1236 """
1237 parents = [p for p in repo.dirstate.parents() if p != nullid]
1237 parents = [p for p in repo.dirstate.parents() if p != nullid]
1238 if not parents:
1238 if not parents:
1239 ui.write(_("unknown\n"))
1239 ui.write(_("unknown\n"))
1240 return
1240 return
1241
1241
1242 hexfunc = ui.debugflag and hex or short
1242 hexfunc = ui.debugflag and hex or short
1243 modified, added, removed, deleted = repo.status()[:4]
1243 modified, added, removed, deleted = repo.status()[:4]
1244 output = ["%s%s" %
1244 output = ["%s%s" %
1245 ('+'.join([hexfunc(parent) for parent in parents]),
1245 ('+'.join([hexfunc(parent) for parent in parents]),
1246 (modified or added or removed or deleted) and "+" or "")]
1246 (modified or added or removed or deleted) and "+" or "")]
1247
1247
1248 if not ui.quiet:
1248 if not ui.quiet:
1249
1249
1250 branch = repo.workingctx().branch()
1250 branch = repo.workingctx().branch()
1251 if branch:
1251 if branch:
1252 output.append("(%s)" % branch)
1252 output.append("(%s)" % branch)
1253
1253
1254 # multiple tags for a single parent separated by '/'
1254 # multiple tags for a single parent separated by '/'
1255 parenttags = ['/'.join(tags)
1255 parenttags = ['/'.join(tags)
1256 for tags in map(repo.nodetags, parents) if tags]
1256 for tags in map(repo.nodetags, parents) if tags]
1257 # tags for multiple parents separated by ' + '
1257 # tags for multiple parents separated by ' + '
1258 if parenttags:
1258 if parenttags:
1259 output.append(' + '.join(parenttags))
1259 output.append(' + '.join(parenttags))
1260
1260
1261 ui.write("%s\n" % ' '.join(output))
1261 ui.write("%s\n" % ' '.join(output))
1262
1262
1263 def import_(ui, repo, patch1, *patches, **opts):
1263 def import_(ui, repo, patch1, *patches, **opts):
1264 """import an ordered set of patches
1264 """import an ordered set of patches
1265
1265
1266 Import a list of patches and commit them individually.
1266 Import a list of patches and commit them individually.
1267
1267
1268 If there are outstanding changes in the working directory, import
1268 If there are outstanding changes in the working directory, import
1269 will abort unless given the -f flag.
1269 will abort unless given the -f flag.
1270
1270
1271 You can import a patch straight from a mail message. Even patches
1271 You can import a patch straight from a mail message. Even patches
1272 as attachments work (body part must be type text/plain or
1272 as attachments work (body part must be type text/plain or
1273 text/x-patch to be used). From and Subject headers of email
1273 text/x-patch to be used). From and Subject headers of email
1274 message are used as default committer and commit message. All
1274 message are used as default committer and commit message. All
1275 text/plain body parts before first diff are added to commit
1275 text/plain body parts before first diff are added to commit
1276 message.
1276 message.
1277
1277
1278 If imported patch was generated by hg export, user and description
1278 If imported patch was generated by hg export, user and description
1279 from patch override values from message headers and body. Values
1279 from patch override values from message headers and body. Values
1280 given on command line with -m and -u override these.
1280 given on command line with -m and -u override these.
1281
1281
1282 To read a patch from standard input, use patch name "-".
1282 To read a patch from standard input, use patch name "-".
1283 """
1283 """
1284 patches = (patch1,) + patches
1284 patches = (patch1,) + patches
1285
1285
1286 if not opts['force']:
1286 if not opts['force']:
1287 bail_if_changed(repo)
1287 bail_if_changed(repo)
1288
1288
1289 d = opts["base"]
1289 d = opts["base"]
1290 strip = opts["strip"]
1290 strip = opts["strip"]
1291
1291
1292 wlock = repo.wlock()
1292 wlock = repo.wlock()
1293 lock = repo.lock()
1293 lock = repo.lock()
1294
1294
1295 for p in patches:
1295 for p in patches:
1296 pf = os.path.join(d, p)
1296 pf = os.path.join(d, p)
1297
1297
1298 if pf == '-':
1298 if pf == '-':
1299 ui.status(_("applying patch from stdin\n"))
1299 ui.status(_("applying patch from stdin\n"))
1300 tmpname, message, user, date = patch.extract(ui, sys.stdin)
1300 tmpname, message, user, date = patch.extract(ui, sys.stdin)
1301 else:
1301 else:
1302 ui.status(_("applying %s\n") % p)
1302 ui.status(_("applying %s\n") % p)
1303 tmpname, message, user, date = patch.extract(ui, file(pf))
1303 tmpname, message, user, date = patch.extract(ui, file(pf))
1304
1304
1305 if tmpname is None:
1305 if tmpname is None:
1306 raise util.Abort(_('no diffs found'))
1306 raise util.Abort(_('no diffs found'))
1307
1307
1308 try:
1308 try:
1309 if opts['message']:
1309 if opts['message']:
1310 # pickup the cmdline msg
1310 # pickup the cmdline msg
1311 message = opts['message']
1311 message = opts['message']
1312 elif message:
1312 elif message:
1313 # pickup the patch msg
1313 # pickup the patch msg
1314 message = message.strip()
1314 message = message.strip()
1315 else:
1315 else:
1316 # launch the editor
1316 # launch the editor
1317 message = None
1317 message = None
1318 ui.debug(_('message:\n%s\n') % message)
1318 ui.debug(_('message:\n%s\n') % message)
1319
1319
1320 files = {}
1320 files = {}
1321 try:
1321 try:
1322 fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
1322 fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
1323 files=files)
1323 files=files)
1324 finally:
1324 finally:
1325 files = patch.updatedir(ui, repo, files, wlock=wlock)
1325 files = patch.updatedir(ui, repo, files, wlock=wlock)
1326 repo.commit(files, message, user, date, wlock=wlock, lock=lock)
1326 repo.commit(files, message, user, date, wlock=wlock, lock=lock)
1327 finally:
1327 finally:
1328 os.unlink(tmpname)
1328 os.unlink(tmpname)
1329
1329
1330 def incoming(ui, repo, source="default", **opts):
1330 def incoming(ui, repo, source="default", **opts):
1331 """show new changesets found in source
1331 """show new changesets found in source
1332
1332
1333 Show new changesets found in the specified path/URL or the default
1333 Show new changesets found in the specified path/URL or the default
1334 pull location. These are the changesets that would be pulled if a pull
1334 pull location. These are the changesets that would be pulled if a pull
1335 was requested.
1335 was requested.
1336
1336
1337 For remote repository, using --bundle avoids downloading the changesets
1337 For remote repository, using --bundle avoids downloading the changesets
1338 twice if the incoming is followed by a pull.
1338 twice if the incoming is followed by a pull.
1339
1339
1340 See pull for valid source format details.
1340 See pull for valid source format details.
1341 """
1341 """
1342 source = ui.expandpath(source)
1342 source = ui.expandpath(source)
1343 setremoteconfig(ui, opts)
1343 setremoteconfig(ui, opts)
1344
1344
1345 other = hg.repository(ui, source)
1345 other = hg.repository(ui, source)
1346 incoming = repo.findincoming(other, force=opts["force"])
1346 incoming = repo.findincoming(other, force=opts["force"])
1347 if not incoming:
1347 if not incoming:
1348 ui.status(_("no changes found\n"))
1348 ui.status(_("no changes found\n"))
1349 return
1349 return
1350
1350
1351 cleanup = None
1351 cleanup = None
1352 try:
1352 try:
1353 fname = opts["bundle"]
1353 fname = opts["bundle"]
1354 if fname or not other.local():
1354 if fname or not other.local():
1355 # create a bundle (uncompressed if other repo is not local)
1355 # create a bundle (uncompressed if other repo is not local)
1356 cg = other.changegroup(incoming, "incoming")
1356 cg = other.changegroup(incoming, "incoming")
1357 fname = cleanup = write_bundle(cg, fname, compress=other.local())
1357 fname = cleanup = write_bundle(cg, fname, compress=other.local())
1358 # keep written bundle?
1358 # keep written bundle?
1359 if opts["bundle"]:
1359 if opts["bundle"]:
1360 cleanup = None
1360 cleanup = None
1361 if not other.local():
1361 if not other.local():
1362 # use the created uncompressed bundlerepo
1362 # use the created uncompressed bundlerepo
1363 other = bundlerepo.bundlerepository(ui, repo.root, fname)
1363 other = bundlerepo.bundlerepository(ui, repo.root, fname)
1364
1364
1365 revs = None
1365 revs = None
1366 if opts['rev']:
1366 if opts['rev']:
1367 revs = [other.lookup(rev) for rev in opts['rev']]
1367 revs = [other.lookup(rev) for rev in opts['rev']]
1368 o = other.changelog.nodesbetween(incoming, revs)[0]
1368 o = other.changelog.nodesbetween(incoming, revs)[0]
1369 if opts['newest_first']:
1369 if opts['newest_first']:
1370 o.reverse()
1370 o.reverse()
1371 displayer = cmdutil.show_changeset(ui, other, opts)
1371 displayer = cmdutil.show_changeset(ui, other, opts)
1372 for n in o:
1372 for n in o:
1373 parents = [p for p in other.changelog.parents(n) if p != nullid]
1373 parents = [p for p in other.changelog.parents(n) if p != nullid]
1374 if opts['no_merges'] and len(parents) == 2:
1374 if opts['no_merges'] and len(parents) == 2:
1375 continue
1375 continue
1376 displayer.show(changenode=n)
1376 displayer.show(changenode=n)
1377 finally:
1377 finally:
1378 if hasattr(other, 'close'):
1378 if hasattr(other, 'close'):
1379 other.close()
1379 other.close()
1380 if cleanup:
1380 if cleanup:
1381 os.unlink(cleanup)
1381 os.unlink(cleanup)
1382
1382
1383 def init(ui, dest=".", **opts):
1383 def init(ui, dest=".", **opts):
1384 """create a new repository in the given directory
1384 """create a new repository in the given directory
1385
1385
1386 Initialize a new repository in the given directory. If the given
1386 Initialize a new repository in the given directory. If the given
1387 directory does not exist, it is created.
1387 directory does not exist, it is created.
1388
1388
1389 If no directory is given, the current directory is used.
1389 If no directory is given, the current directory is used.
1390
1390
1391 It is possible to specify an ssh:// URL as the destination.
1391 It is possible to specify an ssh:// URL as the destination.
1392 Look at the help text for the pull command for important details
1392 Look at the help text for the pull command for important details
1393 about ssh:// URLs.
1393 about ssh:// URLs.
1394 """
1394 """
1395 setremoteconfig(ui, opts)
1395 setremoteconfig(ui, opts)
1396 hg.repository(ui, dest, create=1)
1396 hg.repository(ui, dest, create=1)
1397
1397
1398 def locate(ui, repo, *pats, **opts):
1398 def locate(ui, repo, *pats, **opts):
1399 """locate files matching specific patterns
1399 """locate files matching specific patterns
1400
1400
1401 Print all files under Mercurial control whose names match the
1401 Print all files under Mercurial control whose names match the
1402 given patterns.
1402 given patterns.
1403
1403
1404 This command searches the current directory and its
1404 This command searches the current directory and its
1405 subdirectories. To search an entire repository, move to the root
1405 subdirectories. To search an entire repository, move to the root
1406 of the repository.
1406 of the repository.
1407
1407
1408 If no patterns are given to match, this command prints all file
1408 If no patterns are given to match, this command prints all file
1409 names.
1409 names.
1410
1410
1411 If you want to feed the output of this command into the "xargs"
1411 If you want to feed the output of this command into the "xargs"
1412 command, use the "-0" option to both this command and "xargs".
1412 command, use the "-0" option to both this command and "xargs".
1413 This will avoid the problem of "xargs" treating single filenames
1413 This will avoid the problem of "xargs" treating single filenames
1414 that contain white space as multiple filenames.
1414 that contain white space as multiple filenames.
1415 """
1415 """
1416 end = opts['print0'] and '\0' or '\n'
1416 end = opts['print0'] and '\0' or '\n'
1417 rev = opts['rev']
1417 rev = opts['rev']
1418 if rev:
1418 if rev:
1419 node = repo.lookup(rev)
1419 node = repo.lookup(rev)
1420 else:
1420 else:
1421 node = None
1421 node = None
1422
1422
1423 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
1423 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
1424 head='(?:.*/|)'):
1424 head='(?:.*/|)'):
1425 if not node and repo.dirstate.state(abs) == '?':
1425 if not node and repo.dirstate.state(abs) == '?':
1426 continue
1426 continue
1427 if opts['fullpath']:
1427 if opts['fullpath']:
1428 ui.write(os.path.join(repo.root, abs), end)
1428 ui.write(os.path.join(repo.root, abs), end)
1429 else:
1429 else:
1430 ui.write(((pats and rel) or abs), end)
1430 ui.write(((pats and rel) or abs), end)
1431
1431
1432 def log(ui, repo, *pats, **opts):
1432 def log(ui, repo, *pats, **opts):
1433 """show revision history of entire repository or files
1433 """show revision history of entire repository or files
1434
1434
1435 Print the revision history of the specified files or the entire
1435 Print the revision history of the specified files or the entire
1436 project.
1436 project.
1437
1437
1438 File history is shown without following rename or copy history of
1438 File history is shown without following rename or copy history of
1439 files. Use -f/--follow with a file name to follow history across
1439 files. Use -f/--follow with a file name to follow history across
1440 renames and copies. --follow without a file name will only show
1440 renames and copies. --follow without a file name will only show
1441 ancestors or descendants of the starting revision. --follow-first
1441 ancestors or descendants of the starting revision. --follow-first
1442 only follows the first parent of merge revisions.
1442 only follows the first parent of merge revisions.
1443
1443
1444 If no revision range is specified, the default is tip:0 unless
1444 If no revision range is specified, the default is tip:0 unless
1445 --follow is set, in which case the working directory parent is
1445 --follow is set, in which case the working directory parent is
1446 used as the starting revision.
1446 used as the starting revision.
1447
1447
1448 By default this command outputs: changeset id and hash, tags,
1448 By default this command outputs: changeset id and hash, tags,
1449 non-trivial parents, user, date and time, and a summary for each
1449 non-trivial parents, user, date and time, and a summary for each
1450 commit. When the -v/--verbose switch is used, the list of changed
1450 commit. When the -v/--verbose switch is used, the list of changed
1451 files and full commit message is shown.
1451 files and full commit message is shown.
1452 """
1452 """
1453
1453
1454 get = util.cachefunc(lambda r:repo.changectx(r).changeset())
1454 get = util.cachefunc(lambda r:repo.changectx(r).changeset())
1455 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1455 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1456
1456
1457 if opts['limit']:
1457 if opts['limit']:
1458 try:
1458 try:
1459 limit = int(opts['limit'])
1459 limit = int(opts['limit'])
1460 except ValueError:
1460 except ValueError:
1461 raise util.Abort(_('limit must be a positive integer'))
1461 raise util.Abort(_('limit must be a positive integer'))
1462 if limit <= 0: raise util.Abort(_('limit must be positive'))
1462 if limit <= 0: raise util.Abort(_('limit must be positive'))
1463 else:
1463 else:
1464 limit = sys.maxint
1464 limit = sys.maxint
1465 count = 0
1465 count = 0
1466
1466
1467 if opts['copies'] and opts['rev']:
1467 if opts['copies'] and opts['rev']:
1468 endrev = max(cmdutil.revrange(ui, repo, opts['rev'])) + 1
1468 endrev = max(cmdutil.revrange(ui, repo, opts['rev'])) + 1
1469 else:
1469 else:
1470 endrev = repo.changelog.count()
1470 endrev = repo.changelog.count()
1471 rcache = {}
1471 rcache = {}
1472 ncache = {}
1472 ncache = {}
1473 dcache = []
1473 dcache = []
1474 def getrenamed(fn, rev, man):
1474 def getrenamed(fn, rev, man):
1475 '''looks up all renames for a file (up to endrev) the first
1475 '''looks up all renames for a file (up to endrev) the first
1476 time the file is given. It indexes on the changerev and only
1476 time the file is given. It indexes on the changerev and only
1477 parses the manifest if linkrev != changerev.
1477 parses the manifest if linkrev != changerev.
1478 Returns rename info for fn at changerev rev.'''
1478 Returns rename info for fn at changerev rev.'''
1479 if fn not in rcache:
1479 if fn not in rcache:
1480 rcache[fn] = {}
1480 rcache[fn] = {}
1481 ncache[fn] = {}
1481 ncache[fn] = {}
1482 fl = repo.file(fn)
1482 fl = repo.file(fn)
1483 for i in xrange(fl.count()):
1483 for i in xrange(fl.count()):
1484 node = fl.node(i)
1484 node = fl.node(i)
1485 lr = fl.linkrev(node)
1485 lr = fl.linkrev(node)
1486 renamed = fl.renamed(node)
1486 renamed = fl.renamed(node)
1487 rcache[fn][lr] = renamed
1487 rcache[fn][lr] = renamed
1488 if renamed:
1488 if renamed:
1489 ncache[fn][node] = renamed
1489 ncache[fn][node] = renamed
1490 if lr >= endrev:
1490 if lr >= endrev:
1491 break
1491 break
1492 if rev in rcache[fn]:
1492 if rev in rcache[fn]:
1493 return rcache[fn][rev]
1493 return rcache[fn][rev]
1494 mr = repo.manifest.rev(man)
1494 mr = repo.manifest.rev(man)
1495 if repo.manifest.parentrevs(mr) != (mr - 1, nullrev):
1495 if repo.manifest.parentrevs(mr) != (mr - 1, nullrev):
1496 return ncache[fn].get(repo.manifest.find(man, fn)[0])
1496 return ncache[fn].get(repo.manifest.find(man, fn)[0])
1497 if not dcache or dcache[0] != man:
1497 if not dcache or dcache[0] != man:
1498 dcache[:] = [man, repo.manifest.readdelta(man)]
1498 dcache[:] = [man, repo.manifest.readdelta(man)]
1499 if fn in dcache[1]:
1499 if fn in dcache[1]:
1500 return ncache[fn].get(dcache[1][fn])
1500 return ncache[fn].get(dcache[1][fn])
1501 return None
1501 return None
1502
1502
1503 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
1503 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
1504 for st, rev, fns in changeiter:
1504 for st, rev, fns in changeiter:
1505 if st == 'add':
1505 if st == 'add':
1506 changenode = repo.changelog.node(rev)
1506 changenode = repo.changelog.node(rev)
1507 parents = [p for p in repo.changelog.parentrevs(rev)
1507 parents = [p for p in repo.changelog.parentrevs(rev)
1508 if p != nullrev]
1508 if p != nullrev]
1509 if opts['no_merges'] and len(parents) == 2:
1509 if opts['no_merges'] and len(parents) == 2:
1510 continue
1510 continue
1511 if opts['only_merges'] and len(parents) != 2:
1511 if opts['only_merges'] and len(parents) != 2:
1512 continue
1512 continue
1513
1513
1514 if opts['keyword']:
1514 if opts['keyword']:
1515 changes = get(rev)
1515 changes = get(rev)
1516 miss = 0
1516 miss = 0
1517 for k in [kw.lower() for kw in opts['keyword']]:
1517 for k in [kw.lower() for kw in opts['keyword']]:
1518 if not (k in changes[1].lower() or
1518 if not (k in changes[1].lower() or
1519 k in changes[4].lower() or
1519 k in changes[4].lower() or
1520 k in " ".join(changes[3][:20]).lower()):
1520 k in " ".join(changes[3][:20]).lower()):
1521 miss = 1
1521 miss = 1
1522 break
1522 break
1523 if miss:
1523 if miss:
1524 continue
1524 continue
1525
1525
1526 copies = []
1526 copies = []
1527 if opts.get('copies') and rev:
1527 if opts.get('copies') and rev:
1528 mf = get(rev)[0]
1528 mf = get(rev)[0]
1529 for fn in get(rev)[3]:
1529 for fn in get(rev)[3]:
1530 rename = getrenamed(fn, rev, mf)
1530 rename = getrenamed(fn, rev, mf)
1531 if rename:
1531 if rename:
1532 copies.append((fn, rename[0]))
1532 copies.append((fn, rename[0]))
1533 displayer.show(rev, changenode, copies=copies)
1533 displayer.show(rev, changenode, copies=copies)
1534 elif st == 'iter':
1534 elif st == 'iter':
1535 if count == limit: break
1535 if count == limit: break
1536 if displayer.flush(rev):
1536 if displayer.flush(rev):
1537 count += 1
1537 count += 1
1538
1538
1539 def manifest(ui, repo, rev=None):
1539 def manifest(ui, repo, rev=None):
1540 """output the latest or given revision of the project manifest
1540 """output the latest or given revision of the project manifest
1541
1541
1542 Print a list of version controlled files for the given revision.
1542 Print a list of version controlled files for the given revision.
1543
1543
1544 The manifest is the list of files being version controlled. If no revision
1544 The manifest is the list of files being version controlled. If no revision
1545 is given then the tip is used.
1545 is given then the tip is used.
1546 """
1546 """
1547 if rev:
1547 if rev:
1548 try:
1548 try:
1549 # assume all revision numbers are for changesets
1549 # assume all revision numbers are for changesets
1550 n = repo.lookup(rev)
1550 n = repo.lookup(rev)
1551 change = repo.changelog.read(n)
1551 change = repo.changelog.read(n)
1552 n = change[0]
1552 n = change[0]
1553 except hg.RepoError:
1553 except hg.RepoError:
1554 n = repo.manifest.lookup(rev)
1554 n = repo.manifest.lookup(rev)
1555 else:
1555 else:
1556 n = repo.manifest.tip()
1556 n = repo.manifest.tip()
1557 m = repo.manifest.read(n)
1557 m = repo.manifest.read(n)
1558 files = m.keys()
1558 files = m.keys()
1559 files.sort()
1559 files.sort()
1560
1560
1561 for f in files:
1561 for f in files:
1562 ui.write("%40s %3s %s\n" % (hex(m[f]),
1562 ui.write("%40s %3s %s\n" % (hex(m[f]),
1563 m.execf(f) and "755" or "644", f))
1563 m.execf(f) and "755" or "644", f))
1564
1564
1565 def merge(ui, repo, node=None, force=None, branch=None):
1565 def merge(ui, repo, node=None, force=None, branch=None):
1566 """Merge working directory with another revision
1566 """Merge working directory with another revision
1567
1567
1568 Merge the contents of the current working directory and the
1568 Merge the contents of the current working directory and the
1569 requested revision. Files that changed between either parent are
1569 requested revision. Files that changed between either parent are
1570 marked as changed for the next commit and a commit must be
1570 marked as changed for the next commit and a commit must be
1571 performed before any further updates are allowed.
1571 performed before any further updates are allowed.
1572
1572
1573 If no revision is specified, the working directory's parent is a
1573 If no revision is specified, the working directory's parent is a
1574 head revision, and the repository contains exactly one other head,
1574 head revision, and the repository contains exactly one other head,
1575 the other head is merged with by default. Otherwise, an explicit
1575 the other head is merged with by default. Otherwise, an explicit
1576 revision to merge with must be provided.
1576 revision to merge with must be provided.
1577 """
1577 """
1578
1578
1579 if node or branch:
1579 if node or branch:
1580 node = _lookup(repo, node, branch)
1580 node = _lookup(repo, node, branch)
1581 else:
1581 else:
1582 heads = repo.heads()
1582 heads = repo.heads()
1583 if len(heads) > 2:
1583 if len(heads) > 2:
1584 raise util.Abort(_('repo has %d heads - '
1584 raise util.Abort(_('repo has %d heads - '
1585 'please merge with an explicit rev') %
1585 'please merge with an explicit rev') %
1586 len(heads))
1586 len(heads))
1587 if len(heads) == 1:
1587 if len(heads) == 1:
1588 raise util.Abort(_('there is nothing to merge - '
1588 raise util.Abort(_('there is nothing to merge - '
1589 'use "hg update" instead'))
1589 'use "hg update" instead'))
1590 parent = repo.dirstate.parents()[0]
1590 parent = repo.dirstate.parents()[0]
1591 if parent not in heads:
1591 if parent not in heads:
1592 raise util.Abort(_('working dir not at a head rev - '
1592 raise util.Abort(_('working dir not at a head rev - '
1593 'use "hg update" or merge with an explicit rev'))
1593 'use "hg update" or merge with an explicit rev'))
1594 node = parent == heads[0] and heads[-1] or heads[0]
1594 node = parent == heads[0] and heads[-1] or heads[0]
1595 return hg.merge(repo, node, force=force)
1595 return hg.merge(repo, node, force=force)
1596
1596
1597 def outgoing(ui, repo, dest=None, **opts):
1597 def outgoing(ui, repo, dest=None, **opts):
1598 """show changesets not found in destination
1598 """show changesets not found in destination
1599
1599
1600 Show changesets not found in the specified destination repository or
1600 Show changesets not found in the specified destination repository or
1601 the default push location. These are the changesets that would be pushed
1601 the default push location. These are the changesets that would be pushed
1602 if a push was requested.
1602 if a push was requested.
1603
1603
1604 See pull for valid destination format details.
1604 See pull for valid destination format details.
1605 """
1605 """
1606 dest = ui.expandpath(dest or 'default-push', dest or 'default')
1606 dest = ui.expandpath(dest or 'default-push', dest or 'default')
1607 setremoteconfig(ui, opts)
1607 setremoteconfig(ui, opts)
1608 revs = None
1608 revs = None
1609 if opts['rev']:
1609 if opts['rev']:
1610 revs = [repo.lookup(rev) for rev in opts['rev']]
1610 revs = [repo.lookup(rev) for rev in opts['rev']]
1611
1611
1612 other = hg.repository(ui, dest)
1612 other = hg.repository(ui, dest)
1613 o = repo.findoutgoing(other, force=opts['force'])
1613 o = repo.findoutgoing(other, force=opts['force'])
1614 if not o:
1614 if not o:
1615 ui.status(_("no changes found\n"))
1615 ui.status(_("no changes found\n"))
1616 return
1616 return
1617 o = repo.changelog.nodesbetween(o, revs)[0]
1617 o = repo.changelog.nodesbetween(o, revs)[0]
1618 if opts['newest_first']:
1618 if opts['newest_first']:
1619 o.reverse()
1619 o.reverse()
1620 displayer = cmdutil.show_changeset(ui, repo, opts)
1620 displayer = cmdutil.show_changeset(ui, repo, opts)
1621 for n in o:
1621 for n in o:
1622 parents = [p for p in repo.changelog.parents(n) if p != nullid]
1622 parents = [p for p in repo.changelog.parents(n) if p != nullid]
1623 if opts['no_merges'] and len(parents) == 2:
1623 if opts['no_merges'] and len(parents) == 2:
1624 continue
1624 continue
1625 displayer.show(changenode=n)
1625 displayer.show(changenode=n)
1626
1626
1627 def parents(ui, repo, file_=None, rev=None, **opts):
1627 def parents(ui, repo, file_=None, rev=None, **opts):
1628 """show the parents of the working dir or revision
1628 """show the parents of the working dir or revision
1629
1629
1630 Print the working directory's parent revisions.
1630 Print the working directory's parent revisions.
1631 """
1631 """
1632 # legacy
1632 # legacy
1633 if file_ and not rev:
1633 if file_ and not rev:
1634 try:
1634 try:
1635 rev = repo.lookup(file_)
1635 rev = repo.lookup(file_)
1636 file_ = None
1636 file_ = None
1637 except hg.RepoError:
1637 except hg.RepoError:
1638 pass
1638 pass
1639 else:
1639 else:
1640 ui.warn(_("'hg parent REV' is deprecated, "
1640 ui.warn(_("'hg parent REV' is deprecated, "
1641 "please use 'hg parents -r REV instead\n"))
1641 "please use 'hg parents -r REV instead\n"))
1642
1642
1643 if rev:
1643 if rev:
1644 if file_:
1644 if file_:
1645 ctx = repo.filectx(file_, changeid=rev)
1645 ctx = repo.filectx(file_, changeid=rev)
1646 else:
1646 else:
1647 ctx = repo.changectx(rev)
1647 ctx = repo.changectx(rev)
1648 p = [cp.node() for cp in ctx.parents()]
1648 p = [cp.node() for cp in ctx.parents()]
1649 else:
1649 else:
1650 p = repo.dirstate.parents()
1650 p = repo.dirstate.parents()
1651
1651
1652 displayer = cmdutil.show_changeset(ui, repo, opts)
1652 displayer = cmdutil.show_changeset(ui, repo, opts)
1653 for n in p:
1653 for n in p:
1654 if n != nullid:
1654 if n != nullid:
1655 displayer.show(changenode=n)
1655 displayer.show(changenode=n)
1656
1656
1657 def paths(ui, repo, search=None):
1657 def paths(ui, repo, search=None):
1658 """show definition of symbolic path names
1658 """show definition of symbolic path names
1659
1659
1660 Show definition of symbolic path name NAME. If no name is given, show
1660 Show definition of symbolic path name NAME. If no name is given, show
1661 definition of available names.
1661 definition of available names.
1662
1662
1663 Path names are defined in the [paths] section of /etc/mercurial/hgrc
1663 Path names are defined in the [paths] section of /etc/mercurial/hgrc
1664 and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.
1664 and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.
1665 """
1665 """
1666 if search:
1666 if search:
1667 for name, path in ui.configitems("paths"):
1667 for name, path in ui.configitems("paths"):
1668 if name == search:
1668 if name == search:
1669 ui.write("%s\n" % path)
1669 ui.write("%s\n" % path)
1670 return
1670 return
1671 ui.warn(_("not found!\n"))
1671 ui.warn(_("not found!\n"))
1672 return 1
1672 return 1
1673 else:
1673 else:
1674 for name, path in ui.configitems("paths"):
1674 for name, path in ui.configitems("paths"):
1675 ui.write("%s = %s\n" % (name, path))
1675 ui.write("%s = %s\n" % (name, path))
1676
1676
1677 def postincoming(ui, repo, modheads, optupdate):
1677 def postincoming(ui, repo, modheads, optupdate):
1678 if modheads == 0:
1678 if modheads == 0:
1679 return
1679 return
1680 if optupdate:
1680 if optupdate:
1681 if modheads == 1:
1681 if modheads == 1:
1682 return hg.update(repo, repo.changelog.tip()) # update
1682 return hg.update(repo, repo.changelog.tip()) # update
1683 else:
1683 else:
1684 ui.status(_("not updating, since new heads added\n"))
1684 ui.status(_("not updating, since new heads added\n"))
1685 if modheads > 1:
1685 if modheads > 1:
1686 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
1686 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
1687 else:
1687 else:
1688 ui.status(_("(run 'hg update' to get a working copy)\n"))
1688 ui.status(_("(run 'hg update' to get a working copy)\n"))
1689
1689
1690 def pull(ui, repo, source="default", **opts):
1690 def pull(ui, repo, source="default", **opts):
1691 """pull changes from the specified source
1691 """pull changes from the specified source
1692
1692
1693 Pull changes from a remote repository to a local one.
1693 Pull changes from a remote repository to a local one.
1694
1694
1695 This finds all changes from the repository at the specified path
1695 This finds all changes from the repository at the specified path
1696 or URL and adds them to the local repository. By default, this
1696 or URL and adds them to the local repository. By default, this
1697 does not update the copy of the project in the working directory.
1697 does not update the copy of the project in the working directory.
1698
1698
1699 Valid URLs are of the form:
1699 Valid URLs are of the form:
1700
1700
1701 local/filesystem/path (or file://local/filesystem/path)
1701 local/filesystem/path (or file://local/filesystem/path)
1702 http://[user@]host[:port]/[path]
1702 http://[user@]host[:port]/[path]
1703 https://[user@]host[:port]/[path]
1703 https://[user@]host[:port]/[path]
1704 ssh://[user@]host[:port]/[path]
1704 ssh://[user@]host[:port]/[path]
1705 static-http://host[:port]/[path]
1705 static-http://host[:port]/[path]
1706
1706
1707 Paths in the local filesystem can either point to Mercurial
1707 Paths in the local filesystem can either point to Mercurial
1708 repositories or to bundle files (as created by 'hg bundle' or
1708 repositories or to bundle files (as created by 'hg bundle' or
1709 'hg incoming --bundle'). The static-http:// protocol, albeit slow,
1709 'hg incoming --bundle'). The static-http:// protocol, albeit slow,
1710 allows access to a Mercurial repository where you simply use a web
1710 allows access to a Mercurial repository where you simply use a web
1711 server to publish the .hg directory as static content.
1711 server to publish the .hg directory as static content.
1712
1712
1713 Some notes about using SSH with Mercurial:
1713 Some notes about using SSH with Mercurial:
1714 - SSH requires an accessible shell account on the destination machine
1714 - SSH requires an accessible shell account on the destination machine
1715 and a copy of hg in the remote path or specified with as remotecmd.
1715 and a copy of hg in the remote path or specified with as remotecmd.
1716 - path is relative to the remote user's home directory by default.
1716 - path is relative to the remote user's home directory by default.
1717 Use an extra slash at the start of a path to specify an absolute path:
1717 Use an extra slash at the start of a path to specify an absolute path:
1718 ssh://example.com//tmp/repository
1718 ssh://example.com//tmp/repository
1719 - Mercurial doesn't use its own compression via SSH; the right thing
1719 - Mercurial doesn't use its own compression via SSH; the right thing
1720 to do is to configure it in your ~/.ssh/config, e.g.:
1720 to do is to configure it in your ~/.ssh/config, e.g.:
1721 Host *.mylocalnetwork.example.com
1721 Host *.mylocalnetwork.example.com
1722 Compression no
1722 Compression no
1723 Host *
1723 Host *
1724 Compression yes
1724 Compression yes
1725 Alternatively specify "ssh -C" as your ssh command in your hgrc or
1725 Alternatively specify "ssh -C" as your ssh command in your hgrc or
1726 with the --ssh command line option.
1726 with the --ssh command line option.
1727 """
1727 """
1728 source = ui.expandpath(source)
1728 source = ui.expandpath(source)
1729 setremoteconfig(ui, opts)
1729 setremoteconfig(ui, opts)
1730
1730
1731 other = hg.repository(ui, source)
1731 other = hg.repository(ui, source)
1732 ui.status(_('pulling from %s\n') % (source))
1732 ui.status(_('pulling from %s\n') % (source))
1733 revs = None
1733 revs = None
1734 if opts['rev']:
1734 if opts['rev']:
1735 if 'lookup' in other.capabilities:
1735 if 'lookup' in other.capabilities:
1736 revs = [other.lookup(rev) for rev in opts['rev']]
1736 revs = [other.lookup(rev) for rev in opts['rev']]
1737 else:
1737 else:
1738 error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
1738 error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
1739 raise util.Abort(error)
1739 raise util.Abort(error)
1740 modheads = repo.pull(other, heads=revs, force=opts['force'])
1740 modheads = repo.pull(other, heads=revs, force=opts['force'])
1741 return postincoming(ui, repo, modheads, opts['update'])
1741 return postincoming(ui, repo, modheads, opts['update'])
1742
1742
1743 def push(ui, repo, dest=None, **opts):
1743 def push(ui, repo, dest=None, **opts):
1744 """push changes to the specified destination
1744 """push changes to the specified destination
1745
1745
1746 Push changes from the local repository to the given destination.
1746 Push changes from the local repository to the given destination.
1747
1747
1748 This is the symmetrical operation for pull. It helps to move
1748 This is the symmetrical operation for pull. It helps to move
1749 changes from the current repository to a different one. If the
1749 changes from the current repository to a different one. If the
1750 destination is local this is identical to a pull in that directory
1750 destination is local this is identical to a pull in that directory
1751 from the current one.
1751 from the current one.
1752
1752
1753 By default, push will refuse to run if it detects the result would
1753 By default, push will refuse to run if it detects the result would
1754 increase the number of remote heads. This generally indicates the
1754 increase the number of remote heads. This generally indicates the
1755 the client has forgotten to sync and merge before pushing.
1755 the client has forgotten to sync and merge before pushing.
1756
1756
1757 Valid URLs are of the form:
1757 Valid URLs are of the form:
1758
1758
1759 local/filesystem/path (or file://local/filesystem/path)
1759 local/filesystem/path (or file://local/filesystem/path)
1760 ssh://[user@]host[:port]/[path]
1760 ssh://[user@]host[:port]/[path]
1761 http://[user@]host[:port]/[path]
1761 http://[user@]host[:port]/[path]
1762 https://[user@]host[:port]/[path]
1762 https://[user@]host[:port]/[path]
1763
1763
1764 Look at the help text for the pull command for important details
1764 Look at the help text for the pull command for important details
1765 about ssh:// URLs.
1765 about ssh:// URLs.
1766
1766
1767 Pushing to http:// and https:// URLs is only possible, if this
1767 Pushing to http:// and https:// URLs is only possible, if this
1768 feature is explicitly enabled on the remote Mercurial server.
1768 feature is explicitly enabled on the remote Mercurial server.
1769 """
1769 """
1770 dest = ui.expandpath(dest or 'default-push', dest or 'default')
1770 dest = ui.expandpath(dest or 'default-push', dest or 'default')
1771 setremoteconfig(ui, opts)
1771 setremoteconfig(ui, opts)
1772
1772
1773 other = hg.repository(ui, dest)
1773 other = hg.repository(ui, dest)
1774 ui.status('pushing to %s\n' % (dest))
1774 ui.status('pushing to %s\n' % (dest))
1775 revs = None
1775 revs = None
1776 if opts['rev']:
1776 if opts['rev']:
1777 revs = [repo.lookup(rev) for rev in opts['rev']]
1777 revs = [repo.lookup(rev) for rev in opts['rev']]
1778 r = repo.push(other, opts['force'], revs=revs)
1778 r = repo.push(other, opts['force'], revs=revs)
1779 return r == 0
1779 return r == 0
1780
1780
1781 def rawcommit(ui, repo, *flist, **rc):
1781 def rawcommit(ui, repo, *pats, **opts):
1782 """raw commit interface (DEPRECATED)
1782 """raw commit interface (DEPRECATED)
1783
1783
1784 (DEPRECATED)
1784 (DEPRECATED)
1785 Lowlevel commit, for use in helper scripts.
1785 Lowlevel commit, for use in helper scripts.
1786
1786
1787 This command is not intended to be used by normal users, as it is
1787 This command is not intended to be used by normal users, as it is
1788 primarily useful for importing from other SCMs.
1788 primarily useful for importing from other SCMs.
1789
1789
1790 This command is now deprecated and will be removed in a future
1790 This command is now deprecated and will be removed in a future
1791 release, please use debugsetparents and commit instead.
1791 release, please use debugsetparents and commit instead.
1792 """
1792 """
1793
1793
1794 ui.warn(_("(the rawcommit command is deprecated)\n"))
1794 ui.warn(_("(the rawcommit command is deprecated)\n"))
1795
1795
1796 message = rc['message']
1796 message = logmessage(opts)
1797 if not message and rc['logfile']:
1797
1798 try:
1798 files, match, anypats = cmdutil.matchpats(repo, pats, opts)
1799 message = open(rc['logfile']).read()
1799 if opts['files']:
1800 except IOError:
1800 files += open(opts['files']).read().splitlines()
1801 pass
1801
1802 if not message and not rc['logfile']:
1802 parents = [repo.lookup(p) for p in opts['parent']]
1803 raise util.Abort(_("missing commit message"))
1804
1805 files = relpath(repo, list(flist))
1806 if rc['files']:
1807 files += open(rc['files']).read().splitlines()
1808
1809 rc['parent'] = map(repo.lookup, rc['parent'])
1810
1803
1811 try:
1804 try:
1812 repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent'])
1805 repo.rawcommit(files, message,
1806 opts['user'], opts['date'], *parents)
1813 except ValueError, inst:
1807 except ValueError, inst:
1814 raise util.Abort(str(inst))
1808 raise util.Abort(str(inst))
1815
1809
1816 def recover(ui, repo):
1810 def recover(ui, repo):
1817 """roll back an interrupted transaction
1811 """roll back an interrupted transaction
1818
1812
1819 Recover from an interrupted commit or pull.
1813 Recover from an interrupted commit or pull.
1820
1814
1821 This command tries to fix the repository status after an interrupted
1815 This command tries to fix the repository status after an interrupted
1822 operation. It should only be necessary when Mercurial suggests it.
1816 operation. It should only be necessary when Mercurial suggests it.
1823 """
1817 """
1824 if repo.recover():
1818 if repo.recover():
1825 return hg.verify(repo)
1819 return hg.verify(repo)
1826 return 1
1820 return 1
1827
1821
1828 def remove(ui, repo, *pats, **opts):
1822 def remove(ui, repo, *pats, **opts):
1829 """remove the specified files on the next commit
1823 """remove the specified files on the next commit
1830
1824
1831 Schedule the indicated files for removal from the repository.
1825 Schedule the indicated files for removal from the repository.
1832
1826
1833 This command schedules the files to be removed at the next commit.
1827 This command schedules the files to be removed at the next commit.
1834 This only removes files from the current branch, not from the
1828 This only removes files from the current branch, not from the
1835 entire project history. If the files still exist in the working
1829 entire project history. If the files still exist in the working
1836 directory, they will be deleted from it. If invoked with --after,
1830 directory, they will be deleted from it. If invoked with --after,
1837 files that have been manually deleted are marked as removed.
1831 files that have been manually deleted are marked as removed.
1838
1832
1839 Modified files and added files are not removed by default. To
1833 Modified files and added files are not removed by default. To
1840 remove them, use the -f/--force option.
1834 remove them, use the -f/--force option.
1841 """
1835 """
1842 names = []
1836 names = []
1843 if not opts['after'] and not pats:
1837 if not opts['after'] and not pats:
1844 raise util.Abort(_('no files specified'))
1838 raise util.Abort(_('no files specified'))
1845 files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
1839 files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
1846 exact = dict.fromkeys(files)
1840 exact = dict.fromkeys(files)
1847 mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5]
1841 mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5]
1848 modified, added, removed, deleted, unknown = mardu
1842 modified, added, removed, deleted, unknown = mardu
1849 remove, forget = [], []
1843 remove, forget = [], []
1850 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
1844 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
1851 reason = None
1845 reason = None
1852 if abs not in deleted and opts['after']:
1846 if abs not in deleted and opts['after']:
1853 reason = _('is still present')
1847 reason = _('is still present')
1854 elif abs in modified and not opts['force']:
1848 elif abs in modified and not opts['force']:
1855 reason = _('is modified (use -f to force removal)')
1849 reason = _('is modified (use -f to force removal)')
1856 elif abs in added:
1850 elif abs in added:
1857 if opts['force']:
1851 if opts['force']:
1858 forget.append(abs)
1852 forget.append(abs)
1859 continue
1853 continue
1860 reason = _('has been marked for add (use -f to force removal)')
1854 reason = _('has been marked for add (use -f to force removal)')
1861 elif abs in unknown:
1855 elif abs in unknown:
1862 reason = _('is not managed')
1856 reason = _('is not managed')
1863 elif abs in removed:
1857 elif abs in removed:
1864 continue
1858 continue
1865 if reason:
1859 if reason:
1866 if exact:
1860 if exact:
1867 ui.warn(_('not removing %s: file %s\n') % (rel, reason))
1861 ui.warn(_('not removing %s: file %s\n') % (rel, reason))
1868 else:
1862 else:
1869 if ui.verbose or not exact:
1863 if ui.verbose or not exact:
1870 ui.status(_('removing %s\n') % rel)
1864 ui.status(_('removing %s\n') % rel)
1871 remove.append(abs)
1865 remove.append(abs)
1872 repo.forget(forget)
1866 repo.forget(forget)
1873 repo.remove(remove, unlink=not opts['after'])
1867 repo.remove(remove, unlink=not opts['after'])
1874
1868
1875 def rename(ui, repo, *pats, **opts):
1869 def rename(ui, repo, *pats, **opts):
1876 """rename files; equivalent of copy + remove
1870 """rename files; equivalent of copy + remove
1877
1871
1878 Mark dest as copies of sources; mark sources for deletion. If
1872 Mark dest as copies of sources; mark sources for deletion. If
1879 dest is a directory, copies are put in that directory. If dest is
1873 dest is a directory, copies are put in that directory. If dest is
1880 a file, there can only be one source.
1874 a file, there can only be one source.
1881
1875
1882 By default, this command copies the contents of files as they
1876 By default, this command copies the contents of files as they
1883 stand in the working directory. If invoked with --after, the
1877 stand in the working directory. If invoked with --after, the
1884 operation is recorded, but no copying is performed.
1878 operation is recorded, but no copying is performed.
1885
1879
1886 This command takes effect in the next commit.
1880 This command takes effect in the next commit.
1887
1881
1888 NOTE: This command should be treated as experimental. While it
1882 NOTE: This command should be treated as experimental. While it
1889 should properly record rename files, this information is not yet
1883 should properly record rename files, this information is not yet
1890 fully used by merge, nor fully reported by log.
1884 fully used by merge, nor fully reported by log.
1891 """
1885 """
1892 wlock = repo.wlock(0)
1886 wlock = repo.wlock(0)
1893 errs, copied = docopy(ui, repo, pats, opts, wlock)
1887 errs, copied = docopy(ui, repo, pats, opts, wlock)
1894 names = []
1888 names = []
1895 for abs, rel, exact in copied:
1889 for abs, rel, exact in copied:
1896 if ui.verbose or not exact:
1890 if ui.verbose or not exact:
1897 ui.status(_('removing %s\n') % rel)
1891 ui.status(_('removing %s\n') % rel)
1898 names.append(abs)
1892 names.append(abs)
1899 if not opts.get('dry_run'):
1893 if not opts.get('dry_run'):
1900 repo.remove(names, True, wlock)
1894 repo.remove(names, True, wlock)
1901 return errs
1895 return errs
1902
1896
1903 def revert(ui, repo, *pats, **opts):
1897 def revert(ui, repo, *pats, **opts):
1904 """revert files or dirs to their states as of some revision
1898 """revert files or dirs to their states as of some revision
1905
1899
1906 With no revision specified, revert the named files or directories
1900 With no revision specified, revert the named files or directories
1907 to the contents they had in the parent of the working directory.
1901 to the contents they had in the parent of the working directory.
1908 This restores the contents of the affected files to an unmodified
1902 This restores the contents of the affected files to an unmodified
1909 state. If the working directory has two parents, you must
1903 state. If the working directory has two parents, you must
1910 explicitly specify the revision to revert to.
1904 explicitly specify the revision to revert to.
1911
1905
1912 Modified files are saved with a .orig suffix before reverting.
1906 Modified files are saved with a .orig suffix before reverting.
1913 To disable these backups, use --no-backup.
1907 To disable these backups, use --no-backup.
1914
1908
1915 Using the -r option, revert the given files or directories to their
1909 Using the -r option, revert the given files or directories to their
1916 contents as of a specific revision. This can be helpful to "roll
1910 contents as of a specific revision. This can be helpful to "roll
1917 back" some or all of a change that should not have been committed.
1911 back" some or all of a change that should not have been committed.
1918
1912
1919 Revert modifies the working directory. It does not commit any
1913 Revert modifies the working directory. It does not commit any
1920 changes, or change the parent of the working directory. If you
1914 changes, or change the parent of the working directory. If you
1921 revert to a revision other than the parent of the working
1915 revert to a revision other than the parent of the working
1922 directory, the reverted files will thus appear modified
1916 directory, the reverted files will thus appear modified
1923 afterwards.
1917 afterwards.
1924
1918
1925 If a file has been deleted, it is recreated. If the executable
1919 If a file has been deleted, it is recreated. If the executable
1926 mode of a file was changed, it is reset.
1920 mode of a file was changed, it is reset.
1927
1921
1928 If names are given, all files matching the names are reverted.
1922 If names are given, all files matching the names are reverted.
1929
1923
1930 If no arguments are given, no files are reverted.
1924 If no arguments are given, no files are reverted.
1931 """
1925 """
1932
1926
1933 if not pats and not opts['all']:
1927 if not pats and not opts['all']:
1934 raise util.Abort(_('no files or directories specified; '
1928 raise util.Abort(_('no files or directories specified; '
1935 'use --all to revert the whole repo'))
1929 'use --all to revert the whole repo'))
1936
1930
1937 parent, p2 = repo.dirstate.parents()
1931 parent, p2 = repo.dirstate.parents()
1938 if not opts['rev'] and p2 != nullid:
1932 if not opts['rev'] and p2 != nullid:
1939 raise util.Abort(_('uncommitted merge - please provide a '
1933 raise util.Abort(_('uncommitted merge - please provide a '
1940 'specific revision'))
1934 'specific revision'))
1941 node = repo.changectx(opts['rev']).node()
1935 node = repo.changectx(opts['rev']).node()
1942 mf = repo.manifest.read(repo.changelog.read(node)[0])
1936 mf = repo.manifest.read(repo.changelog.read(node)[0])
1943 if node == parent:
1937 if node == parent:
1944 pmf = mf
1938 pmf = mf
1945 else:
1939 else:
1946 pmf = None
1940 pmf = None
1947
1941
1948 wlock = repo.wlock()
1942 wlock = repo.wlock()
1949
1943
1950 # need all matching names in dirstate and manifest of target rev,
1944 # need all matching names in dirstate and manifest of target rev,
1951 # so have to walk both. do not print errors if files exist in one
1945 # so have to walk both. do not print errors if files exist in one
1952 # but not other.
1946 # but not other.
1953
1947
1954 names = {}
1948 names = {}
1955 target_only = {}
1949 target_only = {}
1956
1950
1957 # walk dirstate.
1951 # walk dirstate.
1958
1952
1959 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
1953 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
1960 badmatch=mf.has_key):
1954 badmatch=mf.has_key):
1961 names[abs] = (rel, exact)
1955 names[abs] = (rel, exact)
1962 if src == 'b':
1956 if src == 'b':
1963 target_only[abs] = True
1957 target_only[abs] = True
1964
1958
1965 # walk target manifest.
1959 # walk target manifest.
1966
1960
1967 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
1961 for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node,
1968 badmatch=names.has_key):
1962 badmatch=names.has_key):
1969 if abs in names: continue
1963 if abs in names: continue
1970 names[abs] = (rel, exact)
1964 names[abs] = (rel, exact)
1971 target_only[abs] = True
1965 target_only[abs] = True
1972
1966
1973 changes = repo.status(match=names.has_key, wlock=wlock)[:5]
1967 changes = repo.status(match=names.has_key, wlock=wlock)[:5]
1974 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes)
1968 modified, added, removed, deleted, unknown = map(dict.fromkeys, changes)
1975
1969
1976 revert = ([], _('reverting %s\n'))
1970 revert = ([], _('reverting %s\n'))
1977 add = ([], _('adding %s\n'))
1971 add = ([], _('adding %s\n'))
1978 remove = ([], _('removing %s\n'))
1972 remove = ([], _('removing %s\n'))
1979 forget = ([], _('forgetting %s\n'))
1973 forget = ([], _('forgetting %s\n'))
1980 undelete = ([], _('undeleting %s\n'))
1974 undelete = ([], _('undeleting %s\n'))
1981 update = {}
1975 update = {}
1982
1976
1983 disptable = (
1977 disptable = (
1984 # dispatch table:
1978 # dispatch table:
1985 # file state
1979 # file state
1986 # action if in target manifest
1980 # action if in target manifest
1987 # action if not in target manifest
1981 # action if not in target manifest
1988 # make backup if in target manifest
1982 # make backup if in target manifest
1989 # make backup if not in target manifest
1983 # make backup if not in target manifest
1990 (modified, revert, remove, True, True),
1984 (modified, revert, remove, True, True),
1991 (added, revert, forget, True, False),
1985 (added, revert, forget, True, False),
1992 (removed, undelete, None, False, False),
1986 (removed, undelete, None, False, False),
1993 (deleted, revert, remove, False, False),
1987 (deleted, revert, remove, False, False),
1994 (unknown, add, None, True, False),
1988 (unknown, add, None, True, False),
1995 (target_only, add, None, False, False),
1989 (target_only, add, None, False, False),
1996 )
1990 )
1997
1991
1998 entries = names.items()
1992 entries = names.items()
1999 entries.sort()
1993 entries.sort()
2000
1994
2001 for abs, (rel, exact) in entries:
1995 for abs, (rel, exact) in entries:
2002 mfentry = mf.get(abs)
1996 mfentry = mf.get(abs)
2003 def handle(xlist, dobackup):
1997 def handle(xlist, dobackup):
2004 xlist[0].append(abs)
1998 xlist[0].append(abs)
2005 update[abs] = 1
1999 update[abs] = 1
2006 if dobackup and not opts['no_backup'] and os.path.exists(rel):
2000 if dobackup and not opts['no_backup'] and os.path.exists(rel):
2007 bakname = "%s.orig" % rel
2001 bakname = "%s.orig" % rel
2008 ui.note(_('saving current version of %s as %s\n') %
2002 ui.note(_('saving current version of %s as %s\n') %
2009 (rel, bakname))
2003 (rel, bakname))
2010 if not opts.get('dry_run'):
2004 if not opts.get('dry_run'):
2011 util.copyfile(rel, bakname)
2005 util.copyfile(rel, bakname)
2012 if ui.verbose or not exact:
2006 if ui.verbose or not exact:
2013 ui.status(xlist[1] % rel)
2007 ui.status(xlist[1] % rel)
2014 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2008 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2015 if abs not in table: continue
2009 if abs not in table: continue
2016 # file has changed in dirstate
2010 # file has changed in dirstate
2017 if mfentry:
2011 if mfentry:
2018 handle(hitlist, backuphit)
2012 handle(hitlist, backuphit)
2019 elif misslist is not None:
2013 elif misslist is not None:
2020 handle(misslist, backupmiss)
2014 handle(misslist, backupmiss)
2021 else:
2015 else:
2022 if exact: ui.warn(_('file not managed: %s\n' % rel))
2016 if exact: ui.warn(_('file not managed: %s\n' % rel))
2023 break
2017 break
2024 else:
2018 else:
2025 # file has not changed in dirstate
2019 # file has not changed in dirstate
2026 if node == parent:
2020 if node == parent:
2027 if exact: ui.warn(_('no changes needed to %s\n' % rel))
2021 if exact: ui.warn(_('no changes needed to %s\n' % rel))
2028 continue
2022 continue
2029 if pmf is None:
2023 if pmf is None:
2030 # only need parent manifest in this unlikely case,
2024 # only need parent manifest in this unlikely case,
2031 # so do not read by default
2025 # so do not read by default
2032 pmf = repo.manifest.read(repo.changelog.read(parent)[0])
2026 pmf = repo.manifest.read(repo.changelog.read(parent)[0])
2033 if abs in pmf:
2027 if abs in pmf:
2034 if mfentry:
2028 if mfentry:
2035 # if version of file is same in parent and target
2029 # if version of file is same in parent and target
2036 # manifests, do nothing
2030 # manifests, do nothing
2037 if pmf[abs] != mfentry:
2031 if pmf[abs] != mfentry:
2038 handle(revert, False)
2032 handle(revert, False)
2039 else:
2033 else:
2040 handle(remove, False)
2034 handle(remove, False)
2041
2035
2042 if not opts.get('dry_run'):
2036 if not opts.get('dry_run'):
2043 repo.dirstate.forget(forget[0])
2037 repo.dirstate.forget(forget[0])
2044 r = hg.revert(repo, node, update.has_key, wlock)
2038 r = hg.revert(repo, node, update.has_key, wlock)
2045 repo.dirstate.update(add[0], 'a')
2039 repo.dirstate.update(add[0], 'a')
2046 repo.dirstate.update(undelete[0], 'n')
2040 repo.dirstate.update(undelete[0], 'n')
2047 repo.dirstate.update(remove[0], 'r')
2041 repo.dirstate.update(remove[0], 'r')
2048 return r
2042 return r
2049
2043
2050 def rollback(ui, repo):
2044 def rollback(ui, repo):
2051 """roll back the last transaction in this repository
2045 """roll back the last transaction in this repository
2052
2046
2053 Roll back the last transaction in this repository, restoring the
2047 Roll back the last transaction in this repository, restoring the
2054 project to its state prior to the transaction.
2048 project to its state prior to the transaction.
2055
2049
2056 Transactions are used to encapsulate the effects of all commands
2050 Transactions are used to encapsulate the effects of all commands
2057 that create new changesets or propagate existing changesets into a
2051 that create new changesets or propagate existing changesets into a
2058 repository. For example, the following commands are transactional,
2052 repository. For example, the following commands are transactional,
2059 and their effects can be rolled back:
2053 and their effects can be rolled back:
2060
2054
2061 commit
2055 commit
2062 import
2056 import
2063 pull
2057 pull
2064 push (with this repository as destination)
2058 push (with this repository as destination)
2065 unbundle
2059 unbundle
2066
2060
2067 This command should be used with care. There is only one level of
2061 This command should be used with care. There is only one level of
2068 rollback, and there is no way to undo a rollback.
2062 rollback, and there is no way to undo a rollback.
2069
2063
2070 This command is not intended for use on public repositories. Once
2064 This command is not intended for use on public repositories. Once
2071 changes are visible for pull by other users, rolling a transaction
2065 changes are visible for pull by other users, rolling a transaction
2072 back locally is ineffective (someone else may already have pulled
2066 back locally is ineffective (someone else may already have pulled
2073 the changes). Furthermore, a race is possible with readers of the
2067 the changes). Furthermore, a race is possible with readers of the
2074 repository; for example an in-progress pull from the repository
2068 repository; for example an in-progress pull from the repository
2075 may fail if a rollback is performed.
2069 may fail if a rollback is performed.
2076 """
2070 """
2077 repo.rollback()
2071 repo.rollback()
2078
2072
2079 def root(ui, repo):
2073 def root(ui, repo):
2080 """print the root (top) of the current working dir
2074 """print the root (top) of the current working dir
2081
2075
2082 Print the root directory of the current repository.
2076 Print the root directory of the current repository.
2083 """
2077 """
2084 ui.write(repo.root + "\n")
2078 ui.write(repo.root + "\n")
2085
2079
2086 def serve(ui, repo, **opts):
2080 def serve(ui, repo, **opts):
2087 """export the repository via HTTP
2081 """export the repository via HTTP
2088
2082
2089 Start a local HTTP repository browser and pull server.
2083 Start a local HTTP repository browser and pull server.
2090
2084
2091 By default, the server logs accesses to stdout and errors to
2085 By default, the server logs accesses to stdout and errors to
2092 stderr. Use the "-A" and "-E" options to log to files.
2086 stderr. Use the "-A" and "-E" options to log to files.
2093 """
2087 """
2094
2088
2095 if opts["stdio"]:
2089 if opts["stdio"]:
2096 if repo is None:
2090 if repo is None:
2097 raise hg.RepoError(_("There is no Mercurial repository here"
2091 raise hg.RepoError(_("There is no Mercurial repository here"
2098 " (.hg not found)"))
2092 " (.hg not found)"))
2099 s = sshserver.sshserver(ui, repo)
2093 s = sshserver.sshserver(ui, repo)
2100 s.serve_forever()
2094 s.serve_forever()
2101
2095
2102 optlist = ("name templates style address port ipv6"
2096 optlist = ("name templates style address port ipv6"
2103 " accesslog errorlog webdir_conf")
2097 " accesslog errorlog webdir_conf")
2104 for o in optlist.split():
2098 for o in optlist.split():
2105 if opts[o]:
2099 if opts[o]:
2106 ui.setconfig("web", o, str(opts[o]))
2100 ui.setconfig("web", o, str(opts[o]))
2107
2101
2108 if repo is None and not ui.config("web", "webdir_conf"):
2102 if repo is None and not ui.config("web", "webdir_conf"):
2109 raise hg.RepoError(_("There is no Mercurial repository here"
2103 raise hg.RepoError(_("There is no Mercurial repository here"
2110 " (.hg not found)"))
2104 " (.hg not found)"))
2111
2105
2112 if opts['daemon'] and not opts['daemon_pipefds']:
2106 if opts['daemon'] and not opts['daemon_pipefds']:
2113 rfd, wfd = os.pipe()
2107 rfd, wfd = os.pipe()
2114 args = sys.argv[:]
2108 args = sys.argv[:]
2115 args.append('--daemon-pipefds=%d,%d' % (rfd, wfd))
2109 args.append('--daemon-pipefds=%d,%d' % (rfd, wfd))
2116 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0),
2110 pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0),
2117 args[0], args)
2111 args[0], args)
2118 os.close(wfd)
2112 os.close(wfd)
2119 os.read(rfd, 1)
2113 os.read(rfd, 1)
2120 os._exit(0)
2114 os._exit(0)
2121
2115
2122 httpd = hgweb.server.create_server(ui, repo)
2116 httpd = hgweb.server.create_server(ui, repo)
2123
2117
2124 if ui.verbose:
2118 if ui.verbose:
2125 if httpd.port != 80:
2119 if httpd.port != 80:
2126 ui.status(_('listening at http://%s:%d/\n') %
2120 ui.status(_('listening at http://%s:%d/\n') %
2127 (httpd.addr, httpd.port))
2121 (httpd.addr, httpd.port))
2128 else:
2122 else:
2129 ui.status(_('listening at http://%s/\n') % httpd.addr)
2123 ui.status(_('listening at http://%s/\n') % httpd.addr)
2130
2124
2131 if opts['pid_file']:
2125 if opts['pid_file']:
2132 fp = open(opts['pid_file'], 'w')
2126 fp = open(opts['pid_file'], 'w')
2133 fp.write(str(os.getpid()) + '\n')
2127 fp.write(str(os.getpid()) + '\n')
2134 fp.close()
2128 fp.close()
2135
2129
2136 if opts['daemon_pipefds']:
2130 if opts['daemon_pipefds']:
2137 rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')]
2131 rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')]
2138 os.close(rfd)
2132 os.close(rfd)
2139 os.write(wfd, 'y')
2133 os.write(wfd, 'y')
2140 os.close(wfd)
2134 os.close(wfd)
2141 sys.stdout.flush()
2135 sys.stdout.flush()
2142 sys.stderr.flush()
2136 sys.stderr.flush()
2143 fd = os.open(util.nulldev, os.O_RDWR)
2137 fd = os.open(util.nulldev, os.O_RDWR)
2144 if fd != 0: os.dup2(fd, 0)
2138 if fd != 0: os.dup2(fd, 0)
2145 if fd != 1: os.dup2(fd, 1)
2139 if fd != 1: os.dup2(fd, 1)
2146 if fd != 2: os.dup2(fd, 2)
2140 if fd != 2: os.dup2(fd, 2)
2147 if fd not in (0, 1, 2): os.close(fd)
2141 if fd not in (0, 1, 2): os.close(fd)
2148
2142
2149 httpd.serve_forever()
2143 httpd.serve_forever()
2150
2144
2151 def status(ui, repo, *pats, **opts):
2145 def status(ui, repo, *pats, **opts):
2152 """show changed files in the working directory
2146 """show changed files in the working directory
2153
2147
2154 Show status of files in the repository. If names are given, only
2148 Show status of files in the repository. If names are given, only
2155 files that match are shown. Files that are clean or ignored, are
2149 files that match are shown. Files that are clean or ignored, are
2156 not listed unless -c (clean), -i (ignored) or -A is given.
2150 not listed unless -c (clean), -i (ignored) or -A is given.
2157
2151
2158 If one revision is given, it is used as the base revision.
2152 If one revision is given, it is used as the base revision.
2159 If two revisions are given, the difference between them is shown.
2153 If two revisions are given, the difference between them is shown.
2160
2154
2161 The codes used to show the status of files are:
2155 The codes used to show the status of files are:
2162 M = modified
2156 M = modified
2163 A = added
2157 A = added
2164 R = removed
2158 R = removed
2165 C = clean
2159 C = clean
2166 ! = deleted, but still tracked
2160 ! = deleted, but still tracked
2167 ? = not tracked
2161 ? = not tracked
2168 I = ignored (not shown by default)
2162 I = ignored (not shown by default)
2169 = the previous added file was copied from here
2163 = the previous added file was copied from here
2170 """
2164 """
2171
2165
2172 all = opts['all']
2166 all = opts['all']
2173 node1, node2 = cmdutil.revpair(ui, repo, opts.get('rev'))
2167 node1, node2 = cmdutil.revpair(ui, repo, opts.get('rev'))
2174
2168
2175 files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
2169 files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
2176 cwd = (pats and repo.getcwd()) or ''
2170 cwd = (pats and repo.getcwd()) or ''
2177 modified, added, removed, deleted, unknown, ignored, clean = [
2171 modified, added, removed, deleted, unknown, ignored, clean = [
2178 [util.pathto(cwd, x) for x in n]
2172 [util.pathto(cwd, x) for x in n]
2179 for n in repo.status(node1=node1, node2=node2, files=files,
2173 for n in repo.status(node1=node1, node2=node2, files=files,
2180 match=matchfn,
2174 match=matchfn,
2181 list_ignored=all or opts['ignored'],
2175 list_ignored=all or opts['ignored'],
2182 list_clean=all or opts['clean'])]
2176 list_clean=all or opts['clean'])]
2183
2177
2184 changetypes = (('modified', 'M', modified),
2178 changetypes = (('modified', 'M', modified),
2185 ('added', 'A', added),
2179 ('added', 'A', added),
2186 ('removed', 'R', removed),
2180 ('removed', 'R', removed),
2187 ('deleted', '!', deleted),
2181 ('deleted', '!', deleted),
2188 ('unknown', '?', unknown),
2182 ('unknown', '?', unknown),
2189 ('ignored', 'I', ignored))
2183 ('ignored', 'I', ignored))
2190
2184
2191 explicit_changetypes = changetypes + (('clean', 'C', clean),)
2185 explicit_changetypes = changetypes + (('clean', 'C', clean),)
2192
2186
2193 end = opts['print0'] and '\0' or '\n'
2187 end = opts['print0'] and '\0' or '\n'
2194
2188
2195 for opt, char, changes in ([ct for ct in explicit_changetypes
2189 for opt, char, changes in ([ct for ct in explicit_changetypes
2196 if all or opts[ct[0]]]
2190 if all or opts[ct[0]]]
2197 or changetypes):
2191 or changetypes):
2198 if opts['no_status']:
2192 if opts['no_status']:
2199 format = "%%s%s" % end
2193 format = "%%s%s" % end
2200 else:
2194 else:
2201 format = "%s %%s%s" % (char, end)
2195 format = "%s %%s%s" % (char, end)
2202
2196
2203 for f in changes:
2197 for f in changes:
2204 ui.write(format % f)
2198 ui.write(format % f)
2205 if ((all or opts.get('copies')) and not opts.get('no_status')):
2199 if ((all or opts.get('copies')) and not opts.get('no_status')):
2206 copied = repo.dirstate.copied(f)
2200 copied = repo.dirstate.copied(f)
2207 if copied:
2201 if copied:
2208 ui.write(' %s%s' % (copied, end))
2202 ui.write(' %s%s' % (copied, end))
2209
2203
2210 def tag(ui, repo, name, rev_=None, **opts):
2204 def tag(ui, repo, name, rev_=None, **opts):
2211 """add a tag for the current tip or a given revision
2205 """add a tag for the current tip or a given revision
2212
2206
2213 Name a particular revision using <name>.
2207 Name a particular revision using <name>.
2214
2208
2215 Tags are used to name particular revisions of the repository and are
2209 Tags are used to name particular revisions of the repository and are
2216 very useful to compare different revision, to go back to significant
2210 very useful to compare different revision, to go back to significant
2217 earlier versions or to mark branch points as releases, etc.
2211 earlier versions or to mark branch points as releases, etc.
2218
2212
2219 If no revision is given, the parent of the working directory is used.
2213 If no revision is given, the parent of the working directory is used.
2220
2214
2221 To facilitate version control, distribution, and merging of tags,
2215 To facilitate version control, distribution, and merging of tags,
2222 they are stored as a file named ".hgtags" which is managed
2216 they are stored as a file named ".hgtags" which is managed
2223 similarly to other project files and can be hand-edited if
2217 similarly to other project files and can be hand-edited if
2224 necessary. The file '.hg/localtags' is used for local tags (not
2218 necessary. The file '.hg/localtags' is used for local tags (not
2225 shared among repositories).
2219 shared among repositories).
2226 """
2220 """
2227 if name in ['tip', '.']:
2221 if name in ['tip', '.']:
2228 raise util.Abort(_("the name '%s' is reserved") % name)
2222 raise util.Abort(_("the name '%s' is reserved") % name)
2229 if rev_ is not None:
2223 if rev_ is not None:
2230 ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, "
2224 ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, "
2231 "please use 'hg tag [-r REV] NAME' instead\n"))
2225 "please use 'hg tag [-r REV] NAME' instead\n"))
2232 if opts['rev']:
2226 if opts['rev']:
2233 raise util.Abort(_("use only one form to specify the revision"))
2227 raise util.Abort(_("use only one form to specify the revision"))
2234 if opts['rev']:
2228 if opts['rev']:
2235 rev_ = opts['rev']
2229 rev_ = opts['rev']
2236 if not rev_ and repo.dirstate.parents()[1] != nullid:
2230 if not rev_ and repo.dirstate.parents()[1] != nullid:
2237 raise util.Abort(_('uncommitted merge - please provide a '
2231 raise util.Abort(_('uncommitted merge - please provide a '
2238 'specific revision'))
2232 'specific revision'))
2239 r = repo.changectx(rev_).node()
2233 r = repo.changectx(rev_).node()
2240
2234
2241 message = opts['message']
2235 message = opts['message']
2242 if not message:
2236 if not message:
2243 message = _('Added tag %s for changeset %s') % (name, short(r))
2237 message = _('Added tag %s for changeset %s') % (name, short(r))
2244
2238
2245 repo.tag(name, r, message, opts['local'], opts['user'], opts['date'])
2239 repo.tag(name, r, message, opts['local'], opts['user'], opts['date'])
2246
2240
2247 def tags(ui, repo):
2241 def tags(ui, repo):
2248 """list repository tags
2242 """list repository tags
2249
2243
2250 List the repository tags.
2244 List the repository tags.
2251
2245
2252 This lists both regular and local tags.
2246 This lists both regular and local tags.
2253 """
2247 """
2254
2248
2255 l = repo.tagslist()
2249 l = repo.tagslist()
2256 l.reverse()
2250 l.reverse()
2257 hexfunc = ui.debugflag and hex or short
2251 hexfunc = ui.debugflag and hex or short
2258 for t, n in l:
2252 for t, n in l:
2259 try:
2253 try:
2260 r = "%5d:%s" % (repo.changelog.rev(n), hexfunc(n))
2254 r = "%5d:%s" % (repo.changelog.rev(n), hexfunc(n))
2261 except KeyError:
2255 except KeyError:
2262 r = " ?:?"
2256 r = " ?:?"
2263 if ui.quiet:
2257 if ui.quiet:
2264 ui.write("%s\n" % t)
2258 ui.write("%s\n" % t)
2265 else:
2259 else:
2266 ui.write("%-30s %s\n" % (t, r))
2260 ui.write("%-30s %s\n" % (t, r))
2267
2261
2268 def tip(ui, repo, **opts):
2262 def tip(ui, repo, **opts):
2269 """show the tip revision
2263 """show the tip revision
2270
2264
2271 Show the tip revision.
2265 Show the tip revision.
2272 """
2266 """
2273 cmdutil.show_changeset(ui, repo, opts).show(repo.changelog.count()-1)
2267 cmdutil.show_changeset(ui, repo, opts).show(repo.changelog.count()-1)
2274
2268
2275 def unbundle(ui, repo, fname, **opts):
2269 def unbundle(ui, repo, fname, **opts):
2276 """apply a changegroup file
2270 """apply a changegroup file
2277
2271
2278 Apply a compressed changegroup file generated by the bundle
2272 Apply a compressed changegroup file generated by the bundle
2279 command.
2273 command.
2280 """
2274 """
2281 f = urllib.urlopen(fname)
2275 f = urllib.urlopen(fname)
2282
2276
2283 header = f.read(6)
2277 header = f.read(6)
2284 if not header.startswith("HG"):
2278 if not header.startswith("HG"):
2285 raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
2279 raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
2286 elif not header.startswith("HG10"):
2280 elif not header.startswith("HG10"):
2287 raise util.Abort(_("%s: unknown bundle version") % fname)
2281 raise util.Abort(_("%s: unknown bundle version") % fname)
2288 elif header == "HG10BZ":
2282 elif header == "HG10BZ":
2289 def generator(f):
2283 def generator(f):
2290 zd = bz2.BZ2Decompressor()
2284 zd = bz2.BZ2Decompressor()
2291 zd.decompress("BZ")
2285 zd.decompress("BZ")
2292 for chunk in f:
2286 for chunk in f:
2293 yield zd.decompress(chunk)
2287 yield zd.decompress(chunk)
2294 elif header == "HG10UN":
2288 elif header == "HG10UN":
2295 def generator(f):
2289 def generator(f):
2296 for chunk in f:
2290 for chunk in f:
2297 yield chunk
2291 yield chunk
2298 else:
2292 else:
2299 raise util.Abort(_("%s: unknown bundle compression type")
2293 raise util.Abort(_("%s: unknown bundle compression type")
2300 % fname)
2294 % fname)
2301 gen = generator(util.filechunkiter(f, 4096))
2295 gen = generator(util.filechunkiter(f, 4096))
2302 modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle',
2296 modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle',
2303 'bundle:' + fname)
2297 'bundle:' + fname)
2304 return postincoming(ui, repo, modheads, opts['update'])
2298 return postincoming(ui, repo, modheads, opts['update'])
2305
2299
2306 def update(ui, repo, node=None, merge=False, clean=False, force=None,
2300 def update(ui, repo, node=None, merge=False, clean=False, force=None,
2307 branch=None):
2301 branch=None):
2308 """update or merge working directory
2302 """update or merge working directory
2309
2303
2310 Update the working directory to the specified revision.
2304 Update the working directory to the specified revision.
2311
2305
2312 If there are no outstanding changes in the working directory and
2306 If there are no outstanding changes in the working directory and
2313 there is a linear relationship between the current version and the
2307 there is a linear relationship between the current version and the
2314 requested version, the result is the requested version.
2308 requested version, the result is the requested version.
2315
2309
2316 To merge the working directory with another revision, use the
2310 To merge the working directory with another revision, use the
2317 merge command.
2311 merge command.
2318
2312
2319 By default, update will refuse to run if doing so would require
2313 By default, update will refuse to run if doing so would require
2320 merging or discarding local changes.
2314 merging or discarding local changes.
2321 """
2315 """
2322 node = _lookup(repo, node, branch)
2316 node = _lookup(repo, node, branch)
2323 if clean:
2317 if clean:
2324 return hg.clean(repo, node)
2318 return hg.clean(repo, node)
2325 else:
2319 else:
2326 return hg.update(repo, node)
2320 return hg.update(repo, node)
2327
2321
2328 def _lookup(repo, node, branch=None):
2322 def _lookup(repo, node, branch=None):
2329 if branch:
2323 if branch:
2330 repo.ui.warn(_("the --branch option is deprecated, "
2324 repo.ui.warn(_("the --branch option is deprecated, "
2331 "please use 'hg branch' instead\n"))
2325 "please use 'hg branch' instead\n"))
2332 br = repo.branchlookup(branch=branch)
2326 br = repo.branchlookup(branch=branch)
2333 found = []
2327 found = []
2334 for x in br:
2328 for x in br:
2335 if branch in br[x]:
2329 if branch in br[x]:
2336 found.append(x)
2330 found.append(x)
2337 if len(found) > 1:
2331 if len(found) > 1:
2338 repo.ui.warn(_("Found multiple heads for %s\n") % branch)
2332 repo.ui.warn(_("Found multiple heads for %s\n") % branch)
2339 for x in found:
2333 for x in found:
2340 cmdutil.show_changeset(ui, repo, {}).show(changenode=x)
2334 cmdutil.show_changeset(ui, repo, {}).show(changenode=x)
2341 raise util.Abort("")
2335 raise util.Abort("")
2342 if len(found) == 1:
2336 if len(found) == 1:
2343 node = found[0]
2337 node = found[0]
2344 repo.ui.warn(_("Using head %s for branch %s\n")
2338 repo.ui.warn(_("Using head %s for branch %s\n")
2345 % (short(node), branch))
2339 % (short(node), branch))
2346 else:
2340 else:
2347 raise util.Abort(_("branch %s not found") % branch)
2341 raise util.Abort(_("branch %s not found") % branch)
2348 else:
2342 else:
2349 node = node and repo.lookup(node) or repo.changelog.tip()
2343 node = node and repo.lookup(node) or repo.changelog.tip()
2350 return node
2344 return node
2351
2345
2352 def verify(ui, repo):
2346 def verify(ui, repo):
2353 """verify the integrity of the repository
2347 """verify the integrity of the repository
2354
2348
2355 Verify the integrity of the current repository.
2349 Verify the integrity of the current repository.
2356
2350
2357 This will perform an extensive check of the repository's
2351 This will perform an extensive check of the repository's
2358 integrity, validating the hashes and checksums of each entry in
2352 integrity, validating the hashes and checksums of each entry in
2359 the changelog, manifest, and tracked files, as well as the
2353 the changelog, manifest, and tracked files, as well as the
2360 integrity of their crosslinks and indices.
2354 integrity of their crosslinks and indices.
2361 """
2355 """
2362 return hg.verify(repo)
2356 return hg.verify(repo)
2363
2357
2364 def version_(ui):
2358 def version_(ui):
2365 """output version and copyright information"""
2359 """output version and copyright information"""
2366 ui.write(_("Mercurial Distributed SCM (version %s)\n")
2360 ui.write(_("Mercurial Distributed SCM (version %s)\n")
2367 % version.get_version())
2361 % version.get_version())
2368 ui.status(_(
2362 ui.status(_(
2369 "\nCopyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>\n"
2363 "\nCopyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>\n"
2370 "This is free software; see the source for copying conditions. "
2364 "This is free software; see the source for copying conditions. "
2371 "There is NO\nwarranty; "
2365 "There is NO\nwarranty; "
2372 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
2366 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
2373 ))
2367 ))
2374
2368
2375 # Command options and aliases are listed here, alphabetically
2369 # Command options and aliases are listed here, alphabetically
2376
2370
2377 globalopts = [
2371 globalopts = [
2378 ('R', 'repository', '',
2372 ('R', 'repository', '',
2379 _('repository root directory or symbolic path name')),
2373 _('repository root directory or symbolic path name')),
2380 ('', 'cwd', '', _('change working directory')),
2374 ('', 'cwd', '', _('change working directory')),
2381 ('y', 'noninteractive', None,
2375 ('y', 'noninteractive', None,
2382 _('do not prompt, assume \'yes\' for any required answers')),
2376 _('do not prompt, assume \'yes\' for any required answers')),
2383 ('q', 'quiet', None, _('suppress output')),
2377 ('q', 'quiet', None, _('suppress output')),
2384 ('v', 'verbose', None, _('enable additional output')),
2378 ('v', 'verbose', None, _('enable additional output')),
2385 ('', 'config', [], _('set/override config option')),
2379 ('', 'config', [], _('set/override config option')),
2386 ('', 'debug', None, _('enable debugging output')),
2380 ('', 'debug', None, _('enable debugging output')),
2387 ('', 'debugger', None, _('start debugger')),
2381 ('', 'debugger', None, _('start debugger')),
2388 ('', 'lsprof', None, _('print improved command execution profile')),
2382 ('', 'lsprof', None, _('print improved command execution profile')),
2389 ('', 'traceback', None, _('print traceback on exception')),
2383 ('', 'traceback', None, _('print traceback on exception')),
2390 ('', 'time', None, _('time how long the command takes')),
2384 ('', 'time', None, _('time how long the command takes')),
2391 ('', 'profile', None, _('print command execution profile')),
2385 ('', 'profile', None, _('print command execution profile')),
2392 ('', 'version', None, _('output version information and exit')),
2386 ('', 'version', None, _('output version information and exit')),
2393 ('h', 'help', None, _('display help and exit')),
2387 ('h', 'help', None, _('display help and exit')),
2394 ]
2388 ]
2395
2389
2396 dryrunopts = [('n', 'dry-run', None,
2390 dryrunopts = [('n', 'dry-run', None,
2397 _('do not perform actions, just print output'))]
2391 _('do not perform actions, just print output'))]
2398
2392
2399 remoteopts = [
2393 remoteopts = [
2400 ('e', 'ssh', '', _('specify ssh command to use')),
2394 ('e', 'ssh', '', _('specify ssh command to use')),
2401 ('', 'remotecmd', '', _('specify hg command to run on the remote side')),
2395 ('', 'remotecmd', '', _('specify hg command to run on the remote side')),
2402 ]
2396 ]
2403
2397
2404 walkopts = [
2398 walkopts = [
2405 ('I', 'include', [], _('include names matching the given patterns')),
2399 ('I', 'include', [], _('include names matching the given patterns')),
2406 ('X', 'exclude', [], _('exclude names matching the given patterns')),
2400 ('X', 'exclude', [], _('exclude names matching the given patterns')),
2407 ]
2401 ]
2408
2402
2409 table = {
2403 table = {
2410 "^add":
2404 "^add":
2411 (add,
2405 (add,
2412 walkopts + dryrunopts,
2406 walkopts + dryrunopts,
2413 _('hg add [OPTION]... [FILE]...')),
2407 _('hg add [OPTION]... [FILE]...')),
2414 "addremove":
2408 "addremove":
2415 (addremove,
2409 (addremove,
2416 [('s', 'similarity', '',
2410 [('s', 'similarity', '',
2417 _('guess renamed files by similarity (0<=s<=100)')),
2411 _('guess renamed files by similarity (0<=s<=100)')),
2418 ] + walkopts + dryrunopts,
2412 ] + walkopts + dryrunopts,
2419 _('hg addremove [OPTION]... [FILE]...')),
2413 _('hg addremove [OPTION]... [FILE]...')),
2420 "^annotate":
2414 "^annotate":
2421 (annotate,
2415 (annotate,
2422 [('r', 'rev', '', _('annotate the specified revision')),
2416 [('r', 'rev', '', _('annotate the specified revision')),
2423 ('f', 'follow', None, _('follow file copies and renames')),
2417 ('f', 'follow', None, _('follow file copies and renames')),
2424 ('a', 'text', None, _('treat all files as text')),
2418 ('a', 'text', None, _('treat all files as text')),
2425 ('u', 'user', None, _('list the author')),
2419 ('u', 'user', None, _('list the author')),
2426 ('d', 'date', None, _('list the date')),
2420 ('d', 'date', None, _('list the date')),
2427 ('n', 'number', None, _('list the revision number (default)')),
2421 ('n', 'number', None, _('list the revision number (default)')),
2428 ('c', 'changeset', None, _('list the changeset')),
2422 ('c', 'changeset', None, _('list the changeset')),
2429 ] + walkopts,
2423 ] + walkopts,
2430 _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')),
2424 _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')),
2431 "archive":
2425 "archive":
2432 (archive,
2426 (archive,
2433 [('', 'no-decode', None, _('do not pass files through decoders')),
2427 [('', 'no-decode', None, _('do not pass files through decoders')),
2434 ('p', 'prefix', '', _('directory prefix for files in archive')),
2428 ('p', 'prefix', '', _('directory prefix for files in archive')),
2435 ('r', 'rev', '', _('revision to distribute')),
2429 ('r', 'rev', '', _('revision to distribute')),
2436 ('t', 'type', '', _('type of distribution to create')),
2430 ('t', 'type', '', _('type of distribution to create')),
2437 ] + walkopts,
2431 ] + walkopts,
2438 _('hg archive [OPTION]... DEST')),
2432 _('hg archive [OPTION]... DEST')),
2439 "backout":
2433 "backout":
2440 (backout,
2434 (backout,
2441 [('', 'merge', None,
2435 [('', 'merge', None,
2442 _('merge with old dirstate parent after backout')),
2436 _('merge with old dirstate parent after backout')),
2443 ('m', 'message', '', _('use <text> as commit message')),
2437 ('m', 'message', '', _('use <text> as commit message')),
2444 ('l', 'logfile', '', _('read commit message from <file>')),
2438 ('l', 'logfile', '', _('read commit message from <file>')),
2445 ('d', 'date', '', _('record datecode as commit date')),
2439 ('d', 'date', '', _('record datecode as commit date')),
2446 ('', 'parent', '', _('parent to choose when backing out merge')),
2440 ('', 'parent', '', _('parent to choose when backing out merge')),
2447 ('u', 'user', '', _('record user as committer')),
2441 ('u', 'user', '', _('record user as committer')),
2448 ] + walkopts,
2442 ] + walkopts,
2449 _('hg backout [OPTION]... REV')),
2443 _('hg backout [OPTION]... REV')),
2450 "branch": (branch, [], _('hg branch [NAME]')),
2444 "branch": (branch, [], _('hg branch [NAME]')),
2451 "branches": (branches, [], _('hg branches')),
2445 "branches": (branches, [], _('hg branches')),
2452 "bundle":
2446 "bundle":
2453 (bundle,
2447 (bundle,
2454 [('f', 'force', None,
2448 [('f', 'force', None,
2455 _('run even when remote repository is unrelated')),
2449 _('run even when remote repository is unrelated')),
2456 ('r', 'rev', [],
2450 ('r', 'rev', [],
2457 _('a changeset you would like to bundle')),
2451 _('a changeset you would like to bundle')),
2458 ('', 'base', [],
2452 ('', 'base', [],
2459 _('a base changeset to specify instead of a destination')),
2453 _('a base changeset to specify instead of a destination')),
2460 ] + remoteopts,
2454 ] + remoteopts,
2461 _('hg bundle [--base REV]... [--rev REV]... FILE [DEST]')),
2455 _('hg bundle [--base REV]... [--rev REV]... FILE [DEST]')),
2462 "cat":
2456 "cat":
2463 (cat,
2457 (cat,
2464 [('o', 'output', '', _('print output to file with formatted name')),
2458 [('o', 'output', '', _('print output to file with formatted name')),
2465 ('r', 'rev', '', _('print the given revision')),
2459 ('r', 'rev', '', _('print the given revision')),
2466 ] + walkopts,
2460 ] + walkopts,
2467 _('hg cat [OPTION]... FILE...')),
2461 _('hg cat [OPTION]... FILE...')),
2468 "^clone":
2462 "^clone":
2469 (clone,
2463 (clone,
2470 [('U', 'noupdate', None, _('do not update the new working directory')),
2464 [('U', 'noupdate', None, _('do not update the new working directory')),
2471 ('r', 'rev', [],
2465 ('r', 'rev', [],
2472 _('a changeset you would like to have after cloning')),
2466 _('a changeset you would like to have after cloning')),
2473 ('', 'pull', None, _('use pull protocol to copy metadata')),
2467 ('', 'pull', None, _('use pull protocol to copy metadata')),
2474 ('', 'uncompressed', None,
2468 ('', 'uncompressed', None,
2475 _('use uncompressed transfer (fast over LAN)')),
2469 _('use uncompressed transfer (fast over LAN)')),
2476 ] + remoteopts,
2470 ] + remoteopts,
2477 _('hg clone [OPTION]... SOURCE [DEST]')),
2471 _('hg clone [OPTION]... SOURCE [DEST]')),
2478 "^commit|ci":
2472 "^commit|ci":
2479 (commit,
2473 (commit,
2480 [('A', 'addremove', None,
2474 [('A', 'addremove', None,
2481 _('mark new/missing files as added/removed before committing')),
2475 _('mark new/missing files as added/removed before committing')),
2482 ('m', 'message', '', _('use <text> as commit message')),
2476 ('m', 'message', '', _('use <text> as commit message')),
2483 ('l', 'logfile', '', _('read the commit message from <file>')),
2477 ('l', 'logfile', '', _('read the commit message from <file>')),
2484 ('d', 'date', '', _('record datecode as commit date')),
2478 ('d', 'date', '', _('record datecode as commit date')),
2485 ('u', 'user', '', _('record user as commiter')),
2479 ('u', 'user', '', _('record user as commiter')),
2486 ] + walkopts,
2480 ] + walkopts,
2487 _('hg commit [OPTION]... [FILE]...')),
2481 _('hg commit [OPTION]... [FILE]...')),
2488 "copy|cp":
2482 "copy|cp":
2489 (copy,
2483 (copy,
2490 [('A', 'after', None, _('record a copy that has already occurred')),
2484 [('A', 'after', None, _('record a copy that has already occurred')),
2491 ('f', 'force', None,
2485 ('f', 'force', None,
2492 _('forcibly copy over an existing managed file')),
2486 _('forcibly copy over an existing managed file')),
2493 ] + walkopts + dryrunopts,
2487 ] + walkopts + dryrunopts,
2494 _('hg copy [OPTION]... [SOURCE]... DEST')),
2488 _('hg copy [OPTION]... [SOURCE]... DEST')),
2495 "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
2489 "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')),
2496 "debugcomplete":
2490 "debugcomplete":
2497 (debugcomplete,
2491 (debugcomplete,
2498 [('o', 'options', None, _('show the command options'))],
2492 [('o', 'options', None, _('show the command options'))],
2499 _('debugcomplete [-o] CMD')),
2493 _('debugcomplete [-o] CMD')),
2500 "debugrebuildstate":
2494 "debugrebuildstate":
2501 (debugrebuildstate,
2495 (debugrebuildstate,
2502 [('r', 'rev', '', _('revision to rebuild to'))],
2496 [('r', 'rev', '', _('revision to rebuild to'))],
2503 _('debugrebuildstate [-r REV] [REV]')),
2497 _('debugrebuildstate [-r REV] [REV]')),
2504 "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
2498 "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')),
2505 "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')),
2499 "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')),
2506 "debugstate": (debugstate, [], _('debugstate')),
2500 "debugstate": (debugstate, [], _('debugstate')),
2507 "debugdata": (debugdata, [], _('debugdata FILE REV')),
2501 "debugdata": (debugdata, [], _('debugdata FILE REV')),
2508 "debugindex": (debugindex, [], _('debugindex FILE')),
2502 "debugindex": (debugindex, [], _('debugindex FILE')),
2509 "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')),
2503 "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')),
2510 "debugrename": (debugrename, [], _('debugrename FILE [REV]')),
2504 "debugrename": (debugrename, [], _('debugrename FILE [REV]')),
2511 "debugwalk":
2505 "debugwalk":
2512 (debugwalk, walkopts, _('debugwalk [OPTION]... [FILE]...')),
2506 (debugwalk, walkopts, _('debugwalk [OPTION]... [FILE]...')),
2513 "^diff":
2507 "^diff":
2514 (diff,
2508 (diff,
2515 [('r', 'rev', [], _('revision')),
2509 [('r', 'rev', [], _('revision')),
2516 ('a', 'text', None, _('treat all files as text')),
2510 ('a', 'text', None, _('treat all files as text')),
2517 ('p', 'show-function', None,
2511 ('p', 'show-function', None,
2518 _('show which function each change is in')),
2512 _('show which function each change is in')),
2519 ('g', 'git', None, _('use git extended diff format')),
2513 ('g', 'git', None, _('use git extended diff format')),
2520 ('', 'nodates', None, _("don't include dates in diff headers")),
2514 ('', 'nodates', None, _("don't include dates in diff headers")),
2521 ('w', 'ignore-all-space', None,
2515 ('w', 'ignore-all-space', None,
2522 _('ignore white space when comparing lines')),
2516 _('ignore white space when comparing lines')),
2523 ('b', 'ignore-space-change', None,
2517 ('b', 'ignore-space-change', None,
2524 _('ignore changes in the amount of white space')),
2518 _('ignore changes in the amount of white space')),
2525 ('B', 'ignore-blank-lines', None,
2519 ('B', 'ignore-blank-lines', None,
2526 _('ignore changes whose lines are all blank')),
2520 _('ignore changes whose lines are all blank')),
2527 ] + walkopts,
2521 ] + walkopts,
2528 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
2522 _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')),
2529 "^export":
2523 "^export":
2530 (export,
2524 (export,
2531 [('o', 'output', '', _('print output to file with formatted name')),
2525 [('o', 'output', '', _('print output to file with formatted name')),
2532 ('a', 'text', None, _('treat all files as text')),
2526 ('a', 'text', None, _('treat all files as text')),
2533 ('g', 'git', None, _('use git extended diff format')),
2527 ('g', 'git', None, _('use git extended diff format')),
2534 ('', 'nodates', None, _("don't include dates in diff headers")),
2528 ('', 'nodates', None, _("don't include dates in diff headers")),
2535 ('', 'switch-parent', None, _('diff against the second parent'))],
2529 ('', 'switch-parent', None, _('diff against the second parent'))],
2536 _('hg export [-a] [-o OUTFILESPEC] REV...')),
2530 _('hg export [-a] [-o OUTFILESPEC] REV...')),
2537 "grep":
2531 "grep":
2538 (grep,
2532 (grep,
2539 [('0', 'print0', None, _('end fields with NUL')),
2533 [('0', 'print0', None, _('end fields with NUL')),
2540 ('', 'all', None, _('print all revisions that match')),
2534 ('', 'all', None, _('print all revisions that match')),
2541 ('f', 'follow', None,
2535 ('f', 'follow', None,
2542 _('follow changeset history, or file history across copies and renames')),
2536 _('follow changeset history, or file history across copies and renames')),
2543 ('i', 'ignore-case', None, _('ignore case when matching')),
2537 ('i', 'ignore-case', None, _('ignore case when matching')),
2544 ('l', 'files-with-matches', None,
2538 ('l', 'files-with-matches', None,
2545 _('print only filenames and revs that match')),
2539 _('print only filenames and revs that match')),
2546 ('n', 'line-number', None, _('print matching line numbers')),
2540 ('n', 'line-number', None, _('print matching line numbers')),
2547 ('r', 'rev', [], _('search in given revision range')),
2541 ('r', 'rev', [], _('search in given revision range')),
2548 ('u', 'user', None, _('print user who committed change')),
2542 ('u', 'user', None, _('print user who committed change')),
2549 ] + walkopts,
2543 ] + walkopts,
2550 _('hg grep [OPTION]... PATTERN [FILE]...')),
2544 _('hg grep [OPTION]... PATTERN [FILE]...')),
2551 "heads":
2545 "heads":
2552 (heads,
2546 (heads,
2553 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2547 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2554 ('', 'style', '', _('display using template map file')),
2548 ('', 'style', '', _('display using template map file')),
2555 ('r', 'rev', '', _('show only heads which are descendants of rev')),
2549 ('r', 'rev', '', _('show only heads which are descendants of rev')),
2556 ('', 'template', '', _('display with template'))],
2550 ('', 'template', '', _('display with template'))],
2557 _('hg heads [-r REV]')),
2551 _('hg heads [-r REV]')),
2558 "help": (help_, [], _('hg help [COMMAND]')),
2552 "help": (help_, [], _('hg help [COMMAND]')),
2559 "identify|id": (identify, [], _('hg identify')),
2553 "identify|id": (identify, [], _('hg identify')),
2560 "import|patch":
2554 "import|patch":
2561 (import_,
2555 (import_,
2562 [('p', 'strip', 1,
2556 [('p', 'strip', 1,
2563 _('directory strip option for patch. This has the same\n'
2557 _('directory strip option for patch. This has the same\n'
2564 'meaning as the corresponding patch option')),
2558 'meaning as the corresponding patch option')),
2565 ('m', 'message', '', _('use <text> as commit message')),
2559 ('m', 'message', '', _('use <text> as commit message')),
2566 ('b', 'base', '', _('base path (DEPRECATED)')),
2560 ('b', 'base', '', _('base path (DEPRECATED)')),
2567 ('f', 'force', None,
2561 ('f', 'force', None,
2568 _('skip check for outstanding uncommitted changes'))],
2562 _('skip check for outstanding uncommitted changes'))],
2569 _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')),
2563 _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')),
2570 "incoming|in": (incoming,
2564 "incoming|in": (incoming,
2571 [('M', 'no-merges', None, _('do not show merges')),
2565 [('M', 'no-merges', None, _('do not show merges')),
2572 ('f', 'force', None,
2566 ('f', 'force', None,
2573 _('run even when remote repository is unrelated')),
2567 _('run even when remote repository is unrelated')),
2574 ('', 'style', '', _('display using template map file')),
2568 ('', 'style', '', _('display using template map file')),
2575 ('n', 'newest-first', None, _('show newest record first')),
2569 ('n', 'newest-first', None, _('show newest record first')),
2576 ('', 'bundle', '', _('file to store the bundles into')),
2570 ('', 'bundle', '', _('file to store the bundles into')),
2577 ('p', 'patch', None, _('show patch')),
2571 ('p', 'patch', None, _('show patch')),
2578 ('r', 'rev', [], _('a specific revision up to which you would like to pull')),
2572 ('r', 'rev', [], _('a specific revision up to which you would like to pull')),
2579 ('', 'template', '', _('display with template')),
2573 ('', 'template', '', _('display with template')),
2580 ] + remoteopts,
2574 ] + remoteopts,
2581 _('hg incoming [-p] [-n] [-M] [-r REV]...'
2575 _('hg incoming [-p] [-n] [-M] [-r REV]...'
2582 ' [--bundle FILENAME] [SOURCE]')),
2576 ' [--bundle FILENAME] [SOURCE]')),
2583 "^init":
2577 "^init":
2584 (init, remoteopts, _('hg init [-e FILE] [--remotecmd FILE] [DEST]')),
2578 (init, remoteopts, _('hg init [-e FILE] [--remotecmd FILE] [DEST]')),
2585 "locate":
2579 "locate":
2586 (locate,
2580 (locate,
2587 [('r', 'rev', '', _('search the repository as it stood at rev')),
2581 [('r', 'rev', '', _('search the repository as it stood at rev')),
2588 ('0', 'print0', None,
2582 ('0', 'print0', None,
2589 _('end filenames with NUL, for use with xargs')),
2583 _('end filenames with NUL, for use with xargs')),
2590 ('f', 'fullpath', None,
2584 ('f', 'fullpath', None,
2591 _('print complete paths from the filesystem root')),
2585 _('print complete paths from the filesystem root')),
2592 ] + walkopts,
2586 ] + walkopts,
2593 _('hg locate [OPTION]... [PATTERN]...')),
2587 _('hg locate [OPTION]... [PATTERN]...')),
2594 "^log|history":
2588 "^log|history":
2595 (log,
2589 (log,
2596 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2590 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2597 ('f', 'follow', None,
2591 ('f', 'follow', None,
2598 _('follow changeset history, or file history across copies and renames')),
2592 _('follow changeset history, or file history across copies and renames')),
2599 ('', 'follow-first', None,
2593 ('', 'follow-first', None,
2600 _('only follow the first parent of merge changesets')),
2594 _('only follow the first parent of merge changesets')),
2601 ('C', 'copies', None, _('show copied files')),
2595 ('C', 'copies', None, _('show copied files')),
2602 ('k', 'keyword', [], _('search for a keyword')),
2596 ('k', 'keyword', [], _('search for a keyword')),
2603 ('l', 'limit', '', _('limit number of changes displayed')),
2597 ('l', 'limit', '', _('limit number of changes displayed')),
2604 ('r', 'rev', [], _('show the specified revision or range')),
2598 ('r', 'rev', [], _('show the specified revision or range')),
2605 ('M', 'no-merges', None, _('do not show merges')),
2599 ('M', 'no-merges', None, _('do not show merges')),
2606 ('', 'style', '', _('display using template map file')),
2600 ('', 'style', '', _('display using template map file')),
2607 ('m', 'only-merges', None, _('show only merges')),
2601 ('m', 'only-merges', None, _('show only merges')),
2608 ('p', 'patch', None, _('show patch')),
2602 ('p', 'patch', None, _('show patch')),
2609 ('P', 'prune', [], _('do not display revision or any of its ancestors')),
2603 ('P', 'prune', [], _('do not display revision or any of its ancestors')),
2610 ('', 'template', '', _('display with template')),
2604 ('', 'template', '', _('display with template')),
2611 ] + walkopts,
2605 ] + walkopts,
2612 _('hg log [OPTION]... [FILE]')),
2606 _('hg log [OPTION]... [FILE]')),
2613 "manifest": (manifest, [], _('hg manifest [REV]')),
2607 "manifest": (manifest, [], _('hg manifest [REV]')),
2614 "merge":
2608 "merge":
2615 (merge,
2609 (merge,
2616 [('b', 'branch', '', _('merge with head of a specific branch (DEPRECATED)')),
2610 [('b', 'branch', '', _('merge with head of a specific branch (DEPRECATED)')),
2617 ('f', 'force', None, _('force a merge with outstanding changes'))],
2611 ('f', 'force', None, _('force a merge with outstanding changes'))],
2618 _('hg merge [-f] [REV]')),
2612 _('hg merge [-f] [REV]')),
2619 "outgoing|out": (outgoing,
2613 "outgoing|out": (outgoing,
2620 [('M', 'no-merges', None, _('do not show merges')),
2614 [('M', 'no-merges', None, _('do not show merges')),
2621 ('f', 'force', None,
2615 ('f', 'force', None,
2622 _('run even when remote repository is unrelated')),
2616 _('run even when remote repository is unrelated')),
2623 ('p', 'patch', None, _('show patch')),
2617 ('p', 'patch', None, _('show patch')),
2624 ('', 'style', '', _('display using template map file')),
2618 ('', 'style', '', _('display using template map file')),
2625 ('r', 'rev', [], _('a specific revision you would like to push')),
2619 ('r', 'rev', [], _('a specific revision you would like to push')),
2626 ('n', 'newest-first', None, _('show newest record first')),
2620 ('n', 'newest-first', None, _('show newest record first')),
2627 ('', 'template', '', _('display with template')),
2621 ('', 'template', '', _('display with template')),
2628 ] + remoteopts,
2622 ] + remoteopts,
2629 _('hg outgoing [-M] [-p] [-n] [-r REV]... [DEST]')),
2623 _('hg outgoing [-M] [-p] [-n] [-r REV]... [DEST]')),
2630 "^parents":
2624 "^parents":
2631 (parents,
2625 (parents,
2632 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2626 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2633 ('r', 'rev', '', _('show parents from the specified rev')),
2627 ('r', 'rev', '', _('show parents from the specified rev')),
2634 ('', 'style', '', _('display using template map file')),
2628 ('', 'style', '', _('display using template map file')),
2635 ('', 'template', '', _('display with template'))],
2629 ('', 'template', '', _('display with template'))],
2636 _('hg parents [-r REV] [FILE]')),
2630 _('hg parents [-r REV] [FILE]')),
2637 "paths": (paths, [], _('hg paths [NAME]')),
2631 "paths": (paths, [], _('hg paths [NAME]')),
2638 "^pull":
2632 "^pull":
2639 (pull,
2633 (pull,
2640 [('u', 'update', None,
2634 [('u', 'update', None,
2641 _('update to new tip if changesets were pulled')),
2635 _('update to new tip if changesets were pulled')),
2642 ('f', 'force', None,
2636 ('f', 'force', None,
2643 _('run even when remote repository is unrelated')),
2637 _('run even when remote repository is unrelated')),
2644 ('r', 'rev', [], _('a specific revision up to which you would like to pull')),
2638 ('r', 'rev', [], _('a specific revision up to which you would like to pull')),
2645 ] + remoteopts,
2639 ] + remoteopts,
2646 _('hg pull [-u] [-r REV]... [-e FILE] [--remotecmd FILE] [SOURCE]')),
2640 _('hg pull [-u] [-r REV]... [-e FILE] [--remotecmd FILE] [SOURCE]')),
2647 "^push":
2641 "^push":
2648 (push,
2642 (push,
2649 [('f', 'force', None, _('force push')),
2643 [('f', 'force', None, _('force push')),
2650 ('r', 'rev', [], _('a specific revision you would like to push')),
2644 ('r', 'rev', [], _('a specific revision you would like to push')),
2651 ] + remoteopts,
2645 ] + remoteopts,
2652 _('hg push [-f] [-r REV]... [-e FILE] [--remotecmd FILE] [DEST]')),
2646 _('hg push [-f] [-r REV]... [-e FILE] [--remotecmd FILE] [DEST]')),
2653 "debugrawcommit|rawcommit":
2647 "debugrawcommit|rawcommit":
2654 (rawcommit,
2648 (rawcommit,
2655 [('p', 'parent', [], _('parent')),
2649 [('p', 'parent', [], _('parent')),
2656 ('d', 'date', '', _('date code')),
2650 ('d', 'date', '', _('date code')),
2657 ('u', 'user', '', _('user')),
2651 ('u', 'user', '', _('user')),
2658 ('F', 'files', '', _('file list')),
2652 ('F', 'files', '', _('file list')),
2659 ('m', 'message', '', _('commit message')),
2653 ('m', 'message', '', _('commit message')),
2660 ('l', 'logfile', '', _('commit message file'))],
2654 ('l', 'logfile', '', _('commit message file'))],
2661 _('hg debugrawcommit [OPTION]... [FILE]...')),
2655 _('hg debugrawcommit [OPTION]... [FILE]...')),
2662 "recover": (recover, [], _('hg recover')),
2656 "recover": (recover, [], _('hg recover')),
2663 "^remove|rm":
2657 "^remove|rm":
2664 (remove,
2658 (remove,
2665 [('A', 'after', None, _('record remove that has already occurred')),
2659 [('A', 'after', None, _('record remove that has already occurred')),
2666 ('f', 'force', None, _('remove file even if modified')),
2660 ('f', 'force', None, _('remove file even if modified')),
2667 ] + walkopts,
2661 ] + walkopts,
2668 _('hg remove [OPTION]... FILE...')),
2662 _('hg remove [OPTION]... FILE...')),
2669 "rename|mv":
2663 "rename|mv":
2670 (rename,
2664 (rename,
2671 [('A', 'after', None, _('record a rename that has already occurred')),
2665 [('A', 'after', None, _('record a rename that has already occurred')),
2672 ('f', 'force', None,
2666 ('f', 'force', None,
2673 _('forcibly copy over an existing managed file')),
2667 _('forcibly copy over an existing managed file')),
2674 ] + walkopts + dryrunopts,
2668 ] + walkopts + dryrunopts,
2675 _('hg rename [OPTION]... SOURCE... DEST')),
2669 _('hg rename [OPTION]... SOURCE... DEST')),
2676 "^revert":
2670 "^revert":
2677 (revert,
2671 (revert,
2678 [('a', 'all', None, _('revert all changes when no arguments given')),
2672 [('a', 'all', None, _('revert all changes when no arguments given')),
2679 ('r', 'rev', '', _('revision to revert to')),
2673 ('r', 'rev', '', _('revision to revert to')),
2680 ('', 'no-backup', None, _('do not save backup copies of files')),
2674 ('', 'no-backup', None, _('do not save backup copies of files')),
2681 ] + walkopts + dryrunopts,
2675 ] + walkopts + dryrunopts,
2682 _('hg revert [-r REV] [NAME]...')),
2676 _('hg revert [-r REV] [NAME]...')),
2683 "rollback": (rollback, [], _('hg rollback')),
2677 "rollback": (rollback, [], _('hg rollback')),
2684 "root": (root, [], _('hg root')),
2678 "root": (root, [], _('hg root')),
2685 "showconfig|debugconfig":
2679 "showconfig|debugconfig":
2686 (showconfig,
2680 (showconfig,
2687 [('u', 'untrusted', None, _('show untrusted configuration options'))],
2681 [('u', 'untrusted', None, _('show untrusted configuration options'))],
2688 _('showconfig [-u] [NAME]...')),
2682 _('showconfig [-u] [NAME]...')),
2689 "^serve":
2683 "^serve":
2690 (serve,
2684 (serve,
2691 [('A', 'accesslog', '', _('name of access log file to write to')),
2685 [('A', 'accesslog', '', _('name of access log file to write to')),
2692 ('d', 'daemon', None, _('run server in background')),
2686 ('d', 'daemon', None, _('run server in background')),
2693 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
2687 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
2694 ('E', 'errorlog', '', _('name of error log file to write to')),
2688 ('E', 'errorlog', '', _('name of error log file to write to')),
2695 ('p', 'port', 0, _('port to use (default: 8000)')),
2689 ('p', 'port', 0, _('port to use (default: 8000)')),
2696 ('a', 'address', '', _('address to use')),
2690 ('a', 'address', '', _('address to use')),
2697 ('n', 'name', '',
2691 ('n', 'name', '',
2698 _('name to show in web pages (default: working dir)')),
2692 _('name to show in web pages (default: working dir)')),
2699 ('', 'webdir-conf', '', _('name of the webdir config file'
2693 ('', 'webdir-conf', '', _('name of the webdir config file'
2700 ' (serve more than one repo)')),
2694 ' (serve more than one repo)')),
2701 ('', 'pid-file', '', _('name of file to write process ID to')),
2695 ('', 'pid-file', '', _('name of file to write process ID to')),
2702 ('', 'stdio', None, _('for remote clients')),
2696 ('', 'stdio', None, _('for remote clients')),
2703 ('t', 'templates', '', _('web templates to use')),
2697 ('t', 'templates', '', _('web templates to use')),
2704 ('', 'style', '', _('template style to use')),
2698 ('', 'style', '', _('template style to use')),
2705 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))],
2699 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))],
2706 _('hg serve [OPTION]...')),
2700 _('hg serve [OPTION]...')),
2707 "^status|st":
2701 "^status|st":
2708 (status,
2702 (status,
2709 [('A', 'all', None, _('show status of all files')),
2703 [('A', 'all', None, _('show status of all files')),
2710 ('m', 'modified', None, _('show only modified files')),
2704 ('m', 'modified', None, _('show only modified files')),
2711 ('a', 'added', None, _('show only added files')),
2705 ('a', 'added', None, _('show only added files')),
2712 ('r', 'removed', None, _('show only removed files')),
2706 ('r', 'removed', None, _('show only removed files')),
2713 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
2707 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
2714 ('c', 'clean', None, _('show only files without changes')),
2708 ('c', 'clean', None, _('show only files without changes')),
2715 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
2709 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
2716 ('i', 'ignored', None, _('show ignored files')),
2710 ('i', 'ignored', None, _('show ignored files')),
2717 ('n', 'no-status', None, _('hide status prefix')),
2711 ('n', 'no-status', None, _('hide status prefix')),
2718 ('C', 'copies', None, _('show source of copied files')),
2712 ('C', 'copies', None, _('show source of copied files')),
2719 ('0', 'print0', None,
2713 ('0', 'print0', None,
2720 _('end filenames with NUL, for use with xargs')),
2714 _('end filenames with NUL, for use with xargs')),
2721 ('', 'rev', [], _('show difference from revision')),
2715 ('', 'rev', [], _('show difference from revision')),
2722 ] + walkopts,
2716 ] + walkopts,
2723 _('hg status [OPTION]... [FILE]...')),
2717 _('hg status [OPTION]... [FILE]...')),
2724 "tag":
2718 "tag":
2725 (tag,
2719 (tag,
2726 [('l', 'local', None, _('make the tag local')),
2720 [('l', 'local', None, _('make the tag local')),
2727 ('m', 'message', '', _('message for tag commit log entry')),
2721 ('m', 'message', '', _('message for tag commit log entry')),
2728 ('d', 'date', '', _('record datecode as commit date')),
2722 ('d', 'date', '', _('record datecode as commit date')),
2729 ('u', 'user', '', _('record user as commiter')),
2723 ('u', 'user', '', _('record user as commiter')),
2730 ('r', 'rev', '', _('revision to tag'))],
2724 ('r', 'rev', '', _('revision to tag'))],
2731 _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')),
2725 _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')),
2732 "tags": (tags, [], _('hg tags')),
2726 "tags": (tags, [], _('hg tags')),
2733 "tip":
2727 "tip":
2734 (tip,
2728 (tip,
2735 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2729 [('b', 'branches', None, _('show branches (DEPRECATED)')),
2736 ('', 'style', '', _('display using template map file')),
2730 ('', 'style', '', _('display using template map file')),
2737 ('p', 'patch', None, _('show patch')),
2731 ('p', 'patch', None, _('show patch')),
2738 ('', 'template', '', _('display with template'))],
2732 ('', 'template', '', _('display with template'))],
2739 _('hg tip [-p]')),
2733 _('hg tip [-p]')),
2740 "unbundle":
2734 "unbundle":
2741 (unbundle,
2735 (unbundle,
2742 [('u', 'update', None,
2736 [('u', 'update', None,
2743 _('update to new tip if changesets were unbundled'))],
2737 _('update to new tip if changesets were unbundled'))],
2744 _('hg unbundle [-u] FILE')),
2738 _('hg unbundle [-u] FILE')),
2745 "^update|up|checkout|co":
2739 "^update|up|checkout|co":
2746 (update,
2740 (update,
2747 [('b', 'branch', '',
2741 [('b', 'branch', '',
2748 _('checkout the head of a specific branch (DEPRECATED)')),
2742 _('checkout the head of a specific branch (DEPRECATED)')),
2749 ('m', 'merge', None, _('allow merging of branches (DEPRECATED)')),
2743 ('m', 'merge', None, _('allow merging of branches (DEPRECATED)')),
2750 ('C', 'clean', None, _('overwrite locally modified files')),
2744 ('C', 'clean', None, _('overwrite locally modified files')),
2751 ('f', 'force', None, _('force a merge with outstanding changes'))],
2745 ('f', 'force', None, _('force a merge with outstanding changes'))],
2752 _('hg update [-C] [-f] [REV]')),
2746 _('hg update [-C] [-f] [REV]')),
2753 "verify": (verify, [], _('hg verify')),
2747 "verify": (verify, [], _('hg verify')),
2754 "version": (version_, [], _('hg version')),
2748 "version": (version_, [], _('hg version')),
2755 }
2749 }
2756
2750
2757 norepo = ("clone init version help debugancestor debugcomplete debugdata"
2751 norepo = ("clone init version help debugancestor debugcomplete debugdata"
2758 " debugindex debugindexdot")
2752 " debugindex debugindexdot")
2759 optionalrepo = ("paths serve showconfig")
2753 optionalrepo = ("paths serve showconfig")
2760
2754
2761 def findpossible(ui, cmd):
2755 def findpossible(ui, cmd):
2762 """
2756 """
2763 Return cmd -> (aliases, command table entry)
2757 Return cmd -> (aliases, command table entry)
2764 for each matching command.
2758 for each matching command.
2765 Return debug commands (or their aliases) only if no normal command matches.
2759 Return debug commands (or their aliases) only if no normal command matches.
2766 """
2760 """
2767 choice = {}
2761 choice = {}
2768 debugchoice = {}
2762 debugchoice = {}
2769 for e in table.keys():
2763 for e in table.keys():
2770 aliases = e.lstrip("^").split("|")
2764 aliases = e.lstrip("^").split("|")
2771 found = None
2765 found = None
2772 if cmd in aliases:
2766 if cmd in aliases:
2773 found = cmd
2767 found = cmd
2774 elif not ui.config("ui", "strict"):
2768 elif not ui.config("ui", "strict"):
2775 for a in aliases:
2769 for a in aliases:
2776 if a.startswith(cmd):
2770 if a.startswith(cmd):
2777 found = a
2771 found = a
2778 break
2772 break
2779 if found is not None:
2773 if found is not None:
2780 if aliases[0].startswith("debug") or found.startswith("debug"):
2774 if aliases[0].startswith("debug") or found.startswith("debug"):
2781 debugchoice[found] = (aliases, table[e])
2775 debugchoice[found] = (aliases, table[e])
2782 else:
2776 else:
2783 choice[found] = (aliases, table[e])
2777 choice[found] = (aliases, table[e])
2784
2778
2785 if not choice and debugchoice:
2779 if not choice and debugchoice:
2786 choice = debugchoice
2780 choice = debugchoice
2787
2781
2788 return choice
2782 return choice
2789
2783
2790 def findcmd(ui, cmd):
2784 def findcmd(ui, cmd):
2791 """Return (aliases, command table entry) for command string."""
2785 """Return (aliases, command table entry) for command string."""
2792 choice = findpossible(ui, cmd)
2786 choice = findpossible(ui, cmd)
2793
2787
2794 if choice.has_key(cmd):
2788 if choice.has_key(cmd):
2795 return choice[cmd]
2789 return choice[cmd]
2796
2790
2797 if len(choice) > 1:
2791 if len(choice) > 1:
2798 clist = choice.keys()
2792 clist = choice.keys()
2799 clist.sort()
2793 clist.sort()
2800 raise AmbiguousCommand(cmd, clist)
2794 raise AmbiguousCommand(cmd, clist)
2801
2795
2802 if choice:
2796 if choice:
2803 return choice.values()[0]
2797 return choice.values()[0]
2804
2798
2805 raise UnknownCommand(cmd)
2799 raise UnknownCommand(cmd)
2806
2800
2807 def catchterm(*args):
2801 def catchterm(*args):
2808 raise util.SignalInterrupt
2802 raise util.SignalInterrupt
2809
2803
2810 def run():
2804 def run():
2811 sys.exit(dispatch(sys.argv[1:]))
2805 sys.exit(dispatch(sys.argv[1:]))
2812
2806
2813 class ParseError(Exception):
2807 class ParseError(Exception):
2814 """Exception raised on errors in parsing the command line."""
2808 """Exception raised on errors in parsing the command line."""
2815
2809
2816 def parse(ui, args):
2810 def parse(ui, args):
2817 options = {}
2811 options = {}
2818 cmdoptions = {}
2812 cmdoptions = {}
2819
2813
2820 try:
2814 try:
2821 args = fancyopts.fancyopts(args, globalopts, options)
2815 args = fancyopts.fancyopts(args, globalopts, options)
2822 except fancyopts.getopt.GetoptError, inst:
2816 except fancyopts.getopt.GetoptError, inst:
2823 raise ParseError(None, inst)
2817 raise ParseError(None, inst)
2824
2818
2825 if args:
2819 if args:
2826 cmd, args = args[0], args[1:]
2820 cmd, args = args[0], args[1:]
2827 aliases, i = findcmd(ui, cmd)
2821 aliases, i = findcmd(ui, cmd)
2828 cmd = aliases[0]
2822 cmd = aliases[0]
2829 defaults = ui.config("defaults", cmd)
2823 defaults = ui.config("defaults", cmd)
2830 if defaults:
2824 if defaults:
2831 args = shlex.split(defaults) + args
2825 args = shlex.split(defaults) + args
2832 c = list(i[1])
2826 c = list(i[1])
2833 else:
2827 else:
2834 cmd = None
2828 cmd = None
2835 c = []
2829 c = []
2836
2830
2837 # combine global options into local
2831 # combine global options into local
2838 for o in globalopts:
2832 for o in globalopts:
2839 c.append((o[0], o[1], options[o[1]], o[3]))
2833 c.append((o[0], o[1], options[o[1]], o[3]))
2840
2834
2841 try:
2835 try:
2842 args = fancyopts.fancyopts(args, c, cmdoptions)
2836 args = fancyopts.fancyopts(args, c, cmdoptions)
2843 except fancyopts.getopt.GetoptError, inst:
2837 except fancyopts.getopt.GetoptError, inst:
2844 raise ParseError(cmd, inst)
2838 raise ParseError(cmd, inst)
2845
2839
2846 # separate global options back out
2840 # separate global options back out
2847 for o in globalopts:
2841 for o in globalopts:
2848 n = o[1]
2842 n = o[1]
2849 options[n] = cmdoptions[n]
2843 options[n] = cmdoptions[n]
2850 del cmdoptions[n]
2844 del cmdoptions[n]
2851
2845
2852 return (cmd, cmd and i[0] or None, args, options, cmdoptions)
2846 return (cmd, cmd and i[0] or None, args, options, cmdoptions)
2853
2847
2854 external = {}
2848 external = {}
2855
2849
2856 def findext(name):
2850 def findext(name):
2857 '''return module with given extension name'''
2851 '''return module with given extension name'''
2858 try:
2852 try:
2859 return sys.modules[external[name]]
2853 return sys.modules[external[name]]
2860 except KeyError:
2854 except KeyError:
2861 for k, v in external.iteritems():
2855 for k, v in external.iteritems():
2862 if k.endswith('.' + name) or k.endswith('/' + name) or v == name:
2856 if k.endswith('.' + name) or k.endswith('/' + name) or v == name:
2863 return sys.modules[v]
2857 return sys.modules[v]
2864 raise KeyError(name)
2858 raise KeyError(name)
2865
2859
2866 def load_extensions(ui):
2860 def load_extensions(ui):
2867 added = []
2861 added = []
2868 for ext_name, load_from_name in ui.extensions():
2862 for ext_name, load_from_name in ui.extensions():
2869 if ext_name in external:
2863 if ext_name in external:
2870 continue
2864 continue
2871 try:
2865 try:
2872 if load_from_name:
2866 if load_from_name:
2873 # the module will be loaded in sys.modules
2867 # the module will be loaded in sys.modules
2874 # choose an unique name so that it doesn't
2868 # choose an unique name so that it doesn't
2875 # conflicts with other modules
2869 # conflicts with other modules
2876 module_name = "hgext_%s" % ext_name.replace('.', '_')
2870 module_name = "hgext_%s" % ext_name.replace('.', '_')
2877 mod = imp.load_source(module_name, load_from_name)
2871 mod = imp.load_source(module_name, load_from_name)
2878 else:
2872 else:
2879 def importh(name):
2873 def importh(name):
2880 mod = __import__(name)
2874 mod = __import__(name)
2881 components = name.split('.')
2875 components = name.split('.')
2882 for comp in components[1:]:
2876 for comp in components[1:]:
2883 mod = getattr(mod, comp)
2877 mod = getattr(mod, comp)
2884 return mod
2878 return mod
2885 try:
2879 try:
2886 mod = importh("hgext.%s" % ext_name)
2880 mod = importh("hgext.%s" % ext_name)
2887 except ImportError:
2881 except ImportError:
2888 mod = importh(ext_name)
2882 mod = importh(ext_name)
2889 external[ext_name] = mod.__name__
2883 external[ext_name] = mod.__name__
2890 added.append((mod, ext_name))
2884 added.append((mod, ext_name))
2891 except (util.SignalInterrupt, KeyboardInterrupt):
2885 except (util.SignalInterrupt, KeyboardInterrupt):
2892 raise
2886 raise
2893 except Exception, inst:
2887 except Exception, inst:
2894 ui.warn(_("*** failed to import extension %s: %s\n") %
2888 ui.warn(_("*** failed to import extension %s: %s\n") %
2895 (ext_name, inst))
2889 (ext_name, inst))
2896 if ui.print_exc():
2890 if ui.print_exc():
2897 return 1
2891 return 1
2898
2892
2899 for mod, name in added:
2893 for mod, name in added:
2900 uisetup = getattr(mod, 'uisetup', None)
2894 uisetup = getattr(mod, 'uisetup', None)
2901 if uisetup:
2895 if uisetup:
2902 uisetup(ui)
2896 uisetup(ui)
2903 cmdtable = getattr(mod, 'cmdtable', {})
2897 cmdtable = getattr(mod, 'cmdtable', {})
2904 for t in cmdtable:
2898 for t in cmdtable:
2905 if t in table:
2899 if t in table:
2906 ui.warn(_("module %s overrides %s\n") % (name, t))
2900 ui.warn(_("module %s overrides %s\n") % (name, t))
2907 table.update(cmdtable)
2901 table.update(cmdtable)
2908
2902
2909 def parseconfig(config):
2903 def parseconfig(config):
2910 """parse the --config options from the command line"""
2904 """parse the --config options from the command line"""
2911 parsed = []
2905 parsed = []
2912 for cfg in config:
2906 for cfg in config:
2913 try:
2907 try:
2914 name, value = cfg.split('=', 1)
2908 name, value = cfg.split('=', 1)
2915 section, name = name.split('.', 1)
2909 section, name = name.split('.', 1)
2916 if not section or not name:
2910 if not section or not name:
2917 raise IndexError
2911 raise IndexError
2918 parsed.append((section, name, value))
2912 parsed.append((section, name, value))
2919 except (IndexError, ValueError):
2913 except (IndexError, ValueError):
2920 raise util.Abort(_('malformed --config option: %s') % cfg)
2914 raise util.Abort(_('malformed --config option: %s') % cfg)
2921 return parsed
2915 return parsed
2922
2916
2923 def dispatch(args):
2917 def dispatch(args):
2924 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
2918 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
2925 num = getattr(signal, name, None)
2919 num = getattr(signal, name, None)
2926 if num: signal.signal(num, catchterm)
2920 if num: signal.signal(num, catchterm)
2927
2921
2928 try:
2922 try:
2929 u = ui.ui(traceback='--traceback' in sys.argv[1:])
2923 u = ui.ui(traceback='--traceback' in sys.argv[1:])
2930 except util.Abort, inst:
2924 except util.Abort, inst:
2931 sys.stderr.write(_("abort: %s\n") % inst)
2925 sys.stderr.write(_("abort: %s\n") % inst)
2932 return -1
2926 return -1
2933
2927
2934 load_extensions(u)
2928 load_extensions(u)
2935 u.addreadhook(load_extensions)
2929 u.addreadhook(load_extensions)
2936
2930
2937 try:
2931 try:
2938 cmd, func, args, options, cmdoptions = parse(u, args)
2932 cmd, func, args, options, cmdoptions = parse(u, args)
2939 if options["time"]:
2933 if options["time"]:
2940 def get_times():
2934 def get_times():
2941 t = os.times()
2935 t = os.times()
2942 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
2936 if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()
2943 t = (t[0], t[1], t[2], t[3], time.clock())
2937 t = (t[0], t[1], t[2], t[3], time.clock())
2944 return t
2938 return t
2945 s = get_times()
2939 s = get_times()
2946 def print_time():
2940 def print_time():
2947 t = get_times()
2941 t = get_times()
2948 u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
2942 u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") %
2949 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
2943 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
2950 atexit.register(print_time)
2944 atexit.register(print_time)
2951
2945
2952 # enter the debugger before command execution
2946 # enter the debugger before command execution
2953 if options['debugger']:
2947 if options['debugger']:
2954 pdb.set_trace()
2948 pdb.set_trace()
2955
2949
2956 try:
2950 try:
2957 if options['cwd']:
2951 if options['cwd']:
2958 try:
2952 try:
2959 os.chdir(options['cwd'])
2953 os.chdir(options['cwd'])
2960 except OSError, inst:
2954 except OSError, inst:
2961 raise util.Abort('%s: %s' %
2955 raise util.Abort('%s: %s' %
2962 (options['cwd'], inst.strerror))
2956 (options['cwd'], inst.strerror))
2963
2957
2964 u.updateopts(options["verbose"], options["debug"], options["quiet"],
2958 u.updateopts(options["verbose"], options["debug"], options["quiet"],
2965 not options["noninteractive"], options["traceback"],
2959 not options["noninteractive"], options["traceback"],
2966 parseconfig(options["config"]))
2960 parseconfig(options["config"]))
2967
2961
2968 path = u.expandpath(options["repository"]) or ""
2962 path = u.expandpath(options["repository"]) or ""
2969 repo = path and hg.repository(u, path=path) or None
2963 repo = path and hg.repository(u, path=path) or None
2970 if repo and not repo.local():
2964 if repo and not repo.local():
2971 raise util.Abort(_("repository '%s' is not local") % path)
2965 raise util.Abort(_("repository '%s' is not local") % path)
2972
2966
2973 if options['help']:
2967 if options['help']:
2974 return help_(u, cmd, options['version'])
2968 return help_(u, cmd, options['version'])
2975 elif options['version']:
2969 elif options['version']:
2976 return version_(u)
2970 return version_(u)
2977 elif not cmd:
2971 elif not cmd:
2978 return help_(u, 'shortlist')
2972 return help_(u, 'shortlist')
2979
2973
2980 if cmd not in norepo.split():
2974 if cmd not in norepo.split():
2981 try:
2975 try:
2982 if not repo:
2976 if not repo:
2983 repo = hg.repository(u, path=path)
2977 repo = hg.repository(u, path=path)
2984 u = repo.ui
2978 u = repo.ui
2985 for name in external.itervalues():
2979 for name in external.itervalues():
2986 mod = sys.modules[name]
2980 mod = sys.modules[name]
2987 if hasattr(mod, 'reposetup'):
2981 if hasattr(mod, 'reposetup'):
2988 mod.reposetup(u, repo)
2982 mod.reposetup(u, repo)
2989 hg.repo_setup_hooks.append(mod.reposetup)
2983 hg.repo_setup_hooks.append(mod.reposetup)
2990 except hg.RepoError:
2984 except hg.RepoError:
2991 if cmd not in optionalrepo.split():
2985 if cmd not in optionalrepo.split():
2992 raise
2986 raise
2993 d = lambda: func(u, repo, *args, **cmdoptions)
2987 d = lambda: func(u, repo, *args, **cmdoptions)
2994 else:
2988 else:
2995 d = lambda: func(u, *args, **cmdoptions)
2989 d = lambda: func(u, *args, **cmdoptions)
2996
2990
2997 try:
2991 try:
2998 if options['profile']:
2992 if options['profile']:
2999 import hotshot, hotshot.stats
2993 import hotshot, hotshot.stats
3000 prof = hotshot.Profile("hg.prof")
2994 prof = hotshot.Profile("hg.prof")
3001 try:
2995 try:
3002 try:
2996 try:
3003 return prof.runcall(d)
2997 return prof.runcall(d)
3004 except:
2998 except:
3005 try:
2999 try:
3006 u.warn(_('exception raised - generating '
3000 u.warn(_('exception raised - generating '
3007 'profile anyway\n'))
3001 'profile anyway\n'))
3008 except:
3002 except:
3009 pass
3003 pass
3010 raise
3004 raise
3011 finally:
3005 finally:
3012 prof.close()
3006 prof.close()
3013 stats = hotshot.stats.load("hg.prof")
3007 stats = hotshot.stats.load("hg.prof")
3014 stats.strip_dirs()
3008 stats.strip_dirs()
3015 stats.sort_stats('time', 'calls')
3009 stats.sort_stats('time', 'calls')
3016 stats.print_stats(40)
3010 stats.print_stats(40)
3017 elif options['lsprof']:
3011 elif options['lsprof']:
3018 try:
3012 try:
3019 from mercurial import lsprof
3013 from mercurial import lsprof
3020 except ImportError:
3014 except ImportError:
3021 raise util.Abort(_(
3015 raise util.Abort(_(
3022 'lsprof not available - install from '
3016 'lsprof not available - install from '
3023 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
3017 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
3024 p = lsprof.Profiler()
3018 p = lsprof.Profiler()
3025 p.enable(subcalls=True)
3019 p.enable(subcalls=True)
3026 try:
3020 try:
3027 return d()
3021 return d()
3028 finally:
3022 finally:
3029 p.disable()
3023 p.disable()
3030 stats = lsprof.Stats(p.getstats())
3024 stats = lsprof.Stats(p.getstats())
3031 stats.sort()
3025 stats.sort()
3032 stats.pprint(top=10, file=sys.stderr, climit=5)
3026 stats.pprint(top=10, file=sys.stderr, climit=5)
3033 else:
3027 else:
3034 return d()
3028 return d()
3035 finally:
3029 finally:
3036 u.flush()
3030 u.flush()
3037 except:
3031 except:
3038 # enter the debugger when we hit an exception
3032 # enter the debugger when we hit an exception
3039 if options['debugger']:
3033 if options['debugger']:
3040 pdb.post_mortem(sys.exc_info()[2])
3034 pdb.post_mortem(sys.exc_info()[2])
3041 u.print_exc()
3035 u.print_exc()
3042 raise
3036 raise
3043 except ParseError, inst:
3037 except ParseError, inst:
3044 if inst.args[0]:
3038 if inst.args[0]:
3045 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
3039 u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
3046 help_(u, inst.args[0])
3040 help_(u, inst.args[0])
3047 else:
3041 else:
3048 u.warn(_("hg: %s\n") % inst.args[1])
3042 u.warn(_("hg: %s\n") % inst.args[1])
3049 help_(u, 'shortlist')
3043 help_(u, 'shortlist')
3050 except AmbiguousCommand, inst:
3044 except AmbiguousCommand, inst:
3051 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
3045 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
3052 (inst.args[0], " ".join(inst.args[1])))
3046 (inst.args[0], " ".join(inst.args[1])))
3053 except UnknownCommand, inst:
3047 except UnknownCommand, inst:
3054 u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
3048 u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
3055 help_(u, 'shortlist')
3049 help_(u, 'shortlist')
3056 except hg.RepoError, inst:
3050 except hg.RepoError, inst:
3057 u.warn(_("abort: %s!\n") % inst)
3051 u.warn(_("abort: %s!\n") % inst)
3058 except lock.LockHeld, inst:
3052 except lock.LockHeld, inst:
3059 if inst.errno == errno.ETIMEDOUT:
3053 if inst.errno == errno.ETIMEDOUT:
3060 reason = _('timed out waiting for lock held by %s') % inst.locker
3054 reason = _('timed out waiting for lock held by %s') % inst.locker
3061 else:
3055 else:
3062 reason = _('lock held by %s') % inst.locker
3056 reason = _('lock held by %s') % inst.locker
3063 u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
3057 u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
3064 except lock.LockUnavailable, inst:
3058 except lock.LockUnavailable, inst:
3065 u.warn(_("abort: could not lock %s: %s\n") %
3059 u.warn(_("abort: could not lock %s: %s\n") %
3066 (inst.desc or inst.filename, inst.strerror))
3060 (inst.desc or inst.filename, inst.strerror))
3067 except revlog.RevlogError, inst:
3061 except revlog.RevlogError, inst:
3068 u.warn(_("abort: %s!\n") % inst)
3062 u.warn(_("abort: %s!\n") % inst)
3069 except util.SignalInterrupt:
3063 except util.SignalInterrupt:
3070 u.warn(_("killed!\n"))
3064 u.warn(_("killed!\n"))
3071 except KeyboardInterrupt:
3065 except KeyboardInterrupt:
3072 try:
3066 try:
3073 u.warn(_("interrupted!\n"))
3067 u.warn(_("interrupted!\n"))
3074 except IOError, inst:
3068 except IOError, inst:
3075 if inst.errno == errno.EPIPE:
3069 if inst.errno == errno.EPIPE:
3076 if u.debugflag:
3070 if u.debugflag:
3077 u.warn(_("\nbroken pipe\n"))
3071 u.warn(_("\nbroken pipe\n"))
3078 else:
3072 else:
3079 raise
3073 raise
3080 except IOError, inst:
3074 except IOError, inst:
3081 if hasattr(inst, "code"):
3075 if hasattr(inst, "code"):
3082 u.warn(_("abort: %s\n") % inst)
3076 u.warn(_("abort: %s\n") % inst)
3083 elif hasattr(inst, "reason"):
3077 elif hasattr(inst, "reason"):
3084 u.warn(_("abort: error: %s\n") % inst.reason[1])
3078 u.warn(_("abort: error: %s\n") % inst.reason[1])
3085 elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
3079 elif hasattr(inst, "args") and inst[0] == errno.EPIPE:
3086 if u.debugflag:
3080 if u.debugflag:
3087 u.warn(_("broken pipe\n"))
3081 u.warn(_("broken pipe\n"))
3088 elif getattr(inst, "strerror", None):
3082 elif getattr(inst, "strerror", None):
3089 if getattr(inst, "filename", None):
3083 if getattr(inst, "filename", None):
3090 u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
3084 u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
3091 else:
3085 else:
3092 u.warn(_("abort: %s\n") % inst.strerror)
3086 u.warn(_("abort: %s\n") % inst.strerror)
3093 else:
3087 else:
3094 raise
3088 raise
3095 except OSError, inst:
3089 except OSError, inst:
3096 if getattr(inst, "filename", None):
3090 if getattr(inst, "filename", None):
3097 u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
3091 u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
3098 else:
3092 else:
3099 u.warn(_("abort: %s\n") % inst.strerror)
3093 u.warn(_("abort: %s\n") % inst.strerror)
3100 except util.UnexpectedOutput, inst:
3094 except util.UnexpectedOutput, inst:
3101 u.warn(_("abort: %s") % inst[0])
3095 u.warn(_("abort: %s") % inst[0])
3102 if not isinstance(inst[1], basestring):
3096 if not isinstance(inst[1], basestring):
3103 u.warn(" %r\n" % (inst[1],))
3097 u.warn(" %r\n" % (inst[1],))
3104 elif not inst[1]:
3098 elif not inst[1]:
3105 u.warn(_(" empty string\n"))
3099 u.warn(_(" empty string\n"))
3106 else:
3100 else:
3107 u.warn("\n%r%s\n" %
3101 u.warn("\n%r%s\n" %
3108 (inst[1][:400], len(inst[1]) > 400 and '...' or ''))
3102 (inst[1][:400], len(inst[1]) > 400 and '...' or ''))
3109 except util.Abort, inst:
3103 except util.Abort, inst:
3110 u.warn(_("abort: %s\n") % inst)
3104 u.warn(_("abort: %s\n") % inst)
3111 except TypeError, inst:
3105 except TypeError, inst:
3112 # was this an argument error?
3106 # was this an argument error?
3113 tb = traceback.extract_tb(sys.exc_info()[2])
3107 tb = traceback.extract_tb(sys.exc_info()[2])
3114 if len(tb) > 2: # no
3108 if len(tb) > 2: # no
3115 raise
3109 raise
3116 u.debug(inst, "\n")
3110 u.debug(inst, "\n")
3117 u.warn(_("%s: invalid arguments\n") % cmd)
3111 u.warn(_("%s: invalid arguments\n") % cmd)
3118 help_(u, cmd)
3112 help_(u, cmd)
3119 except SystemExit, inst:
3113 except SystemExit, inst:
3120 # Commands shouldn't sys.exit directly, but give a return code.
3114 # Commands shouldn't sys.exit directly, but give a return code.
3121 # Just in case catch this and and pass exit code to caller.
3115 # Just in case catch this and and pass exit code to caller.
3122 return inst.code
3116 return inst.code
3123 except:
3117 except:
3124 u.warn(_("** unknown exception encountered, details follow\n"))
3118 u.warn(_("** unknown exception encountered, details follow\n"))
3125 u.warn(_("** report bug details to "
3119 u.warn(_("** report bug details to "
3126 "http://www.selenic.com/mercurial/bts\n"))
3120 "http://www.selenic.com/mercurial/bts\n"))
3127 u.warn(_("** or mercurial@selenic.com\n"))
3121 u.warn(_("** or mercurial@selenic.com\n"))
3128 u.warn(_("** Mercurial Distributed SCM (version %s)\n")
3122 u.warn(_("** Mercurial Distributed SCM (version %s)\n")
3129 % version.get_version())
3123 % version.get_version())
3130 raise
3124 raise
3131
3125
3132 return -1
3126 return -1
General Comments 0
You need to be logged in to leave comments. Login now