Message ID | pull.587.v3.git.1585269403947.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v3] run-command: trigger PATH lookup properly on Cygwin | expand |
"András Kucsma via GitGitGadget" <gitgitgadget@gmail.com> writes: > Subject: Re: [PATCH v3] run-command: trigger PATH lookup properly on Cygwin You phrased it much better than my earlier attempt. Succinct, accurate and to the point. Good. > compat/win32/path-utils.h | 11 +++++++++++ > git-compat-util.h | 8 ++++++++ > run-command.c | 10 +++++----- > 3 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h > index f2e70872cd2..18eff7899e9 100644 > --- a/compat/win32/path-utils.h > +++ b/compat/win32/path-utils.h > @@ -20,6 +20,17 @@ static inline char *win32_find_last_dir_sep(const char *path) > return ret; > } > #define find_last_dir_sep win32_find_last_dir_sep > +static inline int win32_has_dir_sep(const char *path) > +{ > + /* > + * See how long the non-separator part of the given path is, and > + * if and only if it covers the whole path (i.e. path[len] is NULL), The name of the ASCII character '\0' is NUL, not NULL (I'll fix it while applying, so no need to resend if you do not have anything else that needs updating). Otherwise, the patch looks good. Thanks.
On Fri, Mar 27, 2020 at 7:04 PM Junio C Hamano <gitster@pobox.com> wrote: > The name of the ASCII character '\0' is NUL, not NULL (I'll fix it > while applying, so no need to resend if you do not have anything > else that needs updating). Right, sorry! I have no other updates. > Otherwise, the patch looks good. > > Thanks. Thanks for the help!
On Mär 27 2020, Junio C Hamano wrote:
> The name of the ASCII character '\0' is NUL, not NULL
NUL is not a name, it is an abbreviation or acronym. Its name is the
Null character.
Andreas.
Andreas Schwab <schwab@linux-m68k.org> writes: > On Mär 27 2020, Junio C Hamano wrote: > >> The name of the ASCII character '\0' is NUL, not NULL > > NUL is not a name, it is an abbreviation or acronym. Its name is the > Null character. OK, let's put it differently. > + * See how long the non-separator part of the given path is, and > + * if and only if it covers the whole path (i.e. path[len] is NULL), When referring to character '\0' like so, write "NUL", not "NULL", as the latter is how you write a null pointer.
diff --git a/compat/win32/path-utils.h b/compat/win32/path-utils.h index f2e70872cd2..18eff7899e9 100644 --- a/compat/win32/path-utils.h +++ b/compat/win32/path-utils.h @@ -20,6 +20,17 @@ static inline char *win32_find_last_dir_sep(const char *path) return ret; } #define find_last_dir_sep win32_find_last_dir_sep +static inline int win32_has_dir_sep(const char *path) +{ + /* + * See how long the non-separator part of the given path is, and + * if and only if it covers the whole path (i.e. path[len] is NULL), + * there is no separator in the path---otherwise there is a separator. + */ + size_t len = strcspn(path, "/\\"); + return !!path[len]; +} +#define has_dir_sep(path) win32_has_dir_sep(path) int win32_offset_1st_component(const char *path); #define offset_1st_component win32_offset_1st_component diff --git a/git-compat-util.h b/git-compat-util.h index aed0b5d4f90..8ba576e81e3 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -389,6 +389,14 @@ static inline char *git_find_last_dir_sep(const char *path) #define find_last_dir_sep git_find_last_dir_sep #endif +#ifndef has_dir_sep +static inline int git_has_dir_sep(const char *path) +{ + return !!strchr(path, '/'); +} +#define has_dir_sep(path) git_has_dir_sep(path) +#endif + #ifndef query_user_email #define query_user_email() NULL #endif diff --git a/run-command.c b/run-command.c index f5e1149f9b3..0f41af3b550 100644 --- a/run-command.c +++ b/run-command.c @@ -421,12 +421,12 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) } /* - * If there are no '/' characters in the command then perform a path - * lookup and use the resolved path as the command to exec. If there - * are '/' characters, we have exec attempt to invoke the command - * directly. + * If there are no dir separator characters in the command then perform + * a path lookup and use the resolved path as the command to exec. If + * there are dir separator characters, we have exec attempt to invoke + * the command directly. */ - if (!strchr(out->argv[1], '/')) { + if (!has_dir_sep(out->argv[1])) { char *program = locate_in_PATH(out->argv[1]); if (program) { free((char *)out->argv[1]);