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