From: Michael Haggerty <mhagger@alum.mit.edu>
To: Tanay Abhra <tanayabh@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, max@quendi.de
Subject: Re: [PATCH v5] commit.c: use skip_prefix() instead of starts_with()
Date: Fri, 21 Mar 2014 16:48:23 +0100 [thread overview]
Message-ID: <532C5F47.3020801@alum.mit.edu> (raw)
In-Reply-To: <1393970831-3558-1-git-send-email-tanayabh@gmail.com>
On 03/04/2014 11:07 PM, Tanay Abhra wrote:
> In record_author_date() & parse_gpg_output(), the callers of
> starts_with() not just want to know if the string starts with the
> prefix, but also can benefit from knowing the string that follows
> the prefix.
>
> By using skip_prefix(), we can do both at the same time.
>
> Helped-by: Max Horn <max@quendi.de>
> Helped-by: Junio C Hamano <gitster@pobox.com>
> Helped-by: Michael Haggerty <mhagger@alum.mit.edu>
> Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
> ---
> Patch V5 Minor revision of indentation
> Patch V4 Identation improved, removed useless comment. [1]
> Thanks to Junio C Hamano and Max Horn.
> [1] http://article.gmane.org/gmane.comp.version-control.git/243388
>
> Patch V3 Variable naming improved, removed assignments inside conditionals.
> Thanks to Junio C Hamano and Max Horn.
>
> Patch V2 Corrected email formatting ,reapplied the implementation according to suggestions.
> Thanks to Michael Haggerty.
>
> This is in respect to GSoC microproject #10.
>
> In record_author_date(), extra and useless calls to strlen due to using starts_with()
> were removed by using skip_prefix(). Extra variable "ident_line" was used as "buf" is used in
> for loop update check.
>
> Other usages of starts_with() in the same file can be found with,
>
> $ grep -n starts_with commit.c
>
> 1116: else if (starts_with(line, gpg_sig_header) &&
> 1196: if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
>
> The starts_with() in line 1116 was left as it is, as strlen values were pre computed as
> global variables, and replacing may hamper the clarity.
> The starts_with() in line 1196 was replaced as it abstracts way the skip_prefix part by
> directly using the function.
> Also skip_prefix() is inline when compared to starts_with().
>
> ---
> commit.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/commit.c b/commit.c
> index 6bf4fe0..d37675c 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -548,7 +548,7 @@ define_commit_slab(author_date_slab, unsigned long);
> static void record_author_date(struct author_date_slab *author_date,
> struct commit *commit)
> {
> - const char *buf, *line_end;
> + const char *buf, *line_end, *ident_line;
> char *buffer = NULL;
> struct ident_split ident;
> char *date_end;
> @@ -566,14 +566,14 @@ static void record_author_date(struct author_date_slab *author_date,
> buf;
> buf = line_end + 1) {
> line_end = strchrnul(buf, '\n');
> - if (!starts_with(buf, "author ")) {
> + ident_line = skip_prefix(buf, "author ");
> + if (!ident_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 "))) ||
> + ident_line, line_end - ident_line) ||
> !ident.date_begin || !ident.date_end)
> goto fail_exit; /* malformed "author" line */
> break;
> @@ -1193,10 +1193,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) {
Nit: There should be a space between "if" and the opening parenthesis.
> found = strstr(buf, sigcheck_gpg_status[i].check);
> if (!found)
> continue;
>
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
next prev parent reply other threads:[~2014-03-21 15:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-04 22:07 [PATCH v5] commit.c: use skip_prefix() instead of starts_with() Tanay Abhra
2014-03-21 15:48 ` Michael Haggerty [this message]
2014-03-21 15:53 ` Michael Haggerty
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=532C5F47.3020801@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=max@quendi.de \
--cc=tanayabh@gmail.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).