From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH] [PATCH] commit.c: Replace starts_with() with skip_prefix()
Date: Tue, 4 Mar 2014 21:24:05 +0530 [thread overview]
Message-ID: <1393948445-24689-1-git-send-email-karthik.188@gmail.com> (raw)
In record_author_date() :
Replace "buf + strlen(author )" by skip_prefix(), which is
saved in a new "const char" variable "indent_line".
In parse_signed_commit() :
Replace "line + gpg_sig_header_len" by skip_prefix(), which
is saved in a new "const char" variable "indent_line".
In parse_gpg_output() :
Replace "buf + strlen(sigcheck_gpg_status[i].check + 1)" by
skip_prefix(), which is saved in already available
variable "found".
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
commit.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/commit.c b/commit.c
index 6bf4fe0..71a03e3 100644
--- a/commit.c
+++ b/commit.c
@@ -553,6 +553,7 @@ static void record_author_date(struct author_date_slab *author_date,
struct ident_split ident;
char *date_end;
unsigned long date;
+ const char *indent_line;
if (!commit->buffer) {
unsigned long size;
@@ -562,18 +563,19 @@ static void record_author_date(struct author_date_slab *author_date,
return;
}
+ indent_line = 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 (!indent_line) {
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 "))) ||
+ if (split_ident_line(&ident, indent_line,
+ line_end - indent_line) ||
!ident.date_begin || !ident.date_end)
goto fail_exit; /* malformed "author" line */
break;
@@ -1098,6 +1100,7 @@ int parse_signed_commit(const unsigned char *sha1,
char *buffer = read_sha1_file(sha1, &type, &size);
int in_signature, saw_signature = -1;
char *line, *tail;
+ const char *indent_line;
if (!buffer || type != OBJ_COMMIT)
goto cleanup;
@@ -1111,11 +1114,11 @@ int parse_signed_commit(const unsigned char *sha1,
char *next = memchr(line, '\n', tail - line);
next = next ? next + 1 : tail;
+ indent_line = skip_prefix(line, gpg_sig_header);
if (in_signature && line[0] == ' ')
sig = line + 1;
- else if (starts_with(line, gpg_sig_header) &&
- line[gpg_sig_header_len] == ' ')
- sig = line + gpg_sig_header_len + 1;
+ else if (indent_line && indent_line[1] == ' ')
+ sig = indent_line + 2;
if (sig) {
strbuf_add(signature, sig, next - sig);
saw_signature = 1;
@@ -1193,10 +1196,8 @@ 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)) {
- /* At the very beginning of the buffer */
- found = buf + strlen(sigcheck_gpg_status[i].check + 1);
- } else {
+ found = skip_prefix(buf, sigcheck_gpg_status[i].check +1);
+ if(!found) {
found = strstr(buf, sigcheck_gpg_status[i].check);
if (!found)
continue;
--
1.9.0.138.g2de3478
Hey Eric,
As per your suggestion in the previous mail :
http://article.gmane.org/gmane.comp.version-control.git/243316
I have made necessary changes:
1. Better Naming of variables as per suggestion
2. Proper replacement of skip_prefix() over starts_with() .
next reply other threads:[~2014-03-04 15:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-04 15:54 Karthik Nayak [this message]
2014-03-04 17:31 ` [PATCH] [PATCH] commit.c: Replace starts_with() with skip_prefix() Tanay Abhra
2014-03-04 17:58 ` karthik nayak
2014-03-04 22:30 ` Eric Sunshine
2014-03-04 22:27 ` Eric Sunshine
2014-03-04 22:43 ` Eric Sunshine
2014-03-05 7:48 ` Eric Sunshine
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=1393948445-24689-1-git-send-email-karthik.188@gmail.com \
--to=karthik.188@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).