git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian MICHON <christian.michon@gmail.com>
Cc: git list <git@vger.kernel.org>
Subject: Re: how to force a commit date matching info from a mbox ?
Date: Thu, 22 Jan 2009 16:14:58 -0800	[thread overview]
Message-ID: <7vljt26fp9.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 46d6db660901221441q60eb90bdge601a7a250c3a247@mail.gmail.com

Christian MICHON <christian.michon@gmail.com> writes:

> I'd like to force the commit date to match the info/date from the time
> I received the email (and therefore always get back the right
> sha1sums).
>
> is this possible ?

"am" being a tool to accept patches written in some past to faithfully
record both author timestamp and committer timestamp, what you seem to
want is outside of the current scope of the tool.

A patch to butcher "git-am" to copy GIT_COMMITTER_DATE from
GIT_AUTHOR_DATE and export it should be trivial to implement, though.

Perhaps something like this totally untested patch.



 git-am.sh     |   13 ++++++++++++-
 t/t4150-am.sh |   20 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletions(-)

diff --git c/git-am.sh w/git-am.sh
index e20dd88..e96071d 100755
--- c/git-am.sh
+++ w/git-am.sh
@@ -23,6 +23,7 @@ resolvemsg=     override error message when patch failure occurs
 r,resolved      to be used after a patch failure
 skip            skip the current patch
 abort           restore the original branch and abort the patching operation.
+committer-date-is-author-date    lie about committer date
 rebasing        (internal use for git-rebase)"
 
 . git-sh-setup
@@ -133,6 +134,7 @@ dotest="$GIT_DIR/rebase-apply"
 sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
 resolvemsg= resume=
 git_apply_opt=
+committer_date_is_author_date=
 
 while test $# != 0
 do
@@ -168,6 +170,8 @@ do
 		git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
 	-C|-p)
 		git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
+	--committer-date-is-author-date)
+		committer_date_is_author_date=t ;;
 	--)
 		shift; break ;;
 	*)
@@ -521,7 +525,14 @@ do
 
 	tree=$(git write-tree) &&
 	parent=$(git rev-parse --verify HEAD) &&
-	commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
+	commit=$(
+		if test -n "$committer_date_is_author_date"
+		then
+			GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
+			export GIT_COMMITTER_DATE
+		fi &&
+		git commit-tree $tree -p $parent <"$dotest/final-commit"
+	) &&
 	git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
 	stop_here $this
 
diff --git c/t/t4150-am.sh w/t/t4150-am.sh
index 796f795..8d3fb00 100755
--- c/t/t4150-am.sh
+++ w/t/t4150-am.sh
@@ -257,4 +257,24 @@ test_expect_success 'am works from file (absolute path given) in subdirectory' '
 	test -z "$(git diff second)"
 '
 
+test_expect_success 'am --committer-date-is-author-date' '
+	git checkout first &&
+	test_tick &&
+	git am --committer-date-is-author-date patch1 &&
+	git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
+	at=$(sed -ne "/^author /s/.*> //p" head1) &&
+	ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
+	test "$at" = "$ct"
+'
+
+test_expect_success 'am without --committer-date-is-author-date' '
+	git checkout first &&
+	test_tick &&
+	git am patch1 &&
+	git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
+	at=$(sed -ne "/^author /s/.*> //p" head1) &&
+	ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
+	test "$at" != "$ct"
+'
+
 test_done

  reply	other threads:[~2009-01-23  0:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-22 22:41 how to force a commit date matching info from a mbox ? Christian MICHON
2009-01-23  0:14 ` Junio C Hamano [this message]
2009-01-23  8:08   ` Christian MICHON
2009-01-23  8:51     ` Christian MICHON
2009-01-23  0:21 ` Johannes Schindelin
2009-01-23  8:07   ` Christian MICHON
2009-01-23  0:45 ` Nanako Shiraishi
2009-01-23  7:37   ` Junio C Hamano
2009-01-23  8:26   ` Nanako Shiraishi
2009-01-23  9:39     ` Junio C Hamano
2009-01-23 22:29       ` Jeff King
2009-01-24  0:34         ` Johannes Schindelin
2009-01-24  0:52           ` Jeff King
2009-01-24  1:43             ` Johannes Schindelin
2009-01-24  2:35               ` Jeff King
2009-01-23  9:52     ` Nanako Shiraishi
2009-01-23 17:27       ` Junio C Hamano
2009-01-23 12:38     ` [PATCH] git-am: Add --ignore-date option Johannes Schindelin
2009-01-23 13:17       ` Adeodato Simó

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

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

  git send-email \
    --in-reply-to=7vljt26fp9.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=christian.michon@gmail.com \
    --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.
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 NNTP newsgroup(s).