Show More
@@ -1,2557 +1,2563 b'' | |||
|
1 | 1 | # context.py - changeset and file context objects for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import errno |
|
11 | 11 | import filecmp |
|
12 | 12 | import os |
|
13 | 13 | import stat |
|
14 | 14 | |
|
15 | 15 | from .i18n import _ |
|
16 | 16 | from .node import ( |
|
17 | 17 | addednodeid, |
|
18 | 18 | bin, |
|
19 | 19 | hex, |
|
20 | 20 | modifiednodeid, |
|
21 | 21 | nullid, |
|
22 | 22 | nullrev, |
|
23 | 23 | short, |
|
24 | 24 | wdirfilenodeids, |
|
25 | 25 | wdirid, |
|
26 | 26 | ) |
|
27 | 27 | from . import ( |
|
28 | 28 | dagop, |
|
29 | 29 | encoding, |
|
30 | 30 | error, |
|
31 | 31 | fileset, |
|
32 | 32 | match as matchmod, |
|
33 | 33 | obsolete as obsmod, |
|
34 | 34 | patch, |
|
35 | 35 | pathutil, |
|
36 | 36 | phases, |
|
37 | 37 | pycompat, |
|
38 | 38 | repoview, |
|
39 | 39 | revlog, |
|
40 | 40 | scmutil, |
|
41 | 41 | sparse, |
|
42 | 42 | subrepo, |
|
43 | 43 | subrepoutil, |
|
44 | 44 | util, |
|
45 | 45 | ) |
|
46 | 46 | from .utils import ( |
|
47 | 47 | dateutil, |
|
48 | 48 | stringutil, |
|
49 | 49 | ) |
|
50 | 50 | |
|
51 | 51 | propertycache = util.propertycache |
|
52 | 52 | |
|
53 | 53 | class basectx(object): |
|
54 | 54 | """A basectx object represents the common logic for its children: |
|
55 | 55 | changectx: read-only context that is already present in the repo, |
|
56 | 56 | workingctx: a context that represents the working directory and can |
|
57 | 57 | be committed, |
|
58 | 58 | memctx: a context that represents changes in-memory and can also |
|
59 | 59 | be committed.""" |
|
60 | 60 | |
|
61 | 61 | def __init__(self, repo): |
|
62 | 62 | self._repo = repo |
|
63 | 63 | |
|
64 | 64 | def __bytes__(self): |
|
65 | 65 | return short(self.node()) |
|
66 | 66 | |
|
67 | 67 | __str__ = encoding.strmethod(__bytes__) |
|
68 | 68 | |
|
69 | 69 | def __repr__(self): |
|
70 | 70 | return r"<%s %s>" % (type(self).__name__, str(self)) |
|
71 | 71 | |
|
72 | 72 | def __eq__(self, other): |
|
73 | 73 | try: |
|
74 | 74 | return type(self) == type(other) and self._rev == other._rev |
|
75 | 75 | except AttributeError: |
|
76 | 76 | return False |
|
77 | 77 | |
|
78 | 78 | def __ne__(self, other): |
|
79 | 79 | return not (self == other) |
|
80 | 80 | |
|
81 | 81 | def __contains__(self, key): |
|
82 | 82 | return key in self._manifest |
|
83 | 83 | |
|
84 | 84 | def __getitem__(self, key): |
|
85 | 85 | return self.filectx(key) |
|
86 | 86 | |
|
87 | 87 | def __iter__(self): |
|
88 | 88 | return iter(self._manifest) |
|
89 | 89 | |
|
90 | 90 | def _buildstatusmanifest(self, status): |
|
91 | 91 | """Builds a manifest that includes the given status results, if this is |
|
92 | 92 | a working copy context. For non-working copy contexts, it just returns |
|
93 | 93 | the normal manifest.""" |
|
94 | 94 | return self.manifest() |
|
95 | 95 | |
|
96 | 96 | def _matchstatus(self, other, match): |
|
97 | 97 | """This internal method provides a way for child objects to override the |
|
98 | 98 | match operator. |
|
99 | 99 | """ |
|
100 | 100 | return match |
|
101 | 101 | |
|
102 | 102 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
103 | 103 | listunknown): |
|
104 | 104 | """build a status with respect to another context""" |
|
105 | 105 | # Load earliest manifest first for caching reasons. More specifically, |
|
106 | 106 | # if you have revisions 1000 and 1001, 1001 is probably stored as a |
|
107 | 107 | # delta against 1000. Thus, if you read 1000 first, we'll reconstruct |
|
108 | 108 | # 1000 and cache it so that when you read 1001, we just need to apply a |
|
109 | 109 | # delta to what's in the cache. So that's one full reconstruction + one |
|
110 | 110 | # delta application. |
|
111 | 111 | mf2 = None |
|
112 | 112 | if self.rev() is not None and self.rev() < other.rev(): |
|
113 | 113 | mf2 = self._buildstatusmanifest(s) |
|
114 | 114 | mf1 = other._buildstatusmanifest(s) |
|
115 | 115 | if mf2 is None: |
|
116 | 116 | mf2 = self._buildstatusmanifest(s) |
|
117 | 117 | |
|
118 | 118 | modified, added = [], [] |
|
119 | 119 | removed = [] |
|
120 | 120 | clean = [] |
|
121 | 121 | deleted, unknown, ignored = s.deleted, s.unknown, s.ignored |
|
122 | 122 | deletedset = set(deleted) |
|
123 | 123 | d = mf1.diff(mf2, match=match, clean=listclean) |
|
124 | 124 | for fn, value in d.iteritems(): |
|
125 | 125 | if fn in deletedset: |
|
126 | 126 | continue |
|
127 | 127 | if value is None: |
|
128 | 128 | clean.append(fn) |
|
129 | 129 | continue |
|
130 | 130 | (node1, flag1), (node2, flag2) = value |
|
131 | 131 | if node1 is None: |
|
132 | 132 | added.append(fn) |
|
133 | 133 | elif node2 is None: |
|
134 | 134 | removed.append(fn) |
|
135 | 135 | elif flag1 != flag2: |
|
136 | 136 | modified.append(fn) |
|
137 | 137 | elif node2 not in wdirfilenodeids: |
|
138 | 138 | # When comparing files between two commits, we save time by |
|
139 | 139 | # not comparing the file contents when the nodeids differ. |
|
140 | 140 | # Note that this means we incorrectly report a reverted change |
|
141 | 141 | # to a file as a modification. |
|
142 | 142 | modified.append(fn) |
|
143 | 143 | elif self[fn].cmp(other[fn]): |
|
144 | 144 | modified.append(fn) |
|
145 | 145 | else: |
|
146 | 146 | clean.append(fn) |
|
147 | 147 | |
|
148 | 148 | if removed: |
|
149 | 149 | # need to filter files if they are already reported as removed |
|
150 | 150 | unknown = [fn for fn in unknown if fn not in mf1 and |
|
151 | 151 | (not match or match(fn))] |
|
152 | 152 | ignored = [fn for fn in ignored if fn not in mf1 and |
|
153 | 153 | (not match or match(fn))] |
|
154 | 154 | # if they're deleted, don't report them as removed |
|
155 | 155 | removed = [fn for fn in removed if fn not in deletedset] |
|
156 | 156 | |
|
157 | 157 | return scmutil.status(modified, added, removed, deleted, unknown, |
|
158 | 158 | ignored, clean) |
|
159 | 159 | |
|
160 | 160 | @propertycache |
|
161 | 161 | def substate(self): |
|
162 | 162 | return subrepoutil.state(self, self._repo.ui) |
|
163 | 163 | |
|
164 | 164 | def subrev(self, subpath): |
|
165 | 165 | return self.substate[subpath][1] |
|
166 | 166 | |
|
167 | 167 | def rev(self): |
|
168 | 168 | return self._rev |
|
169 | 169 | def node(self): |
|
170 | 170 | return self._node |
|
171 | 171 | def hex(self): |
|
172 | 172 | return hex(self.node()) |
|
173 | 173 | def manifest(self): |
|
174 | 174 | return self._manifest |
|
175 | 175 | def manifestctx(self): |
|
176 | 176 | return self._manifestctx |
|
177 | 177 | def repo(self): |
|
178 | 178 | return self._repo |
|
179 | 179 | def phasestr(self): |
|
180 | 180 | return phases.phasenames[self.phase()] |
|
181 | 181 | def mutable(self): |
|
182 | 182 | return self.phase() > phases.public |
|
183 | 183 | |
|
184 | 184 | def matchfileset(self, expr, badfn=None): |
|
185 | 185 | return fileset.match(self, expr, badfn=badfn) |
|
186 | 186 | |
|
187 | 187 | def obsolete(self): |
|
188 | 188 | """True if the changeset is obsolete""" |
|
189 | 189 | return self.rev() in obsmod.getrevs(self._repo, 'obsolete') |
|
190 | 190 | |
|
191 | 191 | def extinct(self): |
|
192 | 192 | """True if the changeset is extinct""" |
|
193 | 193 | return self.rev() in obsmod.getrevs(self._repo, 'extinct') |
|
194 | 194 | |
|
195 | 195 | def orphan(self): |
|
196 | 196 | """True if the changeset is not obsolete but it's ancestor are""" |
|
197 | 197 | return self.rev() in obsmod.getrevs(self._repo, 'orphan') |
|
198 | 198 | |
|
199 | 199 | def phasedivergent(self): |
|
200 | 200 | """True if the changeset try to be a successor of a public changeset |
|
201 | 201 | |
|
202 | 202 | Only non-public and non-obsolete changesets may be bumped. |
|
203 | 203 | """ |
|
204 | 204 | return self.rev() in obsmod.getrevs(self._repo, 'phasedivergent') |
|
205 | 205 | |
|
206 | 206 | def contentdivergent(self): |
|
207 | 207 | """Is a successors of a changeset with multiple possible successors set |
|
208 | 208 | |
|
209 | 209 | Only non-public and non-obsolete changesets may be divergent. |
|
210 | 210 | """ |
|
211 | 211 | return self.rev() in obsmod.getrevs(self._repo, 'contentdivergent') |
|
212 | 212 | |
|
213 | 213 | def isunstable(self): |
|
214 | 214 | """True if the changeset is either unstable, bumped or divergent""" |
|
215 | 215 | return self.orphan() or self.phasedivergent() or self.contentdivergent() |
|
216 | 216 | |
|
217 | 217 | def instabilities(self): |
|
218 | 218 | """return the list of instabilities affecting this changeset. |
|
219 | 219 | |
|
220 | 220 | Instabilities are returned as strings. possible values are: |
|
221 | 221 | - orphan, |
|
222 | 222 | - phase-divergent, |
|
223 | 223 | - content-divergent. |
|
224 | 224 | """ |
|
225 | 225 | instabilities = [] |
|
226 | 226 | if self.orphan(): |
|
227 | 227 | instabilities.append('orphan') |
|
228 | 228 | if self.phasedivergent(): |
|
229 | 229 | instabilities.append('phase-divergent') |
|
230 | 230 | if self.contentdivergent(): |
|
231 | 231 | instabilities.append('content-divergent') |
|
232 | 232 | return instabilities |
|
233 | 233 | |
|
234 | 234 | def parents(self): |
|
235 | 235 | """return contexts for each parent changeset""" |
|
236 | 236 | return self._parents |
|
237 | 237 | |
|
238 | 238 | def p1(self): |
|
239 | 239 | return self._parents[0] |
|
240 | 240 | |
|
241 | 241 | def p2(self): |
|
242 | 242 | parents = self._parents |
|
243 | 243 | if len(parents) == 2: |
|
244 | 244 | return parents[1] |
|
245 | 245 | return changectx(self._repo, nullrev) |
|
246 | 246 | |
|
247 | 247 | def _fileinfo(self, path): |
|
248 | 248 | if r'_manifest' in self.__dict__: |
|
249 | 249 | try: |
|
250 | 250 | return self._manifest[path], self._manifest.flags(path) |
|
251 | 251 | except KeyError: |
|
252 | 252 | raise error.ManifestLookupError(self._node, path, |
|
253 | 253 | _('not found in manifest')) |
|
254 | 254 | if r'_manifestdelta' in self.__dict__ or path in self.files(): |
|
255 | 255 | if path in self._manifestdelta: |
|
256 | 256 | return (self._manifestdelta[path], |
|
257 | 257 | self._manifestdelta.flags(path)) |
|
258 | 258 | mfl = self._repo.manifestlog |
|
259 | 259 | try: |
|
260 | 260 | node, flag = mfl[self._changeset.manifest].find(path) |
|
261 | 261 | except KeyError: |
|
262 | 262 | raise error.ManifestLookupError(self._node, path, |
|
263 | 263 | _('not found in manifest')) |
|
264 | 264 | |
|
265 | 265 | return node, flag |
|
266 | 266 | |
|
267 | 267 | def filenode(self, path): |
|
268 | 268 | return self._fileinfo(path)[0] |
|
269 | 269 | |
|
270 | 270 | def flags(self, path): |
|
271 | 271 | try: |
|
272 | 272 | return self._fileinfo(path)[1] |
|
273 | 273 | except error.LookupError: |
|
274 | 274 | return '' |
|
275 | 275 | |
|
276 | 276 | def sub(self, path, allowcreate=True): |
|
277 | 277 | '''return a subrepo for the stored revision of path, never wdir()''' |
|
278 | 278 | return subrepo.subrepo(self, path, allowcreate=allowcreate) |
|
279 | 279 | |
|
280 | 280 | def nullsub(self, path, pctx): |
|
281 | 281 | return subrepo.nullsubrepo(self, path, pctx) |
|
282 | 282 | |
|
283 | 283 | def workingsub(self, path): |
|
284 | 284 | '''return a subrepo for the stored revision, or wdir if this is a wdir |
|
285 | 285 | context. |
|
286 | 286 | ''' |
|
287 | 287 | return subrepo.subrepo(self, path, allowwdir=True) |
|
288 | 288 | |
|
289 | 289 | def match(self, pats=None, include=None, exclude=None, default='glob', |
|
290 | 290 | listsubrepos=False, badfn=None): |
|
291 | 291 | r = self._repo |
|
292 | 292 | return matchmod.match(r.root, r.getcwd(), pats, |
|
293 | 293 | include, exclude, default, |
|
294 | 294 | auditor=r.nofsauditor, ctx=self, |
|
295 | 295 | listsubrepos=listsubrepos, badfn=badfn) |
|
296 | 296 | |
|
297 | 297 | def diff(self, ctx2=None, match=None, changes=None, opts=None, |
|
298 | 298 | losedatafn=None, prefix='', relroot='', copy=None, |
|
299 | 299 | hunksfilterfn=None): |
|
300 | 300 | """Returns a diff generator for the given contexts and matcher""" |
|
301 | 301 | if ctx2 is None: |
|
302 | 302 | ctx2 = self.p1() |
|
303 | 303 | if ctx2 is not None: |
|
304 | 304 | ctx2 = self._repo[ctx2] |
|
305 | 305 | return patch.diff(self._repo, ctx2, self, match=match, changes=changes, |
|
306 | 306 | opts=opts, losedatafn=losedatafn, prefix=prefix, |
|
307 | 307 | relroot=relroot, copy=copy, |
|
308 | 308 | hunksfilterfn=hunksfilterfn) |
|
309 | 309 | |
|
310 | 310 | def dirs(self): |
|
311 | 311 | return self._manifest.dirs() |
|
312 | 312 | |
|
313 | 313 | def hasdir(self, dir): |
|
314 | 314 | return self._manifest.hasdir(dir) |
|
315 | 315 | |
|
316 | 316 | def status(self, other=None, match=None, listignored=False, |
|
317 | 317 | listclean=False, listunknown=False, listsubrepos=False): |
|
318 | 318 | """return status of files between two nodes or node and working |
|
319 | 319 | directory. |
|
320 | 320 | |
|
321 | 321 | If other is None, compare this node with working directory. |
|
322 | 322 | |
|
323 | 323 | returns (modified, added, removed, deleted, unknown, ignored, clean) |
|
324 | 324 | """ |
|
325 | 325 | |
|
326 | 326 | ctx1 = self |
|
327 | 327 | ctx2 = self._repo[other] |
|
328 | 328 | |
|
329 | 329 | # This next code block is, admittedly, fragile logic that tests for |
|
330 | 330 | # reversing the contexts and wouldn't need to exist if it weren't for |
|
331 | 331 | # the fast (and common) code path of comparing the working directory |
|
332 | 332 | # with its first parent. |
|
333 | 333 | # |
|
334 | 334 | # What we're aiming for here is the ability to call: |
|
335 | 335 | # |
|
336 | 336 | # workingctx.status(parentctx) |
|
337 | 337 | # |
|
338 | 338 | # If we always built the manifest for each context and compared those, |
|
339 | 339 | # then we'd be done. But the special case of the above call means we |
|
340 | 340 | # just copy the manifest of the parent. |
|
341 | 341 | reversed = False |
|
342 | 342 | if (not isinstance(ctx1, changectx) |
|
343 | 343 | and isinstance(ctx2, changectx)): |
|
344 | 344 | reversed = True |
|
345 | 345 | ctx1, ctx2 = ctx2, ctx1 |
|
346 | 346 | |
|
347 | 347 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
348 | 348 | match = ctx2._matchstatus(ctx1, match) |
|
349 | 349 | r = scmutil.status([], [], [], [], [], [], []) |
|
350 | 350 | r = ctx2._buildstatus(ctx1, r, match, listignored, listclean, |
|
351 | 351 | listunknown) |
|
352 | 352 | |
|
353 | 353 | if reversed: |
|
354 | 354 | # Reverse added and removed. Clear deleted, unknown and ignored as |
|
355 | 355 | # these make no sense to reverse. |
|
356 | 356 | r = scmutil.status(r.modified, r.removed, r.added, [], [], [], |
|
357 | 357 | r.clean) |
|
358 | 358 | |
|
359 | 359 | if listsubrepos: |
|
360 | 360 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
|
361 | 361 | try: |
|
362 | 362 | rev2 = ctx2.subrev(subpath) |
|
363 | 363 | except KeyError: |
|
364 | 364 | # A subrepo that existed in node1 was deleted between |
|
365 | 365 | # node1 and node2 (inclusive). Thus, ctx2's substate |
|
366 | 366 | # won't contain that subpath. The best we can do ignore it. |
|
367 | 367 | rev2 = None |
|
368 | 368 | submatch = matchmod.subdirmatcher(subpath, match) |
|
369 | 369 | s = sub.status(rev2, match=submatch, ignored=listignored, |
|
370 | 370 | clean=listclean, unknown=listunknown, |
|
371 | 371 | listsubrepos=True) |
|
372 | 372 | for rfiles, sfiles in zip(r, s): |
|
373 | 373 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) |
|
374 | 374 | |
|
375 | 375 | for l in r: |
|
376 | 376 | l.sort() |
|
377 | 377 | |
|
378 | 378 | return r |
|
379 | 379 | |
|
380 | 380 | class changectx(basectx): |
|
381 | 381 | """A changecontext object makes access to data related to a particular |
|
382 | 382 | changeset convenient. It represents a read-only context already present in |
|
383 | 383 | the repo.""" |
|
384 | 384 | def __init__(self, repo, changeid='.'): |
|
385 | 385 | """changeid is a revision number, node, or tag""" |
|
386 | 386 | super(changectx, self).__init__(repo) |
|
387 | 387 | |
|
388 | 388 | try: |
|
389 | 389 | if isinstance(changeid, int): |
|
390 | 390 | self._node = repo.changelog.node(changeid) |
|
391 | 391 | self._rev = changeid |
|
392 | 392 | return |
|
393 | 393 | elif changeid == 'null': |
|
394 | 394 | self._node = nullid |
|
395 | 395 | self._rev = nullrev |
|
396 | 396 | return |
|
397 | 397 | elif changeid == 'tip': |
|
398 | 398 | self._node = repo.changelog.tip() |
|
399 | 399 | self._rev = repo.changelog.rev(self._node) |
|
400 | 400 | return |
|
401 | 401 | elif (changeid == '.' |
|
402 | 402 | or repo.local() and changeid == repo.dirstate.p1()): |
|
403 | 403 | # this is a hack to delay/avoid loading obsmarkers |
|
404 | 404 | # when we know that '.' won't be hidden |
|
405 | 405 | self._node = repo.dirstate.p1() |
|
406 | 406 | self._rev = repo.unfiltered().changelog.rev(self._node) |
|
407 | 407 | return |
|
408 | 408 | elif len(changeid) == 20: |
|
409 | 409 | try: |
|
410 | 410 | self._node = changeid |
|
411 | 411 | self._rev = repo.changelog.rev(changeid) |
|
412 | 412 | return |
|
413 | 413 | except error.FilteredLookupError: |
|
414 | 414 | changeid = hex(changeid) # for the error message |
|
415 | 415 | raise |
|
416 | 416 | except LookupError: |
|
417 | 417 | # check if it might have come from damaged dirstate |
|
418 | 418 | # |
|
419 | 419 | # XXX we could avoid the unfiltered if we had a recognizable |
|
420 | 420 | # exception for filtered changeset access |
|
421 | 421 | if (repo.local() |
|
422 | 422 | and changeid in repo.unfiltered().dirstate.parents()): |
|
423 | 423 | msg = _("working directory has unknown parent '%s'!") |
|
424 | 424 | raise error.Abort(msg % short(changeid)) |
|
425 | 425 | changeid = hex(changeid) # for the error message |
|
426 | 426 | |
|
427 | 427 | elif len(changeid) == 40: |
|
428 | 428 | try: |
|
429 | 429 | self._node = bin(changeid) |
|
430 | 430 | self._rev = repo.changelog.rev(self._node) |
|
431 | 431 | return |
|
432 | 432 | except error.FilteredLookupError: |
|
433 | 433 | raise |
|
434 | 434 | except (TypeError, LookupError): |
|
435 | 435 | pass |
|
436 | 436 | else: |
|
437 | 437 | raise error.ProgrammingError( |
|
438 | 438 | "unsupported changeid '%s' of type %s" % |
|
439 | 439 | (changeid, type(changeid))) |
|
440 | 440 | |
|
441 | 441 | # lookup failed |
|
442 | 442 | except (error.FilteredIndexError, error.FilteredLookupError): |
|
443 | 443 | raise error.FilteredRepoLookupError(_("filtered revision '%s'") |
|
444 | 444 | % pycompat.bytestr(changeid)) |
|
445 | 445 | except error.FilteredRepoLookupError: |
|
446 | 446 | raise |
|
447 | 447 | except IndexError: |
|
448 | 448 | pass |
|
449 | 449 | raise error.RepoLookupError( |
|
450 | 450 | _("unknown revision '%s'") % changeid) |
|
451 | 451 | |
|
452 | 452 | def __hash__(self): |
|
453 | 453 | try: |
|
454 | 454 | return hash(self._rev) |
|
455 | 455 | except AttributeError: |
|
456 | 456 | return id(self) |
|
457 | 457 | |
|
458 | 458 | def __nonzero__(self): |
|
459 | 459 | return self._rev != nullrev |
|
460 | 460 | |
|
461 | 461 | __bool__ = __nonzero__ |
|
462 | 462 | |
|
463 | 463 | @propertycache |
|
464 | 464 | def _changeset(self): |
|
465 | 465 | return self._repo.changelog.changelogrevision(self.rev()) |
|
466 | 466 | |
|
467 | 467 | @propertycache |
|
468 | 468 | def _manifest(self): |
|
469 | 469 | return self._manifestctx.read() |
|
470 | 470 | |
|
471 | 471 | @property |
|
472 | 472 | def _manifestctx(self): |
|
473 | 473 | return self._repo.manifestlog[self._changeset.manifest] |
|
474 | 474 | |
|
475 | 475 | @propertycache |
|
476 | 476 | def _manifestdelta(self): |
|
477 | 477 | return self._manifestctx.readdelta() |
|
478 | 478 | |
|
479 | 479 | @propertycache |
|
480 | 480 | def _parents(self): |
|
481 | 481 | repo = self._repo |
|
482 | 482 | p1, p2 = repo.changelog.parentrevs(self._rev) |
|
483 | 483 | if p2 == nullrev: |
|
484 | 484 | return [changectx(repo, p1)] |
|
485 | 485 | return [changectx(repo, p1), changectx(repo, p2)] |
|
486 | 486 | |
|
487 | 487 | def changeset(self): |
|
488 | 488 | c = self._changeset |
|
489 | 489 | return ( |
|
490 | 490 | c.manifest, |
|
491 | 491 | c.user, |
|
492 | 492 | c.date, |
|
493 | 493 | c.files, |
|
494 | 494 | c.description, |
|
495 | 495 | c.extra, |
|
496 | 496 | ) |
|
497 | 497 | def manifestnode(self): |
|
498 | 498 | return self._changeset.manifest |
|
499 | 499 | |
|
500 | 500 | def user(self): |
|
501 | 501 | return self._changeset.user |
|
502 | 502 | def date(self): |
|
503 | 503 | return self._changeset.date |
|
504 | 504 | def files(self): |
|
505 | 505 | return self._changeset.files |
|
506 | 506 | def description(self): |
|
507 | 507 | return self._changeset.description |
|
508 | 508 | def branch(self): |
|
509 | 509 | return encoding.tolocal(self._changeset.extra.get("branch")) |
|
510 | 510 | def closesbranch(self): |
|
511 | 511 | return 'close' in self._changeset.extra |
|
512 | 512 | def extra(self): |
|
513 | 513 | """Return a dict of extra information.""" |
|
514 | 514 | return self._changeset.extra |
|
515 | 515 | def tags(self): |
|
516 | 516 | """Return a list of byte tag names""" |
|
517 | 517 | return self._repo.nodetags(self._node) |
|
518 | 518 | def bookmarks(self): |
|
519 | 519 | """Return a list of byte bookmark names.""" |
|
520 | 520 | return self._repo.nodebookmarks(self._node) |
|
521 | 521 | def phase(self): |
|
522 | 522 | return self._repo._phasecache.phase(self._repo, self._rev) |
|
523 | 523 | def hidden(self): |
|
524 | 524 | return self._rev in repoview.filterrevs(self._repo, 'visible') |
|
525 | 525 | |
|
526 | 526 | def isinmemory(self): |
|
527 | 527 | return False |
|
528 | 528 | |
|
529 | 529 | def children(self): |
|
530 | 530 | """return list of changectx contexts for each child changeset. |
|
531 | 531 | |
|
532 | 532 | This returns only the immediate child changesets. Use descendants() to |
|
533 | 533 | recursively walk children. |
|
534 | 534 | """ |
|
535 | 535 | c = self._repo.changelog.children(self._node) |
|
536 | 536 | return [changectx(self._repo, x) for x in c] |
|
537 | 537 | |
|
538 | 538 | def ancestors(self): |
|
539 | 539 | for a in self._repo.changelog.ancestors([self._rev]): |
|
540 | 540 | yield changectx(self._repo, a) |
|
541 | 541 | |
|
542 | 542 | def descendants(self): |
|
543 | 543 | """Recursively yield all children of the changeset. |
|
544 | 544 | |
|
545 | 545 | For just the immediate children, use children() |
|
546 | 546 | """ |
|
547 | 547 | for d in self._repo.changelog.descendants([self._rev]): |
|
548 | 548 | yield changectx(self._repo, d) |
|
549 | 549 | |
|
550 | 550 | def filectx(self, path, fileid=None, filelog=None): |
|
551 | 551 | """get a file context from this changeset""" |
|
552 | 552 | if fileid is None: |
|
553 | 553 | fileid = self.filenode(path) |
|
554 | 554 | return filectx(self._repo, path, fileid=fileid, |
|
555 | 555 | changectx=self, filelog=filelog) |
|
556 | 556 | |
|
557 | 557 | def ancestor(self, c2, warn=False): |
|
558 | 558 | """return the "best" ancestor context of self and c2 |
|
559 | 559 | |
|
560 | 560 | If there are multiple candidates, it will show a message and check |
|
561 | 561 | merge.preferancestor configuration before falling back to the |
|
562 | 562 | revlog ancestor.""" |
|
563 | 563 | # deal with workingctxs |
|
564 | 564 | n2 = c2._node |
|
565 | 565 | if n2 is None: |
|
566 | 566 | n2 = c2._parents[0]._node |
|
567 | 567 | cahs = self._repo.changelog.commonancestorsheads(self._node, n2) |
|
568 | 568 | if not cahs: |
|
569 | 569 | anc = nullid |
|
570 | 570 | elif len(cahs) == 1: |
|
571 | 571 | anc = cahs[0] |
|
572 | 572 | else: |
|
573 | 573 | # experimental config: merge.preferancestor |
|
574 | 574 | for r in self._repo.ui.configlist('merge', 'preferancestor'): |
|
575 | 575 | try: |
|
576 | 576 | ctx = scmutil.revsymbol(self._repo, r) |
|
577 | 577 | except error.RepoLookupError: |
|
578 | 578 | continue |
|
579 | 579 | anc = ctx.node() |
|
580 | 580 | if anc in cahs: |
|
581 | 581 | break |
|
582 | 582 | else: |
|
583 | 583 | anc = self._repo.changelog.ancestor(self._node, n2) |
|
584 | 584 | if warn: |
|
585 | 585 | self._repo.ui.status( |
|
586 | 586 | (_("note: using %s as ancestor of %s and %s\n") % |
|
587 | 587 | (short(anc), short(self._node), short(n2))) + |
|
588 | 588 | ''.join(_(" alternatively, use --config " |
|
589 | 589 | "merge.preferancestor=%s\n") % |
|
590 | 590 | short(n) for n in sorted(cahs) if n != anc)) |
|
591 | 591 | return changectx(self._repo, anc) |
|
592 | 592 | |
|
593 | 593 | def descendant(self, other): |
|
594 | 594 | msg = (b'ctx.descendant(other) is deprecated, ' |
|
595 | 595 | b'use ctx.isancestorof(other)') |
|
596 | 596 | self._repo.ui.deprecwarn(msg, b'4.7') |
|
597 | 597 | return self.isancestorof(other) |
|
598 | 598 | |
|
599 | 599 | def isancestorof(self, other): |
|
600 | 600 | """True if this changeset is an ancestor of other""" |
|
601 | 601 | return self._repo.changelog.isancestorrev(self._rev, other._rev) |
|
602 | 602 | |
|
603 | 603 | def walk(self, match): |
|
604 | 604 | '''Generates matching file names.''' |
|
605 | 605 | |
|
606 | 606 | # Wrap match.bad method to have message with nodeid |
|
607 | 607 | def bad(fn, msg): |
|
608 | 608 | # The manifest doesn't know about subrepos, so don't complain about |
|
609 | 609 | # paths into valid subrepos. |
|
610 | 610 | if any(fn == s or fn.startswith(s + '/') |
|
611 | 611 | for s in self.substate): |
|
612 | 612 | return |
|
613 | 613 | match.bad(fn, _('no such file in rev %s') % self) |
|
614 | 614 | |
|
615 | 615 | m = matchmod.badmatch(match, bad) |
|
616 | 616 | return self._manifest.walk(m) |
|
617 | 617 | |
|
618 | 618 | def matches(self, match): |
|
619 | 619 | return self.walk(match) |
|
620 | 620 | |
|
621 | 621 | class basefilectx(object): |
|
622 | 622 | """A filecontext object represents the common logic for its children: |
|
623 | 623 | filectx: read-only access to a filerevision that is already present |
|
624 | 624 | in the repo, |
|
625 | 625 | workingfilectx: a filecontext that represents files from the working |
|
626 | 626 | directory, |
|
627 | 627 | memfilectx: a filecontext that represents files in-memory, |
|
628 | 628 | overlayfilectx: duplicate another filecontext with some fields overridden. |
|
629 | 629 | """ |
|
630 | 630 | @propertycache |
|
631 | 631 | def _filelog(self): |
|
632 | 632 | return self._repo.file(self._path) |
|
633 | 633 | |
|
634 | 634 | @propertycache |
|
635 | 635 | def _changeid(self): |
|
636 | 636 | if r'_changeid' in self.__dict__: |
|
637 | 637 | return self._changeid |
|
638 | 638 | elif r'_changectx' in self.__dict__: |
|
639 | 639 | return self._changectx.rev() |
|
640 | 640 | elif r'_descendantrev' in self.__dict__: |
|
641 | 641 | # this file context was created from a revision with a known |
|
642 | 642 | # descendant, we can (lazily) correct for linkrev aliases |
|
643 | 643 | return self._adjustlinkrev(self._descendantrev) |
|
644 | 644 | else: |
|
645 | 645 | return self._filelog.linkrev(self._filerev) |
|
646 | 646 | |
|
647 | 647 | @propertycache |
|
648 | 648 | def _filenode(self): |
|
649 | 649 | if r'_fileid' in self.__dict__: |
|
650 | 650 | return self._filelog.lookup(self._fileid) |
|
651 | 651 | else: |
|
652 | 652 | return self._changectx.filenode(self._path) |
|
653 | 653 | |
|
654 | 654 | @propertycache |
|
655 | 655 | def _filerev(self): |
|
656 | 656 | return self._filelog.rev(self._filenode) |
|
657 | 657 | |
|
658 | 658 | @propertycache |
|
659 | 659 | def _repopath(self): |
|
660 | 660 | return self._path |
|
661 | 661 | |
|
662 | 662 | def __nonzero__(self): |
|
663 | 663 | try: |
|
664 | 664 | self._filenode |
|
665 | 665 | return True |
|
666 | 666 | except error.LookupError: |
|
667 | 667 | # file is missing |
|
668 | 668 | return False |
|
669 | 669 | |
|
670 | 670 | __bool__ = __nonzero__ |
|
671 | 671 | |
|
672 | 672 | def __bytes__(self): |
|
673 | 673 | try: |
|
674 | 674 | return "%s@%s" % (self.path(), self._changectx) |
|
675 | 675 | except error.LookupError: |
|
676 | 676 | return "%s@???" % self.path() |
|
677 | 677 | |
|
678 | 678 | __str__ = encoding.strmethod(__bytes__) |
|
679 | 679 | |
|
680 | 680 | def __repr__(self): |
|
681 | 681 | return r"<%s %s>" % (type(self).__name__, str(self)) |
|
682 | 682 | |
|
683 | 683 | def __hash__(self): |
|
684 | 684 | try: |
|
685 | 685 | return hash((self._path, self._filenode)) |
|
686 | 686 | except AttributeError: |
|
687 | 687 | return id(self) |
|
688 | 688 | |
|
689 | 689 | def __eq__(self, other): |
|
690 | 690 | try: |
|
691 | 691 | return (type(self) == type(other) and self._path == other._path |
|
692 | 692 | and self._filenode == other._filenode) |
|
693 | 693 | except AttributeError: |
|
694 | 694 | return False |
|
695 | 695 | |
|
696 | 696 | def __ne__(self, other): |
|
697 | 697 | return not (self == other) |
|
698 | 698 | |
|
699 | 699 | def filerev(self): |
|
700 | 700 | return self._filerev |
|
701 | 701 | def filenode(self): |
|
702 | 702 | return self._filenode |
|
703 | 703 | @propertycache |
|
704 | 704 | def _flags(self): |
|
705 | 705 | return self._changectx.flags(self._path) |
|
706 | 706 | def flags(self): |
|
707 | 707 | return self._flags |
|
708 | 708 | def filelog(self): |
|
709 | 709 | return self._filelog |
|
710 | 710 | def rev(self): |
|
711 | 711 | return self._changeid |
|
712 | 712 | def linkrev(self): |
|
713 | 713 | return self._filelog.linkrev(self._filerev) |
|
714 | 714 | def node(self): |
|
715 | 715 | return self._changectx.node() |
|
716 | 716 | def hex(self): |
|
717 | 717 | return self._changectx.hex() |
|
718 | 718 | def user(self): |
|
719 | 719 | return self._changectx.user() |
|
720 | 720 | def date(self): |
|
721 | 721 | return self._changectx.date() |
|
722 | 722 | def files(self): |
|
723 | 723 | return self._changectx.files() |
|
724 | 724 | def description(self): |
|
725 | 725 | return self._changectx.description() |
|
726 | 726 | def branch(self): |
|
727 | 727 | return self._changectx.branch() |
|
728 | 728 | def extra(self): |
|
729 | 729 | return self._changectx.extra() |
|
730 | 730 | def phase(self): |
|
731 | 731 | return self._changectx.phase() |
|
732 | 732 | def phasestr(self): |
|
733 | 733 | return self._changectx.phasestr() |
|
734 | 734 | def obsolete(self): |
|
735 | 735 | return self._changectx.obsolete() |
|
736 | 736 | def instabilities(self): |
|
737 | 737 | return self._changectx.instabilities() |
|
738 | 738 | def manifest(self): |
|
739 | 739 | return self._changectx.manifest() |
|
740 | 740 | def changectx(self): |
|
741 | 741 | return self._changectx |
|
742 | 742 | def renamed(self): |
|
743 | 743 | return self._copied |
|
744 | 744 | def repo(self): |
|
745 | 745 | return self._repo |
|
746 | 746 | def size(self): |
|
747 | 747 | return len(self.data()) |
|
748 | 748 | |
|
749 | 749 | def path(self): |
|
750 | 750 | return self._path |
|
751 | 751 | |
|
752 | 752 | def isbinary(self): |
|
753 | 753 | try: |
|
754 | 754 | return stringutil.binary(self.data()) |
|
755 | 755 | except IOError: |
|
756 | 756 | return False |
|
757 | 757 | def isexec(self): |
|
758 | 758 | return 'x' in self.flags() |
|
759 | 759 | def islink(self): |
|
760 | 760 | return 'l' in self.flags() |
|
761 | 761 | |
|
762 | 762 | def isabsent(self): |
|
763 | 763 | """whether this filectx represents a file not in self._changectx |
|
764 | 764 | |
|
765 | 765 | This is mainly for merge code to detect change/delete conflicts. This is |
|
766 | 766 | expected to be True for all subclasses of basectx.""" |
|
767 | 767 | return False |
|
768 | 768 | |
|
769 | 769 | _customcmp = False |
|
770 | 770 | def cmp(self, fctx): |
|
771 | 771 | """compare with other file context |
|
772 | 772 | |
|
773 | 773 | returns True if different than fctx. |
|
774 | 774 | """ |
|
775 | 775 | if fctx._customcmp: |
|
776 | 776 | return fctx.cmp(self) |
|
777 | 777 | |
|
778 | 778 | if (fctx._filenode is None |
|
779 | 779 | and (self._repo._encodefilterpats |
|
780 | 780 | # if file data starts with '\1\n', empty metadata block is |
|
781 | 781 | # prepended, which adds 4 bytes to filelog.size(). |
|
782 | 782 | or self.size() - 4 == fctx.size()) |
|
783 | 783 | or self.size() == fctx.size()): |
|
784 | 784 | return self._filelog.cmp(self._filenode, fctx.data()) |
|
785 | 785 | |
|
786 | 786 | return True |
|
787 | 787 | |
|
788 | 788 | def _adjustlinkrev(self, srcrev, inclusive=False): |
|
789 | 789 | """return the first ancestor of <srcrev> introducing <fnode> |
|
790 | 790 | |
|
791 | 791 | If the linkrev of the file revision does not point to an ancestor of |
|
792 | 792 | srcrev, we'll walk down the ancestors until we find one introducing |
|
793 | 793 | this file revision. |
|
794 | 794 | |
|
795 | 795 | :srcrev: the changeset revision we search ancestors from |
|
796 | 796 | :inclusive: if true, the src revision will also be checked |
|
797 | 797 | """ |
|
798 | 798 | repo = self._repo |
|
799 | 799 | cl = repo.unfiltered().changelog |
|
800 | 800 | mfl = repo.manifestlog |
|
801 | 801 | # fetch the linkrev |
|
802 | 802 | lkr = self.linkrev() |
|
803 | 803 | # hack to reuse ancestor computation when searching for renames |
|
804 | 804 | memberanc = getattr(self, '_ancestrycontext', None) |
|
805 | 805 | iteranc = None |
|
806 | 806 | if srcrev is None: |
|
807 | 807 | # wctx case, used by workingfilectx during mergecopy |
|
808 | 808 | revs = [p.rev() for p in self._repo[None].parents()] |
|
809 | 809 | inclusive = True # we skipped the real (revless) source |
|
810 | 810 | else: |
|
811 | 811 | revs = [srcrev] |
|
812 | 812 | if memberanc is None: |
|
813 | 813 | memberanc = iteranc = cl.ancestors(revs, lkr, |
|
814 | 814 | inclusive=inclusive) |
|
815 | 815 | # check if this linkrev is an ancestor of srcrev |
|
816 | 816 | if lkr not in memberanc: |
|
817 | 817 | if iteranc is None: |
|
818 | 818 | iteranc = cl.ancestors(revs, lkr, inclusive=inclusive) |
|
819 | 819 | fnode = self._filenode |
|
820 | 820 | path = self._path |
|
821 | 821 | for a in iteranc: |
|
822 | 822 | ac = cl.read(a) # get changeset data (we avoid object creation) |
|
823 | 823 | if path in ac[3]: # checking the 'files' field. |
|
824 | 824 | # The file has been touched, check if the content is |
|
825 | 825 | # similar to the one we search for. |
|
826 | 826 | if fnode == mfl[ac[0]].readfast().get(path): |
|
827 | 827 | return a |
|
828 | 828 | # In theory, we should never get out of that loop without a result. |
|
829 | 829 | # But if manifest uses a buggy file revision (not children of the |
|
830 | 830 | # one it replaces) we could. Such a buggy situation will likely |
|
831 | 831 | # result is crash somewhere else at to some point. |
|
832 | 832 | return lkr |
|
833 | 833 | |
|
834 | 834 | def introrev(self): |
|
835 | 835 | """return the rev of the changeset which introduced this file revision |
|
836 | 836 | |
|
837 | 837 | This method is different from linkrev because it take into account the |
|
838 | 838 | changeset the filectx was created from. It ensures the returned |
|
839 | 839 | revision is one of its ancestors. This prevents bugs from |
|
840 | 840 | 'linkrev-shadowing' when a file revision is used by multiple |
|
841 | 841 | changesets. |
|
842 | 842 | """ |
|
843 | 843 | lkr = self.linkrev() |
|
844 | 844 | attrs = vars(self) |
|
845 | 845 | noctx = not (r'_changeid' in attrs or r'_changectx' in attrs) |
|
846 | 846 | if noctx or self.rev() == lkr: |
|
847 | 847 | return self.linkrev() |
|
848 | 848 | return self._adjustlinkrev(self.rev(), inclusive=True) |
|
849 | 849 | |
|
850 | 850 | def introfilectx(self): |
|
851 | 851 | """Return filectx having identical contents, but pointing to the |
|
852 | 852 | changeset revision where this filectx was introduced""" |
|
853 | 853 | introrev = self.introrev() |
|
854 | 854 | if self.rev() == introrev: |
|
855 | 855 | return self |
|
856 | 856 | return self.filectx(self.filenode(), changeid=introrev) |
|
857 | 857 | |
|
858 | 858 | def _parentfilectx(self, path, fileid, filelog): |
|
859 | 859 | """create parent filectx keeping ancestry info for _adjustlinkrev()""" |
|
860 | 860 | fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) |
|
861 | 861 | if r'_changeid' in vars(self) or r'_changectx' in vars(self): |
|
862 | 862 | # If self is associated with a changeset (probably explicitly |
|
863 | 863 | # fed), ensure the created filectx is associated with a |
|
864 | 864 | # changeset that is an ancestor of self.changectx. |
|
865 | 865 | # This lets us later use _adjustlinkrev to get a correct link. |
|
866 | 866 | fctx._descendantrev = self.rev() |
|
867 | 867 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
868 | 868 | elif r'_descendantrev' in vars(self): |
|
869 | 869 | # Otherwise propagate _descendantrev if we have one associated. |
|
870 | 870 | fctx._descendantrev = self._descendantrev |
|
871 | 871 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
872 | 872 | return fctx |
|
873 | 873 | |
|
874 | 874 | def parents(self): |
|
875 | 875 | _path = self._path |
|
876 | 876 | fl = self._filelog |
|
877 | 877 | parents = self._filelog.parents(self._filenode) |
|
878 | 878 | pl = [(_path, node, fl) for node in parents if node != nullid] |
|
879 | 879 | |
|
880 | 880 | r = fl.renamed(self._filenode) |
|
881 | 881 | if r: |
|
882 | 882 | # - In the simple rename case, both parent are nullid, pl is empty. |
|
883 | 883 | # - In case of merge, only one of the parent is null id and should |
|
884 | 884 | # be replaced with the rename information. This parent is -always- |
|
885 | 885 | # the first one. |
|
886 | 886 | # |
|
887 | 887 | # As null id have always been filtered out in the previous list |
|
888 | 888 | # comprehension, inserting to 0 will always result in "replacing |
|
889 | 889 | # first nullid parent with rename information. |
|
890 | 890 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) |
|
891 | 891 | |
|
892 | 892 | return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl] |
|
893 | 893 | |
|
894 | 894 | def p1(self): |
|
895 | 895 | return self.parents()[0] |
|
896 | 896 | |
|
897 | 897 | def p2(self): |
|
898 | 898 | p = self.parents() |
|
899 | 899 | if len(p) == 2: |
|
900 | 900 | return p[1] |
|
901 | 901 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) |
|
902 | 902 | |
|
903 | 903 | def annotate(self, follow=False, skiprevs=None, diffopts=None): |
|
904 | 904 | """Returns a list of annotateline objects for each line in the file |
|
905 | 905 | |
|
906 | 906 | - line.fctx is the filectx of the node where that line was last changed |
|
907 | 907 | - line.lineno is the line number at the first appearance in the managed |
|
908 | 908 | file |
|
909 | 909 | - line.text is the data on that line (including newline character) |
|
910 | 910 | """ |
|
911 | 911 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
912 | 912 | |
|
913 | 913 | def parents(f): |
|
914 | 914 | # Cut _descendantrev here to mitigate the penalty of lazy linkrev |
|
915 | 915 | # adjustment. Otherwise, p._adjustlinkrev() would walk changelog |
|
916 | 916 | # from the topmost introrev (= srcrev) down to p.linkrev() if it |
|
917 | 917 | # isn't an ancestor of the srcrev. |
|
918 | 918 | f._changeid |
|
919 | 919 | pl = f.parents() |
|
920 | 920 | |
|
921 | 921 | # Don't return renamed parents if we aren't following. |
|
922 | 922 | if not follow: |
|
923 | 923 | pl = [p for p in pl if p.path() == f.path()] |
|
924 | 924 | |
|
925 | 925 | # renamed filectx won't have a filelog yet, so set it |
|
926 | 926 | # from the cache to save time |
|
927 | 927 | for p in pl: |
|
928 | 928 | if not r'_filelog' in p.__dict__: |
|
929 | 929 | p._filelog = getlog(p.path()) |
|
930 | 930 | |
|
931 | 931 | return pl |
|
932 | 932 | |
|
933 | 933 | # use linkrev to find the first changeset where self appeared |
|
934 | 934 | base = self.introfilectx() |
|
935 | 935 | if getattr(base, '_ancestrycontext', None) is None: |
|
936 | 936 | cl = self._repo.changelog |
|
937 | 937 | if base.rev() is None: |
|
938 | 938 | # wctx is not inclusive, but works because _ancestrycontext |
|
939 | 939 | # is used to test filelog revisions |
|
940 | 940 | ac = cl.ancestors([p.rev() for p in base.parents()], |
|
941 | 941 | inclusive=True) |
|
942 | 942 | else: |
|
943 | 943 | ac = cl.ancestors([base.rev()], inclusive=True) |
|
944 | 944 | base._ancestrycontext = ac |
|
945 | 945 | |
|
946 | 946 | return dagop.annotate(base, parents, skiprevs=skiprevs, |
|
947 | 947 | diffopts=diffopts) |
|
948 | 948 | |
|
949 | 949 | def ancestors(self, followfirst=False): |
|
950 | 950 | visit = {} |
|
951 | 951 | c = self |
|
952 | 952 | if followfirst: |
|
953 | 953 | cut = 1 |
|
954 | 954 | else: |
|
955 | 955 | cut = None |
|
956 | 956 | |
|
957 | 957 | while True: |
|
958 | 958 | for parent in c.parents()[:cut]: |
|
959 | 959 | visit[(parent.linkrev(), parent.filenode())] = parent |
|
960 | 960 | if not visit: |
|
961 | 961 | break |
|
962 | 962 | c = visit.pop(max(visit)) |
|
963 | 963 | yield c |
|
964 | 964 | |
|
965 | 965 | def decodeddata(self): |
|
966 | 966 | """Returns `data()` after running repository decoding filters. |
|
967 | 967 | |
|
968 | 968 | This is often equivalent to how the data would be expressed on disk. |
|
969 | 969 | """ |
|
970 | 970 | return self._repo.wwritedata(self.path(), self.data()) |
|
971 | 971 | |
|
972 | 972 | class filectx(basefilectx): |
|
973 | 973 | """A filecontext object makes access to data related to a particular |
|
974 | 974 | filerevision convenient.""" |
|
975 | 975 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
976 | 976 | filelog=None, changectx=None): |
|
977 | 977 | """changeid can be a changeset revision, node, or tag. |
|
978 | 978 | fileid can be a file revision or node.""" |
|
979 | 979 | self._repo = repo |
|
980 | 980 | self._path = path |
|
981 | 981 | |
|
982 | 982 | assert (changeid is not None |
|
983 | 983 | or fileid is not None |
|
984 | 984 | or changectx is not None), \ |
|
985 | 985 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
986 | 986 | % (changeid, fileid, changectx)) |
|
987 | 987 | |
|
988 | 988 | if filelog is not None: |
|
989 | 989 | self._filelog = filelog |
|
990 | 990 | |
|
991 | 991 | if changeid is not None: |
|
992 | 992 | self._changeid = changeid |
|
993 | 993 | if changectx is not None: |
|
994 | 994 | self._changectx = changectx |
|
995 | 995 | if fileid is not None: |
|
996 | 996 | self._fileid = fileid |
|
997 | 997 | |
|
998 | 998 | @propertycache |
|
999 | 999 | def _changectx(self): |
|
1000 | 1000 | try: |
|
1001 | 1001 | return changectx(self._repo, self._changeid) |
|
1002 | 1002 | except error.FilteredRepoLookupError: |
|
1003 | 1003 | # Linkrev may point to any revision in the repository. When the |
|
1004 | 1004 | # repository is filtered this may lead to `filectx` trying to build |
|
1005 | 1005 | # `changectx` for filtered revision. In such case we fallback to |
|
1006 | 1006 | # creating `changectx` on the unfiltered version of the reposition. |
|
1007 | 1007 | # This fallback should not be an issue because `changectx` from |
|
1008 | 1008 | # `filectx` are not used in complex operations that care about |
|
1009 | 1009 | # filtering. |
|
1010 | 1010 | # |
|
1011 | 1011 | # This fallback is a cheap and dirty fix that prevent several |
|
1012 | 1012 | # crashes. It does not ensure the behavior is correct. However the |
|
1013 | 1013 | # behavior was not correct before filtering either and "incorrect |
|
1014 | 1014 | # behavior" is seen as better as "crash" |
|
1015 | 1015 | # |
|
1016 | 1016 | # Linkrevs have several serious troubles with filtering that are |
|
1017 | 1017 | # complicated to solve. Proper handling of the issue here should be |
|
1018 | 1018 | # considered when solving linkrev issue are on the table. |
|
1019 | 1019 | return changectx(self._repo.unfiltered(), self._changeid) |
|
1020 | 1020 | |
|
1021 | 1021 | def filectx(self, fileid, changeid=None): |
|
1022 | 1022 | '''opens an arbitrary revision of the file without |
|
1023 | 1023 | opening a new filelog''' |
|
1024 | 1024 | return filectx(self._repo, self._path, fileid=fileid, |
|
1025 | 1025 | filelog=self._filelog, changeid=changeid) |
|
1026 | 1026 | |
|
1027 | 1027 | def rawdata(self): |
|
1028 | 1028 | return self._filelog.revision(self._filenode, raw=True) |
|
1029 | 1029 | |
|
1030 | 1030 | def rawflags(self): |
|
1031 | 1031 | """low-level revlog flags""" |
|
1032 | 1032 | return self._filelog.flags(self._filerev) |
|
1033 | 1033 | |
|
1034 | 1034 | def data(self): |
|
1035 | 1035 | try: |
|
1036 | 1036 | return self._filelog.read(self._filenode) |
|
1037 | 1037 | except error.CensoredNodeError: |
|
1038 | 1038 | if self._repo.ui.config("censor", "policy") == "ignore": |
|
1039 | 1039 | return "" |
|
1040 | 1040 | raise error.Abort(_("censored node: %s") % short(self._filenode), |
|
1041 | 1041 | hint=_("set censor.policy to ignore errors")) |
|
1042 | 1042 | |
|
1043 | 1043 | def size(self): |
|
1044 | 1044 | return self._filelog.size(self._filerev) |
|
1045 | 1045 | |
|
1046 | 1046 | @propertycache |
|
1047 | 1047 | def _copied(self): |
|
1048 | 1048 | """check if file was actually renamed in this changeset revision |
|
1049 | 1049 | |
|
1050 | 1050 | If rename logged in file revision, we report copy for changeset only |
|
1051 | 1051 | if file revisions linkrev points back to the changeset in question |
|
1052 | 1052 | or both changeset parents contain different file revisions. |
|
1053 | 1053 | """ |
|
1054 | 1054 | |
|
1055 | 1055 | renamed = self._filelog.renamed(self._filenode) |
|
1056 | 1056 | if not renamed: |
|
1057 | 1057 | return renamed |
|
1058 | 1058 | |
|
1059 | 1059 | if self.rev() == self.linkrev(): |
|
1060 | 1060 | return renamed |
|
1061 | 1061 | |
|
1062 | 1062 | name = self.path() |
|
1063 | 1063 | fnode = self._filenode |
|
1064 | 1064 | for p in self._changectx.parents(): |
|
1065 | 1065 | try: |
|
1066 | 1066 | if fnode == p.filenode(name): |
|
1067 | 1067 | return None |
|
1068 | 1068 | except error.LookupError: |
|
1069 | 1069 | pass |
|
1070 | 1070 | return renamed |
|
1071 | 1071 | |
|
1072 | 1072 | def children(self): |
|
1073 | 1073 | # hard for renames |
|
1074 | 1074 | c = self._filelog.children(self._filenode) |
|
1075 | 1075 | return [filectx(self._repo, self._path, fileid=x, |
|
1076 | 1076 | filelog=self._filelog) for x in c] |
|
1077 | 1077 | |
|
1078 | 1078 | class committablectx(basectx): |
|
1079 | 1079 | """A committablectx object provides common functionality for a context that |
|
1080 | 1080 | wants the ability to commit, e.g. workingctx or memctx.""" |
|
1081 | 1081 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1082 | 1082 | changes=None): |
|
1083 | 1083 | super(committablectx, self).__init__(repo) |
|
1084 | 1084 | self._rev = None |
|
1085 | 1085 | self._node = None |
|
1086 | 1086 | self._text = text |
|
1087 | 1087 | if date: |
|
1088 | 1088 | self._date = dateutil.parsedate(date) |
|
1089 | 1089 | if user: |
|
1090 | 1090 | self._user = user |
|
1091 | 1091 | if changes: |
|
1092 | 1092 | self._status = changes |
|
1093 | 1093 | |
|
1094 | 1094 | self._extra = {} |
|
1095 | 1095 | if extra: |
|
1096 | 1096 | self._extra = extra.copy() |
|
1097 | 1097 | if 'branch' not in self._extra: |
|
1098 | 1098 | try: |
|
1099 | 1099 | branch = encoding.fromlocal(self._repo.dirstate.branch()) |
|
1100 | 1100 | except UnicodeDecodeError: |
|
1101 | 1101 | raise error.Abort(_('branch name not in UTF-8!')) |
|
1102 | 1102 | self._extra['branch'] = branch |
|
1103 | 1103 | if self._extra['branch'] == '': |
|
1104 | 1104 | self._extra['branch'] = 'default' |
|
1105 | 1105 | |
|
1106 | 1106 | def __bytes__(self): |
|
1107 | 1107 | return bytes(self._parents[0]) + "+" |
|
1108 | 1108 | |
|
1109 | 1109 | __str__ = encoding.strmethod(__bytes__) |
|
1110 | 1110 | |
|
1111 | 1111 | def __nonzero__(self): |
|
1112 | 1112 | return True |
|
1113 | 1113 | |
|
1114 | 1114 | __bool__ = __nonzero__ |
|
1115 | 1115 | |
|
1116 | 1116 | def _buildflagfunc(self): |
|
1117 | 1117 | # Create a fallback function for getting file flags when the |
|
1118 | 1118 | # filesystem doesn't support them |
|
1119 | 1119 | |
|
1120 | 1120 | copiesget = self._repo.dirstate.copies().get |
|
1121 | 1121 | parents = self.parents() |
|
1122 | 1122 | if len(parents) < 2: |
|
1123 | 1123 | # when we have one parent, it's easy: copy from parent |
|
1124 | 1124 | man = parents[0].manifest() |
|
1125 | 1125 | def func(f): |
|
1126 | 1126 | f = copiesget(f, f) |
|
1127 | 1127 | return man.flags(f) |
|
1128 | 1128 | else: |
|
1129 | 1129 | # merges are tricky: we try to reconstruct the unstored |
|
1130 | 1130 | # result from the merge (issue1802) |
|
1131 | 1131 | p1, p2 = parents |
|
1132 | 1132 | pa = p1.ancestor(p2) |
|
1133 | 1133 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() |
|
1134 | 1134 | |
|
1135 | 1135 | def func(f): |
|
1136 | 1136 | f = copiesget(f, f) # may be wrong for merges with copies |
|
1137 | 1137 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) |
|
1138 | 1138 | if fl1 == fl2: |
|
1139 | 1139 | return fl1 |
|
1140 | 1140 | if fl1 == fla: |
|
1141 | 1141 | return fl2 |
|
1142 | 1142 | if fl2 == fla: |
|
1143 | 1143 | return fl1 |
|
1144 | 1144 | return '' # punt for conflicts |
|
1145 | 1145 | |
|
1146 | 1146 | return func |
|
1147 | 1147 | |
|
1148 | 1148 | @propertycache |
|
1149 | 1149 | def _flagfunc(self): |
|
1150 | 1150 | return self._repo.dirstate.flagfunc(self._buildflagfunc) |
|
1151 | 1151 | |
|
1152 | 1152 | @propertycache |
|
1153 | 1153 | def _status(self): |
|
1154 | 1154 | return self._repo.status() |
|
1155 | 1155 | |
|
1156 | 1156 | @propertycache |
|
1157 | 1157 | def _user(self): |
|
1158 | 1158 | return self._repo.ui.username() |
|
1159 | 1159 | |
|
1160 | 1160 | @propertycache |
|
1161 | 1161 | def _date(self): |
|
1162 | 1162 | ui = self._repo.ui |
|
1163 | 1163 | date = ui.configdate('devel', 'default-date') |
|
1164 | 1164 | if date is None: |
|
1165 | 1165 | date = dateutil.makedate() |
|
1166 | 1166 | return date |
|
1167 | 1167 | |
|
1168 | 1168 | def subrev(self, subpath): |
|
1169 | 1169 | return None |
|
1170 | 1170 | |
|
1171 | 1171 | def manifestnode(self): |
|
1172 | 1172 | return None |
|
1173 | 1173 | def user(self): |
|
1174 | 1174 | return self._user or self._repo.ui.username() |
|
1175 | 1175 | def date(self): |
|
1176 | 1176 | return self._date |
|
1177 | 1177 | def description(self): |
|
1178 | 1178 | return self._text |
|
1179 | 1179 | def files(self): |
|
1180 | 1180 | return sorted(self._status.modified + self._status.added + |
|
1181 | 1181 | self._status.removed) |
|
1182 | 1182 | |
|
1183 | 1183 | def modified(self): |
|
1184 | 1184 | return self._status.modified |
|
1185 | 1185 | def added(self): |
|
1186 | 1186 | return self._status.added |
|
1187 | 1187 | def removed(self): |
|
1188 | 1188 | return self._status.removed |
|
1189 | 1189 | def deleted(self): |
|
1190 | 1190 | return self._status.deleted |
|
1191 | 1191 | def branch(self): |
|
1192 | 1192 | return encoding.tolocal(self._extra['branch']) |
|
1193 | 1193 | def closesbranch(self): |
|
1194 | 1194 | return 'close' in self._extra |
|
1195 | 1195 | def extra(self): |
|
1196 | 1196 | return self._extra |
|
1197 | 1197 | |
|
1198 | 1198 | def isinmemory(self): |
|
1199 | 1199 | return False |
|
1200 | 1200 | |
|
1201 | 1201 | def tags(self): |
|
1202 | 1202 | return [] |
|
1203 | 1203 | |
|
1204 | 1204 | def bookmarks(self): |
|
1205 | 1205 | b = [] |
|
1206 | 1206 | for p in self.parents(): |
|
1207 | 1207 | b.extend(p.bookmarks()) |
|
1208 | 1208 | return b |
|
1209 | 1209 | |
|
1210 | 1210 | def phase(self): |
|
1211 | 1211 | phase = phases.draft # default phase to draft |
|
1212 | 1212 | for p in self.parents(): |
|
1213 | 1213 | phase = max(phase, p.phase()) |
|
1214 | 1214 | return phase |
|
1215 | 1215 | |
|
1216 | 1216 | def hidden(self): |
|
1217 | 1217 | return False |
|
1218 | 1218 | |
|
1219 | 1219 | def children(self): |
|
1220 | 1220 | return [] |
|
1221 | 1221 | |
|
1222 | 1222 | def flags(self, path): |
|
1223 | 1223 | if r'_manifest' in self.__dict__: |
|
1224 | 1224 | try: |
|
1225 | 1225 | return self._manifest.flags(path) |
|
1226 | 1226 | except KeyError: |
|
1227 | 1227 | return '' |
|
1228 | 1228 | |
|
1229 | 1229 | try: |
|
1230 | 1230 | return self._flagfunc(path) |
|
1231 | 1231 | except OSError: |
|
1232 | 1232 | return '' |
|
1233 | 1233 | |
|
1234 | 1234 | def ancestor(self, c2): |
|
1235 | 1235 | """return the "best" ancestor context of self and c2""" |
|
1236 | 1236 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
1237 | 1237 | |
|
1238 | 1238 | def walk(self, match): |
|
1239 | 1239 | '''Generates matching file names.''' |
|
1240 | 1240 | return sorted(self._repo.dirstate.walk(match, |
|
1241 | 1241 | subrepos=sorted(self.substate), |
|
1242 | 1242 | unknown=True, ignored=False)) |
|
1243 | 1243 | |
|
1244 | 1244 | def matches(self, match): |
|
1245 | 1245 | ds = self._repo.dirstate |
|
1246 | 1246 | return sorted(f for f in ds.matches(match) if ds[f] != 'r') |
|
1247 | 1247 | |
|
1248 | 1248 | def ancestors(self): |
|
1249 | 1249 | for p in self._parents: |
|
1250 | 1250 | yield p |
|
1251 | 1251 | for a in self._repo.changelog.ancestors( |
|
1252 | 1252 | [p.rev() for p in self._parents]): |
|
1253 | 1253 | yield changectx(self._repo, a) |
|
1254 | 1254 | |
|
1255 | 1255 | def markcommitted(self, node): |
|
1256 | 1256 | """Perform post-commit cleanup necessary after committing this ctx |
|
1257 | 1257 | |
|
1258 | 1258 | Specifically, this updates backing stores this working context |
|
1259 | 1259 | wraps to reflect the fact that the changes reflected by this |
|
1260 | 1260 | workingctx have been committed. For example, it marks |
|
1261 | 1261 | modified and added files as normal in the dirstate. |
|
1262 | 1262 | |
|
1263 | 1263 | """ |
|
1264 | 1264 | |
|
1265 | 1265 | with self._repo.dirstate.parentchange(): |
|
1266 | 1266 | for f in self.modified() + self.added(): |
|
1267 | 1267 | self._repo.dirstate.normal(f) |
|
1268 | 1268 | for f in self.removed(): |
|
1269 | 1269 | self._repo.dirstate.drop(f) |
|
1270 | 1270 | self._repo.dirstate.setparents(node) |
|
1271 | 1271 | |
|
1272 | 1272 | # write changes out explicitly, because nesting wlock at |
|
1273 | 1273 | # runtime may prevent 'wlock.release()' in 'repo.commit()' |
|
1274 | 1274 | # from immediately doing so for subsequent changing files |
|
1275 | 1275 | self._repo.dirstate.write(self._repo.currenttransaction()) |
|
1276 | 1276 | |
|
1277 | 1277 | def dirty(self, missing=False, merge=True, branch=True): |
|
1278 | 1278 | return False |
|
1279 | 1279 | |
|
1280 | 1280 | class workingctx(committablectx): |
|
1281 | 1281 | """A workingctx object makes access to data related to |
|
1282 | 1282 | the current working directory convenient. |
|
1283 | 1283 | date - any valid date string or (unixtime, offset), or None. |
|
1284 | 1284 | user - username string, or None. |
|
1285 | 1285 | extra - a dictionary of extra values, or None. |
|
1286 | 1286 | changes - a list of file lists as returned by localrepo.status() |
|
1287 | 1287 | or None to use the repository status. |
|
1288 | 1288 | """ |
|
1289 | 1289 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1290 | 1290 | changes=None): |
|
1291 | 1291 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) |
|
1292 | 1292 | |
|
1293 | 1293 | def __iter__(self): |
|
1294 | 1294 | d = self._repo.dirstate |
|
1295 | 1295 | for f in d: |
|
1296 | 1296 | if d[f] != 'r': |
|
1297 | 1297 | yield f |
|
1298 | 1298 | |
|
1299 | 1299 | def __contains__(self, key): |
|
1300 | 1300 | return self._repo.dirstate[key] not in "?r" |
|
1301 | 1301 | |
|
1302 | 1302 | def hex(self): |
|
1303 | 1303 | return hex(wdirid) |
|
1304 | 1304 | |
|
1305 | 1305 | @propertycache |
|
1306 | 1306 | def _parents(self): |
|
1307 | 1307 | p = self._repo.dirstate.parents() |
|
1308 | 1308 | if p[1] == nullid: |
|
1309 | 1309 | p = p[:-1] |
|
1310 | 1310 | return [changectx(self._repo, x) for x in p] |
|
1311 | 1311 | |
|
1312 | 1312 | def _fileinfo(self, path): |
|
1313 | 1313 | # populate __dict__['_manifest'] as workingctx has no _manifestdelta |
|
1314 | 1314 | self._manifest |
|
1315 | 1315 | return super(workingctx, self)._fileinfo(path) |
|
1316 | 1316 | |
|
1317 | 1317 | def filectx(self, path, filelog=None): |
|
1318 | 1318 | """get a file context from the working directory""" |
|
1319 | 1319 | return workingfilectx(self._repo, path, workingctx=self, |
|
1320 | 1320 | filelog=filelog) |
|
1321 | 1321 | |
|
1322 | 1322 | def dirty(self, missing=False, merge=True, branch=True): |
|
1323 | 1323 | "check whether a working directory is modified" |
|
1324 | 1324 | # check subrepos first |
|
1325 | 1325 | for s in sorted(self.substate): |
|
1326 | 1326 | if self.sub(s).dirty(missing=missing): |
|
1327 | 1327 | return True |
|
1328 | 1328 | # check current working dir |
|
1329 | 1329 | return ((merge and self.p2()) or |
|
1330 | 1330 | (branch and self.branch() != self.p1().branch()) or |
|
1331 | 1331 | self.modified() or self.added() or self.removed() or |
|
1332 | 1332 | (missing and self.deleted())) |
|
1333 | 1333 | |
|
1334 | 1334 | def add(self, list, prefix=""): |
|
1335 | 1335 | with self._repo.wlock(): |
|
1336 | 1336 | ui, ds = self._repo.ui, self._repo.dirstate |
|
1337 | 1337 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) |
|
1338 | 1338 | rejected = [] |
|
1339 | 1339 | lstat = self._repo.wvfs.lstat |
|
1340 | 1340 | for f in list: |
|
1341 | 1341 | # ds.pathto() returns an absolute file when this is invoked from |
|
1342 | 1342 | # the keyword extension. That gets flagged as non-portable on |
|
1343 | 1343 | # Windows, since it contains the drive letter and colon. |
|
1344 | 1344 | scmutil.checkportable(ui, os.path.join(prefix, f)) |
|
1345 | 1345 | try: |
|
1346 | 1346 | st = lstat(f) |
|
1347 | 1347 | except OSError: |
|
1348 | 1348 | ui.warn(_("%s does not exist!\n") % uipath(f)) |
|
1349 | 1349 | rejected.append(f) |
|
1350 | 1350 | continue |
|
1351 | 1351 | limit = ui.configbytes('ui', 'large-file-limit') |
|
1352 | 1352 | if limit != 0 and st.st_size > limit: |
|
1353 | 1353 | ui.warn(_("%s: up to %d MB of RAM may be required " |
|
1354 | 1354 | "to manage this file\n" |
|
1355 | 1355 | "(use 'hg revert %s' to cancel the " |
|
1356 | 1356 | "pending addition)\n") |
|
1357 | 1357 | % (f, 3 * st.st_size // 1000000, uipath(f))) |
|
1358 | 1358 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1359 | 1359 | ui.warn(_("%s not added: only files and symlinks " |
|
1360 | 1360 | "supported currently\n") % uipath(f)) |
|
1361 | 1361 | rejected.append(f) |
|
1362 | 1362 | elif ds[f] in 'amn': |
|
1363 | 1363 | ui.warn(_("%s already tracked!\n") % uipath(f)) |
|
1364 | 1364 | elif ds[f] == 'r': |
|
1365 | 1365 | ds.normallookup(f) |
|
1366 | 1366 | else: |
|
1367 | 1367 | ds.add(f) |
|
1368 | 1368 | return rejected |
|
1369 | 1369 | |
|
1370 | 1370 | def forget(self, files, prefix=""): |
|
1371 | 1371 | with self._repo.wlock(): |
|
1372 | 1372 | ds = self._repo.dirstate |
|
1373 | 1373 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) |
|
1374 | 1374 | rejected = [] |
|
1375 | 1375 | for f in files: |
|
1376 | 1376 | if f not in self._repo.dirstate: |
|
1377 | 1377 | self._repo.ui.warn(_("%s not tracked!\n") % uipath(f)) |
|
1378 | 1378 | rejected.append(f) |
|
1379 | 1379 | elif self._repo.dirstate[f] != 'a': |
|
1380 | 1380 | self._repo.dirstate.remove(f) |
|
1381 | 1381 | else: |
|
1382 | 1382 | self._repo.dirstate.drop(f) |
|
1383 | 1383 | return rejected |
|
1384 | 1384 | |
|
1385 | 1385 | def undelete(self, list): |
|
1386 | 1386 | pctxs = self.parents() |
|
1387 | 1387 | with self._repo.wlock(): |
|
1388 | 1388 | ds = self._repo.dirstate |
|
1389 | 1389 | for f in list: |
|
1390 | 1390 | if self._repo.dirstate[f] != 'r': |
|
1391 | 1391 | self._repo.ui.warn(_("%s not removed!\n") % ds.pathto(f)) |
|
1392 | 1392 | else: |
|
1393 | 1393 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] |
|
1394 | 1394 | t = fctx.data() |
|
1395 | 1395 | self._repo.wwrite(f, t, fctx.flags()) |
|
1396 | 1396 | self._repo.dirstate.normal(f) |
|
1397 | 1397 | |
|
1398 | 1398 | def copy(self, source, dest): |
|
1399 | 1399 | try: |
|
1400 | 1400 | st = self._repo.wvfs.lstat(dest) |
|
1401 | 1401 | except OSError as err: |
|
1402 | 1402 | if err.errno != errno.ENOENT: |
|
1403 | 1403 | raise |
|
1404 | 1404 | self._repo.ui.warn(_("%s does not exist!\n") |
|
1405 | 1405 | % self._repo.dirstate.pathto(dest)) |
|
1406 | 1406 | return |
|
1407 | 1407 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1408 | 1408 | self._repo.ui.warn(_("copy failed: %s is not a file or a " |
|
1409 | 1409 | "symbolic link\n") |
|
1410 | 1410 | % self._repo.dirstate.pathto(dest)) |
|
1411 | 1411 | else: |
|
1412 | 1412 | with self._repo.wlock(): |
|
1413 | 1413 | if self._repo.dirstate[dest] in '?': |
|
1414 | 1414 | self._repo.dirstate.add(dest) |
|
1415 | 1415 | elif self._repo.dirstate[dest] in 'r': |
|
1416 | 1416 | self._repo.dirstate.normallookup(dest) |
|
1417 | 1417 | self._repo.dirstate.copy(source, dest) |
|
1418 | 1418 | |
|
1419 | 1419 | def match(self, pats=None, include=None, exclude=None, default='glob', |
|
1420 | 1420 | listsubrepos=False, badfn=None): |
|
1421 | 1421 | r = self._repo |
|
1422 | 1422 | |
|
1423 | 1423 | # Only a case insensitive filesystem needs magic to translate user input |
|
1424 | 1424 | # to actual case in the filesystem. |
|
1425 | 1425 | icasefs = not util.fscasesensitive(r.root) |
|
1426 | 1426 | return matchmod.match(r.root, r.getcwd(), pats, include, exclude, |
|
1427 | 1427 | default, auditor=r.auditor, ctx=self, |
|
1428 | 1428 | listsubrepos=listsubrepos, badfn=badfn, |
|
1429 | 1429 | icasefs=icasefs) |
|
1430 | 1430 | |
|
1431 | 1431 | def _filtersuspectsymlink(self, files): |
|
1432 | 1432 | if not files or self._repo.dirstate._checklink: |
|
1433 | 1433 | return files |
|
1434 | 1434 | |
|
1435 | 1435 | # Symlink placeholders may get non-symlink-like contents |
|
1436 | 1436 | # via user error or dereferencing by NFS or Samba servers, |
|
1437 | 1437 | # so we filter out any placeholders that don't look like a |
|
1438 | 1438 | # symlink |
|
1439 | 1439 | sane = [] |
|
1440 | 1440 | for f in files: |
|
1441 | 1441 | if self.flags(f) == 'l': |
|
1442 | 1442 | d = self[f].data() |
|
1443 | 1443 | if (d == '' or len(d) >= 1024 or '\n' in d |
|
1444 | 1444 | or stringutil.binary(d)): |
|
1445 | 1445 | self._repo.ui.debug('ignoring suspect symlink placeholder' |
|
1446 | 1446 | ' "%s"\n' % f) |
|
1447 | 1447 | continue |
|
1448 | 1448 | sane.append(f) |
|
1449 | 1449 | return sane |
|
1450 | 1450 | |
|
1451 | 1451 | def _checklookup(self, files): |
|
1452 | 1452 | # check for any possibly clean files |
|
1453 | 1453 | if not files: |
|
1454 | 1454 | return [], [], [] |
|
1455 | 1455 | |
|
1456 | 1456 | modified = [] |
|
1457 | 1457 | deleted = [] |
|
1458 | 1458 | fixup = [] |
|
1459 | 1459 | pctx = self._parents[0] |
|
1460 | 1460 | # do a full compare of any files that might have changed |
|
1461 | 1461 | for f in sorted(files): |
|
1462 | 1462 | try: |
|
1463 | 1463 | # This will return True for a file that got replaced by a |
|
1464 | 1464 | # directory in the interim, but fixing that is pretty hard. |
|
1465 | 1465 | if (f not in pctx or self.flags(f) != pctx.flags(f) |
|
1466 | 1466 | or pctx[f].cmp(self[f])): |
|
1467 | 1467 | modified.append(f) |
|
1468 | 1468 | else: |
|
1469 | 1469 | fixup.append(f) |
|
1470 | 1470 | except (IOError, OSError): |
|
1471 | 1471 | # A file become inaccessible in between? Mark it as deleted, |
|
1472 | 1472 | # matching dirstate behavior (issue5584). |
|
1473 | 1473 | # The dirstate has more complex behavior around whether a |
|
1474 | 1474 | # missing file matches a directory, etc, but we don't need to |
|
1475 | 1475 | # bother with that: if f has made it to this point, we're sure |
|
1476 | 1476 | # it's in the dirstate. |
|
1477 | 1477 | deleted.append(f) |
|
1478 | 1478 | |
|
1479 | 1479 | return modified, deleted, fixup |
|
1480 | 1480 | |
|
1481 | 1481 | def _poststatusfixup(self, status, fixup): |
|
1482 | 1482 | """update dirstate for files that are actually clean""" |
|
1483 | 1483 | poststatus = self._repo.postdsstatus() |
|
1484 | 1484 | if fixup or poststatus: |
|
1485 | 1485 | try: |
|
1486 | 1486 | oldid = self._repo.dirstate.identity() |
|
1487 | 1487 | |
|
1488 | 1488 | # updating the dirstate is optional |
|
1489 | 1489 | # so we don't wait on the lock |
|
1490 | 1490 | # wlock can invalidate the dirstate, so cache normal _after_ |
|
1491 | 1491 | # taking the lock |
|
1492 | 1492 | with self._repo.wlock(False): |
|
1493 | 1493 | if self._repo.dirstate.identity() == oldid: |
|
1494 | 1494 | if fixup: |
|
1495 | 1495 | normal = self._repo.dirstate.normal |
|
1496 | 1496 | for f in fixup: |
|
1497 | 1497 | normal(f) |
|
1498 | 1498 | # write changes out explicitly, because nesting |
|
1499 | 1499 | # wlock at runtime may prevent 'wlock.release()' |
|
1500 | 1500 | # after this block from doing so for subsequent |
|
1501 | 1501 | # changing files |
|
1502 | 1502 | tr = self._repo.currenttransaction() |
|
1503 | 1503 | self._repo.dirstate.write(tr) |
|
1504 | 1504 | |
|
1505 | 1505 | if poststatus: |
|
1506 | 1506 | for ps in poststatus: |
|
1507 | 1507 | ps(self, status) |
|
1508 | 1508 | else: |
|
1509 | 1509 | # in this case, writing changes out breaks |
|
1510 | 1510 | # consistency, because .hg/dirstate was |
|
1511 | 1511 | # already changed simultaneously after last |
|
1512 | 1512 | # caching (see also issue5584 for detail) |
|
1513 | 1513 | self._repo.ui.debug('skip updating dirstate: ' |
|
1514 | 1514 | 'identity mismatch\n') |
|
1515 | 1515 | except error.LockError: |
|
1516 | 1516 | pass |
|
1517 | 1517 | finally: |
|
1518 | 1518 | # Even if the wlock couldn't be grabbed, clear out the list. |
|
1519 | 1519 | self._repo.clearpostdsstatus() |
|
1520 | 1520 | |
|
1521 | 1521 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): |
|
1522 | 1522 | '''Gets the status from the dirstate -- internal use only.''' |
|
1523 | 1523 | subrepos = [] |
|
1524 | 1524 | if '.hgsub' in self: |
|
1525 | 1525 | subrepos = sorted(self.substate) |
|
1526 | 1526 | cmp, s = self._repo.dirstate.status(match, subrepos, ignored=ignored, |
|
1527 | 1527 | clean=clean, unknown=unknown) |
|
1528 | 1528 | |
|
1529 | 1529 | # check for any possibly clean files |
|
1530 | 1530 | fixup = [] |
|
1531 | 1531 | if cmp: |
|
1532 | 1532 | modified2, deleted2, fixup = self._checklookup(cmp) |
|
1533 | 1533 | s.modified.extend(modified2) |
|
1534 | 1534 | s.deleted.extend(deleted2) |
|
1535 | 1535 | |
|
1536 | 1536 | if fixup and clean: |
|
1537 | 1537 | s.clean.extend(fixup) |
|
1538 | 1538 | |
|
1539 | 1539 | self._poststatusfixup(s, fixup) |
|
1540 | 1540 | |
|
1541 | 1541 | if match.always(): |
|
1542 | 1542 | # cache for performance |
|
1543 | 1543 | if s.unknown or s.ignored or s.clean: |
|
1544 | 1544 | # "_status" is cached with list*=False in the normal route |
|
1545 | 1545 | self._status = scmutil.status(s.modified, s.added, s.removed, |
|
1546 | 1546 | s.deleted, [], [], []) |
|
1547 | 1547 | else: |
|
1548 | 1548 | self._status = s |
|
1549 | 1549 | |
|
1550 | 1550 | return s |
|
1551 | 1551 | |
|
1552 | 1552 | @propertycache |
|
1553 | 1553 | def _manifest(self): |
|
1554 | 1554 | """generate a manifest corresponding to the values in self._status |
|
1555 | 1555 | |
|
1556 | 1556 | This reuse the file nodeid from parent, but we use special node |
|
1557 | 1557 | identifiers for added and modified files. This is used by manifests |
|
1558 | 1558 | merge to see that files are different and by update logic to avoid |
|
1559 | 1559 | deleting newly added files. |
|
1560 | 1560 | """ |
|
1561 | 1561 | return self._buildstatusmanifest(self._status) |
|
1562 | 1562 | |
|
1563 | 1563 | def _buildstatusmanifest(self, status): |
|
1564 | 1564 | """Builds a manifest that includes the given status results.""" |
|
1565 | 1565 | parents = self.parents() |
|
1566 | 1566 | |
|
1567 | 1567 | man = parents[0].manifest().copy() |
|
1568 | 1568 | |
|
1569 | 1569 | ff = self._flagfunc |
|
1570 | 1570 | for i, l in ((addednodeid, status.added), |
|
1571 | 1571 | (modifiednodeid, status.modified)): |
|
1572 | 1572 | for f in l: |
|
1573 | 1573 | man[f] = i |
|
1574 | 1574 | try: |
|
1575 | 1575 | man.setflag(f, ff(f)) |
|
1576 | 1576 | except OSError: |
|
1577 | 1577 | pass |
|
1578 | 1578 | |
|
1579 | 1579 | for f in status.deleted + status.removed: |
|
1580 | 1580 | if f in man: |
|
1581 | 1581 | del man[f] |
|
1582 | 1582 | |
|
1583 | 1583 | return man |
|
1584 | 1584 | |
|
1585 | 1585 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
1586 | 1586 | listunknown): |
|
1587 | 1587 | """build a status with respect to another context |
|
1588 | 1588 | |
|
1589 | 1589 | This includes logic for maintaining the fast path of status when |
|
1590 | 1590 | comparing the working directory against its parent, which is to skip |
|
1591 | 1591 | building a new manifest if self (working directory) is not comparing |
|
1592 | 1592 | against its parent (repo['.']). |
|
1593 | 1593 | """ |
|
1594 | 1594 | s = self._dirstatestatus(match, listignored, listclean, listunknown) |
|
1595 | 1595 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, |
|
1596 | 1596 | # might have accidentally ended up with the entire contents of the file |
|
1597 | 1597 | # they are supposed to be linking to. |
|
1598 | 1598 | s.modified[:] = self._filtersuspectsymlink(s.modified) |
|
1599 | 1599 | if other != self._repo['.']: |
|
1600 | 1600 | s = super(workingctx, self)._buildstatus(other, s, match, |
|
1601 | 1601 | listignored, listclean, |
|
1602 | 1602 | listunknown) |
|
1603 | 1603 | return s |
|
1604 | 1604 | |
|
1605 | 1605 | def _matchstatus(self, other, match): |
|
1606 | 1606 | """override the match method with a filter for directory patterns |
|
1607 | 1607 | |
|
1608 | 1608 | We use inheritance to customize the match.bad method only in cases of |
|
1609 | 1609 | workingctx since it belongs only to the working directory when |
|
1610 | 1610 | comparing against the parent changeset. |
|
1611 | 1611 | |
|
1612 | 1612 | If we aren't comparing against the working directory's parent, then we |
|
1613 | 1613 | just use the default match object sent to us. |
|
1614 | 1614 | """ |
|
1615 | 1615 | if other != self._repo['.']: |
|
1616 | 1616 | def bad(f, msg): |
|
1617 | 1617 | # 'f' may be a directory pattern from 'match.files()', |
|
1618 | 1618 | # so 'f not in ctx1' is not enough |
|
1619 | 1619 | if f not in other and not other.hasdir(f): |
|
1620 | 1620 | self._repo.ui.warn('%s: %s\n' % |
|
1621 | 1621 | (self._repo.dirstate.pathto(f), msg)) |
|
1622 | 1622 | match.bad = bad |
|
1623 | 1623 | return match |
|
1624 | 1624 | |
|
1625 | 1625 | def markcommitted(self, node): |
|
1626 | 1626 | super(workingctx, self).markcommitted(node) |
|
1627 | 1627 | |
|
1628 | 1628 | sparse.aftercommit(self._repo, node) |
|
1629 | 1629 | |
|
1630 | 1630 | class committablefilectx(basefilectx): |
|
1631 | 1631 | """A committablefilectx provides common functionality for a file context |
|
1632 | 1632 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" |
|
1633 | 1633 | def __init__(self, repo, path, filelog=None, ctx=None): |
|
1634 | 1634 | self._repo = repo |
|
1635 | 1635 | self._path = path |
|
1636 | 1636 | self._changeid = None |
|
1637 | 1637 | self._filerev = self._filenode = None |
|
1638 | 1638 | |
|
1639 | 1639 | if filelog is not None: |
|
1640 | 1640 | self._filelog = filelog |
|
1641 | 1641 | if ctx: |
|
1642 | 1642 | self._changectx = ctx |
|
1643 | 1643 | |
|
1644 | 1644 | def __nonzero__(self): |
|
1645 | 1645 | return True |
|
1646 | 1646 | |
|
1647 | 1647 | __bool__ = __nonzero__ |
|
1648 | 1648 | |
|
1649 | 1649 | def linkrev(self): |
|
1650 | 1650 | # linked to self._changectx no matter if file is modified or not |
|
1651 | 1651 | return self.rev() |
|
1652 | 1652 | |
|
1653 | 1653 | def parents(self): |
|
1654 | 1654 | '''return parent filectxs, following copies if necessary''' |
|
1655 | 1655 | def filenode(ctx, path): |
|
1656 | 1656 | return ctx._manifest.get(path, nullid) |
|
1657 | 1657 | |
|
1658 | 1658 | path = self._path |
|
1659 | 1659 | fl = self._filelog |
|
1660 | 1660 | pcl = self._changectx._parents |
|
1661 | 1661 | renamed = self.renamed() |
|
1662 | 1662 | |
|
1663 | 1663 | if renamed: |
|
1664 | 1664 | pl = [renamed + (None,)] |
|
1665 | 1665 | else: |
|
1666 | 1666 | pl = [(path, filenode(pcl[0], path), fl)] |
|
1667 | 1667 | |
|
1668 | 1668 | for pc in pcl[1:]: |
|
1669 | 1669 | pl.append((path, filenode(pc, path), fl)) |
|
1670 | 1670 | |
|
1671 | 1671 | return [self._parentfilectx(p, fileid=n, filelog=l) |
|
1672 | 1672 | for p, n, l in pl if n != nullid] |
|
1673 | 1673 | |
|
1674 | 1674 | def children(self): |
|
1675 | 1675 | return [] |
|
1676 | 1676 | |
|
1677 | 1677 | class workingfilectx(committablefilectx): |
|
1678 | 1678 | """A workingfilectx object makes access to data related to a particular |
|
1679 | 1679 | file in the working directory convenient.""" |
|
1680 | 1680 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
1681 | 1681 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) |
|
1682 | 1682 | |
|
1683 | 1683 | @propertycache |
|
1684 | 1684 | def _changectx(self): |
|
1685 | 1685 | return workingctx(self._repo) |
|
1686 | 1686 | |
|
1687 | 1687 | def data(self): |
|
1688 | 1688 | return self._repo.wread(self._path) |
|
1689 | 1689 | def renamed(self): |
|
1690 | 1690 | rp = self._repo.dirstate.copied(self._path) |
|
1691 | 1691 | if not rp: |
|
1692 | 1692 | return None |
|
1693 | 1693 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
1694 | 1694 | |
|
1695 | 1695 | def size(self): |
|
1696 | 1696 | return self._repo.wvfs.lstat(self._path).st_size |
|
1697 | 1697 | def date(self): |
|
1698 | 1698 | t, tz = self._changectx.date() |
|
1699 | 1699 | try: |
|
1700 | 1700 | return (self._repo.wvfs.lstat(self._path)[stat.ST_MTIME], tz) |
|
1701 | 1701 | except OSError as err: |
|
1702 | 1702 | if err.errno != errno.ENOENT: |
|
1703 | 1703 | raise |
|
1704 | 1704 | return (t, tz) |
|
1705 | 1705 | |
|
1706 | 1706 | def exists(self): |
|
1707 | 1707 | return self._repo.wvfs.exists(self._path) |
|
1708 | 1708 | |
|
1709 | 1709 | def lexists(self): |
|
1710 | 1710 | return self._repo.wvfs.lexists(self._path) |
|
1711 | 1711 | |
|
1712 | 1712 | def audit(self): |
|
1713 | 1713 | return self._repo.wvfs.audit(self._path) |
|
1714 | 1714 | |
|
1715 | 1715 | def cmp(self, fctx): |
|
1716 | 1716 | """compare with other file context |
|
1717 | 1717 | |
|
1718 | 1718 | returns True if different than fctx. |
|
1719 | 1719 | """ |
|
1720 | 1720 | # fctx should be a filectx (not a workingfilectx) |
|
1721 | 1721 | # invert comparison to reuse the same code path |
|
1722 | 1722 | return fctx.cmp(self) |
|
1723 | 1723 | |
|
1724 | 1724 | def remove(self, ignoremissing=False): |
|
1725 | 1725 | """wraps unlink for a repo's working directory""" |
|
1726 | 1726 | rmdir = self._repo.ui.configbool('experimental', 'removeemptydirs') |
|
1727 | 1727 | self._repo.wvfs.unlinkpath(self._path, ignoremissing=ignoremissing, |
|
1728 | 1728 | rmdir=rmdir) |
|
1729 | 1729 | |
|
1730 | 1730 | def write(self, data, flags, backgroundclose=False, **kwargs): |
|
1731 | 1731 | """wraps repo.wwrite""" |
|
1732 | 1732 | self._repo.wwrite(self._path, data, flags, |
|
1733 | 1733 | backgroundclose=backgroundclose, |
|
1734 | 1734 | **kwargs) |
|
1735 | 1735 | |
|
1736 | 1736 | def markcopied(self, src): |
|
1737 | 1737 | """marks this file a copy of `src`""" |
|
1738 | 1738 | if self._repo.dirstate[self._path] in "nma": |
|
1739 | 1739 | self._repo.dirstate.copy(src, self._path) |
|
1740 | 1740 | |
|
1741 | 1741 | def clearunknown(self): |
|
1742 | 1742 | """Removes conflicting items in the working directory so that |
|
1743 | 1743 | ``write()`` can be called successfully. |
|
1744 | 1744 | """ |
|
1745 | 1745 | wvfs = self._repo.wvfs |
|
1746 | 1746 | f = self._path |
|
1747 | 1747 | wvfs.audit(f) |
|
1748 | if self._repo.ui.configbool('experimental', 'merge.checkpathconflicts'): | |
|
1749 | # remove files under the directory as they should already be | |
|
1750 | # warned and backed up | |
|
1748 | 1751 | if wvfs.isdir(f) and not wvfs.islink(f): |
|
1749 | 1752 | wvfs.rmtree(f, forcibly=True) |
|
1750 | if self._repo.ui.configbool('experimental', 'merge.checkpathconflicts'): | |
|
1751 | 1753 | for p in reversed(list(util.finddirs(f))): |
|
1752 | 1754 | if wvfs.isfileorlink(p): |
|
1753 | 1755 | wvfs.unlink(p) |
|
1754 | 1756 | break |
|
1757 | else: | |
|
1758 | # don't remove files if path conflicts are not processed | |
|
1759 | if wvfs.isdir(f) and not wvfs.islink(f): | |
|
1760 | wvfs.removedirs(f) | |
|
1755 | 1761 | |
|
1756 | 1762 | def setflags(self, l, x): |
|
1757 | 1763 | self._repo.wvfs.setflags(self._path, l, x) |
|
1758 | 1764 | |
|
1759 | 1765 | class overlayworkingctx(committablectx): |
|
1760 | 1766 | """Wraps another mutable context with a write-back cache that can be |
|
1761 | 1767 | converted into a commit context. |
|
1762 | 1768 | |
|
1763 | 1769 | self._cache[path] maps to a dict with keys: { |
|
1764 | 1770 | 'exists': bool? |
|
1765 | 1771 | 'date': date? |
|
1766 | 1772 | 'data': str? |
|
1767 | 1773 | 'flags': str? |
|
1768 | 1774 | 'copied': str? (path or None) |
|
1769 | 1775 | } |
|
1770 | 1776 | If `exists` is True, `flags` must be non-None and 'date' is non-None. If it |
|
1771 | 1777 | is `False`, the file was deleted. |
|
1772 | 1778 | """ |
|
1773 | 1779 | |
|
1774 | 1780 | def __init__(self, repo): |
|
1775 | 1781 | super(overlayworkingctx, self).__init__(repo) |
|
1776 | 1782 | self.clean() |
|
1777 | 1783 | |
|
1778 | 1784 | def setbase(self, wrappedctx): |
|
1779 | 1785 | self._wrappedctx = wrappedctx |
|
1780 | 1786 | self._parents = [wrappedctx] |
|
1781 | 1787 | # Drop old manifest cache as it is now out of date. |
|
1782 | 1788 | # This is necessary when, e.g., rebasing several nodes with one |
|
1783 | 1789 | # ``overlayworkingctx`` (e.g. with --collapse). |
|
1784 | 1790 | util.clearcachedproperty(self, '_manifest') |
|
1785 | 1791 | |
|
1786 | 1792 | def data(self, path): |
|
1787 | 1793 | if self.isdirty(path): |
|
1788 | 1794 | if self._cache[path]['exists']: |
|
1789 | 1795 | if self._cache[path]['data']: |
|
1790 | 1796 | return self._cache[path]['data'] |
|
1791 | 1797 | else: |
|
1792 | 1798 | # Must fallback here, too, because we only set flags. |
|
1793 | 1799 | return self._wrappedctx[path].data() |
|
1794 | 1800 | else: |
|
1795 | 1801 | raise error.ProgrammingError("No such file or directory: %s" % |
|
1796 | 1802 | path) |
|
1797 | 1803 | else: |
|
1798 | 1804 | return self._wrappedctx[path].data() |
|
1799 | 1805 | |
|
1800 | 1806 | @propertycache |
|
1801 | 1807 | def _manifest(self): |
|
1802 | 1808 | parents = self.parents() |
|
1803 | 1809 | man = parents[0].manifest().copy() |
|
1804 | 1810 | |
|
1805 | 1811 | flag = self._flagfunc |
|
1806 | 1812 | for path in self.added(): |
|
1807 | 1813 | man[path] = addednodeid |
|
1808 | 1814 | man.setflag(path, flag(path)) |
|
1809 | 1815 | for path in self.modified(): |
|
1810 | 1816 | man[path] = modifiednodeid |
|
1811 | 1817 | man.setflag(path, flag(path)) |
|
1812 | 1818 | for path in self.removed(): |
|
1813 | 1819 | del man[path] |
|
1814 | 1820 | return man |
|
1815 | 1821 | |
|
1816 | 1822 | @propertycache |
|
1817 | 1823 | def _flagfunc(self): |
|
1818 | 1824 | def f(path): |
|
1819 | 1825 | return self._cache[path]['flags'] |
|
1820 | 1826 | return f |
|
1821 | 1827 | |
|
1822 | 1828 | def files(self): |
|
1823 | 1829 | return sorted(self.added() + self.modified() + self.removed()) |
|
1824 | 1830 | |
|
1825 | 1831 | def modified(self): |
|
1826 | 1832 | return [f for f in self._cache.keys() if self._cache[f]['exists'] and |
|
1827 | 1833 | self._existsinparent(f)] |
|
1828 | 1834 | |
|
1829 | 1835 | def added(self): |
|
1830 | 1836 | return [f for f in self._cache.keys() if self._cache[f]['exists'] and |
|
1831 | 1837 | not self._existsinparent(f)] |
|
1832 | 1838 | |
|
1833 | 1839 | def removed(self): |
|
1834 | 1840 | return [f for f in self._cache.keys() if |
|
1835 | 1841 | not self._cache[f]['exists'] and self._existsinparent(f)] |
|
1836 | 1842 | |
|
1837 | 1843 | def isinmemory(self): |
|
1838 | 1844 | return True |
|
1839 | 1845 | |
|
1840 | 1846 | def filedate(self, path): |
|
1841 | 1847 | if self.isdirty(path): |
|
1842 | 1848 | return self._cache[path]['date'] |
|
1843 | 1849 | else: |
|
1844 | 1850 | return self._wrappedctx[path].date() |
|
1845 | 1851 | |
|
1846 | 1852 | def markcopied(self, path, origin): |
|
1847 | 1853 | if self.isdirty(path): |
|
1848 | 1854 | self._cache[path]['copied'] = origin |
|
1849 | 1855 | else: |
|
1850 | 1856 | raise error.ProgrammingError('markcopied() called on clean context') |
|
1851 | 1857 | |
|
1852 | 1858 | def copydata(self, path): |
|
1853 | 1859 | if self.isdirty(path): |
|
1854 | 1860 | return self._cache[path]['copied'] |
|
1855 | 1861 | else: |
|
1856 | 1862 | raise error.ProgrammingError('copydata() called on clean context') |
|
1857 | 1863 | |
|
1858 | 1864 | def flags(self, path): |
|
1859 | 1865 | if self.isdirty(path): |
|
1860 | 1866 | if self._cache[path]['exists']: |
|
1861 | 1867 | return self._cache[path]['flags'] |
|
1862 | 1868 | else: |
|
1863 | 1869 | raise error.ProgrammingError("No such file or directory: %s" % |
|
1864 | 1870 | self._path) |
|
1865 | 1871 | else: |
|
1866 | 1872 | return self._wrappedctx[path].flags() |
|
1867 | 1873 | |
|
1868 | 1874 | def _existsinparent(self, path): |
|
1869 | 1875 | try: |
|
1870 | 1876 | # ``commitctx` raises a ``ManifestLookupError`` if a path does not |
|
1871 | 1877 | # exist, unlike ``workingctx``, which returns a ``workingfilectx`` |
|
1872 | 1878 | # with an ``exists()`` function. |
|
1873 | 1879 | self._wrappedctx[path] |
|
1874 | 1880 | return True |
|
1875 | 1881 | except error.ManifestLookupError: |
|
1876 | 1882 | return False |
|
1877 | 1883 | |
|
1878 | 1884 | def _auditconflicts(self, path): |
|
1879 | 1885 | """Replicates conflict checks done by wvfs.write(). |
|
1880 | 1886 | |
|
1881 | 1887 | Since we never write to the filesystem and never call `applyupdates` in |
|
1882 | 1888 | IMM, we'll never check that a path is actually writable -- e.g., because |
|
1883 | 1889 | it adds `a/foo`, but `a` is actually a file in the other commit. |
|
1884 | 1890 | """ |
|
1885 | 1891 | def fail(path, component): |
|
1886 | 1892 | # p1() is the base and we're receiving "writes" for p2()'s |
|
1887 | 1893 | # files. |
|
1888 | 1894 | if 'l' in self.p1()[component].flags(): |
|
1889 | 1895 | raise error.Abort("error: %s conflicts with symlink %s " |
|
1890 | 1896 | "in %s." % (path, component, |
|
1891 | 1897 | self.p1().rev())) |
|
1892 | 1898 | else: |
|
1893 | 1899 | raise error.Abort("error: '%s' conflicts with file '%s' in " |
|
1894 | 1900 | "%s." % (path, component, |
|
1895 | 1901 | self.p1().rev())) |
|
1896 | 1902 | |
|
1897 | 1903 | # Test that each new directory to be created to write this path from p2 |
|
1898 | 1904 | # is not a file in p1. |
|
1899 | 1905 | components = path.split('/') |
|
1900 | 1906 | for i in xrange(len(components)): |
|
1901 | 1907 | component = "/".join(components[0:i]) |
|
1902 | 1908 | if component in self.p1(): |
|
1903 | 1909 | fail(path, component) |
|
1904 | 1910 | |
|
1905 | 1911 | # Test the other direction -- that this path from p2 isn't a directory |
|
1906 | 1912 | # in p1 (test that p1 doesn't any paths matching `path/*`). |
|
1907 | 1913 | match = matchmod.match('/', '', [path + '/'], default=b'relpath') |
|
1908 | 1914 | matches = self.p1().manifest().matches(match) |
|
1909 | 1915 | if len(matches) > 0: |
|
1910 | 1916 | if len(matches) == 1 and matches.keys()[0] == path: |
|
1911 | 1917 | return |
|
1912 | 1918 | raise error.Abort("error: file '%s' cannot be written because " |
|
1913 | 1919 | " '%s/' is a folder in %s (containing %d " |
|
1914 | 1920 | "entries: %s)" |
|
1915 | 1921 | % (path, path, self.p1(), len(matches), |
|
1916 | 1922 | ', '.join(matches.keys()))) |
|
1917 | 1923 | |
|
1918 | 1924 | def write(self, path, data, flags='', **kwargs): |
|
1919 | 1925 | if data is None: |
|
1920 | 1926 | raise error.ProgrammingError("data must be non-None") |
|
1921 | 1927 | self._auditconflicts(path) |
|
1922 | 1928 | self._markdirty(path, exists=True, data=data, date=dateutil.makedate(), |
|
1923 | 1929 | flags=flags) |
|
1924 | 1930 | |
|
1925 | 1931 | def setflags(self, path, l, x): |
|
1926 | 1932 | self._markdirty(path, exists=True, date=dateutil.makedate(), |
|
1927 | 1933 | flags=(l and 'l' or '') + (x and 'x' or '')) |
|
1928 | 1934 | |
|
1929 | 1935 | def remove(self, path): |
|
1930 | 1936 | self._markdirty(path, exists=False) |
|
1931 | 1937 | |
|
1932 | 1938 | def exists(self, path): |
|
1933 | 1939 | """exists behaves like `lexists`, but needs to follow symlinks and |
|
1934 | 1940 | return False if they are broken. |
|
1935 | 1941 | """ |
|
1936 | 1942 | if self.isdirty(path): |
|
1937 | 1943 | # If this path exists and is a symlink, "follow" it by calling |
|
1938 | 1944 | # exists on the destination path. |
|
1939 | 1945 | if (self._cache[path]['exists'] and |
|
1940 | 1946 | 'l' in self._cache[path]['flags']): |
|
1941 | 1947 | return self.exists(self._cache[path]['data'].strip()) |
|
1942 | 1948 | else: |
|
1943 | 1949 | return self._cache[path]['exists'] |
|
1944 | 1950 | |
|
1945 | 1951 | return self._existsinparent(path) |
|
1946 | 1952 | |
|
1947 | 1953 | def lexists(self, path): |
|
1948 | 1954 | """lexists returns True if the path exists""" |
|
1949 | 1955 | if self.isdirty(path): |
|
1950 | 1956 | return self._cache[path]['exists'] |
|
1951 | 1957 | |
|
1952 | 1958 | return self._existsinparent(path) |
|
1953 | 1959 | |
|
1954 | 1960 | def size(self, path): |
|
1955 | 1961 | if self.isdirty(path): |
|
1956 | 1962 | if self._cache[path]['exists']: |
|
1957 | 1963 | return len(self._cache[path]['data']) |
|
1958 | 1964 | else: |
|
1959 | 1965 | raise error.ProgrammingError("No such file or directory: %s" % |
|
1960 | 1966 | self._path) |
|
1961 | 1967 | return self._wrappedctx[path].size() |
|
1962 | 1968 | |
|
1963 | 1969 | def tomemctx(self, text, branch=None, extra=None, date=None, parents=None, |
|
1964 | 1970 | user=None, editor=None): |
|
1965 | 1971 | """Converts this ``overlayworkingctx`` into a ``memctx`` ready to be |
|
1966 | 1972 | committed. |
|
1967 | 1973 | |
|
1968 | 1974 | ``text`` is the commit message. |
|
1969 | 1975 | ``parents`` (optional) are rev numbers. |
|
1970 | 1976 | """ |
|
1971 | 1977 | # Default parents to the wrapped contexts' if not passed. |
|
1972 | 1978 | if parents is None: |
|
1973 | 1979 | parents = self._wrappedctx.parents() |
|
1974 | 1980 | if len(parents) == 1: |
|
1975 | 1981 | parents = (parents[0], None) |
|
1976 | 1982 | |
|
1977 | 1983 | # ``parents`` is passed as rev numbers; convert to ``commitctxs``. |
|
1978 | 1984 | if parents[1] is None: |
|
1979 | 1985 | parents = (self._repo[parents[0]], None) |
|
1980 | 1986 | else: |
|
1981 | 1987 | parents = (self._repo[parents[0]], self._repo[parents[1]]) |
|
1982 | 1988 | |
|
1983 | 1989 | files = self._cache.keys() |
|
1984 | 1990 | def getfile(repo, memctx, path): |
|
1985 | 1991 | if self._cache[path]['exists']: |
|
1986 | 1992 | return memfilectx(repo, memctx, path, |
|
1987 | 1993 | self._cache[path]['data'], |
|
1988 | 1994 | 'l' in self._cache[path]['flags'], |
|
1989 | 1995 | 'x' in self._cache[path]['flags'], |
|
1990 | 1996 | self._cache[path]['copied']) |
|
1991 | 1997 | else: |
|
1992 | 1998 | # Returning None, but including the path in `files`, is |
|
1993 | 1999 | # necessary for memctx to register a deletion. |
|
1994 | 2000 | return None |
|
1995 | 2001 | return memctx(self._repo, parents, text, files, getfile, date=date, |
|
1996 | 2002 | extra=extra, user=user, branch=branch, editor=editor) |
|
1997 | 2003 | |
|
1998 | 2004 | def isdirty(self, path): |
|
1999 | 2005 | return path in self._cache |
|
2000 | 2006 | |
|
2001 | 2007 | def isempty(self): |
|
2002 | 2008 | # We need to discard any keys that are actually clean before the empty |
|
2003 | 2009 | # commit check. |
|
2004 | 2010 | self._compact() |
|
2005 | 2011 | return len(self._cache) == 0 |
|
2006 | 2012 | |
|
2007 | 2013 | def clean(self): |
|
2008 | 2014 | self._cache = {} |
|
2009 | 2015 | |
|
2010 | 2016 | def _compact(self): |
|
2011 | 2017 | """Removes keys from the cache that are actually clean, by comparing |
|
2012 | 2018 | them with the underlying context. |
|
2013 | 2019 | |
|
2014 | 2020 | This can occur during the merge process, e.g. by passing --tool :local |
|
2015 | 2021 | to resolve a conflict. |
|
2016 | 2022 | """ |
|
2017 | 2023 | keys = [] |
|
2018 | 2024 | for path in self._cache.keys(): |
|
2019 | 2025 | cache = self._cache[path] |
|
2020 | 2026 | try: |
|
2021 | 2027 | underlying = self._wrappedctx[path] |
|
2022 | 2028 | if (underlying.data() == cache['data'] and |
|
2023 | 2029 | underlying.flags() == cache['flags']): |
|
2024 | 2030 | keys.append(path) |
|
2025 | 2031 | except error.ManifestLookupError: |
|
2026 | 2032 | # Path not in the underlying manifest (created). |
|
2027 | 2033 | continue |
|
2028 | 2034 | |
|
2029 | 2035 | for path in keys: |
|
2030 | 2036 | del self._cache[path] |
|
2031 | 2037 | return keys |
|
2032 | 2038 | |
|
2033 | 2039 | def _markdirty(self, path, exists, data=None, date=None, flags=''): |
|
2034 | 2040 | self._cache[path] = { |
|
2035 | 2041 | 'exists': exists, |
|
2036 | 2042 | 'data': data, |
|
2037 | 2043 | 'date': date, |
|
2038 | 2044 | 'flags': flags, |
|
2039 | 2045 | 'copied': None, |
|
2040 | 2046 | } |
|
2041 | 2047 | |
|
2042 | 2048 | def filectx(self, path, filelog=None): |
|
2043 | 2049 | return overlayworkingfilectx(self._repo, path, parent=self, |
|
2044 | 2050 | filelog=filelog) |
|
2045 | 2051 | |
|
2046 | 2052 | class overlayworkingfilectx(committablefilectx): |
|
2047 | 2053 | """Wrap a ``workingfilectx`` but intercepts all writes into an in-memory |
|
2048 | 2054 | cache, which can be flushed through later by calling ``flush()``.""" |
|
2049 | 2055 | |
|
2050 | 2056 | def __init__(self, repo, path, filelog=None, parent=None): |
|
2051 | 2057 | super(overlayworkingfilectx, self).__init__(repo, path, filelog, |
|
2052 | 2058 | parent) |
|
2053 | 2059 | self._repo = repo |
|
2054 | 2060 | self._parent = parent |
|
2055 | 2061 | self._path = path |
|
2056 | 2062 | |
|
2057 | 2063 | def cmp(self, fctx): |
|
2058 | 2064 | return self.data() != fctx.data() |
|
2059 | 2065 | |
|
2060 | 2066 | def changectx(self): |
|
2061 | 2067 | return self._parent |
|
2062 | 2068 | |
|
2063 | 2069 | def data(self): |
|
2064 | 2070 | return self._parent.data(self._path) |
|
2065 | 2071 | |
|
2066 | 2072 | def date(self): |
|
2067 | 2073 | return self._parent.filedate(self._path) |
|
2068 | 2074 | |
|
2069 | 2075 | def exists(self): |
|
2070 | 2076 | return self.lexists() |
|
2071 | 2077 | |
|
2072 | 2078 | def lexists(self): |
|
2073 | 2079 | return self._parent.exists(self._path) |
|
2074 | 2080 | |
|
2075 | 2081 | def renamed(self): |
|
2076 | 2082 | path = self._parent.copydata(self._path) |
|
2077 | 2083 | if not path: |
|
2078 | 2084 | return None |
|
2079 | 2085 | return path, self._changectx._parents[0]._manifest.get(path, nullid) |
|
2080 | 2086 | |
|
2081 | 2087 | def size(self): |
|
2082 | 2088 | return self._parent.size(self._path) |
|
2083 | 2089 | |
|
2084 | 2090 | def markcopied(self, origin): |
|
2085 | 2091 | self._parent.markcopied(self._path, origin) |
|
2086 | 2092 | |
|
2087 | 2093 | def audit(self): |
|
2088 | 2094 | pass |
|
2089 | 2095 | |
|
2090 | 2096 | def flags(self): |
|
2091 | 2097 | return self._parent.flags(self._path) |
|
2092 | 2098 | |
|
2093 | 2099 | def setflags(self, islink, isexec): |
|
2094 | 2100 | return self._parent.setflags(self._path, islink, isexec) |
|
2095 | 2101 | |
|
2096 | 2102 | def write(self, data, flags, backgroundclose=False, **kwargs): |
|
2097 | 2103 | return self._parent.write(self._path, data, flags, **kwargs) |
|
2098 | 2104 | |
|
2099 | 2105 | def remove(self, ignoremissing=False): |
|
2100 | 2106 | return self._parent.remove(self._path) |
|
2101 | 2107 | |
|
2102 | 2108 | def clearunknown(self): |
|
2103 | 2109 | pass |
|
2104 | 2110 | |
|
2105 | 2111 | class workingcommitctx(workingctx): |
|
2106 | 2112 | """A workingcommitctx object makes access to data related to |
|
2107 | 2113 | the revision being committed convenient. |
|
2108 | 2114 | |
|
2109 | 2115 | This hides changes in the working directory, if they aren't |
|
2110 | 2116 | committed in this context. |
|
2111 | 2117 | """ |
|
2112 | 2118 | def __init__(self, repo, changes, |
|
2113 | 2119 | text="", user=None, date=None, extra=None): |
|
2114 | 2120 | super(workingctx, self).__init__(repo, text, user, date, extra, |
|
2115 | 2121 | changes) |
|
2116 | 2122 | |
|
2117 | 2123 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): |
|
2118 | 2124 | """Return matched files only in ``self._status`` |
|
2119 | 2125 | |
|
2120 | 2126 | Uncommitted files appear "clean" via this context, even if |
|
2121 | 2127 | they aren't actually so in the working directory. |
|
2122 | 2128 | """ |
|
2123 | 2129 | if clean: |
|
2124 | 2130 | clean = [f for f in self._manifest if f not in self._changedset] |
|
2125 | 2131 | else: |
|
2126 | 2132 | clean = [] |
|
2127 | 2133 | return scmutil.status([f for f in self._status.modified if match(f)], |
|
2128 | 2134 | [f for f in self._status.added if match(f)], |
|
2129 | 2135 | [f for f in self._status.removed if match(f)], |
|
2130 | 2136 | [], [], [], clean) |
|
2131 | 2137 | |
|
2132 | 2138 | @propertycache |
|
2133 | 2139 | def _changedset(self): |
|
2134 | 2140 | """Return the set of files changed in this context |
|
2135 | 2141 | """ |
|
2136 | 2142 | changed = set(self._status.modified) |
|
2137 | 2143 | changed.update(self._status.added) |
|
2138 | 2144 | changed.update(self._status.removed) |
|
2139 | 2145 | return changed |
|
2140 | 2146 | |
|
2141 | 2147 | def makecachingfilectxfn(func): |
|
2142 | 2148 | """Create a filectxfn that caches based on the path. |
|
2143 | 2149 | |
|
2144 | 2150 | We can't use util.cachefunc because it uses all arguments as the cache |
|
2145 | 2151 | key and this creates a cycle since the arguments include the repo and |
|
2146 | 2152 | memctx. |
|
2147 | 2153 | """ |
|
2148 | 2154 | cache = {} |
|
2149 | 2155 | |
|
2150 | 2156 | def getfilectx(repo, memctx, path): |
|
2151 | 2157 | if path not in cache: |
|
2152 | 2158 | cache[path] = func(repo, memctx, path) |
|
2153 | 2159 | return cache[path] |
|
2154 | 2160 | |
|
2155 | 2161 | return getfilectx |
|
2156 | 2162 | |
|
2157 | 2163 | def memfilefromctx(ctx): |
|
2158 | 2164 | """Given a context return a memfilectx for ctx[path] |
|
2159 | 2165 | |
|
2160 | 2166 | This is a convenience method for building a memctx based on another |
|
2161 | 2167 | context. |
|
2162 | 2168 | """ |
|
2163 | 2169 | def getfilectx(repo, memctx, path): |
|
2164 | 2170 | fctx = ctx[path] |
|
2165 | 2171 | # this is weird but apparently we only keep track of one parent |
|
2166 | 2172 | # (why not only store that instead of a tuple?) |
|
2167 | 2173 | copied = fctx.renamed() |
|
2168 | 2174 | if copied: |
|
2169 | 2175 | copied = copied[0] |
|
2170 | 2176 | return memfilectx(repo, memctx, path, fctx.data(), |
|
2171 | 2177 | islink=fctx.islink(), isexec=fctx.isexec(), |
|
2172 | 2178 | copied=copied) |
|
2173 | 2179 | |
|
2174 | 2180 | return getfilectx |
|
2175 | 2181 | |
|
2176 | 2182 | def memfilefrompatch(patchstore): |
|
2177 | 2183 | """Given a patch (e.g. patchstore object) return a memfilectx |
|
2178 | 2184 | |
|
2179 | 2185 | This is a convenience method for building a memctx based on a patchstore. |
|
2180 | 2186 | """ |
|
2181 | 2187 | def getfilectx(repo, memctx, path): |
|
2182 | 2188 | data, mode, copied = patchstore.getfile(path) |
|
2183 | 2189 | if data is None: |
|
2184 | 2190 | return None |
|
2185 | 2191 | islink, isexec = mode |
|
2186 | 2192 | return memfilectx(repo, memctx, path, data, islink=islink, |
|
2187 | 2193 | isexec=isexec, copied=copied) |
|
2188 | 2194 | |
|
2189 | 2195 | return getfilectx |
|
2190 | 2196 | |
|
2191 | 2197 | class memctx(committablectx): |
|
2192 | 2198 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
2193 | 2199 | |
|
2194 | 2200 | Revision information is supplied at initialization time while |
|
2195 | 2201 | related files data and is made available through a callback |
|
2196 | 2202 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
2197 | 2203 | sequence of two parent revisions identifiers (pass None for every |
|
2198 | 2204 | missing parent), 'text' is the commit message and 'files' lists |
|
2199 | 2205 | names of files touched by the revision (normalized and relative to |
|
2200 | 2206 | repository root). |
|
2201 | 2207 | |
|
2202 | 2208 | filectxfn(repo, memctx, path) is a callable receiving the |
|
2203 | 2209 | repository, the current memctx object and the normalized path of |
|
2204 | 2210 | requested file, relative to repository root. It is fired by the |
|
2205 | 2211 | commit function for every file in 'files', but calls order is |
|
2206 | 2212 | undefined. If the file is available in the revision being |
|
2207 | 2213 | committed (updated or added), filectxfn returns a memfilectx |
|
2208 | 2214 | object. If the file was removed, filectxfn return None for recent |
|
2209 | 2215 | Mercurial. Moved files are represented by marking the source file |
|
2210 | 2216 | removed and the new file added with copy information (see |
|
2211 | 2217 | memfilectx). |
|
2212 | 2218 | |
|
2213 | 2219 | user receives the committer name and defaults to current |
|
2214 | 2220 | repository username, date is the commit date in any format |
|
2215 | 2221 | supported by dateutil.parsedate() and defaults to current date, extra |
|
2216 | 2222 | is a dictionary of metadata or is left empty. |
|
2217 | 2223 | """ |
|
2218 | 2224 | |
|
2219 | 2225 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. |
|
2220 | 2226 | # Extensions that need to retain compatibility across Mercurial 3.1 can use |
|
2221 | 2227 | # this field to determine what to do in filectxfn. |
|
2222 | 2228 | _returnnoneformissingfiles = True |
|
2223 | 2229 | |
|
2224 | 2230 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
2225 | 2231 | date=None, extra=None, branch=None, editor=False): |
|
2226 | 2232 | super(memctx, self).__init__(repo, text, user, date, extra) |
|
2227 | 2233 | self._rev = None |
|
2228 | 2234 | self._node = None |
|
2229 | 2235 | parents = [(p or nullid) for p in parents] |
|
2230 | 2236 | p1, p2 = parents |
|
2231 | 2237 | self._parents = [self._repo[p] for p in (p1, p2)] |
|
2232 | 2238 | files = sorted(set(files)) |
|
2233 | 2239 | self._files = files |
|
2234 | 2240 | if branch is not None: |
|
2235 | 2241 | self._extra['branch'] = encoding.fromlocal(branch) |
|
2236 | 2242 | self.substate = {} |
|
2237 | 2243 | |
|
2238 | 2244 | if isinstance(filectxfn, patch.filestore): |
|
2239 | 2245 | filectxfn = memfilefrompatch(filectxfn) |
|
2240 | 2246 | elif not callable(filectxfn): |
|
2241 | 2247 | # if store is not callable, wrap it in a function |
|
2242 | 2248 | filectxfn = memfilefromctx(filectxfn) |
|
2243 | 2249 | |
|
2244 | 2250 | # memoizing increases performance for e.g. vcs convert scenarios. |
|
2245 | 2251 | self._filectxfn = makecachingfilectxfn(filectxfn) |
|
2246 | 2252 | |
|
2247 | 2253 | if editor: |
|
2248 | 2254 | self._text = editor(self._repo, self, []) |
|
2249 | 2255 | self._repo.savecommitmessage(self._text) |
|
2250 | 2256 | |
|
2251 | 2257 | def filectx(self, path, filelog=None): |
|
2252 | 2258 | """get a file context from the working directory |
|
2253 | 2259 | |
|
2254 | 2260 | Returns None if file doesn't exist and should be removed.""" |
|
2255 | 2261 | return self._filectxfn(self._repo, self, path) |
|
2256 | 2262 | |
|
2257 | 2263 | def commit(self): |
|
2258 | 2264 | """commit context to the repo""" |
|
2259 | 2265 | return self._repo.commitctx(self) |
|
2260 | 2266 | |
|
2261 | 2267 | @propertycache |
|
2262 | 2268 | def _manifest(self): |
|
2263 | 2269 | """generate a manifest based on the return values of filectxfn""" |
|
2264 | 2270 | |
|
2265 | 2271 | # keep this simple for now; just worry about p1 |
|
2266 | 2272 | pctx = self._parents[0] |
|
2267 | 2273 | man = pctx.manifest().copy() |
|
2268 | 2274 | |
|
2269 | 2275 | for f in self._status.modified: |
|
2270 | 2276 | p1node = nullid |
|
2271 | 2277 | p2node = nullid |
|
2272 | 2278 | p = pctx[f].parents() # if file isn't in pctx, check p2? |
|
2273 | 2279 | if len(p) > 0: |
|
2274 | 2280 | p1node = p[0].filenode() |
|
2275 | 2281 | if len(p) > 1: |
|
2276 | 2282 | p2node = p[1].filenode() |
|
2277 | 2283 | man[f] = revlog.hash(self[f].data(), p1node, p2node) |
|
2278 | 2284 | |
|
2279 | 2285 | for f in self._status.added: |
|
2280 | 2286 | man[f] = revlog.hash(self[f].data(), nullid, nullid) |
|
2281 | 2287 | |
|
2282 | 2288 | for f in self._status.removed: |
|
2283 | 2289 | if f in man: |
|
2284 | 2290 | del man[f] |
|
2285 | 2291 | |
|
2286 | 2292 | return man |
|
2287 | 2293 | |
|
2288 | 2294 | @propertycache |
|
2289 | 2295 | def _status(self): |
|
2290 | 2296 | """Calculate exact status from ``files`` specified at construction |
|
2291 | 2297 | """ |
|
2292 | 2298 | man1 = self.p1().manifest() |
|
2293 | 2299 | p2 = self._parents[1] |
|
2294 | 2300 | # "1 < len(self._parents)" can't be used for checking |
|
2295 | 2301 | # existence of the 2nd parent, because "memctx._parents" is |
|
2296 | 2302 | # explicitly initialized by the list, of which length is 2. |
|
2297 | 2303 | if p2.node() != nullid: |
|
2298 | 2304 | man2 = p2.manifest() |
|
2299 | 2305 | managing = lambda f: f in man1 or f in man2 |
|
2300 | 2306 | else: |
|
2301 | 2307 | managing = lambda f: f in man1 |
|
2302 | 2308 | |
|
2303 | 2309 | modified, added, removed = [], [], [] |
|
2304 | 2310 | for f in self._files: |
|
2305 | 2311 | if not managing(f): |
|
2306 | 2312 | added.append(f) |
|
2307 | 2313 | elif self[f]: |
|
2308 | 2314 | modified.append(f) |
|
2309 | 2315 | else: |
|
2310 | 2316 | removed.append(f) |
|
2311 | 2317 | |
|
2312 | 2318 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
2313 | 2319 | |
|
2314 | 2320 | class memfilectx(committablefilectx): |
|
2315 | 2321 | """memfilectx represents an in-memory file to commit. |
|
2316 | 2322 | |
|
2317 | 2323 | See memctx and committablefilectx for more details. |
|
2318 | 2324 | """ |
|
2319 | 2325 | def __init__(self, repo, changectx, path, data, islink=False, |
|
2320 | 2326 | isexec=False, copied=None): |
|
2321 | 2327 | """ |
|
2322 | 2328 | path is the normalized file path relative to repository root. |
|
2323 | 2329 | data is the file content as a string. |
|
2324 | 2330 | islink is True if the file is a symbolic link. |
|
2325 | 2331 | isexec is True if the file is executable. |
|
2326 | 2332 | copied is the source file path if current file was copied in the |
|
2327 | 2333 | revision being committed, or None.""" |
|
2328 | 2334 | super(memfilectx, self).__init__(repo, path, None, changectx) |
|
2329 | 2335 | self._data = data |
|
2330 | 2336 | if islink: |
|
2331 | 2337 | self._flags = 'l' |
|
2332 | 2338 | elif isexec: |
|
2333 | 2339 | self._flags = 'x' |
|
2334 | 2340 | else: |
|
2335 | 2341 | self._flags = '' |
|
2336 | 2342 | self._copied = None |
|
2337 | 2343 | if copied: |
|
2338 | 2344 | self._copied = (copied, nullid) |
|
2339 | 2345 | |
|
2340 | 2346 | def data(self): |
|
2341 | 2347 | return self._data |
|
2342 | 2348 | |
|
2343 | 2349 | def remove(self, ignoremissing=False): |
|
2344 | 2350 | """wraps unlink for a repo's working directory""" |
|
2345 | 2351 | # need to figure out what to do here |
|
2346 | 2352 | del self._changectx[self._path] |
|
2347 | 2353 | |
|
2348 | 2354 | def write(self, data, flags, **kwargs): |
|
2349 | 2355 | """wraps repo.wwrite""" |
|
2350 | 2356 | self._data = data |
|
2351 | 2357 | |
|
2352 | 2358 | class overlayfilectx(committablefilectx): |
|
2353 | 2359 | """Like memfilectx but take an original filectx and optional parameters to |
|
2354 | 2360 | override parts of it. This is useful when fctx.data() is expensive (i.e. |
|
2355 | 2361 | flag processor is expensive) and raw data, flags, and filenode could be |
|
2356 | 2362 | reused (ex. rebase or mode-only amend a REVIDX_EXTSTORED file). |
|
2357 | 2363 | """ |
|
2358 | 2364 | |
|
2359 | 2365 | def __init__(self, originalfctx, datafunc=None, path=None, flags=None, |
|
2360 | 2366 | copied=None, ctx=None): |
|
2361 | 2367 | """originalfctx: filecontext to duplicate |
|
2362 | 2368 | |
|
2363 | 2369 | datafunc: None or a function to override data (file content). It is a |
|
2364 | 2370 | function to be lazy. path, flags, copied, ctx: None or overridden value |
|
2365 | 2371 | |
|
2366 | 2372 | copied could be (path, rev), or False. copied could also be just path, |
|
2367 | 2373 | and will be converted to (path, nullid). This simplifies some callers. |
|
2368 | 2374 | """ |
|
2369 | 2375 | |
|
2370 | 2376 | if path is None: |
|
2371 | 2377 | path = originalfctx.path() |
|
2372 | 2378 | if ctx is None: |
|
2373 | 2379 | ctx = originalfctx.changectx() |
|
2374 | 2380 | ctxmatch = lambda: True |
|
2375 | 2381 | else: |
|
2376 | 2382 | ctxmatch = lambda: ctx == originalfctx.changectx() |
|
2377 | 2383 | |
|
2378 | 2384 | repo = originalfctx.repo() |
|
2379 | 2385 | flog = originalfctx.filelog() |
|
2380 | 2386 | super(overlayfilectx, self).__init__(repo, path, flog, ctx) |
|
2381 | 2387 | |
|
2382 | 2388 | if copied is None: |
|
2383 | 2389 | copied = originalfctx.renamed() |
|
2384 | 2390 | copiedmatch = lambda: True |
|
2385 | 2391 | else: |
|
2386 | 2392 | if copied and not isinstance(copied, tuple): |
|
2387 | 2393 | # repo._filecommit will recalculate copyrev so nullid is okay |
|
2388 | 2394 | copied = (copied, nullid) |
|
2389 | 2395 | copiedmatch = lambda: copied == originalfctx.renamed() |
|
2390 | 2396 | |
|
2391 | 2397 | # When data, copied (could affect data), ctx (could affect filelog |
|
2392 | 2398 | # parents) are not overridden, rawdata, rawflags, and filenode may be |
|
2393 | 2399 | # reused (repo._filecommit should double check filelog parents). |
|
2394 | 2400 | # |
|
2395 | 2401 | # path, flags are not hashed in filelog (but in manifestlog) so they do |
|
2396 | 2402 | # not affect reusable here. |
|
2397 | 2403 | # |
|
2398 | 2404 | # If ctx or copied is overridden to a same value with originalfctx, |
|
2399 | 2405 | # still consider it's reusable. originalfctx.renamed() may be a bit |
|
2400 | 2406 | # expensive so it's not called unless necessary. Assuming datafunc is |
|
2401 | 2407 | # always expensive, do not call it for this "reusable" test. |
|
2402 | 2408 | reusable = datafunc is None and ctxmatch() and copiedmatch() |
|
2403 | 2409 | |
|
2404 | 2410 | if datafunc is None: |
|
2405 | 2411 | datafunc = originalfctx.data |
|
2406 | 2412 | if flags is None: |
|
2407 | 2413 | flags = originalfctx.flags() |
|
2408 | 2414 | |
|
2409 | 2415 | self._datafunc = datafunc |
|
2410 | 2416 | self._flags = flags |
|
2411 | 2417 | self._copied = copied |
|
2412 | 2418 | |
|
2413 | 2419 | if reusable: |
|
2414 | 2420 | # copy extra fields from originalfctx |
|
2415 | 2421 | attrs = ['rawdata', 'rawflags', '_filenode', '_filerev'] |
|
2416 | 2422 | for attr_ in attrs: |
|
2417 | 2423 | if util.safehasattr(originalfctx, attr_): |
|
2418 | 2424 | setattr(self, attr_, getattr(originalfctx, attr_)) |
|
2419 | 2425 | |
|
2420 | 2426 | def data(self): |
|
2421 | 2427 | return self._datafunc() |
|
2422 | 2428 | |
|
2423 | 2429 | class metadataonlyctx(committablectx): |
|
2424 | 2430 | """Like memctx but it's reusing the manifest of different commit. |
|
2425 | 2431 | Intended to be used by lightweight operations that are creating |
|
2426 | 2432 | metadata-only changes. |
|
2427 | 2433 | |
|
2428 | 2434 | Revision information is supplied at initialization time. 'repo' is the |
|
2429 | 2435 | current localrepo, 'ctx' is original revision which manifest we're reuisng |
|
2430 | 2436 | 'parents' is a sequence of two parent revisions identifiers (pass None for |
|
2431 | 2437 | every missing parent), 'text' is the commit. |
|
2432 | 2438 | |
|
2433 | 2439 | user receives the committer name and defaults to current repository |
|
2434 | 2440 | username, date is the commit date in any format supported by |
|
2435 | 2441 | dateutil.parsedate() and defaults to current date, extra is a dictionary of |
|
2436 | 2442 | metadata or is left empty. |
|
2437 | 2443 | """ |
|
2438 | 2444 | def __init__(self, repo, originalctx, parents=None, text=None, user=None, |
|
2439 | 2445 | date=None, extra=None, editor=False): |
|
2440 | 2446 | if text is None: |
|
2441 | 2447 | text = originalctx.description() |
|
2442 | 2448 | super(metadataonlyctx, self).__init__(repo, text, user, date, extra) |
|
2443 | 2449 | self._rev = None |
|
2444 | 2450 | self._node = None |
|
2445 | 2451 | self._originalctx = originalctx |
|
2446 | 2452 | self._manifestnode = originalctx.manifestnode() |
|
2447 | 2453 | if parents is None: |
|
2448 | 2454 | parents = originalctx.parents() |
|
2449 | 2455 | else: |
|
2450 | 2456 | parents = [repo[p] for p in parents if p is not None] |
|
2451 | 2457 | parents = parents[:] |
|
2452 | 2458 | while len(parents) < 2: |
|
2453 | 2459 | parents.append(repo[nullid]) |
|
2454 | 2460 | p1, p2 = self._parents = parents |
|
2455 | 2461 | |
|
2456 | 2462 | # sanity check to ensure that the reused manifest parents are |
|
2457 | 2463 | # manifests of our commit parents |
|
2458 | 2464 | mp1, mp2 = self.manifestctx().parents |
|
2459 | 2465 | if p1 != nullid and p1.manifestnode() != mp1: |
|
2460 | 2466 | raise RuntimeError('can\'t reuse the manifest: ' |
|
2461 | 2467 | 'its p1 doesn\'t match the new ctx p1') |
|
2462 | 2468 | if p2 != nullid and p2.manifestnode() != mp2: |
|
2463 | 2469 | raise RuntimeError('can\'t reuse the manifest: ' |
|
2464 | 2470 | 'its p2 doesn\'t match the new ctx p2') |
|
2465 | 2471 | |
|
2466 | 2472 | self._files = originalctx.files() |
|
2467 | 2473 | self.substate = {} |
|
2468 | 2474 | |
|
2469 | 2475 | if editor: |
|
2470 | 2476 | self._text = editor(self._repo, self, []) |
|
2471 | 2477 | self._repo.savecommitmessage(self._text) |
|
2472 | 2478 | |
|
2473 | 2479 | def manifestnode(self): |
|
2474 | 2480 | return self._manifestnode |
|
2475 | 2481 | |
|
2476 | 2482 | @property |
|
2477 | 2483 | def _manifestctx(self): |
|
2478 | 2484 | return self._repo.manifestlog[self._manifestnode] |
|
2479 | 2485 | |
|
2480 | 2486 | def filectx(self, path, filelog=None): |
|
2481 | 2487 | return self._originalctx.filectx(path, filelog=filelog) |
|
2482 | 2488 | |
|
2483 | 2489 | def commit(self): |
|
2484 | 2490 | """commit context to the repo""" |
|
2485 | 2491 | return self._repo.commitctx(self) |
|
2486 | 2492 | |
|
2487 | 2493 | @property |
|
2488 | 2494 | def _manifest(self): |
|
2489 | 2495 | return self._originalctx.manifest() |
|
2490 | 2496 | |
|
2491 | 2497 | @propertycache |
|
2492 | 2498 | def _status(self): |
|
2493 | 2499 | """Calculate exact status from ``files`` specified in the ``origctx`` |
|
2494 | 2500 | and parents manifests. |
|
2495 | 2501 | """ |
|
2496 | 2502 | man1 = self.p1().manifest() |
|
2497 | 2503 | p2 = self._parents[1] |
|
2498 | 2504 | # "1 < len(self._parents)" can't be used for checking |
|
2499 | 2505 | # existence of the 2nd parent, because "metadataonlyctx._parents" is |
|
2500 | 2506 | # explicitly initialized by the list, of which length is 2. |
|
2501 | 2507 | if p2.node() != nullid: |
|
2502 | 2508 | man2 = p2.manifest() |
|
2503 | 2509 | managing = lambda f: f in man1 or f in man2 |
|
2504 | 2510 | else: |
|
2505 | 2511 | managing = lambda f: f in man1 |
|
2506 | 2512 | |
|
2507 | 2513 | modified, added, removed = [], [], [] |
|
2508 | 2514 | for f in self._files: |
|
2509 | 2515 | if not managing(f): |
|
2510 | 2516 | added.append(f) |
|
2511 | 2517 | elif f in self: |
|
2512 | 2518 | modified.append(f) |
|
2513 | 2519 | else: |
|
2514 | 2520 | removed.append(f) |
|
2515 | 2521 | |
|
2516 | 2522 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
2517 | 2523 | |
|
2518 | 2524 | class arbitraryfilectx(object): |
|
2519 | 2525 | """Allows you to use filectx-like functions on a file in an arbitrary |
|
2520 | 2526 | location on disk, possibly not in the working directory. |
|
2521 | 2527 | """ |
|
2522 | 2528 | def __init__(self, path, repo=None): |
|
2523 | 2529 | # Repo is optional because contrib/simplemerge uses this class. |
|
2524 | 2530 | self._repo = repo |
|
2525 | 2531 | self._path = path |
|
2526 | 2532 | |
|
2527 | 2533 | def cmp(self, fctx): |
|
2528 | 2534 | # filecmp follows symlinks whereas `cmp` should not, so skip the fast |
|
2529 | 2535 | # path if either side is a symlink. |
|
2530 | 2536 | symlinks = ('l' in self.flags() or 'l' in fctx.flags()) |
|
2531 | 2537 | if not symlinks and isinstance(fctx, workingfilectx) and self._repo: |
|
2532 | 2538 | # Add a fast-path for merge if both sides are disk-backed. |
|
2533 | 2539 | # Note that filecmp uses the opposite return values (True if same) |
|
2534 | 2540 | # from our cmp functions (True if different). |
|
2535 | 2541 | return not filecmp.cmp(self.path(), self._repo.wjoin(fctx.path())) |
|
2536 | 2542 | return self.data() != fctx.data() |
|
2537 | 2543 | |
|
2538 | 2544 | def path(self): |
|
2539 | 2545 | return self._path |
|
2540 | 2546 | |
|
2541 | 2547 | def flags(self): |
|
2542 | 2548 | return '' |
|
2543 | 2549 | |
|
2544 | 2550 | def data(self): |
|
2545 | 2551 | return util.readfile(self._path) |
|
2546 | 2552 | |
|
2547 | 2553 | def decodeddata(self): |
|
2548 | 2554 | with open(self._path, "rb") as f: |
|
2549 | 2555 | return f.read() |
|
2550 | 2556 | |
|
2551 | 2557 | def remove(self): |
|
2552 | 2558 | util.unlink(self._path) |
|
2553 | 2559 | |
|
2554 | 2560 | def write(self, data, flags, **kwargs): |
|
2555 | 2561 | assert not flags |
|
2556 | 2562 | with open(self._path, "w") as f: |
|
2557 | 2563 | f.write(data) |
@@ -1,430 +1,431 b'' | |||
|
1 | 1 | $ cat <<EOF > merge |
|
2 | 2 | > from __future__ import print_function |
|
3 | 3 | > import sys, os |
|
4 | 4 | > |
|
5 | 5 | > try: |
|
6 | 6 | > import msvcrt |
|
7 | 7 | > msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
|
8 | 8 | > msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
|
9 | 9 | > except ImportError: |
|
10 | 10 | > pass |
|
11 | 11 | > |
|
12 | 12 | > print("merging for", os.path.basename(sys.argv[1])) |
|
13 | 13 | > EOF |
|
14 | 14 | $ HGMERGE="$PYTHON ../merge"; export HGMERGE |
|
15 | 15 | |
|
16 | 16 | $ hg init t |
|
17 | 17 | $ cd t |
|
18 | 18 | $ echo This is file a1 > a |
|
19 | 19 | $ hg add a |
|
20 | 20 | $ hg commit -m "commit #0" |
|
21 | 21 | $ echo This is file b1 > b |
|
22 | 22 | $ hg add b |
|
23 | 23 | $ hg commit -m "commit #1" |
|
24 | 24 | |
|
25 | 25 | $ hg update 0 |
|
26 | 26 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
27 | 27 | |
|
28 | 28 | Test interrupted updates by having a non-empty dir with the same name as one |
|
29 | 29 | of the files in a commit we're updating to |
|
30 | 30 | |
|
31 | 31 | $ mkdir b && touch b/nonempty |
|
32 | 32 | $ hg up |
|
33 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
33 | abort: Directory not empty: '$TESTTMP/t/b' | |
|
34 | [255] | |
|
34 | 35 | $ hg ci |
|
35 | nothing changed | |
|
36 | [1] | |
|
36 | abort: last update was interrupted | |
|
37 | (use 'hg update' to get a consistent checkout) | |
|
38 | [255] | |
|
37 | 39 | $ hg sum |
|
38 |
parent: |
|
|
39 |
commit # |
|
|
40 | parent: 0:538afb845929 | |
|
41 | commit #0 | |
|
40 | 42 | branch: default |
|
41 | commit: (clean) | |
|
42 | update: (current) | |
|
43 | commit: 1 unknown (interrupted update) | |
|
44 | update: 1 new changesets (update) | |
|
43 | 45 | phases: 2 draft |
|
44 | 46 | |
|
45 | The following line is commented out because the file doesn't exist at the moment, and some OSes error out even with `rm -f`. | |
|
46 | 47 | $ rm b/nonempty |
|
47 | 48 | |
|
48 | 49 | $ hg up |
|
49 |
|
|
|
50 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
50 | 51 | $ hg sum |
|
51 | 52 | parent: 1:b8bb4a988f25 tip |
|
52 | 53 | commit #1 |
|
53 | 54 | branch: default |
|
54 | 55 | commit: (clean) |
|
55 | 56 | update: (current) |
|
56 | 57 | phases: 2 draft |
|
57 | 58 | |
|
58 | 59 | Prepare a basic merge |
|
59 | 60 | |
|
60 | 61 | $ hg up 0 |
|
61 | 62 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
62 | 63 | $ echo This is file c1 > c |
|
63 | 64 | $ hg add c |
|
64 | 65 | $ hg commit -m "commit #2" |
|
65 | 66 | created new head |
|
66 | 67 | $ echo This is file b1 > b |
|
67 | 68 | no merges expected |
|
68 | 69 | $ hg merge -P 1 |
|
69 | 70 | changeset: 1:b8bb4a988f25 |
|
70 | 71 | user: test |
|
71 | 72 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
72 | 73 | summary: commit #1 |
|
73 | 74 |
|
|
74 | 75 | $ hg merge 1 |
|
75 | 76 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
76 | 77 |
|
|
77 | 78 | $ hg diff --nodates |
|
78 | 79 | diff -r 49035e18a8e6 b |
|
79 | 80 | --- /dev/null |
|
80 | 81 | +++ b/b |
|
81 | 82 | @@ -0,0 +1,1 @@ |
|
82 | 83 | +This is file b1 |
|
83 | 84 | $ hg status |
|
84 | 85 | M b |
|
85 | 86 | $ cd ..; rm -r t |
|
86 | 87 | |
|
87 | 88 | $ hg init t |
|
88 | 89 | $ cd t |
|
89 | 90 | $ echo This is file a1 > a |
|
90 | 91 | $ hg add a |
|
91 | 92 | $ hg commit -m "commit #0" |
|
92 | 93 | $ echo This is file b1 > b |
|
93 | 94 | $ hg add b |
|
94 | 95 | $ hg commit -m "commit #1" |
|
95 | 96 | |
|
96 | 97 | $ hg update 0 |
|
97 | 98 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
98 | 99 | $ echo This is file c1 > c |
|
99 | 100 | $ hg add c |
|
100 | 101 | $ hg commit -m "commit #2" |
|
101 | 102 | created new head |
|
102 | 103 | $ echo This is file b2 > b |
|
103 | 104 | merge should fail |
|
104 | 105 | $ hg merge 1 |
|
105 | 106 | b: untracked file differs |
|
106 | 107 | abort: untracked files in working directory differ from files in requested revision |
|
107 | 108 | [255] |
|
108 | 109 | |
|
109 | 110 | #if symlink |
|
110 | 111 | symlinks to directories should be treated as regular files (issue5027) |
|
111 | 112 | $ rm b |
|
112 | 113 |
$ ln -s 'This |
|
113 | 114 | $ hg merge 1 |
|
114 | 115 | b: untracked file differs |
|
115 | 116 | abort: untracked files in working directory differ from files in requested revision |
|
116 | 117 | [255] |
|
117 | 118 | symlinks shouldn't be followed |
|
118 | 119 | $ rm b |
|
119 | 120 | $ echo This is file b1 > .hg/b |
|
120 | 121 | $ ln -s .hg/b b |
|
121 | 122 | $ hg merge 1 |
|
122 | 123 | b: untracked file differs |
|
123 | 124 | abort: untracked files in working directory differ from files in requested revision |
|
124 | 125 | [255] |
|
125 | 126 | |
|
126 | 127 | $ rm b |
|
127 | 128 | $ echo This is file b2 > b |
|
128 | 129 |
|
|
129 | 130 |
|
|
130 | 131 | bad config |
|
131 | 132 | $ hg merge 1 --config merge.checkunknown=x |
|
132 | 133 |
abort: merge.checkunknown not valid ('x' is none of 'abort', 'ignore', 'warn') |
|
133 | 134 | [255] |
|
134 | 135 | this merge should fail |
|
135 | 136 | $ hg merge 1 --config merge.checkunknown=abort |
|
136 | 137 | b: untracked file differs |
|
137 | 138 | abort: untracked files in working directory differ from files in requested revision |
|
138 | 139 | [255] |
|
139 | 140 | |
|
140 | 141 | this merge should warn |
|
141 | 142 | $ hg merge 1 --config merge.checkunknown=warn |
|
142 | 143 | b: replacing untracked file |
|
143 | 144 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
144 | 145 |
|
|
145 | 146 | $ cat b.orig |
|
146 | 147 | This is file b2 |
|
147 | 148 | $ hg up --clean 2 |
|
148 | 149 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
149 | 150 | $ mv b.orig b |
|
150 | 151 | |
|
151 | 152 | this merge should silently ignore |
|
152 | 153 | $ cat b |
|
153 | 154 | This is file b2 |
|
154 | 155 | $ hg merge 1 --config merge.checkunknown=ignore |
|
155 | 156 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
156 | 157 | (branch merge, don't forget to commit) |
|
157 | 158 | |
|
158 | 159 | merge.checkignored |
|
159 | 160 | $ hg up --clean 1 |
|
160 | 161 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
161 | 162 | $ cat >> .hgignore << EOF |
|
162 | 163 | > remoteignored |
|
163 | 164 | > EOF |
|
164 | 165 | $ echo This is file localignored3 > localignored |
|
165 | 166 | $ echo This is file remoteignored3 > remoteignored |
|
166 | 167 | $ hg add .hgignore localignored remoteignored |
|
167 | 168 | $ hg commit -m "commit #3" |
|
168 | 169 | |
|
169 | 170 | $ hg up 2 |
|
170 | 171 | 1 files updated, 0 files merged, 4 files removed, 0 files unresolved |
|
171 | 172 | $ cat >> .hgignore << EOF |
|
172 | 173 | > localignored |
|
173 | 174 | > EOF |
|
174 | 175 | $ hg add .hgignore |
|
175 | 176 | $ hg commit -m "commit #4" |
|
176 | 177 | |
|
177 | 178 | remote .hgignore shouldn't be used for determining whether a file is ignored |
|
178 | 179 | $ echo This is file remoteignored4 > remoteignored |
|
179 | 180 | $ hg merge 3 --config merge.checkignored=ignore --config merge.checkunknown=abort |
|
180 | 181 | remoteignored: untracked file differs |
|
181 | 182 | abort: untracked files in working directory differ from files in requested revision |
|
182 | 183 | [255] |
|
183 | 184 | $ hg merge 3 --config merge.checkignored=abort --config merge.checkunknown=ignore |
|
184 | 185 | merging .hgignore |
|
185 | 186 | merging for .hgignore |
|
186 | 187 | 3 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
187 | 188 | (branch merge, don't forget to commit) |
|
188 | 189 | $ cat remoteignored |
|
189 | 190 | This is file remoteignored3 |
|
190 | 191 | $ cat remoteignored.orig |
|
191 | 192 | This is file remoteignored4 |
|
192 | 193 | $ rm remoteignored.orig |
|
193 | 194 | |
|
194 | 195 | local .hgignore should be used for that |
|
195 | 196 | $ hg up --clean 4 |
|
196 | 197 | 1 files updated, 0 files merged, 3 files removed, 0 files unresolved |
|
197 | 198 | $ echo This is file localignored4 > localignored |
|
198 | 199 | also test other conflicting files to see we output the full set of warnings |
|
199 | 200 | $ echo This is file b2 > b |
|
200 | 201 | $ hg merge 3 --config merge.checkignored=abort --config merge.checkunknown=abort |
|
201 | 202 | b: untracked file differs |
|
202 | 203 | localignored: untracked file differs |
|
203 | 204 | abort: untracked files in working directory differ from files in requested revision |
|
204 | 205 | [255] |
|
205 | 206 | $ hg merge 3 --config merge.checkignored=abort --config merge.checkunknown=ignore |
|
206 | 207 | localignored: untracked file differs |
|
207 | 208 | abort: untracked files in working directory differ from files in requested revision |
|
208 | 209 | [255] |
|
209 | 210 | $ hg merge 3 --config merge.checkignored=warn --config merge.checkunknown=abort |
|
210 | 211 | b: untracked file differs |
|
211 | 212 | abort: untracked files in working directory differ from files in requested revision |
|
212 | 213 | [255] |
|
213 | 214 | $ hg merge 3 --config merge.checkignored=warn --config merge.checkunknown=warn |
|
214 | 215 | b: replacing untracked file |
|
215 | 216 | localignored: replacing untracked file |
|
216 | 217 | merging .hgignore |
|
217 | 218 | merging for .hgignore |
|
218 | 219 | 3 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
219 | 220 | (branch merge, don't forget to commit) |
|
220 | 221 | $ cat localignored |
|
221 | 222 | This is file localignored3 |
|
222 | 223 | $ cat localignored.orig |
|
223 | 224 | This is file localignored4 |
|
224 | 225 | $ rm localignored.orig |
|
225 | 226 | |
|
226 | 227 | $ cat b.orig |
|
227 | 228 | This is file b2 |
|
228 | 229 | $ hg up --clean 2 |
|
229 | 230 | 0 files updated, 0 files merged, 4 files removed, 0 files unresolved |
|
230 | 231 | $ mv b.orig b |
|
231 | 232 | |
|
232 | 233 | this merge of b should work |
|
233 | 234 | $ cat b |
|
234 | 235 | This is file b2 |
|
235 | 236 | $ hg merge -f 1 |
|
236 | 237 | merging b |
|
237 | 238 | merging for b |
|
238 | 239 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
239 | 240 | (branch merge, don't forget to commit) |
|
240 | 241 | $ hg diff --nodates |
|
241 | 242 | diff -r 49035e18a8e6 b |
|
242 | 243 | --- /dev/null |
|
243 | 244 | +++ b/b |
|
244 | 245 | @@ -0,0 +1,1 @@ |
|
245 | 246 | +This is file b2 |
|
246 | 247 | $ hg status |
|
247 | 248 | M b |
|
248 | 249 | $ cd ..; rm -r t |
|
249 | 250 | |
|
250 | 251 | $ hg init t |
|
251 | 252 | $ cd t |
|
252 | 253 | $ echo This is file a1 > a |
|
253 | 254 | $ hg add a |
|
254 | 255 | $ hg commit -m "commit #0" |
|
255 | 256 | $ echo This is file b1 > b |
|
256 | 257 | $ hg add b |
|
257 | 258 | $ hg commit -m "commit #1" |
|
258 | 259 | $ echo This is file b22 > b |
|
259 | 260 | $ hg commit -m "commit #2" |
|
260 | 261 | $ hg update 1 |
|
261 | 262 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
262 | 263 | $ echo This is file c1 > c |
|
263 | 264 | $ hg add c |
|
264 | 265 | $ hg commit -m "commit #3" |
|
265 | 266 | created new head |
|
266 | 267 | |
|
267 | 268 | Contents of b should be "this is file b1" |
|
268 | 269 | $ cat b |
|
269 | 270 | This is file b1 |
|
270 | 271 | |
|
271 | 272 | $ echo This is file b22 > b |
|
272 | 273 | merge fails |
|
273 | 274 | $ hg merge 2 |
|
274 | 275 | abort: uncommitted changes |
|
275 | 276 | (use 'hg status' to list changes) |
|
276 | 277 | [255] |
|
277 | 278 | merge expected! |
|
278 | 279 | $ hg merge -f 2 |
|
279 | 280 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
280 | 281 | (branch merge, don't forget to commit) |
|
281 | 282 | $ hg diff --nodates |
|
282 | 283 | diff -r 85de557015a8 b |
|
283 | 284 | --- a/b |
|
284 | 285 | +++ b/b |
|
285 | 286 | @@ -1,1 +1,1 @@ |
|
286 | 287 | -This is file b1 |
|
287 | 288 | +This is file b22 |
|
288 | 289 | $ hg status |
|
289 | 290 | M b |
|
290 | 291 | $ cd ..; rm -r t |
|
291 | 292 | |
|
292 | 293 | $ hg init t |
|
293 | 294 | $ cd t |
|
294 | 295 | $ echo This is file a1 > a |
|
295 | 296 | $ hg add a |
|
296 | 297 | $ hg commit -m "commit #0" |
|
297 | 298 | $ echo This is file b1 > b |
|
298 | 299 | $ hg add b |
|
299 | 300 | $ hg commit -m "commit #1" |
|
300 | 301 | $ echo This is file b22 > b |
|
301 | 302 | $ hg commit -m "commit #2" |
|
302 | 303 | $ hg update 1 |
|
303 | 304 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
304 | 305 | $ echo This is file c1 > c |
|
305 | 306 | $ hg add c |
|
306 | 307 | $ hg commit -m "commit #3" |
|
307 | 308 | created new head |
|
308 | 309 | $ echo This is file b33 > b |
|
309 | 310 | merge of b should fail |
|
310 | 311 | $ hg merge 2 |
|
311 | 312 | abort: uncommitted changes |
|
312 | 313 | (use 'hg status' to list changes) |
|
313 | 314 | [255] |
|
314 | 315 | merge of b expected |
|
315 | 316 | $ hg merge -f 2 |
|
316 | 317 | merging b |
|
317 | 318 | merging for b |
|
318 | 319 | 0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
|
319 | 320 | (branch merge, don't forget to commit) |
|
320 | 321 | $ hg diff --nodates |
|
321 | 322 | diff -r 85de557015a8 b |
|
322 | 323 | --- a/b |
|
323 | 324 | +++ b/b |
|
324 | 325 | @@ -1,1 +1,1 @@ |
|
325 | 326 | -This is file b1 |
|
326 | 327 | +This is file b33 |
|
327 | 328 | $ hg status |
|
328 | 329 | M b |
|
329 | 330 | |
|
330 | 331 | Test for issue2364 |
|
331 | 332 | |
|
332 | 333 | $ hg up -qC . |
|
333 | 334 | $ hg rm b |
|
334 | 335 | $ hg ci -md |
|
335 | 336 | $ hg revert -r -2 b |
|
336 | 337 | $ hg up -q -- -2 |
|
337 | 338 | |
|
338 | 339 | Test that updated files are treated as "modified", when |
|
339 | 340 | 'merge.update()' is aborted before 'merge.recordupdates()' (= parents |
|
340 | 341 | aren't changed), even if none of mode, size and timestamp of them |
|
341 | 342 | isn't changed on the filesystem (see also issue4583). |
|
342 | 343 | |
|
343 | 344 | $ cat > $TESTTMP/abort.py <<EOF |
|
344 | 345 | > from __future__ import absolute_import |
|
345 | 346 | > # emulate aborting before "recordupdates()". in this case, files |
|
346 | 347 | > # are changed without updating dirstate |
|
347 | 348 | > from mercurial import ( |
|
348 | 349 | > error, |
|
349 | 350 | > extensions, |
|
350 | 351 | > merge, |
|
351 | 352 | > ) |
|
352 | 353 | > def applyupdates(orig, *args, **kwargs): |
|
353 | 354 | > orig(*args, **kwargs) |
|
354 | 355 | > raise error.Abort('intentional aborting') |
|
355 | 356 | > def extsetup(ui): |
|
356 | 357 | > extensions.wrapfunction(merge, "applyupdates", applyupdates) |
|
357 | 358 | > EOF |
|
358 | 359 | |
|
359 | 360 | $ cat >> .hg/hgrc <<EOF |
|
360 | 361 | > [fakedirstatewritetime] |
|
361 | 362 | > # emulate invoking dirstate.write() via repo.status() |
|
362 | 363 | > # at 2000-01-01 00:00 |
|
363 | 364 | > fakenow = 200001010000 |
|
364 | 365 | > EOF |
|
365 | 366 | |
|
366 | 367 | (file gotten from other revision) |
|
367 | 368 | |
|
368 | 369 | $ hg update -q -C 2 |
|
369 | 370 | $ echo 'THIS IS FILE B5' > b |
|
370 | 371 | $ hg commit -m 'commit #5' |
|
371 | 372 | |
|
372 | 373 | $ hg update -q -C 3 |
|
373 | 374 | $ cat b |
|
374 | 375 | This is file b1 |
|
375 | 376 | $ touch -t 200001010000 b |
|
376 | 377 | $ hg debugrebuildstate |
|
377 | 378 | |
|
378 | 379 | $ cat >> .hg/hgrc <<EOF |
|
379 | 380 | > [extensions] |
|
380 | 381 | > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py |
|
381 | 382 | > abort = $TESTTMP/abort.py |
|
382 | 383 | > EOF |
|
383 | 384 | $ hg merge 5 |
|
384 | 385 | abort: intentional aborting |
|
385 | 386 | [255] |
|
386 | 387 | $ cat >> .hg/hgrc <<EOF |
|
387 | 388 | > [extensions] |
|
388 | 389 | > fakedirstatewritetime = ! |
|
389 | 390 | > abort = ! |
|
390 | 391 | > EOF |
|
391 | 392 | |
|
392 | 393 | $ cat b |
|
393 | 394 | THIS IS FILE B5 |
|
394 | 395 | $ touch -t 200001010000 b |
|
395 | 396 | $ hg status -A b |
|
396 | 397 | M b |
|
397 | 398 | |
|
398 | 399 | (file merged from other revision) |
|
399 | 400 | |
|
400 | 401 | $ hg update -q -C 3 |
|
401 | 402 | $ echo 'this is file b6' > b |
|
402 | 403 | $ hg commit -m 'commit #6' |
|
403 | 404 | created new head |
|
404 | 405 | |
|
405 | 406 | $ cat b |
|
406 | 407 | this is file b6 |
|
407 | 408 | $ touch -t 200001010000 b |
|
408 | 409 | $ hg debugrebuildstate |
|
409 | 410 | |
|
410 | 411 | $ cat >> .hg/hgrc <<EOF |
|
411 | 412 | > [extensions] |
|
412 | 413 | > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py |
|
413 | 414 | > abort = $TESTTMP/abort.py |
|
414 | 415 | > EOF |
|
415 | 416 | $ hg merge --tool internal:other 5 |
|
416 | 417 | abort: intentional aborting |
|
417 | 418 | [255] |
|
418 | 419 | $ cat >> .hg/hgrc <<EOF |
|
419 | 420 | > [extensions] |
|
420 | 421 | > fakedirstatewritetime = ! |
|
421 | 422 | > abort = ! |
|
422 | 423 | > EOF |
|
423 | 424 | |
|
424 | 425 | $ cat b |
|
425 | 426 | THIS IS FILE B5 |
|
426 | 427 | $ touch -t 200001010000 b |
|
427 | 428 | $ hg status -A b |
|
428 | 429 | M b |
|
429 | 430 | |
|
430 | 431 | $ cd .. |
@@ -1,89 +1,92 b'' | |||
|
1 | 1 | Test update logic when there are renames or weird same-name cases between dirs |
|
2 | 2 | and files |
|
3 | 3 | |
|
4 | 4 | Update with local changes across a file rename |
|
5 | 5 | |
|
6 | 6 | $ hg init r1 && cd r1 |
|
7 | 7 | |
|
8 | 8 | $ echo a > a |
|
9 | 9 | $ hg add a |
|
10 | 10 | $ hg ci -m a |
|
11 | 11 | |
|
12 | 12 | $ hg mv a b |
|
13 | 13 | $ hg ci -m rename |
|
14 | 14 | |
|
15 | 15 | $ echo b > b |
|
16 | 16 | $ hg ci -m change |
|
17 | 17 | |
|
18 | 18 | $ hg up -q 0 |
|
19 | 19 | |
|
20 | 20 | $ echo c > a |
|
21 | 21 | |
|
22 | 22 | $ hg up |
|
23 | 23 | merging a and b to b |
|
24 | 24 | warning: conflicts while merging b! (edit, then use 'hg resolve --mark') |
|
25 | 25 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
26 | 26 | use 'hg resolve' to retry unresolved file merges |
|
27 | 27 | [1] |
|
28 | 28 | |
|
29 | 29 | Test update when local untracked directory exists with the same name as a |
|
30 | 30 | tracked file in a commit we are updating to |
|
31 | 31 | $ hg init r2 && cd r2 |
|
32 | 32 | $ echo root > root && hg ci -Am root # rev 0 |
|
33 | 33 | adding root |
|
34 | 34 | $ echo text > name && hg ci -Am "name is a file" # rev 1 |
|
35 | 35 | adding name |
|
36 | 36 | $ hg up 0 |
|
37 | 37 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
38 | 38 | $ mkdir name |
|
39 | 39 | $ hg up 1 |
|
40 | 40 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
41 | 41 | |
|
42 | 42 | Test update when local untracked directory exists with some files in it and has |
|
43 | 43 | the same name a tracked file in a commit we are updating to. In future this |
|
44 | 44 | should be updated to give an friendlier error message, but now we should just |
|
45 | 45 | make sure that this does not erase untracked data |
|
46 | 46 | $ hg up 0 |
|
47 | 47 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
48 | 48 | $ mkdir name |
|
49 | 49 | $ echo text > name/file |
|
50 | 50 | $ hg st |
|
51 | 51 | ? name/file |
|
52 | 52 | $ hg up 1 |
|
53 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
53 | abort: Directory not empty: '$TESTTMP/r1/r2/name' | |
|
54 | [255] | |
|
55 | $ cat name/file | |
|
56 | text | |
|
54 | 57 | $ cd .. |
|
55 | 58 | |
|
56 | 59 | #if symlink |
|
57 | 60 | |
|
58 | 61 | Test update when two commits have symlinks that point to different folders |
|
59 | 62 | $ hg init r3 && cd r3 |
|
60 | 63 | $ echo root > root && hg ci -Am root |
|
61 | 64 | adding root |
|
62 | 65 | $ mkdir folder1 && mkdir folder2 |
|
63 | 66 | $ ln -s folder1 folder |
|
64 | 67 | $ hg ci -Am "symlink to folder1" |
|
65 | 68 | adding folder |
|
66 | 69 | $ rm folder |
|
67 | 70 | $ ln -s folder2 folder |
|
68 | 71 | $ hg ci -Am "symlink to folder2" |
|
69 | 72 | $ hg up 1 |
|
70 | 73 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
71 | 74 | $ cd .. |
|
72 | 75 | |
|
73 | 76 | #endif |
|
74 | 77 | |
|
75 | 78 | #if rmcwd |
|
76 | 79 | |
|
77 | 80 | Test that warning is printed if cwd is deleted during update |
|
78 | 81 | $ hg init r4 && cd r4 |
|
79 | 82 | $ mkdir dir |
|
80 | 83 | $ cd dir |
|
81 | 84 | $ echo a > a |
|
82 | 85 | $ echo b > b |
|
83 | 86 | $ hg add a b |
|
84 | 87 | $ hg ci -m "file and dir" |
|
85 | 88 | $ hg up -q null |
|
86 | 89 | current directory was removed |
|
87 | 90 | (consider changing to repo root: $TESTTMP/r1/r4) |
|
88 | 91 | |
|
89 | 92 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now