git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Peter Krefting <peter@softwolves.pp.se>
To: Git Mailing List <git@vger.kernel.org>
Subject: [RFC PATCH 1/2] Use localized date in log output
Date: Tue, 23 Oct 2012 13:25:05 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.00.1210231325010.705@ds9.cixit.se> (raw)
In-Reply-To: <alpine.DEB.2.00.1210231323480.602@ds9.cixit.se>

When outputting a normal log, without having specified which date format
to use, we should output the current user locale's default format. Do this
by initializing LC_TIME properly and using strftime() to format the date.
---
  date.c    |  4 +++-
  gettext.c |  1 +
  strbuf.c  | 10 ++++++++++
  strbuf.h  |  1 +
  4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/date.c b/date.c
index 57331ed..88f928c 100644
--- a/date.c
+++ b/date.c
@@ -203,7 +203,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
  			weekday_names[tm->tm_wday], tm->tm_mday,
  			month_names[tm->tm_mon], tm->tm_year + 1900,
  			tm->tm_hour, tm->tm_min, tm->tm_sec, tz);
-	else
+	else if (mode == DATE_RAW)
  		strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
  				weekday_names[tm->tm_wday],
  				month_names[tm->tm_mon],
@@ -212,6 +212,8 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
  				tm->tm_year + 1900,
  				(mode == DATE_LOCAL) ? 0 : ' ',
  				tz);
+	else
+		strbuf_strftime(&timebuf,"%c",tm);
  	return timebuf.buf;
  }

diff --git a/gettext.c b/gettext.c
index 71e9545..a87d144 100644
--- a/gettext.c
+++ b/gettext.c
@@ -126,6 +126,7 @@ void git_setup_gettext(void)
  		podir = GIT_LOCALE_PATH;
  	bindtextdomain("git", podir);
  	setlocale(LC_MESSAGES, "");
+	setlocale(LC_TIME, "");
  	init_gettext_charset("git");
  	textdomain("git");
  }
diff --git a/strbuf.c b/strbuf.c
index 0510f76..d393de9 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -228,6 +228,16 @@ void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)
  	strbuf_setlen(sb, sb->len + len);
  }

+void strbuf_strftime(struct strbuf *sb, const char *fmt, struct tm *tm)
+{
+	int len;
+
+	if (!strbuf_avail(sb))
+		strbuf_grow(sb, 256);
+	len = strftime(sb->buf + sb->len, sb->alloc - sb->len, fmt, tm);
+	strbuf_setlen(sb, sb->len + len);
+}
+
  void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
  		   void *context)
  {
diff --git a/strbuf.h b/strbuf.h
index be941ee..9ca1d59 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -99,6 +99,7 @@ __attribute__((format (printf,2,3)))
  extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
  __attribute__((format (printf,2,0)))
  extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
+extern void strbuf_strfime(struct strbuf *sb, const char *fmt, struct tm *tm);

  extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size);

-- 
1.8.0

  reply	other threads:[~2012-10-23 12:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23 12:24 [RFC PATCH 0/2] Localize log output Peter Krefting
2012-10-23 12:25 ` Peter Krefting [this message]
2012-10-23 12:25 ` [RFC PATCH 2/2] Localize diff and " Peter Krefting

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.00.1210231325010.705@ds9.cixit.se \
    --to=peter@softwolves.pp.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).