threads / patch / 23479

patchformat-patch: use current date in mbox 'From COMMIT DATE' header line

Subject: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line

## tl;dr

12 messages between Apr 15, 2010 and Apr 17, 2010. Diffs are folded; open one to read it.

replies: 11people: 5as markdown or json

Chris Webb· Apr 15, 2010, 14:41 UTC · lore

Put the current date in the 'From COMMIT DATE' header line instead of using the fixed date 'Mon Sep 17 00:00:00 2001'. A DATE_UTC mode for show_date() is introduced so we can easily generate this line in the correct format.

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 builtin/blame.c |    1 +
 cache.h         |    3 ++-
 date.c          |    4 +++-
 log-tree.c      |    2 +-
 4 files changed, 7 insertions(+), 3 deletions(-)
Show changes to 4 files +7 −3

builtin/blame.c, cache.h, date.c, log-tree.c

diff --git a/builtin/blame.c b/builtin/blame.c
index fc15863..42fb1bd 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2301,6 +2301,7 @@ parse_done:
 		/* "normal" is used as the fallback for "relative" */
 	case DATE_LOCAL:
 	case DATE_NORMAL:
+	case DATE_UTC:
 		blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
 		break;
 	}
diff --git a/cache.h b/cache.h
index 5eb0573..fdb0643 100644
--- a/cache.h
+++ b/cache.h
@@ -769,7 +769,8 @@ enum date_mode {
 	DATE_LOCAL,
 	DATE_ISO8601,
 	DATE_RFC2822,
-	DATE_RAW
+	DATE_RAW,
+	DATE_UTC
 };
 
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
diff --git a/date.c b/date.c
index 002aa3c..88b1b58 100644
--- a/date.c
+++ b/date.c
@@ -166,6 +166,8 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 
 	if (mode == DATE_LOCAL)
 		tz = local_tzoffset(time);
+	else if (mode == DATE_UTC)
+		tz = 0;
 
 	tm = time_to_tm(time, tz);
 	if (!tm)
@@ -192,7 +194,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 				tm->tm_mday,
 				tm->tm_hour, tm->tm_min, tm->tm_sec,
 				tm->tm_year + 1900,
-				(mode == DATE_LOCAL) ? 0 : ' ',
+				(mode != DATE_NORMAL) ? 0 : ' ',
 				tz);
 	return timebuf;
 }
diff --git a/log-tree.c b/log-tree.c
index d3ae969..798baf6 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -217,7 +217,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 		subject = "Subject: ";
 	}
 
-	printf("From %s Mon Sep 17 00:00:00 2001\n", name);
+	printf("From %s %s\n", name, show_date(time(NULL), 0, DATE_UTC));
 	graph_show_oneline(opt->graph);
 	if (opt->message_id) {
 		printf("Message-Id: <%s>\n", opt->message_id);
-- 
1.7.0.3
Chris Webb· Apr 15, 2010, 15:16 UTC · re: Chris Webb · lore

Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line

Chris Webb <chris@arachsys.com> writes:
> Put the current date in the 'From COMMIT DATE' header line instead of using
> the fixed date 'Mon Sep 17 00:00:00 2001'. A DATE_UTC mode for show_date() is
> introduced so we can easily generate this line in the correct format.

...but this will break t4013-diff-various which expects the exact date string 'Mon Sep 17 00:00:00 2001' in the mbox header. Patch to fix this test to follow!

Cheers,
Chris.
Thomas Rast· Apr 15, 2010, 15:35 UTC · re: Chris Webb · lore

Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line

Chris Webb wrote:
Show 9 quoted lines
> Chris Webb <chris@arachsys.com> writes:
> 
> > Put the current date in the 'From COMMIT DATE' header line instead of using
> > the fixed date 'Mon Sep 17 00:00:00 2001'. A DATE_UTC mode for show_date() is
> > introduced so we can easily generate this line in the correct format.
> 
> ...but this will break t4013-diff-various which expects the exact date
> string 'Mon Sep 17 00:00:00 2001' in the mbox header. Patch to fix this test
> to follow!
Have you read
  http://thread.gmane.org/gmane.comp.version-control.git/124082/focus=124092

Not that I really care either way, but you should at least convince us why it is broken as it stands :-)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Chris Webb· Apr 15, 2010, 15:55 UTC · re: Thomas Rast · lore

Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line

Thomas Rast <trast@student.ethz.ch> writes:
> Have you read
> 
>   http://thread.gmane.org/gmane.comp.version-control.git/124082/focus=124092

I hadn't but have now. I don't buy the idea that this date is an unused placeholder in mbox files, and therefore can be sensibly set to an arbitary constant date in the distant past.

RFC4155 appendix A defines this date as the date a message was received. This isn't directly applicable to the context of format-patch, but other users of mbox format (e.g. MUAs doing an fcc) tend to fill it with the date the message was generated, and might reasonably expect to be able to sort on this date, e.g. when displaying a drafts folder.

If nothing else, it's extremely surprising to run format-patch, see a ridiculous date and wonder how your system time has become corrupted while you've been working!

