From d031eee14e4981fb67261d182d701021f5602058 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 6 Aug 2023 00:52:30 +0200 Subject: [PATCH] Grey out untracked children --- ...fc37347ea280ebdf584bc535f135f63610a66.json | 26 ++++++++++++++++ ...12898959bfba8d12f31428b6e582ce2106719.json | 20 ------------- src/recurring/repo.rs | 2 ++ src/web/commit_hash.rs | 30 ++++++++++++------- static/base.css | 5 ++++ templates/commit_hash.html | 5 ++++ 6 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 .sqlx/query-2846970f979d84f4ba4ba2cd659fc37347ea280ebdf584bc535f135f63610a66.json delete mode 100644 .sqlx/query-c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719.json diff --git a/.sqlx/query-2846970f979d84f4ba4ba2cd659fc37347ea280ebdf584bc535f135f63610a66.json b/.sqlx/query-2846970f979d84f4ba4ba2cd659fc37347ea280ebdf584bc535f135f63610a66.json new file mode 100644 index 0000000..78ede63 --- /dev/null +++ b/.sqlx/query-2846970f979d84f4ba4ba2cd659fc37347ea280ebdf584bc535f135f63610a66.json @@ -0,0 +1,26 @@ +{ + "db_name": "SQLite", + "query": "\nSELECT child, tracked FROM commit_links\nJOIN commits ON hash = child\nWHERE parent = ?\n ", + "describe": { + "columns": [ + { + "name": "child", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "tracked", + "ordinal": 1, + "type_info": "Int64" + } + ], + "parameters": { + "Right": 1 + }, + "nullable": [ + false, + false + ] + }, + "hash": "2846970f979d84f4ba4ba2cd659fc37347ea280ebdf584bc535f135f63610a66" +} diff --git a/.sqlx/query-c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719.json b/.sqlx/query-c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719.json deleted file mode 100644 index 648a663..0000000 --- a/.sqlx/query-c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "db_name": "SQLite", - "query": "SELECT child FROM commit_links WHERE parent = ?", - "describe": { - "columns": [ - { - "name": "child", - "ordinal": 0, - "type_info": "Text" - } - ], - "parameters": { - "Right": 1 - }, - "nullable": [ - false - ] - }, - "hash": "c8172df79e5000f77a957a648fc12898959bfba8d12f31428b6e582ce2106719" -} diff --git a/src/recurring/repo.rs b/src/recurring/repo.rs index acecfaf..48547e8 100644 --- a/src/recurring/repo.rs +++ b/src/recurring/repo.rs @@ -103,6 +103,7 @@ async fn track_main_branch(conn: &mut SqliteConnection, repo: &Repository) -> so Ok(()) } +// TODO Write all refs to DB, not just tracked ones async fn update_tracked_refs( conn: &mut SqliteConnection, repo: &Repository, @@ -134,6 +135,7 @@ async fn update_tracked_refs( Ok(()) } +// TODO tracked -> reachable, 0 = unreachable, 1 = reachable, 2 = reachable from tracked ref async fn update_commit_tracked_status(conn: &mut SqliteConnection) -> somehow::Result<()> { sqlx::query!( " diff --git a/src/web/commit_hash.rs b/src/web/commit_hash.rs index 689b2a0..c6dbcef 100644 --- a/src/web/commit_hash.rs +++ b/src/web/commit_hash.rs @@ -5,7 +5,6 @@ use axum::{ extract::{Path, State}, response::IntoResponse, }; -use futures::TryStreamExt; use gix::{prelude::ObjectIdExt, Id, ObjectId, ThreadSafeRepository}; use sqlx::SqlitePool; @@ -14,14 +13,16 @@ use crate::{config::Config, repo, somehow}; struct Commit { hash: String, description: String, + tracked: bool, } impl Commit { - fn new(id: Id<'_>) -> somehow::Result { + fn new(id: Id<'_>, tracked: bool) -> somehow::Result { let commit = id.object()?.try_into_commit()?; Ok(Self { hash: id.to_string(), description: repo::format_commit_short(&commit)?, + tracked, }) } } @@ -50,12 +51,18 @@ pub async fn get( State(repo): State>, ) -> somehow::Result { // Do this first because a &Repository can't be kept across awaits. - let child_ids = sqlx::query!("SELECT child FROM commit_links WHERE parent = ?", hash) - .fetch(&db) - .map_ok(|r| r.child) - .try_collect::>() - .await?; + let child_rows = sqlx::query!( + " +SELECT child, tracked FROM commit_links +JOIN commits ON hash = child +WHERE parent = ? + ", + hash + ) + .fetch_all(&db) + .await?; + // TODO Include untracked info for current commit let repo = repo.to_thread_local(); let id = hash.parse::()?.attach(&repo); let commit = id.object()?.try_into_commit()?; @@ -64,13 +71,14 @@ pub async fn get( let mut parents = vec![]; for id in commit.parent_ids() { - parents.push(Commit::new(id)?); + // TODO Include untracked info for parents + parents.push(Commit::new(id, true)?); } let mut children = vec![]; - for hash in child_ids { - let id = hash.parse::()?.attach(&repo); - children.push(Commit::new(id)?); + for row in child_rows { + let id = row.child.parse::()?.attach(&repo); + children.push(Commit::new(id, row.tracked != 0)?); } Ok(CommitIdTemplate { diff --git a/static/base.css b/static/base.css index 9cbc0f0..ac5a67e 100644 --- a/static/base.css +++ b/static/base.css @@ -82,3 +82,8 @@ dd { grid: auto-flow / min-content max-content; column-gap: 1ch; } + +.commit .untracked, +.commit .untracked a { + color: #777; +} diff --git a/templates/commit_hash.html b/templates/commit_hash.html index b5a6297..f8e462a 100644 --- a/templates/commit_hash.html +++ b/templates/commit_hash.html @@ -25,8 +25,13 @@ {% endfor %} {% for commit in children %} + {% if commit.tracked %}
Child:
{{ commit.description }}
+ {% else %} +
Child:
+
{{ commit.description }}
+ {% endif %} {% endfor %}
{{ message }}