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