Re: [RFC/PATCH 4/6] Add is_git_command_or_alias() for checking availability of a given git command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Tue, 11 Aug 2009, Johan Herland wrote:

> diff --git a/help.c b/help.c
> index 994561d..a616277 100644
> --- a/help.c
> +++ b/help.c
> @@ -296,6 +296,27 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
>  	old->names = NULL;
>  }
>  
> +int is_git_command_or_alias(const char *cmd)
> +{
> +	struct cmdnames main_cmds, other_cmds;
> +
> +	memset(&main_cmds, 0, sizeof(main_cmds));
> +	memset(&other_cmds, 0, sizeof(other_cmds));
> +	memset(&aliases, 0, sizeof(aliases));
> +
> +	git_config(git_unknown_cmd_config, NULL);
> +
> +	load_command_list("git-", &main_cmds, &other_cmds);
> +
> +	add_cmd_list(&main_cmds, &aliases);
> +	add_cmd_list(&main_cmds, &other_cmds);
> +	qsort(main_cmds.names, main_cmds.cnt,
> +	      sizeof(main_cmds.names), cmdname_compare);
> +	uniq(&main_cmds);
> +
> +	return is_in_cmdlist(&main_cmds, cmd);
> +}

Sorting a list is an O(n log n) operation, searching through a list 
linearly is O(n).  You throw away main_cmds (without freeing) after that, 
so I think it is not a good trade-off.

Ciao,
Dscho

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]