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

svn commit: r1709630 - in /subversion/branches/move-tracking-2/subversion: include/private/svn_branch_nested.h libsvn_delta/branch_nested.c libsvn_delta/compat3e.c

Author: julianfoad
Date: Tue Oct 20 16:05:55 2015
New Revision: 1709630

URL: http://svn.apache.org/viewvc?rev=1709630&view=rev
Log:
On the 'move-tracking-2' branch: Refactoring: Move the handling of nested
branches into a branch txn class that wraps a basic branch txn class.

* subversion/include/private/svn_branch_nested.h
  (svn_nested_branch_txn_create): New.

* subversion/libsvn_delta/branch_nested.c
  (branch_in_rev_or_txn): Move here from compat3e.c.
  (svn_branch_txn_priv_t,
   svn_nested_branch_txn_create): New.
   nested_branch_txn_new_eid,
   nested_branch_txn_open_branch,
   nested_branch_txn_branch,
   nested_branch_txn_sequence_point): New, with implementations moved from
    compat3e.c.

* subversion/libsvn_delta/compat3e.c
  (branch_in_rev_or_txn): Move to branch_nested.c.
  (editor3_new_eid,
   editor3_open_branch,
   editor3_branch,
   editor3_sequence_point): Move implementations to branch_nested.c, and
    instead wrap a nested-branch-txn object around the plain txn.

Modified:
    subversion/branches/move-tracking-2/subversion/include/private/svn_branch_nested.h
    subversion/branches/move-tracking-2/subversion/libsvn_delta/branch_nested.c
    subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3e.c

Modified: subversion/branches/move-tracking-2/subversion/include/private/svn_branch_nested.h
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/include/private/svn_branch_nested.h?rev=1709630&r1=1709629&r2=1709630&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/include/private/svn_branch_nested.h (original)
+++ subversion/branches/move-tracking-2/subversion/include/private/svn_branch_nested.h Tue Oct 20 16:05:55 2015
@@ -198,6 +198,13 @@ svn_branch_instantiate_elements_r(svn_br
                                   svn_branch_subtree_t elements,
                                   apr_pool_t *scratch_pool);
 
+/* Create a branch txn object that implements nesting, and wraps a plain
+ * branch txn (that doesn't support nesting) WRAPPED_TXN.
+ */
+svn_branch_txn_t *
+svn_nested_branch_txn_create(svn_branch_txn_t *wrapped_txn,
+                             apr_pool_t *result_pool);
+
 
 #ifdef __cplusplus
 }

Modified: subversion/branches/move-tracking-2/subversion/libsvn_delta/branch_nested.c
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/libsvn_delta/branch_nested.c?rev=1709630&r1=1709629&r2=1709630&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/libsvn_delta/branch_nested.c (original)
+++ subversion/branches/move-tracking-2/subversion/libsvn_delta/branch_nested.c Tue Oct 20 16:05:55 2015
@@ -28,9 +28,13 @@
 #include "svn_dirent_uri.h"
 #include "svn_hash.h"
 #include "svn_iter.h"
+#include "svn_pools.h"
 
 #include "private/svn_branch_nested.h"
 #include "private/svn_branch_repos.h"
+
+#include "branch_private.h"
+
 #include "svn_private_config.h"
 
 
@@ -134,6 +138,7 @@ svn_branch_get_immediate_subbranches(svn
             = svn_branch_txn_get_branch_by_id(branch->txn, subbranch_id,
                                               scratch_pool);
 
+          SVN_ERR_ASSERT_NO_RETURN(subbranch);
           SVN_ARRAY_PUSH(subbranches) = subbranch;
         }
     }
@@ -327,3 +332,165 @@ svn_branch_repos_find_el_rev_by_path_rev
   return SVN_NO_ERROR;
 }
 
