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

12 messages from 2010-04-15 to 2010-04-17. Participants: Chris Webb, Thomas Rast, Jonathan Nieder, Santi Béjar, Junio C Hamano.
Thread: https://gitlist.dev/t/23479

## Chris Webb, 2010-04-15 14:41

Subject: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line
Message-ID: <9946ffbdf26e7b08b9b00b87d4b575fea774be4c.1271342450.git.chris@arachsys.com>
URL: https://gitlist.dev/e/9946ffbdf26e7b08b9b00b87d4b575fea774be4c.1271342450.git.chris%40arachsys.com

```
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(-)

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, 2010-04-15 15:16

Subject: Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line
Message-ID: <20100415151619.GK12365@arachsys.com>
URL: https://gitlist.dev/e/20100415151619.GK12365%40arachsys.com
In-Reply-To: <9946ffbdf26e7b08b9b00b87d4b575fea774be4c.1271342450.git.chris@arachsys.com>

```
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, 2010-04-15 15:35

Subject: Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line
Message-ID: <201004151735.31415.trast@student.ethz.ch>
URL: https://gitlist.dev/e/201004151735.31415.trast%40student.ethz.ch
In-Reply-To: <20100415151619.GK12365@arachsys.com>

```
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

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, 2010-04-15 15:55

Subject: Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line
Message-ID: <20100415155523.GL12365@arachsys.com>
URL: https://gitlist.dev/e/20100415155523.GL12365%40arachsys.com
In-Reply-To: <201004151735.31415.trast@student.ethz.ch>

```
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.

```

## Chris Webb, 2010-04-15 15:57

Subject: [PATCH] Fix t4013 with current date in mbox 'From COMMIT DATE' header lines
Message-ID: <d64c9b1fe1b02cdf9f67760e43141c3410388957.1271346952.git.chris@arachsys.com>
URL: https://gitlist.dev/e/d64c9b1fe1b02cdf9f67760e43141c3410388957.1271346952.git.chris%40arachsys.com
In-Reply-To: <20100415151619.GK12365@arachsys.com>

```
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

```

## Jonathan Nieder, 2010-04-15 23:19

Subject: Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line
Message-ID: <20100415231945.GA20584@progeny.tock>
URL: https://gitlist.dev/e/20100415231945.GA20584%40progeny.tock
In-Reply-To: <9946ffbdf26e7b08b9b00b87d4b575fea774be4c.1271342450.git.chris@arachsys.com>

```
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, 2010-04-16 07:52

Subject: Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line
Message-ID: <20100416075251.GA25147@arachsys.com>
URL: https://gitlist.dev/e/20100416075251.GA25147%40arachsys.com
In-Reply-To: <20100415231945.GA20584@progeny.tock>

```
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, 2010-04-16 16:42

Subject: [PATCH v2 1/2] format-patch: use commit date in mbox 'From COMMIT DATE' header line
Message-ID: <39d9b1c49e6d8e28eed7fa8d2817dc55834011fb.1271436192.git.chris@arachsys.com>
URL: https://gitlist.dev/e/39d9b1c49e6d8e28eed7fa8d2817dc55834011fb.1271436192.git.chris%40arachsys.com
In-Reply-To: <20100416075251.GA25147@arachsys.com>

```
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(-)

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, 2010-04-16 16:42

Subject: [PATCH 2/2] Fix t4013 with commit date in mbox 'From COMMIT DATE' header lines
Message-ID: <2b1d2ec748f3a28e7210f235df29703fd425e08a.1271436192.git.chris@arachsys.com>
URL: https://gitlist.dev/e/2b1d2ec748f3a28e7210f235df29703fd425e08a.1271436192.git.chris%40arachsys.com
In-Reply-To: <20100416075251.GA25147@arachsys.com>

```
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

```

## Santi Béjar, 2010-04-16 17:59

Subject: Re: [PATCH 2/2] Fix t4013 with commit date in mbox 'From COMMIT DATE' header lines
Message-ID: <o2jadf1fd3d1004161059z5b85989br9984fac87ac7e92b@mail.gmail.com>
URL: https://gitlist.dev/e/o2jadf1fd3d1004161059z5b85989br9984fac87ac7e92b%40mail.gmail.com
In-Reply-To: <2b1d2ec748f3a28e7210f235df29703fd425e08a.1271436192.git.chris@arachsys.com>

```
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:
> 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, 2010-04-17 08:01

Subject: [PATCH v3] format-patch: use commit date in mbox 'From COMMIT DATE' header line
Message-ID: <f71d42d6949caffa6f79278888c59fb4232bb277.1271490953.git.chris@arachsys.com>
URL: https://gitlist.dev/e/f71d42d6949caffa6f79278888c59fb4232bb277.1271490953.git.chris%40arachsys.com
In-Reply-To: <o2jadf1fd3d1004161059z5b85989br9984fac87ac7e92b@mail.gmail.com>

```
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(-)

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

```

## Junio C Hamano, 2010-04-17 18:16

Subject: Re: [PATCH] format-patch: use current date in mbox 'From COMMIT DATE' header line
Message-ID: <7v1vee0wsa.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1vee0wsa.fsf%40alter.siamese.dyndns.org
In-Reply-To: <201004151735.31415.trast@student.ethz.ch>

```
Thomas Rast <trast@student.ethz.ch> writes:

> 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.

```
