You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Michael W Thelen <th...@cs.utah.edu> on 2004/07/01 07:05:36 UTC

[PATCH] Issue #692: Handle "svn log" with empty repos

Here's an attempt at fixing issue #692 the right way.

Log:
Fix issue #692 the right way.  There are two special cases to be handled:

(a) The repository has 0 revisions and the user runs "svn log URL": it
    is as if the user had requested -rHEAD:1.  We don't want to error
    out just because r1 doesn't exist.

(b) The working copy is at BASE revision 0 but the repository is not
    empty, and the user runs "svn log" in the working copy: it is as if
    the user requested -rBASE:1.  We don't want to print the log message
    for r1, since the working copy is at r0.

* subversion/include/svn_client.h
  (svn_client_log): Add documentation for special case (b).

* subversion/libsvn_client/log.c
  (svn_client_log): Detect both special case conditions before requesting
  logs from the server.  If either one occurs, invoke the log message
  receiver manually with a message for revision 0.

Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h	(revision 10111)
+++ subversion/include/svn_client.h	(working copy)
@@ -753,6 +753,19 @@
  * revision 1.  That works fine, except when there are no commits in
  * the repository, hence this special case.
  *
+ * Special case for working copies at revision 0:
+ *
+ * If @a start->kind is @c svn_opt_revision_base, and @a end->kind is
+ * @c svn_opt_revision_number && @a end->number is @c 1, then handle an
+ * a working copy at revision 0 specially: instead of invoking @a receiver
+ * on revisions 0 through 1, only invoke @a receiver on revision 0, passing
+ * @c NULL for changed paths and empty strings for the author and date.  This
+ * is because that particular combination of @a start and @a end usually
+ * indicates the common case of log invocation from the working copy -- the
+ * user wants to see all log messages from the BASE revision back through
+ * revision 1.  That works fine, except when the BASE revision is 0, hence
+ * this special case.
+ *
  * If @a ctx->notify_func is non-null, then call @a ctx->notify_func/baton
  * with a 'skip' signal on any unversioned targets.
  *
Index: subversion/libsvn_client/log.c
===================================================================
--- subversion/libsvn_client/log.c	(revision 10111)
+++ subversion/libsvn_client/log.c	(working copy)
@@ -113,7 +113,7 @@
       apr_array_header_t *target_urls;
       apr_array_header_t *real_targets;
       int i;
-      
+
       /* Get URLs for each target */
       target_urls = apr_array_make (pool, 1, sizeof (const char *));
       real_targets = apr_array_make (pool, 1, sizeof (const char *));
@@ -135,7 +135,7 @@
                                      svn_wc_notify_state_unknown,
                                      SVN_INVALID_REVNUM);
 
-              
+
               continue;
             }
           if (! entry->url)
@@ -175,6 +175,33 @@
                                         (NULL != base_name), TRUE, 
                                         ctx, pool));
 
+  /* Special case: If there have been no commits, we'll get an error
+   * for requesting log of a revision higher than 0.  But the
+   * default behavior of "svn log" when given a URL is to give revisions HEAD
+   * through 1, on the assumption that HEAD >= 1.  So if we see a start
+   * revision of HEAD and an end revision of 1, then we just invoke the
+   * receiver manually on a hand-constructed log message for revision 0.
+   *
+   * See also http://subversion.tigris.org/issues/show_bug.cgi?id=692.
+   */
+  {
+    svn_revnum_t youngest_rev;
+    SVN_ERR (ra_lib->get_latest_revnum (session, &youngest_rev, pool));
+    if ((start->kind == svn_opt_revision_head)
+        && (youngest_rev == 0)
+        && (end->kind == svn_opt_revision_number)
+        && (end->value.number == 1))
+      {
+        /* Log receivers are free to handle revision 0 specially... But
+           just in case some don't, we make up a message here. */
+        SVN_ERR (receiver (receiver_baton,
+                           NULL, 0, "", "", _("No commits in repository"),
+                           pool));
+
+        return SVN_NO_ERROR;
+      }
+  }
+
   /* It's a bit complex to correctly handle the special revision words
    * such as "BASE", "COMMITTED", and "PREV".  For example, if the
    * user runs
@@ -243,20 +270,50 @@
             if (start_is_local)
               SVN_ERR (svn_client__get_revision_number
                        (&start_revnum, ra_lib, session, start, target, pool));
-            
+
             if (end_is_local)
               SVN_ERR (svn_client__get_revision_number
                        (&end_revnum, ra_lib, session, end, target, pool));
 
-            err = ra_lib->get_log (session,
-                                   condensed_targets,
-                                   start_revnum,
-                                   end_revnum,
-                                   discover_changed_paths,
-                                   strict_node_history,
-                                   receiver,
-                                   receiver_baton,
-                                   pool);
+            /* Special case: If the BASE revision is 0 but the HEAD revision
+             * of the repository is > 0, then we'll get the log message for
+             * revision 1 when running "svn log" with no arguments in the
+             * working copy.  That's because the default behavior of "svn log"
+             * in a working copy is to give revisions BASE through 1, on the
+             * assumption that BASE >= 1.  So if we see a start revision of
+             * BASE and an end revision of 1, then we just invoke the receiver
+             * manually on a hand-constructed log message for revision 0.
+             *
+             * See also
+             * http://subversion.tigris.org/issues/show_bug.cgi?id=692.
+             */
+            if ((start->kind == svn_opt_revision_base)
+              && (start_revnum == 0)
+              && (end->kind == svn_opt_revision_number)
+              && (end->value.number == 1))
+              {
+                err = SVN_NO_ERROR;
+
+                /* Log receivers are free to handle revision 0 specially... But
+                   just in case some don't, we make up a message here. */
+                SVN_ERR (receiver (receiver_baton,
+                                   NULL, 0, "", "",
+                                   _("No commits in BASE revision"),
+                                   pool));
+              }
+            else
+              {
+                err = ra_lib->get_log (session,
+                                       condensed_targets,
+                                       start_revnum,
+                                       end_revnum,
+                                       discover_changed_paths,
+                                       strict_node_history,
+                                       receiver,
+                                       receiver_baton,
+                                       pool);
+              }
+
             if (err)
               break;
           }
@@ -273,40 +330,7 @@
                                receiver_baton,
                                pool);
       }
-    
-    /* Special case: If there have been no commits, we'll get an error
-     * for requesting log of a revision higher than 0.  But the
-     * default behavior of "svn log" is to give revisions HEAD through
-     * 1, on the assumption that HEAD >= 1.
-     *
-     * So if we got that error for that reason, and it looks like the
-     * user was just depending on the defaults (rather than explicitly
-     * requesting the log for revision 1), then we don't error.  Instead
-     * we just invoke the receiver manually on a hand-constructed log
-     * message for revision 0.
-     *
-     * See also http://subversion.tigris.org/issues/show_bug.cgi?id=692.
-     */
-    if (err && (err->apr_err == SVN_ERR_FS_NO_SUCH_REVISION)
-        && (start->kind == svn_opt_revision_head)
-        && ((end->kind == svn_opt_revision_number)
-            && (end->value.number == 1)))
-      {
-        svn_revnum_t youngest_rev;
-        
-        SVN_ERR (ra_lib->get_latest_revnum (session, &youngest_rev, pool));
-        if (youngest_rev == 0)
-          {
-            err = SVN_NO_ERROR;
-            
-            /* Log receivers are free to handle revision 0 specially... But
-               just in case some don't, we make up a message here. */
-            SVN_ERR (receiver (receiver_baton,
-                               NULL, 0, "", "", _("No commits in repository."),
-                               pool));
-          }
-      }
   }
