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

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

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Mar 3, 2014, 08:52 UTC
Message-ID
<CAPig+cQLoZy=MV_AqPQseMxsrU6T_PqmCifWn1SrOGwF2FcYzg@mail.gmail.com>
In-Reply-To
<1393832875-29096-1-git-send-email-karthik.188@gmail.com>

Thanks for the submission. Some commentary below to expose you to the review process on this project...

On Mon, Mar 3, 2014 at 2:47 AM, Karthik Nayak <karthik.188@gmail.com> wrote:
> Replace with skip_prefix(), which uses the inbuilt function
> strcmp() to compare.

Explaining the purpose of the change is indeed important, however, this description misses the mark. See below.

> Other Places were this can be implemented:
> commit.c : line 1117
> commit.c : line 1197
Bonus points if you actually follow through with this.
Show 14 quoted lines
> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
>  commit.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/commit.c b/commit.c
> index 6bf4fe0..1e181cf 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;
> +       char *flag_sp; /* stores return value of skip_prefix() */

It's not clear why this variable is needed. It's only assigned (below) but never referenced. Also, the name conveys little or no meaning. If you need a comment to explain the purpose of the variable, that's probably a good indication that it's poorly named.

Show 9 quoted lines
>         unsigned long date;
>
>         if (!commit->buffer) {
> @@ -566,7 +567,7 @@ 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 ")) {
> +               if ((flag_sp = skip_prefix(buf, "author ")) == NULL) {

Unfortunately, this change makes the code more difficult to read. Let's review the GSoC microproject:

    Rewrite commit.c:record_author_date() to use skip_prefix().
    Are there other places in this file where skip_prefix() would
    be **more readable** than starts_with()?

Note the part I **highlighted**. This is a good clue that use of skip_prefix() can be used to simplify the code. Examine record_author_date() more carefully and see if you can identify how to do so.

Show 5 quoted lines
>                         if (!line_end[0] || line_end[1] == '\n')
>                                 return; /* end of header */
>                         continue;
> --
> 1.9.0.138.g2de3478
Previous: Karthik NayakNext: karthik nayak
Message 2 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.