##// END OF EJS Templates
changectx: skip all invalid merge.preferancestor values...
Mads Kiilerich -
r22671:5220c12c default
parent child Browse files
Show More
@@ -1,1709 +1,1710 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, bin
8 from node import nullid, nullrev, short, hex, bin
9 from i18n import _
9 from i18n import _
10 import mdiff, error, util, scmutil, subrepo, patch, encoding, phases
10 import mdiff, error, util, scmutil, subrepo, patch, encoding, phases
11 import match as matchmod
11 import match as matchmod
12 import os, errno, stat
12 import os, errno, stat
13 import obsolete as obsmod
13 import obsolete as obsmod
14 import repoview
14 import repoview
15 import fileset
15 import fileset
16 import revlog
16 import revlog
17
17
18 propertycache = util.propertycache
18 propertycache = util.propertycache
19
19
20 class basectx(object):
20 class basectx(object):
21 """A basectx object represents the common logic for its children:
21 """A basectx object represents the common logic for its children:
22 changectx: read-only context that is already present in the repo,
22 changectx: read-only context that is already present in the repo,
23 workingctx: a context that represents the working directory and can
23 workingctx: a context that represents the working directory and can
24 be committed,
24 be committed,
25 memctx: a context that represents changes in-memory and can also
25 memctx: a context that represents changes in-memory and can also
26 be committed."""
26 be committed."""
27 def __new__(cls, repo, changeid='', *args, **kwargs):
27 def __new__(cls, repo, changeid='', *args, **kwargs):
28 if isinstance(changeid, basectx):
28 if isinstance(changeid, basectx):
29 return changeid
29 return changeid
30
30
31 o = super(basectx, cls).__new__(cls)
31 o = super(basectx, cls).__new__(cls)
32
32
33 o._repo = repo
33 o._repo = repo
34 o._rev = nullrev
34 o._rev = nullrev
35 o._node = nullid
35 o._node = nullid
36
36
37 return o
37 return o
38
38
39 def __str__(self):
39 def __str__(self):
40 return short(self.node())
40 return short(self.node())
41
41
42 def __int__(self):
42 def __int__(self):
43 return self.rev()
43 return self.rev()
44
44
45 def __repr__(self):
45 def __repr__(self):
46 return "<%s %s>" % (type(self).__name__, str(self))
46 return "<%s %s>" % (type(self).__name__, str(self))
47
47
48 def __eq__(self, other):
48 def __eq__(self, other):
49 try:
49 try:
50 return type(self) == type(other) and self._rev == other._rev
50 return type(self) == type(other) and self._rev == other._rev
51 except AttributeError:
51 except AttributeError:
52 return False
52 return False
53
53
54 def __ne__(self, other):
54 def __ne__(self, other):
55 return not (self == other)
55 return not (self == other)
56
56
57 def __contains__(self, key):
57 def __contains__(self, key):
58 return key in self._manifest
58 return key in self._manifest
59
59
60 def __getitem__(self, key):
60 def __getitem__(self, key):
61 return self.filectx(key)
61 return self.filectx(key)
62
62
63 def __iter__(self):
63 def __iter__(self):
64 for f in sorted(self._manifest):
64 for f in sorted(self._manifest):
65 yield f
65 yield f
66
66
67 def _manifestmatches(self, match, s):
67 def _manifestmatches(self, match, s):
68 """generate a new manifest filtered by the match argument
68 """generate a new manifest filtered by the match argument
69
69
70 This method is for internal use only and mainly exists to provide an
70 This method is for internal use only and mainly exists to provide an
71 object oriented way for other contexts to customize the manifest
71 object oriented way for other contexts to customize the manifest
72 generation.
72 generation.
73 """
73 """
74 if match.always():
74 if match.always():
75 return self.manifest().copy()
75 return self.manifest().copy()
76
76
77 files = match.files()
77 files = match.files()
78 if (match.matchfn == match.exact or
78 if (match.matchfn == match.exact or
79 (not match.anypats() and util.all(fn in self for fn in files))):
79 (not match.anypats() and util.all(fn in self for fn in files))):
80 return self.manifest().intersectfiles(files)
80 return self.manifest().intersectfiles(files)
81
81
82 mf = self.manifest().copy()
82 mf = self.manifest().copy()
83 for fn in mf.keys():
83 for fn in mf.keys():
84 if not match(fn):
84 if not match(fn):
85 del mf[fn]
85 del mf[fn]
86 return mf
86 return mf
87
87
88 def _matchstatus(self, other, s, match, listignored, listclean,
88 def _matchstatus(self, other, s, match, listignored, listclean,
89 listunknown):
89 listunknown):
90 """return match.always if match is none
90 """return match.always if match is none
91
91
92 This internal method provides a way for child objects to override the
92 This internal method provides a way for child objects to override the
93 match operator.
93 match operator.
94 """
94 """
95 return match or matchmod.always(self._repo.root, self._repo.getcwd())
95 return match or matchmod.always(self._repo.root, self._repo.getcwd())
96
96
97 def _prestatus(self, other, s, match, listignored, listclean, listunknown):
97 def _prestatus(self, other, s, match, listignored, listclean, listunknown):
98 """provide a hook to allow child objects to preprocess status results
98 """provide a hook to allow child objects to preprocess status results
99
99
100 For example, this allows other contexts, such as workingctx, to query
100 For example, this allows other contexts, such as workingctx, to query
101 the dirstate before comparing the manifests.
101 the dirstate before comparing the manifests.
102 """
102 """
103 # load earliest manifest first for caching reasons
103 # load earliest manifest first for caching reasons
104 if self.rev() < other.rev():
104 if self.rev() < other.rev():
105 self.manifest()
105 self.manifest()
106 return s
106 return s
107
107
108 def _poststatus(self, other, s, match, listignored, listclean, listunknown):
108 def _poststatus(self, other, s, match, listignored, listclean, listunknown):
109 """provide a hook to allow child objects to postprocess status results
109 """provide a hook to allow child objects to postprocess status results
110
110
111 For example, this allows other contexts, such as workingctx, to filter
111 For example, this allows other contexts, such as workingctx, to filter
112 suspect symlinks in the case of FAT32 and NTFS filesytems.
112 suspect symlinks in the case of FAT32 and NTFS filesytems.
113 """
113 """
114 return s
114 return s
115
115
116 def _buildstatus(self, other, s, match, listignored, listclean,
116 def _buildstatus(self, other, s, match, listignored, listclean,
117 listunknown):
117 listunknown):
118 """build a status with respect to another context"""
118 """build a status with respect to another context"""
119 mf1 = other._manifestmatches(match, s)
119 mf1 = other._manifestmatches(match, s)
120 mf2 = self._manifestmatches(match, s)
120 mf2 = self._manifestmatches(match, s)
121
121
122 modified, added, clean = [], [], []
122 modified, added, clean = [], [], []
123 deleted, unknown, ignored = s[3], s[4], s[5]
123 deleted, unknown, ignored = s[3], s[4], s[5]
124 withflags = mf1.withflags() | mf2.withflags()
124 withflags = mf1.withflags() | mf2.withflags()
125 for fn, mf2node in mf2.iteritems():
125 for fn, mf2node in mf2.iteritems():
126 if fn in mf1:
126 if fn in mf1:
127 if (fn not in deleted and
127 if (fn not in deleted and
128 ((fn in withflags and mf1.flags(fn) != mf2.flags(fn)) or
128 ((fn in withflags and mf1.flags(fn) != mf2.flags(fn)) or
129 (mf1[fn] != mf2node and
129 (mf1[fn] != mf2node and
130 (mf2node or self[fn].cmp(other[fn]))))):
130 (mf2node or self[fn].cmp(other[fn]))))):
131 modified.append(fn)
131 modified.append(fn)
132 elif listclean:
132 elif listclean:
133 clean.append(fn)
133 clean.append(fn)
134 del mf1[fn]
134 del mf1[fn]
135 elif fn not in deleted:
135 elif fn not in deleted:
136 added.append(fn)
136 added.append(fn)
137 removed = mf1.keys()
137 removed = mf1.keys()
138 if removed:
138 if removed:
139 # need to filter files if they are already reported as removed
139 # need to filter files if they are already reported as removed
140 unknown = [fn for fn in unknown if fn not in mf1]
140 unknown = [fn for fn in unknown if fn not in mf1]
141 ignored = [fn for fn in ignored if fn not in mf1]
141 ignored = [fn for fn in ignored if fn not in mf1]
142
142
143 return [modified, added, removed, deleted, unknown, ignored, clean]
143 return [modified, added, removed, deleted, unknown, ignored, clean]
144
144
145 @propertycache
145 @propertycache
146 def substate(self):
146 def substate(self):
147 return subrepo.state(self, self._repo.ui)
147 return subrepo.state(self, self._repo.ui)
148
148
149 def subrev(self, subpath):
149 def subrev(self, subpath):
150 return self.substate[subpath][1]
150 return self.substate[subpath][1]
151
151
152 def rev(self):
152 def rev(self):
153 return self._rev
153 return self._rev
154 def node(self):
154 def node(self):
155 return self._node
155 return self._node
156 def hex(self):
156 def hex(self):
157 return hex(self.node())
157 return hex(self.node())
158 def manifest(self):
158 def manifest(self):
159 return self._manifest
159 return self._manifest
160 def phasestr(self):
160 def phasestr(self):
161 return phases.phasenames[self.phase()]
161 return phases.phasenames[self.phase()]
162 def mutable(self):
162 def mutable(self):
163 return self.phase() > phases.public
163 return self.phase() > phases.public
164
164
165 def getfileset(self, expr):
165 def getfileset(self, expr):
166 return fileset.getfileset(self, expr)
166 return fileset.getfileset(self, expr)
167
167
168 def obsolete(self):
168 def obsolete(self):
169 """True if the changeset is obsolete"""
169 """True if the changeset is obsolete"""
170 return self.rev() in obsmod.getrevs(self._repo, 'obsolete')
170 return self.rev() in obsmod.getrevs(self._repo, 'obsolete')
171
171
172 def extinct(self):
172 def extinct(self):
173 """True if the changeset is extinct"""
173 """True if the changeset is extinct"""
174 return self.rev() in obsmod.getrevs(self._repo, 'extinct')
174 return self.rev() in obsmod.getrevs(self._repo, 'extinct')
175
175
176 def unstable(self):
176 def unstable(self):
177 """True if the changeset is not obsolete but it's ancestor are"""
177 """True if the changeset is not obsolete but it's ancestor are"""
178 return self.rev() in obsmod.getrevs(self._repo, 'unstable')
178 return self.rev() in obsmod.getrevs(self._repo, 'unstable')
179
179
180 def bumped(self):
180 def bumped(self):
181 """True if the changeset try to be a successor of a public changeset
181 """True if the changeset try to be a successor of a public changeset
182
182
183 Only non-public and non-obsolete changesets may be bumped.
183 Only non-public and non-obsolete changesets may be bumped.
184 """
184 """
185 return self.rev() in obsmod.getrevs(self._repo, 'bumped')
185 return self.rev() in obsmod.getrevs(self._repo, 'bumped')
186
186
187 def divergent(self):
187 def divergent(self):
188 """Is a successors of a changeset with multiple possible successors set
188 """Is a successors of a changeset with multiple possible successors set
189
189
190 Only non-public and non-obsolete changesets may be divergent.
190 Only non-public and non-obsolete changesets may be divergent.
191 """
191 """
192 return self.rev() in obsmod.getrevs(self._repo, 'divergent')
192 return self.rev() in obsmod.getrevs(self._repo, 'divergent')
193
193
194 def troubled(self):
194 def troubled(self):
195 """True if the changeset is either unstable, bumped or divergent"""
195 """True if the changeset is either unstable, bumped or divergent"""
196 return self.unstable() or self.bumped() or self.divergent()
196 return self.unstable() or self.bumped() or self.divergent()
197
197
198 def troubles(self):
198 def troubles(self):
199 """return the list of troubles affecting this changesets.
199 """return the list of troubles affecting this changesets.
200
200
201 Troubles are returned as strings. possible values are:
201 Troubles are returned as strings. possible values are:
202 - unstable,
202 - unstable,
203 - bumped,
203 - bumped,
204 - divergent.
204 - divergent.
205 """
205 """
206 troubles = []
206 troubles = []
207 if self.unstable():
207 if self.unstable():
208 troubles.append('unstable')
208 troubles.append('unstable')
209 if self.bumped():
209 if self.bumped():
210 troubles.append('bumped')
210 troubles.append('bumped')
211 if self.divergent():
211 if self.divergent():
212 troubles.append('divergent')
212 troubles.append('divergent')
213 return troubles
213 return troubles
214
214
215 def parents(self):
215 def parents(self):
216 """return contexts for each parent changeset"""
216 """return contexts for each parent changeset"""
217 return self._parents
217 return self._parents
218
218
219 def p1(self):
219 def p1(self):
220 return self._parents[0]
220 return self._parents[0]
221
221
222 def p2(self):
222 def p2(self):
223 if len(self._parents) == 2:
223 if len(self._parents) == 2:
224 return self._parents[1]
224 return self._parents[1]
225 return changectx(self._repo, -1)
225 return changectx(self._repo, -1)
226
226
227 def _fileinfo(self, path):
227 def _fileinfo(self, path):
228 if '_manifest' in self.__dict__:
228 if '_manifest' in self.__dict__:
229 try:
229 try:
230 return self._manifest[path], self._manifest.flags(path)
230 return self._manifest[path], self._manifest.flags(path)
231 except KeyError:
231 except KeyError:
232 raise error.ManifestLookupError(self._node, path,
232 raise error.ManifestLookupError(self._node, path,
233 _('not found in manifest'))
233 _('not found in manifest'))
234 if '_manifestdelta' in self.__dict__ or path in self.files():
234 if '_manifestdelta' in self.__dict__ or path in self.files():
235 if path in self._manifestdelta:
235 if path in self._manifestdelta:
236 return (self._manifestdelta[path],
236 return (self._manifestdelta[path],
237 self._manifestdelta.flags(path))
237 self._manifestdelta.flags(path))
238 node, flag = self._repo.manifest.find(self._changeset[0], path)
238 node, flag = self._repo.manifest.find(self._changeset[0], path)
239 if not node:
239 if not node:
240 raise error.ManifestLookupError(self._node, path,
240 raise error.ManifestLookupError(self._node, path,
241 _('not found in manifest'))
241 _('not found in manifest'))
242
242
243 return node, flag
243 return node, flag
244
244
245 def filenode(self, path):
245 def filenode(self, path):
246 return self._fileinfo(path)[0]
246 return self._fileinfo(path)[0]
247
247
248 def flags(self, path):
248 def flags(self, path):
249 try:
249 try:
250 return self._fileinfo(path)[1]
250 return self._fileinfo(path)[1]
251 except error.LookupError:
251 except error.LookupError:
252 return ''
252 return ''
253
253
254 def sub(self, path):
254 def sub(self, path):
255 return subrepo.subrepo(self, path)
255 return subrepo.subrepo(self, path)
256
256
257 def match(self, pats=[], include=None, exclude=None, default='glob'):
257 def match(self, pats=[], include=None, exclude=None, default='glob'):
258 r = self._repo
258 r = self._repo
259 return matchmod.match(r.root, r.getcwd(), pats,
259 return matchmod.match(r.root, r.getcwd(), pats,
260 include, exclude, default,
260 include, exclude, default,
261 auditor=r.auditor, ctx=self)
261 auditor=r.auditor, ctx=self)
262
262
263 def diff(self, ctx2=None, match=None, **opts):
263 def diff(self, ctx2=None, match=None, **opts):
264 """Returns a diff generator for the given contexts and matcher"""
264 """Returns a diff generator for the given contexts and matcher"""
265 if ctx2 is None:
265 if ctx2 is None:
266 ctx2 = self.p1()
266 ctx2 = self.p1()
267 if ctx2 is not None:
267 if ctx2 is not None:
268 ctx2 = self._repo[ctx2]
268 ctx2 = self._repo[ctx2]
269 diffopts = patch.diffopts(self._repo.ui, opts)
269 diffopts = patch.diffopts(self._repo.ui, opts)
270 return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts)
270 return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts)
271
271
272 @propertycache
272 @propertycache
273 def _dirs(self):
273 def _dirs(self):
274 return scmutil.dirs(self._manifest)
274 return scmutil.dirs(self._manifest)
275
275
276 def dirs(self):
276 def dirs(self):
277 return self._dirs
277 return self._dirs
278
278
279 def dirty(self, missing=False, merge=True, branch=True):
279 def dirty(self, missing=False, merge=True, branch=True):
280 return False
280 return False
281
281
282 def status(self, other=None, match=None, listignored=False,
282 def status(self, other=None, match=None, listignored=False,
283 listclean=False, listunknown=False, listsubrepos=False):
283 listclean=False, listunknown=False, listsubrepos=False):
284 """return status of files between two nodes or node and working
284 """return status of files between two nodes or node and working
285 directory.
285 directory.
286
286
287 If other is None, compare this node with working directory.
287 If other is None, compare this node with working directory.
288
288
289 returns (modified, added, removed, deleted, unknown, ignored, clean)
289 returns (modified, added, removed, deleted, unknown, ignored, clean)
290 """
290 """
291
291
292 ctx1 = self
292 ctx1 = self
293 ctx2 = self._repo[other]
293 ctx2 = self._repo[other]
294
294
295 # This next code block is, admittedly, fragile logic that tests for
295 # This next code block is, admittedly, fragile logic that tests for
296 # reversing the contexts and wouldn't need to exist if it weren't for
296 # reversing the contexts and wouldn't need to exist if it weren't for
297 # the fast (and common) code path of comparing the working directory
297 # the fast (and common) code path of comparing the working directory
298 # with its first parent.
298 # with its first parent.
299 #
299 #
300 # What we're aiming for here is the ability to call:
300 # What we're aiming for here is the ability to call:
301 #
301 #
302 # workingctx.status(parentctx)
302 # workingctx.status(parentctx)
303 #
303 #
304 # If we always built the manifest for each context and compared those,
304 # If we always built the manifest for each context and compared those,
305 # then we'd be done. But the special case of the above call means we
305 # then we'd be done. But the special case of the above call means we
306 # just copy the manifest of the parent.
306 # just copy the manifest of the parent.
307 reversed = False
307 reversed = False
308 if (not isinstance(ctx1, changectx)
308 if (not isinstance(ctx1, changectx)
309 and isinstance(ctx2, changectx)):
309 and isinstance(ctx2, changectx)):
310 reversed = True
310 reversed = True
311 ctx1, ctx2 = ctx2, ctx1
311 ctx1, ctx2 = ctx2, ctx1
312
312
313 r = [[], [], [], [], [], [], []]
313 r = [[], [], [], [], [], [], []]
314 match = ctx2._matchstatus(ctx1, r, match, listignored, listclean,
314 match = ctx2._matchstatus(ctx1, r, match, listignored, listclean,
315 listunknown)
315 listunknown)
316 r = ctx2._prestatus(ctx1, r, match, listignored, listclean, listunknown)
316 r = ctx2._prestatus(ctx1, r, match, listignored, listclean, listunknown)
317 r = ctx2._buildstatus(ctx1, r, match, listignored, listclean,
317 r = ctx2._buildstatus(ctx1, r, match, listignored, listclean,
318 listunknown)
318 listunknown)
319 r = ctx2._poststatus(ctx1, r, match, listignored, listclean,
319 r = ctx2._poststatus(ctx1, r, match, listignored, listclean,
320 listunknown)
320 listunknown)
321
321
322 if reversed:
322 if reversed:
323 # reverse added and removed
323 # reverse added and removed
324 r[1], r[2] = r[2], r[1]
324 r[1], r[2] = r[2], r[1]
325
325
326 if listsubrepos:
326 if listsubrepos:
327 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
327 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
328 rev2 = ctx2.subrev(subpath)
328 rev2 = ctx2.subrev(subpath)
329 try:
329 try:
330 submatch = matchmod.narrowmatcher(subpath, match)
330 submatch = matchmod.narrowmatcher(subpath, match)
331 s = sub.status(rev2, match=submatch, ignored=listignored,
331 s = sub.status(rev2, match=submatch, ignored=listignored,
332 clean=listclean, unknown=listunknown,
332 clean=listclean, unknown=listunknown,
333 listsubrepos=True)
333 listsubrepos=True)
334 for rfiles, sfiles in zip(r, s):
334 for rfiles, sfiles in zip(r, s):
335 rfiles.extend("%s/%s" % (subpath, f) for f in sfiles)
335 rfiles.extend("%s/%s" % (subpath, f) for f in sfiles)
336 except error.LookupError:
336 except error.LookupError:
337 self._repo.ui.status(_("skipping missing "
337 self._repo.ui.status(_("skipping missing "
338 "subrepository: %s\n") % subpath)
338 "subrepository: %s\n") % subpath)
339
339
340 for l in r:
340 for l in r:
341 l.sort()
341 l.sort()
342
342
343 # we return a tuple to signify that this list isn't changing
343 # we return a tuple to signify that this list isn't changing
344 return tuple(r)
344 return tuple(r)
345
345
346
346
347 def makememctx(repo, parents, text, user, date, branch, files, store,
347 def makememctx(repo, parents, text, user, date, branch, files, store,
348 editor=None):
348 editor=None):
349 def getfilectx(repo, memctx, path):
349 def getfilectx(repo, memctx, path):
350 data, mode, copied = store.getfile(path)
350 data, mode, copied = store.getfile(path)
351 if data is None:
351 if data is None:
352 return None
352 return None
353 islink, isexec = mode
353 islink, isexec = mode
354 return memfilectx(repo, path, data, islink=islink, isexec=isexec,
354 return memfilectx(repo, path, data, islink=islink, isexec=isexec,
355 copied=copied, memctx=memctx)
355 copied=copied, memctx=memctx)
356 extra = {}
356 extra = {}
357 if branch:
357 if branch:
358 extra['branch'] = encoding.fromlocal(branch)
358 extra['branch'] = encoding.fromlocal(branch)
359 ctx = memctx(repo, parents, text, files, getfilectx, user,
359 ctx = memctx(repo, parents, text, files, getfilectx, user,
360 date, extra, editor)
360 date, extra, editor)
361 return ctx
361 return ctx
362
362
363 class changectx(basectx):
363 class changectx(basectx):
364 """A changecontext object makes access to data related to a particular
364 """A changecontext object makes access to data related to a particular
365 changeset convenient. It represents a read-only context already present in
365 changeset convenient. It represents a read-only context already present in
366 the repo."""
366 the repo."""
367 def __init__(self, repo, changeid=''):
367 def __init__(self, repo, changeid=''):
368 """changeid is a revision number, node, or tag"""
368 """changeid is a revision number, node, or tag"""
369
369
370 # since basectx.__new__ already took care of copying the object, we
370 # since basectx.__new__ already took care of copying the object, we
371 # don't need to do anything in __init__, so we just exit here
371 # don't need to do anything in __init__, so we just exit here
372 if isinstance(changeid, basectx):
372 if isinstance(changeid, basectx):
373 return
373 return
374
374
375 if changeid == '':
375 if changeid == '':
376 changeid = '.'
376 changeid = '.'
377 self._repo = repo
377 self._repo = repo
378
378
379 if isinstance(changeid, int):
379 if isinstance(changeid, int):
380 try:
380 try:
381 self._node = repo.changelog.node(changeid)
381 self._node = repo.changelog.node(changeid)
382 except IndexError:
382 except IndexError:
383 raise error.RepoLookupError(
383 raise error.RepoLookupError(
384 _("unknown revision '%s'") % changeid)
384 _("unknown revision '%s'") % changeid)
385 self._rev = changeid
385 self._rev = changeid
386 return
386 return
387 if isinstance(changeid, long):
387 if isinstance(changeid, long):
388 changeid = str(changeid)
388 changeid = str(changeid)
389 if changeid == '.':
389 if changeid == '.':
390 self._node = repo.dirstate.p1()
390 self._node = repo.dirstate.p1()
391 self._rev = repo.changelog.rev(self._node)
391 self._rev = repo.changelog.rev(self._node)
392 return
392 return
393 if changeid == 'null':
393 if changeid == 'null':
394 self._node = nullid
394 self._node = nullid
395 self._rev = nullrev
395 self._rev = nullrev
396 return
396 return
397 if changeid == 'tip':
397 if changeid == 'tip':
398 self._node = repo.changelog.tip()
398 self._node = repo.changelog.tip()
399 self._rev = repo.changelog.rev(self._node)
399 self._rev = repo.changelog.rev(self._node)
400 return
400 return
401 if len(changeid) == 20:
401 if len(changeid) == 20:
402 try:
402 try:
403 self._node = changeid
403 self._node = changeid
404 self._rev = repo.changelog.rev(changeid)
404 self._rev = repo.changelog.rev(changeid)
405 return
405 return
406 except LookupError:
406 except LookupError:
407 pass
407 pass
408
408
409 try:
409 try:
410 r = int(changeid)
410 r = int(changeid)
411 if str(r) != changeid:
411 if str(r) != changeid:
412 raise ValueError
412 raise ValueError
413 l = len(repo.changelog)
413 l = len(repo.changelog)
414 if r < 0:
414 if r < 0:
415 r += l
415 r += l
416 if r < 0 or r >= l:
416 if r < 0 or r >= l:
417 raise ValueError
417 raise ValueError
418 self._rev = r
418 self._rev = r
419 self._node = repo.changelog.node(r)
419 self._node = repo.changelog.node(r)
420 return
420 return
421 except (ValueError, OverflowError, IndexError):
421 except (ValueError, OverflowError, IndexError):
422 pass
422 pass
423
423
424 if len(changeid) == 40:
424 if len(changeid) == 40:
425 try:
425 try:
426 self._node = bin(changeid)
426 self._node = bin(changeid)
427 self._rev = repo.changelog.rev(self._node)
427 self._rev = repo.changelog.rev(self._node)
428 return
428 return
429 except (TypeError, LookupError):
429 except (TypeError, LookupError):
430 pass
430 pass
431
431
432 if changeid in repo._bookmarks:
432 if changeid in repo._bookmarks:
433 self._node = repo._bookmarks[changeid]
433 self._node = repo._bookmarks[changeid]
434 self._rev = repo.changelog.rev(self._node)
434 self._rev = repo.changelog.rev(self._node)
435 return
435 return
436 if changeid in repo._tagscache.tags:
436 if changeid in repo._tagscache.tags:
437 self._node = repo._tagscache.tags[changeid]
437 self._node = repo._tagscache.tags[changeid]
438 self._rev = repo.changelog.rev(self._node)
438 self._rev = repo.changelog.rev(self._node)
439 return
439 return
440 try:
440 try:
441 self._node = repo.branchtip(changeid)
441 self._node = repo.branchtip(changeid)
442 self._rev = repo.changelog.rev(self._node)
442 self._rev = repo.changelog.rev(self._node)
443 return
443 return
444 except error.RepoLookupError:
444 except error.RepoLookupError:
445 pass
445 pass
446
446
447 self._node = repo.changelog._partialmatch(changeid)
447 self._node = repo.changelog._partialmatch(changeid)
448 if self._node is not None:
448 if self._node is not None:
449 self._rev = repo.changelog.rev(self._node)
449 self._rev = repo.changelog.rev(self._node)
450 return
450 return
451
451
452 # lookup failed
452 # lookup failed
453 # check if it might have come from damaged dirstate
453 # check if it might have come from damaged dirstate
454 #
454 #
455 # XXX we could avoid the unfiltered if we had a recognizable exception
455 # XXX we could avoid the unfiltered if we had a recognizable exception
456 # for filtered changeset access
456 # for filtered changeset access
457 if changeid in repo.unfiltered().dirstate.parents():
457 if changeid in repo.unfiltered().dirstate.parents():
458 raise error.Abort(_("working directory has unknown parent '%s'!")
458 raise error.Abort(_("working directory has unknown parent '%s'!")
459 % short(changeid))
459 % short(changeid))
460 try:
460 try:
461 if len(changeid) == 20:
461 if len(changeid) == 20:
462 changeid = hex(changeid)
462 changeid = hex(changeid)
463 except TypeError:
463 except TypeError:
464 pass
464 pass
465 raise error.RepoLookupError(
465 raise error.RepoLookupError(
466 _("unknown revision '%s'") % changeid)
466 _("unknown revision '%s'") % changeid)
467
467
468 def __hash__(self):
468 def __hash__(self):
469 try:
469 try:
470 return hash(self._rev)
470 return hash(self._rev)
471 except AttributeError:
471 except AttributeError:
472 return id(self)
472 return id(self)
473
473
474 def __nonzero__(self):
474 def __nonzero__(self):
475 return self._rev != nullrev
475 return self._rev != nullrev
476
476
477 @propertycache
477 @propertycache
478 def _changeset(self):
478 def _changeset(self):
479 return self._repo.changelog.read(self.rev())
479 return self._repo.changelog.read(self.rev())
480
480
481 @propertycache
481 @propertycache
482 def _manifest(self):
482 def _manifest(self):
483 return self._repo.manifest.read(self._changeset[0])
483 return self._repo.manifest.read(self._changeset[0])
484
484
485 @propertycache
485 @propertycache
486 def _manifestdelta(self):
486 def _manifestdelta(self):
487 return self._repo.manifest.readdelta(self._changeset[0])
487 return self._repo.manifest.readdelta(self._changeset[0])
488
488
489 @propertycache
489 @propertycache
490 def _parents(self):
490 def _parents(self):
491 p = self._repo.changelog.parentrevs(self._rev)
491 p = self._repo.changelog.parentrevs(self._rev)
492 if p[1] == nullrev:
492 if p[1] == nullrev:
493 p = p[:-1]
493 p = p[:-1]
494 return [changectx(self._repo, x) for x in p]
494 return [changectx(self._repo, x) for x in p]
495
495
496 def changeset(self):
496 def changeset(self):
497 return self._changeset
497 return self._changeset
498 def manifestnode(self):
498 def manifestnode(self):
499 return self._changeset[0]
499 return self._changeset[0]
500
500
501 def user(self):
501 def user(self):
502 return self._changeset[1]
502 return self._changeset[1]
503 def date(self):
503 def date(self):
504 return self._changeset[2]
504 return self._changeset[2]
505 def files(self):
505 def files(self):
506 return self._changeset[3]
506 return self._changeset[3]
507 def description(self):
507 def description(self):
508 return self._changeset[4]
508 return self._changeset[4]
509 def branch(self):
509 def branch(self):
510 return encoding.tolocal(self._changeset[5].get("branch"))
510 return encoding.tolocal(self._changeset[5].get("branch"))
511 def closesbranch(self):
511 def closesbranch(self):
512 return 'close' in self._changeset[5]
512 return 'close' in self._changeset[5]
513 def extra(self):
513 def extra(self):
514 return self._changeset[5]
514 return self._changeset[5]
515 def tags(self):
515 def tags(self):
516 return self._repo.nodetags(self._node)
516 return self._repo.nodetags(self._node)
517 def bookmarks(self):
517 def bookmarks(self):
518 return self._repo.nodebookmarks(self._node)
518 return self._repo.nodebookmarks(self._node)
519 def phase(self):
519 def phase(self):
520 return self._repo._phasecache.phase(self._repo, self._rev)
520 return self._repo._phasecache.phase(self._repo, self._rev)
521 def hidden(self):
521 def hidden(self):
522 return self._rev in repoview.filterrevs(self._repo, 'visible')
522 return self._rev in repoview.filterrevs(self._repo, 'visible')
523
523
524 def children(self):
524 def children(self):
525 """return contexts for each child changeset"""
525 """return contexts for each child changeset"""
526 c = self._repo.changelog.children(self._node)
526 c = self._repo.changelog.children(self._node)
527 return [changectx(self._repo, x) for x in c]
527 return [changectx(self._repo, x) for x in c]
528
528
529 def ancestors(self):
529 def ancestors(self):
530 for a in self._repo.changelog.ancestors([self._rev]):
530 for a in self._repo.changelog.ancestors([self._rev]):
531 yield changectx(self._repo, a)
531 yield changectx(self._repo, a)
532
532
533 def descendants(self):
533 def descendants(self):
534 for d in self._repo.changelog.descendants([self._rev]):
534 for d in self._repo.changelog.descendants([self._rev]):
535 yield changectx(self._repo, d)
535 yield changectx(self._repo, d)
536
536
537 def filectx(self, path, fileid=None, filelog=None):
537 def filectx(self, path, fileid=None, filelog=None):
538 """get a file context from this changeset"""
538 """get a file context from this changeset"""
539 if fileid is None:
539 if fileid is None:
540 fileid = self.filenode(path)
540 fileid = self.filenode(path)
541 return filectx(self._repo, path, fileid=fileid,
541 return filectx(self._repo, path, fileid=fileid,
542 changectx=self, filelog=filelog)
542 changectx=self, filelog=filelog)
543
543
544 def ancestor(self, c2, warn=False):
544 def ancestor(self, c2, warn=False):
545 """return the "best" ancestor context of self and c2
545 """return the "best" ancestor context of self and c2
546
546
547 If there are multiple candidates, it will show a message and check
547 If there are multiple candidates, it will show a message and check
548 merge.preferancestor configuration before falling back to the
548 merge.preferancestor configuration before falling back to the
549 revlog ancestor."""
549 revlog ancestor."""
550 # deal with workingctxs
550 # deal with workingctxs
551 n2 = c2._node
551 n2 = c2._node
552 if n2 is None:
552 if n2 is None:
553 n2 = c2._parents[0]._node
553 n2 = c2._parents[0]._node
554 cahs = self._repo.changelog.commonancestorsheads(self._node, n2)
554 cahs = self._repo.changelog.commonancestorsheads(self._node, n2)
555 if not cahs:
555 if not cahs:
556 anc = nullid
556 anc = nullid
557 elif len(cahs) == 1:
557 elif len(cahs) == 1:
558 anc = cahs[0]
558 anc = cahs[0]
559 else:
559 else:
560 for r in self._repo.ui.configlist('merge', 'preferancestor'):
560 for r in self._repo.ui.configlist('merge', 'preferancestor'):
561 if r == '*':
561 try:
562 ctx = changectx(self._repo, r)
563 except error.RepoLookupError:
562 continue
564 continue
563 ctx = changectx(self._repo, r)
564 anc = ctx.node()
565 anc = ctx.node()
565 if anc in cahs:
566 if anc in cahs:
566 break
567 break
567 else:
568 else:
568 anc = self._repo.changelog.ancestor(self._node, n2)
569 anc = self._repo.changelog.ancestor(self._node, n2)
569 if warn:
570 if warn:
570 self._repo.ui.status(
571 self._repo.ui.status(
571 (_("note: using %s as ancestor of %s and %s\n") %
572 (_("note: using %s as ancestor of %s and %s\n") %
572 (short(anc), short(self._node), short(n2))) +
573 (short(anc), short(self._node), short(n2))) +
573 ''.join(_(" alternatively, use --config "
574 ''.join(_(" alternatively, use --config "
574 "merge.preferancestor=%s\n") %
575 "merge.preferancestor=%s\n") %
575 short(n) for n in sorted(cahs) if n != anc))
576 short(n) for n in sorted(cahs) if n != anc))
576 return changectx(self._repo, anc)
577 return changectx(self._repo, anc)
577
578
578 def descendant(self, other):
579 def descendant(self, other):
579 """True if other is descendant of this changeset"""
580 """True if other is descendant of this changeset"""
580 return self._repo.changelog.descendant(self._rev, other._rev)
581 return self._repo.changelog.descendant(self._rev, other._rev)
581
582
582 def walk(self, match):
583 def walk(self, match):
583 fset = set(match.files())
584 fset = set(match.files())
584 # for dirstate.walk, files=['.'] means "walk the whole tree".
585 # for dirstate.walk, files=['.'] means "walk the whole tree".
585 # follow that here, too
586 # follow that here, too
586 fset.discard('.')
587 fset.discard('.')
587
588
588 # avoid the entire walk if we're only looking for specific files
589 # avoid the entire walk if we're only looking for specific files
589 if fset and not match.anypats():
590 if fset and not match.anypats():
590 if util.all([fn in self for fn in fset]):
591 if util.all([fn in self for fn in fset]):
591 for fn in sorted(fset):
592 for fn in sorted(fset):
592 if match(fn):
593 if match(fn):
593 yield fn
594 yield fn
594 raise StopIteration
595 raise StopIteration
595
596
596 for fn in self:
597 for fn in self:
597 if fn in fset:
598 if fn in fset:
598 # specified pattern is the exact name
599 # specified pattern is the exact name
599 fset.remove(fn)
600 fset.remove(fn)
600 if match(fn):
601 if match(fn):
601 yield fn
602 yield fn
602 for fn in sorted(fset):
603 for fn in sorted(fset):
603 if fn in self._dirs:
604 if fn in self._dirs:
604 # specified pattern is a directory
605 # specified pattern is a directory
605 continue
606 continue
606 match.bad(fn, _('no such file in rev %s') % self)
607 match.bad(fn, _('no such file in rev %s') % self)
607
608
608 def matches(self, match):
609 def matches(self, match):
609 return self.walk(match)
610 return self.walk(match)
610
611
611 class basefilectx(object):
612 class basefilectx(object):
612 """A filecontext object represents the common logic for its children:
613 """A filecontext object represents the common logic for its children:
613 filectx: read-only access to a filerevision that is already present
614 filectx: read-only access to a filerevision that is already present
614 in the repo,
615 in the repo,
615 workingfilectx: a filecontext that represents files from the working
616 workingfilectx: a filecontext that represents files from the working
616 directory,
617 directory,
617 memfilectx: a filecontext that represents files in-memory."""
618 memfilectx: a filecontext that represents files in-memory."""
618 def __new__(cls, repo, path, *args, **kwargs):
619 def __new__(cls, repo, path, *args, **kwargs):
619 return super(basefilectx, cls).__new__(cls)
620 return super(basefilectx, cls).__new__(cls)
620
621
621 @propertycache
622 @propertycache
622 def _filelog(self):
623 def _filelog(self):
623 return self._repo.file(self._path)
624 return self._repo.file(self._path)
624
625
625 @propertycache
626 @propertycache
626 def _changeid(self):
627 def _changeid(self):
627 if '_changeid' in self.__dict__:
628 if '_changeid' in self.__dict__:
628 return self._changeid
629 return self._changeid
629 elif '_changectx' in self.__dict__:
630 elif '_changectx' in self.__dict__:
630 return self._changectx.rev()
631 return self._changectx.rev()
631 else:
632 else:
632 return self._filelog.linkrev(self._filerev)
633 return self._filelog.linkrev(self._filerev)
633
634
634 @propertycache
635 @propertycache
635 def _filenode(self):
636 def _filenode(self):
636 if '_fileid' in self.__dict__:
637 if '_fileid' in self.__dict__:
637 return self._filelog.lookup(self._fileid)
638 return self._filelog.lookup(self._fileid)
638 else:
639 else:
639 return self._changectx.filenode(self._path)
640 return self._changectx.filenode(self._path)
640
641
641 @propertycache
642 @propertycache
642 def _filerev(self):
643 def _filerev(self):
643 return self._filelog.rev(self._filenode)
644 return self._filelog.rev(self._filenode)
644
645
645 @propertycache
646 @propertycache
646 def _repopath(self):
647 def _repopath(self):
647 return self._path
648 return self._path
648
649
649 def __nonzero__(self):
650 def __nonzero__(self):
650 try:
651 try:
651 self._filenode
652 self._filenode
652 return True
653 return True
653 except error.LookupError:
654 except error.LookupError:
654 # file is missing
655 # file is missing
655 return False
656 return False
656
657
657 def __str__(self):
658 def __str__(self):
658 return "%s@%s" % (self.path(), self._changectx)
659 return "%s@%s" % (self.path(), self._changectx)
659
660
660 def __repr__(self):
661 def __repr__(self):
661 return "<%s %s>" % (type(self).__name__, str(self))
662 return "<%s %s>" % (type(self).__name__, str(self))
662
663
663 def __hash__(self):
664 def __hash__(self):
664 try:
665 try:
665 return hash((self._path, self._filenode))
666 return hash((self._path, self._filenode))
666 except AttributeError:
667 except AttributeError:
667 return id(self)
668 return id(self)
668
669
669 def __eq__(self, other):
670 def __eq__(self, other):
670 try:
671 try:
671 return (type(self) == type(other) and self._path == other._path
672 return (type(self) == type(other) and self._path == other._path
672 and self._filenode == other._filenode)
673 and self._filenode == other._filenode)
673 except AttributeError:
674 except AttributeError:
674 return False
675 return False
675
676
676 def __ne__(self, other):
677 def __ne__(self, other):
677 return not (self == other)
678 return not (self == other)
678
679
679 def filerev(self):
680 def filerev(self):
680 return self._filerev
681 return self._filerev
681 def filenode(self):
682 def filenode(self):
682 return self._filenode
683 return self._filenode
683 def flags(self):
684 def flags(self):
684 return self._changectx.flags(self._path)
685 return self._changectx.flags(self._path)
685 def filelog(self):
686 def filelog(self):
686 return self._filelog
687 return self._filelog
687 def rev(self):
688 def rev(self):
688 return self._changeid
689 return self._changeid
689 def linkrev(self):
690 def linkrev(self):
690 return self._filelog.linkrev(self._filerev)
691 return self._filelog.linkrev(self._filerev)
691 def node(self):
692 def node(self):
692 return self._changectx.node()
693 return self._changectx.node()
693 def hex(self):
694 def hex(self):
694 return self._changectx.hex()
695 return self._changectx.hex()
695 def user(self):
696 def user(self):
696 return self._changectx.user()
697 return self._changectx.user()
697 def date(self):
698 def date(self):
698 return self._changectx.date()
699 return self._changectx.date()
699 def files(self):
700 def files(self):
700 return self._changectx.files()
701 return self._changectx.files()
701 def description(self):
702 def description(self):
702 return self._changectx.description()
703 return self._changectx.description()
703 def branch(self):
704 def branch(self):
704 return self._changectx.branch()
705 return self._changectx.branch()
705 def extra(self):
706 def extra(self):
706 return self._changectx.extra()
707 return self._changectx.extra()
707 def phase(self):
708 def phase(self):
708 return self._changectx.phase()
709 return self._changectx.phase()
709 def phasestr(self):
710 def phasestr(self):
710 return self._changectx.phasestr()
711 return self._changectx.phasestr()
711 def manifest(self):
712 def manifest(self):
712 return self._changectx.manifest()
713 return self._changectx.manifest()
713 def changectx(self):
714 def changectx(self):
714 return self._changectx
715 return self._changectx
715
716
716 def path(self):
717 def path(self):
717 return self._path
718 return self._path
718
719
719 def isbinary(self):
720 def isbinary(self):
720 try:
721 try:
721 return util.binary(self.data())
722 return util.binary(self.data())
722 except IOError:
723 except IOError:
723 return False
724 return False
724 def isexec(self):
725 def isexec(self):
725 return 'x' in self.flags()
726 return 'x' in self.flags()
726 def islink(self):
727 def islink(self):
727 return 'l' in self.flags()
728 return 'l' in self.flags()
728
729
729 def cmp(self, fctx):
730 def cmp(self, fctx):
730 """compare with other file context
731 """compare with other file context
731
732
732 returns True if different than fctx.
733 returns True if different than fctx.
733 """
734 """
734 if (fctx._filerev is None
735 if (fctx._filerev is None
735 and (self._repo._encodefilterpats
736 and (self._repo._encodefilterpats
736 # if file data starts with '\1\n', empty metadata block is
737 # if file data starts with '\1\n', empty metadata block is
737 # prepended, which adds 4 bytes to filelog.size().
738 # prepended, which adds 4 bytes to filelog.size().
738 or self.size() - 4 == fctx.size())
739 or self.size() - 4 == fctx.size())
739 or self.size() == fctx.size()):
740 or self.size() == fctx.size()):
740 return self._filelog.cmp(self._filenode, fctx.data())
741 return self._filelog.cmp(self._filenode, fctx.data())
741
742
742 return True
743 return True
743
744
744 def parents(self):
745 def parents(self):
745 _path = self._path
746 _path = self._path
746 fl = self._filelog
747 fl = self._filelog
747 pl = [(_path, n, fl) for n in self._filelog.parents(self._filenode)]
748 pl = [(_path, n, fl) for n in self._filelog.parents(self._filenode)]
748
749
749 r = self._filelog.renamed(self._filenode)
750 r = self._filelog.renamed(self._filenode)
750 if r:
751 if r:
751 pl[0] = (r[0], r[1], None)
752 pl[0] = (r[0], r[1], None)
752
753
753 return [filectx(self._repo, p, fileid=n, filelog=l)
754 return [filectx(self._repo, p, fileid=n, filelog=l)
754 for p, n, l in pl if n != nullid]
755 for p, n, l in pl if n != nullid]
755
756
756 def p1(self):
757 def p1(self):
757 return self.parents()[0]
758 return self.parents()[0]
758
759
759 def p2(self):
760 def p2(self):
760 p = self.parents()
761 p = self.parents()
761 if len(p) == 2:
762 if len(p) == 2:
762 return p[1]
763 return p[1]
763 return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
764 return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
764
765
765 def annotate(self, follow=False, linenumber=None, diffopts=None):
766 def annotate(self, follow=False, linenumber=None, diffopts=None):
766 '''returns a list of tuples of (ctx, line) for each line
767 '''returns a list of tuples of (ctx, line) for each line
767 in the file, where ctx is the filectx of the node where
768 in the file, where ctx is the filectx of the node where
768 that line was last changed.
769 that line was last changed.
769 This returns tuples of ((ctx, linenumber), line) for each line,
770 This returns tuples of ((ctx, linenumber), line) for each line,
770 if "linenumber" parameter is NOT "None".
771 if "linenumber" parameter is NOT "None".
771 In such tuples, linenumber means one at the first appearance
772 In such tuples, linenumber means one at the first appearance
772 in the managed file.
773 in the managed file.
773 To reduce annotation cost,
774 To reduce annotation cost,
774 this returns fixed value(False is used) as linenumber,
775 this returns fixed value(False is used) as linenumber,
775 if "linenumber" parameter is "False".'''
776 if "linenumber" parameter is "False".'''
776
777
777 if linenumber is None:
778 if linenumber is None:
778 def decorate(text, rev):
779 def decorate(text, rev):
779 return ([rev] * len(text.splitlines()), text)
780 return ([rev] * len(text.splitlines()), text)
780 elif linenumber:
781 elif linenumber:
781 def decorate(text, rev):
782 def decorate(text, rev):
782 size = len(text.splitlines())
783 size = len(text.splitlines())
783 return ([(rev, i) for i in xrange(1, size + 1)], text)
784 return ([(rev, i) for i in xrange(1, size + 1)], text)
784 else:
785 else:
785 def decorate(text, rev):
786 def decorate(text, rev):
786 return ([(rev, False)] * len(text.splitlines()), text)
787 return ([(rev, False)] * len(text.splitlines()), text)
787
788
788 def pair(parent, child):
789 def pair(parent, child):
789 blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts,
790 blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts,
790 refine=True)
791 refine=True)
791 for (a1, a2, b1, b2), t in blocks:
792 for (a1, a2, b1, b2), t in blocks:
792 # Changed blocks ('!') or blocks made only of blank lines ('~')
793 # Changed blocks ('!') or blocks made only of blank lines ('~')
793 # belong to the child.
794 # belong to the child.
794 if t == '=':
795 if t == '=':
795 child[0][b1:b2] = parent[0][a1:a2]
796 child[0][b1:b2] = parent[0][a1:a2]
796 return child
797 return child
797
798
798 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
799 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
799
800
800 def parents(f):
801 def parents(f):
801 pl = f.parents()
802 pl = f.parents()
802
803
803 # Don't return renamed parents if we aren't following.
804 # Don't return renamed parents if we aren't following.
804 if not follow:
805 if not follow:
805 pl = [p for p in pl if p.path() == f.path()]
806 pl = [p for p in pl if p.path() == f.path()]
806
807
807 # renamed filectx won't have a filelog yet, so set it
808 # renamed filectx won't have a filelog yet, so set it
808 # from the cache to save time
809 # from the cache to save time
809 for p in pl:
810 for p in pl:
810 if not '_filelog' in p.__dict__:
811 if not '_filelog' in p.__dict__:
811 p._filelog = getlog(p.path())
812 p._filelog = getlog(p.path())
812
813
813 return pl
814 return pl
814
815
815 # use linkrev to find the first changeset where self appeared
816 # use linkrev to find the first changeset where self appeared
816 if self.rev() != self.linkrev():
817 if self.rev() != self.linkrev():
817 base = self.filectx(self.filenode())
818 base = self.filectx(self.filenode())
818 else:
819 else:
819 base = self
820 base = self
820
821
821 # This algorithm would prefer to be recursive, but Python is a
822 # This algorithm would prefer to be recursive, but Python is a
822 # bit recursion-hostile. Instead we do an iterative
823 # bit recursion-hostile. Instead we do an iterative
823 # depth-first search.
824 # depth-first search.
824
825
825 visit = [base]
826 visit = [base]
826 hist = {}
827 hist = {}
827 pcache = {}
828 pcache = {}
828 needed = {base: 1}
829 needed = {base: 1}
829 while visit:
830 while visit:
830 f = visit[-1]
831 f = visit[-1]
831 pcached = f in pcache
832 pcached = f in pcache
832 if not pcached:
833 if not pcached:
833 pcache[f] = parents(f)
834 pcache[f] = parents(f)
834
835
835 ready = True
836 ready = True
836 pl = pcache[f]
837 pl = pcache[f]
837 for p in pl:
838 for p in pl:
838 if p not in hist:
839 if p not in hist:
839 ready = False
840 ready = False
840 visit.append(p)
841 visit.append(p)
841 if not pcached:
842 if not pcached:
842 needed[p] = needed.get(p, 0) + 1
843 needed[p] = needed.get(p, 0) + 1
843 if ready:
844 if ready:
844 visit.pop()
845 visit.pop()
845 reusable = f in hist
846 reusable = f in hist
846 if reusable:
847 if reusable:
847 curr = hist[f]
848 curr = hist[f]
848 else:
849 else:
849 curr = decorate(f.data(), f)
850 curr = decorate(f.data(), f)
850 for p in pl:
851 for p in pl:
851 if not reusable:
852 if not reusable:
852 curr = pair(hist[p], curr)
853 curr = pair(hist[p], curr)
853 if needed[p] == 1:
854 if needed[p] == 1:
854 del hist[p]
855 del hist[p]
855 del needed[p]
856 del needed[p]
856 else:
857 else:
857 needed[p] -= 1
858 needed[p] -= 1
858
859
859 hist[f] = curr
860 hist[f] = curr
860 pcache[f] = []
861 pcache[f] = []
861
862
862 return zip(hist[base][0], hist[base][1].splitlines(True))
863 return zip(hist[base][0], hist[base][1].splitlines(True))
863
864
864 def ancestors(self, followfirst=False):
865 def ancestors(self, followfirst=False):
865 visit = {}
866 visit = {}
866 c = self
867 c = self
867 cut = followfirst and 1 or None
868 cut = followfirst and 1 or None
868 while True:
869 while True:
869 for parent in c.parents()[:cut]:
870 for parent in c.parents()[:cut]:
870 visit[(parent.rev(), parent.node())] = parent
871 visit[(parent.rev(), parent.node())] = parent
871 if not visit:
872 if not visit:
872 break
873 break
873 c = visit.pop(max(visit))
874 c = visit.pop(max(visit))
874 yield c
875 yield c
875
876
876 class filectx(basefilectx):
877 class filectx(basefilectx):
877 """A filecontext object makes access to data related to a particular
878 """A filecontext object makes access to data related to a particular
878 filerevision convenient."""
879 filerevision convenient."""
879 def __init__(self, repo, path, changeid=None, fileid=None,
880 def __init__(self, repo, path, changeid=None, fileid=None,
880 filelog=None, changectx=None):
881 filelog=None, changectx=None):
881 """changeid can be a changeset revision, node, or tag.
882 """changeid can be a changeset revision, node, or tag.
882 fileid can be a file revision or node."""
883 fileid can be a file revision or node."""
883 self._repo = repo
884 self._repo = repo
884 self._path = path
885 self._path = path
885
886
886 assert (changeid is not None
887 assert (changeid is not None
887 or fileid is not None
888 or fileid is not None
888 or changectx is not None), \
889 or changectx is not None), \
889 ("bad args: changeid=%r, fileid=%r, changectx=%r"
890 ("bad args: changeid=%r, fileid=%r, changectx=%r"
890 % (changeid, fileid, changectx))
891 % (changeid, fileid, changectx))
891
892
892 if filelog is not None:
893 if filelog is not None:
893 self._filelog = filelog
894 self._filelog = filelog
894
895
895 if changeid is not None:
896 if changeid is not None:
896 self._changeid = changeid
897 self._changeid = changeid
897 if changectx is not None:
898 if changectx is not None:
898 self._changectx = changectx
899 self._changectx = changectx
899 if fileid is not None:
900 if fileid is not None:
900 self._fileid = fileid
901 self._fileid = fileid
901
902
902 @propertycache
903 @propertycache
903 def _changectx(self):
904 def _changectx(self):
904 try:
905 try:
905 return changectx(self._repo, self._changeid)
906 return changectx(self._repo, self._changeid)
906 except error.RepoLookupError:
907 except error.RepoLookupError:
907 # Linkrev may point to any revision in the repository. When the
908 # Linkrev may point to any revision in the repository. When the
908 # repository is filtered this may lead to `filectx` trying to build
909 # repository is filtered this may lead to `filectx` trying to build
909 # `changectx` for filtered revision. In such case we fallback to
910 # `changectx` for filtered revision. In such case we fallback to
910 # creating `changectx` on the unfiltered version of the reposition.
911 # creating `changectx` on the unfiltered version of the reposition.
911 # This fallback should not be an issue because `changectx` from
912 # This fallback should not be an issue because `changectx` from
912 # `filectx` are not used in complex operations that care about
913 # `filectx` are not used in complex operations that care about
913 # filtering.
914 # filtering.
914 #
915 #
915 # This fallback is a cheap and dirty fix that prevent several
916 # This fallback is a cheap and dirty fix that prevent several
916 # crashes. It does not ensure the behavior is correct. However the
917 # crashes. It does not ensure the behavior is correct. However the
917 # behavior was not correct before filtering either and "incorrect
918 # behavior was not correct before filtering either and "incorrect
918 # behavior" is seen as better as "crash"
919 # behavior" is seen as better as "crash"
919 #
920 #
920 # Linkrevs have several serious troubles with filtering that are
921 # Linkrevs have several serious troubles with filtering that are
921 # complicated to solve. Proper handling of the issue here should be
922 # complicated to solve. Proper handling of the issue here should be
922 # considered when solving linkrev issue are on the table.
923 # considered when solving linkrev issue are on the table.
923 return changectx(self._repo.unfiltered(), self._changeid)
924 return changectx(self._repo.unfiltered(), self._changeid)
924
925
925 def filectx(self, fileid):
926 def filectx(self, fileid):
926 '''opens an arbitrary revision of the file without
927 '''opens an arbitrary revision of the file without
927 opening a new filelog'''
928 opening a new filelog'''
928 return filectx(self._repo, self._path, fileid=fileid,
929 return filectx(self._repo, self._path, fileid=fileid,
929 filelog=self._filelog)
930 filelog=self._filelog)
930
931
931 def data(self):
932 def data(self):
932 return self._filelog.read(self._filenode)
933 return self._filelog.read(self._filenode)
933 def size(self):
934 def size(self):
934 return self._filelog.size(self._filerev)
935 return self._filelog.size(self._filerev)
935
936
936 def renamed(self):
937 def renamed(self):
937 """check if file was actually renamed in this changeset revision
938 """check if file was actually renamed in this changeset revision
938
939
939 If rename logged in file revision, we report copy for changeset only
940 If rename logged in file revision, we report copy for changeset only
940 if file revisions linkrev points back to the changeset in question
941 if file revisions linkrev points back to the changeset in question
941 or both changeset parents contain different file revisions.
942 or both changeset parents contain different file revisions.
942 """
943 """
943
944
944 renamed = self._filelog.renamed(self._filenode)
945 renamed = self._filelog.renamed(self._filenode)
945 if not renamed:
946 if not renamed:
946 return renamed
947 return renamed
947
948
948 if self.rev() == self.linkrev():
949 if self.rev() == self.linkrev():
949 return renamed
950 return renamed
950
951
951 name = self.path()
952 name = self.path()
952 fnode = self._filenode
953 fnode = self._filenode
953 for p in self._changectx.parents():
954 for p in self._changectx.parents():
954 try:
955 try:
955 if fnode == p.filenode(name):
956 if fnode == p.filenode(name):
956 return None
957 return None
957 except error.LookupError:
958 except error.LookupError:
958 pass
959 pass
959 return renamed
960 return renamed
960
961
961 def children(self):
962 def children(self):
962 # hard for renames
963 # hard for renames
963 c = self._filelog.children(self._filenode)
964 c = self._filelog.children(self._filenode)
964 return [filectx(self._repo, self._path, fileid=x,
965 return [filectx(self._repo, self._path, fileid=x,
965 filelog=self._filelog) for x in c]
966 filelog=self._filelog) for x in c]
966
967
967 class committablectx(basectx):
968 class committablectx(basectx):
968 """A committablectx object provides common functionality for a context that
969 """A committablectx object provides common functionality for a context that
969 wants the ability to commit, e.g. workingctx or memctx."""
970 wants the ability to commit, e.g. workingctx or memctx."""
970 def __init__(self, repo, text="", user=None, date=None, extra=None,
971 def __init__(self, repo, text="", user=None, date=None, extra=None,
971 changes=None):
972 changes=None):
972 self._repo = repo
973 self._repo = repo
973 self._rev = None
974 self._rev = None
974 self._node = None
975 self._node = None
975 self._text = text
976 self._text = text
976 if date:
977 if date:
977 self._date = util.parsedate(date)
978 self._date = util.parsedate(date)
978 if user:
979 if user:
979 self._user = user
980 self._user = user
980 if changes:
981 if changes:
981 self._status = changes
982 self._status = changes
982
983
983 self._extra = {}
984 self._extra = {}
984 if extra:
985 if extra:
985 self._extra = extra.copy()
986 self._extra = extra.copy()
986 if 'branch' not in self._extra:
987 if 'branch' not in self._extra:
987 try:
988 try:
988 branch = encoding.fromlocal(self._repo.dirstate.branch())
989 branch = encoding.fromlocal(self._repo.dirstate.branch())
989 except UnicodeDecodeError:
990 except UnicodeDecodeError:
990 raise util.Abort(_('branch name not in UTF-8!'))
991 raise util.Abort(_('branch name not in UTF-8!'))
991 self._extra['branch'] = branch
992 self._extra['branch'] = branch
992 if self._extra['branch'] == '':
993 if self._extra['branch'] == '':
993 self._extra['branch'] = 'default'
994 self._extra['branch'] = 'default'
994
995
995 def __str__(self):
996 def __str__(self):
996 return str(self._parents[0]) + "+"
997 return str(self._parents[0]) + "+"
997
998
998 def __nonzero__(self):
999 def __nonzero__(self):
999 return True
1000 return True
1000
1001
1001 def _buildflagfunc(self):
1002 def _buildflagfunc(self):
1002 # Create a fallback function for getting file flags when the
1003 # Create a fallback function for getting file flags when the
1003 # filesystem doesn't support them
1004 # filesystem doesn't support them
1004
1005
1005 copiesget = self._repo.dirstate.copies().get
1006 copiesget = self._repo.dirstate.copies().get
1006
1007
1007 if len(self._parents) < 2:
1008 if len(self._parents) < 2:
1008 # when we have one parent, it's easy: copy from parent
1009 # when we have one parent, it's easy: copy from parent
1009 man = self._parents[0].manifest()
1010 man = self._parents[0].manifest()
1010 def func(f):
1011 def func(f):
1011 f = copiesget(f, f)
1012 f = copiesget(f, f)
1012 return man.flags(f)
1013 return man.flags(f)
1013 else:
1014 else:
1014 # merges are tricky: we try to reconstruct the unstored
1015 # merges are tricky: we try to reconstruct the unstored
1015 # result from the merge (issue1802)
1016 # result from the merge (issue1802)
1016 p1, p2 = self._parents
1017 p1, p2 = self._parents
1017 pa = p1.ancestor(p2)
1018 pa = p1.ancestor(p2)
1018 m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest()
1019 m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest()
1019
1020
1020 def func(f):
1021 def func(f):
1021 f = copiesget(f, f) # may be wrong for merges with copies
1022 f = copiesget(f, f) # may be wrong for merges with copies
1022 fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f)
1023 fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f)
1023 if fl1 == fl2:
1024 if fl1 == fl2:
1024 return fl1
1025 return fl1
1025 if fl1 == fla:
1026 if fl1 == fla:
1026 return fl2
1027 return fl2
1027 if fl2 == fla:
1028 if fl2 == fla:
1028 return fl1
1029 return fl1
1029 return '' # punt for conflicts
1030 return '' # punt for conflicts
1030
1031
1031 return func
1032 return func
1032
1033
1033 @propertycache
1034 @propertycache
1034 def _flagfunc(self):
1035 def _flagfunc(self):
1035 return self._repo.dirstate.flagfunc(self._buildflagfunc)
1036 return self._repo.dirstate.flagfunc(self._buildflagfunc)
1036
1037
1037 @propertycache
1038 @propertycache
1038 def _manifest(self):
1039 def _manifest(self):
1039 """generate a manifest corresponding to the values in self._status"""
1040 """generate a manifest corresponding to the values in self._status"""
1040
1041
1041 man = self._parents[0].manifest().copy()
1042 man = self._parents[0].manifest().copy()
1042 if len(self._parents) > 1:
1043 if len(self._parents) > 1:
1043 man2 = self.p2().manifest()
1044 man2 = self.p2().manifest()
1044 def getman(f):
1045 def getman(f):
1045 if f in man:
1046 if f in man:
1046 return man
1047 return man
1047 return man2
1048 return man2
1048 else:
1049 else:
1049 getman = lambda f: man
1050 getman = lambda f: man
1050
1051
1051 copied = self._repo.dirstate.copies()
1052 copied = self._repo.dirstate.copies()
1052 ff = self._flagfunc
1053 ff = self._flagfunc
1053 modified, added, removed, deleted = self._status[:4]
1054 modified, added, removed, deleted = self._status[:4]
1054 for i, l in (("a", added), ("m", modified)):
1055 for i, l in (("a", added), ("m", modified)):
1055 for f in l:
1056 for f in l:
1056 orig = copied.get(f, f)
1057 orig = copied.get(f, f)
1057 man[f] = getman(orig).get(orig, nullid) + i
1058 man[f] = getman(orig).get(orig, nullid) + i
1058 try:
1059 try:
1059 man.set(f, ff(f))
1060 man.set(f, ff(f))
1060 except OSError:
1061 except OSError:
1061 pass
1062 pass
1062
1063
1063 for f in deleted + removed:
1064 for f in deleted + removed:
1064 if f in man:
1065 if f in man:
1065 del man[f]
1066 del man[f]
1066
1067
1067 return man
1068 return man
1068
1069
1069 @propertycache
1070 @propertycache
1070 def _status(self):
1071 def _status(self):
1071 return self._repo.status()
1072 return self._repo.status()
1072
1073
1073 @propertycache
1074 @propertycache
1074 def _user(self):
1075 def _user(self):
1075 return self._repo.ui.username()
1076 return self._repo.ui.username()
1076
1077
1077 @propertycache
1078 @propertycache
1078 def _date(self):
1079 def _date(self):
1079 return util.makedate()
1080 return util.makedate()
1080
1081
1081 def subrev(self, subpath):
1082 def subrev(self, subpath):
1082 return None
1083 return None
1083
1084
1084 def user(self):
1085 def user(self):
1085 return self._user or self._repo.ui.username()
1086 return self._user or self._repo.ui.username()
1086 def date(self):
1087 def date(self):
1087 return self._date
1088 return self._date
1088 def description(self):
1089 def description(self):
1089 return self._text
1090 return self._text
1090 def files(self):
1091 def files(self):
1091 return sorted(self._status[0] + self._status[1] + self._status[2])
1092 return sorted(self._status[0] + self._status[1] + self._status[2])
1092
1093
1093 def modified(self):
1094 def modified(self):
1094 return self._status[0]
1095 return self._status[0]
1095 def added(self):
1096 def added(self):
1096 return self._status[1]
1097 return self._status[1]
1097 def removed(self):
1098 def removed(self):
1098 return self._status[2]
1099 return self._status[2]
1099 def deleted(self):
1100 def deleted(self):
1100 return self._status[3]
1101 return self._status[3]
1101 def unknown(self):
1102 def unknown(self):
1102 return self._status[4]
1103 return self._status[4]
1103 def ignored(self):
1104 def ignored(self):
1104 return self._status[5]
1105 return self._status[5]
1105 def clean(self):
1106 def clean(self):
1106 return self._status[6]
1107 return self._status[6]
1107 def branch(self):
1108 def branch(self):
1108 return encoding.tolocal(self._extra['branch'])
1109 return encoding.tolocal(self._extra['branch'])
1109 def closesbranch(self):
1110 def closesbranch(self):
1110 return 'close' in self._extra
1111 return 'close' in self._extra
1111 def extra(self):
1112 def extra(self):
1112 return self._extra
1113 return self._extra
1113
1114
1114 def tags(self):
1115 def tags(self):
1115 t = []
1116 t = []
1116 for p in self.parents():
1117 for p in self.parents():
1117 t.extend(p.tags())
1118 t.extend(p.tags())
1118 return t
1119 return t
1119
1120
1120 def bookmarks(self):
1121 def bookmarks(self):
1121 b = []
1122 b = []
1122 for p in self.parents():
1123 for p in self.parents():
1123 b.extend(p.bookmarks())
1124 b.extend(p.bookmarks())
1124 return b
1125 return b
1125
1126
1126 def phase(self):
1127 def phase(self):
1127 phase = phases.draft # default phase to draft
1128 phase = phases.draft # default phase to draft
1128 for p in self.parents():
1129 for p in self.parents():
1129 phase = max(phase, p.phase())
1130 phase = max(phase, p.phase())
1130 return phase
1131 return phase
1131
1132
1132 def hidden(self):
1133 def hidden(self):
1133 return False
1134 return False
1134
1135
1135 def children(self):
1136 def children(self):
1136 return []
1137 return []
1137
1138
1138 def flags(self, path):
1139 def flags(self, path):
1139 if '_manifest' in self.__dict__:
1140 if '_manifest' in self.__dict__:
1140 try:
1141 try:
1141 return self._manifest.flags(path)
1142 return self._manifest.flags(path)
1142 except KeyError:
1143 except KeyError:
1143 return ''
1144 return ''
1144
1145
1145 try:
1146 try:
1146 return self._flagfunc(path)
1147 return self._flagfunc(path)
1147 except OSError:
1148 except OSError:
1148 return ''
1149 return ''
1149
1150
1150 def ancestor(self, c2):
1151 def ancestor(self, c2):
1151 """return the "best" ancestor context of self and c2"""
1152 """return the "best" ancestor context of self and c2"""
1152 return self._parents[0].ancestor(c2) # punt on two parents for now
1153 return self._parents[0].ancestor(c2) # punt on two parents for now
1153
1154
1154 def walk(self, match):
1155 def walk(self, match):
1155 return sorted(self._repo.dirstate.walk(match, sorted(self.substate),
1156 return sorted(self._repo.dirstate.walk(match, sorted(self.substate),
1156 True, False))
1157 True, False))
1157
1158
1158 def matches(self, match):
1159 def matches(self, match):
1159 return sorted(self._repo.dirstate.matches(match))
1160 return sorted(self._repo.dirstate.matches(match))
1160
1161
1161 def ancestors(self):
1162 def ancestors(self):
1162 for a in self._repo.changelog.ancestors(
1163 for a in self._repo.changelog.ancestors(
1163 [p.rev() for p in self._parents]):
1164 [p.rev() for p in self._parents]):
1164 yield changectx(self._repo, a)
1165 yield changectx(self._repo, a)
1165
1166
1166 def markcommitted(self, node):
1167 def markcommitted(self, node):
1167 """Perform post-commit cleanup necessary after committing this ctx
1168 """Perform post-commit cleanup necessary after committing this ctx
1168
1169
1169 Specifically, this updates backing stores this working context
1170 Specifically, this updates backing stores this working context
1170 wraps to reflect the fact that the changes reflected by this
1171 wraps to reflect the fact that the changes reflected by this
1171 workingctx have been committed. For example, it marks
1172 workingctx have been committed. For example, it marks
1172 modified and added files as normal in the dirstate.
1173 modified and added files as normal in the dirstate.
1173
1174
1174 """
1175 """
1175
1176
1176 self._repo.dirstate.beginparentchange()
1177 self._repo.dirstate.beginparentchange()
1177 for f in self.modified() + self.added():
1178 for f in self.modified() + self.added():
1178 self._repo.dirstate.normal(f)
1179 self._repo.dirstate.normal(f)
1179 for f in self.removed():
1180 for f in self.removed():
1180 self._repo.dirstate.drop(f)
1181 self._repo.dirstate.drop(f)
1181 self._repo.dirstate.setparents(node)
1182 self._repo.dirstate.setparents(node)
1182 self._repo.dirstate.endparentchange()
1183 self._repo.dirstate.endparentchange()
1183
1184
1184 def dirs(self):
1185 def dirs(self):
1185 return self._repo.dirstate.dirs()
1186 return self._repo.dirstate.dirs()
1186
1187
1187 class workingctx(committablectx):
1188 class workingctx(committablectx):
1188 """A workingctx object makes access to data related to
1189 """A workingctx object makes access to data related to
1189 the current working directory convenient.
1190 the current working directory convenient.
1190 date - any valid date string or (unixtime, offset), or None.
1191 date - any valid date string or (unixtime, offset), or None.
1191 user - username string, or None.
1192 user - username string, or None.
1192 extra - a dictionary of extra values, or None.
1193 extra - a dictionary of extra values, or None.
1193 changes - a list of file lists as returned by localrepo.status()
1194 changes - a list of file lists as returned by localrepo.status()
1194 or None to use the repository status.
1195 or None to use the repository status.
1195 """
1196 """
1196 def __init__(self, repo, text="", user=None, date=None, extra=None,
1197 def __init__(self, repo, text="", user=None, date=None, extra=None,
1197 changes=None):
1198 changes=None):
1198 super(workingctx, self).__init__(repo, text, user, date, extra, changes)
1199 super(workingctx, self).__init__(repo, text, user, date, extra, changes)
1199
1200
1200 def __iter__(self):
1201 def __iter__(self):
1201 d = self._repo.dirstate
1202 d = self._repo.dirstate
1202 for f in d:
1203 for f in d:
1203 if d[f] != 'r':
1204 if d[f] != 'r':
1204 yield f
1205 yield f
1205
1206
1206 def __contains__(self, key):
1207 def __contains__(self, key):
1207 return self._repo.dirstate[key] not in "?r"
1208 return self._repo.dirstate[key] not in "?r"
1208
1209
1209 @propertycache
1210 @propertycache
1210 def _parents(self):
1211 def _parents(self):
1211 p = self._repo.dirstate.parents()
1212 p = self._repo.dirstate.parents()
1212 if p[1] == nullid:
1213 if p[1] == nullid:
1213 p = p[:-1]
1214 p = p[:-1]
1214 return [changectx(self._repo, x) for x in p]
1215 return [changectx(self._repo, x) for x in p]
1215
1216
1216 def filectx(self, path, filelog=None):
1217 def filectx(self, path, filelog=None):
1217 """get a file context from the working directory"""
1218 """get a file context from the working directory"""
1218 return workingfilectx(self._repo, path, workingctx=self,
1219 return workingfilectx(self._repo, path, workingctx=self,
1219 filelog=filelog)
1220 filelog=filelog)
1220
1221
1221 def dirty(self, missing=False, merge=True, branch=True):
1222 def dirty(self, missing=False, merge=True, branch=True):
1222 "check whether a working directory is modified"
1223 "check whether a working directory is modified"
1223 # check subrepos first
1224 # check subrepos first
1224 for s in sorted(self.substate):
1225 for s in sorted(self.substate):
1225 if self.sub(s).dirty():
1226 if self.sub(s).dirty():
1226 return True
1227 return True
1227 # check current working dir
1228 # check current working dir
1228 return ((merge and self.p2()) or
1229 return ((merge and self.p2()) or
1229 (branch and self.branch() != self.p1().branch()) or
1230 (branch and self.branch() != self.p1().branch()) or
1230 self.modified() or self.added() or self.removed() or
1231 self.modified() or self.added() or self.removed() or
1231 (missing and self.deleted()))
1232 (missing and self.deleted()))
1232
1233
1233 def add(self, list, prefix=""):
1234 def add(self, list, prefix=""):
1234 join = lambda f: os.path.join(prefix, f)
1235 join = lambda f: os.path.join(prefix, f)
1235 wlock = self._repo.wlock()
1236 wlock = self._repo.wlock()
1236 ui, ds = self._repo.ui, self._repo.dirstate
1237 ui, ds = self._repo.ui, self._repo.dirstate
1237 try:
1238 try:
1238 rejected = []
1239 rejected = []
1239 lstat = self._repo.wvfs.lstat
1240 lstat = self._repo.wvfs.lstat
1240 for f in list:
1241 for f in list:
1241 scmutil.checkportable(ui, join(f))
1242 scmutil.checkportable(ui, join(f))
1242 try:
1243 try:
1243 st = lstat(f)
1244 st = lstat(f)
1244 except OSError:
1245 except OSError:
1245 ui.warn(_("%s does not exist!\n") % join(f))
1246 ui.warn(_("%s does not exist!\n") % join(f))
1246 rejected.append(f)
1247 rejected.append(f)
1247 continue
1248 continue
1248 if st.st_size > 10000000:
1249 if st.st_size > 10000000:
1249 ui.warn(_("%s: up to %d MB of RAM may be required "
1250 ui.warn(_("%s: up to %d MB of RAM may be required "
1250 "to manage this file\n"
1251 "to manage this file\n"
1251 "(use 'hg revert %s' to cancel the "
1252 "(use 'hg revert %s' to cancel the "
1252 "pending addition)\n")
1253 "pending addition)\n")
1253 % (f, 3 * st.st_size // 1000000, join(f)))
1254 % (f, 3 * st.st_size // 1000000, join(f)))
1254 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1255 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1255 ui.warn(_("%s not added: only files and symlinks "
1256 ui.warn(_("%s not added: only files and symlinks "
1256 "supported currently\n") % join(f))
1257 "supported currently\n") % join(f))
1257 rejected.append(f)
1258 rejected.append(f)
1258 elif ds[f] in 'amn':
1259 elif ds[f] in 'amn':
1259 ui.warn(_("%s already tracked!\n") % join(f))
1260 ui.warn(_("%s already tracked!\n") % join(f))
1260 elif ds[f] == 'r':
1261 elif ds[f] == 'r':
1261 ds.normallookup(f)
1262 ds.normallookup(f)
1262 else:
1263 else:
1263 ds.add(f)
1264 ds.add(f)
1264 return rejected
1265 return rejected
1265 finally:
1266 finally:
1266 wlock.release()
1267 wlock.release()
1267
1268
1268 def forget(self, files, prefix=""):
1269 def forget(self, files, prefix=""):
1269 join = lambda f: os.path.join(prefix, f)
1270 join = lambda f: os.path.join(prefix, f)
1270 wlock = self._repo.wlock()
1271 wlock = self._repo.wlock()
1271 try:
1272 try:
1272 rejected = []
1273 rejected = []
1273 for f in files:
1274 for f in files:
1274 if f not in self._repo.dirstate:
1275 if f not in self._repo.dirstate:
1275 self._repo.ui.warn(_("%s not tracked!\n") % join(f))
1276 self._repo.ui.warn(_("%s not tracked!\n") % join(f))
1276 rejected.append(f)
1277 rejected.append(f)
1277 elif self._repo.dirstate[f] != 'a':
1278 elif self._repo.dirstate[f] != 'a':
1278 self._repo.dirstate.remove(f)
1279 self._repo.dirstate.remove(f)
1279 else:
1280 else:
1280 self._repo.dirstate.drop(f)
1281 self._repo.dirstate.drop(f)
1281 return rejected
1282 return rejected
1282 finally:
1283 finally:
1283 wlock.release()
1284 wlock.release()
1284
1285
1285 def undelete(self, list):
1286 def undelete(self, list):
1286 pctxs = self.parents()
1287 pctxs = self.parents()
1287 wlock = self._repo.wlock()
1288 wlock = self._repo.wlock()
1288 try:
1289 try:
1289 for f in list:
1290 for f in list:
1290 if self._repo.dirstate[f] != 'r':
1291 if self._repo.dirstate[f] != 'r':
1291 self._repo.ui.warn(_("%s not removed!\n") % f)
1292 self._repo.ui.warn(_("%s not removed!\n") % f)
1292 else:
1293 else:
1293 fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f]
1294 fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f]
1294 t = fctx.data()
1295 t = fctx.data()
1295 self._repo.wwrite(f, t, fctx.flags())
1296 self._repo.wwrite(f, t, fctx.flags())
1296 self._repo.dirstate.normal(f)
1297 self._repo.dirstate.normal(f)
1297 finally:
1298 finally:
1298 wlock.release()
1299 wlock.release()
1299
1300
1300 def copy(self, source, dest):
1301 def copy(self, source, dest):
1301 try:
1302 try:
1302 st = self._repo.wvfs.lstat(dest)
1303 st = self._repo.wvfs.lstat(dest)
1303 except OSError, err:
1304 except OSError, err:
1304 if err.errno != errno.ENOENT:
1305 if err.errno != errno.ENOENT:
1305 raise
1306 raise
1306 self._repo.ui.warn(_("%s does not exist!\n") % dest)
1307 self._repo.ui.warn(_("%s does not exist!\n") % dest)
1307 return
1308 return
1308 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1309 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1309 self._repo.ui.warn(_("copy failed: %s is not a file or a "
1310 self._repo.ui.warn(_("copy failed: %s is not a file or a "
1310 "symbolic link\n") % dest)
1311 "symbolic link\n") % dest)
1311 else:
1312 else:
1312 wlock = self._repo.wlock()
1313 wlock = self._repo.wlock()
1313 try:
1314 try:
1314 if self._repo.dirstate[dest] in '?r':
1315 if self._repo.dirstate[dest] in '?r':
1315 self._repo.dirstate.add(dest)
1316 self._repo.dirstate.add(dest)
1316 self._repo.dirstate.copy(source, dest)
1317 self._repo.dirstate.copy(source, dest)
1317 finally:
1318 finally:
1318 wlock.release()
1319 wlock.release()
1319
1320
1320 def _filtersuspectsymlink(self, files):
1321 def _filtersuspectsymlink(self, files):
1321 if not files or self._repo.dirstate._checklink:
1322 if not files or self._repo.dirstate._checklink:
1322 return files
1323 return files
1323
1324
1324 # Symlink placeholders may get non-symlink-like contents
1325 # Symlink placeholders may get non-symlink-like contents
1325 # via user error or dereferencing by NFS or Samba servers,
1326 # via user error or dereferencing by NFS or Samba servers,
1326 # so we filter out any placeholders that don't look like a
1327 # so we filter out any placeholders that don't look like a
1327 # symlink
1328 # symlink
1328 sane = []
1329 sane = []
1329 for f in files:
1330 for f in files:
1330 if self.flags(f) == 'l':
1331 if self.flags(f) == 'l':
1331 d = self[f].data()
1332 d = self[f].data()
1332 if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d):
1333 if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d):
1333 self._repo.ui.debug('ignoring suspect symlink placeholder'
1334 self._repo.ui.debug('ignoring suspect symlink placeholder'
1334 ' "%s"\n' % f)
1335 ' "%s"\n' % f)
1335 continue
1336 continue
1336 sane.append(f)
1337 sane.append(f)
1337 return sane
1338 return sane
1338
1339
1339 def _checklookup(self, files):
1340 def _checklookup(self, files):
1340 # check for any possibly clean files
1341 # check for any possibly clean files
1341 if not files:
1342 if not files:
1342 return [], []
1343 return [], []
1343
1344
1344 modified = []
1345 modified = []
1345 fixup = []
1346 fixup = []
1346 pctx = self._parents[0]
1347 pctx = self._parents[0]
1347 # do a full compare of any files that might have changed
1348 # do a full compare of any files that might have changed
1348 for f in sorted(files):
1349 for f in sorted(files):
1349 if (f not in pctx or self.flags(f) != pctx.flags(f)
1350 if (f not in pctx or self.flags(f) != pctx.flags(f)
1350 or pctx[f].cmp(self[f])):
1351 or pctx[f].cmp(self[f])):
1351 modified.append(f)
1352 modified.append(f)
1352 else:
1353 else:
1353 fixup.append(f)
1354 fixup.append(f)
1354
1355
1355 # update dirstate for files that are actually clean
1356 # update dirstate for files that are actually clean
1356 if fixup:
1357 if fixup:
1357 try:
1358 try:
1358 # updating the dirstate is optional
1359 # updating the dirstate is optional
1359 # so we don't wait on the lock
1360 # so we don't wait on the lock
1360 # wlock can invalidate the dirstate, so cache normal _after_
1361 # wlock can invalidate the dirstate, so cache normal _after_
1361 # taking the lock
1362 # taking the lock
1362 wlock = self._repo.wlock(False)
1363 wlock = self._repo.wlock(False)
1363 normal = self._repo.dirstate.normal
1364 normal = self._repo.dirstate.normal
1364 try:
1365 try:
1365 for f in fixup:
1366 for f in fixup:
1366 normal(f)
1367 normal(f)
1367 finally:
1368 finally:
1368 wlock.release()
1369 wlock.release()
1369 except error.LockError:
1370 except error.LockError:
1370 pass
1371 pass
1371 return modified, fixup
1372 return modified, fixup
1372
1373
1373 def _manifestmatches(self, match, s):
1374 def _manifestmatches(self, match, s):
1374 """Slow path for workingctx
1375 """Slow path for workingctx
1375
1376
1376 The fast path is when we compare the working directory to its parent
1377 The fast path is when we compare the working directory to its parent
1377 which means this function is comparing with a non-parent; therefore we
1378 which means this function is comparing with a non-parent; therefore we
1378 need to build a manifest and return what matches.
1379 need to build a manifest and return what matches.
1379 """
1380 """
1380 mf = self._repo['.']._manifestmatches(match, s)
1381 mf = self._repo['.']._manifestmatches(match, s)
1381 modified, added, removed = s[0:3]
1382 modified, added, removed = s[0:3]
1382 for f in modified + added:
1383 for f in modified + added:
1383 mf[f] = None
1384 mf[f] = None
1384 mf.set(f, self.flags(f))
1385 mf.set(f, self.flags(f))
1385 for f in removed:
1386 for f in removed:
1386 if f in mf:
1387 if f in mf:
1387 del mf[f]
1388 del mf[f]
1388 return mf
1389 return mf
1389
1390
1390 def _prestatus(self, other, s, match, listignored, listclean, listunknown):
1391 def _prestatus(self, other, s, match, listignored, listclean, listunknown):
1391 """override the parent hook with a dirstate query
1392 """override the parent hook with a dirstate query
1392
1393
1393 We use this prestatus hook to populate the status with information from
1394 We use this prestatus hook to populate the status with information from
1394 the dirstate.
1395 the dirstate.
1395 """
1396 """
1396 # doesn't need to call super; if that changes, be aware that super
1397 # doesn't need to call super; if that changes, be aware that super
1397 # calls self.manifest which would slow down the common case of calling
1398 # calls self.manifest which would slow down the common case of calling
1398 # status against a workingctx's parent
1399 # status against a workingctx's parent
1399 return self._dirstatestatus(match, listignored, listclean, listunknown)
1400 return self._dirstatestatus(match, listignored, listclean, listunknown)
1400
1401
1401 def _poststatus(self, other, s, match, listignored, listclean, listunknown):
1402 def _poststatus(self, other, s, match, listignored, listclean, listunknown):
1402 """override the parent hook with a filter for suspect symlinks
1403 """override the parent hook with a filter for suspect symlinks
1403
1404
1404 We use this poststatus hook to filter out symlinks that might have
1405 We use this poststatus hook to filter out symlinks that might have
1405 accidentally ended up with the entire contents of the file they are
1406 accidentally ended up with the entire contents of the file they are
1406 susposed to be linking to.
1407 susposed to be linking to.
1407 """
1408 """
1408 s[0] = self._filtersuspectsymlink(s[0])
1409 s[0] = self._filtersuspectsymlink(s[0])
1409 self._status = s[:]
1410 self._status = s[:]
1410 return s
1411 return s
1411
1412
1412 def _dirstatestatus(self, match=None, ignored=False, clean=False,
1413 def _dirstatestatus(self, match=None, ignored=False, clean=False,
1413 unknown=False):
1414 unknown=False):
1414 '''Gets the status from the dirstate -- internal use only.'''
1415 '''Gets the status from the dirstate -- internal use only.'''
1415 listignored, listclean, listunknown = ignored, clean, unknown
1416 listignored, listclean, listunknown = ignored, clean, unknown
1416 match = match or matchmod.always(self._repo.root, self._repo.getcwd())
1417 match = match or matchmod.always(self._repo.root, self._repo.getcwd())
1417 subrepos = []
1418 subrepos = []
1418 if '.hgsub' in self:
1419 if '.hgsub' in self:
1419 subrepos = sorted(self.substate)
1420 subrepos = sorted(self.substate)
1420 s = self._repo.dirstate.status(match, subrepos, listignored,
1421 s = self._repo.dirstate.status(match, subrepos, listignored,
1421 listclean, listunknown)
1422 listclean, listunknown)
1422 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
1423 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
1423
1424
1424 # check for any possibly clean files
1425 # check for any possibly clean files
1425 if cmp:
1426 if cmp:
1426 modified2, fixup = self._checklookup(cmp)
1427 modified2, fixup = self._checklookup(cmp)
1427 modified += modified2
1428 modified += modified2
1428
1429
1429 # update dirstate for files that are actually clean
1430 # update dirstate for files that are actually clean
1430 if fixup and listclean:
1431 if fixup and listclean:
1431 clean += fixup
1432 clean += fixup
1432
1433
1433 return [modified, added, removed, deleted, unknown, ignored, clean]
1434 return [modified, added, removed, deleted, unknown, ignored, clean]
1434
1435
1435 def _buildstatus(self, other, s, match, listignored, listclean,
1436 def _buildstatus(self, other, s, match, listignored, listclean,
1436 listunknown):
1437 listunknown):
1437 """build a status with respect to another context
1438 """build a status with respect to another context
1438
1439
1439 This includes logic for maintaining the fast path of status when
1440 This includes logic for maintaining the fast path of status when
1440 comparing the working directory against its parent, which is to skip
1441 comparing the working directory against its parent, which is to skip
1441 building a new manifest if self (working directory) is not comparing
1442 building a new manifest if self (working directory) is not comparing
1442 against its parent (repo['.']).
1443 against its parent (repo['.']).
1443 """
1444 """
1444 if other != self._repo['.']:
1445 if other != self._repo['.']:
1445 s = super(workingctx, self)._buildstatus(other, s, match,
1446 s = super(workingctx, self)._buildstatus(other, s, match,
1446 listignored, listclean,
1447 listignored, listclean,
1447 listunknown)
1448 listunknown)
1448 return s
1449 return s
1449
1450
1450 def _matchstatus(self, other, s, match, listignored, listclean,
1451 def _matchstatus(self, other, s, match, listignored, listclean,
1451 listunknown):
1452 listunknown):
1452 """override the match method with a filter for directory patterns
1453 """override the match method with a filter for directory patterns
1453
1454
1454 We use inheritance to customize the match.bad method only in cases of
1455 We use inheritance to customize the match.bad method only in cases of
1455 workingctx since it belongs only to the working directory when
1456 workingctx since it belongs only to the working directory when
1456 comparing against the parent changeset.
1457 comparing against the parent changeset.
1457
1458
1458 If we aren't comparing against the working directory's parent, then we
1459 If we aren't comparing against the working directory's parent, then we
1459 just use the default match object sent to us.
1460 just use the default match object sent to us.
1460 """
1461 """
1461 superself = super(workingctx, self)
1462 superself = super(workingctx, self)
1462 match = superself._matchstatus(other, s, match, listignored, listclean,
1463 match = superself._matchstatus(other, s, match, listignored, listclean,
1463 listunknown)
1464 listunknown)
1464 if other != self._repo['.']:
1465 if other != self._repo['.']:
1465 def bad(f, msg):
1466 def bad(f, msg):
1466 # 'f' may be a directory pattern from 'match.files()',
1467 # 'f' may be a directory pattern from 'match.files()',
1467 # so 'f not in ctx1' is not enough
1468 # so 'f not in ctx1' is not enough
1468 if f not in other and f not in other.dirs():
1469 if f not in other and f not in other.dirs():
1469 self._repo.ui.warn('%s: %s\n' %
1470 self._repo.ui.warn('%s: %s\n' %
1470 (self._repo.dirstate.pathto(f), msg))
1471 (self._repo.dirstate.pathto(f), msg))
1471 match.bad = bad
1472 match.bad = bad
1472 return match
1473 return match
1473
1474
1474 def status(self, other='.', match=None, listignored=False,
1475 def status(self, other='.', match=None, listignored=False,
1475 listclean=False, listunknown=False, listsubrepos=False):
1476 listclean=False, listunknown=False, listsubrepos=False):
1476 # yet to be determined: what to do if 'other' is a 'workingctx' or a
1477 # yet to be determined: what to do if 'other' is a 'workingctx' or a
1477 # 'memctx'?
1478 # 'memctx'?
1478 s = super(workingctx, self).status(other, match, listignored, listclean,
1479 s = super(workingctx, self).status(other, match, listignored, listclean,
1479 listunknown, listsubrepos)
1480 listunknown, listsubrepos)
1480 # calling 'super' subtly reveresed the contexts, so we flip the results
1481 # calling 'super' subtly reveresed the contexts, so we flip the results
1481 # (s[1] is 'added' and s[2] is 'removed')
1482 # (s[1] is 'added' and s[2] is 'removed')
1482 s = list(s)
1483 s = list(s)
1483 s[1], s[2] = s[2], s[1]
1484 s[1], s[2] = s[2], s[1]
1484 return tuple(s)
1485 return tuple(s)
1485
1486
1486 class committablefilectx(basefilectx):
1487 class committablefilectx(basefilectx):
1487 """A committablefilectx provides common functionality for a file context
1488 """A committablefilectx provides common functionality for a file context
1488 that wants the ability to commit, e.g. workingfilectx or memfilectx."""
1489 that wants the ability to commit, e.g. workingfilectx or memfilectx."""
1489 def __init__(self, repo, path, filelog=None, ctx=None):
1490 def __init__(self, repo, path, filelog=None, ctx=None):
1490 self._repo = repo
1491 self._repo = repo
1491 self._path = path
1492 self._path = path
1492 self._changeid = None
1493 self._changeid = None
1493 self._filerev = self._filenode = None
1494 self._filerev = self._filenode = None
1494
1495
1495 if filelog is not None:
1496 if filelog is not None:
1496 self._filelog = filelog
1497 self._filelog = filelog
1497 if ctx:
1498 if ctx:
1498 self._changectx = ctx
1499 self._changectx = ctx
1499
1500
1500 def __nonzero__(self):
1501 def __nonzero__(self):
1501 return True
1502 return True
1502
1503
1503 def parents(self):
1504 def parents(self):
1504 '''return parent filectxs, following copies if necessary'''
1505 '''return parent filectxs, following copies if necessary'''
1505 def filenode(ctx, path):
1506 def filenode(ctx, path):
1506 return ctx._manifest.get(path, nullid)
1507 return ctx._manifest.get(path, nullid)
1507
1508
1508 path = self._path
1509 path = self._path
1509 fl = self._filelog
1510 fl = self._filelog
1510 pcl = self._changectx._parents
1511 pcl = self._changectx._parents
1511 renamed = self.renamed()
1512 renamed = self.renamed()
1512
1513
1513 if renamed:
1514 if renamed:
1514 pl = [renamed + (None,)]
1515 pl = [renamed + (None,)]
1515 else:
1516 else:
1516 pl = [(path, filenode(pcl[0], path), fl)]
1517 pl = [(path, filenode(pcl[0], path), fl)]
1517
1518
1518 for pc in pcl[1:]:
1519 for pc in pcl[1:]:
1519 pl.append((path, filenode(pc, path), fl))
1520 pl.append((path, filenode(pc, path), fl))
1520
1521
1521 return [filectx(self._repo, p, fileid=n, filelog=l)
1522 return [filectx(self._repo, p, fileid=n, filelog=l)
1522 for p, n, l in pl if n != nullid]
1523 for p, n, l in pl if n != nullid]
1523
1524
1524 def children(self):
1525 def children(self):
1525 return []
1526 return []
1526
1527
1527 class workingfilectx(committablefilectx):
1528 class workingfilectx(committablefilectx):
1528 """A workingfilectx object makes access to data related to a particular
1529 """A workingfilectx object makes access to data related to a particular
1529 file in the working directory convenient."""
1530 file in the working directory convenient."""
1530 def __init__(self, repo, path, filelog=None, workingctx=None):
1531 def __init__(self, repo, path, filelog=None, workingctx=None):
1531 super(workingfilectx, self).__init__(repo, path, filelog, workingctx)
1532 super(workingfilectx, self).__init__(repo, path, filelog, workingctx)
1532
1533
1533 @propertycache
1534 @propertycache
1534 def _changectx(self):
1535 def _changectx(self):
1535 return workingctx(self._repo)
1536 return workingctx(self._repo)
1536
1537
1537 def data(self):
1538 def data(self):
1538 return self._repo.wread(self._path)
1539 return self._repo.wread(self._path)
1539 def renamed(self):
1540 def renamed(self):
1540 rp = self._repo.dirstate.copied(self._path)
1541 rp = self._repo.dirstate.copied(self._path)
1541 if not rp:
1542 if not rp:
1542 return None
1543 return None
1543 return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
1544 return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
1544
1545
1545 def size(self):
1546 def size(self):
1546 return self._repo.wvfs.lstat(self._path).st_size
1547 return self._repo.wvfs.lstat(self._path).st_size
1547 def date(self):
1548 def date(self):
1548 t, tz = self._changectx.date()
1549 t, tz = self._changectx.date()
1549 try:
1550 try:
1550 return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz)
1551 return (int(self._repo.wvfs.lstat(self._path).st_mtime), tz)
1551 except OSError, err:
1552 except OSError, err:
1552 if err.errno != errno.ENOENT:
1553 if err.errno != errno.ENOENT:
1553 raise
1554 raise
1554 return (t, tz)
1555 return (t, tz)
1555
1556
1556 def cmp(self, fctx):
1557 def cmp(self, fctx):
1557 """compare with other file context
1558 """compare with other file context
1558
1559
1559 returns True if different than fctx.
1560 returns True if different than fctx.
1560 """
1561 """
1561 # fctx should be a filectx (not a workingfilectx)
1562 # fctx should be a filectx (not a workingfilectx)
1562 # invert comparison to reuse the same code path
1563 # invert comparison to reuse the same code path
1563 return fctx.cmp(self)
1564 return fctx.cmp(self)
1564
1565
1565 def remove(self, ignoremissing=False):
1566 def remove(self, ignoremissing=False):
1566 """wraps unlink for a repo's working directory"""
1567 """wraps unlink for a repo's working directory"""
1567 util.unlinkpath(self._repo.wjoin(self._path), ignoremissing)
1568 util.unlinkpath(self._repo.wjoin(self._path), ignoremissing)
1568
1569
1569 def write(self, data, flags):
1570 def write(self, data, flags):
1570 """wraps repo.wwrite"""
1571 """wraps repo.wwrite"""
1571 self._repo.wwrite(self._path, data, flags)
1572 self._repo.wwrite(self._path, data, flags)
1572
1573
1573 class memctx(committablectx):
1574 class memctx(committablectx):
1574 """Use memctx to perform in-memory commits via localrepo.commitctx().
1575 """Use memctx to perform in-memory commits via localrepo.commitctx().
1575
1576
1576 Revision information is supplied at initialization time while
1577 Revision information is supplied at initialization time while
1577 related files data and is made available through a callback
1578 related files data and is made available through a callback
1578 mechanism. 'repo' is the current localrepo, 'parents' is a
1579 mechanism. 'repo' is the current localrepo, 'parents' is a
1579 sequence of two parent revisions identifiers (pass None for every
1580 sequence of two parent revisions identifiers (pass None for every
1580 missing parent), 'text' is the commit message and 'files' lists
1581 missing parent), 'text' is the commit message and 'files' lists
1581 names of files touched by the revision (normalized and relative to
1582 names of files touched by the revision (normalized and relative to
1582 repository root).
1583 repository root).
1583
1584
1584 filectxfn(repo, memctx, path) is a callable receiving the
1585 filectxfn(repo, memctx, path) is a callable receiving the
1585 repository, the current memctx object and the normalized path of
1586 repository, the current memctx object and the normalized path of
1586 requested file, relative to repository root. It is fired by the
1587 requested file, relative to repository root. It is fired by the
1587 commit function for every file in 'files', but calls order is
1588 commit function for every file in 'files', but calls order is
1588 undefined. If the file is available in the revision being
1589 undefined. If the file is available in the revision being
1589 committed (updated or added), filectxfn returns a memfilectx
1590 committed (updated or added), filectxfn returns a memfilectx
1590 object. If the file was removed, filectxfn raises an
1591 object. If the file was removed, filectxfn raises an
1591 IOError. Moved files are represented by marking the source file
1592 IOError. Moved files are represented by marking the source file
1592 removed and the new file added with copy information (see
1593 removed and the new file added with copy information (see
1593 memfilectx).
1594 memfilectx).
1594
1595
1595 user receives the committer name and defaults to current
1596 user receives the committer name and defaults to current
1596 repository username, date is the commit date in any format
1597 repository username, date is the commit date in any format
1597 supported by util.parsedate() and defaults to current date, extra
1598 supported by util.parsedate() and defaults to current date, extra
1598 is a dictionary of metadata or is left empty.
1599 is a dictionary of metadata or is left empty.
1599 """
1600 """
1600
1601
1601 # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files.
1602 # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files.
1602 # Extensions that need to retain compatibility across Mercurial 3.1 can use
1603 # Extensions that need to retain compatibility across Mercurial 3.1 can use
1603 # this field to determine what to do in filectxfn.
1604 # this field to determine what to do in filectxfn.
1604 _returnnoneformissingfiles = True
1605 _returnnoneformissingfiles = True
1605
1606
1606 def __init__(self, repo, parents, text, files, filectxfn, user=None,
1607 def __init__(self, repo, parents, text, files, filectxfn, user=None,
1607 date=None, extra=None, editor=False):
1608 date=None, extra=None, editor=False):
1608 super(memctx, self).__init__(repo, text, user, date, extra)
1609 super(memctx, self).__init__(repo, text, user, date, extra)
1609 self._rev = None
1610 self._rev = None
1610 self._node = None
1611 self._node = None
1611 parents = [(p or nullid) for p in parents]
1612 parents = [(p or nullid) for p in parents]
1612 p1, p2 = parents
1613 p1, p2 = parents
1613 self._parents = [changectx(self._repo, p) for p in (p1, p2)]
1614 self._parents = [changectx(self._repo, p) for p in (p1, p2)]
1614 files = sorted(set(files))
1615 files = sorted(set(files))
1615 self._status = [files, [], [], [], []]
1616 self._status = [files, [], [], [], []]
1616 self._filectxfn = filectxfn
1617 self._filectxfn = filectxfn
1617 self.substate = {}
1618 self.substate = {}
1618
1619
1619 # if store is not callable, wrap it in a function
1620 # if store is not callable, wrap it in a function
1620 if not callable(filectxfn):
1621 if not callable(filectxfn):
1621 def getfilectx(repo, memctx, path):
1622 def getfilectx(repo, memctx, path):
1622 fctx = filectxfn[path]
1623 fctx = filectxfn[path]
1623 # this is weird but apparently we only keep track of one parent
1624 # this is weird but apparently we only keep track of one parent
1624 # (why not only store that instead of a tuple?)
1625 # (why not only store that instead of a tuple?)
1625 copied = fctx.renamed()
1626 copied = fctx.renamed()
1626 if copied:
1627 if copied:
1627 copied = copied[0]
1628 copied = copied[0]
1628 return memfilectx(repo, path, fctx.data(),
1629 return memfilectx(repo, path, fctx.data(),
1629 islink=fctx.islink(), isexec=fctx.isexec(),
1630 islink=fctx.islink(), isexec=fctx.isexec(),
1630 copied=copied, memctx=memctx)
1631 copied=copied, memctx=memctx)
1631 self._filectxfn = getfilectx
1632 self._filectxfn = getfilectx
1632
1633
1633 self._extra = extra and extra.copy() or {}
1634 self._extra = extra and extra.copy() or {}
1634 if self._extra.get('branch', '') == '':
1635 if self._extra.get('branch', '') == '':
1635 self._extra['branch'] = 'default'
1636 self._extra['branch'] = 'default'
1636
1637
1637 if editor:
1638 if editor:
1638 self._text = editor(self._repo, self, [])
1639 self._text = editor(self._repo, self, [])
1639 self._repo.savecommitmessage(self._text)
1640 self._repo.savecommitmessage(self._text)
1640
1641
1641 def filectx(self, path, filelog=None):
1642 def filectx(self, path, filelog=None):
1642 """get a file context from the working directory
1643 """get a file context from the working directory
1643
1644
1644 Returns None if file doesn't exist and should be removed."""
1645 Returns None if file doesn't exist and should be removed."""
1645 return self._filectxfn(self._repo, self, path)
1646 return self._filectxfn(self._repo, self, path)
1646
1647
1647 def commit(self):
1648 def commit(self):
1648 """commit context to the repo"""
1649 """commit context to the repo"""
1649 return self._repo.commitctx(self)
1650 return self._repo.commitctx(self)
1650
1651
1651 @propertycache
1652 @propertycache
1652 def _manifest(self):
1653 def _manifest(self):
1653 """generate a manifest based on the return values of filectxfn"""
1654 """generate a manifest based on the return values of filectxfn"""
1654
1655
1655 # keep this simple for now; just worry about p1
1656 # keep this simple for now; just worry about p1
1656 pctx = self._parents[0]
1657 pctx = self._parents[0]
1657 man = pctx.manifest().copy()
1658 man = pctx.manifest().copy()
1658
1659
1659 for f, fnode in man.iteritems():
1660 for f, fnode in man.iteritems():
1660 p1node = nullid
1661 p1node = nullid
1661 p2node = nullid
1662 p2node = nullid
1662 p = pctx[f].parents() # if file isn't in pctx, check p2?
1663 p = pctx[f].parents() # if file isn't in pctx, check p2?
1663 if len(p) > 0:
1664 if len(p) > 0:
1664 p1node = p[0].node()
1665 p1node = p[0].node()
1665 if len(p) > 1:
1666 if len(p) > 1:
1666 p2node = p[1].node()
1667 p2node = p[1].node()
1667 man[f] = revlog.hash(self[f].data(), p1node, p2node)
1668 man[f] = revlog.hash(self[f].data(), p1node, p2node)
1668
1669
1669 return man
1670 return man
1670
1671
1671
1672
1672 class memfilectx(committablefilectx):
1673 class memfilectx(committablefilectx):
1673 """memfilectx represents an in-memory file to commit.
1674 """memfilectx represents an in-memory file to commit.
1674
1675
1675 See memctx and commitablefilectx for more details.
1676 See memctx and commitablefilectx for more details.
1676 """
1677 """
1677 def __init__(self, repo, path, data, islink=False,
1678 def __init__(self, repo, path, data, islink=False,
1678 isexec=False, copied=None, memctx=None):
1679 isexec=False, copied=None, memctx=None):
1679 """
1680 """
1680 path is the normalized file path relative to repository root.
1681 path is the normalized file path relative to repository root.
1681 data is the file content as a string.
1682 data is the file content as a string.
1682 islink is True if the file is a symbolic link.
1683 islink is True if the file is a symbolic link.
1683 isexec is True if the file is executable.
1684 isexec is True if the file is executable.
1684 copied is the source file path if current file was copied in the
1685 copied is the source file path if current file was copied in the
1685 revision being committed, or None."""
1686 revision being committed, or None."""
1686 super(memfilectx, self).__init__(repo, path, None, memctx)
1687 super(memfilectx, self).__init__(repo, path, None, memctx)
1687 self._data = data
1688 self._data = data
1688 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
1689 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
1689 self._copied = None
1690 self._copied = None
1690 if copied:
1691 if copied:
1691 self._copied = (copied, nullid)
1692 self._copied = (copied, nullid)
1692
1693
1693 def data(self):
1694 def data(self):
1694 return self._data
1695 return self._data
1695 def size(self):
1696 def size(self):
1696 return len(self.data())
1697 return len(self.data())
1697 def flags(self):
1698 def flags(self):
1698 return self._flags
1699 return self._flags
1699 def renamed(self):
1700 def renamed(self):
1700 return self._copied
1701 return self._copied
1701
1702
1702 def remove(self, ignoremissing=False):
1703 def remove(self, ignoremissing=False):
1703 """wraps unlink for a repo's working directory"""
1704 """wraps unlink for a repo's working directory"""
1704 # need to figure out what to do here
1705 # need to figure out what to do here
1705 del self._changectx[self._path]
1706 del self._changectx[self._path]
1706
1707
1707 def write(self, data, flags):
1708 def write(self, data, flags):
1708 """wraps repo.wwrite"""
1709 """wraps repo.wwrite"""
1709 self._data = data
1710 self._data = data
@@ -1,355 +1,355 b''
1 Criss cross merging
1 Criss cross merging
2
2
3 $ hg init criss-cross
3 $ hg init criss-cross
4 $ cd criss-cross
4 $ cd criss-cross
5 $ echo '0 base' > f1
5 $ echo '0 base' > f1
6 $ echo '0 base' > f2
6 $ echo '0 base' > f2
7 $ hg ci -Aqm '0 base'
7 $ hg ci -Aqm '0 base'
8
8
9 $ echo '1 first change' > f1
9 $ echo '1 first change' > f1
10 $ hg ci -m '1 first change f1'
10 $ hg ci -m '1 first change f1'
11
11
12 $ hg up -qr0
12 $ hg up -qr0
13 $ echo '2 first change' > f2
13 $ echo '2 first change' > f2
14 $ hg ci -qm '2 first change f2'
14 $ hg ci -qm '2 first change f2'
15
15
16 $ hg merge -qr 1
16 $ hg merge -qr 1
17 $ hg ci -m '3 merge'
17 $ hg ci -m '3 merge'
18
18
19 $ hg up -qr2
19 $ hg up -qr2
20 $ hg merge -qr1
20 $ hg merge -qr1
21 $ hg ci -qm '4 merge'
21 $ hg ci -qm '4 merge'
22
22
23 $ echo '5 second change' > f1
23 $ echo '5 second change' > f1
24 $ hg ci -m '5 second change f1'
24 $ hg ci -m '5 second change f1'
25
25
26 $ hg up -r3
26 $ hg up -r3
27 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
27 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
28 $ echo '6 second change' > f2
28 $ echo '6 second change' > f2
29 $ hg ci -m '6 second change f2'
29 $ hg ci -m '6 second change f2'
30
30
31 $ hg log -G
31 $ hg log -G
32 @ changeset: 6:3b08d01b0ab5
32 @ changeset: 6:3b08d01b0ab5
33 | tag: tip
33 | tag: tip
34 | parent: 3:cf89f02107e5
34 | parent: 3:cf89f02107e5
35 | user: test
35 | user: test
36 | date: Thu Jan 01 00:00:00 1970 +0000
36 | date: Thu Jan 01 00:00:00 1970 +0000
37 | summary: 6 second change f2
37 | summary: 6 second change f2
38 |
38 |
39 | o changeset: 5:adfe50279922
39 | o changeset: 5:adfe50279922
40 | | user: test
40 | | user: test
41 | | date: Thu Jan 01 00:00:00 1970 +0000
41 | | date: Thu Jan 01 00:00:00 1970 +0000
42 | | summary: 5 second change f1
42 | | summary: 5 second change f1
43 | |
43 | |
44 | o changeset: 4:7d3e55501ae6
44 | o changeset: 4:7d3e55501ae6
45 | |\ parent: 2:40663881a6dd
45 | |\ parent: 2:40663881a6dd
46 | | | parent: 1:0f6b37dbe527
46 | | | parent: 1:0f6b37dbe527
47 | | | user: test
47 | | | user: test
48 | | | date: Thu Jan 01 00:00:00 1970 +0000
48 | | | date: Thu Jan 01 00:00:00 1970 +0000
49 | | | summary: 4 merge
49 | | | summary: 4 merge
50 | | |
50 | | |
51 o---+ changeset: 3:cf89f02107e5
51 o---+ changeset: 3:cf89f02107e5
52 | | | parent: 2:40663881a6dd
52 | | | parent: 2:40663881a6dd
53 |/ / parent: 1:0f6b37dbe527
53 |/ / parent: 1:0f6b37dbe527
54 | | user: test
54 | | user: test
55 | | date: Thu Jan 01 00:00:00 1970 +0000
55 | | date: Thu Jan 01 00:00:00 1970 +0000
56 | | summary: 3 merge
56 | | summary: 3 merge
57 | |
57 | |
58 | o changeset: 2:40663881a6dd
58 | o changeset: 2:40663881a6dd
59 | | parent: 0:40494bf2444c
59 | | parent: 0:40494bf2444c
60 | | user: test
60 | | user: test
61 | | date: Thu Jan 01 00:00:00 1970 +0000
61 | | date: Thu Jan 01 00:00:00 1970 +0000
62 | | summary: 2 first change f2
62 | | summary: 2 first change f2
63 | |
63 | |
64 o | changeset: 1:0f6b37dbe527
64 o | changeset: 1:0f6b37dbe527
65 |/ user: test
65 |/ user: test
66 | date: Thu Jan 01 00:00:00 1970 +0000
66 | date: Thu Jan 01 00:00:00 1970 +0000
67 | summary: 1 first change f1
67 | summary: 1 first change f1
68 |
68 |
69 o changeset: 0:40494bf2444c
69 o changeset: 0:40494bf2444c
70 user: test
70 user: test
71 date: Thu Jan 01 00:00:00 1970 +0000
71 date: Thu Jan 01 00:00:00 1970 +0000
72 summary: 0 base
72 summary: 0 base
73
73
74
74
75 $ hg merge -v --debug --tool internal:dump 5
75 $ hg merge -v --debug --tool internal:dump 5
76 note: using 0f6b37dbe527 as ancestor of 3b08d01b0ab5 and adfe50279922
76 note: using 0f6b37dbe527 as ancestor of 3b08d01b0ab5 and adfe50279922
77 alternatively, use --config merge.preferancestor=40663881a6dd
77 alternatively, use --config merge.preferancestor=40663881a6dd
78 searching for copies back to rev 3
78 searching for copies back to rev 3
79 resolving manifests
79 resolving manifests
80 branchmerge: True, force: False, partial: False
80 branchmerge: True, force: False, partial: False
81 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
81 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
82 preserving f2 for resolve of f2
82 preserving f2 for resolve of f2
83 f1: remote is newer -> g
83 f1: remote is newer -> g
84 getting f1
84 getting f1
85 updating: f1 1/2 files (50.00%)
85 updating: f1 1/2 files (50.00%)
86 f2: versions differ -> m
86 f2: versions differ -> m
87 updating: f2 2/2 files (100.00%)
87 updating: f2 2/2 files (100.00%)
88 picked tool 'internal:dump' for f2 (binary False symlink False)
88 picked tool 'internal:dump' for f2 (binary False symlink False)
89 merging f2
89 merging f2
90 my f2@3b08d01b0ab5+ other f2@adfe50279922 ancestor f2@40494bf2444c
90 my f2@3b08d01b0ab5+ other f2@adfe50279922 ancestor f2@40494bf2444c
91 1 files updated, 0 files merged, 0 files removed, 1 files unresolved
91 1 files updated, 0 files merged, 0 files removed, 1 files unresolved
92 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
92 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
93 [1]
93 [1]
94
94
95 $ head *
95 $ head *
96 ==> f1 <==
96 ==> f1 <==
97 5 second change
97 5 second change
98
98
99 ==> f2 <==
99 ==> f2 <==
100 6 second change
100 6 second change
101
101
102 ==> f2.base <==
102 ==> f2.base <==
103 0 base
103 0 base
104
104
105 ==> f2.local <==
105 ==> f2.local <==
106 6 second change
106 6 second change
107
107
108 ==> f2.orig <==
108 ==> f2.orig <==
109 6 second change
109 6 second change
110
110
111 ==> f2.other <==
111 ==> f2.other <==
112 2 first change
112 2 first change
113
113
114 $ hg up -qC .
114 $ hg up -qC .
115 $ hg merge -v --tool internal:dump 5 --config merge.preferancestor="null 40663881 3b08d"
115 $ hg merge -v --tool internal:dump 5 --config merge.preferancestor="null 40663881 3b08d"
116 note: using 40663881a6dd as ancestor of 3b08d01b0ab5 and adfe50279922
116 note: using 40663881a6dd as ancestor of 3b08d01b0ab5 and adfe50279922
117 alternatively, use --config merge.preferancestor=0f6b37dbe527
117 alternatively, use --config merge.preferancestor=0f6b37dbe527
118 resolving manifests
118 resolving manifests
119 merging f1
119 merging f1
120 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
120 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
121 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
121 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
122 [1]
122 [1]
123
123
124 Redo merge with merge.preferancestor="*" to enable bid merge
124 Redo merge with merge.preferancestor="*" to enable bid merge
125
125
126 $ rm f*
126 $ rm f*
127 $ hg up -qC .
127 $ hg up -qC .
128 $ hg merge -v --debug --tool internal:dump 5 --config merge.preferancestor="*"
128 $ hg merge -v --debug --tool internal:dump 5 --config merge.preferancestor="*"
129 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
129 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
130
130
131 calculating bids for ancestor 0f6b37dbe527
131 calculating bids for ancestor 0f6b37dbe527
132 searching for copies back to rev 3
132 searching for copies back to rev 3
133 resolving manifests
133 resolving manifests
134 branchmerge: True, force: False, partial: False
134 branchmerge: True, force: False, partial: False
135 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
135 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
136 f1: remote is newer -> g
136 f1: remote is newer -> g
137 f2: versions differ -> m
137 f2: versions differ -> m
138
138
139 calculating bids for ancestor 40663881a6dd
139 calculating bids for ancestor 40663881a6dd
140 searching for copies back to rev 3
140 searching for copies back to rev 3
141 resolving manifests
141 resolving manifests
142 branchmerge: True, force: False, partial: False
142 branchmerge: True, force: False, partial: False
143 ancestor: 40663881a6dd, local: 3b08d01b0ab5+, remote: adfe50279922
143 ancestor: 40663881a6dd, local: 3b08d01b0ab5+, remote: adfe50279922
144 f2: keep -> k
144 f2: keep -> k
145 f1: versions differ -> m
145 f1: versions differ -> m
146
146
147 auction for merging merge bids
147 auction for merging merge bids
148 f1: picking 'get' action
148 f1: picking 'get' action
149 f2: picking 'keep' action
149 f2: picking 'keep' action
150 end of auction
150 end of auction
151
151
152 f1: remote is newer -> g
152 f1: remote is newer -> g
153 getting f1
153 getting f1
154 updating: f1 1/1 files (100.00%)
154 updating: f1 1/1 files (100.00%)
155 f2: keep -> k
155 f2: keep -> k
156 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
156 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
157 (branch merge, don't forget to commit)
157 (branch merge, don't forget to commit)
158
158
159 $ head *
159 $ head *
160 ==> f1 <==
160 ==> f1 <==
161 5 second change
161 5 second change
162
162
163 ==> f2 <==
163 ==> f2 <==
164 6 second change
164 6 second change
165
165
166
166
167 The other way around:
167 The other way around:
168
168
169 $ hg up -C -r5
169 $ hg up -C -r5
170 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
170 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
171 $ hg merge -v --debug --config merge.preferancestor="*"
171 $ hg merge -v --debug --config merge.preferancestor="*"
172 note: merging adfe50279922+ and 3b08d01b0ab5 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
172 note: merging adfe50279922+ and 3b08d01b0ab5 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
173
173
174 calculating bids for ancestor 0f6b37dbe527
174 calculating bids for ancestor 0f6b37dbe527
175 searching for copies back to rev 3
175 searching for copies back to rev 3
176 resolving manifests
176 resolving manifests
177 branchmerge: True, force: False, partial: False
177 branchmerge: True, force: False, partial: False
178 ancestor: 0f6b37dbe527, local: adfe50279922+, remote: 3b08d01b0ab5
178 ancestor: 0f6b37dbe527, local: adfe50279922+, remote: 3b08d01b0ab5
179 f1: keep -> k
179 f1: keep -> k
180 f2: versions differ -> m
180 f2: versions differ -> m
181
181
182 calculating bids for ancestor 40663881a6dd
182 calculating bids for ancestor 40663881a6dd
183 searching for copies back to rev 3
183 searching for copies back to rev 3
184 resolving manifests
184 resolving manifests
185 branchmerge: True, force: False, partial: False
185 branchmerge: True, force: False, partial: False
186 ancestor: 40663881a6dd, local: adfe50279922+, remote: 3b08d01b0ab5
186 ancestor: 40663881a6dd, local: adfe50279922+, remote: 3b08d01b0ab5
187 f2: remote is newer -> g
187 f2: remote is newer -> g
188 f1: versions differ -> m
188 f1: versions differ -> m
189
189
190 auction for merging merge bids
190 auction for merging merge bids
191 f1: picking 'keep' action
191 f1: picking 'keep' action
192 f2: picking 'get' action
192 f2: picking 'get' action
193 end of auction
193 end of auction
194
194
195 f2: remote is newer -> g
195 f2: remote is newer -> g
196 getting f2
196 getting f2
197 updating: f2 1/1 files (100.00%)
197 updating: f2 1/1 files (100.00%)
198 f1: keep -> k
198 f1: keep -> k
199 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
199 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
200 (branch merge, don't forget to commit)
200 (branch merge, don't forget to commit)
201
201
202 $ head *
202 $ head *
203 ==> f1 <==
203 ==> f1 <==
204 5 second change
204 5 second change
205
205
206 ==> f2 <==
206 ==> f2 <==
207 6 second change
207 6 second change
208
208
209 Verify how the output looks and and how verbose it is:
209 Verify how the output looks and and how verbose it is:
210
210
211 $ hg up -qC
211 $ hg up -qC
212 $ hg merge --config merge.preferancestor="*"
212 $ hg merge --config merge.preferancestor="*"
213 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
213 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
214 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
214 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
215 (branch merge, don't forget to commit)
215 (branch merge, don't forget to commit)
216
216
217 $ hg up -qC
217 $ hg up -qC
218 $ hg merge -v --config merge.preferancestor="*"
218 $ hg merge -v --config merge.preferancestor="*"
219 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
219 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
220
220
221 calculating bids for ancestor 0f6b37dbe527
221 calculating bids for ancestor 0f6b37dbe527
222 resolving manifests
222 resolving manifests
223
223
224 calculating bids for ancestor 40663881a6dd
224 calculating bids for ancestor 40663881a6dd
225 resolving manifests
225 resolving manifests
226
226
227 auction for merging merge bids
227 auction for merging merge bids
228 f1: picking 'get' action
228 f1: picking 'get' action
229 f2: picking 'keep' action
229 f2: picking 'keep' action
230 end of auction
230 end of auction
231
231
232 getting f1
232 getting f1
233 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
233 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
234 (branch merge, don't forget to commit)
234 (branch merge, don't forget to commit)
235
235
236 $ hg up -qC
236 $ hg up -qC
237 $ hg merge -v --debug --config merge.preferancestor="*"
237 $ hg merge -v --debug --config merge.preferancestor="*"
238 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
238 note: merging 3b08d01b0ab5+ and adfe50279922 using bids from ancestors 0f6b37dbe527 and 40663881a6dd
239
239
240 calculating bids for ancestor 0f6b37dbe527
240 calculating bids for ancestor 0f6b37dbe527
241 searching for copies back to rev 3
241 searching for copies back to rev 3
242 resolving manifests
242 resolving manifests
243 branchmerge: True, force: False, partial: False
243 branchmerge: True, force: False, partial: False
244 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
244 ancestor: 0f6b37dbe527, local: 3b08d01b0ab5+, remote: adfe50279922
245 f1: remote is newer -> g
245 f1: remote is newer -> g
246 f2: versions differ -> m
246 f2: versions differ -> m
247
247
248 calculating bids for ancestor 40663881a6dd
248 calculating bids for ancestor 40663881a6dd
249 searching for copies back to rev 3
249 searching for copies back to rev 3
250 resolving manifests
250 resolving manifests
251 branchmerge: True, force: False, partial: False
251 branchmerge: True, force: False, partial: False
252 ancestor: 40663881a6dd, local: 3b08d01b0ab5+, remote: adfe50279922
252 ancestor: 40663881a6dd, local: 3b08d01b0ab5+, remote: adfe50279922
253 f2: keep -> k
253 f2: keep -> k
254 f1: versions differ -> m
254 f1: versions differ -> m
255
255
256 auction for merging merge bids
256 auction for merging merge bids
257 f1: picking 'get' action
257 f1: picking 'get' action
258 f2: picking 'keep' action
258 f2: picking 'keep' action
259 end of auction
259 end of auction
260
260
261 f1: remote is newer -> g
261 f1: remote is newer -> g
262 getting f1
262 getting f1
263 updating: f1 1/1 files (100.00%)
263 updating: f1 1/1 files (100.00%)
264 f2: keep -> k
264 f2: keep -> k
265 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
265 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
266 (branch merge, don't forget to commit)
266 (branch merge, don't forget to commit)
267
267
268 $ cd ..
268 $ cd ..
269
269
270 http://stackoverflow.com/questions/9350005/how-do-i-specify-a-merge-base-to-use-in-a-hg-merge/9430810
270 http://stackoverflow.com/questions/9350005/how-do-i-specify-a-merge-base-to-use-in-a-hg-merge/9430810
271
271
272 $ hg init ancestor-merging
272 $ hg init ancestor-merging
273 $ cd ancestor-merging
273 $ cd ancestor-merging
274 $ echo a > x
274 $ echo a > x
275 $ hg commit -A -m a x
275 $ hg commit -A -m a x
276 $ hg update -q 0
276 $ hg update -q 0
277 $ echo b >> x
277 $ echo b >> x
278 $ hg commit -m b
278 $ hg commit -m b
279 $ hg update -q 0
279 $ hg update -q 0
280 $ echo c >> x
280 $ echo c >> x
281 $ hg commit -qm c
281 $ hg commit -qm c
282 $ hg update -q 1
282 $ hg update -q 1
283 $ hg merge -q --tool internal:local 2
283 $ hg merge -q --tool internal:local 2
284 $ echo c >> x
284 $ echo c >> x
285 $ hg commit -m bc
285 $ hg commit -m bc
286 $ hg update -q 2
286 $ hg update -q 2
287 $ hg merge -q --tool internal:local 1
287 $ hg merge -q --tool internal:local 1
288 $ echo b >> x
288 $ echo b >> x
289 $ hg commit -qm cb
289 $ hg commit -qm cb
290
290
291 $ hg merge
291 $ hg merge
292 note: using 70008a2163f6 as ancestor of 0d355fdef312 and 4b8b546a3eef
292 note: using 70008a2163f6 as ancestor of 0d355fdef312 and 4b8b546a3eef
293 alternatively, use --config merge.preferancestor=b211bbc6eb3c
293 alternatively, use --config merge.preferancestor=b211bbc6eb3c
294 merging x
294 merging x
295 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
295 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
296 (branch merge, don't forget to commit)
296 (branch merge, don't forget to commit)
297 $ cat x
297 $ cat x
298 a
298 a
299 c
299 c
300 b
300 b
301 c
301 c
302
302
303 $ hg up -qC .
303 $ hg up -qC .
304
304
305 $ hg merge --config merge.preferancestor=b211bbc6eb3c
305 $ hg merge --config merge.preferancestor=b211bbc6eb3c
306 note: using b211bbc6eb3c as ancestor of 0d355fdef312 and 4b8b546a3eef
306 note: using b211bbc6eb3c as ancestor of 0d355fdef312 and 4b8b546a3eef
307 alternatively, use --config merge.preferancestor=70008a2163f6
307 alternatively, use --config merge.preferancestor=70008a2163f6
308 merging x
308 merging x
309 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
309 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
310 (branch merge, don't forget to commit)
310 (branch merge, don't forget to commit)
311 $ cat x
311 $ cat x
312 a
312 a
313 b
313 b
314 c
314 c
315 b
315 b
316
316
317 $ hg up -qC .
317 $ hg up -qC .
318
318
319 $ hg merge -v --config merge.preferancestor="*"
319 $ hg merge -v --config merge.preferancestor="*"
320 note: merging 0d355fdef312+ and 4b8b546a3eef using bids from ancestors 70008a2163f6 and b211bbc6eb3c
320 note: merging 0d355fdef312+ and 4b8b546a3eef using bids from ancestors 70008a2163f6 and b211bbc6eb3c
321
321
322 calculating bids for ancestor 70008a2163f6
322 calculating bids for ancestor 70008a2163f6
323 resolving manifests
323 resolving manifests
324
324
325 calculating bids for ancestor b211bbc6eb3c
325 calculating bids for ancestor b211bbc6eb3c
326 resolving manifests
326 resolving manifests
327
327
328 auction for merging merge bids
328 auction for merging merge bids
329 x: multiple bids for merge action:
329 x: multiple bids for merge action:
330 versions differ -> m
330 versions differ -> m
331 versions differ -> m
331 versions differ -> m
332 x: ambiguous merge - picked m action
332 x: ambiguous merge - picked m action
333 end of auction
333 end of auction
334
334
335 merging x
335 merging x
336 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
336 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
337 (branch merge, don't forget to commit)
337 (branch merge, don't forget to commit)
338 $ cat x
338 $ cat x
339 a
339 a
340 c
340 c
341 b
341 b
342 c
342 c
343
343
344 Verify that the old context ancestor works with / despite preferancestor:
344 Verify that the old context ancestor works with / despite preferancestor:
345
345
346 $ hg log -r 'ancestor(head())' --config merge.preferancestor=1 -T '{rev}\n'
346 $ hg log -r 'ancestor(head())' --config merge.preferancestor=1 -T '{rev}\n'
347 1
347 1
348 $ hg log -r 'ancestor(head())' --config merge.preferancestor=2 -T '{rev}\n'
348 $ hg log -r 'ancestor(head())' --config merge.preferancestor=2 -T '{rev}\n'
349 2
349 2
350 $ hg log -r 'ancestor(head())' --config merge.preferancestor=3 -T '{rev}\n'
350 $ hg log -r 'ancestor(head())' --config merge.preferancestor=3 -T '{rev}\n'
351 1
351 1
352 $ hg log -r 'ancestor(head())' --config merge.preferancestor='*' -T '{rev}\n'
352 $ hg log -r 'ancestor(head())' --config merge.preferancestor='1337 * - 2' -T '{rev}\n'
353 1
353 2
354
354
355 $ cd ..
355 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now