Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
builtin: move builtin retrieval to get_builtin()
author
Slavomir Vlcek
<svlc@inventati.org>
Wed, 12 Nov 2014 13:10:22 +0000
(14:10 +0100)
committer
Junio C Hamano
<gitster@pobox.com>
Thu, 13 Nov 2014 18:40:41 +0000
(10:40 -0800)
There was a redundant code for a builtin command retrieval in
'handle_builtin()' and 'is_builtin()'.
Introduce a new function 'get_builtin()' and using it from
both of these places to reduce the redundancy.
Signed-off-by: Slavomir Vlcek <svlc@inventati.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
7fa1365
)
diff --git
a/git.c
b/git.c
index 9c495198317bf31ff40785a48bf0a44253548098..84310e30ee7f33209ea1d9cc80e3aa010abd5c64 100644
(file)
--- a/
git.c
+++ b/
git.c
@@
-486,15
+486,20
@@
static struct cmd_struct commands[] = {
{ "write-tree", cmd_write_tree, RUN_SETUP },
};
{ "write-tree", cmd_write_tree, RUN_SETUP },
};
-
int is
_builtin(const char *s)
+
static struct cmd_struct *get
_builtin(const char *s)
{
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
{
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
- struct cmd_struct *p = commands
+
i;
+ struct cmd_struct *p = commands
+
i;
if (!strcmp(s, p->cmd))
if (!strcmp(s, p->cmd))
- return
1
;
+ return
p
;
}
}
- return 0;
+ return NULL;
+}
+
+int is_builtin(const char *s)
+{
+ return !!get_builtin(s);
}
static void handle_builtin(int argc, const char **argv)
}
static void handle_builtin(int argc, const char **argv)
@@
-502,6
+507,7
@@
static void handle_builtin(int argc, const char **argv)
const char *cmd = argv[0];
int i;
static const char ext[] = STRIP_EXTENSION;
const char *cmd = argv[0];
int i;
static const char ext[] = STRIP_EXTENSION;
+ struct cmd_struct *builtin;
if (sizeof(ext) > 1) {
i = strlen(argv[0]) - strlen(ext);
if (sizeof(ext) > 1) {
i = strlen(argv[0]) - strlen(ext);
@@
-518,15
+524,12
@@
static void handle_builtin(int argc, const char **argv)
argv[0] = cmd = "help";
}
argv[0] = cmd = "help";
}
- for (i = 0; i < ARRAY_SIZE(commands); i++) {
- struct cmd_struct *p = commands+i;
- if (strcmp(p->cmd, cmd))
- continue;
- if (saved_environment && (p->option & NO_SETUP)) {
+ builtin = get_builtin(cmd);
+ if (builtin) {
+ if (saved_environment && (builtin->option & NO_SETUP))
restore_env();
restore_env();
- break;
- }
- exit(run_builtin(p, argc, argv));
+ else
+ exit(run_builtin(builtin, argc, argv));
}
}
}
}