##// END OF EJS Templates
help: describe bundle compression methods (issue1523)
Henrik Stuart -
r8903:d403cf4e default
parent child Browse files
Show More
@@ -1,3549 +1,3551 b''
1 # commands.py - command processing for mercurial
1 # commands.py - command processing for mercurial
2 #
2 #
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
6 # GNU General Public License version 2, incorporated herein by reference.
7
7
8 from node import hex, nullid, nullrev, short
8 from node import hex, nullid, nullrev, short
9 from lock import release
9 from lock import release
10 from i18n import _, gettext
10 from i18n import _, gettext
11 import os, re, sys, textwrap, subprocess, difflib, time
11 import os, re, sys, textwrap, subprocess, difflib, time
12 import hg, util, revlog, bundlerepo, extensions, copies, context, error
12 import hg, util, revlog, bundlerepo, extensions, copies, context, error
13 import patch, help, mdiff, tempfile, url, encoding
13 import patch, help, mdiff, tempfile, url, encoding
14 import archival, changegroup, cmdutil, sshserver, hbisect
14 import archival, changegroup, cmdutil, sshserver, hbisect
15 from hgweb import server
15 from hgweb import server
16 import merge as merge_
16 import merge as merge_
17
17
18 # Commands start here, listed alphabetically
18 # Commands start here, listed alphabetically
19
19
20 def add(ui, repo, *pats, **opts):
20 def add(ui, repo, *pats, **opts):
21 """add the specified files on the next commit
21 """add the specified files on the next commit
22
22
23 Schedule files to be version controlled and added to the
23 Schedule files to be version controlled and added to the
24 repository.
24 repository.
25
25
26 The files will be added to the repository at the next commit. To
26 The files will be added to the repository at the next commit. To
27 undo an add before that, see hg forget.
27 undo an add before that, see hg forget.
28
28
29 If no names are given, add all files to the repository.
29 If no names are given, add all files to the repository.
30 """
30 """
31
31
32 bad = []
32 bad = []
33 exacts = {}
33 exacts = {}
34 names = []
34 names = []
35 m = cmdutil.match(repo, pats, opts)
35 m = cmdutil.match(repo, pats, opts)
36 oldbad = m.bad
36 oldbad = m.bad
37 m.bad = lambda x,y: bad.append(x) or oldbad(x,y)
37 m.bad = lambda x,y: bad.append(x) or oldbad(x,y)
38
38
39 for f in repo.walk(m):
39 for f in repo.walk(m):
40 exact = m.exact(f)
40 exact = m.exact(f)
41 if exact or f not in repo.dirstate:
41 if exact or f not in repo.dirstate:
42 names.append(f)
42 names.append(f)
43 if ui.verbose or not exact:
43 if ui.verbose or not exact:
44 ui.status(_('adding %s\n') % m.rel(f))
44 ui.status(_('adding %s\n') % m.rel(f))
45 if not opts.get('dry_run'):
45 if not opts.get('dry_run'):
46 bad += [f for f in repo.add(names) if f in m.files()]
46 bad += [f for f in repo.add(names) if f in m.files()]
47 return bad and 1 or 0
47 return bad and 1 or 0
48
48
49 def addremove(ui, repo, *pats, **opts):
49 def addremove(ui, repo, *pats, **opts):
50 """add all new files, delete all missing files
50 """add all new files, delete all missing files
51
51
52 Add all new files and remove all missing files from the
52 Add all new files and remove all missing files from the
53 repository.
53 repository.
54
54
55 New files are ignored if they match any of the patterns in
55 New files are ignored if they match any of the patterns in
56 .hgignore. As with add, these changes take effect at the next
56 .hgignore. As with add, these changes take effect at the next
57 commit.
57 commit.
58
58
59 Use the -s/--similarity option to detect renamed files. With a
59 Use the -s/--similarity option to detect renamed files. With a
60 parameter > 0, this compares every removed file with every added
60 parameter > 0, this compares every removed file with every added
61 file and records those similar enough as renames. This option
61 file and records those similar enough as renames. This option
62 takes a percentage between 0 (disabled) and 100 (files must be
62 takes a percentage between 0 (disabled) and 100 (files must be
63 identical) as its parameter. Detecting renamed files this way can
63 identical) as its parameter. Detecting renamed files this way can
64 be expensive.
64 be expensive.
65 """
65 """
66 try:
66 try:
67 sim = float(opts.get('similarity') or 0)
67 sim = float(opts.get('similarity') or 0)
68 except ValueError:
68 except ValueError:
69 raise util.Abort(_('similarity must be a number'))
69 raise util.Abort(_('similarity must be a number'))
70 if sim < 0 or sim > 100:
70 if sim < 0 or sim > 100:
71 raise util.Abort(_('similarity must be between 0 and 100'))
71 raise util.Abort(_('similarity must be between 0 and 100'))
72 return cmdutil.addremove(repo, pats, opts, similarity=sim/100.)
72 return cmdutil.addremove(repo, pats, opts, similarity=sim/100.)
73
73
74 def annotate(ui, repo, *pats, **opts):
74 def annotate(ui, repo, *pats, **opts):
75 """show changeset information by line for each file
75 """show changeset information by line for each file
76
76
77 List changes in files, showing the revision id responsible for
77 List changes in files, showing the revision id responsible for
78 each line
78 each line
79
79
80 This command is useful for discovering when a change was made and
80 This command is useful for discovering when a change was made and
81 by whom.
81 by whom.
82
82
83 Without the -a/--text option, annotate will avoid processing files
83 Without the -a/--text option, annotate will avoid processing files
84 it detects as binary. With -a, annotate will annotate the file
84 it detects as binary. With -a, annotate will annotate the file
85 anyway, although the results will probably be neither useful
85 anyway, although the results will probably be neither useful
86 nor desirable.
86 nor desirable.
87 """
87 """
88 datefunc = ui.quiet and util.shortdate or util.datestr
88 datefunc = ui.quiet and util.shortdate or util.datestr
89 getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
89 getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
90
90
91 if not pats:
91 if not pats:
92 raise util.Abort(_('at least one filename or pattern is required'))
92 raise util.Abort(_('at least one filename or pattern is required'))
93
93
94 opmap = [('user', lambda x: ui.shortuser(x[0].user())),
94 opmap = [('user', lambda x: ui.shortuser(x[0].user())),
95 ('number', lambda x: str(x[0].rev())),
95 ('number', lambda x: str(x[0].rev())),
96 ('changeset', lambda x: short(x[0].node())),
96 ('changeset', lambda x: short(x[0].node())),
97 ('date', getdate),
97 ('date', getdate),
98 ('follow', lambda x: x[0].path()),
98 ('follow', lambda x: x[0].path()),
99 ]
99 ]
100
100
101 if (not opts.get('user') and not opts.get('changeset') and not opts.get('date')
101 if (not opts.get('user') and not opts.get('changeset') and not opts.get('date')
102 and not opts.get('follow')):
102 and not opts.get('follow')):
103 opts['number'] = 1
103 opts['number'] = 1
104
104
105 linenumber = opts.get('line_number') is not None
105 linenumber = opts.get('line_number') is not None
106 if (linenumber and (not opts.get('changeset')) and (not opts.get('number'))):
106 if (linenumber and (not opts.get('changeset')) and (not opts.get('number'))):
107 raise util.Abort(_('at least one of -n/-c is required for -l'))
107 raise util.Abort(_('at least one of -n/-c is required for -l'))
108
108
109 funcmap = [func for op, func in opmap if opts.get(op)]
109 funcmap = [func for op, func in opmap if opts.get(op)]
110 if linenumber:
110 if linenumber:
111 lastfunc = funcmap[-1]
111 lastfunc = funcmap[-1]
112 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
112 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
113
113
114 ctx = repo[opts.get('rev')]
114 ctx = repo[opts.get('rev')]
115
115
116 m = cmdutil.match(repo, pats, opts)
116 m = cmdutil.match(repo, pats, opts)
117 for abs in ctx.walk(m):
117 for abs in ctx.walk(m):
118 fctx = ctx[abs]
118 fctx = ctx[abs]
119 if not opts.get('text') and util.binary(fctx.data()):
119 if not opts.get('text') and util.binary(fctx.data()):
120 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
120 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
121 continue
121 continue
122
122
123 lines = fctx.annotate(follow=opts.get('follow'),
123 lines = fctx.annotate(follow=opts.get('follow'),
124 linenumber=linenumber)
124 linenumber=linenumber)
125 pieces = []
125 pieces = []
126
126
127 for f in funcmap:
127 for f in funcmap:
128 l = [f(n) for n, dummy in lines]
128 l = [f(n) for n, dummy in lines]
129 if l:
129 if l:
130 ml = max(map(len, l))
130 ml = max(map(len, l))
131 pieces.append(["%*s" % (ml, x) for x in l])
131 pieces.append(["%*s" % (ml, x) for x in l])
132
132
133 if pieces:
133 if pieces:
134 for p, l in zip(zip(*pieces), lines):
134 for p, l in zip(zip(*pieces), lines):
135 ui.write("%s: %s" % (" ".join(p), l[1]))
135 ui.write("%s: %s" % (" ".join(p), l[1]))
136
136
137 def archive(ui, repo, dest, **opts):
137 def archive(ui, repo, dest, **opts):
138 '''create an unversioned archive of a repository revision
138 '''create an unversioned archive of a repository revision
139
139
140 By default, the revision used is the parent of the working
140 By default, the revision used is the parent of the working
141 directory; use -r/--rev to specify a different revision.
141 directory; use -r/--rev to specify a different revision.
142
142
143 To specify the type of archive to create, use -t/--type. Valid
143 To specify the type of archive to create, use -t/--type. Valid
144 types are:
144 types are:
145
145
146 "files" (default): a directory full of files
146 "files" (default): a directory full of files
147 "tar": tar archive, uncompressed
147 "tar": tar archive, uncompressed
148 "tbz2": tar archive, compressed using bzip2
148 "tbz2": tar archive, compressed using bzip2
149 "tgz": tar archive, compressed using gzip
149 "tgz": tar archive, compressed using gzip
150 "uzip": zip archive, uncompressed
150 "uzip": zip archive, uncompressed
151 "zip": zip archive, compressed using deflate
151 "zip": zip archive, compressed using deflate
152
152
153 The exact name of the destination archive or directory is given
153 The exact name of the destination archive or directory is given
154 using a format string; see 'hg help export' for details.
154 using a format string; see 'hg help export' for details.
155
155
156 Each member added to an archive file has a directory prefix
156 Each member added to an archive file has a directory prefix
157 prepended. Use -p/--prefix to specify a format string for the
157 prepended. Use -p/--prefix to specify a format string for the
158 prefix. The default is the basename of the archive, with suffixes
158 prefix. The default is the basename of the archive, with suffixes
159 removed.
159 removed.
160 '''
160 '''
161
161
162 ctx = repo[opts.get('rev')]
162 ctx = repo[opts.get('rev')]
163 if not ctx:
163 if not ctx:
164 raise util.Abort(_('no working directory: please specify a revision'))
164 raise util.Abort(_('no working directory: please specify a revision'))
165 node = ctx.node()
165 node = ctx.node()
166 dest = cmdutil.make_filename(repo, dest, node)
166 dest = cmdutil.make_filename(repo, dest, node)
167 if os.path.realpath(dest) == repo.root:
167 if os.path.realpath(dest) == repo.root:
168 raise util.Abort(_('repository root cannot be destination'))
168 raise util.Abort(_('repository root cannot be destination'))
169 matchfn = cmdutil.match(repo, [], opts)
169 matchfn = cmdutil.match(repo, [], opts)
170 kind = opts.get('type') or 'files'
170 kind = opts.get('type') or 'files'
171 prefix = opts.get('prefix')
171 prefix = opts.get('prefix')
172 if dest == '-':
172 if dest == '-':
173 if kind == 'files':
173 if kind == 'files':
174 raise util.Abort(_('cannot archive plain files to stdout'))
174 raise util.Abort(_('cannot archive plain files to stdout'))
175 dest = sys.stdout
175 dest = sys.stdout
176 if not prefix: prefix = os.path.basename(repo.root) + '-%h'
176 if not prefix: prefix = os.path.basename(repo.root) + '-%h'
177 prefix = cmdutil.make_filename(repo, prefix, node)
177 prefix = cmdutil.make_filename(repo, prefix, node)
178 archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
178 archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
179 matchfn, prefix)
179 matchfn, prefix)
180
180
181 def backout(ui, repo, node=None, rev=None, **opts):
181 def backout(ui, repo, node=None, rev=None, **opts):
182 '''reverse effect of earlier changeset
182 '''reverse effect of earlier changeset
183
183
184 Commit the backed out changes as a new changeset. The new
184 Commit the backed out changes as a new changeset. The new
185 changeset is a child of the backed out changeset.
185 changeset is a child of the backed out changeset.
186
186
187 If you backout a changeset other than the tip, a new head is
187 If you backout a changeset other than the tip, a new head is
188 created. This head will be the new tip and you should merge this
188 created. This head will be the new tip and you should merge this
189 backout changeset with another head.
189 backout changeset with another head.
190
190
191 The --merge option remembers the parent of the working directory
191 The --merge option remembers the parent of the working directory
192 before starting the backout, then merges the new head with that
192 before starting the backout, then merges the new head with that
193 changeset afterwards. This saves you from doing the merge by hand.
193 changeset afterwards. This saves you from doing the merge by hand.
194 The result of this merge is not committed, as with a normal merge.
194 The result of this merge is not committed, as with a normal merge.
195
195
196 See 'hg help dates' for a list of formats valid for -d/--date.
196 See 'hg help dates' for a list of formats valid for -d/--date.
197 '''
197 '''
198 if rev and node:
198 if rev and node:
199 raise util.Abort(_("please specify just one revision"))
199 raise util.Abort(_("please specify just one revision"))
200
200
201 if not rev:
201 if not rev:
202 rev = node
202 rev = node
203
203
204 if not rev:
204 if not rev:
205 raise util.Abort(_("please specify a revision to backout"))
205 raise util.Abort(_("please specify a revision to backout"))
206
206
207 date = opts.get('date')
207 date = opts.get('date')
208 if date:
208 if date:
209 opts['date'] = util.parsedate(date)
209 opts['date'] = util.parsedate(date)
210
210
211 cmdutil.bail_if_changed(repo)
211 cmdutil.bail_if_changed(repo)
212 node = repo.lookup(rev)
212 node = repo.lookup(rev)
213
213
214 op1, op2 = repo.dirstate.parents()
214 op1, op2 = repo.dirstate.parents()
215 a = repo.changelog.ancestor(op1, node)
215 a = repo.changelog.ancestor(op1, node)
216 if a != node:
216 if a != node:
217 raise util.Abort(_('cannot backout change on a different branch'))
217 raise util.Abort(_('cannot backout change on a different branch'))
218
218
219 p1, p2 = repo.changelog.parents(node)
219 p1, p2 = repo.changelog.parents(node)
220 if p1 == nullid:
220 if p1 == nullid:
221 raise util.Abort(_('cannot backout a change with no parents'))
221 raise util.Abort(_('cannot backout a change with no parents'))
222 if p2 != nullid:
222 if p2 != nullid:
223 if not opts.get('parent'):
223 if not opts.get('parent'):
224 raise util.Abort(_('cannot backout a merge changeset without '
224 raise util.Abort(_('cannot backout a merge changeset without '
225 '--parent'))
225 '--parent'))
226 p = repo.lookup(opts['parent'])
226 p = repo.lookup(opts['parent'])
227 if p not in (p1, p2):
227 if p not in (p1, p2):
228 raise util.Abort(_('%s is not a parent of %s') %
228 raise util.Abort(_('%s is not a parent of %s') %
229 (short(p), short(node)))
229 (short(p), short(node)))
230 parent = p
230 parent = p
231 else:
231 else:
232 if opts.get('parent'):
232 if opts.get('parent'):
233 raise util.Abort(_('cannot use --parent on non-merge changeset'))
233 raise util.Abort(_('cannot use --parent on non-merge changeset'))
234 parent = p1
234 parent = p1
235
235
236 # the backout should appear on the same branch
236 # the backout should appear on the same branch
237 branch = repo.dirstate.branch()
237 branch = repo.dirstate.branch()
238 hg.clean(repo, node, show_stats=False)
238 hg.clean(repo, node, show_stats=False)
239 repo.dirstate.setbranch(branch)
239 repo.dirstate.setbranch(branch)
240 revert_opts = opts.copy()
240 revert_opts = opts.copy()
241 revert_opts['date'] = None
241 revert_opts['date'] = None
242 revert_opts['all'] = True
242 revert_opts['all'] = True
243 revert_opts['rev'] = hex(parent)
243 revert_opts['rev'] = hex(parent)
244 revert_opts['no_backup'] = None
244 revert_opts['no_backup'] = None
245 revert(ui, repo, **revert_opts)
245 revert(ui, repo, **revert_opts)
246 commit_opts = opts.copy()
246 commit_opts = opts.copy()
247 commit_opts['addremove'] = False
247 commit_opts['addremove'] = False
248 if not commit_opts['message'] and not commit_opts['logfile']:
248 if not commit_opts['message'] and not commit_opts['logfile']:
249 commit_opts['message'] = _("Backed out changeset %s") % (short(node))
249 commit_opts['message'] = _("Backed out changeset %s") % (short(node))
250 commit_opts['force_editor'] = True
250 commit_opts['force_editor'] = True
251 commit(ui, repo, **commit_opts)
251 commit(ui, repo, **commit_opts)
252 def nice(node):
252 def nice(node):
253 return '%d:%s' % (repo.changelog.rev(node), short(node))
253 return '%d:%s' % (repo.changelog.rev(node), short(node))
254 ui.status(_('changeset %s backs out changeset %s\n') %
254 ui.status(_('changeset %s backs out changeset %s\n') %
255 (nice(repo.changelog.tip()), nice(node)))
255 (nice(repo.changelog.tip()), nice(node)))
256 if op1 != node:
256 if op1 != node:
257 hg.clean(repo, op1, show_stats=False)
257 hg.clean(repo, op1, show_stats=False)
258 if opts.get('merge'):
258 if opts.get('merge'):
259 ui.status(_('merging with changeset %s\n') % nice(repo.changelog.tip()))
259 ui.status(_('merging with changeset %s\n') % nice(repo.changelog.tip()))
260 hg.merge(repo, hex(repo.changelog.tip()))
260 hg.merge(repo, hex(repo.changelog.tip()))
261 else:
261 else:
262 ui.status(_('the backout changeset is a new head - '
262 ui.status(_('the backout changeset is a new head - '
263 'do not forget to merge\n'))
263 'do not forget to merge\n'))
264 ui.status(_('(use "backout --merge" '
264 ui.status(_('(use "backout --merge" '
265 'if you want to auto-merge)\n'))
265 'if you want to auto-merge)\n'))
266
266
267 def bisect(ui, repo, rev=None, extra=None, command=None,
267 def bisect(ui, repo, rev=None, extra=None, command=None,
268 reset=None, good=None, bad=None, skip=None, noupdate=None):
268 reset=None, good=None, bad=None, skip=None, noupdate=None):
269 """subdivision search of changesets
269 """subdivision search of changesets
270
270
271 This command helps to find changesets which introduce problems. To
271 This command helps to find changesets which introduce problems. To
272 use, mark the earliest changeset you know exhibits the problem as
272 use, mark the earliest changeset you know exhibits the problem as
273 bad, then mark the latest changeset which is free from the problem
273 bad, then mark the latest changeset which is free from the problem
274 as good. Bisect will update your working directory to a revision
274 as good. Bisect will update your working directory to a revision
275 for testing (unless the -U/--noupdate option is specified). Once
275 for testing (unless the -U/--noupdate option is specified). Once
276 you have performed tests, mark the working directory as good or
276 you have performed tests, mark the working directory as good or
277 bad, and bisect will either update to another candidate changeset
277 bad, and bisect will either update to another candidate changeset
278 or announce that it has found the bad revision.
278 or announce that it has found the bad revision.
279
279
280 As a shortcut, you can also use the revision argument to mark a
280 As a shortcut, you can also use the revision argument to mark a
281 revision as good or bad without checking it out first.
281 revision as good or bad without checking it out first.
282
282
283 If you supply a command, it will be used for automatic bisection.
283 If you supply a command, it will be used for automatic bisection.
284 Its exit status will be used to mark revisions as good or bad:
284 Its exit status will be used to mark revisions as good or bad:
285 status 0 means good, 125 means to skip the revision, 127
285 status 0 means good, 125 means to skip the revision, 127
286 (command not found) will abort the bisection, and any other
286 (command not found) will abort the bisection, and any other
287 non-zero exit status means the revision is bad.
287 non-zero exit status means the revision is bad.
288 """
288 """
289 def print_result(nodes, good):
289 def print_result(nodes, good):
290 displayer = cmdutil.show_changeset(ui, repo, {})
290 displayer = cmdutil.show_changeset(ui, repo, {})
291 if len(nodes) == 1:
291 if len(nodes) == 1:
292 # narrowed it down to a single revision
292 # narrowed it down to a single revision
293 if good:
293 if good:
294 ui.write(_("The first good revision is:\n"))
294 ui.write(_("The first good revision is:\n"))
295 else:
295 else:
296 ui.write(_("The first bad revision is:\n"))
296 ui.write(_("The first bad revision is:\n"))
297 displayer.show(repo[nodes[0]])
297 displayer.show(repo[nodes[0]])
298 else:
298 else:
299 # multiple possible revisions
299 # multiple possible revisions
300 if good:
300 if good:
301 ui.write(_("Due to skipped revisions, the first "
301 ui.write(_("Due to skipped revisions, the first "
302 "good revision could be any of:\n"))
302 "good revision could be any of:\n"))
303 else:
303 else:
304 ui.write(_("Due to skipped revisions, the first "
304 ui.write(_("Due to skipped revisions, the first "
305 "bad revision could be any of:\n"))
305 "bad revision could be any of:\n"))
306 for n in nodes:
306 for n in nodes:
307 displayer.show(repo[n])
307 displayer.show(repo[n])
308
308
309 def check_state(state, interactive=True):
309 def check_state(state, interactive=True):
310 if not state['good'] or not state['bad']:
310 if not state['good'] or not state['bad']:
311 if (good or bad or skip or reset) and interactive:
311 if (good or bad or skip or reset) and interactive:
312 return
312 return
313 if not state['good']:
313 if not state['good']:
314 raise util.Abort(_('cannot bisect (no known good revisions)'))
314 raise util.Abort(_('cannot bisect (no known good revisions)'))
315 else:
315 else:
316 raise util.Abort(_('cannot bisect (no known bad revisions)'))
316 raise util.Abort(_('cannot bisect (no known bad revisions)'))
317 return True
317 return True
318
318
319 # backward compatibility
319 # backward compatibility
320 if rev in "good bad reset init".split():
320 if rev in "good bad reset init".split():
321 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
321 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
322 cmd, rev, extra = rev, extra, None
322 cmd, rev, extra = rev, extra, None
323 if cmd == "good":
323 if cmd == "good":
324 good = True
324 good = True
325 elif cmd == "bad":
325 elif cmd == "bad":
326 bad = True
326 bad = True
327 else:
327 else:
328 reset = True
328 reset = True
329 elif extra or good + bad + skip + reset + bool(command) > 1:
329 elif extra or good + bad + skip + reset + bool(command) > 1:
330 raise util.Abort(_('incompatible arguments'))
330 raise util.Abort(_('incompatible arguments'))
331
331
332 if reset:
332 if reset:
333 p = repo.join("bisect.state")
333 p = repo.join("bisect.state")
334 if os.path.exists(p):
334 if os.path.exists(p):
335 os.unlink(p)
335 os.unlink(p)
336 return
336 return
337
337
338 state = hbisect.load_state(repo)
338 state = hbisect.load_state(repo)
339
339
340 if command:
340 if command:
341 commandpath = util.find_exe(command)
341 commandpath = util.find_exe(command)
342 if commandpath is None:
342 if commandpath is None:
343 raise util.Abort(_("cannot find executable: %s") % command)
343 raise util.Abort(_("cannot find executable: %s") % command)
344 changesets = 1
344 changesets = 1
345 try:
345 try:
346 while changesets:
346 while changesets:
347 # update state
347 # update state
348 status = subprocess.call([commandpath])
348 status = subprocess.call([commandpath])
349 if status == 125:
349 if status == 125:
350 transition = "skip"
350 transition = "skip"
351 elif status == 0:
351 elif status == 0:
352 transition = "good"
352 transition = "good"
353 # status < 0 means process was killed
353 # status < 0 means process was killed
354 elif status == 127:
354 elif status == 127:
355 raise util.Abort(_("failed to execute %s") % command)
355 raise util.Abort(_("failed to execute %s") % command)
356 elif status < 0:
356 elif status < 0:
357 raise util.Abort(_("%s killed") % command)
357 raise util.Abort(_("%s killed") % command)
358 else:
358 else:
359 transition = "bad"
359 transition = "bad"
360 ctx = repo[rev or '.']
360 ctx = repo[rev or '.']
361 state[transition].append(ctx.node())
361 state[transition].append(ctx.node())
362 ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition))
362 ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition))
363 check_state(state, interactive=False)
363 check_state(state, interactive=False)
364 # bisect
364 # bisect
365 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
365 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
366 # update to next check
366 # update to next check
367 cmdutil.bail_if_changed(repo)
367 cmdutil.bail_if_changed(repo)
368 hg.clean(repo, nodes[0], show_stats=False)
368 hg.clean(repo, nodes[0], show_stats=False)
369 finally:
369 finally:
370 hbisect.save_state(repo, state)
370 hbisect.save_state(repo, state)
371 return print_result(nodes, not status)
371 return print_result(nodes, not status)
372
372
373 # update state
373 # update state
374 node = repo.lookup(rev or '.')
374 node = repo.lookup(rev or '.')
375 if good:
375 if good:
376 state['good'].append(node)
376 state['good'].append(node)
377 elif bad:
377 elif bad:
378 state['bad'].append(node)
378 state['bad'].append(node)
379 elif skip:
379 elif skip:
380 state['skip'].append(node)
380 state['skip'].append(node)
381
381
382 hbisect.save_state(repo, state)
382 hbisect.save_state(repo, state)
383
383
384 if not check_state(state):
384 if not check_state(state):
385 return
385 return
386
386
387 # actually bisect
387 # actually bisect
388 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
388 nodes, changesets, good = hbisect.bisect(repo.changelog, state)
389 if changesets == 0:
389 if changesets == 0:
390 print_result(nodes, good)
390 print_result(nodes, good)
391 else:
391 else:
392 assert len(nodes) == 1 # only a single node can be tested next
392 assert len(nodes) == 1 # only a single node can be tested next
393 node = nodes[0]
393 node = nodes[0]
394 # compute the approximate number of remaining tests
394 # compute the approximate number of remaining tests
395 tests, size = 0, 2
395 tests, size = 0, 2
396 while size <= changesets:
396 while size <= changesets:
397 tests, size = tests + 1, size * 2
397 tests, size = tests + 1, size * 2
398 rev = repo.changelog.rev(node)
398 rev = repo.changelog.rev(node)
399 ui.write(_("Testing changeset %s:%s "
399 ui.write(_("Testing changeset %s:%s "
400 "(%s changesets remaining, ~%s tests)\n")
400 "(%s changesets remaining, ~%s tests)\n")
401 % (rev, short(node), changesets, tests))
401 % (rev, short(node), changesets, tests))
402 if not noupdate:
402 if not noupdate:
403 cmdutil.bail_if_changed(repo)
403 cmdutil.bail_if_changed(repo)
404 return hg.clean(repo, node)
404 return hg.clean(repo, node)
405
405
406 def branch(ui, repo, label=None, **opts):
406 def branch(ui, repo, label=None, **opts):
407 """set or show the current branch name
407 """set or show the current branch name
408
408
409 With no argument, show the current branch name. With one argument,
409 With no argument, show the current branch name. With one argument,
410 set the working directory branch name (the branch will not exist
410 set the working directory branch name (the branch will not exist
411 in the repository until the next commit). Standard practice
411 in the repository until the next commit). Standard practice
412 recommends that primary development take place on the 'default'
412 recommends that primary development take place on the 'default'
413 branch.
413 branch.
414
414
415 Unless -f/--force is specified, branch will not let you set a
415 Unless -f/--force is specified, branch will not let you set a
416 branch name that already exists, even if it's inactive.
416 branch name that already exists, even if it's inactive.
417
417
418 Use -C/--clean to reset the working directory branch to that of
418 Use -C/--clean to reset the working directory branch to that of
419 the parent of the working directory, negating a previous branch
419 the parent of the working directory, negating a previous branch
420 change.
420 change.
421
421
422 Use the command 'hg update' to switch to an existing branch.
422 Use the command 'hg update' to switch to an existing branch.
423 """
423 """
424
424
425 if opts.get('clean'):
425 if opts.get('clean'):
426 label = repo[None].parents()[0].branch()
426 label = repo[None].parents()[0].branch()
427 repo.dirstate.setbranch(label)
427 repo.dirstate.setbranch(label)
428 ui.status(_('reset working directory to branch %s\n') % label)
428 ui.status(_('reset working directory to branch %s\n') % label)
429 elif label:
429 elif label:
430 if not opts.get('force') and label in repo.branchtags():
430 if not opts.get('force') and label in repo.branchtags():
431 if label not in [p.branch() for p in repo.parents()]:
431 if label not in [p.branch() for p in repo.parents()]:
432 raise util.Abort(_('a branch of the same name already exists'
432 raise util.Abort(_('a branch of the same name already exists'
433 ' (use --force to override)'))
433 ' (use --force to override)'))
434 repo.dirstate.setbranch(encoding.fromlocal(label))
434 repo.dirstate.setbranch(encoding.fromlocal(label))
435 ui.status(_('marked working directory as branch %s\n') % label)
435 ui.status(_('marked working directory as branch %s\n') % label)
436 else:
436 else:
437 ui.write("%s\n" % encoding.tolocal(repo.dirstate.branch()))
437 ui.write("%s\n" % encoding.tolocal(repo.dirstate.branch()))
438
438
439 def branches(ui, repo, active=False):
439 def branches(ui, repo, active=False):
440 """list repository named branches
440 """list repository named branches
441
441
442 List the repository's named branches, indicating which ones are
442 List the repository's named branches, indicating which ones are
443 inactive. If active is specified, only show active branches.
443 inactive. If active is specified, only show active branches.
444
444
445 A branch is considered active if it contains repository heads.
445 A branch is considered active if it contains repository heads.
446
446
447 Use the command 'hg update' to switch to an existing branch.
447 Use the command 'hg update' to switch to an existing branch.
448 """
448 """
449 hexfunc = ui.debugflag and hex or short
449 hexfunc = ui.debugflag and hex or short
450 activebranches = [encoding.tolocal(repo[n].branch())
450 activebranches = [encoding.tolocal(repo[n].branch())
451 for n in repo.heads()]
451 for n in repo.heads()]
452 def testactive(tag, node):
452 def testactive(tag, node):
453 realhead = tag in activebranches
453 realhead = tag in activebranches
454 open = node in repo.branchheads(tag, closed=False)
454 open = node in repo.branchheads(tag, closed=False)
455 return realhead and open
455 return realhead and open
456 branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag)
456 branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag)
457 for tag, node in repo.branchtags().items()],
457 for tag, node in repo.branchtags().items()],
458 reverse=True)
458 reverse=True)
459
459
460 for isactive, node, tag in branches:
460 for isactive, node, tag in branches:
461 if (not active) or isactive:
461 if (not active) or isactive:
462 if ui.quiet:
462 if ui.quiet:
463 ui.write("%s\n" % tag)
463 ui.write("%s\n" % tag)
464 else:
464 else:
465 hn = repo.lookup(node)
465 hn = repo.lookup(node)
466 if isactive:
466 if isactive:
467 notice = ''
467 notice = ''
468 elif hn not in repo.branchheads(tag, closed=False):
468 elif hn not in repo.branchheads(tag, closed=False):
469 notice = ' (closed)'
469 notice = ' (closed)'
470 else:
470 else:
471 notice = ' (inactive)'
471 notice = ' (inactive)'
472 rev = str(node).rjust(31 - encoding.colwidth(tag))
472 rev = str(node).rjust(31 - encoding.colwidth(tag))
473 data = tag, rev, hexfunc(hn), notice
473 data = tag, rev, hexfunc(hn), notice
474 ui.write("%s %s:%s%s\n" % data)
474 ui.write("%s %s:%s%s\n" % data)
475
475
476 def bundle(ui, repo, fname, dest=None, **opts):
476 def bundle(ui, repo, fname, dest=None, **opts):
477 """create a changegroup file
477 """create a changegroup file
478
478
479 Generate a compressed changegroup file collecting changesets not
479 Generate a compressed changegroup file collecting changesets not
480 known to be in another repository.
480 known to be in another repository.
481
481
482 If no destination repository is specified the destination is
482 If no destination repository is specified the destination is
483 assumed to have all the nodes specified by one or more --base
483 assumed to have all the nodes specified by one or more --base
484 parameters. To create a bundle containing all changesets, use
484 parameters. To create a bundle containing all changesets, use
485 -a/--all (or --base null). To change the compression method
485 -a/--all (or --base null).
486 applied, use the -t/--type option (by default, bundles are
486
487 compressed using bz2).
487 To change the compression method applied, use the -t/--type
488 option. The available compression methods are: none, bzip2, and
489 gzip (by default, bundles are compressed using bzip2).
488
490
489 The bundle file can then be transferred using conventional means
491 The bundle file can then be transferred using conventional means
490 and applied to another repository with the unbundle or pull
492 and applied to another repository with the unbundle or pull
491 command. This is useful when direct push and pull are not
493 command. This is useful when direct push and pull are not
492 available or when exporting an entire repository is undesirable.
494 available or when exporting an entire repository is undesirable.
493
495
494 Applying bundles preserves all changeset contents including
496 Applying bundles preserves all changeset contents including
495 permissions, copy/rename information, and revision history.
497 permissions, copy/rename information, and revision history.
496 """
498 """
497 revs = opts.get('rev') or None
499 revs = opts.get('rev') or None
498 if revs:
500 if revs:
499 revs = [repo.lookup(rev) for rev in revs]
501 revs = [repo.lookup(rev) for rev in revs]
500 if opts.get('all'):
502 if opts.get('all'):
501 base = ['null']
503 base = ['null']
502 else:
504 else:
503 base = opts.get('base')
505 base = opts.get('base')
504 if base:
506 if base:
505 if dest:
507 if dest:
506 raise util.Abort(_("--base is incompatible with specifying "
508 raise util.Abort(_("--base is incompatible with specifying "
507 "a destination"))
509 "a destination"))
508 base = [repo.lookup(rev) for rev in base]
510 base = [repo.lookup(rev) for rev in base]
509 # create the right base
511 # create the right base
510 # XXX: nodesbetween / changegroup* should be "fixed" instead
512 # XXX: nodesbetween / changegroup* should be "fixed" instead
511 o = []
513 o = []
512 has = set((nullid,))
514 has = set((nullid,))
513 for n in base:
515 for n in base:
514 has.update(repo.changelog.reachable(n))
516 has.update(repo.changelog.reachable(n))
515 if revs:
517 if revs:
516 visit = list(revs)
518 visit = list(revs)
517 else:
519 else:
518 visit = repo.changelog.heads()
520 visit = repo.changelog.heads()
519 seen = {}
521 seen = {}
520 while visit:
522 while visit:
521 n = visit.pop(0)
523 n = visit.pop(0)
522 parents = [p for p in repo.changelog.parents(n) if p not in has]
524 parents = [p for p in repo.changelog.parents(n) if p not in has]
523 if len(parents) == 0:
525 if len(parents) == 0:
524 o.insert(0, n)
526 o.insert(0, n)
525 else:
527 else:
526 for p in parents:
528 for p in parents:
527 if p not in seen:
529 if p not in seen:
528 seen[p] = 1
530 seen[p] = 1
529 visit.append(p)
531 visit.append(p)
530 else:
532 else:
531 dest, revs, checkout = hg.parseurl(
533 dest, revs, checkout = hg.parseurl(
532 ui.expandpath(dest or 'default-push', dest or 'default'), revs)
534 ui.expandpath(dest or 'default-push', dest or 'default'), revs)
533 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
535 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
534 o = repo.findoutgoing(other, force=opts.get('force'))
536 o = repo.findoutgoing(other, force=opts.get('force'))
535
537
536 if revs:
538 if revs:
537 cg = repo.changegroupsubset(o, revs, 'bundle')
539 cg = repo.changegroupsubset(o, revs, 'bundle')
538 else:
540 else:
539 cg = repo.changegroup(o, 'bundle')
541 cg = repo.changegroup(o, 'bundle')
540
542
541 bundletype = opts.get('type', 'bzip2').lower()
543 bundletype = opts.get('type', 'bzip2').lower()
542 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
544 btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
543 bundletype = btypes.get(bundletype)
545 bundletype = btypes.get(bundletype)
544 if bundletype not in changegroup.bundletypes:
546 if bundletype not in changegroup.bundletypes:
545 raise util.Abort(_('unknown bundle type specified with --type'))
547 raise util.Abort(_('unknown bundle type specified with --type'))
546
548
547 changegroup.writebundle(cg, fname, bundletype)
549 changegroup.writebundle(cg, fname, bundletype)
548
550
549 def cat(ui, repo, file1, *pats, **opts):
551 def cat(ui, repo, file1, *pats, **opts):
550 """output the current or given revision of files
552 """output the current or given revision of files
551
553
552 Print the specified files as they were at the given revision. If
554 Print the specified files as they were at the given revision. If
553 no revision is given, the parent of the working directory is used,
555 no revision is given, the parent of the working directory is used,
554 or tip if no revision is checked out.
556 or tip if no revision is checked out.
555
557
556 Output may be to a file, in which case the name of the file is
558 Output may be to a file, in which case the name of the file is
557 given using a format string. The formatting rules are the same as
559 given using a format string. The formatting rules are the same as
558 for the export command, with the following additions:
560 for the export command, with the following additions:
559
561
560 %s basename of file being printed
562 %s basename of file being printed
561 %d dirname of file being printed, or '.' if in repository root
563 %d dirname of file being printed, or '.' if in repository root
562 %p root-relative path name of file being printed
564 %p root-relative path name of file being printed
563 """
565 """
564 ctx = repo[opts.get('rev')]
566 ctx = repo[opts.get('rev')]
565 err = 1
567 err = 1
566 m = cmdutil.match(repo, (file1,) + pats, opts)
568 m = cmdutil.match(repo, (file1,) + pats, opts)
567 for abs in ctx.walk(m):
569 for abs in ctx.walk(m):
568 fp = cmdutil.make_file(repo, opts.get('output'), ctx.node(), pathname=abs)
570 fp = cmdutil.make_file(repo, opts.get('output'), ctx.node(), pathname=abs)
569 data = ctx[abs].data()
571 data = ctx[abs].data()
570 if opts.get('decode'):
572 if opts.get('decode'):
571 data = repo.wwritedata(abs, data)
573 data = repo.wwritedata(abs, data)
572 fp.write(data)
574 fp.write(data)
573 err = 0
575 err = 0
574 return err
576 return err
575
577
576 def clone(ui, source, dest=None, **opts):
578 def clone(ui, source, dest=None, **opts):
577 """make a copy of an existing repository
579 """make a copy of an existing repository
578
580
579 Create a copy of an existing repository in a new directory.
581 Create a copy of an existing repository in a new directory.
580
582
581 If no destination directory name is specified, it defaults to the
583 If no destination directory name is specified, it defaults to the
582 basename of the source.
584 basename of the source.
583
585
584 The location of the source is added to the new repository's
586 The location of the source is added to the new repository's
585 .hg/hgrc file, as the default to be used for future pulls.
587 .hg/hgrc file, as the default to be used for future pulls.
586
588
587 If you use the -r/--rev option to clone up to a specific revision,
589 If you use the -r/--rev option to clone up to a specific revision,
588 no subsequent revisions (including subsequent tags) will be
590 no subsequent revisions (including subsequent tags) will be
589 present in the cloned repository. This option implies --pull, even
591 present in the cloned repository. This option implies --pull, even
590 on local repositories.
592 on local repositories.
591
593
592 By default, clone will check out the head of the 'default' branch.
594 By default, clone will check out the head of the 'default' branch.
593 If the -U/--noupdate option is used, the new clone will contain
595 If the -U/--noupdate option is used, the new clone will contain
594 only a repository (.hg) and no working copy (the working copy
596 only a repository (.hg) and no working copy (the working copy
595 parent is the null revision).
597 parent is the null revision).
596
598
597 See 'hg help urls' for valid source format details.
599 See 'hg help urls' for valid source format details.
598
600
599 It is possible to specify an ssh:// URL as the destination, but no
601 It is possible to specify an ssh:// URL as the destination, but no
600 .hg/hgrc and working directory will be created on the remote side.
602 .hg/hgrc and working directory will be created on the remote side.
601 Please see 'hg help urls' for important details about ssh:// URLs.
603 Please see 'hg help urls' for important details about ssh:// URLs.
602
604
603 For efficiency, hardlinks are used for cloning whenever the source
605 For efficiency, hardlinks are used for cloning whenever the source
604 and destination are on the same filesystem (note this applies only
606 and destination are on the same filesystem (note this applies only
605 to the repository data, not to the checked out files). Some
607 to the repository data, not to the checked out files). Some
606 filesystems, such as AFS, implement hardlinking incorrectly, but
608 filesystems, such as AFS, implement hardlinking incorrectly, but
607 do not report errors. In these cases, use the --pull option to
609 do not report errors. In these cases, use the --pull option to
608 avoid hardlinking.
610 avoid hardlinking.
609
611
610 In some cases, you can clone repositories and checked out files
612 In some cases, you can clone repositories and checked out files
611 using full hardlinks with
613 using full hardlinks with
612
614
613 $ cp -al REPO REPOCLONE
615 $ cp -al REPO REPOCLONE
614
616
615 This is the fastest way to clone, but it is not always safe. The
617 This is the fastest way to clone, but it is not always safe. The
616 operation is not atomic (making sure REPO is not modified during
618 operation is not atomic (making sure REPO is not modified during
617 the operation is up to you) and you have to make sure your editor
619 the operation is up to you) and you have to make sure your editor
618 breaks hardlinks (Emacs and most Linux Kernel tools do so). Also,
620 breaks hardlinks (Emacs and most Linux Kernel tools do so). Also,
619 this is not compatible with certain extensions that place their
621 this is not compatible with certain extensions that place their
620 metadata under the .hg directory, such as mq.
622 metadata under the .hg directory, such as mq.
621
623
622 """
624 """
623 hg.clone(cmdutil.remoteui(ui, opts), source, dest,
625 hg.clone(cmdutil.remoteui(ui, opts), source, dest,
624 pull=opts.get('pull'),
626 pull=opts.get('pull'),
625 stream=opts.get('uncompressed'),
627 stream=opts.get('uncompressed'),
626 rev=opts.get('rev'),
628 rev=opts.get('rev'),
627 update=not opts.get('noupdate'))
629 update=not opts.get('noupdate'))
628
630
629 def commit(ui, repo, *pats, **opts):
631 def commit(ui, repo, *pats, **opts):
630 """commit the specified files or all outstanding changes
632 """commit the specified files or all outstanding changes
631
633
632 Commit changes to the given files into the repository. Unlike a
634 Commit changes to the given files into the repository. Unlike a
633 centralized RCS, this operation is a local operation. See hg push
635 centralized RCS, this operation is a local operation. See hg push
634 for a way to actively distribute your changes.
636 for a way to actively distribute your changes.
635
637
636 If a list of files is omitted, all changes reported by "hg status"
638 If a list of files is omitted, all changes reported by "hg status"
637 will be committed.
639 will be committed.
638
640
639 If you are committing the result of a merge, do not provide any
641 If you are committing the result of a merge, do not provide any
640 filenames or -I/-X filters.
642 filenames or -I/-X filters.
641
643
642 If no commit message is specified, the configured editor is
644 If no commit message is specified, the configured editor is
643 started to prompt you for a message.
645 started to prompt you for a message.
644
646
645 See 'hg help dates' for a list of formats valid for -d/--date.
647 See 'hg help dates' for a list of formats valid for -d/--date.
646 """
648 """
647 extra = {}
649 extra = {}
648 if opts.get('close_branch'):
650 if opts.get('close_branch'):
649 extra['close'] = 1
651 extra['close'] = 1
650 e = cmdutil.commiteditor
652 e = cmdutil.commiteditor
651 if opts.get('force_editor'):
653 if opts.get('force_editor'):
652 e = cmdutil.commitforceeditor
654 e = cmdutil.commitforceeditor
653
655
654 def commitfunc(ui, repo, message, match, opts):
656 def commitfunc(ui, repo, message, match, opts):
655 return repo.commit(message, opts.get('user'), opts.get('date'), match,
657 return repo.commit(message, opts.get('user'), opts.get('date'), match,
656 editor=e, extra=extra)
658 editor=e, extra=extra)
657
659
658 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
660 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
659 if not node:
661 if not node:
660 return
662 return
661 cl = repo.changelog
663 cl = repo.changelog
662 rev = cl.rev(node)
664 rev = cl.rev(node)
663 parents = cl.parentrevs(rev)
665 parents = cl.parentrevs(rev)
664 if rev - 1 in parents:
666 if rev - 1 in parents:
665 # one of the parents was the old tip
667 # one of the parents was the old tip
666 pass
668 pass
667 elif (parents == (nullrev, nullrev) or
669 elif (parents == (nullrev, nullrev) or
668 len(cl.heads(cl.node(parents[0]))) > 1 and
670 len(cl.heads(cl.node(parents[0]))) > 1 and
669 (parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)):
671 (parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)):
670 ui.status(_('created new head\n'))
672 ui.status(_('created new head\n'))
671
673
672 if ui.debugflag:
674 if ui.debugflag:
673 ui.write(_('committed changeset %d:%s\n') % (rev,hex(node)))
675 ui.write(_('committed changeset %d:%s\n') % (rev,hex(node)))
674 elif ui.verbose:
676 elif ui.verbose:
675 ui.write(_('committed changeset %d:%s\n') % (rev,short(node)))
677 ui.write(_('committed changeset %d:%s\n') % (rev,short(node)))
676
678
677 def copy(ui, repo, *pats, **opts):
679 def copy(ui, repo, *pats, **opts):
678 """mark files as copied for the next commit
680 """mark files as copied for the next commit
679
681
680 Mark dest as having copies of source files. If dest is a
682 Mark dest as having copies of source files. If dest is a
681 directory, copies are put in that directory. If dest is a file,
683 directory, copies are put in that directory. If dest is a file,
682 the source must be a single file.
684 the source must be a single file.
683
685
684 By default, this command copies the contents of files as they
686 By default, this command copies the contents of files as they
685 exist in the working directory. If invoked with -A/--after, the
687 exist in the working directory. If invoked with -A/--after, the
686 operation is recorded, but no copying is performed.
688 operation is recorded, but no copying is performed.
687
689
688 This command takes effect with the next commit. To undo a copy
690 This command takes effect with the next commit. To undo a copy
689 before that, see hg revert.
691 before that, see hg revert.
690 """
692 """
691 wlock = repo.wlock(False)
693 wlock = repo.wlock(False)
692 try:
694 try:
693 return cmdutil.copy(ui, repo, pats, opts)
695 return cmdutil.copy(ui, repo, pats, opts)
694 finally:
696 finally:
695 wlock.release()
697 wlock.release()
696
698
697 def debugancestor(ui, repo, *args):
699 def debugancestor(ui, repo, *args):
698 """find the ancestor revision of two revisions in a given index"""
700 """find the ancestor revision of two revisions in a given index"""
699 if len(args) == 3:
701 if len(args) == 3:
700 index, rev1, rev2 = args
702 index, rev1, rev2 = args
701 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index)
703 r = revlog.revlog(util.opener(os.getcwd(), audit=False), index)
702 lookup = r.lookup
704 lookup = r.lookup
703 elif len(args) == 2:
705 elif len(args) == 2:
704 if not repo:
706 if not repo:
705 raise util.Abort(_("There is no Mercurial repository here "
707 raise util.Abort(_("There is no Mercurial repository here "
706 "(.hg not found)"))
708 "(.hg not found)"))
707 rev1, rev2 = args
709 rev1, rev2 = args
708 r = repo.changelog
710 r = repo.changelog
709 lookup = repo.lookup
711 lookup = repo.lookup
710 else:
712 else:
711 raise util.Abort(_('either two or three arguments required'))
713 raise util.Abort(_('either two or three arguments required'))
712 a = r.ancestor(lookup(rev1), lookup(rev2))
714 a = r.ancestor(lookup(rev1), lookup(rev2))
713 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
715 ui.write("%d:%s\n" % (r.rev(a), hex(a)))
714
716
715 def debugcommands(ui, cmd='', *args):
717 def debugcommands(ui, cmd='', *args):
716 for cmd, vals in sorted(table.iteritems()):
718 for cmd, vals in sorted(table.iteritems()):
717 cmd = cmd.split('|')[0].strip('^')
719 cmd = cmd.split('|')[0].strip('^')
718 opts = ', '.join([i[1] for i in vals[1]])
720 opts = ', '.join([i[1] for i in vals[1]])
719 ui.write('%s: %s\n' % (cmd, opts))
721 ui.write('%s: %s\n' % (cmd, opts))
720
722
721 def debugcomplete(ui, cmd='', **opts):
723 def debugcomplete(ui, cmd='', **opts):
722 """returns the completion list associated with the given command"""
724 """returns the completion list associated with the given command"""
723
725
724 if opts.get('options'):
726 if opts.get('options'):
725 options = []
727 options = []
726 otables = [globalopts]
728 otables = [globalopts]
727 if cmd:
729 if cmd:
728 aliases, entry = cmdutil.findcmd(cmd, table, False)
730 aliases, entry = cmdutil.findcmd(cmd, table, False)
729 otables.append(entry[1])
731 otables.append(entry[1])
730 for t in otables:
732 for t in otables:
731 for o in t:
733 for o in t:
732 if o[0]:
734 if o[0]:
733 options.append('-%s' % o[0])
735 options.append('-%s' % o[0])
734 options.append('--%s' % o[1])
736 options.append('--%s' % o[1])
735 ui.write("%s\n" % "\n".join(options))
737 ui.write("%s\n" % "\n".join(options))
736 return
738 return
737
739
738 cmdlist = cmdutil.findpossible(cmd, table)
740 cmdlist = cmdutil.findpossible(cmd, table)
739 if ui.verbose:
741 if ui.verbose:
740 cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
742 cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
741 ui.write("%s\n" % "\n".join(sorted(cmdlist)))
743 ui.write("%s\n" % "\n".join(sorted(cmdlist)))
742
744
743 def debugfsinfo(ui, path = "."):
745 def debugfsinfo(ui, path = "."):
744 file('.debugfsinfo', 'w').write('')
746 file('.debugfsinfo', 'w').write('')
745 ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no'))
747 ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no'))
746 ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
748 ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
747 ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
749 ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
748 and 'yes' or 'no'))
750 and 'yes' or 'no'))
749 os.unlink('.debugfsinfo')
751 os.unlink('.debugfsinfo')
750
752
751 def debugrebuildstate(ui, repo, rev="tip"):
753 def debugrebuildstate(ui, repo, rev="tip"):
752 """rebuild the dirstate as it would look like for the given revision"""
754 """rebuild the dirstate as it would look like for the given revision"""
753 ctx = repo[rev]
755 ctx = repo[rev]
754 wlock = repo.wlock()
756 wlock = repo.wlock()
755 try:
757 try:
756 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
758 repo.dirstate.rebuild(ctx.node(), ctx.manifest())
757 finally:
759 finally:
758 wlock.release()
760 wlock.release()
759
761
760 def debugcheckstate(ui, repo):
762 def debugcheckstate(ui, repo):
761 """validate the correctness of the current dirstate"""
763 """validate the correctness of the current dirstate"""
762 parent1, parent2 = repo.dirstate.parents()
764 parent1, parent2 = repo.dirstate.parents()
763 m1 = repo[parent1].manifest()
765 m1 = repo[parent1].manifest()
764 m2 = repo[parent2].manifest()
766 m2 = repo[parent2].manifest()
765 errors = 0
767 errors = 0
766 for f in repo.dirstate:
768 for f in repo.dirstate:
767 state = repo.dirstate[f]
769 state = repo.dirstate[f]
768 if state in "nr" and f not in m1:
770 if state in "nr" and f not in m1:
769 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
771 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
770 errors += 1
772 errors += 1
771 if state in "a" and f in m1:
773 if state in "a" and f in m1:
772 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
774 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
773 errors += 1
775 errors += 1
774 if state in "m" and f not in m1 and f not in m2:
776 if state in "m" and f not in m1 and f not in m2:
775 ui.warn(_("%s in state %s, but not in either manifest\n") %
777 ui.warn(_("%s in state %s, but not in either manifest\n") %
776 (f, state))
778 (f, state))
777 errors += 1
779 errors += 1
778 for f in m1:
780 for f in m1:
779 state = repo.dirstate[f]
781 state = repo.dirstate[f]
780 if state not in "nrm":
782 if state not in "nrm":
781 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
783 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
782 errors += 1
784 errors += 1
783 if errors:
785 if errors:
784 error = _(".hg/dirstate inconsistent with current parent's manifest")
786 error = _(".hg/dirstate inconsistent with current parent's manifest")
785 raise util.Abort(error)
787 raise util.Abort(error)
786
788
787 def showconfig(ui, repo, *values, **opts):
789 def showconfig(ui, repo, *values, **opts):
788 """show combined config settings from all hgrc files
790 """show combined config settings from all hgrc files
789
791
790 With no arguments, print names and values of all config items.
792 With no arguments, print names and values of all config items.
791
793
792 With one argument of the form section.name, print just the value
794 With one argument of the form section.name, print just the value
793 of that config item.
795 of that config item.
794
796
795 With multiple arguments, print names and values of all config
797 With multiple arguments, print names and values of all config
796 items with matching section names.
798 items with matching section names.
797
799
798 With --debug, the source (filename and line number) is printed
800 With --debug, the source (filename and line number) is printed
799 for each config item.
801 for each config item.
800 """
802 """
801
803
802 untrusted = bool(opts.get('untrusted'))
804 untrusted = bool(opts.get('untrusted'))
803 if values:
805 if values:
804 if len([v for v in values if '.' in v]) > 1:
806 if len([v for v in values if '.' in v]) > 1:
805 raise util.Abort(_('only one config item permitted'))
807 raise util.Abort(_('only one config item permitted'))
806 for section, name, value in ui.walkconfig(untrusted=untrusted):
808 for section, name, value in ui.walkconfig(untrusted=untrusted):
807 sectname = section + '.' + name
809 sectname = section + '.' + name
808 if values:
810 if values:
809 for v in values:
811 for v in values:
810 if v == section:
812 if v == section:
811 ui.debug('%s: ' %
813 ui.debug('%s: ' %
812 ui.configsource(section, name, untrusted))
814 ui.configsource(section, name, untrusted))
813 ui.write('%s=%s\n' % (sectname, value))
815 ui.write('%s=%s\n' % (sectname, value))
814 elif v == sectname:
816 elif v == sectname:
815 ui.debug('%s: ' %
817 ui.debug('%s: ' %
816 ui.configsource(section, name, untrusted))
818 ui.configsource(section, name, untrusted))
817 ui.write(value, '\n')
819 ui.write(value, '\n')
818 else:
820 else:
819 ui.debug('%s: ' %
821 ui.debug('%s: ' %
820 ui.configsource(section, name, untrusted))
822 ui.configsource(section, name, untrusted))
821 ui.write('%s=%s\n' % (sectname, value))
823 ui.write('%s=%s\n' % (sectname, value))
822
824
823 def debugsetparents(ui, repo, rev1, rev2=None):
825 def debugsetparents(ui, repo, rev1, rev2=None):
824 """manually set the parents of the current working directory
826 """manually set the parents of the current working directory
825
827
826 This is useful for writing repository conversion tools, but should
828 This is useful for writing repository conversion tools, but should
827 be used with care.
829 be used with care.
828 """
830 """
829
831
830 if not rev2:
832 if not rev2:
831 rev2 = hex(nullid)
833 rev2 = hex(nullid)
832
834
833 wlock = repo.wlock()
835 wlock = repo.wlock()
834 try:
836 try:
835 repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
837 repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
836 finally:
838 finally:
837 wlock.release()
839 wlock.release()
838
840
839 def debugstate(ui, repo, nodates=None):
841 def debugstate(ui, repo, nodates=None):
840 """show the contents of the current dirstate"""
842 """show the contents of the current dirstate"""
841 timestr = ""
843 timestr = ""
842 showdate = not nodates
844 showdate = not nodates
843 for file_, ent in sorted(repo.dirstate._map.iteritems()):
845 for file_, ent in sorted(repo.dirstate._map.iteritems()):
844 if showdate:
846 if showdate:
845 if ent[3] == -1:
847 if ent[3] == -1:
846 # Pad or slice to locale representation
848 # Pad or slice to locale representation
847 locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(0)))
849 locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(0)))
848 timestr = 'unset'
850 timestr = 'unset'
849 timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr))
851 timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr))
850 else:
852 else:
851 timestr = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(ent[3]))
853 timestr = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(ent[3]))
852 if ent[1] & 020000:
854 if ent[1] & 020000:
853 mode = 'lnk'
855 mode = 'lnk'
854 else:
856 else:
855 mode = '%3o' % (ent[1] & 0777)
857 mode = '%3o' % (ent[1] & 0777)
856 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
858 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
857 for f in repo.dirstate.copies():
859 for f in repo.dirstate.copies():
858 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
860 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
859
861
860 def debugsub(ui, repo, rev=None):
862 def debugsub(ui, repo, rev=None):
861 if rev == '':
863 if rev == '':
862 rev = None
864 rev = None
863 for k,v in sorted(repo[rev].substate.items()):
865 for k,v in sorted(repo[rev].substate.items()):
864 ui.write('path %s\n' % k)
866 ui.write('path %s\n' % k)
865 ui.write(' source %s\n' % v[0])
867 ui.write(' source %s\n' % v[0])
866 ui.write(' revision %s\n' % v[1])
868 ui.write(' revision %s\n' % v[1])
867
869
868 def debugdata(ui, file_, rev):
870 def debugdata(ui, file_, rev):
869 """dump the contents of a data file revision"""
871 """dump the contents of a data file revision"""
870 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i")
872 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i")
871 try:
873 try:
872 ui.write(r.revision(r.lookup(rev)))
874 ui.write(r.revision(r.lookup(rev)))
873 except KeyError:
875 except KeyError:
874 raise util.Abort(_('invalid revision identifier %s') % rev)
876 raise util.Abort(_('invalid revision identifier %s') % rev)
875
877
876 def debugdate(ui, date, range=None, **opts):
878 def debugdate(ui, date, range=None, **opts):
877 """parse and display a date"""
879 """parse and display a date"""
878 if opts["extended"]:
880 if opts["extended"]:
879 d = util.parsedate(date, util.extendeddateformats)
881 d = util.parsedate(date, util.extendeddateformats)
880 else:
882 else:
881 d = util.parsedate(date)
883 d = util.parsedate(date)
882 ui.write("internal: %s %s\n" % d)
884 ui.write("internal: %s %s\n" % d)
883 ui.write("standard: %s\n" % util.datestr(d))
885 ui.write("standard: %s\n" % util.datestr(d))
884 if range:
886 if range:
885 m = util.matchdate(range)
887 m = util.matchdate(range)
886 ui.write("match: %s\n" % m(d[0]))
888 ui.write("match: %s\n" % m(d[0]))
887
889
888 def debugindex(ui, file_):
890 def debugindex(ui, file_):
889 """dump the contents of an index file"""
891 """dump the contents of an index file"""
890 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
892 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
891 ui.write(" rev offset length base linkrev"
893 ui.write(" rev offset length base linkrev"
892 " nodeid p1 p2\n")
894 " nodeid p1 p2\n")
893 for i in r:
895 for i in r:
894 node = r.node(i)
896 node = r.node(i)
895 try:
897 try:
896 pp = r.parents(node)
898 pp = r.parents(node)
897 except:
899 except:
898 pp = [nullid, nullid]
900 pp = [nullid, nullid]
899 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
901 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
900 i, r.start(i), r.length(i), r.base(i), r.linkrev(i),
902 i, r.start(i), r.length(i), r.base(i), r.linkrev(i),
901 short(node), short(pp[0]), short(pp[1])))
903 short(node), short(pp[0]), short(pp[1])))
902
904
903 def debugindexdot(ui, file_):
905 def debugindexdot(ui, file_):
904 """dump an index DAG as a graphviz dot file"""
906 """dump an index DAG as a graphviz dot file"""
905 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
907 r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_)
906 ui.write("digraph G {\n")
908 ui.write("digraph G {\n")
907 for i in r:
909 for i in r:
908 node = r.node(i)
910 node = r.node(i)
909 pp = r.parents(node)
911 pp = r.parents(node)
910 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
912 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
911 if pp[1] != nullid:
913 if pp[1] != nullid:
912 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
914 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
913 ui.write("}\n")
915 ui.write("}\n")
914
916
915 def debuginstall(ui):
917 def debuginstall(ui):
916 '''test Mercurial installation'''
918 '''test Mercurial installation'''
917
919
918 def writetemp(contents):
920 def writetemp(contents):
919 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
921 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
920 f = os.fdopen(fd, "wb")
922 f = os.fdopen(fd, "wb")
921 f.write(contents)
923 f.write(contents)
922 f.close()
924 f.close()
923 return name
925 return name
924
926
925 problems = 0
927 problems = 0
926
928
927 # encoding
929 # encoding
928 ui.status(_("Checking encoding (%s)...\n") % encoding.encoding)
930 ui.status(_("Checking encoding (%s)...\n") % encoding.encoding)
929 try:
931 try:
930 encoding.fromlocal("test")
932 encoding.fromlocal("test")
931 except util.Abort, inst:
933 except util.Abort, inst:
932 ui.write(" %s\n" % inst)
934 ui.write(" %s\n" % inst)
933 ui.write(_(" (check that your locale is properly set)\n"))
935 ui.write(_(" (check that your locale is properly set)\n"))
934 problems += 1
936 problems += 1
935
937
936 # compiled modules
938 # compiled modules
937 ui.status(_("Checking extensions...\n"))
939 ui.status(_("Checking extensions...\n"))
938 try:
940 try:
939 import bdiff, mpatch, base85
941 import bdiff, mpatch, base85
940 except Exception, inst:
942 except Exception, inst:
941 ui.write(" %s\n" % inst)
943 ui.write(" %s\n" % inst)
942 ui.write(_(" One or more extensions could not be found"))
944 ui.write(_(" One or more extensions could not be found"))
943 ui.write(_(" (check that you compiled the extensions)\n"))
945 ui.write(_(" (check that you compiled the extensions)\n"))
944 problems += 1
946 problems += 1
945
947
946 # templates
948 # templates
947 ui.status(_("Checking templates...\n"))
949 ui.status(_("Checking templates...\n"))
948 try:
950 try:
949 import templater
951 import templater
950 templater.templater(templater.templatepath("map-cmdline.default"))
952 templater.templater(templater.templatepath("map-cmdline.default"))
951 except Exception, inst:
953 except Exception, inst:
952 ui.write(" %s\n" % inst)
954 ui.write(" %s\n" % inst)
953 ui.write(_(" (templates seem to have been installed incorrectly)\n"))
955 ui.write(_(" (templates seem to have been installed incorrectly)\n"))
954 problems += 1
956 problems += 1
955
957
956 # patch
958 # patch
957 ui.status(_("Checking patch...\n"))
959 ui.status(_("Checking patch...\n"))
958 patchproblems = 0
960 patchproblems = 0
959 a = "1\n2\n3\n4\n"
961 a = "1\n2\n3\n4\n"
960 b = "1\n2\n3\ninsert\n4\n"
962 b = "1\n2\n3\ninsert\n4\n"
961 fa = writetemp(a)
963 fa = writetemp(a)
962 d = mdiff.unidiff(a, None, b, None, os.path.basename(fa),
964 d = mdiff.unidiff(a, None, b, None, os.path.basename(fa),
963 os.path.basename(fa))
965 os.path.basename(fa))
964 fd = writetemp(d)
966 fd = writetemp(d)
965
967
966 files = {}
968 files = {}
967 try:
969 try:
968 patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files)
970 patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files)
969 except util.Abort, e:
971 except util.Abort, e:
970 ui.write(_(" patch call failed:\n"))
972 ui.write(_(" patch call failed:\n"))
971 ui.write(" " + str(e) + "\n")
973 ui.write(" " + str(e) + "\n")
972 patchproblems += 1
974 patchproblems += 1
973 else:
975 else:
974 if list(files) != [os.path.basename(fa)]:
976 if list(files) != [os.path.basename(fa)]:
975 ui.write(_(" unexpected patch output!\n"))
977 ui.write(_(" unexpected patch output!\n"))
976 patchproblems += 1
978 patchproblems += 1
977 a = file(fa).read()
979 a = file(fa).read()
978 if a != b:
980 if a != b:
979 ui.write(_(" patch test failed!\n"))
981 ui.write(_(" patch test failed!\n"))
980 patchproblems += 1
982 patchproblems += 1
981
983
982 if patchproblems:
984 if patchproblems:
983 if ui.config('ui', 'patch'):
985 if ui.config('ui', 'patch'):
984 ui.write(_(" (Current patch tool may be incompatible with patch,"
986 ui.write(_(" (Current patch tool may be incompatible with patch,"
985 " or misconfigured. Please check your .hgrc file)\n"))
987 " or misconfigured. Please check your .hgrc file)\n"))
986 else:
988 else:
987 ui.write(_(" Internal patcher failure, please report this error"
989 ui.write(_(" Internal patcher failure, please report this error"
988 " to http://www.selenic.com/mercurial/bts\n"))
990 " to http://www.selenic.com/mercurial/bts\n"))
989 problems += patchproblems
991 problems += patchproblems
990
992
991 os.unlink(fa)
993 os.unlink(fa)
992 os.unlink(fd)
994 os.unlink(fd)
993
995
994 # editor
996 # editor
995 ui.status(_("Checking commit editor...\n"))
997 ui.status(_("Checking commit editor...\n"))
996 editor = ui.geteditor()
998 editor = ui.geteditor()
997 cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
999 cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0])
998 if not cmdpath:
1000 if not cmdpath:
999 if editor == 'vi':
1001 if editor == 'vi':
1000 ui.write(_(" No commit editor set and can't find vi in PATH\n"))
1002 ui.write(_(" No commit editor set and can't find vi in PATH\n"))
1001 ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
1003 ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
1002 else:
1004 else:
1003 ui.write(_(" Can't find editor '%s' in PATH\n") % editor)
1005 ui.write(_(" Can't find editor '%s' in PATH\n") % editor)
1004 ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
1006 ui.write(_(" (specify a commit editor in your .hgrc file)\n"))
1005 problems += 1
1007 problems += 1
1006
1008
1007 # check username
1009 # check username
1008 ui.status(_("Checking username...\n"))
1010 ui.status(_("Checking username...\n"))
1009 user = os.environ.get("HGUSER")
1011 user = os.environ.get("HGUSER")
1010 if user is None:
1012 if user is None:
1011 user = ui.config("ui", "username")
1013 user = ui.config("ui", "username")
1012 if user is None:
1014 if user is None:
1013 user = os.environ.get("EMAIL")
1015 user = os.environ.get("EMAIL")
1014 if not user:
1016 if not user:
1015 ui.warn(" ")
1017 ui.warn(" ")
1016 ui.username()
1018 ui.username()
1017 ui.write(_(" (specify a username in your .hgrc file)\n"))
1019 ui.write(_(" (specify a username in your .hgrc file)\n"))
1018
1020
1019 if not problems:
1021 if not problems:
1020 ui.status(_("No problems detected\n"))
1022 ui.status(_("No problems detected\n"))
1021 else:
1023 else:
1022 ui.write(_("%s problems detected,"
1024 ui.write(_("%s problems detected,"
1023 " please check your install!\n") % problems)
1025 " please check your install!\n") % problems)
1024
1026
1025 return problems
1027 return problems
1026
1028
1027 def debugrename(ui, repo, file1, *pats, **opts):
1029 def debugrename(ui, repo, file1, *pats, **opts):
1028 """dump rename information"""
1030 """dump rename information"""
1029
1031
1030 ctx = repo[opts.get('rev')]
1032 ctx = repo[opts.get('rev')]
1031 m = cmdutil.match(repo, (file1,) + pats, opts)
1033 m = cmdutil.match(repo, (file1,) + pats, opts)
1032 for abs in ctx.walk(m):
1034 for abs in ctx.walk(m):
1033 fctx = ctx[abs]
1035 fctx = ctx[abs]
1034 o = fctx.filelog().renamed(fctx.filenode())
1036 o = fctx.filelog().renamed(fctx.filenode())
1035 rel = m.rel(abs)
1037 rel = m.rel(abs)
1036 if o:
1038 if o:
1037 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
1039 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
1038 else:
1040 else:
1039 ui.write(_("%s not renamed\n") % rel)
1041 ui.write(_("%s not renamed\n") % rel)
1040
1042
1041 def debugwalk(ui, repo, *pats, **opts):
1043 def debugwalk(ui, repo, *pats, **opts):
1042 """show how files match on given patterns"""
1044 """show how files match on given patterns"""
1043 m = cmdutil.match(repo, pats, opts)
1045 m = cmdutil.match(repo, pats, opts)
1044 items = list(repo.walk(m))
1046 items = list(repo.walk(m))
1045 if not items:
1047 if not items:
1046 return
1048 return
1047 fmt = 'f %%-%ds %%-%ds %%s' % (
1049 fmt = 'f %%-%ds %%-%ds %%s' % (
1048 max([len(abs) for abs in items]),
1050 max([len(abs) for abs in items]),
1049 max([len(m.rel(abs)) for abs in items]))
1051 max([len(m.rel(abs)) for abs in items]))
1050 for abs in items:
1052 for abs in items:
1051 line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '')
1053 line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '')
1052 ui.write("%s\n" % line.rstrip())
1054 ui.write("%s\n" % line.rstrip())
1053
1055
1054 def diff(ui, repo, *pats, **opts):
1056 def diff(ui, repo, *pats, **opts):
1055 """diff repository (or selected files)
1057 """diff repository (or selected files)
1056
1058
1057 Show differences between revisions for the specified files.
1059 Show differences between revisions for the specified files.
1058
1060
1059 Differences between files are shown using the unified diff format.
1061 Differences between files are shown using the unified diff format.
1060
1062
1061 NOTE: diff may generate unexpected results for merges, as it will
1063 NOTE: diff may generate unexpected results for merges, as it will
1062 default to comparing against the working directory's first parent
1064 default to comparing against the working directory's first parent
1063 changeset if no revisions are specified.
1065 changeset if no revisions are specified.
1064
1066
1065 When two revision arguments are given, then changes are shown
1067 When two revision arguments are given, then changes are shown
1066 between those revisions. If only one revision is specified then
1068 between those revisions. If only one revision is specified then
1067 that revision is compared to the working directory, and, when no
1069 that revision is compared to the working directory, and, when no
1068 revisions are specified, the working directory files are compared
1070 revisions are specified, the working directory files are compared
1069 to its parent.
1071 to its parent.
1070
1072
1071 Without the -a/--text option, diff will avoid generating diffs of
1073 Without the -a/--text option, diff will avoid generating diffs of
1072 files it detects as binary. With -a, diff will generate a diff
1074 files it detects as binary. With -a, diff will generate a diff
1073 anyway, probably with undesirable results.
1075 anyway, probably with undesirable results.
1074
1076
1075 Use the -g/--git option to generate diffs in the git extended diff
1077 Use the -g/--git option to generate diffs in the git extended diff
1076 format. For more information, read 'hg help diffs'.
1078 format. For more information, read 'hg help diffs'.
1077 """
1079 """
1078
1080
1079 revs = opts.get('rev')
1081 revs = opts.get('rev')
1080 change = opts.get('change')
1082 change = opts.get('change')
1081
1083
1082 if revs and change:
1084 if revs and change:
1083 msg = _('cannot specify --rev and --change at the same time')
1085 msg = _('cannot specify --rev and --change at the same time')
1084 raise util.Abort(msg)
1086 raise util.Abort(msg)
1085 elif change:
1087 elif change:
1086 node2 = repo.lookup(change)
1088 node2 = repo.lookup(change)
1087 node1 = repo[node2].parents()[0].node()
1089 node1 = repo[node2].parents()[0].node()
1088 else:
1090 else:
1089 node1, node2 = cmdutil.revpair(repo, revs)
1091 node1, node2 = cmdutil.revpair(repo, revs)
1090
1092
1091 m = cmdutil.match(repo, pats, opts)
1093 m = cmdutil.match(repo, pats, opts)
1092 it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
1094 it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
1093 for chunk in it:
1095 for chunk in it:
1094 ui.write(chunk)
1096 ui.write(chunk)
1095
1097
1096 def export(ui, repo, *changesets, **opts):
1098 def export(ui, repo, *changesets, **opts):
1097 """dump the header and diffs for one or more changesets
1099 """dump the header and diffs for one or more changesets
1098
1100
1099 Print the changeset header and diffs for one or more revisions.
1101 Print the changeset header and diffs for one or more revisions.
1100
1102
1101 The information shown in the changeset header is: author,
1103 The information shown in the changeset header is: author,
1102 changeset hash, parent(s) and commit comment.
1104 changeset hash, parent(s) and commit comment.
1103
1105
1104 NOTE: export may generate unexpected diff output for merge
1106 NOTE: export may generate unexpected diff output for merge
1105 changesets, as it will compare the merge changeset against its
1107 changesets, as it will compare the merge changeset against its
1106 first parent only.
1108 first parent only.
1107
1109
1108 Output may be to a file, in which case the name of the file is
1110 Output may be to a file, in which case the name of the file is
1109 given using a format string. The formatting rules are as follows:
1111 given using a format string. The formatting rules are as follows:
1110
1112
1111 %% literal "%" character
1113 %% literal "%" character
1112 %H changeset hash (40 bytes of hexadecimal)
1114 %H changeset hash (40 bytes of hexadecimal)
1113 %N number of patches being generated
1115 %N number of patches being generated
1114 %R changeset revision number
1116 %R changeset revision number
1115 %b basename of the exporting repository
1117 %b basename of the exporting repository
1116 %h short-form changeset hash (12 bytes of hexadecimal)
1118 %h short-form changeset hash (12 bytes of hexadecimal)
1117 %n zero-padded sequence number, starting at 1
1119 %n zero-padded sequence number, starting at 1
1118 %r zero-padded changeset revision number
1120 %r zero-padded changeset revision number
1119
1121
1120 Without the -a/--text option, export will avoid generating diffs
1122 Without the -a/--text option, export will avoid generating diffs
1121 of files it detects as binary. With -a, export will generate a
1123 of files it detects as binary. With -a, export will generate a
1122 diff anyway, probably with undesirable results.
1124 diff anyway, probably with undesirable results.
1123
1125
1124 Use the -g/--git option to generate diffs in the git extended diff
1126 Use the -g/--git option to generate diffs in the git extended diff
1125 format. See 'hg help diffs' for more information.
1127 format. See 'hg help diffs' for more information.
1126
1128
1127 With the --switch-parent option, the diff will be against the
1129 With the --switch-parent option, the diff will be against the
1128 second parent. It can be useful to review a merge.
1130 second parent. It can be useful to review a merge.
1129 """
1131 """
1130 if not changesets:
1132 if not changesets:
1131 raise util.Abort(_("export requires at least one changeset"))
1133 raise util.Abort(_("export requires at least one changeset"))
1132 revs = cmdutil.revrange(repo, changesets)
1134 revs = cmdutil.revrange(repo, changesets)
1133 if len(revs) > 1:
1135 if len(revs) > 1:
1134 ui.note(_('exporting patches:\n'))
1136 ui.note(_('exporting patches:\n'))
1135 else:
1137 else:
1136 ui.note(_('exporting patch:\n'))
1138 ui.note(_('exporting patch:\n'))
1137 patch.export(repo, revs, template=opts.get('output'),
1139 patch.export(repo, revs, template=opts.get('output'),
1138 switch_parent=opts.get('switch_parent'),
1140 switch_parent=opts.get('switch_parent'),
1139 opts=patch.diffopts(ui, opts))
1141 opts=patch.diffopts(ui, opts))
1140
1142
1141 def forget(ui, repo, *pats, **opts):
1143 def forget(ui, repo, *pats, **opts):
1142 """forget the specified files on the next commit
1144 """forget the specified files on the next commit
1143
1145
1144 Mark the specified files so they will no longer be tracked
1146 Mark the specified files so they will no longer be tracked
1145 after the next commit.
1147 after the next commit.
1146
1148
1147 This only removes files from the current branch, not from the
1149 This only removes files from the current branch, not from the
1148 entire project history, and it does not delete them from the
1150 entire project history, and it does not delete them from the
1149 working directory.
1151 working directory.
1150
1152
1151 To undo a forget before the next commit, see hg add.
1153 To undo a forget before the next commit, see hg add.
1152 """
1154 """
1153
1155
1154 if not pats:
1156 if not pats:
1155 raise util.Abort(_('no files specified'))
1157 raise util.Abort(_('no files specified'))
1156
1158
1157 m = cmdutil.match(repo, pats, opts)
1159 m = cmdutil.match(repo, pats, opts)
1158 s = repo.status(match=m, clean=True)
1160 s = repo.status(match=m, clean=True)
1159 forget = sorted(s[0] + s[1] + s[3] + s[6])
1161 forget = sorted(s[0] + s[1] + s[3] + s[6])
1160
1162
1161 for f in m.files():
1163 for f in m.files():
1162 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
1164 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
1163 ui.warn(_('not removing %s: file is already untracked\n')
1165 ui.warn(_('not removing %s: file is already untracked\n')
1164 % m.rel(f))
1166 % m.rel(f))
1165
1167
1166 for f in forget:
1168 for f in forget:
1167 if ui.verbose or not m.exact(f):
1169 if ui.verbose or not m.exact(f):
1168 ui.status(_('removing %s\n') % m.rel(f))
1170 ui.status(_('removing %s\n') % m.rel(f))
1169
1171
1170 repo.remove(forget, unlink=False)
1172 repo.remove(forget, unlink=False)
1171
1173
1172 def grep(ui, repo, pattern, *pats, **opts):
1174 def grep(ui, repo, pattern, *pats, **opts):
1173 """search for a pattern in specified files and revisions
1175 """search for a pattern in specified files and revisions
1174
1176
1175 Search revisions of files for a regular expression.
1177 Search revisions of files for a regular expression.
1176
1178
1177 This command behaves differently than Unix grep. It only accepts
1179 This command behaves differently than Unix grep. It only accepts
1178 Python/Perl regexps. It searches repository history, not the
1180 Python/Perl regexps. It searches repository history, not the
1179 working directory. It always prints the revision number in which a
1181 working directory. It always prints the revision number in which a
1180 match appears.
1182 match appears.
1181
1183
1182 By default, grep only prints output for the first revision of a
1184 By default, grep only prints output for the first revision of a
1183 file in which it finds a match. To get it to print every revision
1185 file in which it finds a match. To get it to print every revision
1184 that contains a change in match status ("-" for a match that
1186 that contains a change in match status ("-" for a match that
1185 becomes a non-match, or "+" for a non-match that becomes a match),
1187 becomes a non-match, or "+" for a non-match that becomes a match),
1186 use the --all flag.
1188 use the --all flag.
1187 """
1189 """
1188 reflags = 0
1190 reflags = 0
1189 if opts.get('ignore_case'):
1191 if opts.get('ignore_case'):
1190 reflags |= re.I
1192 reflags |= re.I
1191 try:
1193 try:
1192 regexp = re.compile(pattern, reflags)
1194 regexp = re.compile(pattern, reflags)
1193 except Exception, inst:
1195 except Exception, inst:
1194 ui.warn(_("grep: invalid match pattern: %s\n") % inst)
1196 ui.warn(_("grep: invalid match pattern: %s\n") % inst)
1195 return None
1197 return None
1196 sep, eol = ':', '\n'
1198 sep, eol = ':', '\n'
1197 if opts.get('print0'):
1199 if opts.get('print0'):
1198 sep = eol = '\0'
1200 sep = eol = '\0'
1199
1201
1200 fcache = {}
1202 fcache = {}
1201 forder = []
1203 forder = []
1202 def getfile(fn):
1204 def getfile(fn):
1203 if fn not in fcache:
1205 if fn not in fcache:
1204 if len(fcache) > 20:
1206 if len(fcache) > 20:
1205 del fcache[forder.pop(0)]
1207 del fcache[forder.pop(0)]
1206 fcache[fn] = repo.file(fn)
1208 fcache[fn] = repo.file(fn)
1207 else:
1209 else:
1208 forder.remove(fn)
1210 forder.remove(fn)
1209
1211
1210 forder.append(fn)
1212 forder.append(fn)
1211 return fcache[fn]
1213 return fcache[fn]
1212
1214
1213 def matchlines(body):
1215 def matchlines(body):
1214 begin = 0
1216 begin = 0
1215 linenum = 0
1217 linenum = 0
1216 while True:
1218 while True:
1217 match = regexp.search(body, begin)
1219 match = regexp.search(body, begin)
1218 if not match:
1220 if not match:
1219 break
1221 break
1220 mstart, mend = match.span()
1222 mstart, mend = match.span()
1221 linenum += body.count('\n', begin, mstart) + 1
1223 linenum += body.count('\n', begin, mstart) + 1
1222 lstart = body.rfind('\n', begin, mstart) + 1 or begin
1224 lstart = body.rfind('\n', begin, mstart) + 1 or begin
1223 begin = body.find('\n', mend) + 1 or len(body)
1225 begin = body.find('\n', mend) + 1 or len(body)
1224 lend = begin - 1
1226 lend = begin - 1
1225 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
1227 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
1226
1228
1227 class linestate(object):
1229 class linestate(object):
1228 def __init__(self, line, linenum, colstart, colend):
1230 def __init__(self, line, linenum, colstart, colend):
1229 self.line = line
1231 self.line = line
1230 self.linenum = linenum
1232 self.linenum = linenum
1231 self.colstart = colstart
1233 self.colstart = colstart
1232 self.colend = colend
1234 self.colend = colend
1233
1235
1234 def __hash__(self):
1236 def __hash__(self):
1235 return hash((self.linenum, self.line))
1237 return hash((self.linenum, self.line))
1236
1238
1237 def __eq__(self, other):
1239 def __eq__(self, other):
1238 return self.line == other.line
1240 return self.line == other.line
1239
1241
1240 matches = {}
1242 matches = {}
1241 copies = {}
1243 copies = {}
1242 def grepbody(fn, rev, body):
1244 def grepbody(fn, rev, body):
1243 matches[rev].setdefault(fn, [])
1245 matches[rev].setdefault(fn, [])
1244 m = matches[rev][fn]
1246 m = matches[rev][fn]
1245 for lnum, cstart, cend, line in matchlines(body):
1247 for lnum, cstart, cend, line in matchlines(body):
1246 s = linestate(line, lnum, cstart, cend)
1248 s = linestate(line, lnum, cstart, cend)
1247 m.append(s)
1249 m.append(s)
1248
1250
1249 def difflinestates(a, b):
1251 def difflinestates(a, b):
1250 sm = difflib.SequenceMatcher(None, a, b)
1252 sm = difflib.SequenceMatcher(None, a, b)
1251 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
1253 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
1252 if tag == 'insert':
1254 if tag == 'insert':
1253 for i in xrange(blo, bhi):
1255 for i in xrange(blo, bhi):
1254 yield ('+', b[i])
1256 yield ('+', b[i])
1255 elif tag == 'delete':
1257 elif tag == 'delete':
1256 for i in xrange(alo, ahi):
1258 for i in xrange(alo, ahi):
1257 yield ('-', a[i])
1259 yield ('-', a[i])
1258 elif tag == 'replace':
1260 elif tag == 'replace':
1259 for i in xrange(alo, ahi):
1261 for i in xrange(alo, ahi):
1260 yield ('-', a[i])
1262 yield ('-', a[i])
1261 for i in xrange(blo, bhi):
1263 for i in xrange(blo, bhi):
1262 yield ('+', b[i])
1264 yield ('+', b[i])
1263
1265
1264 def display(fn, r, pstates, states):
1266 def display(fn, r, pstates, states):
1265 datefunc = ui.quiet and util.shortdate or util.datestr
1267 datefunc = ui.quiet and util.shortdate or util.datestr
1266 found = False
1268 found = False
1267 filerevmatches = {}
1269 filerevmatches = {}
1268 if opts.get('all'):
1270 if opts.get('all'):
1269 iter = difflinestates(pstates, states)
1271 iter = difflinestates(pstates, states)
1270 else:
1272 else:
1271 iter = [('', l) for l in states]
1273 iter = [('', l) for l in states]
1272 for change, l in iter:
1274 for change, l in iter:
1273 cols = [fn, str(r)]
1275 cols = [fn, str(r)]
1274 if opts.get('line_number'):
1276 if opts.get('line_number'):
1275 cols.append(str(l.linenum))
1277 cols.append(str(l.linenum))
1276 if opts.get('all'):
1278 if opts.get('all'):
1277 cols.append(change)
1279 cols.append(change)
1278 if opts.get('user'):
1280 if opts.get('user'):
1279 cols.append(ui.shortuser(get(r)[1]))
1281 cols.append(ui.shortuser(get(r)[1]))
1280 if opts.get('date'):
1282 if opts.get('date'):
1281 cols.append(datefunc(get(r)[2]))
1283 cols.append(datefunc(get(r)[2]))
1282 if opts.get('files_with_matches'):
1284 if opts.get('files_with_matches'):
1283 c = (fn, r)
1285 c = (fn, r)
1284 if c in filerevmatches:
1286 if c in filerevmatches:
1285 continue
1287 continue
1286 filerevmatches[c] = 1
1288 filerevmatches[c] = 1
1287 else:
1289 else:
1288 cols.append(l.line)
1290 cols.append(l.line)
1289 ui.write(sep.join(cols), eol)
1291 ui.write(sep.join(cols), eol)
1290 found = True
1292 found = True
1291 return found
1293 return found
1292
1294
1293 skip = {}
1295 skip = {}
1294 revfiles = {}
1296 revfiles = {}
1295 get = util.cachefunc(lambda r: repo[r].changeset())
1297 get = util.cachefunc(lambda r: repo[r].changeset())
1296 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1298 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1297 found = False
1299 found = False
1298 follow = opts.get('follow')
1300 follow = opts.get('follow')
1299 for st, rev, fns in changeiter:
1301 for st, rev, fns in changeiter:
1300 if st == 'window':
1302 if st == 'window':
1301 matches.clear()
1303 matches.clear()
1302 revfiles.clear()
1304 revfiles.clear()
1303 elif st == 'add':
1305 elif st == 'add':
1304 ctx = repo[rev]
1306 ctx = repo[rev]
1305 pctx = ctx.parents()[0]
1307 pctx = ctx.parents()[0]
1306 parent = pctx.rev()
1308 parent = pctx.rev()
1307 matches.setdefault(rev, {})
1309 matches.setdefault(rev, {})
1308 matches.setdefault(parent, {})
1310 matches.setdefault(parent, {})
1309 files = revfiles.setdefault(rev, [])
1311 files = revfiles.setdefault(rev, [])
1310 for fn in fns:
1312 for fn in fns:
1311 flog = getfile(fn)
1313 flog = getfile(fn)
1312 try:
1314 try:
1313 fnode = ctx.filenode(fn)
1315 fnode = ctx.filenode(fn)
1314 except error.LookupError:
1316 except error.LookupError:
1315 continue
1317 continue
1316
1318
1317 copied = flog.renamed(fnode)
1319 copied = flog.renamed(fnode)
1318 copy = follow and copied and copied[0]
1320 copy = follow and copied and copied[0]
1319 if copy:
1321 if copy:
1320 copies.setdefault(rev, {})[fn] = copy
1322 copies.setdefault(rev, {})[fn] = copy
1321 if fn in skip:
1323 if fn in skip:
1322 if copy:
1324 if copy:
1323 skip[copy] = True
1325 skip[copy] = True
1324 continue
1326 continue
1325 files.append(fn)
1327 files.append(fn)
1326
1328
1327 if not matches[rev].has_key(fn):
1329 if not matches[rev].has_key(fn):
1328 grepbody(fn, rev, flog.read(fnode))
1330 grepbody(fn, rev, flog.read(fnode))
1329
1331
1330 pfn = copy or fn
1332 pfn = copy or fn
1331 if not matches[parent].has_key(pfn):
1333 if not matches[parent].has_key(pfn):
1332 try:
1334 try:
1333 fnode = pctx.filenode(pfn)
1335 fnode = pctx.filenode(pfn)
1334 grepbody(pfn, parent, flog.read(fnode))
1336 grepbody(pfn, parent, flog.read(fnode))
1335 except error.LookupError:
1337 except error.LookupError:
1336 pass
1338 pass
1337 elif st == 'iter':
1339 elif st == 'iter':
1338 parent = repo[rev].parents()[0].rev()
1340 parent = repo[rev].parents()[0].rev()
1339 for fn in sorted(revfiles.get(rev, [])):
1341 for fn in sorted(revfiles.get(rev, [])):
1340 states = matches[rev][fn]
1342 states = matches[rev][fn]
1341 copy = copies.get(rev, {}).get(fn)
1343 copy = copies.get(rev, {}).get(fn)
1342 if fn in skip:
1344 if fn in skip:
1343 if copy:
1345 if copy:
1344 skip[copy] = True
1346 skip[copy] = True
1345 continue
1347 continue
1346 pstates = matches.get(parent, {}).get(copy or fn, [])
1348 pstates = matches.get(parent, {}).get(copy or fn, [])
1347 if pstates or states:
1349 if pstates or states:
1348 r = display(fn, rev, pstates, states)
1350 r = display(fn, rev, pstates, states)
1349 found = found or r
1351 found = found or r
1350 if r and not opts.get('all'):
1352 if r and not opts.get('all'):
1351 skip[fn] = True
1353 skip[fn] = True
1352 if copy:
1354 if copy:
1353 skip[copy] = True
1355 skip[copy] = True
1354
1356
1355 def heads(ui, repo, *branchrevs, **opts):
1357 def heads(ui, repo, *branchrevs, **opts):
1356 """show current repository heads or show branch heads
1358 """show current repository heads or show branch heads
1357
1359
1358 With no arguments, show all repository head changesets.
1360 With no arguments, show all repository head changesets.
1359
1361
1360 Repository "heads" are changesets that don't have child
1362 Repository "heads" are changesets that don't have child
1361 changesets. They are where development generally takes place and
1363 changesets. They are where development generally takes place and
1362 are the usual targets for update and merge operations.
1364 are the usual targets for update and merge operations.
1363
1365
1364 If one or more REV is given, the "branch heads" will be shown for
1366 If one or more REV is given, the "branch heads" will be shown for
1365 the named branch associated with that revision. The name of the
1367 the named branch associated with that revision. The name of the
1366 branch is called the revision's branch tag.
1368 branch is called the revision's branch tag.
1367
1369
1368 Branch heads are revisions on a given named branch that do not have
1370 Branch heads are revisions on a given named branch that do not have
1369 any children on the same branch. A branch head could be a true head
1371 any children on the same branch. A branch head could be a true head
1370 or it could be the last changeset on a branch before a new branch
1372 or it could be the last changeset on a branch before a new branch
1371 was created. If none of the branch heads are true heads, the branch
1373 was created. If none of the branch heads are true heads, the branch
1372 is considered inactive.
1374 is considered inactive.
1373
1375
1374 If STARTREV is specified only those heads (or branch heads) that
1376 If STARTREV is specified only those heads (or branch heads) that
1375 are descendants of STARTREV will be displayed.
1377 are descendants of STARTREV will be displayed.
1376 """
1378 """
1377 if opts.get('rev'):
1379 if opts.get('rev'):
1378 start = repo.lookup(opts['rev'])
1380 start = repo.lookup(opts['rev'])
1379 else:
1381 else:
1380 start = None
1382 start = None
1381 closed = opts.get('closed')
1383 closed = opts.get('closed')
1382 hideinactive, _heads = opts.get('active'), None
1384 hideinactive, _heads = opts.get('active'), None
1383 if not branchrevs:
1385 if not branchrevs:
1384 # Assume we're looking repo-wide heads if no revs were specified.
1386 # Assume we're looking repo-wide heads if no revs were specified.
1385 heads = repo.heads(start)
1387 heads = repo.heads(start)
1386 else:
1388 else:
1387 if hideinactive:
1389 if hideinactive:
1388 _heads = repo.heads(start)
1390 _heads = repo.heads(start)
1389 heads = []
1391 heads = []
1390 visitedset = set()
1392 visitedset = set()
1391 for branchrev in branchrevs:
1393 for branchrev in branchrevs:
1392 branch = repo[branchrev].branch()
1394 branch = repo[branchrev].branch()
1393 if branch in visitedset:
1395 if branch in visitedset:
1394 continue
1396 continue
1395 visitedset.add(branch)
1397 visitedset.add(branch)
1396 bheads = repo.branchheads(branch, start, closed=closed)
1398 bheads = repo.branchheads(branch, start, closed=closed)
1397 if not bheads:
1399 if not bheads:
1398 if not opts.get('rev'):
1400 if not opts.get('rev'):
1399 ui.warn(_("no open branch heads on branch %s\n") % branch)
1401 ui.warn(_("no open branch heads on branch %s\n") % branch)
1400 elif branch != branchrev:
1402 elif branch != branchrev:
1401 ui.warn(_("no changes on branch %s containing %s are "
1403 ui.warn(_("no changes on branch %s containing %s are "
1402 "reachable from %s\n")
1404 "reachable from %s\n")
1403 % (branch, branchrev, opts.get('rev')))
1405 % (branch, branchrev, opts.get('rev')))
1404 else:
1406 else:
1405 ui.warn(_("no changes on branch %s are reachable from %s\n")
1407 ui.warn(_("no changes on branch %s are reachable from %s\n")
1406 % (branch, opts.get('rev')))
1408 % (branch, opts.get('rev')))
1407 if hideinactive:
1409 if hideinactive:
1408 bheads = [bhead for bhead in bheads if bhead in _heads]
1410 bheads = [bhead for bhead in bheads if bhead in _heads]
1409 heads.extend(bheads)
1411 heads.extend(bheads)
1410 if not heads:
1412 if not heads:
1411 return 1
1413 return 1
1412 displayer = cmdutil.show_changeset(ui, repo, opts)
1414 displayer = cmdutil.show_changeset(ui, repo, opts)
1413 for n in heads:
1415 for n in heads:
1414 displayer.show(repo[n])
1416 displayer.show(repo[n])
1415
1417
1416 def help_(ui, name=None, with_version=False):
1418 def help_(ui, name=None, with_version=False):
1417 """show help for a given topic or a help overview
1419 """show help for a given topic or a help overview
1418
1420
1419 With no arguments, print a list of commands with short help messages.
1421 With no arguments, print a list of commands with short help messages.
1420
1422
1421 Given a topic, extension, or command name, print help for that
1423 Given a topic, extension, or command name, print help for that
1422 topic."""
1424 topic."""
1423 option_lists = []
1425 option_lists = []
1424
1426
1425 def addglobalopts(aliases):
1427 def addglobalopts(aliases):
1426 if ui.verbose:
1428 if ui.verbose:
1427 option_lists.append((_("global options:"), globalopts))
1429 option_lists.append((_("global options:"), globalopts))
1428 if name == 'shortlist':
1430 if name == 'shortlist':
1429 option_lists.append((_('use "hg help" for the full list '
1431 option_lists.append((_('use "hg help" for the full list '
1430 'of commands'), ()))
1432 'of commands'), ()))
1431 else:
1433 else:
1432 if name == 'shortlist':
1434 if name == 'shortlist':
1433 msg = _('use "hg help" for the full list of commands '
1435 msg = _('use "hg help" for the full list of commands '
1434 'or "hg -v" for details')
1436 'or "hg -v" for details')
1435 elif aliases:
1437 elif aliases:
1436 msg = _('use "hg -v help%s" to show aliases and '
1438 msg = _('use "hg -v help%s" to show aliases and '
1437 'global options') % (name and " " + name or "")
1439 'global options') % (name and " " + name or "")
1438 else:
1440 else:
1439 msg = _('use "hg -v help %s" to show global options') % name
1441 msg = _('use "hg -v help %s" to show global options') % name
1440 option_lists.append((msg, ()))
1442 option_lists.append((msg, ()))
1441
1443
1442 def helpcmd(name):
1444 def helpcmd(name):
1443 if with_version:
1445 if with_version:
1444 version_(ui)
1446 version_(ui)
1445 ui.write('\n')
1447 ui.write('\n')
1446
1448
1447 try:
1449 try:
1448 aliases, i = cmdutil.findcmd(name, table, False)
1450 aliases, i = cmdutil.findcmd(name, table, False)
1449 except error.AmbiguousCommand, inst:
1451 except error.AmbiguousCommand, inst:
1450 select = lambda c: c.lstrip('^').startswith(inst.args[0])
1452 select = lambda c: c.lstrip('^').startswith(inst.args[0])
1451 helplist(_('list of commands:\n\n'), select)
1453 helplist(_('list of commands:\n\n'), select)
1452 return
1454 return
1453
1455
1454 # synopsis
1456 # synopsis
1455 if len(i) > 2:
1457 if len(i) > 2:
1456 if i[2].startswith('hg'):
1458 if i[2].startswith('hg'):
1457 ui.write("%s\n" % i[2])
1459 ui.write("%s\n" % i[2])
1458 else:
1460 else:
1459 ui.write('hg %s %s\n' % (aliases[0], i[2]))
1461 ui.write('hg %s %s\n' % (aliases[0], i[2]))
1460 else:
1462 else:
1461 ui.write('hg %s\n' % aliases[0])
1463 ui.write('hg %s\n' % aliases[0])
1462
1464
1463 # aliases
1465 # aliases
1464 if not ui.quiet and len(aliases) > 1:
1466 if not ui.quiet and len(aliases) > 1:
1465 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
1467 ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
1466
1468
1467 # description
1469 # description
1468 doc = gettext(i[0].__doc__)
1470 doc = gettext(i[0].__doc__)
1469 if not doc:
1471 if not doc:
1470 doc = _("(no help text available)")
1472 doc = _("(no help text available)")
1471 if ui.quiet:
1473 if ui.quiet:
1472 doc = doc.splitlines(0)[0]
1474 doc = doc.splitlines(0)[0]
1473 ui.write("\n%s\n" % doc.rstrip())
1475 ui.write("\n%s\n" % doc.rstrip())
1474
1476
1475 if not ui.quiet:
1477 if not ui.quiet:
1476 # options
1478 # options
1477 if i[1]:
1479 if i[1]:
1478 option_lists.append((_("options:\n"), i[1]))
1480 option_lists.append((_("options:\n"), i[1]))
1479
1481
1480 addglobalopts(False)
1482 addglobalopts(False)
1481
1483
1482 def helplist(header, select=None):
1484 def helplist(header, select=None):
1483 h = {}
1485 h = {}
1484 cmds = {}
1486 cmds = {}
1485 for c, e in table.iteritems():
1487 for c, e in table.iteritems():
1486 f = c.split("|", 1)[0]
1488 f = c.split("|", 1)[0]
1487 if select and not select(f):
1489 if select and not select(f):
1488 continue
1490 continue
1489 if (not select and name != 'shortlist' and
1491 if (not select and name != 'shortlist' and
1490 e[0].__module__ != __name__):
1492 e[0].__module__ != __name__):
1491 continue
1493 continue
1492 if name == "shortlist" and not f.startswith("^"):
1494 if name == "shortlist" and not f.startswith("^"):
1493 continue
1495 continue
1494 f = f.lstrip("^")
1496 f = f.lstrip("^")
1495 if not ui.debugflag and f.startswith("debug"):
1497 if not ui.debugflag and f.startswith("debug"):
1496 continue
1498 continue
1497 doc = gettext(e[0].__doc__)
1499 doc = gettext(e[0].__doc__)
1498 if not doc:
1500 if not doc:
1499 doc = _("(no help text available)")
1501 doc = _("(no help text available)")
1500 h[f] = doc.splitlines(0)[0].rstrip()
1502 h[f] = doc.splitlines(0)[0].rstrip()
1501 cmds[f] = c.lstrip("^")
1503 cmds[f] = c.lstrip("^")
1502
1504
1503 if not h:
1505 if not h:
1504 ui.status(_('no commands defined\n'))
1506 ui.status(_('no commands defined\n'))
1505 return
1507 return
1506
1508
1507 ui.status(header)
1509 ui.status(header)
1508 fns = sorted(h)
1510 fns = sorted(h)
1509 m = max(map(len, fns))
1511 m = max(map(len, fns))
1510 for f in fns:
1512 for f in fns:
1511 if ui.verbose:
1513 if ui.verbose:
1512 commands = cmds[f].replace("|",", ")
1514 commands = cmds[f].replace("|",", ")
1513 ui.write(" %s:\n %s\n"%(commands, h[f]))
1515 ui.write(" %s:\n %s\n"%(commands, h[f]))
1514 else:
1516 else:
1515 ui.write(' %-*s %s\n' % (m, f, h[f]))
1517 ui.write(' %-*s %s\n' % (m, f, h[f]))
1516
1518
1517 if name != 'shortlist':
1519 if name != 'shortlist':
1518 exts, maxlength = extensions.enabled()
1520 exts, maxlength = extensions.enabled()
1519 ui.write(help.listexts(_('enabled extensions:'), exts, maxlength))
1521 ui.write(help.listexts(_('enabled extensions:'), exts, maxlength))
1520
1522
1521 if not ui.quiet:
1523 if not ui.quiet:
1522 addglobalopts(True)
1524 addglobalopts(True)
1523
1525
1524 def helptopic(name):
1526 def helptopic(name):
1525 for names, header, doc in help.helptable:
1527 for names, header, doc in help.helptable:
1526 if name in names:
1528 if name in names:
1527 break
1529 break
1528 else:
1530 else:
1529 raise error.UnknownCommand(name)
1531 raise error.UnknownCommand(name)
1530
1532
1531 # description
1533 # description
1532 if not doc:
1534 if not doc:
1533 doc = _("(no help text available)")
1535 doc = _("(no help text available)")
1534 if hasattr(doc, '__call__'):
1536 if hasattr(doc, '__call__'):
1535 doc = doc()
1537 doc = doc()
1536
1538
1537 ui.write("%s\n" % header)
1539 ui.write("%s\n" % header)
1538 ui.write("%s\n" % doc.rstrip())
1540 ui.write("%s\n" % doc.rstrip())
1539
1541
1540 def helpext(name):
1542 def helpext(name):
1541 try:
1543 try:
1542 mod = extensions.find(name)
1544 mod = extensions.find(name)
1543 except KeyError:
1545 except KeyError:
1544 raise error.UnknownCommand(name)
1546 raise error.UnknownCommand(name)
1545
1547
1546 doc = gettext(mod.__doc__) or _('no help text available')
1548 doc = gettext(mod.__doc__) or _('no help text available')
1547 doc = doc.splitlines(0)
1549 doc = doc.splitlines(0)
1548 ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0]))
1550 ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0]))
1549 for d in doc[1:]:
1551 for d in doc[1:]:
1550 ui.write(d, '\n')
1552 ui.write(d, '\n')
1551
1553
1552 ui.status('\n')
1554 ui.status('\n')
1553
1555
1554 try:
1556 try:
1555 ct = mod.cmdtable
1557 ct = mod.cmdtable
1556 except AttributeError:
1558 except AttributeError:
1557 ct = {}
1559 ct = {}
1558
1560
1559 modcmds = set([c.split('|', 1)[0] for c in ct])
1561 modcmds = set([c.split('|', 1)[0] for c in ct])
1560 helplist(_('list of commands:\n\n'), modcmds.__contains__)
1562 helplist(_('list of commands:\n\n'), modcmds.__contains__)
1561
1563
1562 if name and name != 'shortlist':
1564 if name and name != 'shortlist':
1563 i = None
1565 i = None
1564 for f in (helptopic, helpcmd, helpext):
1566 for f in (helptopic, helpcmd, helpext):
1565 try:
1567 try:
1566 f(name)
1568 f(name)
1567 i = None
1569 i = None
1568 break
1570 break
1569 except error.UnknownCommand, inst:
1571 except error.UnknownCommand, inst:
1570 i = inst
1572 i = inst
1571 if i:
1573 if i:
1572 raise i
1574 raise i
1573
1575
1574 else:
1576 else:
1575 # program name
1577 # program name
1576 if ui.verbose or with_version:
1578 if ui.verbose or with_version:
1577 version_(ui)
1579 version_(ui)
1578 else:
1580 else:
1579 ui.status(_("Mercurial Distributed SCM\n"))
1581 ui.status(_("Mercurial Distributed SCM\n"))
1580 ui.status('\n')
1582 ui.status('\n')
1581
1583
1582 # list of commands
1584 # list of commands
1583 if name == "shortlist":
1585 if name == "shortlist":
1584 header = _('basic commands:\n\n')
1586 header = _('basic commands:\n\n')
1585 else:
1587 else:
1586 header = _('list of commands:\n\n')
1588 header = _('list of commands:\n\n')
1587
1589
1588 helplist(header)
1590 helplist(header)
1589
1591
1590 # list all option lists
1592 # list all option lists
1591 opt_output = []
1593 opt_output = []
1592 for title, options in option_lists:
1594 for title, options in option_lists:
1593 opt_output.append(("\n%s" % title, None))
1595 opt_output.append(("\n%s" % title, None))
1594 for shortopt, longopt, default, desc in options:
1596 for shortopt, longopt, default, desc in options:
1595 if "DEPRECATED" in desc and not ui.verbose: continue
1597 if "DEPRECATED" in desc and not ui.verbose: continue
1596 opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
1598 opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
1597 longopt and " --%s" % longopt),
1599 longopt and " --%s" % longopt),
1598 "%s%s" % (desc,
1600 "%s%s" % (desc,
1599 default
1601 default
1600 and _(" (default: %s)") % default
1602 and _(" (default: %s)") % default
1601 or "")))
1603 or "")))
1602
1604
1603 if not name:
1605 if not name:
1604 ui.write(_("\nadditional help topics:\n\n"))
1606 ui.write(_("\nadditional help topics:\n\n"))
1605 topics = []
1607 topics = []
1606 for names, header, doc in help.helptable:
1608 for names, header, doc in help.helptable:
1607 names = [(-len(name), name) for name in names]
1609 names = [(-len(name), name) for name in names]
1608 names.sort()
1610 names.sort()
1609 topics.append((names[0][1], header))
1611 topics.append((names[0][1], header))
1610 topics_len = max([len(s[0]) for s in topics])
1612 topics_len = max([len(s[0]) for s in topics])
1611 for t, desc in topics:
1613 for t, desc in topics:
1612 ui.write(" %-*s %s\n" % (topics_len, t, desc))
1614 ui.write(" %-*s %s\n" % (topics_len, t, desc))
1613
1615
1614 if opt_output:
1616 if opt_output:
1615 opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
1617 opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
1616 for first, second in opt_output:
1618 for first, second in opt_output:
1617 if second:
1619 if second:
1618 # wrap descriptions at 70 characters, just like the
1620 # wrap descriptions at 70 characters, just like the
1619 # main help texts
1621 # main help texts
1620 second = textwrap.wrap(second, width=70 - opts_len - 3)
1622 second = textwrap.wrap(second, width=70 - opts_len - 3)
1621 pad = '\n' + ' ' * (opts_len + 3)
1623 pad = '\n' + ' ' * (opts_len + 3)
1622 ui.write(" %-*s %s\n" % (opts_len, first, pad.join(second)))
1624 ui.write(" %-*s %s\n" % (opts_len, first, pad.join(second)))
1623 else:
1625 else:
1624 ui.write("%s\n" % first)
1626 ui.write("%s\n" % first)
1625
1627
1626 def identify(ui, repo, source=None,
1628 def identify(ui, repo, source=None,
1627 rev=None, num=None, id=None, branch=None, tags=None):
1629 rev=None, num=None, id=None, branch=None, tags=None):
1628 """identify the working copy or specified revision
1630 """identify the working copy or specified revision
1629
1631
1630 With no revision, print a summary of the current state of the
1632 With no revision, print a summary of the current state of the
1631 repository.
1633 repository.
1632
1634
1633 Specifying a path to a repository root or Mercurial bundle will
1635 Specifying a path to a repository root or Mercurial bundle will
1634 cause lookup to operate on that repository/bundle.
1636 cause lookup to operate on that repository/bundle.
1635
1637
1636 This summary identifies the repository state using one or two
1638 This summary identifies the repository state using one or two
1637 parent hash identifiers, followed by a "+" if there are
1639 parent hash identifiers, followed by a "+" if there are
1638 uncommitted changes in the working directory, a list of tags for
1640 uncommitted changes in the working directory, a list of tags for
1639 this revision and a branch name for non-default branches.
1641 this revision and a branch name for non-default branches.
1640 """
1642 """
1641
1643
1642 if not repo and not source:
1644 if not repo and not source:
1643 raise util.Abort(_("There is no Mercurial repository here "
1645 raise util.Abort(_("There is no Mercurial repository here "
1644 "(.hg not found)"))
1646 "(.hg not found)"))
1645
1647
1646 hexfunc = ui.debugflag and hex or short
1648 hexfunc = ui.debugflag and hex or short
1647 default = not (num or id or branch or tags)
1649 default = not (num or id or branch or tags)
1648 output = []
1650 output = []
1649
1651
1650 revs = []
1652 revs = []
1651 if source:
1653 if source:
1652 source, revs, checkout = hg.parseurl(ui.expandpath(source), [])
1654 source, revs, checkout = hg.parseurl(ui.expandpath(source), [])
1653 repo = hg.repository(ui, source)
1655 repo = hg.repository(ui, source)
1654
1656
1655 if not repo.local():
1657 if not repo.local():
1656 if not rev and revs:
1658 if not rev and revs:
1657 rev = revs[0]
1659 rev = revs[0]
1658 if not rev:
1660 if not rev:
1659 rev = "tip"
1661 rev = "tip"
1660 if num or branch or tags:
1662 if num or branch or tags:
1661 raise util.Abort(
1663 raise util.Abort(
1662 "can't query remote revision number, branch, or tags")
1664 "can't query remote revision number, branch, or tags")
1663 output = [hexfunc(repo.lookup(rev))]
1665 output = [hexfunc(repo.lookup(rev))]
1664 elif not rev:
1666 elif not rev:
1665 ctx = repo[None]
1667 ctx = repo[None]
1666 parents = ctx.parents()
1668 parents = ctx.parents()
1667 changed = False
1669 changed = False
1668 if default or id or num:
1670 if default or id or num:
1669 changed = ctx.files() + ctx.deleted()
1671 changed = ctx.files() + ctx.deleted()
1670 if default or id:
1672 if default or id:
1671 output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]),
1673 output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]),
1672 (changed) and "+" or "")]
1674 (changed) and "+" or "")]
1673 if num:
1675 if num:
1674 output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]),
1676 output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]),
1675 (changed) and "+" or ""))
1677 (changed) and "+" or ""))
1676 else:
1678 else:
1677 ctx = repo[rev]
1679 ctx = repo[rev]
1678 if default or id:
1680 if default or id:
1679 output = [hexfunc(ctx.node())]
1681 output = [hexfunc(ctx.node())]
1680 if num:
1682 if num:
1681 output.append(str(ctx.rev()))
1683 output.append(str(ctx.rev()))
1682
1684
1683 if repo.local() and default and not ui.quiet:
1685 if repo.local() and default and not ui.quiet:
1684 b = encoding.tolocal(ctx.branch())
1686 b = encoding.tolocal(ctx.branch())
1685 if b != 'default':
1687 if b != 'default':
1686 output.append("(%s)" % b)
1688 output.append("(%s)" % b)
1687
1689
1688 # multiple tags for a single parent separated by '/'
1690 # multiple tags for a single parent separated by '/'
1689 t = "/".join(ctx.tags())
1691 t = "/".join(ctx.tags())
1690 if t:
1692 if t:
1691 output.append(t)
1693 output.append(t)
1692
1694
1693 if branch:
1695 if branch:
1694 output.append(encoding.tolocal(ctx.branch()))
1696 output.append(encoding.tolocal(ctx.branch()))
1695
1697
1696 if tags:
1698 if tags:
1697 output.extend(ctx.tags())
1699 output.extend(ctx.tags())
1698
1700
1699 ui.write("%s\n" % ' '.join(output))
1701 ui.write("%s\n" % ' '.join(output))
1700
1702
1701 def import_(ui, repo, patch1, *patches, **opts):
1703 def import_(ui, repo, patch1, *patches, **opts):
1702 """import an ordered set of patches
1704 """import an ordered set of patches
1703
1705
1704 Import a list of patches and commit them individually.
1706 Import a list of patches and commit them individually.
1705
1707
1706 If there are outstanding changes in the working directory, import
1708 If there are outstanding changes in the working directory, import
1707 will abort unless given the -f/--force flag.
1709 will abort unless given the -f/--force flag.
1708
1710
1709 You can import a patch straight from a mail message. Even patches
1711 You can import a patch straight from a mail message. Even patches
1710 as attachments work (to use the body part, it must have type
1712 as attachments work (to use the body part, it must have type
1711 text/plain or text/x-patch). From and Subject headers of email
1713 text/plain or text/x-patch). From and Subject headers of email
1712 message are used as default committer and commit message. All
1714 message are used as default committer and commit message. All
1713 text/plain body parts before first diff are added to commit
1715 text/plain body parts before first diff are added to commit
1714 message.
1716 message.
1715
1717
1716 If the imported patch was generated by hg export, user and
1718 If the imported patch was generated by hg export, user and
1717 description from patch override values from message headers and
1719 description from patch override values from message headers and
1718 body. Values given on command line with -m/--message and -u/--user
1720 body. Values given on command line with -m/--message and -u/--user
1719 override these.
1721 override these.
1720
1722
1721 If --exact is specified, import will set the working directory to
1723 If --exact is specified, import will set the working directory to
1722 the parent of each patch before applying it, and will abort if the
1724 the parent of each patch before applying it, and will abort if the
1723 resulting changeset has a different ID than the one recorded in
1725 resulting changeset has a different ID than the one recorded in
1724 the patch. This may happen due to character set problems or other
1726 the patch. This may happen due to character set problems or other
1725 deficiencies in the text patch format.
1727 deficiencies in the text patch format.
1726
1728
1727 With -s/--similarity, hg will attempt to discover renames and
1729 With -s/--similarity, hg will attempt to discover renames and
1728 copies in the patch in the same way as 'addremove'.
1730 copies in the patch in the same way as 'addremove'.
1729
1731
1730 To read a patch from standard input, use "-" as the patch name.
1732 To read a patch from standard input, use "-" as the patch name.
1731 See 'hg help dates' for a list of formats valid for -d/--date.
1733 See 'hg help dates' for a list of formats valid for -d/--date.
1732 """
1734 """
1733 patches = (patch1,) + patches
1735 patches = (patch1,) + patches
1734
1736
1735 date = opts.get('date')
1737 date = opts.get('date')
1736 if date:
1738 if date:
1737 opts['date'] = util.parsedate(date)
1739 opts['date'] = util.parsedate(date)
1738
1740
1739 try:
1741 try:
1740 sim = float(opts.get('similarity') or 0)
1742 sim = float(opts.get('similarity') or 0)
1741 except ValueError:
1743 except ValueError:
1742 raise util.Abort(_('similarity must be a number'))
1744 raise util.Abort(_('similarity must be a number'))
1743 if sim < 0 or sim > 100:
1745 if sim < 0 or sim > 100:
1744 raise util.Abort(_('similarity must be between 0 and 100'))
1746 raise util.Abort(_('similarity must be between 0 and 100'))
1745
1747
1746 if opts.get('exact') or not opts.get('force'):
1748 if opts.get('exact') or not opts.get('force'):
1747 cmdutil.bail_if_changed(repo)
1749 cmdutil.bail_if_changed(repo)
1748
1750
1749 d = opts["base"]
1751 d = opts["base"]
1750 strip = opts["strip"]
1752 strip = opts["strip"]
1751 wlock = lock = None
1753 wlock = lock = None
1752 try:
1754 try:
1753 wlock = repo.wlock()
1755 wlock = repo.wlock()
1754 lock = repo.lock()
1756 lock = repo.lock()
1755 for p in patches:
1757 for p in patches:
1756 pf = os.path.join(d, p)
1758 pf = os.path.join(d, p)
1757
1759
1758 if pf == '-':
1760 if pf == '-':
1759 ui.status(_("applying patch from stdin\n"))
1761 ui.status(_("applying patch from stdin\n"))
1760 pf = sys.stdin
1762 pf = sys.stdin
1761 else:
1763 else:
1762 ui.status(_("applying %s\n") % p)
1764 ui.status(_("applying %s\n") % p)
1763 pf = url.open(ui, pf)
1765 pf = url.open(ui, pf)
1764 data = patch.extract(ui, pf)
1766 data = patch.extract(ui, pf)
1765 tmpname, message, user, date, branch, nodeid, p1, p2 = data
1767 tmpname, message, user, date, branch, nodeid, p1, p2 = data
1766
1768
1767 if tmpname is None:
1769 if tmpname is None:
1768 raise util.Abort(_('no diffs found'))
1770 raise util.Abort(_('no diffs found'))
1769
1771
1770 try:
1772 try:
1771 cmdline_message = cmdutil.logmessage(opts)
1773 cmdline_message = cmdutil.logmessage(opts)
1772 if cmdline_message:
1774 if cmdline_message:
1773 # pickup the cmdline msg
1775 # pickup the cmdline msg
1774 message = cmdline_message
1776 message = cmdline_message
1775 elif message:
1777 elif message:
1776 # pickup the patch msg
1778 # pickup the patch msg
1777 message = message.strip()
1779 message = message.strip()
1778 else:
1780 else:
1779 # launch the editor
1781 # launch the editor
1780 message = None
1782 message = None
1781 ui.debug(_('message:\n%s\n') % message)
1783 ui.debug(_('message:\n%s\n') % message)
1782
1784
1783 wp = repo.parents()
1785 wp = repo.parents()
1784 if opts.get('exact'):
1786 if opts.get('exact'):
1785 if not nodeid or not p1:
1787 if not nodeid or not p1:
1786 raise util.Abort(_('not a Mercurial patch'))
1788 raise util.Abort(_('not a Mercurial patch'))
1787 p1 = repo.lookup(p1)
1789 p1 = repo.lookup(p1)
1788 p2 = repo.lookup(p2 or hex(nullid))
1790 p2 = repo.lookup(p2 or hex(nullid))
1789
1791
1790 if p1 != wp[0].node():
1792 if p1 != wp[0].node():
1791 hg.clean(repo, p1)
1793 hg.clean(repo, p1)
1792 repo.dirstate.setparents(p1, p2)
1794 repo.dirstate.setparents(p1, p2)
1793 elif p2:
1795 elif p2:
1794 try:
1796 try:
1795 p1 = repo.lookup(p1)
1797 p1 = repo.lookup(p1)
1796 p2 = repo.lookup(p2)
1798 p2 = repo.lookup(p2)
1797 if p1 == wp[0].node():
1799 if p1 == wp[0].node():
1798 repo.dirstate.setparents(p1, p2)
1800 repo.dirstate.setparents(p1, p2)
1799 except error.RepoError:
1801 except error.RepoError:
1800 pass
1802 pass
1801 if opts.get('exact') or opts.get('import_branch'):
1803 if opts.get('exact') or opts.get('import_branch'):
1802 repo.dirstate.setbranch(branch or 'default')
1804 repo.dirstate.setbranch(branch or 'default')
1803
1805
1804 files = {}
1806 files = {}
1805 try:
1807 try:
1806 patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
1808 patch.patch(tmpname, ui, strip=strip, cwd=repo.root,
1807 files=files, eolmode=None)
1809 files=files, eolmode=None)
1808 finally:
1810 finally:
1809 files = patch.updatedir(ui, repo, files, similarity=sim/100.)
1811 files = patch.updatedir(ui, repo, files, similarity=sim/100.)
1810 if not opts.get('no_commit'):
1812 if not opts.get('no_commit'):
1811 m = cmdutil.matchfiles(repo, files or [])
1813 m = cmdutil.matchfiles(repo, files or [])
1812 n = repo.commit(message, opts.get('user') or user,
1814 n = repo.commit(message, opts.get('user') or user,
1813 opts.get('date') or date, match=m,
1815 opts.get('date') or date, match=m,
1814 editor=cmdutil.commiteditor)
1816 editor=cmdutil.commiteditor)
1815 if opts.get('exact'):
1817 if opts.get('exact'):
1816 if hex(n) != nodeid:
1818 if hex(n) != nodeid:
1817 repo.rollback()
1819 repo.rollback()
1818 raise util.Abort(_('patch is damaged'
1820 raise util.Abort(_('patch is damaged'
1819 ' or loses information'))
1821 ' or loses information'))
1820 # Force a dirstate write so that the next transaction
1822 # Force a dirstate write so that the next transaction
1821 # backups an up-do-date file.
1823 # backups an up-do-date file.
1822 repo.dirstate.write()
1824 repo.dirstate.write()
1823 finally:
1825 finally:
1824 os.unlink(tmpname)
1826 os.unlink(tmpname)
1825 finally:
1827 finally:
1826 release(lock, wlock)
1828 release(lock, wlock)
1827
1829
1828 def incoming(ui, repo, source="default", **opts):
1830 def incoming(ui, repo, source="default", **opts):
1829 """show new changesets found in source
1831 """show new changesets found in source
1830
1832
1831 Show new changesets found in the specified path/URL or the default
1833 Show new changesets found in the specified path/URL or the default
1832 pull location. These are the changesets that would have been pulled
1834 pull location. These are the changesets that would have been pulled
1833 if a pull at the time you issued this command.
1835 if a pull at the time you issued this command.
1834
1836
1835 For remote repository, using --bundle avoids downloading the
1837 For remote repository, using --bundle avoids downloading the
1836 changesets twice if the incoming is followed by a pull.
1838 changesets twice if the incoming is followed by a pull.
1837
1839
1838 See pull for valid source format details.
1840 See pull for valid source format details.
1839 """
1841 """
1840 limit = cmdutil.loglimit(opts)
1842 limit = cmdutil.loglimit(opts)
1841 source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
1843 source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
1842 other = hg.repository(cmdutil.remoteui(repo, opts), source)
1844 other = hg.repository(cmdutil.remoteui(repo, opts), source)
1843 ui.status(_('comparing with %s\n') % url.hidepassword(source))
1845 ui.status(_('comparing with %s\n') % url.hidepassword(source))
1844 if revs:
1846 if revs:
1845 revs = [other.lookup(rev) for rev in revs]
1847 revs = [other.lookup(rev) for rev in revs]
1846 common, incoming, rheads = repo.findcommonincoming(other, heads=revs,
1848 common, incoming, rheads = repo.findcommonincoming(other, heads=revs,
1847 force=opts["force"])
1849 force=opts["force"])
1848 if not incoming:
1850 if not incoming:
1849 try:
1851 try:
1850 os.unlink(opts["bundle"])
1852 os.unlink(opts["bundle"])
1851 except:
1853 except:
1852 pass
1854 pass
1853 ui.status(_("no changes found\n"))
1855 ui.status(_("no changes found\n"))
1854 return 1
1856 return 1
1855
1857
1856 cleanup = None
1858 cleanup = None
1857 try:
1859 try:
1858 fname = opts["bundle"]
1860 fname = opts["bundle"]
1859 if fname or not other.local():
1861 if fname or not other.local():
1860 # create a bundle (uncompressed if other repo is not local)
1862 # create a bundle (uncompressed if other repo is not local)
1861
1863
1862 if revs is None and other.capable('changegroupsubset'):
1864 if revs is None and other.capable('changegroupsubset'):
1863 revs = rheads
1865 revs = rheads
1864
1866
1865 if revs is None:
1867 if revs is None:
1866 cg = other.changegroup(incoming, "incoming")
1868 cg = other.changegroup(incoming, "incoming")
1867 else:
1869 else:
1868 cg = other.changegroupsubset(incoming, revs, 'incoming')
1870 cg = other.changegroupsubset(incoming, revs, 'incoming')
1869 bundletype = other.local() and "HG10BZ" or "HG10UN"
1871 bundletype = other.local() and "HG10BZ" or "HG10UN"
1870 fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
1872 fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
1871 # keep written bundle?
1873 # keep written bundle?
1872 if opts["bundle"]:
1874 if opts["bundle"]:
1873 cleanup = None
1875 cleanup = None
1874 if not other.local():
1876 if not other.local():
1875 # use the created uncompressed bundlerepo
1877 # use the created uncompressed bundlerepo
1876 other = bundlerepo.bundlerepository(ui, repo.root, fname)
1878 other = bundlerepo.bundlerepository(ui, repo.root, fname)
1877
1879
1878 o = other.changelog.nodesbetween(incoming, revs)[0]
1880 o = other.changelog.nodesbetween(incoming, revs)[0]
1879 if opts.get('newest_first'):
1881 if opts.get('newest_first'):
1880 o.reverse()
1882 o.reverse()
1881 displayer = cmdutil.show_changeset(ui, other, opts)
1883 displayer = cmdutil.show_changeset(ui, other, opts)
1882 count = 0
1884 count = 0
1883 for n in o:
1885 for n in o:
1884 if count >= limit:
1886 if count >= limit:
1885 break
1887 break
1886 parents = [p for p in other.changelog.parents(n) if p != nullid]
1888 parents = [p for p in other.changelog.parents(n) if p != nullid]
1887 if opts.get('no_merges') and len(parents) == 2:
1889 if opts.get('no_merges') and len(parents) == 2:
1888 continue
1890 continue
1889 count += 1
1891 count += 1
1890 displayer.show(other[n])
1892 displayer.show(other[n])
1891 finally:
1893 finally:
1892 if hasattr(other, 'close'):
1894 if hasattr(other, 'close'):
1893 other.close()
1895 other.close()
1894 if cleanup:
1896 if cleanup:
1895 os.unlink(cleanup)
1897 os.unlink(cleanup)
1896
1898
1897 def init(ui, dest=".", **opts):
1899 def init(ui, dest=".", **opts):
1898 """create a new repository in the given directory
1900 """create a new repository in the given directory
1899
1901
1900 Initialize a new repository in the given directory. If the given
1902 Initialize a new repository in the given directory. If the given
1901 directory does not exist, it will be created.
1903 directory does not exist, it will be created.
1902
1904
1903 If no directory is given, the current directory is used.
1905 If no directory is given, the current directory is used.
1904
1906
1905 It is possible to specify an ssh:// URL as the destination.
1907 It is possible to specify an ssh:// URL as the destination.
1906 See 'hg help urls' for more information.
1908 See 'hg help urls' for more information.
1907 """
1909 """
1908 hg.repository(cmdutil.remoteui(ui, opts), dest, create=1)
1910 hg.repository(cmdutil.remoteui(ui, opts), dest, create=1)
1909
1911
1910 def locate(ui, repo, *pats, **opts):
1912 def locate(ui, repo, *pats, **opts):
1911 """locate files matching specific patterns
1913 """locate files matching specific patterns
1912
1914
1913 Print files under Mercurial control in the working directory whose
1915 Print files under Mercurial control in the working directory whose
1914 names match the given patterns.
1916 names match the given patterns.
1915
1917
1916 By default, this command searches all directories in the working
1918 By default, this command searches all directories in the working
1917 directory. To search just the current directory and its
1919 directory. To search just the current directory and its
1918 subdirectories, use "--include .".
1920 subdirectories, use "--include .".
1919
1921
1920 If no patterns are given to match, this command prints the names
1922 If no patterns are given to match, this command prints the names
1921 of all files under Mercurial control in the working directory.
1923 of all files under Mercurial control in the working directory.
1922
1924
1923 If you want to feed the output of this command into the "xargs"
1925 If you want to feed the output of this command into the "xargs"
1924 command, use the -0 option to both this command and "xargs". This
1926 command, use the -0 option to both this command and "xargs". This
1925 will avoid the problem of "xargs" treating single filenames that
1927 will avoid the problem of "xargs" treating single filenames that
1926 contain whitespace as multiple filenames.
1928 contain whitespace as multiple filenames.
1927 """
1929 """
1928 end = opts.get('print0') and '\0' or '\n'
1930 end = opts.get('print0') and '\0' or '\n'
1929 rev = opts.get('rev') or None
1931 rev = opts.get('rev') or None
1930
1932
1931 ret = 1
1933 ret = 1
1932 m = cmdutil.match(repo, pats, opts, default='relglob')
1934 m = cmdutil.match(repo, pats, opts, default='relglob')
1933 m.bad = lambda x,y: False
1935 m.bad = lambda x,y: False
1934 for abs in repo[rev].walk(m):
1936 for abs in repo[rev].walk(m):
1935 if not rev and abs not in repo.dirstate:
1937 if not rev and abs not in repo.dirstate:
1936 continue
1938 continue
1937 if opts.get('fullpath'):
1939 if opts.get('fullpath'):
1938 ui.write(repo.wjoin(abs), end)
1940 ui.write(repo.wjoin(abs), end)
1939 else:
1941 else:
1940 ui.write(((pats and m.rel(abs)) or abs), end)
1942 ui.write(((pats and m.rel(abs)) or abs), end)
1941 ret = 0
1943 ret = 0
1942
1944
1943 return ret
1945 return ret
1944
1946
1945 def log(ui, repo, *pats, **opts):
1947 def log(ui, repo, *pats, **opts):
1946 """show revision history of entire repository or files
1948 """show revision history of entire repository or files
1947
1949
1948 Print the revision history of the specified files or the entire
1950 Print the revision history of the specified files or the entire
1949 project.
1951 project.
1950
1952
1951 File history is shown without following rename or copy history of
1953 File history is shown without following rename or copy history of
1952 files. Use -f/--follow with a filename to follow history across
1954 files. Use -f/--follow with a filename to follow history across
1953 renames and copies. --follow without a filename will only show
1955 renames and copies. --follow without a filename will only show
1954 ancestors or descendants of the starting revision. --follow-first
1956 ancestors or descendants of the starting revision. --follow-first
1955 only follows the first parent of merge revisions.
1957 only follows the first parent of merge revisions.
1956
1958
1957 If no revision range is specified, the default is tip:0 unless
1959 If no revision range is specified, the default is tip:0 unless
1958 --follow is set, in which case the working directory parent is
1960 --follow is set, in which case the working directory parent is
1959 used as the starting revision.
1961 used as the starting revision.
1960
1962
1961 See 'hg help dates' for a list of formats valid for -d/--date.
1963 See 'hg help dates' for a list of formats valid for -d/--date.
1962
1964
1963 By default this command prints revision number and changeset id,
1965 By default this command prints revision number and changeset id,
1964 tags, non-trivial parents, user, date and time, and a summary for
1966 tags, non-trivial parents, user, date and time, and a summary for
1965 each commit. When the -v/--verbose switch is used, the list of
1967 each commit. When the -v/--verbose switch is used, the list of
1966 changed files and full commit message are shown.
1968 changed files and full commit message are shown.
1967
1969
1968 NOTE: log -p/--patch may generate unexpected diff output for merge
1970 NOTE: log -p/--patch may generate unexpected diff output for merge
1969 changesets, as it will only compare the merge changeset against
1971 changesets, as it will only compare the merge changeset against
1970 its first parent. Also, only files different from BOTH parents
1972 its first parent. Also, only files different from BOTH parents
1971 will appear in files:.
1973 will appear in files:.
1972 """
1974 """
1973
1975
1974 get = util.cachefunc(lambda r: repo[r].changeset())
1976 get = util.cachefunc(lambda r: repo[r].changeset())
1975 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1977 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1976
1978
1977 limit = cmdutil.loglimit(opts)
1979 limit = cmdutil.loglimit(opts)
1978 count = 0
1980 count = 0
1979
1981
1980 if opts.get('copies') and opts.get('rev'):
1982 if opts.get('copies') and opts.get('rev'):
1981 endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
1983 endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
1982 else:
1984 else:
1983 endrev = len(repo)
1985 endrev = len(repo)
1984 rcache = {}
1986 rcache = {}
1985 ncache = {}
1987 ncache = {}
1986 def getrenamed(fn, rev):
1988 def getrenamed(fn, rev):
1987 '''looks up all renames for a file (up to endrev) the first
1989 '''looks up all renames for a file (up to endrev) the first
1988 time the file is given. It indexes on the changerev and only
1990 time the file is given. It indexes on the changerev and only
1989 parses the manifest if linkrev != changerev.
1991 parses the manifest if linkrev != changerev.
1990 Returns rename info for fn at changerev rev.'''
1992 Returns rename info for fn at changerev rev.'''
1991 if fn not in rcache:
1993 if fn not in rcache:
1992 rcache[fn] = {}
1994 rcache[fn] = {}
1993 ncache[fn] = {}
1995 ncache[fn] = {}
1994 fl = repo.file(fn)
1996 fl = repo.file(fn)
1995 for i in fl:
1997 for i in fl:
1996 node = fl.node(i)
1998 node = fl.node(i)
1997 lr = fl.linkrev(i)
1999 lr = fl.linkrev(i)
1998 renamed = fl.renamed(node)
2000 renamed = fl.renamed(node)
1999 rcache[fn][lr] = renamed
2001 rcache[fn][lr] = renamed
2000 if renamed:
2002 if renamed:
2001 ncache[fn][node] = renamed
2003 ncache[fn][node] = renamed
2002 if lr >= endrev:
2004 if lr >= endrev:
2003 break
2005 break
2004 if rev in rcache[fn]:
2006 if rev in rcache[fn]:
2005 return rcache[fn][rev]
2007 return rcache[fn][rev]
2006
2008
2007 # If linkrev != rev (i.e. rev not found in rcache) fallback to
2009 # If linkrev != rev (i.e. rev not found in rcache) fallback to
2008 # filectx logic.
2010 # filectx logic.
2009
2011
2010 try:
2012 try:
2011 return repo[rev][fn].renamed()
2013 return repo[rev][fn].renamed()
2012 except error.LookupError:
2014 except error.LookupError:
2013 pass
2015 pass
2014 return None
2016 return None
2015
2017
2016 df = False
2018 df = False
2017 if opts["date"]:
2019 if opts["date"]:
2018 df = util.matchdate(opts["date"])
2020 df = util.matchdate(opts["date"])
2019
2021
2020 only_branches = opts.get('only_branch')
2022 only_branches = opts.get('only_branch')
2021
2023
2022 displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
2024 displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
2023 for st, rev, fns in changeiter:
2025 for st, rev, fns in changeiter:
2024 if st == 'add':
2026 if st == 'add':
2025 parents = [p for p in repo.changelog.parentrevs(rev)
2027 parents = [p for p in repo.changelog.parentrevs(rev)
2026 if p != nullrev]
2028 if p != nullrev]
2027 if opts.get('no_merges') and len(parents) == 2:
2029 if opts.get('no_merges') and len(parents) == 2:
2028 continue
2030 continue
2029 if opts.get('only_merges') and len(parents) != 2:
2031 if opts.get('only_merges') and len(parents) != 2:
2030 continue
2032 continue
2031
2033
2032 if only_branches:
2034 if only_branches:
2033 revbranch = get(rev)[5]['branch']
2035 revbranch = get(rev)[5]['branch']
2034 if revbranch not in only_branches:
2036 if revbranch not in only_branches:
2035 continue
2037 continue
2036
2038
2037 if df:
2039 if df:
2038 changes = get(rev)
2040 changes = get(rev)
2039 if not df(changes[2][0]):
2041 if not df(changes[2][0]):
2040 continue
2042 continue
2041
2043
2042 if opts.get('keyword'):
2044 if opts.get('keyword'):
2043 changes = get(rev)
2045 changes = get(rev)
2044 miss = 0
2046 miss = 0
2045 for k in [kw.lower() for kw in opts['keyword']]:
2047 for k in [kw.lower() for kw in opts['keyword']]:
2046 if not (k in changes[1].lower() or
2048 if not (k in changes[1].lower() or
2047 k in changes[4].lower() or
2049 k in changes[4].lower() or
2048 k in " ".join(changes[3]).lower()):
2050 k in " ".join(changes[3]).lower()):
2049 miss = 1
2051 miss = 1
2050 break
2052 break
2051 if miss:
2053 if miss:
2052 continue
2054 continue
2053
2055
2054 if opts['user']:
2056 if opts['user']:
2055 changes = get(rev)
2057 changes = get(rev)
2056 if not [k for k in opts['user'] if k in changes[1]]:
2058 if not [k for k in opts['user'] if k in changes[1]]:
2057 continue
2059 continue
2058
2060
2059 copies = []
2061 copies = []
2060 if opts.get('copies') and rev:
2062 if opts.get('copies') and rev:
2061 for fn in get(rev)[3]:
2063 for fn in get(rev)[3]:
2062 rename = getrenamed(fn, rev)
2064 rename = getrenamed(fn, rev)
2063 if rename:
2065 if rename:
2064 copies.append((fn, rename[0]))
2066 copies.append((fn, rename[0]))
2065 displayer.show(context.changectx(repo, rev), copies=copies)
2067 displayer.show(context.changectx(repo, rev), copies=copies)
2066 elif st == 'iter':
2068 elif st == 'iter':
2067 if count == limit: break
2069 if count == limit: break
2068 if displayer.flush(rev):
2070 if displayer.flush(rev):
2069 count += 1
2071 count += 1
2070
2072
2071 def manifest(ui, repo, node=None, rev=None):
2073 def manifest(ui, repo, node=None, rev=None):
2072 """output the current or given revision of the project manifest
2074 """output the current or given revision of the project manifest
2073
2075
2074 Print a list of version controlled files for the given revision.
2076 Print a list of version controlled files for the given revision.
2075 If no revision is given, the first parent of the working directory
2077 If no revision is given, the first parent of the working directory
2076 is used, or the null revision if no revision is checked out.
2078 is used, or the null revision if no revision is checked out.
2077
2079
2078 With -v, print file permissions, symlink and executable bits.
2080 With -v, print file permissions, symlink and executable bits.
2079 With --debug, print file revision hashes.
2081 With --debug, print file revision hashes.
2080 """
2082 """
2081
2083
2082 if rev and node:
2084 if rev and node:
2083 raise util.Abort(_("please specify just one revision"))
2085 raise util.Abort(_("please specify just one revision"))
2084
2086
2085 if not node:
2087 if not node:
2086 node = rev
2088 node = rev
2087
2089
2088 decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '}
2090 decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '}
2089 ctx = repo[node]
2091 ctx = repo[node]
2090 for f in ctx:
2092 for f in ctx:
2091 if ui.debugflag:
2093 if ui.debugflag:
2092 ui.write("%40s " % hex(ctx.manifest()[f]))
2094 ui.write("%40s " % hex(ctx.manifest()[f]))
2093 if ui.verbose:
2095 if ui.verbose:
2094 ui.write(decor[ctx.flags(f)])
2096 ui.write(decor[ctx.flags(f)])
2095 ui.write("%s\n" % f)
2097 ui.write("%s\n" % f)
2096
2098
2097 def merge(ui, repo, node=None, **opts):
2099 def merge(ui, repo, node=None, **opts):
2098 """merge working directory with another revision
2100 """merge working directory with another revision
2099
2101
2100 The current working directory is updated with all changes made in
2102 The current working directory is updated with all changes made in
2101 the requested revision since the last common predecessor revision.
2103 the requested revision since the last common predecessor revision.
2102
2104
2103 Files that changed between either parent are marked as changed for
2105 Files that changed between either parent are marked as changed for
2104 the next commit and a commit must be performed before any further
2106 the next commit and a commit must be performed before any further
2105 updates to the repository are allowed. The next commit will have
2107 updates to the repository are allowed. The next commit will have
2106 two parents.
2108 two parents.
2107
2109
2108 If no revision is specified, the working directory's parent is a
2110 If no revision is specified, the working directory's parent is a
2109 head revision, and the current branch contains exactly one other
2111 head revision, and the current branch contains exactly one other
2110 head, the other head is merged with by default. Otherwise, an
2112 head, the other head is merged with by default. Otherwise, an
2111 explicit revision with which to merge with must be provided.
2113 explicit revision with which to merge with must be provided.
2112 """
2114 """
2113
2115
2114 if opts.get('rev') and node:
2116 if opts.get('rev') and node:
2115 raise util.Abort(_("please specify just one revision"))
2117 raise util.Abort(_("please specify just one revision"))
2116 if not node:
2118 if not node:
2117 node = opts.get('rev')
2119 node = opts.get('rev')
2118
2120
2119 if not node:
2121 if not node:
2120 branch = repo.changectx(None).branch()
2122 branch = repo.changectx(None).branch()
2121 bheads = repo.branchheads(branch)
2123 bheads = repo.branchheads(branch)
2122 if len(bheads) > 2:
2124 if len(bheads) > 2:
2123 raise util.Abort(_("branch '%s' has %d heads - "
2125 raise util.Abort(_("branch '%s' has %d heads - "
2124 "please merge with an explicit rev") %
2126 "please merge with an explicit rev") %
2125 (branch, len(bheads)))
2127 (branch, len(bheads)))
2126
2128
2127 parent = repo.dirstate.parents()[0]
2129 parent = repo.dirstate.parents()[0]
2128 if len(bheads) == 1:
2130 if len(bheads) == 1:
2129 if len(repo.heads()) > 1:
2131 if len(repo.heads()) > 1:
2130 raise util.Abort(_("branch '%s' has one head - "
2132 raise util.Abort(_("branch '%s' has one head - "
2131 "please merge with an explicit rev") %
2133 "please merge with an explicit rev") %
2132 branch)
2134 branch)
2133 msg = _('there is nothing to merge')
2135 msg = _('there is nothing to merge')
2134 if parent != repo.lookup(repo[None].branch()):
2136 if parent != repo.lookup(repo[None].branch()):
2135 msg = _('%s - use "hg update" instead') % msg
2137 msg = _('%s - use "hg update" instead') % msg
2136 raise util.Abort(msg)
2138 raise util.Abort(msg)
2137
2139
2138 if parent not in bheads:
2140 if parent not in bheads:
2139 raise util.Abort(_('working dir not at a head rev - '
2141 raise util.Abort(_('working dir not at a head rev - '
2140 'use "hg update" or merge with an explicit rev'))
2142 'use "hg update" or merge with an explicit rev'))
2141 node = parent == bheads[0] and bheads[-1] or bheads[0]
2143 node = parent == bheads[0] and bheads[-1] or bheads[0]
2142
2144
2143 if opts.get('preview'):
2145 if opts.get('preview'):
2144 p1 = repo['.']
2146 p1 = repo['.']
2145 p2 = repo[node]
2147 p2 = repo[node]
2146 common = p1.ancestor(p2)
2148 common = p1.ancestor(p2)
2147 roots, heads = [common.node()], [p2.node()]
2149 roots, heads = [common.node()], [p2.node()]
2148 displayer = cmdutil.show_changeset(ui, repo, opts)
2150 displayer = cmdutil.show_changeset(ui, repo, opts)
2149 for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]:
2151 for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]:
2150 displayer.show(repo[node])
2152 displayer.show(repo[node])
2151 return 0
2153 return 0
2152
2154
2153 return hg.merge(repo, node, force=opts.get('force'))
2155 return hg.merge(repo, node, force=opts.get('force'))
2154
2156
2155 def outgoing(ui, repo, dest=None, **opts):
2157 def outgoing(ui, repo, dest=None, **opts):
2156 """show changesets not found in destination
2158 """show changesets not found in destination
2157
2159
2158 Show changesets not found in the specified destination repository
2160 Show changesets not found in the specified destination repository
2159 or the default push location. These are the changesets that would
2161 or the default push location. These are the changesets that would
2160 be pushed if a push was requested.
2162 be pushed if a push was requested.
2161
2163
2162 See pull for valid destination format details.
2164 See pull for valid destination format details.
2163 """
2165 """
2164 limit = cmdutil.loglimit(opts)
2166 limit = cmdutil.loglimit(opts)
2165 dest, revs, checkout = hg.parseurl(
2167 dest, revs, checkout = hg.parseurl(
2166 ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
2168 ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
2167 if revs:
2169 if revs:
2168 revs = [repo.lookup(rev) for rev in revs]
2170 revs = [repo.lookup(rev) for rev in revs]
2169
2171
2170 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
2172 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
2171 ui.status(_('comparing with %s\n') % url.hidepassword(dest))
2173 ui.status(_('comparing with %s\n') % url.hidepassword(dest))
2172 o = repo.findoutgoing(other, force=opts.get('force'))
2174 o = repo.findoutgoing(other, force=opts.get('force'))
2173 if not o:
2175 if not o:
2174 ui.status(_("no changes found\n"))
2176 ui.status(_("no changes found\n"))
2175 return 1
2177 return 1
2176 o = repo.changelog.nodesbetween(o, revs)[0]
2178 o = repo.changelog.nodesbetween(o, revs)[0]
2177 if opts.get('newest_first'):
2179 if opts.get('newest_first'):
2178 o.reverse()
2180 o.reverse()
2179 displayer = cmdutil.show_changeset(ui, repo, opts)
2181 displayer = cmdutil.show_changeset(ui, repo, opts)
2180 count = 0
2182 count = 0
2181 for n in o:
2183 for n in o:
2182 if count >= limit:
2184 if count >= limit:
2183 break
2185 break
2184 parents = [p for p in repo.changelog.parents(n) if p != nullid]
2186 parents = [p for p in repo.changelog.parents(n) if p != nullid]
2185 if opts.get('no_merges') and len(parents) == 2:
2187 if opts.get('no_merges') and len(parents) == 2:
2186 continue
2188 continue
2187 count += 1
2189 count += 1
2188 displayer.show(repo[n])
2190 displayer.show(repo[n])
2189
2191
2190 def parents(ui, repo, file_=None, **opts):
2192 def parents(ui, repo, file_=None, **opts):
2191 """show the parents of the working directory or revision
2193 """show the parents of the working directory or revision
2192
2194
2193 Print the working directory's parent revisions. If a revision is
2195 Print the working directory's parent revisions. If a revision is
2194 given via -r/--rev, the parent of that revision will be printed.
2196 given via -r/--rev, the parent of that revision will be printed.
2195 If a file argument is given, the revision in which the file was
2197 If a file argument is given, the revision in which the file was
2196 last changed (before the working directory revision or the
2198 last changed (before the working directory revision or the
2197 argument to --rev if given) is printed.
2199 argument to --rev if given) is printed.
2198 """
2200 """
2199 rev = opts.get('rev')
2201 rev = opts.get('rev')
2200 if rev:
2202 if rev:
2201 ctx = repo[rev]
2203 ctx = repo[rev]
2202 else:
2204 else:
2203 ctx = repo[None]
2205 ctx = repo[None]
2204
2206
2205 if file_:
2207 if file_:
2206 m = cmdutil.match(repo, (file_,), opts)
2208 m = cmdutil.match(repo, (file_,), opts)
2207 if m.anypats() or len(m.files()) != 1:
2209 if m.anypats() or len(m.files()) != 1:
2208 raise util.Abort(_('can only specify an explicit filename'))
2210 raise util.Abort(_('can only specify an explicit filename'))
2209 file_ = m.files()[0]
2211 file_ = m.files()[0]
2210 filenodes = []
2212 filenodes = []
2211 for cp in ctx.parents():
2213 for cp in ctx.parents():
2212 if not cp:
2214 if not cp:
2213 continue
2215 continue
2214 try:
2216 try:
2215 filenodes.append(cp.filenode(file_))
2217 filenodes.append(cp.filenode(file_))
2216 except error.LookupError:
2218 except error.LookupError:
2217 pass
2219 pass
2218 if not filenodes:
2220 if not filenodes:
2219 raise util.Abort(_("'%s' not found in manifest!") % file_)
2221 raise util.Abort(_("'%s' not found in manifest!") % file_)
2220 fl = repo.file(file_)
2222 fl = repo.file(file_)
2221 p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes]
2223 p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes]
2222 else:
2224 else:
2223 p = [cp.node() for cp in ctx.parents()]
2225 p = [cp.node() for cp in ctx.parents()]
2224
2226
2225 displayer = cmdutil.show_changeset(ui, repo, opts)
2227 displayer = cmdutil.show_changeset(ui, repo, opts)
2226 for n in p:
2228 for n in p:
2227 if n != nullid:
2229 if n != nullid:
2228 displayer.show(repo[n])
2230 displayer.show(repo[n])
2229
2231
2230 def paths(ui, repo, search=None):
2232 def paths(ui, repo, search=None):
2231 """show aliases for remote repositories
2233 """show aliases for remote repositories
2232
2234
2233 Show definition of symbolic path name NAME. If no name is given,
2235 Show definition of symbolic path name NAME. If no name is given,
2234 show definition of all available names.
2236 show definition of all available names.
2235
2237
2236 Path names are defined in the [paths] section of /etc/mercurial/hgrc
2238 Path names are defined in the [paths] section of /etc/mercurial/hgrc
2237 and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.
2239 and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too.
2238
2240
2239 See 'hg help urls' for more information.
2241 See 'hg help urls' for more information.
2240 """
2242 """
2241 if search:
2243 if search:
2242 for name, path in ui.configitems("paths"):
2244 for name, path in ui.configitems("paths"):
2243 if name == search:
2245 if name == search:
2244 ui.write("%s\n" % url.hidepassword(path))
2246 ui.write("%s\n" % url.hidepassword(path))
2245 return
2247 return
2246 ui.warn(_("not found!\n"))
2248 ui.warn(_("not found!\n"))
2247 return 1
2249 return 1
2248 else:
2250 else:
2249 for name, path in ui.configitems("paths"):
2251 for name, path in ui.configitems("paths"):
2250 ui.write("%s = %s\n" % (name, url.hidepassword(path)))
2252 ui.write("%s = %s\n" % (name, url.hidepassword(path)))
2251
2253
2252 def postincoming(ui, repo, modheads, optupdate, checkout):
2254 def postincoming(ui, repo, modheads, optupdate, checkout):
2253 if modheads == 0:
2255 if modheads == 0:
2254 return
2256 return
2255 if optupdate:
2257 if optupdate:
2256 if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout:
2258 if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout:
2257 return hg.update(repo, checkout)
2259 return hg.update(repo, checkout)
2258 else:
2260 else:
2259 ui.status(_("not updating, since new heads added\n"))
2261 ui.status(_("not updating, since new heads added\n"))
2260 if modheads > 1:
2262 if modheads > 1:
2261 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
2263 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
2262 else:
2264 else:
2263 ui.status(_("(run 'hg update' to get a working copy)\n"))
2265 ui.status(_("(run 'hg update' to get a working copy)\n"))
2264
2266
2265 def pull(ui, repo, source="default", **opts):
2267 def pull(ui, repo, source="default", **opts):
2266 """pull changes from the specified source
2268 """pull changes from the specified source
2267
2269
2268 Pull changes from a remote repository to a local one.
2270 Pull changes from a remote repository to a local one.
2269
2271
2270 This finds all changes from the repository at the specified path
2272 This finds all changes from the repository at the specified path
2271 or URL and adds them to a local repository (the current one unless
2273 or URL and adds them to a local repository (the current one unless
2272 -R is specified). By default, this does not update the copy of the
2274 -R is specified). By default, this does not update the copy of the
2273 project in the working directory.
2275 project in the working directory.
2274
2276
2275 Use hg incoming if you want to see what would have been added by a
2277 Use hg incoming if you want to see what would have been added by a
2276 pull at the time you issued this command. If you then decide to
2278 pull at the time you issued this command. If you then decide to
2277 added those changes to the repository, you should use pull -r X
2279 added those changes to the repository, you should use pull -r X
2278 where X is the last changeset listed by hg incoming.
2280 where X is the last changeset listed by hg incoming.
2279
2281
2280 If SOURCE is omitted, the 'default' path will be used.
2282 If SOURCE is omitted, the 'default' path will be used.
2281 See 'hg help urls' for more information.
2283 See 'hg help urls' for more information.
2282 """
2284 """
2283 source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
2285 source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
2284 other = hg.repository(cmdutil.remoteui(repo, opts), source)
2286 other = hg.repository(cmdutil.remoteui(repo, opts), source)
2285 ui.status(_('pulling from %s\n') % url.hidepassword(source))
2287 ui.status(_('pulling from %s\n') % url.hidepassword(source))
2286 if revs:
2288 if revs:
2287 try:
2289 try:
2288 revs = [other.lookup(rev) for rev in revs]
2290 revs = [other.lookup(rev) for rev in revs]
2289 except error.CapabilityError:
2291 except error.CapabilityError:
2290 err = _("Other repository doesn't support revision lookup, "
2292 err = _("Other repository doesn't support revision lookup, "
2291 "so a rev cannot be specified.")
2293 "so a rev cannot be specified.")
2292 raise util.Abort(err)
2294 raise util.Abort(err)
2293
2295
2294 modheads = repo.pull(other, heads=revs, force=opts.get('force'))
2296 modheads = repo.pull(other, heads=revs, force=opts.get('force'))
2295 return postincoming(ui, repo, modheads, opts.get('update'), checkout)
2297 return postincoming(ui, repo, modheads, opts.get('update'), checkout)
2296
2298
2297 def push(ui, repo, dest=None, **opts):
2299 def push(ui, repo, dest=None, **opts):
2298 """push changes to the specified destination
2300 """push changes to the specified destination
2299
2301
2300 Push changes from the local repository to the given destination.
2302 Push changes from the local repository to the given destination.
2301
2303
2302 This is the symmetrical operation for pull. It moves changes from
2304 This is the symmetrical operation for pull. It moves changes from
2303 the current repository to a different one. If the destination is
2305 the current repository to a different one. If the destination is
2304 local this is identical to a pull in that directory from the
2306 local this is identical to a pull in that directory from the
2305 current one.
2307 current one.
2306
2308
2307 By default, push will refuse to run if it detects the result would
2309 By default, push will refuse to run if it detects the result would
2308 increase the number of remote heads. This generally indicates the
2310 increase the number of remote heads. This generally indicates the
2309 user forgot to pull and merge before pushing.
2311 user forgot to pull and merge before pushing.
2310
2312
2311 If -r/--rev is used, the named revision and all its ancestors will
2313 If -r/--rev is used, the named revision and all its ancestors will
2312 be pushed to the remote repository.
2314 be pushed to the remote repository.
2313
2315
2314 Please see 'hg help urls' for important details about ssh://
2316 Please see 'hg help urls' for important details about ssh://
2315 URLs. If DESTINATION is omitted, a default path will be used.
2317 URLs. If DESTINATION is omitted, a default path will be used.
2316 See 'hg help urls' for more information.
2318 See 'hg help urls' for more information.
2317 """
2319 """
2318 dest, revs, checkout = hg.parseurl(
2320 dest, revs, checkout = hg.parseurl(
2319 ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
2321 ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev'))
2320 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
2322 other = hg.repository(cmdutil.remoteui(repo, opts), dest)
2321 ui.status(_('pushing to %s\n') % url.hidepassword(dest))
2323 ui.status(_('pushing to %s\n') % url.hidepassword(dest))
2322 if revs:
2324 if revs:
2323 revs = [repo.lookup(rev) for rev in revs]
2325 revs = [repo.lookup(rev) for rev in revs]
2324
2326
2325 # push subrepos depth-first for coherent ordering
2327 # push subrepos depth-first for coherent ordering
2326 c = repo['']
2328 c = repo['']
2327 subs = c.substate # only repos that are committed
2329 subs = c.substate # only repos that are committed
2328 for s in sorted(subs):
2330 for s in sorted(subs):
2329 c.sub(s).push(opts.get('force'))
2331 c.sub(s).push(opts.get('force'))
2330
2332
2331 r = repo.push(other, opts.get('force'), revs=revs)
2333 r = repo.push(other, opts.get('force'), revs=revs)
2332 return r == 0
2334 return r == 0
2333
2335
2334 def recover(ui, repo):
2336 def recover(ui, repo):
2335 """roll back an interrupted transaction
2337 """roll back an interrupted transaction
2336
2338
2337 Recover from an interrupted commit or pull.
2339 Recover from an interrupted commit or pull.
2338
2340
2339 This command tries to fix the repository status after an
2341 This command tries to fix the repository status after an
2340 interrupted operation. It should only be necessary when Mercurial
2342 interrupted operation. It should only be necessary when Mercurial
2341 suggests it.
2343 suggests it.
2342 """
2344 """
2343 if repo.recover():
2345 if repo.recover():
2344 return hg.verify(repo)
2346 return hg.verify(repo)
2345 return 1
2347 return 1
2346
2348
2347 def remove(ui, repo, *pats, **opts):
2349 def remove(ui, repo, *pats, **opts):
2348 """remove the specified files on the next commit
2350 """remove the specified files on the next commit
2349
2351
2350 Schedule the indicated files for removal from the repository.
2352 Schedule the indicated files for removal from the repository.
2351
2353
2352 This only removes files from the current branch, not from the
2354 This only removes files from the current branch, not from the
2353 entire project history. -A/--after can be used to remove only
2355 entire project history. -A/--after can be used to remove only
2354 files that have already been deleted, -f/--force can be used to
2356 files that have already been deleted, -f/--force can be used to
2355 force deletion, and -Af can be used to remove files from the next
2357 force deletion, and -Af can be used to remove files from the next
2356 revision without deleting them from the working directory.
2358 revision without deleting them from the working directory.
2357
2359
2358 The following table details the behavior of remove for different
2360 The following table details the behavior of remove for different
2359 file states (columns) and option combinations (rows). The file
2361 file states (columns) and option combinations (rows). The file
2360 states are Added [A], Clean [C], Modified [M] and Missing [!]
2362 states are Added [A], Clean [C], Modified [M] and Missing [!]
2361 (as reported by hg status). The actions are Warn, Remove (from
2363 (as reported by hg status). The actions are Warn, Remove (from
2362 branch) and Delete (from disk).
2364 branch) and Delete (from disk).
2363
2365
2364 A C M !
2366 A C M !
2365 none W RD W R
2367 none W RD W R
2366 -f R RD RD R
2368 -f R RD RD R
2367 -A W W W R
2369 -A W W W R
2368 -Af R R R R
2370 -Af R R R R
2369
2371
2370 This command schedules the files to be removed at the next commit.
2372 This command schedules the files to be removed at the next commit.
2371 To undo a remove before that, see hg revert.
2373 To undo a remove before that, see hg revert.
2372 """
2374 """
2373
2375
2374 after, force = opts.get('after'), opts.get('force')
2376 after, force = opts.get('after'), opts.get('force')
2375 if not pats and not after:
2377 if not pats and not after:
2376 raise util.Abort(_('no files specified'))
2378 raise util.Abort(_('no files specified'))
2377
2379
2378 m = cmdutil.match(repo, pats, opts)
2380 m = cmdutil.match(repo, pats, opts)
2379 s = repo.status(match=m, clean=True)
2381 s = repo.status(match=m, clean=True)
2380 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
2382 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
2381
2383
2382 for f in m.files():
2384 for f in m.files():
2383 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
2385 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
2384 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
2386 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
2385
2387
2386 def warn(files, reason):
2388 def warn(files, reason):
2387 for f in files:
2389 for f in files:
2388 ui.warn(_('not removing %s: file %s (use -f to force removal)\n')
2390 ui.warn(_('not removing %s: file %s (use -f to force removal)\n')
2389 % (m.rel(f), reason))
2391 % (m.rel(f), reason))
2390
2392
2391 if force:
2393 if force:
2392 remove, forget = modified + deleted + clean, added
2394 remove, forget = modified + deleted + clean, added
2393 elif after:
2395 elif after:
2394 remove, forget = deleted, []
2396 remove, forget = deleted, []
2395 warn(modified + added + clean, _('still exists'))
2397 warn(modified + added + clean, _('still exists'))
2396 else:
2398 else:
2397 remove, forget = deleted + clean, []
2399 remove, forget = deleted + clean, []
2398 warn(modified, _('is modified'))
2400 warn(modified, _('is modified'))
2399 warn(added, _('has been marked for add'))
2401 warn(added, _('has been marked for add'))
2400
2402
2401 for f in sorted(remove + forget):
2403 for f in sorted(remove + forget):
2402 if ui.verbose or not m.exact(f):
2404 if ui.verbose or not m.exact(f):
2403 ui.status(_('removing %s\n') % m.rel(f))
2405 ui.status(_('removing %s\n') % m.rel(f))
2404
2406
2405 repo.forget(forget)
2407 repo.forget(forget)
2406 repo.remove(remove, unlink=not after)
2408 repo.remove(remove, unlink=not after)
2407
2409
2408 def rename(ui, repo, *pats, **opts):
2410 def rename(ui, repo, *pats, **opts):
2409 """rename files; equivalent of copy + remove
2411 """rename files; equivalent of copy + remove
2410
2412
2411 Mark dest as copies of sources; mark sources for deletion. If dest
2413 Mark dest as copies of sources; mark sources for deletion. If dest
2412 is a directory, copies are put in that directory. If dest is a
2414 is a directory, copies are put in that directory. If dest is a
2413 file, there can only be one source.
2415 file, there can only be one source.
2414
2416
2415 By default, this command copies the contents of files as they
2417 By default, this command copies the contents of files as they
2416 exist in the working directory. If invoked with -A/--after, the
2418 exist in the working directory. If invoked with -A/--after, the
2417 operation is recorded, but no copying is performed.
2419 operation is recorded, but no copying is performed.
2418
2420
2419 This command takes effect at the next commit. To undo a rename
2421 This command takes effect at the next commit. To undo a rename
2420 before that, see hg revert.
2422 before that, see hg revert.
2421 """
2423 """
2422 wlock = repo.wlock(False)
2424 wlock = repo.wlock(False)
2423 try:
2425 try:
2424 return cmdutil.copy(ui, repo, pats, opts, rename=True)
2426 return cmdutil.copy(ui, repo, pats, opts, rename=True)
2425 finally:
2427 finally:
2426 wlock.release()
2428 wlock.release()
2427
2429
2428 def resolve(ui, repo, *pats, **opts):
2430 def resolve(ui, repo, *pats, **opts):
2429 """retry file merges from a merge or update
2431 """retry file merges from a merge or update
2430
2432
2431 This command will cleanly retry unresolved file merges using file
2433 This command will cleanly retry unresolved file merges using file
2432 revisions preserved from the last update or merge. To attempt to
2434 revisions preserved from the last update or merge. To attempt to
2433 resolve all unresolved files, use the -a/--all switch.
2435 resolve all unresolved files, use the -a/--all switch.
2434
2436
2435 If a conflict is resolved manually, please note that the changes
2437 If a conflict is resolved manually, please note that the changes
2436 will be overwritten if the merge is retried with resolve. The
2438 will be overwritten if the merge is retried with resolve. The
2437 -m/--mark switch should be used to mark the file as resolved.
2439 -m/--mark switch should be used to mark the file as resolved.
2438
2440
2439 This command also allows listing resolved files and manually
2441 This command also allows listing resolved files and manually
2440 indicating whether or not files are resolved. All files must be
2442 indicating whether or not files are resolved. All files must be
2441 marked as resolved before a commit is permitted.
2443 marked as resolved before a commit is permitted.
2442
2444
2443 The codes used to show the status of files are:
2445 The codes used to show the status of files are:
2444 U = unresolved
2446 U = unresolved
2445 R = resolved
2447 R = resolved
2446 """
2448 """
2447
2449
2448 all, mark, unmark, show = [opts.get(o) for o in 'all mark unmark list'.split()]
2450 all, mark, unmark, show = [opts.get(o) for o in 'all mark unmark list'.split()]
2449
2451
2450 if (show and (mark or unmark)) or (mark and unmark):
2452 if (show and (mark or unmark)) or (mark and unmark):
2451 raise util.Abort(_("too many options specified"))
2453 raise util.Abort(_("too many options specified"))
2452 if pats and all:
2454 if pats and all:
2453 raise util.Abort(_("can't specify --all and patterns"))
2455 raise util.Abort(_("can't specify --all and patterns"))
2454 if not (all or pats or show or mark or unmark):
2456 if not (all or pats or show or mark or unmark):
2455 raise util.Abort(_('no files or directories specified; '
2457 raise util.Abort(_('no files or directories specified; '
2456 'use --all to remerge all files'))
2458 'use --all to remerge all files'))
2457
2459
2458 ms = merge_.mergestate(repo)
2460 ms = merge_.mergestate(repo)
2459 m = cmdutil.match(repo, pats, opts)
2461 m = cmdutil.match(repo, pats, opts)
2460
2462
2461 for f in ms:
2463 for f in ms:
2462 if m(f):
2464 if m(f):
2463 if show:
2465 if show:
2464 ui.write("%s %s\n" % (ms[f].upper(), f))
2466 ui.write("%s %s\n" % (ms[f].upper(), f))
2465 elif mark:
2467 elif mark:
2466 ms.mark(f, "r")
2468 ms.mark(f, "r")
2467 elif unmark:
2469 elif unmark:
2468 ms.mark(f, "u")
2470 ms.mark(f, "u")
2469 else:
2471 else:
2470 wctx = repo[None]
2472 wctx = repo[None]
2471 mctx = wctx.parents()[-1]
2473 mctx = wctx.parents()[-1]
2472
2474
2473 # backup pre-resolve (merge uses .orig for its own purposes)
2475 # backup pre-resolve (merge uses .orig for its own purposes)
2474 a = repo.wjoin(f)
2476 a = repo.wjoin(f)
2475 util.copyfile(a, a + ".resolve")
2477 util.copyfile(a, a + ".resolve")
2476
2478
2477 # resolve file
2479 # resolve file
2478 ms.resolve(f, wctx, mctx)
2480 ms.resolve(f, wctx, mctx)
2479
2481
2480 # replace filemerge's .orig file with our resolve file
2482 # replace filemerge's .orig file with our resolve file
2481 util.rename(a + ".resolve", a + ".orig")
2483 util.rename(a + ".resolve", a + ".orig")
2482
2484
2483 def revert(ui, repo, *pats, **opts):
2485 def revert(ui, repo, *pats, **opts):
2484 """restore individual files or directories to an earlier state
2486 """restore individual files or directories to an earlier state
2485
2487
2486 (Use update -r to check out earlier revisions, revert does not
2488 (Use update -r to check out earlier revisions, revert does not
2487 change the working directory parents.)
2489 change the working directory parents.)
2488
2490
2489 With no revision specified, revert the named files or directories
2491 With no revision specified, revert the named files or directories
2490 to the contents they had in the parent of the working directory.
2492 to the contents they had in the parent of the working directory.
2491 This restores the contents of the affected files to an unmodified
2493 This restores the contents of the affected files to an unmodified
2492 state and unschedules adds, removes, copies, and renames. If the
2494 state and unschedules adds, removes, copies, and renames. If the
2493 working directory has two parents, you must explicitly specify the
2495 working directory has two parents, you must explicitly specify the
2494 revision to revert to.
2496 revision to revert to.
2495
2497
2496 Using the -r/--rev option, revert the given files or directories
2498 Using the -r/--rev option, revert the given files or directories
2497 to their contents as of a specific revision. This can be helpful
2499 to their contents as of a specific revision. This can be helpful
2498 to "roll back" some or all of an earlier change. See 'hg help
2500 to "roll back" some or all of an earlier change. See 'hg help
2499 dates' for a list of formats valid for -d/--date.
2501 dates' for a list of formats valid for -d/--date.
2500
2502
2501 Revert modifies the working directory. It does not commit any
2503 Revert modifies the working directory. It does not commit any
2502 changes, or change the parent of the working directory. If you
2504 changes, or change the parent of the working directory. If you
2503 revert to a revision other than the parent of the working
2505 revert to a revision other than the parent of the working
2504 directory, the reverted files will thus appear modified
2506 directory, the reverted files will thus appear modified
2505 afterwards.
2507 afterwards.
2506
2508
2507 If a file has been deleted, it is restored. If the executable mode
2509 If a file has been deleted, it is restored. If the executable mode
2508 of a file was changed, it is reset.
2510 of a file was changed, it is reset.
2509
2511
2510 If names are given, all files matching the names are reverted.
2512 If names are given, all files matching the names are reverted.
2511 If no arguments are given, no files are reverted.
2513 If no arguments are given, no files are reverted.
2512
2514
2513 Modified files are saved with a .orig suffix before reverting.
2515 Modified files are saved with a .orig suffix before reverting.
2514 To disable these backups, use --no-backup.
2516 To disable these backups, use --no-backup.
2515 """
2517 """
2516
2518
2517 if opts["date"]:
2519 if opts["date"]:
2518 if opts["rev"]:
2520 if opts["rev"]:
2519 raise util.Abort(_("you can't specify a revision and a date"))
2521 raise util.Abort(_("you can't specify a revision and a date"))
2520 opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
2522 opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
2521
2523
2522 if not pats and not opts.get('all'):
2524 if not pats and not opts.get('all'):
2523 raise util.Abort(_('no files or directories specified; '
2525 raise util.Abort(_('no files or directories specified; '
2524 'use --all to revert the whole repo'))
2526 'use --all to revert the whole repo'))
2525
2527
2526 parent, p2 = repo.dirstate.parents()
2528 parent, p2 = repo.dirstate.parents()
2527 if not opts.get('rev') and p2 != nullid:
2529 if not opts.get('rev') and p2 != nullid:
2528 raise util.Abort(_('uncommitted merge - please provide a '
2530 raise util.Abort(_('uncommitted merge - please provide a '
2529 'specific revision'))
2531 'specific revision'))
2530 ctx = repo[opts.get('rev')]
2532 ctx = repo[opts.get('rev')]
2531 node = ctx.node()
2533 node = ctx.node()
2532 mf = ctx.manifest()
2534 mf = ctx.manifest()
2533 if node == parent:
2535 if node == parent:
2534 pmf = mf
2536 pmf = mf
2535 else:
2537 else:
2536 pmf = None
2538 pmf = None
2537
2539
2538 # need all matching names in dirstate and manifest of target rev,
2540 # need all matching names in dirstate and manifest of target rev,
2539 # so have to walk both. do not print errors if files exist in one
2541 # so have to walk both. do not print errors if files exist in one
2540 # but not other.
2542 # but not other.
2541
2543
2542 names = {}
2544 names = {}
2543
2545
2544 wlock = repo.wlock()
2546 wlock = repo.wlock()
2545 try:
2547 try:
2546 # walk dirstate.
2548 # walk dirstate.
2547
2549
2548 m = cmdutil.match(repo, pats, opts)
2550 m = cmdutil.match(repo, pats, opts)
2549 m.bad = lambda x,y: False
2551 m.bad = lambda x,y: False
2550 for abs in repo.walk(m):
2552 for abs in repo.walk(m):
2551 names[abs] = m.rel(abs), m.exact(abs)
2553 names[abs] = m.rel(abs), m.exact(abs)
2552
2554
2553 # walk target manifest.
2555 # walk target manifest.
2554
2556
2555 def badfn(path, msg):
2557 def badfn(path, msg):
2556 if path in names:
2558 if path in names:
2557 return
2559 return
2558 path_ = path + '/'
2560 path_ = path + '/'
2559 for f in names:
2561 for f in names:
2560 if f.startswith(path_):
2562 if f.startswith(path_):
2561 return
2563 return
2562 ui.warn("%s: %s\n" % (m.rel(path), msg))
2564 ui.warn("%s: %s\n" % (m.rel(path), msg))
2563
2565
2564 m = cmdutil.match(repo, pats, opts)
2566 m = cmdutil.match(repo, pats, opts)
2565 m.bad = badfn
2567 m.bad = badfn
2566 for abs in repo[node].walk(m):
2568 for abs in repo[node].walk(m):
2567 if abs not in names:
2569 if abs not in names:
2568 names[abs] = m.rel(abs), m.exact(abs)
2570 names[abs] = m.rel(abs), m.exact(abs)
2569
2571
2570 m = cmdutil.matchfiles(repo, names)
2572 m = cmdutil.matchfiles(repo, names)
2571 changes = repo.status(match=m)[:4]
2573 changes = repo.status(match=m)[:4]
2572 modified, added, removed, deleted = map(set, changes)
2574 modified, added, removed, deleted = map(set, changes)
2573
2575
2574 # if f is a rename, also revert the source
2576 # if f is a rename, also revert the source
2575 cwd = repo.getcwd()
2577 cwd = repo.getcwd()
2576 for f in added:
2578 for f in added:
2577 src = repo.dirstate.copied(f)
2579 src = repo.dirstate.copied(f)
2578 if src and src not in names and repo.dirstate[src] == 'r':
2580 if src and src not in names and repo.dirstate[src] == 'r':
2579 removed.add(src)
2581 removed.add(src)
2580 names[src] = (repo.pathto(src, cwd), True)
2582 names[src] = (repo.pathto(src, cwd), True)
2581
2583
2582 def removeforget(abs):
2584 def removeforget(abs):
2583 if repo.dirstate[abs] == 'a':
2585 if repo.dirstate[abs] == 'a':
2584 return _('forgetting %s\n')
2586 return _('forgetting %s\n')
2585 return _('removing %s\n')
2587 return _('removing %s\n')
2586
2588
2587 revert = ([], _('reverting %s\n'))
2589 revert = ([], _('reverting %s\n'))
2588 add = ([], _('adding %s\n'))
2590 add = ([], _('adding %s\n'))
2589 remove = ([], removeforget)
2591 remove = ([], removeforget)
2590 undelete = ([], _('undeleting %s\n'))
2592 undelete = ([], _('undeleting %s\n'))
2591
2593
2592 disptable = (
2594 disptable = (
2593 # dispatch table:
2595 # dispatch table:
2594 # file state
2596 # file state
2595 # action if in target manifest
2597 # action if in target manifest
2596 # action if not in target manifest
2598 # action if not in target manifest
2597 # make backup if in target manifest
2599 # make backup if in target manifest
2598 # make backup if not in target manifest
2600 # make backup if not in target manifest
2599 (modified, revert, remove, True, True),
2601 (modified, revert, remove, True, True),
2600 (added, revert, remove, True, False),
2602 (added, revert, remove, True, False),
2601 (removed, undelete, None, False, False),
2603 (removed, undelete, None, False, False),
2602 (deleted, revert, remove, False, False),
2604 (deleted, revert, remove, False, False),
2603 )
2605 )
2604
2606
2605 for abs, (rel, exact) in sorted(names.items()):
2607 for abs, (rel, exact) in sorted(names.items()):
2606 mfentry = mf.get(abs)
2608 mfentry = mf.get(abs)
2607 target = repo.wjoin(abs)
2609 target = repo.wjoin(abs)
2608 def handle(xlist, dobackup):
2610 def handle(xlist, dobackup):
2609 xlist[0].append(abs)
2611 xlist[0].append(abs)
2610 if dobackup and not opts.get('no_backup') and util.lexists(target):
2612 if dobackup and not opts.get('no_backup') and util.lexists(target):
2611 bakname = "%s.orig" % rel
2613 bakname = "%s.orig" % rel
2612 ui.note(_('saving current version of %s as %s\n') %
2614 ui.note(_('saving current version of %s as %s\n') %
2613 (rel, bakname))
2615 (rel, bakname))
2614 if not opts.get('dry_run'):
2616 if not opts.get('dry_run'):
2615 util.copyfile(target, bakname)
2617 util.copyfile(target, bakname)
2616 if ui.verbose or not exact:
2618 if ui.verbose or not exact:
2617 msg = xlist[1]
2619 msg = xlist[1]
2618 if not isinstance(msg, basestring):
2620 if not isinstance(msg, basestring):
2619 msg = msg(abs)
2621 msg = msg(abs)
2620 ui.status(msg % rel)
2622 ui.status(msg % rel)
2621 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2623 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2622 if abs not in table: continue
2624 if abs not in table: continue
2623 # file has changed in dirstate
2625 # file has changed in dirstate
2624 if mfentry:
2626 if mfentry:
2625 handle(hitlist, backuphit)
2627 handle(hitlist, backuphit)
2626 elif misslist is not None:
2628 elif misslist is not None:
2627 handle(misslist, backupmiss)
2629 handle(misslist, backupmiss)
2628 break
2630 break
2629 else:
2631 else:
2630 if abs not in repo.dirstate:
2632 if abs not in repo.dirstate:
2631 if mfentry:
2633 if mfentry:
2632 handle(add, True)
2634 handle(add, True)
2633 elif exact:
2635 elif exact:
2634 ui.warn(_('file not managed: %s\n') % rel)
2636 ui.warn(_('file not managed: %s\n') % rel)
2635 continue
2637 continue
2636 # file has not changed in dirstate
2638 # file has not changed in dirstate
2637 if node == parent:
2639 if node == parent:
2638 if exact: ui.warn(_('no changes needed to %s\n') % rel)
2640 if exact: ui.warn(_('no changes needed to %s\n') % rel)
2639 continue
2641 continue
2640 if pmf is None:
2642 if pmf is None:
2641 # only need parent manifest in this unlikely case,
2643 # only need parent manifest in this unlikely case,
2642 # so do not read by default
2644 # so do not read by default
2643 pmf = repo[parent].manifest()
2645 pmf = repo[parent].manifest()
2644 if abs in pmf:
2646 if abs in pmf:
2645 if mfentry:
2647 if mfentry:
2646 # if version of file is same in parent and target
2648 # if version of file is same in parent and target
2647 # manifests, do nothing
2649 # manifests, do nothing
2648 if (pmf[abs] != mfentry or
2650 if (pmf[abs] != mfentry or
2649 pmf.flags(abs) != mf.flags(abs)):
2651 pmf.flags(abs) != mf.flags(abs)):
2650 handle(revert, False)
2652 handle(revert, False)
2651 else:
2653 else:
2652 handle(remove, False)
2654 handle(remove, False)
2653
2655
2654 if not opts.get('dry_run'):
2656 if not opts.get('dry_run'):
2655 def checkout(f):
2657 def checkout(f):
2656 fc = ctx[f]
2658 fc = ctx[f]
2657 repo.wwrite(f, fc.data(), fc.flags())
2659 repo.wwrite(f, fc.data(), fc.flags())
2658
2660
2659 audit_path = util.path_auditor(repo.root)
2661 audit_path = util.path_auditor(repo.root)
2660 for f in remove[0]:
2662 for f in remove[0]:
2661 if repo.dirstate[f] == 'a':
2663 if repo.dirstate[f] == 'a':
2662 repo.dirstate.forget(f)
2664 repo.dirstate.forget(f)
2663 continue
2665 continue
2664 audit_path(f)
2666 audit_path(f)
2665 try:
2667 try:
2666 util.unlink(repo.wjoin(f))
2668 util.unlink(repo.wjoin(f))
2667 except OSError:
2669 except OSError:
2668 pass
2670 pass
2669 repo.dirstate.remove(f)
2671 repo.dirstate.remove(f)
2670
2672
2671 normal = None
2673 normal = None
2672 if node == parent:
2674 if node == parent:
2673 # We're reverting to our parent. If possible, we'd like status
2675 # We're reverting to our parent. If possible, we'd like status
2674 # to report the file as clean. We have to use normallookup for
2676 # to report the file as clean. We have to use normallookup for
2675 # merges to avoid losing information about merged/dirty files.
2677 # merges to avoid losing information about merged/dirty files.
2676 if p2 != nullid:
2678 if p2 != nullid:
2677 normal = repo.dirstate.normallookup
2679 normal = repo.dirstate.normallookup
2678 else:
2680 else:
2679 normal = repo.dirstate.normal
2681 normal = repo.dirstate.normal
2680 for f in revert[0]:
2682 for f in revert[0]:
2681 checkout(f)
2683 checkout(f)
2682 if normal:
2684 if normal:
2683 normal(f)
2685 normal(f)
2684
2686
2685 for f in add[0]:
2687 for f in add[0]:
2686 checkout(f)
2688 checkout(f)
2687 repo.dirstate.add(f)
2689 repo.dirstate.add(f)
2688
2690
2689 normal = repo.dirstate.normallookup
2691 normal = repo.dirstate.normallookup
2690 if node == parent and p2 == nullid:
2692 if node == parent and p2 == nullid:
2691 normal = repo.dirstate.normal
2693 normal = repo.dirstate.normal
2692 for f in undelete[0]:
2694 for f in undelete[0]:
2693 checkout(f)
2695 checkout(f)
2694 normal(f)
2696 normal(f)
2695
2697
2696 finally:
2698 finally:
2697 wlock.release()
2699 wlock.release()
2698
2700
2699 def rollback(ui, repo):
2701 def rollback(ui, repo):
2700 """roll back the last transaction
2702 """roll back the last transaction
2701
2703
2702 This command should be used with care. There is only one level of
2704 This command should be used with care. There is only one level of
2703 rollback, and there is no way to undo a rollback. It will also
2705 rollback, and there is no way to undo a rollback. It will also
2704 restore the dirstate at the time of the last transaction, losing
2706 restore the dirstate at the time of the last transaction, losing
2705 any dirstate changes since that time. This command does not alter
2707 any dirstate changes since that time. This command does not alter
2706 the working directory.
2708 the working directory.
2707
2709
2708 Transactions are used to encapsulate the effects of all commands
2710 Transactions are used to encapsulate the effects of all commands
2709 that create new changesets or propagate existing changesets into a
2711 that create new changesets or propagate existing changesets into a
2710 repository. For example, the following commands are transactional,
2712 repository. For example, the following commands are transactional,
2711 and their effects can be rolled back:
2713 and their effects can be rolled back:
2712
2714
2713 commit
2715 commit
2714 import
2716 import
2715 pull
2717 pull
2716 push (with this repository as destination)
2718 push (with this repository as destination)
2717 unbundle
2719 unbundle
2718
2720
2719 This command is not intended for use on public repositories. Once
2721 This command is not intended for use on public repositories. Once
2720 changes are visible for pull by other users, rolling a transaction
2722 changes are visible for pull by other users, rolling a transaction
2721 back locally is ineffective (someone else may already have pulled
2723 back locally is ineffective (someone else may already have pulled
2722 the changes). Furthermore, a race is possible with readers of the
2724 the changes). Furthermore, a race is possible with readers of the
2723 repository; for example an in-progress pull from the repository
2725 repository; for example an in-progress pull from the repository
2724 may fail if a rollback is performed.
2726 may fail if a rollback is performed.
2725 """
2727 """
2726 repo.rollback()
2728 repo.rollback()
2727
2729
2728 def root(ui, repo):
2730 def root(ui, repo):
2729 """print the root (top) of the current working directory
2731 """print the root (top) of the current working directory
2730
2732
2731 Print the root directory of the current repository.
2733 Print the root directory of the current repository.
2732 """
2734 """
2733 ui.write(repo.root + "\n")
2735 ui.write(repo.root + "\n")
2734
2736
2735 def serve(ui, repo, **opts):
2737 def serve(ui, repo, **opts):
2736 """export the repository via HTTP
2738 """export the repository via HTTP
2737
2739
2738 Start a local HTTP repository browser and pull server.
2740 Start a local HTTP repository browser and pull server.
2739
2741
2740 By default, the server logs accesses to stdout and errors to
2742 By default, the server logs accesses to stdout and errors to
2741 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
2743 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
2742 files.
2744 files.
2743 """
2745 """
2744
2746
2745 if opts["stdio"]:
2747 if opts["stdio"]:
2746 if repo is None:
2748 if repo is None:
2747 raise error.RepoError(_("There is no Mercurial repository here"
2749 raise error.RepoError(_("There is no Mercurial repository here"
2748 " (.hg not found)"))
2750 " (.hg not found)"))
2749 s = sshserver.sshserver(ui, repo)
2751 s = sshserver.sshserver(ui, repo)
2750 s.serve_forever()
2752 s.serve_forever()
2751
2753
2752 baseui = repo and repo.baseui or ui
2754 baseui = repo and repo.baseui or ui
2753 optlist = ("name templates style address port prefix ipv6"
2755 optlist = ("name templates style address port prefix ipv6"
2754 " accesslog errorlog webdir_conf certificate encoding")
2756 " accesslog errorlog webdir_conf certificate encoding")
2755 for o in optlist.split():
2757 for o in optlist.split():
2756 if opts.get(o, None):
2758 if opts.get(o, None):
2757 baseui.setconfig("web", o, str(opts[o]))
2759 baseui.setconfig("web", o, str(opts[o]))
2758 if (repo is not None) and (repo.ui != baseui):
2760 if (repo is not None) and (repo.ui != baseui):
2759 repo.ui.setconfig("web", o, str(opts[o]))
2761 repo.ui.setconfig("web", o, str(opts[o]))
2760
2762
2761 if repo is None and not ui.config("web", "webdir_conf"):
2763 if repo is None and not ui.config("web", "webdir_conf"):
2762 raise error.RepoError(_("There is no Mercurial repository here"
2764 raise error.RepoError(_("There is no Mercurial repository here"
2763 " (.hg not found)"))
2765 " (.hg not found)"))
2764
2766
2765 class service(object):
2767 class service(object):
2766 def init(self):
2768 def init(self):
2767 util.set_signal_handler()
2769 util.set_signal_handler()
2768 self.httpd = server.create_server(baseui, repo)
2770 self.httpd = server.create_server(baseui, repo)
2769
2771
2770 if not ui.verbose: return
2772 if not ui.verbose: return
2771
2773
2772 if self.httpd.prefix:
2774 if self.httpd.prefix:
2773 prefix = self.httpd.prefix.strip('/') + '/'
2775 prefix = self.httpd.prefix.strip('/') + '/'
2774 else:
2776 else:
2775 prefix = ''
2777 prefix = ''
2776
2778
2777 port = ':%d' % self.httpd.port
2779 port = ':%d' % self.httpd.port
2778 if port == ':80':
2780 if port == ':80':
2779 port = ''
2781 port = ''
2780
2782
2781 bindaddr = self.httpd.addr
2783 bindaddr = self.httpd.addr
2782 if bindaddr == '0.0.0.0':
2784 if bindaddr == '0.0.0.0':
2783 bindaddr = '*'
2785 bindaddr = '*'
2784 elif ':' in bindaddr: # IPv6
2786 elif ':' in bindaddr: # IPv6
2785 bindaddr = '[%s]' % bindaddr
2787 bindaddr = '[%s]' % bindaddr
2786
2788
2787 fqaddr = self.httpd.fqaddr
2789 fqaddr = self.httpd.fqaddr
2788 if ':' in fqaddr:
2790 if ':' in fqaddr:
2789 fqaddr = '[%s]' % fqaddr
2791 fqaddr = '[%s]' % fqaddr
2790 ui.status(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
2792 ui.status(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
2791 (fqaddr, port, prefix, bindaddr, self.httpd.port))
2793 (fqaddr, port, prefix, bindaddr, self.httpd.port))
2792
2794
2793 def run(self):
2795 def run(self):
2794 self.httpd.serve_forever()
2796 self.httpd.serve_forever()
2795
2797
2796 service = service()
2798 service = service()
2797
2799
2798 cmdutil.service(opts, initfn=service.init, runfn=service.run)
2800 cmdutil.service(opts, initfn=service.init, runfn=service.run)
2799
2801
2800 def status(ui, repo, *pats, **opts):
2802 def status(ui, repo, *pats, **opts):
2801 """show changed files in the working directory
2803 """show changed files in the working directory
2802
2804
2803 Show status of files in the repository. If names are given, only
2805 Show status of files in the repository. If names are given, only
2804 files that match are shown. Files that are clean or ignored or
2806 files that match are shown. Files that are clean or ignored or
2805 the source of a copy/move operation, are not listed unless
2807 the source of a copy/move operation, are not listed unless
2806 -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
2808 -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
2807 Unless options described with "show only ..." are given, the
2809 Unless options described with "show only ..." are given, the
2808 options -mardu are used.
2810 options -mardu are used.
2809
2811
2810 Option -q/--quiet hides untracked (unknown and ignored) files
2812 Option -q/--quiet hides untracked (unknown and ignored) files
2811 unless explicitly requested with -u/--unknown or -i/--ignored.
2813 unless explicitly requested with -u/--unknown or -i/--ignored.
2812
2814
2813 NOTE: status may appear to disagree with diff if permissions have
2815 NOTE: status may appear to disagree with diff if permissions have
2814 changed or a merge has occurred. The standard diff format does not
2816 changed or a merge has occurred. The standard diff format does not
2815 report permission changes and diff only reports changes relative
2817 report permission changes and diff only reports changes relative
2816 to one merge parent.
2818 to one merge parent.
2817
2819
2818 If one revision is given, it is used as the base revision.
2820 If one revision is given, it is used as the base revision.
2819 If two revisions are given, the differences between them are
2821 If two revisions are given, the differences between them are
2820 shown.
2822 shown.
2821
2823
2822 The codes used to show the status of files are:
2824 The codes used to show the status of files are:
2823 M = modified
2825 M = modified
2824 A = added
2826 A = added
2825 R = removed
2827 R = removed
2826 C = clean
2828 C = clean
2827 ! = missing (deleted by non-hg command, but still tracked)
2829 ! = missing (deleted by non-hg command, but still tracked)
2828 ? = not tracked
2830 ? = not tracked
2829 I = ignored
2831 I = ignored
2830 = origin of the previous file listed as A (added)
2832 = origin of the previous file listed as A (added)
2831 """
2833 """
2832
2834
2833 node1, node2 = cmdutil.revpair(repo, opts.get('rev'))
2835 node1, node2 = cmdutil.revpair(repo, opts.get('rev'))
2834 cwd = (pats and repo.getcwd()) or ''
2836 cwd = (pats and repo.getcwd()) or ''
2835 end = opts.get('print0') and '\0' or '\n'
2837 end = opts.get('print0') and '\0' or '\n'
2836 copy = {}
2838 copy = {}
2837 states = 'modified added removed deleted unknown ignored clean'.split()
2839 states = 'modified added removed deleted unknown ignored clean'.split()
2838 show = [k for k in states if opts.get(k)]
2840 show = [k for k in states if opts.get(k)]
2839 if opts.get('all'):
2841 if opts.get('all'):
2840 show += ui.quiet and (states[:4] + ['clean']) or states
2842 show += ui.quiet and (states[:4] + ['clean']) or states
2841 if not show:
2843 if not show:
2842 show = ui.quiet and states[:4] or states[:5]
2844 show = ui.quiet and states[:4] or states[:5]
2843
2845
2844 stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
2846 stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
2845 'ignored' in show, 'clean' in show, 'unknown' in show)
2847 'ignored' in show, 'clean' in show, 'unknown' in show)
2846 changestates = zip(states, 'MAR!?IC', stat)
2848 changestates = zip(states, 'MAR!?IC', stat)
2847
2849
2848 if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
2850 if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'):
2849 ctxn = repo[nullid]
2851 ctxn = repo[nullid]
2850 ctx1 = repo[node1]
2852 ctx1 = repo[node1]
2851 ctx2 = repo[node2]
2853 ctx2 = repo[node2]
2852 added = stat[1]
2854 added = stat[1]
2853 if node2 is None:
2855 if node2 is None:
2854 added = stat[0] + stat[1] # merged?
2856 added = stat[0] + stat[1] # merged?
2855
2857
2856 for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems():
2858 for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems():
2857 if k in added:
2859 if k in added:
2858 copy[k] = v
2860 copy[k] = v
2859 elif v in added:
2861 elif v in added:
2860 copy[v] = k
2862 copy[v] = k
2861
2863
2862 for state, char, files in changestates:
2864 for state, char, files in changestates:
2863 if state in show:
2865 if state in show:
2864 format = "%s %%s%s" % (char, end)
2866 format = "%s %%s%s" % (char, end)
2865 if opts.get('no_status'):
2867 if opts.get('no_status'):
2866 format = "%%s%s" % end
2868 format = "%%s%s" % end
2867
2869
2868 for f in files:
2870 for f in files:
2869 ui.write(format % repo.pathto(f, cwd))
2871 ui.write(format % repo.pathto(f, cwd))
2870 if f in copy:
2872 if f in copy:
2871 ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end))
2873 ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end))
2872
2874
2873 def tag(ui, repo, name1, *names, **opts):
2875 def tag(ui, repo, name1, *names, **opts):
2874 """add one or more tags for the current or given revision
2876 """add one or more tags for the current or given revision
2875
2877
2876 Name a particular revision using <name>.
2878 Name a particular revision using <name>.
2877
2879
2878 Tags are used to name particular revisions of the repository and are
2880 Tags are used to name particular revisions of the repository and are
2879 very useful to compare different revisions, to go back to significant
2881 very useful to compare different revisions, to go back to significant
2880 earlier versions or to mark branch points as releases, etc.
2882 earlier versions or to mark branch points as releases, etc.
2881
2883
2882 If no revision is given, the parent of the working directory is
2884 If no revision is given, the parent of the working directory is
2883 used, or tip if no revision is checked out.
2885 used, or tip if no revision is checked out.
2884
2886
2885 To facilitate version control, distribution, and merging of tags,
2887 To facilitate version control, distribution, and merging of tags,
2886 they are stored as a file named ".hgtags" which is managed
2888 they are stored as a file named ".hgtags" which is managed
2887 similarly to other project files and can be hand-edited if
2889 similarly to other project files and can be hand-edited if
2888 necessary. The file '.hg/localtags' is used for local tags (not
2890 necessary. The file '.hg/localtags' is used for local tags (not
2889 shared among repositories).
2891 shared among repositories).
2890
2892
2891 See 'hg help dates' for a list of formats valid for -d/--date.
2893 See 'hg help dates' for a list of formats valid for -d/--date.
2892 """
2894 """
2893
2895
2894 rev_ = "."
2896 rev_ = "."
2895 names = (name1,) + names
2897 names = (name1,) + names
2896 if len(names) != len(set(names)):
2898 if len(names) != len(set(names)):
2897 raise util.Abort(_('tag names must be unique'))
2899 raise util.Abort(_('tag names must be unique'))
2898 for n in names:
2900 for n in names:
2899 if n in ['tip', '.', 'null']:
2901 if n in ['tip', '.', 'null']:
2900 raise util.Abort(_('the name \'%s\' is reserved') % n)
2902 raise util.Abort(_('the name \'%s\' is reserved') % n)
2901 if opts.get('rev') and opts.get('remove'):
2903 if opts.get('rev') and opts.get('remove'):
2902 raise util.Abort(_("--rev and --remove are incompatible"))
2904 raise util.Abort(_("--rev and --remove are incompatible"))
2903 if opts.get('rev'):
2905 if opts.get('rev'):
2904 rev_ = opts['rev']
2906 rev_ = opts['rev']
2905 message = opts.get('message')
2907 message = opts.get('message')
2906 if opts.get('remove'):
2908 if opts.get('remove'):
2907 expectedtype = opts.get('local') and 'local' or 'global'
2909 expectedtype = opts.get('local') and 'local' or 'global'
2908 for n in names:
2910 for n in names:
2909 if not repo.tagtype(n):
2911 if not repo.tagtype(n):
2910 raise util.Abort(_('tag \'%s\' does not exist') % n)
2912 raise util.Abort(_('tag \'%s\' does not exist') % n)
2911 if repo.tagtype(n) != expectedtype:
2913 if repo.tagtype(n) != expectedtype:
2912 if expectedtype == 'global':
2914 if expectedtype == 'global':
2913 raise util.Abort(_('tag \'%s\' is not a global tag') % n)
2915 raise util.Abort(_('tag \'%s\' is not a global tag') % n)
2914 else:
2916 else:
2915 raise util.Abort(_('tag \'%s\' is not a local tag') % n)
2917 raise util.Abort(_('tag \'%s\' is not a local tag') % n)
2916 rev_ = nullid
2918 rev_ = nullid
2917 if not message:
2919 if not message:
2918 message = _('Removed tag %s') % ', '.join(names)
2920 message = _('Removed tag %s') % ', '.join(names)
2919 elif not opts.get('force'):
2921 elif not opts.get('force'):
2920 for n in names:
2922 for n in names:
2921 if n in repo.tags():
2923 if n in repo.tags():
2922 raise util.Abort(_('tag \'%s\' already exists '
2924 raise util.Abort(_('tag \'%s\' already exists '
2923 '(use -f to force)') % n)
2925 '(use -f to force)') % n)
2924 if not rev_ and repo.dirstate.parents()[1] != nullid:
2926 if not rev_ and repo.dirstate.parents()[1] != nullid:
2925 raise util.Abort(_('uncommitted merge - please provide a '
2927 raise util.Abort(_('uncommitted merge - please provide a '
2926 'specific revision'))
2928 'specific revision'))
2927 r = repo[rev_].node()
2929 r = repo[rev_].node()
2928
2930
2929 if not message:
2931 if not message:
2930 message = (_('Added tag %s for changeset %s') %
2932 message = (_('Added tag %s for changeset %s') %
2931 (', '.join(names), short(r)))
2933 (', '.join(names), short(r)))
2932
2934
2933 date = opts.get('date')
2935 date = opts.get('date')
2934 if date:
2936 if date:
2935 date = util.parsedate(date)
2937 date = util.parsedate(date)
2936
2938
2937 repo.tag(names, r, message, opts.get('local'), opts.get('user'), date)
2939 repo.tag(names, r, message, opts.get('local'), opts.get('user'), date)
2938
2940
2939 def tags(ui, repo):
2941 def tags(ui, repo):
2940 """list repository tags
2942 """list repository tags
2941
2943
2942 This lists both regular and local tags. When the -v/--verbose
2944 This lists both regular and local tags. When the -v/--verbose
2943 switch is used, a third column "local" is printed for local tags.
2945 switch is used, a third column "local" is printed for local tags.
2944 """
2946 """
2945
2947
2946 hexfunc = ui.debugflag and hex or short
2948 hexfunc = ui.debugflag and hex or short
2947 tagtype = ""
2949 tagtype = ""
2948
2950
2949 for t, n in reversed(repo.tagslist()):
2951 for t, n in reversed(repo.tagslist()):
2950 if ui.quiet:
2952 if ui.quiet:
2951 ui.write("%s\n" % t)
2953 ui.write("%s\n" % t)
2952 continue
2954 continue
2953
2955
2954 try:
2956 try:
2955 hn = hexfunc(n)
2957 hn = hexfunc(n)
2956 r = "%5d:%s" % (repo.changelog.rev(n), hn)
2958 r = "%5d:%s" % (repo.changelog.rev(n), hn)
2957 except error.LookupError:
2959 except error.LookupError:
2958 r = " ?:%s" % hn
2960 r = " ?:%s" % hn
2959 else:
2961 else:
2960 spaces = " " * (30 - encoding.colwidth(t))
2962 spaces = " " * (30 - encoding.colwidth(t))
2961 if ui.verbose:
2963 if ui.verbose:
2962 if repo.tagtype(t) == 'local':
2964 if repo.tagtype(t) == 'local':
2963 tagtype = " local"
2965 tagtype = " local"
2964 else:
2966 else:
2965 tagtype = ""
2967 tagtype = ""
2966 ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype))
2968 ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype))
2967
2969
2968 def tip(ui, repo, **opts):
2970 def tip(ui, repo, **opts):
2969 """show the tip revision
2971 """show the tip revision
2970
2972
2971 The tip revision (usually just called the tip) is the changeset
2973 The tip revision (usually just called the tip) is the changeset
2972 most recently added to the repository (and therefore the most
2974 most recently added to the repository (and therefore the most
2973 recently changed head).
2975 recently changed head).
2974
2976
2975 If you have just made a commit, that commit will be the tip. If
2977 If you have just made a commit, that commit will be the tip. If
2976 you have just pulled changes from another repository, the tip of
2978 you have just pulled changes from another repository, the tip of
2977 that repository becomes the current tip. The "tip" tag is special
2979 that repository becomes the current tip. The "tip" tag is special
2978 and cannot be renamed or assigned to a different changeset.
2980 and cannot be renamed or assigned to a different changeset.
2979 """
2981 """
2980 cmdutil.show_changeset(ui, repo, opts).show(repo[len(repo) - 1])
2982 cmdutil.show_changeset(ui, repo, opts).show(repo[len(repo) - 1])
2981
2983
2982 def unbundle(ui, repo, fname1, *fnames, **opts):
2984 def unbundle(ui, repo, fname1, *fnames, **opts):
2983 """apply one or more changegroup files
2985 """apply one or more changegroup files
2984
2986
2985 Apply one or more compressed changegroup files generated by the
2987 Apply one or more compressed changegroup files generated by the
2986 bundle command.
2988 bundle command.
2987 """
2989 """
2988 fnames = (fname1,) + fnames
2990 fnames = (fname1,) + fnames
2989
2991
2990 lock = repo.lock()
2992 lock = repo.lock()
2991 try:
2993 try:
2992 for fname in fnames:
2994 for fname in fnames:
2993 f = url.open(ui, fname)
2995 f = url.open(ui, fname)
2994 gen = changegroup.readbundle(f, fname)
2996 gen = changegroup.readbundle(f, fname)
2995 modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
2997 modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
2996 finally:
2998 finally:
2997 lock.release()
2999 lock.release()
2998
3000
2999 return postincoming(ui, repo, modheads, opts.get('update'), None)
3001 return postincoming(ui, repo, modheads, opts.get('update'), None)
3000
3002
3001 def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False):
3003 def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False):
3002 """update working directory
3004 """update working directory
3003
3005
3004 Update the repository's working directory to the specified
3006 Update the repository's working directory to the specified
3005 revision, or the tip of the current branch if none is specified.
3007 revision, or the tip of the current branch if none is specified.
3006 Use null as the revision to remove the working copy (like 'hg
3008 Use null as the revision to remove the working copy (like 'hg
3007 clone -U').
3009 clone -U').
3008
3010
3009 When the working directory contains no uncommitted changes, it
3011 When the working directory contains no uncommitted changes, it
3010 will be replaced by the state of the requested revision from the
3012 will be replaced by the state of the requested revision from the
3011 repository. When the requested revision is on a different branch,
3013 repository. When the requested revision is on a different branch,
3012 the working directory will additionally be switched to that
3014 the working directory will additionally be switched to that
3013 branch.
3015 branch.
3014
3016
3015 When there are uncommitted changes, use option -C/--clean to
3017 When there are uncommitted changes, use option -C/--clean to
3016 discard them, forcibly replacing the state of the working
3018 discard them, forcibly replacing the state of the working
3017 directory with the requested revision. Alternately, use -c/--check
3019 directory with the requested revision. Alternately, use -c/--check
3018 to abort.
3020 to abort.
3019
3021
3020 When there are uncommitted changes and option -C/--clean is not
3022 When there are uncommitted changes and option -C/--clean is not
3021 used, and the parent revision and requested revision are on the
3023 used, and the parent revision and requested revision are on the
3022 same branch, and one of them is an ancestor of the other, then the
3024 same branch, and one of them is an ancestor of the other, then the
3023 new working directory will contain the requested revision merged
3025 new working directory will contain the requested revision merged
3024 with the uncommitted changes. Otherwise, the update will fail with
3026 with the uncommitted changes. Otherwise, the update will fail with
3025 a suggestion to use 'merge' or 'update -C' instead.
3027 a suggestion to use 'merge' or 'update -C' instead.
3026
3028
3027 If you want to update just one file to an older revision, use
3029 If you want to update just one file to an older revision, use
3028 revert.
3030 revert.
3029
3031
3030 See 'hg help dates' for a list of formats valid for -d/--date.
3032 See 'hg help dates' for a list of formats valid for -d/--date.
3031 """
3033 """
3032 if rev and node:
3034 if rev and node:
3033 raise util.Abort(_("please specify just one revision"))
3035 raise util.Abort(_("please specify just one revision"))
3034
3036
3035 if not rev:
3037 if not rev:
3036 rev = node
3038 rev = node
3037
3039
3038 if not clean and check:
3040 if not clean and check:
3039 # we could use dirty() but we can ignore merge and branch trivia
3041 # we could use dirty() but we can ignore merge and branch trivia
3040 c = repo[None]
3042 c = repo[None]
3041 if c.modified() or c.added() or c.removed():
3043 if c.modified() or c.added() or c.removed():
3042 raise util.Abort(_("uncommitted local changes"))
3044 raise util.Abort(_("uncommitted local changes"))
3043
3045
3044 if date:
3046 if date:
3045 if rev:
3047 if rev:
3046 raise util.Abort(_("you can't specify a revision and a date"))
3048 raise util.Abort(_("you can't specify a revision and a date"))
3047 rev = cmdutil.finddate(ui, repo, date)
3049 rev = cmdutil.finddate(ui, repo, date)
3048
3050
3049 if clean:
3051 if clean:
3050 return hg.clean(repo, rev)
3052 return hg.clean(repo, rev)
3051 else:
3053 else:
3052 return hg.update(repo, rev)
3054 return hg.update(repo, rev)
3053
3055
3054 def verify(ui, repo):
3056 def verify(ui, repo):
3055 """verify the integrity of the repository
3057 """verify the integrity of the repository
3056
3058
3057 Verify the integrity of the current repository.
3059 Verify the integrity of the current repository.
3058
3060
3059 This will perform an extensive check of the repository's
3061 This will perform an extensive check of the repository's
3060 integrity, validating the hashes and checksums of each entry in
3062 integrity, validating the hashes and checksums of each entry in
3061 the changelog, manifest, and tracked files, as well as the
3063 the changelog, manifest, and tracked files, as well as the
3062 integrity of their crosslinks and indices.
3064 integrity of their crosslinks and indices.
3063 """
3065 """
3064 return hg.verify(repo)
3066 return hg.verify(repo)
3065
3067
3066 def version_(ui):
3068 def version_(ui):
3067 """output version and copyright information"""
3069 """output version and copyright information"""
3068 ui.write(_("Mercurial Distributed SCM (version %s)\n")
3070 ui.write(_("Mercurial Distributed SCM (version %s)\n")
3069 % util.version())
3071 % util.version())
3070 ui.status(_(
3072 ui.status(_(
3071 "\nCopyright (C) 2005-2009 Matt Mackall <mpm@selenic.com> and others\n"
3073 "\nCopyright (C) 2005-2009 Matt Mackall <mpm@selenic.com> and others\n"
3072 "This is free software; see the source for copying conditions. "
3074 "This is free software; see the source for copying conditions. "
3073 "There is NO\nwarranty; "
3075 "There is NO\nwarranty; "
3074 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
3076 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
3075 ))
3077 ))
3076
3078
3077 # Command options and aliases are listed here, alphabetically
3079 # Command options and aliases are listed here, alphabetically
3078
3080
3079 globalopts = [
3081 globalopts = [
3080 ('R', 'repository', '',
3082 ('R', 'repository', '',
3081 _('repository root directory or symbolic path name')),
3083 _('repository root directory or symbolic path name')),
3082 ('', 'cwd', '', _('change working directory')),
3084 ('', 'cwd', '', _('change working directory')),
3083 ('y', 'noninteractive', None,
3085 ('y', 'noninteractive', None,
3084 _('do not prompt, assume \'yes\' for any required answers')),
3086 _('do not prompt, assume \'yes\' for any required answers')),
3085 ('q', 'quiet', None, _('suppress output')),
3087 ('q', 'quiet', None, _('suppress output')),
3086 ('v', 'verbose', None, _('enable additional output')),
3088 ('v', 'verbose', None, _('enable additional output')),
3087 ('', 'config', [], _('set/override config option')),
3089 ('', 'config', [], _('set/override config option')),
3088 ('', 'debug', None, _('enable debugging output')),
3090 ('', 'debug', None, _('enable debugging output')),
3089 ('', 'debugger', None, _('start debugger')),
3091 ('', 'debugger', None, _('start debugger')),
3090 ('', 'encoding', encoding.encoding, _('set the charset encoding')),
3092 ('', 'encoding', encoding.encoding, _('set the charset encoding')),
3091 ('', 'encodingmode', encoding.encodingmode,
3093 ('', 'encodingmode', encoding.encodingmode,
3092 _('set the charset encoding mode')),
3094 _('set the charset encoding mode')),
3093 ('', 'traceback', None, _('print traceback on exception')),
3095 ('', 'traceback', None, _('print traceback on exception')),
3094 ('', 'time', None, _('time how long the command takes')),
3096 ('', 'time', None, _('time how long the command takes')),
3095 ('', 'profile', None, _('print command execution profile')),
3097 ('', 'profile', None, _('print command execution profile')),
3096 ('', 'version', None, _('output version information and exit')),
3098 ('', 'version', None, _('output version information and exit')),
3097 ('h', 'help', None, _('display help and exit')),
3099 ('h', 'help', None, _('display help and exit')),
3098 ]
3100 ]
3099
3101
3100 dryrunopts = [('n', 'dry-run', None,
3102 dryrunopts = [('n', 'dry-run', None,
3101 _('do not perform actions, just print output'))]
3103 _('do not perform actions, just print output'))]
3102
3104
3103 remoteopts = [
3105 remoteopts = [
3104 ('e', 'ssh', '', _('specify ssh command to use')),
3106 ('e', 'ssh', '', _('specify ssh command to use')),
3105 ('', 'remotecmd', '', _('specify hg command to run on the remote side')),
3107 ('', 'remotecmd', '', _('specify hg command to run on the remote side')),
3106 ]
3108 ]
3107
3109
3108 walkopts = [
3110 walkopts = [
3109 ('I', 'include', [], _('include names matching the given patterns')),
3111 ('I', 'include', [], _('include names matching the given patterns')),
3110 ('X', 'exclude', [], _('exclude names matching the given patterns')),
3112 ('X', 'exclude', [], _('exclude names matching the given patterns')),
3111 ]
3113 ]
3112
3114
3113 commitopts = [
3115 commitopts = [
3114 ('m', 'message', '', _('use <text> as commit message')),
3116 ('m', 'message', '', _('use <text> as commit message')),
3115 ('l', 'logfile', '', _('read commit message from <file>')),
3117 ('l', 'logfile', '', _('read commit message from <file>')),
3116 ]
3118 ]
3117
3119
3118 commitopts2 = [
3120 commitopts2 = [
3119 ('d', 'date', '', _('record datecode as commit date')),
3121 ('d', 'date', '', _('record datecode as commit date')),
3120 ('u', 'user', '', _('record the specified user as committer')),
3122 ('u', 'user', '', _('record the specified user as committer')),
3121 ]
3123 ]
3122
3124
3123 templateopts = [
3125 templateopts = [
3124 ('', 'style', '', _('display using template map file')),
3126 ('', 'style', '', _('display using template map file')),
3125 ('', 'template', '', _('display with template')),
3127 ('', 'template', '', _('display with template')),
3126 ]
3128 ]
3127
3129
3128 logopts = [
3130 logopts = [
3129 ('p', 'patch', None, _('show patch')),
3131 ('p', 'patch', None, _('show patch')),
3130 ('g', 'git', None, _('use git extended diff format')),
3132 ('g', 'git', None, _('use git extended diff format')),
3131 ('l', 'limit', '', _('limit number of changes displayed')),
3133 ('l', 'limit', '', _('limit number of changes displayed')),
3132 ('M', 'no-merges', None, _('do not show merges')),
3134 ('M', 'no-merges', None, _('do not show merges')),
3133 ] + templateopts
3135 ] + templateopts
3134
3136
3135 diffopts = [
3137 diffopts = [
3136 ('a', 'text', None, _('treat all files as text')),
3138 ('a', 'text', None, _('treat all files as text')),
3137 ('g', 'git', None, _('use git extended diff format')),
3139 ('g', 'git', None, _('use git extended diff format')),
3138 ('', 'nodates', None, _("don't include dates in diff headers"))
3140 ('', 'nodates', None, _("don't include dates in diff headers"))
3139 ]
3141 ]
3140
3142
3141 diffopts2 = [
3143 diffopts2 = [
3142 ('p', 'show-function', None, _('show which function each change is in')),
3144 ('p', 'show-function', None, _('show which function each change is in')),
3143 ('w', 'ignore-all-space', None,
3145 ('w', 'ignore-all-space', None,
3144 _('ignore white space when comparing lines')),
3146 _('ignore white space when comparing lines')),
3145 ('b', 'ignore-space-change', None,
3147 ('b', 'ignore-space-change', None,
3146 _('ignore changes in the amount of white space')),
3148 _('ignore changes in the amount of white space')),
3147 ('B', 'ignore-blank-lines', None,
3149 ('B', 'ignore-blank-lines', None,
3148 _('ignore changes whose lines are all blank')),
3150 _('ignore changes whose lines are all blank')),
3149 ('U', 'unified', '', _('number of lines of context to show'))
3151 ('U', 'unified', '', _('number of lines of context to show'))
3150 ]
3152 ]
3151
3153
3152 similarityopts = [
3154 similarityopts = [
3153 ('s', 'similarity', '',
3155 ('s', 'similarity', '',
3154 _('guess renamed files by similarity (0<=s<=100)'))
3156 _('guess renamed files by similarity (0<=s<=100)'))
3155 ]
3157 ]
3156
3158
3157 table = {
3159 table = {
3158 "^add": (add, walkopts + dryrunopts, _('[OPTION]... [FILE]...')),
3160 "^add": (add, walkopts + dryrunopts, _('[OPTION]... [FILE]...')),
3159 "addremove":
3161 "addremove":
3160 (addremove, similarityopts + walkopts + dryrunopts,
3162 (addremove, similarityopts + walkopts + dryrunopts,
3161 _('[OPTION]... [FILE]...')),
3163 _('[OPTION]... [FILE]...')),
3162 "^annotate|blame":
3164 "^annotate|blame":
3163 (annotate,
3165 (annotate,
3164 [('r', 'rev', '', _('annotate the specified revision')),
3166 [('r', 'rev', '', _('annotate the specified revision')),
3165 ('f', 'follow', None, _('follow file copies and renames')),
3167 ('f', 'follow', None, _('follow file copies and renames')),
3166 ('a', 'text', None, _('treat all files as text')),
3168 ('a', 'text', None, _('treat all files as text')),
3167 ('u', 'user', None, _('list the author (long with -v)')),
3169 ('u', 'user', None, _('list the author (long with -v)')),
3168 ('d', 'date', None, _('list the date (short with -q)')),
3170 ('d', 'date', None, _('list the date (short with -q)')),
3169 ('n', 'number', None, _('list the revision number (default)')),
3171 ('n', 'number', None, _('list the revision number (default)')),
3170 ('c', 'changeset', None, _('list the changeset')),
3172 ('c', 'changeset', None, _('list the changeset')),
3171 ('l', 'line-number', None,
3173 ('l', 'line-number', None,
3172 _('show line number at the first appearance'))
3174 _('show line number at the first appearance'))
3173 ] + walkopts,
3175 ] + walkopts,
3174 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')),
3176 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')),
3175 "archive":
3177 "archive":
3176 (archive,
3178 (archive,
3177 [('', 'no-decode', None, _('do not pass files through decoders')),
3179 [('', 'no-decode', None, _('do not pass files through decoders')),
3178 ('p', 'prefix', '', _('directory prefix for files in archive')),
3180 ('p', 'prefix', '', _('directory prefix for files in archive')),
3179 ('r', 'rev', '', _('revision to distribute')),
3181 ('r', 'rev', '', _('revision to distribute')),
3180 ('t', 'type', '', _('type of distribution to create')),
3182 ('t', 'type', '', _('type of distribution to create')),
3181 ] + walkopts,
3183 ] + walkopts,
3182 _('[OPTION]... DEST')),
3184 _('[OPTION]... DEST')),
3183 "backout":
3185 "backout":
3184 (backout,
3186 (backout,
3185 [('', 'merge', None,
3187 [('', 'merge', None,
3186 _('merge with old dirstate parent after backout')),
3188 _('merge with old dirstate parent after backout')),
3187 ('', 'parent', '', _('parent to choose when backing out merge')),
3189 ('', 'parent', '', _('parent to choose when backing out merge')),
3188 ('r', 'rev', '', _('revision to backout')),
3190 ('r', 'rev', '', _('revision to backout')),
3189 ] + walkopts + commitopts + commitopts2,
3191 ] + walkopts + commitopts + commitopts2,
3190 _('[OPTION]... [-r] REV')),
3192 _('[OPTION]... [-r] REV')),
3191 "bisect":
3193 "bisect":
3192 (bisect,
3194 (bisect,
3193 [('r', 'reset', False, _('reset bisect state')),
3195 [('r', 'reset', False, _('reset bisect state')),
3194 ('g', 'good', False, _('mark changeset good')),
3196 ('g', 'good', False, _('mark changeset good')),
3195 ('b', 'bad', False, _('mark changeset bad')),
3197 ('b', 'bad', False, _('mark changeset bad')),
3196 ('s', 'skip', False, _('skip testing changeset')),
3198 ('s', 'skip', False, _('skip testing changeset')),
3197 ('c', 'command', '', _('use command to check changeset state')),
3199 ('c', 'command', '', _('use command to check changeset state')),
3198 ('U', 'noupdate', False, _('do not update to target'))],
3200 ('U', 'noupdate', False, _('do not update to target'))],
3199 _("[-gbsr] [-c CMD] [REV]")),
3201 _("[-gbsr] [-c CMD] [REV]")),
3200 "branch":
3202 "branch":
3201 (branch,
3203 (branch,
3202 [('f', 'force', None,
3204 [('f', 'force', None,
3203 _('set branch name even if it shadows an existing branch')),
3205 _('set branch name even if it shadows an existing branch')),
3204 ('C', 'clean', None, _('reset branch name to parent branch name'))],
3206 ('C', 'clean', None, _('reset branch name to parent branch name'))],
3205 _('[-fC] [NAME]')),
3207 _('[-fC] [NAME]')),
3206 "branches":
3208 "branches":
3207 (branches,
3209 (branches,
3208 [('a', 'active', False,
3210 [('a', 'active', False,
3209 _('show only branches that have unmerged heads'))],
3211 _('show only branches that have unmerged heads'))],
3210 _('[-a]')),
3212 _('[-a]')),
3211 "bundle":
3213 "bundle":
3212 (bundle,
3214 (bundle,
3213 [('f', 'force', None,
3215 [('f', 'force', None,
3214 _('run even when remote repository is unrelated')),
3216 _('run even when remote repository is unrelated')),
3215 ('r', 'rev', [],
3217 ('r', 'rev', [],
3216 _('a changeset up to which you would like to bundle')),
3218 _('a changeset up to which you would like to bundle')),
3217 ('', 'base', [],
3219 ('', 'base', [],
3218 _('a base changeset to specify instead of a destination')),
3220 _('a base changeset to specify instead of a destination')),
3219 ('a', 'all', None, _('bundle all changesets in the repository')),
3221 ('a', 'all', None, _('bundle all changesets in the repository')),
3220 ('t', 'type', 'bzip2', _('bundle compression type to use')),
3222 ('t', 'type', 'bzip2', _('bundle compression type to use')),
3221 ] + remoteopts,
3223 ] + remoteopts,
3222 _('[-f] [-a] [-r REV]... [--base REV]... FILE [DEST]')),
3224 _('[-f] [-a] [-r REV]... [--base REV]... FILE [DEST]')),
3223 "cat":
3225 "cat":
3224 (cat,
3226 (cat,
3225 [('o', 'output', '', _('print output to file with formatted name')),
3227 [('o', 'output', '', _('print output to file with formatted name')),
3226 ('r', 'rev', '', _('print the given revision')),
3228 ('r', 'rev', '', _('print the given revision')),
3227 ('', 'decode', None, _('apply any matching decode filter')),
3229 ('', 'decode', None, _('apply any matching decode filter')),
3228 ] + walkopts,
3230 ] + walkopts,
3229 _('[OPTION]... FILE...')),
3231 _('[OPTION]... FILE...')),
3230 "^clone":
3232 "^clone":
3231 (clone,
3233 (clone,
3232 [('U', 'noupdate', None,
3234 [('U', 'noupdate', None,
3233 _('the clone will only contain a repository (no working copy)')),
3235 _('the clone will only contain a repository (no working copy)')),
3234 ('r', 'rev', [],
3236 ('r', 'rev', [],
3235 _('a changeset you would like to have after cloning')),
3237 _('a changeset you would like to have after cloning')),
3236 ('', 'pull', None, _('use pull protocol to copy metadata')),
3238 ('', 'pull', None, _('use pull protocol to copy metadata')),
3237 ('', 'uncompressed', None,
3239 ('', 'uncompressed', None,
3238 _('use uncompressed transfer (fast over LAN)')),
3240 _('use uncompressed transfer (fast over LAN)')),
3239 ] + remoteopts,
3241 ] + remoteopts,
3240 _('[OPTION]... SOURCE [DEST]')),
3242 _('[OPTION]... SOURCE [DEST]')),
3241 "^commit|ci":
3243 "^commit|ci":
3242 (commit,
3244 (commit,
3243 [('A', 'addremove', None,
3245 [('A', 'addremove', None,
3244 _('mark new/missing files as added/removed before committing')),
3246 _('mark new/missing files as added/removed before committing')),
3245 ('', 'close-branch', None,
3247 ('', 'close-branch', None,
3246 _('mark a branch as closed, hiding it from the branch list')),
3248 _('mark a branch as closed, hiding it from the branch list')),
3247 ] + walkopts + commitopts + commitopts2,
3249 ] + walkopts + commitopts + commitopts2,
3248 _('[OPTION]... [FILE]...')),
3250 _('[OPTION]... [FILE]...')),
3249 "copy|cp":
3251 "copy|cp":
3250 (copy,
3252 (copy,
3251 [('A', 'after', None, _('record a copy that has already occurred')),
3253 [('A', 'after', None, _('record a copy that has already occurred')),
3252 ('f', 'force', None,
3254 ('f', 'force', None,
3253 _('forcibly copy over an existing managed file')),
3255 _('forcibly copy over an existing managed file')),
3254 ] + walkopts + dryrunopts,
3256 ] + walkopts + dryrunopts,
3255 _('[OPTION]... [SOURCE]... DEST')),
3257 _('[OPTION]... [SOURCE]... DEST')),
3256 "debugancestor": (debugancestor, [], _('[INDEX] REV1 REV2')),
3258 "debugancestor": (debugancestor, [], _('[INDEX] REV1 REV2')),
3257 "debugcheckstate": (debugcheckstate, []),
3259 "debugcheckstate": (debugcheckstate, []),
3258 "debugcommands": (debugcommands, [], _('[COMMAND]')),
3260 "debugcommands": (debugcommands, [], _('[COMMAND]')),
3259 "debugcomplete":
3261 "debugcomplete":
3260 (debugcomplete,
3262 (debugcomplete,
3261 [('o', 'options', None, _('show the command options'))],
3263 [('o', 'options', None, _('show the command options'))],
3262 _('[-o] CMD')),
3264 _('[-o] CMD')),
3263 "debugdate":
3265 "debugdate":
3264 (debugdate,
3266 (debugdate,
3265 [('e', 'extended', None, _('try extended date formats'))],
3267 [('e', 'extended', None, _('try extended date formats'))],
3266 _('[-e] DATE [RANGE]')),
3268 _('[-e] DATE [RANGE]')),
3267 "debugdata": (debugdata, [], _('FILE REV')),
3269 "debugdata": (debugdata, [], _('FILE REV')),
3268 "debugfsinfo": (debugfsinfo, [], _('[PATH]')),
3270 "debugfsinfo": (debugfsinfo, [], _('[PATH]')),
3269 "debugindex": (debugindex, [], _('FILE')),
3271 "debugindex": (debugindex, [], _('FILE')),
3270 "debugindexdot": (debugindexdot, [], _('FILE')),
3272 "debugindexdot": (debugindexdot, [], _('FILE')),
3271 "debuginstall": (debuginstall, []),
3273 "debuginstall": (debuginstall, []),
3272 "debugrebuildstate":
3274 "debugrebuildstate":
3273 (debugrebuildstate,
3275 (debugrebuildstate,
3274 [('r', 'rev', '', _('revision to rebuild to'))],
3276 [('r', 'rev', '', _('revision to rebuild to'))],
3275 _('[-r REV] [REV]')),
3277 _('[-r REV] [REV]')),
3276 "debugrename":
3278 "debugrename":
3277 (debugrename,
3279 (debugrename,
3278 [('r', 'rev', '', _('revision to debug'))],
3280 [('r', 'rev', '', _('revision to debug'))],
3279 _('[-r REV] FILE')),
3281 _('[-r REV] FILE')),
3280 "debugsetparents":
3282 "debugsetparents":
3281 (debugsetparents, [], _('REV1 [REV2]')),
3283 (debugsetparents, [], _('REV1 [REV2]')),
3282 "debugstate":
3284 "debugstate":
3283 (debugstate,
3285 (debugstate,
3284 [('', 'nodates', None, _('do not display the saved mtime'))],
3286 [('', 'nodates', None, _('do not display the saved mtime'))],
3285 _('[OPTION]...')),
3287 _('[OPTION]...')),
3286 "debugsub":
3288 "debugsub":
3287 (debugsub,
3289 (debugsub,
3288 [('r', 'rev', '', _('revision to check'))],
3290 [('r', 'rev', '', _('revision to check'))],
3289 _('[-r REV] [REV]')),
3291 _('[-r REV] [REV]')),
3290 "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')),
3292 "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')),
3291 "^diff":
3293 "^diff":
3292 (diff,
3294 (diff,
3293 [('r', 'rev', [], _('revision')),
3295 [('r', 'rev', [], _('revision')),
3294 ('c', 'change', '', _('change made by revision'))
3296 ('c', 'change', '', _('change made by revision'))
3295 ] + diffopts + diffopts2 + walkopts,
3297 ] + diffopts + diffopts2 + walkopts,
3296 _('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
3298 _('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
3297 "^export":
3299 "^export":
3298 (export,
3300 (export,
3299 [('o', 'output', '', _('print output to file with formatted name')),
3301 [('o', 'output', '', _('print output to file with formatted name')),
3300 ('', 'switch-parent', None, _('diff against the second parent'))
3302 ('', 'switch-parent', None, _('diff against the second parent'))
3301 ] + diffopts,
3303 ] + diffopts,
3302 _('[OPTION]... [-o OUTFILESPEC] REV...')),
3304 _('[OPTION]... [-o OUTFILESPEC] REV...')),
3303 "^forget":
3305 "^forget":
3304 (forget,
3306 (forget,
3305 [] + walkopts,
3307 [] + walkopts,
3306 _('[OPTION]... FILE...')),
3308 _('[OPTION]... FILE...')),
3307 "grep":
3309 "grep":
3308 (grep,
3310 (grep,
3309 [('0', 'print0', None, _('end fields with NUL')),
3311 [('0', 'print0', None, _('end fields with NUL')),
3310 ('', 'all', None, _('print all revisions that match')),
3312 ('', 'all', None, _('print all revisions that match')),
3311 ('f', 'follow', None,
3313 ('f', 'follow', None,
3312 _('follow changeset history, or file history across copies and renames')),
3314 _('follow changeset history, or file history across copies and renames')),
3313 ('i', 'ignore-case', None, _('ignore case when matching')),
3315 ('i', 'ignore-case', None, _('ignore case when matching')),
3314 ('l', 'files-with-matches', None,
3316 ('l', 'files-with-matches', None,
3315 _('print only filenames and revisions that match')),
3317 _('print only filenames and revisions that match')),
3316 ('n', 'line-number', None, _('print matching line numbers')),
3318 ('n', 'line-number', None, _('print matching line numbers')),
3317 ('r', 'rev', [], _('search in given revision range')),
3319 ('r', 'rev', [], _('search in given revision range')),
3318 ('u', 'user', None, _('list the author (long with -v)')),
3320 ('u', 'user', None, _('list the author (long with -v)')),
3319 ('d', 'date', None, _('list the date (short with -q)')),
3321 ('d', 'date', None, _('list the date (short with -q)')),
3320 ] + walkopts,
3322 ] + walkopts,
3321 _('[OPTION]... PATTERN [FILE]...')),
3323 _('[OPTION]... PATTERN [FILE]...')),
3322 "heads":
3324 "heads":
3323 (heads,
3325 (heads,
3324 [('r', 'rev', '', _('show only heads which are descendants of REV')),
3326 [('r', 'rev', '', _('show only heads which are descendants of REV')),
3325 ('a', 'active', False,
3327 ('a', 'active', False,
3326 _('show only the active heads from open branches')),
3328 _('show only the active heads from open branches')),
3327 ('c', 'closed', False,
3329 ('c', 'closed', False,
3328 _('show normal and closed heads')),
3330 _('show normal and closed heads')),
3329 ] + templateopts,
3331 ] + templateopts,
3330 _('[-r STARTREV] [REV]...')),
3332 _('[-r STARTREV] [REV]...')),
3331 "help": (help_, [], _('[TOPIC]')),
3333 "help": (help_, [], _('[TOPIC]')),
3332 "identify|id":
3334 "identify|id":
3333 (identify,
3335 (identify,
3334 [('r', 'rev', '', _('identify the specified revision')),
3336 [('r', 'rev', '', _('identify the specified revision')),
3335 ('n', 'num', None, _('show local revision number')),
3337 ('n', 'num', None, _('show local revision number')),
3336 ('i', 'id', None, _('show global revision id')),
3338 ('i', 'id', None, _('show global revision id')),
3337 ('b', 'branch', None, _('show branch')),
3339 ('b', 'branch', None, _('show branch')),
3338 ('t', 'tags', None, _('show tags'))],
3340 ('t', 'tags', None, _('show tags'))],
3339 _('[-nibt] [-r REV] [SOURCE]')),
3341 _('[-nibt] [-r REV] [SOURCE]')),
3340 "import|patch":
3342 "import|patch":
3341 (import_,
3343 (import_,
3342 [('p', 'strip', 1,
3344 [('p', 'strip', 1,
3343 _('directory strip option for patch. This has the same '
3345 _('directory strip option for patch. This has the same '
3344 'meaning as the corresponding patch option')),
3346 'meaning as the corresponding patch option')),
3345 ('b', 'base', '', _('base path')),
3347 ('b', 'base', '', _('base path')),
3346 ('f', 'force', None,
3348 ('f', 'force', None,
3347 _('skip check for outstanding uncommitted changes')),
3349 _('skip check for outstanding uncommitted changes')),
3348 ('', 'no-commit', None, _("don't commit, just update the working directory")),
3350 ('', 'no-commit', None, _("don't commit, just update the working directory")),
3349 ('', 'exact', None,
3351 ('', 'exact', None,
3350 _('apply patch to the nodes from which it was generated')),
3352 _('apply patch to the nodes from which it was generated')),
3351 ('', 'import-branch', None,
3353 ('', 'import-branch', None,
3352 _('use any branch information in patch (implied by --exact)'))] +
3354 _('use any branch information in patch (implied by --exact)'))] +
3353 commitopts + commitopts2 + similarityopts,
3355 commitopts + commitopts2 + similarityopts,
3354 _('[OPTION]... PATCH...')),
3356 _('[OPTION]... PATCH...')),
3355 "incoming|in":
3357 "incoming|in":
3356 (incoming,
3358 (incoming,
3357 [('f', 'force', None,
3359 [('f', 'force', None,
3358 _('run even when remote repository is unrelated')),
3360 _('run even when remote repository is unrelated')),
3359 ('n', 'newest-first', None, _('show newest record first')),
3361 ('n', 'newest-first', None, _('show newest record first')),
3360 ('', 'bundle', '', _('file to store the bundles into')),
3362 ('', 'bundle', '', _('file to store the bundles into')),
3361 ('r', 'rev', [],
3363 ('r', 'rev', [],
3362 _('a specific revision up to which you would like to pull')),
3364 _('a specific revision up to which you would like to pull')),
3363 ] + logopts + remoteopts,
3365 ] + logopts + remoteopts,
3364 _('[-p] [-n] [-M] [-f] [-r REV]...'
3366 _('[-p] [-n] [-M] [-f] [-r REV]...'
3365 ' [--bundle FILENAME] [SOURCE]')),
3367 ' [--bundle FILENAME] [SOURCE]')),
3366 "^init":
3368 "^init":
3367 (init,
3369 (init,
3368 remoteopts,
3370 remoteopts,
3369 _('[-e CMD] [--remotecmd CMD] [DEST]')),
3371 _('[-e CMD] [--remotecmd CMD] [DEST]')),
3370 "locate":
3372 "locate":
3371 (locate,
3373 (locate,
3372 [('r', 'rev', '', _('search the repository as it stood at REV')),
3374 [('r', 'rev', '', _('search the repository as it stood at REV')),
3373 ('0', 'print0', None,
3375 ('0', 'print0', None,
3374 _('end filenames with NUL, for use with xargs')),
3376 _('end filenames with NUL, for use with xargs')),
3375 ('f', 'fullpath', None,
3377 ('f', 'fullpath', None,
3376 _('print complete paths from the filesystem root')),
3378 _('print complete paths from the filesystem root')),
3377 ] + walkopts,
3379 ] + walkopts,
3378 _('[OPTION]... [PATTERN]...')),
3380 _('[OPTION]... [PATTERN]...')),
3379 "^log|history":
3381 "^log|history":
3380 (log,
3382 (log,
3381 [('f', 'follow', None,
3383 [('f', 'follow', None,
3382 _('follow changeset history, or file history across copies and renames')),
3384 _('follow changeset history, or file history across copies and renames')),
3383 ('', 'follow-first', None,
3385 ('', 'follow-first', None,
3384 _('only follow the first parent of merge changesets')),
3386 _('only follow the first parent of merge changesets')),
3385 ('d', 'date', '', _('show revisions matching date spec')),
3387 ('d', 'date', '', _('show revisions matching date spec')),
3386 ('C', 'copies', None, _('show copied files')),
3388 ('C', 'copies', None, _('show copied files')),
3387 ('k', 'keyword', [], _('do case-insensitive search for a keyword')),
3389 ('k', 'keyword', [], _('do case-insensitive search for a keyword')),
3388 ('r', 'rev', [], _('show the specified revision or range')),
3390 ('r', 'rev', [], _('show the specified revision or range')),
3389 ('', 'removed', None, _('include revisions where files were removed')),
3391 ('', 'removed', None, _('include revisions where files were removed')),
3390 ('m', 'only-merges', None, _('show only merges')),
3392 ('m', 'only-merges', None, _('show only merges')),
3391 ('u', 'user', [], _('revisions committed by user')),
3393 ('u', 'user', [], _('revisions committed by user')),
3392 ('b', 'only-branch', [],
3394 ('b', 'only-branch', [],
3393 _('show only changesets within the given named branch')),
3395 _('show only changesets within the given named branch')),
3394 ('P', 'prune', [], _('do not display revision or any of its ancestors')),
3396 ('P', 'prune', [], _('do not display revision or any of its ancestors')),
3395 ] + logopts + walkopts,
3397 ] + logopts + walkopts,
3396 _('[OPTION]... [FILE]')),
3398 _('[OPTION]... [FILE]')),
3397 "manifest":
3399 "manifest":
3398 (manifest,
3400 (manifest,
3399 [('r', 'rev', '', _('revision to display'))],
3401 [('r', 'rev', '', _('revision to display'))],
3400 _('[-r REV]')),
3402 _('[-r REV]')),
3401 "^merge":
3403 "^merge":
3402 (merge,
3404 (merge,
3403 [('f', 'force', None, _('force a merge with outstanding changes')),
3405 [('f', 'force', None, _('force a merge with outstanding changes')),
3404 ('r', 'rev', '', _('revision to merge')),
3406 ('r', 'rev', '', _('revision to merge')),
3405 ('P', 'preview', None,
3407 ('P', 'preview', None,
3406 _('review revisions to merge (no merge is performed)'))],
3408 _('review revisions to merge (no merge is performed)'))],
3407 _('[-f] [[-r] REV]')),
3409 _('[-f] [[-r] REV]')),
3408 "outgoing|out":
3410 "outgoing|out":
3409 (outgoing,
3411 (outgoing,
3410 [('f', 'force', None,
3412 [('f', 'force', None,
3411 _('run even when remote repository is unrelated')),
3413 _('run even when remote repository is unrelated')),
3412 ('r', 'rev', [],
3414 ('r', 'rev', [],
3413 _('a specific revision up to which you would like to push')),
3415 _('a specific revision up to which you would like to push')),
3414 ('n', 'newest-first', None, _('show newest record first')),
3416 ('n', 'newest-first', None, _('show newest record first')),
3415 ] + logopts + remoteopts,
3417 ] + logopts + remoteopts,
3416 _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')),
3418 _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')),
3417 "^parents":
3419 "^parents":
3418 (parents,
3420 (parents,
3419 [('r', 'rev', '', _('show parents from the specified revision')),
3421 [('r', 'rev', '', _('show parents from the specified revision')),
3420 ] + templateopts,
3422 ] + templateopts,
3421 _('[-r REV] [FILE]')),
3423 _('[-r REV] [FILE]')),
3422 "paths": (paths, [], _('[NAME]')),
3424 "paths": (paths, [], _('[NAME]')),
3423 "^pull":
3425 "^pull":
3424 (pull,
3426 (pull,
3425 [('u', 'update', None,
3427 [('u', 'update', None,
3426 _('update to new tip if changesets were pulled')),
3428 _('update to new tip if changesets were pulled')),
3427 ('f', 'force', None,
3429 ('f', 'force', None,
3428 _('run even when remote repository is unrelated')),
3430 _('run even when remote repository is unrelated')),
3429 ('r', 'rev', [],
3431 ('r', 'rev', [],
3430 _('a specific revision up to which you would like to pull')),
3432 _('a specific revision up to which you would like to pull')),
3431 ] + remoteopts,
3433 ] + remoteopts,
3432 _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')),
3434 _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')),
3433 "^push":
3435 "^push":
3434 (push,
3436 (push,
3435 [('f', 'force', None, _('force push')),
3437 [('f', 'force', None, _('force push')),
3436 ('r', 'rev', [],
3438 ('r', 'rev', [],
3437 _('a specific revision up to which you would like to push')),
3439 _('a specific revision up to which you would like to push')),
3438 ] + remoteopts,
3440 ] + remoteopts,
3439 _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')),
3441 _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')),
3440 "recover": (recover, []),
3442 "recover": (recover, []),
3441 "^remove|rm":
3443 "^remove|rm":
3442 (remove,
3444 (remove,
3443 [('A', 'after', None, _('record delete for missing files')),
3445 [('A', 'after', None, _('record delete for missing files')),
3444 ('f', 'force', None,
3446 ('f', 'force', None,
3445 _('remove (and delete) file even if added or modified')),
3447 _('remove (and delete) file even if added or modified')),
3446 ] + walkopts,
3448 ] + walkopts,
3447 _('[OPTION]... FILE...')),
3449 _('[OPTION]... FILE...')),
3448 "rename|mv":
3450 "rename|mv":
3449 (rename,
3451 (rename,
3450 [('A', 'after', None, _('record a rename that has already occurred')),
3452 [('A', 'after', None, _('record a rename that has already occurred')),
3451 ('f', 'force', None,
3453 ('f', 'force', None,
3452 _('forcibly copy over an existing managed file')),
3454 _('forcibly copy over an existing managed file')),
3453 ] + walkopts + dryrunopts,
3455 ] + walkopts + dryrunopts,
3454 _('[OPTION]... SOURCE... DEST')),
3456 _('[OPTION]... SOURCE... DEST')),
3455 "resolve":
3457 "resolve":
3456 (resolve,
3458 (resolve,
3457 [('a', 'all', None, _('remerge all unresolved files')),
3459 [('a', 'all', None, _('remerge all unresolved files')),
3458 ('l', 'list', None, _('list state of files needing merge')),
3460 ('l', 'list', None, _('list state of files needing merge')),
3459 ('m', 'mark', None, _('mark files as resolved')),
3461 ('m', 'mark', None, _('mark files as resolved')),
3460 ('u', 'unmark', None, _('unmark files as resolved'))]
3462 ('u', 'unmark', None, _('unmark files as resolved'))]
3461 + walkopts,
3463 + walkopts,
3462 _('[OPTION]... [FILE]...')),
3464 _('[OPTION]... [FILE]...')),
3463 "revert":
3465 "revert":
3464 (revert,
3466 (revert,
3465 [('a', 'all', None, _('revert all changes when no arguments given')),
3467 [('a', 'all', None, _('revert all changes when no arguments given')),
3466 ('d', 'date', '', _('tipmost revision matching date')),
3468 ('d', 'date', '', _('tipmost revision matching date')),
3467 ('r', 'rev', '', _('revision to revert to')),
3469 ('r', 'rev', '', _('revision to revert to')),
3468 ('', 'no-backup', None, _('do not save backup copies of files')),
3470 ('', 'no-backup', None, _('do not save backup copies of files')),
3469 ] + walkopts + dryrunopts,
3471 ] + walkopts + dryrunopts,
3470 _('[OPTION]... [-r REV] [NAME]...')),
3472 _('[OPTION]... [-r REV] [NAME]...')),
3471 "rollback": (rollback, []),
3473 "rollback": (rollback, []),
3472 "root": (root, []),
3474 "root": (root, []),
3473 "^serve":
3475 "^serve":
3474 (serve,
3476 (serve,
3475 [('A', 'accesslog', '', _('name of access log file to write to')),
3477 [('A', 'accesslog', '', _('name of access log file to write to')),
3476 ('d', 'daemon', None, _('run server in background')),
3478 ('d', 'daemon', None, _('run server in background')),
3477 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
3479 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
3478 ('E', 'errorlog', '', _('name of error log file to write to')),
3480 ('E', 'errorlog', '', _('name of error log file to write to')),
3479 ('p', 'port', 0, _('port to listen on (default: 8000)')),
3481 ('p', 'port', 0, _('port to listen on (default: 8000)')),
3480 ('a', 'address', '', _('address to listen on (default: all interfaces)')),
3482 ('a', 'address', '', _('address to listen on (default: all interfaces)')),
3481 ('', 'prefix', '', _('prefix path to serve from (default: server root)')),
3483 ('', 'prefix', '', _('prefix path to serve from (default: server root)')),
3482 ('n', 'name', '',
3484 ('n', 'name', '',
3483 _('name to show in web pages (default: working directory)')),
3485 _('name to show in web pages (default: working directory)')),
3484 ('', 'webdir-conf', '', _('name of the webdir config file'
3486 ('', 'webdir-conf', '', _('name of the webdir config file'
3485 ' (serve more than one repository)')),
3487 ' (serve more than one repository)')),
3486 ('', 'pid-file', '', _('name of file to write process ID to')),
3488 ('', 'pid-file', '', _('name of file to write process ID to')),
3487 ('', 'stdio', None, _('for remote clients')),
3489 ('', 'stdio', None, _('for remote clients')),
3488 ('t', 'templates', '', _('web templates to use')),
3490 ('t', 'templates', '', _('web templates to use')),
3489 ('', 'style', '', _('template style to use')),
3491 ('', 'style', '', _('template style to use')),
3490 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
3492 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
3491 ('', 'certificate', '', _('SSL certificate file'))],
3493 ('', 'certificate', '', _('SSL certificate file'))],
3492 _('[OPTION]...')),
3494 _('[OPTION]...')),
3493 "showconfig|debugconfig":
3495 "showconfig|debugconfig":
3494 (showconfig,
3496 (showconfig,
3495 [('u', 'untrusted', None, _('show untrusted configuration options'))],
3497 [('u', 'untrusted', None, _('show untrusted configuration options'))],
3496 _('[-u] [NAME]...')),
3498 _('[-u] [NAME]...')),
3497 "^status|st":
3499 "^status|st":
3498 (status,
3500 (status,
3499 [('A', 'all', None, _('show status of all files')),
3501 [('A', 'all', None, _('show status of all files')),
3500 ('m', 'modified', None, _('show only modified files')),
3502 ('m', 'modified', None, _('show only modified files')),
3501 ('a', 'added', None, _('show only added files')),
3503 ('a', 'added', None, _('show only added files')),
3502 ('r', 'removed', None, _('show only removed files')),
3504 ('r', 'removed', None, _('show only removed files')),
3503 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
3505 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
3504 ('c', 'clean', None, _('show only files without changes')),
3506 ('c', 'clean', None, _('show only files without changes')),
3505 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
3507 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
3506 ('i', 'ignored', None, _('show only ignored files')),
3508 ('i', 'ignored', None, _('show only ignored files')),
3507 ('n', 'no-status', None, _('hide status prefix')),
3509 ('n', 'no-status', None, _('hide status prefix')),
3508 ('C', 'copies', None, _('show source of copied files')),
3510 ('C', 'copies', None, _('show source of copied files')),
3509 ('0', 'print0', None,
3511 ('0', 'print0', None,
3510 _('end filenames with NUL, for use with xargs')),
3512 _('end filenames with NUL, for use with xargs')),
3511 ('', 'rev', [], _('show difference from revision')),
3513 ('', 'rev', [], _('show difference from revision')),
3512 ] + walkopts,
3514 ] + walkopts,
3513 _('[OPTION]... [FILE]...')),
3515 _('[OPTION]... [FILE]...')),
3514 "tag":
3516 "tag":
3515 (tag,
3517 (tag,
3516 [('f', 'force', None, _('replace existing tag')),
3518 [('f', 'force', None, _('replace existing tag')),
3517 ('l', 'local', None, _('make the tag local')),
3519 ('l', 'local', None, _('make the tag local')),
3518 ('r', 'rev', '', _('revision to tag')),
3520 ('r', 'rev', '', _('revision to tag')),
3519 ('', 'remove', None, _('remove a tag')),
3521 ('', 'remove', None, _('remove a tag')),
3520 # -l/--local is already there, commitopts cannot be used
3522 # -l/--local is already there, commitopts cannot be used
3521 ('m', 'message', '', _('use <text> as commit message')),
3523 ('m', 'message', '', _('use <text> as commit message')),
3522 ] + commitopts2,
3524 ] + commitopts2,
3523 _('[-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')),
3525 _('[-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')),
3524 "tags": (tags, []),
3526 "tags": (tags, []),
3525 "tip":
3527 "tip":
3526 (tip,
3528 (tip,
3527 [('p', 'patch', None, _('show patch')),
3529 [('p', 'patch', None, _('show patch')),
3528 ('g', 'git', None, _('use git extended diff format')),
3530 ('g', 'git', None, _('use git extended diff format')),
3529 ] + templateopts,
3531 ] + templateopts,
3530 _('[-p]')),
3532 _('[-p]')),
3531 "unbundle":
3533 "unbundle":
3532 (unbundle,
3534 (unbundle,
3533 [('u', 'update', None,
3535 [('u', 'update', None,
3534 _('update to new tip if changesets were unbundled'))],
3536 _('update to new tip if changesets were unbundled'))],
3535 _('[-u] FILE...')),
3537 _('[-u] FILE...')),
3536 "^update|up|checkout|co":
3538 "^update|up|checkout|co":
3537 (update,
3539 (update,
3538 [('C', 'clean', None, _('overwrite locally modified files (no backup)')),
3540 [('C', 'clean', None, _('overwrite locally modified files (no backup)')),
3539 ('c', 'check', None, _('check for uncommitted changes')),
3541 ('c', 'check', None, _('check for uncommitted changes')),
3540 ('d', 'date', '', _('tipmost revision matching date')),
3542 ('d', 'date', '', _('tipmost revision matching date')),
3541 ('r', 'rev', '', _('revision'))],
3543 ('r', 'rev', '', _('revision'))],
3542 _('[-C] [-d DATE] [[-r] REV]')),
3544 _('[-C] [-d DATE] [[-r] REV]')),
3543 "verify": (verify, []),
3545 "verify": (verify, []),
3544 "version": (version_, []),
3546 "version": (version_, []),
3545 }
3547 }
3546
3548
3547 norepo = ("clone init version help debugcommands debugcomplete debugdata"
3549 norepo = ("clone init version help debugcommands debugcomplete debugdata"
3548 " debugindex debugindexdot debugdate debuginstall debugfsinfo")
3550 " debugindex debugindexdot debugdate debuginstall debugfsinfo")
3549 optionalrepo = ("identify paths serve showconfig debugancestor")
3551 optionalrepo = ("identify paths serve showconfig debugancestor")
General Comments 0
You need to be logged in to leave comments. Login now