aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* ui-shared: add now-dynamic age to footerch/warmcatAndy Green2018-06-291-1/+3
| | | | | | Now ages advance at the client, we can add one to the generated footer. Signed-off-by: Andy Green <andy@warmcat.com>
* cgit.css: add dynamic age updateAndy Green2018-06-293-1/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch updates the emitted "ages" dynamically on the client side. After updating on completion of the document load, it sets a timer to update according to the smallest age it found. If there are any ages listed in minutes, then it will update again in 10s. When the most recent age is in hours, it updates every 5m. If days, then every 30m and so on. This keeps the cost of the dynamic updates at worst once per 10s. The updates are done entirely on the client side without contact with the server. To make this work reliably, since parsing datetimes is unreliable in browser js, the unix time is added as an attribute to all age spans. To make that reliable cross-platform, the unix time is treated as a uint64_t when it is formatted for printing. The rules for display conversion of the age is aligned with the existing server-side rules in ui-shared.h. If the client or server-side time are not synchronized by ntpd etc, ages shown on the client will not relate to the original ages computed at the server. The client updates the ages immediately when the DOM has finished loading, so in the case the times at the server and client are not aligned, this patch changes what the user sees on the page to reflect patch age compared to client time. If the server and client clocks are aligned, this patch makes no difference to what is seen on the page. Signed-off-by: Andy Green <andy@warmcat.com>
* desc: add root-desc-html and repo.desc-htmlAndy Green2018-06-294-1/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are optional, default-empty raw html strings that are emitted after the corresponding text-only versions root-desc and repo.desc when they are used in the header area. This provides a flexible way to place buttons or links in the header region for both the repo index page and for repos individually. The existing root-desc and repo.desc keep their original meaning as a shortish text-only repo description. The reason for that is the description is also used in places like the repo list, where any decoration is not wanted. Where root-desc and repo.desc are used in the header region, also emit their html counterparts afterwards if they are defined. Where root-desc are repo.desc are used outside the header, eg in the repo list, leave it as it is without adding any related html. It's possible to not define the text repo.desc and just define the repo.desc-html counterpart; only the html part is shown then. But results in the repo list page will then vary according to what's in the html (text size, pictures etc). Signed-off-by: Andy Green <andy@warmcat.com>
* line-range-highlight: copy textAndy Green2018-06-291-10/+41
| | | | | | | | | Implement picking a line range or single line from the textContent version of the rendered source to the clipboard. It works in blame and tree the same. Signed-off-by: Andy Green <andy@warmcat.com>
* line-range-highlight: burger menu and popup menuAndy Green2018-06-292-13/+264
| | | | | | | | | | | | | | | | | | | | | | | | Clicking on the line numbers to control the highlight, or visiting a #URL link, causes a burger menu to appear on the left of either the top of the range or the bottom if that was last clicked. Clicking this brings up a popup menu with Copy Lines (implemented in next patch) Copy Link (copies complete #URL to clipboard) View / Remove Blame (changes to view to have or not have blame) Clicking outside the popup menu clears it, but the burger menu is sticky. This is an entirely clientside implementation in cgit.css and cgit.js only. If JS disabled at server or at client, it cannot provide this functionality and operates with one-line browser URLs as before. Tested on Linux Chrome 67 + Firefox 60. Signed-off-by: Andy Green <andy@warmcat.com>
* line-range-highlight: onclick handler and range selectionAndy Green2018-06-293-2/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | This allows the user to select line ranges simply by clicking on the line number links. - No selected highlit line, or a range already selected, causes the click to highlight just the clicked line as usual. - Clicking on a second line number link when a single line was already highlit creates a line range highlight, between the lowest and highest line numbers of the already-selected and newly-selected line number links. The order of the clicks is unimportant, you can click the higher line number link first and then the lower to define the range of lines equally well. The implementation is slightly complicated by our single parent onclick handler not being able to interrupt the already ongoing processing of the a href #n change from the link click itself. Rather than bloat every linenumber link with its own onclick handler defeating this default we simply do it with a single parent onclick event and apply any computed range url in the existing hashchange event handler. Signed-off-by: Andy Green <andy@warmcat.com>
* cgit.js: line range highlight: improve vertical scroll logicAndy Green2018-06-291-2/+13
| | | | | | | | | | | | | Instead of following the browser heuristic to put any matching id element to the top left of the browser window, compute the number of visible lines vertically in the window, and the middle of the highlit range, and try to centre the middle of the highlit range in the window. If the top of the range is no longer visible due to a range consisting of more lines than the window can show, fall back to placing the top of the range at the top of the window. Signed-off-by: Andy Green <andy@warmcat.com>
* cgit.js: line range highlight: make responsive to url changesAndy Green2018-06-291-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | Browser default interpretation of the # part of the URL is to try to match it to an element ID one time at page load. Subsequent modifications in the URL bar are ignored, even if you hit enter there. This patch makes the line range highlight able to clean up after itself and be reapplied, and has the highlight function listen for hashchange events and re-interpret the # part when they occur. Now if you edit the URL and press enter, any existing highlight is removed, the # part reinterpreted and the new highlight applied automatically. This is particularly useful if you edit the # link with the intention to show a range before copying the URL. Clicking on the line number, which changes the URL bar to have a corresponding #n part, also triggers hashchange and makes the clicked line be highlit immediately. Signed-off-by: Andy Green <andy@warmcat.com>
* cgit.js: line range highlight: introduce javascriptAndy Green2018-06-292-0/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a small css class, and a clientside js function plus event registrations in cgit.js, to interpret the # part of the URL on the client, and apply a highlight to filtered source. Unlike blame highlight boxes which use generated divs, this applies a computed absolutely-positioned, transparent div highlight over the affected line(s) on the client side. The # part of the URL is defined to not be passed to the server, so the highlight can't be rendered on the server side. However this has the advantage that the line range highlight can operate on /blame/ urls trivially, since it doesn't conflict with blame's generated div scheme. pointer-events: none is used on the highlight overlay div to allow the user to cut-and-paste in the highlit region and click on links underneath normally. The JS supports highlighting single lines as before like #n123 and also ranges of lines like #n123-135. Because the browser can no longer automatically scroll to the element in the second case, the JS also takes care of extracting the range start element and scrolling to it dynamically. Tested on Linux Firefox 60 + Linux Chrome 67 Signed-off-by: Andy Green <andy@warmcat.com>
* config: add jsAndy Green2018-06-296-0/+15
| | | | | | | | | | Just like the config allows setting css URL path, add a config for setting the js URL path Setting the js path to an empty string disables emitting the reference to it in the head section. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* noheader: place branch combo on tabs if no headerAndy Green2018-06-291-10/+24
| | | | | | | | | | | | | | | | | noheader=1 stops the static page header from being emitted by cgit, but along with that, the small form that lets the user change branch context on the page is also lost. This isn't actually static since it contains a dynamic list of branches; it can't be reproduced on the user's external header static html. So it seems it doesn't belong to the set of header things that should be disabled. This patch relocates the branch selection combo and form on the left of the tabs line if noheader=1. It doesn't change anything if noheader is not set. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* md2html: change css name to not conflict with highlightAndy Green2018-06-291-3/+3
| | | | | | | | | | | md2html gets pygments to define the css for "highlight", making display of the blame view fragile against pygments version. On Fedora 28 / python3-pygments-2.2.0-10.fc28.noarch, "highlight" gets redefined so it no longer displays at the top of its parent. This patch changes the css class name used by md2html to "md2html_highlight" so there is no conflict with other definitions of "highlight". Signed-off-by: Andy Green <andy@warmcat.com>
* render: adapt for providing extra filter args for plainAndy Green2018-06-293-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes the render filter exec part to provide a second and third argument, which are used by md2html to fix up the url path for "plain" for the repo, eg, "/cgit/plain/" and "?h=mybranch", as required by the modifications to md2html in the previous patches. The combination means cgit becomes able to serve assets using markdown urls starting from the repo root dir, without mentioning any virtual url part specific to a cgit or other web rendering instance, while respecting the version context. Eg, continuing the example of the arguments being "/cgit/plain/" and "?h=mybranch" from above, if the markdown has ![overview](./doc-assets/overview.png) the img src will be fixed up to "/cgit/plain/doc-assets/overview.png?h=mybranch" If the same document is viewed from a different rev in cgit, the processed markdown url will change to match the cgit context, even though the markdown relative URL is the same for all versions. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* ui-shared: add helper for generating non-urlencoded linksAndy Green2018-06-292-0/+35
| | | | | | | | | | We are going to have to produce plain links in the next patch. But depending on config, the links are not simple. Reproduce the logic in repolink() to generate correctly- formatted links in a strbuf, without urlencoding, in a reusable helper cgit_repo_create_url(). Signed-off-by: Andy Green <andy@warmcat.com>
* md2html: add asset postfix argAndy Green2018-06-291-6/+13
| | | | | Extend md2html with an optional third argument for URL postfix, like "?h=mybranch" Signed-off-by: Andy Green <andy@warmcat.com>
* md2html: add asset mappingJohn Keeping2018-06-291-1/+49
| | | | | | | | | | | | | This remaps the "src" attribute on <img> elements according to a second command line argument, you can try it out with: md2html <README.md README.md /path/to/plain/directory/ The trailing "/" is important. This is useful when serving relative URLs from the repo in a readme. Signed-off-by: John Keeping <john@keeping.me.uk>
* ui-tree: render any matching README file in tree viewAndy Green2018-06-291-1/+52
| | | | | | | | | | | While listing the items in tree view, if we spot a filename matching any inline-readme entries from the config file, we stash the first one into walk_tree_context. After the tree view has been shown, if there is a stashed inline-readme we render it inline. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* config: add repo inline-readme listAndy Green2018-06-294-1/+19
| | | | | | | | This allows the user to choose to override any global inline-readme list for a specific repo, using the same kind of semantics as the other repo overrides. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* config: add global inline-readme listAndy Green2018-06-293-1/+15
| | | | | | Allows the user to specify a list of filenames that should be rendered inline with tree view, if present in the directory. Signed-off-by: Andy Green <andy@warmcat.com>
* ui-tree: ls_tail: add walk table paramAndy Green2018-06-291-3/+3
| | | | | | | Arrange that walk_tree_ctx is available in ls_tail, we will make use of it shortly. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* ui-tree: use render filters to display contentJohn Keeping2018-06-294-10/+105
| | | | | | | This allows applying filters to files in the repository, for example to render Markdown or AsciiDoc as HTML. Signed-off-by: John Keeping <john@keeping.me.uk>
* ui-tree: split out buffer printingJohn Keeping2018-06-291-10/+15
| | | | Signed-off-by: John Keeping <john@keeping.me.uk>
* Parse render filters from the configJohn Keeping2018-06-295-3/+59
| | | | | | | | | | | | | | Render filters will be used to present rendered content in the tree view, for example to display Markdown source rendered as HTML. We will add support for using these from the tree view in the following commits. AG: adapted so render.= can be used to specify the filter for files without any suffix Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* Add source pageJohn Keeping2018-06-293-0/+23
| | | | | | | | We are about to introduce rendering of content for the tree view. This source page will allow bypassing the renderer and accessing the content of the current tree view. Signed-off-by: John Keeping <john@keeping.me.uk>
* cgit_repobasename: convert to allocated resultAndy Green2018-06-294-30/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | cgit_repobasename has one user also in ui-shared.c. Make it static and remove the declaration from cgit.h. Instead of the gnarly return pointer to now deallocated stack, compute the valid part of the string using the incoming pointer, then just allocate the right amount and copy it in. Drop the const on the return type now it's allocated. Cover the fact the input may be garbage by returning NULL if so. Comment the function at the start that the result may be NULL or must be freed now. Convert the only user, cgit_snapshot_prefix(), to the same return convention and also comment him at the start that the result may be NULL or must be freed. Also change the return type to char *. Convert his only users, get_ref_from_filename() and cgit_print_snapshot()in ui-snapshot.c, to deal with the new result convention. cgit_print_snapshot() already did an xstrdup() on him anyway, just remove it and check for NULL. The reason triggering all this was ../ui-shared.c: In function ‘cgit_repobasename’: ../ui-shared.c:135:2: warning: ‘strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation] strncpy(rvbuf, reponame, sizeof(rvbuf)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + comment from John Keeping. Signed-off-by: Andy Green <andy@warmcat.com>
* gcc8.1: fix strncpy bounds warningsAndy Green2018-06-291-1/+1
| | | | | | | | | | | | | | | | These warnings are coming on default Fedora 28 build and probably others using gcc 8.1 ../shared.c: In function ‘expand_macro’: ../shared.c:483:3: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=] strncpy(name, value, len); ^~~~~~~~~~~~~~~~~~~~~~~~~ ../shared.c:480:9: note: length computed here len = strlen(value); ^~~~~~~~~~~~~ strncpy with a computed length via strlen is usually not the right thing. Signed-off-by: Andy Green <andy@warmcat.com>
* cgit.css: add copyright linesAndy Green2018-06-291-0/+8
| | | | | | The existing css file does not have any copyright lines on it. Signed-off-by: Andy Green <andy@warmcat.com>
* Use string list strdup_strings for mimetypesJohn Keeping2018-06-271-2/+2
| | | | | | | There's no need to do this manually with the string list API will do it for us. Signed-off-by: John Keeping <john@keeping.me.uk>
* manpage: fix sorting orderAndy Green2018-06-271-88/+88
| | | | | | | | You maybe didn't know you had OCD until you saw an alpha sorted list that has stuff out of order in it. Signed-off-by: Andy Green <andy@warmcat.com> Reviewed-by: John Keeping <john@keeping.me.uk>
* cache: close race window when unlocking slotsJohn Keeping2018-06-271-23/+14
| | | | | | | | | | | | | | | | | | | | We use POSIX advisory record locks to control access to cache slots, but these have an unhelpful behaviour in that they are released when any file descriptor referencing the file is closed by this process. Mostly this is okay, since we know we won't be opening the lock file anywhere else, but there is one place that it does matter: when we restore stdout we dup2() over a file descriptor referring to the file, thus closing that descriptor. Since we restore stdout before unlocking the slot, this creates a window during which the slot content can be overwritten. The fix is reasonably straightforward: simply restore stdout after unlocking the slot, but the diff is a bit bigger because this requires us to move the temporary stdout FD into struct cache_slot. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* git: update to v2.18.0Christian Hesse2018-06-2713-70/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Update to git version v2.18.0. Required changes follow upstream commits: * Convert find_unique_abbrev* to struct object_id (aab9583f7b5ea5463eb3f653a0b4ecac7539dc94) * sha1_file: convert read_sha1_file to struct object_id (b4f5aca40e6f77cbabcbf4ff003c3cf30a1830c8) * sha1_file: convert sha1_object_info* to object_id (abef9020e3df87c441c9a3a95f592fce5fa49bb9) * object-store: move packed_git and packed_git_mru to object store (a80d72db2a73174b3f22142eb2014b33696fd795) * treewide: rename tree to maybe_tree (891435d55da80ca3654b19834481205be6bdfe33) The changed data types required some of our own functions to be converted to struct object_id: ls_item print_dir print_dir_entry print_object single_tree_cb walk_tree write_tree_link And finally we use new upstream functions that were added for struct object_id: hashcpy -> oidcpy sha1_to_hex -> oid_to_hex Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk>
* global: remove functionality we deprecated for cgit v1.0Christian Hesse2018-06-275-43/+3
| | | | | | | | The man page states these were deprecated for v1.0. We are past v1.1, so remove the functionality. Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk>
* snapshot: strip bit from struct cgit_snapshot_formatChristian Hesse2018-06-275-10/+17
| | | | | | | We had a static bit value in struct cgit_snapshot_format. We do not rely on it and things can be calculated on the fly. So strip it. Signed-off-by: Christian Hesse <mail@eworm.de>
* snapshot: support special value 'all' to enable all formatsChristian Hesse2018-06-272-0/+4
| | | | | Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk>
* snapshot: support archive signaturesJohn Keeping2018-06-273-1/+84
| | | | | | | | | | | | | | | | | | Read signatures from the notes refs refs/notes/signatures/$FORMAT where FORMAT is one of our archive formats ("tar", "tar.gz", ...). The note is expected to simply contain the signature content to be returned when the snapshot "${filename}.asc" is requested, so the signature for cgit-1.1.tar.xz can be stored against the v1.1 tag with: git notes --ref=refs/notes/signatures/tar.xz add -C "$( gpg --output - --armor --detach-sign cgit-1.1.tar.xz | git hash-object -w --stdin )" v1.1 and then downloaded by simply appending ".asc" to the archive URL. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-refs: use shared function to print tag downloadsJohn Keeping2018-06-271-26/+1
| | | | | | | | cgit_compose_snapshot_prefix() is identical to print_tag_downloads(), so remove the latter and use the function from ui-shared.c instead. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-shared: pass separator in to cgit_print_snapshot_links()John Keeping2018-06-274-5/+6
| | | | | | | | | cgit_print_snapshot_links() is almost identical to print_tag_downloads(), so let's extract the difference to a parameter in preparation for removing print_tag_downloads() in the next commit. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-shared: use the same snapshot logic as ui-refsJohn Keeping2018-06-271-1/+7
| | | | | | | | | Make snapshot links in the commit UI use the same prefix algorithm as those in the summary UI, so that refs starting with the snapshot prefix are used as-is rather than composed with the prefix repeated. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-shared: rename parameter to cgit_print_snapshot_links()John Keeping2018-06-272-3/+3
| | | | | | | | This is expected to be a ref not a hex object ID, so name it more appropriately. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-shared: remove unused parameterJohn Keeping2018-06-274-5/+4
| | | | | | | | The "head" parameter to cgit_print_snapshot_links() is never used, so remove it. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-refs: remove unnecessary sanity checkJohn Keeping2018-06-271-3/+0
| | | | | | | | There is no way for refinfo::refname to be null, and Git will prevent zero-length refs so this check is unnecessary. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-snapshot: filter permitted snapshot requestsJohn Keeping2018-06-271-1/+1
| | | | | | | | | | Currently the snapshots configuration option only filters which links are displayed, not which snapshots may be generated and downloaded. Apply the filter also to requests to ensure that the system policy is enforced. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* Add "snapshot-prefix" repo configurationJohn Keeping2018-06-277-4/+23
| | | | | | | | | | | | Allow using a user-specified value for the prefix in snapshot files instead of the repository basename. For example, files downloaded from the linux-stable.git repository should be named linux-$VERSION and not linux-stable-$VERSION, which can be achieved by setting: repo.snapshot-prefix=linux Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-snapshot: pass repo into get_ref_from_filename()John Keeping2018-06-271-3/+4
| | | | | | | Prepare to allow a custom snapshot prefix. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-shared: pass repo object to print_snapshot_links()John Keeping2018-06-274-10/+8
| | | | | | | | | | Both call sites of cgit_print_snapshot_links() use the same values for the snapshot mask and repository name, which are derived from the cgit_repo structure so let's pass in the structure and access the fields directly. Signed-off-by: John Keeping <john@keeping.me.uk> Reviewed-by: Christian Hesse <mail@eworm.de>
* ui-log: highlight annotated tags in different colorChristian Hesse2018-06-272-1/+13
| | | | | | | | | Annotated tags have some extra information... Descriptive text or signature. Highlighting annotated tags in a different color show what tag may be worth clicking for extra information. Signed-off-by: Christian Hesse <mail@eworm.de> Reviewed-by: John Keeping <john@keeping.me.uk>
* print git version string in footerChristian Hesse2018-06-271-2/+3
| | | | | | | | | | | This helps tracking what git version cgit uses. The security implications are low as anybody can look up the version of our submodule anyway. The paranoid can use a custom footer. :-p On the other hand this brings potential security issues to the administrators eyes... Signed-off-by: Christian Hesse <mail@eworm.de>
* git: update to v2.17.1Christian Hesse2018-06-273-2/+2
| | | | | | | | | Update to git version v2.17.1. Required changes: * The function 'typename' has been renamed to 'type_name' (upstream commit debca9d2fe784193dc2d9f98b5edac605ddfefbb) Signed-off-by: Christian Hesse <mail@eworm.de>
* ui-blame: free read_sha1_file() buffer after useAndy Green2018-06-191-1/+4
| | | | | Signed-off-by: Andy Green <andy@warmcat.com> Signed-off-by: John Keeping <john@keeping.me.uk>
* ui-tag: Fix inconsistent capitalizationJon DeVree2018-06-161-1/+1
| | | | | | | | Way back in 2009 all of these were lower cased except this one occurrence. Signed-off-by: Jon DeVree <nuxi@vault24.org> Signed-off-by: John Keeping <john@keeping.me.uk>