Author: rinrab
Date: Wed May 28 15:28:14 2025
New Revision: 1925907

URL: http://svn.apache.org/viewvc?rev=1925907&view=rev
Log:
Add svn_opt_parse_revnum() function that parses revnum in format that
the cmdline (opt) accepts instead of relying on custom code.

This also allows revision number beginning with 'r' to be passed to
svnlook program.

Note: error messages may change a bit, but they will be improved because
this function can handle more special cases than the old custom code.

* subversion/include/svn_opt.h
  (svn_opt_parse_revnum): Declare.
* subversion/libsvn_subr/opt.c
  (svn_opt_parse_revnum): Implement.

* subversion/svnlook/svnlook.c
* subversion/svnmucc/svnmucc.c
  (sub_main): Use the function.

Modified:
    subversion/trunk/subversion/include/svn_opt.h
    subversion/trunk/subversion/libsvn_subr/opt.c
    subversion/trunk/subversion/svnlook/svnlook.c
    subversion/trunk/subversion/svnmucc/svnmucc.c

Modified: subversion/trunk/subversion/include/svn_opt.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_opt.h?rev=1925907&r1=1925906&r2=1925907&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_opt.h (original)
+++ subversion/trunk/subversion/include/svn_opt.h Wed May 28 15:28:14 2025
@@ -482,6 +482,24 @@ typedef struct svn_opt_revision_range_t
   svn_opt_revision_t end;
 } svn_opt_revision_range_t;
 
+
+/**
+ * Parse NULL-terminated C string @a str as a revision number and
+ * store its value in @a rev.
+ *
+ * If @a str is not a valid revision number, then the error
+ * #SVN_ERR_REVNUM_PARSE_FAILURE error is returned.  Negative numbers
+ * parsed from @a str are considered invalid, and result in the same error.
+ *
+ * Unlike svn_revnum_parse(), this function support our cmdline revision
+ * number format, whereas the revnum may be prefixed with an 'r' symbol.
+ *
+ * @since New in 1.15
+ * @see svn_revnum_parse()
+ */
+svn_error_t *
+svn_opt_parse_revnum(svn_revnum_t *rev, const char *str);
+
 /**
  * Set @a *start_revision and/or @a *end_revision according to @a arg,
  * where @a arg is "N" or "N:M", like so:

Modified: subversion/trunk/subversion/libsvn_subr/opt.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/opt.c?rev=1925907&r1=1925906&r2=1925907&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/opt.c (original)
+++ subversion/trunk/subversion/libsvn_subr/opt.c Wed May 28 15:28:14 2025
@@ -710,6 +710,16 @@ int svn_opt_parse_change_to_range(apr_ar
 }
 
 svn_error_t *
+svn_opt_parse_revnum(svn_revnum_t *rev, const char *str)
+{
+  /* Allow any number of 'r's to prefix a revision number. */
+  while (*str == 'r')
+    str++;
+
+  return svn_error_trace(svn_revnum_parse(rev, str, NULL));
+}
+
+svn_error_t *
 svn_opt_resolve_revisions(svn_opt_revision_t *peg_rev,
                           svn_opt_revision_t *op_rev,
                           svn_boolean_t is_url,

Modified: subversion/trunk/subversion/svnlook/svnlook.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnlook/svnlook.c?rev=1925907&r1=1925906&r2=1925907&view=diff
==============================================================================
--- subversion/trunk/subversion/svnlook/svnlook.c (original)
+++ subversion/trunk/subversion/svnlook/svnlook.c Wed May 28 15:28:14 2025
@@ -2529,15 +2529,7 @@ sub_main(int *exit_code,
       switch (opt_id)
         {
         case 'r':
-          {
-            char *digits_end = NULL;
-            opt_state.rev = strtol(opt_arg, &digits_end, 10);
-            if ((! SVN_IS_VALID_REVNUM(opt_state.rev))
-                || (! digits_end)
-                || *digits_end)
-              return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                                      _("Invalid revision number supplied"));
-          }
+          SVN_ERR(svn_opt_parse_revnum(&opt_state.rev, opt_arg));
           break;
 
         case 't':

Modified: subversion/trunk/subversion/svnmucc/svnmucc.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnmucc/svnmucc.c?rev=1925907&r1=1925906&r2=1925907&view=diff
==============================================================================
--- subversion/trunk/subversion/svnmucc/svnmucc.c (original)
+++ subversion/trunk/subversion/svnmucc/svnmucc.c Wed May 28 15:28:14 2025
@@ -824,18 +824,8 @@ sub_main(int *exit_code,
           if (svn_cstring_casecmp(rev_str, "head") == 0)
             action->rev = SVN_INVALID_REVNUM;
           else
-            {
-              char *end;
+            SVN_ERR(svn_opt_parse_revnum(&action->rev, rev_str));
 
-              while (*rev_str == 'r')
-                ++rev_str;
-
-              action->rev = strtol(rev_str, &end, 0);
-              if (*end)
-                return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
-                                         "'%s' is not a revision\n",
-                                         rev_str);
-            }
           if (++i == action_args->nelts)
             return insufficient();
         }


Reply via email to