-  
+
   return err;
 }

-- Mike

-- 
Michael W. Thelen
It is a painful thing
To look at your own trouble and know
That you yourself and no one else has made it
                -- Sophocles, "Ajax"

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Michael W Thelen <th...@cs.utah.edu>.
* Michael W Thelen <th...@cs.utah.edu> [2004-07-03 18:52]:
> * Michael W Thelen <th...@cs.utah.edu> [2004-07-03 15:25]:
> > Anyway, this discussion is a bit separate from the actual patch.  In a
> > little while I'll send a new patch containing what you suggested: only
> > the (b) special case handling, with the other changes removed.
> 
> Okay, here's a new patch.  It only contains the changes necessary to fix
> the problem of running 'svn log' on a working copy at BASE revision 0.
> This time I also delved into the wondrous world of Python and added a
> test case.  I'm hoping that it actually does what I think it does, and
> tests this change.  Happily, the test fails on /trunk but passes after
> applying this patch. :-)  Just a warning that you may want to inspect
> the Python code particularly closely.

I created a new issue for this bug (#1950) and included a link to this
patch.  The "working copy at revision 0" bug is different from issue
#692, and the bug still exists in /trunk (harmless as it may be :).  I'd
like to see at least this patch make it into 1.1 if possible, since it's
such an easy fix.

-- Mike

-- 
Michael W. Thelen
Never express yourself more clearly than you are able to think.
                -- Niels Bohr

[PATCH] Fix issue #1950

Posted by Michael W Thelen <th...@cs.utah.edu>.
Here is a repost of a patch that fixes issue #1950 and adds a test case for it
(minus whitespace fixes, to make it easier to read).  It's straightforward and
should be easy to review.  If you think it's worth including in 1.1, would
anyone be willing to nominate it?

-- Mike

Log:
Fix issue #1950.  Fix and document the special case when the user runs "svn
log" with no arguments in a working copy at BASE revision 0.  This case is
handled as if the user requested -rBASE:1.  But if the repository is not
empty, we don't want to print the log message for r1, since the working copy
is at r0.  Also add a test case.

* subversion/include/svn_client.h
  (svn_client_log): Add documentation for this special case.

* subversion/libsvn_client/log.c
  (svn_client_log): Detect the special case condition and if it occurs, invoke
    the log message receiver manually with a message for revision 0.

* subversion/tests/clients/cmdline/log_tests.py
  (log_with_wc_at_revision_zero): New test case for the above functionality.
  (parse_log_output): Add support for recognizing a revision 0 log message,
    since it is radically different from normal log messages.
  (check_log_chain): Only test log message text for revisions greater than 0.
    Also, fail if there are extra log messages in the list after checking all
    expected messages.

Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h	(revision 10435)
+++ subversion/include/svn_client.h	(working copy)
@@ -754,6 +754,19 @@
  * revision 1.  That works fine, except when there are no commits in
  * the repository, hence this special case.
  *
+ * Special case for working copies at revision 0:
+ *
+ * If @a start->kind is @c svn_opt_revision_base, and @a end->kind is
+ * @c svn_opt_revision_number && @a end->number is @c 1, then handle an
+ * a working copy at revision 0 specially: instead of invoking @a receiver
+ * on revisions 0 through 1, only invoke @a receiver on revision 0, passing
+ * @c NULL for changed paths and empty strings for the author and date.  This
+ * is because that particular combination of @a start and @a end usually
+ * indicates the common case of log invocation from the working copy -- the
+ * user wants to see all log messages from the BASE revision back through
+ * revision 1.  That works fine, except when the BASE revision is 0, hence
+ * this special case.
+ *
  * If @a ctx->notify_func is non-null, then call @a ctx->notify_func/baton
  * with a 'skip' signal on any unversioned targets.
  *
Index: subversion/libsvn_client/log.c
===================================================================
--- subversion/libsvn_client/log.c	(revision 10435)
+++ subversion/libsvn_client/log.c	(working copy)
@@ -243,20 +243,46 @@
             if (start_is_local)
               SVN_ERR (svn_client__get_revision_number
                        (&start_revnum, ra_lib, session, start, target, pool));
-            
+
             if (end_is_local)
               SVN_ERR (svn_client__get_revision_number
                        (&end_revnum, ra_lib, session, end, target, pool));
 
-            err = ra_lib->get_log (session,
-                                   condensed_targets,
-                                   start_revnum,
-                                   end_revnum,
-                                   discover_changed_paths,
-                                   strict_node_history,
-                                   receiver,
-                                   receiver_baton,
-                                   pool);
+            /* Special case: If the BASE revision is 0 but the HEAD revision
+             * of the repository is > 0, then we'll get the log message for
+             * revision 1 when running "svn log" with no arguments in the
+             * working copy.  That's because the default behavior of "svn log"
+             * in a working copy is to give revisions BASE through 1, on the
+             * assumption that BASE >= 1.  So if we see a start revision of
+             * BASE and an end revision of 1, then we just invoke the receiver
+             * manually on a hand-constructed log message for revision 0.  */
+            if ((start->kind == svn_opt_revision_base)
+              && (start_revnum == 0)
+              && (end->kind == svn_opt_revision_number)
+              && (end->value.number == 1))
+              {
+                err = SVN_NO_ERROR;
+
+                /* Log receivers are free to handle revision 0 specially... But
+                   just in case some don't, we make up a message here. */
+                SVN_ERR (receiver (receiver_baton,
+                                   NULL, 0, "", "",
+                                   _("No commits in BASE revision"),
+                                   pool));
+              }
+            else
+              {
+                err = ra_lib->get_log (session,
+                                       condensed_targets,
+                                       start_revnum,
+                                       end_revnum,
+                                       discover_changed_paths,
+                                       strict_node_history,
+                                       receiver,
+                                       receiver_baton,
+                                       pool);
+              }
+
             if (err)
               break;
           }
Index: subversion/tests/clients/cmdline/log_tests.py
===================================================================
--- subversion/tests/clients/cmdline/log_tests.py	(revision 10435)
+++ subversion/tests/clients/cmdline/log_tests.py	(working copy)
@@ -255,6 +255,22 @@
       if this_item:
         this_item['msg'] = msg
         chain.append (this_item)
+      this_item = None
+    elif this_line == "No commit for revision 0.\n":
+      # Add previous log message
+      if this_item:
+        this_item['msg'] = msg
+        chain.append (this_item)
+      this_item = {}
+      this_item['revision'] = '0'
+      this_item['author']   = '(no author)'
+      this_item['date']     = '1970-01-01 00:00:00 -0000 (Thu, 01 Jan 1970)'
+      this_item['msg']      = this_line
+      chain.append (this_item)
+      this_item = None
+      # Remove the message separator line - it comes after the r0 log message,
+      # not before it.
+      log_lines.pop (0)
     else:  # if didn't see separator now, then something's wrong
       raise SVNLogParseError, "trailing garbage after log message"
 
@@ -297,14 +313,17 @@
              or author == '(no author)')): raise svntest.Failure
     # Check that the log message looks right:
     msg_re = re.compile ('Log message for revision ' + `saw_rev`)
-    if (not msg_re.search (msg)): raise svntest.Failure
+    if (saw_rev > 0 and not msg_re.search (msg)): raise svntest.Failure
 
   ### todo: need some multi-line log messages mixed in with the
   ### one-liners.  Easy enough, just make the prime revisions use REV
   ### lines, and the rest use 1 line, or something, so it's
   ### predictable based on REV.
 