+/* Set *BRANCH_P to the branch found in the repository of TXN, at the
+ * location (in a revision or in this txn) SRC_EL_REV.
+ *
+ * Return an error if REVNUM or BRANCH_ID is not found.
+ */
+static svn_error_t *
+branch_in_rev_or_txn(svn_branch_state_t **branch_p,
+                     const svn_branch_rev_bid_eid_t *src_el_rev,
+                     svn_branch_txn_t *txn,
+                     apr_pool_t *result_pool)
+{
+  if (SVN_IS_VALID_REVNUM(src_el_rev->rev))
+    {
+      SVN_ERR(svn_branch_repos_get_branch_by_id(branch_p,
+                                                txn->repos,
+                                                src_el_rev->rev,
+                                                src_el_rev->bid,
+                                                result_pool));
+    }
+  else
+    {
+      *branch_p
+        = svn_branch_txn_get_branch_by_id(
+            txn, src_el_rev->bid, result_pool);
+      if (! *branch_p)
+        return svn_error_createf(SVN_ERR_BRANCHING, NULL,
+                                 _("Branch %s not found"),
+                                 src_el_rev->bid);
+    }
+
+  return SVN_NO_ERROR;
+}
+
+struct svn_branch_txn_priv_t
+{
+  /* The underlying branch-txn that supports only non-nested branching. */
+  svn_branch_txn_t *wrapped_txn;
+
+};
+
+/* Implements nested branching.
+ * An #svn_branch_txn_t method. */
+static svn_error_t *
+nested_branch_txn_new_eid(svn_branch_txn_t *txn,
+                          svn_branch_eid_t *eid_p,
+                          apr_pool_t *scratch_pool)
+{
+  /* Just forwarding: nothing more is needed. */
+  SVN_ERR(svn_branch_txn_new_eid(txn->priv->wrapped_txn,
+                                 eid_p,
+                                 scratch_pool));
+  return SVN_NO_ERROR;
+}
+
+/* Implements nested branching.
+ * An #svn_branch_txn_t method. */
+static svn_error_t *
+nested_branch_txn_open_branch(svn_branch_txn_t *txn,
+                              const char **new_branch_id_p,
+                              svn_branch_rev_bid_t *predecessor,
+                              const char *outer_branch_id,
+                              int outer_eid,
+                              int root_eid,
+                              apr_pool_t *result_pool,
+                              apr_pool_t *scratch_pool)
+{
+  /* Just forwarding: nothing more is needed. */
+  SVN_ERR(svn_branch_txn_open_branch(txn->priv->wrapped_txn,
+                                     new_branch_id_p, predecessor,
+                                     outer_branch_id, outer_eid, root_eid,
+                                     result_pool,
+                                     scratch_pool));
+  return SVN_NO_ERROR;
+}
+
+/* Implements nested branching.
+ * An #svn_branch_txn_t method. */
+static svn_error_t *
+nested_branch_txn_branch(svn_branch_txn_t *txn,
+                         const char **new_branch_id_p,
+                         svn_branch_rev_bid_eid_t *from,
+                         const char *outer_branch_id,
+                         int outer_eid,
+                         apr_pool_t *result_pool,
+                         apr_pool_t *scratch_pool)
+{
+  svn_branch_state_t *new_branch;
+  svn_branch_state_t *from_branch;
+  svn_branch_subtree_t *from_subtree;
+
+  SVN_ERR(svn_branch_txn_branch(txn->priv->wrapped_txn,
+                                new_branch_id_p, from,
+                                outer_branch_id, outer_eid,
+                                result_pool,
+                                scratch_pool));
+
+  /* Recursively branch any nested branches */
+  /* (The way we're doing it here also redundantly re-instantiates all the
+     elements in NEW_BRANCH.) */
+  SVN_ERR(branch_in_rev_or_txn(&from_branch, from, txn->priv->wrapped_txn,
+                               scratch_pool));
+  from_subtree = svn_branch_get_subtree(from_branch, from->eid, scratch_pool);
+  new_branch = svn_branch_txn_get_branch_by_id(txn->priv->wrapped_txn,
+                                               *new_branch_id_p,
+                                               scratch_pool);
+  SVN_ERR(svn_branch_instantiate_elements_r(new_branch, *from_subtree,
+                                            scratch_pool));
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+nested_branch_txn_sequence_point(svn_branch_txn_t *txn,
+                                 apr_pool_t *scratch_pool)
+{
+  svn_branch_txn_t *wrapped_txn = txn->priv->wrapped_txn;
+  apr_array_header_t *branches;
+  int i;
+
+  /* first, purge elements in each branch */
+  SVN_ERR(svn_branch_txn_sequence_point(wrapped_txn, scratch_pool));
+
+  /* second, purge branches that are no longer nested */
+  branches = svn_branch_txn_get_branches(wrapped_txn, scratch_pool);
+  for (i = 0; i < branches->nelts; i++)
+    {
+      svn_branch_state_t *b = APR_ARRAY_IDX(branches, i, void *);
+      svn_branch_state_t *outer_branch;
+      int outer_eid;
+
+      svn_branch_get_outer_branch_and_eid(&outer_branch, &outer_eid,
+                                          b, scratch_pool);
+
+      if (outer_branch
+          && ! svn_branch_get_element(outer_branch, outer_eid))
+        {
+          SVN_ERR(svn_branch_txn_delete_branch(wrapped_txn, b->bid,
+                                               scratch_pool));
+        }
+    }
+  return SVN_NO_ERROR;
+}
+
+svn_branch_txn_t *
+svn_nested_branch_txn_create(svn_branch_txn_t *wrapped_txn,
+                             apr_pool_t *result_pool)
+{
+  static const svn_branch_txn_vtable_t vtable = {
+    {0},
+    nested_branch_txn_new_eid,
+    nested_branch_txn_open_branch,
+    nested_branch_txn_branch,
+    nested_branch_txn_sequence_point,
+  };
+  svn_branch_txn_t *txn
+    = svn_branch_txn_create(&vtable, NULL, NULL, result_pool);
+
+  txn->priv = apr_pcalloc(result_pool, sizeof(*txn->priv));
+  txn->priv->wrapped_txn = wrapped_txn;
+  return txn;
+}
+

Modified: subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3e.c
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3e.c?rev=1709630&r1=1709629&r2=1709630&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3e.c (original)
+++ subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3e.c Tue Oct 20 16:05:55 2015
@@ -1023,31 +1023,6 @@ storage_pathrev_from_branch_ref(svn_path
  */
 
 /*  */
-static svn_error_t *
-branch_in_rev_or_txn(svn_branch_state_t **src_branch,
-                     const svn_branch_rev_bid_eid_t *src_el_rev,
-                     ev3_from_delta_baton_t *eb,
-                     apr_pool_t *result_pool)
-{
-  if (SVN_IS_VALID_REVNUM(src_el_rev->rev))
-    {
-      SVN_ERR(svn_branch_repos_get_branch_by_id(src_branch,
-                                                eb->txn->repos,
-                                                src_el_rev->rev,
-                                                src_el_rev->bid,
-                                                result_pool));
-    }
-  else
-    {
-      *src_branch
-        = svn_branch_txn_get_branch_by_id(
-            eb->txn, src_el_rev->bid, result_pool);
-    }
-
-  return SVN_NO_ERROR;
-}
-
-/*  */
 #define PAYLOAD_IS_ONLY_BY_REFERENCE(payload) \
     ((payload)->kind == svn_node_unknown)
 
@@ -1157,8 +1132,10 @@ editor3_new_eid(void *baton,
                 apr_pool_t *scratch_pool)
 {
   ev3_from_delta_baton_t *eb = baton;
+  svn_branch_txn_t *txn = eb->txn;
 
-  SVN_ERR(svn_branch_txn_new_eid(eb->txn, eid_p, scratch_pool));
+  txn = svn_nested_branch_txn_create(txn, scratch_pool);
+  SVN_ERR(svn_branch_txn_new_eid(txn, eid_p, scratch_pool));
   return SVN_NO_ERROR;
 }
 
@@ -1174,8 +1151,10 @@ editor3_open_branch(void *baton,
                     apr_pool_t *scratch_pool)
 {
   ev3_from_delta_baton_t *eb = baton;
+  svn_branch_txn_t *txn = eb->txn;
 
-  SVN_ERR(svn_branch_txn_open_branch(eb->txn,
+  txn = svn_nested_branch_txn_create(txn, scratch_pool);
+  SVN_ERR(svn_branch_txn_open_branch(txn,
                                      new_branch_id_p,
                                      predecessor,
                                      outer_branch_id,
@@ -1197,11 +1176,10 @@ editor3_branch(void *baton,
                apr_pool_t *scratch_pool)
 {
   ev3_from_delta_baton_t *eb = baton;
-  svn_branch_state_t *new_branch;
-  svn_branch_state_t *from_branch;
-  svn_branch_subtree_t *from_subtree;
+  svn_branch_txn_t *txn = eb->txn;
 
-  SVN_ERR(svn_branch_txn_branch(eb->txn,
+  txn = svn_nested_branch_txn_create(txn, scratch_pool);
+  SVN_ERR(svn_branch_txn_branch(txn,
                                 new_branch_id_p,
                                 from,
                                 outer_branch_id,
@@ -1209,16 +1187,6 @@ editor3_branch(void *baton,
                                 result_pool,
                                 scratch_pool));
 
-  /* Recursively branch any nested branches */
-  /* (The way we're doing it here also redundantly re-instantiates all the
-     elements in NEW_BRANCH.) */
-  SVN_ERR(branch_in_rev_or_txn(&from_branch, from, eb, scratch_pool));
-  from_subtree = svn_branch_get_subtree(from_branch, from->eid, scratch_pool);
-  new_branch = svn_branch_txn_get_branch_by_id(eb->txn, *new_branch_id_p,
-                                               scratch_pool);
-  SVN_ERR(svn_branch_instantiate_elements_r(new_branch, *from_subtree,
-                                            scratch_pool));
-
   return SVN_NO_ERROR;
 }
 
@@ -1830,30 +1798,10 @@ editor3_sequence_point(void *baton,
                        apr_pool_t *scratch_pool)
 {
   ev3_from_delta_baton_t *eb = baton;
-  apr_array_header_t *branches;
-  int i;
+  svn_branch_txn_t *txn = eb->txn;
 
-  branches = svn_branch_txn_get_branches(eb->txn, scratch_pool);
-
-  /* first, purge elements in each branch */
-  SVN_ERR(svn_branch_txn_sequence_point(eb->txn, scratch_pool));
-
-  /* second, purge branches that are no longer nested */
-  for (i = 0; i < branches->nelts; i++)
-    {
-      svn_branch_state_t *b = APR_ARRAY_IDX(branches, i, void *);
-      svn_branch_state_t *outer_branch;
-      int outer_eid;
-
-      svn_branch_get_outer_branch_and_eid(&outer_branch, &outer_eid,
-                                          b, scratch_pool);
-
-      if (outer_branch
-          && ! svn_branch_get_element(outer_branch, outer_eid))
-        {
-          SVN_ERR(svn_branch_txn_delete_branch(eb->txn, b->bid, scratch_pool));
-        }
-    }
+  txn = svn_nested_branch_txn_create(txn, scratch_pool);
+  SVN_ERR(svn_branch_txn_sequence_point(txn, scratch_pool));
 
   return SVN_NO_ERROR;
 }