comparison mercurial/localrepo.py @ 6770:854b907527e5

status: various cleanups - rename lookup to cmp for formatting reasons - reduce nesting level of fixup code - sort fixup results - group comparison cases in a separate clause - make list initialization simpler - delay flag lookup for working directory - sort removed list in comparison - avoid sorting already sorted lists
author Matt Mackall <mpm@selenic.com>
date Fri, 11 Jul 2008 18:46:02 -0500
parents 97c12b1ed1e0
children 6a9025a667ae
comparison
equal deleted inserted replaced
6769:97c12b1ed1e0 6770:854b907527e5
956 for fn in mf: 956 for fn in mf:
957 if not match(fn): 957 if not match(fn):
958 del mf[fn] 958 del mf[fn]
959 return mf 959 return mf
960 960
961 if not match:
962 match = match_.always(self.root, self.getcwd())
963
964 ctx1 = self[node1] 961 ctx1 = self[node1]
965 ctx2 = self[node2] 962 ctx2 = self[node2]
966 working = ctx2 == self[None] 963 working = ctx2 == self[None]
967 parentworking = working and ctx1 == self['.'] 964 parentworking = working and ctx1 == self['.']
968 965 match = match or match_.always(self.root, self.getcwd())
969 listignored, listclean, listunknown = ignored, clean, unknown 966 listignored, listclean, listunknown = ignored, clean, unknown
970 modified, added, removed, deleted, unknown = [], [], [], [], [] 967
971 ignored, clean = [], [] 968 if working: # we need to scan the working dir
969 s = self.dirstate.status(match, listignored, listclean, listunknown)
970 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
971
972 # check for any possibly clean files
973 if parentworking and cmp:
974 fixup = []
975 # do a full compare of any files that might have changed
976 for f in cmp:
977 if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
978 or ctx1[f].cmp(ctx2[f].data())):
979 modified.append(f)
980 else:
981 fixup.append(f)
982
983 modified.sort()
984 if listclean:
985 clean = util.sort(clean + fixup)
986
987 # update dirstate for files that are actually clean
988 if fixup:
989 wlock = None
990 try:
991 try:
992 wlock = self.wlock(False)
993 for f in fixup:
994 self.dirstate.normal(f)
995 except lock.LockException:
996 pass
997 finally:
998 del wlock
972 999
973 if not parentworking: 1000 if not parentworking:
974 # read the manifest from node1 before the manifest from node2, 1001 modified, added, clean = [], [], []
975 # so that we'll hit the manifest cache if we're going through
976 # all the revisions in parent->child order.
977 mf1 = mfmatches(ctx1) 1002 mf1 = mfmatches(ctx1)
978 1003
979 # are we comparing the working directory? 1004 if working:
980 if working:
981 (lookup, modified, added, removed, deleted, unknown,
982 ignored, clean) = self.dirstate.status(match, listignored,
983 listclean, listunknown)
984 # are we comparing working dir against its parent?
985 if parentworking:
986 if lookup:
987 fixup = []
988 # do a full compare of any files that might have changed
989 for f in lookup:
990 if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
991 or ctx1[f].cmp(ctx2[f].read())):
992 modified.append(f)
993 else:
994 fixup.append(f)
995 if listclean:
996 clean.append(f)
997
998 # update dirstate for files that are actually clean
999 if fixup:
1000 wlock = None
1001 try:
1002 try:
1003 wlock = self.wlock(False)
1004 except lock.LockException:
1005 pass
1006 if wlock:
1007 for f in fixup:
1008 self.dirstate.normal(f)
1009 finally:
1010 del wlock
1011 else:
1012 # we are comparing working dir against non-parent 1005 # we are comparing working dir against non-parent
1013 # generate a pseudo-manifest for the working dir 1006 # generate a pseudo-manifest for the working dir
1014 # XXX: create it in dirstate.py ?
1015 mf2 = mfmatches(self['.']) 1007 mf2 = mfmatches(self['.'])
1016 for f in lookup + modified + added: 1008 mf2.flags = ctx2.flags # delay flag lookup
1009 for f in cmp + modified + added:
1017 mf2[f] = None 1010 mf2[f] = None
1018 mf2.set(f, ctx2.flags(f))
1019 for f in removed: 1011 for f in removed:
1020 if f in mf2: 1012 if f in mf2:
1021 del mf2[f] 1013 del mf2[f]
1022 else: 1014 else:
1023 # we are comparing two revisions 1015 # we are comparing two revisions
1024 mf2 = mfmatches(ctx2) 1016 deleted, unknown, ignored = [], [], []
1025 1017 mf2 = mfmatches(ctx2)
1026 if not parentworking: 1018
1027 # flush lists from dirstate before comparing manifests
1028 modified, added, clean = [], [], []
1029
1030 # make sure to sort the files so we talk to the disk in a
1031 # reasonable order
1032 for fn in util.sort(mf2): 1019 for fn in util.sort(mf2):
1033 if fn in mf1: 1020 if fn in mf1:
1034 if (mf1.flags(fn) != mf2.flags(fn) or 1021 if ((mf1[fn] != mf2[fn] and
1035 (mf1[fn] != mf2[fn] and 1022 (mf2[fn] or ctx1[f].cmp(ctx2[f].data())))
1036 (mf2[fn] or ctx1[f].cmp(ctx2[f].read())))): 1023 or mf1.flags(fn) != mf2.flags(fn)):
1037 modified.append(fn) 1024 modified.append(fn)
1038 elif listclean: 1025 elif listclean:
1039 clean.append(fn) 1026 clean.append(fn)
1040 del mf1[fn] 1027 del mf1[fn]
1041 else: 1028 else:
1042 added.append(fn) 1029 added.append(fn)
1043 1030 removed = util.sort(mf1.keys())
1044 removed = mf1.keys() 1031
1045 1032 return modified, added, removed, deleted, unknown, ignored, clean
1046 # sort and return results:
1047 for l in modified, added, removed, deleted, unknown, ignored, clean:
1048 l.sort()
1049 return (modified, added, removed, deleted, unknown, ignored, clean)
1050 1033
1051 def add(self, list): 1034 def add(self, list):
1052 wlock = self.wlock() 1035 wlock = self.wlock()
1053 try: 1036 try:
1054 rejected = [] 1037 rejected = []