httpd: Remove diff and branches from history route

This commit is contained in:
Sebastian Martinez 2024-04-10 11:33:13 +02:00 committed by cloudhead
parent 3556758386
commit 574ac3566b
No known key found for this signature in database
1 changed files with 53 additions and 339 deletions

View File

@ -214,41 +214,21 @@ async fn history_handler(
let commits = repo let commits = repo
.history(&sha)? .history(&sha)?
.filter(|q| { .filter_map(|commit| {
if let Ok(q) = q { let commit = commit.ok()?;
if let (Some(since), Some(until)) = (since, until) { let time = commit.committer.time.seconds();
q.committer.time.seconds() >= since && q.committer.time.seconds() < until let commit = api::json::commit(&commit);
} else if let Some(since) = since { match (since, until) {
q.committer.time.seconds() >= since (Some(since), Some(until)) if time >= since && time < until => Some(commit),
} else if let Some(until) = until { (Some(since), None) if time >= since => Some(commit),
q.committer.time.seconds() < until (None, Some(until)) if time < until => Some(commit),
} else { (None, None) => Some(commit),
// If neither `since` nor `until` are specified, we include the commit. _ => None,
true
}
} else {
false
} }
}) })
.skip(page * per_page) .skip(page * per_page)
.take(per_page) .take(per_page)
.map(|r| { .collect::<Vec<_>>();
r.and_then(|c| {
let glob = Glob::all_heads().branches().and(Glob::all_remotes());
let branches: Vec<String> = repo
.revision_branches(c.id, glob)?
.iter()
.map(|b| b.refname().to_string())
.collect();
let diff = repo.diff_commit(c.id)?;
Ok(json!({
"commit": api::json::commit(&c),
"diff": diff,
"branches": branches
}))
})
})
.collect::<Result<Vec<_>, _>>()?;
let response = json!({ let response = json!({
"commits": commits, "commits": commits,
@ -1124,7 +1104,6 @@ mod routes {
json!({ json!({
"commits": [ "commits": [
{ {
"commit": {
"id": HEAD, "id": HEAD,
"author": { "author": {
"name": "Alice Liddell", "name": "Alice Liddell",
@ -1141,131 +1120,7 @@ mod routes {
"time": 1673003014 "time": 1673003014
}, },
}, },
"diff": {
"added": [
{ {
"path": "README",
"diff": {
"type": "plain",
"hunks": [
{
"header": "@@ -0,0 +1 @@\n",
"lines": [
{
"line": "Hello World!\n",
"lineNo": 1,
"type": "addition",
},
],
"old": {
"start": 0,
"end": 0,
},
"new": {
"start": 1,
"end": 2,
},
},
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
"oid": "980a0d5f19a64b4b30a87d4206aade58726b60e3",
"mode": "blob",
},
},
{
"path": "dir1/README",
"diff": {
"type": "plain",
"hunks": [
{
"header": "@@ -0,0 +1 @@\n",
"lines": [
{
"line": "Hello World from dir1!\n",
"lineNo": 1,
"type": "addition"
}
],
"old": {
"start": 0,
"end": 0,
},
"new": {
"start": 1,
"end": 2,
},
}
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
"oid": "1dd5654ca2d2cf9f33b14c92b5ca9e1d21a91ae1",
"mode": "blob",
},
}
],
"deleted": [
{
"path": "CONTRIBUTING",
"diff": {
"type": "plain",
"hunks": [
{
"header": "@@ -1 +0,0 @@\n",
"lines": [
{
"line": "Thank you very much!\n",
"lineNo": 1,
"type": "deletion",
},
],
"old": {
"start": 1,
"end": 2,
},
"new": {
"start": 0,
"end": 0,
},
},
],
"stats": {
"additions": 0,
"deletions": 1,
},
"eof": "noneMissing",
},
"old": {
"oid": "82eb77880c693655bce074e3dbbd9fa711dc018b",
"mode": "blob",
},
},
],
"moved": [],
"copied": [],
"modified": [],
"stats": {
"filesChanged": 3,
"insertions": 2,
"deletions": 1
}
},
"branches": [
"refs/heads/master"
]
},
{
"commit": {
"id": PARENT, "id": PARENT,
"author": { "author": {
"name": "Alice Liddell", "name": "Alice Liddell",
@ -1282,96 +1137,7 @@ mod routes {
"time": 1673002014, "time": 1673002014,
}, },
}, },
"diff": {
"added": [
{ {
"path": "CONTRIBUTING",
"diff": {
"type": "plain",
"hunks": [
{
"header": "@@ -0,0 +1 @@\n",
"lines": [
{
"line": "Thank you very much!\n",
"lineNo": 1,
"type": "addition",
},
],
"old": {
"start": 0,
"end": 0,
},
"new": {
"start": 1,
"end": 2,
},
},
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
"oid": "82eb77880c693655bce074e3dbbd9fa711dc018b",
"mode": "blob",
},
},
],
"deleted": [
{
"path": "README",
"diff": {
"type": "plain",
"hunks": [
{
"header": "@@ -1 +0,0 @@\n",
"lines": [
{
"line": "Hello World!\n",
"lineNo": 1,
"type": "deletion",
},
],
"old": {
"start": 1,
"end": 2,
},
"new": {
"start": 0,
"end": 0,
},
},
],
"stats": {
"additions": 0,
"deletions": 1,
},
"eof": "noneMissing",
},
"old": {
"oid": "980a0d5f19a64b4b30a87d4206aade58726b60e3",
"mode": "blob",
},
},
],
"moved": [],
"copied": [],
"modified": [],
"stats": {
"filesChanged": 2,
"insertions": 1,
"deletions": 1,
},
},
"branches": [
"refs/heads/master",
],
},
{
"commit": {
"id": INITIAL_COMMIT, "id": INITIAL_COMMIT,
"author": { "author": {
"name": "Alice Liddell", "name": "Alice Liddell",
@ -1386,58 +1152,6 @@ mod routes {
"time": 1673001014, "time": 1673001014,
}, },
}, },
"diff": {
"added": [
{
"path": "README",
"diff": {
"type": "plain",
"hunks": [
{
"header": "@@ -0,0 +1 @@\n",
"lines": [
{
"line": "Hello World!\n",
"lineNo": 1,
"type": "addition"
}
],
"old": {
"start": 0,
"end": 0,
},
"new": {
"start": 1,
"end": 2,
},
}
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
"oid": "980a0d5f19a64b4b30a87d4206aade58726b60e3",
"mode": "blob",
},
}
],
"deleted": [],
"moved": [],
"copied": [],
"modified": [],
"stats": {
"filesChanged": 1,
"insertions": 1,
"deletions": 0
}
},
"branches": [
"refs/heads/master"
]
}
], ],
"stats": { "stats": {
"commits": 3, "commits": 3,