You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2013/04/10 19:08:32 UTC
svn commit: r1466570 - in /subversion/trunk/subversion: include/svn_subst.h
libsvn_client/cat.c libsvn_client/export.c libsvn_client/import.c
libsvn_subr/subst.c libsvn_wc/translate.c svn/svn.c
tests/libsvn_subr/subst_translate-test.c
Author: stsp
Date: Wed Apr 10 17:08:31 2013
New Revision: 1466570
URL: http://svn.apache.org/r1466570
Log:
Add support for custom keyword definitions, fixing issue #890.
Custom keywords can be defined using a format string which controls
the way keyword information is expanded. For instance, a keyword set
the command 'svn propset svn:keywords MyKeyword=%a%_%b%_%d myfile'
can be referenced in 'myfile' as $MyKeyword$, and expands to the author,
a space, the file's name ('myfile'), another space, and the short
representation of the date of the last-changed revision.
The following format codes are currently available:
%a - The author.
%b - The basename of the URL.
%d - Short format of the date.
%D - Long format of the date.
%P - The file's path, relative to the repository root URL.
%r - The revision.
%R - The URL to the root of the repository.
%u - The URL of the file.
%_ - A space (keyword definitions cannot contain a literal space).
% - A literal '%'.
Most of these were already defined internally in libsvn_subr.
This patch adds the %P, %R, and %_ format codes.
More format codes could be added in the future but might require API changes.
Based on a patch submitted several times by various FreeBSD developers
who have added this feature to their port of Subversion.
I'm crediting those who I know were involved in this patch in one way
or another. But I don't know for sure who wrote the initial implementation.
Patch by: Peter Wemm <pe...@FreeBSD.org>
David O'Brien <ob...@FreeBSD.org>
Lev A. Serebryakov <le...@FreeBSD.org>
Alfred Perlstein <al...@FreeBSD.org>
me
* subversion/include/svn_subst.h
(svn_subst_build_keywords3): Declare.
(svn_subst_build_keywords2): Deprecate.
* subversion/libsvn_client/cat.c
(svn_client__get_normalized_stream): Call svn_subst_build_keywords3().
* subversion/libsvn_client/export.c
(export_node, close_file): Call svn_subst_build_keywords3().
* subversion/libsvn_client/import.c
(send_file_contents): Call svn_subst_build_keywords3().
* subversion/libsvn_subr/subst.c
(keyword_printf): Add support for %P, %R, and %_. Add repos_root_url
parameter which is required to implement these new format codes.
(build_keywords): New helper function which implements the guts of
svn_subst_build_keywords2() and svn_subst_build_keywords3().
(svn_subst_build_keywords2): Reimplement as wrapper around build_keywords().
Turn off support for custom keywords to ensure backwards compatibility.
(svn_subst_build_keywords3): New, implemented as wrapper around the
build_keywords() helper. Enable support for custom keywords.
* subversion/libsvn_wc/translate.c
(svn_wc__expand_keywords): Call svn_subst_build_keywords3().
* subversion/svn/svn.c
(svn_cl__cmd_table): Document the custom keywords feature, including the
support format codes, in the output of 'svn help propset'.
* subversion/tests/libsvn_subr/subst_translate-test.c
(test_svn_subst_build_keywords3): New test.
(test_funcs): Add new test.
Modified:
subversion/trunk/subversion/include/svn_subst.h
subversion/trunk/subversion/libsvn_client/cat.c
subversion/trunk/subversion/libsvn_client/export.c
subversion/trunk/subversion/libsvn_client/import.c
subversion/trunk/subversion/libsvn_subr/subst.c
subversion/trunk/subversion/libsvn_wc/translate.c
subversion/trunk/subversion/svn/svn.c
subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c
Modified: subversion/trunk/subversion/include/svn_subst.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_subst.h?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_subst.h (original)
+++ subversion/trunk/subversion/include/svn_subst.h Wed Apr 10 17:08:31 2013
@@ -127,13 +127,29 @@ typedef struct svn_subst_keywords_t
* Set @a *kw to a new keywords hash filled with the appropriate contents
* given a @a keywords_string (the contents of the svn:keywords
* property for the file in question), the revision @a rev, the @a url,
- * the @a date the file was committed on, and the @a author of the last
- * commit.
+ * the @a date the file was committed on, the @a author of the last
+ * commit, and the URL of the repository root @a repos_root_url.
*
- * Any of the inputs @a rev, @a url, @a date and @a author can be @c NULL,
- * or @c 0 for @a date, to indicate that the information is not present.
- * Each piece of information that is not present expands to the empty
- * string wherever it appears in an expanded keyword value. (This can
+ * Custom keywords defined in svn:keywords properties are expanded
+ * using the provided parameters and in accordance with the following
+ * format substitutions in the @a keywords_string:
+ * %a - The author.
+ * %b - The basename of the URL.
+ * %d - Short format of the date.
+ * %D - Long format of the date.
+ * %P - The file's path, relative to the repository root URL.
+ * %r - The revision.
+ * %R - The URL to the root of the repository.
+ * %u - The URL of the file.
+ * %_ - A space (keyword definitions cannot contain a literal space).
+ * % - A literal '%'.
+ * Custom keywords are defined by appending '=' to the keyword name, followed
+ * by a string containing any combination of the format substitutions.
+ *
+ * Any of the inputs @a rev, @a url, @a date, @a author, and @a repos_root_url
+ * can be @c NULL, or @c 0 for @a date, to indicate that the information is
+ * not present. Each piece of information that is not present expands to the
+ * empty string wherever it appears in an expanded keyword value. (This can
* result in multiple adjacent spaces in the expansion of a multi-valued
* keyword such as "Id".)
*
@@ -142,8 +158,26 @@ typedef struct svn_subst_keywords_t
*
* All memory is allocated out of @a pool.
*
+ * @since New in 1.8.
+ */
+svn_error_t *
+svn_subst_build_keywords3(apr_hash_t **kw,
+ const char *keywords_string,
+ const char *rev,
+ const char *url,
+ const char *repos_root_url,
+ apr_time_t date,
+ const char *author,
+ apr_pool_t *pool);
+
+/** Similar to svn_subst_build_keywords3() except that it does not accept
+ * the @a repos_root_url parameter and hence supports less substitutions,
+ * and also does not support custom keyword definitions.
+ *
* @since New in 1.3.
+ * @deprecated Provided for backward compatibility with the 1.7 API.
*/
+SVN_DEPRECATED
svn_error_t *
svn_subst_build_keywords2(apr_hash_t **kw,
const char *keywords_string,
Modified: subversion/trunk/subversion/libsvn_client/cat.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/cat.c?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/cat.c (original)
+++ subversion/trunk/subversion/libsvn_client/cat.c Wed Apr 10 17:08:31 2013
@@ -124,12 +124,16 @@ svn_client__get_normalized_stream(svn_st
const char *author;
const char *url;
apr_time_t tm;
+ const char *repos_root_url;
SVN_ERR(svn_wc__node_get_changed_info(&changed_rev, &tm, &author, wc_ctx,
local_abspath, scratch_pool,
scratch_pool));
SVN_ERR(svn_wc__node_get_url(&url, wc_ctx, local_abspath, scratch_pool,
scratch_pool));
+ SVN_ERR(svn_wc__node_get_repos_info(NULL, NULL, &repos_root_url, NULL,
+ wc_ctx, local_abspath, scratch_pool,
+ scratch_pool));
if (local_mod)
{
@@ -152,8 +156,9 @@ svn_client__get_normalized_stream(svn_st
rev_str = apr_psprintf(scratch_pool, "%ld", changed_rev);
}
- SVN_ERR(svn_subst_build_keywords2(&kw, keywords->data, rev_str, url, tm,
- author, scratch_pool));
+ SVN_ERR(svn_subst_build_keywords3(&kw, keywords->data, rev_str, url,
+ repos_root_url, tm, author,
+ scratch_pool));
}
/* Wrap the output stream if translation is needed. */
@@ -181,6 +186,7 @@ svn_client_cat2(svn_stream_t *out,
svn_string_t *eol_style;
svn_string_t *keywords;
apr_hash_t *props;
+ const char *repos_root_url;
svn_stream_t *output = out;
svn_error_t *err;
@@ -225,6 +231,9 @@ svn_client_cat2(svn_stream_t *out,
peg_revision,
revision, ctx, pool));
+ /* Find the repos root URL */
+ SVN_ERR(svn_ra_get_repos_root2(ra_session, &repos_root_url, pool));
+
/* Grab some properties we need to know in order to figure out if anything
special needs to be done with this file. */
err = svn_ra_get_file(ra_session, "", loc->rev, NULL, NULL, &props, pool);
@@ -272,13 +281,12 @@ svn_client_cat2(svn_stream_t *out,
if (cmt_date)
SVN_ERR(svn_time_from_cstring(&when, cmt_date->data, pool));
- SVN_ERR(svn_subst_build_keywords2
- (&kw, keywords->data,
- cmt_rev->data,
- loc->url,
- when,
- cmt_author ? cmt_author->data : NULL,
- pool));
+ SVN_ERR(svn_subst_build_keywords3(&kw, keywords->data,
+ cmt_rev->data, loc->url,
+ repos_root_url, when,
+ cmt_author ?
+ cmt_author->data : NULL,
+ pool));
}
else
kw = NULL;
Modified: subversion/trunk/subversion/libsvn_client/export.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/export.c?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/export.c (original)
+++ subversion/trunk/subversion/libsvn_client/export.c Wed Apr 10 17:08:31 2013
@@ -392,10 +392,11 @@ export_node(void *baton,
suffix = "";
}
- SVN_ERR(svn_subst_build_keywords2
- (&kw, keywords->data,
- apr_psprintf(scratch_pool, "%ld%s", changed_rev, suffix),
- url, tm, author, scratch_pool));
+ SVN_ERR(svn_subst_build_keywords3(&kw, keywords->data,
+ apr_psprintf(scratch_pool, "%ld%s",
+ changed_rev, suffix),
+ url, status->repos_root_url, tm,
+ author, scratch_pool));
}
/* For atomicity, we translate to a tmp file and then rename the tmp file
@@ -541,6 +542,7 @@ struct file_baton
/* Any keyword vals to be substituted */
const char *revision;
const char *url;
+ const char *repos_root_url;
const char *author;
apr_time_t date;
@@ -662,6 +664,7 @@ add_file(const char *path,
fb->edit_baton = eb;
fb->path = full_path;
fb->url = full_url;
+ fb->repos_root_url = eb->root_url;
fb->pool = pool;
*baton = fb;
@@ -827,8 +830,9 @@ close_file(void *file_baton,
}
if (fb->keywords_val)
- SVN_ERR(svn_subst_build_keywords2(&final_kw, fb->keywords_val->data,
- fb->revision, fb->url, fb->date,
+ SVN_ERR(svn_subst_build_keywords3(&final_kw, fb->keywords_val->data,
+ fb->revision, fb->url,
+ fb->repos_root_url, fb->date,
fb->author, pool));
SVN_ERR(svn_subst_copy_and_translate4(fb->tmppath, fb->path,
Modified: subversion/trunk/subversion/libsvn_client/import.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/import.c?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/import.c (original)
+++ subversion/trunk/subversion/libsvn_client/import.c Wed Apr 10 17:08:31 2013
@@ -134,9 +134,9 @@ send_file_contents(const char *local_abs
}
if (keywords_val)
- SVN_ERR(svn_subst_build_keywords2(&keywords, keywords_val->data,
+ SVN_ERR(svn_subst_build_keywords3(&keywords, keywords_val->data,
APR_STRINGIFY(SVN_INVALID_REVNUM),
- "", 0, "", pool));
+ "", "", 0, "", pool));
else
keywords = NULL;
Modified: subversion/trunk/subversion/libsvn_subr/subst.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/subst.c?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/subst.c (original)
+++ subversion/trunk/subversion/libsvn_subr/subst.c Wed Apr 10 17:08:31 2013
@@ -136,8 +136,11 @@ svn_subst_translation_required(svn_subst
* %b basename of the URL of this file
* %d short format of date of this revision
* %D long format of date of this revision
+ * %P path relative to root of repos
* %r number of this revision
+ * %R root url of repository
* %u URL of this file
+ * %_ a space
* %% a literal %
*
* All memory is allocated out of @a pool.
@@ -146,6 +149,7 @@ static svn_string_t *
keyword_printf(const char *fmt,
const char *rev,
const char *url,
+ const char *repos_root_url,
apr_time_t date,
const char *author,
apr_pool_t *pool)
@@ -204,6 +208,21 @@ keyword_printf(const char *fmt,
svn_stringbuf_appendcstr(value,
svn_time_to_human_cstring(date, pool));
break;
+ case 'P': /* relative path of this file */
+ if (repos_root_url && url &&
+ svn_path_is_url(repos_root_url) && svn_path_is_url(url))
+ {
+ const char *repos_relpath;
+
+ repos_relpath = svn_uri_skip_ancestor(repos_root_url, url, pool);
+ if (repos_relpath)
+ svn_stringbuf_appendcstr(value, repos_relpath);
+ }
+ break;
+ case 'R': /* root of repos */
+ if (repos_root_url && svn_path_is_url(repos_root_url))
+ svn_stringbuf_appendcstr(value, repos_root_url);
+ break;
case 'r': /* number of this revision */
if (rev)
svn_stringbuf_appendcstr(value, rev);
@@ -212,6 +231,9 @@ keyword_printf(const char *fmt,
if (url)
svn_stringbuf_appendcstr(value, url);
break;
+ case '_': /* '%_' => a space */
+ svn_stringbuf_appendbyte(value, ' ');
+ break;
case '%': /* '%%' => a literal % */
svn_stringbuf_appendbyte(value, *cur);
break;
@@ -278,14 +300,16 @@ svn_subst_build_keywords(svn_subst_keywo
return SVN_NO_ERROR;
}
-svn_error_t *
-svn_subst_build_keywords2(apr_hash_t **kw,
- const char *keywords_val,
- const char *rev,
- const char *url,
- apr_time_t date,
- const char *author,
- apr_pool_t *pool)
+static svn_error_t *
+build_keywords(apr_hash_t **kw,
+ svn_boolean_t expand_custom_keywords,
+ const char *keywords_val,
+ const char *rev,
+ const char *url,
+ const char *repos_root_url,
+ apr_time_t date,
+ const char *author,
+ apr_pool_t *pool)
{
apr_array_header_t *keyword_tokens;
int i;
@@ -297,14 +321,36 @@ svn_subst_build_keywords2(apr_hash_t **k
for (i = 0; i < keyword_tokens->nelts; ++i)
{
const char *keyword = APR_ARRAY_IDX(keyword_tokens, i, const char *);
-
- if ((! strcmp(keyword, SVN_KEYWORD_REVISION_LONG))
- || (! strcmp(keyword, SVN_KEYWORD_REVISION_MEDIUM))
- || (! svn_cstring_casecmp(keyword, SVN_KEYWORD_REVISION_SHORT)))
+ apr_array_header_t *custom_keyword_tokens = NULL;
+
+ if (expand_custom_keywords)
+ custom_keyword_tokens = svn_cstring_split(keyword, "=",
+ TRUE /* chop */, pool);
+ if (expand_custom_keywords && custom_keyword_tokens->nelts == 2)
+ {
+ const char *custom_fmt;
+ svn_string_t *custom_val;
+
+ /* Custom keywords must be allowed to match the name of an
+ * existing fixed keyword. This is for compatibility purposes,
+ * in case new fixed keywords are added to Subversion which
+ * happen to match a custom keyword defined somewhere.
+ * There is only one global namespace for keyword names. */
+
+ keyword = APR_ARRAY_IDX(custom_keyword_tokens, 0, const char*);
+ custom_fmt = APR_ARRAY_IDX(custom_keyword_tokens, 1, const char*);
+ custom_val = keyword_printf(custom_fmt, rev, url, repos_root_url,
+ date, author, pool);
+ svn_hash_sets(*kw, keyword, custom_val);
+ }
+ else if ((! strcmp(keyword, SVN_KEYWORD_REVISION_LONG))
+ || (! strcmp(keyword, SVN_KEYWORD_REVISION_MEDIUM))
+ || (! svn_cstring_casecmp(keyword, SVN_KEYWORD_REVISION_SHORT)))
{
svn_string_t *revision_val;
- revision_val = keyword_printf("%r", rev, url, date, author, pool);
+ revision_val = keyword_printf("%r", rev, url, repos_root_url,
+ date, author, pool);
svn_hash_sets(*kw, SVN_KEYWORD_REVISION_LONG, revision_val);
svn_hash_sets(*kw, SVN_KEYWORD_REVISION_MEDIUM, revision_val);
svn_hash_sets(*kw, SVN_KEYWORD_REVISION_SHORT, revision_val);
@@ -314,7 +360,8 @@ svn_subst_build_keywords2(apr_hash_t **k
{
svn_string_t *date_val;
- date_val = keyword_printf("%D", rev, url, date, author, pool);
+ date_val = keyword_printf("%D", rev, url, repos_root_url, date,
+ author, pool);
svn_hash_sets(*kw, SVN_KEYWORD_DATE_LONG, date_val);
svn_hash_sets(*kw, SVN_KEYWORD_DATE_SHORT, date_val);
}
@@ -323,7 +370,8 @@ svn_subst_build_keywords2(apr_hash_t **k
{
svn_string_t *author_val;
- author_val = keyword_printf("%a", rev, url, date, author, pool);
+ author_val = keyword_printf("%a", rev, url, repos_root_url, date,
+ author, pool);
svn_hash_sets(*kw, SVN_KEYWORD_AUTHOR_LONG, author_val);
svn_hash_sets(*kw, SVN_KEYWORD_AUTHOR_SHORT, author_val);
}
@@ -332,7 +380,8 @@ svn_subst_build_keywords2(apr_hash_t **k
{
svn_string_t *url_val;
- url_val = keyword_printf("%u", rev, url, date, author, pool);
+ url_val = keyword_printf("%u", rev, url, repos_root_url, date,
+ author, pool);
svn_hash_sets(*kw, SVN_KEYWORD_URL_LONG, url_val);
svn_hash_sets(*kw, SVN_KEYWORD_URL_SHORT, url_val);
}
@@ -340,16 +389,16 @@ svn_subst_build_keywords2(apr_hash_t **k
{
svn_string_t *id_val;
- id_val = keyword_printf("%b %r %d %a", rev, url, date, author,
- pool);
+ id_val = keyword_printf("%b %r %d %a", rev, url, repos_root_url,
+ date, author, pool);
svn_hash_sets(*kw, SVN_KEYWORD_ID, id_val);
}
else if ((! svn_cstring_casecmp(keyword, SVN_KEYWORD_HEADER)))
{
svn_string_t *header_val;
- header_val = keyword_printf("%u %r %d %a", rev, url, date, author,
- pool);
+ header_val = keyword_printf("%u %r %d %a", rev, url, repos_root_url,
+ date, author, pool);
svn_hash_sets(*kw, SVN_KEYWORD_HEADER, header_val);
}
}
@@ -357,6 +406,35 @@ svn_subst_build_keywords2(apr_hash_t **k
return SVN_NO_ERROR;
}
+svn_error_t *
+svn_subst_build_keywords2(apr_hash_t **kw,
+ const char *keywords_val,
+ const char *rev,
+ const char *url,
+ apr_time_t date,
+ const char *author,
+ apr_pool_t *pool)
+{
+ return svn_error_trace(build_keywords(kw, FALSE, keywords_val, rev, url,
+ NULL, date, author, pool));
+}
+
+
+svn_error_t *
+svn_subst_build_keywords3(apr_hash_t **kw,
+ const char *keywords_val,
+ const char *rev,
+ const char *url,
+ const char *repos_root_url,
+ apr_time_t date,
+ const char *author,
+ apr_pool_t *pool)
+{
+ return svn_error_trace(build_keywords(kw, TRUE, keywords_val,
+ rev, url, repos_root_url,
+ date, author, pool));
+}
+
/*** Helpers for svn_subst_translate_stream2 ***/
Modified: subversion/trunk/subversion/libsvn_wc/translate.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/translate.c?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/translate.c (original)
+++ subversion/trunk/subversion/libsvn_wc/translate.c Wed Apr 10 17:08:31 2013
@@ -314,10 +314,10 @@ svn_wc__expand_keywords(apr_hash_t **key
apr_time_t changed_date;
const char *changed_author;
const char *url;
+ const char *repos_root_url;
if (! for_normalization)
{
- const char *repos_root_url;
const char *repos_relpath;
SVN_ERR(svn_wc__db_read_info(NULL, NULL, NULL, &repos_relpath,
@@ -342,15 +342,22 @@ svn_wc__expand_keywords(apr_hash_t **key
changed_rev = SVN_INVALID_REVNUM;
changed_date = 0;
changed_author = "";
+
+ SVN_ERR(svn_wc__db_read_info(NULL, NULL, NULL, NULL,
+ &repos_root_url, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ db, local_abspath,
+ scratch_pool, scratch_pool));
}
- SVN_ERR(svn_subst_build_keywords2(keywords,
- keyword_list,
+ SVN_ERR(svn_subst_build_keywords3(keywords, keyword_list,
apr_psprintf(scratch_pool, "%ld",
changed_rev),
- url,
- changed_date,
- changed_author,
+ url, repos_root_url,
+ changed_date, changed_author,
result_pool));
if (apr_hash_count(*keywords) == 0)
Modified: subversion/trunk/subversion/svn/svn.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/svn.c?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/svn.c (original)
+++ subversion/trunk/subversion/svn/svn.c Wed Apr 10 17:08:31 2013
@@ -1281,6 +1281,23 @@ const svn_opt_subcommand_desc2_t svn_cl_
" LastChangedRevision\n"
" Id - A compressed summary of the previous four.\n"
" Header - Similar to Id but includes the full URL.\n"
+ "\n"
+ " Custom keywords can be defined with a format string separated from\n"
+ " the keyword name with '='. Valid format substitutions are:\n"
+ " %a - The author of the revision given by %r.\n"
+ " %b - The basename of the URL of the file.\n"
+ " %d - Short format of the date of the revision given by %r.\n"
+ " %D - Long format of the date of the revision given by %r.\n"
+ " %P - The file's path, relative to the repository root.\n"
+ " %r - The number of the revision which last changed the file.\n"
+ " %R - The URL to the root of the repository.\n"
+ " %u - The URL of the file.\n"
+ " %_ - A space (keyword definitions cannot contain a literal space).\n"
+ " % - A literal '%'.\n"
+ " Example custom keyword definition: MyKeyword=%r%_%a%_%P\n"
+ " Once a custom keyword has been defined for a file, it can be used\n"
+ " within the file like any other keyword: $MyKeyword$\n"
+ "\n"
" svn:executable - If present, make the file executable. Use\n"
" 'svn propdel svn:executable PATH...' to clear.\n"
" svn:eol-style - One of 'native', 'LF', 'CR', 'CRLF'.\n"
Modified: subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c?rev=1466570&r1=1466569&r2=1466570&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c Wed Apr 10 17:08:31 2013
@@ -23,12 +23,14 @@
#include <locale.h>
#include <string.h>
+#include <apr_time.h>
#include "../svn_test.h"
#include "svn_types.h"
#include "svn_string.h"
#include "svn_subst.h"
+#include "svn_hash.h"
#define ARRAY_LEN(ary) ((sizeof (ary)) / (sizeof ((ary)[0])))
@@ -246,6 +248,51 @@ test_svn_subst_translate_cstring2(apr_po
return SVN_NO_ERROR;
}
+static svn_error_t *
+test_svn_subst_build_keywords3(apr_pool_t *pool)
+{
+ /* Test expansion of custom keywords. */
+ struct keywords_tests_data
+ {
+ const char *keyword_name;
+ const char *keywords_string;
+ const char *expanded_keyword;
+ const char *rev;
+ const char *url;
+ const char *repos_root_url;
+ /* Can't test date since expanded value depends on local clock. */
+ const char *author;
+ }
+ tests[] =
+ {
+ {"FOO", "FOO=%P%_%a%_%b%_%%",
+ "trunk/foo.txt stsp foo.txt %",
+ "1234", "http://svn.example.com/repos/trunk/foo.txt",
+ "http://svn.example.com/repos", "stsp"},
+ {"MyKeyword", "MyKeyword=%r%_%u%_%_%a",
+ "4567 http://svn.example.com/svn/branches/myfile jrandom",
+ "4567", "http://svn.example.com/svn/branches/myfile",
+ "http://svn.example.com/svn", "jrandom"},
+ { NULL, NULL, NULL, NULL, NULL, NULL, NULL}
+ };
+
+ const struct keywords_tests_data *t;
+
+ for (t = tests; t->keyword_name != NULL; t++)
+ {
+ apr_hash_t *kw;
+ svn_string_t *expanded_keyword;
+
+ SVN_ERR(svn_subst_build_keywords3(&kw, t->keywords_string,
+ t->rev, t->url, t->repos_root_url,
+ 0 /* date */, t->author, pool));
+ expanded_keyword = svn_hash_gets(kw, t->keyword_name);
+ SVN_TEST_STRING_ASSERT(expanded_keyword->data, t->expanded_keyword);
+ }
+
+ return SVN_NO_ERROR;
+}
+
struct svn_test_descriptor_t test_funcs[] =
{
SVN_TEST_NULL,
@@ -257,5 +304,7 @@ struct svn_test_descriptor_t test_funcs[
"test repairing svn_subst_translate_string2()"),
SVN_TEST_PASS2(test_svn_subst_translate_cstring2,
"test svn_subst_translate_cstring2()"),
+ SVN_TEST_PASS2(test_svn_subst_build_keywords3,
+ "test svn_subst_build_keywords3()"),
SVN_TEST_NULL
};