diff options
-rwxr-xr-x | setuptools/command/egg_info.py | 26 | ||||
-rw-r--r-- | setuptools/svn_utils.py | 41 | ||||
-rw-r--r-- | setuptools/tests/test_svn.py | 4 |
3 files changed, 27 insertions, 44 deletions
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 9d30b125..345ec8ae 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -217,31 +217,7 @@ class egg_info(Command): @staticmethod def get_svn_revision(): - revision = 0 - - for base,dirs,files in os.walk(os.curdir): - if '.svn' not in dirs: - dirs[:] = [] - continue # no sense walking uncontrolled subdirs - dirs.remove('.svn') - - entries = svn_utils.SVNEntries.load_dir(base) - if not entries.is_valid: - log.warn(" get_svn_revision: Cannot determine how to read enteries.") - dirs[:] = [] - continue - - localrev = entries.parse_revision() - dirurl = entries.get_url() - - if base==os.curdir: - base_url = dirurl+'/' # save the root url - elif not dirurl.startswith(base_url): - dirs[:] = [] - continue # not part of the same svn tree, skip it - revision = max(revision, localrev) - - return str(revision or get_pkg_info_revision()) + return str(svn_utils.parse_revision(os.curdir)) diff --git a/setuptools/svn_utils.py b/setuptools/svn_utils.py index 57cf6849..e45f05bc 100644 --- a/setuptools/svn_utils.py +++ b/setuptools/svn_utils.py @@ -34,6 +34,25 @@ def _run_command(args, stdout=_PIPE, stderr=_PIPE): return proc.returncode, data
+#svnversion return values (previous implementations return max revision)
+# 4123:4168 mixed revision working copy
+# 4168M modified working copy
+# 4123S switched working copy
+# 4123:4168MS mixed revision, modified, switched working copy
+_SVN_VER_RE = re.compile(r'(?:(\d+):)?(\d+)([a-z]*)\s*$', re.I)
+
+def parse_revision(path):
+ _, data = _run_command(['svnversion', path])
+ parsed = _SVN_VER_RE.match(data)
+ if parsed:
+ try:
+ #No max needed this command summarizes working copy since 1.0
+ return int(parsed.group(2))
+ except ValueError:
+ #This should only happen if the revision is WAY too big.
+ pass
+ return 0
+
#TODO add the text entry back, and make its use dependent on the
# non existence of svn?
@@ -242,13 +261,6 @@ class SVNEntriesCMD(SVNEntries): entryre = re.compile(r'<entry.*?</entry>', re.DOTALL or re.I)
namere = re.compile(r'<name>(.*?)</name>', re.I)
- #svnversion return values (previous implementations return max revision)
- # 4123:4168 mixed revision working copy
- # 4168M modified working copy
- # 4123S switched working copy
- # 4123:4168MS mixed revision, modified, switched working copy
- svnverre = re.compile(r'(?:(\d+):)?(\d+)([a-z]*)\s*$', re.I)
-
def __get_cached_dir_data(self):
return self.dir_data
@@ -294,18 +306,9 @@ class SVNEntriesCMD(SVNEntries): return self.revision
def parse_revision(self):
- _, data = _run_command(['svnversion', self.path])
- parsed = self.svnverre.match(data)
- if parsed:
- try:
- #No max needed this command summarizes working copy since 1.0
- self.revision = int(parsed.group(2))
- self.parse_revision = self.__get_cached_revision
- return self.revision
- except ValueError:
- #This should only happen if the revision is WAY too big.
- pass
- return 0
+ self.revision = parse_revision(self.path)
+ self.parse_revision = self.__get_cached_revision
+ return self.revision
def get_undeleted_records(self):
#NOTE: Need to parse entities?
diff --git a/setuptools/tests/test_svn.py b/setuptools/tests/test_svn.py index b6950ea3..5e8a3e1b 100644 --- a/setuptools/tests/test_svn.py +++ b/setuptools/tests/test_svn.py @@ -11,6 +11,7 @@ import shutil import stat from setuptools import svn_utils +from setuptools.command import egg_info #requires python >= 2.4 from subprocess import call as _call @@ -83,6 +84,9 @@ class TestSvn_1_7(unittest.TestCase): self.assertEqual(set(entries.get_external_dirs('dir-props')), set([u'third_party3', u'third_party2', u'third_party'])) + def test_egg_info(self): + rev = egg_info.egg_info.get_svn_revision() + self.assertEqual(rev, '4') def test_suite(): |