You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ne...@apache.org on 2010/04/17 01:09:06 UTC

svn commit: r935095 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_client/diff.c libsvn_client/prop_commands.c libsvn_client/revisions.c libsvn_wc/node.c

Author: neels
Date: Fri Apr 16 23:09:06 2010
New Revision: 935095

URL: http://svn.apache.org/viewvc?rev=935095&view=rev
Log:
Remove entry_t usage from svn_client__get_revision_number(). Change this
function's behaviour so that it does not return a revision number of 0 for
added nodes, anymore. Instead, return an error when asked for a revision
number of an added node.

The diff and propget code paths still use a revnum of 0, which is now
accounted for outside of svn_client__get_revision_number(). Add comments to
mark the places.

* subversion/include/private/svn_wc_private.h,
* subversion/libsvn_wc/node.c
  (svn_wc__node_get_commit_base_rev): New function.

* subversion/libsvn_client/revisions.c
  (svn_client__get_revision_number): Remove entry_t use, change behaviour as
    described above.

* subversion/libsvn_client/diff.c
  (diff_wc_wc): Handle errors returned by svn_client__get_revision_number()
    upon added nodes by using a revnum of zero, as before this patch.

* subversion/libsvn_client/prop_commands.c
  (svn_client_propget3): Do not try to determine a revnum for added nodes but
    use 0 right away.


Modified:
    subversion/trunk/subversion/include/private/svn_wc_private.h
    subversion/trunk/subversion/libsvn_client/diff.c
    subversion/trunk/subversion/libsvn_client/prop_commands.c
    subversion/trunk/subversion/libsvn_client/revisions.c
    subversion/trunk/subversion/libsvn_wc/node.c

Modified: subversion/trunk/subversion/include/private/svn_wc_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_wc_private.h?rev=935095&r1=935094&r2=935095&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_wc_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_wc_private.h Fri Apr 16 23:09:06 2010
@@ -496,6 +496,35 @@ svn_wc__node_get_base_rev(svn_revnum_t *
                           const char *local_abspath,
                           apr_pool_t *scratch_pool);
 
+/** This whole function is for legacy, and it sucks. It does not really
+ * make sense to get the copy-from revision number without the copy-from
+ * URL, but higher level code currently wants that. This should go away.
+ * (This function serves to get away from entry_t->revision without having to
+ * change the public API.)
+ *
+ * Get the base revision of @a local_abspath using @a wc_ctx.  If @a
+ * local_abspath is not in the working copy, return @c
+ * SVN_ERR_WC_PATH_NOT_FOUND.
+ *
+ * Return the revision number of the base for this node's next commit,
+ * reflecting any local tree modifications affecting this node.
+ *
+ * If this node has no uncommitted changes, return the same as
+ * svn_wc__node_get_base_rev().
+ *
+ * If this node is moved-here or copied-here (possibly as part of a replace),
+ * return the revision of the copy/move source. Do the same even when the node
+ * has been removed from a recursive copy (subpath excluded from the copy).
+ *
+ * If this node is locally added or replaced and is not moved-here or
+ * copied-here, return SVN_INVALID_REVNUM.
+ */
+svn_error_t *
+svn_wc__node_get_commit_base_rev(svn_revnum_t *base_revision,
+                                 svn_wc_context_t *wc_ctx,
+                                 const char *local_abspath,
+                                 apr_pool_t *scratch_pool);
+
 /**
  * Get the lock token of @a local_abspath using @a wc_ctx or NULL
  * if there is no lock.  If @a local_abspath is not in the working

Modified: subversion/trunk/subversion/libsvn_client/diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/diff.c?rev=935095&r1=935094&r2=935095&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/diff.c (original)
+++ subversion/trunk/subversion/libsvn_client/diff.c Fri Apr 16 23:09:06 2010
@@ -1197,6 +1197,7 @@ diff_wc_wc(const char *path1,
            apr_pool_t *pool)
 {
   const char *abspath1;
+  svn_error_t *err;
 
   SVN_ERR_ASSERT(! svn_path_is_url(path1));
   SVN_ERR_ASSERT(! svn_path_is_url(path2));
@@ -1215,9 +1216,22 @@ diff_wc_wc(const char *path1,
           "and its working files are supported at this time")));
 
   /* Resolve named revisions to real numbers. */
