Skip to content

Commit d01b722

Browse files
committed
Merge branch 'ak/run-command-on-cygwin-fix'
Utitiles run via the run_command() API were not spawned correctly on Cygwin, when the paths to them are given as a full path with backslashes. * ak/run-command-on-cygwin-fix: run-command: trigger PATH lookup properly on Cygwin
2 parents 8777ec1 + 05ac858 commit d01b722

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

compat/win32/path-utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ static inline char *win32_find_last_dir_sep(const char *path)
2020
return ret;
2121
}
2222
#define find_last_dir_sep win32_find_last_dir_sep
23+
static inline int win32_has_dir_sep(const char *path)
24+
{
25+
/*
26+
* See how long the non-separator part of the given path is, and
27+
* if and only if it covers the whole path (i.e. path[len] is NUL),
28+
* there is no separator in the path---otherwise there is a separator.
29+
*/
30+
size_t len = strcspn(path, "/\\");
31+
return !!path[len];
32+
}
33+
#define has_dir_sep(path) win32_has_dir_sep(path)
2334
int win32_offset_1st_component(const char *path);
2435
#define offset_1st_component win32_offset_1st_component
2536

git-compat-util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ static inline char *git_find_last_dir_sep(const char *path)
389389
#define find_last_dir_sep git_find_last_dir_sep
390390
#endif
391391

392+
#ifndef has_dir_sep
393+
static inline int git_has_dir_sep(const char *path)
394+
{
395+
return !!strchr(path, '/');
396+
}
397+
#define has_dir_sep(path) git_has_dir_sep(path)
398+
#endif
399+
392400
#ifndef query_user_email
393401
#define query_user_email() NULL
394402
#endif

run-command.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,12 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd)
421421
}
422422

423423
/*
424-
* If there are no '/' characters in the command then perform a path
425-
* lookup and use the resolved path as the command to exec. If there
426-
* are '/' characters, we have exec attempt to invoke the command
427-
* directly.
424+
* If there are no dir separator characters in the command then perform
425+
* a path lookup and use the resolved path as the command to exec. If
426+
* there are dir separator characters, we have exec attempt to invoke
427+
* the command directly.
428428
*/
429-
if (!strchr(out->argv[1], '/')) {
429+
if (!has_dir_sep(out->argv[1])) {
430430
char *program = locate_in_PATH(out->argv[1]);
431431
if (program) {
432432
free((char *)out->argv[1]);

0 commit comments

Comments
 (0)