GITv

Compare two revisions, and link each release to the changes since the last

Browse files

/<owner>/<name>/compare?from=&to= lists the commits one revision has that the other lacks and the changes they make, counted from where the two diverged, so a branch behind main doesn't show main's newer work as undone. With no revisions it is a plain GET form suggesting branch and tag names. Results are keyed by commit ids and cached. Each tag links to the changes since the nearest earlier tag in its own history (git describe), not the previous one by date, which breaks for tags made in the same second or added late. A branch's commit list links to its comparison with the default branch. Commit pages and comparisons now share one diff renderer, and history and comparisons share the commit-row template. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Author
Um9i vulgarmessiah@gmail.com
Date
22 Nov 2026, 23:26
Commit
7f0fe6d92594
Parent
a4d3c9a

15 files changed +358−39

@@ -12,7 +12,7 @@ Deferred until a second person pushes to the server: individual accounts and rep
- [x] **SSH key list and revoke.** `gitv keys [owner]` lists every active key with its owner, SHA-256 fingerprint (as `ssh-keygen -l` prints it) and label. `gitv add-key --label <text>` records a label for a new key. `gitv remove-key <fingerprint>` removes exactly that key, atomically and under the same lock as `add-key`. Verify that a revoked key no longer reaches anything, that a second key for the same owner still works, that an unknown fingerprint changes nothing, and that hand-written lines (options, comments, tabs) survive a removal.
- [x] **File history and line links.** A file's page links to the commits that changed it (`log` limited to that path, paged like branch history). Source lines carry `#L<n>` anchors, and a "Permalink" link pins the current file to its commit id, so a copied link opens the same lines after the branch moves. A range (`?lines=10-20`) is highlighted by the server, with no JavaScript.
- [ ] **Compare revisions.** `/<owner>/<name>/compare?from=<rev>&to=<rev>` shows the commits in `from..to`, the changed files, and the diff against the merge base. It reuses the commit page's diff rendering, output caps and cache. Cover a release-to-release comparison and a feature branch that has diverged from its target, and the access rules for private repositories.
- [x] **Compare revisions.** `/<owner>/<name>/compare?from=<rev>&to=<rev>` shows the commits in `from..to`, the changed files, and the diff against the merge base. It reuses the commit page's diff rendering, output caps and cache. Cover a release-to-release comparison and a feature branch that has diverged from its target, and the access rules for private repositories.
- [ ] **Description, default branch and index filter.** Over SSH (and as root): `description <name> <text>` writes git's `description` file, and `default-branch <name> <branch>` points `HEAD` at an existing branch. The index shows descriptions and can be filtered by name with a plain GET form (`?q=`). The repository header shows its visibility to the signed-in operator.
- [ ] **Tagged source archives.** The tags page links a `.tar.gz` of each tag, made by `git archive` and served through the download pool, under the repository's access rules. Tag annotations remain the release notes. Verify with a tagged GITv release that the archive matches `git archive` run locally.
- [ ] **Single-repository restore from backup.** Document restoring one repository from a retained snapshot after its trash entry was purged, and test it in `tests/backup.rs`: branches, tags, default branch and visibility come back, it can be restored under a new name, and a repository that has since taken the name is never overwritten.
+3−1
@@ -3,10 +3,12 @@
Git hosting with SSH pushes, public and private repository browsing, and read-only HTTPS cloning for public repositories.
- `gitv`: the SSH forced-command handler (`serve`) and the root admin CLI (`create`, `visibility`, `delete`, `add-key`, `keys`, `remove-key`, `trash`, `restore`, `purge`)
- `gitv-web`: the read-only browser (repositories, tree, blob, raw, log, commit, tags), with Markdown rendering and syntax highlighting (`crates/gitv-web/src/render.rs`)
- `gitv-web`: the read-only browser (repositories, tree, blob, raw, log, commit, compare, tags), with Markdown rendering and syntax highlighting (`crates/gitv-web/src/render.rs`)
**Linking to code.** A file's History lists the commits that changed it, and a folder's History does the same for everything inside. Permalink opens the file at the commit you're looking at, so the link keeps showing the same content after the branch moves. Click a line number to link that line (`#L12`). To link a range, add `lines=` to the address, for example `…&lines=12-20#L12`; the server marks those lines, and Permalink keeps the range.
**Comparing revisions.** `/<owner>/<name>/compare?from=v0.1.0&to=main` lists the commits `to` has that `from` lacks and the changes they make. A branch that has diverged is compared from where the two split, so the other branch's newer work isn't shown as undone. Any branch, tag or commit id works on either side, `to` defaults to the default branch, and the address can be shared. Each tag links to the changes since the previous tag in its history, and a branch's commit list links to its comparison with the default branch.
**Who can read what.** Over SSH each key reaches only its owner's repositories. The web browser has one account, and whoever signs in to it can read every repository on the server. It binds to localhost only; put it behind an HTTPS reverse proxy.
Existing and newly created repositories default to private. Publish one as its SSH owner or as the server administrator:
@@ -260,6 +260,15 @@ a.entry:hover .name{color:var(--accent)}
font-weight:600;cursor:pointer}
.button.primary:hover{filter:brightness(1.08)}
button.button{cursor:pointer}
/* Comparing revisions */
.compare-form{flex-direction:row;flex-wrap:wrap;align-items:flex-end;padding:16px 20px}
.compare-form label{flex:1 1 14em}
.compare-form input{font:400 15px var(--f-mono)}
.compare-summary{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin:0 0 16px}
.compare-summary p{margin:0;max-width:72ch}
.locator-bar{display:flex;align-items:flex-start;justify-content:space-between;gap:0 12px;flex-wrap:wrap}
.actions{display:flex;gap:8px;margin:0 0 12px}
.alert{margin:0 0 16px;padding:12px 14px;font-size:14px;border-radius:8px;color:var(--del-ink);background:var(--del);
border:1px solid var(--del-num)}
.alert.ok{color:var(--add-ink);background:var(--add);border-color:var(--add-num)}
@@ -129,6 +129,8 @@ pub(crate) struct TagRow<'a> {
pub sha_link: String,
pub when: String,
pub browse: String,
/// A comparison with the previous tag, and its label.
pub compare: Option<(String, String)>,
}
#[derive(Template)]
@@ -154,6 +156,8 @@ pub(crate) struct Diff<'a> {
pub file_count: String,
pub totals: Option<(usize, usize)>,
pub too_big: bool,
/// What the changes are, for the note when they're too large: "This commit’s changes".
pub what: &'static str,
pub file_icon: String,
pub files: Vec<DiffFile<'a>>,
}
@@ -184,6 +188,27 @@ pub(super) struct TagLink<'a> {
pub url: String,
}
#[derive(Template)]
#[template(path = "compare.html")]
pub(super) struct Compare<'a> {
pub title: String,
pub signed_in: bool,
pub masthead: String,
pub action: String,
pub from: String,
pub to: String,
/// Branch and tag names the form suggests.
pub refs: Vec<String>,
pub message: Option<String>,
pub summary: Option<String>,
pub swap: Option<String>,
pub rows: Vec<CommitRow<'a>>,
pub more: Option<String>,
// Rendered by `Diff`, which escapes repository data.
pub diff: Option<String>,
pub tag_icon: String,
}
pub(super) struct CommitRow<'a> {
pub url: String,
pub subject: String,
@@ -203,6 +228,8 @@ pub(super) struct History<'a> {
pub locator: String,
pub tag_icon: String,
pub rows: Vec<CommitRow<'a>>,
/// A link comparing a branch with the default one, and its label.
pub compare: Option<(String, String)>,
pub newer: Option<String>,
pub older: Option<String>,
}
@@ -153,15 +153,39 @@ pub(crate) fn view_commit(repo: &Repo, q: &Q) -> Option<View> {
))
}
/// A commit's changes as one panel per file. Only [`DIFF_LIMIT`] bytes of patch are read; past
/// that the files are listed without their lines.
/// A commit's changes as one panel per file.
pub(crate) fn render_diff(repo: &Repo, oid: &str, parents: &str) -> Option<String> {
// A merge shows what it brought in relative to its first parent.
let options = ["--format=", "--no-color", "-M", "--diff-merges=first-parent"];
let names = repo.reader.git_bytes(&[&["show", "-z", "--name-status"][..], &options, &[oid]].concat())?;
let names = [&["show", "-z", "--name-status"][..], &options, &[oid]].concat();
let patch = [&["show", "--patch"][..], &options, &[oid]].concat();
// A deleted file still exists in the parent commit.
let parent = parents.split_whitespace().next().unwrap_or(oid);
render_changes(repo, &names, &patch, parent, oid, "This commit’s changes")
}
/// The changes from commit `old` to commit `new` as one panel per file, for a comparison.
pub(crate) fn render_diff_between(repo: &Repo, old: &str, new: &str) -> Option<String> {
let options = ["--no-color", "-M", old, new, "--"];
let names = [&["diff", "-z", "--name-status"][..], &options].concat();
let patch = [&["diff", "--patch"][..], &options].concat();
render_changes(repo, &names, &patch, old, new, "These changes")
}
/// Changes as one panel per file, from git's `names` (NUL-delimited `--name-status`) and
/// `patch` listings of the same diff. Files link to `new`, or to `old` when deleted. Only
/// [`DIFF_LIMIT`] bytes of patch are read; past that the files are listed without their lines.
fn render_changes(
repo: &Repo,
names: &[&str],
patch: &[&str],
old: &str,
new: &str,
what: &'static str,
) -> Option<String> {
let names = repo.reader.git_bytes(names)?;
let changes = parse_changes(&names);
let (patch, too_big) =
git_capped(&repo.reader.dir, &[&["show", "--patch"][..], &options, &[oid]].concat(), DIFF_LIMIT).ok()?;
let (patch, too_big) = git_capped(&repo.reader.dir, patch, DIFF_LIMIT).ok()?;
let files = if too_big { Vec::new() } else { parse_diff(&String::from_utf8_lossy(&patch)) };
// The two listings come from the same diff, in the same order; if they ever disagree, show
// names only rather than pair lines with the wrong file.
@@ -171,8 +195,7 @@ pub(crate) fn render_diff(repo: &Repo, oid: &str, parents: &str) -> Option<Strin
.iter()
.enumerate()
.map(|(i, change)| {
// A deleted file still exists in the parent commit.
let at = if change.status == "Deleted" { parents.split_whitespace().next().unwrap_or(oid) } else { oid };
let at = if change.status == "Deleted" { old } else { new };
templates::DiffFile {
href: repo.url_at("blob", at.as_bytes(), &change.path, ""),
path: lossy(&change.path),
@@ -186,6 +209,7 @@ pub(crate) fn render_diff(repo: &Repo, oid: &str, parents: &str) -> Option<Strin
file_count: plural(changes.len(), "file", "files"),
totals,
too_big,
what,
file_icon: icon("file"),
files: panels,
};
@@ -0,0 +1,94 @@
//! Two revisions compared: the commits one has that the other lacks, and what changed.
use super::Repo;
use super::commit::render_diff_between;
use super::log::commit_rows;
use crate::cache::cached;
use crate::html::{icon, plural};
use crate::repository::Head;
use crate::urls::{Q, lossy};
use crate::{View, templates};
/// The most commits a comparison lists; the diff still covers all of them.
const COMPARE_COMMITS: usize = 250;
pub(crate) fn view_compare(repo: &Repo, q: &Q) -> Option<View> {
let given = |key| q.get(key).filter(|v| !v.is_empty()).cloned();
let from = given("from");
// Only `from` is needed: comparing against the default branch is the common case.
let to = given("to").or_else(|| from.as_ref().map(|_| repo.reader.default_ref()));
let mut refs: Vec<String> =
repo.reader.heads().iter().chain(repo.reader.tags()).map(|name| lossy(name).into_owned()).collect();
refs.dedup();
let mut page = templates::Compare {
title: "Compare revisions".into(),
signed_in: repo.signed_in,
masthead: String::new(),
action: repo.url("compare", &[]),
from: from.as_deref().map(lossy).unwrap_or_default().into_owned(),
to: to.as_deref().map(lossy).unwrap_or_default().into_owned(),
refs,
message: None,
summary: None,
swap: None,
rows: Vec::new(),
more: None,
diff: None,
tag_icon: icon("tag"),
};
let (Some(from), Some(to)) = (from, to) else {
page.masthead = repo.masthead("log", &repo.reader.default_ref(), None);
return Some(View::Html(page.to_string()));
};
let resolved = (repo.reader.resolve(&from), repo.reader.resolve(&to));
let (Some(old), Some(new)) = resolved else {
let missing = if resolved.0.is_none() { &from } else { &to };
page.masthead = repo.masthead("log", &repo.reader.default_ref(), None);
page.message = Some(format!("There’s no branch, tag or commit named {}.", lossy(missing)));
return Some(View::Html(page.to_string()));
};
let (from_name, to_name) = (page.from.clone(), page.to.clone());
page.title = format!("Comparing {from_name}...{to_name}");
page.masthead = repo.masthead("log", &to, Some(&new));
page.swap = Some(repo.compare_url(&to, &from));
// Both ids are commits, so these results never change and are cached by them.
let span = format!("{old}...{new}");
let counts = cached(repo.key("ahead", &span, ""), || {
repo.reader.git(&["rev-list", "--left-right", "--count", &span, "--"]).map(|out| out.trim().to_string())
})?;
let (behind, ahead) = counts.split_once('\t')?;
let (behind, ahead): (usize, usize) = (behind.parse().ok()?, ahead.parse().ok()?);
// Unrelated histories have no merge base; their trees are then compared directly.
let base =
cached(repo.key("base", &span, ""), || repo.reader.git(&["merge-base", &old, &new]).map(|o| o.trim().into()));
let commits = plural(ahead, "commit", "commits");
page.summary = Some(match (&base, ahead, behind) {
_ if old == new => format!("{from_name} and {to_name} are the same commit."),
(None, ..) => format!(
"{to_name} and {from_name} share no history. The {commits} below are all of {to_name}’s, \
and the changes compare the two directly."
),
(_, 0, _) => format!("{to_name} has no commits that {from_name} lacks."),
(_, _, 0) => format!("{to_name} is {commits} ahead of {from_name}."),
(_, _, behind) => format!(
"{to_name} is {commits} ahead of {from_name} and {} behind it. The changes are {to_name}’s since \
the two diverged.",
plural(behind, "commit", "commits")
),
});
if ahead == 0 {
return Some(View::Html(page.to_string()));
}
let range = format!("{old}..{new}");
let count = format!("-n{COMPARE_COMMITS}");
let log = repo.reader.git(&["log", &count, "--date=format:%-d %b %Y", Head::FORMAT, &range, "--"])?;
page.rows = commit_rows(repo, &log, COMPARE_COMMITS);
page.more = (ahead > COMPARE_COMMITS).then(|| format!("Showing the newest {COMPARE_COMMITS} of {ahead} commits."));
let start = base.as_deref().map_or(old.as_str(), |b| b);
let diff = cached(repo.key("compare", &format!("{start}..{new}"), ""), || render_diff_between(repo, start, &new))
.map_or_else(|| r#"<p class="note">These changes couldn’t be read.</p>"#.to_string(), |d| d.to_string());
page.diff = Some(diff);
Some(View::Html(page.to_string()))
}
@@ -27,28 +27,13 @@ pub(crate) fn view_log(repo: &Repo, q: &Q) -> Option<View> {
}
let out = repo.reader.git(&args)?;
let lines: Vec<&str> = out.lines().collect();
let tags = repo.reader.tags_by_commit();
let mut rows = Vec::new();
for head in lines.iter().take(PAGE).filter_map(|line| Head::parse(line)) {
let labels = tags
.get(&head.oid)
.into_iter()
.flatten()
.map(|name| templates::TagLink {
name: lossy(name),
url: repo.url_at("tree", &repo.reader.tag_ref(name), b"", ""),
})
.collect();
rows.push(templates::CommitRow {
url: repo.url("commit", &[("id", &head.oid)]),
subject: subject_or_placeholder(&head.subject).to_owned(),
short_id: head.oid.chars().take(7).collect(),
author: head.author,
when: ago(&head.stamp, &head.date),
tags: labels,
});
}
let rows = commit_rows(repo, &out, PAGE);
let page_url = |n: usize| repo.url_at("log", &reference, &path, &format!("page={n}"));
let default = repo.reader.default_ref();
let compare = (path.is_empty() && repo.reader.resolve(&default).is_some_and(|d| d != commit)).then(|| {
let shown = default.strip_prefix(b"refs/heads/").unwrap_or(&default);
(repo.compare_url(&default, &reference), format!("Compare with {}", lossy(shown)))
});
let title = if path.is_empty() {
format!("Commits on {}", lossy(&reference))
} else {
@@ -61,6 +46,7 @@ pub(crate) fn view_log(repo: &Repo, q: &Q) -> Option<View> {
masthead: repo.masthead("log", &reference, Some(&commit)),
locator: repo.locator("log", &reference, &path),
rows,
compare,
newer: number.checked_sub(1).map(page_url),
older: (lines.len() > PAGE).then(|| page_url(number + 1)),
tag_icon: icon("tag"),
@@ -68,3 +54,30 @@ pub(crate) fn view_log(repo: &Repo, q: &Q) -> Option<View> {
.to_string(),
))
}
/// Rows for up to `limit` commits of `git log` output in [`Head::FORMAT`], each labelled with
/// the tags that point at it.
pub(crate) fn commit_rows<'a>(repo: &'a Repo, out: &str, limit: usize) -> Vec<templates::CommitRow<'a>> {
let tags = repo.reader.tags_by_commit();
let mut rows = Vec::new();
for head in out.lines().take(limit).filter_map(Head::parse) {
let labels = tags
.get(&head.oid)
.into_iter()
.flatten()
.map(|name| templates::TagLink {
name: lossy(name).into_owned().into(),
url: repo.url_at("tree", &repo.reader.tag_ref(name), b"", ""),
})
.collect();
rows.push(templates::CommitRow {
url: repo.url("commit", &[("id", &head.oid)]),
subject: subject_or_placeholder(&head.subject).to_owned(),
short_id: head.oid.chars().take(7).collect(),
author: head.author,
when: ago(&head.stamp, &head.date),
tags: labels,
});
}
rows
}
@@ -2,6 +2,7 @@
mod blob;
mod commit;
mod compare;
mod index;
mod log;
mod tags;
@@ -21,6 +22,7 @@ use crate::urls::{Q, encode, lossy};
use crate::{View, templates};
use blob::view_blob;
use commit::view_commit;
use compare::view_compare;
use log::view_log;
use tags::view_tags;
use tree::view_tree;
@@ -195,6 +197,11 @@ impl Repo {
.to_string()
}
/// A comparison of two revisions, named as the URL should carry them.
pub(crate) fn compare_url(&self, from: &[u8], to: &[u8]) -> String {
format!("{}?from={}&to={}", self.url("compare", &[]), encode(from), encode(to))
}
pub(crate) fn sha_link(&self, oid: &str) -> String {
templates::ShaLink { href: self.url("commit", &[("id", oid)]), short: &oid[..oid.len().min(7)] }.to_string()
}
@@ -254,6 +261,7 @@ pub(crate) fn route(owner: &str, name: &str, view: Option<&str>, q: &Q, signed_i
Some("raw") => view_blob(&repo, q, true),
Some("log") => view_log(&repo, q),
Some("commit") => view_commit(&repo, q),
Some("compare") => view_compare(&repo, q),
Some("tags") => view_tags(&repo),
Some(_) => None,
};
@@ -1,6 +1,10 @@
//! The tags in a repository.
use data_encoding::HEXLOWER;
use sha2::{Digest, Sha256};
use super::Repo;
use crate::cache::cached;
use crate::html::ago;
use crate::urls::lossy;
use crate::{View, templates};
@@ -12,7 +16,9 @@ pub(crate) fn view_tags(repo: &Repo) -> Option<View> {
"--format=%(refname:lstrip=2)%1f%(objectname)%1f%(*objectname)%1f%(creatordate:unix)%1f%(creatordate:format:%-d %b %Y)%1f%(objecttype)%1f%(contents:subject)",
"refs/tags",
])?;
let mut rows = Vec::new();
let mut rows: Vec<templates::TagRow> = Vec::new();
let mut names: Vec<&[u8]> = Vec::new();
let mut targets: Vec<String> = Vec::new();
for line in out.split(|b| *b == b'\n') {
// The tag's message goes last, so one containing the separator stays whole.
let Ok([name, direct, peeled, stamp, date, kind, note]) =
@@ -21,14 +27,25 @@ pub(crate) fn view_tags(repo: &Repo) -> Option<View> {
continue;
};
let target = if peeled.is_empty() { direct } else { peeled };
names.push(name);
targets.push(lossy(target).into_owned());
rows.push(templates::TagRow {
name: lossy(name),
note: (kind == b"tag" && !note.is_empty()).then(|| lossy(note)),
sha_link: repo.sha_link(&lossy(target)),
when: ago(&lossy(stamp), &lossy(date)),
browse: repo.url_at("tree", &repo.reader.tag_ref(name), b"", ""),
compare: None,
});
}
// Each tag is compared with the release before it: the nearest tag in its own history.
for (row, (i, previous)) in rows.iter_mut().zip(previous_tags(repo, &out, &names, &targets).into_iter().enumerate())
{
if let Some(previous) = previous.and_then(|p| names.get(p)) {
let (from, to) = (repo.reader.tag_ref(previous), repo.reader.tag_ref(names[i]));
row.compare = Some((repo.compare_url(&from, &to), format!("Changes since {}", lossy(previous))));
}
}
Some(View::Html(
templates::Tags {
title: format!("Tags in {}/{}", repo.owner, repo.name),
@@ -39,3 +56,31 @@ pub(crate) fn view_tags(repo: &Repo) -> Option<View> {
.to_string(),
))
}
/// For each tag, the index in `names` of the nearest tag on an earlier commit in its history,
/// as `git describe` finds it. Creation dates can't order releases: tags made in the same
/// second, or added late, would pair with the wrong neighbour.
///
/// One git command per tag, so the answer is cached for the whole listing; `listing` (every
/// tag's name, target and date) names it, so any change to the tags makes a new entry.
fn previous_tags(repo: &Repo, listing: &[u8], names: &[&[u8]], targets: &[String]) -> Vec<Option<usize>> {
let key = repo.key("previous-tags", &HEXLOWER.encode(&Sha256::digest(listing)), "");
let found = cached(key, || {
let previous: Vec<String> = targets
.iter()
.map(|target| {
// Only a commit has history; a tag of a tree or blob has no predecessor.
let commit = repo.reader.commit_object(target)?;
let name = repo.reader.git_bytes(&["describe", "--tags", "--abbrev=0", &format!("{commit}^")])?;
let name = name.strip_suffix(b"\n").unwrap_or(&name);
names.iter().position(|n| *n == name).map(|i| i.to_string())
})
.map(Option::unwrap_or_default)
.collect();
Some(previous.join(","))
});
let found = found.as_deref().unwrap_or_default();
let mut previous: Vec<Option<usize>> = found.split(',').map(|i| i.parse().ok()).collect();
previous.resize(names.len(), None);
previous
}
@@ -0,0 +1,5 @@
{% for row in rows %}
<li class="commit-row"><div class="cmain"><a class="csubj" href="{{ row.url }}">{{ row.subject }}</a>
{% for tag in row.tags %}<a class="tagchip" href="{{ tag.url }}">{{ tag_icon|safe }}{{ tag.name }}</a>{% endfor %}
<span class="cmeta">{{ row.author }} committed {{ row.when }}</span></div><a class="sha" href="{{ row.url }}">{{ row.short_id }}</a></li>
{% endfor %}
@@ -0,0 +1,17 @@
{% extends "base.html" %}
{% block content %}
{{ masthead|safe }}
<form class="panel form compare-form" method="get" action="{{ action }}">
<label>From<input name="from" value="{{ from }}" list="refs" placeholder="v1.0.0" autocapitalize="none" autocomplete="off" spellcheck="false" required></label>
<label>To<input name="to" value="{{ to }}" list="refs" placeholder="main" autocapitalize="none" autocomplete="off" spellcheck="false" required></label>
<button class="button primary" type="submit">Compare</button>
<datalist id="refs">{% for name in refs %}<option value="{{ name }}">{% endfor %}</datalist>
</form>
{% if let Some(message) = message %}<p class="alert" role="alert">{{ message }}</p>{% endif %}
{% if let Some(summary) = summary %}<div class="compare-summary"><p>{{ summary }}</p>{% if let Some(url) = swap %}<a class="button" href="{{ url }}">Swap</a>{% endif %}</div>{% endif %}
{% if !rows.is_empty() %}<div class="panel"><ul class="rows">
{% include "commit-rows.html" %}
</ul></div>{% endif %}
{% if let Some(more) = more %}<p class="note">{{ more }}</p>{% endif %}
{% if let Some(diff) = diff %}{{ diff|safe }}{% endif %}
{% endblock %}
@@ -1,4 +1,4 @@
<h2 class="changes">{{ file_count }} changed{% if let Some((added, removed)) = totals %} <span class="plus">+{{ added }}</span><span class="minus">−{{ removed }}</span>{% endif %}</h2>{% if too_big %}<p class="note">This commit’s changes are too large to show line by line.</p>{% endif %}
<h2 class="changes">{{ file_count }} changed{% if let Some((added, removed)) = totals %} <span class="plus">+{{ added }}</span><span class="minus">−{{ removed }}</span>{% endif %}</h2>{% if too_big %}<p class="note">{{ what }} are too large to show line by line.</p>{% endif %}
{%- for file in files %}<section class="panel"><div class="panel-head"><div class="lead">{{ file_icon|safe }}<a href="{{ file.href }}"><b>{{ file.path }}</b></a>{% if !file.status.is_empty() %}<span class="status">{{ file.status }}</span>{% endif %}</div><div class="side">{% if let Some(diff) = file.diff %}<span class="plus">+{{ diff.added }}</span><span class="minus">−{{ diff.removed }}</span>{% endif %}</div></div>
{%- if let Some(diff) = file.diff %}{% if diff.binary %}<p class="note">Binary file changed.</p>{% else if diff.rows.is_empty() %}<p class="note">No content changes.</p>{% else %}<div class="diff-wrap"><table class="diff">
{%- for row in diff.rows %}{% if row.class == "hunk" %}<tr class="hunk"><td colspan="3">{{ row.text }}</td></tr>{% else %}<tr class="{{ row.class }}"><td class="num" data-n="{{ row.old }}"></td><td class="num" data-n="{{ row.new }}"></td><td class="line" data-s="{{ row.sign() }}">{{ row.text }}</td></tr>{% endif %}{% endfor -%}
@@ -1,12 +1,9 @@
{% extends "base.html" %}
{% block content %}
{{ masthead|safe }}{{ locator|safe }}
{{ masthead|safe }}
{% if let Some((url, label)) = compare %}<div class="locator-bar">{{ locator|safe }}<div class="actions"><a class="button" href="{{ url }}">{{ label }}</a></div></div>{% else %}{{ locator|safe }}{% endif %}
<div class="panel"><ul class="rows">
{% for row in rows %}
<li class="commit-row"><div class="cmain"><a class="csubj" href="{{ row.url }}">{{ row.subject }}</a>
{% for tag in row.tags %}<a class="tagchip" href="{{ tag.url }}">{{ tag_icon|safe }}{{ tag.name }}</a>{% endfor %}
<span class="cmeta">{{ row.author }} committed {{ row.when }}</span></div><a class="sha" href="{{ row.url }}">{{ row.short_id }}</a></li>
{% endfor %}
{% include "commit-rows.html" %}
</ul></div>
<nav class="pager" aria-label="Pages">
{% if let Some(url) = newer %}<a class="button" href="{{ url }}">Newer</a>{% else %}<span></span>{% endif %}
@@ -3,5 +3,5 @@
{{ masthead|safe }}
{% if rows.is_empty() %}<div class="panel empty"><h2>No tags yet</h2><p>Tag a release and push it to see it here.</p><code>git tag -a v1.0.0 -m "v1.0.0" &amp;&amp; git push origin v1.0.0</code></div>
{% else %}<div class="panel"><ul class="rows">{% for row in rows %}<li class="tag-row"><span class="tname">{{ row.name }}</span>{% if let Some(note) = row.note %}<span class="tnote">{{ note }}</span>{% endif %}<span class="tmeta">{{ row.sha_link|safe }}{{ row.when }}</span>
<span class="tacts"><a class="button" href="{{ row.browse }}">Browse files</a></span></li>{% endfor %}</ul></div>{% endif %}
<span class="tacts">{% if let Some((url, label)) = row.compare %}<a class="button" href="{{ url }}">{{ label }}</a>{% endif %}<a class="button" href="{{ row.browse }}">Browse files</a></span></li>{% endfor %}</ul></div>{% endif %}
{% endblock %}
@@ -1037,3 +1037,81 @@ fn file_links_pin_the_commit_and_the_lines() {
let bad = s.get("/ada/site/blob?path=src/main.rs&lines=x").text();
assert!(!bad.contains("class=\"sel\""), "{bad}");
}
#[test]
fn comparing_two_releases_lists_the_commits_and_changes_between_them() {
let s = server();
let f = fixture();
let html = s.get("/ada/site/compare?from=v0.1.0&to=light").text();
assert!(html.contains("<title>Comparing v0.1.0...light"), "{html}");
assert!(html.contains("light is 4 commits ahead of v0.1.0."), "{html}");
let expected = git(&f.repos.join("ada/site.git"), &["log", "--format=%s", &format!("{}..{}", f.first, f.tip)]);
assert_eq!(expected.lines().count(), 4);
for subject in expected.lines() {
assert!(html.contains(subject), "{subject} missing");
}
assert!(html.matches("class=\"commit-row\"").count() == 4, "{html}");
// The changes since the release, with a deleted file linked where it last existed.
assert!(html.contains("<span class=\"status\">Deleted</span>"), "{html}");
assert!(html.contains(&format!("href=\"/ada/site/blob?ref={}&#38;path=old.txt\"", f.first)), "{html}");
assert!(html.contains("<span class=\"status\">Added</span>") && html.contains(">side.txt<"), "{html}");
assert!(html.contains("href=\"/ada/site/compare?from=light&#38;to=v0.1.0\">Swap"), "{html}");
// The same comparison the other way has nothing to show.
let back = s.get("/ada/site/compare?from=light&to=v0.1.0").text();
assert!(back.contains("v0.1.0 has no commits that light lacks."), "{back}");
assert!(!back.contains("class=\"commit-row\"") && !back.contains("changed</h2>"), "{back}");
let same = s.get(&format!("/ada/site/compare?from=v0.1.0&to={}", f.first)).text();
assert!(same.contains("are the same commit."), "{same}");
// The tags page links each tag to the changes since the one before it.
let tags = s.get("/ada/site/tags").text();
let link = tags.split("href=\"").find(|part| part.contains("compare?from=")).expect("a comparison link");
let url = link.split('"').next().unwrap().replace("&#38;", "&");
assert_eq!(s.get(&url).status, 200, "{url}");
assert!(tags.contains(">Changes since "), "{tags}");
}
#[test]
fn a_diverged_branch_shows_only_its_own_changes() {
let s = server();
// `long` left main at the first commit: 55 commits of its own, and 4 of main's it lacks.
let html = s.get("/ada/site/compare?from=main&to=long").text();
assert!(html.contains("long is 55 commits ahead of main and 4 commits behind it."), "{html}");
assert_eq!(html.matches("class=\"commit-row\"").count(), 55);
assert!(!html.contains("Remove old.txt"), "main's own commits aren't listed");
// Compared from where the two diverged: main's removal of old.txt isn't a change here.
assert!(html.contains("0 files changed"), "{html}");
assert!(!html.contains("old.txt"), "{html}");
// Only `from` is needed; `to` defaults to the default branch.
let reverse = s.get("/ada/site/compare?from=long").text();
assert!(reverse.contains("main is 4 commits ahead of long and 55 commits behind it."), "{reverse}");
assert!(reverse.contains(">old.txt<"), "{reverse}");
// A branch's history offers the comparison with the default branch; main's doesn't.
let log = s.get("/ada/site/log?ref=long").text();
assert!(log.contains("href=\"/ada/site/compare?from=main&#38;to=long\">Compare with main"), "{log}");
assert!(!s.get("/ada/site/log").text().contains("Compare with"));
}
#[test]
fn the_compare_form_and_its_mistakes() {
let s = server();
let form = s.get("/ada/site/compare");
assert_eq!(form.status, 200);
let form = form.text();
assert!(form.contains("<form class=\"panel form compare-form\" method=\"get\" action=\"/ada/site/compare\">"));
assert!(form.contains("<option value=\"v0.1.0\">") && form.contains("<option value=\"long\">"), "{form}");
assert!(!form.contains("class=\"commit-row\""));
let missing = s.get("/ada/site/compare?from=nope&to=main").text();
assert!(missing.contains("There’s no branch, tag or commit named nope."), "{missing}");
assert!(missing.contains("value=\"nope\""), "the form keeps what was asked: {missing}");
// Escaped like everything else.
let odd = s.get("/ada/site/compare?from=%3Cb%3E").text();
assert!(odd.contains("named &#60;b&#62;.") && !odd.contains("<b>."), "{odd}");
// A private repository's comparison needs sign-in, like its other pages.
assert_eq!(s.get_signed_out("/ada/site/compare?from=v0.1.0&to=light").status, 303);
}