On Sat, Jul 27, 2002 at 04:18:24AM +0200, Branko _ibej wrote:
> Yes, that's why this is an auspicious time for adding date format
> customization.
ok, here's a new version of the previous patch, with the added ability
to specify some format strings in ~/.subversion/formats for use as the
suffix of the long time format and the entire short time format.
a few things i don't like about this patch as it stands:
we're just ignoring errors that might occur if we can't read the
configuration files, since the time conversion functions don't return
svn_error_t's we can't currently propogate the error up the stack. i
don't know if we really care about this enough to change them, but if
we do i can do it. it'll be a mechanical change and shouldn't be too
hard.
there's no win32 stuff done, someone with some windows savy has to
write the parts of the code that hit the registry.
i'm not thrilled about reading in a config file for this kind of
thing, but i also don't like the idea of caching it in a static
variable (what if it's a long running app and the user changes the
config...), and i also don't like the idea of reading this in once and
passing it all over the place, so i suppose this is the best we can
do.
input is welcome as always.
-garrett
Index: ./subversion/include/svn_config.h
===================================================================
--- ./subversion/include/svn_config.h
+++ ./subversion/include/svn_config.h Fri Jul 26 23:47:08 2002
@@ -67,6 +67,8 @@
*/
svn_error_t *svn_config_read_proxies (svn_config_t **cfgp, apr_pool_t *pool);
+/* Read in the configuration information for user defined format strings. */
+svn_error_t *svn_config_read_formats (svn_config_t **cfgp, apr_pool_t *pool);
/* Read configuration data from FILE (a file or registry path) into
*CFGP, allocated in POOL.
Index: ./subversion/include/svn_time.h
===================================================================
--- ./subversion/include/svn_time.h
+++ ./subversion/include/svn_time.h Fri Jul 26 22:13:21 2002
@@ -43,6 +43,10 @@
suitable for human display. */
const char *svn_time_to_human_nts (apr_time_t when, apr_pool_t *pool);
+/* Convert WHEN to a const char * representation allocated in POOL,
+ suitable for human display and shorter than that produced by
+ svn_time_to_human_nts (). */
+const char *svn_time_to_short_human_nts (apr_time_t when, apr_pool_t *pool);
/* Needed by getdate.y parser */
struct getdate_time {
Index: ./subversion/libsvn_subr/time.c
===================================================================
--- ./subversion/libsvn_subr/time.c
+++ ./subversion/libsvn_subr/time.c Sat Jul 27 00:05:20 2002
@@ -23,6 +23,7 @@
#include <apr_time.h>
#include <apr_strings.h>
#include "svn_time.h"
+#include "svn_config.h"
@@ -77,6 +78,11 @@
static const char * const human_timestamp_format_suffix =
" (%a, %d %b %Y)";
+/* for situations when the long format is too long, we provide a shorter
+ version. */
+#define SVN_TIME__MAX_SHORT_LENGTH SVN_TIME__MAX_LENGTH / 5
+
+static const char * const short_human_timestamp_format = "%b %d %H:%m";
const char *
svn_time_to_nts (apr_time_t t, apr_pool_t *pool)
@@ -251,16 +257,71 @@
/* Calculate offset to the end of the machine parseable part. */
curptr = datestr + len;
- /* Put in human explanatory part */
- ret = apr_strftime (curptr,
- &retlen,
- SVN_TIME__MAX_LENGTH - len,
- human_timestamp_format_suffix,
- &exploded_time);
-
+ {
+ const char *timestamp_format_suffix;
+ svn_config_t *cfg;
+ svn_error_t *err;
+
+ err = svn_config_read_formats (&cfg, pool);
+ if (! err)
+ {
+ svn_config_get (cfg, ×tamp_format_suffix, "time",
+ "long_format_suffix", human_timestamp_format_suffix);
+ }
+ else
+ {
+ timestamp_format_suffix = human_timestamp_format_suffix;
+ }
+
+ /* Put in human explanatory part */
+ ret = apr_strftime (curptr,
+ &retlen,
+ SVN_TIME__MAX_LENGTH - len,
+ timestamp_format_suffix,
+ &exploded_time);
+ }
+
/* If there was an error, ensure that the string is zero-terminated. */
if (!ret || retlen == 0)
curptr = '\0';
+
+ return datestr;
+}
+
+
+const char *
+svn_time_to_short_human_nts (apr_time_t t, apr_pool_t *pool)
+{
+ apr_time_exp_t exploded_time;
+ apr_status_t apr_err;
+ apr_size_t size;
+
+ char *datestr = apr_palloc(pool, SVN_TIME__MAX_SHORT_LENGTH);
+
+ apr_time_exp_lt (&exploded_time, t);
+
+ {
+ const char *short_timestamp_format;
+ svn_config_t *cfg;
+ svn_error_t *err;
+
+ err = svn_config_read_formats (&cfg, pool);
+ if (! err)
+ {
+ svn_config_get (cfg, &short_timestamp_format, "time",
+ "short_format", short_human_timestamp_format);
+ }
+ else
+ {
+ short_timestamp_format = short_human_timestamp_format;
+ }
+
+ apr_err = apr_strftime (datestr, &size, SVN_TIME__MAX_SHORT_LENGTH,
+ short_timestamp_format, &exploded_time);
+ /* if that failed, just null terminate the string. */
+ if (apr_err)
+ datestr[0] = '\0';
+ }
return datestr;
}
Index: ./subversion/libsvn_subr/config.c
===================================================================
--- ./subversion/libsvn_subr/config.c
+++ ./subversion/libsvn_subr/config.c Fri Jul 26 23:50:29 2002
@@ -212,6 +212,30 @@
}
+svn_error_t *
+svn_config_read_formats (svn_config_t **cfgp, apr_pool_t *pool)
+{
+ const char *usr_cfg_path, *sys_cfg_path;
+ const char *usr_reg_path, *sys_reg_path;
+
+ /* XXX need win32 impl */
+
+ SVN_ERR (svn_config__sys_config_path (&sys_cfg_path,
+ SVN_CONFIG__USR_FORMATS_FILE,
+ pool));
+
+ SVN_ERR (svn_config__user_config_path (&usr_cfg_path,
+ SVN_CONFIG__USR_FORMATS_FILE,
+ pool));
+
+ SVN_ERR (read_all (cfgp,
+ sys_reg_path, usr_reg_path,
+ sys_cfg_path, usr_cfg_path,
+ pool));
+
+ return SVN_NO_ERROR;
+}
+
/* Iterate through CFG, passing BATON to CALLBACK for every (SECTION, OPTION)
pair. Stop if CALLBACK returns TRUE. Allocate from POOL. */
Index: ./subversion/libsvn_subr/config_impl.h
===================================================================
--- ./subversion/libsvn_subr/config_impl.h
+++ ./subversion/libsvn_subr/config_impl.h Fri Jul 26 23:45:27 2002
@@ -112,6 +112,8 @@
/* The proxy config file in SVN_CONFIG__DIRECTORY. */
#define SVN_CONFIG__USR_PROXY_FILE "proxies"
+/* The formats config file in SVN_CONFIG__DIRECTORY. */
+#define SVN_CONFIG__USR_FORMATS_FILE "formats"
/* Set *PATH_P to the path to config file FNAME in the system
configuration area, allocated in POOL. If FNAME is NULL, set
Index: ./subversion/clients/cmdline/ls-cmd.c
===================================================================
--- ./subversion/clients/cmdline/ls-cmd.c
+++ ./subversion/clients/cmdline/ls-cmd.c Fri Jul 26 22:16:50 2002
@@ -59,7 +59,6 @@
const char *native_author;
svn_dirent_t *dirent;
svn_item_t *item;
- char timestr[20];
item = &APR_ARRAY_IDX (array, i, svn_item_t);
@@ -72,29 +71,12 @@
SVN_ERR (svn_utf_cstring_from_utf8 (&native_author,
dirent->last_author, pool));
- {
- /* svn_time_to_human_nts gives us something *way* to long to use for
- this, so we have to roll our own. */
- apr_time_exp_t exp_time;
- apr_status_t apr_err;
- apr_size_t size;
-
- apr_time_exp_lt (&exp_time, dirent->time);
-
- apr_err = apr_strftime (timestr, &size, sizeof (timestr), "%b %d %H:%m",
- &exp_time);
-
- /* if that failed, just zero out the string and print nothing */
- if (apr_err)
- timestr[0] = '\0';
- }
-
printf ("%c %7"SVN_REVNUM_T_FMT" %8.8s %8ld %12s %s%s\n",
dirent->has_props ? 'P' : '_',
dirent->created_rev,
native_author ? native_author : " ? ",
(long int) dirent->size,
- timestr,
+ svn_time_to_short_human_nts (dirent->time, pool),
native_entryname,
(dirent->kind == svn_node_dir) ? "/" : "");
}
--
garrett rooney Remember, any design flaw you're
rooneg@electricjellyfish.net sufficiently snide about becomes
http://electricjellyfish.net/ a feature. -- Dan Sugalski
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jul 27 06:15:42 2002