gitscope
← rgit / Diff · 98383dc → 98383dc
Changes 98383dc..98383dc
Patch commit
diff --git a/flake.nix b/flake.nix
index c6bb4d9..a2a2506 100644
--- a/flake.nix
+++ b/flake.nix
@@ -54,7 +54,6 @@
./src
./statics
./templates
- ./grammar
./themes
./build.rs
];
diff --git a/grammar/fortran/highlights.scm b/grammar/fortran/highlights.scm
deleted file mode 100644
index 418e40d..0000000
--- a/grammar/fortran/highlights.scm
+++ /dev/null
@@ -1,197 +0,0 @@
-(identifier) @variable
-(string_literal) @string
-(number_literal) @number
-(boolean_literal) @boolean
-(comment) @comment
-
-[
- (intrinsic_type)
- "allocatable"
- "attributes"
- "device"
- "dimension"
- "endtype"
- "global"
- "grid_global"
- "host"
- "import"
- "in"
- "inout"
- "intent"
- "optional"
- "out"
- "pointer"
- "type"
- "value"
- ] @type
-
-[
- "contains"
- "private"
- "public"
- ] @include
-
-[
- (none)
- "implicit"
- ] @attribute
-
-[
- "endfunction"
- "endprogram"
- "endsubroutine"
- "function"
- "procedure"
- "subroutine"
- ] @keyword.function
-
-[
- (default)
- (procedure_qualifier)
- "abstract"
- "bind"
- "call"
- "class"
- "continue"
- "cycle"
- "endenum"
- "endinterface"
- "endmodule"
- "endprocedure"
- "endprogram"
- "endsubmodule"
- "enum"
- "enumerator"
- "equivalence"
- "exit"
- "extends"
- "format"
- "goto"
- "include"
- "interface"
- "intrinsic"
- "non_intrinsic"
- "module"
- "namelist"
- "only"
- "parameter"
- "print"
- "procedure"
- "program"
- "read"
- "stop"
- "submodule"
- "use"
- "write"
- ] @keyword
-
-"return" @keyword.return
-
-[
- "else"
- "elseif"
- "elsewhere"
- "endif"
- "endwhere"
- "if"
- "then"
- "where"
- ] @conditional
-
-[
- "do"
- "enddo"
- "forall"
- "while"
- ] @repeat
-
-[
- "*"
- "+"
- "-"
- "/"
- "="
- "<"
- ">"
- "<="
- ">="
- "=="
- "/="
- ] @operator
-
-[
- "\\.and\\."
- "\\.or\\."
- "\\.lt\\."
- "\\.gt\\."
- "\\.ge\\."
- "\\.le\\."
- "\\.eq\\."
- "\\.eqv\\."
- "\\.neqv\\."
- ] @keyword.operator
-
-;; Brackets
-[
- "("
- ")"
- "["
- "]"
- "<<<"
- ">>>"
- ] @punctuation.bracket
-
-;; Delimiter
-[
- "::"
- ","
- "%"
- ] @punctuation.delimiter
-
-(parameters
- (identifier) @parameter)
-
-(program_statement
- (name) @namespace)
-
-(module_statement
- (name) @namespace)
-
-(submodule_statement
- (module_name) (name) @namespace)
-
-(function_statement
- (name) @function)
-
-(subroutine_statement
- (name) @function)
-
-(module_procedure_statement
- (name) @function)
-
-(end_program_statement
- (name) @namespace)
-
-(end_module_statement
- (name) @namespace)
-
-(end_submodule_statement
- (name) @namespace)
-
-(end_function_statement
- (name) @function)
-
-(end_subroutine_statement
- (name) @function)
-
-(end_module_procedure_statement
- (name) @function)
-
-(subroutine_call
- (identifier) @function)
-
-(keyword_argument
- name: (identifier) @keyword)
-
-(derived_type_member_expression
- (type_member) @property)
diff --git a/grammar/html/highlights.scm b/grammar/html/highlights.scm
deleted file mode 100644
index 99f39c9..0000000
--- a/grammar/html/highlights.scm
+++ /dev/null
@@ -1,20 +0,0 @@
-(tag_name) @tag
-(erroneous_end_tag_name) @tag.error
-(doctype) @constant
-(attribute_name) @attribute
-(comment) @comment
-
-[
- "\""
- (attribute_value)
-] @string
-
-[
- "<"
- ">"
- "</"
- "/>"
- "<!"
-] @punctuation.bracket
-
-"=" @punctuation.delimiter
diff --git a/grammar/html/injections.scm b/grammar/html/injections.scm
deleted file mode 100644
index ef58f41..0000000
--- a/grammar/html/injections.scm
+++ /dev/null
@@ -1,10 +0,0 @@
-((comment) @injection.content
- (#set! injection.language "comment"))
-
-((script_element
- (raw_text) @injection.content)
- (#set! injection.language "javascript"))
-
-((style_element
- (raw_text) @injection.content)
- (#set! injection.language "css"))
diff --git a/src/git.rs b/src/git.rs
index 3194e60..d5dd2b4 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -1,15 +1,3 @@
-use std::{
- borrow::Cow,
- collections::{BTreeMap, VecDeque},
- ffi::OsStr,
- fmt::{self, Arguments, Write},
- io::ErrorKind,
- path::{Path, PathBuf},
- str::FromStr,
- sync::Arc,
- time::Duration,
-};
-
use anyhow::{anyhow, Context, Result};
use axum::response::IntoResponse;
use bytes::{buf::Writer, BufMut, Bytes, BytesMut};
@@ -26,7 +14,19 @@ use gix::{
url::Scheme,
ObjectId, ThreadSafeRepository, Url,
};
+use itertools::Itertools;
use moka::future::Cache;
+use std::borrow::Cow;
+use std::{
+ collections::{BTreeMap, VecDeque},
+ ffi::OsStr,
+ fmt::{self, Arguments, Write},
+ io::ErrorKind,
+ path::{Path, PathBuf},
+ str::FromStr,
+ sync::Arc,
+ time::Duration,
+};
use tar::Builder;
use time::{OffsetDateTime, UtcOffset};
use tracing::{error, instrument, warn};
@@ -198,7 +198,7 @@ impl OpenRepository {
| EntryKind::Blob
| EntryKind::BlobExecutable
| EntryKind::Link => {
- let object = item
+ let mut object = item
.object()
.context("Expected item in tree to be object but it wasn't")?;
@@ -209,11 +209,36 @@ impl OpenRepository {
path,
name: item.filename().to_string(),
}),
- Kind::Tree => TreeItem::Tree(Tree {
- mode: item.mode().0,
- path,
- name: item.filename().to_string(),
- }),
+ Kind::Tree => {
+ let mut children = PathBuf::new();
+
+ // if the tree only has one child, flatten it down
+ while let Ok(Some(Ok(item))) = object
+ .try_into_tree()
+ .iter()
+ .map(gix::Tree::iter)
+ .flatten()
+ .at_most_one()
+ {
+ let nested_object = item.object().context(
+ "Expected item in tree to be object but it wasn't",
+ )?;
+
+ if nested_object.kind != Kind::Tree {
+ break;
+ }
+
+ object = nested_object;
+ children.push(item.filename().to_path_lossy());
+ }
+
+ TreeItem::Tree(Tree {
+ mode: item.mode().0,
+ path,
+ children,
+ name: item.filename().to_string(),
+ })
+ }
_ => continue,
});
}
@@ -602,6 +627,7 @@ pub struct Submodule {
pub struct Tree {
pub mode: u16,
pub name: String,
+ pub children: PathBuf,
pub path: PathBuf,
}
diff --git a/src/methods/repo/tree.rs b/src/methods/repo/tree.rs
index 485c2da..b80f89d 100644
--- a/src/methods/repo/tree.rs
+++ b/src/methods/repo/tree.rs
@@ -5,6 +5,7 @@ use std::{
use askama::Template;
use axum::{extract::Query, response::IntoResponse, Extension};
+use itertools::Itertools;
use serde::Deserialize;
use crate::{
diff --git a/templates/repo/tree.html b/templates/repo/tree.html
index faa1be6..fcad7db 100644
--- a/templates/repo/tree.html
+++ b/templates/repo/tree.html
@@ -19,7 +19,11 @@
{% match item -%}
{%- when crate::git::TreeItem::Tree with (tree) -%}
<td><pre>{{ tree.mode|file_perms }}</pre></td>
- <td><pre><a class="nested-tree" href="/{{ repo.display() }}/tree/{{ tree.path.display() }}{{ query }}">{{ tree.name }}</a></pre></td>
+ <td><pre><a class="nested-tree" href="/{{ repo.display() }}/tree/{{ tree.path.display() }}{{ query }}">{{ tree.name }}</a>
+ {%- for child in tree.children.ancestors().collect_vec().into_iter().rev() -%}
+ {%- if let Some(file_name) = child.file_name() %} / <a class="nested-tree" href="/{{ repo.display() }}/tree/{{ tree.path.display() }}/{{ child.display() }}{{ query }}">{{ file_name.to_string_lossy() }}</a>{%- endif -%}
+ {%- endfor -%}
+ </pre></td>
<td></td>
<td></td>