+  # If any log messages are still on the chain, that's a failure
+  if chain: raise svntest.Failure
 
+
 ######################################################################
 # Tests
 #
@@ -515,7 +534,21 @@
                                       'log', '-r', '2', mu2_path)
   svntest.actions.run_and_verify_svn (None, [], SVNAnyOutput,
                                       'log', '-r', '2', mu2_URL)
-  
+
+#----------------------------------------------------------------------
+def log_with_wc_at_revision_zero(sbox):
+  "'svn log', no args, top of wc at BASE revision 0"
+
+  guarantee_repos_and_wc(sbox)
+
+  svntest.main.run_svn (None, 'up', '-r', '0', sbox.wc_dir)
+  output, err = svntest.actions.run_and_verify_svn(
+    None, None, [], 'log', sbox.wc_dir)
+
+  log_chain = parse_log_output (output)
+  if check_log_chain (log_chain, [0]):
+    raise svntest.Failure
+
 ########################################################################
 # Run the tests
 
@@ -530,6 +563,7 @@
               log_with_path_args,
               url_missing_in_head,
               log_through_copyfrom_history,
+              log_with_wc_at_revision_zero,
              ]
 
 if __name__ == '__main__':

-- 
Michael W. Thelen
The great thing about democracy is that is gives every voter a chance to do
something stupid.
                -- Art Spander

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Michael W Thelen <th...@cs.utah.edu>.
* Greg Hudson <gh...@MIT.EDU> [2004-07-03 23:03]:
> I'm not sure how I feel about changing the behavior of "svn log -r
> 5:0".  Also, I think (though I'm not sure) that your candidate patch
> might produce slightly different behavior for new servers vs. old
> servers when a new client is used, since the old server wouldn't filter
> out rev 0.

Whooops... you're right, it does.  Thanks for pointing that out.

> What might conceivably make sense is to ask for HEAD:0 when no revs are
> specified, and then filter out the rev 0 log before passing it to the
> caller in that case.  A tiny bit of wasted data in the common case, but
> no wasted round trip.

Maybe... that seems nicer, but not too much nicer, than issuing a bad
HEAD:1 request and then catching the error.  Here's another thought: the
check for 0 at one endpoint of a revision range can happen in the client
library instead of the repos library.  We can still change the default
end revision from 1 to 0, but detect the edge cases immediately -before-
issuing the log request rather than catching the error afterward.  We
still have to handle the special cases, but the code to do so is much
smaller and more straightforward.  Here's a rough idea of what I mean.
What do you think of this idea?

Index: subversion/libsvn_client/log.c
===================================================================
--- subversion/libsvn_client/log.c	(revision 10137)
+++ subversion/libsvn_client/log.c	(working copy)
@@ -248,6 +248,11 @@
               SVN_ERR (svn_client__get_revision_number
                        (&end_revnum, ra_lib, session, end, target, pool));
 
+            if ((start_revnum == 0) && (end_revnum > 0))
+              start_revnum = 1;
+            else if ((start_revnum > 0) && (end_revnum == 0))
+              end_revnum = 1;
+
             err = ra_lib->get_log (session,
                                    condensed_targets,
                                    start_revnum,
@@ -263,6 +268,11 @@
       }
     else  /* both revisions are static, so no loop needed */
       {
+        if ((start_revnum == 0) && (end_revnum > 0))
+          start_revnum = 1;
+        else if ((start_revnum > 0) && (end_revnum == 0))
+          end_revnum = 1;
+
         err = ra_lib->get_log (session,
                                condensed_targets,
                                start_revnum,
@@ -273,39 +283,6 @@
                                receiver_baton,
                                pool);
       }
-    
-    /* Special case: If there have been no commits, we'll get an error
-     * for requesting log of a revision higher than 0.  But the
-     * default behavior of "svn log" is to give revisions HEAD through
-     * 1, on the assumption that HEAD >= 1.
-     *
-     * So if we got that error for that reason, and it looks like the
-     * user was just depending on the defaults (rather than explicitly
-     * requesting the log for revision 1), then we don't error.  Instead
-     * we just invoke the receiver manually on a hand-constructed log
-     * message for revision 0.
-     *
-     * See also http://subversion.tigris.org/issues/show_bug.cgi?id=692.
-     */
-    if (err && (err->apr_err == SVN_ERR_FS_NO_SUCH_REVISION)
-        && (start->kind == svn_opt_revision_head)
-        && ((end->kind == svn_opt_revision_number)
-            && (end->value.number == 1)))
-      {
-        svn_revnum_t youngest_rev;
-        
-        SVN_ERR (ra_lib->get_latest_revnum (session, &youngest_rev, pool));
-        if (youngest_rev == 0)
-          {
-            err = SVN_NO_ERROR;
-            
-            /* Log receivers are free to handle revision 0 specially... But
-               just in case some don't, we make up a message here. */
-            SVN_ERR (receiver (receiver_baton,
-                               NULL, 0, "", "", _("No commits in repository."),
-                               pool));
-          }
-      }
   }
   
   return err;
Index: subversion/clients/cmdline/log-cmd.c
===================================================================
--- subversion/clients/cmdline/log-cmd.c	(revision 10137)
+++ subversion/clients/cmdline/log-cmd.c	(working copy)
@@ -515,7 +515,7 @@
       if (opt_state->end_revision.kind == svn_opt_revision_unspecified)
         {
           opt_state->end_revision.kind = svn_opt_revision_number;
-          opt_state->end_revision.value.number = 1;  /* oldest commit */
+          opt_state->end_revision.value.number = 0;  /* oldest commit */
         }
     }
 

-- Mike

-- 
Michael W. Thelen
Ninety percent of the politicians give the other ten percent a bad reputation.
                -- Henry Kissinger

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Greg Hudson <gh...@MIT.EDU>.
I'm not sure how I feel about changing the behavior of "svn log -r
5:0".  Also, I think (though I'm not sure) that your candidate patch
might produce slightly different behavior for new servers vs. old
servers when a new client is used, since the old server wouldn't filter
out rev 0.

What might conceivably make sense is to ask for HEAD:0 when no revs are
specified, and then filter out the rev 0 log before passing it to the
caller in that case.  A tiny bit of wasted data in the common case, but
no wasted round trip.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Michael W Thelen <th...@cs.utah.edu>.
* Michael W Thelen <th...@cs.utah.edu> [2004-07-03 18:52]:
> I think I'll also produce a patch for the changes I was proposing
> before, just so you have the clearest possible idea (i.e. source code)
> of what I'm suggesting.

As promised, here's an alternate patch to demonstrate the change I was
talking about.  I think this patch is cleaner than the other one, since
it nicely eliminates the need for special case handling in the client
library.  I'm not positive that libsvn_repos is the right place for the
change, but it seems like it.

This patch does change the behavior of the repos library when a range of
revisions is requested that includes zero (e.g. -r5:0 or -r0:5).
Specifically, no log message for revision 0 is produced unless -r0 or
-r0:0 is requested.  I don't know if this is an acceptable change of
behavior or not.  But I think the change is for the better, and I
couldn't find the current behavior clearly documented anywhere.  I
really doubt that anyone depends on the current behavior, but of course
I don't know that for sure.

This patch includes the same new test that was included in the other
patch.  All tests pass, and I'm planning on writing some more, but I'll
hold off on that until it's decided which route to go with these two
patches.

