Move property definitions to a separate file.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 5 Jun 2008 17:26:28 +0000 (19:26 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 5 Jun 2008 17:26:28 +0000 (19:26 +0200)
commit.py
config.py
fetch.py
mapping.py
mapping3/__init__.py
mapping3/scheme.py
properties.py [moved from util.py with 57% similarity]
transport.py
tree.py
workingtree.py

index 916ee845700e0d72e46a429aa1007073aa203290..6dd1863b9beb84d5718af1f26b6ce1d09e66dfff 100644 (file)
--- a/commit.py
+++ b/commit.py
@@ -28,7 +28,7 @@ from bzrlib.repository import RootCommitBuilder, InterRepository
 from bzrlib.revision import NULL_REVISION
 from bzrlib.trace import mutter, warning
 
-from bzrlib.plugins.svn import util
+from bzrlib.plugins.svn import properties
 
 from cStringIO import StringIO
 from bzrlib.plugins.svn.errors import ChangesRootLHSHistory, MissingPrefix, RevpropChangeFailed
@@ -280,20 +280,20 @@ class SvnCommitBuilder(RootCommitBuilder):
             if child_baton is not None:
                 if old_executable != child_ie.executable:
                     if child_ie.executable:
-                        value = svn.core.SVN_PROP_EXECUTABLE_VALUE
+                        value = properties.PROP_EXECUTABLE_VALUE
                     else:
                         value = None
                     self.editor.change_file_prop(child_baton, 
-                            svn.core.SVN_PROP_EXECUTABLE, value, self.pool)
+                            properties.PROP_EXECUTABLE, value, self.pool)
 
                 if old_special != (child_ie.kind == 'symlink'):
                     if child_ie.kind == 'symlink':
-                        value = svn.core.SVN_PROP_SPECIAL_VALUE
+                        value = properties.PROP_SPECIAL_VALUE
                     else:
                         value = None
 
                     self.editor.change_file_prop(child_baton, 
-                            svn.core.SVN_PROP_SPECIAL, value, self.pool)
+                            properties.PROP_SPECIAL, value, self.pool)
 
             # handle the file
             if child_ie.file_id in self.modified_files:
@@ -446,14 +446,14 @@ class SvnCommitBuilder(RootCommitBuilder):
         if self._config.get_log_strip_trailing_newline():
             self.base_mapping.export_message(message, self._svn_revprops, self._svnprops)
             message = message.rstrip("\n")
-        self._svn_revprops[svn.core.SVN_PROP_REVISION_LOG] = message.encode("utf-8")
+        self._svn_revprops[properties.PROP_REVISION_LOG] = message.encode("utf-8")
 
         try:
             existing_bp_parts = _check_dirs_exist(self.repository.transport, 
                                               bp_parts, -1)
             self.revision_metadata = None
             for prop in self._svn_revprops:
-                if not util.is_valid_property_name(prop):
+                if not properties.is_valid_property_name(prop):
                     warning("Setting property %r with invalid characters in name" % prop)
             try:
                 self.editor = self.repository.transport.get_commit_editor(
@@ -464,9 +464,9 @@ class SvnCommitBuilder(RootCommitBuilder):
                     raise
                 # Try without bzr: revprops
                 self.editor = self.repository.transport.get_commit_editor({
-                    svn.core.SVN_PROP_REVISION_LOG: self._svn_revprops[svn.core.SVN_PROP_REVISION_LOG]},
+                    properties.PROP_REVISION_LOG: self._svn_revprops[properties.PROP_REVISION_LOG]},
                     done, None, False)
-                del self._svn_revprops[svn.core.SVN_PROP_REVISION_LOG]
+                del self._svn_revprops[properties.PROP_REVISION_LOG]
 
             root = self.editor.open_root(self.base_revnum)
 
@@ -492,7 +492,7 @@ class SvnCommitBuilder(RootCommitBuilder):
 
             # Set all the revprops
             for prop, value in self._svnprops.items():
-                if not util.is_valid_property_name(prop):
+                if not properties.is_valid_property_name(prop):
                     warning("Setting property %r with invalid characters in name" % prop)
                 if value is not None:
                     value = value.encode('utf-8')
