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

[PATCH] Use a short date format in "blame -v"

From: Julian Foad <julianfoad_at_btopenworld.com>
Date: 2005-01-26 03:35:44 CET

~/src/subversion> svn blame -v HACKING
   9234 kfogel 2004-03-30 19:45:22 +0100 (Tue, 30 Mar 2004)
                                                  -*-text-*-
      1 svn 2001-08-31 05:24:14 +0100 (Fri, 31 Aug 2001)
      1 svn 2001-08-31 05:24:14 +0100 (Fri, 31 Aug 2001) If you are
contributing code to the Subversion project, please read
      1 svn 2001-08-31 05:24:14 +0100 (Fri, 31 Aug 2001) this first.
[...]

I feel that this output is so verbose that we could justifiably call it a bug.
  According to our rules, we can't change this format now unless we call it a bug.

My patch changes it to the abbreviated date format used by "svn list" (with
time instead of year for recent dates):

~/src/subversion> svn blame -v HACKING | head -5
   9234 kfogel Mar 30 2004
                  -*-text-*-
      1 svn Aug 31 2001
      1 svn Aug 31 2001 If you are contributing code to the Subversion
project, please read
      1 svn Aug 31 2001 this first.
[...]

Opinions on whether I can make this change without a compatibility option, and,
if so, on the patch itself?

- Julian

Make "svn blame --verbose" use a short date format as used by "svn list
--verbose", instead of the present very long date format as used by "svn log".

* subversion/clients/cmdline/blame-cmd.c
  (blame_receiver): Print a short date instead of a long one.

* subversion/clients/cmdline/ls-cmd.c
  (print_dirents): Extract the code to print a short date into a new function
    svn_cl__short_date in util.c.

* subversion/clients/cmdline/cl.h
* subversion/clients/cmdline/util.c
  (svn_cl__short_date): New function extracted from ls-cmd.c:print_dirents.

Index: subversion/clients/cmdline/cl.h
===================================================================
--- subversion/clients/cmdline/cl.h (revision 12784)
+++ subversion/clients/cmdline/cl.h (working copy)
@@ -402,6 +402,12 @@
 /* Add a message about --force if appropriate */
 svn_error_t *svn_cl__may_need_force (svn_error_t *err);
 
+/* Set *OUT to a short human-readable representation of the date WHEN.
+ * Use POOL for all allocations. Format is "Mmm DD hh:mm" for dates within
+ * six months of now, otherwise "Mmm DD YYYY", in local time zone. */
+svn_error_t *
+svn_cl__short_date (const char **out, apr_time_t when, apr_pool_t *pool);
+
 
 #ifdef __cplusplus
 }
Index: subversion/clients/cmdline/util.c
===================================================================
--- subversion/clients/cmdline/util.c (revision 12784)
+++ subversion/clients/cmdline/util.c (working copy)
@@ -634,3 +634,34 @@
 
   return err;
 }
+
+
+svn_error_t *
+svn_cl__short_date (const char **out, apr_time_t when, apr_pool_t *pool)
+{
+ apr_time_t now = apr_time_now ();
+ apr_time_exp_t exp_time;
+ apr_status_t apr_err;
+ apr_size_t size;
+ char timestr[20];
+
+ apr_time_exp_lt (&exp_time, when);
+ if (apr_time_sec (now - when) < (365 * 86400 / 2)
+ && apr_time_sec (when - now) < (365 * 86400 / 2))
+ {
+ apr_err = apr_strftime (timestr, &size, sizeof (timestr),
+ "%b %d %H:%M", &exp_time);
+ }
+ else
+ {
+ apr_err = apr_strftime (timestr, &size, sizeof (timestr),
+ "%b %d %Y", &exp_time);
+ }
+
+ /* if that failed, just zero out the string and print nothing */
+ if (apr_err)
+ timestr[0] = '\0';
+
+ /* we need it in UTF-8. */
+ return svn_utf_cstring_to_utf8 (out, timestr, pool);
+}
Index: subversion/clients/cmdline/ls-cmd.c
===================================================================
--- subversion/clients/cmdline/ls-cmd.c (revision 12784)
+++ subversion/clients/cmdline/ls-cmd.c (working copy)
@@ -61,36 +61,9 @@
 
       if (verbose)
         {
- apr_time_t now = apr_time_now();
- apr_time_exp_t exp_time;
- apr_status_t apr_err;
- apr_size_t size;
- char timestr[20];
           const char *sizestr, *utf8_timestr;
-
- /* svn_time_to_human_cstring gives us something *way* too long
- to use for this, so we have to roll our own. We include
- the year if the entry's time is not within half a year. */
- apr_time_exp_lt (&exp_time, dirent->time);
- if (apr_time_sec(now - dirent->time) < (365 * 86400 / 2)
- && apr_time_sec(dirent->time - now) < (365 * 86400 / 2))
- {
- apr_err = apr_strftime (timestr, &size, sizeof (timestr),
- "%b %d %H:%M", &exp_time);
- }
- else
- {
- apr_err = apr_strftime (timestr, &size, sizeof (timestr),
- "%b %d %Y", &exp_time);
- }
-
- /* if that failed, just zero out the string and print nothing */
- if (apr_err)
- timestr[0] = '\0';
-
- /* we need it in UTF-8. */
- SVN_ERR (svn_utf_cstring_to_utf8 (&utf8_timestr, timestr, pool));
 
+ SVN_ERR (svn_cl__short_date (&utf8_timestr, dirent->time, pool));
           sizestr = apr_psprintf (pool, "%" SVN_FILESIZE_T_FMT, dirent->size);
 
           SVN_ERR (svn_cmdline_printf
Index: subversion/clients/cmdline/blame-cmd.c
===================================================================
--- subversion/clients/cmdline/blame-cmd.c (revision 12784)
+++ subversion/clients/cmdline/blame-cmd.c (working copy)
@@ -61,15 +61,15 @@
       if (date)
         {
           SVN_ERR (svn_time_from_cstring (&atime, date, pool));
- time_utf8 = svn_time_to_human_cstring (atime, pool);
+ SVN_ERR (svn_cl__short_date (&time_utf8, atime, pool));
           SVN_ERR (svn_cmdline_cstring_from_utf8 (&time_stdout, time_utf8,
                                                   pool));
         } else
- /* ### This is a 44 characters long string. It assumes the current
- format of svn_time_to_human_cstring and also 3 letter
- abbreviations for the month and weekday names. Else, the
+ /* ### This is a 12 characters long string. It assumes the current
+ format of svn_cl__short_date and also 3 letter
+ abbreviations for the month names. Else, the
              line contents will be misaligned. */
- time_stdout = " -";
+ time_stdout = " -";
       return svn_stream_printf (out, pool, "%s %10s %s %s\n", rev_str,
                                 author ? author : " -",
                                 time_stdout , line);

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jan 26 03:36:57 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.