Index: subversion/include/svn_config.h
===================================================================
--- subversion/include/svn_config.h	(revision 5740)
+++ subversion/include/svn_config.h	(working copy)
@@ -83,8 +83,8 @@
 #define SVN_CONFIG_OPTION_GLOBAL_IGNORES            "global-ignores"
 #define SVN_CONFIG_OPTION_LOG_ENCODING              "log-encoding"
 #define SVN_CONFIG_OPTION_TEMPLATE_ROOT             "template-root"
+#define SVN_CONFIG_OPTION_COMPRESS_TEXT_BASE        "compress-text-base" 
 
-
 /** Read configuration information from the standard sources and merge
  * it into the hash @a *cfg_hash.  That is, first read any system-wide
  * configurations (from a file or from the registry), then merge in
Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h	(revision 5740)
+++ subversion/include/svn_io.h	(working copy)
@@ -372,6 +372,22 @@
 svn_stream_t *svn_stream_compressed (svn_stream_t *stream, 
                                      apr_pool_t *pool);
 
+/** Mark the @c apr_file_t @a file as being a compressed file.
+ *
+ * Mark @a file as compressed. Any subsequent calls to @c
+ * svn_stream_from_aprfile with this @c apr_file_t will automatically
+ * wrap it around a compressed stream.
+ */
+svn_error_t *svn_stream_mark_apr_file_compressed (apr_file_t *file, 
+                                                  apr_pool_t *pool);
+
+/** Is the @c apr_file_t @a file marked as compressed?
+ *
+ */
+svn_error_t *svn_stream_is_apr_file_marked_compressed (apr_file_t 
+                                                       *file, svn_boolean_t 
+                                                       *compressed);
+
 /** Read from a generic stream. */
 svn_error_t *svn_stream_read (svn_stream_t *stream, char *buffer,
                               apr_size_t *len);
@@ -431,6 +447,29 @@
                                          apr_file_t *file,
                                          apr_pool_t *pool);
 
+/** The filename extension for compressed files.  */
+#define SVN_IO_COMPRESS_SUFFIX ".gz"
+
+/** Compress file @a file, a utf8-encoded path.
+ * 
+ * Compress @a file to a new file named @a file + @c
+ * SVN_IO_COMPRESS_SUFFIX. The old file is removed once the compression
+ * is finished.
+ */
+svn_error_t *svn_io_file_compress (const char *file, apr_pool_t *pool);
+
+/** Decompress file @a file, a utf8-encoded path.
+ *
+ * Decompress @a to a new file with the @c SVN_IO_COMPRESS_SUFFIX
+ * striped off the end of the filename. @a file is removed once
+ * compression is finished.
+ */
+svn_error_t *svn_io_file_decompress (const char *file, apr_pool_t *pool);
+
+svn_error_t *svn_io_file_decompress_to_file (const char *file, 
+                                             const char *dst_file,
+                                             apr_pool_t *pool);
+
 /** Remove file @a path, a utf8-encoded path.  This wraps @c apr_file_remove(), 
  * converting any error to a Subversion error.
  */
Index: subversion/include/svn_wc.h
===================================================================
--- subversion/include/svn_wc.h	(revision 5740)
+++ subversion/include/svn_wc.h	(working copy)
@@ -1333,6 +1333,8 @@
  * If @a diff3_cmd is non-null, then use it as the diff3 command for
  * any merging; otherwise, use the built-in merge code.
  *
+ * If @a compress_text_base is true, compress all the new text base files. 
+ *
  * @a target_revision is the repository revision that results from this set
  * of changes.
  */
@@ -1345,6 +1347,7 @@
                                        svn_cancel_func_t cancel_func,
                                        void *cancel_baton,
                                        const char *diff3_cmd,
+                                       svn_boolean_t compress_text_base,
                                        const svn_delta_editor_t **editor,
                                        void **edit_baton,
                                        svn_wc_traversal_info_t *ti,
@@ -1380,6 +1383,7 @@
                                          void *notify_baton,
                                          svn_cancel_func_t cancel_func,
                                          void *cancel_baton,
+                                         svn_boolean_t compress_text_base,
                                          const svn_delta_editor_t **editor,
                                          void **edit_baton,
                                          svn_wc_traversal_info_t *ti,
@@ -1427,6 +1431,7 @@
                                        svn_cancel_func_t cancel_func,
                                        void *cancel_baton,
                                        const char *diff3_cmd,
+                                       svn_boolean_t compress_text_base,
                                        const svn_delta_editor_t **editor,
                                        void **edit_baton,
                                        svn_wc_traversal_info_t *ti,
@@ -1496,6 +1501,7 @@
                                   svn_boolean_t is_full_proplist,
                                   const char *new_URL,
                                   const char *diff3_cmd,
+                                  svn_boolean_t compress_text_base,
                                   apr_pool_t *pool);
 
 
Index: subversion/libsvn_wc/diff.c
===================================================================
--- subversion/libsvn_wc/diff.c	(revision 5740)
+++ subversion/libsvn_wc/diff.c	(working copy)
@@ -471,7 +471,7 @@
     schedule = svn_wc_schedule_normal;
 
   /* Prep these two paths early. */
-  pristine_copy = svn_wc__text_base_path (path, FALSE, pool);
+  SVN_ERR (svn_wc__uncompressed_text_base_path (path, &pristine_copy, pool));
   empty_file = svn_wc__empty_file_path (path, pool);
 
   switch (schedule)
@@ -544,7 +544,8 @@
           const char *translated;
           svn_error_t *err;
 
-          pristine_copy = svn_wc__text_base_path (path, FALSE, pool);   
+          SVN_ERR (svn_wc__uncompressed_text_base_path (path, &pristine_copy, 
+                                                        pool));
 
           /* Note that this might be the _second_ time we translate
              the file, as svn_wc_text_modified_p() might have used a
@@ -796,8 +797,9 @@
       if (eb->reverse_order)
         {
           /* Whenever showing a deletion, we show the text-base vanishing. */
