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

SubWCRev and different date formats

From: Glenn R Heard Jr <gheard_at_neo.rr.com>
Date: 2007-08-09 20:24:11 CEST

Hello TortoiseSVN community!

My company uses a different date format than the international one used
in TSVN's SubWCRev. So, I set about my merry way of checking out TSVN
and modifying SubWCRev to meet our needs. In doing so, I made a variant
of $WCDATE$ and $WCNOW$ that accept strftime() format strings.

example:

char *Date = "$WCDATE=%a %b %d %I:%M:%S %p$";
char *TimeNow = "$WCNOW=%a %b %d %I:%M:%S %p$";

Works like a charm for us, and I though I might send out the patch for
anyone else that might be interested. It is derived from the TSVN 1.4.4
branch.

Also, I would like to once again thank the TSVN developers for making
such a fine product as well as the great build documentation.

-- 
Glenn R Heard Jr        gheard  _at_ neo.rr.com
ICQ: 123194600          grheard _at_ gmail.com
Y!: glennheard
---
"Any sufficiently advanced technology is indistinguishable from magic."
-- Arthur C. Clarke

Index: SubWCRev.cpp
===================================================================
--- SubWCRev.cpp (revision 10312)
+++ SubWCRev.cpp (working copy)
@@ -63,24 +63,31 @@
 \n\
 $WCREV$ Highest committed revision number\n\
 $WCDATE$ Date of highest committed revision\n\
+$WCDATE=$ Like $WCDATE$ with an added strftime format after the =\n\
 $WCRANGE$ Update revision range\n\
 $WCURL$ Repository URL of the working copy\n\
 $WCNOW$ Current system date & time\n\
+$WCNOW=$ Like $WCNOW$ with an added strftime format after the =\n\
 \n\
 Placeholders of the form \"$WCxxx?TrueText:FalseText$\" are replaced with\n\
 TrueText if the tested condition is true, and FalseText if false.\n\
 \n\
 $WCMODS$ True if local modifications found\n\
-$WCMIXED$ True if mixed update revisions found\n"
+$WCMIXED$ True if mixed update revisions found\n\
+\n\
+The strftime format strings for $WCDATE=$ & $WCNOW=$ must not be longer\n\
+than 64 characters, and must not produce output greater than 128 characters.\n"
 // End of multi-line help text.
 
 #define VERDEF "$WCREV$"
 #define DATEDEF "$WCDATE$"
+#define DATEWFMTDEF "$WCDATE="
 #define MODDEF "$WCMODS?"
 #define RANGEDEF "$WCRANGE$"
 #define MIXEDDEF "$WCMIXED?"
 #define URLDEF "$WCURL$"
 #define NOWDEF "$WCNOW$"
+#define NOWWFMTDEF "$WCNOW="
 
 // Internal error codes
 #define ERR_SYNTAX 1 // Syntax error
@@ -192,18 +199,47 @@
         struct tm newtime;
         if (_localtime64_s(&newtime, &ttime))
                 return FALSE;
- // Format the date/time in international format as yyyy/mm/dd hh:mm:ss
- char destbuf[32];
- sprintf_s(destbuf, 32, "%04d/%02d/%02d %02d:%02d:%02d",
- newtime.tm_year + 1900,
- newtime.tm_mon + 1,
- newtime.tm_mday,
- newtime.tm_hour,
- newtime.tm_min,
- newtime.tm_sec);
- // Replace the $WCDATE$ string with the actual commit date
+ char destbuf[128];
         char * pBuild = pBuf + index;
- ptrdiff_t Expansion = strlen(destbuf) - strlen(def);
+ ptrdiff_t Expansion;
+ if ((strcmp(def,DATEWFMTDEF) == 0) || (strcmp(def,NOWWFMTDEF) == 0))
+ {
+ // Format the date/time according to the supplied strftime format string
+ char format[65];
+ char * pStart = pBuf + index + strlen(def);
+ char * pEnd = pStart + 1;
+
+ while (*pEnd != '$')
+ {
+ pEnd++;
+ if (pEnd - pBuf >= (__int64)filelength)
+ return FALSE; // No terminator - malformed so give up.
+ }
+ if ((pEnd - pStart) > 64)
+ {
+ return FALSE; // Format specifier too big
+ }
+ memset(format,0,65);
+ memcpy(format,pStart,pEnd - pStart);
+
+ strftime(destbuf,128,format,&newtime);
+
+ Expansion = strlen(destbuf) - (strlen(def) + pEnd - pStart + 1);
+ }
+ else
+ {
+ // Format the date/time in international format as yyyy/mm/dd hh:mm:ss
+ sprintf_s(destbuf, 128, "%04d/%02d/%02d %02d:%02d:%02d",
+ newtime.tm_year + 1900,
+ newtime.tm_mon + 1,
+ newtime.tm_mday,
+ newtime.tm_hour,
+ newtime.tm_min,
+ newtime.tm_sec);
+
+ Expansion = strlen(destbuf) - strlen(def);
+ }
+ // Replace the def string with the actual commit date
         if (Expansion < 0)
         {
                 memmove(pBuild, pBuild - Expansion, filelength - ((pBuild - Expansion) - pBuf));
@@ -532,9 +568,15 @@
         while (InsertDate(DATEDEF, pBuf, index, filelength, maxlength, SubStat.CmtDate));
         
         index = 0;
+ while (InsertDate(DATEWFMTDEF, pBuf, index, filelength, maxlength, SubStat.CmtDate));
+
+ index = 0;
         while (InsertDate(NOWDEF, pBuf, index, filelength, maxlength, USE_TIME_NOW));
         
         index = 0;
+ while (InsertDate(NOWWFMTDEF, pBuf, index, filelength, maxlength, USE_TIME_NOW));
+
+ index = 0;
         while (InsertBoolean(MODDEF, pBuf, index, filelength, SubStat.HasMods));
         
         index = 0;

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: users-help@tortoisesvn.tigris.org
Received on Thu Aug 9 20:22:01 2007

This is an archived mail posted to the TortoiseSVN Users mailing list.