Simplify merge code by using a single RA session for access to both the
merge source and the merge target trees in the repository.

### Seems not to be a good idea, as it results in a large number of
### svn_ra_reparent() calls flip-flopping between the two trees.
### With RA-svn, reparenting is not free and can be expensive with old
### servers.  With other RA layers, reparenting is basically free.

* subversion/libsvn_client/merge.c
  (merge_cousins_and_supplement_mergeinfo): 
  (merge_locked): 
  (find_unmerged_mergeinfo): 
  (calculate_left_hand_side): 
  (find_reintegrate_merge): 
  (svn_client_find_reintegrate_merge): 
  (merge_reintegrate_locked): 
  (do_symmetric_merge_locked): 
--This line, and those below, will be ignored--

Index: subversion/libsvn_client/merge.c
===================================================================
--- subversion/libsvn_client/merge.c	(revision 1365585)
+++ subversion/libsvn_client/merge.c	(working copy)
@@ -9238,9 +9238,10 @@ merge_cousins_and_supplement_mergeinfo
    merge (unless this is record-only), followed by record-only merges
    to represent the changed mergeinfo.
 
-   The merge is between SOURCE->url1@rev1 (in URL1_RA_SESSION1) and
-   SOURCE->url2@rev2 (in URL2_RA_SESSION2); YCA is their youngest
-   common ancestor.
+   The merge takes the difference between SOURCE->loc1 and SOURCE->loc2;
+   YCA is their youngest common ancestor.  RA_SESSION is an RA session
+   open to the repository containing SOURCE and TARGET; it may be
+   temporarily reparented as needed by this function.
    SAME_REPOS must be true if and only if the source URLs are in the same
    repository as the target working copy.  Other arguments are as in
    all of the public merge APIs.
@@ -9252,8 +9253,7 @@ merge_cousins_and_supplement_mergeinfo
  */
 static svn_error_t *
 merge_cousins_and_supplement_mergeinfo(const merge_target_t *target,
-                                       svn_ra_session_t *URL1_ra_session,
-                                       svn_ra_session_t *URL2_ra_session,
+                                       svn_ra_session_t *ra_session,
                                        const merge_source_t *source,
                                        const svn_client__pathrev_t *yca,
                                        svn_boolean_t same_repos,
@@ -9283,13 +9283,13 @@ merge_cousins_and_supplement_mergeinfo(c
             &remove_sources, source->loc1,
             svn_rangelist__initialize(source->loc1->rev, yca->rev, TRUE,
                                       scratch_pool),
-            URL1_ra_session, ctx, scratch_pool, subpool));
+            ra_session, ctx, scratch_pool, subpool));
 
   SVN_ERR(normalize_merge_sources_internal(
             &add_sources, source->loc2,
             svn_rangelist__initialize(yca->rev, source->loc2->rev, TRUE,
                                       scratch_pool),
-            URL2_ra_session, ctx, scratch_pool, subpool));
+            ra_session, ctx, scratch_pool, subpool));
 
   /* If this isn't a record-only merge, we'll first do a stupid
      point-to-point merge... */
