Hi all, In one of my previous patches, I factored-out the svn_opt_parse_change_to_range from the svn program into the libsvn_subr library and added unit tests on it. However, a similar code block exists in the svnbench program, so I think it could be replaced with this function.
[[[ Use svn_opt_parse_change_to_range function to parse the --change argument in the svnbench program. In r1918076, the svn_opt_parse_change_to_range function was factored-out from the svn program into the libsvn_subr library. Since the same functionality is needed for parsing the same argument in the svnbench program, we can use this function there as well. Additionally, this refactoring would fix some parsing bugs related to this argument, which were resolved in the svn program [1], but still exist in the svnbench program, because this code was duplicated. * subversion/svnbench/svnbench.c (sub_main): Replace the code that parses the --change argument with svn_opt_parse_change_to_range function. [1] The fixes in the --change argument parser were committed in r1917944 and r1917864. Patch by: Timofey Zhakov (tima {at} chemodax _dot_ net) ]]] Thanks! -- Timofei Zhakov
Index: subversion/svnbench/svnbench.c =================================================================== --- subversion/svnbench/svnbench.c (revision 1918076) +++ subversion/svnbench/svnbench.c (working copy) @@ -482,86 +482,26 @@ sub_main(int *exit_code, int argc, const char *arg break; case 'c': { - apr_array_header_t *change_revs = - svn_cstring_split(opt_arg, ", \n\r\t\v", TRUE, pool); + apr_array_header_t *change_revs; + SVN_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool)); + change_revs = svn_cstring_split(utf8_opt_arg, ", \n\r\t\v", TRUE, + pool); + for (i = 0; i < change_revs->nelts; i++) { - char *end; - svn_revnum_t changeno, changeno_end; const char *change_str = APR_ARRAY_IDX(change_revs, i, const char *); - const char *s = change_str; - svn_boolean_t is_negative; - /* Check for a leading minus to allow "-c -r42". - * The is_negative flag is used to handle "-c -42" and "-c -r42". - * The "-c r-42" case is handled by strtol() returning a - * negative number. */ - is_negative = (*s == '-'); - if (is_negative) - s++; - - /* Allow any number of 'r's to prefix a revision number. */ - while (*s == 'r') - s++; - changeno = changeno_end = strtol(s, &end, 10); - if (end != s && *end == '-') + if (svn_opt_parse_change_to_range(opt_state.revision_ranges, + change_str, pool) != 0) { - if (changeno < 0 || is_negative) - { - return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, - NULL, - _("Negative number in range (%s)" - " not supported with -c"), - change_str); - } - s = end + 1; - while (*s == 'r') - s++; - changeno_end = strtol(s, &end, 10); - } - if (end == change_str || *end != '\0') - { return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL, - _("Non-numeric change argument (%s) " - "given to -c"), change_str); + _("Syntax error in change argument " + "'%s'"), change_str); } - if (changeno == 0) - { - return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL, - _("There is no change 0")); - } - - if (is_negative) - changeno = -changeno; - - /* Figure out the range: - -c N -> -r N-1:N - -c -N -> -r N:N-1 - -c M-N -> -r M-1:N for M < N - -c M-N -> -r M:N-1 for M > N - -c -M-N -> error (too confusing/no valid use case) - */ - if (changeno > 0) - { - if (changeno <= changeno_end) - changeno--; - else - changeno_end--; - } - else - { - changeno = -changeno; - changeno_end = changeno - 1; - } - opt_state.used_change_arg = TRUE; - APR_ARRAY_PUSH(opt_state.revision_ranges, - svn_opt_revision_range_t *) - = svn_opt__revision_range_from_revnums(changeno, changeno_end, - pool); } } break;