Author: julianfoad
Date: Fri Jan 20 18:13:26 2012
New Revision: 1234053
URL: http://svn.apache.org/viewvc?rev=1234053&view=rev
Log:
Factor out repeated code from find_unmerged_mergeinfo().
* subversion/libsvn_client/merge.c
(find_youngest_merged_rev, find_unmerged_mergeinfo_subroutine): New
functions, factored out ...
(find_unmerged_mergeinfo): ... from here.
Modified:
subversion/trunk/subversion/libsvn_client/merge.c
Modified: subversion/trunk/subversion/libsvn_client/merge.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/merge.c?rev=1234053&r1=1234052&r2=1234053&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/merge.c (original)
+++ subversion/trunk/subversion/libsvn_client/merge.c Fri Jan 20 18:13:26 2012
@@ -9842,6 +9842,91 @@ find_unsynced_ranges(const char *source_
}
+/* Find the youngest revision that has been merged from target to source.
+ *
+ * If any location in TARGET_HISTORY_AS_MERGEINFO is mentioned in
+ * SOURCE_MERGEINFO, then we know that at least one merge was done from the
+ * target to the source. In that case, set *YOUNGEST_MERGED_REV to the
+ * youngest revision of that intersection (unless *YOUNGEST_MERGED_REV is
+ * already younger than that). Otherwise, leave *YOUNGEST_MERGED_REV alone.
+ */
+static svn_error_t *
+find_youngest_merged_rev(svn_revnum_t *youngest_merged_rev,
+ svn_mergeinfo_t target_history_as_mergeinfo,
+ svn_mergeinfo_t source_mergeinfo,
+ apr_pool_t *scratch_pool)
+{
+ svn_mergeinfo_t explicit_source_target_history_intersection;
+
+ SVN_ERR(svn_mergeinfo_intersect2(
+ &explicit_source_target_history_intersection,
+ source_mergeinfo, target_history_as_mergeinfo, TRUE,
+ scratch_pool, scratch_pool));
+ if (apr_hash_count(explicit_source_target_history_intersection))
+ {
+ svn_revnum_t old_rev, young_rev;
+
+ /* Keep track of the youngest revision merged from target to source. */
+ SVN_ERR(svn_mergeinfo__get_range_endpoints(
+ &young_rev, &old_rev,
+ explicit_source_target_history_intersection, scratch_pool));
+ if (!SVN_IS_VALID_REVNUM(*youngest_merged_rev)
+ || (young_rev > *youngest_merged_rev))
+ *youngest_merged_rev = young_rev;
+ }
+
+ return SVN_NO_ERROR;
+}
+
+/* Set *FILTERED_MERGEINFO_P to the parts of TARGET_HISTORY_AS_MERGEINFO
+ * that are not present in the source branch.
+ *
+ * SOURCE_MERGEINFO is the explicit or inherited mergeinfo of the source
+ * branch SOURCE_URL@SOURCE_REV. Extend SOURCE_MERGEINFO, modifying it in
+ * place, to include the natural history (implicit mergeinfo) of
+ * SOURCE_URL@SOURCE_REV. ### But make these additions in SCRATCH_POOL.
+ */
+static svn_error_t *
+find_unmerged_mergeinfo_subroutine(svn_mergeinfo_t *filtered_mergeinfo_p,
+ svn_mergeinfo_t target_history_as_mergeinfo,
+ svn_mergeinfo_t source_mergeinfo,
+ const char *source_url,
+ svn_revnum_t source_rev,
+ svn_ra_session_t *source_ra_session,
+ svn_client_ctx_t *ctx,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
+{
+ svn_mergeinfo_t source_history_as_mergeinfo;
+ svn_mergeinfo_t common_mergeinfo;
+
+ /* Get the source path's natural history and merge it into source
+ path's explicit or inherited mergeinfo. */
+ SVN_ERR(svn_client__get_history_as_mergeinfo(
+ &source_history_as_mergeinfo, NULL /* has_rev_zero_history */,
+ source_url, source_rev, source_rev, SVN_INVALID_REVNUM,
+ source_ra_session, ctx, scratch_pool));
+ SVN_ERR(svn_mergeinfo_merge2(source_mergeinfo,
+ source_history_as_mergeinfo,
+ scratch_pool, scratch_pool));
+
+ /* Now source_mergeinfo represents everything we know about
+ source_path's history. Now we need to know what part, if any, of the
+ corresponding target's history is *not* part of source_path's total
+ history; because it is neither shared history nor was it ever merged
+ from the target to the source. */
+ SVN_ERR(svn_mergeinfo_intersect2(&common_mergeinfo,
+ source_mergeinfo,
+ target_history_as_mergeinfo, TRUE,
+ scratch_pool, scratch_pool));
+
+ SVN_ERR(svn_mergeinfo_remove2(filtered_mergeinfo_p,
+ common_mergeinfo,
+ target_history_as_mergeinfo, TRUE,
+ result_pool, scratch_pool));
+ return SVN_NO_ERROR;
+}
+
/* Helper for calculate_left_hand_side() which produces a mergeinfo catalog
describing what parts of of the reintegrate target have not previously been
merged to the reintegrate source.
@@ -9912,7 +9997,6 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
apr_hash_index_t *hi;
svn_mergeinfo_catalog_t new_catalog = apr_hash_make(result_pool);
apr_pool_t *iterpool = svn_pool_create(scratch_pool);
- svn_revnum_t old_rev, young_rev;
*youngest_merged_rev = SVN_INVALID_REVNUM;
@@ -9929,12 +10013,11 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
{
const char *target_path = svn__apr_hash_index_key(hi);
svn_mergeinfo_t target_history_as_mergeinfo =
svn__apr_hash_index_val(hi);
- svn_mergeinfo_t source_history_as_mergeinfo;
const char *path_rel_to_session
= svn_relpath_skip_ancestor(target_repos_rel_path, target_path);
const char *source_path;
const char *source_url;
- svn_mergeinfo_t source_mergeinfo, filtered_mergeinfo, common_mergeinfo;
+ svn_mergeinfo_t source_mergeinfo, filtered_mergeinfo;
svn_pool_clear(iterpool);
@@ -9963,30 +10046,13 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
APR_HASH_KEY_STRING);
if (source_mergeinfo)
{
- svn_mergeinfo_t explicit_source_target_history_intersection;
-
apr_hash_set(source_catalog, source_path, APR_HASH_KEY_STRING,
NULL);
- /* If there is an intersection between the *explicit* mergeinfo on
- this source path and the corresponding target's history then we
- know that at least one merge was done from the target to the
- source. */
- SVN_ERR(svn_mergeinfo_intersect2(
- &explicit_source_target_history_intersection,
- source_mergeinfo, target_history_as_mergeinfo, TRUE,
- iterpool, iterpool));
- if (apr_hash_count(explicit_source_target_history_intersection))
- {
- /* Keep track of the youngest revision merged from the
- target to the source. */
- SVN_ERR(svn_mergeinfo__get_range_endpoints(
- &young_rev, &old_rev,
- explicit_source_target_history_intersection,
- iterpool));
- if (!SVN_IS_VALID_REVNUM(*youngest_merged_rev)
- || (young_rev > *youngest_merged_rev))
- *youngest_merged_rev = young_rev;
- }
+
+ SVN_ERR(find_youngest_merged_rev(youngest_merged_rev,
+ target_history_as_mergeinfo,
+ source_mergeinfo,
+ iterpool));
}
else
{
@@ -10023,40 +10089,13 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
source_mergeinfo = apr_hash_make(iterpool);
}
- /* Get the source path's natural history and convert it to mergeinfo.
- Then merge that natural history into source path's explicit
- or inherited mergeinfo. */
-
SVN_ERR(svn_client__get_history_as_mergeinfo(&source_history_as_mergeinfo,
- NULL /*
has_rev_zero_history */,
- source_url,
- source_rev, source_rev,
- SVN_INVALID_REVNUM,
- source_ra_session,
- ctx, iterpool));
- SVN_ERR(svn_mergeinfo_merge2(source_mergeinfo,
- source_history_as_mergeinfo, iterpool,
- iterpool));
-
- /* Now source_mergeinfo represents everything we know about
- source_path's history. Now we need to know what part, if any, of the
- corresponding target's history is *not* part of source_path's total
- history; because it is neither shared history nor was it ever merged
- from the target to the source. */
- SVN_ERR(svn_mergeinfo_intersect2(&common_mergeinfo,
- source_mergeinfo,
- target_history_as_mergeinfo, TRUE,
- iterpool, iterpool));
-
- /* Use scratch_pool rather than iterpool because filtered_mergeinfo is
- going into new_catalog below and needs to last to the end of
+ /* Use scratch_pool rather than iterpool because filtered_mergeinfo
+ is going into new_catalog below and needs to last to the end of
this function. */
- SVN_ERR(svn_mergeinfo_remove2(&filtered_mergeinfo,
- common_mergeinfo,
- target_history_as_mergeinfo, TRUE,
- scratch_pool, iterpool));
-
- /* As with svn_mergeinfo_intersect above, we need to use scratch_pool
- rather than iterpool. */
+ SVN_ERR(find_unmerged_mergeinfo_subroutine(
+ &filtered_mergeinfo, target_history_as_mergeinfo,
+ source_mergeinfo, source_url, source_rev,
+ source_ra_session, ctx, scratch_pool, iterpool));
apr_hash_set(new_catalog,
apr_pstrdup(scratch_pool, source_path),
APR_HASH_KEY_STRING,
@@ -10077,9 +10116,9 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
svn_relpath_skip_ancestor(source_repos_rel_path, source_path);
const char *source_url;
svn_mergeinfo_t source_mergeinfo = svn__apr_hash_index_val(hi);
- svn_mergeinfo_t filtered_mergeinfo, common_mergeinfo;
+ svn_mergeinfo_t filtered_mergeinfo;
const char *target_url;
- svn_mergeinfo_t target_history_as_mergeinfo, source_history_as_mergeinfo;
+ svn_mergeinfo_t target_history_as_mergeinfo;
svn_error_t *err;
svn_pool_clear(iterpool);
@@ -10112,55 +10151,19 @@ find_unmerged_mergeinfo(svn_mergeinfo_ca
}
else
{
- svn_mergeinfo_t explicit_source_target_history_intersection;
-
- /* If there is an intersection between the *explicit* mergeinfo
- on this source path and the corresponding target's history
- then we know that at least one merge was done from the target
- to the source. */
- SVN_ERR(svn_mergeinfo_intersect2(
- &explicit_source_target_history_intersection,
- source_mergeinfo, target_history_as_mergeinfo, TRUE,
- iterpool, iterpool));
-
- if (apr_hash_count(explicit_source_target_history_intersection))
- {
- /* Keep track of the youngest revision merged from the
- target to the source. */
- SVN_ERR(svn_mergeinfo__get_range_endpoints(
- &young_rev, &old_rev,
- explicit_source_target_history_intersection, iterpool));
- if (!SVN_IS_VALID_REVNUM(*youngest_merged_rev)
- || (young_rev > *youngest_merged_rev))
- *youngest_merged_rev = young_rev;
- }
-
- /* Get the source path's natural history and convert it to
- mergeinfo. Then merge that natural history into source
- path's explicit or inherited mergeinfo. */
- SVN_ERR(svn_client__get_history_as_mergeinfo(
- &source_history_as_mergeinfo,
- NULL /* has_rev_zero_history */,
- source_url,
- target_rev,
- target_rev,
- SVN_INVALID_REVNUM,
- source_ra_session,
- ctx, iterpool));
- SVN_ERR(svn_mergeinfo_merge2(source_mergeinfo,
- source_history_as_mergeinfo,
- iterpool, iterpool));
- SVN_ERR(svn_mergeinfo_intersect2(&common_mergeinfo,
- source_mergeinfo,
+ SVN_ERR(find_youngest_merged_rev(youngest_merged_rev,
target_history_as_mergeinfo,
- TRUE, iterpool, iterpool));
- /* Use subpool rather than iterpool because filtered_mergeinfo
- is going into new_catalog below and needs to last to the
- end of this function. */
- SVN_ERR(svn_mergeinfo_remove2(&filtered_mergeinfo,
- common_mergeinfo,
- target_history_as_mergeinfo,
- TRUE, scratch_pool, iterpool));
+ source_mergeinfo,
+ iterpool));
+
+ /* Use scratch_pool rather than iterpool because filtered_mergeinfo
+ is going into new_catalog below and needs to last to the end of
+ this function. */
+ /* ### Why looking at SOURCE_url at TARGET_rev? */
+ SVN_ERR(find_unmerged_mergeinfo_subroutine(
+ &filtered_mergeinfo, target_history_as_mergeinfo,
+ source_mergeinfo, source_url, target_rev,
+ source_ra_session, ctx, scratch_pool, iterpool));
if (apr_hash_count(filtered_mergeinfo))
apr_hash_set(new_catalog,
apr_pstrdup(scratch_pool, source_path),