Cheers,
Chris.
Junio C Hamano· Apr 17, 2010, 18:16 UTC · re: Thomas Rast · lore

Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line

Thomas Rast <trast@student.ethz.ch> writes:
Show 14 quoted lines
> Chris Webb wrote:
>> Chris Webb <chris@arachsys.com> writes:
>> 
>> > Put the current date in the 'From COMMIT DATE' header line instead of using
>> > the fixed date 'Mon Sep 17 00:00:00 2001'. A DATE_UTC mode for show_date() is
>> > introduced so we can easily generate this line in the correct format.
>> 
>> ...but this will break t4013-diff-various which expects the exact date
>> string 'Mon Sep 17 00:00:00 2001' in the mbox header. Patch to fix this test
>> to follow!
>
> Have you read
>
>   http://thread.gmane.org/gmane.comp.version-control.git/124082/focus=124092
Thanks for a sanity.
Chris Webb· Apr 15, 2010, 15:57 UTC · re: Chris Webb · lore

[PATCH] Fix t4013 with current date in mbox 'From COMMIT DATE' header lines

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 t/t4013-diff-various.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Show changes to t/t4013-diff-various.sh +2 −1
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index dae6358..ce42d3f 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -110,7 +110,8 @@ do
 			echo "\$ git $cmd"
 			git $cmd |
 			sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
-			    -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
+			    -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" \
+			    -e "s/^\\(From [0-9a-f][0-9a-f]*\\) .*/\\1 Mon Sep 17 00:00:00 2001/"
 			echo "\$"
 		} >"$actual" &&
 		if test -f "$expect"
-- 
1.7.0.3
Jonathan Nieder· Apr 15, 2010, 23:19 UTC · re: Chris Webb · lore

Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line

Hi,
Chris Webb wrote:
> Put the current date in the 'From COMMIT DATE' header line instead of using
> the fixed date 'Mon Sep 17 00:00:00 2001'.

Please no. It is useful that format-patch generates the same output when run a few times in a row.

If it is important to have a realistic date, would the commit date or similar work?

Jonathan
Chris Webb· Apr 16, 2010, 07:52 UTC · re: Jonathan Nieder · lore

Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line

Jonathan Nieder <jrnieder@gmail.com> writes:
> Please no.  It is useful that format-patch generates the same output when
> run a few times in a row. If it is important to have a realistic date,
> would the commit date or similar work?
Yes, sure: s/time(NULL)/commit->date/ works equally well for me.
Best wishes,
Chris.
Chris Webb· Apr 16, 2010, 16:42 UTC · re: Chris Webb · lore

[PATCH v2 1/2] format-patch: use commit date in mbox 'From COMMIT DATE' header line

Put the commit date in the 'From COMMIT DATE' header line instead of using the fixed date 'Mon Sep 17 00:00:00 2001'. A DATE_UTC mode for show_date() is introduced so we can easily generate this line in the correct format.

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 builtin/blame.c |    1 +
 cache.h         |    3 ++-
 date.c          |    4 +++-
 log-tree.c      |    2 +-
 4 files changed, 7 insertions(+), 3 deletions(-)
Show changes to 4 files +7 −3

builtin/blame.c, cache.h, date.c, log-tree.c

diff --git a/builtin/blame.c b/builtin/blame.c
index fc15863..42fb1bd 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2301,6 +2301,7 @@ parse_done:
 		/* "normal" is used as the fallback for "relative" */
 	case DATE_LOCAL:
 	case DATE_NORMAL:
+	case DATE_UTC:
 		blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
 		break;
 	}
diff --git a/cache.h b/cache.h
index 5eb0573..fdb0643 100644
--- a/cache.h
+++ b/cache.h
@@ -769,7 +769,8 @@ enum date_mode {
 	DATE_LOCAL,
 	DATE_ISO8601,
 	DATE_RFC2822,
-	DATE_RAW
+	DATE_RAW,
+	DATE_UTC
 };
 
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
diff --git a/date.c b/date.c
index 002aa3c..88b1b58 100644
--- a/date.c
+++ b/date.c
@@ -166,6 +166,8 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 
 	if (mode == DATE_LOCAL)
 		tz = local_tzoffset(time);
+	else if (mode == DATE_UTC)
+		tz = 0;
 
 	tm = time_to_tm(time, tz);
 	if (!tm)
@@ -192,7 +194,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 				tm->tm_mday,
 				tm->tm_hour, tm->tm_min, tm->tm_sec,
 				tm->tm_year + 1900,
-				(mode == DATE_LOCAL) ? 0 : ' ',
+				(mode != DATE_NORMAL) ? 0 : ' ',
 				tz);
 	return timebuf;
 }
diff --git a/log-tree.c b/log-tree.c
index d3ae969..90262f9 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -217,7 +217,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 		subject = "Subject: ";
 	}
 
