Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 3673:eb0b4a2d70a9
white space and line break cleanups
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 17 Nov 2006 08:06:54 +0100 |
parents | 3b4e00cba57a |
children | 1bd70d40ec57 |
comparison
equal
deleted
inserted
replaced
3672:e8730b5b8a32 | 3673:eb0b4a2d70a9 |
---|---|
67 def branch(self): return self._changeset[5].get("branch", "") | 67 def branch(self): return self._changeset[5].get("branch", "") |
68 | 68 |
69 def parents(self): | 69 def parents(self): |
70 """return contexts for each parent changeset""" | 70 """return contexts for each parent changeset""" |
71 p = self._repo.changelog.parents(self._node) | 71 p = self._repo.changelog.parents(self._node) |
72 return [ changectx(self._repo, x) for x in p ] | 72 return [changectx(self._repo, x) for x in p] |
73 | 73 |
74 def children(self): | 74 def children(self): |
75 """return contexts for each child changeset""" | 75 """return contexts for each child changeset""" |
76 c = self._repo.changelog.children(self._node) | 76 c = self._repo.changelog.children(self._node) |
77 return [ changectx(self._repo, x) for x in c ] | 77 return [changectx(self._repo, x) for x in c] |
78 | 78 |
79 def filenode(self, path): | 79 def filenode(self, path): |
80 if '_manifest' in self.__dict__: | 80 if '_manifest' in self.__dict__: |
81 try: | 81 try: |
82 return self._manifest[path] | 82 return self._manifest[path] |
208 def cmp(self, text): return self._filelog.cmp(self._filenode, text) | 208 def cmp(self, text): return self._filelog.cmp(self._filenode, text) |
209 | 209 |
210 def parents(self): | 210 def parents(self): |
211 p = self._path | 211 p = self._path |
212 fl = self._filelog | 212 fl = self._filelog |
213 pl = [ (p, n, fl) for n in self._filelog.parents(self._filenode) ] | 213 pl = [(p, n, fl) for n in self._filelog.parents(self._filenode)] |
214 | 214 |
215 r = self.renamed() | 215 r = self.renamed() |
216 if r: | 216 if r: |
217 pl[0] = (r[0], r[1], None) | 217 pl[0] = (r[0], r[1], None) |
218 | 218 |
219 return [ filectx(self._repo, p, fileid=n, filelog=l) | 219 return [filectx(self._repo, p, fileid=n, filelog=l) |
220 for p,n,l in pl if n != nullid ] | 220 for p,n,l in pl if n != nullid] |
221 | 221 |
222 def children(self): | 222 def children(self): |
223 # hard for renames | 223 # hard for renames |
224 c = self._filelog.children(self._filenode) | 224 c = self._filelog.children(self._filenode) |
225 return [ filectx(self._repo, self._path, fileid=x, | 225 return [filectx(self._repo, self._path, fileid=x, |
226 filelog=self._filelog) for x in c ] | 226 filelog=self._filelog) for x in c] |
227 | 227 |
228 def annotate(self, follow=False): | 228 def annotate(self, follow=False): |
229 '''returns a list of tuples of (ctx, line) for each line | 229 '''returns a list of tuples of (ctx, line) for each line |
230 in the file, where ctx is the filectx of the node where | 230 in the file, where ctx is the filectx of the node where |
231 that line was last changed''' | 231 that line was last changed''' |
246 | 246 |
247 def parents(f): | 247 def parents(f): |
248 # we want to reuse filectx objects as much as possible | 248 # we want to reuse filectx objects as much as possible |
249 p = f._path | 249 p = f._path |
250 if f._filerev is None: # working dir | 250 if f._filerev is None: # working dir |
251 pl = [ (n.path(), n.filerev()) for n in f.parents() ] | 251 pl = [(n.path(), n.filerev()) for n in f.parents()] |
252 else: | 252 else: |
253 pl = [ (p, n) for n in f._filelog.parentrevs(f._filerev) ] | 253 pl = [(p, n) for n in f._filelog.parentrevs(f._filerev)] |
254 | 254 |
255 if follow: | 255 if follow: |
256 r = f.renamed() | 256 r = f.renamed() |
257 if r: | 257 if r: |
258 pl[0] = (r[0], getlog(r[0]).rev(r[1])) | 258 pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
311 acache = {} | 311 acache = {} |
312 | 312 |
313 # prime the ancestor cache for the working directory | 313 # prime the ancestor cache for the working directory |
314 for c in (self, fc2): | 314 for c in (self, fc2): |
315 if c._filerev == None: | 315 if c._filerev == None: |
316 pl = [ (n.path(), n.filenode()) for n in c.parents() ] | 316 pl = [(n.path(), n.filenode()) for n in c.parents()] |
317 acache[(c._path, None)] = pl | 317 acache[(c._path, None)] = pl |
318 | 318 |
319 flcache = {self._path:self._filelog, fc2._path:fc2._filelog} | 319 flcache = {self._path:self._filelog, fc2._path:fc2._filelog} |
320 def parents(vertex): | 320 def parents(vertex): |
321 if vertex in acache: | 321 if vertex in acache: |
322 return acache[vertex] | 322 return acache[vertex] |
323 f, n = vertex | 323 f, n = vertex |
324 if f not in flcache: | 324 if f not in flcache: |
325 flcache[f] = self._repo.file(f) | 325 flcache[f] = self._repo.file(f) |
326 fl = flcache[f] | 326 fl = flcache[f] |
327 pl = [ (f,p) for p in fl.parents(n) if p != nullid ] | 327 pl = [(f, p) for p in fl.parents(n) if p != nullid] |
328 re = fl.renamed(n) | 328 re = fl.renamed(n) |
329 if re: | 329 if re: |
330 pl.append(re) | 330 pl.append(re) |
331 acache[vertex]=pl | 331 acache[vertex] = pl |
332 return pl | 332 return pl |
333 | 333 |
334 a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) | 334 a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
335 v = ancestor.ancestor(a, b, parents) | 335 v = ancestor.ancestor(a, b, parents) |
336 if v: | 336 if v: |
337 f,n = v | 337 f, n = v |
338 return filectx(self._repo, f, fileid=n, filelog=flcache[f]) | 338 return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
339 | 339 |
340 return None | 340 return None |
341 | 341 |
342 class workingctx(changectx): | 342 class workingctx(changectx): |
370 """generate a manifest corresponding to the working directory""" | 370 """generate a manifest corresponding to the working directory""" |
371 | 371 |
372 man = self._parents[0].manifest().copy() | 372 man = self._parents[0].manifest().copy() |
373 copied = self._repo.dirstate.copies() | 373 copied = self._repo.dirstate.copies() |
374 modified, added, removed, deleted, unknown = self._status[:5] | 374 modified, added, removed, deleted, unknown = self._status[:5] |
375 for i,l in (("a", added), ("m", modified), ("u", unknown)): | 375 for i, l in (("a", added), ("m", modified), ("u", unknown)): |
376 for f in l: | 376 for f in l: |
377 man[f] = man.get(copied.get(f, f), nullid) + i | 377 man[f] = man.get(copied.get(f, f), nullid) + i |
378 man.set(f, util.is_exec(self._repo.wjoin(f), man.execf(f))) | 378 man.set(f, util.is_exec(self._repo.wjoin(f), man.execf(f))) |
379 | 379 |
380 for f in deleted + removed: | 380 for f in deleted + removed: |
478 '''return parent filectxs, following copies if necessary''' | 478 '''return parent filectxs, following copies if necessary''' |
479 p = self._path | 479 p = self._path |
480 rp = self._repopath | 480 rp = self._repopath |
481 pcl = self._changectx._parents | 481 pcl = self._changectx._parents |
482 fl = self._filelog | 482 fl = self._filelog |
483 pl = [ (rp, pcl[0]._manifest.get(rp, nullid), fl) ] | 483 pl = [(rp, pcl[0]._manifest.get(rp, nullid), fl)] |
484 if len(pcl) > 1: | 484 if len(pcl) > 1: |
485 if rp != p: | 485 if rp != p: |
486 fl = None | 486 fl = None |
487 pl.append((p, pcl[1]._manifest.get(p, nullid), fl)) | 487 pl.append((p, pcl[1]._manifest.get(p, nullid), fl)) |
488 | 488 |
489 return [ filectx(self._repo, p, fileid=n, filelog=l) | 489 return [filectx(self._repo, p, fileid=n, filelog=l) |
490 for p,n,l in pl if n != nullid ] | 490 for p,n,l in pl if n != nullid] |
491 | 491 |
492 def children(self): | 492 def children(self): |
493 return [] | 493 return [] |
494 | 494 |
495 def size(self): return os.stat(self._repo.wjoin(self._path)).st_size | 495 def size(self): return os.stat(self._repo.wjoin(self._path)).st_size |