-          const char *textbase = svn_wc__text_base_path (full_path,
-                                                         FALSE, pool);
+          const char *textbase;
+          SVN_ERR (svn_wc__uncompressed_text_base_path (full_path, &textbase, 
+                                                        pool));
 
           SVN_ERR (pb->edit_baton->callbacks->file_deleted
                    (NULL, full_path,
@@ -1077,7 +1079,7 @@
 
   {
     const char *tmp_path;
-
+    
     apr_file_name_get (&tmp_path, b->temp_file);
     svn_txdelta_apply (svn_stream_from_aprfile (b->original_file, b->pool),
                        svn_stream_from_aprfile (b->temp_file, b->pool),
@@ -1157,9 +1159,11 @@
              file is deleted. */
           svn_error_t *err1, *err2 = SVN_NO_ERROR;
           const char *localfile;
+          svn_boolean_t ignored;
 
           if (eb->use_text_base)
-            localfile = svn_wc__text_base_path (b->path, FALSE, b->pool);
+            SVN_ERR (svn_wc__real_text_base_path (b->path, FALSE, &localfile, 
+                                                  &ignored, b->pool));
           else
             /* a detranslated version of the working file */
             SVN_ERR (svn_wc_translated_file (&localfile, b->path, adm_access,
Index: subversion/libsvn_wc/copy.c
===================================================================
--- subversion/libsvn_wc/copy.c	(revision 5740)
+++ subversion/libsvn_wc/copy.c	(working copy)
@@ -206,8 +206,15 @@
     const char *src_wprop, *src_bprop, *dst_wprop, *dst_bprop;
 
     /* Discover the paths to the two text-base files */
-    const char *src_txtb = svn_wc__text_base_path (src_path, FALSE, pool);
-    const char *dst_txtb = svn_wc__text_base_path (dst_path, FALSE, pool);
+    const char *src_txtb, *dst_txtb;
+	svn_boolean_t src_txtb_compressed;
+	
+	SVN_ERR (svn_wc__real_text_base_path (src_path, FALSE, &src_txtb, 
+										  &src_txtb_compressed, pool));
+    if (src_txtb_compressed)
+	  dst_txtb = svn_wc__text_base_compressed_path (dst_path, FALSE, pool);
+	else
+	  dst_txtb = svn_wc__text_base_path (dst_path, FALSE, pool);
 
     /* Discover the paths to the four prop files */
     SVN_ERR (svn_wc__prop_path (&src_wprop, src_path, src_access, FALSE, pool));
Index: subversion/libsvn_wc/wc.h
===================================================================
--- subversion/libsvn_wc/wc.h	(revision 5740)
+++ subversion/libsvn_wc/wc.h	(working copy)
@@ -25,6 +25,7 @@
 
 #include "svn_types.h"
 #include "svn_error.h"
+#include "svn_io.h"
 #include "svn_wc.h"
 
 #ifdef __cplusplus
@@ -37,6 +38,7 @@
 #define SVN_WC__TEXT_REJ_EXT  ".rej"
 #define SVN_WC__PROP_REJ_EXT  ".prej"
 #define SVN_WC__BASE_EXT      ".svn-base" /* for text and prop bases */
+#define SVN_WC__BASE_EXT_GZ   (SVN_WC__BASE_EXT SVN_IO_COMPRESS_SUFFIX)
 #define SVN_WC__WORK_EXT      ".svn-work" /* for working propfiles */
 
 
Index: subversion/libsvn_wc/adm_crawler.c
===================================================================
--- subversion/libsvn_wc/adm_crawler.c	(revision 5740)
+++ subversion/libsvn_wc/adm_crawler.c	(working copy)
@@ -47,39 +47,34 @@
 /* Helper for report_revisions().
    
    Perform an atomic restoration of the file FILE_PATH; that is, copy
-   the file's text-base to the administrative tmp area, and then move
-   that file to FILE_PATH with possible translations/expansions.  */
+   the file's text-base to FILE_PATH with possible
+   translations/expansions.  */
 static svn_error_t *
 restore_file (const char *file_path,
               svn_wc_adm_access_t *adm_access,
               apr_pool_t *pool)
 {
-  const char *text_base_path, *tmp_text_base_path;
+  const char *text_base_path;
   svn_subst_keywords_t *keywords;
   const char *eol;
 
-  text_base_path = svn_wc__text_base_path (file_path, FALSE, pool);
-  tmp_text_base_path = svn_wc__text_base_path (file_path, TRUE, pool);
+  SVN_ERR (svn_wc__uncompressed_text_base_path (file_path, &text_base_path, 
+                                                pool));
 
-  SVN_ERR (svn_io_copy_file (text_base_path, tmp_text_base_path,
-                             FALSE, pool));
-
   SVN_ERR (svn_wc__get_eol_style (NULL, &eol, file_path, adm_access, pool));
   SVN_ERR (svn_wc__get_keywords (&keywords,
                                  file_path, adm_access, NULL, pool));
   
-  /* When copying the tmp-text-base out to the working copy, make
+  /* When copying the text-base out to the working copy, make
      sure to do any eol translations or keyword substitutions,
      as dictated by the property values.  If these properties
      are turned off, then this is just a normal copy. */
-  SVN_ERR (svn_subst_copy_and_translate (tmp_text_base_path,
+  SVN_ERR (svn_subst_copy_and_translate (text_base_path,
                                          file_path,
                                          eol, FALSE, /* don't repair */
                                          keywords,
                                          TRUE, /* expand keywords */
                                          pool));
-  
-  SVN_ERR (svn_io_remove_file (tmp_text_base_path, pool));
 
   /* If necessary, tweak the new working file's executable bit. */
   SVN_ERR (svn_wc__maybe_set_executable (NULL, file_path, adm_access, pool));
@@ -546,9 +541,10 @@
       /* For backwards compatibility, no checksum means assume a match. */
       if (ent->checksum)
         {
-          const char *tb = svn_wc__text_base_path (path, FALSE, pool);
+          const char *tb;
           unsigned char tb_digest[MD5_DIGESTSIZE];
 
+          SVN_ERR (svn_wc__uncompressed_text_base_path (path, &tb, pool));
           SVN_ERR (svn_io_file_checksum (tb_digest, tb, pool));
           base_digest_hex = svn_md5_digest_to_cstring (tb_digest, pool);
 
Index: subversion/libsvn_wc/log.c
===================================================================
--- subversion/libsvn_wc/log.c	(revision 5740)
+++ subversion/libsvn_wc/log.c	(working copy)
@@ -496,9 +496,30 @@
   return SVN_NO_ERROR;
 }
 
+/* Compress file */
+static svn_error_t *
+log_do_compress (struct log_runner *loggy, const char *name)
+{
+  const char *full_path
+    = svn_path_join (svn_wc_adm_access_path (loggy->adm_access),
+                     name, loggy->pool);
+  SVN_ERR (svn_io_file_compress (full_path, loggy->pool));
+  
+  return SVN_NO_ERROR;
+}
 
+/* Decompress file */
+static svn_error_t *
+log_do_decompress (struct log_runner *loggy, const char *name)
+{
+  const char *full_path 
+    = svn_path_join (svn_wc_adm_access_path (loggy->adm_access),
+                     name, loggy->pool);
+  SVN_ERR (svn_io_file_decompress (full_path, loggy->pool));
+  
+  return SVN_NO_ERROR;
+}
 
-
 static svn_error_t *
 log_do_modify_entry (struct log_runner *loggy,
                      const char *name,
@@ -1200,6 +1221,12 @@
   else if (strcmp (eltname, SVN_WC__LOG_RM) == 0) {
     err = log_do_rm (loggy, name);
   }
+  else if (strcmp (eltname, SVN_WC__LOG_COMPRESS) == 0) {
+    err = log_do_compress (loggy, name);
+  }
+  else if (strcmp (eltname, SVN_WC__LOG_DECOMPRESS) == 0) {
+    err = log_do_decompress (loggy, name);
+  }
   else if (strcmp (eltname, SVN_WC__LOG_MERGE) == 0) {
     err = log_do_merge (loggy, name, atts);
   }
Index: subversion/libsvn_wc/adm_ops.c
===================================================================
--- subversion/libsvn_wc/adm_ops.c	(revision 5740)
+++ subversion/libsvn_wc/adm_ops.c	(working copy)
@@ -236,7 +236,8 @@
       SVN_ERR (svn_io_check_path (latest_base, &kind, pool));
       if (kind == svn_node_none)
         {
-          latest_base = svn_wc__text_base_path (path, FALSE, pool);
+          SVN_ERR (svn_wc__uncompressed_text_base_path (path, &latest_base, 
+                                                        pool));
           SVN_ERR (svn_io_check_path (latest_base, &kind, pool));
         }
 
@@ -1249,7 +1250,8 @@
              file. */
           svn_subst_keywords_t *keywords;
           const char *eol;
-          base_thing = svn_wc__text_base_path (fullpath, 0, pool);
+          SVN_ERR (svn_wc__uncompressed_text_base_path (fullpath, &base_thing, 
+                                                        pool));
 
           SVN_ERR (svn_wc__get_eol_style (NULL, &eol, fullpath, adm_access,
                                           pool));
@@ -1648,7 +1650,8 @@
         const char *svn_thang;
 
         /* Text base. */
-        svn_thang = svn_wc__text_base_path (full_path, 0, subpool);
+        SVN_ERR (svn_wc__real_text_base_path (full_path, 0, &svn_thang, 
+                                              NULL, subpool));
         SVN_ERR (remove_file_if_present (svn_thang, subpool));
 
         /* Working prop file. */
Index: subversion/libsvn_wc/adm_files.c
===================================================================
--- subversion/libsvn_wc/adm_files.c	(revision 5740)
+++ subversion/libsvn_wc/adm_files.c	(working copy)
@@ -29,6 +29,7 @@
 #include <apr_file_io.h>
 #include <apr_time.h>
 #include <apr_strings.h>
+#include "svn_pools.h"
 #include "svn_types.h"
 #include "svn_string.h"
 #include "svn_error.h"
@@ -238,7 +239,6 @@
   return SVN_NO_ERROR;
 }
 
-
 
 /*** Syncing files in the adm area. ***/
 
@@ -305,9 +305,125 @@
                                SVN_WC__ADM_TEXT_BASE,
                                base_name,
                                NULL);
+  
 }
 
+const char *
+svn_wc__text_base_compressed_path(const char *path,
+                                  svn_boolean_t tmp,
+                                  apr_pool_t *pool)
+{
+  const char *newpath, *base_name;
 
+  svn_path_split (path, &newpath, &base_name, pool);
+  return extend_with_adm_name (newpath,
+                               SVN_WC__BASE_EXT_GZ,
+                               tmp,
+                               pool,
+                               SVN_WC__ADM_TEXT_BASE,
+                               base_name,
+                               NULL);
+}
+
+struct tmp_cleaner_t {
+  const char *tmp_file;
+  apr_pool_t *pool;
+};
+
+
+static apr_status_t
+cleanup_uncompressed_tmp (void *arg)
+{
+  svn_error_t *err = SVN_NO_ERROR;
+  apr_status_t status;
+  struct tmp_cleaner_t *cleaner = arg;
+
+  /*err = svn_io_remove_file (cleaner->tmp_file, cleaner->pool);*/
+  status = err != SVN_NO_ERROR ? err->apr_err : APR_SUCCESS;
+  svn_error_clear (err);
+  
+  if (APR_STATUS_IS_SUCCESS (status) || APR_STATUS_IS_ENOENT (status))
+    status = APR_SUCCESS;
+  
+  return status;
+}
+
+svn_error_t *
+svn_wc__uncompressed_text_base_path(const char *path, 
+                                    const char **newpath,
+                                    apr_pool_t *pool)
+{
+  svn_boolean_t compressed;
+  char *compressed_path;
+  const char *tmp_path, *npath;
+  struct tmp_cleaner_t *cleaner;
+  svn_node_kind_t kind;
+  
+  SVN_ERR (svn_wc__real_text_base_path (path, FALSE, &npath, &compressed, 
+                                        pool));
+  
+  if (! compressed)
+    {
+      *newpath = npath;
+    }
+  else
+    {
+      compressed_path = 
+        apr_pstrcat (pool, svn_wc__text_base_compressed_path (path, TRUE, 
+                                                              pool), 
+                     ".tmp", NULL);
+      tmp_path = apr_pstrcat (pool, 
+                              svn_wc__text_base_path (path, TRUE, pool),
+                              ".uncomp", NULL);
+      SVN_ERR (svn_io_check_path (tmp_path, &kind, pool));
+      
+      if (kind == svn_node_none) 
+        {
+          cleaner = apr_palloc (pool, sizeof (struct tmp_cleaner_t));
+          cleaner->tmp_file = tmp_path;
+          cleaner->pool = pool;
+          apr_pool_cleanup_register (pool, cleaner, cleanup_uncompressed_tmp, 
+                                     NULL);
+      
+          SVN_ERR (svn_io_copy_file (npath, compressed_path, TRUE, pool));
+          SVN_ERR (svn_io_file_decompress_to_file (compressed_path, 
+                                                   tmp_path, pool));
+        }
+      
+      *newpath = tmp_path;
+    }
+  
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_wc__real_text_base_path(const char *path,
+                            svn_boolean_t tmp,
+                            const char **newpath,
+                            svn_boolean_t *compressed,
+                            apr_pool_t *pool)
+{
+  const char *compressed_path;
+  svn_node_kind_t kind;
+  
+  compressed_path = svn_wc__text_base_compressed_path (path, tmp, pool);
+  SVN_ERR (svn_io_check_path (compressed_path, &kind, pool));
+  if (kind == svn_node_none)
+    {
+      *newpath = svn_wc__text_base_path (path, tmp, pool);
+      if (compressed)
+        *compressed = FALSE;
+    }
+  else
+    {
+      *newpath = compressed_path;
+      if (compressed)
+        *compressed = TRUE;
+    }
+  return SVN_NO_ERROR;
+}
+
+
 static svn_error_t *
 prop_path_internal (const char **prop_path,
                     const char *path,
@@ -431,8 +547,12 @@
                ...)
 {
   svn_error_t *err = SVN_NO_ERROR;
+  svn_boolean_t compressed = FALSE;
   va_list ap;
 
+  if (extension)
+    compressed = apr_strnatcmp(extension, SVN_WC__BASE_EXT_GZ) == 0;
+  
   /* If we're writing, always do it to a tmp file. */
   if (flags & APR_WRITE)
     {
@@ -474,6 +594,12 @@
          handle. */
       *handle = NULL;
     }
+  else if (compressed)
+    {
+      /* If compressed, mark the handle as compressed so the
+         compressed stream wrapper will work. */
+      err = svn_stream_mark_apr_file_compressed(*handle, pool);
+    }
 
   return err;
 }
@@ -609,9 +735,15 @@
                         apr_int32_t flags,
                         apr_pool_t *pool)
 {
-  const char *parent_path, *base_name;
+  const char *parent_path, *base_name, *extension;
+  svn_boolean_t compressed;
+  
+  SVN_ERR (svn_wc__real_text_base_path (path, FALSE, &parent_path, &compressed,
+                                        pool));
+  extension = compressed ? SVN_WC__BASE_EXT_GZ : SVN_WC__BASE_EXT;
+  
   svn_path_split (path, &parent_path, &base_name, pool);
-  return open_adm_file (handle, parent_path, SVN_WC__BASE_EXT, APR_OS_DEFAULT,
+  return open_adm_file (handle, parent_path, extension, APR_OS_DEFAULT,
                         flags, pool, SVN_WC__ADM_TEXT_BASE, base_name, NULL);
 }
 
@@ -622,9 +754,14 @@
                          int write,
                          apr_pool_t *pool)
 {
-  const char *parent_path, *base_name;
+  const char *parent_path, *base_name, *extension;
+  svn_boolean_t compressed;
+  
+  SVN_ERR (svn_stream_is_apr_file_marked_compressed (fp, &compressed));
+  extension = compressed ? SVN_WC__BASE_EXT_GZ : SVN_WC__BASE_EXT;
+
   svn_path_split (path, &parent_path, &base_name, pool);
-  return close_adm_file (fp, parent_path, SVN_WC__BASE_EXT, write, pool,
+  return close_adm_file (fp, parent_path, extension, write, pool,
                          SVN_WC__ADM_TEXT_BASE, base_name, NULL);
 }
 
Index: subversion/libsvn_wc/log.h
===================================================================
--- subversion/libsvn_wc/log.h	(revision 5740)
+++ subversion/libsvn_wc/log.h	(working copy)
@@ -77,6 +77,12 @@
    properties of NAME. */
 #define SVN_WC__LOG_CP_AND_DETRANSLATE    "cp-and-detranslate"
 
+/* Compress file SVN_WC__LOG_ATTR_NAME. */
+#define SVN_WC__LOG_COMPRESS            "compress"
+
+/* Decompress file SVN_WC__LOG_ATTR_NAME. */
+#define SVN_WC__LOG_DECOMPRESS          "decompress"
+
 /* Remove file SVN_WC__LOG_ATTR_NAME. */
 #define SVN_WC__LOG_RM                  "rm"
 
Index: subversion/libsvn_wc/update_editor.c
===================================================================
--- subversion/libsvn_wc/update_editor.c	(revision 5740)
+++ subversion/libsvn_wc/update_editor.c	(working copy)
@@ -80,6 +80,9 @@
   /* Non-null if this is a 'switch' operation. */
   const char *switch_url;
 
+  /* Should the text-base be compressed? */
+  svn_boolean_t compress_text_base;
+  
   /* External diff3 to use for merges (can be null, in which case
      internal merge code is used). */
   const char *diff3_cmd;
@@ -1210,7 +1213,8 @@
             const char *hex_digest;
             const char *tb;
 
-            tb = svn_wc__text_base_path (fb->path, FALSE, pool);
+            SVN_ERR (svn_wc__uncompressed_text_base_path (fb->path, &tb, 
+                                                          pool));
             SVN_ERR (svn_io_file_checksum (digest, tb, pool));
             hex_digest = svn_md5_digest_to_cstring (digest, pool);
             
@@ -1348,6 +1352,7 @@
                      svn_boolean_t is_full_proplist,
                      const char *new_URL,
                      const char *diff3_cmd,
+                     svn_boolean_t compress_text_base,
                      apr_pool_t *pool)
 {
   apr_file_t *log_fp = NULL;
@@ -1355,7 +1360,7 @@
   char *revision_str = NULL;
   const char *parent_dir, *base_name;
   svn_stringbuf_t *log_accum;
-  svn_boolean_t is_locally_modified;
+  svn_boolean_t is_locally_modified, is_compressed;
   svn_boolean_t magic_props_changed = FALSE;
   apr_array_header_t *regular_props = NULL, *wc_props = NULL,
     *entry_props = NULL;
@@ -1363,7 +1368,8 @@
   /* The code flow does not depend upon these being set to NULL, but
      it removes a gcc 3.1 `might be used uninitialized in this
      function' warning. */
-  const char *txtb = NULL, *tmp_txtb = NULL;
+  const char *txtb = NULL, *tmp_txtb = NULL, *real_txtb = NULL,
+    *compressed_txtb = NULL;
 
   /* Start by splitting FILE_PATH. */
   svn_path_split (file_path, &parent_dir, &base_name, pool);
@@ -1522,6 +1528,10 @@
     {
       txtb     = svn_wc__text_base_path (base_name, FALSE, pool);
       tmp_txtb = svn_wc__text_base_path (base_name, TRUE, pool);
+      compressed_txtb = svn_wc__text_base_compressed_path (base_name, FALSE, 
+                                                           pool);
+      SVN_ERR (svn_wc__real_text_base_path (base_name, FALSE, &real_txtb,
+                                            &is_compressed, pool));
     }
   else if (magic_props_changed) /* no new text base, but... */
     {
@@ -1643,6 +1653,17 @@
               const char *oldrev_str, *newrev_str;
               const svn_wc_entry_t *e;
               
+              /* If our text-base is compressed, we need to decompress
+                 it before we try to do the merge */
+              if (is_compressed)
+                svn_xml_make_open_tag (&log_accum,
+                                       pool,
+                                       svn_xml_self_closing,
+                                       SVN_WC__LOG_DECOMPRESS,
+                                       SVN_WC__LOG_ATTR_NAME,
+                                       compressed_txtb,
+                                       NULL);
+              
               /* Create strings representing the revisions of the
                  old and new text-bases. */
               SVN_ERR (svn_wc_entry (&e, file_path, adm_access, FALSE, pool));
@@ -1676,6 +1697,16 @@
                  marked "Conflicted" and will track either 2 or 3 new
                  temporary fulltext files that resulted. */
               
+              /* If our text-base was compressed, remove the
+                 decompressed file */
+              if (is_compressed)
+                svn_xml_make_open_tag (&log_accum,
+                                       pool,
+                                       svn_xml_self_closing,
+                                       SVN_WC__LOG_RM,
+                                       SVN_WC__LOG_ATTR_NAME, txtb,
+                                       NULL);
+              
             } /* end: working file exists and has mods */
         } /* end: working file has mods */
     }  /* end:  "textual" merging process */
@@ -1723,7 +1754,7 @@
     }
 
   if (new_text_path)
-    {
+    { 
       /* Write out log commands to set up the new text base and its
          checksum. */
 
@@ -1737,12 +1768,21 @@
                              txtb,
                              NULL);
       
+      if (compress_text_base)
+        svn_xml_make_open_tag (&log_accum,
+                               pool,
+                               svn_xml_self_closing,
+                               SVN_WC__LOG_COMPRESS,
+                               SVN_WC__LOG_ATTR_NAME,
+                               txtb,
+                               NULL);
+
       svn_xml_make_open_tag (&log_accum,
                              pool,
                              svn_xml_self_closing,
                              SVN_WC__LOG_READONLY,
                              SVN_WC__LOG_ATTR_NAME,
-                             txtb,
+                             compress_text_base ? compressed_txtb : txtb,
                              NULL);
 
       {
@@ -1870,6 +1910,7 @@
                                 FALSE, /* -not- a full proplist */
                                 fb->new_URL,
                                 fb->edit_baton->diff3_cmd,
+                                fb->edit_baton->compress_text_base,
                                 pool));
 
   /* We have one less referrer to the directory's bump information. */
@@ -1972,6 +2013,7 @@
              svn_cancel_func_t cancel_func,
              void *cancel_baton,
              const char *diff3_cmd,
+             svn_boolean_t compress_text_base,
              const svn_delta_editor_t **editor,
              void **edit_baton,
              svn_wc_traversal_info_t *traversal_info,
@@ -1998,6 +2040,7 @@
   eb->notify_func     = notify_func;
   eb->notify_baton    = notify_baton;
   eb->traversal_info  = traversal_info;
+  eb->compress_text_base = compress_text_base;
   eb->diff3_cmd       = diff3_cmd;
 
   /* Construct an editor. */
@@ -2037,6 +2080,7 @@
                           svn_cancel_func_t cancel_func,
                           void *cancel_baton,
                           const char *diff3_cmd,
+                          svn_boolean_t compress_text_base,
                           const svn_delta_editor_t **editor,
                           void **edit_baton,
                           svn_wc_traversal_info_t *traversal_info,
@@ -2046,7 +2090,7 @@
                       target, target_revision, 
                       FALSE, NULL, NULL,
                       recurse, notify_func, notify_baton,
-                      cancel_func, cancel_baton, diff3_cmd,
+                      cancel_func, cancel_baton, diff3_cmd, compress_text_base,
                       editor, edit_baton, traversal_info, pool);
 }
 
@@ -2060,6 +2104,7 @@
                             void *notify_baton,
                             svn_cancel_func_t cancel_func,
                             void *cancel_baton,
+                            svn_boolean_t compress_text_base,
                             const svn_delta_editor_t **editor,
                             void **edit_baton,
                             svn_wc_traversal_info_t *traversal_info,
@@ -2068,7 +2113,7 @@
   return make_editor (NULL, dest, NULL, target_revision, 
                       TRUE, ancestor_url, NULL,
                       recurse, notify_func, notify_baton,
-                      cancel_func, cancel_baton, NULL,
+                      cancel_func, cancel_baton, NULL, compress_text_base,
                       editor, edit_baton,
                       traversal_info, pool);
 }
@@ -2085,6 +2130,7 @@
                           svn_cancel_func_t cancel_func,
                           void *cancel_baton,
                           const char *diff3_cmd,
+                          svn_boolean_t compress_text_base,
                           const svn_delta_editor_t **editor,
                           void **edit_baton,
                           svn_wc_traversal_info_t *traversal_info,
@@ -2096,8 +2142,8 @@
                       target, target_revision,
                       FALSE, NULL, switch_url,
                       recurse, notify_func, notify_baton,
-                      cancel_func, cancel_baton, diff3_cmd,
-                      editor, edit_baton,
+                      cancel_func, cancel_baton, diff3_cmd, 
+                      compress_text_base, editor, edit_baton,
                       traversal_info, pool);
 }
 
