From 5d7cdd18c9a3ece7bebab05d21792559bc67b645 Mon Sep 17 00:00:00 2001 From: mhagger Date: Sun, 29 Aug 2010 20:55:10 +0000 Subject: [PATCH] Order CVSPath instances using a key rather than a compare function. git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5269 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/cvs_path.py | 17 +++++++++++------ cvs2svn_lib/cvs_path_database.py | 3 +-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cvs2svn_lib/cvs_path.py b/cvs2svn_lib/cvs_path.py index 37f7c67a..f92a454f 100644 --- a/cvs2svn_lib/cvs_path.py +++ b/cvs2svn_lib/cvs_path.py @@ -43,9 +43,9 @@ class CVSPath(object): ordinal -- (int) the order that this instance should be sorted relative to other CVSPath instances. This member is set based - on the ordering imposed by slow_compare() by CVSPathDatabase - after all CVSFiles have been processed. Comparisons of - CVSPath using __cmp__() simply compare the ordinals. + on the ordering imposed by sort_key() by CVSPathDatabase after + all CVSFiles have been processed. Comparisons of CVSPath + using __cmp__() simply compare the ordinals. """ @@ -157,12 +157,17 @@ class CVSPath(object): return a is b - def slow_compare(a, b): + def sort_key(self): + """Return the key that should be used for sorting CVSPath instances. + + This is a relatively expensive computation, so it is only used + once, the the results are used to set the ordinal member.""" + return ( # Sort first by project: - cmp(a.project, b.project) + self.project, # Then by directory components: - or cmp(a._get_dir_components(), b._get_dir_components()) + self._get_dir_components(), ) def __cmp__(a, b): diff --git a/cvs2svn_lib/cvs_path_database.py b/cvs2svn_lib/cvs_path_database.py index 5ff72856..c99ee9e8 100644 --- a/cvs2svn_lib/cvs_path_database.py +++ b/cvs2svn_lib/cvs_path_database.py @@ -54,8 +54,7 @@ class CVSPathDatabase: raise RuntimeError('Invalid mode %r' % self.mode) def set_cvs_path_ordinals(self): - cvs_files = list(self.itervalues()) - cvs_files.sort(CVSPath.slow_compare) + cvs_files = sorted(self.itervalues(), key=CVSPath.sort_key) for (i, cvs_file) in enumerate(cvs_files): cvs_file.ordinal = i -- 2.11.4.GIT