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 2014/11/14 16:02:56 UTC

svn commit: r1639658 - in /subversion/branches/move-tracking-2: BRANCH-README subversion/libsvn_delta/branching.c subversion/libsvn_delta/compat3b.c subversion/libsvn_delta/editor3.c subversion/svnmover/svnmover.c

Author: julianfoad
Date: Fri Nov 14 15:02:55 2014
New Revision: 1639658

URL: http://svn.apache.org/r1639658
Log:
On the 'move-tracking-2' branch: Make the 'svnmover mv' UI degrade
cross-branch moves so that the user gets some sort of reasonable result
rather than an error. Add a bit more error checking.

* BRANCH-README
  Remove the done item; add another.

* subversion/libsvn_delta/branching.c
  (branch_map_node_validate): Guard against simple cycles (parent==self).

* subversion/libsvn_delta/compat3b.c
  (svn_editor3_el_rev_get): Don't crash when the element does not exist.

* subversion/libsvn_delta/editor3.c
  (VERIFY): New macro.
  (svn_editor3_instantiate,
   svn_editor3_alter): Guard against simple cycles (parent==self).

* subversion/svnmover/svnmover.c
  (do_move): New function.
  (VERIFY_PARENT_EID_EXISTS): New macro.
  (execute): Use do_move() for moves. Check that the specified parent
    element exists, for several commands.

Modified:
    subversion/branches/move-tracking-2/BRANCH-README
    subversion/branches/move-tracking-2/subversion/libsvn_delta/branching.c
    subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3b.c
    subversion/branches/move-tracking-2/subversion/libsvn_delta/editor3.c
    subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c

Modified: subversion/branches/move-tracking-2/BRANCH-README
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/BRANCH-README?rev=1639658&r1=1639657&r2=1639658&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/BRANCH-README (original)
+++ subversion/branches/move-tracking-2/BRANCH-README Fri Nov 14 15:02:55 2014
@@ -38,12 +38,11 @@ Work on this branch:
       merge
 
     To do:
+      'diff' should recurse into sub-branches
       dissolve (unbranchify)
       provide a way to specify a mixed-rev base state
       synthesize element tracking info (instead of aborting) when reading
         a revision that was committed by a non-move-tracking client
-      make the user interface degrade cross-branch moves so that the user
-        gets some sort of reasonable result rather than an error
 
 
   * The model.