Index: subversion/libsvn_wc/adm_files.h
===================================================================
--- subversion/libsvn_wc/adm_files.h	(revision 5740)
+++ subversion/libsvn_wc/adm_files.h	(working copy)
@@ -72,7 +72,21 @@
                                     svn_boolean_t tmp,
                                     apr_pool_t *pool);
 
+const char *svn_wc__text_base_compressed_path(const char *path,
+                                              svn_boolean_t tmp,
+                                              apr_pool_t *pool);
 
+svn_error_t *svn_wc__uncompressed_text_base_path(const char *path, 
+                                                 const char **newpath,
+                                                 apr_pool_t *pool);
+
+svn_error_t *svn_wc__real_text_base_path(const char *path,
+                                         svn_boolean_t tmp,
+                                         const char **newpath,
+                                         svn_boolean_t *compressed,
+                                         apr_pool_t *pool);
+
+
 /* Return a path to the 'wcprop' file for PATH, possibly in TMP area.
    ADM_ACCESS is an access baton set that contains PATH. */
 svn_error_t *svn_wc__wcprop_path (const char **wcprop_path,
Index: subversion/libsvn_wc/questions.c
===================================================================
--- subversion/libsvn_wc/questions.c	(revision 5740)
+++ subversion/libsvn_wc/questions.c	(working copy)
@@ -349,7 +349,8 @@
   /* If there's no text-base file, we have to assume the working file
      is modified.  For example, a file scheduled for addition but not
      yet committed. */
-  textbase_filename = svn_wc__text_base_path (filename, 0, subpool);
+  SVN_ERR (svn_wc__uncompressed_text_base_path (filename, 
+                                                &textbase_filename, subpool));
   SVN_ERR (svn_io_check_path (textbase_filename, &kind, subpool));
   if (kind != svn_node_file)
     {
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c	(revision 5740)
+++ subversion/libsvn_subr/io.c	(working copy)
@@ -462,7 +462,98 @@
 #endif
 }
 
+
+/*** Compress and decompress file ***/
 
+static svn_error_t *
+compress_or_decompress(const char *src_file, const char *dst_file, 
+                       svn_boolean_t compress, apr_pool_t *pool)
+{
+  apr_file_t *src, *dst;
+  svn_stream_t *in_stream, *out_stream;
+  char *buf;
+  apr_size_t read, len;
+
+  SVN_ERR (svn_io_file_open (&src, src_file, APR_READ,
+                             APR_OS_DEFAULT, pool));
+  SVN_ERR (svn_io_file_open (&dst, dst_file, APR_WRITE | APR_CREATE
+                             | APR_TRUNCATE, APR_OS_DEFAULT, pool));
+  
+  in_stream = svn_stream_from_aprfile (src, pool);
+  out_stream = svn_stream_from_aprfile (dst, pool);
+  if (compress)
+    out_stream = svn_stream_compressed (out_stream, pool);
+  else 
+    in_stream = svn_stream_compressed (in_stream, pool);
+  
+  buf = apr_palloc (pool, SVN_STREAM_CHUNK_SIZE);
+  
+  do {
+    len = SVN_STREAM_CHUNK_SIZE;
+    SVN_ERR (svn_stream_read (in_stream, buf, &len));
+    read = len;
+    SVN_ERR (svn_stream_write (out_stream, buf, &len));
+  } while (read >= SVN_STREAM_CHUNK_SIZE);
+  
+  SVN_ERR (svn_stream_close (in_stream));
+  SVN_ERR (svn_stream_close (out_stream));
+  apr_file_close (src);
+  apr_file_close (dst);
+  SVN_ERR (svn_io_remove_file (src_file, pool));
+  
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_io_file_compress (const char *file, apr_pool_t *pool)
+{
+#ifdef SVN_HAVE_ZLIB
+  apr_file_t *src, *dst;
+  char *dst_file;
+  
+  dst_file = apr_pstrcat (pool, file, SVN_IO_COMPRESS_SUFFIX, NULL);
+  
+  return compress_or_decompress (file, dst_file, TRUE, pool);
+#else
+  return svn_error_create (APR_ENOTIMPL, NULL, "no zlib support");
+#endif
+}
+
+svn_error_t *
+svn_io_file_decompress_to_file (const char *file, const char *dst_file,
+                                apr_pool_t *pool)
+{
+#ifdef SVN_HAVE_ZLIB
+  return compress_or_decompress (file, dst_file, FALSE, pool);
+#else
+  return svn_error_create (APR_ENOTIMPL, NULL, "no zlib support"); 
+#endif
+}
+
+svn_error_t *
+svn_io_file_decompress (const char *file, apr_pool_t *pool)
+{
+#ifdef SVN_HAVE_ZLIB
+  char *dst_file;
+  int len, suffix_len;
+  
+  len = strlen(file);
+  suffix_len = strlen (SVN_IO_COMPRESS_SUFFIX);
+  if (len <= suffix_len || apr_strnatcmp (SVN_IO_COMPRESS_SUFFIX, 
+                                          file + (len - suffix_len)) != 0)
+    return svn_error_createf (SVN_ERR_BAD_FILENAME, NULL, 
+                              "svn_io_file_decompress: Bad filename '%s'",
+                              file);
+  
+  dst_file = apr_pstrdup (pool, file);
+  dst_file[len - suffix_len] = '\0';
+  
+  return compress_or_decompress (file, dst_file, FALSE, pool);
+#else
+  return svn_error_create (APR_ENOTIMPL, NULL, "no zlib support");
+#endif
+}
+
 
 /*** Modtime checking. ***/
 
Index: subversion/libsvn_subr/stream.c
===================================================================
--- subversion/libsvn_subr/stream.c	(revision 5740)
+++ subversion/libsvn_subr/stream.c	(working copy)
@@ -36,6 +36,7 @@
 #include "svn_error.h"
 #include "svn_string.h"
 
+#define SVN_COMPRESSED "svn:compressed"
 
 struct svn_stream_t {
   void *baton;
@@ -245,6 +246,9 @@
 {
   struct baton_apr *baton;
   svn_stream_t *stream;
+  svn_boolean_t compressed;
+  apr_status_t err;
+  void *data;
 
   if (file == NULL)
     return svn_stream_empty(pool);
@@ -254,6 +258,12 @@
   stream = svn_stream_create (baton, pool);
   svn_stream_set_read (stream, read_handler_apr);
   svn_stream_set_write (stream, write_handler_apr);
+  
+  svn_error_clear (svn_stream_is_apr_file_marked_compressed (file, 
+                                                             &compressed));
+  if (compressed)
+    stream = svn_stream_compressed (stream, pool);
+    
   return stream;
 }
 
@@ -546,6 +556,36 @@
 #endif /* SVN_HAVE_ZLIB */
 }
 
+svn_error_t *
+svn_stream_mark_apr_file_compressed (apr_file_t *file, apr_pool_t *pool)
+{
+  apr_status_t status;
+  
+  status = apr_file_data_set (file, (void *) TRUE, SVN_COMPRESSED, NULL);
+  if (! APR_STATUS_IS_SUCCESS (status))
+    return svn_error_create (status, NULL, 
+                             "Unable to mark apr_file_t compressed");
+  
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_stream_is_apr_file_marked_compressed (apr_file_t *file, 
+                                          svn_boolean_t *compressed)
+{
+  apr_status_t err;
+  void *data;
+
+  /* Use apr's data method to see if this stream is compressed */
+  err = apr_file_data_get (&data, SVN_COMPRESSED, file);
+  if (APR_STATUS_IS_SUCCESS(err) && data != NULL)
+    *compressed = TRUE;
+  else
+    *compressed = FALSE;
+  
+  return SVN_NO_ERROR;
+}
+
 
 /* Miscellaneous stream functions. */
 struct string_stream_baton
Index: subversion/libsvn_client/switch.c
===================================================================
--- subversion/libsvn_client/switch.c	(revision 5740)
+++ subversion/libsvn_client/switch.c	(working copy)
@@ -65,6 +65,7 @@
   void *ra_baton, *session;
   svn_ra_plugin_t *ra_lib;
   svn_revnum_t revnum;
+  svn_boolean_t compress_text_base;
   svn_error_t *err = SVN_NO_ERROR;
   svn_wc_adm_access_t *adm_access;
   const char *diff3_cmd;
@@ -80,6 +81,9 @@
                     SVN_CONFIG_OPTION_DIFF3_CMD, NULL);
   }
 
+  /* Get compress-text-base config */
+  compress_text_base = svn_client__compress_text_base(ctx->config);
+  
   /* Sanity check.  Without these, the switch is meaningless. */
   assert (path);
   assert (switch_url && (switch_url[0] != '\0'));
@@ -170,6 +174,7 @@
                                          ctx->notify_func, ctx->notify_baton,
                                          ctx->cancel_func, ctx->cancel_baton,
                                          diff3_cmd,
+                                         compress_text_base,
                                          &switch_editor, &switch_edit_baton,
                                          traversal_info, pool));
 
