Update to Rust 2024 Edition
Diff
Cargo.toml | 2 +-
flake.lock | 25 +++++++++++++------------
flake.nix | 8 ++++++--
src/git.rs | 12 ++++++------
src/main.rs | 36 +++++++++++++++++++++---------------
src/theme.rs | 2 +-
src/unified_diff_builder.rs | 2 +-
tree-sitter-grammar-repository/Cargo.toml | 2 +-
tree-sitter-grammar-repository/build.rs | 4 ++--
src/database/indexer.rs | 2 +-
src/layers/logger.rs | 2 +-
src/methods/filters.rs | 2 +-
src/methods/index.rs | 2 +-
src/database/schema/commit.rs | 4 ++--
src/database/schema/repository.rs | 2 +-
src/database/schema/tag.rs | 2 +-
src/database/schema/tree.rs | 6 +++---
src/methods/repo/about.rs | 4 ++--
src/methods/repo/commit.rs | 4 ++--
src/methods/repo/diff.rs | 6 +++---
src/methods/repo/log.rs | 4 ++--
src/methods/repo/refs.rs | 2 +-
src/methods/repo/smart_git.rs | 10 +++++-----
src/methods/repo/snapshot.rs | 6 +++---
src/methods/repo/summary.rs | 4 ++--
src/methods/repo/tag.rs | 4 ++--
src/methods/repo/tree.rs | 6 +++---
27 files changed, 84 insertions(+), 81 deletions(-)
@@ -1,8 +1,8 @@
[package]
name = "rgit"
description = "A gitweb/cgit-like interface"
version = "0.1.5"
edition = "2021"
edition = "2024"
authors = ["Jordan Doyle <jordan@doyle.la>"]
license = "WTFPL"
@@ -1,13 +1,13 @@
{
"nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1746174207,
"narHash": "sha256-/ZPWm1dsz3tXREXGQfa/W6UsQ+J3Pvi0A0U1DZVgLqU=",
"lastModified": 1747937073,
"narHash": "sha256-52H8P6jAHEwRvg7rXr4Z7h1KHZivO8T1Z9tN6R0SWJg=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "4584ad9a5ea16ce196317cf4d3593e974fb4a8a1",
"rev": "bccf313a98c034573ac4170e6271749113343d97",
"type": "github"
},
"original": {
@@ -18,11 +18,11 @@
},
"crane": {
"locked": {
"lastModified": 1746291859,
"narHash": "sha256-DdWJLA+D5tcmrRSg5Y7tp/qWaD05ATI4Z7h22gd1h7Q=",
"lastModified": 1748047550,
"narHash": "sha256-t0qLLqb4C1rdtiY8IFRH5KIapTY/n3Lqt57AmxEv9mk=",
"owner": "ipetkov",
"repo": "crane",
"rev": "dfd9a8dfd09db9aad544c4d3b6c47b12562544a5",
"rev": "b718a78696060df6280196a6f992d04c87a16aef",
"type": "github"
},
"original": {
@@ -69,16 +69,15 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1746282974,
"narHash": "sha256-+mBFyA/Viq1m6qZkdRsg1w+SGlI0WGy9qlvVEHSAaho=",
"lastModified": 1748159586,
"narHash": "sha256-xeCMAhKjhDjVFsfJcftv+CWcExYo+X8IBUW8L947ww4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "328d7e75d76c2fef489056c7195ae3f913a0f5fa",
"rev": "7382d075365a977c4a9c8aa4c5e4abed15f00ee1",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "staging-next",
"repo": "nixpkgs",
"type": "github"
}
@@ -130,11 +129,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1746216483,
"narHash": "sha256-4h3s1L/kKqt3gMDcVfN8/4v2jqHrgLIe4qok4ApH5x4=",
"lastModified": 1747912973,
"narHash": "sha256-XgxghfND8TDypxsMTPU2GQdtBEsHTEc3qWE6RVEk8O0=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "29ec5026372e0dec56f890e50dbe4f45930320fd",
"rev": "020cb423808365fa3f10ff4cb8c0a25df35065a3",
"type": "github"
},
"original": {
@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/staging-next";
nixpkgs.url = "github:NixOS/nixpkgs";
crane.url = "github:ipetkov/crane";
utils.url = "github:numtide/flake-utils";
@@ -60,6 +60,7 @@
nativeBuildInputs = with pkgs; [ cmake clang makeBinaryWrapper ];
LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib";
SNAPPY_LIB_DIR = "${pkgs.snappy}/lib";
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { src = cargoOnlySrc; });
buildArgs = commonArgs // {
@@ -97,9 +98,12 @@
devShells.default = craneLib.devShell {
checks = self.checks.${system};
packages = with pkgs; [ rust-analyzer ];
packages = with pkgs; [ rust-analyzer clang ];
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";
TREE_SITTER_GRAMMAR_LIB_DIR = rgit-grammar;
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib";
SNAPPY_LIB_DIR = "${pkgs.snappy}/lib";
};
nixosModules.default = { config, lib, pkgs, ... }:
@@ -1,17 +1,17 @@
use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result, anyhow};
use axum::response::IntoResponse;
use bytes::{buf::Writer, BufMut, Bytes, BytesMut};
use bytes::{BufMut, Bytes, BytesMut, buf::Writer};
use comrak::{ComrakPlugins, Options};
use flate2::write::GzEncoder;
use gix::{
ObjectId, ThreadSafeRepository,
actor::SignatureRef,
bstr::{BStr, BString, ByteSlice, ByteVec},
diff::blob::{platform::prepare_diff::Operation, Sink},
diff::blob::{Sink, platform::prepare_diff::Operation},
object::Kind,
objs::{tree::EntryRef, CommitRef, TagRef},
objs::{CommitRef, TagRef, tree::EntryRef},
prelude::TreeEntryRefExt,
traverse::tree::visit::Action,
ObjectId, ThreadSafeRepository,
};
use itertools::Either;
use moka::future::Cache;
@@ -34,7 +34,7 @@
use crate::{
methods::filters::DisplayHexBuffer,
syntax_highlight::{format_file, format_file_inner, ComrakHighlightAdapter, FileIdentifier},
syntax_highlight::{ComrakHighlightAdapter, FileIdentifier, format_file, format_file_inner},
unified_diff_builder::{Callback, UnifiedDiffBuilder},
};
@@ -14,30 +14,30 @@
use anyhow::Context;
use askama::Template;
use axum::{
Extension, Router,
body::Body,
http,
http::{HeaderValue, StatusCode},
response::{IntoResponse, Response},
routing::get,
Extension, Router,
};
use clap::Parser;
use const_format::formatcp;
use database::schema::{
prefixes::{TREE_FAMILY, TREE_ITEM_FAMILY},
SCHEMA_VERSION,
prefixes::{TREE_FAMILY, TREE_ITEM_FAMILY},
};
use rocksdb::{Options, SliceTransform};
use tokio::{
net::TcpListener,
signal::unix::{signal, SignalKind},
signal::unix::{SignalKind, signal},
sync::mpsc,
};
use tower_http::{cors::CorsLayer, timeout::TimeoutLayer};
use tower_layer::layer_fn;
use tracing::{error, info, instrument, warn};
use tracing::{error, info, instrument, level_filters::LevelFilter, warn};
use tracing_subscriber::{
fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter,
EnvFilter, fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt,
};
use xxhash_rust::const_xxh3;
@@ -127,12 +127,10 @@
async fn main() -> Result<(), anyhow::Error> {
let args: Args = Args::parse();
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "info");
}
let logger_layer = tracing_subscriber::fmt::layer().with_span_events(FmtSpan::CLOSE);
let env_filter = EnvFilter::from_default_env();
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env()?;
tracing_subscriber::registry()
.with(env_filter)
@@ -312,13 +310,15 @@
) -> Result<(), tokio::task::JoinError> {
let (indexer_wakeup_send, mut indexer_wakeup_recv) = mpsc::channel(10);
std::thread::spawn(move || loop {
info!("Running periodic index");
crate::database::indexer::run(&scan_path, repository_list.as_deref(), &db);
info!("Finished periodic index");
if indexer_wakeup_recv.blocking_recv().is_none() {
break;
std::thread::spawn(move || {
loop {
info!("Running periodic index");
crate::database::indexer::run(&scan_path, repository_list.as_deref(), &db);
info!("Finished periodic index");
if indexer_wakeup_recv.blocking_recv().is_none() {
break;
}
}
});
@@ -328,7 +328,7 @@
match refresh_interval {
RefreshInterval::Never => futures_util::future::pending().await,
RefreshInterval::Duration(v) => tokio::time::sleep(v).await,
};
}
};
async move {
@@ -1,8 +1,8 @@
use std::fmt::{Formatter, Write};
use serde::{
de::{value::MapAccessDeserializer, Error, MapAccess, Visitor},
Deserialize, Deserializer,
de::{Error, MapAccess, Visitor, value::MapAccessDeserializer},
};
#[derive(Deserialize)]
@@ -1,11 +1,11 @@
use std::{fmt::Write, ops::Range};
use gix::diff::blob::{
intern::{InternedInput, Interner, Token},
Sink,
intern::{InternedInput, Interner, Token},
};
pub(crate) trait Callback {
@@ -1,8 +1,8 @@
[package]
name = "tree-sitter-grammar-repository"
description = "tree-sitter grammars built from Helix with support for dynamic linking"
version = "0.0.1"
edition = "2021"
edition = "2024"
authors = ["Jordan Doyle <jordan@doyle.la>"]
license = "WTFPL"
@@ -8,7 +8,7 @@
sync::LazyLock,
};
use anyhow::{bail, Context};
use anyhow::{Context, bail};
use heck::{ToSnakeCase, ToUpperCamelCase};
use quote::{format_ident, quote};
use serde::Deserialize;
@@ -357,7 +357,7 @@
Ok(Some(quote! {
pub mod #name {
extern "C" {
unsafe extern "C" {
fn #ffi() -> *const ();
}
@@ -9,11 +9,11 @@
use anyhow::Context;
use gix::{
ObjectId, Reference, Url,
bstr::{BStr, ByteSlice},
objs::tree::EntryKind,
refs::Category,
url::Scheme,
ObjectId, Reference, Url,
};
use itertools::{Either, Itertools};
use rocksdb::WriteBatch;
@@ -15,7 +15,7 @@
use futures_util::future::{FutureExt, Join, Map, Ready};
use tokio::task::futures::TaskLocalFuture;
use tower_service::Service;
use tracing::{error, info, instrument::Instrumented, Instrument, Span};
use tracing::{Instrument, Span, error, info, instrument::Instrumented};
use uuid::Uuid;
use super::UnwrapInfallible;
@@ -12,7 +12,7 @@
rend::{i32_le, i64_le},
tuple::ArchivedTuple2,
};
use time::{format_description::well_known::Rfc3339, OffsetDateTime, UtcOffset};
use time::{OffsetDateTime, UtcOffset, format_description::well_known::Rfc3339};
pub fn format_time(s: impl Into<Timestamp>) -> Result<String, askama::Error> {
@@ -1,10 +1,10 @@
use std::{cell::RefCell, sync::Arc};
use anyhow::Context;
use askama::Template;
use axum::{
response::{IntoResponse, Response},
Extension,
response::{IntoResponse, Response},
};
use itertools::{Either, Itertools};
@@ -1,7 +1,7 @@
use std::sync::Arc;
use anyhow::Context;
use gix::{actor::SignatureRef, objs::CommitRef, ObjectId};
use gix::{ObjectId, actor::SignatureRef, objs::CommitRef};
use rkyv::{Archive, Serialize};
use rocksdb::{IteratorMode, ReadOptions, WriteBatch};
use time::{OffsetDateTime, UtcOffset};
@@ -9,9 +9,9 @@
use yoke::{Yoke, Yokeable};
use crate::database::schema::{
Yoked,
prefixes::{COMMIT_COUNT_FAMILY, COMMIT_FAMILY},
repository::RepositoryId,
Yoked,
};
#[derive(Serialize, Archive, Debug, Yokeable)]
@@ -7,10 +7,10 @@
use yoke::{Yoke, Yokeable};
use crate::database::schema::{
Yoked,
commit::CommitTree,
prefixes::{COMMIT_FAMILY, REFERENCE_FAMILY, REPOSITORY_FAMILY, TAG_FAMILY},
tag::TagTree,
Yoked,
};
#[derive(Serialize, Archive, Debug, PartialEq, Eq, Hash, Yokeable)]
@@ -6,10 +6,10 @@
use yoke::{Yoke, Yokeable};
use crate::database::schema::{
Yoked,
commit::{ArchivedAuthor, Author},
prefixes::TAG_FAMILY,
repository::RepositoryId,
Yoked,
};
#[derive(Serialize, Archive, Debug, Yokeable)]
@@ -1,15 +1,15 @@
use std::collections::BTreeMap;
use anyhow::Context;
use gix::{bstr::BStr, ObjectId};
use gix::{ObjectId, bstr::BStr};
use itertools::{Either, Itertools};
use rkyv::{Archive, Serialize};
use rocksdb::{WriteBatch, DB};
use rocksdb::{DB, WriteBatch};
use yoke::{Yoke, Yokeable};
use super::{
prefixes::{TREE_FAMILY, TREE_ITEM_FAMILY},
Yoked,
prefixes::{TREE_FAMILY, TREE_ITEM_FAMILY},
};
#[derive(Serialize, Archive, Debug, PartialEq, Eq, Hash)]
@@ -1,17 +1,17 @@
use std::sync::Arc;
use askama::Template;
use axum::{extract::Query, response::IntoResponse, Extension};
use axum::{Extension, extract::Query, response::IntoResponse};
use serde::Deserialize;
use crate::{
Git,
git::ReadmeFormat,
into_response,
methods::{
filters,
repo::{Repository, RepositoryPath, Result},
},
Git,
};
#[derive(Deserialize)]
@@ -1,17 +1,17 @@
use std::sync::Arc;
use askama::Template;
use axum::{extract::Query, response::IntoResponse, Extension};
use axum::{Extension, extract::Query, response::IntoResponse};
use serde::Deserialize;
use crate::{
Git,
git::{Commit, OpenRepository},
into_response,
methods::{
filters,
repo::{Repository, RepositoryPath, Result},
},
Git,
};
#[derive(Template)]
@@ -1,24 +1,24 @@
use std::{fmt::Write, sync::Arc};
use askama::Template;
use axum::{
Extension,
extract::Query,
http::HeaderValue,
response::{IntoResponse, Response},
Extension,
};
use bytes::{BufMut, BytesMut};
use clap::crate_version;
use time::format_description::well_known::Rfc2822;
use crate::{
Git,
git::Commit,
http, into_response,
methods::{
filters,
repo::{commit::UriQuery, Repository, RepositoryPath, Result},
repo::{Repository, RepositoryPath, Result, commit::UriQuery},
},
Git,
};
#[derive(Template)]
@@ -1,8 +1,8 @@
use std::sync::Arc;
use anyhow::Context;
use askama::Template;
use axum::{extract::Query, response::IntoResponse, Extension};
use axum::{Extension, extract::Query, response::IntoResponse};
use serde::Deserialize;
use crate::{
@@ -10,7 +10,7 @@
into_response,
methods::{
filters,
repo::{Repository, Result, DEFAULT_BRANCHES},
repo::{DEFAULT_BRANCHES, Repository, Result},
},
};
@@ -9,7 +9,7 @@
};
use anyhow::Context;
use askama::Template;
use axum::{response::IntoResponse, Extension};
use axum::{Extension, response::IntoResponse};
use rkyv::string::ArchivedString;
use yoke::Yoke;
@@ -1,14 +1,14 @@
use std::{io, io::ErrorKind, path::Path, process::Stdio, str::FromStr};
use anyhow::{anyhow, Context};
use anyhow::{Context, anyhow};
use axum::{
Extension,
body::Body,
http::{
header::{HeaderMap, HeaderName, HeaderValue},
Method, Uri,
header::{HeaderMap, HeaderName, HeaderValue},
},
response::{IntoResponse, Response},
Extension,
};
use bytes::{Buf, Bytes, BytesMut};
use futures_util::TryStreamExt;
@@ -20,11 +20,11 @@
};
use tokio_stream::wrappers::ReceiverStream;
use tokio_util::io::StreamReader;
use tracing::{debug, error, info_span, warn, Instrument};
use tracing::{Instrument, debug, error, info_span, warn};
use crate::{
methods::repo::{Repository, RepositoryPath, Result},
StatusCode,
methods::repo::{Repository, RepositoryPath, Result},
};
#[allow(clippy::unused_async)]
@@ -1,10 +1,10 @@
use std::sync::Arc;
use anyhow::{anyhow, Context};
use axum::{body::Body, extract::Query, http::Response, Extension};
use anyhow::{Context, anyhow};
use axum::{Extension, body::Body, extract::Query, http::Response};
use serde::Deserialize;
use tokio_stream::wrappers::ReceiverStream;
use tracing::{error, info_span, Instrument};
use tracing::{Instrument, error, info_span};
use super::{RepositoryPath, Result};
use crate::git::Git;
@@ -1,8 +1,8 @@
use std::{collections::BTreeMap, sync::Arc};
use anyhow::Context;
use askama::Template;
use axum::{response::IntoResponse, Extension};
use axum::{Extension, response::IntoResponse};
use axum_extra::extract::Host;
use rkyv::string::ArchivedString;
@@ -11,7 +11,7 @@
into_response,
methods::{
filters,
repo::{Refs, Repository, Result, DEFAULT_BRANCHES},
repo::{DEFAULT_BRANCHES, Refs, Repository, Result},
},
};
@@ -1,18 +1,18 @@
use std::sync::Arc;
use askama::Template;
use axum::{extract::Query, response::IntoResponse, Extension};
use axum::{Extension, extract::Query, response::IntoResponse};
use serde::Deserialize;
use yoke::Yoke;
use crate::{
Git,
git::DetailedTag,
into_response,
methods::{
filters,
repo::{Repository, RepositoryPath, Result},
},
Git,
};
#[derive(Deserialize)]
@@ -1,6 +1,6 @@
use anyhow::{bail, Context};
use anyhow::{Context, bail};
use askama::Template;
use axum::{extract::Query, response::IntoResponse, Extension};
use axum::{Extension, extract::Query, response::IntoResponse};
use gix::ObjectId;
use itertools::Itertools;
use serde::Deserialize;
@@ -16,13 +16,13 @@
YokedSortedTree, YokedTreeItem, YokedTreeItemKeyUtf8,
};
use crate::{
Git, ResponseEither,
git::FileWithContent,
into_response,
methods::{
filters,
repo::{ChildPath, Repository, RepositoryPath, Result},
},
Git, ResponseEither,
};
use super::log::get_branch_commits;