@@ -522,10 +522,10 @@ class SvnCommitBuilder(RootCommitBuilder):
         override_svn_revprops = self._config.get_override_svn_revprops()
         if override_svn_revprops is not None:
             new_revprops = {}
-            if svn.core.SVN_PROP_REVISION_AUTHOR in override_svn_revprops:
-                new_revprops[svn.core.SVN_PROP_REVISION_AUTHOR] = self._committer.encode("utf-8")
-            if svn.core.SVN_PROP_REVISION_DATE in override_svn_revprops:
-                new_revprops[svn.core.SVN_PROP_REVISION_DATE] = svn_time_to_cstring(1000000*self._timestamp)
+            if properties.PROP_REVISION_AUTHOR in override_svn_revprops:
+                new_revprops[properties.PROP_REVISION_AUTHOR] = self._committer.encode("utf-8")
+            if properties.PROP_REVISION_DATE in override_svn_revprops:
+                new_revprops[properties.PROP_REVISION_DATE] = svn_time_to_cstring(1000000*self._timestamp)
             set_svn_revprops(self.repository.transport, self.revision_metadata.revision, new_revprops)
 
         try:
index 878831d18b5d2890d8627a4fdc8548845f806179..7285d4b0d88825cb546c7e861484a90e172de06d 100644 (file)
--- a/config.py
+++ b/config.py
@@ -20,6 +20,8 @@ from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists,
 
 import os
 
+from bzrlib.plugins.svn import properties
+
 import svn.core
 
 # Settings are stored by UUID. 
@@ -120,7 +122,7 @@ class SvnRepositoryConfig(IniBasedConfig):
         def get_list(parser, section):
             try:
                 if parser.get_bool(section, "override-svn-revprops"):
-                    return [svn.core.SVN_PROP_REVISION_DATE, svn.core.SVN_PROP_REVISION_AUTHOR]
+                    return [properties.PROP_REVISION_DATE, properties.PROP_REVISION_AUTHOR]
                 return []
             except ValueError:
                 val = parser.get_value(section, "override-svn-revprops")
index 44d8356f82aba0204f5ac67078ba02b7f51e0031..fc91a59c3b077aff790d8dfae7a57cce188f9b8b 100644 (file)
--- a/fetch.py
+++ b/fetch.py
@@ -28,6 +28,7 @@ import md5
 from svn.core import Pool
 import svn.core
 
