Skip to content

Commit cbfaf22

Browse files
committed
Export a function for parsing a single opt_revision into the public API. We'll
probably use it in svnbrowse. Neither of other tools need it because they primarly operate over a revision range for which there is a separate function in the API. * subversion/include/svn_error_codes.h (SVN_ERR_OPT_REVISION_PARSE_ERROR): Define new error code. * subversion/include/svn_opt.h (svn_opt_parse_one_revision): Define function. * subversion/libsvn_subr/opt_revision.c (svn_opt_parse_one_revision): New function; forward most of the logic into parse_one_rev() + error handling and dup string. * subversion/tests/libsvn_subr/opt-test.c (test_parse_one_rev): New stupid test to cover up the fact that this function has zero usages (yet). (test_funcs): Run new test. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1932855 13f79535-47bb-0310-9956-ffa450edef68
1 parent d3712e8 commit cbfaf22

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

subversion/include/svn_error_codes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,11 @@ SVN_ERROR_START
14351435
SVN_ERR_MISC_CATEGORY_START + 31,
14361436
"Attempted to write to readonly SQLite db")
14371437

1438+
/** @since New in 1.16. */
1439+
SVN_ERRDEF(SVN_ERR_OPT_REVISION_PARSE_ERROR,
1440+
SVN_ERR_MISC_CATEGORY_START + 32,
1441+
"Error parsing revision argument")
1442+
14381443
/** @since New in 1.6.
14391444
* @deprecated the internal sqlite support code does not manage schemas
14401445
* any longer. */

subversion/include/svn_opt.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,18 @@ typedef struct svn_opt_revision_range_t
500500
svn_error_t *
501501
svn_opt_parse_revnum(svn_revnum_t *rev, const char *str);
502502

503+
/**
504+
* Parse one revision specification from @a arg into @a revision. Use @a
505+
* scratch_pool for temporary allocation.
506+
*
507+
* @since New in 1.16
508+
* @see svn_opt_parse_revision
509+
*/
510+
svn_error_t *
511+
svn_opt_parse_one_revision(svn_opt_revision_t *revision,
512+
const char *arg,
513+
apr_pool_t *scratch_pool);
514+
503515
/**
504516
* Set @a *start_revision and/or @a *end_revision according to @a arg,
505517
* where @a arg is "N" or "N:M", like so:

subversion/libsvn_subr/opt_revision.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ static char *parse_one_rev(svn_opt_revision_t *revision, char *str,
159159
return NULL;
160160
}
161161

162+
svn_error_t *
163+
svn_opt_parse_one_revision(svn_opt_revision_t *revision,
164+
const char *arg,
165+
apr_pool_t *scratch_pool)
166+
{
167+
/* copy because parse_one_rev() will mess up the string */
168+
char *str = apr_pstrdup(scratch_pool, arg);
169+
char *end = parse_one_rev(revision, str, scratch_pool);
170+
171+
if (! end || *end != '\0')
172+
return svn_error_createf(SVN_ERR_OPT_REVISION_PARSE_ERROR, NULL,
173+
"Error parsing revision argument '%s'", arg);
174+
175+
return SVN_NO_ERROR;
176+
}
162177

163178
int
164179
svn_opt_parse_revision(svn_opt_revision_t *start_revision,

subversion/tests/libsvn_subr/opt-test.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,31 @@ test_svn_opt_parse_change_to_range(apr_pool_t *pool)
263263
return SVN_NO_ERROR;
264264
}
265265

266+
static svn_error_t *
267+
test_parse_one_rev(apr_pool_t *pool)
268+
{
269+
{
270+
svn_opt_revision_t rev = { 0 };
271+
SVN_ERR(svn_opt_parse_one_revision(&rev, "r123", pool));
272+
SVN_TEST_INT_ASSERT(rev.kind, svn_opt_revision_number);
273+
SVN_TEST_INT_ASSERT(rev.value.number, 123);
274+
}
275+
276+
{
277+
svn_opt_revision_t rev = { 0 };
278+
SVN_TEST_ASSERT_ERROR(svn_opt_parse_one_revision(&rev, "bad", pool),
279+
SVN_ERR_OPT_REVISION_PARSE_ERROR);
280+
}
281+
282+
{
283+
svn_opt_revision_t rev = { 0 };
284+
SVN_TEST_ASSERT_ERROR(svn_opt_parse_one_revision(&rev, "r123bad", pool),
285+
SVN_ERR_OPT_REVISION_PARSE_ERROR);
286+
}
287+
288+
return SVN_NO_ERROR;
289+
}
290+
266291

267292
/* The test table. */
268293

@@ -277,6 +302,8 @@ static struct svn_test_descriptor_t test_funcs[] =
277302
"test svn_opt_args_to_target_array2"),
278303
SVN_TEST_PASS2(test_svn_opt_parse_change_to_range,
279304
"test svn_opt_parse_change_to_range"),
305+
SVN_TEST_PASS2(test_parse_one_rev,
306+
"test svn_opt_parse_one_revision"),
280307
SVN_TEST_NULL
281308
};
282309

0 commit comments

Comments
 (0)