blob: fa8d8ddafe99155ccd3d1a8104aa2b6017a53c4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * The page furniture and the link builders every renderer shares. A page
 * handler renders its own body and calls in here for all that surrounds it,
 * which is the HTTP headers, the document head and footer, the header block
 * with its tabs and search form, the error page, and an anchor to any other
 * cgit page.
 */

#ifndef CGIT_UI_SHARED_H
#define CGIT_UI_SHARED_H

#include "cgit.h"

extern const char *cgit_httpscheme(void);
extern char *cgit_hosturl(void);

/*
 * The URL of the request being answered, which cgit_currentfullurl gives with
 * the query string on the end as well, minus the url argument that the path
 * was taken from. cgit_currentquery is that query string alone, led by its
 * question mark, or an empty string when nothing is left of it.
 */
extern char *cgit_currenturl(void);
extern char *cgit_currentfullurl(void);
extern char *cgit_currentquery(void);
extern const char *cgit_loginurl(void);

/*
 * The urls of a repository and of its pages. The repository url is encoded
 * here, since it is configuration or a scanned path and may hold any byte,
 * while a page name, file name or query must arrive encoded already. The
 * result still needs escaping for wherever it lands.
 */
extern char *cgit_repourl(const char *reponame);
extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename,
	const char *query);
extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query);

/*
 * The url of the current repository's tree page at head, split where a path
 * in the tree goes, for a filter to build links of its own from. Both parts
 * are escaped for a url but not for HTML, and query stays empty for the
 * default branch.
 */
extern void cgit_tree_url(const char *head, struct strbuf *base, struct strbuf *query);

/*
 * Call fn once for every URL this repository can be cloned from.
 */
extern void cgit_add_clone_urls(void (*fn)(const char *));

/*
 * One row of the clone table. Every row is a link, but a browser cannot
 * follow the ssh, scp or git forms, so those rows point at the first http
 * url in the clone list, or at the repository's own page when the list has
 * none. A colspan of zero leaves the attribute out.
 */
extern void cgit_print_clone_row(const char *url, int colspan);

/*
 * Each of these writes one anchor to the page and nothing around it, with name
 * as the text a reader sees. A NULL title or class leaves that attribute out,
 * and what follows them is the state the target page should open in.
 */
extern void cgit_index_link(const char *name, const char *title, const char *class,
	const char *pattern, const char *sort, int ofs, int always_root);
extern void cgit_summary_link(const char *name, const char *title, const char *class,
	const char *head);
extern void cgit_tag_link(const char *name, const char *title, const char *class, const char *tag);
extern void cgit_tree_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_plain_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_blame_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_log_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path, int ofs, const char *grep,
	const char *pattern, int showmsg, int follow);
extern void cgit_commit_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_patch_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_refs_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_diff_link(const char *name, const char *title, const char *class,
	const char *head, const char *new_rev, const char *old_rev, const char *path);
extern void cgit_stats_link(const char *name, const char *title, const char *class,
	const char *head, const char *path);
/*
 * Names the object by type and id, abbreviated unless full is set.
 */
extern void cgit_object_link(struct object *obj, int full);

extern void cgit_submodule_link(const char *class, char *path, const char *rev);

extern void cgit_print_layout_start(void);
extern void cgit_print_layout_end(void);

__attribute__((format (printf,1,2)))
extern void cgit_print_error(const char *fmt, ...);
extern struct date_mode cgit_date_mode(enum date_mode_type type);

/*
 * Print the time t, which was recorded in the timezone tz, as an age. An age
 * further back than max_relative is given as a calendar date instead, and a
 * negative max_relative stays relative however old it is. A site that turns
 * relative dates off gets the date either way.
 */
extern void cgit_print_age(time_t t, int tz, time_t max_relative);
extern void cgit_print_http_headers(void);
/*
 * Answer with a redirect to url, followed by query when one is given. Both
 * are written as they arrived, encoded already, the url the way cgit_repourl
 * builds it, and only a byte a header line cannot carry is encoded here.
 */
extern void cgit_redirect(const char *url, const char *query, bool permanent);
__attribute__((format (printf,3,4)))
extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...);

/*
 * Answer with the error page for a blob of size bytes past max-blob-size.
 */
extern void cgit_print_blob_too_large(size_t size);

/*
 * Resolve rev to the parsed commit it names, peeling a tag, with oid set to
 * what rev itself names. Returns NULL once the 404 page naming rev is out.
 */
extern struct commit *cgit_get_commit(const char *rev, struct object_id *oid);

/*
 * Fill oid with the older end of a comparison with commit, which is what
 * old_rev names when it is given, else commit's first parent, else the null
 * id for a root commit. Returns -1 once the 404 page for old_rev is out.
 */
extern int cgit_get_old_oid(const char *old_rev, const struct commit *commit, struct object_id *oid);

/*
 * Start rev's walk, or print the error page and return non-zero when git
 * cannot. A failed setup leaves the walk holding freed commits, so the caller
 * must not read from it then.
 */
extern int cgit_prepare_walk(struct rev_info *rev);

extern void cgit_print_filemode(unsigned short mode);
extern void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref,
	const char *separator);

/*
 * The name a snapshot of this repository is downloaded under, which is the
 * configured prefix or the last component of the repository URL. A name taken
 * from the URL is only good until the next call.
 */
extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo);

/*
 * Carry the current request into a form as hidden inputs, so that submitting
 * it changes only what the form itself asks about. The branch and the search
 * terms are carried only when the caller asks for them, since a form with a
 * field of its own for either would otherwise submit that name twice.
 */
extern void cgit_add_hidden_formfields(int incl_head, int incl_search);

/*
 * Put path in front of the page title, its last component first.
 */
extern void cgit_set_title_from_path(const char *path);

/*
 * Names the page ahead of the repository and the site, so that the pages of one
 * repository can be told apart in tabs, history and search results.
 */
extern void cgit_prefix_title(const char *name);

#endif // CGIT_UI_SHARED_H