-  SVN_ERR(svn_client__get_revision_number(&callback_baton->revnum1, NULL,
-                                          ctx->wc_ctx, abspath1, NULL,
-                                          revision1, pool));
+  err = svn_client__get_revision_number(&callback_baton->revnum1, NULL,
+                                        ctx->wc_ctx, abspath1, NULL,
+                                        revision1, pool);
+
+  /* In case of an added node, we have no base rev, and we show a revision
+   * number of 0. Note that this code is currently always asking for
+   * svn_opt_revision_base.
+   * ### TODO: get rid of this 0 for added nodes. */
+  if (err && (err->apr_err == SVN_ERR_CLIENT_BAD_REVISION))
+    {
+      svn_error_clear(err);
+      callback_baton->revnum1 = 0;
+    }
+  else
+    SVN_ERR(err);
+
   callback_baton->revnum2 = SVN_INVALID_REVNUM;  /* WC */
 
   SVN_ERR(svn_wc_diff6(ctx->wc_ctx,

Modified: subversion/trunk/subversion/libsvn_client/prop_commands.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/prop_commands.c?rev=935095&r1=935094&r2=935095&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/prop_commands.c (original)
+++ subversion/trunk/subversion/libsvn_client/prop_commands.c Fri Apr 16 23:09:06 2010
@@ -849,6 +849,7 @@ svn_client_propget3(apr_hash_t **props,
       svn_boolean_t pristine;
       const char *local_abspath;
       svn_error_t *err;
+      svn_boolean_t added;
 
       SVN_ERR(svn_dirent_get_absolute(&local_abspath, path_or_url, pool));
 
@@ -868,9 +869,17 @@ svn_client_propget3(apr_hash_t **props,
       else
         SVN_ERR(err);
 
-      SVN_ERR(svn_client__get_revision_number(&revnum, NULL, ctx->wc_ctx,
-                                              local_abspath, NULL, revision,
-                                              pool));
+      /* Get the actual_revnum; added nodes have no revision yet, and we
+       * return the mock-up revision of 0.
+       * ### TODO: get rid of this 0. */
+      SVN_ERR(svn_wc__node_is_status_added(&added, ctx->wc_ctx, local_abspath,
+                                           pool));
+      if (added)
+        revnum = 0;
+      else
+        SVN_ERR(svn_client__get_revision_number(&revnum, NULL, ctx->wc_ctx,
+                                                local_abspath, NULL, revision,
+                                                pool));
 
       /* If FALSE, we must want the working revision. */
       pristine = (revision->kind == svn_opt_revision_committed

Modified: subversion/trunk/subversion/libsvn_client/revisions.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/revisions.c?rev=935095&r1=935094&r2=935095&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/revisions.c (original)
+++ subversion/trunk/subversion/libsvn_client/revisions.c Fri Apr 16 23:09:06 2010
@@ -79,7 +79,7 @@ svn_client__get_revision_number(svn_revn
     case svn_opt_revision_working:
     case svn_opt_revision_base:
       {
-        const svn_wc_entry_t *ent;
+        svn_error_t *err;
 
         /* Sanity check. */
         if (local_abspath == NULL)
@@ -91,19 +91,33 @@ svn_client__get_revision_number(svn_revn
         if (svn_path_is_url(local_abspath))
           goto invalid_rev_arg;
 
-        SVN_ERR(svn_wc__get_entry_versioned(&ent, wc_ctx, local_abspath,
-                                            svn_node_unknown, FALSE, FALSE,
-                                            scratch_pool, scratch_pool));
+        err = svn_wc__node_get_commit_base_rev(revnum, wc_ctx,
+                                               local_abspath,
+                                               scratch_pool);
+
+        /* Return the same error as older code did (before and at r935091).
+           At least svn_client_proplist3 promises SVN_ERR_ENTRY_NOT_FOUND. */
+        if (err && err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
+          {
+            svn_error_clear(err);
+            return svn_error_createf(SVN_ERR_ENTRY_NOT_FOUND, NULL,
+                                     _("'%s' is not under version control"),
+                                     svn_dirent_local_style(local_abspath,
+                                                            scratch_pool));
+          }
+        else
+          SVN_ERR(err);
 
-        *revnum = ent->revision;
+        if (! SVN_IS_VALID_REVNUM(*revnum))
+          return svn_error_createf(SVN_ERR_CLIENT_BAD_REVISION, NULL,
+                                   _("Path '%s' has no committed "
+                                     "revision"), local_abspath);
       }
       break;
 
     case svn_opt_revision_committed:
     case svn_opt_revision_previous:
       {
-        const svn_wc_entry_t *ent;
-
         /* Sanity check. */
         if (local_abspath == NULL)
           return svn_error_create(SVN_ERR_CLIENT_VERSIONED_PATH_REQUIRED,
@@ -114,15 +128,14 @@ svn_client__get_revision_number(svn_revn
         if (svn_path_is_url(local_abspath))
           goto invalid_rev_arg;
 
-        SVN_ERR(svn_wc__get_entry_versioned(&ent, wc_ctx, local_abspath,
-                                            svn_node_unknown, FALSE, FALSE,
-                                            scratch_pool, scratch_pool));
-
-        if (! SVN_IS_VALID_REVNUM(ent->cmt_rev))
+        SVN_ERR(svn_wc__node_get_changed_info(revnum, NULL, NULL,
+                                              wc_ctx, local_abspath,
+                                              scratch_pool, scratch_pool));
+        if (! SVN_IS_VALID_REVNUM(*revnum))
           return svn_error_createf(SVN_ERR_CLIENT_BAD_REVISION, NULL,
                                    _("Path '%s' has no committed "
                                      "revision"), local_abspath);
-        *revnum = ent->cmt_rev;
+
         if (revision->kind == svn_opt_revision_previous)
           (*revnum)--;
       }

Modified: subversion/trunk/subversion/libsvn_wc/node.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/node.c?rev=935095&r1=935094&r2=935095&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/node.c (original)
+++ subversion/trunk/subversion/libsvn_wc/node.c Fri Apr 16 23:09:06 2010
@@ -626,6 +626,75 @@ svn_wc__node_get_base_rev(svn_revnum_t *
 }
 
 svn_error_t *
+svn_wc__node_get_commit_base_rev(svn_revnum_t *commit_base_revision,
+                                 svn_wc_context_t *wc_ctx,
+                                 const char *local_abspath,
+                                 apr_pool_t *scratch_pool)
+{
+  svn_wc__db_status_t status;
+
+  SVN_ERR(svn_wc__db_read_info(&status, NULL,
+                               commit_base_revision,
+                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                               NULL, NULL, NULL, NULL, NULL,
+                               wc_ctx->db, local_abspath, scratch_pool,
+                               scratch_pool));
+
+  /* If this returned a valid revnum, there is no WORKING node. The node is
+     cleanly checked out, no modifications, copies or replaces. */
+  if (SVN_IS_VALID_REVNUM(*commit_base_revision))
+    return SVN_NO_ERROR;
+
+  if (status == svn_wc__db_status_added)
+    {
+      /* If the node was copied/moved-here, return the copy/move source
+         revision (not this node's base revision). If it's just added,
+         return SVN_INVALID_REVNUM. */
+      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
+                                       NULL, NULL, commit_base_revision,
+                                       wc_ctx->db, local_abspath,
+                                       scratch_pool, scratch_pool));
+    }
+  else if (status == svn_wc__db_status_deleted)
+    {
+      /* This node is deleted, but we didn't get a revnum above. So this must
+         be a delete inside a locally copied tree. Return the revision number
+         of the parent of the delete, presumably the copy-from revision.
+         ### This is legacy behaviour, and it sucks. */
+      const char *work_del_abspath;
+      const char *parent_abspath;
+      svn_wc__db_status_t parent_status;
+
+      SVN_ERR(svn_wc__db_scan_deletion(NULL, NULL, NULL,
+                                       &work_del_abspath,
+                                       wc_ctx->db, local_abspath,
+                                       scratch_pool, scratch_pool));
+      SVN_ERR_ASSERT(work_del_abspath != NULL);
+      parent_abspath = svn_dirent_dirname(work_del_abspath, scratch_pool);
+
+      SVN_ERR(svn_wc__db_read_info(&parent_status,
+                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+                                   NULL, NULL,
+                                   wc_ctx->db, parent_abspath,
+                                   scratch_pool, scratch_pool));
+
+      SVN_ERR_ASSERT(parent_status == svn_wc__db_status_added
+                     || parent_status == svn_wc__db_status_obstructed_add);
+
+      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
+                                       NULL, NULL,
+                                       commit_base_revision,
+                                       wc_ctx->db, parent_abspath,
+                                       scratch_pool, scratch_pool));
+    }
+
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
 svn_wc__node_get_lock_token(const char **lock_token,
                             svn_wc_context_t *wc_ctx,
                             const char *local_abspath,



Re: svn commit: r935095 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_client/diff.c libsvn_client/prop_commands.c libsvn_client/revisions.c libsvn_wc/node.c

Posted by Daniel Näslund <da...@longitudo.com>.
On Thu, Apr 22, 2010 at 01:28:11AM +0200, Neels J Hofmeyr wrote:
> Daniel Näslund wrote:
> > On Fri, Apr 16, 2010 at 11:09:06PM -0000, neels@apache.org wrote:
> >> ==============================================================================
> >> --- subversion/trunk/subversion/libsvn_wc/node.c (original)
> >> +++ subversion/trunk/subversion/libsvn_wc/node.c Fri Apr 16 23:09:06 2010
> >> @@ -626,6 +626,75 @@ svn_wc__node_get_base_rev(svn_revnum_t *

[...]

> >> +  else if (status == svn_wc__db_status_deleted)
> >> +    {
> >> +      /* This node is deleted, but we didn't get a revnum above. So this must
> >> +         be a delete inside a locally copied tree. Return the revision number
> >> +         of the parent of the delete, presumably the copy-from revision.
> >> +         ### This is legacy behaviour, and it sucks. */
> > 
> > I thought that we would only get a rev from read_info() when we have a
> > delete if the op_root was the path itself, e.g. that we would need to
> > scan upwards if we had deleted A/D and was checking the rev of A/D/G/pi.
> 
> My code was wrong. I fixed that in above-mentioned revision. Thanks!
> Not sure if read_info() even returns the revision for the op_root. I think
> it did otherwise during my recent testing.

Yeah, read_info() gives us SVN_INVALID_REVNUM if there is a WORKING node. For a
plain delete op_root (e.g. base_del_abspath) we have a WORKING node and should
use base_get_info(). For some reason I had a strange idea of the op_root
not beeing a WORKING node. That was  _wrong_.

Daniel

Re: svn commit: r935095 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_client/diff.c libsvn_client/prop_commands.c libsvn_client/revisions.c libsvn_wc/node.c

Posted by Daniel Näslund <da...@longitudo.com>.
On Thu, Apr 22, 2010 at 01:28:11AM +0200, Neels J Hofmeyr wrote:
> Daniel Näslund wrote:
> > On Fri, Apr 16, 2010 at 11:09:06PM -0000, neels@apache.org wrote:
> >> ==============================================================================
> >> --- subversion/trunk/subversion/libsvn_wc/node.c (original)
> >> +++ subversion/trunk/subversion/libsvn_wc/node.c Fri Apr 16 23:09:06 2010
> >> @@ -626,6 +626,75 @@ svn_wc__node_get_base_rev(svn_revnum_t *

[...]

> >> +  else if (status == svn_wc__db_status_deleted)
> >> +    {
> >> +      /* This node is deleted, but we didn't get a revnum above. So this must
> >> +         be a delete inside a locally copied tree. Return the revision number
> >> +         of the parent of the delete, presumably the copy-from revision.
> >> +         ### This is legacy behaviour, and it sucks. */
> > 
> > I thought that we would only get a rev from read_info() when we have a
> > delete if the op_root was the path itself, e.g. that we would need to
> > scan upwards if we had deleted A/D and was checking the rev of A/D/G/pi.
> 
> My code was wrong. I fixed that in above-mentioned revision. Thanks!
> Not sure if read_info() even returns the revision for the op_root. I think
> it did otherwise during my recent testing.

Yeah, read_info() gives us SVN_INVALID_REVNUM if there is a WORKING node. For a
plain delete op_root (e.g. base_del_abspath) we have a WORKING node and should
use base_get_info(). For some reason I had a strange idea of the op_root
not beeing a WORKING node. That was  _wrong_.

Daniel

Re: svn commit: r935095 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_client/diff.c libsvn_client/prop_commands.c libsvn_client/revisions.c libsvn_wc/node.c

Posted by Neels J Hofmeyr <ne...@elego.de>.
Daniel Näslund wrote:
> On Fri, Apr 16, 2010 at 11:09:06PM -0000, neels@apache.org wrote:
> 
> [...]
> 
>> ==============================================================================
>> --- subversion/trunk/subversion/libsvn_wc/node.c (original)
>> +++ subversion/trunk/subversion/libsvn_wc/node.c Fri Apr 16 23:09:06 2010
>> @@ -626,6 +626,75 @@ svn_wc__node_get_base_rev(svn_revnum_t *
>>  }
>>  
>>  svn_error_t *
>> +svn_wc__node_get_commit_base_rev(svn_revnum_t *commit_base_revision,
>> +                                 svn_wc_context_t *wc_ctx,
>> +                                 const char *local_abspath,
>> +                                 apr_pool_t *scratch_pool)
>> +{
>> +  svn_wc__db_status_t status;
>> +
>> +  SVN_ERR(svn_wc__db_read_info(&status, NULL,
>> +                               commit_base_revision,
>> +                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
>> +                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
>> +                               NULL, NULL, NULL, NULL, NULL,
>> +                               wc_ctx->db, local_abspath, scratch_pool,
>> +                               scratch_pool));
> 
> What about if a path has been replaced? svn_wc__node_get_commit_base_rev
> is used when diffing wc to wc. Consider this:
> 
> [[[
> $ svn rm A/D/G/pi
> $ svn di
> Index: A/D/G/pi
> ===================================================================
> --- A/D/G/pi  (revision 1)
> +++ A/D/G/pi  (working copy)
> @@ -1 +0,0 @@
> -This is the file 'pi'.
> ]]]
> 
> [[[
> $ svn rm A/D/G/pi
> $ touch A/D/G/pi
> $ svn add A/D/G/pi
> Index: A/D/G/pi
> ===================================================================
> --- A/D/G/pi  (working copy)
> +++ A/D/G/pi  (working copy)
> @@ -1 +0,0 @@
> -This is the file 'pi'.
> ]]]
> 
> When we have a replaced node we get an incorrect base revision!

Thanks!

Looking at this, I first found that I apparently broke diff of
simply-deleted nodes. I fixed that in r936464.

Then I looked into replace -- but apparently that behaviour was not changed
by my patch. However, looking into 1.6.x, it still says a revision number
instead of the first "(working copy)" line. So I found some entirely
unrelated code being responsible for that, got a fix for it in the pipeline
as we speak.

It is not plain straightforward to define how svn should act by default. But
you're right that this behaviour is bogus: the line "This is the file 'pi'."
obviously is of revision 1, and diff is showing revision 1's content.


>> +  /* If this returned a valid revnum, there is no WORKING node. The node is
>> +     cleanly checked out, no modifications, copies or replaces. */
>> +  if (SVN_IS_VALID_REVNUM(*commit_base_revision))
>> +    return SVN_NO_ERROR;
>> +
>> +  if (status == svn_wc__db_status_added)
>> +    {
>> +      /* If the node was copied/moved-here, return the copy/move source
>> +         revision (not this node's base revision). If it's just added,
>> +         return SVN_INVALID_REVNUM. */
>> +      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
>> +                                       NULL, NULL, commit_base_revision,
>> +                                       wc_ctx->db, local_abspath,
>> +                                       scratch_pool, scratch_pool));
>> +    }
> 
> I assume you're doing this to not change the behaviour of the callers.
> But that we in the future, always should set the revision to -1 for
> add, copy-here and move-here.

No, actually not entirely. -1 would be fine if we were to redesign the use
of svn_opt_revision_kind_t. Currently, a return value of -1 corresponds to
svn_opt_revision_unspecified, and callers assume HEAD or stuff. So it's Not
Good when the return value for _revision_base of an added node looks like we
were asking for _revision_unspecified. I've made the code return an error
instead of SVN_INVALID_REVNUM, and I had to adjust two callers to do the
ugly 0 magic themselves.

There should be more solid API around this. I believe it would be best to
not even have a function to get only a revision number, but rather the full
toss of number, URL and content, in one function. We also need something
like an svn_opt_revision_revert_base and we need to properly define
svn_opt_revision_base and _working. In particular, _revision_working should
not even have any revision number, it's the working state that is
uncommitted. So that should throw an error. That kind of stuff. Callers
desperately need to clear up on those things. But I'm not taking that on at
this juncture... I'm a burnt child with these things, I keep biting off more
than I can chew :)

> 
>> +  else if (status == svn_wc__db_status_deleted)
>> +    {
>> +      /* This node is deleted, but we didn't get a revnum above. So this must
>> +         be a delete inside a locally copied tree. Return the revision number
>> +         of the parent of the delete, presumably the copy-from revision.
>> +         ### This is legacy behaviour, and it sucks. */
> 
> I thought that we would only get a rev from read_info() when we have a
> delete if the op_root was the path itself, e.g. that we would need to
> scan upwards if we had deleted A/D and was checking the rev of A/D/G/pi.

My code was wrong. I fixed that in above-mentioned revision. Thanks!
Not sure if read_info() even returns the revision for the op_root. I think
it did otherwise during my recent testing.

> 
>> +      const char *work_del_abspath;
>> +      const char *parent_abspath;
>> +      svn_wc__db_status_t parent_status;
>> +
>> +      SVN_ERR(svn_wc__db_scan_deletion(NULL, NULL, NULL,
>> +                                       &work_del_abspath,
>> +                                       wc_ctx->db, local_abspath,
>> +                                       scratch_pool, scratch_pool));
>> +      SVN_ERR_ASSERT(work_del_abspath != NULL);
>> +      parent_abspath = svn_dirent_dirname(work_del_abspath, scratch_pool);
>> +
>> +      SVN_ERR(svn_wc__db_read_info(&parent_status,
>> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
>> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
>> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
>> +                                   NULL, NULL,
>> +                                   wc_ctx->db, parent_abspath,
>> +                                   scratch_pool, scratch_pool));
>> +
>> +      SVN_ERR_ASSERT(parent_status == svn_wc__db_status_added
>> +                     || parent_status == svn_wc__db_status_obstructed_add);
>> +
>> +      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
>> +                                       NULL, NULL,
>> +                                       commit_base_revision,
>> +                                       wc_ctx->db, parent_abspath,
>> +                                       scratch_pool, scratch_pool));
>> +    }
>> +
>> +  return SVN_NO_ERROR;
>> +}
> 
> In a couple of places we're going to have similar behaviour as this one.
> Consider libsvn_wc/adm_crawler.c:find_base_rev() and my WIP for
> libsvn_wc/status.c:assemble_status(). Maybe some parts could be put
> together to avoid code duplication.

I actually haven't thought to the bottom of which revision numbers we should
be getting when. It's rather complex. My feeling is that it should be
simpler than this, because callers should be asking more precise things.

But feel free to "outsource" some code. Maybe your code can even call
svn_client__get_commit_base_rev()? I've also found other code duplicating
this kind of behaviour (or failing to) -- subversion/libsvn_wc/diff.c
(file_diff) determines the revisions displayed by diff_wc_wc. I guess mature
code would also be sensitive to whether the revision is a copy_from or
revert_base revision, and for comparisons against copied/moved-here bases it
would make the client display something like "(URL@REV)" instead of
"(revision REV)" or "(working copy)".

So there's a lot to do. Maybe later. I'm still concentrating on keeping
things as similar as possible.

~Neels



Re: svn commit: r935095 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_client/diff.c libsvn_client/prop_commands.c libsvn_client/revisions.c libsvn_wc/node.c

Posted by Daniel Näslund <da...@longitudo.com>.
On Fri, Apr 16, 2010 at 11:09:06PM -0000, neels@apache.org wrote:

[...]

> ==============================================================================
> --- subversion/trunk/subversion/libsvn_wc/node.c (original)
> +++ subversion/trunk/subversion/libsvn_wc/node.c Fri Apr 16 23:09:06 2010
> @@ -626,6 +626,75 @@ svn_wc__node_get_base_rev(svn_revnum_t *
>  }
>  
>  svn_error_t *
> +svn_wc__node_get_commit_base_rev(svn_revnum_t *commit_base_revision,
> +                                 svn_wc_context_t *wc_ctx,
> +                                 const char *local_abspath,
> +                                 apr_pool_t *scratch_pool)
> +{
> +  svn_wc__db_status_t status;
> +
> +  SVN_ERR(svn_wc__db_read_info(&status, NULL,
> +                               commit_base_revision,
> +                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                               NULL, NULL, NULL, NULL, NULL,
> +                               wc_ctx->db, local_abspath, scratch_pool,
> +                               scratch_pool));

What about if a path has been replaced? svn_wc__node_get_commit_base_rev
is used when diffing wc to wc. Consider this:

[[[
$ svn rm A/D/G/pi
$ svn di
Index: A/D/G/pi
===================================================================
--- A/D/G/pi  (revision 1)
+++ A/D/G/pi  (working copy)
@@ -1 +0,0 @@
-This is the file 'pi'.
]]]

[[[
$ svn rm A/D/G/pi
$ touch A/D/G/pi
$ svn add A/D/G/pi
Index: A/D/G/pi
===================================================================
--- A/D/G/pi  (working copy)
+++ A/D/G/pi  (working copy)
@@ -1 +0,0 @@
-This is the file 'pi'.
]]]

When we have a replaced node we get an incorrect base revision!

> +
> +  /* If this returned a valid revnum, there is no WORKING node. The node is
> +     cleanly checked out, no modifications, copies or replaces. */
> +  if (SVN_IS_VALID_REVNUM(*commit_base_revision))
> +    return SVN_NO_ERROR;
> +
> +  if (status == svn_wc__db_status_added)
> +    {
> +      /* If the node was copied/moved-here, return the copy/move source
> +         revision (not this node's base revision). If it's just added,
> +         return SVN_INVALID_REVNUM. */
> +      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
> +                                       NULL, NULL, commit_base_revision,
> +                                       wc_ctx->db, local_abspath,
> +                                       scratch_pool, scratch_pool));
> +    }

I assume you're doing this to not change the behaviour of the callers.
But that we in the future, always should set the revision to -1 for
add, copy-here and move-here.

> +  else if (status == svn_wc__db_status_deleted)
> +    {
> +      /* This node is deleted, but we didn't get a revnum above. So this must
> +         be a delete inside a locally copied tree. Return the revision number
> +         of the parent of the delete, presumably the copy-from revision.
> +         ### This is legacy behaviour, and it sucks. */

I thought that we would only get a rev from read_info() when we have a
delete if the op_root was the path itself, e.g. that we would need to
scan upwards if we had deleted A/D and was checking the rev of A/D/G/pi.

> +      const char *work_del_abspath;
> +      const char *parent_abspath;
> +      svn_wc__db_status_t parent_status;
> +
> +      SVN_ERR(svn_wc__db_scan_deletion(NULL, NULL, NULL,
> +                                       &work_del_abspath,
> +                                       wc_ctx->db, local_abspath,
> +                                       scratch_pool, scratch_pool));
> +      SVN_ERR_ASSERT(work_del_abspath != NULL);
> +      parent_abspath = svn_dirent_dirname(work_del_abspath, scratch_pool);
> +
> +      SVN_ERR(svn_wc__db_read_info(&parent_status,
> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                                   NULL, NULL,
> +                                   wc_ctx->db, parent_abspath,
> +                                   scratch_pool, scratch_pool));
> +
> +      SVN_ERR_ASSERT(parent_status == svn_wc__db_status_added
> +                     || parent_status == svn_wc__db_status_obstructed_add);
> +
> +      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
> +                                       NULL, NULL,
> +                                       commit_base_revision,
> +                                       wc_ctx->db, parent_abspath,
> +                                       scratch_pool, scratch_pool));
> +    }
> +
> +  return SVN_NO_ERROR;
> +}

In a couple of places we're going to have similar behaviour as this one.
Consider libsvn_wc/adm_crawler.c:find_base_rev() and my WIP for
libsvn_wc/status.c:assemble_status(). Maybe some parts could be put
together to avoid code duplication.

> +
> +svn_error_t *
>  svn_wc__node_get_lock_token(const char **lock_token,
>                              svn_wc_context_t *wc_ctx,
>                              const char *local_abspath,

Re: svn commit: r935095 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_client/diff.c libsvn_client/prop_commands.c libsvn_client/revisions.c libsvn_wc/node.c

Posted by Daniel Näslund <da...@longitudo.com>.
On Fri, Apr 16, 2010 at 11:09:06PM -0000, neels@apache.org wrote:

[...]

> ==============================================================================
> --- subversion/trunk/subversion/libsvn_wc/node.c (original)
> +++ subversion/trunk/subversion/libsvn_wc/node.c Fri Apr 16 23:09:06 2010
> @@ -626,6 +626,75 @@ svn_wc__node_get_base_rev(svn_revnum_t *
>  }
>  
>  svn_error_t *
> +svn_wc__node_get_commit_base_rev(svn_revnum_t *commit_base_revision,
> +                                 svn_wc_context_t *wc_ctx,
> +                                 const char *local_abspath,
> +                                 apr_pool_t *scratch_pool)
> +{
> +  svn_wc__db_status_t status;
> +
> +  SVN_ERR(svn_wc__db_read_info(&status, NULL,
> +                               commit_base_revision,
> +                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                               NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                               NULL, NULL, NULL, NULL, NULL,
> +                               wc_ctx->db, local_abspath, scratch_pool,
> +                               scratch_pool));

What about if a path has been replaced? svn_wc__node_get_commit_base_rev
is used when diffing wc to wc. Consider this:

[[[
$ svn rm A/D/G/pi
$ svn di
Index: A/D/G/pi
===================================================================
--- A/D/G/pi  (revision 1)
+++ A/D/G/pi  (working copy)
@@ -1 +0,0 @@
-This is the file 'pi'.
]]]

[[[
$ svn rm A/D/G/pi
$ touch A/D/G/pi
$ svn add A/D/G/pi
Index: A/D/G/pi
===================================================================
--- A/D/G/pi  (working copy)
+++ A/D/G/pi  (working copy)
@@ -1 +0,0 @@
-This is the file 'pi'.
]]]

When we have a replaced node we get an incorrect base revision!

> +
> +  /* If this returned a valid revnum, there is no WORKING node. The node is
> +     cleanly checked out, no modifications, copies or replaces. */
> +  if (SVN_IS_VALID_REVNUM(*commit_base_revision))
> +    return SVN_NO_ERROR;
> +
> +  if (status == svn_wc__db_status_added)
> +    {
> +      /* If the node was copied/moved-here, return the copy/move source
> +         revision (not this node's base revision). If it's just added,
> +         return SVN_INVALID_REVNUM. */
> +      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
> +                                       NULL, NULL, commit_base_revision,
> +                                       wc_ctx->db, local_abspath,
> +                                       scratch_pool, scratch_pool));
> +    }

I assume you're doing this to not change the behaviour of the callers.
But that we in the future, always should set the revision to -1 for
add, copy-here and move-here.

> +  else if (status == svn_wc__db_status_deleted)
> +    {
> +      /* This node is deleted, but we didn't get a revnum above. So this must
> +         be a delete inside a locally copied tree. Return the revision number
> +         of the parent of the delete, presumably the copy-from revision.
> +         ### This is legacy behaviour, and it sucks. */

I thought that we would only get a rev from read_info() when we have a
delete if the op_root was the path itself, e.g. that we would need to
scan upwards if we had deleted A/D and was checking the rev of A/D/G/pi.

> +      const char *work_del_abspath;
> +      const char *parent_abspath;
> +      svn_wc__db_status_t parent_status;
> +
> +      SVN_ERR(svn_wc__db_scan_deletion(NULL, NULL, NULL,
> +                                       &work_del_abspath,
> +                                       wc_ctx->db, local_abspath,
> +                                       scratch_pool, scratch_pool));
> +      SVN_ERR_ASSERT(work_del_abspath != NULL);
> +      parent_abspath = svn_dirent_dirname(work_del_abspath, scratch_pool);
> +
> +      SVN_ERR(svn_wc__db_read_info(&parent_status,
> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
> +                                   NULL, NULL,
> +                                   wc_ctx->db, parent_abspath,
> +                                   scratch_pool, scratch_pool));
> +
> +      SVN_ERR_ASSERT(parent_status == svn_wc__db_status_added
> +                     || parent_status == svn_wc__db_status_obstructed_add);
> +
> +      SVN_ERR(svn_wc__db_scan_addition(NULL, NULL, NULL, NULL, NULL, NULL,
> +                                       NULL, NULL,
> +                                       commit_base_revision,
> +                                       wc_ctx->db, parent_abspath,
> +                                       scratch_pool, scratch_pool));
> +    }
> +
> +  return SVN_NO_ERROR;
> +}

In a couple of places we're going to have similar behaviour as this one.
Consider libsvn_wc/adm_crawler.c:find_base_rev() and my WIP for
libsvn_wc/status.c:assemble_status(). Maybe some parts could be put
together to avoid code duplication.

> +
> +svn_error_t *
>  svn_wc__node_get_lock_token(const char **lock_token,
>                              svn_wc_context_t *wc_ctx,
>                              const char *local_abspath,