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

Re: I like the new output of 'ls'

From: Garrett Rooney <rooneg_at_electricjellyfish.net>
Date: 2002-07-27 04:27:15 CEST

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.

well, here's a patch to add a 'svn_time_to_short_human_nts ()'
function, to go along with our existing 'svn_time_to_human_nts ()'.

i believe that Nuutti Kotivuori was planning on making the date format
configurable in the future (at least the comments in
libsvn_subr/time.c seem to give that impression), so i'd say that when
that is done we should just add two options, one for long and one for
short.

-garrett

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 Fri Jul 26 22:20:49 2002
@@ -77,6 +77,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)
@@ -261,6 +266,27 @@
   /* 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);
+
+ apr_err = apr_strftime (datestr, &size, SVN_TIME__MAX_SHORT_LENGTH,
+ short_human_timestamp_format, &exploded_time);
+ /* if that failed, just null terminate the string. */
+ if (apr_err)
+ datestr[0] = '\0';
 
   return datestr;
 }
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 04:27:45 2002

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.