From: Miklos Vajna <vmiklos@frugalware.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 3/6] builtin-help: make it possible to exclude some commands in list_commands()
Date: Tue, 29 Jul 2008 01:24:52 +0200 [thread overview]
Message-ID: <5ad105819efb1c905bd01db3d08eb3422d283b3b.1217287269.git.vmiklos@frugalware.org> (raw)
In-Reply-To: <7vr69ex00x.fsf@gitster.siamese.dyndns.org>
The supposed method is to build a list of commands to be excluded using
add_cmdname(), then pass the list as the new exclude parameter. If no
exclude is needed, NULL should be used.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
On Sun, Jul 27, 2008 at 06:36:30PM -0700, Junio C Hamano <gitster@pobox.com> wrote:
> > + struct cmdname {
> > + size_t len;
> > + char name[1];
> > + } **names;
> > +};
>
> I thought we do this kind of thing using FLEX_ARRAY macro. Is there
> any
> reason its use is not appropriate here?
Now I'm using it. :-)
Note that FLEX_ARRAY would be a drop-in replacement only in case it
would be name[0], so I needed
- struct cmdname *ent = xmalloc(sizeof(*ent) + len);
+ struct cmdname *ent = xmalloc(sizeof(*ent) + len + 1);
later in add_cmdname().
help.c | 26 +++++++++++---------------
help.h | 14 +++++++++++++-
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/help.c b/help.c
index 7a42517..858f76a 100644
--- a/help.c
+++ b/help.c
@@ -9,6 +9,7 @@
#include "common-cmds.h"
#include "parse-options.h"
#include "run-command.h"
+#include "help.h"
static struct man_viewer_list {
struct man_viewer_list *next;
@@ -300,18 +301,11 @@ static inline void mput_char(char c, unsigned int num)
putchar(c);
}
-static struct cmdnames {
- int alloc;
- int cnt;
- struct cmdname {
- size_t len;
- char name[1];
- } **names;
-} main_cmds, other_cmds;
+struct cmdnames main_cmds, other_cmds;
-static void add_cmdname(struct cmdnames *cmds, const char *name, int len)
+void add_cmdname(struct cmdnames *cmds, const char *name, int len)
{
- struct cmdname *ent = xmalloc(sizeof(*ent) + len);
+ struct cmdname *ent = xmalloc(sizeof(*ent) + len + 1);
ent->len = len;
memcpy(ent->name, name, len);
@@ -463,7 +457,7 @@ static unsigned int list_commands_in_dir(struct cmdnames *cmds,
return longest;
}
-static unsigned int load_command_list(const char *prefix)
+static unsigned int load_command_list(const char *prefix, struct cmdnames *exclude)
{
unsigned int longest = 0;
unsigned int len;
@@ -502,13 +496,15 @@ static unsigned int load_command_list(const char *prefix)
sizeof(*other_cmds.names), cmdname_compare);
uniq(&other_cmds);
exclude_cmds(&other_cmds, &main_cmds);
+ if (exclude)
+ exclude_cmds(&main_cmds, exclude);
return longest;
}
-void list_commands(const char *prefix, const char *title)
+void list_commands(const char *prefix, const char *title, struct cmdnames *exclude)
{
- unsigned int longest = load_command_list(prefix);
+ unsigned int longest = load_command_list(prefix, exclude);
const char *exec_path = git_exec_path();
if (main_cmds.cnt) {
@@ -558,7 +554,7 @@ static int is_in_cmdlist(struct cmdnames *c, const char *s)
int is_git_command(const char *s, const char *prefix)
{
- load_command_list(prefix);
+ load_command_list(prefix, NULL);
return is_in_cmdlist(&main_cmds, s) ||
is_in_cmdlist(&other_cmds, s);
}
@@ -704,7 +700,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
if (show_all) {
printf("usage: %s\n\n", git_usage_string);
- list_commands("git-", "git commands");
+ list_commands("git-", "git commands", NULL);
printf("%s\n", git_more_info_string);
return 0;
}
diff --git a/help.h b/help.h
index 0741662..3eb8cfb 100644
--- a/help.h
+++ b/help.h
@@ -1,7 +1,19 @@
#ifndef HELP_H
#define HELP_H
+struct cmdnames {
+ int alloc;
+ int cnt;
+ struct cmdname {
+ size_t len;
+ char name[FLEX_ARRAY];
+ } **names;
+};
+
int is_git_command(const char *s, const char *prefix);
-void list_commands(const char *prefix, const char *title);
+void list_commands(const char *prefix, const char *title, struct cmdnames *exclude);
+void add_cmdname(struct cmdnames *cmds, const char *name, int len);
+
+extern struct cmdnames main_cmds, other_cmds;
#endif /* HELP_H */
--
1.6.0.rc0.14.g95f8.dirty
next prev parent reply other threads:[~2008-07-28 23:25 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-26 11:54 [PATCH 0/7] Allow custom merge strategies Miklos Vajna
2008-07-26 11:54 ` [PATCH 1/7] Make is_git_command() usable outside builtin-help Miklos Vajna
2008-07-26 18:12 ` Jonathan Nieder
2008-07-28 1:18 ` Miklos Vajna
2008-07-28 1:21 ` [PATCH 0/6] Allow custom merge strategies, take 2 Miklos Vajna
2008-07-28 1:21 ` [PATCH 1/6] builtin-help: make is_git_command() usable outside builtin-help Miklos Vajna
2008-07-28 1:21 ` [PATCH 2/6] builtin-help: make list_commands() a bit more generic Miklos Vajna
2008-07-28 1:21 ` [PATCH 3/6] builtin-help: make it possible to exclude some commands in list_commands() Miklos Vajna
2008-07-28 1:21 ` [PATCH 4/6] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-28 1:21 ` [PATCH 5/6] builtin-merge: avoid non-strategy git-merge commands in error message Miklos Vajna
2008-07-28 1:21 ` [PATCH 6/6] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-28 13:12 ` Johannes Schindelin
2008-07-28 23:39 ` Miklos Vajna
2008-07-28 23:54 ` Johannes Schindelin
2008-07-28 23:58 ` Miklos Vajna
2008-07-29 0:01 ` Miklos Vajna
2008-07-28 13:06 ` [PATCH 5/6] builtin-merge: avoid non-strategy git-merge commands in error message Johannes Schindelin
2008-07-28 23:48 ` [PATCH] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-28 23:59 ` Johannes Schindelin
2008-07-28 1:36 ` [PATCH 3/6] builtin-help: make it possible to exclude some commands in list_commands() Junio C Hamano
2008-07-28 2:43 ` Johannes Schindelin
2008-07-28 3:05 ` Junio C Hamano
2008-07-28 4:29 ` Junio C Hamano
2008-07-28 9:58 ` Johannes Schindelin
2008-07-28 23:24 ` Miklos Vajna [this message]
2008-07-29 15:24 ` [PATCH 0/5] Allow custom merge strategies, take 3 Miklos Vajna
2008-07-29 15:24 ` [PATCH 1/5] builtin-help: make is_git_command() usable outside builtin-help Miklos Vajna
2008-07-29 15:25 ` [PATCH 2/5] builtin-help: make list_commands() a bit more generic Miklos Vajna
2008-07-29 15:25 ` [PATCH 3/5] builtin-help: make it possible to exclude some commands in list_commands() Miklos Vajna
2008-07-29 15:25 ` [PATCH 4/5] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-29 15:25 ` [PATCH 5/5] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-29 19:47 ` [PATCH 4/5] builtin-merge: allow using a custom strategy Junio C Hamano
2008-07-29 23:16 ` [PATCH 0/4] Allow custom merge strategies, take 4 Miklos Vajna
2008-07-29 23:16 ` [PATCH 1/4] builtin-help: make some internal functions available to other builtins Miklos Vajna
2008-07-29 23:16 ` [PATCH 2/4] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-29 23:17 ` [PATCH 3/4] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-29 23:17 ` [PATCH 4/4] Add a second testcase for handling invalid strategies in git-merge Miklos Vajna
2008-07-29 23:42 ` Junio C Hamano
2008-07-30 17:27 ` Miklos Vajna
2008-07-29 23:43 ` [PATCH 3/4] Add a new test for using a custom merge strategy Junio C Hamano
2008-07-30 17:25 ` Miklos Vajna
2008-07-30 6:21 ` [PATCH 1/4] builtin-help: make some internal functions available to other builtins Junio C Hamano
2008-07-29 19:46 ` [PATCH 3/5] builtin-help: make it possible to exclude some commands in list_commands() Junio C Hamano
2008-07-29 21:25 ` Miklos Vajna
-- strict thread matches above, loose matches on Subject: below --
2008-07-21 16:10 [PATCH] builtin-merge: give a proper error message for invalid strategies in config Miklos Vajna
2008-07-22 5:01 ` Junio C Hamano
2008-07-22 5:22 ` Junio C Hamano
2008-07-22 7:39 ` Miklos Vajna
2008-07-22 8:24 ` Junio C Hamano
2008-07-22 17:05 ` [PATCH] t7601: extend the 'merge picks up the best result' test Miklos Vajna
2008-07-26 11:54 ` Miklos Vajna
2008-07-26 11:54 ` [PATCH 2/7] builtin-help: change the current directory back in list_commands_in_dir() Miklos Vajna
2008-07-26 11:54 ` [PATCH 3/7] builtin-help: make list_commands() a bit more generic Miklos Vajna
2008-07-26 11:54 ` [PATCH 4/7] builtin-merge: allow using a custom strategy Miklos Vajna
2008-07-26 11:54 ` [PATCH 5/7] Add a new test for using a custom merge strategy Miklos Vajna
2008-07-26 11:54 ` [PATCH 6/7] builtin-help: make it possible to exclude some commands in list_commands() Miklos Vajna
2008-07-26 11:54 ` [PATCH 7/7] builtin-merge: avoid non-strategy git-merge commands in error message Miklos Vajna
2008-07-26 15:08 ` Johannes Schindelin
2008-07-26 15:25 ` Miklos Vajna
2008-07-26 15:27 ` Miklos Vajna
2008-07-26 15:38 ` Johannes Schindelin
2008-07-26 16:00 ` Miklos Vajna
2008-07-26 17:01 ` Johannes Schindelin
2008-07-26 17:12 ` [PATCH] " Miklos Vajna
2008-07-26 18:28 ` [PATCH 3/7] builtin-help: make list_commands() a bit more generic Jonathan Nieder
2008-07-26 21:40 ` Miklos Vajna
2008-07-26 14:58 ` [PATCH 2/7] builtin-help: change the current directory back in list_commands_in_dir() Johannes Schindelin
2008-07-27 20:02 ` Junio C Hamano
2008-07-27 20:21 ` Johannes Schindelin
2008-07-27 20:34 ` [PATCH] Avoid chdir() " Johannes Schindelin
2008-07-26 12:33 ` [PATCH] t7601: extend the 'merge picks up the best result' test Miklos Vajna
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5ad105819efb1c905bd01db3d08eb3422d283b3b.1217287269.git.vmiklos@frugalware.org \
--to=vmiklos@frugalware.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).