git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] am: gather GIT_AUTHOR_* from original commit when rebasing
@ 2010-06-15 22:39 Jay Soffian
  2010-06-16  6:30 ` Johannes Sixt
  0 siblings, 1 reply; 4+ messages in thread
From: Jay Soffian @ 2010-06-15 22:39 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, Junio C Hamano

In certain situations, commit authorship can contain an invalid
e-mail address. For example, this is the case when working with git
svn repos where the author email has the svn repo UUID appended such
as:

 author@example.com <author@example.com@deadbeef-dead-beef-dead-beefdeadbeef>

In such situations, mailinfo extracts the authorship incorrectly
as it assumes a valid email address.

Regardless, when rebasing the original authorship should be
preserved irrespective of its validity as an email address.

This commit teaches am to gather the GIT_AUTHOR_* variables
from the original commit, bypassing any of mailinfo's assumptions.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 git-am.sh         |   14 +++++++++++---
 t/t3400-rebase.sh |    9 +++++++--
 2 files changed, 18 insertions(+), 5 deletions(-)

This is a second take at 
http://article.gmane.org/gmane.comp.version-control.git/148568

diff --git a/git-am.sh b/git-am.sh
index 87ffae2..568844c 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -613,9 +613,17 @@ do
 		;;
 	esac
 
-	GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
-	GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
-	GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
+	if test -f "$dotest/original-commit"
+	then
+		original_commit="$(cat "$dotest/original-commit")"
+		GIT_AUTHOR_NAME="$(GIT_PAGER='' git log --format=%an -1 "$original_commit")"
+		GIT_AUTHOR_EMAIL="$(GIT_PAGER='' git log --format=%ae -1 "$original_commit")"
+		GIT_AUTHOR_DATE="$(GIT_PAGER='' git log --format=%aD -1 "$original_commit")"
+	else
+		GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
+		GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
+		GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
+	fi
 
 	if test -z "$GIT_AUTHOR_EMAIL"
 	then
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index dbf7dfb..c41bcc7 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -10,8 +10,9 @@ among other things.
 '
 . ./test-lib.sh
 
-GIT_AUTHOR_EMAIL=bogus_email_address
-export GIT_AUTHOR_EMAIL
+GIT_AUTHOR_NAME=author@name
+GIT_AUTHOR_EMAIL=bogus@email@address
+export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
 
 test_expect_success \
     'prepare repository with topic branches' \
@@ -80,6 +81,10 @@ test_expect_success \
     'the rebase operation should not have destroyed author information' \
     '! (git log | grep "Author:" | grep "<>")'
 
+test_expect_success \
+    'the rebase operation should not have destroyed author information (2)' \
+    "git log -1 | grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'"
+
 test_expect_success 'HEAD was detached during rebase' '
      test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
 '
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] am: gather GIT_AUTHOR_* from original commit when rebasing
  2010-06-15 22:39 [PATCH v2] am: gather GIT_AUTHOR_* from original commit when rebasing Jay Soffian
@ 2010-06-16  6:30 ` Johannes Sixt
  2010-06-16  7:12   ` [PATCH v3] am: use get_author_ident_from_commit instead of mailinfo " Jay Soffian
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2010-06-16  6:30 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Junio C Hamano

Am 6/16/2010 0:39, schrieb Jay Soffian:
> +	if test -f "$dotest/original-commit"
> +	then
> +		original_commit="$(cat "$dotest/original-commit")"
> +		GIT_AUTHOR_NAME="$(GIT_PAGER='' git log --format=%an -1 "$original_commit")"
> +		GIT_AUTHOR_EMAIL="$(GIT_PAGER='' git log --format=%ae -1 "$original_commit")"
> +		GIT_AUTHOR_DATE="$(GIT_PAGER='' git log --format=%aD -1 "$original_commit")"

I think you can use the function get_author_ident_from_commit() for this.
See git-sh-setup.

-- Hannes

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3] am: use get_author_ident_from_commit instead of mailinfo when rebasing
  2010-06-16  6:30 ` Johannes Sixt
