[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r16171 - in trunk/subversion: libsvn_subr

From: <kfogel_at_collab.net>
Date: 2005-09-20 22:06:02 CEST

julianfoad@tigris.org writes:
> --- trunk/subversion/libsvn_subr/subst.c (original)
> +++ trunk/subversion/libsvn_subr/subst.c Tue Sep 20 14:42:28 2005
> @@ -91,31 +91,175 @@
> }
> }
>
> -/* A helper function to convert the date property to something suitable for
> - printing out. If LONG_P is TRUE, use the long format, otherwise use a
> - shorter one. Returns a UTF8 encoded cstring. */
> -static svn_error_t *
> -date_prop_to_human (const char **human, svn_boolean_t long_p, apr_time_t when,
> - apr_pool_t *pool)
> +
> +/* Helper function for svn_subst_build_keywords */
> +
> +/* Given a printf-like format string, return a string with proper
> + * information filled in.
> + *
> + * Important API note: This function is the core of the implementation of
> + * svn_subst_build_keywords (all versions), and as such must implement the
> + * tolerance of NULL and zero inputs that that function's documention
> + * stipulates.
> + *
> + * The format codes:
> + *
> + * %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
> + * %% a literal %
> + *
> + * 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,
> + apr_pool_t *pool)
> {
> - if (long_p)
> - *human = svn_time_to_human_cstring (when, pool);
> - else
> + svn_stringbuf_t *value = svn_stringbuf_ncreate ("", 0, pool);
> + const char *cur;
> + int n;
> +
> + for (;;)
> {
> - apr_time_exp_t exploded_time;
> + cur = fmt;
> +
> + while (*cur != '\0' && *cur != '%')
> + cur++;
> +
> + if ((n = cur - fmt) > 0) /* Do we have an as-is string? */
> + svn_stringbuf_appendbytes (value, fmt, n);
> +
> + if (*cur == '\0')
> + break;
> +
> + switch (cur[1])
> + {
> + 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
> + = svn_path_uri_decode (svn_path_basename (url, pool), pool);
> + svn_stringbuf_appendcstr (value, base_name);
> + }
> + break;
> + case 'd': /* short format of date of this revision */
> + if (date)
> + {
> + apr_time_exp_t exploded_time;
> + const char *human;
> +
> + apr_time_exp_gmt (&exploded_time, date);
>
> - apr_time_exp_gmt (&exploded_time, when);
> + human = apr_psprintf (pool, "%04d-%02d-%02d %02d:%02d:%02dZ",
> + exploded_time.tm_year + 1900,
> + exploded_time.tm_mon + 1,
> + exploded_time.tm_mday,
> + exploded_time.tm_hour,
> + exploded_time.tm_min,
> + exploded_time.tm_sec);
>
> - *human = apr_psprintf (pool, "%04d-%02d-%02d %02d:%02d:%02dZ",
> - exploded_time.tm_year + 1900,
> - exploded_time.tm_mon + 1,
> - exploded_time.tm_mday,
> - exploded_time.tm_hour,
> - exploded_time.tm_min,
> - exploded_time.tm_sec);
> + svn_stringbuf_appendcstr (value, human);
> + }
> + break;
> + case 'D': /* long format of date of this revision */
> + if (date)
> + svn_stringbuf_appendcstr (value,
> + svn_time_to_human_cstring (date, pool));
> + 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 '%': /* '%%' => a literal % */
> + svn_stringbuf_appendbytes (value, cur, 1);
> + break;
> + case '\0': /* '%' as the last character of the string. */
> + svn_stringbuf_appendbytes (value, cur, 1);
> + /* Now go back one character, since this was just a one character
> + * sequence, whereas all others are two characters, and we do not
> + * want to skip the null terminator entirely and carry on
> + * formatting random memory contents. */
> + cur--;
> + break;
> + default: /* Unrecognized code, just print it literally. */
> + svn_stringbuf_appendbytes (value, cur, 2);
> + break;
> + }

Since we might add new codes in the future (e.g., "%R" for the base
repository URL, not including the path-within-the-repos), we should be
careful to document that just because an unknown code expands to the
literal characters today, it might not tomorrow.

I'm not sure where this feature is getting documented, but seeing the
'default' case above made me want to mention this concern. Thoughts?

-Karl

-- 
www.collab.net  <>  CollabNet  |  Distributed Development On Demand
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Sep 20 23:12:12 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.