-	printf("From %s Mon Sep 17 00:00:00 2001\n", name);
+	printf("From %s %s\n", name, show_date(commit->date, 0, DATE_UTC));
 	graph_show_oneline(opt->graph);
 	if (opt->message_id) {
 		printf("Message-Id: <%s>\n", opt->message_id);
-- 
1.7.0.3
Chris Webb· Apr 16, 2010, 16:42 UTC · re: Chris Webb · lore

[PATCH 2/2] Fix t4013 with commit date in mbox 'From COMMIT DATE' header lines

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 t/t4013-diff-various.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Show changes to t/t4013-diff-various.sh +2 −1
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index dae6358..ce42d3f 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -110,7 +110,8 @@ do
 			echo "\$ git $cmd"
 			git $cmd |
 			sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
-			    -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
+			    -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" \
+			    -e "s/^\\(From [0-9a-f][0-9a-f]*\\) .*/\\1 Mon Sep 17 00:00:00 2001/"
 			echo "\$"
 		} >"$actual" &&
 		if test -f "$expect"
-- 
1.7.0.3
Santi Béjar· Apr 16, 2010, 17:59 UTC · re: Chris Webb · lore

Re: [PATCH 2/2] Fix t4013 with commit date in mbox 'From COMMIT DATE' header lines

It is better if you squash this patch into the earlier one, then the tests always pass.

Santi
On Fri, Apr 16, 2010 at 6:42 PM, Chris Webb <chris@arachsys.com> wrote:
Show 27 quoted lines
> Signed-off-by: Chris Webb <chris@arachsys.com>
> ---
>  t/t4013-diff-various.sh |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
> index dae6358..ce42d3f 100755
> --- a/t/t4013-diff-various.sh
> +++ b/t/t4013-diff-various.sh
> @@ -110,7 +110,8 @@ do
>                        echo "\$ git $cmd"
>                        git $cmd |
>                        sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
> -                           -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
> +                           -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" \
> +                           -e "s/^\\(From [0-9a-f][0-9a-f]*\\) .*/\\1 Mon Sep 17 00:00:00 2001/"
>                        echo "\$"
>                } >"$actual" &&
>                if test -f "$expect"
> --
> 1.7.0.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Chris Webb· Apr 17, 2010, 08:01 UTC · re: Santi Béjar · lore

[PATCH v3] format-patch: use commit date in mbox 'From COMMIT DATE' header line

Put the commit date in the 'From COMMIT DATE' header line instead of using the fixed date 'Mon Sep 17 00:00:00 2001'. A DATE_UTC mode for show_date() is introduced so we can easily generate this line in the correct format, and t4013 is fixed not to expect a constant From line.

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 builtin/blame.c         |    1 +
 cache.h                 |    3 ++-
 date.c                  |    4 +++-
 log-tree.c              |    2 +-
 t/t4013-diff-various.sh |    3 ++-
 5 files changed, 9 insertions(+), 4 deletions(-)
Show changes to 5 files +9 −4

builtin/blame.c, cache.h, date.c, log-tree.c, t/t4013-diff-various.sh

diff --git a/builtin/blame.c b/builtin/blame.c
index fc15863..42fb1bd 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2301,6 +2301,7 @@ parse_done:
 		/* "normal" is used as the fallback for "relative" */
 	case DATE_LOCAL:
 	case DATE_NORMAL:
+	case DATE_UTC:
 		blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
 		break;
 	}
diff --git a/cache.h b/cache.h
index 5eb0573..fdb0643 100644
--- a/cache.h
+++ b/cache.h
@@ -769,7 +769,8 @@ enum date_mode {
 	DATE_LOCAL,
 	DATE_ISO8601,
 	DATE_RFC2822,
-	DATE_RAW
+	DATE_RAW,
+	DATE_UTC
 };
 
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
diff --git a/date.c b/date.c
index 002aa3c..88b1b58 100644
--- a/date.c
+++ b/date.c
@@ -166,6 +166,8 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 
 	if (mode == DATE_LOCAL)
 		tz = local_tzoffset(time);
+	else if (mode == DATE_UTC)
+		tz = 0;
 
 	tm = time_to_tm(time, tz);
 	if (!tm)
@@ -192,7 +194,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 				tm->tm_mday,
 				tm->tm_hour, tm->tm_min, tm->tm_sec,
 				tm->tm_year + 1900,
-				(mode == DATE_LOCAL) ? 0 : ' ',
+				(mode != DATE_NORMAL) ? 0 : ' ',
 				tz);
 	return timebuf;
 }
diff --git a/log-tree.c b/log-tree.c
index d3ae969..90262f9 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -217,7 +217,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 		subject = "Subject: ";
 	}
 
-	printf("From %s Mon Sep 17 00:00:00 2001\n", name);
+	printf("From %s %s\n", name, show_date(commit->date, 0, DATE_UTC));
 	graph_show_oneline(opt->graph);
 	if (opt->message_id) {
 		printf("Message-Id: <%s>\n", opt->message_id);
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index dae6358..ce42d3f 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -110,7 +110,8 @@ do
 			echo "\$ git $cmd"
 			git $cmd |
 			sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
-			    -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
+			    -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/" \
+			    -e "s/^\\(From [0-9a-f][0-9a-f]*\\) .*/\\1 Mon Sep 17 00:00:00 2001/"
 			echo "\$"
 		} >"$actual" &&
 		if test -f "$expect"
-- 
1.7.0.3

← back to recent threads