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

[PATCH] Add Id keyword

From: <epg_at_pretzelnet.org>
Date: 2002-07-28 23:36:02 CEST

We've already been through why a customizable, format-string keyword
is valuable. Unfortunately, this is post-1.0 because we need a mechanism
for the server to send configuration data to the client. In the meantime,
this patch will provide the concise Id keyword we're used to from CVS, and
provide projects a single place to patch to replace Id with $NetBSD$
or whatever. Not as good as the format-string based keyword, but much
easier than CVS.

I also provide a second patch. IMNSHO, the date used in the keyword
should not be client-customizable. Nor does it need to be as verbose.
The second patch implements a new function to format the date string.

The first patch gives us this:

$Id: bar 146 2002-07-28 16:13:53 -0500 (Sun, 28 Jul 2002) epg $
$Date: 2002-07-28 16:13:53 -0500 (Sun, 28 Jul 2002) $

The second patch gives us this:

$Id: bar 148 2002-07-28 21:30:43 epg $
$Date: 2002-07-28 21:30:43 $

Index: ./subversion/include/svn_types.h
===================================================================
--- ./subversion/include/svn_types.h
+++ ./subversion/include/svn_types.h Sun Jul 28 15:44:00 2002
@@ -318,6 +318,11 @@
 #define SVN_KEYWORD_URL_LONG "HeadURL"
 #define SVN_KEYWORD_URL_SHORT "URL"
 
+/* A short combination of the above four keywords. Note that this
+ should go away once the above, more complete solution is
+ implemented. */
+
+#define SVN_KEYWORD_ID "Id"
 
 
 /*** Shared function types ***/
Index: ./subversion/include/svn_wc.h
===================================================================
--- ./subversion/include/svn_wc.h
+++ ./subversion/include/svn_wc.h Sun Jul 28 15:44:38 2002
@@ -1381,6 +1381,7 @@
   const svn_string_t *date;
   const svn_string_t *author;
   const svn_string_t *url;
+ const svn_string_t *id;
 } svn_wc_keywords_t;
 
 
Index: ./subversion/libsvn_wc/translate.c
===================================================================
--- ./subversion/libsvn_wc/translate.c
+++ ./subversion/libsvn_wc/translate.c Sun Jul 28 16:07:31 2002
@@ -284,6 +284,15 @@
         return TRUE;
     }
 
+ 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;
 }
@@ -926,6 +935,25 @@
         keywords->url = svn_string_create (entry->url, pool);
       else
         keywords->url = svn_string_create ("", pool);
+ }
+ else if ((! strcmp (keyword, SVN_KEYWORD_ID)))
+ {
+ if (entry && (entry->cmt_rev && entry->cmt_date
+ && entry->cmt_author && entry->url))
+ {
+ char *basename = svn_path_basename (entry->url, pool);
+ svn_string_t *rev = svn_string_createf (pool, "%" SVN_REVNUM_T_FMT,
+ entry->cmt_rev);
+ const char *date = svn_time_to_human_nts (entry->cmt_date, pool);
+
+ keywords->id = svn_string_createf (pool, "%s %s %s %s",
+ basename,
+ rev->data,
+ date,
+ entry->cmt_author);
+ }
+ else
+ keywords->id = svn_string_create ("", pool);
     }
   else
     *is_valid_p = FALSE;

Index: ./subversion/include/svn_types.h
===================================================================
--- ./subversion/include/svn_types.h
+++ ./subversion/include/svn_types.h Sun Jul 28 15:44:00 2002
@@ -318,6 +318,11 @@
 #define SVN_KEYWORD_URL_LONG "HeadURL"
 #define SVN_KEYWORD_URL_SHORT "URL"
 
+/* A short combination of the above four keywords. Note that this
+ should go away once the above, more complete solution is
+ implemented. */
+
+#define SVN_KEYWORD_ID "Id"
 
 
 /*** Shared function types ***/
Index: ./subversion/include/svn_wc.h
===================================================================
--- ./subversion/include/svn_wc.h
+++ ./subversion/include/svn_wc.h Sun Jul 28 15:44:38 2002
@@ -1381,6 +1381,7 @@
   const svn_string_t *date;
   const svn_string_t *author;
   const svn_string_t *url;
+ const svn_string_t *id;
 } svn_wc_keywords_t;
 
 
Index: ./subversion/libsvn_wc/translate.c
===================================================================
--- ./subversion/libsvn_wc/translate.c
+++ ./subversion/libsvn_wc/translate.c Sun Jul 28 16:25:35 2002
@@ -284,6 +284,15 @@
         return TRUE;
     }
 
+ 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;
 }
@@ -861,6 +870,38 @@
 }
 
 
+static const char *
+time_to_date_keyword (apr_time_t t, apr_pool_t *pool)
+{
+ const char *t_cstr;
+ apr_time_exp_t exploded_time;
+
+ /* We toss apr_status_t return value here -- for one thing, caller
+ should pass in good information. But also, where APR's own code
+ calls these functions it tosses the return values, and
+ furthermore their current implementations can only return success
+ anyway. */
+
+ /* We get the date in GMT now -- and expect the tm_gmtoff and
+ tm_isdst to be not set. We also ignore the weekday and yearday,
+ since those are not needed. */
+
+ apr_time_exp_gmt (&exploded_time, t);
+
+ /* It would be nice to use apr_strftime(), but APR doesn't give a
+ way to convert back, so we wouldn't be able to share the format
+ string between the writer and reader. */
+ t_cstr = apr_psprintf (pool, "%04d-%02d-%02d %02d:%02d:%02d",
+ 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);
+
+ return t_cstr;
+}
+
 /* Helper for svn_wc__get_keywords().
    
    If KEYWORD is a valid keyword, look up its value in ENTRY, fill in
@@ -907,7 +948,7 @@
     {
       if (entry && (entry->cmt_date))
         keywords->date = svn_string_create
- (svn_time_to_human_nts (entry->cmt_date, pool), pool);
+ (time_to_date_keyword (entry->cmt_date, pool), pool);
       else
         keywords->date = svn_string_create ("", pool);
     }
@@ -926,6 +967,25 @@
         keywords->url = svn_string_create (entry->url, pool);
       else
         keywords->url = svn_string_create ("", pool);
+ }
+ else if ((! strcmp (keyword, SVN_KEYWORD_ID)))
+ {
+ if (entry && (entry->cmt_rev && entry->cmt_date
+ && entry->cmt_author && entry->url))
+ {
+ char *basename = svn_path_basename (entry->url, pool);
+ svn_string_t *rev = svn_string_createf (pool, "%" SVN_REVNUM_T_FMT,
+ entry->cmt_rev);
+ const char *date = time_to_date_keyword (entry->cmt_date, pool);
+
+ keywords->id = svn_string_createf (pool, "%s %s %s %s",
+ basename,
+ rev->data,
+ date,
+ entry->cmt_author);
+ }
+ else
+ keywords->id = svn_string_create ("", pool);
     }
   else
     *is_valid_p = FALSE;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Jul 28 23:39:07 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.