Index: subversion/libsvn_repos/log.c
===================================================================
--- subversion/libsvn_repos/log.c	(revision 18395)
+++ subversion/libsvn_repos/log.c	(working copy)
@@ -195,11 +195,10 @@
  */
 struct path_info
 {
-  const char *path;
-  svn_fs_history_t *hist;
-  apr_pool_t *newpool;
-  apr_pool_t *oldpool;
+  svn_stringbuf_t *path;
   svn_revnum_t history_rev;
+  svn_boolean_t done;
+  svn_boolean_t first_time;
 };
 
 /* Set INFO->HIST to the next history for the path.
@@ -221,25 +220,49 @@
              svn_boolean_t strict,
              svn_repos_authz_func_t authz_read_func,
              void *authz_read_baton,
-             svn_revnum_t start)
+             svn_revnum_t start,
+             apr_pool_t *pool)
 {
-  apr_pool_t *temppool;
+  svn_fs_root_t *history_root;
+  svn_fs_history_t *hist;
+  apr_pool_t *subpool;
+  const char *path;
 
-  SVN_ERR (svn_fs_history_prev (&info->hist, info->hist,
-                                strict ? FALSE : TRUE,
-                                info->newpool));
-  if (! info->hist)
-    return SVN_NO_ERROR;
+  subpool = svn_pool_create (pool);
 
+  /* Open the history located at the last rev we were at. */
+  SVN_ERR (svn_fs_revision_root (&history_root, fs, info->history_rev,
+                                 subpool));
+
+  SVN_ERR (svn_fs_node_history (&hist, history_root, info->path->data,
+                                subpool));
+
+  SVN_ERR (svn_fs_history_prev (&hist, hist, strict ? FALSE : TRUE, subpool));
+
+  if (info->first_time)
+    info->first_time = FALSE;
+  else
+    SVN_ERR (svn_fs_history_prev (&hist, hist, strict ? FALSE : TRUE,
+                                  subpool));
+
+  if (! hist)
+    {
+      svn_pool_destroy (subpool);
+      info->done = TRUE;
+      return SVN_NO_ERROR;
+    }
+
   /* Fetch the location information for this history step. */
-  SVN_ERR (svn_fs_history_location (&info->path, &info->history_rev,
-                                    info->hist, info->newpool));
+  SVN_ERR (svn_fs_history_location (&path, &info->history_rev,
+                                    hist, subpool));
 
+  svn_stringbuf_set (info->path, path);
+
   /* If this history item predates our START revision then
      don't fetch any more for this path. */
   if (info->history_rev < start)
     {
-      info->hist = NULL;
+      info->done = TRUE;
       return SVN_NO_ERROR;
     }
   
@@ -247,23 +270,18 @@
   if (authz_read_func)
     {
       svn_boolean_t readable;
-      svn_fs_root_t *history_root;
       SVN_ERR (svn_fs_revision_root (&history_root, fs,
                                      info->history_rev,
-                                     info->newpool));
+                                     subpool));
       SVN_ERR (authz_read_func (&readable, history_root,
-                                info->path,
+                                info->path->data,
                                 authz_read_baton,
-                                info->newpool));
+                                subpool));
       if (! readable)
-        info->hist = NULL;
+        info->done = TRUE;
     }
 
-  /* Now we can clear the old pool. */
-  temppool = info->oldpool;
-  info->oldpool = info->newpool;
-  svn_pool_clear (temppool);
-  info->newpool = temppool;
+  svn_pool_destroy (subpool);
 
   return SVN_NO_ERROR;
 }
@@ -285,11 +303,12 @@
                svn_boolean_t strict,
                svn_repos_authz_func_t authz_read_func,
                void *authz_read_baton,
-               svn_revnum_t start)
+               svn_revnum_t start,
+               apr_pool_t *pool)
 {
   /* If we're already done with histories for this path,
      don't try to fetch any more. */
-  if (! info->hist)
+  if (info->done)
     return SVN_NO_ERROR;
 
   /* If the last rev we got for this path is less than CURRENT,
@@ -304,7 +323,7 @@
      rev where this path was changed. */
   *changed = TRUE;
   SVN_ERR (get_history (info, fs, strict, authz_read_func,
-                        authz_read_baton, start));
+                        authz_read_baton, start, pool));
   return SVN_NO_ERROR;
 }
 
@@ -319,7 +338,7 @@
     {
       struct path_info *info = APR_ARRAY_IDX (histories, i,
                                               struct path_info *);
-      if (! info->hist)
+      if (info->done)
         continue;
       if (info->history_rev > next_rev)
         next_rev = info->history_rev;
@@ -529,15 +548,15 @@
             return svn_error_create (SVN_ERR_AUTHZ_UNREADABLE, NULL, NULL);
         }
 
-      info->path = this_path;
-      info->oldpool = svn_pool_create (pool);
-      info->newpool = svn_pool_create (pool);
-      SVN_ERR (svn_fs_node_history (&info->hist, root, info->path,
-                                    info->oldpool));
+      info->path = svn_stringbuf_create (this_path, pool);
+      info->done = FALSE;
+      info->history_rev = hist_end;
+      info->first_time = TRUE;
+
       SVN_ERR (get_history (info, fs,
                             strict_node_history,
                             authz_read_func, authz_read_baton,
-                            hist_start));
+                            hist_start, pool));
       *((struct path_info **) apr_array_push (histories)) = info;
     }
 
@@ -562,8 +581,8 @@
           SVN_ERR (check_history (&changed, info, fs, current,
                                   strict_node_history,
                                   authz_read_func, authz_read_baton,
-                                  hist_start));
-          if (info->hist != NULL)
+                                  hist_start, pool));
+          if (! info->done)
             any_histories_left = TRUE;
         }
 


