comparison mercurial/context.py @ 10282:08a0f04b56bd

many, many trivial check-code fixups
author Matt Mackall <mpm@selenic.com>
date Mon, 25 Jan 2010 00:05:27 -0600
parents d6512b3e9ac0
children fb89cd21a7a0
comparison
equal deleted inserted replaced
10281:e7d3b509af8b 10282:08a0f04b56bd
85 85
86 def __iter__(self): 86 def __iter__(self):
87 for f in sorted(self._manifest): 87 for f in sorted(self._manifest):
88 yield f 88 yield f
89 89
90 def changeset(self): return self._changeset 90 def changeset(self):
91 def manifest(self): return self._manifest 91 return self._changeset
92 def manifestnode(self): return self._changeset[0] 92 def manifest(self):
93 93 return self._manifest
94 def rev(self): return self._rev 94 def manifestnode(self):
95 def node(self): return self._node 95 return self._changeset[0]
96 def hex(self): return hex(self._node) 96
97 def user(self): return self._changeset[1] 97 def rev(self):
98 def date(self): return self._changeset[2] 98 return self._rev
99 def files(self): return self._changeset[3] 99 def node(self):
100 def description(self): return self._changeset[4] 100 return self._node
101 def branch(self): return self._changeset[5].get("branch") 101 def hex(self):
102 def extra(self): return self._changeset[5] 102 return hex(self._node)
103 def tags(self): return self._repo.nodetags(self._node) 103 def user(self):
104 return self._changeset[1]
105 def date(self):
106 return self._changeset[2]
107 def files(self):
108 return self._changeset[3]
109 def description(self):
110 return self._changeset[4]
111 def branch(self):
112 return self._changeset[5].get("branch")
113 def extra(self):
114 return self._changeset[5]
115 def tags(self):
116 return self._repo.nodetags(self._node)
104 117
105 def parents(self): 118 def parents(self):
106 """return contexts for each parent changeset""" 119 """return contexts for each parent changeset"""
107 return self._parents 120 return self._parents
108 121
281 '''opens an arbitrary revision of the file without 294 '''opens an arbitrary revision of the file without
282 opening a new filelog''' 295 opening a new filelog'''
283 return filectx(self._repo, self._path, fileid=fileid, 296 return filectx(self._repo, self._path, fileid=fileid,
284 filelog=self._filelog) 297 filelog=self._filelog)
285 298
286 def filerev(self): return self._filerev 299 def filerev(self):
287 def filenode(self): return self._filenode 300 return self._filerev
288 def flags(self): return self._changectx.flags(self._path) 301 def filenode(self):
289 def filelog(self): return self._filelog 302 return self._filenode
303 def flags(self):
304 return self._changectx.flags(self._path)
305 def filelog(self):
306 return self._filelog
290 307
291 def rev(self): 308 def rev(self):
292 if '_changectx' in self.__dict__: 309 if '_changectx' in self.__dict__:
293 return self._changectx.rev() 310 return self._changectx.rev()
294 if '_changeid' in self.__dict__: 311 if '_changeid' in self.__dict__:
295 return self._changectx.rev() 312 return self._changectx.rev()
296 return self._filelog.linkrev(self._filerev) 313 return self._filelog.linkrev(self._filerev)
297 314
298 def linkrev(self): return self._filelog.linkrev(self._filerev) 315 def linkrev(self):
299 def node(self): return self._changectx.node() 316 return self._filelog.linkrev(self._filerev)
300 def hex(self): return hex(self.node()) 317 def node(self):
301 def user(self): return self._changectx.user() 318 return self._changectx.node()
302 def date(self): return self._changectx.date() 319 def hex(self):
303 def files(self): return self._changectx.files() 320 return hex(self.node())
304 def description(self): return self._changectx.description() 321 def user(self):
305 def branch(self): return self._changectx.branch() 322 return self._changectx.user()
306 def extra(self): return self._changectx.extra() 323 def date(self):
307 def manifest(self): return self._changectx.manifest() 324 return self._changectx.date()
308 def changectx(self): return self._changectx 325 def files(self):
309 326 return self._changectx.files()
310 def data(self): return self._filelog.read(self._filenode) 327 def description(self):
311 def path(self): return self._path 328 return self._changectx.description()
312 def size(self): return self._filelog.size(self._filerev) 329 def branch(self):
313 330 return self._changectx.branch()
314 def cmp(self, text): return self._filelog.cmp(self._filenode, text) 331 def extra(self):
332 return self._changectx.extra()
333 def manifest(self):
334 return self._changectx.manifest()
335 def changectx(self):
336 return self._changectx
337
338 def data(self):
339 return self._filelog.read(self._filenode)
340 def path(self):
341 return self._path
342 def size(self):
343 return self._filelog.size(self._filerev)
344
345 def cmp(self, text):
346 return self._filelog.cmp(self._filenode, text)
315 347
316 def renamed(self): 348 def renamed(self):
317 """check if file was actually renamed in this changeset revision 349 """check if file was actually renamed in this changeset revision
318 350
319 If rename logged in file revision, we report copy for changeset only 351 If rename logged in file revision, we report copy for changeset only
346 r = self._filelog.renamed(self._filenode) 378 r = self._filelog.renamed(self._filenode)
347 if r: 379 if r:
348 pl[0] = (r[0], r[1], None) 380 pl[0] = (r[0], r[1], None)
349 381
350 return [filectx(self._repo, p, fileid=n, filelog=l) 382 return [filectx(self._repo, p, fileid=n, filelog=l)
351 for p,n,l in pl if n != nullid] 383 for p, n, l in pl if n != nullid]
352 384
353 def children(self): 385 def children(self):
354 # hard for renames 386 # hard for renames
355 c = self._filelog.children(self._filenode) 387 c = self._filelog.children(self._filenode)
356 return [filectx(self._repo, self._path, fileid=x, 388 return [filectx(self._repo, self._path, fileid=x,
592 if p[1] == nullid: 624 if p[1] == nullid:
593 p = p[:-1] 625 p = p[:-1]
594 self._parents = [changectx(self._repo, x) for x in p] 626 self._parents = [changectx(self._repo, x) for x in p]
595 return self._parents 627 return self._parents
596 628
597 def manifest(self): return self._manifest 629 def manifest(self):
598 630 return self._manifest
599 def user(self): return self._user or self._repo.ui.username() 631 def user(self):
600 def date(self): return self._date 632 return self._user or self._repo.ui.username()
601 def description(self): return self._text 633 def date(self):
634 return self._date
635 def description(self):
636 return self._text
602 def files(self): 637 def files(self):
603 return sorted(self._status[0] + self._status[1] + self._status[2]) 638 return sorted(self._status[0] + self._status[1] + self._status[2])
604 639
605 def modified(self): return self._status[0] 640 def modified(self):
606 def added(self): return self._status[1] 641 return self._status[0]
607 def removed(self): return self._status[2] 642 def added(self):
608 def deleted(self): return self._status[3] 643 return self._status[1]
609 def unknown(self): return self._status[4] 644 def removed(self):
610 def clean(self): return self._status[5] 645 return self._status[2]
611 def branch(self): return self._extra['branch'] 646 def deleted(self):
612 def extra(self): return self._extra 647 return self._status[3]
648 def unknown(self):
649 return self._status[4]
650 def clean(self):
651 return self._status[5]
652 def branch(self):
653 return self._extra['branch']
654 def extra(self):
655 return self._extra
613 656
614 def tags(self): 657 def tags(self):
615 t = [] 658 t = []
616 [t.extend(p.tags()) for p in self.parents()] 659 [t.extend(p.tags()) for p in self.parents()]
617 return t 660 return t
683 return True 726 return True
684 727
685 def __str__(self): 728 def __str__(self):
686 return "%s@%s" % (self.path(), self._changectx) 729 return "%s@%s" % (self.path(), self._changectx)
687 730
688 def data(self): return self._repo.wread(self._path) 731 def data(self):
732 return self._repo.wread(self._path)
689 def renamed(self): 733 def renamed(self):
690 rp = self._repo.dirstate.copied(self._path) 734 rp = self._repo.dirstate.copied(self._path)
691 if not rp: 735 if not rp:
692 return None 736 return None
693 return rp, self._changectx._parents[0]._manifest.get(rp, nullid) 737 return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
709 753
710 for pc in pcl[1:]: 754 for pc in pcl[1:]:
711 pl.append((path, filenode(pc, path), fl)) 755 pl.append((path, filenode(pc, path), fl))
712 756
713 return [filectx(self._repo, p, fileid=n, filelog=l) 757 return [filectx(self._repo, p, fileid=n, filelog=l)
714 for p,n,l in pl if n != nullid] 758 for p, n, l in pl if n != nullid]
715 759
716 def children(self): 760 def children(self):
717 return [] 761 return []
718 762
719 def size(self): return os.stat(self._repo.wjoin(self._path)).st_size 763 def size(self):
764 return os.stat(self._repo.wjoin(self._path)).st_size
720 def date(self): 765 def date(self):
721 t, tz = self._changectx.date() 766 t, tz = self._changectx.date()
722 try: 767 try:
723 return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) 768 return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz)
724 except OSError, err: 769 except OSError, err:
725 if err.errno != errno.ENOENT: raise 770 if err.errno != errno.ENOENT:
771 raise
726 return (t, tz) 772 return (t, tz)
727 773
728 def cmp(self, text): return self._repo.wread(self._path) == text 774 def cmp(self, text):
775 return self._repo.wread(self._path) == text
729 776
730 class memctx(object): 777 class memctx(object):
731 """Use memctx to perform in-memory commits via localrepo.commitctx(). 778 """Use memctx to perform in-memory commits via localrepo.commitctx().
732 779
733 Revision information is supplied at initialization time while 780 Revision information is supplied at initialization time while
785 return True 832 return True
786 833
787 def __getitem__(self, key): 834 def __getitem__(self, key):
788 return self.filectx(key) 835 return self.filectx(key)
789 836
790 def p1(self): return self._parents[0] 837 def p1(self):
791 def p2(self): return self._parents[1] 838 return self._parents[0]
792 839 def p2(self):
793 def user(self): return self._user or self._repo.ui.username() 840 return self._parents[1]
794 def date(self): return self._date 841
795 def description(self): return self._text 842 def user(self):
796 def files(self): return self.modified() 843 return self._user or self._repo.ui.username()
797 def modified(self): return self._status[0] 844 def date(self):
798 def added(self): return self._status[1] 845 return self._date
799 def removed(self): return self._status[2] 846 def description(self):
800 def deleted(self): return self._status[3] 847 return self._text
801 def unknown(self): return self._status[4] 848 def files(self):
802 def clean(self): return self._status[5] 849 return self.modified()
803 def branch(self): return self._extra['branch'] 850 def modified(self):
804 def extra(self): return self._extra 851 return self._status[0]
805 def flags(self, f): return self[f].flags() 852 def added(self):
853 return self._status[1]
854 def removed(self):
855 return self._status[2]
856 def deleted(self):
857 return self._status[3]
858 def unknown(self):
859 return self._status[4]
860 def clean(self):
861 return self._status[5]
862 def branch(self):
863 return self._extra['branch']
864 def extra(self):
865 return self._extra
866 def flags(self, f):
867 return self[f].flags()
806 868
807 def parents(self): 869 def parents(self):
808 """return contexts for each parent changeset""" 870 """return contexts for each parent changeset"""
809 return self._parents 871 return self._parents
810 872
830 self._flags = (islink and 'l' or '') + (isexec and 'x' or '') 892 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
831 self._copied = None 893 self._copied = None
832 if copied: 894 if copied:
833 self._copied = (copied, nullid) 895 self._copied = (copied, nullid)
834 896
835 def __nonzero__(self): return True 897 def __nonzero__(self):
836 def __str__(self): return "%s@%s" % (self.path(), self._changectx) 898 return True
837 def path(self): return self._path 899 def __str__(self):
838 def data(self): return self._data 900 return "%s@%s" % (self.path(), self._changectx)
839 def flags(self): return self._flags 901 def path(self):
840 def isexec(self): return 'x' in self._flags 902 return self._path
841 def islink(self): return 'l' in self._flags 903 def data(self):
842 def renamed(self): return self._copied 904 return self._data
905 def flags(self):
906 return self._flags
907 def isexec(self):
908 return 'x' in self._flags
909 def islink(self):
910 return 'l' in self._flags
911 def renamed(self):
912 return self._copied