status: various cleanups
authorMatt Mackall <mpm@selenic.com>
Fri, 11 Jul 2008 18:46:02 -0500
changeset 6770 854b907527e5
parent 6769 97c12b1ed1e0
child 6771 f5d7cfcbb4d3
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
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Fri Jul 11 18:46:02 2008 -0500
+++ b/mercurial/localrepo.py	Fri Jul 11 18:46:02 2008 -0500
@@ -958,95 +958,78 @@
                     del mf[fn]
             return mf
 
-        if not match:
-            match = match_.always(self.root, self.getcwd())
-
         ctx1 = self[node1]
         ctx2 = self[node2]
         working = ctx2 == self[None]
         parentworking = working and ctx1 == self['.']
-
+        match = match or match_.always(self.root, self.getcwd())
         listignored, listclean, listunknown = ignored, clean, unknown
-        modified, added, removed, deleted, unknown = [], [], [], [], []
-        ignored, clean = [], []
+
+        if working: # we need to scan the working dir
+            s = self.dirstate.status(match, listignored, listclean, listunknown)
+            cmp, modified, added, removed, deleted, unknown, ignored, clean = s
+
+            # check for any possibly clean files
+            if parentworking and cmp:
+                fixup = []
+                # do a full compare of any files that might have changed
+                for f in cmp:
+                    if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
+                        or ctx1[f].cmp(ctx2[f].data())):
+                        modified.append(f)
+                    else:
+                        fixup.append(f)
+
+                modified.sort()
+                if listclean:
+                    clean = util.sort(clean + fixup)
+
+                # update dirstate for files that are actually clean
+                if fixup:
+                    wlock = None
+                    try:
+                        try:
+                            wlock = self.wlock(False)
+                            for f in fixup:
+                                self.dirstate.normal(f)
+                        except lock.LockException:
+                            pass
+                    finally:
+                        del wlock
 
         if not parentworking:
-            # read the manifest from node1 before the manifest from node2,
-            # so that we'll hit the manifest cache if we're going through
-            # all the revisions in parent->child order.
+            modified, added, clean = [], [], []
             mf1 = mfmatches(ctx1)
 
-        # are we comparing the working directory?
-        if working:
-            (lookup, modified, added, removed, deleted, unknown,
-             ignored, clean) = self.dirstate.status(match, listignored,
-                                                    listclean, listunknown)
-            # are we comparing working dir against its parent?
-            if parentworking:
-                if lookup:
-                    fixup = []
-                    # do a full compare of any files that might have changed
-                    for f in lookup:
-                        if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
-                            or ctx1[f].cmp(ctx2[f].read())):
-                            modified.append(f)
-                        else:
-                            fixup.append(f)
-                            if listclean:
-                                clean.append(f)
-
-                    # update dirstate for files that are actually clean
-                    if fixup:
-                        wlock = None
-                        try:
-                            try:
-                                wlock = self.wlock(False)
-                            except lock.LockException:
-                                pass
-                            if wlock:
-                                for f in fixup:
-                                    self.dirstate.normal(f)
-                        finally:
-                            del wlock
-            else:
+            if working:
                 # we are comparing working dir against non-parent
                 # generate a pseudo-manifest for the working dir
-                # XXX: create it in dirstate.py ?
                 mf2 = mfmatches(self['.'])
-                for f in lookup + modified + added:
+                mf2.flags = ctx2.flags # delay flag lookup
+                for f in cmp + modified + added:
                     mf2[f] = None
-                    mf2.set(f, ctx2.flags(f))
                 for f in removed:
                     if f in mf2:
                         del mf2[f]
-        else:
-            # we are comparing two revisions
-            mf2 = mfmatches(ctx2)
+            else:
+                # we are comparing two revisions
+                deleted, unknown, ignored = [], [], []
+                mf2 = mfmatches(ctx2)
 
-        if not parentworking:
-            # flush lists from dirstate before comparing manifests
-            modified, added, clean = [], [], []
-
-            # make sure to sort the files so we talk to the disk in a
-            # reasonable order
             for fn in util.sort(mf2):
                 if fn in mf1:
-                    if (mf1.flags(fn) != mf2.flags(fn) or
-                        (mf1[fn] != mf2[fn] and
-                         (mf2[fn] or ctx1[f].cmp(ctx2[f].read())))):
+                    if ((mf1[fn] != mf2[fn] and
+                        (mf2[fn] or ctx1[f].cmp(ctx2[f].data())))
+                        or mf1.flags(fn) != mf2.flags(fn)):
                         modified.append(fn)
                     elif listclean:
                         clean.append(fn)
                     del mf1[fn]
                 else:
                     added.append(fn)
-
-            removed = mf1.keys()
+            removed = util.sort(mf1.keys())
 
-        # sort and return results:
-        for l in modified, added, removed, deleted, unknown, ignored, clean:
-            l.sort()
-        return (modified, added, removed, deleted, unknown, ignored, clean)
+        return modified, added, removed, deleted, unknown, ignored, clean
 
     def add(self, list):
         wlock = self.wlock()