git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] split_ident: parse timestamp from end of line

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 15, 2013, 17:52 UTC
Message-ID
<xmqqob6qe808.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20131014232949.GA10415@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 5 quoted lines
>> Yeah, unrolling the loop is probably better.  You may even be able
>> to do so in a single pass with an extra "last > seen" pointer
>> variable without too much additional code complexity, I would think.
>
> I'm not sure what you mean here.
> If you mean doing a single pass to find the final ">", that is easy,
> because we know the length of the line already and can jump past and
> start from the back.
I meant a single forward pass, like this.
 ident.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/ident.c b/ident.c
index 7d1c79c..ff29779 100644
--- a/ident.c
+++ b/ident.c
@@ -200,7 +200,7 @@ static void strbuf_addstr_without_crud(struct strbuf *sb, const char *src)
  */
 int split_ident_line(struct ident_split *split, const char *line, int len)
 {
-	const char *cp;
+	const char *cp, *last_ket;
 	size_t span;
 	int status = -1;
 
@@ -225,29 +225,22 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
 		split->name_end = split->name_begin;
 	}
 
-	for (cp = split->mail_begin; cp < line + len; cp++)
-		if (*cp == '>') {
+	for (cp = split->mail_begin, last_ket = NULL; cp < line + len; cp++) {
+		if (*cp != '>')
+			continue;
+		if (!last_ket)
 			split->mail_end = cp;
-			break;
-		}
+		last_ket = cp;
+	}
 	if (!split->mail_end)
 		return status;
 
 	/*
-	 * Look from the end-of-line to find the trailing ">" of the mail
-	 * address, even though we should already know it as split->mail_end.
-	 * This can help in cases of broken idents with an extra ">" somewhere
-	 * in the email address.  Note that we are assuming the timestamp will
-	 * never have a ">" in it.
-	 *
-	 * Note that we will always find some ">" before going off the front of
-	 * the string, because will always hit the split->mail_end closing
-	 * bracket.
+	 * Typically, last_ket is the same as split_mail_end, but with
+	 * a broken identity line, there may be multiple closing ket '>';
+	 * read the timestamp after the last one.
 	 */
-	for (cp = line + len - 1; *cp != '>'; cp--)
-		;
-
-	for (cp = cp + 1; cp < line + len && isspace(*cp); cp++)
+	for (cp = last_ket + 1; cp < line + len && isspace(*cp); cp++)
 		;
 	if (line + len <= cp)
 		goto person_only;
Previous: Jeff KingNext: Jeff King
Message 7 of 9 in “split_ident: parse timestamp from end of line”
  1. split_ident: parse timestamp from end of lineJeff King, Oct 14, 2013
  2. Junio C HamanoOct 14, 2013
  3. Jeff KingOct 14, 2013
  4. Jeff KingOct 14, 2013
  5. Junio C HamanoOct 14, 2013
  6. Jeff KingOct 14, 2013
  7. Junio C HamanoOct 15, 2013
  8. Jeff KingOct 15, 2013
  9. Junio C HamanoOct 15, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.