@@ -283,6 +288,7 @@
                                       proparray, TRUE, /* is full proplist */
                                       switch_url, /* new url */
                                       diff3_cmd,
+                                      compress_text_base,
                                       pool));     
 
         if (ctx->notify_func != NULL)
Index: subversion/libsvn_client/checkout.c
===================================================================
--- subversion/libsvn_client/checkout.c	(revision 5740)
+++ subversion/libsvn_client/checkout.c	(working copy)
@@ -56,6 +56,7 @@
   svn_wc_traversal_info_t *traversal_info = svn_wc_init_traversal_info (pool);
   svn_error_t *err;
   svn_revnum_t revnum;
+  svn_boolean_t compress_text_base;
   svn_boolean_t sleep_here = FALSE;
   svn_boolean_t *use_sleep = timestamp_sleep ? timestamp_sleep : &sleep_here;
 
@@ -63,6 +64,9 @@
   assert (path != NULL);
   assert (URL != NULL);
 
+  /* Get compress-text-base config */
+  compress_text_base = svn_client__compress_text_base (ctx->config);
+
   /* Get revnum set to something meaningful, so we can fetch the
      checkout editor. */
   if (revision->kind == svn_opt_revision_number)
@@ -84,6 +88,7 @@
                                        ctx->notify_baton,
                                        ctx->cancel_func,
                                        ctx->cancel_baton,