----------------------------------------------------------------------------
Log:
Change the behavior of svn_repos_get_logs so that no log message is
produced for revision 0 unless the start and end revisions requested are
both 0.  Also change the cmdline client behavior so that "svn log" with
no arguments defaults to HEAD:0 or BASE:0 instead of HEAD:1 or BASE:1.
This eliminates the need for special case code in libsvn_client that
checks for errors occurring due to the default being HEAD:1.

* subversion/include/svn_client.h
  (svn_client_log): Remove documentation for the HEAD:1 special case,
    since it's no longer needed.

* subversion/libsvn_client/log.c
  (svn_client_log): Remove the code that specifically checks for an
    error after requesting HEAD:1.  This special-case code is no longer
    needed since HEAD:0 is now the default requested by the client code.

* subversion/libsvn_repos/log.c
  (svn_repos_get_logs): Don't produce a log message for revision 0 if it
    is the endpoint of a range including non-zero revisions.  For
    example, if -r5:0 is requested, only produce log messages for r5
    through r1.  A log message for revision 0 is only produced if both
    the start and end revisions requested are 0.

* subversion/clients/cmdline/log-cmd.c
  (svn_cl__log): Request 0 as the end revision when the end revision is
    unspecified.  This means that "svn log" with no arguments will be
    interpreted as HEAD:0 or BASE:0 instead of HEAD:1 or BASE:1.  This
    eliminates the errors that can occur when HEAD or BASE are 0.

* subversion/tests/clients/cmdline/log_tests.py
  (log_with_wc_at_revision_zero): New test case for "svn log" on a
    working copy at BASE revision 0 with a non-empty repository.
  (parse_log_output): Add support for recognizing a revision 0 log
    message, since it is radically different from normal log messages.
  (check_log_chain): Only test log message text for revisions greater
    than 0.  Also, fail if there are extra log messages in the list
    after checking all expected messages.

Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h	(revision 10131)
+++ subversion/include/svn_client.h	(working copy)
@@ -739,20 +739,6 @@
  *
  * Use @a pool for any temporary allocation.
  *
- * Special case for repositories at revision 0:
- *
- * If @a start->kind is @c svn_opt_revision_head, and @a end->kind is
- * @c svn_opt_revision_number && @a end->number is @c 1, then handle an
- * empty (no revisions) repository specially: instead of erroring
- * because requested revision 1 when the highest revision is 0, just
- * invoke @a receiver on revision 0, passing @c NULL for changed paths and
- * empty strings for the author and date.  This is because that
- * particular combination of @a start and @a end usually indicates the
- * common case of log invocation -- the user wants to see all log
- * messages from youngest to oldest, where the oldest commit is
- * revision 1.  That works fine, except when there are no commits in
- * the repository, hence this special case.
- *
  * If @a ctx->notify_func is non-null, then call @a ctx->notify_func/baton
  * with a 'skip' signal on any unversioned targets.
  *
Index: subversion/libsvn_client/log.c
===================================================================
--- subversion/libsvn_client/log.c	(revision 10131)
+++ subversion/libsvn_client/log.c	(working copy)
@@ -273,39 +273,6 @@
                                receiver_baton,
                                pool);
       }
-    
-    /* Special case: If there have been no commits, we'll get an error
-     * for requesting log of a revision higher than 0.  But the
-     * default behavior of "svn log" is to give revisions HEAD through
-     * 1, on the assumption that HEAD >= 1.
-     *
-     * So if we got that error for that reason, and it looks like the
-     * user was just depending on the defaults (rather than explicitly
-     * requesting the log for revision 1), then we don't error.  Instead
-     * we just invoke the receiver manually on a hand-constructed log
-     * message for revision 0.
-     *
-     * See also http://subversion.tigris.org/issues/show_bug.cgi?id=692.
-     */
-    if (err && (err->apr_err == SVN_ERR_FS_NO_SUCH_REVISION)
-        && (start->kind == svn_opt_revision_head)
-        && ((end->kind == svn_opt_revision_number)
-            && (end->value.number == 1)))
-      {
-        svn_revnum_t youngest_rev;
-        
-        SVN_ERR (ra_lib->get_latest_revnum (session, &youngest_rev, pool));
-        if (youngest_rev == 0)
-          {
-            err = SVN_NO_ERROR;
-            
-            /* Log receivers are free to handle revision 0 specially... But
-               just in case some don't, we make up a message here. */
-            SVN_ERR (receiver (receiver_baton,
-                               NULL, 0, "", "", _("No commits in repository."),
-                               pool));
-          }
-      }
   }
   
   return err;
Index: subversion/clients/cmdline/log-cmd.c
===================================================================
--- subversion/clients/cmdline/log-cmd.c	(revision 10131)
+++ subversion/clients/cmdline/log-cmd.c	(working copy)
@@ -515,7 +515,7 @@
       if (opt_state->end_revision.kind == svn_opt_revision_unspecified)
         {
           opt_state->end_revision.kind = svn_opt_revision_number;
-          opt_state->end_revision.value.number = 1;  /* oldest commit */
+          opt_state->end_revision.value.number = 0;  /* oldest commit */
         }
     }
 
Index: subversion/tests/clients/cmdline/log_tests.py
===================================================================
--- subversion/tests/clients/cmdline/log_tests.py	(revision 10131)
+++ subversion/tests/clients/cmdline/log_tests.py	(working copy)
@@ -255,6 +255,22 @@
       if this_item:
         this_item['msg'] = msg
         chain.append (this_item)
+      this_item = None
+    elif this_line == "No commit for revision 0.\n":
+      # Add previous log message
+      if this_item:
+        this_item['msg'] = msg
+        chain.append (this_item)
+      this_item = {}
+      this_item['revision'] = '0'
+      this_item['author']   = '(no author)'
+      this_item['date']     = '1970-01-01 00:00:00 -0000 (Thu, 01 Jan 1970)'
+      this_item['msg']      = this_line
+      chain.append (this_item)
+      this_item = None
+      # Remove the message separator line - it comes after the r0 log message,
+      # not before it.
+      log_lines.pop (0)
     else:  # if didn't see separator now, then something's wrong
       raise SVNLogParseError, "trailing garbage after log message"
 
@@ -297,14 +313,17 @@
              or author == '(no author)')): raise svntest.Failure
     # Check that the log message looks right:
     msg_re = re.compile ('Log message for revision ' + `saw_rev`)
-    if (not msg_re.search (msg)): raise svntest.Failure
+    if (saw_rev > 0 and not msg_re.search (msg)): raise svntest.Failure
 
   ### todo: need some multi-line log messages mixed in with the
   ### one-liners.  Easy enough, just make the prime revisions use REV
   ### lines, and the rest use 1 line, or something, so it's
   ### predictable based on REV.
 
+  # If any log messages are still on the chain, that's a failure
+  if chain: raise svntest.Failure
 
+
 ######################################################################
 # Tests
 #
@@ -515,7 +534,21 @@
                                       'log', '-r', '2', mu2_path)
   svntest.actions.run_and_verify_svn (None, [], SVNAnyOutput,
                                       'log', '-r', '2', mu2_URL)
-  
+
+#----------------------------------------------------------------------
+def log_with_wc_at_revision_zero(sbox):
+  "'svn log', no args, top of wc at BASE revision 0"
+
+  guarantee_repos_and_wc(sbox)
+
+  svntest.main.run_svn (None, 'up', '-r', '0', sbox.wc_dir)
+  output, err = svntest.actions.run_and_verify_svn(
+    None, None, [], 'log', sbox.wc_dir)
+
+  log_chain = parse_log_output (output)
+  if check_log_chain (log_chain, [0]):
+    raise svntest.Failure
+
 ########################################################################
 # Run the tests
 
