Author: hwright Date: Thu Aug 11 17:39:40 2011 New Revision: 1156697 URL: http://svn.apache.org/viewvc?rev=1156697&view=rev Log: On the fs-py branch: Move most of the create_fs implementation into Python.
* subversion/python/svn/fs.py (): A few more constants. (FS.__write_revision_zero): New. (FS._create_fs): Create the directories and files required for a FSFS filesystem. (FS.__setup_paths): Add another path. * subversion/python/svn/prop.py: New. * subversion/libsvn_fs_py/fs_fs.c (write_revision_zero): Remove. (svn_fs_py__create): Largely gut, in favor of the Python version. * subversion/libsvn_fs_py/py_util.c (get_int_attr_baton, get_int_attr, svn_fs_py__get_int_attr): New. * subversion/libsvn_fs_py/py_util.h (svn_fs_py__get_int_attr): New. Added: subversion/branches/fs-py/subversion/python/svn/prop.py (with props) Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h subversion/branches/fs-py/subversion/python/svn/fs.py Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c URL: http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c?rev=1156697&r1=1156696&r2=1156697&view=diff ============================================================================== --- subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c (original) +++ subversion/branches/fs-py/subversion/libsvn_fs_py/fs_fs.c Thu Aug 11 17:39:40 2011 @@ -6196,40 +6196,11 @@ svn_fs_py__reserve_copy_id(const char ** return SVN_NO_ERROR; } -/* Write out the zeroth revision for filesystem FS. */ -static svn_error_t * -write_revision_zero(svn_fs_t *fs) -{ - const char *path_revision_zero = path_rev(fs, 0, fs->pool); - apr_hash_t *proplist; - svn_string_t date; - - /* Write out a rev file for revision 0. */ - SVN_ERR(svn_io_file_create(path_revision_zero, - "PLAIN\nEND\nENDREP\n" - "id: 0.0.r0/17\n" - "type: dir\n" - "count: 0\n" - "text: 0 0 4 4 " - "2d2977d1c96f487abe4a1e202dd03b4e\n" - "cpath: /\n" - "\n\n17 107\n", fs->pool)); - SVN_ERR(svn_io_set_file_read_only(path_revision_zero, FALSE, fs->pool)); - - /* Set a date on revision 0. */ - date.data = svn_time_to_cstring(apr_time_now(), fs->pool); - date.len = strlen(date.data); - proplist = apr_hash_make(fs->pool); - apr_hash_set(proplist, SVN_PROP_REVISION_DATE, APR_HASH_KEY_STRING, &date); - return set_revision_proplist(fs, 0, proplist, fs->pool); -} - svn_error_t * svn_fs_py__create(svn_fs_t *fs, const char *path, apr_pool_t *pool) { - int format = SVN_FS_FS__FORMAT_NUMBER; fs_fs_data_t *ffd = fs->fsap_data; fs->path = apr_pstrdup(pool, path); @@ -6240,75 +6211,17 @@ svn_fs_py__create(svn_fs_t *fs, apr_pool_cleanup_register(fs->pool, ffd->p_fs, svn_fs_py__destroy_py_object, apr_pool_cleanup_null); - /* See if compatibility with older versions was explicitly requested. */ - if (fs->config) - { - if (apr_hash_get(fs->config, SVN_FS_CONFIG_PRE_1_4_COMPATIBLE, - APR_HASH_KEY_STRING)) - format = 1; - else if (apr_hash_get(fs->config, SVN_FS_CONFIG_PRE_1_5_COMPATIBLE, - APR_HASH_KEY_STRING)) - format = 2; - else if (apr_hash_get(fs->config, SVN_FS_CONFIG_PRE_1_6_COMPATIBLE, - APR_HASH_KEY_STRING)) - format = 3; - } - ffd->format = format; - - /* Override the default linear layout if this is a new-enough format. */ - if (format >= SVN_FS_FS__MIN_LAYOUT_FORMAT_OPTION_FORMAT) - ffd->max_files_per_dir = SVN_FS_FS_DEFAULT_MAX_FILES_PER_DIR; - - /* Create the revision data directories. */ - if (ffd->max_files_per_dir) - SVN_ERR(svn_io_make_dir_recursively(path_rev_shard(fs, 0, pool), pool)); - else - SVN_ERR(svn_io_make_dir_recursively(svn_dirent_join(path, PATH_REVS_DIR, - pool), - pool)); - - /* Create the revprops directory. */ - if (ffd->max_files_per_dir) - SVN_ERR(svn_io_make_dir_recursively(path_revprops_shard(fs, 0, pool), - pool)); - else - SVN_ERR(svn_io_make_dir_recursively(svn_dirent_join(path, - PATH_REVPROPS_DIR, - pool), - pool)); - - /* Create the transaction directory. */ - SVN_ERR(svn_io_make_dir_recursively(svn_dirent_join(path, PATH_TXNS_DIR, - pool), - pool)); - - /* Create the protorevs directory. */ - if (format >= SVN_FS_FS__MIN_PROTOREVS_DIR_FORMAT) - SVN_ERR(svn_io_make_dir_recursively(svn_dirent_join(path, PATH_TXN_PROTOS_DIR, - pool), - pool)); - - /* Create the 'current' file. */ - SVN_ERR(svn_io_file_create(svn_fs_py__path_current(fs, pool), - (format >= SVN_FS_FS__MIN_NO_GLOBAL_IDS_FORMAT - ? "0\n" : "0 1 1\n"), - pool)); - SVN_ERR(svn_io_file_create(path_lock(fs, pool), "", pool)); - SVN_ERR(svn_fs_py__set_uuid(fs, NULL, pool)); - - SVN_ERR(write_revision_zero(fs)); + SVN_ERR(svn_fs_py__get_int_attr(&ffd->format, ffd->p_fs, "format")); + SVN_ERR(svn_fs_py__get_int_attr(&ffd->max_files_per_dir, ffd->p_fs, + "max_files_per_dir")); SVN_ERR(write_config(fs, pool)); SVN_ERR(read_config(fs, pool)); - /* Create the min unpacked rev file. */ - if (ffd->format >= SVN_FS_FS__MIN_PACKED_FORMAT) - SVN_ERR(svn_io_file_create(path_min_unpacked_rev(fs, pool), "0\n", pool)); - /* Create the txn-current file if the repository supports the transaction sequence file. */ - if (format >= SVN_FS_FS__MIN_TXN_CURRENT_FORMAT) + if (ffd->format >= SVN_FS_FS__MIN_TXN_CURRENT_FORMAT) { SVN_ERR(svn_io_file_create(path_txn_current(fs, pool), "0\n", pool)); Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c URL: http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c?rev=1156697&r1=1156696&r2=1156697&view=diff ============================================================================== --- subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c (original) +++ subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.c Thu Aug 11 17:39:40 2011 @@ -308,6 +308,45 @@ svn_fs_py__get_string_attr(const char ** } + +struct get_int_attr_baton +{ + int *result; + PyObject *p_obj; + const char *name; +}; + + +static void +get_int_attr(void *baton, + va_list argp) +{ + struct get_int_attr_baton *giab = baton; + PyObject *p_int; + + /* ### This needs some exception handling */ + + p_int = PyObject_GetAttrString(giab->p_obj, giab->name); + if (PyErr_Occurred()) + return; + + *giab->result = (int) PyInt_AsLong(p_int); + Py_DECREF(p_int); + + return; +} + + +svn_error_t * +svn_fs_py__get_int_attr(int *result, + PyObject *p_obj, + const char *name) +{ + struct get_int_attr_baton giab = { result, p_obj, name }; + return svn_error_trace(catch_py_exception(get_int_attr, &giab, NULL)); +} + + struct call_method_baton { PyObject **p_result; Modified: subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h URL: http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h?rev=1156697&r1=1156696&r2=1156697&view=diff ============================================================================== --- subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h (original) +++ subversion/branches/fs-py/subversion/libsvn_fs_py/py_util.h Thu Aug 11 17:39:40 2011 @@ -57,3 +57,8 @@ svn_fs_py__get_string_attr(const char ** PyObject *p_obj, const char *name, apr_pool_t *result_pool); + +svn_error_t * +svn_fs_py__get_int_attr(int *result, + PyObject *p_obj, + const char *name); Modified: subversion/branches/fs-py/subversion/python/svn/fs.py URL: http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/python/svn/fs.py?rev=1156697&r1=1156696&r2=1156697&view=diff ============================================================================== --- subversion/branches/fs-py/subversion/python/svn/fs.py (original) +++ subversion/branches/fs-py/subversion/python/svn/fs.py Thu Aug 11 17:39:40 2011 @@ -18,10 +18,11 @@ # specific language governing permissions and limitations # under the License. -import os, uuid, shutil, tempfile +import os, uuid, stat, shutil, tempfile, datetime import svn import svn.hash +import svn.prop # Some constants CONFIG_PRE_1_4_COMPATIBLE = "pre-1.4-compatible" @@ -31,8 +32,11 @@ CONFIG_PRE_1_6_COMPATIBLE = "pre-1.6-c PATH_FORMAT = "format" # Contains format number PATH_UUID = "uuid" # Contains UUID PATH_CURRENT = "current" # Youngest revision +PATH_LOCK_FILE = "write-lock" # Revision lock file PATH_REVS_DIR = "revs" # Directory of revisions PATH_REVPROPS_DIR = "revprops" # Directory of revprops +PATH_TXNS_DIR = "transactions" # Directory of transactions +PATH_TXN_PROTOS_DIR = "txn-protorevs" # Directory of proto-revs PATH_MIN_UNPACKED_REV = "min-unpacked-rev" # Oldest revision which # has not been packed. @@ -44,6 +48,7 @@ MIN_NO_GLOBAL_IDS_FORMAT = 3 MIN_PACKED_FORMAT = 4 _DEFAULT_MAX_FILES_PER_DIR = 1000 +_TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ' class FS(object): @@ -156,6 +161,28 @@ class FS(object): self.__min_unpacked_rev = int(f.readline()) + def __write_revision_zero(self): + 'Write out the zeroth revision for filesystem FS.' + path_revision_zero = self.__path_rev(0) + + with open(path_revision_zero, 'wb') as f: + f.write("PLAIN\nEND\nENDREP\n" + + "id: 0.0.r0/17\n" + + "type: dir\n" + + "count: 0\n" + + "text: 0 0 4 4 " + + "2d2977d1c96f487abe4a1e202dd03b4e\n" + + "cpath: /\n" + + "\n\n17 107\n") + + # Set the file read-only + os.chmod(path_revision_zero, stat.S_IREAD | stat.S_IRGRP | stat.S_IROTH) + + now = datetime.datetime.utcnow() + props = { svn.prop.REVISION_DATE : now.strftime(_TIMESTAMP_FORMAT) } + self._set_revision_proplist(0, props) + + def _create_fs(self): 'Create a new Subversion filesystem' self.__youngest_rev_cache = 0 @@ -177,6 +204,40 @@ class FS(object): else: self.max_files_per_dir = 0 + # Create the revision data and revprops directories. + if self.max_files_per_dir: + os.makedirs(self.__path_rev_shard(0)) + os.makedirs(self.__path_revprops_shard(0)) + else: + os.makedirs(os.path.join(self.path, PATH_REVS_DIR)) + os.makedirs(os.path.join(self.path, PATH_REVPROPS_DIR)) + + # Create the transaction directory. + os.makedirs(os.path.join(self.path, PATH_TXNS_DIR)) + + # Create the protorevs directory. + if self.format >= MIN_PROTOREVS_DIR_FORMAT: + os.makedirs(os.path.join(self.path, PATH_TXN_PROTOS_DIR)) + + # Create the 'current' file. + if self.format >= MIN_NO_GLOBAL_IDS_FORMAT: + current_contents = "0\n" + else: + current_contents = "0 1 1\n" + with open(self.__path_current, 'wb') as f: + f.write(current_contents) + + with open(self.__path_lock, 'wb') as f: + f.write('') + + # Create the min unpacked rev file. + if self.format >= MIN_PACKED_FORMAT: + with open(self.__path_min_unpacked_rev, 'wb') as f: + f.write('0\n') + + self.set_uuid() + self.__write_revision_zero() + def _open_fs(self): 'Open an existing Subvesion filesystem' @@ -195,6 +256,7 @@ class FS(object): self.__path_format = os.path.join(self.path, PATH_FORMAT) self.__path_min_unpacked_rev = os.path.join(self.path, PATH_MIN_UNPACKED_REV) + self.__path_lock = os.path.join(self.path, PATH_LOCK_FILE) def __init__(self, path, create=False, config=None): Added: subversion/branches/fs-py/subversion/python/svn/prop.py URL: http://svn.apache.org/viewvc/subversion/branches/fs-py/subversion/python/svn/prop.py?rev=1156697&view=auto ============================================================================== --- subversion/branches/fs-py/subversion/python/svn/prop.py (added) +++ subversion/branches/fs-py/subversion/python/svn/prop.py Thu Aug 11 17:39:40 2011 @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# All Subversion property names start with this +PREFIX = "svn:" + +# The fs revision property that stores a commit's date. +REVISION_DATE = PREFIX + "date" Propchange: subversion/branches/fs-py/subversion/python/svn/prop.py ------------------------------------------------------------------------------ svn:eol-style = native