@@ -9300,7 +9300,7 @@ merge_cousins_and_supplement_mergeinfo(c
       modified_subtrees = apr_hash_make(scratch_pool);
       APR_ARRAY_PUSH(faux_sources, const merge_source_t *) = source;
       SVN_ERR(do_merge(&modified_subtrees, NULL, faux_sources, target,
-                       URL1_ra_session, TRUE, same_repos,
+                       ra_session, TRUE, same_repos,
                        ignore_ancestry, force, dry_run, FALSE, NULL, TRUE,
                        FALSE, depth, merge_options, use_sleep, ctx,
                        scratch_pool, subpool));
@@ -9332,14 +9332,14 @@ merge_cousins_and_supplement_mergeinfo(c
       notify_mergeinfo_recording(target->abspath, NULL, ctx, scratch_pool);
       svn_pool_clear(subpool);
       SVN_ERR(do_merge(NULL, add_result_catalog, add_sources, target,
-                       URL1_ra_session, TRUE, same_repos,
+                       ra_session, TRUE, same_repos,
                        ignore_ancestry, force, dry_run, TRUE,
                        modified_subtrees, TRUE,
                        TRUE, depth, merge_options, use_sleep, ctx,
                        scratch_pool, subpool));
       svn_pool_clear(subpool);
       SVN_ERR(do_merge(NULL, remove_result_catalog, remove_sources, target,
-                       URL1_ra_session, TRUE, same_repos,
+                       ra_session, TRUE, same_repos,
                        ignore_ancestry, force, dry_run, TRUE,
                        modified_subtrees, TRUE,
                        TRUE, depth, merge_options, use_sleep, ctx,
@@ -9676,7 +9676,6 @@ merge_locked(const char *source1,
 
           err = merge_cousins_and_supplement_mergeinfo(target,
                                                        ra_session1,
-                                                       ra_session2,
                                                        &source,
                                                        yca,
                                                        same_repos,
@@ -10208,8 +10210,9 @@ find_unmerged_mergeinfo
 
    SOURCE_LOC is the reintegrate source.
 
-   SOURCE_RA_SESSION is a session opened to the URL of SOURCE_LOC
-   and TARGET_RA_SESSION is open to TARGET->loc.url.
+   SOURCE_RA_SESSION is a session opened to the URL of SOURCE_LOC; it
+   must be the same repository as TARGET; it may
+   be temporarily reparented by this function.
 
    For each entry in TARGET_HISTORY_HASH check that the history it
    represents is contained in either the explicit mergeinfo for the
@@ -10239,11 +10242,11 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
                         const svn_client__pathrev_t *source_loc,
                         const merge_target_t *target,
                         svn_ra_session_t *source_ra_session,
-                        svn_ra_session_t *target_ra_session,
                         svn_client_ctx_t *ctx,
                         apr_pool_t *result_pool,
                         apr_pool_t *scratch_pool)
 {
+  svn_ra_session_t *ra_session = source_ra_session;
   const char *source_repos_rel_path
     = svn_client__pathrev_relpath(source_loc, scratch_pool);
   const char *target_repos_rel_path
@@ -10319,7 +10322,7 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
              Find its inherited mergeinfo.  If it doesn't have any then simply
              set source_mergeinfo to an empty hash. */
           SVN_ERR(svn_client__get_repos_mergeinfo(
-                    &source_mergeinfo, source_ra_session,
+                    &source_mergeinfo, ra_session,
                     source_pathrev->url, source_pathrev->rev,
                     svn_mergeinfo_inherited, FALSE /*squelch_incapable*/,
                     iterpool));
@@ -10333,7 +10336,7 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
       SVN_ERR(find_unmerged_mergeinfo_subroutine(
                 &filtered_mergeinfo, target_history_as_mergeinfo,
                 source_mergeinfo, source_pathrev,
-                source_ra_session, ctx, scratch_pool, iterpool));
+                ra_session, ctx, scratch_pool, iterpool));
       apr_hash_set(new_catalog,
                    apr_pstrdup(scratch_pool, source_path),
                    APR_HASH_KEY_STRING,
@@ -10370,7 +10373,7 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
                                                  target_pathrev,
                                                  target->loc.rev,
                                                  SVN_INVALID_REVNUM,
-                                                 target_ra_session,
+                                                 ra_session,
                                                  ctx, iterpool);
       if (err)
         {
@@ -10401,12 +10404,12 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
              this function. */
           /* ### Why looking at SOURCE_url at TARGET_rev? */
           SVN_ERR(svn_client__pathrev_create_with_session(
-                    &pathrev, source_ra_session, target->loc.rev, source_url,
+                    &pathrev, ra_session, target->loc.rev, source_url,
                     iterpool));
           SVN_ERR(find_unmerged_mergeinfo_subroutine(
                     &filtered_mergeinfo, target_history_as_mergeinfo,
                     source_mergeinfo, pathrev,
-                    source_ra_session, ctx, scratch_pool, iterpool));
+                    ra_session, ctx, scratch_pool, iterpool));
           if (apr_hash_count(filtered_mergeinfo))
             apr_hash_set(new_catalog,
                          apr_pstrdup(scratch_pool, source_path),
@@ -10456,12 +10459,13 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
    youngest revision ever merged from the TARGET->abspath to the source if
    such exists, see doc string for find_unmerged_mergeinfo().
 
-   SOURCE_RA_SESSION is a session opened to the SOURCE_LOC
-   and TARGET_RA_SESSION is open to TARGET->loc.url.
+   SOURCE_RA_SESSION is a session opened to the SOURCE_LOC; it may be
+   temporarily reparented within this function.
 
    *LEFT_P, *MERGED_TO_SOURCE_CATALOG , and *UNMERGED_TO_SOURCE_CATALOG are
    allocated in RESULT_POOL.  SCRATCH_POOL is used for all temporary
    allocations. */
+/* ### Change to not care where ra_session is parented. */
 static svn_error_t *
 calculate_left_hand_side(svn_client__pathrev_t **left_p,
                          svn_mergeinfo_catalog_t *merged_to_source_catalog,
@@ -10470,11 +10474,11 @@ calculate_left_hand_side(svn_client__pat
                          apr_hash_t *subtrees_with_mergeinfo,
                          const svn_client__pathrev_t *source_loc,
                          svn_ra_session_t *source_ra_session,
-                         svn_ra_session_t *target_ra_session,
                          svn_client_ctx_t *ctx,
                          apr_pool_t *result_pool,
                          apr_pool_t *scratch_pool)
 {
+  svn_ra_session_t *ra_session = source_ra_session;
   svn_mergeinfo_catalog_t mergeinfo_catalog, unmerged_catalog;
   apr_pool_t *iterpool = svn_pool_create(scratch_pool);
   apr_hash_index_t *hi;
@@ -10521,7 +10525,7 @@ calculate_left_hand_side(svn_client__pat
                                                    target_child,
                                                    target->loc.rev,
                                                    SVN_INVALID_REVNUM,
-                                                   target_ra_session,
+                                                   ra_session,
                                                    ctx, scratch_pool));
 
       apr_hash_set(target_history_hash, repos_relpath,
@@ -10532,7 +10536,7 @@ calculate_left_hand_side(svn_client__pat
      actually related, we can't reintegrate if they are not.  Also
      get an initial value for the YCA revision number. */
   SVN_ERR(svn_client__get_youngest_common_ancestor(
-              &yc_ancestor, source_loc, &target->loc, target_ra_session, ctx,
+              &yc_ancestor, source_loc, &target->loc, ra_session, ctx,
               iterpool, iterpool));
   if (! yc_ancestor)
     return svn_error_createf(SVN_ERR_CLIENT_NOT_READY_TO_MERGE, NULL,
@@ -10552,7 +10556,7 @@ calculate_left_hand_side(svn_client__pat
   /* Get the mergeinfo from the source, including its descendants
      with differing explicit mergeinfo. */
   SVN_ERR(svn_client__get_repos_mergeinfo_catalog(
-            &mergeinfo_catalog, source_ra_session,
+            &mergeinfo_catalog, ra_session,
             source_loc->url, source_loc->rev,
             svn_mergeinfo_inherited, FALSE /* squelch_incapable */,
             TRUE /* include_descendants */, iterpool, iterpool));
@@ -10574,7 +10578,6 @@ calculate_left_hand_side(svn_client__pat
                                   source_loc,
                                   target,
                                   source_ra_session,
-                                  target_ra_session,
                                   ctx,
                                   iterpool, iterpool));
 
@@ -10594,7 +10597,7 @@ calculate_left_hand_side(svn_client__pat
       /* We've previously merged some or all of the target, up to
          youngest_merged_rev, to the source.  Set
          *LEFT_P to cover the youngest part of this range. */
-      SVN_ERR(svn_client__repos_location(left_p, target_ra_session,
+      SVN_ERR(svn_client__repos_location(left_p, ra_session,
                                          &target->loc, youngest_merged_rev,
                                          ctx, result_pool, iterpool));
     }
@@ -10606,8 +10609,7 @@ calculate_left_hand_side(svn_client__pat
 /* Determine the URLs and revisions needed to perform a reintegrate merge
  * from SOURCE_LOC into the working copy at TARGET.
  *
- * SOURCE_RA_SESSION and TARGET_RA_SESSION are RA sessions opened to the
- * source and target branches respectively.
+ * SOURCE_RA_SESSION is an RA session open to the URL of SOURCE_LOC.
  *
  * Set *SOURCE_P to
  * the source-left and source-right locations of the required merge.  Set
@@ -10621,12 +10623,12 @@ find_reintegrate_merge(merge_source_t **
                        svn_client__pathrev_t **yc_ancestor_p,
                        svn_ra_session_t *source_ra_session,
                        const svn_client__pathrev_t *source_loc,
-                       svn_ra_session_t *target_ra_session,
                        const merge_target_t *target,
                        svn_client_ctx_t *ctx,
                        apr_pool_t *result_pool,
                        apr_pool_t *scratch_pool)
 {
+  svn_ra_session_t *ra_session = source_ra_session;
   svn_client__pathrev_t *yc_ancestor;
   svn_client__pathrev_t *loc1;
   merge_source_t source;
@@ -10665,7 +10667,6 @@ find_reintegrate_merge(merge_source_t **
                                    subtrees_with_mergeinfo,
                                    source_loc,
                                    source_ra_session,
-                                   target_ra_session,
                                    ctx,
                                    scratch_pool, scratch_pool));
 
@@ -10683,14 +10684,8 @@ find_reintegrate_merge(merge_source_t **
   source.loc1 = loc1;
   source.loc2 = source_loc;
 
-  /* If the target was moved after the source was branched from it,
-     it is possible that the left URL differs from the target's current
-     URL.  If so, then adjust TARGET_RA_SESSION to point to the old URL. */
-  if (strcmp(source.loc1->url, target->loc.url))
-    SVN_ERR(svn_ra_reparent(target_ra_session, source.loc1->url, scratch_pool));
-
   SVN_ERR(svn_client__get_youngest_common_ancestor(
-            &yc_ancestor, source.loc2, source.loc1, target_ra_session,
+            &yc_ancestor, source.loc2, source.loc1, ra_session,
             ctx, scratch_pool, scratch_pool));
 
   /* The source side of a reintegrate merge is not 'ancestral', except in
@@ -10715,7 +10710,7 @@ find_reintegrate_merge(merge_source_t **
                                    unmerged_to_source_mergeinfo_catalog,
                                    merged_to_source_mergeinfo_catalog,
                                    final_unmerged_catalog,
-                                   target_ra_session, scratch_pool,
+                                   ra_session, scratch_pool,
                                    scratch_pool));
 
       if (apr_hash_count(final_unmerged_catalog))
@@ -10843,8 +10838,7 @@ svn_client_find_reintegrate_merge(const
             ctx, scratch_pool, scratch_pool));
 
   SVN_ERR(find_reintegrate_merge(&source, NULL,
-                                 source_ra_session, source_loc,
-                                 target_ra_session, target,
+                                 source_ra_session, source_loc, target,
                                  ctx, result_pool, scratch_pool));
   if (source)
     {
@@ -10887,8 +10881,7 @@ merge_reintegrate_locked(const char *sou
             ctx, scratch_pool, scratch_pool));
 
   SVN_ERR(find_reintegrate_merge(&source, &yc_ancestor,
-                                 source_ra_session, source_loc,
-                                 target_ra_session, target,
+                                 source_ra_session, source_loc, target,
                                  ctx, scratch_pool, scratch_pool));
 
   if (! source)
@@ -10904,8 +10897,7 @@ merge_reintegrate_locked(const char *sou
      ### source-left equals YCA). */
   source->ancestral = FALSE;
   err = merge_cousins_and_supplement_mergeinfo(target,
-                                               target_ra_session,
-                                               source_ra_session,
+                                               target_ra_session /* , source_ra_session */,
                                                source, yc_ancestor,
                                                TRUE /* same_repos */,
                                                svn_depth_infinity,
@@ -11621,16 +11613,11 @@ do_symmetric_merge_locked(const svn_clie
        * 'reintegrate' merge would have rejected. */
       {
         merge_source_t *source2;
-        svn_ra_session_t *source_ra_session = NULL;
-        svn_ra_session_t *target_ra_session = NULL;
 
-        SVN_ERR(ensure_ra_session_url(&source_ra_session, merge->right->url,
-                                      ctx, scratch_pool));
-        SVN_ERR(ensure_ra_session_url(&target_ra_session, target->loc.url,
+        SVN_ERR(ensure_ra_session_url(&ra_session, merge->right->url,
                                       ctx, scratch_pool));
         SVN_ERR(find_reintegrate_merge(&source2, NULL,
-                                       source_ra_session, merge->right,
-                                       target_ra_session, target,
+                                       ra_session, merge->right, target,
                                        ctx, scratch_pool, scratch_pool));
       }
 
@@ -11638,11 +11625,8 @@ do_symmetric_merge_locked(const svn_clie
       source.loc2 = merge->right;
       source.ancestral = (merge->mid == NULL);
 
-      SVN_ERR(ensure_ra_session_url(&ra_session, source.loc1->url,
-                                    ctx, scratch_pool));
-
       err = merge_cousins_and_supplement_mergeinfo(target,
-                                                   ra_session, ra_session,
+                                                   ra_session,
                                                    &source, merge->yca,
                                                    TRUE /* same_repos */,
                                                    depth, ignore_ancestry,
