git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Scott R Parish <srp@srparish.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 6/7] include $PATH in generating list of commands for "help -a"
Date: Sun, 28 Oct 2007 16:51:00 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0710281642220.4362@racer.site> (raw)
In-Reply-To: <1193582654-12100-1-git-send-email-srp@srparish.net>

Hi,

On Sun, 28 Oct 2007, Scott R Parish wrote:

> diff --git a/help.c b/help.c
> index 34ac5db..07cf67a 100644
> --- a/help.c
> +++ b/help.c
> @@ -37,24 +37,28 @@ static inline void mput_char(char c, unsigned int num)
>  		putchar(c);
>  }
>  
> -static struct cmdname {
> -	size_t len;
> -	char name[1];
> -} **cmdname;
> -static int cmdname_alloc, cmdname_cnt;
> -
> -static void add_cmdname(const char *name, int len)
> +static struct cmdnames {
> +	int alloc;
> +	int cnt;
> +	struct cmdname {
> +		size_t len;
> +		char name[1];
> +	} **names;
> +} main_cmds, other_cmds;
> +
> +static void add_cmdname(struct cmdnames *cmds, const char *name, int len)
>  {
>  	struct cmdname *ent;
> -	if (cmdname_alloc <= cmdname_cnt) {
> -		cmdname_alloc = cmdname_alloc + 200;
> -		cmdname = xrealloc(cmdname, cmdname_alloc * sizeof(*cmdname));
> +	if (cmds->alloc <= cmds->cnt) {
> +		cmds->alloc = cmds->alloc + 200;
> +		cmds->names = xrealloc(cmds->names,
> +				       cmds->alloc * sizeof(*cmds->names));

Looks like a candidate for ALLOC_GROW() ...

> @@ -64,7 +68,44 @@ static int cmdname_compare(const void *a_, const void *b_)
>  	return strcmp(a->name, b->name);
>  }
>  
> -static void pretty_print_string_list(struct cmdname **cmdname, int longest)
> +static void uniq(struct cmdnames *cmds)
> +{
> +	int i, j;
> +
> +	if (!cmds->cnt)
> +		return;
> +
> +	for (i = j = 1; i < cmds->cnt; i++) {
> +		if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) {
> +			cmds->names[j++] = cmds->names[i];
> +		}
> +	}

Losing the curly brackets would make this look much nicer.

> +
> +	cmds->cnt = j;
> +}
> +
> +static void subtract_cmds(struct cmdnames *a, struct cmdnames *b) {

Maybe "exclude_cmds()", and choose more suggestive names for the 
parameters?

> -	DIR *dir = opendir(exec_path);
> +	DIR *dirp = opendir(dir);

I am not sure that a rename from "dir" to "dirp" is needed here.  It 
distracts a little from the real content of your patch.

Thanks,
Dscho

  reply	other threads:[~2007-10-28 16:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-27  8:36 [PATCH 1/7] "git" returns 1; "git help" and "git help -a" return 0 Scott R Parish
2007-10-27  8:36 ` [PATCH 2/7] remove unused/unneeded "pattern" argument of list_commands Scott R Parish
2007-10-27  8:36   ` [PATCH 3/7] "current_exec_path" is a misleading name, use "argv_exec_path" Scott R Parish
2007-10-27  8:36     ` [PATCH 4/7] list_commands(): simplify code by using chdir() Scott R Parish
2007-10-27  8:36       ` [PATCH 5/7] use only the $PATH for exec'ing git commands Scott R Parish
2007-10-27  8:36         ` [PATCH 6/7] walk $PATH to generate list of commands for "help -a" Scott R Parish
2007-10-27  8:36           ` [PATCH 7/7] shell should call the new setup_path() to setup $PATH Scott R Parish
2007-10-28  6:18           ` [PATCH 6/7] walk $PATH to generate list of commands for "help -a" Junio C Hamano
2007-10-28  9:45             ` Scott Parish
2007-10-28 10:07               ` Junio C Hamano
2007-10-28 11:15                 ` Scott Parish
2007-10-28 11:18           ` [PATCH 6/7] include $PATH in generating " Scott R Parish
2007-10-28 11:32             ` Junio C Hamano
2007-10-28 14:39               ` Scott Parish
2007-10-28 14:44           ` Scott R Parish
2007-10-28 16:51             ` Johannes Schindelin [this message]
2007-10-29  2:44               ` Scott Parish
2007-10-29 11:30                 ` Johannes Schindelin
2007-10-29 11:45                   ` David Symonds
2007-10-29  3:30           ` Scott R Parish
2007-10-29 21:17             ` Junio C Hamano
2007-10-30  3:00               ` Scott Parish
2007-10-28  6:18         ` [PATCH 5/7] use only the $PATH for exec'ing git commands Junio C Hamano
2007-10-28  6:19           ` Adam Roben
2007-10-28 11:17         ` Scott R Parish

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=Pine.LNX.4.64.0710281642220.4362@racer.site \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=srp@srparish.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).