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
.history(&sha)?
.filter(|q| {
if let Ok(q) = q {
if let (Some(since), Some(until)) = (since, until) {
q.committer.time.seconds() >= since && q.committer.time.seconds() < until
} else if let Some(since) = since {
q.committer.time.seconds() >= since
} else if let Some(until) = until {
q.committer.time.seconds() < until
} else {
// If neither `since` nor `until` are specified, we include the commit.
true
}
} else {
false
.filter_map(|commit| {
let commit = commit.ok()?;
let time = commit.committer.time.seconds();
let commit = api::json::commit(&commit);
match (since, until) {
(Some(since), Some(until)) if time >= since && time < until => Some(commit),
(Some(since), None) if time >= since => Some(commit),
(None, Some(until)) if time < until => Some(commit),
(None, None) => Some(commit),
_ => None,
}
})
.skip(page * per_page)
.take(per_page)
.map(|r| {
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<_>, _>>()?;
.collect::<Vec<_>>();
let response = json!({
"commits": commits,
@ -1124,7 +1104,6 @@ mod routes {
json!({
"commits": [
{
"commit": {
"id": HEAD,
"author": {
"name": "Alice Liddell",
@ -1141,131 +1120,7 @@ mod routes {
"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,
"author": {
"name": "Alice Liddell",
@ -1282,96 +1137,7 @@ mod routes {
"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,
"author": {
"name": "Alice Liddell",
@ -1386,58 +1152,6 @@ mod routes {
"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": {
"commits": 3,