]>
git.cameronkatri.com Git - cgit.git/blob - ui-summary.c
1 /* ui-summary.c: functions for generating repo summary page
3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text)
11 #include "ui-summary.h"
17 static void print_url(char *base
, char *suffix
)
20 struct strbuf basebuf
= STRBUF_INIT
;
22 if (ctx
.repo
->enable_log_filecount
)
24 if (ctx
.repo
->enable_log_linecount
)
29 if (suffix
&& *suffix
) {
30 strbuf_addf(&basebuf
, "%s/%s", base
, suffix
);
33 htmlf("<tr><td colspan='%d'><a href='", columns
);
37 html("</a></td></tr>\n");
38 strbuf_release(&basebuf
);
41 static void print_urls(char *txt
, char *suffix
)
47 if (ctx
.repo
->enable_log_filecount
)
49 if (ctx
.repo
->enable_log_linecount
)
54 while (h
&& *h
== ' ')
59 while (t
&& *t
&& *t
!= ' ')
64 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
65 htmlf("<tr><th class='left' colspan='%d'>Clone</th></tr>\n", columns
);
73 void cgit_print_summary()
77 if (ctx
.repo
->enable_log_filecount
)
79 if (ctx
.repo
->enable_log_linecount
)
82 html("<table summary='repository info' class='list nowrap'>");
83 cgit_print_branches(ctx
.cfg
.summary_branches
);
84 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
85 cgit_print_tags(ctx
.cfg
.summary_tags
);
86 if (ctx
.cfg
.summary_log
> 0) {
87 htmlf("<tr class='nohover'><td colspan='%d'> </td></tr>", columns
);
88 cgit_print_log(ctx
.qry
.head
, 0, ctx
.cfg
.summary_log
, NULL
,
91 if (ctx
.repo
->clone_url
)
92 print_urls(expand_macros(ctx
.repo
->clone_url
), NULL
);
93 else if (ctx
.cfg
.clone_prefix
)
94 print_urls(ctx
.cfg
.clone_prefix
, ctx
.repo
->url
);
98 void cgit_print_repo_readme(char *path
)
100 char *slash
, *tmp
, *colon
, *ref
;
102 if (!ctx
.repo
->readme
|| !(*ctx
.repo
->readme
))
107 /* Check if the readme is tracked in the git repo. */
108 colon
= strchr(ctx
.repo
->readme
, ':');
109 if (colon
&& strlen(colon
) > 1) {
111 /* If it starts with a colon, we want to use
112 * the default branch */
113 if (colon
== ctx
.repo
->readme
&& ctx
.repo
->defbranch
)
114 ref
= ctx
.repo
->defbranch
;
116 ref
= ctx
.repo
->readme
;
117 ctx
.repo
->readme
= colon
+ 1;
118 if (!(*ctx
.repo
->readme
))
122 /* Prepend repo path to relative readme path unless tracked. */
123 if (!ref
&& *ctx
.repo
->readme
!= '/')
124 ctx
.repo
->readme
= fmtalloc("%s/%s", ctx
.repo
->path
,
127 /* If a subpath is specified for the about page, make it relative
128 * to the directory containing the configured readme.
131 slash
= strrchr(ctx
.repo
->readme
, '/');
137 tmp
= xmalloc(slash
- ctx
.repo
->readme
+ 1 + strlen(path
) + 1);
138 strncpy(tmp
, ctx
.repo
->readme
, slash
- ctx
.repo
->readme
+ 1);
139 strcpy(tmp
+ (slash
- ctx
.repo
->readme
+ 1), path
);
141 tmp
= ctx
.repo
->readme
;
143 /* Print the calculated readme, either from the git repo or from the
144 * filesystem, while applying the about-filter.
146 html("<div id='summary'>");
147 if (ctx
.repo
->about_filter
)
148 cgit_open_filter(ctx
.repo
->about_filter
);
150 cgit_print_file(tmp
, ref
);
153 if (ctx
.repo
->about_filter
)
154 cgit_close_filter(ctx
.repo
->about_filter
);