You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2015/01/16 18:32:55 UTC

svn commit: r1652469 - in /subversion/trunk/subversion/libsvn_fs_x: util.c util.h

Author: stefan2
Date: Fri Jan 16 17:32:55 2015
New Revision: 1652469

URL: http://svn.apache.org/r1652469
Log:
Continue work on FSX's path constructors.

In this patch, get rid of the temporary buffers for files in sharded
directories.

* subversion/libsvn_fs_x/util.c
  (construct_shard_sub_path): New path construction utility. 
  (svn_fs_x__path_rev_packed,
   svn_fs_x__path_rev): Simplify by calling the new utility.
                        The POOL is now a pure RESULT_POOL.
  (svn_fs_x__path_rev_absolute): The POOL is now a pure RESULT_POOL.
  (svn_fs_x__path_revprops_pack_shard,
   svn_fs_x__path_revprops): Same due to calling the new utility.

* subversion/libsvn_fs_x/util.h
  (svn_fs_x__path_rev_packed,
   svn_fs_x__path_rev_shard,
   svn_fs_x__path_rev,
   svn_fs_x__path_revprops_pack_shard,
   svn_fs_x__path_revprops):  Sync declarations with the implementations.

Modified:
    subversion/trunk/subversion/libsvn_fs_x/util.c
    subversion/trunk/subversion/libsvn_fs_x/util.h

Modified: subversion/trunk/subversion/libsvn_fs_x/util.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_x/util.c?rev=1652469&r1=1652468&r2=1652469&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_x/util.c (original)
+++ subversion/trunk/subversion/libsvn_fs_x/util.c Fri Jan 16 17:32:55 2015
@@ -145,18 +145,46 @@ svn_fs_x__path_revprop_generation(svn_fs
   return svn_dirent_join(fs->path, PATH_REVPROP_GENERATION, result_pool);
 }
 
-const char *
-svn_fs_x__path_rev_packed(svn_fs_t *fs, svn_revnum_t rev, const char *kind,
-                          apr_pool_t *pool)
+/* Return the full path of the file FILENAME within revision REV's shard in
+ * FS.  If FILENAME is NULL, return the shard directory directory itself.
+ * REVPROPS indicates the parent of the shard parent folder ("revprops" or
+ * "revs").  PACKED says whether we want the packed shard's name.
+ *
+ * Allocate the result in RESULT_POOL.
+ */static const char*
+construct_shard_sub_path(svn_fs_t *fs,
+                         svn_revnum_t rev,
+                         svn_boolean_t revprops,
+                         svn_boolean_t packed,
+                         const char *filename,
+                         apr_pool_t *result_pool)
 {
   svn_fs_x__data_t *ffd = fs->fsap_data;
-  assert(svn_fs_x__is_packed_rev(fs, rev));
+  char buffer[SVN_INT64_BUFFER_SIZE + sizeof(PATH_EXT_PACKED_SHARD)];
+
+  /* Select the appropriate parent path constant. */
+  const char *parent = revprops ? PATH_REVPROPS_DIR : PATH_REVS_DIR;
+
+  /* String containing the shard number. */
+  apr_size_t len = svn__i64toa(buffer, rev / ffd->max_files_per_dir);
+
+  /* Append the suffix.  Limit it to the buffer size (should never hit it). */
+  if (packed)
+    strncpy(buffer + len, PATH_EXT_PACKED_SHARD, sizeof(buffer) - len - 1);
 
-  return svn_dirent_join_many(pool, fs->path, PATH_REVS_DIR,
-                              apr_psprintf(pool,
-                                           "%ld" PATH_EXT_PACKED_SHARD,
-                                           rev / ffd->max_files_per_dir),
-                              kind, SVN_VA_NULL);
+  /* This will also work for NULL FILENAME as well. */
+  return svn_dirent_join_many(result_pool, fs->path, parent, buffer,
+                              filename, SVN_VA_NULL);
+}
+
+const char *
+svn_fs_x__path_rev_packed(svn_fs_t *fs,
+                          svn_revnum_t rev,
+                          const char *kind,
+                          apr_pool_t *result_pool)
+{
+  assert(svn_fs_x__is_packed_rev(fs, rev));
+  return construct_shard_sub_path(fs, rev, FALSE, TRUE, kind, result_pool);
 }
 
 const char *
@@ -174,23 +202,27 @@ svn_fs_x__path_rev_shard(svn_fs_t *fs,
 }
 
 const char *
-svn_fs_x__path_rev(svn_fs_t *fs, svn_revnum_t rev, apr_pool_t *pool)
+svn_fs_x__path_rev(svn_fs_t *fs,
+                   svn_revnum_t rev,
+                   apr_pool_t *result_pool)
 {
-  assert(! svn_fs_x__is_packed_rev(fs, rev));
+  svn_fs_x__data_t *ffd = fs->fsap_data;
 
-  return svn_dirent_join(svn_fs_x__path_rev_shard(fs, rev, pool),
-                         apr_psprintf(pool, "%ld", rev),
-                         pool);
+  char buffer[SVN_INT64_BUFFER_SIZE];
+  svn__i64toa(buffer, rev / ffd->max_files_per_dir);
+
+  assert(! svn_fs_x__is_packed_rev(fs, rev));
+  return construct_shard_sub_path(fs, rev, FALSE, FALSE, buffer, result_pool);
 }
 
 const char *
 svn_fs_x__path_rev_absolute(svn_fs_t *fs,
                             svn_revnum_t rev,
-                            apr_pool_t *pool)
+                            apr_pool_t *result_pool)
 {
   return ! svn_fs_x__is_packed_rev(fs, rev)
-       ? svn_fs_x__path_rev(fs, rev, pool)
-       : svn_fs_x__path_rev_packed(fs, rev, PATH_PACKED, pool);
+       ? svn_fs_x__path_rev(fs, rev, result_pool)
+       : svn_fs_x__path_rev_packed(fs, rev, PATH_PACKED, result_pool);
 }
 
 const char *