+                                       compress_text_base,
                                        &checkout_editor,
                                        &checkout_edit_baton,
                                        traversal_info,
Index: subversion/libsvn_client/copy.c
===================================================================
--- subversion/libsvn_client/copy.c	(revision 5740)
+++ subversion/libsvn_client/copy.c	(working copy)
@@ -706,7 +706,7 @@
   apr_hash_t *props = NULL;
   apr_hash_index_t *hi;
   const char *src_uuid = NULL, *dst_uuid = NULL;
-  svn_boolean_t same_repositories;
+  svn_boolean_t same_repositories, compress_text_base;
   const char *auth_dir;
 
   /* Get the RA vtable that matches URL. */
@@ -828,10 +828,13 @@
       const svn_delta_editor_t *editor;
       void *edit_baton;
 
+      compress_text_base = svn_client__compress_text_base (ctx->config);
+      
       /* Get a checkout editor and wrap it. */
       SVN_ERR (svn_wc_get_checkout_editor (dst_path, src_url, src_revnum, 1,
                                            ctx->notify_func, ctx->notify_baton,
                                            ctx->cancel_func, ctx->cancel_baton,
+                                           compress_text_base,
                                            &editor, &edit_baton,
                                            NULL, pool));
       
Index: subversion/libsvn_client/update.c
===================================================================
--- subversion/libsvn_client/update.c	(revision 5740)
+++ subversion/libsvn_client/update.c	(working copy)
@@ -23,7 +23,9 @@
 /*** Includes. ***/
 
 #include <assert.h>
