git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing
Date: Fri, 20 Dec 2013 07:51:00 +0100	[thread overview]
Message-ID: <52B3E8D4.1030805@viscovery.net> (raw)
In-Reply-To: <1387378437-20646-3-git-send-email-pclouds@gmail.com>

Am 12/18/2013 15:53, schrieb Nguyễn Thái Ngọc Duy:
> The code that's not converted to use parse_options() often does
> 
>   if (!starts_with(arg, "foo=")) {
>      value = atoi(arg + 4);
>   }
> 
> This patch removes those magic numbers with skip_prefix()
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/fetch-pack.c     | 13 +++++----
>  builtin/index-pack.c     | 17 +++++------
>  builtin/ls-remote.c      |  9 +++---
>  builtin/mailinfo.c       |  5 ++--
>  builtin/reflog.c         |  9 +++---
>  builtin/rev-parse.c      | 41 +++++++++++++-------------
>  builtin/send-pack.c      | 18 ++++++------
>  builtin/unpack-objects.c |  5 ++--
>  builtin/update-ref.c     | 21 +++++++-------
>  daemon.c                 | 75 ++++++++++++++++++++++++------------------------
>  diff.c                   | 49 +++++++++++++++----------------
>  git.c                    | 13 +++++----
>  merge-recursive.c        | 13 +++++----
>  revision.c               | 60 +++++++++++++++++++-------------------
>  upload-pack.c            |  5 ++--
>  15 files changed, 182 insertions(+), 171 deletions(-)
> 
> diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
> index 8b8978a2..2df1423 100644
> --- a/builtin/fetch-pack.c
> +++ b/builtin/fetch-pack.c
> @@ -47,13 +47,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
>  
>  	for (i = 1; i < argc && *argv[i] == '-'; i++) {
>  		const char *arg = argv[i];
> +		const char *optarg;
>  
> -		if (starts_with(arg, "--upload-pack=")) {
> -			args.uploadpack = arg + 14;
> +		if ((optarg = skip_prefix(arg, "--upload-pack=")) != NULL) {
> +			args.uploadpack = optarg;

Quite frankly, I do not think this is an improvement. The old code is
*MUCH* easier to understand because "starts_with" is clearly a predicate
that is either true or false, but the code with "skip_prefix" is much
heavier on the eye with its extra level of parenthesis. That it removes a
hard-coded constant does not count much IMHO because it is very clear
where the value comes from.

-- Hannes

  reply	other threads:[~2013-12-20  6:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18 14:53 [PATCH 00/12] Hard coded string length cleanup Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 01/12] Make starts_with() a wrapper of skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 17:50   ` Junio C Hamano
2013-12-18 18:16     ` Junio C Hamano
2013-12-18 14:53 ` [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing Nguyễn Thái Ngọc Duy
2013-12-20  6:51   ` Johannes Sixt [this message]
2013-12-20  7:04     ` Jeff King
2013-12-20  8:46       ` Christian Couder
2013-12-20 10:43       ` René Scharfe
2013-12-20 21:31       ` Junio C Hamano
2013-12-21  4:44         ` Duy Nguyen
2013-12-26 19:27           ` Junio C Hamano
2013-12-28  9:54             ` Jeff King
2013-12-18 14:53 ` [PATCH 03/12] Add and use skip_prefix_defval() Nguyễn Thái Ngọc Duy
2013-12-18 16:27   ` Kent R. Spillner
2013-12-18 17:51     ` Junio C Hamano
2013-12-18 14:53 ` [PATCH 04/12] Replace some use of starts_with() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 05/12] Convert a lot of starts_with() to skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 06/12] fetch.c: replace some use of starts_with() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 07/12] connect.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 08/12] refs.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 09/12] diff.c: reduce code duplication in --stat-xxx parsing Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 10/12] environment.c: replace starts_with() in strip_namespace() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 11/12] diff.c: convert diff_scoreopt_parse to use skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 12/12] refs.c: use skip_prefix() in prune_ref() Nguyễn Thái Ngọc Duy
2013-12-18 18:06 ` [PATCH 00/12] Hard coded string length cleanup Junio C Hamano
2013-12-19 23:32 ` René Scharfe
2013-12-19 23:50   ` Duy Nguyen
2013-12-20  1:06     ` René Scharfe
2013-12-20  2:29       ` Duy Nguyen
2013-12-20 16:53       ` Junio C Hamano

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=52B3E8D4.1030805@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=git@vger.kernel.org \
    --cc=pclouds@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).