From: Jonathan Nieder <jrnieder@gmail.com>
To: Jeremy Huddleston <jeremyhu@apple.com>
Cc: Thiago Farina <tfransosi@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH updated] Fallback on _NSGetExecutablePath to get the executable path if using argv[0] fails
Date: Mon, 29 Nov 2010 12:49:29 -0600 [thread overview]
Message-ID: <20101129184929.GA9441@burratino> (raw)
In-Reply-To: <DD9829B7-8851-41CF-BCC6-2676B6015028@apple.com>
Jeremy Huddleston wrote:
> This adds better support for RUNTIME_PREFIX on Mac OS X. The previous codepath
> would only work if argv[0] contained the full path to the executable or $PATH
> already contained /path/to/libexec/git-core. We use _NSGetExecutablePath here
> to find the full path (and thus prepend the correct libexec/git-core to $PATH)
> in the case where argv[0] does not contain the full path to the executable.
Closer. But that is perhaps too much at the level of code rather than
the user:
Subject: MacOSX: Use _NSGetExecutablePath to get full argv[0] path
When RUNTIME_PREFIX support is enabled (which is common on Mac OS X)
the exec-path is derived from the program invocation path.
Unfortunately, usual Unix semantics are for argv[0] to contain
the path used to invoke a program rather than the path to the
executable. So usual invocations of git would not result in
helpers from exec-path being found correctly:
$ git fast-import
... example output here ...
So in the spirit of v1.6.0-rc1~21 (Windows: make sure argv[0]
has a path, 2008-07-21), use _NSGetExecutablePath to find the full
path to the git binary, avoiding such trouble.
> --- a/exec_cmd.c
> +++ b/exec_cmd.c
[...]
> @@ -53,6 +57,19 @@ const char *git_extract_argv0_path(const char *argv0)
> if (slash >= argv0) {
> argv0_path = xstrndup(argv0, slash - argv0);
> return slash + 1;
> +#if defined(__APPLE__)
> + } else {
> + char new_argv0[PATH_MAX];
> + uint32_t new_argv0_s = PATH_MAX;
> + if(_NSGetExecutablePath(new_argv0, &new_argv0_s) == 0) {
> + slash = new_argv0 + strlen(new_argv0);
> + while (new_argv0 <= slash && !is_dir_sep(*slash))
> + slash--;
> +
> + if (slash >= new_argv0)
> + argv0_path = xstrndup(new_argv0, slash - new_argv0);
> + }
> +#endif
Can't this ifdef be avoided? The ideal is for such code to be
abstracted away into helper functions in git-compat-util.h and compat/*.c.
Jonathan
next prev parent reply other threads:[~2010-11-29 18:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-29 16:57 [PATCH] Fallback on _NSGetExecutablePath to get the executable path if using argv[0] fails Jeremy Huddleston
2010-11-29 17:09 ` Thiago Farina
2010-11-29 17:12 ` Jonathan Nieder
2010-11-29 18:29 ` [PATCH updated] " Jeremy Huddleston
2010-11-29 18:49 ` Jonathan Nieder [this message]
2010-11-29 20:24 ` Junio C Hamano
2010-11-29 21:02 ` Jeremy Huddleston
2010-11-29 18:34 ` [PATCH] " Jeremy Huddleston
2010-11-29 18:50 ` Jonathan Nieder
2010-11-29 20:07 ` Jeremy Huddleston
2010-11-29 20:19 ` Jonathan Nieder
2010-11-29 23:13 ` Kevin Ballard
2010-12-03 7:42 ` Jonathan Nieder
2010-12-03 7:50 ` Kevin Ballard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101129184929.GA9441@burratino \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=jeremyhu@apple.com \
--cc=tfransosi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).