Merge branch 'ak/git-strip-extension-from-dashed-command' into maint
Code simplification. * ak/git-strip-extension-from-dashed-command: git.c: simplify stripping extension of a file in handle_builtin()
This commit is contained in:
commit
08e21c9b5f
@ -333,10 +333,6 @@ extern char *gitdirname(char *);
|
|||||||
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
|
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STRIP_EXTENSION
|
|
||||||
#define STRIP_EXTENSION ""
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef has_dos_drive_prefix
|
#ifndef has_dos_drive_prefix
|
||||||
static inline int git_has_dos_drive_prefix(const char *path)
|
static inline int git_has_dos_drive_prefix(const char *path)
|
||||||
{
|
{
|
||||||
|
26
git.c
26
git.c
@ -502,21 +502,25 @@ int is_builtin(const char *s)
|
|||||||
return !!get_builtin(s);
|
return !!get_builtin(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef STRIP_EXTENSION
|
||||||
|
static void strip_extension(const char **argv)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (strip_suffix(argv[0], STRIP_EXTENSION, &len))
|
||||||
|
argv[0] = xmemdupz(argv[0], len);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define strip_extension(cmd)
|
||||||
|
#endif
|
||||||
|
|
||||||
static void handle_builtin(int argc, const char **argv)
|
static void handle_builtin(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const char *cmd = argv[0];
|
const char *cmd;
|
||||||
int i;
|
|
||||||
static const char ext[] = STRIP_EXTENSION;
|
|
||||||
struct cmd_struct *builtin;
|
struct cmd_struct *builtin;
|
||||||
|
|
||||||
if (sizeof(ext) > 1) {
|
strip_extension(argv);
|
||||||
i = strlen(argv[0]) - strlen(ext);
|
cmd = argv[0];
|
||||||
if (i > 0 && !strcmp(argv[0] + i, ext)) {
|
|
||||||
char *argv0 = xstrdup(argv[0]);
|
|
||||||
argv[0] = cmd = argv0;
|
|
||||||
argv0[i] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Turn "git cmd --help" into "git help cmd" */
|
/* Turn "git cmd --help" into "git help cmd" */
|
||||||
if (argc > 1 && !strcmp(argv[1], "--help")) {
|
if (argc > 1 && !strcmp(argv[1], "--help")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user