Skip to content

Commit 08e21c9

Browse files
committed
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()
2 parents c6f399c + 63ca1c0 commit 08e21c9

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

git-compat-util.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,6 @@ extern char *gitdirname(char *);
333333
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
334334
#endif
335335

336-
#ifndef STRIP_EXTENSION
337-
#define STRIP_EXTENSION ""
338-
#endif
339-
340336
#ifndef has_dos_drive_prefix
341337
static inline int git_has_dos_drive_prefix(const char *path)
342338
{

git.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,21 +502,25 @@ int is_builtin(const char *s)
502502
return !!get_builtin(s);
503503
}
504504

505+
#ifdef STRIP_EXTENSION
506+
static void strip_extension(const char **argv)
507+
{
508+
size_t len;
509+
510+
if (strip_suffix(argv[0], STRIP_EXTENSION, &len))
511+
argv[0] = xmemdupz(argv[0], len);
512+
}
513+
#else
514+
#define strip_extension(cmd)
515+
#endif
516+
505517
static void handle_builtin(int argc, const char **argv)
506518
{
507-
const char *cmd = argv[0];
508-
int i;
509-
static const char ext[] = STRIP_EXTENSION;
519+
const char *cmd;
510520
struct cmd_struct *builtin;
511521

512-
if (sizeof(ext) > 1) {
513-
i = strlen(argv[0]) - strlen(ext);
514-
if (i > 0 && !strcmp(argv[0] + i, ext)) {
515-
char *argv0 = xstrdup(argv[0]);
516-
argv[0] = cmd = argv0;
517-
argv0[i] = '\0';
518-
}
519-
}
522+
strip_extension(argv);
523+
cmd = argv[0];
520524

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

0 commit comments

Comments
 (0)