From: Junio C Hamano <gitster@pobox.com>
To: Scott R Parish <srp@srparish.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 6/7] walk $PATH to generate list of commands for "help -a"
Date: Sat, 27 Oct 2007 23:18:02 -0700 [thread overview]
Message-ID: <7vsl3vzrs5.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 1193474215-6728-6-git-send-email-srp@srparish.net
Scott R Parish <srp@srparish.net> writes:
> Git had previously been using the $PATH for scripts--a previous
> patch moved exec'ed commands to also use the $PATH. For consistancy
> "help -a" should also use the $PATH.
s/consistancy/consistency/
> We walk all the paths in $PATH collecting the names of "git-*"
> commands. To help distinguish between the main git commands
> and commands picked up elsewhere (probably extensions) we
> print them seperately. The main commands are the ones that
> are found in the first directory in $PATH that contains the
> "git" binary.
This is not right. $(gitexecdir) in Makefile is designed to
allow distros to move git-* commands out of the primary user
$PATH directories and install only "git" wrapper in /usr/bin.
"Use the directory 'git' is in" rule breaks this.
The "main commands" should be the first of argv_exec_path,
EXEC_PATH_ENVIRONMENT or builtin_exec_path.
> diff --git a/help.c b/help.c
> index ce3d795..ee4fce0 100644
> --- a/help.c
> +++ b/help.c
> @@ -64,7 +69,42 @@ static int cmdname_compare(const void *a_, const void *b_)
> ...
> +static void subtract_cmds(struct cmdnames *a, struct cmdnames *b) {
> + int ai, aj, bi;
> +
> + ai = aj = bi = 0;
> + while (ai < a->cnt && bi < b->cnt) {
> + if (0 > strcmp(a->names[ai]->name, b->names[bi]->name))
> + a->names[aj++] = a->names[ai++];
> + else if (0 > strcmp(a->names[ai]->name, b->names[bi]->name))
> + bi++;
> + else
> + ai++, bi++;
In general, xxxcmp(a, b) is designed to return the same sign as
"a - b" (subtract b from a, using an appropriate definition of
"subtract" in the domain of a and b). It is a good habit to
write:
strcmp(a, b) < 0 strcmp(a, b) > 0
because these give the same sign as
a < b a > b
and makes your program easier to read.
> @@ -122,18 +168,66 @@ static void list_commands(const char *exec_path)
> if (has_extension(de->d_name, ".exe"))
> entlen -= 4;
>
> + if (has_extension(de->d_name, ".perl") ||
> + has_extension(de->d_name, ".sh"))
> + continue;
> +
This needs a good justification.
If you have "." on PATH, and you run ./git in a freshly built
source directory, "git relink.perl" would try to run
./git-relink.perl.
I do not think excluding these is necessary nor is a good idea.
> +static void list_commands()
> +{
ANSI. "static void list_commands(void)".
> + path = paths = xstrdup(env_path);
> + while ((char *)1 != path) {
> + if ((colon = strchr(path, ':')))
> + *colon = 0;
> +
> + len = list_commands_in_dir(path);
> + longest = MAX(longest, len);
> +
> + path = colon + 1;
> + }
I know that on modern architectures bit representation of
(char*) NULL is the same as integer 0 of the same size as a
pointer, and adding 1 to it would yield (char *)1, but the above
feels _dirty_.
while (1) {
...
if (!colon)
break;
path = colon + 1;
}
next prev parent reply other threads:[~2007-10-28 6:18 UTC|newest]
Thread overview: 30+ 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 ` Junio C Hamano [this message]
2007-10-28 9:45 ` [PATCH 6/7] walk $PATH to generate list of commands for "help -a" 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
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
-- strict thread matches above, loose matches on Subject: below --
2007-10-25 3:37 [PATCH 1/7] "git" calls help_unknown_cmd(""); "git help" and "git help -a" return 0 Scott R Parish
2007-10-25 3:37 ` [PATCH 2/7] s/pattern/prefix/ in help's list_commands Scott R Parish
2007-10-25 3:37 ` [PATCH 3/7] "current_exec_path" is a misleading name, use "argv_exec_path" Signed-off-by: Scott R Parish <srp@srparish.net> Scott R Parish
2007-10-25 3:37 ` [PATCH 4/7] use only the PATH for exec'ing git commands Scott R Parish
2007-10-25 3:37 ` [PATCH 5/7] chdir() into list_commands() dir instead of building paths for stat() Scott R Parish
2007-10-25 3:37 ` [PATCH 6/7] walk PATH to generate list of commands for "help -a" Scott R Parish
2007-10-25 4:42 ` Junio C Hamano
2007-10-25 5:07 ` Scott Parish
2007-10-25 5:33 ` Junio C Hamano
2007-10-25 7:07 ` Scott 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=7vsl3vzrs5.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--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).