mirror of
https://git.zx2c4.com/cgit
synced 2024-11-10 02:28:41 +00:00
Merge branch 'lh/clone-url'
This commit is contained in:
commit
1b1bf635b5
3
cgit.c
3
cgit.c
@ -244,6 +244,8 @@ void config_cb(const char *name, const char *value)
|
|||||||
ctx.cfg.robots = xstrdup(value);
|
ctx.cfg.robots = xstrdup(value);
|
||||||
else if (!strcmp(name, "clone-prefix"))
|
else if (!strcmp(name, "clone-prefix"))
|
||||||
ctx.cfg.clone_prefix = xstrdup(value);
|
ctx.cfg.clone_prefix = xstrdup(value);
|
||||||
|
else if (!strcmp(name, "clone-url"))
|
||||||
|
ctx.cfg.clone_url = xstrdup(value);
|
||||||
else if (!strcmp(name, "local-time"))
|
else if (!strcmp(name, "local-time"))
|
||||||
ctx.cfg.local_time = atoi(value);
|
ctx.cfg.local_time = atoi(value);
|
||||||
else if (!prefixcmp(name, "mimetype."))
|
else if (!prefixcmp(name, "mimetype."))
|
||||||
@ -463,6 +465,7 @@ static int prepare_repo_cmd(struct cgit_context *ctx)
|
|||||||
cgit_print_docend();
|
cgit_print_docend();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
cgit_prepare_repo_env(ctx->repo);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
cgit.h
5
cgit.h
@ -165,6 +165,7 @@ struct cgit_config {
|
|||||||
char *agefile;
|
char *agefile;
|
||||||
char *cache_root;
|
char *cache_root;
|
||||||
char *clone_prefix;
|
char *clone_prefix;
|
||||||
|
char *clone_url;
|
||||||
char *css;
|
char *css;
|
||||||
char *favicon;
|
char *favicon;
|
||||||
char *footer;
|
char *footer;
|
||||||
@ -319,9 +320,11 @@ extern const char *cgit_repobasename(const char *reponame);
|
|||||||
|
|
||||||
extern int cgit_parse_snapshots_mask(const char *str);
|
extern int cgit_parse_snapshots_mask(const char *str);
|
||||||
|
|
||||||
extern int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo);
|
extern int cgit_open_filter(struct cgit_filter *filter);
|
||||||
extern int cgit_close_filter(struct cgit_filter *filter);
|
extern int cgit_close_filter(struct cgit_filter *filter);
|
||||||
|
|
||||||
|
extern void cgit_prepare_repo_env(struct cgit_repo * repo);
|
||||||
|
|
||||||
extern int readfile(const char *path, char **buf, size_t *size);
|
extern int readfile(const char *path, char **buf, size_t *size);
|
||||||
|
|
||||||
extern char *expand_macros(const char *txt);
|
extern char *expand_macros(const char *txt);
|
||||||
|
17
cgitrc.5.txt
17
cgitrc.5.txt
@ -76,6 +76,11 @@ clone-prefix::
|
|||||||
setting is only used if `repo.clone-url` is unspecified. Default value:
|
setting is only used if `repo.clone-url` is unspecified. Default value:
|
||||||
none.
|
none.
|
||||||
|
|
||||||
|
clone-url::
|
||||||
|
Space-separated list of clone-url templates. This setting is only
|
||||||
|
used if `repo.clone-url` is unspecified. Default value: none. See
|
||||||
|
also: "MACRO EXPANSION", "FILTER API".
|
||||||
|
|
||||||
commit-filter::
|
commit-filter::
|
||||||
Specifies a command which will be invoked to format commit messages.
|
Specifies a command which will be invoked to format commit messages.
|
||||||
The command will get the message on its STDIN, and the STDOUT from the
|
The command will get the message on its STDIN, and the STDOUT from the
|
||||||
@ -363,7 +368,7 @@ repo.about-filter::
|
|||||||
|
|
||||||
repo.clone-url::
|
repo.clone-url::
|
||||||
A list of space-separated urls which can be used to clone this repo.
|
A list of space-separated urls which can be used to clone this repo.
|
||||||
Default value: none.
|
Default value: none. See also: "MACRO EXPANSION".
|
||||||
|
|
||||||
repo.commit-filter::
|
repo.commit-filter::
|
||||||
Override the default commit-filter. Default value: none. See also:
|
Override the default commit-filter. Default value: none. See also:
|
||||||
@ -511,6 +516,12 @@ can be accomplished by adding the following line to /etc/cgitrc:
|
|||||||
|
|
||||||
include=/etc/cgitrc.d/$HTTP_HOST
|
include=/etc/cgitrc.d/$HTTP_HOST
|
||||||
|
|
||||||
|
The following options are expanded during request processing, and support
|
||||||
|
the environment variables defined in "FILTER API":
|
||||||
|
|
||||||
|
- clone-url
|
||||||
|
- repo.clone-url
|
||||||
|
|
||||||
|
|
||||||
EXAMPLE CGITRC FILE
|
EXAMPLE CGITRC FILE
|
||||||
-------------------
|
-------------------
|
||||||
@ -520,8 +531,8 @@ EXAMPLE CGITRC FILE
|
|||||||
cache-size=1000
|
cache-size=1000
|
||||||
|
|
||||||
|
|
||||||
# Specify some default clone prefixes
|
# Specify some default clone urls using macro expansion
|
||||||
clone-prefix=git://example.com ssh://example.com/pub/git http://example.com/git
|
clone-url=git://foo.org/$CGIT_REPO_URL git@foo.org:$CGIT_REPO_URL
|
||||||
|
|
||||||
# Specify the css url
|
# Specify the css url
|
||||||
css=/css/cgit.css
|
css=/css/cgit.css
|
||||||
|
8
shared.c
8
shared.c
@ -70,6 +70,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
|
|||||||
ret->about_filter = ctx.cfg.about_filter;
|
ret->about_filter = ctx.cfg.about_filter;
|
||||||
ret->commit_filter = ctx.cfg.commit_filter;
|
ret->commit_filter = ctx.cfg.commit_filter;
|
||||||
ret->source_filter = ctx.cfg.source_filter;
|
ret->source_filter = ctx.cfg.source_filter;
|
||||||
|
ret->clone_url = ctx.cfg.clone_url;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +375,8 @@ typedef struct {
|
|||||||
char * value;
|
char * value;
|
||||||
} cgit_env_var;
|
} cgit_env_var;
|
||||||
|
|
||||||
static void prepare_env(struct cgit_repo * repo) {
|
void cgit_prepare_repo_env(struct cgit_repo * repo)
|
||||||
|
{
|
||||||
cgit_env_var env_vars[] = {
|
cgit_env_var env_vars[] = {
|
||||||
{ .name = "CGIT_REPO_URL", .value = repo->url },
|
{ .name = "CGIT_REPO_URL", .value = repo->url },
|
||||||
{ .name = "CGIT_REPO_NAME", .value = repo->name },
|
{ .name = "CGIT_REPO_NAME", .value = repo->name },
|
||||||
@ -395,7 +397,7 @@ static void prepare_env(struct cgit_repo * repo) {
|
|||||||
fprintf(stderr, warn, p->name, p->value);
|
fprintf(stderr, warn, p->name, p->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)
|
int cgit_open_filter(struct cgit_filter *filter)
|
||||||
{
|
{
|
||||||
|
|
||||||
filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
|
filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
|
||||||
@ -406,8 +408,6 @@ int cgit_open_filter(struct cgit_filter *filter, struct cgit_repo * repo)
|
|||||||
close(filter->pipe_fh[1]);
|
close(filter->pipe_fh[1]);
|
||||||
chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
|
chk_non_negative(dup2(filter->pipe_fh[0], STDIN_FILENO),
|
||||||
"Unable to use pipe as STDIN");
|
"Unable to use pipe as STDIN");
|
||||||
if (repo)
|
|
||||||
prepare_env(repo);
|
|
||||||
execvp(filter->cmd, filter->argv);
|
execvp(filter->cmd, filter->argv);
|
||||||
die("Unable to exec subprocess %s: %s (%d)", filter->cmd,
|
die("Unable to exec subprocess %s: %s (%d)", filter->cmd,
|
||||||
strerror(errno), errno);
|
strerror(errno), errno);
|
||||||
|
@ -62,6 +62,7 @@ enable-log-linecount=1
|
|||||||
summary-log=5
|
summary-log=5
|
||||||
summary-branches=5
|
summary-branches=5
|
||||||
summary-tags=5
|
summary-tags=5
|
||||||
|
clone-url=git://example.org/\$CGIT_REPO_URL.git
|
||||||
|
|
||||||
repo.url=foo
|
repo.url=foo
|
||||||
repo.path=$PWD/trash/repos/foo/.git
|
repo.path=$PWD/trash/repos/foo/.git
|
||||||
|
@ -9,6 +9,9 @@ run_test 'find commit 1' 'grep -e "commit 1" trash/tmp'
|
|||||||
run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
|
run_test 'find commit 5' 'grep -e "commit 5" trash/tmp'
|
||||||
run_test 'find branch master' 'grep -e "master" trash/tmp'
|
run_test 'find branch master' 'grep -e "master" trash/tmp'
|
||||||
run_test 'no tags' '! grep -e "tags" trash/tmp'
|
run_test 'no tags' '! grep -e "tags" trash/tmp'
|
||||||
|
run_test 'clone-url expanded correctly' '
|
||||||
|
grep -e "git://example.org/foo.git" trash/tmp
|
||||||
|
'
|
||||||
|
|
||||||
run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp'
|
run_test 'generate bar summary' 'cgit_url "bar" >trash/tmp'
|
||||||
run_test 'no commit 45' '! grep -e "commit 45" trash/tmp'
|
run_test 'no commit 45' '! grep -e "commit 45" trash/tmp'
|
||||||
@ -16,5 +19,8 @@ run_test 'find commit 46' 'grep -e "commit 46" trash/tmp'
|
|||||||
run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
|
run_test 'find commit 50' 'grep -e "commit 50" trash/tmp'
|
||||||
run_test 'find branch master' 'grep -e "master" trash/tmp'
|
run_test 'find branch master' 'grep -e "master" trash/tmp'
|
||||||
run_test 'no tags' '! grep -e "tags" trash/tmp'
|
run_test 'no tags' '! grep -e "tags" trash/tmp'
|
||||||
|
run_test 'clone-url expanded correctly' '
|
||||||
|
grep -e "git://example.org/bar.git" trash/tmp
|
||||||
|
'
|
||||||
|
|
||||||
tests_done
|
tests_done
|
||||||
|
@ -106,7 +106,7 @@ void cgit_print_commit(char *hex, const char *prefix)
|
|||||||
html("</table>\n");
|
html("</table>\n");
|
||||||
html("<div class='commit-subject'>");
|
html("<div class='commit-subject'>");
|
||||||
if (ctx.repo->commit_filter)
|
if (ctx.repo->commit_filter)
|
||||||
cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
|
cgit_open_filter(ctx.repo->commit_filter);
|
||||||
html_txt(info->subject);
|
html_txt(info->subject);
|
||||||
if (ctx.repo->commit_filter)
|
if (ctx.repo->commit_filter)
|
||||||
cgit_close_filter(ctx.repo->commit_filter);
|
cgit_close_filter(ctx.repo->commit_filter);
|
||||||
@ -114,7 +114,7 @@ void cgit_print_commit(char *hex, const char *prefix)
|
|||||||
html("</div>");
|
html("</div>");
|
||||||
html("<div class='commit-msg'>");
|
html("<div class='commit-msg'>");
|
||||||
if (ctx.repo->commit_filter)
|
if (ctx.repo->commit_filter)
|
||||||
cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
|
cgit_open_filter(ctx.repo->commit_filter);
|
||||||
html_txt(info->msg);
|
html_txt(info->msg);
|
||||||
if (ctx.repo->commit_filter)
|
if (ctx.repo->commit_filter)
|
||||||
cgit_close_filter(ctx.repo->commit_filter);
|
cgit_close_filter(ctx.repo->commit_filter);
|
||||||
@ -123,7 +123,7 @@ void cgit_print_commit(char *hex, const char *prefix)
|
|||||||
html("<div class='notes-header'>Notes</div>");
|
html("<div class='notes-header'>Notes</div>");
|
||||||
html("<div class='notes'>");
|
html("<div class='notes'>");
|
||||||
if (ctx.repo->commit_filter)
|
if (ctx.repo->commit_filter)
|
||||||
cgit_open_filter(ctx.repo->commit_filter, ctx.repo);
|
cgit_open_filter(ctx.repo->commit_filter);
|
||||||
html_txt(notes.buf);
|
html_txt(notes.buf);
|
||||||
if (ctx.repo->commit_filter)
|
if (ctx.repo->commit_filter)
|
||||||
cgit_close_filter(ctx.repo->commit_filter);
|
cgit_close_filter(ctx.repo->commit_filter);
|
||||||
|
@ -300,7 +300,7 @@ void cgit_print_site_readme()
|
|||||||
if (!ctx.cfg.root_readme)
|
if (!ctx.cfg.root_readme)
|
||||||
return;
|
return;
|
||||||
if (ctx.cfg.about_filter)
|
if (ctx.cfg.about_filter)
|
||||||
cgit_open_filter(ctx.cfg.about_filter, NULL);
|
cgit_open_filter(ctx.cfg.about_filter);
|
||||||
html_include(ctx.cfg.root_readme);
|
html_include(ctx.cfg.root_readme);
|
||||||
if (ctx.cfg.about_filter)
|
if (ctx.cfg.about_filter)
|
||||||
cgit_close_filter(ctx.cfg.about_filter);
|
cgit_close_filter(ctx.cfg.about_filter);
|
||||||
|
@ -19,7 +19,7 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f
|
|||||||
f.argv = malloc(2 * sizeof(char *));
|
f.argv = malloc(2 * sizeof(char *));
|
||||||
f.argv[0] = f.cmd;
|
f.argv[0] = f.cmd;
|
||||||
f.argv[1] = NULL;
|
f.argv[1] = NULL;
|
||||||
cgit_open_filter(&f, NULL);
|
cgit_open_filter(&f);
|
||||||
rv = write_tar_archive(args);
|
rv = write_tar_archive(args);
|
||||||
cgit_close_filter(&f);
|
cgit_close_filter(&f);
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -62,7 +62,7 @@ void cgit_print_summary()
|
|||||||
NULL, NULL, 0, 0);
|
NULL, NULL, 0, 0);
|
||||||
}
|
}
|
||||||
if (ctx.repo->clone_url)
|
if (ctx.repo->clone_url)
|
||||||
print_urls(ctx.repo->clone_url, NULL);
|
print_urls(expand_macros(ctx.repo->clone_url), NULL);
|
||||||
else if (ctx.cfg.clone_prefix)
|
else if (ctx.cfg.clone_prefix)
|
||||||
print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
|
print_urls(ctx.cfg.clone_prefix, ctx.repo->url);
|
||||||
html("</table>");
|
html("</table>");
|
||||||
@ -113,7 +113,7 @@ void cgit_print_repo_readme(char *path)
|
|||||||
*/
|
*/
|
||||||
html("<div id='summary'>");
|
html("<div id='summary'>");
|
||||||
if (ctx.repo->about_filter)
|
if (ctx.repo->about_filter)
|
||||||
cgit_open_filter(ctx.repo->about_filter, ctx.repo);
|
cgit_open_filter(ctx.repo->about_filter);
|
||||||
if (ref)
|
if (ref)
|
||||||
cgit_print_file(tmp, ref);
|
cgit_print_file(tmp, ref);
|
||||||
else
|
else
|
||||||
|
@ -45,7 +45,7 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
|
|||||||
if (ctx.repo->source_filter) {
|
if (ctx.repo->source_filter) {
|
||||||
html("<td class='lines'><pre><code>");
|
html("<td class='lines'><pre><code>");
|
||||||
ctx.repo->source_filter->argv[1] = xstrdup(name);
|
ctx.repo->source_filter->argv[1] = xstrdup(name);
|
||||||
cgit_open_filter(ctx.repo->source_filter, ctx.repo);
|
cgit_open_filter(ctx.repo->source_filter);
|
||||||
html_raw(buf, size);
|
html_raw(buf, size);
|
||||||
cgit_close_filter(ctx.repo->source_filter);
|
cgit_close_filter(ctx.repo->source_filter);
|
||||||
free(ctx.repo->source_filter->argv[1]);
|
free(ctx.repo->source_filter->argv[1]);
|
||||||
|
Loading…
Reference in New Issue
Block a user