Rev 1429: Move externals parsing to properties module. in http://people.samba.org/bzr/jelmer/bzr-svn/trunk
Jelmer Vernooij
jelmer at samba.org
Thu Jul 3 23:10:53 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/trunk
------------------------------------------------------------
revno: 1429
revision-id: jelmer at samba.org-20080703221049-ktyf5hwv0yjjx141
parent: jelmer at samba.org-20080703211843-5twv11n03hlqcedq
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Fri 2008-07-04 00:10:49 +0200
message:
Move externals parsing to properties module.
added:
tests/test_properties.py test_properties.py-20080703215223-t5ydp87wwi7dtyas-1
modified:
errors.py errors.py-20061226172623-w1sbj8ynpo0eojqp-1
fetch.py fetch.py-20060625004942-x2lfaib8ra707a8p-1
properties.py util.py-20080502170127-o220e9py99vt69s6-1
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
tests/test_core.py test_core.py-20080603032119-q91zmret1lv84ay9-1
tests/test_tree.py test_tree.py-20070103204350-pr8nupes7e5sd2wr-1
tree.py tree.py-20060624222557-dudlwqcmkf22lt2s-1
=== modified file 'errors.py'
--- a/errors.py 2008-07-01 13:00:37 +0000
+++ b/errors.py 2008-07-03 22:10:49 +0000
@@ -25,10 +25,6 @@
from bzrlib.plugins.svn import core
-class InvalidExternalsDescription(BzrError):
- _fmt = """Unable to parse externals description."""
-
-
ERR_UNKNOWN_HOSTNAME = 670002
ERR_UNKNOWN_HOSTNAME = 670002
ERR_RA_SVN_CONNECTION_CLOSED = 210002
=== modified file 'fetch.py'
--- a/fetch.py 2008-07-01 19:39:37 +0000
+++ b/fetch.py 2008-07-03 22:10:49 +0000
@@ -35,10 +35,10 @@
SVN_PROP_BZR_FILEIDS, SVN_REVPROP_BZR_SIGNATURE,
parse_merge_property,
parse_revision_metadata)
+from bzrlib.plugins.svn.properties import parse_externals_description
from bzrlib.plugins.svn.repository import SvnRepository, SvnRepositoryFormat
from bzrlib.plugins.svn.svk import SVN_PROP_SVK_MERGE
-from bzrlib.plugins.svn.tree import (parse_externals_description,
- inventory_add_external)
+from bzrlib.plugins.svn.tree import inventory_add_external
def _escape_commit_message(message):
"""Replace xml-incompatible control characters."""
=== modified file 'properties.py'
--- a/properties.py 2008-06-22 18:53:14 +0000
+++ b/properties.py 2008-07-03 22:10:49 +0000
@@ -13,6 +13,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from bzrlib.errors import BzrError
+
+
+class InvalidExternalsDescription(BzrError):
+ _fmt = """Unable to parse externals description."""
+
+
def is_valid_property_name(prop):
if not prop[0].isalnum() and not prop[0] in ":_":
return False
@@ -37,6 +44,38 @@
return (long(time.mktime((tm[0], tm[1], tm[2], tm[3], tm[4], tm[5], tm[6], tm[7], -1)) - time.timezone) * 1000000 + tm_usec)
+def parse_externals_description(base_url, val):
+ """Parse an svn:externals property value.
+
+ :param base_url: URL on which the property is set. Used for
+ relative externals.
+
+ :returns: dictionary with local names as keys, (revnum, url)
+ as value. revnum is the revision number and is
+ set to None if not applicable.
+ """
+ ret = {}
+ for l in val.splitlines():
+ if l == "" or l[0] == "#":
+ continue
+ pts = l.rsplit(None, 2)
+ if len(pts) == 3:
+ if not pts[1].startswith("-r"):
+ raise InvalidExternalsDescription()
+ ret[pts[0]] = (int(pts[1][2:]), urlutils.join(base_url, pts[2]))
+ elif len(pts) == 2:
+ if pts[1].startswith("//"):
+ raise NotImplementedError("Relative to the scheme externals not yet supported")
+ if pts[1].startswith("^/"):
+ raise NotImplementedError("Relative to the repository root externals not yet supported")
+ ret[pts[0]] = (None, urlutils.join(base_url, pts[1]))
+ else:
+ raise InvalidExternalsDescription()
+ return ret
+
+
+
+
PROP_EXECUTABLE = 'svn:executable'
PROP_EXECUTABLE_VALUE = '*'
PROP_EXTERNALS = 'svn:externals'
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-07-01 21:10:09 +0000
+++ b/tests/__init__.py 2008-07-03 22:10:49 +0000
@@ -329,6 +329,7 @@
'test_fileids',
'test_logwalker',
'test_mapping',
+ 'test_properties',
'test_push',
'test_ra',
'test_radir',
=== modified file 'tests/test_core.py'
--- a/tests/test_core.py 2008-06-22 18:53:14 +0000
+++ b/tests/test_core.py 2008-07-03 22:10:49 +0000
@@ -24,10 +24,3 @@
def test_exc(self):
self.assertIsInstance(core.SubversionException("foo", 1), Exception)
-
- def test_time_from_cstring(self):
- self.assertEquals(1225704780716938L, properties.time_from_cstring("2008-11-03T09:33:00.716938Z"))
-
- def test_time_to_cstring(self):
- self.assertEquals("2008-11-03T09:33:00.716938Z", properties.time_to_cstring(1225704780716938L))
-
=== added file 'tests/test_properties.py'
--- a/tests/test_properties.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_properties.py 2008-07-03 22:10:49 +0000
@@ -0,0 +1,87 @@
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""Subversion core library tests."""
+
+from bzrlib.tests import TestCase
+from bzrlib.plugins.svn import core, properties
+
+class TestProperties(TestCase):
+ def setUp(self):
+ super(TestProperties, self).setUp()
+
+ def test_time_from_cstring(self):
+ self.assertEquals(1225704780716938L, properties.time_from_cstring("2008-11-03T09:33:00.716938Z"))
+
+ def test_time_to_cstring(self):
+ self.assertEquals("2008-11-03T09:33:00.716938Z", properties.time_to_cstring(1225704780716938L))
+
+
+class TestExternalsParser(TestCase):
+ def test_parse_root_relative_externals(self):
+ self.assertRaises(NotImplementedError, properties.parse_externals_description,
+ "http://example.com", "third-party/skins ^/foo")
+
+ def test_parse_scheme_relative_externals(self):
+ self.assertRaises(NotImplementedError, properties.parse_externals_description,
+ "http://example.com", "third-party/skins //foo")
+
+ def test_parse_externals(self):
+ self.assertEqual({
+ 'third-party/sounds': (None, "http://sounds.red-bean.com/repos"),
+ 'third-party/skins': (None, "http://skins.red-bean.com/repositories/skinproj"),
+ 'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
+ properties.parse_externals_description("http://example.com",
+"""third-party/sounds http://sounds.red-bean.com/repos
+third-party/skins http://skins.red-bean.com/repositories/skinproj
+third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
+
+ def test_parse_comment(self):
+ self.assertEqual({
+ 'third-party/sounds': (None, "http://sounds.red-bean.com/repos")
+ },
+ properties.parse_externals_description("http://example.com/",
+"""
+
+third-party/sounds http://sounds.red-bean.com/repos
+#third-party/skins http://skins.red-bean.com/repositories/skinproj
+#third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
+
+ def test_parse_relative(self):
+ self.assertEqual({
+ 'third-party/sounds': (None, "http://example.com/branches/other"),
+ },
+ properties.parse_externals_description("http://example.com/trunk",
+"third-party/sounds ../branches/other"))
+
+ def test_parse_repos_root_relative(self):
+ self.assertEqual({
+ 'third-party/sounds': (None, "http://example.com/bar/bla/branches/other"),
+ },
+ properties.parse_externals_description("http://example.com/trunk",
+"third-party/sounds /bar/bla/branches/other"))
+
+ def test_parse_invalid_missing_url(self):
+ """No URL specified."""
+ self.assertRaises(InvalidExternalsDescription,
+ lambda: properties.parse_externals_description("http://example.com/", "bla"))
+
+ def test_parse_invalid_too_much_data(self):
+ """No URL specified."""
+ self.assertRaises(InvalidExternalsDescription,
+ lambda: properties.parse_externals_description(None, "bla -R40 http://bla/"))
+
+
+
=== modified file 'tests/test_tree.py'
--- a/tests/test_tree.py 2008-06-27 19:11:10 +0000
+++ b/tests/test_tree.py 2008-07-03 22:10:49 +0000
@@ -24,8 +24,7 @@
from bzrlib.plugins.svn import errors
from bzrlib.plugins.svn.tests import TestCaseWithSubversionRepository
-from bzrlib.plugins.svn.tree import (SvnBasisTree, parse_externals_description,
- inventory_add_external)
+from bzrlib.plugins.svn.tree import SvnBasisTree, inventory_add_external
import os
import sys
@@ -130,61 +129,6 @@
self.assertFalse(wt.inventory[wt.inventory.path2id("file")].executable)
-class TestExternalsParser(TestCase):
- def test_parse_root_relative_externals(self):
- self.assertRaises(NotImplementedError, parse_externals_description,
- "http://example.com", "third-party/skins ^/foo")
-
- def test_parse_scheme_relative_externals(self):
- self.assertRaises(NotImplementedError, parse_externals_description,
- "http://example.com", "third-party/skins //foo")
-
- def test_parse_externals(self):
- self.assertEqual({
- 'third-party/sounds': (None, "http://sounds.red-bean.com/repos"),
- 'third-party/skins': (None, "http://skins.red-bean.com/repositories/skinproj"),
- 'third-party/skins/toolkit': (21, "http://svn.red-bean.com/repos/skin-maker")},
- parse_externals_description("http://example.com",
-"""third-party/sounds http://sounds.red-bean.com/repos
-third-party/skins http://skins.red-bean.com/repositories/skinproj
-third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
-
- def test_parse_comment(self):
- self.assertEqual({
- 'third-party/sounds': (None, "http://sounds.red-bean.com/repos")
- },
- parse_externals_description("http://example.com/",
-"""
-
-third-party/sounds http://sounds.red-bean.com/repos
-#third-party/skins http://skins.red-bean.com/repositories/skinproj
-#third-party/skins/toolkit -r21 http://svn.red-bean.com/repos/skin-maker"""))
-
- def test_parse_relative(self):
- self.assertEqual({
- 'third-party/sounds': (None, "http://example.com/branches/other"),
- },
- parse_externals_description("http://example.com/trunk",
-"third-party/sounds ../branches/other"))
-
- def test_parse_repos_root_relative(self):
- self.assertEqual({
- 'third-party/sounds': (None, "http://example.com/bar/bla/branches/other"),
- },
- parse_externals_description("http://example.com/trunk",
-"third-party/sounds /bar/bla/branches/other"))
-
- def test_parse_invalid_missing_url(self):
- """No URL specified."""
- self.assertRaises(errors.InvalidExternalsDescription,
- lambda: parse_externals_description("http://example.com/", "bla"))
-
- def test_parse_invalid_too_much_data(self):
- """No URL specified."""
- self.assertRaises(errors.InvalidExternalsDescription,
- lambda: parse_externals_description(None, "bla -R40 http://bla/"))
-
-
class TestInventoryExternals(TestCaseWithSubversionRepository):
def test_add_nested_norev(self):
"""Add a nested tree with no specific revision referenced."""
=== modified file 'tree.py'
--- a/tree.py 2008-07-01 17:50:18 +0000
+++ b/tree.py 2008-07-03 22:10:49 +0000
@@ -31,36 +31,6 @@
from bzrlib.plugins.svn.delta import apply_txdelta_handler
-def parse_externals_description(base_url, val):
- """Parse an svn:externals property value.
-
- :param base_url: URL on which the property is set. Used for
- relative externals.
-
- :returns: dictionary with local names as keys, (revnum, url)
- as value. revnum is the revision number and is
- set to None if not applicable.
- """
- ret = {}
- for l in val.splitlines():
- if l == "" or l[0] == "#":
- continue
- pts = l.rsplit(None, 2)
- if len(pts) == 3:
- if not pts[1].startswith("-r"):
- raise errors.InvalidExternalsDescription()
- ret[pts[0]] = (int(pts[1][2:]), urlutils.join(base_url, pts[2]))
- elif len(pts) == 2:
- if pts[1].startswith("//"):
- raise NotImplementedError("Relative to the scheme externals not yet supported")
- if pts[1].startswith("^/"):
- raise NotImplementedError("Relative to the repository root externals not yet supported")
- ret[pts[0]] = (None, urlutils.join(base_url, pts[1]))
- else:
- raise errors.InvalidExternalsDescription()
- return ret
-
-
def inventory_add_external(inv, parent_id, path, revid, ref_revnum, url):
"""Add an svn:externals entry to an inventory as a tree-reference.
More information about the bazaar-commits
mailing list