@ 2010-06-16  7:12   ` Jay Soffian
  2010-06-16 19:06     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jay Soffian @ 2010-06-16  7:12 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, Junio C Hamano, Johannes Sixt

In certain situations, commit authorship can consist of an invalid
e-mail address. For example, this is the case when working with git svn
repos where the author email has had the svn repo UUID appended such as:

 author@example.com <author@example.com@deadbeef-dead-beef-dead-beefdeadbeef>

Given such an address, mailinfo extracts the authorship incorrectly as
it assumes a valid domain. However, when rebasing the original
authorship should be preserved irrespective of its validity as an email
address.

Using get_author_ident_from_commit instead of mailinfo when rebasing
preserves the original authorship.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 git-am.sh         |   14 ++++++++++----
 t/t3400-rebase.sh |    9 +++++++--
 2 files changed, 17 insertions(+), 6 deletions(-)

Incorporated Hannes' suggestion to use get_author_ident_from_commit.

diff --git a/git-am.sh b/git-am.sh
index 87ffae2..1df5b04 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -593,7 +593,7 @@ do
 			echo "Patch is empty.  Was it split wrong?"
 			stop_here $this
 		}
-		rm -f "$dotest/original-commit"
+		rm -f "$dotest/original-commit" "$dotest/author-script"
 		if test -f "$dotest/rebasing" &&
 			commit=$(sed -e 's/^From \([0-9a-f]*\) .*/\1/' \
 				-e q "$dotest/$msgnum") &&
@@ -602,6 +602,7 @@ do
 			git cat-file commit "$commit" |
 			sed -e '1,/^$/d' >"$dotest/msg-clean"
 			echo "$commit" > "$dotest/original-commit"
+			get_author_ident_from_commit "$commit" > "$dotest/author-script"
 		else
 			{
 				sed -n '/^Subject/ s/Subject: //p' "$dotest/info"
@@ -613,9 +614,14 @@ do
 		;;
 	esac
 
-	GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
-	GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
-	GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
+	if test -f "$dotest/author-script"
+	then
+		eval $(cat "$dotest/author-script")
+	else
+		GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' "$dotest/info")"
+		GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' "$dotest/info")"
+		GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' "$dotest/info")"
+	fi
 
 	if test -z "$GIT_AUTHOR_EMAIL"
 	then
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index dbf7dfb..c41bcc7 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -10,8 +10,9 @@ among other things.
 '
 . ./test-lib.sh
 
-GIT_AUTHOR_EMAIL=bogus_email_address
-export GIT_AUTHOR_EMAIL
+GIT_AUTHOR_NAME=author@name
+GIT_AUTHOR_EMAIL=bogus@email@address
+export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
 
 test_expect_success \
     'prepare repository with topic branches' \
@@ -80,6 +81,10 @@ test_expect_success \
     'the rebase operation should not have destroyed author information' \
     '! (git log | grep "Author:" | grep "<>")'
 
+test_expect_success \
+    'the rebase operation should not have destroyed author information (2)' \
+    "git log -1 | grep 'Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>'"
+
 test_expect_success 'HEAD was detached during rebase' '
      test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
 '
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] am: use get_author_ident_from_commit instead of mailinfo when rebasing
  2010-06-16  7:12   ` [PATCH v3] am: use get_author_ident_from_commit instead of mailinfo " Jay Soffian
@ 2010-06-16 19:06     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2010-06-16 19:06 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Johannes Sixt

Jay Soffian <jaysoffian@gmail.com> writes:

> In certain situations, commit authorship can consist of an invalid
> e-mail address. For example, this is the case when working with git svn
> repos where the author email has had the svn repo UUID appended such as:
>
>  author@example.com <author@example.com@deadbeef-dead-beef-dead-beefdeadbeef>
>
> Given such an address, mailinfo extracts the authorship incorrectly as
> it assumes a valid domain. However, when rebasing the original
> authorship should be preserved irrespective of its validity as an email
> address.

This justifies the motivation very well.  Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-06-16 19:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-15 22:39 [PATCH v2] am: gather GIT_AUTHOR_* from original commit when rebasing Jay Soffian
2010-06-16  6:30 ` Johannes Sixt
2010-06-16  7:12   ` [PATCH v3] am: use get_author_ident_from_commit instead of mailinfo " Jay Soffian
2010-06-16 19:06     ` Junio C Hamano

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