@@ -530,6 +563,7 @@
               log_with_path_args,
               url_missing_in_head,
               log_through_copyfrom_history,
+              log_with_wc_at_revision_zero,
              ]
 
 if __name__ == '__main__':
Index: subversion/libsvn_repos/log.c
===================================================================
--- subversion/libsvn_repos/log.c	(revision 10131)
+++ subversion/libsvn_repos/log.c	(working copy)
@@ -166,6 +166,13 @@
       (SVN_ERR_FS_NO_SUCH_REVISION, 0,
        _("No such revision %ld"), end);
 
+  /* Don't produce a log message for revision 0 if it's one endpoint
+   * of a range including non-zero revisions */
+  if ((start == 0) && (end > 0))
+    start = 1;
+  else if ((start > 0) && (end == 0))
+    end = 1;
+
   /* If paths were specified, then we only really care about revisions
      in which those paths were changed.  So we ask the filesystem for
      all the revisions in which any of the paths was changed.

-- Mike

-- 
Michael W. Thelen
It is a painful thing
To look at your own trouble and know
That you yourself and no one else has made it
                -- Sophocles, "Ajax"

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Michael W Thelen <th...@cs.utah.edu>.
* Michael W Thelen <th...@cs.utah.edu> [2004-07-03 15:25]:
> Anyway, this discussion is a bit separate from the actual patch.  In a
> little while I'll send a new patch containing what you suggested: only
> the (b) special case handling, with the other changes removed.

Okay, here's a new patch.  It only contains the changes necessary to fix
the problem of running 'svn log' on a working copy at BASE revision 0.
This time I also delved into the wondrous world of Python and added a
test case.  I'm hoping that it actually does what I think it does, and
tests this change.  Happily, the test fails on /trunk but passes after
applying this patch. :-)  Just a warning that you may want to inspect
the Python code particularly closely.

I think I'll also produce a patch for the changes I was proposing
before, just so you have the clearest possible idea (i.e. source code)
of what I'm suggesting.

Log:
Fix and document the special case when the user runs "svn log" with no
arguments in a working copy at BASE revision 0.  This case is handled as if
the user requested -rBASE:1.  But if the repository is not empty, we don't
want to print the log message for r1, since the working copy is at r0.
Also add a test case.

* subversion/include/svn_client.h
  (svn_client_log): Add documentation for this special case.

* subversion/libsvn_client/log.c
  (svn_client_log): Detect the special case condition and if it occurs, invoke
    the log message receiver manually with a message for revision 0.

* subversion/tests/clients/cmdline/log_tests.py
  (log_with_wc_at_revision_zero): New test case for the above functionality.
  (parse_log_output): Add support for recognizing a revision 0 log message,
    since it is radically different from normal log messages.
  (check_log_chain): Only test log message text for revisions greater than 0.
    Also, fail if there are extra log messages in the list after checking all
    expected messages.

Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h	(revision 10131)
+++ subversion/include/svn_client.h	(working copy)
@@ -753,6 +753,19 @@
  * revision 1.  That works fine, except when there are no commits in
  * the repository, hence this special case.
  *
+ * Special case for working copies at revision 0:
+ *
+ * If @a start->kind is @c svn_opt_revision_base, and @a end->kind is
+ * @c svn_opt_revision_number && @a end->number is @c 1, then handle an
+ * a working copy at revision 0 specially: instead of invoking @a receiver
+ * on revisions 0 through 1, only invoke @a receiver on revision 0, passing
+ * @c NULL for changed paths and empty strings for the author and date.  This
+ * is because that particular combination of @a start and @a end usually
+ * indicates the common case of log invocation from the working copy -- the
+ * user wants to see all log messages from the BASE revision back through
+ * revision 1.  That works fine, except when the BASE revision is 0, hence
+ * this special case.
+ *
  * If @a ctx->notify_func is non-null, then call @a ctx->notify_func/baton
  * with a 'skip' signal on any unversioned targets.
  *
Index: subversion/libsvn_client/log.c
===================================================================
--- subversion/libsvn_client/log.c	(revision 10131)
+++ subversion/libsvn_client/log.c	(working copy)
@@ -113,7 +113,7 @@
       apr_array_header_t *target_urls;
       apr_array_header_t *real_targets;
       int i;
-      
+
       /* Get URLs for each target */
       target_urls = apr_array_make (pool, 1, sizeof (const char *));
       real_targets = apr_array_make (pool, 1, sizeof (const char *));
@@ -135,7 +135,6 @@
                                      svn_wc_notify_state_unknown,
                                      SVN_INVALID_REVNUM);
 
-              
               continue;
             }
           if (! entry->url)
@@ -243,20 +242,46 @@
             if (start_is_local)
               SVN_ERR (svn_client__get_revision_number
                        (&start_revnum, ra_lib, session, start, target, pool));
-            
+
             if (end_is_local)
               SVN_ERR (svn_client__get_revision_number
                        (&end_revnum, ra_lib, session, end, target, pool));
 
-            err = ra_lib->get_log (session,
-                                   condensed_targets,
-                                   start_revnum,
-                                   end_revnum,
-                                   discover_changed_paths,
-                                   strict_node_history,
-                                   receiver,
-                                   receiver_baton,
-                                   pool);
+            /* Special case: If the BASE revision is 0 but the HEAD revision
+             * of the repository is > 0, then we'll get the log message for
+             * revision 1 when running "svn log" with no arguments in the
+             * working copy.  That's because the default behavior of "svn log"
+             * in a working copy is to give revisions BASE through 1, on the
+             * assumption that BASE >= 1.  So if we see a start revision of
+             * BASE and an end revision of 1, then we just invoke the receiver
+             * manually on a hand-constructed log message for revision 0.  */
+            if ((start->kind == svn_opt_revision_base)
+              && (start_revnum == 0)
+              && (end->kind == svn_opt_revision_number)
+              && (end->value.number == 1))
+              {
+                err = SVN_NO_ERROR;
+
+                /* Log receivers are free to handle revision 0 specially... But
+                   just in case some don't, we make up a message here. */
+                SVN_ERR (receiver (receiver_baton,
+                                   NULL, 0, "", "",
+                                   _("No commits in BASE revision"),
+                                   pool));
+              }
+            else
+              {
+                err = ra_lib->get_log (session,
+                                       condensed_targets,
+                                       start_revnum,
+                                       end_revnum,
+                                       discover_changed_paths,
+                                       strict_node_history,
+                                       receiver,
+                                       receiver_baton,
+                                       pool);
+              }
+
             if (err)
               break;
           }
@@ -273,7 +298,7 @@
                                receiver_baton,
                                pool);
       }
-    
+
     /* Special case: If there have been no commits, we'll get an error
      * for requesting log of a revision higher than 0.  But the
      * default behavior of "svn log" is to give revisions HEAD through
@@ -293,12 +318,12 @@
             && (end->value.number == 1)))
       {
         svn_revnum_t youngest_rev;
-        
+
         SVN_ERR (ra_lib->get_latest_revnum (session, &youngest_rev, pool));
         if (youngest_rev == 0)
           {
             err = SVN_NO_ERROR;
-            
+
             /* Log receivers are free to handle revision 0 specially... But
                just in case some don't, we make up a message here. */
             SVN_ERR (receiver (receiver_baton,
@@ -307,6 +332,6 @@
           }
       }
   }
-  
+
   return err;
 }