+#include <apr_strings.h>
 
+#include "svn_private_config.h"
 #include "svn_wc.h"
 #include "svn_client.h"
 #include "svn_string.h"
@@ -56,7 +58,7 @@
   svn_revnum_t revnum;
   svn_wc_traversal_info_t *traversal_info = svn_wc_init_traversal_info (pool);
   svn_wc_adm_access_t *adm_access;
-  svn_boolean_t sleep_here = FALSE;
+  svn_boolean_t compress_text_base, sleep_here = FALSE;
   svn_boolean_t *use_sleep = timestamp_sleep ? timestamp_sleep : &sleep_here;
   const char *diff3_cmd;
   
@@ -97,6 +99,9 @@
                     SVN_CONFIG_OPTION_DIFF3_CMD, NULL);
   }
 
+  /* Get the text-base compression config. */
+  compress_text_base = svn_client__compress_text_base (ctx->config);
+  
   /* Fetch the update editor.  If REVISION is invalid, that's okay;
      the RA driver will call editor->set_target_revision later on. */
   SVN_ERR (svn_wc_get_update_editor (adm_access,
@@ -106,6 +111,7 @@
                                      ctx->notify_func, ctx->notify_baton,
                                      ctx->cancel_func, ctx->cancel_baton,
                                      diff3_cmd,
+                                     compress_text_base,
                                      &update_editor, &update_edit_baton,
                                      traversal_info,
                                      pool));
