git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Jari Aalto <jari.aalto@cante.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile
Date: Mon, 28 Jan 2008 14:32:51 -0800 (PST)	[thread overview]
Message-ID: <m3y7a98ttg.fsf@localhost.localdomain> (raw)
In-Reply-To: <y7a9aaem.fsf@blue.sea.net>

Jari Aalto <jari.aalto@cante.net> writes:

> * str_replace(): New function. Generic replace command.
> * str_replace_home(): New function. Substitute $HOME and tilde(~) in string.
> * git_default_config(): Pass core.excludesfile to str_replace_home().
> 
> Signed-off-by: Jari Aalto <jari.aalto AT cante.net>

First, git project does NOT use GNU ChangeLog convention for it's
commit messages.  We rather use descriptive commit messages.

Second, I'm not sure about str_replace... how it fits with strbufs?
AFAIK we try to use strbufs whenever possible and feasible, to avoid
errors in git.

Third, I agree that it is a good idea, but I'd rather have *full*
solution, i.e. for git to expand $HOME (or better yet any
environmental variable) and '~' everywhere, not only for
core.excludesfile, but also for --git-dir and GIT_DIR, for
core.worktree and --work-tree and GIT_WORK_TREE, and for all other
config variables and enviroment variables.

> ---
> 
>  From ac6941f5055b2acdded59627d228bbf03ba0d9fc

What does it mean? A bit cryptic, don't you think?


Comments on code below. One thing: we use tabs for indent, not
spaces.  You use spaces in your code, while context uses tabs.

> +char *str_replace(const char *str, const char *find, const char *replace)
> +{
> +        int maxlen   = strlen(str) + strlen(replace) + 1;
> +        char *start  = strstr(str, find);
> +        char *ptr    = (char *)malloc(maxlen);
> +        int len      = strlen(find);
> +        int llen, rlen;         /* left, right portion length */
> +
> +        if (start == (char *)NULL) {

There is no need to cast NULL. Besides, we write IIRC "if (!start)",
it is common enough idiom.

> +                strcpy( ptr, str);

Style: no space after opening parenthesis: "strcpy(ptr, str)".
Performance: I think it would be better to use stpcpy, although I'm
not quite sure if here too.

> +        }
> +        else{
> +                rlen = strlen(start) - strlen(find);
> +                llen = strlen(str) - strlen(start);
> +                strncpy( ptr, str, llen);
> +                strcat( ptr, replace);
> +                strncat( ptr, start + len, rlen); /* Does not add  '\0' */
> +                strcat( ptr, "");   /* Terminate with null string */

Performance suck here; although this is not time-critical path using
sequence of strcat is just bad style. And 'strcat( ptr, "");' just
takes the cake: use "ptr[len] = '\0'", ehere 'len' is calculated
length of string.

P.S. Junio, when do you think 1.5.4 would be finally released? We have
feature freeze still, isn't it?

-- 
Jakub Narebski
Poland
ShadeHawk on #git

  parent reply	other threads:[~2008-01-28 22:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-28 21:49 [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile Jari Aalto
2008-01-28 22:28 ` Johannes Schindelin
2008-01-28 22:32 ` Jakub Narebski [this message]
2008-01-29  5:59   ` Miles Bader
2008-01-29  7:25     ` David Symonds
2008-01-29  7:51       ` Miles Bader
2008-01-28 23:52 ` Wayne Davison

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=m3y7a98ttg.fsf@localhost.localdomain \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jari.aalto@cante.net \
    /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).