+from bzrlib.plugins.svn import properties
 from bzrlib.plugins.svn.errors import InvalidFileName
 from bzrlib.plugins.svn.logwalker import lazy_dict
 from bzrlib.plugins.svn.mapping import (SVN_PROP_BZR_MERGE, 
@@ -262,40 +263,40 @@ class RevisionBuildEditor(svn.delta.Editor):
                 self.revmeta.fileprops = {}
             self.revmeta.fileprops[name] = value
 
-        if name in (svn.core.SVN_PROP_ENTRY_COMMITTED_DATE,
-                      svn.core.SVN_PROP_ENTRY_COMMITTED_REV,
-                      svn.core.SVN_PROP_ENTRY_LAST_AUTHOR,
-                      svn.core.SVN_PROP_ENTRY_LOCK_TOKEN,
-                      svn.core.SVN_PROP_ENTRY_UUID,
-                      svn.core.SVN_PROP_EXECUTABLE):
+        if name in (properties.PROP_ENTRY_COMMITTED_DATE,
+                    properties.PROP_ENTRY_COMMITTED_REV,
+                    properties.PROP_ENTRY_LAST_AUTHOR,
+                    properties.PROP_ENTRY_LOCK_TOKEN,
+                    properties.PROP_ENTRY_UUID,
+                    properties.PROP_EXECUTABLE):
             pass
-        elif (name.startswith(svn.core.SVN_PROP_WC_PREFIX)):
+        elif (name.startswith(properties.PROP_WC_PREFIX)):
             pass
-        elif name.startswith(svn.core.SVN_PROP_PREFIX):
+        elif name.startswith(properties.PROP_PREFIX):
             mutter('unsupported dir property %r' % name)
 
     def change_file_prop(self, id, name, value, pool):
-        if name == svn.core.SVN_PROP_EXECUTABLE: 
+        if name == properties.PROP_EXECUTABLE: 
             # You'd expect executable to match 
-            # svn.core.SVN_PROP_EXECUTABLE_VALUE, but that's not 
+            # properties.PROP_EXECUTABLE_VALUE, but that's not 
             # how SVN behaves. It appears to consider the presence 
             # of the property sufficient to mark it executable.
             self.is_executable = (value != None)
-        elif (name == svn.core.SVN_PROP_SPECIAL):
+        elif (name == properties.PROP_SPECIAL):
             self.is_symlink = (value != None)
-        elif name == svn.core.SVN_PROP_ENTRY_COMMITTED_REV:
+        elif name == properties.PROP_ENTRY_COMMITTED_REV:
             self.last_file_rev = int(value)
-        elif name == svn.core.SVN_PROP_EXTERNALS:
+        elif name == properties.PROP_EXTERNALS:
             mutter('svn:externals property on file!')
-        elif name in (svn.core.SVN_PROP_ENTRY_COMMITTED_DATE,
-                      svn.core.SVN_PROP_ENTRY_LAST_AUTHOR,
-                      svn.core.SVN_PROP_ENTRY_LOCK_TOKEN,
-                      svn.core.SVN_PROP_ENTRY_UUID,
-                      svn.core.SVN_PROP_MIME_TYPE):
+        elif name in (properties.PROP_ENTRY_COMMITTED_DATE,
+                      properties.PROP_ENTRY_LAST_AUTHOR,
+                      properties.PROP_ENTRY_LOCK_TOKEN,
+                      properties.PROP_ENTRY_UUID,
+                      properties.PROP_MIME_TYPE):
             pass
-        elif name.startswith(svn.core.SVN_PROP_WC_PREFIX):
+        elif name.startswith(properties.PROP_WC_PREFIX):
             pass
-        elif (name.startswith(svn.core.SVN_PROP_PREFIX) or
+        elif (name.startswith(properties.PROP_PREFIX) or
               name.startswith(SVN_PROP_BZR_PREFIX)):
             mutter('unsupported file property %r' % name)
 
index e8c5393c712bae19fd88774afcdba05fd2223f33..4ef06563538e0b0914bcd7814b9a7530979fd3e9 100644 (file)
@@ -19,7 +19,7 @@ from bzrlib import osutils, registry
 from bzrlib.errors import InvalidRevisionId
 from bzrlib.trace import mutter
 
-from bzrlib.plugins.svn import version_info, errors
+from bzrlib.plugins.svn import version_info, errors, properties
 import calendar
 import svn
 import time
@@ -137,12 +137,12 @@ def parse_merge_property(line):
     return tuple(filter(lambda x: x != "", line.split("\t")))
 
 def parse_svn_revprops(svn_revprops, rev):
-    if svn_revprops.has_key(svn.core.SVN_PROP_REVISION_AUTHOR):
-        rev.committer = svn_revprops[svn.core.SVN_PROP_REVISION_AUTHOR]
+    if svn_revprops.has_key(properties.PROP_REVISION_AUTHOR):
+        rev.committer = svn_revprops[properties.PROP_REVISION_AUTHOR]
     else:
         rev.committer = ""
     
-    rev.message = svn_revprops.get(svn.core.SVN_PROP_REVISION_LOG)
+    rev.message = svn_revprops.get(properties.PROP_REVISION_LOG)
 
     if rev.message:
         try:
@@ -150,8 +150,8 @@ def parse_svn_revprops(svn_revprops, rev):
         except UnicodeDecodeError:
             pass
 
-    if svn_revprops.has_key(svn.core.SVN_PROP_REVISION_DATE):
-        rev.timestamp = 1.0 * svn.core.secs_from_timestr(svn_revprops[svn.core.SVN_PROP_REVISION_DATE], None)
+    if svn_revprops.has_key(properties.PROP_REVISION_DATE):
+        rev.timestamp = 1.0 * svn.core.secs_from_timestr(svn_revprops[properties.PROP_REVISION_DATE], None)
     else:
         rev.timestamp = 0.0 # FIXME: Obtain repository creation time
     rev.timezone = None
index 9534e69b28c17626db658276045a0da544e15229..623ca019b01a217871697355e966489819f857d8 100644 (file)
@@ -16,7 +16,7 @@
 from bzrlib import osutils, ui
 from bzrlib.errors import InvalidRevisionId
 from bzrlib.trace import mutter
-from bzrlib.plugins.svn import mapping
+from bzrlib.plugins.svn import mapping, properties
 from bzrlib.plugins.svn.layout import RepositoryLayout
 from bzrlib.plugins.svn.mapping3.scheme import (BranchingScheme, guess_scheme_from_branch_path, 
                              guess_scheme_from_history, ListBranchingScheme, 
@@ -121,7 +121,7 @@ def set_property_scheme(repository, scheme):
     def done(revmetadata, pool):
         pass
     editor = repository.transport.get_commit_editor(
-            {svn.core.SVN_PROP_REVISION_LOG: "Updating branching scheme for Bazaar."},
+            {properties.PROP_REVISION_LOG: "Updating branching scheme for Bazaar."},
             done, None, False)
     root = editor.open_root(-1)
     editor.change_dir_prop(root, SVN_PROP_BZR_BRANCHING_SCHEME, 
index 807301256aa7f53f55753326e49b18785579874c..b67f25596dd9cbe9e2e09ec22b4374d67b1d65a1 100644 (file)
@@ -23,7 +23,7 @@ from bzrlib.errors import NotBranchError
 
 from base64 import urlsafe_b64decode, urlsafe_b64encode
 from bzrlib.plugins.svn.errors import InvalidSvnBranchPath
-from bzrlib.plugins.svn import util
+from bzrlib.plugins.svn import properties
 import bz2
 import urllib
 
@@ -338,7 +338,7 @@ class SingleBranchingScheme(ListBranchingScheme):
                 path[len(self.path):].strip("/"))
 
     def __str__(self):
-        if util.is_valid_property_name(self.path):
+        if properties.is_valid_property_name(self.path):
             return "single-%s" % self.path
         else:
             return "single1-%s" % prop_name_quote(self.path)
similarity index 57%
rename from util.py
rename to properties.py
index 7f48afa9df0bfca4344a80d2032af3d43d063848..f3d894cbf482e12bc44b66fff1068f7971533cc3 100644 (file)
--- a/util.py
@@ -20,3 +20,25 @@ def is_valid_property_name(prop):
         if not c.isalnum() and not c in "-:._":
             return False
     return True
+
+PROP_EXECUTABLE = 'svn:executable'
+PROP_EXECUTABLE_VALUE = '*'
+PROP_EXTERNALS = 'svn:externals'
+PROP_IGNORE = 'svn:ignore'
+PROP_KEYWORDS = 'svn:keywords'
+PROP_MIME_TYPE = 'svn:mime-type'
+PROP_NEEDS_LOCK = 'svn:needs-lock'
+PROP_NEEDS_LOCK_VALUE = '*'
+PROP_PREFIX = 'svn:'
+PROP_SPECIAL = 'svn:special'
+PROP_SPECIAL_VALUE = '*'
+PROP_WC_PREFIX = 'svn:wc:'
+PROP_ENTRY_COMMITTED_DATE = 'svn:entry:committed-date'
+PROP_ENTRY_COMMITTED_REV = 'svn:entry:committed-rev'
+PROP_ENTRY_LAST_AUTHOR = 'svn:entry:last-author'
+PROP_ENTRY_LOCK_TOKEN = 'svn:entry:lock-token'
+PROP_ENTRY_UUID = 'svn:entry:uuid'
+
+PROP_REVISION_LOG = "svn:log"
+PROP_REVISION_AUTHOR = "svn:author"
+PROP_REVISION_DATE = "svn:date"
index 9efb04fccfe35028601ca3123bee43b038b6bbfb..bb46ab6ce78be8d1bd7c55607fa8756e88ee0396 100644 (file)
@@ -26,6 +26,7 @@ import svn.ra
 import svn.core
 import svn.client
 
+from bzrlib.plugins.svn import properties
 from bzrlib.plugins.svn.errors import convert_svn_error, NoSvnRepositoryPresent
 import urlparse
 import urllib
@@ -387,11 +388,11 @@ class Connection(object):
             if hasattr(svn.ra, 'get_commit_editor3'):
                 editor = svn.ra.get_commit_editor3(self._ra, revprops, done_cb, 
                                                   lock_token, keep_locks)
-            elif revprops.keys() != [svn.core.SVN_PROP_REVISION_LOG]:
+            elif revprops.keys() != [properties.PROP_REVISION_LOG]:
                 raise NotImplementedError()
             else:
                 editor = svn.ra.get_commit_editor2(self._ra, 
-                            revprops[svn.core.SVN_PROP_REVISION_LOG],
+                            revprops[properties.PROP_REVISION_LOG],
                             done_cb, lock_token, keep_locks)
 
             return Editor(self, editor)
@@ -438,12 +439,12 @@ class Connection(object):
             def __init__(self, changed_paths, rev, author, date, message):
                 self.changed_paths = changed_paths
                 self.revprops = {}
-                if svn.core.SVN_PROP_REVISION_AUTHOR in revprops:
-                    self.revprops[svn.core.SVN_PROP_REVISION_AUTHOR] = author
-                if svn.core.SVN_PROP_REVISION_LOG in revprops:
-                    self.revprops[svn.core.SVN_PROP_REVISION_LOG] = message
-                if svn.core.SVN_PROP_REVISION_DATE in revprops:
-                    self.revprops[svn.core.SVN_PROP_REVISION_DATE] = date
+                if properties.PROP_REVISION_AUTHOR in revprops:
+                    self.revprops[properties.PROP_REVISION_AUTHOR] = author
+                if properties.PROP_REVISION_LOG in revprops:
+                    self.revprops[properties.PROP_REVISION_LOG] = message
+                if properties.PROP_REVISION_DATE in revprops:
+                    self.revprops[properties.PROP_REVISION_DATE] = date
                 # FIXME: Check other revprops
                 # FIXME: Handle revprops is None
                 self.revision = rev
diff --git a/tree.py b/tree.py
index af3e63c315caceb85ea7f9b472a792912dfd432c..c1ac846b96411aaeb870fa5a9f321eb66f841ece 100644 (file)
--- a/tree.py
+++ b/tree.py
@@ -31,7 +31,7 @@ import urllib
 import svn.core, svn.wc, svn.delta
 from svn.core import Pool
 
-from bzrlib.plugins.svn import errors
+from bzrlib.plugins.svn import errors, properties
 
 def parse_externals_description(base_url, val):
     """Parse an svn:externals property value.
@@ -176,39 +176,39 @@ class TreeBuildEditor(svn.delta.Editor):
         return file_id
 
     def change_dir_prop(self, id, name, value, pool):
-        if name == svn.core.SVN_PROP_ENTRY_COMMITTED_REV:
+        if name == properties.PROP_ENTRY_COMMITTED_REV:
             self.dir_revnum[id] = int(value)
-        elif name == svn.core.SVN_PROP_IGNORE:
+        elif name == properties.PROP_IGNORE:
             self.dir_ignores[id] = value
-        elif name in (svn.core.SVN_PROP_ENTRY_COMMITTED_DATE,
-                      svn.core.SVN_PROP_ENTRY_LAST_AUTHOR,
-                      svn.core.SVN_PROP_ENTRY_LOCK_TOKEN,
-                      svn.core.SVN_PROP_ENTRY_UUID,
-                      svn.core.SVN_PROP_EXECUTABLE):
+        elif name in (properties.PROP_ENTRY_COMMITTED_DATE,
+                      properties.PROP_ENTRY_LAST_AUTHOR,
+                      properties.PROP_ENTRY_LOCK_TOKEN,
+                      properties.PROP_ENTRY_UUID,
+                      properties.PROP_EXECUTABLE):
             pass
-        elif name.startswith(svn.core.SVN_PROP_WC_PREFIX):
+        elif name.startswith(properties.PROP_WC_PREFIX):
             pass
-        elif name.startswith(svn.core.SVN_PROP_PREFIX):
+        elif name.startswith(properties.PROP_PREFIX):
             mutter('unsupported dir property %r' % name)
 
     def change_file_prop(self, id, name, value, pool):
-        if name == svn.core.SVN_PROP_EXECUTABLE:
+        if name == properties.PROP_EXECUTABLE:
             self.is_executable = (value != None)
-        elif name == svn.core.SVN_PROP_SPECIAL:
+        elif name == properties.PROP_SPECIAL:
             self.is_symlink = (value != None)
-        elif name == svn.core.SVN_PROP_EXTERNALS:
+        elif name == properties.PROP_EXTERNALS:
             mutter('%r property on file!' % name)
-        elif name == svn.core.SVN_PROP_ENTRY_COMMITTED_REV:
+        elif name == properties.PROP_ENTRY_COMMITTED_REV:
             self.last_file_rev = int(value)
-        elif name in (svn.core.SVN_PROP_ENTRY_COMMITTED_DATE,
-                      svn.core.SVN_PROP_ENTRY_LAST_AUTHOR,
-                      svn.core.SVN_PROP_ENTRY_LOCK_TOKEN,
-                      svn.core.SVN_PROP_ENTRY_UUID,
-                      svn.core.SVN_PROP_MIME_TYPE):
+        elif name in (properties.PROP_ENTRY_COMMITTED_DATE,
+                      properties.PROP_ENTRY_LAST_AUTHOR,
+                      properties.PROP_ENTRY_LOCK_TOKEN,
+                      properties.PROP_ENTRY_UUID,
+                      properties.PROP_MIME_TYPE):
             pass
-        elif name.startswith(svn.core.SVN_PROP_WC_PREFIX):
+        elif name.startswith(properties.PROP_WC_PREFIX):
             pass
-        elif name.startswith(svn.core.SVN_PROP_PREFIX):
+        elif name.startswith(properties.PROP_PREFIX):
             mutter('unsupported file property %r' % name)
 
     def add_file(self, path, parent_id, copyfrom_path, copyfrom_revnum, baton):
@@ -281,7 +281,7 @@ class SvnBasisTree(RevisionTree):
             props = svn.wc.get_prop_diffs(self.workingtree.abspath(relpath).encode("utf-8"), wc)
             if isinstance(props, list): # Subversion 1.5
                 props = props[1]
-            if props.has_key(svn.core.SVN_PROP_SPECIAL):
+            if props.has_key(properties.PROP_SPECIAL):
                 ie = self._inventory.add_path(relpath, 'symlink', id)
                 ie.symlink_target = open(self._abspath(relpath)).read()[len("link "):]
                 ie.text_sha1 = None
@@ -293,7 +293,7 @@ class SvnBasisTree(RevisionTree):
                 data = osutils.fingerprint_file(open(self._abspath(relpath)))
                 ie.text_sha1 = data['sha1']
                 ie.text_size = data['size']
-                ie.executable = props.has_key(svn.core.SVN_PROP_EXECUTABLE)
+                ie.executable = props.has_key(properties.PROP_EXECUTABLE)
             ie.revision = revid
             return ie
 
index 1b85de73e814e22739d4aedb21d9aad74b9ffc62..7b3f60252e8c203a570e0a2f75b64b1e350694ef 100644 (file)
@@ -32,6 +32,7 @@ from bzrlib.revisiontree import RevisionTree
 from bzrlib.transport.local import LocalTransport
 from bzrlib.workingtree import WorkingTree, WorkingTreeFormat
 
+from bzrlib.plugins.svn import properties
 from bzrlib.plugins.svn.branch import SvnBranch
 from bzrlib.plugins.svn.commit import _revision_id_to_svk_feature
 from bzrlib.plugins.svn.convert import SvnConverter
@@ -107,7 +108,7 @@ class SvnWorkingTree(WorkingTree):
         ignores.update(svn.wc.get_default_ignores(svn_config))
 
         def dir_add(wc, prefix, patprefix):
-            ignorestr = svn.wc.prop_get(svn.core.SVN_PROP_IGNORE, 
+            ignorestr = svn.wc.prop_get(properties.PROP_IGNORE, 
                                         self.abspath(prefix).rstrip("/"), wc)
             if ignorestr is not None:
                 for pat in ignorestr.splitlines():