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

Subsystems: the rest

STALE3753d

11 messages, 4 authors, 2016-06-15 · open the first message on its own page

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:37

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 <redacted>
---
 builtin/blame.c |    1 +
 cache.h         |    3 ++-
 date.c          |    4 +++-
 log-tree.c      |    2 +-
 4 files changed, 7 insertions(+), 3 deletions(-)
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

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:37

Chris Webb [off-list ref] 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.

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

From: Thomas Rast <hidden>
Date: 2016-06-15 22:48:37

Chris Webb wrote:
Chris Webb [off-list ref] writes:
quoted
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

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:37

Thomas Rast [off-list ref] 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.

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:37

Signed-off-by: Chris Webb <redacted>
---
 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

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

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:48:39

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

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:39

Jonathan Nieder [off-list ref] 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.

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:39

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 <redacted>
---
 builtin/blame.c |    1 +
 cache.h         |    3 ++-
 date.c          |    4 +++-
 log-tree.c      |    2 +-
 4 files changed, 7 insertions(+), 3 deletions(-)
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

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:39

Signed-off-by: Chris Webb <redacted>
---
 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

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

From: Santi Béjar <hidden>
Date: 2016-06-15 22:48:39

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 [off-list ref] wrote:
quoted hunk
Signed-off-by: Chris Webb <redacted>
---
 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

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

From: Chris Webb <hidden>
Date: 2016-06-15 22:48:39

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 <redacted>
---
 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(-)
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help