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

Re: [PATCH] commit.c: Replace starts_with() with skip_prefix()

From
karthik nayak <karthik.188@gmail.com>
Date
Mar 3, 2014, 15:23 UTC
Message-ID
<CAOLa=ZRxj-iBiQRXEYvq6MrQyQcyzk32kPij8zzxh4ECbBrnMw@mail.gmail.com>
In-Reply-To
<CAPig+cQLoZy=MV_AqPQseMxsrU6T_PqmCifWn1SrOGwF2FcYzg@mail.gmail.com>
Hello Eric,
Thanks for Pointing out everything, i had a thorough look and fixed a
couple of things.
Here is an Updated Patch.
- Removed unnecessary code and variables.
- Replaced all instances of starts_with() with skip_prefix()

Replace starts_with() with skip_prefix() for better reading purposes. Also to replace "buf + strlen(author )" by skip_prefix(), which is saved in a new "const char" variable "buf_skipprefix".

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 commit.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/commit.c b/commit.c
index 6bf4fe0..e5dc2e2 100644
--- a/commit.c
+++ b/commit.c
@@ -552,6 +552,7 @@ static void record_author_date(struct
author_date_slab *author_date,
  char *buffer = NULL;
  struct ident_split ident;
  char *date_end;
+ const char *buf_skipprefix;
  unsigned long date;

  if (!commit->buffer) {
@@ -562,18 +563,20 @@ static void record_author_date(struct
author_date_slab *author_date,
  return;
  }

+ buf_skipprefix = skip_prefix(buf, "author ");
+
  for (buf = commit->buffer ? commit->buffer : buffer;
      buf;
      buf = line_end + 1) {
  line_end = strchrnul(buf, '\n');
- if (!starts_with(buf, "author ")) {
+ if (!buf_skipprefix) {
  if (!line_end[0] || line_end[1] == '\n')
  return; /* end of header */
  continue;
  }
  if (split_ident_line(&ident,
-     buf + strlen("author "),
-     line_end - (buf + strlen("author "))) ||
+ buf_skipprefix,
+ line_end - buf_skipprefix) ||
     !ident.date_begin || !ident.date_end)
  goto fail_exit; /* malformed "author" line */
  break;
@@ -1113,7 +1116,7 @@ int parse_signed_commit(const unsigned char *sha1,
  next = next ? next + 1 : tail;
  if (in_signature && line[0] == ' ')
  sig = line + 1;
- else if (starts_with(line, gpg_sig_header) &&
+ else if (skip_prefix(line, gpg_sig_header) &&
  line[gpg_sig_header_len] == ' ')
  sig = line + gpg_sig_header_len + 1;
  if (sig) {
@@ -1193,7 +1196,7 @@ static void parse_gpg_output(struct signature_check *sigc)
  for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
  const char *found, *next;

- if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
+ if (skip_prefix(buf, sigcheck_gpg_status[i].check + 1)) {
  /* At the very beginning of the buffer */
  found = buf + strlen(sigcheck_gpg_status[i].check + 1);
  } else {
-- 
1.9.0.138.g2de3478
Previous: Eric SunshineNext: Eric Sunshine
Message 3 of 4 in “commit.c: Replace starts_with() with skip_prefix()”
  1. commit.c: Replace starts_with() with skip_prefix()Karthik Nayak, Mar 3, 2014
  2. Eric SunshineMar 3, 2014
  3. karthik nayakMar 3, 2014
  4. Eric SunshineMar 3, 2014

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.