@@ -192,3 +198,24 @@
 {
   return svn_client__update_internal (path, revision, recurse, NULL, ctx, pool);
 }
+
+svn_boolean_t
+svn_client__compress_text_base(apr_hash_t *config)
+{
+  
+  const char *str;
+  svn_boolean_t compress;
+  svn_config_t *cfg = config
+    ? apr_hash_get (config, SVN_CONFIG_CATEGORY_CONFIG,  
+                    APR_HASH_KEY_STRING) : NULL;
+  
+  svn_config_get (cfg, &str, SVN_CONFIG_SECTION_MISCELLANY,
+                  SVN_CONFIG_OPTION_COMPRESS_TEXT_BASE, "no");
+  
+#ifdef SVN_HAVE_ZLIB
+  return apr_strnatcasecmp(str, "yes") == 0;
+#else
+  return FALSE;
+#endif
+
+}
Index: subversion/libsvn_client/client.h
===================================================================
--- subversion/libsvn_client/client.h	(revision 5740)
+++ subversion/libsvn_client/client.h	(working copy)
@@ -284,6 +284,10 @@
                                svn_client_ctx_t *ctx,
                                apr_pool_t *pool);
 
+/* Get the compress-text-base from the config file */
+svn_boolean_t
+svn_client__compress_text_base(apr_hash_t *config);
+
 /* ---------------------------------------------------------------- */
 
 /*** Editor for repository diff ***/