Index: subversion/tests/clients/cmdline/log_tests.py
===================================================================
--- subversion/tests/clients/cmdline/log_tests.py	(revision 10131)
+++ subversion/tests/clients/cmdline/log_tests.py	(working copy)
@@ -255,6 +255,22 @@
       if this_item:
         this_item['msg'] = msg
         chain.append (this_item)
+      this_item = None
+    elif this_line == "No commit for revision 0.\n":
+      # Add previous log message
+      if this_item:
+        this_item['msg'] = msg
+        chain.append (this_item)
+      this_item = {}
+      this_item['revision'] = '0'
+      this_item['author']   = '(no author)'
+      this_item['date']     = '1970-01-01 00:00:00 -0000 (Thu, 01 Jan 1970)'
+      this_item['msg']      = this_line
+      chain.append (this_item)
+      this_item = None
+      # Remove the message separator line - it comes after the r0 log message,
+      # not before it.
+      log_lines.pop (0)
     else:  # if didn't see separator now, then something's wrong
       raise SVNLogParseError, "trailing garbage after log message"
 
@@ -297,14 +313,17 @@
              or author == '(no author)')): raise svntest.Failure
     # Check that the log message looks right:
     msg_re = re.compile ('Log message for revision ' + `saw_rev`)
-    if (not msg_re.search (msg)): raise svntest.Failure
+    if (saw_rev > 0 and not msg_re.search (msg)): raise svntest.Failure
 
   ### todo: need some multi-line log messages mixed in with the
   ### one-liners.  Easy enough, just make the prime revisions use REV
   ### lines, and the rest use 1 line, or something, so it's
   ### predictable based on REV.
 
+  # If any log messages are still on the chain, that's a failure
+  if chain: raise svntest.Failure
 
+
 ######################################################################
 # Tests
 #
@@ -515,7 +534,21 @@
                                       'log', '-r', '2', mu2_path)
   svntest.actions.run_and_verify_svn (None, [], SVNAnyOutput,
                                       'log', '-r', '2', mu2_URL)
-  
+
+#----------------------------------------------------------------------
+def log_with_wc_at_revision_zero(sbox):
+  "'svn log', no args, top of wc at BASE revision 0"
+
+  guarantee_repos_and_wc(sbox)
+
+  svntest.main.run_svn (None, 'up', '-r', '0', sbox.wc_dir)
+  output, err = svntest.actions.run_and_verify_svn(
+    None, None, [], 'log', sbox.wc_dir)
+
+  log_chain = parse_log_output (output)
+  if check_log_chain (log_chain, [0]):
+    raise svntest.Failure
+
 ########################################################################
 # Run the tests
 
@@ -530,6 +563,7 @@
               log_with_path_args,
               url_missing_in_head,
               log_through_copyfrom_history,
+              log_with_wc_at_revision_zero,
              ]
 
 if __name__ == '__main__':

-- Mike

-- 
Michael W. Thelen
Never express yourself more clearly than you are able to think.
                -- Niels Bohr

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Michael W Thelen <th...@cs.utah.edu>.
* kfogel@collab.net <kf...@collab.net> [2004-07-03 14:25]:
> Michael W Thelen <th...@cs.utah.edu> writes:
> > But speaking of elegance... both special case (a) and (b) seem to be
> > made necessary by the fact that we default to HEAD:1 and BASE:1 instead
> > of HEAD:0 and BASE:0 when the user passes no arguments to "svn log".
> > While writing the patch, I thought it would have been much nicer if we
> > could just pass HEAD:0 to ra_lib->get_log and have it "do the right
> > thing".  That is, produce an r0 log message when the start and end
> > revisions requested are both 0, but don't tack an r0 log message on the
> > end otherwise.
> 
> It's hard to imagine a circumstance under which the r0 logs could be
> relevant to anyone, since no user created r0.  And the behavior
> proposed above is... Well, let's just say I had to read it three times
> myself, and I was already thinking hard about the issue :-).  Do you
> really want to have to document that behavior for users?

Sorry, I don't think I made myself very clear.  I agree, no one really
wants an r0 log message, unless they explicitly request it with -r0 or
-r0:0.  My suggestion was that ra_lib->get_log's behavior could be
changed so that it never produces an r0 log message except when
requested in this way.

So requesting -r5:0, for example, would only produce log messages for r5
down through r1.  Currently, requesting -r5:0 produces log messages for
r5 through r1, plus a "No commit for revision 0" message.  That's the
only change to ra_lib->get_log that I'm proposing.

If this behavior were put in place, we could easily make both special
cases (a) and (b) go away by changing the default requests from
HEAD:1/BASE:1 to HEAD:0/BASE:0:

(a) The repository has 0 revisions and the user runs "svn log URL".
    Currently this is translated to HEAD:1 (0:1), which will produce an
    error because r1 doesn't exist.  If it were translated to HEAD:0
    (0:0), only a "No commit for revision 0" message would be produced.

(b) The working copy is at BASE revision 0 but the repository is not empty,
    and the user runs "svn log" in the working copy.  Currently this is
    translated to BASE:1 (0:1), which will produce an r1 log message
    even though the working copy is only at revision 0.  If it were
    translated to BASE:0 (0:0), only a "No commit for revision 0"
    message would be produced.

> (IOW, I'm punting on the question of interface compatibility, because
> even if this were compatible, I don't think we'd want to do it.)
> 
> I think r1 is a good default for almost all cases.  In the rare times
> when it's not, we can notice the problem, and handle the special case.

That's a fine solution, too.  I just thought that the client code would
be simpler without having to catch these special cases.  Making the
proposed change should only break client code that is relying on a "No
commit for revision 0" message when requesting a range including r0,
like -r5:0.  I would doubt that anyone does this, but I don't know.

Anyway, this discussion is a bit separate from the actual patch.  In a
little while I'll send a new patch containing what you suggested: only
the (b) special case handling, with the other changes removed.

-- Mike

-- 
Michael W. Thelen
Continued dependence upon relief induces a spiritual and moral disintegration
fundamentally destructive to the national fibre. To dole out relief in this
way is to administer a narcotic, a subtle destroyer of the human spirit.
                -- Franklin Delano Roosevelt

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by kf...@collab.net.
Michael W Thelen <th...@cs.utah.edu> writes:
> But speaking of elegance... both special case (a) and (b) seem to be
> made necessary by the fact that we default to HEAD:1 and BASE:1 instead
> of HEAD:0 and BASE:0 when the user passes no arguments to "svn log".
> While writing the patch, I thought it would have been much nicer if we
> could just pass HEAD:0 to ra_lib->get_log and have it "do the right
> thing".  That is, produce an r0 log message when the start and end
> revisions requested are both 0, but don't tack an r0 log message on the
> end otherwise.

It's hard to imagine a circumstance under which the r0 logs could be
relevant to anyone, since no user created r0.  And the behavior
proposed above is... Well, let's just say I had to read it three times
myself, and I was already thinking hard about the issue :-).  Do you
really want to have to document that behavior for users?

(IOW, I'm punting on the question of interface compatibility, because
even if this were compatible, I don't think we'd want to do it.)

