Skip to content

Commit dede296

Browse files
committed
Merge branch 'ak/git-strip-extension-from-dashed-command'
Code simplification. * ak/git-strip-extension-from-dashed-command: git.c: simplify stripping extension of a file in handle_builtin()
2 parents 7943cba + 63ca1c0 commit dede296

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

git-compat-util.h

-4
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,6 @@ extern char *gitdirname(char *);
325325
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
326326
#endif
327327

328-
#ifndef STRIP_EXTENSION
329-
#define STRIP_EXTENSION ""
330-
#endif
331-
332328
#ifndef has_dos_drive_prefix
333329
static inline int git_has_dos_drive_prefix(const char *path)
334330
{

git.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -513,21 +513,25 @@ int is_builtin(const char *s)
513513
return !!get_builtin(s);
514514
}
515515

516+
#ifdef STRIP_EXTENSION
517+
static void strip_extension(const char **argv)
518+
{
519+
size_t len;
520+
521+
if (strip_suffix(argv[0], STRIP_EXTENSION, &len))
522+
argv[0] = xmemdupz(argv[0], len);
523+
}
524+
#else
525+
#define strip_extension(cmd)
526+
#endif
527+
516528
static void handle_builtin(int argc, const char **argv)
517529
{
518-
const char *cmd = argv[0];
519-
int i;
520-
static const char ext[] = STRIP_EXTENSION;
530+
const char *cmd;
521531
struct cmd_struct *builtin;
522532

523-
if (sizeof(ext) > 1) {
524-
i = strlen(argv[0]) - strlen(ext);
525-
if (i > 0 && !strcmp(argv[0] + i, ext)) {
526-
char *argv0 = xstrdup(argv[0]);
527-
argv[0] = cmd = argv0;
528-
argv0[i] = '\0';
529-
}
530-
}
533+
strip_extension(argv);
534+
cmd = argv[0];
531535

532536
/* Turn "git cmd --help" into "git help cmd" */
533537
if (argc > 1 && !strcmp(argv[1], "--help")) {

0 commit comments

Comments
 (0)