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

Re: [PATCH 6/7] include $PATH in generating list of commands for "help -a"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 28, 2007, 16:51 UTC
Message-ID
<Pine.LNX.4.64.0710281642220.4362@racer.site>
In-Reply-To
<1193582654-12100-1-git-send-email-srp@srparish.net>
Hi,
On Sun, 28 Oct 2007, Scott R Parish wrote:
Show 34 quoted lines
> 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() ...
Show 17 quoted lines
> @@ -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.
Show 5 quoted lines
> +
> +	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

Previous: Scott R ParishNext: Scott Parish
Message 16 of 25 in “"git" returns 1; "git help" and "git help -a" return 0”
  1. 1/7 "git" returns 1; "git help" and "git help -a" return 0Scott R Parish, Oct 27, 2007
  2. 2/7 remove unused/unneeded "pattern" argument of list_commandsScott R Parish, Oct 27, 2007
  3. 3/7 "current_exec_path" is a misleading name, use "argv_exec_path"Scott R Parish, Oct 27, 2007
  4. 4/7 list_commands(): simplify code by using chdir()Scott R Parish, Oct 27, 2007
  5. 5/7 use only the $PATH for exec'ing git commandsScott R Parish, Oct 27, 2007
  6. 6/7 walk $PATH to generate list of commands for "help -a"Scott R Parish, Oct 27, 2007
  7. 7/7 shell should call the new setup_path() to setup $PATHScott R Parish, Oct 27, 2007
  8. Junio C HamanoOct 28, 2007
  9. Scott ParishOct 28, 2007
  10. Junio C HamanoOct 28, 2007
  11. Scott ParishOct 28, 2007
  12. 6/7 include $PATH in generating list of commands for "help -a"Scott R Parish, Oct 28, 2007
  13. Junio C HamanoOct 28, 2007
  14. Scott ParishOct 28, 2007
  15. 6/7 include $PATH in generating list of commands for "help -a"Scott R Parish, Oct 28, 2007
  16. Johannes SchindelinOct 28, 2007
  17. Scott ParishOct 29, 2007
  18. Johannes SchindelinOct 29, 2007
  19. David SymondsOct 29, 2007
  20. 6/7 include $PATH in generating list of commands for "help -a"Scott R Parish, Oct 29, 2007
  21. Junio C HamanoOct 29, 2007
  22. Scott ParishOct 30, 2007
  23. Junio C HamanoOct 28, 2007
  24. Adam RobenOct 28, 2007
  25. 5/7 use only the $PATH for exec'ing git commandsScott R Parish, Oct 28, 2007

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.