I think r1 is a good default for almost all cases.  In the rare times
when it's not, we can notice the problem, and handle the special case.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Michael W Thelen <th...@cs.utah.edu>.
* Greg Hudson <gh...@MIT.EDU> [2004-07-02 13:27]:
> > The client cannot know the HEAD revision without asking the server.
> > Therefore, if we want to avoid issuing a bogus request, we must ask
> > the server for the HEAD revision first.  That causes an extra network
> > turnaround (see r1864), which in most cases is a useless burden,
> > because it's a rare repository where HEAD == 0
> 
> Well, I think it's inelegant for any valid, non-erroneous user operation
> to involve producing and ignoring an error; it suggests that something
> is wrong.  Perhaps what's really wrong here is that ra_lib->get_log has
> the wrong defaults, but we can't easily fix that.
> 
> So, while I think it's more elegant to spend a network turnaround in
> order to avoid the possibility of producing a spurious error (in
> general, a small constant number of network turnarounds is no big deal),
> it's certainly not "insane" to think otherwise.  So, my comment can be
> changed from a strong preference to a mild preference.

I agree with that... it just feels wrong to issue a bogus request and
catch an error under normal conditions.  But the network overhead of
issuing the request every time may outweigh the inelegance of producing
and catching a bogus error.

But speaking of elegance... both special case (a) and (b) seem to be
made necessary by the fact that we default to HEAD:1 and BASE:1 instead
of HEAD:0 and BASE:0 when the user passes no arguments to "svn log".
While writing the patch, I thought it would have been much nicer if we
could just pass HEAD:0 to ra_lib->get_log and have it "do the right
thing".  That is, produce an r0 log message when the start and end
revisions requested are both 0, but don't tack an r0 log message on the
end otherwise.

Is it allowable to make a change like this?  I thought probably not,
since it's a change in how the interface behaves, but wasn't sure.

-- Mike