Modified: subversion/branches/move-tracking-2/subversion/libsvn_delta/branching.c
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/libsvn_delta/branching.c?rev=1639658&r1=1639657&r2=1639658&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/libsvn_delta/branching.c (original)
+++ subversion/branches/move-tracking-2/subversion/libsvn_delta/branching.c Fri Nov 14 15:02:55 2014
@@ -365,11 +365,13 @@ branch_map_node_validate(const svn_branc
 {
   SVN_ERR_ASSERT_NO_RETURN(node);
 
-  /* Parent EID must be valid, or -1 iff EID is the branch root. */
+  /* Parent EID must be valid and different from this node's EID, or -1
+     iff this is the branch root element. */
   SVN_ERR_ASSERT_NO_RETURN(
     (eid == branch->sibling_defn->root_eid)
     ? (node->parent_eid == -1)
-    : (node->parent_eid >= branch->sibling_defn->family->first_eid
+    : (node->parent_eid != eid
+       && node->parent_eid >= branch->sibling_defn->family->first_eid
        && node->parent_eid < branch->sibling_defn->family->next_eid));
 
   /* Node name must be given, and empty iff EID is the branch root. */

Modified: subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3b.c
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3b.c?rev=1639658&r1=1639657&r2=1639658&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3b.c (original)
+++ subversion/branches/move-tracking-2/subversion/libsvn_delta/compat3b.c Fri Nov 14 15:02:55 2014
@@ -812,14 +812,14 @@ svn_editor3_el_rev_get(svn_branch_el_rev
                       apr_pool_t *scratch_pool)
 {
   ev3_from_delta_baton_t *eb = svn_editor3__get_baton(editor);
-  svn_branch_el_rev_content_t *node
-    = svn_branch_el_rev_content_dup(svn_branch_map_get(branch, eid),
-                                    result_pool);
+  svn_branch_el_rev_content_t *node = svn_branch_map_get(branch, eid);
 
   /* Node content is null iff node is a subbranch root, but we shouldn't
      be querying a subbranch root. */
   SVN_ERR_ASSERT(!node || node->content);
 
+  node = node ? svn_branch_el_rev_content_dup(node, result_pool) : NULL;
+
   /* If content is by reference, fetch full content. */
   if (node && (node->content->ref.relpath))
     {

Modified: subversion/branches/move-tracking-2/subversion/libsvn_delta/editor3.c
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/libsvn_delta/editor3.c?rev=1639658&r1=1639657&r2=1639658&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/libsvn_delta/editor3.c (original)
+++ subversion/branches/move-tracking-2/subversion/libsvn_delta/editor3.c Fri Nov 14 15:02:55 2014
@@ -30,6 +30,7 @@
 #include "svn_props.h"
 
 #include "private/svn_editor3.h"
+#include "svn_private_config.h"
 
 #ifdef SVN_DEBUG
 /* This enables runtime checks of the editor API constraints.  This may
@@ -272,6 +273,12 @@ svn_editor3_put(svn_editor3_t *editor,
 #define VALID_CONTENT(content) ((content) && VALID_NODE_KIND((content)->kind))
 #define VALID_EL_REV_ID(el_rev) (el_rev && el_rev->branch && VALID_EID(el_rev->eid))
 
+#define VERIFY(method, expr) \
+  if (! (expr)) \
+    return svn_error_createf(SVN_ERR_BRANCHING, NULL, \
+                             _("svn_editor3_%s: validation (%s) failed"), \
+                             #method, #expr)
+
 svn_error_t *
 svn_editor3_add(svn_editor3_t *editor,
                 svn_editor3_eid_t *local_eid_p,
@@ -316,6 +323,8 @@ svn_editor3_instantiate(svn_editor3_t *e
   SVN_ERR_ASSERT(VALID_EID(new_parent_eid));
   SVN_ERR_ASSERT(VALID_NAME(new_name));
   SVN_ERR_ASSERT(VALID_CONTENT(new_content));
+  VERIFY(instantiate, new_parent_eid != local_eid);
+  /* TODO: verify this element does not exist (in initial state) */
 
   DO_CALLBACK(editor, cb_instantiate,
               5(branch, local_eid,
@@ -338,6 +347,7 @@ svn_editor3_copy_one(svn_editor3_t *edit
   SVN_ERR_ASSERT(VALID_EID(new_parent_eid));
   SVN_ERR_ASSERT(VALID_NAME(new_name));
   SVN_ERR_ASSERT(! new_content || VALID_CONTENT(new_content));
+  /* TODO: verify source element exists (in a committed rev) */
 
   DO_CALLBACK(editor, cb_copy_one,
               6(src_el_rev,
@@ -358,6 +368,7 @@ svn_editor3_copy_tree(svn_editor3_t *edi
   SVN_ERR_ASSERT(VALID_EL_REV_ID(src_el_rev));
   SVN_ERR_ASSERT(VALID_EID(new_parent_eid));
   SVN_ERR_ASSERT(VALID_NAME(new_name));
+  /* TODO: verify source element exists (in a committed rev) */
 
   DO_CALLBACK(editor, cb_copy_tree,
               4(src_el_rev,
@@ -373,6 +384,7 @@ svn_editor3_delete(svn_editor3_t *editor
                    svn_editor3_eid_t eid)
 {
   SVN_ERR_ASSERT(VALID_EID(eid));
+  /* TODO: verify this element exists (in initial state) */
 
   DO_CALLBACK(editor, cb_delete,
               3(since_rev, branch, eid));
@@ -393,6 +405,8 @@ svn_editor3_alter(svn_editor3_t *editor,
   SVN_ERR_ASSERT(VALID_EID(new_parent_eid));
   SVN_ERR_ASSERT(VALID_NAME(new_name));
   SVN_ERR_ASSERT(! new_content || VALID_CONTENT(new_content));
+  VERIFY(alter, new_parent_eid != eid);
+  /* TODO: verify this element exists (in initial state) */
 
   DO_CALLBACK(editor, cb_alter,
               6(since_rev, branch, eid,

Modified: subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c
URL: http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c?rev=1639658&r1=1639657&r2=1639658&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c (original)
+++ subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c Fri Nov 14 15:02:55 2014
@@ -908,6 +908,94 @@ svn_branch_diff(svn_editor3_t *editor,
   return SVN_NO_ERROR;
 }
 
+/* Move in the 'best' way possible.
+ *
+ *    if target is in same branch:
+ *      move the element
+ *    else if target is in another branch of same family:
+ *      delete element from source branch
+ *      instantiate same element in target branch
+ *    else:
+ *      delete element from source branch
+ *      create a new element in target branch
+ */
+static svn_error_t *
+do_move(svn_editor3_t *editor,
+        svn_branch_el_rev_id_t *el_rev,
+        svn_branch_el_rev_id_t *to_parent_el_rev,
+        const char *to_name,
+        apr_pool_t *scratch_pool)
+{
+  svn_branch_el_rev_content_t *old_node;
+
+  /* Simple move/rename within same branch, if possible */
+  if (to_parent_el_rev->branch == el_rev->branch)
+    {
+      /* Move within same branch */
+      SVN_ERR(svn_editor3_alter(editor, el_rev->rev,
+                                el_rev->branch, el_rev->eid,
+                                to_parent_el_rev->eid, to_name,
+                                NULL /* "no change" */));
+      return SVN_NO_ERROR;
+    }
+
+  /* Instantiate same element in another branch of same family, if possible */
+  if (el_rev->branch->sibling_defn->family->fid
+      == to_parent_el_rev->branch->sibling_defn->family->fid)
+    {
+      /* Does this element already exist in the target branch? We can't
+         use this method if it does. */
+      SVN_ERR(svn_editor3_el_rev_get(&old_node,
+                                     editor,
+                                     to_parent_el_rev->branch, el_rev->eid,
+                                     scratch_pool, scratch_pool));
+      if (! old_node)
+        {
+          /* (There is no danger of creating a cyclic directory hierarchy in
+             the target branch, as this element doesn't yet exist there.) */
+
+          printf("mv: moving by deleting element in source branch and "
+                 "instantiating same element in target branch\n");
+
+          /* Get the old content of the source node (which we know exists) */
+          SVN_ERR(svn_editor3_el_rev_get(&old_node,
+                                         editor, el_rev->branch, el_rev->eid,
+                                         scratch_pool, scratch_pool));
+          SVN_ERR_ASSERT(old_node);
+          SVN_ERR(svn_editor3_delete(editor, el_rev->rev,
+                                     el_rev->branch, el_rev->eid));
+          SVN_ERR(svn_editor3_instantiate(editor,
+                                          to_parent_el_rev->branch, el_rev->eid,
+                                          to_parent_el_rev->eid, to_name,
+                                          old_node->content));
+          return SVN_NO_ERROR;
+        }
+    }
+
+  /* Move by copy-and-delete */
+  if (el_rev->branch->sibling_defn->family->fid
+      != to_parent_el_rev->branch->sibling_defn->family->fid)
+    {
+      printf("mv: moving by copy-and-delete to a different branch family\n");
+    }
+  else
+    {
+      printf("mv: moving by copy-and-delete\n");
+    }
+  SVN_ERR(svn_editor3_el_rev_get(&old_node,
+                                 editor, el_rev->branch, el_rev->eid,
+                                 scratch_pool, scratch_pool));
+  SVN_ERR(svn_editor3_delete(editor, el_rev->rev,
+                             el_rev->branch, el_rev->eid));
+  SVN_ERR(svn_editor3_add(editor, NULL /*new_eid*/,
+                          old_node->content->kind,
+                          to_parent_el_rev->branch,
+                          to_parent_el_rev->eid, to_name,
+                          old_node->content));
+
+  return SVN_NO_ERROR;
+}
+
 #define VERIFY_REV_SPECIFIED(op, i)                                     \
   if (el_rev[i]->rev == SVN_INVALID_REVNUM)                             \
     return svn_error_createf(SVN_ERR_BRANCHING, NULL,                   \
@@ -932,6 +1020,12 @@ svn_branch_diff(svn_editor3_t *editor,
                              _("%s: Path '%s' not found"),              \
                              op, action->path[i]);
 
+#define VERIFY_PARENT_EID_EXISTS(op, i)                                 \
+  if (parent_el_rev[i]->eid == -1)                                      \
+    return svn_error_createf(SVN_ERR_BRANCHING, NULL,                   \
+                             _("%s: Path '%s' not found"),              \
+                             op, svn_relpath_dirname(action->path[i], pool));
+
 static svn_error_t *
 execute(const apr_array_header_t *actions,
         const char *anchor_url,
@@ -1057,6 +1151,7 @@ execute(const apr_array_header_t *action
         case ACTION_BRANCH:
           VERIFY_REV_UNSPECIFIED("branch", 1);
           VERIFY_EID_NONEXISTENT("branch", 1);
+          VERIFY_PARENT_EID_EXISTS("branch", 1);
           SVN_ERR(svn_branch_branch(editor,
                                     el_rev[0]->branch, el_rev[0]->eid,
                                     el_rev[1]->branch, parent_el_rev[1]->eid,
@@ -1093,17 +1188,16 @@ execute(const apr_array_header_t *action
           made_changes = TRUE;
           break;
         case ACTION_MV:
+          if (svn_relpath_skip_ancestor(action->path[0], action->path[1]))
+            return svn_error_createf(SVN_ERR_BRANCHING, NULL,
+                                     _("mv: cannot move to child of self"));
           VERIFY_REV_UNSPECIFIED("mv", 0);
           VERIFY_EID_EXISTS("mv", 0);
           VERIFY_REV_UNSPECIFIED("mv", 1);
           VERIFY_EID_NONEXISTENT("mv", 1);
-          {
-            svn_editor3_node_content_t *content = NULL; /* "no change" */
-
-            SVN_ERR(svn_editor3_alter(editor, el_rev[0]->rev,
-                                      el_rev[0]->branch, el_rev[0]->eid,
-                                      parent_el_rev[1]->eid, path_name[1], content));
-          }
+          VERIFY_PARENT_EID_EXISTS("mv", 1);
+          SVN_ERR(do_move(editor, el_rev[0], parent_el_rev[1], path_name[1],
+                          pool));
           made_changes = TRUE;
           break;
         case ACTION_CP:
@@ -1112,6 +1206,7 @@ execute(const apr_array_header_t *action
           VERIFY_EID_EXISTS("cp", 0);
           VERIFY_REV_UNSPECIFIED("cp", 1);
           VERIFY_EID_NONEXISTENT("cp", 1);
+          VERIFY_PARENT_EID_EXISTS("cp", 1);
           SVN_ERR(svn_editor3_copy_tree(editor,
                                         el_rev[0],
                                         parent_el_rev[1]->branch,
@@ -1128,6 +1223,7 @@ execute(const apr_array_header_t *action
         case ACTION_MKDIR:
           VERIFY_REV_UNSPECIFIED("mkdir", 0);
           VERIFY_EID_NONEXISTENT("mkdir", 0);
+          VERIFY_PARENT_EID_EXISTS("mkdir", 0);
           {
             apr_hash_t *props = apr_hash_make(iterpool);
             svn_editor3_node_content_t *content
@@ -1143,6 +1239,7 @@ execute(const apr_array_header_t *action
           break;
         case ACTION_PUT_FILE:
           VERIFY_REV_UNSPECIFIED("put", 1);
+          VERIFY_PARENT_EID_EXISTS("put", 1);
           {
             apr_hash_t *props = apr_hash_make(iterpool);
             svn_stringbuf_t *text;