@@ -210,22 +242,23 @@ svn_fs_x__path_revprops_shard(svn_fs_t *
 const char *
 svn_fs_x__path_revprops_pack_shard(svn_fs_t *fs,
                                    svn_revnum_t rev,
-                                   apr_pool_t *pool)
+                                   apr_pool_t *result_pool)
 {
-  svn_fs_x__data_t *ffd = fs->fsap_data;
-
-  return svn_dirent_join_many(pool, fs->path, PATH_REVPROPS_DIR,
-                              apr_psprintf(pool, "%ld" PATH_EXT_PACKED_SHARD,
-                                           rev / ffd->max_files_per_dir),
-                              SVN_VA_NULL);
+  return construct_shard_sub_path(fs, rev, TRUE, TRUE, NULL, result_pool);
 }
 
 const char *
-svn_fs_x__path_revprops(svn_fs_t *fs, svn_revnum_t rev, apr_pool_t *pool)
+svn_fs_x__path_revprops(svn_fs_t *fs,
+                        svn_revnum_t rev,
+                        apr_pool_t *result_pool)
 {
-  return svn_dirent_join(svn_fs_x__path_revprops_shard(fs, rev, pool),
-                         apr_psprintf(pool, "%ld", rev),
-                         pool);
+  svn_fs_x__data_t *ffd = fs->fsap_data;
+
+  char buffer[SVN_INT64_BUFFER_SIZE];
+  svn__i64toa(buffer, rev / ffd->max_files_per_dir);
+
+  assert(! svn_fs_x__is_packed_rev(fs, rev));
+  return construct_shard_sub_path(fs, rev, TRUE, FALSE, buffer, result_pool);
 }
 
 const char *

Modified: subversion/trunk/subversion/libsvn_fs_x/util.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_x/util.h?rev=1652469&r1=1652468&r2=1652469&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_x/util.h (original)
+++ subversion/trunk/subversion/libsvn_fs_x/util.h Fri Jan 16 17:32:55 2015
@@ -146,13 +146,13 @@ svn_fs_x__path_revprop_generation(svn_fs
 
 /* Return the path of the pack-related file that for revision REV in FS.
  * KIND specifies the file name base, e.g. "pack".
- * The result will be allocated in POOL.
+ * The result will be allocated in RESULT_POOL.
  */
 const char *
 svn_fs_x__path_rev_packed(svn_fs_t *fs,
                           svn_revnum_t rev,
                           const char *kind,
-                          apr_pool_t *pool);
+                          apr_pool_t *result_pool);
 
 /* Return the full path of the rev shard directory that will contain
  * revision REV in FS.  Allocate the result in RESULT_POOL.
@@ -163,15 +163,15 @@ svn_fs_x__path_rev_shard(svn_fs_t *fs,
                          apr_pool_t *result_pool);
 
 /* Return the full path of the non-packed rev file containing revision REV
- * in FS.  Allocate the result in POOL.
+ * in FS.  Allocate the result in RESULT_POOL.
  */
 const char *
 svn_fs_x__path_rev(svn_fs_t *fs,
                    svn_revnum_t rev,
-                   apr_pool_t *pool);
+                   apr_pool_t *result_pool);
 
 /* Set *PATH to the path of REV in FS, whether in a pack file or not.
-   Allocate *PATH in POOL.
+   Allocate *PATH in RESULT_POOL.
 
    Note: If the caller does not have the write lock on FS, then the path is
    not guaranteed to be correct or to remain correct after the function
@@ -181,7 +181,7 @@ svn_fs_x__path_rev(svn_fs_t *fs,
 const char *
 svn_fs_x__path_rev_absolute(svn_fs_t *fs,
                             svn_revnum_t rev,
-                            apr_pool_t *pool);
+                            apr_pool_t *result_pool);
 
 /* Return the full path of the revision properties shard directory that
  * will contain the properties of revision REV in FS.
@@ -194,20 +194,21 @@ svn_fs_x__path_revprops_shard(svn_fs_t *
 
 /* Return the full path of the revision properties pack shard directory
  * that will contain the packed properties of revision REV in FS.
- * Allocate the result in POOL.
+ * Allocate the result in RESULT_POOL.
  */
 const char *
 svn_fs_x__path_revprops_pack_shard(svn_fs_t *fs,
                                    svn_revnum_t rev,
-                                   apr_pool_t *pool);
+                                   apr_pool_t *result_pool);
 
 /* Return the full path of the non-packed revision properties file that
- * contains the props for revision REV in FS.  Allocate the result in POOL.
+ * contains the props for revision REV in FS.
+ * Allocate the result in RESULT_POOL.
  */
 const char *
 svn_fs_x__path_revprops(svn_fs_t *fs,
                         svn_revnum_t rev,
-                        apr_pool_t *pool);
+                        apr_pool_t *result_pool);
 
 /* Convert the TXN_ID into a string, allocated from RESULT_POOL.
  */