Skip to content

Commit 1466080

Browse files
committed
Merge branch 'js/more-win'
* 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()
2 parents fab600c + 4804aab commit 1466080

File tree

7 files changed

+58
-26
lines changed

7 files changed

+58
-26
lines changed

builtin-init-db.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,8 @@ static void copy_templates(const char *template_dir)
115115

116116
if (!template_dir)
117117
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
118-
if (!template_dir) {
119-
/*
120-
* if the hard-coded template is relative, it is
121-
* interpreted relative to the exec_dir
122-
*/
123-
template_dir = DEFAULT_GIT_TEMPLATE_DIR;
124-
if (!is_absolute_path(template_dir)) {
125-
struct strbuf d = STRBUF_INIT;
126-
strbuf_addf(&d, "%s/%s", git_exec_path(), template_dir);
127-
template_dir = strbuf_detach(&d, NULL);
128-
}
129-
}
118+
if (!template_dir)
119+
template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
130120
strcpy(template_path, template_dir);
131121
template_len = strlen(template_path);
132122
if (template_path[template_len-1] != '/') {

compat/mingw.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,3 +1017,25 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
10171017
timer_fn = handler;
10181018
return old;
10191019
}
1020+
1021+
static const char *make_backslash_path(const char *path)
1022+
{
1023+
static char buf[PATH_MAX + 1];
1024+
char *c;
1025+
1026+
if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
1027+
die("Too long path: %.*s", 60, path);
1028+
1029+
for (c = buf; *c; c++) {
1030+
if (*c == '/')
1031+
*c = '\\';
1032+
}
1033+
return buf;
1034+
}
1035+
1036+
void mingw_open_html(const char *unixpath)
1037+
{
1038+
const char *htmlpath = make_backslash_path(unixpath);
1039+
printf("Launching default browser to display HTML ...\n");
1040+
ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
1041+
}

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);
202202
#define PATH_SEP ';'
203203
#define PRIuMAX "I64u"
204204

205+
void mingw_open_html(const char *path);
206+
#define open_html mingw_open_html
207+
205208
/*
206209
* helpers
207210
*/

config.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,8 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
581581
const char *git_etc_gitconfig(void)
582582
{
583583
static const char *system_wide;
584-
if (!system_wide) {
585-
system_wide = ETC_GITCONFIG;
586-
if (!is_absolute_path(system_wide)) {
587-
/* interpret path relative to exec-dir */
588-
struct strbuf d = STRBUF_INIT;
589-
strbuf_addf(&d, "%s/%s", git_exec_path(), system_wide);
590-
system_wide = strbuf_detach(&d, NULL);
591-
}
592-
}
584+
if (!system_wide)
585+
system_wide = system_path(ETC_GITCONFIG);
593586
return system_wide;
594587
}
595588

exec_cmd.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ static const char *builtin_exec_path(void)
4040
#endif
4141
}
4242

43+
const char *system_path(const char *path)
44+
{
45+
if (!is_absolute_path(path)) {
46+
struct strbuf d = STRBUF_INIT;
47+
strbuf_addf(&d, "%s/%s", git_exec_path(), path);
48+
path = strbuf_detach(&d, NULL);
49+
}
50+
return path;
51+
}
52+
4353
void git_set_argv_exec_path(const char *exec_path)
4454
{
4555
argv_exec_path = exec_path;

exec_cmd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ extern const char* git_exec_path(void);
66
extern void setup_path(const char *);
77
extern int execv_git_cmd(const char **argv); /* NULL terminated */
88
extern int execl_git_cmd(const char *cmd, ...);
9-
9+
extern const char *system_path(const char *path);
1010

1111
#endif /* GIT_EXEC_CMD_H */

help.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,23 +633,37 @@ static void show_info_page(const char *git_cmd)
633633
static void get_html_page_path(struct strbuf *page_path, const char *page)
634634
{
635635
struct stat st;
636+
const char *html_path = system_path(GIT_HTML_PATH);
636637

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

641643
strbuf_init(page_path, 0);
642-
strbuf_addf(page_path, GIT_HTML_PATH "/%s.html", page);
644+
strbuf_addf(page_path, "%s/%s.html", html_path, page);
643645
}
644646

647+
/*
648+
* If open_html is not defined in a platform-specific way (see for
649+
* example compat/mingw.h), we use the script web--browse to display
650+
* HTML.
651+
*/
652+
#ifndef open_html
653+
void open_html(const char *path)
654+
{
655+
execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
656+
}
657+
#endif
658+
645659
static void show_html_page(const char *git_cmd)
646660
{
647661
const char *page = cmd_to_page(git_cmd);
648662
struct strbuf page_path; /* it leaks but we exec bellow */
649663

650664
get_html_page_path(&page_path, page);
651665

652-
execl_git_cmd("web--browse", "-c", "help.browser", page_path.buf, NULL);
666+
open_html(page_path.buf);
653667
}
654668

655669
void help_unknown_cmd(const char *cmd)

0 commit comments

Comments
 (0)