-- 
Michael W. Thelen
It is the duty of every citizen according to his best capacities to give
validity to his convictions in political affairs.
                -- Albert Einstein, "Treasury for the Free World", 1946

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by kf...@collab.net.
Greg Hudson <gh...@MIT.EDU> writes:
> I may have misunderstood the code, not realizing that
> svn_client__get_revision_number doesn't always fully resolve the
> revision number (it evaluates HEAD by making a query, but returns
> SVN_INVALID_REVNUM if the revision isn't specified at all).

Ah.

> > The client cannot know the HEAD revision without asking the server.
> > Therefore, if we want to avoid issuing a bogus request, we must ask
> > the server for the HEAD revision first.  That causes an extra network
> > turnaround (see r1864), which in most cases is a useless burden,
> > because it's a rare repository where HEAD == 0
> 
> Well, I think it's inelegant for any valid, non-erroneous user operation
> to involve producing and ignoring an error; it suggests that something
> is wrong.  Perhaps what's really wrong here is that ra_lib->get_log has
> the wrong defaults, but we can't easily fix that.
> 
> So, while I think it's more elegant to spend a network turnaround in
> order to avoid the possibility of producing a spurious error (in
> general, a small constant number of network turnarounds is no big deal),
> it's certainly not "insane" to think otherwise.  So, my comment can be
> changed from a strong preference to a mild preference.

Ok, thanks for the quick response.

I guess all I can say is, I don't find it inelegant.  The generation
and catching of an error is entirely an internal implementation
detail, the same way it is in, say, svn_io_open_unique_file().  It's
simply an efficient way to get the desired result.  (Well, in
svn_io_open_unique_file() it's also a matter of correctness, but I
think the example still holds.)

Extra network turnarounds bother me much more, as they can start to be
significant on a high-latency network.  "A million here, a million
there, pretty soon you're talking about real money..."

So I hope Michael will just do part (b) of his patch.

-Karl

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by Greg Hudson <gh...@MIT.EDU>.
On Fri, 2004-07-02 at 13:02, kfogel@collab.net wrote:
> But in any case, I don't understand his comment: "We have every
> ability to avoid requesting a log of r0 through r1 when the head
> revision is 0, so there is no reason to issue a bogus request and
> catch the error."
> 
> Uh, how exactly do we have this ability?

I may have misunderstood the code, not realizing that
svn_client__get_revision_number doesn't always fully resolve the
revision number (it evaluates HEAD by making a query, but returns
SVN_INVALID_REVNUM if the revision isn't specified at all).

> The client cannot know the HEAD revision without asking the server.
> Therefore, if we want to avoid issuing a bogus request, we must ask
> the server for the HEAD revision first.  That causes an extra network
> turnaround (see r1864), which in most cases is a useless burden,
> because it's a rare repository where HEAD == 0

Well, I think it's inelegant for any valid, non-erroneous user operation
to involve producing and ignoring an error; it suggests that something
is wrong.  Perhaps what's really wrong here is that ra_lib->get_log has
the wrong defaults, but we can't easily fix that.

So, while I think it's more elegant to spend a network turnaround in
order to avoid the possibility of producing a spurious error (in
general, a small constant number of network turnarounds is no big deal),
it's certainly not "insane" to think otherwise.  So, my comment can be
changed from a strong preference to a mild preference.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #692: Handle "svn log" with empty repos

Posted by kf...@collab.net.
Michael W Thelen <th...@cs.utah.edu> writes:
> Here's an attempt at fixing issue #692 the right way.

Okay, I'm looking carefully at issue #692 now, and the history of this
problem.  I have some questions:

In the issue, Greg Hudson writes:

> The workaround in r1864 is ridiculous.  We have every ability to
> avoid requesting a log of r0 through r1 when the head revision is 0,
> so there is no reason to issue a bogus request and catch the error.
> I'm reopening this issue until there is a saner fix.

First, note that r1864 didn't introduce the error-catch.  It used an
unconditional extra network turnaround to determine the youngest
revision.  Then r1874 changed that into a conditional: *if* we got
back a certain error from the server, *then* do the extra network
turnaround to determine youngest rev, and enter the special case.

So I'll assume Greg's really talking about r1864 and r1874.

But in any case, I don't understand his comment: "We have every
ability to avoid requesting a log of r0 through r1 when the head
revision is 0, so there is no reason to issue a bogus request and
catch the error."

Uh, how exactly do we have this ability?

The client cannot know the HEAD revision without asking the server.
Therefore, if we want to avoid issuing a bogus request, we must ask
the server for the HEAD revision first.  That causes an extra network
turnaround (see r1864), which in most cases is a useless burden,
because it's a rare repository where HEAD == 0

Thus, the solution is to issue the possibly-bogus request, see if we
get an error indicating this particular kind of bogosity, and only
*then* fall into a network-inefficient behavior.

This seems eminently reasonable to me, not at all "ridiculous".

Maybe there's something I'm missing here, but I'll need a more
detailed explanation from Greg or someone to see what it is.

Okay, that brings us to your patch.

I have no conceptual problem with part (b) of your patch.  That WC
BASE special case deserves to be handled better.

But part (a) reintroduces the extra network turnaround that I got rid
of in r1874.

I'd like to understand why r1874 is not a good solution, and why it is
preferable to have an extra network turnaround instead?

(I haven't reviewed the part (b) code carefully yet, since it's still
mixed in with the part (a) code.  When we all get on the same page
about exactly *what* we're trying to do here, then it'll be time for
line-level code review. :-) )

Thanks,
-Karl

> Log:
> Fix issue #692 the right way.  There are two special cases to be handled:
> 
> (a) The repository has 0 revisions and the user runs "svn log URL": it
>     is as if the user had requested -rHEAD:1.  We don't want to error
>     out just because r1 doesn't exist.
> 
> (b) The working copy is at BASE revision 0 but the repository is not
>     empty, and the user runs "svn log" in the working copy: it is as if
>     the user requested -rBASE:1.  We don't want to print the log message
>     for r1, since the working copy is at r0.
> 
> * subversion/include/svn_client.h
>   (svn_client_log): Add documentation for special case (b).
> 
> * subversion/libsvn_client/log.c
>   (svn_client_log): Detect both special case conditions before requesting
>   logs from the server.  If either one occurs, invoke the log message
>   receiver manually with a message for revision 0.
> 
> Index: subversion/include/svn_client.h
> ===================================================================
> --- subversion/include/svn_client.h	(revision 10111)
> +++ subversion/include/svn_client.h	(working copy)
> @@ -753,6 +753,19 @@
>   * revision 1.  That works fine, except when there are no commits in
>   * the repository, hence this special case.
>   *
> + * Special case for working copies at revision 0:
> + *
> + * If @a start->kind is @c svn_opt_revision_base, and @a end->kind is
> + * @c svn_opt_revision_number && @a end->number is @c 1, then handle an
> + * a working copy at revision 0 specially: instead of invoking @a receiver
> + * on revisions 0 through 1, only invoke @a receiver on revision 0, passing
> + * @c NULL for changed paths and empty strings for the author and date.  This
> + * is because that particular combination of @a start and @a end usually
> + * indicates the common case of log invocation from the working copy -- the
> + * user wants to see all log messages from the BASE revision back through
> + * revision 1.  That works fine, except when the BASE revision is 0, hence
> + * this special case.
> + *
>   * If @a ctx->notify_func is non-null, then call @a ctx->notify_func/baton
>   * with a 'skip' signal on any unversioned targets.
>   *
> Index: subversion/libsvn_client/log.c
> ===================================================================
> --- subversion/libsvn_client/log.c	(revision 10111)
> +++ subversion/libsvn_client/log.c	(working copy)
> @@ -113,7 +113,7 @@
>        apr_array_header_t *target_urls;
>        apr_array_header_t *real_targets;
>        int i;
> -      
> +
>        /* Get URLs for each target */
>        target_urls = apr_array_make (pool, 1, sizeof (const char *));
>        real_targets = apr_array_make (pool, 1, sizeof (const char *));
> @@ -135,7 +135,7 @@
>                                       svn_wc_notify_state_unknown,
>                                       SVN_INVALID_REVNUM);
>  
> -              
> +
>                continue;
>              }
>            if (! entry->url)
> @@ -175,6 +175,33 @@
>                                          (NULL != base_name), TRUE, 
>                                          ctx, pool));
>  
> +  /* Special case: If there have been no commits, we'll get an error
> +   * for requesting log of a revision higher than 0.  But the
> +   * default behavior of "svn log" when given a URL is to give revisions HEAD
> +   * through 1, on the assumption that HEAD >= 1.  So if we see a start
> +   * revision of HEAD and an end revision of 1, then we just invoke the
> +   * receiver manually on a hand-constructed log message for revision 0.
> +   *
> +   * See also http://subversion.tigris.org/issues/show_bug.cgi?id=692.
> +   */
> +  {
> +    svn_revnum_t youngest_rev;
> +    SVN_ERR (ra_lib->get_latest_revnum (session, &youngest_rev, pool));
> +    if ((start->kind == svn_opt_revision_head)
> +        && (youngest_rev == 0)
> +        && (end->kind == svn_opt_revision_number)
> +        && (end->value.number == 1))
> +      {
> +        /* Log receivers are free to handle revision 0 specially... But
> +           just in case some don't, we make up a message here. */
> +        SVN_ERR (receiver (receiver_baton,
> +                           NULL, 0, "", "", _("No commits in repository"),
> +                           pool));
> +
> +        return SVN_NO_ERROR;
> +      }
> +  }
> +
>    /* It's a bit complex to correctly handle the special revision words
>     * such as "BASE", "COMMITTED", and "PREV".  For example, if the
>     * user runs
> @@ -243,20 +270,50 @@
>              if (start_is_local)
>                SVN_ERR (svn_client__get_revision_number
>                         (&start_revnum, ra_lib, session, start, target, pool));
> -            
> +
>              if (end_is_local)
>                SVN_ERR (svn_client__get_revision_number
>                         (&end_revnum, ra_lib, session, end, target, pool));
>  
> -            err = ra_lib->get_log (session,
> -                                   condensed_targets,
> -                                   start_revnum,
> -                                   end_revnum,
> -                                   discover_changed_paths,
> -                                   strict_node_history,
> -                                   receiver,
> -                                   receiver_baton,
> -                                   pool);
> +            /* Special case: If the BASE revision is 0 but the HEAD revision
> +             * of the repository is > 0, then we'll get the log message for
> +             * revision 1 when running "svn log" with no arguments in the
> +             * working copy.  That's because the default behavior of "svn log"
> +             * in a working copy is to give revisions BASE through 1, on the
> +             * assumption that BASE >= 1.  So if we see a start revision of
> +             * BASE and an end revision of 1, then we just invoke the receiver
> +             * manually on a hand-constructed log message for revision 0.
> +             *
> +             * See also
> +             * http://subversion.tigris.org/issues/show_bug.cgi?id=692.
> +             */
> +            if ((start->kind == svn_opt_revision_base)
> +              && (start_revnum == 0)
> +              && (end->kind == svn_opt_revision_number)
> +              && (end->value.number == 1))
> +              {
> +                err = SVN_NO_ERROR;
> +
> +                /* Log receivers are free to handle revision 0 specially... But
> +                   just in case some don't, we make up a message here. */
> +                SVN_ERR (receiver (receiver_baton,
> +                                   NULL, 0, "", "",
> +                                   _("No commits in BASE revision"),
> +                                   pool));
> +              }
> +            else
> +              {
> +                err = ra_lib->get_log (session,
> +                                       condensed_targets,
> +                                       start_revnum,
> +                                       end_revnum,
> +                                       discover_changed_paths,
> +                                       strict_node_history,
> +                                       receiver,
> +                                       receiver_baton,
> +                                       pool);
> +              }
> +
>              if (err)
>                break;
>            }
> @@ -273,40 +330,7 @@
>                                 receiver_baton,
>                                 pool);
>        }
> -    
> -    /* Special case: If there have been no commits, we'll get an error
> -     * for requesting log of a revision higher than 0.  But the
> -     * default behavior of "svn log" is to give revisions HEAD through
> -     * 1, on the assumption that HEAD >= 1.
> -     *
> -     * So if we got that error for that reason, and it looks like the
> -     * user was just depending on the defaults (rather than explicitly
> -     * requesting the log for revision 1), then we don't error.  Instead
> -     * we just invoke the receiver manually on a hand-constructed log
> -     * message for revision 0.
> -     *
> -     * See also http://subversion.tigris.org/issues/show_bug.cgi?id=692.
> -     */
> -    if (err && (err->apr_err == SVN_ERR_FS_NO_SUCH_REVISION)
> -        && (start->kind == svn_opt_revision_head)
> -        && ((end->kind == svn_opt_revision_number)
> -            && (end->value.number == 1)))
> -      {
> -        svn_revnum_t youngest_rev;
> -        
> -        SVN_ERR (ra_lib->get_latest_revnum (session, &youngest_rev, pool));
> -        if (youngest_rev == 0)
> -          {
> -            err = SVN_NO_ERROR;
> -            
> -            /* Log receivers are free to handle revision 0 specially... But
> -               just in case some don't, we make up a message here. */
> -            SVN_ERR (receiver (receiver_baton,
> -                               NULL, 0, "", "", _("No commits in repository."),
> -                               pool));
> -          }
> -      }
>    }
> -  
> +
>    return err;
>  }
> 
> -- Mike
> 
> -- 
> Michael W. Thelen
> It is a painful thing
> To look at your own trouble and know
> That you yourself and no one else has made it
>                 -- Sophocles, "Ajax"

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org