##// END OF EJS Templates
Merge with stable
Martin Geisler -
r12031:77bbeafd merge default
parent child Browse files
Show More
@@ -1,1088 +1,1088 b''
1 # context.py - changeset and file context objects for mercurial
1 # context.py - changeset and file context objects for mercurial
2 #
2 #
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from node import nullid, nullrev, short, hex
8 from node import nullid, nullrev, short, hex
9 from i18n import _
9 from i18n import _
10 import ancestor, bdiff, error, util, subrepo, patch
10 import ancestor, bdiff, error, util, subrepo, patch
11 import os, errno, stat
11 import os, errno, stat
12
12
13 propertycache = util.propertycache
13 propertycache = util.propertycache
14
14
15 class changectx(object):
15 class changectx(object):
16 """A changecontext object makes access to data related to a particular
16 """A changecontext object makes access to data related to a particular
17 changeset convenient."""
17 changeset convenient."""
18 def __init__(self, repo, changeid=''):
18 def __init__(self, repo, changeid=''):
19 """changeid is a revision number, node, or tag"""
19 """changeid is a revision number, node, or tag"""
20 if changeid == '':
20 if changeid == '':
21 changeid = '.'
21 changeid = '.'
22 self._repo = repo
22 self._repo = repo
23 if isinstance(changeid, (long, int)):
23 if isinstance(changeid, (long, int)):
24 self._rev = changeid
24 self._rev = changeid
25 self._node = self._repo.changelog.node(changeid)
25 self._node = self._repo.changelog.node(changeid)
26 else:
26 else:
27 self._node = self._repo.lookup(changeid)
27 self._node = self._repo.lookup(changeid)
28 self._rev = self._repo.changelog.rev(self._node)
28 self._rev = self._repo.changelog.rev(self._node)
29
29
30 def __str__(self):
30 def __str__(self):
31 return short(self.node())
31 return short(self.node())
32
32
33 def __int__(self):
33 def __int__(self):
34 return self.rev()
34 return self.rev()
35
35
36 def __repr__(self):
36 def __repr__(self):
37 return "<changectx %s>" % str(self)
37 return "<changectx %s>" % str(self)
38
38
39 def __hash__(self):
39 def __hash__(self):
40 try:
40 try:
41 return hash(self._rev)
41 return hash(self._rev)
42 except AttributeError:
42 except AttributeError:
43 return id(self)
43 return id(self)
44
44
45 def __eq__(self, other):
45 def __eq__(self, other):
46 try:
46 try:
47 return self._rev == other._rev
47 return self._rev == other._rev
48 except AttributeError:
48 except AttributeError:
49 return False
49 return False
50
50
51 def __ne__(self, other):
51 def __ne__(self, other):
52 return not (self == other)
52 return not (self == other)
53
53
54 def __nonzero__(self):
54 def __nonzero__(self):
55 return self._rev != nullrev
55 return self._rev != nullrev
56
56
57 @propertycache
57 @propertycache
58 def _changeset(self):
58 def _changeset(self):
59 return self._repo.changelog.read(self.node())
59 return self._repo.changelog.read(self.node())
60
60
61 @propertycache
61 @propertycache
62 def _manifest(self):
62 def _manifest(self):
63 return self._repo.manifest.read(self._changeset[0])
63 return self._repo.manifest.read(self._changeset[0])
64
64
65 @propertycache
65 @propertycache
66 def _manifestdelta(self):
66 def _manifestdelta(self):
67 return self._repo.manifest.readdelta(self._changeset[0])
67 return self._repo.manifest.readdelta(self._changeset[0])
68
68
69 @propertycache
69 @propertycache
70 def _parents(self):
70 def _parents(self):
71 p = self._repo.changelog.parentrevs(self._rev)
71 p = self._repo.changelog.parentrevs(self._rev)
72 if p[1] == nullrev:
72 if p[1] == nullrev:
73 p = p[:-1]
73 p = p[:-1]
74 return [changectx(self._repo, x) for x in p]
74 return [changectx(self._repo, x) for x in p]
75
75
76 @propertycache
76 @propertycache
77 def substate(self):
77 def substate(self):
78 return subrepo.state(self, self._repo.ui)
78 return subrepo.state(self, self._repo.ui)
79
79
80 def __contains__(self, key):
80 def __contains__(self, key):
81 return key in self._manifest
81 return key in self._manifest
82
82
83 def __getitem__(self, key):
83 def __getitem__(self, key):
84 return self.filectx(key)
84 return self.filectx(key)
85
85
86 def __iter__(self):
86 def __iter__(self):
87 for f in sorted(self._manifest):
87 for f in sorted(self._manifest):
88 yield f
88 yield f
89
89
90 def changeset(self):
90 def changeset(self):
91 return self._changeset
91 return self._changeset
92 def manifest(self):
92 def manifest(self):
93 return self._manifest
93 return self._manifest
94 def manifestnode(self):
94 def manifestnode(self):
95 return self._changeset[0]
95 return self._changeset[0]
96
96
97 def rev(self):
97 def rev(self):
98 return self._rev
98 return self._rev
99 def node(self):
99 def node(self):
100 return self._node
100 return self._node
101 def hex(self):
101 def hex(self):
102 return hex(self._node)
102 return hex(self._node)
103 def user(self):
103 def user(self):
104 return self._changeset[1]
104 return self._changeset[1]
105 def date(self):
105 def date(self):
106 return self._changeset[2]
106 return self._changeset[2]
107 def files(self):
107 def files(self):
108 return self._changeset[3]
108 return self._changeset[3]
109 def description(self):
109 def description(self):
110 return self._changeset[4]
110 return self._changeset[4]
111 def branch(self):
111 def branch(self):
112 return self._changeset[5].get("branch")
112 return self._changeset[5].get("branch")
113 def extra(self):
113 def extra(self):
114 return self._changeset[5]
114 return self._changeset[5]
115 def tags(self):
115 def tags(self):
116 return self._repo.nodetags(self._node)
116 return self._repo.nodetags(self._node)
117
117
118 def parents(self):
118 def parents(self):
119 """return contexts for each parent changeset"""
119 """return contexts for each parent changeset"""
120 return self._parents
120 return self._parents
121
121
122 def p1(self):
122 def p1(self):
123 return self._parents[0]
123 return self._parents[0]
124
124
125 def p2(self):
125 def p2(self):
126 if len(self._parents) == 2:
126 if len(self._parents) == 2:
127 return self._parents[1]
127 return self._parents[1]
128 return changectx(self._repo, -1)
128 return changectx(self._repo, -1)
129
129
130 def children(self):
130 def children(self):
131 """return contexts for each child changeset"""
131 """return contexts for each child changeset"""
132 c = self._repo.changelog.children(self._node)
132 c = self._repo.changelog.children(self._node)
133 return [changectx(self._repo, x) for x in c]
133 return [changectx(self._repo, x) for x in c]
134
134
135 def ancestors(self):
135 def ancestors(self):
136 for a in self._repo.changelog.ancestors(self._rev):
136 for a in self._repo.changelog.ancestors(self._rev):
137 yield changectx(self._repo, a)
137 yield changectx(self._repo, a)
138
138
139 def descendants(self):
139 def descendants(self):
140 for d in self._repo.changelog.descendants(self._rev):
140 for d in self._repo.changelog.descendants(self._rev):
141 yield changectx(self._repo, d)
141 yield changectx(self._repo, d)
142
142
143 def _fileinfo(self, path):
143 def _fileinfo(self, path):
144 if '_manifest' in self.__dict__:
144 if '_manifest' in self.__dict__:
145 try:
145 try:
146 return self._manifest[path], self._manifest.flags(path)
146 return self._manifest[path], self._manifest.flags(path)
147 except KeyError:
147 except KeyError:
148 raise error.LookupError(self._node, path,
148 raise error.LookupError(self._node, path,
149 _('not found in manifest'))
149 _('not found in manifest'))
150 if '_manifestdelta' in self.__dict__ or path in self.files():
150 if '_manifestdelta' in self.__dict__ or path in self.files():
151 if path in self._manifestdelta:
151 if path in self._manifestdelta:
152 return self._manifestdelta[path], self._manifestdelta.flags(path)
152 return self._manifestdelta[path], self._manifestdelta.flags(path)
153 node, flag = self._repo.manifest.find(self._changeset[0], path)
153 node, flag = self._repo.manifest.find(self._changeset[0], path)
154 if not node:
154 if not node:
155 raise error.LookupError(self._node, path,
155 raise error.LookupError(self._node, path,
156 _('not found in manifest'))
156 _('not found in manifest'))
157
157
158 return node, flag
158 return node, flag
159
159
160 def filenode(self, path):
160 def filenode(self, path):
161 return self._fileinfo(path)[0]
161 return self._fileinfo(path)[0]
162
162
163 def flags(self, path):
163 def flags(self, path):
164 try:
164 try:
165 return self._fileinfo(path)[1]
165 return self._fileinfo(path)[1]
166 except error.LookupError:
166 except error.LookupError:
167 return ''
167 return ''
168
168
169 def filectx(self, path, fileid=None, filelog=None):
169 def filectx(self, path, fileid=None, filelog=None):
170 """get a file context from this changeset"""
170 """get a file context from this changeset"""
171 if fileid is None:
171 if fileid is None:
172 fileid = self.filenode(path)
172 fileid = self.filenode(path)
173 return filectx(self._repo, path, fileid=fileid,
173 return filectx(self._repo, path, fileid=fileid,
174 changectx=self, filelog=filelog)
174 changectx=self, filelog=filelog)
175
175
176 def ancestor(self, c2):
176 def ancestor(self, c2):
177 """
177 """
178 return the ancestor context of self and c2
178 return the ancestor context of self and c2
179 """
179 """
180 # deal with workingctxs
180 # deal with workingctxs
181 n2 = c2._node
181 n2 = c2._node
182 if n2 == None:
182 if n2 == None:
183 n2 = c2._parents[0]._node
183 n2 = c2._parents[0]._node
184 n = self._repo.changelog.ancestor(self._node, n2)
184 n = self._repo.changelog.ancestor(self._node, n2)
185 return changectx(self._repo, n)
185 return changectx(self._repo, n)
186
186
187 def walk(self, match):
187 def walk(self, match):
188 fset = set(match.files())
188 fset = set(match.files())
189 # for dirstate.walk, files=['.'] means "walk the whole tree".
189 # for dirstate.walk, files=['.'] means "walk the whole tree".
190 # follow that here, too
190 # follow that here, too
191 fset.discard('.')
191 fset.discard('.')
192 for fn in self:
192 for fn in self:
193 for ffn in fset:
193 for ffn in fset:
194 # match if the file is the exact name or a directory
194 # match if the file is the exact name or a directory
195 if ffn == fn or fn.startswith("%s/" % ffn):
195 if ffn == fn or fn.startswith("%s/" % ffn):
196 fset.remove(ffn)
196 fset.remove(ffn)
197 break
197 break
198 if match(fn):
198 if match(fn):
199 yield fn
199 yield fn
200 for fn in sorted(fset):
200 for fn in sorted(fset):
201 if match.bad(fn, 'No such file in rev ' + str(self)) and match(fn):
201 if match.bad(fn, _('No such file in rev %s') % self) and match(fn):
202 yield fn
202 yield fn
203
203
204 def sub(self, path):
204 def sub(self, path):
205 return subrepo.subrepo(self, path)
205 return subrepo.subrepo(self, path)
206
206
207 def diff(self, ctx2=None, match=None, **opts):
207 def diff(self, ctx2=None, match=None, **opts):
208 """Returns a diff generator for the given contexts and matcher"""
208 """Returns a diff generator for the given contexts and matcher"""
209 if ctx2 is None:
209 if ctx2 is None:
210 ctx2 = self.p1()
210 ctx2 = self.p1()
211 if ctx2 is not None and not isinstance(ctx2, changectx):
211 if ctx2 is not None and not isinstance(ctx2, changectx):
212 ctx2 = self._repo[ctx2]
212 ctx2 = self._repo[ctx2]
213 diffopts = patch.diffopts(self._repo.ui, opts)
213 diffopts = patch.diffopts(self._repo.ui, opts)
214 return patch.diff(self._repo, ctx2.node(), self.node(),
214 return patch.diff(self._repo, ctx2.node(), self.node(),
215 match=match, opts=diffopts)
215 match=match, opts=diffopts)
216
216
217 class filectx(object):
217 class filectx(object):
218 """A filecontext object makes access to data related to a particular
218 """A filecontext object makes access to data related to a particular
219 filerevision convenient."""
219 filerevision convenient."""
220 def __init__(self, repo, path, changeid=None, fileid=None,
220 def __init__(self, repo, path, changeid=None, fileid=None,
221 filelog=None, changectx=None):
221 filelog=None, changectx=None):
222 """changeid can be a changeset revision, node, or tag.
222 """changeid can be a changeset revision, node, or tag.
223 fileid can be a file revision or node."""
223 fileid can be a file revision or node."""
224 self._repo = repo
224 self._repo = repo
225 self._path = path
225 self._path = path
226
226
227 assert (changeid is not None
227 assert (changeid is not None
228 or fileid is not None
228 or fileid is not None
229 or changectx is not None), \
229 or changectx is not None), \
230 ("bad args: changeid=%r, fileid=%r, changectx=%r"
230 ("bad args: changeid=%r, fileid=%r, changectx=%r"
231 % (changeid, fileid, changectx))
231 % (changeid, fileid, changectx))
232
232
233 if filelog:
233 if filelog:
234 self._filelog = filelog
234 self._filelog = filelog
235
235
236 if changeid is not None:
236 if changeid is not None:
237 self._changeid = changeid
237 self._changeid = changeid
238 if changectx is not None:
238 if changectx is not None:
239 self._changectx = changectx
239 self._changectx = changectx
240 if fileid is not None:
240 if fileid is not None:
241 self._fileid = fileid
241 self._fileid = fileid
242
242
243 @propertycache
243 @propertycache
244 def _changectx(self):
244 def _changectx(self):
245 return changectx(self._repo, self._changeid)
245 return changectx(self._repo, self._changeid)
246
246
247 @propertycache
247 @propertycache
248 def _filelog(self):
248 def _filelog(self):
249 return self._repo.file(self._path)
249 return self._repo.file(self._path)
250
250
251 @propertycache
251 @propertycache
252 def _changeid(self):
252 def _changeid(self):
253 if '_changectx' in self.__dict__:
253 if '_changectx' in self.__dict__:
254 return self._changectx.rev()
254 return self._changectx.rev()
255 else:
255 else:
256 return self._filelog.linkrev(self._filerev)
256 return self._filelog.linkrev(self._filerev)
257
257
258 @propertycache
258 @propertycache
259 def _filenode(self):
259 def _filenode(self):
260 if '_fileid' in self.__dict__:
260 if '_fileid' in self.__dict__:
261 return self._filelog.lookup(self._fileid)
261 return self._filelog.lookup(self._fileid)
262 else:
262 else:
263 return self._changectx.filenode(self._path)
263 return self._changectx.filenode(self._path)
264
264
265 @propertycache
265 @propertycache
266 def _filerev(self):
266 def _filerev(self):
267 return self._filelog.rev(self._filenode)
267 return self._filelog.rev(self._filenode)
268
268
269 @propertycache
269 @propertycache
270 def _repopath(self):
270 def _repopath(self):
271 return self._path
271 return self._path
272
272
273 def __nonzero__(self):
273 def __nonzero__(self):
274 try:
274 try:
275 self._filenode
275 self._filenode
276 return True
276 return True
277 except error.LookupError:
277 except error.LookupError:
278 # file is missing
278 # file is missing
279 return False
279 return False
280
280
281 def __str__(self):
281 def __str__(self):
282 return "%s@%s" % (self.path(), short(self.node()))
282 return "%s@%s" % (self.path(), short(self.node()))
283
283
284 def __repr__(self):
284 def __repr__(self):
285 return "<filectx %s>" % str(self)
285 return "<filectx %s>" % str(self)
286
286
287 def __hash__(self):
287 def __hash__(self):
288 try:
288 try:
289 return hash((self._path, self._filenode))
289 return hash((self._path, self._filenode))
290 except AttributeError:
290 except AttributeError:
291 return id(self)
291 return id(self)
292
292
293 def __eq__(self, other):
293 def __eq__(self, other):
294 try:
294 try:
295 return (self._path == other._path
295 return (self._path == other._path
296 and self._filenode == other._filenode)
296 and self._filenode == other._filenode)
297 except AttributeError:
297 except AttributeError:
298 return False
298 return False
299
299
300 def __ne__(self, other):
300 def __ne__(self, other):
301 return not (self == other)
301 return not (self == other)
302
302
303 def filectx(self, fileid):
303 def filectx(self, fileid):
304 '''opens an arbitrary revision of the file without
304 '''opens an arbitrary revision of the file without
305 opening a new filelog'''
305 opening a new filelog'''
306 return filectx(self._repo, self._path, fileid=fileid,
306 return filectx(self._repo, self._path, fileid=fileid,
307 filelog=self._filelog)
307 filelog=self._filelog)
308
308
309 def filerev(self):
309 def filerev(self):
310 return self._filerev
310 return self._filerev
311 def filenode(self):
311 def filenode(self):
312 return self._filenode
312 return self._filenode
313 def flags(self):
313 def flags(self):
314 return self._changectx.flags(self._path)
314 return self._changectx.flags(self._path)
315 def filelog(self):
315 def filelog(self):
316 return self._filelog
316 return self._filelog
317
317
318 def rev(self):
318 def rev(self):
319 if '_changectx' in self.__dict__:
319 if '_changectx' in self.__dict__:
320 return self._changectx.rev()
320 return self._changectx.rev()
321 if '_changeid' in self.__dict__:
321 if '_changeid' in self.__dict__:
322 return self._changectx.rev()
322 return self._changectx.rev()
323 return self._filelog.linkrev(self._filerev)
323 return self._filelog.linkrev(self._filerev)
324
324
325 def linkrev(self):
325 def linkrev(self):
326 return self._filelog.linkrev(self._filerev)
326 return self._filelog.linkrev(self._filerev)
327 def node(self):
327 def node(self):
328 return self._changectx.node()
328 return self._changectx.node()
329 def hex(self):
329 def hex(self):
330 return hex(self.node())
330 return hex(self.node())
331 def user(self):
331 def user(self):
332 return self._changectx.user()
332 return self._changectx.user()
333 def date(self):
333 def date(self):
334 return self._changectx.date()
334 return self._changectx.date()
335 def files(self):
335 def files(self):
336 return self._changectx.files()
336 return self._changectx.files()
337 def description(self):
337 def description(self):
338 return self._changectx.description()
338 return self._changectx.description()
339 def branch(self):
339 def branch(self):
340 return self._changectx.branch()
340 return self._changectx.branch()
341 def extra(self):
341 def extra(self):
342 return self._changectx.extra()
342 return self._changectx.extra()
343 def manifest(self):
343 def manifest(self):
344 return self._changectx.manifest()
344 return self._changectx.manifest()
345 def changectx(self):
345 def changectx(self):
346 return self._changectx
346 return self._changectx
347
347
348 def data(self):
348 def data(self):
349 return self._filelog.read(self._filenode)
349 return self._filelog.read(self._filenode)
350 def path(self):
350 def path(self):
351 return self._path
351 return self._path
352 def size(self):
352 def size(self):
353 return self._filelog.size(self._filerev)
353 return self._filelog.size(self._filerev)
354
354
355 def cmp(self, fctx):
355 def cmp(self, fctx):
356 """compare with other file context
356 """compare with other file context
357
357
358 returns True if different than fctx.
358 returns True if different than fctx.
359 """
359 """
360 return self._filelog.cmp(self._filenode, fctx.data())
360 return self._filelog.cmp(self._filenode, fctx.data())
361
361
362 def renamed(self):
362 def renamed(self):
363 """check if file was actually renamed in this changeset revision
363 """check if file was actually renamed in this changeset revision
364
364
365 If rename logged in file revision, we report copy for changeset only
365 If rename logged in file revision, we report copy for changeset only
366 if file revisions linkrev points back to the changeset in question
366 if file revisions linkrev points back to the changeset in question
367 or both changeset parents contain different file revisions.
367 or both changeset parents contain different file revisions.
368 """
368 """
369
369
370 renamed = self._filelog.renamed(self._filenode)
370 renamed = self._filelog.renamed(self._filenode)
371 if not renamed:
371 if not renamed:
372 return renamed
372 return renamed
373
373
374 if self.rev() == self.linkrev():
374 if self.rev() == self.linkrev():
375 return renamed
375 return renamed
376
376
377 name = self.path()
377 name = self.path()
378 fnode = self._filenode
378 fnode = self._filenode
379 for p in self._changectx.parents():
379 for p in self._changectx.parents():
380 try:
380 try:
381 if fnode == p.filenode(name):
381 if fnode == p.filenode(name):
382 return None
382 return None
383 except error.LookupError:
383 except error.LookupError:
384 pass
384 pass
385 return renamed
385 return renamed
386
386
387 def parents(self):
387 def parents(self):
388 p = self._path
388 p = self._path
389 fl = self._filelog
389 fl = self._filelog
390 pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)]
390 pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)]
391
391
392 r = self._filelog.renamed(self._filenode)
392 r = self._filelog.renamed(self._filenode)
393 if r:
393 if r:
394 pl[0] = (r[0], r[1], None)
394 pl[0] = (r[0], r[1], None)
395
395
396 return [filectx(self._repo, p, fileid=n, filelog=l)
396 return [filectx(self._repo, p, fileid=n, filelog=l)
397 for p, n, l in pl if n != nullid]
397 for p, n, l in pl if n != nullid]
398
398
399 def children(self):
399 def children(self):
400 # hard for renames
400 # hard for renames
401 c = self._filelog.children(self._filenode)
401 c = self._filelog.children(self._filenode)
402 return [filectx(self._repo, self._path, fileid=x,
402 return [filectx(self._repo, self._path, fileid=x,
403 filelog=self._filelog) for x in c]
403 filelog=self._filelog) for x in c]
404
404
405 def annotate(self, follow=False, linenumber=None):
405 def annotate(self, follow=False, linenumber=None):
406 '''returns a list of tuples of (ctx, line) for each line
406 '''returns a list of tuples of (ctx, line) for each line
407 in the file, where ctx is the filectx of the node where
407 in the file, where ctx is the filectx of the node where
408 that line was last changed.
408 that line was last changed.
409 This returns tuples of ((ctx, linenumber), line) for each line,
409 This returns tuples of ((ctx, linenumber), line) for each line,
410 if "linenumber" parameter is NOT "None".
410 if "linenumber" parameter is NOT "None".
411 In such tuples, linenumber means one at the first appearance
411 In such tuples, linenumber means one at the first appearance
412 in the managed file.
412 in the managed file.
413 To reduce annotation cost,
413 To reduce annotation cost,
414 this returns fixed value(False is used) as linenumber,
414 this returns fixed value(False is used) as linenumber,
415 if "linenumber" parameter is "False".'''
415 if "linenumber" parameter is "False".'''
416
416
417 def decorate_compat(text, rev):
417 def decorate_compat(text, rev):
418 return ([rev] * len(text.splitlines()), text)
418 return ([rev] * len(text.splitlines()), text)
419
419
420 def without_linenumber(text, rev):
420 def without_linenumber(text, rev):
421 return ([(rev, False)] * len(text.splitlines()), text)
421 return ([(rev, False)] * len(text.splitlines()), text)
422
422
423 def with_linenumber(text, rev):
423 def with_linenumber(text, rev):
424 size = len(text.splitlines())
424 size = len(text.splitlines())
425 return ([(rev, i) for i in xrange(1, size + 1)], text)
425 return ([(rev, i) for i in xrange(1, size + 1)], text)
426
426
427 decorate = (((linenumber is None) and decorate_compat) or
427 decorate = (((linenumber is None) and decorate_compat) or
428 (linenumber and with_linenumber) or
428 (linenumber and with_linenumber) or
429 without_linenumber)
429 without_linenumber)
430
430
431 def pair(parent, child):
431 def pair(parent, child):
432 for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]):
432 for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]):
433 child[0][b1:b2] = parent[0][a1:a2]
433 child[0][b1:b2] = parent[0][a1:a2]
434 return child
434 return child
435
435
436 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
436 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
437 def getctx(path, fileid):
437 def getctx(path, fileid):
438 log = path == self._path and self._filelog or getlog(path)
438 log = path == self._path and self._filelog or getlog(path)
439 return filectx(self._repo, path, fileid=fileid, filelog=log)
439 return filectx(self._repo, path, fileid=fileid, filelog=log)
440 getctx = util.lrucachefunc(getctx)
440 getctx = util.lrucachefunc(getctx)
441
441
442 def parents(f):
442 def parents(f):
443 # we want to reuse filectx objects as much as possible
443 # we want to reuse filectx objects as much as possible
444 p = f._path
444 p = f._path
445 if f._filerev is None: # working dir
445 if f._filerev is None: # working dir
446 pl = [(n.path(), n.filerev()) for n in f.parents()]
446 pl = [(n.path(), n.filerev()) for n in f.parents()]
447 else:
447 else:
448 pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)]
448 pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)]
449
449
450 if follow:
450 if follow:
451 r = f.renamed()
451 r = f.renamed()
452 if r:
452 if r:
453 pl[0] = (r[0], getlog(r[0]).rev(r[1]))
453 pl[0] = (r[0], getlog(r[0]).rev(r[1]))
454
454
455 return [getctx(p, n) for p, n in pl if n != nullrev]
455 return [getctx(p, n) for p, n in pl if n != nullrev]
456
456
457 # use linkrev to find the first changeset where self appeared
457 # use linkrev to find the first changeset where self appeared
458 if self.rev() != self.linkrev():
458 if self.rev() != self.linkrev():
459 base = self.filectx(self.filerev())
459 base = self.filectx(self.filerev())
460 else:
460 else:
461 base = self
461 base = self
462
462
463 # find all ancestors
463 # find all ancestors
464 needed = {base: 1}
464 needed = {base: 1}
465 visit = [base]
465 visit = [base]
466 files = [base._path]
466 files = [base._path]
467 while visit:
467 while visit:
468 f = visit.pop(0)
468 f = visit.pop(0)
469 for p in parents(f):
469 for p in parents(f):
470 if p not in needed:
470 if p not in needed:
471 needed[p] = 1
471 needed[p] = 1
472 visit.append(p)
472 visit.append(p)
473 if p._path not in files:
473 if p._path not in files:
474 files.append(p._path)
474 files.append(p._path)
475 else:
475 else:
476 # count how many times we'll use this
476 # count how many times we'll use this
477 needed[p] += 1
477 needed[p] += 1
478
478
479 # sort by revision (per file) which is a topological order
479 # sort by revision (per file) which is a topological order
480 visit = []
480 visit = []
481 for f in files:
481 for f in files:
482 visit.extend(n for n in needed if n._path == f)
482 visit.extend(n for n in needed if n._path == f)
483
483
484 hist = {}
484 hist = {}
485 for f in sorted(visit, key=lambda x: x.rev()):
485 for f in sorted(visit, key=lambda x: x.rev()):
486 curr = decorate(f.data(), f)
486 curr = decorate(f.data(), f)
487 for p in parents(f):
487 for p in parents(f):
488 curr = pair(hist[p], curr)
488 curr = pair(hist[p], curr)
489 # trim the history of unneeded revs
489 # trim the history of unneeded revs
490 needed[p] -= 1
490 needed[p] -= 1
491 if not needed[p]:
491 if not needed[p]:
492 del hist[p]
492 del hist[p]
493 hist[f] = curr
493 hist[f] = curr
494
494
495 return zip(hist[f][0], hist[f][1].splitlines(True))
495 return zip(hist[f][0], hist[f][1].splitlines(True))
496
496
497 def ancestor(self, fc2, actx=None):
497 def ancestor(self, fc2, actx=None):
498 """
498 """
499 find the common ancestor file context, if any, of self, and fc2
499 find the common ancestor file context, if any, of self, and fc2
500
500
501 If actx is given, it must be the changectx of the common ancestor
501 If actx is given, it must be the changectx of the common ancestor
502 of self's and fc2's respective changesets.
502 of self's and fc2's respective changesets.
503 """
503 """
504
504
505 if actx is None:
505 if actx is None:
506 actx = self.changectx().ancestor(fc2.changectx())
506 actx = self.changectx().ancestor(fc2.changectx())
507
507
508 # the trivial case: changesets are unrelated, files must be too
508 # the trivial case: changesets are unrelated, files must be too
509 if not actx:
509 if not actx:
510 return None
510 return None
511
511
512 # the easy case: no (relevant) renames
512 # the easy case: no (relevant) renames
513 if fc2.path() == self.path() and self.path() in actx:
513 if fc2.path() == self.path() and self.path() in actx:
514 return actx[self.path()]
514 return actx[self.path()]
515 acache = {}
515 acache = {}
516
516
517 # prime the ancestor cache for the working directory
517 # prime the ancestor cache for the working directory
518 for c in (self, fc2):
518 for c in (self, fc2):
519 if c._filerev is None:
519 if c._filerev is None:
520 pl = [(n.path(), n.filenode()) for n in c.parents()]
520 pl = [(n.path(), n.filenode()) for n in c.parents()]
521 acache[(c._path, None)] = pl
521 acache[(c._path, None)] = pl
522
522
523 flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog}
523 flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog}
524 def parents(vertex):
524 def parents(vertex):
525 if vertex in acache:
525 if vertex in acache:
526 return acache[vertex]
526 return acache[vertex]
527 f, n = vertex
527 f, n = vertex
528 if f not in flcache:
528 if f not in flcache:
529 flcache[f] = self._repo.file(f)
529 flcache[f] = self._repo.file(f)
530 fl = flcache[f]
530 fl = flcache[f]
531 pl = [(f, p) for p in fl.parents(n) if p != nullid]
531 pl = [(f, p) for p in fl.parents(n) if p != nullid]
532 re = fl.renamed(n)
532 re = fl.renamed(n)
533 if re:
533 if re:
534 pl.append(re)
534 pl.append(re)
535 acache[vertex] = pl
535 acache[vertex] = pl
536 return pl
536 return pl
537
537
538 a, b = (self._path, self._filenode), (fc2._path, fc2._filenode)
538 a, b = (self._path, self._filenode), (fc2._path, fc2._filenode)
539 v = ancestor.ancestor(a, b, parents)
539 v = ancestor.ancestor(a, b, parents)
540 if v:
540 if v:
541 f, n = v
541 f, n = v
542 return filectx(self._repo, f, fileid=n, filelog=flcache[f])
542 return filectx(self._repo, f, fileid=n, filelog=flcache[f])
543
543
544 return None
544 return None
545
545
546 def ancestors(self):
546 def ancestors(self):
547 seen = set(str(self))
547 seen = set(str(self))
548 visit = [self]
548 visit = [self]
549 while visit:
549 while visit:
550 for parent in visit.pop(0).parents():
550 for parent in visit.pop(0).parents():
551 s = str(parent)
551 s = str(parent)
552 if s not in seen:
552 if s not in seen:
553 visit.append(parent)
553 visit.append(parent)
554 seen.add(s)
554 seen.add(s)
555 yield parent
555 yield parent
556
556
557 class workingctx(changectx):
557 class workingctx(changectx):
558 """A workingctx object makes access to data related to
558 """A workingctx object makes access to data related to
559 the current working directory convenient.
559 the current working directory convenient.
560 date - any valid date string or (unixtime, offset), or None.
560 date - any valid date string or (unixtime, offset), or None.
561 user - username string, or None.
561 user - username string, or None.
562 extra - a dictionary of extra values, or None.
562 extra - a dictionary of extra values, or None.
563 changes - a list of file lists as returned by localrepo.status()
563 changes - a list of file lists as returned by localrepo.status()
564 or None to use the repository status.
564 or None to use the repository status.
565 """
565 """
566 def __init__(self, repo, text="", user=None, date=None, extra=None,
566 def __init__(self, repo, text="", user=None, date=None, extra=None,
567 changes=None):
567 changes=None):
568 self._repo = repo
568 self._repo = repo
569 self._rev = None
569 self._rev = None
570 self._node = None
570 self._node = None
571 self._text = text
571 self._text = text
572 if date:
572 if date:
573 self._date = util.parsedate(date)
573 self._date = util.parsedate(date)
574 if user:
574 if user:
575 self._user = user
575 self._user = user
576 if changes:
576 if changes:
577 self._status = list(changes[:4])
577 self._status = list(changes[:4])
578 self._unknown = changes[4]
578 self._unknown = changes[4]
579 self._ignored = changes[5]
579 self._ignored = changes[5]
580 self._clean = changes[6]
580 self._clean = changes[6]
581 else:
581 else:
582 self._unknown = None
582 self._unknown = None
583 self._ignored = None
583 self._ignored = None
584 self._clean = None
584 self._clean = None
585
585
586 self._extra = {}
586 self._extra = {}
587 if extra:
587 if extra:
588 self._extra = extra.copy()
588 self._extra = extra.copy()
589 if 'branch' not in self._extra:
589 if 'branch' not in self._extra:
590 branch = self._repo.dirstate.branch()
590 branch = self._repo.dirstate.branch()
591 try:
591 try:
592 branch = branch.decode('UTF-8').encode('UTF-8')
592 branch = branch.decode('UTF-8').encode('UTF-8')
593 except UnicodeDecodeError:
593 except UnicodeDecodeError:
594 raise util.Abort(_('branch name not in UTF-8!'))
594 raise util.Abort(_('branch name not in UTF-8!'))
595 self._extra['branch'] = branch
595 self._extra['branch'] = branch
596 if self._extra['branch'] == '':
596 if self._extra['branch'] == '':
597 self._extra['branch'] = 'default'
597 self._extra['branch'] = 'default'
598
598
599 def __str__(self):
599 def __str__(self):
600 return str(self._parents[0]) + "+"
600 return str(self._parents[0]) + "+"
601
601
602 def __nonzero__(self):
602 def __nonzero__(self):
603 return True
603 return True
604
604
605 def __contains__(self, key):
605 def __contains__(self, key):
606 return self._repo.dirstate[key] not in "?r"
606 return self._repo.dirstate[key] not in "?r"
607
607
608 @propertycache
608 @propertycache
609 def _manifest(self):
609 def _manifest(self):
610 """generate a manifest corresponding to the working directory"""
610 """generate a manifest corresponding to the working directory"""
611
611
612 if self._unknown is None:
612 if self._unknown is None:
613 self.status(unknown=True)
613 self.status(unknown=True)
614
614
615 man = self._parents[0].manifest().copy()
615 man = self._parents[0].manifest().copy()
616 copied = self._repo.dirstate.copies()
616 copied = self._repo.dirstate.copies()
617 if len(self._parents) > 1:
617 if len(self._parents) > 1:
618 man2 = self.p2().manifest()
618 man2 = self.p2().manifest()
619 def getman(f):
619 def getman(f):
620 if f in man:
620 if f in man:
621 return man
621 return man
622 return man2
622 return man2
623 else:
623 else:
624 getman = lambda f: man
624 getman = lambda f: man
625 def cf(f):
625 def cf(f):
626 f = copied.get(f, f)
626 f = copied.get(f, f)
627 return getman(f).flags(f)
627 return getman(f).flags(f)
628 ff = self._repo.dirstate.flagfunc(cf)
628 ff = self._repo.dirstate.flagfunc(cf)
629 modified, added, removed, deleted = self._status
629 modified, added, removed, deleted = self._status
630 unknown = self._unknown
630 unknown = self._unknown
631 for i, l in (("a", added), ("m", modified), ("u", unknown)):
631 for i, l in (("a", added), ("m", modified), ("u", unknown)):
632 for f in l:
632 for f in l:
633 orig = copied.get(f, f)
633 orig = copied.get(f, f)
634 man[f] = getman(orig).get(orig, nullid) + i
634 man[f] = getman(orig).get(orig, nullid) + i
635 try:
635 try:
636 man.set(f, ff(f))
636 man.set(f, ff(f))
637 except OSError:
637 except OSError:
638 pass
638 pass
639
639
640 for f in deleted + removed:
640 for f in deleted + removed:
641 if f in man:
641 if f in man:
642 del man[f]
642 del man[f]
643
643
644 return man
644 return man
645
645
646 @propertycache
646 @propertycache
647 def _status(self):
647 def _status(self):
648 return self._repo.status()[:4]
648 return self._repo.status()[:4]
649
649
650 @propertycache
650 @propertycache
651 def _user(self):
651 def _user(self):
652 return self._repo.ui.username()
652 return self._repo.ui.username()
653
653
654 @propertycache
654 @propertycache
655 def _date(self):
655 def _date(self):
656 return util.makedate()
656 return util.makedate()
657
657
658 @propertycache
658 @propertycache
659 def _parents(self):
659 def _parents(self):
660 p = self._repo.dirstate.parents()
660 p = self._repo.dirstate.parents()
661 if p[1] == nullid:
661 if p[1] == nullid:
662 p = p[:-1]
662 p = p[:-1]
663 self._parents = [changectx(self._repo, x) for x in p]
663 self._parents = [changectx(self._repo, x) for x in p]
664 return self._parents
664 return self._parents
665
665
666 def status(self, ignored=False, clean=False, unknown=False):
666 def status(self, ignored=False, clean=False, unknown=False):
667 """Explicit status query
667 """Explicit status query
668 Unless this method is used to query the working copy status, the
668 Unless this method is used to query the working copy status, the
669 _status property will implicitly read the status using its default
669 _status property will implicitly read the status using its default
670 arguments."""
670 arguments."""
671 stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown)
671 stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown)
672 self._unknown = self._ignored = self._clean = None
672 self._unknown = self._ignored = self._clean = None
673 if unknown:
673 if unknown:
674 self._unknown = stat[4]
674 self._unknown = stat[4]
675 if ignored:
675 if ignored:
676 self._ignored = stat[5]
676 self._ignored = stat[5]
677 if clean:
677 if clean:
678 self._clean = stat[6]
678 self._clean = stat[6]
679 self._status = stat[:4]
679 self._status = stat[:4]
680 return stat
680 return stat
681
681
682 def manifest(self):
682 def manifest(self):
683 return self._manifest
683 return self._manifest
684 def user(self):
684 def user(self):
685 return self._user or self._repo.ui.username()
685 return self._user or self._repo.ui.username()
686 def date(self):
686 def date(self):
687 return self._date
687 return self._date
688 def description(self):
688 def description(self):
689 return self._text
689 return self._text
690 def files(self):
690 def files(self):
691 return sorted(self._status[0] + self._status[1] + self._status[2])
691 return sorted(self._status[0] + self._status[1] + self._status[2])
692
692
693 def modified(self):
693 def modified(self):
694 return self._status[0]
694 return self._status[0]
695 def added(self):
695 def added(self):
696 return self._status[1]
696 return self._status[1]
697 def removed(self):
697 def removed(self):
698 return self._status[2]
698 return self._status[2]
699 def deleted(self):
699 def deleted(self):
700 return self._status[3]
700 return self._status[3]
701 def unknown(self):
701 def unknown(self):
702 assert self._unknown is not None # must call status first
702 assert self._unknown is not None # must call status first
703 return self._unknown
703 return self._unknown
704 def ignored(self):
704 def ignored(self):
705 assert self._ignored is not None # must call status first
705 assert self._ignored is not None # must call status first
706 return self._ignored
706 return self._ignored
707 def clean(self):
707 def clean(self):
708 assert self._clean is not None # must call status first
708 assert self._clean is not None # must call status first
709 return self._clean
709 return self._clean
710 def branch(self):
710 def branch(self):
711 return self._extra['branch']
711 return self._extra['branch']
712 def extra(self):
712 def extra(self):
713 return self._extra
713 return self._extra
714
714
715 def tags(self):
715 def tags(self):
716 t = []
716 t = []
717 [t.extend(p.tags()) for p in self.parents()]
717 [t.extend(p.tags()) for p in self.parents()]
718 return t
718 return t
719
719
720 def children(self):
720 def children(self):
721 return []
721 return []
722
722
723 def flags(self, path):
723 def flags(self, path):
724 if '_manifest' in self.__dict__:
724 if '_manifest' in self.__dict__:
725 try:
725 try:
726 return self._manifest.flags(path)
726 return self._manifest.flags(path)
727 except KeyError:
727 except KeyError:
728 return ''
728 return ''
729
729
730 orig = self._repo.dirstate.copies().get(path, path)
730 orig = self._repo.dirstate.copies().get(path, path)
731
731
732 def findflag(ctx):
732 def findflag(ctx):
733 mnode = ctx.changeset()[0]
733 mnode = ctx.changeset()[0]
734 node, flag = self._repo.manifest.find(mnode, orig)
734 node, flag = self._repo.manifest.find(mnode, orig)
735 ff = self._repo.dirstate.flagfunc(lambda x: flag or '')
735 ff = self._repo.dirstate.flagfunc(lambda x: flag or '')
736 try:
736 try:
737 return ff(path)
737 return ff(path)
738 except OSError:
738 except OSError:
739 pass
739 pass
740
740
741 flag = findflag(self._parents[0])
741 flag = findflag(self._parents[0])
742 if flag is None and len(self.parents()) > 1:
742 if flag is None and len(self.parents()) > 1:
743 flag = findflag(self._parents[1])
743 flag = findflag(self._parents[1])
744 if flag is None or self._repo.dirstate[path] == 'r':
744 if flag is None or self._repo.dirstate[path] == 'r':
745 return ''
745 return ''
746 return flag
746 return flag
747
747
748 def filectx(self, path, filelog=None):
748 def filectx(self, path, filelog=None):
749 """get a file context from the working directory"""
749 """get a file context from the working directory"""
750 return workingfilectx(self._repo, path, workingctx=self,
750 return workingfilectx(self._repo, path, workingctx=self,
751 filelog=filelog)
751 filelog=filelog)
752
752
753 def ancestor(self, c2):
753 def ancestor(self, c2):
754 """return the ancestor context of self and c2"""
754 """return the ancestor context of self and c2"""
755 return self._parents[0].ancestor(c2) # punt on two parents for now
755 return self._parents[0].ancestor(c2) # punt on two parents for now
756
756
757 def walk(self, match):
757 def walk(self, match):
758 return sorted(self._repo.dirstate.walk(match, self.substate.keys(),
758 return sorted(self._repo.dirstate.walk(match, self.substate.keys(),
759 True, False))
759 True, False))
760
760
761 def dirty(self, missing=False):
761 def dirty(self, missing=False):
762 "check whether a working directory is modified"
762 "check whether a working directory is modified"
763 # check subrepos first
763 # check subrepos first
764 for s in self.substate:
764 for s in self.substate:
765 if self.sub(s).dirty():
765 if self.sub(s).dirty():
766 return True
766 return True
767 # check current working dir
767 # check current working dir
768 return (self.p2() or self.branch() != self.p1().branch() or
768 return (self.p2() or self.branch() != self.p1().branch() or
769 self.modified() or self.added() or self.removed() or
769 self.modified() or self.added() or self.removed() or
770 (missing and self.deleted()))
770 (missing and self.deleted()))
771
771
772 def add(self, list):
772 def add(self, list):
773 wlock = self._repo.wlock()
773 wlock = self._repo.wlock()
774 ui, ds = self._repo.ui, self._repo.dirstate
774 ui, ds = self._repo.ui, self._repo.dirstate
775 try:
775 try:
776 rejected = []
776 rejected = []
777 for f in list:
777 for f in list:
778 p = self._repo.wjoin(f)
778 p = self._repo.wjoin(f)
779 try:
779 try:
780 st = os.lstat(p)
780 st = os.lstat(p)
781 except:
781 except:
782 ui.warn(_("%s does not exist!\n") % f)
782 ui.warn(_("%s does not exist!\n") % f)
783 rejected.append(f)
783 rejected.append(f)
784 continue
784 continue
785 if st.st_size > 10000000:
785 if st.st_size > 10000000:
786 ui.warn(_("%s: up to %d MB of RAM may be required "
786 ui.warn(_("%s: up to %d MB of RAM may be required "
787 "to manage this file\n"
787 "to manage this file\n"
788 "(use 'hg revert %s' to cancel the "
788 "(use 'hg revert %s' to cancel the "
789 "pending addition)\n")
789 "pending addition)\n")
790 % (f, 3 * st.st_size // 1000000, f))
790 % (f, 3 * st.st_size // 1000000, f))
791 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
791 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
792 ui.warn(_("%s not added: only files and symlinks "
792 ui.warn(_("%s not added: only files and symlinks "
793 "supported currently\n") % f)
793 "supported currently\n") % f)
794 rejected.append(p)
794 rejected.append(p)
795 elif ds[f] in 'amn':
795 elif ds[f] in 'amn':
796 ui.warn(_("%s already tracked!\n") % f)
796 ui.warn(_("%s already tracked!\n") % f)
797 elif ds[f] == 'r':
797 elif ds[f] == 'r':
798 ds.normallookup(f)
798 ds.normallookup(f)
799 else:
799 else:
800 ds.add(f)
800 ds.add(f)
801 return rejected
801 return rejected
802 finally:
802 finally:
803 wlock.release()
803 wlock.release()
804
804
805 def forget(self, list):
805 def forget(self, list):
806 wlock = self._repo.wlock()
806 wlock = self._repo.wlock()
807 try:
807 try:
808 for f in list:
808 for f in list:
809 if self._repo.dirstate[f] != 'a':
809 if self._repo.dirstate[f] != 'a':
810 self._repo.ui.warn(_("%s not added!\n") % f)
810 self._repo.ui.warn(_("%s not added!\n") % f)
811 else:
811 else:
812 self._repo.dirstate.forget(f)
812 self._repo.dirstate.forget(f)
813 finally:
813 finally:
814 wlock.release()
814 wlock.release()
815
815
816 def remove(self, list, unlink=False):
816 def remove(self, list, unlink=False):
817 if unlink:
817 if unlink:
818 for f in list:
818 for f in list:
819 try:
819 try:
820 util.unlink(self._repo.wjoin(f))
820 util.unlink(self._repo.wjoin(f))
821 except OSError, inst:
821 except OSError, inst:
822 if inst.errno != errno.ENOENT:
822 if inst.errno != errno.ENOENT:
823 raise
823 raise
824 wlock = self._repo.wlock()
824 wlock = self._repo.wlock()
825 try:
825 try:
826 for f in list:
826 for f in list:
827 if unlink and os.path.exists(self._repo.wjoin(f)):
827 if unlink and os.path.exists(self._repo.wjoin(f)):
828 self._repo.ui.warn(_("%s still exists!\n") % f)
828 self._repo.ui.warn(_("%s still exists!\n") % f)
829 elif self._repo.dirstate[f] == 'a':
829 elif self._repo.dirstate[f] == 'a':
830 self._repo.dirstate.forget(f)
830 self._repo.dirstate.forget(f)
831 elif f not in self._repo.dirstate:
831 elif f not in self._repo.dirstate:
832 self._repo.ui.warn(_("%s not tracked!\n") % f)
832 self._repo.ui.warn(_("%s not tracked!\n") % f)
833 else:
833 else:
834 self._repo.dirstate.remove(f)
834 self._repo.dirstate.remove(f)
835 finally:
835 finally:
836 wlock.release()
836 wlock.release()
837
837
838 def undelete(self, list):
838 def undelete(self, list):
839 pctxs = self.parents()
839 pctxs = self.parents()
840 wlock = self._repo.wlock()
840 wlock = self._repo.wlock()
841 try:
841 try:
842 for f in list:
842 for f in list:
843 if self._repo.dirstate[f] != 'r':
843 if self._repo.dirstate[f] != 'r':
844 self._repo.ui.warn(_("%s not removed!\n") % f)
844 self._repo.ui.warn(_("%s not removed!\n") % f)
845 else:
845 else:
846 fctx = f in pctxs[0] and pctxs[0] or pctxs[1]
846 fctx = f in pctxs[0] and pctxs[0] or pctxs[1]
847 t = fctx.data()
847 t = fctx.data()
848 self._repo.wwrite(f, t, fctx.flags())
848 self._repo.wwrite(f, t, fctx.flags())
849 self._repo.dirstate.normal(f)
849 self._repo.dirstate.normal(f)
850 finally:
850 finally:
851 wlock.release()
851 wlock.release()
852
852
853 def copy(self, source, dest):
853 def copy(self, source, dest):
854 p = self._repo.wjoin(dest)
854 p = self._repo.wjoin(dest)
855 if not (os.path.exists(p) or os.path.islink(p)):
855 if not (os.path.exists(p) or os.path.islink(p)):
856 self._repo.ui.warn(_("%s does not exist!\n") % dest)
856 self._repo.ui.warn(_("%s does not exist!\n") % dest)
857 elif not (os.path.isfile(p) or os.path.islink(p)):
857 elif not (os.path.isfile(p) or os.path.islink(p)):
858 self._repo.ui.warn(_("copy failed: %s is not a file or a "
858 self._repo.ui.warn(_("copy failed: %s is not a file or a "
859 "symbolic link\n") % dest)
859 "symbolic link\n") % dest)
860 else:
860 else:
861 wlock = self._repo.wlock()
861 wlock = self._repo.wlock()
862 try:
862 try:
863 if self._repo.dirstate[dest] in '?r':
863 if self._repo.dirstate[dest] in '?r':
864 self._repo.dirstate.add(dest)
864 self._repo.dirstate.add(dest)
865 self._repo.dirstate.copy(source, dest)
865 self._repo.dirstate.copy(source, dest)
866 finally:
866 finally:
867 wlock.release()
867 wlock.release()
868
868
869 class workingfilectx(filectx):
869 class workingfilectx(filectx):
870 """A workingfilectx object makes access to data related to a particular
870 """A workingfilectx object makes access to data related to a particular
871 file in the working directory convenient."""
871 file in the working directory convenient."""
872 def __init__(self, repo, path, filelog=None, workingctx=None):
872 def __init__(self, repo, path, filelog=None, workingctx=None):
873 """changeid can be a changeset revision, node, or tag.
873 """changeid can be a changeset revision, node, or tag.
874 fileid can be a file revision or node."""
874 fileid can be a file revision or node."""
875 self._repo = repo
875 self._repo = repo
876 self._path = path
876 self._path = path
877 self._changeid = None
877 self._changeid = None
878 self._filerev = self._filenode = None
878 self._filerev = self._filenode = None
879
879
880 if filelog:
880 if filelog:
881 self._filelog = filelog
881 self._filelog = filelog
882 if workingctx:
882 if workingctx:
883 self._changectx = workingctx
883 self._changectx = workingctx
884
884
885 @propertycache
885 @propertycache
886 def _changectx(self):
886 def _changectx(self):
887 return workingctx(self._repo)
887 return workingctx(self._repo)
888
888
889 def __nonzero__(self):
889 def __nonzero__(self):
890 return True
890 return True
891
891
892 def __str__(self):
892 def __str__(self):
893 return "%s@%s" % (self.path(), self._changectx)
893 return "%s@%s" % (self.path(), self._changectx)
894
894
895 def data(self):
895 def data(self):
896 return self._repo.wread(self._path)
896 return self._repo.wread(self._path)
897 def renamed(self):
897 def renamed(self):
898 rp = self._repo.dirstate.copied(self._path)
898 rp = self._repo.dirstate.copied(self._path)
899 if not rp:
899 if not rp:
900 return None
900 return None
901 return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
901 return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
902
902
903 def parents(self):
903 def parents(self):
904 '''return parent filectxs, following copies if necessary'''
904 '''return parent filectxs, following copies if necessary'''
905 def filenode(ctx, path):
905 def filenode(ctx, path):
906 return ctx._manifest.get(path, nullid)
906 return ctx._manifest.get(path, nullid)
907
907
908 path = self._path
908 path = self._path
909 fl = self._filelog
909 fl = self._filelog
910 pcl = self._changectx._parents
910 pcl = self._changectx._parents
911 renamed = self.renamed()
911 renamed = self.renamed()
912
912
913 if renamed:
913 if renamed:
914 pl = [renamed + (None,)]
914 pl = [renamed + (None,)]
915 else:
915 else:
916 pl = [(path, filenode(pcl[0], path), fl)]
916 pl = [(path, filenode(pcl[0], path), fl)]
917
917
918 for pc in pcl[1:]:
918 for pc in pcl[1:]:
919 pl.append((path, filenode(pc, path), fl))
919 pl.append((path, filenode(pc, path), fl))
920
920
921 return [filectx(self._repo, p, fileid=n, filelog=l)
921 return [filectx(self._repo, p, fileid=n, filelog=l)
922 for p, n, l in pl if n != nullid]
922 for p, n, l in pl if n != nullid]
923
923
924 def children(self):
924 def children(self):
925 return []
925 return []
926
926
927 def size(self):
927 def size(self):
928 return os.lstat(self._repo.wjoin(self._path)).st_size
928 return os.lstat(self._repo.wjoin(self._path)).st_size
929 def date(self):
929 def date(self):
930 t, tz = self._changectx.date()
930 t, tz = self._changectx.date()
931 try:
931 try:
932 return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz)
932 return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz)
933 except OSError, err:
933 except OSError, err:
934 if err.errno != errno.ENOENT:
934 if err.errno != errno.ENOENT:
935 raise
935 raise
936 return (t, tz)
936 return (t, tz)
937
937
938 def cmp(self, fctx):
938 def cmp(self, fctx):
939 """compare with other file context
939 """compare with other file context
940
940
941 returns True if different than fctx.
941 returns True if different than fctx.
942 """
942 """
943 # fctx should be a filectx (not a wfctx)
943 # fctx should be a filectx (not a wfctx)
944 # invert comparison to reuse the same code path
944 # invert comparison to reuse the same code path
945 return fctx.cmp(self)
945 return fctx.cmp(self)
946
946
947 class memctx(object):
947 class memctx(object):
948 """Use memctx to perform in-memory commits via localrepo.commitctx().
948 """Use memctx to perform in-memory commits via localrepo.commitctx().
949
949
950 Revision information is supplied at initialization time while
950 Revision information is supplied at initialization time while
951 related files data and is made available through a callback
951 related files data and is made available through a callback
952 mechanism. 'repo' is the current localrepo, 'parents' is a
952 mechanism. 'repo' is the current localrepo, 'parents' is a
953 sequence of two parent revisions identifiers (pass None for every
953 sequence of two parent revisions identifiers (pass None for every
954 missing parent), 'text' is the commit message and 'files' lists
954 missing parent), 'text' is the commit message and 'files' lists
955 names of files touched by the revision (normalized and relative to
955 names of files touched by the revision (normalized and relative to
956 repository root).
956 repository root).
957
957
958 filectxfn(repo, memctx, path) is a callable receiving the
958 filectxfn(repo, memctx, path) is a callable receiving the
959 repository, the current memctx object and the normalized path of
959 repository, the current memctx object and the normalized path of
960 requested file, relative to repository root. It is fired by the
960 requested file, relative to repository root. It is fired by the
961 commit function for every file in 'files', but calls order is
961 commit function for every file in 'files', but calls order is
962 undefined. If the file is available in the revision being
962 undefined. If the file is available in the revision being
963 committed (updated or added), filectxfn returns a memfilectx
963 committed (updated or added), filectxfn returns a memfilectx
964 object. If the file was removed, filectxfn raises an
964 object. If the file was removed, filectxfn raises an
965 IOError. Moved files are represented by marking the source file
965 IOError. Moved files are represented by marking the source file
966 removed and the new file added with copy information (see
966 removed and the new file added with copy information (see
967 memfilectx).
967 memfilectx).
968
968
969 user receives the committer name and defaults to current
969 user receives the committer name and defaults to current
970 repository username, date is the commit date in any format
970 repository username, date is the commit date in any format
971 supported by util.parsedate() and defaults to current date, extra
971 supported by util.parsedate() and defaults to current date, extra
972 is a dictionary of metadata or is left empty.
972 is a dictionary of metadata or is left empty.
973 """
973 """
974 def __init__(self, repo, parents, text, files, filectxfn, user=None,
974 def __init__(self, repo, parents, text, files, filectxfn, user=None,
975 date=None, extra=None):
975 date=None, extra=None):
976 self._repo = repo
976 self._repo = repo
977 self._rev = None
977 self._rev = None
978 self._node = None
978 self._node = None
979 self._text = text
979 self._text = text
980 self._date = date and util.parsedate(date) or util.makedate()
980 self._date = date and util.parsedate(date) or util.makedate()
981 self._user = user
981 self._user = user
982 parents = [(p or nullid) for p in parents]
982 parents = [(p or nullid) for p in parents]
983 p1, p2 = parents
983 p1, p2 = parents
984 self._parents = [changectx(self._repo, p) for p in (p1, p2)]
984 self._parents = [changectx(self._repo, p) for p in (p1, p2)]
985 files = sorted(set(files))
985 files = sorted(set(files))
986 self._status = [files, [], [], [], []]
986 self._status = [files, [], [], [], []]
987 self._filectxfn = filectxfn
987 self._filectxfn = filectxfn
988
988
989 self._extra = extra and extra.copy() or {}
989 self._extra = extra and extra.copy() or {}
990 if 'branch' not in self._extra:
990 if 'branch' not in self._extra:
991 self._extra['branch'] = 'default'
991 self._extra['branch'] = 'default'
992 elif self._extra.get('branch') == '':
992 elif self._extra.get('branch') == '':
993 self._extra['branch'] = 'default'
993 self._extra['branch'] = 'default'
994
994
995 def __str__(self):
995 def __str__(self):
996 return str(self._parents[0]) + "+"
996 return str(self._parents[0]) + "+"
997
997
998 def __int__(self):
998 def __int__(self):
999 return self._rev
999 return self._rev
1000
1000
1001 def __nonzero__(self):
1001 def __nonzero__(self):
1002 return True
1002 return True
1003
1003
1004 def __getitem__(self, key):
1004 def __getitem__(self, key):
1005 return self.filectx(key)
1005 return self.filectx(key)
1006
1006
1007 def p1(self):
1007 def p1(self):
1008 return self._parents[0]
1008 return self._parents[0]
1009 def p2(self):
1009 def p2(self):
1010 return self._parents[1]
1010 return self._parents[1]
1011
1011
1012 def user(self):
1012 def user(self):
1013 return self._user or self._repo.ui.username()
1013 return self._user or self._repo.ui.username()
1014 def date(self):
1014 def date(self):
1015 return self._date
1015 return self._date
1016 def description(self):
1016 def description(self):
1017 return self._text
1017 return self._text
1018 def files(self):
1018 def files(self):
1019 return self.modified()
1019 return self.modified()
1020 def modified(self):
1020 def modified(self):
1021 return self._status[0]
1021 return self._status[0]
1022 def added(self):
1022 def added(self):
1023 return self._status[1]
1023 return self._status[1]
1024 def removed(self):
1024 def removed(self):
1025 return self._status[2]
1025 return self._status[2]
1026 def deleted(self):
1026 def deleted(self):
1027 return self._status[3]
1027 return self._status[3]
1028 def unknown(self):
1028 def unknown(self):
1029 return self._status[4]
1029 return self._status[4]
1030 def ignored(self):
1030 def ignored(self):
1031 return self._status[5]
1031 return self._status[5]
1032 def clean(self):
1032 def clean(self):
1033 return self._status[6]
1033 return self._status[6]
1034 def branch(self):
1034 def branch(self):
1035 return self._extra['branch']
1035 return self._extra['branch']
1036 def extra(self):
1036 def extra(self):
1037 return self._extra
1037 return self._extra
1038 def flags(self, f):
1038 def flags(self, f):
1039 return self[f].flags()
1039 return self[f].flags()
1040
1040
1041 def parents(self):
1041 def parents(self):
1042 """return contexts for each parent changeset"""
1042 """return contexts for each parent changeset"""
1043 return self._parents
1043 return self._parents
1044
1044
1045 def filectx(self, path, filelog=None):
1045 def filectx(self, path, filelog=None):
1046 """get a file context from the working directory"""
1046 """get a file context from the working directory"""
1047 return self._filectxfn(self._repo, self, path)
1047 return self._filectxfn(self._repo, self, path)
1048
1048
1049 def commit(self):
1049 def commit(self):
1050 """commit context to the repo"""
1050 """commit context to the repo"""
1051 return self._repo.commitctx(self)
1051 return self._repo.commitctx(self)
1052
1052
1053 class memfilectx(object):
1053 class memfilectx(object):
1054 """memfilectx represents an in-memory file to commit.
1054 """memfilectx represents an in-memory file to commit.
1055
1055
1056 See memctx for more details.
1056 See memctx for more details.
1057 """
1057 """
1058 def __init__(self, path, data, islink=False, isexec=False, copied=None):
1058 def __init__(self, path, data, islink=False, isexec=False, copied=None):
1059 """
1059 """
1060 path is the normalized file path relative to repository root.
1060 path is the normalized file path relative to repository root.
1061 data is the file content as a string.
1061 data is the file content as a string.
1062 islink is True if the file is a symbolic link.
1062 islink is True if the file is a symbolic link.
1063 isexec is True if the file is executable.
1063 isexec is True if the file is executable.
1064 copied is the source file path if current file was copied in the
1064 copied is the source file path if current file was copied in the
1065 revision being committed, or None."""
1065 revision being committed, or None."""
1066 self._path = path
1066 self._path = path
1067 self._data = data
1067 self._data = data
1068 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
1068 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
1069 self._copied = None
1069 self._copied = None
1070 if copied:
1070 if copied:
1071 self._copied = (copied, nullid)
1071 self._copied = (copied, nullid)
1072
1072
1073 def __nonzero__(self):
1073 def __nonzero__(self):
1074 return True
1074 return True
1075 def __str__(self):
1075 def __str__(self):
1076 return "%s@%s" % (self.path(), self._changectx)
1076 return "%s@%s" % (self.path(), self._changectx)
1077 def path(self):
1077 def path(self):
1078 return self._path
1078 return self._path
1079 def data(self):
1079 def data(self):
1080 return self._data
1080 return self._data
1081 def flags(self):
1081 def flags(self):
1082 return self._flags
1082 return self._flags
1083 def isexec(self):
1083 def isexec(self):
1084 return 'x' in self._flags
1084 return 'x' in self._flags
1085 def islink(self):
1085 def islink(self):
1086 return 'l' in self._flags
1086 return 'l' in self._flags
1087 def renamed(self):
1087 def renamed(self):
1088 return self._copied
1088 return self._copied
@@ -1,143 +1,153 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 "$TESTDIR/hghave" cvs || exit 80
3 "$TESTDIR/hghave" cvs || exit 80
4
4
5 cvscall()
5 cvscall()
6 {
6 {
7 cvs -f "$@"
7 cvs -f "$@"
8 }
8 }
9
9
10 hgcat()
10 hgcat()
11 {
11 {
12 hg --cwd src-hg cat -r tip "$1"
12 hg --cwd src-hg cat -r tip "$1"
13 }
13 }
14
14
15 echo "[extensions]" >> $HGRCPATH
15 echo "[extensions]" >> $HGRCPATH
16 echo "convert = " >> $HGRCPATH
16 echo "convert = " >> $HGRCPATH
17 echo "graphlog = " >> $HGRCPATH
17 echo "graphlog = " >> $HGRCPATH
18
18
19 cat > cvshooks.py <<EOF
19 cat > cvshooks.py <<EOF
20 def cvslog(ui,repo,hooktype,log):
20 def cvslog(ui,repo,hooktype,log):
21 print "%s hook: %d entries"%(hooktype,len(log))
21 print "%s hook: %d entries"%(hooktype,len(log))
22
22
23 def cvschangesets(ui,repo,hooktype,changesets):
23 def cvschangesets(ui,repo,hooktype,changesets):
24 print "%s hook: %d changesets"%(hooktype,len(changesets))
24 print "%s hook: %d changesets"%(hooktype,len(changesets))
25 EOF
25 EOF
26 hookpath=`pwd`
26 hookpath=`pwd`
27
27
28 echo "[hooks]" >> $HGRCPATH
28 echo "[hooks]" >> $HGRCPATH
29 echo "cvslog=python:$hookpath/cvshooks.py:cvslog" >> $HGRCPATH
29 echo "cvslog=python:$hookpath/cvshooks.py:cvslog" >> $HGRCPATH
30 echo "cvschangesets=python:$hookpath/cvshooks.py:cvschangesets" >> $HGRCPATH
30 echo "cvschangesets=python:$hookpath/cvshooks.py:cvschangesets" >> $HGRCPATH
31
31
32 echo % create cvs repository
32 echo % create cvs repository
33 mkdir cvsrepo
33 mkdir cvsrepo
34 cd cvsrepo
34 cd cvsrepo
35 CVSROOT=`pwd`
35 CVSROOT=`pwd`
36 export CVSROOT
36 export CVSROOT
37 CVS_OPTIONS=-f
37 CVS_OPTIONS=-f
38 export CVS_OPTIONS
38 export CVS_OPTIONS
39 cd ..
39 cd ..
40
40
41 cvscall -q -d "$CVSROOT" init
41 cvscall -q -d "$CVSROOT" init
42
42
43 echo % create source directory
43 echo % create source directory
44 mkdir src-temp
44 mkdir src-temp
45 cd src-temp
45 cd src-temp
46 echo a > a
46 echo a > a
47 mkdir b
47 mkdir b
48 cd b
48 cd b
49 echo c > c
49 echo c > c
50 cd ..
50 cd ..
51
51
52 echo % import source directory
52 echo % import source directory
53 cvscall -q import -m import src INITIAL start
53 cvscall -q import -m import src INITIAL start
54 cd ..
54 cd ..
55
55
56 echo % checkout source directory
56 echo % checkout source directory
57 cvscall -q checkout src
57 cvscall -q checkout src
58
58
59 echo % commit a new revision changing b/c
59 echo % commit a new revision changing b/c
60 cd src
60 cd src
61 sleep 1
61 sleep 1
62 echo c >> b/c
62 echo c >> b/c
63 cvscall -q commit -mci0 . | grep '<--' |\
63 cvscall -q commit -mci0 . | grep '<--' |\
64 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
64 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
65 cd ..
65 cd ..
66
66
67 echo % convert fresh repo
67 echo % convert fresh repo
68 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
68 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
69 hgcat a
69 hgcat a
70 hgcat b/c
70 hgcat b/c
71
71
72 echo % convert fresh repo with --filemap
72 echo % convert fresh repo with --filemap
73 echo include b/c > filemap
73 echo include b/c > filemap
74 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
74 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
75 hgcat b/c
75 hgcat b/c
76 hg -R src-filemap log --template '{rev} {desc} files: {files}\n'
76 hg -R src-filemap log --template '{rev} {desc} files: {files}\n'
77
77
78 echo % 'convert full repository (issue1649)'
78 echo % 'convert full repository (issue1649)'
79 cvscall -q -d "$CVSROOT" checkout -d srcfull "." | grep -v CVSROOT
79 cvscall -q -d "$CVSROOT" checkout -d srcfull "." | grep -v CVSROOT
80 ls srcfull
80 ls srcfull
81 hg convert srcfull srcfull-hg \
81 hg convert srcfull srcfull-hg \
82 | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' \
82 | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g' \
83 | grep -v 'log entries' | grep -v 'hook:' \
83 | grep -v 'log entries' | grep -v 'hook:' \
84 | grep -v '^[0-3] .*' # filter instable changeset order
84 | grep -v '^[0-3] .*' # filter instable changeset order
85 hg cat -r tip srcfull-hg/src/a
85 hg cat -r tip srcfull-hg/src/a
86 hg cat -r tip srcfull-hg/src/b/c
86 hg cat -r tip srcfull-hg/src/b/c
87
87
88 echo % commit new file revisions
88 echo % commit new file revisions
89 cd src
89 cd src
90 echo a >> a
90 echo a >> a
91 echo c >> b/c
91 echo c >> b/c
92 cvscall -q commit -mci1 . | grep '<--' |\
92 cvscall -q commit -mci1 . | grep '<--' |\
93 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
93 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
94 cd ..
94 cd ..
95
95
96 echo % convert again
96 echo % convert again
97 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
97 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
98 hgcat a
98 hgcat a
99 hgcat b/c
99 hgcat b/c
100
100
101 echo % convert again with --filemap
101 echo % convert again with --filemap
102 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
102 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
103 hgcat b/c
103 hgcat b/c
104 hg -R src-filemap log --template '{rev} {desc} files: {files}\n'
104 hg -R src-filemap log --template '{rev} {desc} files: {files}\n'
105
105
106 echo % commit branch
106 echo % commit branch
107 cd src
107 cd src
108 cvs -q update -r1.1 b/c
108 cvs -q update -r1.1 b/c
109 cvs -q tag -b branch
109 cvs -q tag -b branch
110 cvs -q update -r branch > /dev/null
110 cvs -q update -r branch > /dev/null
111 echo d >> b/c
111 echo d >> b/c
112 cvs -q commit -mci2 . | grep '<--' |\
112 cvs -q commit -mci2 . | grep '<--' |\
113 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
113 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
114 cd ..
114 cd ..
115
115
116 echo % convert again
116 echo % convert again
117 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
117 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
118 hgcat b/c
118 hgcat b/c
119
119
120 echo % convert again with --filemap
120 echo % convert again with --filemap
121 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
121 hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
122 hgcat b/c
122 hgcat b/c
123 hg -R src-filemap log --template '{rev} {desc} files: {files}\n'
123 hg -R src-filemap log --template '{rev} {desc} files: {files}\n'
124
124
125 echo % commit a new revision with funny log message
125 echo % commit a new revision with funny log message
126 cd src
126 cd src
127 sleep 1
127 sleep 1
128 echo e >> a
128 echo e >> a
129 cvscall -q commit -m'funny
129 cvscall -q commit -m'funny
130 ----------------------------
130 ----------------------------
131 log message' . | grep '<--' |\
131 log message' . | grep '<--' |\
132 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
132 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
133 cd ..
133 cd ..
134
134
135 echo % commit new file revisions with some fuzz
136 cd src
137 echo f >> a
138 cvscall -q commit -mfuzzy . | grep '<--' |\
139 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
140 sleep 4 # the two changes will be split if fuzz < 4
141 echo g >> b/c
142 cvscall -q commit -mfuzzy . | grep '<--' |\
143 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
144 cd ..
145
135 echo % convert again
146 echo % convert again
136 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
147 hg convert --config convert.cvsps.fuzz=2 src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
137
148
138 echo "graphlog = " >> $HGRCPATH
139 hg -R src-hg glog --template '{rev} ({branches}) {desc} files: {files}\n'
149 hg -R src-hg glog --template '{rev} ({branches}) {desc} files: {files}\n'
140
150
141 echo % testing debugcvsps
151 echo % testing debugcvsps
142 cd src
152 cd src
143 hg debugcvsps | sed -e 's/Author:.*/Author:/' -e 's/Date:.*/Date:/'
153 hg debugcvsps --fuzz=2 | sed -e 's/Author:.*/Author:/' -e 's/Date:.*/Date:/'
@@ -1,288 +1,321 b''
1 % create cvs repository
1 % create cvs repository
2 % create source directory
2 % create source directory
3 % import source directory
3 % import source directory
4 N src/a
4 N src/a
5 N src/b/c
5 N src/b/c
6
6
7 No conflicts created by this import
7 No conflicts created by this import
8
8
9 % checkout source directory
9 % checkout source directory
10 U src/a
10 U src/a
11 U src/b/c
11 U src/b/c
12 % commit a new revision changing b/c
12 % commit a new revision changing b/c
13 checking in src/b/c,v
13 checking in src/b/c,v
14 % convert fresh repo
14 % convert fresh repo
15 initializing destination src-hg repository
15 initializing destination src-hg repository
16 connecting to cvsrepo
16 connecting to cvsrepo
17 scanning source...
17 scanning source...
18 collecting CVS rlog
18 collecting CVS rlog
19 5 log entries
19 5 log entries
20 cvslog hook: 5 entries
20 cvslog hook: 5 entries
21 creating changesets
21 creating changesets
22 3 changeset entries
22 3 changeset entries
23 cvschangesets hook: 3 changesets
23 cvschangesets hook: 3 changesets
24 sorting...
24 sorting...
25 converting...
25 converting...
26 2 Initial revision
26 2 Initial revision
27 1 import
27 1 import
28 0 ci0
28 0 ci0
29 updating tags
29 updating tags
30 a
30 a
31 c
31 c
32 c
32 c
33 % convert fresh repo with --filemap
33 % convert fresh repo with --filemap
34 initializing destination src-filemap repository
34 initializing destination src-filemap repository
35 connecting to cvsrepo
35 connecting to cvsrepo
36 scanning source...
36 scanning source...
37 collecting CVS rlog
37 collecting CVS rlog
38 5 log entries
38 5 log entries
39 cvslog hook: 5 entries
39 cvslog hook: 5 entries
40 creating changesets
40 creating changesets
41 3 changeset entries
41 3 changeset entries
42 cvschangesets hook: 3 changesets
42 cvschangesets hook: 3 changesets
43 sorting...
43 sorting...
44 converting...
44 converting...
45 2 Initial revision
45 2 Initial revision
46 1 import
46 1 import
47 filtering out empty revision
47 filtering out empty revision
48 rolling back to revision 0 (undo commit)
48 rolling back to revision 0 (undo commit)
49 0 ci0
49 0 ci0
50 updating tags
50 updating tags
51 c
51 c
52 c
52 c
53 2 update tags files: .hgtags
53 2 update tags files: .hgtags
54 1 ci0 files: b/c
54 1 ci0 files: b/c
55 0 Initial revision files: b/c
55 0 Initial revision files: b/c
56 % convert full repository (issue1649)
56 % convert full repository (issue1649)
57 U srcfull/src/a
57 U srcfull/src/a
58 U srcfull/src/b/c
58 U srcfull/src/b/c
59 CVS
59 CVS
60 CVSROOT
60 CVSROOT
61 src
61 src
62 initializing destination srcfull-hg repository
62 initializing destination srcfull-hg repository
63 connecting to cvsrepo
63 connecting to cvsrepo
64 scanning source...
64 scanning source...
65 collecting CVS rlog
65 collecting CVS rlog
66 creating changesets
66 creating changesets
67 4 changeset entries
67 4 changeset entries
68 sorting...
68 sorting...
69 converting...
69 converting...
70 updating tags
70 updating tags
71 a
71 a
72 c
72 c
73 c
73 c
74 % commit new file revisions
74 % commit new file revisions
75 checking in src/a,v
75 checking in src/a,v
76 checking in src/b/c,v
76 checking in src/b/c,v
77 % convert again
77 % convert again
78 connecting to cvsrepo
78 connecting to cvsrepo
79 scanning source...
79 scanning source...
80 collecting CVS rlog
80 collecting CVS rlog
81 7 log entries
81 7 log entries
82 cvslog hook: 7 entries
82 cvslog hook: 7 entries
83 creating changesets
83 creating changesets
84 4 changeset entries
84 4 changeset entries
85 cvschangesets hook: 4 changesets
85 cvschangesets hook: 4 changesets
86 sorting...
86 sorting...
87 converting...
87 converting...
88 0 ci1
88 0 ci1
89 a
89 a
90 a
90 a
91 c
91 c
92 c
92 c
93 c
93 c
94 % convert again with --filemap
94 % convert again with --filemap
95 connecting to cvsrepo
95 connecting to cvsrepo
96 scanning source...
96 scanning source...
97 collecting CVS rlog
97 collecting CVS rlog
98 7 log entries
98 7 log entries
99 cvslog hook: 7 entries
99 cvslog hook: 7 entries
100 creating changesets
100 creating changesets
101 4 changeset entries
101 4 changeset entries
102 cvschangesets hook: 4 changesets
102 cvschangesets hook: 4 changesets
103 sorting...
103 sorting...
104 converting...
104 converting...
105 0 ci1
105 0 ci1
106 c
106 c
107 c
107 c
108 c
108 c
109 3 ci1 files: b/c
109 3 ci1 files: b/c
110 2 update tags files: .hgtags
110 2 update tags files: .hgtags
111 1 ci0 files: b/c
111 1 ci0 files: b/c
112 0 Initial revision files: b/c
112 0 Initial revision files: b/c
113 % commit branch
113 % commit branch
114 U b/c
114 U b/c
115 T a
115 T a
116 T b/c
116 T b/c
117 checking in src/b/c,v
117 checking in src/b/c,v
118 % convert again
118 % convert again
119 connecting to cvsrepo
119 connecting to cvsrepo
120 scanning source...
120 scanning source...
121 collecting CVS rlog
121 collecting CVS rlog
122 8 log entries
122 8 log entries
123 cvslog hook: 8 entries
123 cvslog hook: 8 entries
124 creating changesets
124 creating changesets
125 5 changeset entries
125 5 changeset entries
126 cvschangesets hook: 5 changesets
126 cvschangesets hook: 5 changesets
127 sorting...
127 sorting...
128 converting...
128 converting...
129 0 ci2
129 0 ci2
130 c
130 c
131 d
131 d
132 % convert again with --filemap
132 % convert again with --filemap
133 connecting to cvsrepo
133 connecting to cvsrepo
134 scanning source...
134 scanning source...
135 collecting CVS rlog
135 collecting CVS rlog
136 8 log entries
136 8 log entries
137 cvslog hook: 8 entries
137 cvslog hook: 8 entries
138 creating changesets
138 creating changesets
139 5 changeset entries
139 5 changeset entries
140 cvschangesets hook: 5 changesets
140 cvschangesets hook: 5 changesets
141 sorting...
141 sorting...
142 converting...
142 converting...
143 0 ci2
143 0 ci2
144 c
144 c
145 d
145 d
146 4 ci2 files: b/c
146 4 ci2 files: b/c
147 3 ci1 files: b/c
147 3 ci1 files: b/c
148 2 update tags files: .hgtags
148 2 update tags files: .hgtags
149 1 ci0 files: b/c
149 1 ci0 files: b/c
150 0 Initial revision files: b/c
150 0 Initial revision files: b/c
151 % commit a new revision with funny log message
151 % commit a new revision with funny log message
152 checking in src/a,v
152 checking in src/a,v
153 % commit new file revisions with some fuzz
154 checking in src/a,v
155 checking in src/b/c,v
153 % convert again
156 % convert again
154 connecting to cvsrepo
157 connecting to cvsrepo
155 scanning source...
158 scanning source...
156 collecting CVS rlog
159 collecting CVS rlog
157 9 log entries
160 11 log entries
158 cvslog hook: 9 entries
161 cvslog hook: 11 entries
159 creating changesets
162 creating changesets
160 6 changeset entries
163 8 changeset entries
161 cvschangesets hook: 6 changesets
164 cvschangesets hook: 8 changesets
162 sorting...
165 sorting...
163 converting...
166 converting...
164 0 funny
167 2 funny
168 1 fuzzy
169 0 fuzzy
170 o 8 (branch) fuzzy files: b/c
171 |
172 o 7 (branch) fuzzy files: a
173 |
165 o 6 (branch) funny
174 o 6 (branch) funny
166 | ----------------------------
175 | ----------------------------
167 | log message files: a
176 | log message files: a
168 o 5 (branch) ci2 files: b/c
177 o 5 (branch) ci2 files: b/c
169
178
170 o 4 () ci1 files: a b/c
179 o 4 () ci1 files: a b/c
171 |
180 |
172 o 3 () update tags files: .hgtags
181 o 3 () update tags files: .hgtags
173 |
182 |
174 o 2 () ci0 files: b/c
183 o 2 () ci0 files: b/c
175 |
184 |
176 | o 1 (INITIAL) import files:
185 | o 1 (INITIAL) import files:
177 |/
186 |/
178 o 0 () Initial revision files: a b/c
187 o 0 () Initial revision files: a b/c
179
188
180 % testing debugcvsps
189 % testing debugcvsps
181 collecting CVS rlog
190 collecting CVS rlog
182 9 log entries
191 11 log entries
183 cvslog hook: 9 entries
192 cvslog hook: 11 entries
184 creating changesets
193 creating changesets
185 8 changeset entries
194 10 changeset entries
186 cvschangesets hook: 8 changesets
195 cvschangesets hook: 10 changesets
187 ---------------------
196 ---------------------
188 PatchSet 1
197 PatchSet 1
189 Date:
198 Date:
190 Author:
199 Author:
191 Branch: HEAD
200 Branch: HEAD
192 Tag: (none)
201 Tag: (none)
193 Branchpoints: INITIAL
202 Branchpoints: INITIAL
194 Log:
203 Log:
195 Initial revision
204 Initial revision
196
205
197 Members:
206 Members:
198 a:INITIAL->1.1
207 a:INITIAL->1.1
199
208
200 ---------------------
209 ---------------------
201 PatchSet 2
210 PatchSet 2
202 Date:
211 Date:
203 Author:
212 Author:
204 Branch: HEAD
213 Branch: HEAD
205 Tag: (none)
214 Tag: (none)
206 Branchpoints: INITIAL, branch
215 Branchpoints: INITIAL, branch
207 Log:
216 Log:
208 Initial revision
217 Initial revision
209
218
210 Members:
219 Members:
211 b/c:INITIAL->1.1
220 b/c:INITIAL->1.1
212
221
213 ---------------------
222 ---------------------
214 PatchSet 3
223 PatchSet 3
215 Date:
224 Date:
216 Author:
225 Author:
217 Branch: INITIAL
226 Branch: INITIAL
218 Tag: start
227 Tag: start
219 Log:
228 Log:
220 import
229 import
221
230
222 Members:
231 Members:
223 a:1.1->1.1.1.1
232 a:1.1->1.1.1.1
224 b/c:1.1->1.1.1.1
233 b/c:1.1->1.1.1.1
225
234
226 ---------------------
235 ---------------------
227 PatchSet 4
236 PatchSet 4
228 Date:
237 Date:
229 Author:
238 Author:
230 Branch: HEAD
239 Branch: HEAD
231 Tag: (none)
240 Tag: (none)
232 Log:
241 Log:
233 ci0
242 ci0
234
243
235 Members:
244 Members:
236 b/c:1.1->1.2
245 b/c:1.1->1.2
237
246
238 ---------------------
247 ---------------------
239 PatchSet 5
248 PatchSet 5
240 Date:
249 Date:
241 Author:
250 Author:
242 Branch: HEAD
251 Branch: HEAD
243 Tag: (none)
252 Tag: (none)
244 Branchpoints: branch
253 Branchpoints: branch
245 Log:
254 Log:
246 ci1
255 ci1
247
256
248 Members:
257 Members:
249 a:1.1->1.2
258 a:1.1->1.2
250
259
251 ---------------------
260 ---------------------
252 PatchSet 6
261 PatchSet 6
253 Date:
262 Date:
254 Author:
263 Author:
255 Branch: HEAD
264 Branch: HEAD
256 Tag: (none)
265 Tag: (none)
257 Log:
266 Log:
258 ci1
267 ci1
259
268
260 Members:
269 Members:
261 b/c:1.2->1.3
270 b/c:1.2->1.3
262
271
263 ---------------------
272 ---------------------
264 PatchSet 7
273 PatchSet 7
265 Date:
274 Date:
266 Author:
275 Author:
267 Branch: branch
276 Branch: branch
268 Tag: (none)
277 Tag: (none)
269 Log:
278 Log:
270 ci2
279 ci2
271
280
272 Members:
281 Members:
273 b/c:1.1->1.1.2.1
282 b/c:1.1->1.1.2.1
274
283
275 ---------------------
284 ---------------------
276 PatchSet 8
285 PatchSet 8
277 Date:
286 Date:
278 Author:
287 Author:
279 Branch: branch
288 Branch: branch
280 Tag: (none)
289 Tag: (none)
281 Log:
290 Log:
282 funny
291 funny
283 ----------------------------
292 ----------------------------
284 log message
293 log message
285
294
286 Members:
295 Members:
287 a:1.2->1.2.2.1
296 a:1.2->1.2.2.1
288
297
298 ---------------------
299 PatchSet 9
300 Date:
301 Author:
302 Branch: branch
303 Tag: (none)
304 Log:
305 fuzzy
306
307 Members:
308 a:1.2.2.1->1.2.2.2
309
310 ---------------------
311 PatchSet 10
312 Date:
313 Author:
314 Branch: branch
315 Tag: (none)
316 Log:
317 fuzzy
318
319 Members:
320 b/c:1.1.2.1->1.1.2.2
321
@@ -1,33 +1,29 b''
1 #!/bin/sh
1 #!/bin/sh
2 # test command parsing and dispatch
2 # test command parsing and dispatch
3
3
4 "$TESTDIR/hghave" no-outer-repo || exit 80
4 "$TESTDIR/hghave" no-outer-repo || exit 80
5
5
6 dir=`pwd`
6 dir=`pwd`
7
7
8 hg init a
8 hg init a
9 cd a
9 cd a
10 echo a > a
10 echo a > a
11 hg ci -Ama
11 hg ci -Ama
12
12
13 echo "# missing arg"
13 echo "# missing arg"
14 hg cat
14 hg cat
15
15
16 echo '% [defaults]'
16 echo '% [defaults]'
17 hg cat a
17 hg cat a
18 cat >> $HGRCPATH <<EOF
18 cat >> $HGRCPATH <<EOF
19 [defaults]
19 [defaults]
20 cat = -r null
20 cat = -r null
21 EOF
21 EOF
22 hg cat a
22 hg cat a
23
23
24 echo '% working directory removed'
25 sh -c "cd $dir && rm -rf a"
26 hg --version 2>&1 | sed -e 's,\(abort:.*:\).*$,\1 ...,g'
27
28 echo '% no repo'
24 echo '% no repo'
29 cd $dir
25 cd $dir
30 hg cat
26 hg cat
31
27
32 exit 0
28 exit 0
33
29
@@ -1,39 +1,37 b''
1 adding a
1 adding a
2 # missing arg
2 # missing arg
3 hg cat: invalid arguments
3 hg cat: invalid arguments
4 hg cat [OPTION]... FILE...
4 hg cat [OPTION]... FILE...
5
5
6 output the current or given revision of files
6 output the current or given revision of files
7
7
8 Print the specified files as they were at the given revision. If no
8 Print the specified files as they were at the given revision. If no
9 revision is given, the parent of the working directory is used, or tip if
9 revision is given, the parent of the working directory is used, or tip if
10 no revision is checked out.
10 no revision is checked out.
11
11
12 Output may be to a file, in which case the name of the file is given using
12 Output may be to a file, in which case the name of the file is given using
13 a format string. The formatting rules are the same as for the export
13 a format string. The formatting rules are the same as for the export
14 command, with the following additions:
14 command, with the following additions:
15
15
16 "%s" basename of file being printed
16 "%s" basename of file being printed
17 "%d" dirname of file being printed, or '.' if in repository root
17 "%d" dirname of file being printed, or '.' if in repository root
18 "%p" root-relative path name of file being printed
18 "%p" root-relative path name of file being printed
19
19
20 Returns 0 on success.
20 Returns 0 on success.
21
21
22 options:
22 options:
23
23
24 -o --output FORMAT print output to file with formatted name
24 -o --output FORMAT print output to file with formatted name
25 -r --rev REV print the given revision
25 -r --rev REV print the given revision
26 --decode apply any matching decode filter
26 --decode apply any matching decode filter
27 -I --include PATTERN [+] include names matching the given patterns
27 -I --include PATTERN [+] include names matching the given patterns
28 -X --exclude PATTERN [+] exclude names matching the given patterns
28 -X --exclude PATTERN [+] exclude names matching the given patterns
29
29
30 [+] marked option can be specified multiple times
30 [+] marked option can be specified multiple times
31
31
32 use "hg -v help cat" to show global options
32 use "hg -v help cat" to show global options
33 % [defaults]
33 % [defaults]
34 a
34 a
35 a: No such file in rev 000000000000
35 a: No such file in rev 000000000000
36 % working directory removed
37 abort: error getting current working directory: ...
38 % no repo
36 % no repo
39 abort: There is no Mercurial repository here (.hg not found)!
37 abort: There is no Mercurial repository here (.hg not found)!
General Comments 0
You need to be logged in to leave comments. Login now