Skip to content

Commit

Permalink
Merge branch 'js/more-win'
Browse files Browse the repository at this point in the history
* js/more-win:
  help (Windows): Display HTML in default browser using Windows' shell API
  help.c: Add support for htmldir relative to git_exec_path()
  Move code interpreting path relative to exec-dir to new function system_path()
  • Loading branch information
Junio C Hamano committed Jul 16, 2008
2 parents fab600c + 4804aab commit 1466080
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 26 deletions.
14 changes: 2 additions & 12 deletions builtin-init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,8 @@ static void copy_templates(const char *template_dir)

if (!template_dir)
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
if (!template_dir) {
/*
* if the hard-coded template is relative, it is
* interpreted relative to the exec_dir
*/
template_dir = DEFAULT_GIT_TEMPLATE_DIR;
if (!is_absolute_path(template_dir)) {
struct strbuf d = STRBUF_INIT;
strbuf_addf(&d, "%s/%s", git_exec_path(), template_dir);
template_dir = strbuf_detach(&d, NULL);
}
}
if (!template_dir)
template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
strcpy(template_path, template_dir);
template_len = strlen(template_path);
if (template_path[template_len-1] != '/') {
Expand Down
22 changes: 22 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,3 +1017,25 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
timer_fn = handler;
return old;
}

static const char *make_backslash_path(const char *path)
{
static char buf[PATH_MAX + 1];
char *c;

if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
die("Too long path: %.*s", 60, path);

for (c = buf; *c; c++) {
if (*c == '/')
*c = '\\';
}
return buf;
}

void mingw_open_html(const char *unixpath)
{
const char *htmlpath = make_backslash_path(unixpath);
printf("Launching default browser to display HTML ...\n");
ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
}
3 changes: 3 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);
#define PATH_SEP ';'
#define PRIuMAX "I64u"

void mingw_open_html(const char *path);
#define open_html mingw_open_html

/*
* helpers
*/
Expand Down
11 changes: 2 additions & 9 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,8 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
const char *git_etc_gitconfig(void)
{
static const char *system_wide;
if (!system_wide) {
system_wide = ETC_GITCONFIG;
if (!is_absolute_path(system_wide)) {
/* interpret path relative to exec-dir */
struct strbuf d = STRBUF_INIT;
strbuf_addf(&d, "%s/%s", git_exec_path(), system_wide);
system_wide = strbuf_detach(&d, NULL);
}
}
if (!system_wide)
system_wide = system_path(ETC_GITCONFIG);
return system_wide;
}

Expand Down
10 changes: 10 additions & 0 deletions exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ static const char *builtin_exec_path(void)
#endif
}

const char *system_path(const char *path)
{
if (!is_absolute_path(path)) {
struct strbuf d = STRBUF_INIT;
strbuf_addf(&d, "%s/%s", git_exec_path(), path);
path = strbuf_detach(&d, NULL);
}
return path;
}

void git_set_argv_exec_path(const char *exec_path)
{
argv_exec_path = exec_path;
Expand Down
2 changes: 1 addition & 1 deletion exec_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ extern const char* git_exec_path(void);
extern void setup_path(const char *);
extern int execv_git_cmd(const char **argv); /* NULL terminated */
extern int execl_git_cmd(const char *cmd, ...);

extern const char *system_path(const char *path);

#endif /* GIT_EXEC_CMD_H */
22 changes: 18 additions & 4 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,23 +633,37 @@ static void show_info_page(const char *git_cmd)
static void get_html_page_path(struct strbuf *page_path, const char *page)
{
struct stat st;
const char *html_path = system_path(GIT_HTML_PATH);

/* Check that we have a git documentation directory. */
if (stat(GIT_HTML_PATH "/git.html", &st) || !S_ISREG(st.st_mode))
die("'%s': not a documentation directory.", GIT_HTML_PATH);
if (stat(mkpath("%s/git.html", html_path), &st)
|| !S_ISREG(st.st_mode))
die("'%s': not a documentation directory.", html_path);

strbuf_init(page_path, 0);
strbuf_addf(page_path, GIT_HTML_PATH "/%s.html", page);
strbuf_addf(page_path, "%s/%s.html", html_path, page);
}

/*
* If open_html is not defined in a platform-specific way (see for
* example compat/mingw.h), we use the script web--browse to display
* HTML.
*/
#ifndef open_html
void open_html(const char *path)
{
execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
}
#endif

static void show_html_page(const char *git_cmd)
{
const char *page = cmd_to_page(git_cmd);
struct strbuf page_path; /* it leaks but we exec bellow */

get_html_page_path(&page_path, page);

execl_git_cmd("web--browse", "-c", "help.browser", page_path.buf, NULL);
open_html(page_path.buf);
}

void help_unknown_cmd(const char *cmd)
Expand Down

0 comments on commit 1466080

Please sign in to comment.