As promised, here is the first of two patch to implement keywords as
hashes. Both commit log message and patch are attached (log is also
below, probably wrapped horribly ;). NOTE: I have excised properties as
keywords from this version.
The Phase 1 patch only implements the core features and compatibility
layers; all other code in the Subversion core continues to use strictly
the 1.1 compatible function calls.
John
===================
Implement printf-like format characters for keyword expansion. See
Issue #890 for further information.
* includes/svn_subst.h:
deprecate svn_subst_keywords_t
(svn_subst_build_keywords2): Interface change. A new argument
const char *uuid.
(svn_subst_build_keywords): API compatibility wrapper for previous
(svn_subst_keywords_differ2): Interface change. A new argument
apr_pool_t *pool and use hash instead of struct.
(svn_subst_keywords_differ): API compatibility wrapper for previous
(svn_subst_copy_and_translate3): Interface change; hash instead of
struct
(svn_subst_copy_and_translate2): compatibility wrapper for translate3
(svn_subst_copy_and_translate): compatibility wrapper for translate3
(svn_subst_translate_cstring2): Interface change; hash instead of
struct
(svn_subst_translate_cstring): API compatibility wrapper for previous
(svn_subst_translate_stream2): Interface change; hash instead of struct
(svn_subst_translate_stream): API compatibility wrapper for previous
* includes/svn_types.h:
Define keyword format string for Revision, Date, Author, URL, UUID, ID
* libsvn_subr/svn_subst.c:
(keyword_printf): New private function; printf-style formatting of
keywords based on format strings
(keywords_to_keyhash): New private function; convert keywords
struct into
keywords hash
(keyhash_to_keywords): New private function; convert keywords hash into
keywords struct
(svn_subst_build_keywords): API combatibility wrapper
(svn_subst_build_keywords2): Build keywords using keyword_printf().
(translate_keyword): Interface changes. It now looks up keyword
passed in buffer, instead of predefined constant string.
(svn_subst_translate_stream): API combatibility wrapper
(svn_subst_translate_stream2): Loop over all elements of keyword hash
instead of structure elements.
(svn_subst_keywords_differ): API combatibility wrapper
(svn_subst_keywords_differ2): Compare two hashes instead of comparing
individual structure elements.
(svn_subst_copy_and_translate): API combatibility wrapper
(svn_subst_copy_and_translate2): API combatibility wrapper
(svn_subst_copy_and_translate3): uses keywords hash instead of struct
--
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4501 Forbes Boulevard
Suite H
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5748
Implement printf-like format characters for keyword expansion. See
Issue #890 for further information.
* includes/svn_subst.h:
deprecate svn_subst_keywords_t
(svn_subst_build_keywords2): Interface change. A new argument
const char *uuid.
(svn_subst_build_keywords): API compatibility wrapper for previous
(svn_subst_keywords_differ2): Interface change. A new argument
apr_pool_t *pool and use hash instead of struct.
(svn_subst_keywords_differ): API compatibility wrapper for previous
(svn_subst_copy_and_translate3): Interface change; hash instead of struct
(svn_subst_copy_and_translate2): compatibility wrapper for translate3
(svn_subst_copy_and_translate): compatibility wrapper for translate3
(svn_subst_translate_cstring2): Interface change; hash instead of struct
(svn_subst_translate_cstring): API compatibility wrapper for previous
(svn_subst_translate_stream2): Interface change; hash instead of struct
(svn_subst_translate_stream): API compatibility wrapper for previous
* includes/svn_types.h:
Define keyword format string for Revision, Date, Author, URL, UUID, ID
* libsvn_subr/svn_subst.c:
(keyword_printf): New private function; printf-style formatting of
keywords based on format strings
(keywords_to_keyhash): New private function; convert keywords struct into
keywords hash
(keyhash_to_keywords): New private function; convert keywords hash into
keywords struct
(svn_subst_build_keywords): API combatibility wrapper
(svn_subst_build_keywords2): Build keywords using keyword_printf().
(translate_keyword): Interface changes. It now looks up keyword
passed in buffer, instead of predefined constant string.
(svn_subst_translate_stream): API combatibility wrapper
(svn_subst_translate_stream2): Loop over all elements of keyword hash
instead of structure elements.
(svn_subst_keywords_differ): API combatibility wrapper
(svn_subst_keywords_differ2): Compare two hashes instead of comparing
individual structure elements.
(svn_subst_copy_and_translate): API combatibility wrapper
(svn_subst_copy_and_translate2): API combatibility wrapper
(svn_subst_copy_and_translate3): uses keywords hash instead of struct
=== subversion/include/svn_subst.h
==================================================================
--- subversion/include/svn_subst.h (/mirror/trunk) (revision 12209)
+++ subversion/include/svn_subst.h (/local/keywords-phase1) (revision 12209)
@@ -75,7 +75,9 @@
const char *value);
-/** Values used in keyword expansion. */
+/* struct svn_subst_keywords_t is @deprecated
+* Provided for backward compatibility with the 1.1 API.
+*/
typedef struct svn_subst_keywords_t
{
const svn_string_t *revision;
@@ -86,8 +88,11 @@
} svn_subst_keywords_t;
-/** Fill in an <tt>svn_subst_keywords_t *</tt> @a kw with the appropriate
- * contents given an @a keywords_string (the contents of the svn:keywords
+/**
+ * @since New in 1.2.
+ *
+ * Fill in an <tt>apr_hash_t*</tt> @a kw with the appropriate contents
+ * given an @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. Any of these can be @c NULL to indicate that the information is
@@ -96,6 +101,21 @@
* All memory is allocated out of @a pool.
*/
svn_error_t *
+svn_subst_build_keywords2 (apr_hash_t *kw,
+ const char *keywords_string,
+ const char *rev,
+ const char *url,
+ apr_time_t date,
+ const char *author,
+ const char *uuid,
+ apr_pool_t *pool);
+
+/** Similar to svn_subst_build_keywords2()
+ *
+ * @deprecated Provided for backward compatibility with the 1.1 API.
+ */
+
+svn_error_t *
svn_subst_build_keywords (svn_subst_keywords_t *kw,
const char *keywords_string,
const char *rev,
@@ -104,7 +124,6 @@
const char *author,
apr_pool_t *pool);
-
/** Return @c TRUE if @a a and @a b do not hold the same keywords.
*
* If @a compare_values is @c TRUE, "same" means that the @a a and @a b
@@ -117,6 +136,18 @@
* equivalent to holding no keywords.
*/
svn_boolean_t
+svn_subst_keywords_differ2 (const apr_hash_t *a,
+ const apr_hash_t *b,
+ svn_boolean_t compare_values,
+ apr_pool_t *pool);
+
+/** Similar to svn_subst_keywords_differ2(); provides a pool for performing
+ * the hash comparisons.
+ *
+ * @deprecated Provided for backward compatibility with the 1.1 API.
+ */
+
+svn_boolean_t
svn_subst_keywords_differ (const svn_subst_keywords_t *a,
const svn_subst_keywords_t *b,
svn_boolean_t compare_values);
@@ -155,6 +186,18 @@
* convenient way to get @a eol_str and @a keywords if in libsvn_wc.
*/
svn_error_t *
+svn_subst_translate_stream2 (svn_stream_t *src,
+ svn_stream_t *dst,
+ const char *eol_str,
+ svn_boolean_t repair,
+ apr_hash_t *keywords,
+ svn_boolean_t expand);
+
+/** Similar to svn_subst_translate_stream2()
+ *
+ * @deprecated Provided for backward compatibility with the 1.1 API.
+ */
+svn_error_t *
svn_subst_translate_stream (svn_stream_t *src,
svn_stream_t *dst,
const char *eol_str,
@@ -162,25 +205,9 @@
const svn_subst_keywords_t *keywords,
svn_boolean_t expand);
-
/**
- * @deprecated Provided for backward compatibility with the 1.0 API.
+ * @since New in 1.2.
*
- * Similar to svn_subst_copy_and_translate2 except that @a special is
- * always set to @c FALSE.
- */
-svn_error_t *
-svn_subst_copy_and_translate (const char *src,
- const char *dst,
- const char *eol_str,
- svn_boolean_t repair,
- const svn_subst_keywords_t *keywords,
- svn_boolean_t expand,
- apr_pool_t *pool);
-
-/**
- * @since New in 1.1.
- *
* Convenience routine: a variant of @c svn_subst_translate_stream
* which operates on files. (See previous docstring for details.) In
* addition, it will create/detranslate a special file if @a special
@@ -197,6 +224,23 @@
* copy.
*/
svn_error_t *
+svn_subst_copy_and_translate3 (const char *src,
+ const char *dst,
+ const char *eol_str,
+ svn_boolean_t repair,
+ apr_hash_t *keywords,
+ svn_boolean_t expand,
+ svn_boolean_t special,
+ apr_pool_t *pool);
+
+/**
+ * @since New in 1.1.
+ * @deprecated Provided for backward compatibility with the 1.1 API.
+ *
+ * Similar to svn_subst_copy_and_translate3 except that struct-style
+ * keywords are converted to hash-style
+ */
+svn_error_t *
svn_subst_copy_and_translate2 (const char *src,
const char *dst,
const char *eol_str,
@@ -206,7 +250,24 @@
svn_boolean_t special,
apr_pool_t *pool);
-/** Convenience routine: a variant of @c svn_subst_translate_stream which
+/**
+ * @deprecated Provided for backward compatibility with the 1.0 API.
+ *
+ * Similar to svn_subst_copy_and_translate2 except that @a special is
+ * always set to @c FALSE.
+ */
+svn_error_t *
+svn_subst_copy_and_translate (const char *src,
+ const char *dst,
+ const char *eol_str,
+ svn_boolean_t repair,
+ const svn_subst_keywords_t *keywords,
+ svn_boolean_t expand,
+ apr_pool_t *pool);
+
+/** @since New in 1.2.
+ *
+ * Convenience routine: a variant of @c svn_subst_translate_stream which
* operates on cstrings. (See previous docstring for details.)
*
* Return a new string in @a *dst, allocated in @a pool, by copying the
@@ -217,6 +278,20 @@
* copy.
*/
svn_error_t *
+svn_subst_translate_cstring2 (const char *src,
+ const char **dst,
+ const char *eol_str,
+ svn_boolean_t repair,
+ apr_hash_t *keywords,
+ svn_boolean_t expand,
+ apr_pool_t *pool);
+
+/** @deprecated Provided for backward compatibility with the 1.1 API.
+ *
+ * Similar to svn_subst_translate_cstring2() except that keywords struct
+ * is converted to keywords hash
+ */
+svn_error_t *
svn_subst_translate_cstring (const char *src,
const char **dst,
const char *eol_str,
=== subversion/include/svn_types.h
==================================================================
--- subversion/include/svn_types.h (/mirror/trunk) (revision 12209)
+++ subversion/include/svn_types.h (/local/keywords-phase1) (revision 12209)
@@ -214,35 +214,6 @@
/** Keyword substitution.
*
* All the keywords Subversion recognizes.
- *
- * Note that there is a better, more general proposal out there, which
- * would take care of both internationalization issues and custom
- * keywords (e.g., $NetBSD$). See
- *
- *<pre> http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=8921
- * =====
- * From: "Jonathan M. Manning" <jmanning@alisa-jon.net>
- * To: dev@subversion.tigris.org
- * Date: Fri, 14 Dec 2001 11:56:54 -0500
- * Message-ID: <87970000.1008349014@bdldevel.bl.bdx.com>
- * Subject: Re: keywords</pre>
- *
- * and Eric Gillespie's support of same:
- *
- *<pre> http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=8757
- * =====
- * From: "Eric Gillespie, Jr." <epg@pretzelnet.org>
- * To: dev@subversion.tigris.org
- * Date: Wed, 12 Dec 2001 09:48:42 -0500
- * Message-ID: <87k7vsebp1.fsf@vger.pretzelnet.org>
- * Subject: Re: Customizable Keywords</pre>
- *
- * However, it is considerably more complex than the scheme below.
- * For now we're going with simplicity, hopefully the more general
- * solution can be done post-1.0.
- *
- * @defgroup svn_types_keywords keywords
- * @{
*/
/** The maximum size of an expanded or un-expanded keyword. */
@@ -254,6 +225,9 @@
/** Short version of LastChangedRevision */
#define SVN_KEYWORD_REVISION_SHORT "Rev"
+/** Format string for Revision */
+#define SVN_KEYWORD_REVISION_FORMAT "%r"
+
/** Medium version of LastChangedRevision, matching the one CVS uses */
#define SVN_KEYWORD_REVISION_MEDIUM "Revision"
@@ -263,25 +237,42 @@
/** Short version of LastChangedDate */
#define SVN_KEYWORD_DATE_SHORT "Date"
+/** Format string for Date */
+#define SVN_KEYWORD_DATE_FORMAT "%D"
+
/** Who most recently committed to this file. */
#define SVN_KEYWORD_AUTHOR_LONG "LastChangedBy"
/** Short version of LastChangedBy */
#define SVN_KEYWORD_AUTHOR_SHORT "Author"
+/** Format string for Author */
+#define SVN_KEYWORD_AUTHOR_FORMAT "%a"
+
/** The URL for the head revision of this file. */
#define SVN_KEYWORD_URL_LONG "HeadURL"
/** Short version of HeadURL */
#define SVN_KEYWORD_URL_SHORT "URL"
-/** A compressed combination of the other four keywords.
- *
- * (But see comments above about a more general solution to keyword
- * combinations.)
- */
+/** Format string for URL */
+#define SVN_KEYWORD_URL_FORMAT "%u"
+
+/** The repository UUID. */
+#define SVN_KEYWORD_UUID_LONG "RepositoryUUID"
+
+/** Short version RepositoryUUID */
+#define SVN_KEYWORD_UUID_SHORT "UUID"
+
+/** Format string for URL */
+#define SVN_KEYWORD_UUID_FORMAT "%U"
+
+/** A compressed combination of the other four keywords */
#define SVN_KEYWORD_ID "Id"
+/** Format string for ID */
+#define SVN_KEYWORD_ID_FORMAT "%b %d %a %r"
+
/** @} */
=== subversion/libsvn_subr/subst.c
==================================================================
--- subversion/libsvn_subr/subst.c (/mirror/trunk) (revision 12209)
+++ subversion/libsvn_subr/subst.c (/local/keywords-phase1) (revision 12209)
@@ -118,6 +118,184 @@
return SVN_NO_ERROR;
}
+
+/* Helper function for svn_subst_build_keywords */
+
+/** Given a printf-like format string, return a string with proper
+ * information filled in.
+ *
+ * The codes of format:
+ *
+ * %a author of this revision
+ * %b basename of the URL of this file
+ * %d short format of date of this revision
+ * %D long format of date of this revision
+ * %r number of this revision
+ * %u URL of this file
+ * %U UUID of the repository
+ *
+ * All memory is allocated out of @a pool.
+ */
+static svn_string_t *
+keyword_printf (const char *fmt,
+ const char *rev,
+ const char *url,
+ apr_time_t date,
+ const char *author,
+ const char *uuid,
+ apr_pool_t *pool)
+{
+ svn_stringbuf_t *value = svn_stringbuf_ncreate ("", 0, pool);
+ const char *cur;
+ char ch;
+ int n;
+
+ for (;;)
+ {
+ for (cur = fmt; (ch = *cur) != '\0' && ch != '%'; cur++)
+ /* void */;
+ if ( (n = cur - fmt) > 0) /* Do we have a as-is string? */
+ svn_stringbuf_appendbytes (value, fmt, n);
+
+ if (ch == '\0')
+ break;
+
+ cur++; /* skip '%' */
+ ch = *cur++;
+ switch (ch)
+ {
+ case 'a': /* author of this revision */
+ if (author)
+ svn_stringbuf_appendcstr (value, author);
+ break;
+ case 'b': /* basename of this file */
+ if (url)
+ {
+ const char *base_name = NULL;
+ base_name = svn_path_basename (url, pool);
+
+ svn_stringbuf_appendcstr (value, base_name);
+ }
+ break;
+ case 'd': /* short format of date of this revision */
+ if (date)
+ {
+ const char *human_date = NULL;
+
+ if (!date_prop_to_human (&human_date, FALSE, date, pool))
+ svn_stringbuf_appendcstr (value, human_date);
+ }
+ break;
+ case 'D': /* long format of date of this revision */
+ if (date)
+ {
+ const char *human_date = NULL;
+
+ if (!date_prop_to_human (&human_date, TRUE, date, pool))
+ svn_stringbuf_appendcstr (value, human_date);
+ }
+ break;
+ case 'r': /* number of this revision */
+ if (rev)
+ svn_stringbuf_appendcstr (value, rev);
+ break;
+ case 'u': /* URL of this file */
+ if (url)
+ svn_stringbuf_appendcstr (value, url);
+ break;
+ case 'U': /* UUID of the repository */
+ if (uuid)
+ svn_stringbuf_appendcstr (value, uuid);
+ break;
+ default: /* %?, print ? as is. */
+ svn_stringbuf_appendbytes (value, &ch, 1);
+ break;
+ }
+
+ /* Format code is processed. Get ready for next chunk. */
+ fmt = cur;
+ }
+
+ return svn_string_create_from_buf (value, pool);
+}
+
+/* Convert the old-style keywords struct into the new keywords hash */
+static apr_hash_t *
+keywords_to_keyhash (svn_subst_keywords_t *kw,
+ apr_pool_t *pool)
+{
+ apr_hash_t *khash = apr_hash_make(pool);
+
+ /* if there are no keywords set, just return immediately */
+ if (kw == NULL)
+ return khash;
+
+ if (kw->revision)
+ {
+ apr_hash_set (khash, SVN_KEYWORD_REVISION_LONG,
+ APR_HASH_KEY_STRING, kw->revision);
+ apr_hash_set (khash, SVN_KEYWORD_REVISION_MEDIUM,
+ APR_HASH_KEY_STRING, kw->revision);
+ apr_hash_set (khash, SVN_KEYWORD_REVISION_SHORT,
+ APR_HASH_KEY_STRING, kw->revision);
+ }
+ if (kw->date)
+ {
+ apr_hash_set (khash, SVN_KEYWORD_DATE_LONG,
+ APR_HASH_KEY_STRING, kw->date);
+ apr_hash_set (khash, SVN_KEYWORD_DATE_SHORT,
+ APR_HASH_KEY_STRING, kw->date);
+ }
+ if (kw->author)
+ {
+ apr_hash_set (khash, SVN_KEYWORD_AUTHOR_LONG,
+ APR_HASH_KEY_STRING, kw->author);
+ apr_hash_set (khash, SVN_KEYWORD_AUTHOR_SHORT,
+ APR_HASH_KEY_STRING, kw->author);
+ }
+ if (kw->url)
+ {
+ apr_hash_set (khash, SVN_KEYWORD_URL_LONG,
+ APR_HASH_KEY_STRING, kw->url);
+ apr_hash_set (khash, SVN_KEYWORD_URL_SHORT,
+ APR_HASH_KEY_STRING, kw->url);
+ }
+ if (kw->id)
+ {
+ apr_hash_set (khash, SVN_KEYWORD_ID,
+ APR_HASH_KEY_STRING, kw->id);
+ }
+
+ return khash;
+}
+
+/* Convert new style keyhash into keyword struct */
+static void
+keyhash_to_keywords (svn_subst_keywords_t *kw,
+ apr_hash_t *khash,
+ apr_pool_t *pool)
+{
+ /* Attempt to fill all of the default keyword slots
+ * In each case, if the hash doesn't contain the corresponding
+ * keyword value, the struct element will be null
+ */
+
+ kw->revision = apr_hash_get(khash, SVN_KEYWORD_REVISION_LONG,
+ APR_HASH_KEY_STRING);
+
+ kw->date = apr_hash_get(khash, SVN_KEYWORD_DATE_LONG,
+ APR_HASH_KEY_STRING);
+
+ kw->author = apr_hash_get(khash, SVN_KEYWORD_AUTHOR_LONG,
+ APR_HASH_KEY_STRING);
+
+ kw->url = apr_hash_get(khash, SVN_KEYWORD_URL_LONG,
+ APR_HASH_KEY_STRING);
+
+ kw->id = apr_hash_get(khash, SVN_KEYWORD_ID,
+ APR_HASH_KEY_STRING);
+}
+
svn_error_t *
svn_subst_build_keywords (svn_subst_keywords_t *kw,
const char *keywords_val,
@@ -127,6 +305,26 @@
const char *author,
apr_pool_t *pool)
{
+ apr_hash_t *khash = apr_hash_make(pool);
+ svn_error_t * kerror = svn_subst_build_keywords2(khash, keywords_val, rev,
+ url, date, author, NULL,
+ pool);
+
+ keyhash_to_keywords(kw, khash, pool);
+
+ return kerror;
+}
+
+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,
+ const char *uuid,
+ apr_pool_t *pool)
+{
apr_array_header_t *keyword_tokens;
int i;
@@ -141,45 +339,92 @@
|| (! strcmp (keyword, SVN_KEYWORD_REVISION_MEDIUM))
|| (! strcasecmp (keyword, SVN_KEYWORD_REVISION_SHORT)))
{
- kw->revision = svn_string_create (rev, pool);
- }
+ svn_string_t *revision_val;
+
+ revision_val = keyword_printf (SVN_KEYWORD_REVISION_FORMAT,
+ rev, url, date, author,
+ uuid, pool);
+ apr_hash_set (kw, SVN_KEYWORD_REVISION_LONG,
+ APR_HASH_KEY_STRING, revision_val);
+ apr_hash_set (kw, SVN_KEYWORD_REVISION_MEDIUM,
+ APR_HASH_KEY_STRING, revision_val);
+ apr_hash_set (kw, SVN_KEYWORD_REVISION_SHORT,
+ APR_HASH_KEY_STRING, revision_val);
+ }
else if ((! strcmp (keyword, SVN_KEYWORD_DATE_LONG))
|| (! strcasecmp (keyword, SVN_KEYWORD_DATE_SHORT)))
{
if (date)
{
- const char *human_date;
+ svn_string_t *date_val;
- SVN_ERR (date_prop_to_human (&human_date, TRUE, date, pool));
+ date_val = keyword_printf (SVN_KEYWORD_DATE_FORMAT,
+ rev, url, date, author,
+ uuid, pool);
+ apr_hash_set (kw, SVN_KEYWORD_DATE_LONG,
+ APR_HASH_KEY_STRING, date_val);
+ apr_hash_set (kw, SVN_KEYWORD_DATE_SHORT,
+ APR_HASH_KEY_STRING, date_val);
+ }
+ else
+ {
+ svn_string_t *date_val;
- kw->date = svn_string_create (human_date, pool);
+ date_val = svn_string_create ("", pool);
+ apr_hash_set (kw, SVN_KEYWORD_DATE_LONG,
+ APR_HASH_KEY_STRING, date_val);
+ apr_hash_set (kw, SVN_KEYWORD_DATE_SHORT,
+ APR_HASH_KEY_STRING, date_val);
}
- else
- kw->date = svn_string_create ("", pool);
}
else if ((! strcmp (keyword, SVN_KEYWORD_AUTHOR_LONG))
|| (! strcasecmp (keyword, SVN_KEYWORD_AUTHOR_SHORT)))
{
- kw->author = svn_string_create (author ? author : "", pool);
+ svn_string_t *author_val;
+
+ author_val = keyword_printf (SVN_KEYWORD_AUTHOR_FORMAT,
+ rev, url, date, author,
+ uuid, pool);
+ apr_hash_set (kw, SVN_KEYWORD_AUTHOR_LONG,
+ APR_HASH_KEY_STRING, author_val);
+ apr_hash_set (kw, SVN_KEYWORD_AUTHOR_SHORT,
+ APR_HASH_KEY_STRING, author_val);
}
else if ((! strcmp (keyword, SVN_KEYWORD_URL_LONG))
|| (! strcasecmp (keyword, SVN_KEYWORD_URL_SHORT)))
{
- kw->url = svn_string_create (url ? url : "", pool);
+ svn_string_t *url_val;
+
+ url_val = keyword_printf (SVN_KEYWORD_URL_FORMAT,
+ rev, url, date, author,
+ uuid, pool);
+ apr_hash_set (kw, SVN_KEYWORD_URL_LONG,
+ APR_HASH_KEY_STRING, url_val);
+ apr_hash_set (kw, SVN_KEYWORD_URL_SHORT,
+ APR_HASH_KEY_STRING, url_val);
}
+ else if ((! strcmp (keyword, SVN_KEYWORD_UUID_LONG))
+ || (! strcasecmp (keyword, SVN_KEYWORD_UUID_SHORT)))
+ {
+ svn_string_t *uuid_val;
+
+ uuid_val = keyword_printf (SVN_KEYWORD_UUID_FORMAT,
+ rev, url, date, author,
+ uuid, pool);
+ apr_hash_set (kw, SVN_KEYWORD_UUID_LONG,
+ APR_HASH_KEY_STRING, uuid_val);
+ apr_hash_set (kw, SVN_KEYWORD_UUID_SHORT,
+ APR_HASH_KEY_STRING, uuid_val);
+ }
else if ((! strcasecmp (keyword, SVN_KEYWORD_ID)))
{
- const char *base_name = url ? svn_path_basename (url, pool) : "";
- const char *human_date = NULL;
+ svn_string_t *id_val;
- if (date)
- SVN_ERR (date_prop_to_human (&human_date, FALSE, date, pool));
-
- kw->id = svn_string_createf (pool, "%s %s %s %s",
- base_name,
- rev,
- human_date ? human_date : "",
- author ? author : "");
+ id_val = keyword_printf (SVN_KEYWORD_ID_FORMAT,
+ rev, url, date, author,
+ uuid, pool);
+ apr_hash_set (kw, SVN_KEYWORD_ID,
+ APR_HASH_KEY_STRING, id_val);
}
}
@@ -378,8 +623,12 @@
translate_keyword (char *buf,
apr_size_t *len,
svn_boolean_t expand,
- const svn_subst_keywords_t *keywords)
+ const apr_hash_t *keywords)
{
+ const svn_string_t *value;
+ char key[SVN_KEYWORD_MAX_LEN + 1];
+ int i;
+
/* Make sure we gotz good stuffs. */
assert (*len <= SVN_KEYWORD_MAX_LEN);
assert ((buf[0] == '$') && (buf[*len - 1] == '$'));
@@ -388,86 +637,20 @@
if (! keywords)
return FALSE;
- /* Revision */
- if (keywords->revision)
- {
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_REVISION_LONG,
- (sizeof (SVN_KEYWORD_REVISION_LONG)) - 1,
- expand ? keywords->revision : NULL))
- return TRUE;
+ for (i = 0; i < *len - 2 && buf[i + 1] != ':'; i++)
+ key[i] = *(buf + i + 1);
+ key[i] = 0;
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_REVISION_MEDIUM,
- (sizeof (SVN_KEYWORD_REVISION_MEDIUM)) - 1,
- expand ? keywords->revision : NULL))
- return TRUE;
+ value = apr_hash_get ((apr_hash_t *)keywords, key, APR_HASH_KEY_STRING);
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_REVISION_SHORT,
- (sizeof (SVN_KEYWORD_REVISION_SHORT)) - 1,
- expand ? keywords->revision : NULL))
- return TRUE;
- }
-
- /* Date */
- if (keywords->date)
+ if (value)
{
if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_DATE_LONG,
- (sizeof (SVN_KEYWORD_DATE_LONG)) - 1,
- expand ? keywords->date : NULL))
+ key, strlen(key),
+ expand ? value : NULL))
return TRUE;
-
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_DATE_SHORT,
- (sizeof (SVN_KEYWORD_DATE_SHORT)) - 1,
- expand ? keywords->date : NULL))
- return TRUE;
}
- /* Author */
- if (keywords->author)
- {
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_AUTHOR_LONG,
- (sizeof (SVN_KEYWORD_AUTHOR_LONG)) - 1,
- expand ? keywords->author : NULL))
- return TRUE;
-
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_AUTHOR_SHORT,
- (sizeof (SVN_KEYWORD_AUTHOR_SHORT)) - 1,
- expand ? keywords->author : NULL))
- return TRUE;
- }
-
- /* URL */
- if (keywords->url)
- {
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_URL_LONG,
- (sizeof (SVN_KEYWORD_URL_LONG)) - 1,
- expand ? keywords->url : NULL))
- return TRUE;
-
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_URL_SHORT,
- (sizeof (SVN_KEYWORD_URL_SHORT)) - 1,
- expand ? keywords->url : NULL))
- return TRUE;
- }
-
- /* Id */
- if (keywords->id)
- {
- if (translate_keyword_subst (buf, len,
- SVN_KEYWORD_ID,
- (sizeof (SVN_KEYWORD_ID)) - 1,
- expand ? keywords->id : NULL))
- return TRUE;
- }
-
/* No translations were successful. Return FALSE. */
return FALSE;
}
@@ -528,66 +711,64 @@
const svn_subst_keywords_t *b,
svn_boolean_t compare_values)
{
+ svn_boolean_t result = FALSE;
+ apr_pool_t *pool = svn_pool_create (NULL);
+
+ /* first we have to create a hash of each of the keyword struct's */
+ apr_hash_t *ahash = keywords_to_keyhash((svn_subst_keywords_t *)a,
+ pool);
+ apr_hash_t *bhash = keywords_to_keyhash((svn_subst_keywords_t *)b,
+ pool);
+
+ /* and then call the real function */
+ result = svn_subst_keywords_differ2 (ahash,bhash,compare_values,pool);
+
+ /* Always clean up after ourselves */
+ svn_pool_destroy (pool);
+ return result;
+}
+
+svn_boolean_t
+svn_subst_keywords_differ2 (const apr_hash_t *a,
+ const apr_hash_t *b,
+ svn_boolean_t compare_values,
+ apr_pool_t *pool)
+{
+ svn_boolean_t result = FALSE;
+ apr_hash_index_t *hi;
+ apr_hash_t *lame_a, *lame_b;
+
+ lame_a = (apr_hash_t *) a;
+ lame_b = (apr_hash_t *) b;
+
if (((a == NULL) && (b == NULL)) /* no A or B */
- /* no A, and B has no contents */
- || ((a == NULL)
- && (b->revision == NULL)
- && (b->date == NULL)
- && (b->author == NULL)
- && (b->url == NULL))
- /* no B, and A has no contents */
- || ((b == NULL) && (a->revision == NULL)
- && (a->date == NULL)
- && (a->author == NULL)
- && (a->url == NULL))
- /* neither A nor B has any contents */
- || ((a != NULL) && (b != NULL)
- && (b->revision == NULL)
- && (b->date == NULL)
- && (b->author == NULL)
- && (b->url == NULL)
- && (a->revision == NULL)
- && (a->date == NULL)
- && (a->author == NULL)
- && (a->url == NULL)))
+ /* Unequal number of contents */
+ || (apr_hash_count(lame_a) != apr_hash_count(lame_b)))
{
- return FALSE;
+ return TRUE;
}
- else if ((a == NULL) || (b == NULL))
- return TRUE;
-
- /* Else both A and B have some keywords. */
-
- if ((! a->revision) != (! b->revision))
- return TRUE;
- else if ((compare_values && (a->revision != NULL))
- && (strcmp (a->revision->data, b->revision->data) != 0))
- return TRUE;
-
- if ((! a->date) != (! b->date))
- return TRUE;
- else if ((compare_values && (a->date != NULL))
- && (strcmp (a->date->data, b->date->data) != 0))
- return TRUE;
-
- if ((! a->author) != (! b->author))
- return TRUE;
- else if ((compare_values && (a->author != NULL))
- && (strcmp (a->author->data, b->author->data) != 0))
- return TRUE;
-
- if ((! a->url) != (! b->url))
- return TRUE;
- else if ((compare_values && (a->url != NULL))
- && (strcmp (a->url->data, b->url->data) != 0))
- return TRUE;
-
- /* Else we never found a difference, so they must be the same. */
-
- return FALSE;
+
+ /* If compare_values is FALSE, we can say A and B are the same now. */
+ if (!compare_values)
+ return FALSE;
+
+ /* compare_values is TRUE. Compare value by value */
+ for (hi = apr_hash_first(pool, lame_a);
+ hi && !result;
+ hi = apr_hash_next(hi))
+ {
+ const char *key;
+ apr_hash_this (hi, (const void**) &key, NULL, NULL);
+ if (!svn_string_compare (apr_hash_get (lame_a, key,
+ APR_HASH_KEY_STRING),
+ apr_hash_get (lame_b, key,
+ APR_HASH_KEY_STRING)))
+ result = TRUE;
+ }
+
+ return result;
}
-
svn_error_t *
svn_subst_translate_stream (svn_stream_t *s, /* src stream */
svn_stream_t *d, /* dst stream */
@@ -596,6 +777,28 @@
const svn_subst_keywords_t *keywords,
svn_boolean_t expand)
{
+ apr_pool_t *pool = svn_pool_create (NULL);
+ apr_hash_t *kh =
+ keywords_to_keyhash((svn_subst_keywords_t *)keywords,
+ pool);
+
+ /* call the real function */
+ svn_error_t *err = svn_subst_translate_stream2 (s, d, eol_str,
+ repair, kh, expand);
+
+ /* Always clean up after ourselves */
+ svn_pool_destroy (pool);
+ return err;
+}
+
+svn_error_t *
+svn_subst_translate_stream2 (svn_stream_t *s, /* src stream */
+ svn_stream_t *d, /* dst stream */
+ const char *eol_str,
+ svn_boolean_t repair,
+ apr_hash_t *keywords,
+ svn_boolean_t expand)
+{
char buf[SVN_STREAM_CHUNK_SIZE + 1];
const char *p, *interesting;
apr_size_t len, readlen;
@@ -714,6 +917,22 @@
svn_boolean_t expand,
apr_pool_t *pool)
{
+ apr_hash_t *kh =
+ keywords_to_keyhash((svn_subst_keywords_t *)keywords, pool);
+
+ return svn_subst_translate_cstring2 (src, dst, eol_str, repair,
+ kh, expand, pool);
+}
+
+svn_error_t *
+svn_subst_translate_cstring2 (const char *src,
+ const char **dst,
+ const char *eol_str,
+ svn_boolean_t repair,
+ apr_hash_t *keywords,
+ svn_boolean_t expand,
+ apr_pool_t *pool)
+{
svn_stringbuf_t *src_stringbuf, *dst_stringbuf;
svn_stream_t *src_stream, *dst_stream;
svn_error_t *err;
@@ -733,8 +952,8 @@
dst_stream = svn_stream_from_stringbuf (dst_stringbuf, pool);
/* Translate src stream into dst stream. */
- err = svn_subst_translate_stream (src_stream, dst_stream,
- eol_str, repair, keywords, expand);
+ err = svn_subst_translate_stream2 (src_stream, dst_stream,
+ eol_str, repair, keywords, expand);
if (err)
{
svn_error_clear (svn_stream_close (src_stream));
@@ -923,6 +1142,24 @@
svn_boolean_t special,
apr_pool_t *pool)
{
+ apr_hash_t *kh =
+ keywords_to_keyhash((svn_subst_keywords_t *)keywords, pool);
+
+ return svn_subst_copy_and_translate3 (src, dst, eol_str,
+ repair, kh, expand, special,
+ pool);
+}
+
+svn_error_t *
+svn_subst_copy_and_translate3 (const char *src,
+ const char *dst,
+ const char *eol_str,
+ svn_boolean_t repair,
+ apr_hash_t *keywords,
+ svn_boolean_t expand,
+ svn_boolean_t special,
+ apr_pool_t *pool)
+{
const char *dst_tmp = NULL;
svn_stream_t *src_stream, *dst_stream;
apr_file_t *s = NULL, *d = NULL; /* init to null important for APR */
@@ -975,8 +1212,8 @@
dst_stream = svn_stream_from_aprfile (d, subpool);
/* Translate src stream into dst stream. */
- err = svn_subst_translate_stream (src_stream, dst_stream,
- eol_str, repair, keywords, expand);
+ err = svn_subst_translate_stream2 (src_stream, dst_stream,
+ eol_str, repair, keywords, expand);
if (err)
{
if (err->apr_err == SVN_ERR_IO_INCONSISTENT_EOL)
@@ -1046,13 +1283,13 @@
SVN_ERR (svn_utf_cstring_to_utf8 (&val_utf8, value->data, pool));
}
- SVN_ERR (svn_subst_translate_cstring (val_utf8,
- &val_utf8_lf,
- "\n", /* translate to LF */
- FALSE, /* no repair */
- NULL, /* no keywords */
- FALSE, /* no expansion */
- pool));
+ SVN_ERR (svn_subst_translate_cstring2 (val_utf8,
+ &val_utf8_lf,
+ "\n", /* translate to LF */
+ FALSE, /* no repair */
+ NULL, /* no keywords */
+ FALSE, /* no expansion */
+ pool));
*new_value = svn_string_create (val_utf8_lf, pool);
@@ -1076,13 +1313,13 @@
return SVN_NO_ERROR;
}
- SVN_ERR (svn_subst_translate_cstring (value->data,
- &val_neol,
- APR_EOL_STR, /* 'native' eol */
- FALSE, /* no repair */
- NULL, /* no keywords */
- FALSE, /* no expansion */
- pool));
+ SVN_ERR (svn_subst_translate_cstring2 (value->data,
+ &val_neol,
+ APR_EOL_STR, /* 'native' eol */
+ FALSE, /* no repair */
+ NULL, /* no keywords */
+ FALSE, /* no expansion */
+ pool));
if (for_output)
{
Property changes on:
___________________________________________________________________
Name: svk:merge
+65390229-12b7-0310-b90b-f21a5aa7ec8e:/trunk:12678
+65fbbcb0-2eec-0310-814e-ef69edb84eb1:/local/keywords:12026
ae6c956b-9dc6-0310-97b2-e73af4192982:/svn/local:8265
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jan 12 23:03:51 2005