From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 3/2] Support extracting emails from Signed-off-by lines
Date: Wed, 24 Jun 2009 10:30:29 -0700 [thread overview]
Message-ID: <20090624173029.GF11191@spearce.org> (raw)
In-Reply-To: <1245813109-29763-2-git-send-email-spearce@spearce.org>
A typical Signed-off-by footer line can be seen below in this
message, and it clearly contains an email address (or at least
a user@domain sort of reference to the identity). This identity
may need to be parsed out of a footer line by application code,
to match the Signed-off-by line back to the author or the committer
of the commit, or to some external datastore.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
| 40 ++++++++++++++++++++
| 24 ++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)
--git a/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/FooterLineTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/FooterLineTest.java
index 342346f..431c170 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/FooterLineTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/FooterLineTest.java
@@ -105,6 +105,7 @@ public void testSignedOffBy_OneUserNoLF() {
f = footers.get(0);
assertEquals("Signed-off-by", f.getKey());
assertEquals("A. U. Thor <a@example.com>", f.getValue());
+ assertEquals("a@example.com", f.getEmailAddress());
}
public void testSignedOffBy_OneUserWithLF() {
@@ -119,6 +120,7 @@ public void testSignedOffBy_OneUserWithLF() {
f = footers.get(0);
assertEquals("Signed-off-by", f.getKey());
assertEquals("A. U. Thor <a@example.com>", f.getValue());
+ assertEquals("a@example.com", f.getEmailAddress());
}
public void testSignedOffBy_IgnoreWhitespace() {
@@ -136,6 +138,7 @@ public void testSignedOffBy_IgnoreWhitespace() {
f = footers.get(0);
assertEquals("Signed-off-by", f.getKey());
assertEquals("A. U. Thor <a@example.com> ", f.getValue());
+ assertEquals("a@example.com", f.getEmailAddress());
}
public void testEmptyValueNoLF() {
@@ -150,6 +153,7 @@ public void testEmptyValueNoLF() {
f = footers.get(0);
assertEquals("Signed-off-by", f.getKey());
assertEquals("", f.getValue());
+ assertNull(f.getEmailAddress());
}
public void testEmptyValueWithLF() {
@@ -164,6 +168,7 @@ public void testEmptyValueWithLF() {
f = footers.get(0);
assertEquals("Signed-off-by", f.getKey());
assertEquals("", f.getValue());
+ assertNull(f.getEmailAddress());
}
public void testShortKey() {
@@ -178,6 +183,37 @@ public void testShortKey() {
f = footers.get(0);
assertEquals("K", f.getKey());
assertEquals("V", f.getValue());
+ assertNull(f.getEmailAddress());
+ }
+
+ public void testNonDelimtedEmail() {
+ final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n"
+ + "Acked-by: re@example.com\n");
+ final List<FooterLine> footers = commit.getFooterLines();
+ FooterLine f;
+
+ assertNotNull(footers);
+ assertEquals(1, footers.size());
+
+ f = footers.get(0);
+ assertEquals("Acked-by", f.getKey());
+ assertEquals("re@example.com", f.getValue());
+ assertEquals("re@example.com", f.getEmailAddress());
+ }
+
+ public void testNotEmail() {
+ final RevCommit commit = parse("subject\n\nbody of commit\n" + "\n"
+ + "Acked-by: Main Tain Er\n");
+ final List<FooterLine> footers = commit.getFooterLines();
+ FooterLine f;
+
+ assertNotNull(footers);
+ assertEquals(1, footers.size());
+
+ f = footers.get(0);
+ assertEquals("Acked-by", f.getKey());
+ assertEquals("Main Tain Er", f.getValue());
+ assertNull(f.getEmailAddress());
}
public void testSignedOffBy_ManyUsers() {
@@ -197,18 +233,22 @@ public void testSignedOffBy_ManyUsers() {
f = footers.get(0);
assertEquals("Signed-off-by", f.getKey());
assertEquals("A. U. Thor <a@example.com>", f.getValue());
+ assertEquals("a@example.com", f.getEmailAddress());
f = footers.get(1);
assertEquals("CC", f.getKey());
assertEquals("<some.mailing.list@example.com>", f.getValue());
+ assertEquals("some.mailing.list@example.com", f.getEmailAddress());
f = footers.get(2);
assertEquals("Acked-by", f.getKey());
assertEquals("Some Reviewer <sr@example.com>", f.getValue());
+ assertEquals("sr@example.com", f.getEmailAddress());
f = footers.get(3);
assertEquals("Signed-off-by", f.getKey());
assertEquals("Main Tain Er <mte@example.com>", f.getValue());
+ assertEquals("mte@example.com", f.getEmailAddress());
}
public void testSignedOffBy_SkipNonFooter() {
--git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/FooterLine.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/FooterLine.java
index 1fef47d..b28f52d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/FooterLine.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/FooterLine.java
@@ -114,6 +114,30 @@ public String getValue() {
return RawParseUtils.decode(enc, buffer, valStart, valEnd);
}
+ /**
+ * Extract the email address (if present) from the footer.
+ * <p>
+ * If there is an email address looking string inside of angle brackets
+ * (e.g. "<a@b>"), the return value is the part extracted from inside the
+ * brackets. If no brackets are found, then {@link #getValue()} is returned
+ * if the value contains an '@' sign. Otherwise, null.
+ *
+ * @return email address appearing in the value of this footer, or null.
+ */
+ public String getEmailAddress() {
+ final int lt = RawParseUtils.nextLF(buffer, valStart, '<');
+ if (valEnd <= lt) {
+ final int at = RawParseUtils.nextLF(buffer, valStart, '@');
+ if (valStart < at && at < valEnd)
+ return getValue();
+ return null;
+ }
+ final int gt = RawParseUtils.nextLF(buffer, lt, '>');
+ if (valEnd < gt)
+ return null;
+ return RawParseUtils.decode(enc, buffer, lt, gt - 1);
+ }
+
@Override
public String toString() {
return getKey() + ": " + getValue();
--
1.6.3.3.420.gd4b46
prev parent reply other threads:[~2009-06-24 17:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-24 3:11 [JGIT PATCH 1/2] Add getEncoding() to RevCommit to discover the encoding Shawn O. Pearce
2009-06-24 3:11 ` [JGIT PATCH 2/2] Add parsing support for Signed-off-by lines in commit messages Shawn O. Pearce
2009-06-24 17:30 ` Shawn O. Pearce [this message]
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=20090624173029.GF11191@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
/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).