Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gitarena-common/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a, T: Deserialize<'a>> IpcPacket<T> {
}
}

impl<T: DeserializeOwned + ?Sized> IpcPacket<T> {
impl<T: DeserializeOwned> IpcPacket<T> {
pub fn deserialize_from<R: Read>(input: R) -> bincode::Result<Self> {
Self::bincode().deserialize_from::<_, Self>(input)
}
Expand Down
4 changes: 2 additions & 2 deletions gitarena-common/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use tracing::metadata::LevelFilter;
use tracing::Subscriber;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_appender::rolling;
use tracing_subscriber::filter::{FilterExt, FromEnvError};
use tracing_subscriber::filter::FromEnvError;
use tracing_subscriber::fmt::Layer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{layer, EnvFilter, Layer as RootLayer, Registry};
use tracing_subscriber::{layer, EnvFilter, Registry};
use tracing_unwrap::ResultExt;

pub fn init_logger(
Expand Down
2 changes: 1 addition & 1 deletion gitarena-workhorse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tracing_unwrap::ResultExt;

#[tokio::main]
async fn main() -> Result<()> {
let _log_guards = init_logger("gitarena-workhorse", &[])?;
let _log_guards = init_logger("gitarena-workhorse", &[], None)?;

Endpoint::new(ipc_path()?.to_owned())
.incoming()
Expand Down
2 changes: 1 addition & 1 deletion src/git/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) async fn last_commit_for_blob(
) -> Result<Option<Oid>> {
let commits = commits_for_blob(repo, reference_name, file_name, Some(1)).await?;

Ok(commits.get(0).copied())
Ok(commits.first().copied())
}

#[instrument(err, skip(repo))]
Expand Down
2 changes: 1 addition & 1 deletion src/git/io/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,6 @@ impl GitWriter {

fn u16_to_hex(value: u16) -> [u8; 4] {
let mut buffer = [0u8; 4];
hex::encode_to_slice((value as u16).to_be_bytes(), &mut buffer).unwrap_or_log();
hex::encode_to_slice(value.to_be_bytes(), &mut buffer).unwrap_or_log();
buffer
}
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ use actix_web::{App, HttpResponse, HttpServer};
use anyhow::{anyhow, Context, Result};
use futures_locks::RwLock;
use gitarena_common::database::create_postgres_pool;
use gitarena_common::log::{default_env, init_logger, log_file, stdout, tokio_console};
use gitarena_common::log::init_logger;
use gitarena_macros::from_optional_config;
use log::info;
use magic::{Cookie, CookieFlags};
use time::Duration as TimeDuration;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{EnvFilter, Layer, Registry};
use tracing_subscriber::Layer;
use tracing_unwrap::ResultExt;

mod captcha;
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl GitoxideSignatureExtensions for GitoxideSignature {
name: BString::from("GitArena"), // TODO: Allow administrators to edit this
email: BString::from("git@gitarena.com"), // as well as this
time: GitoxideTime {
time: naive.timestamp() as u32,
time: naive.and_utc().timestamp() as u32,
offset: 0,
sign: Sign::Plus,
},
Expand Down
4 changes: 2 additions & 2 deletions src/privileges/privilege.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ async fn get_repo_privilege<'e, E: Executor<'e, Database = Postgres>>(
Ok(sqlx::query_as::<_, Privilege>(
"select * from privileges where user_id = $1 and repo_id = $2 limit 1",
)
.bind(&user.id)
.bind(&repo.id)
.bind(user.id)
.bind(repo.id)
.fetch_optional(executor)
.await?)
}
4 changes: 2 additions & 2 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Repository {
let repo: Option<Repository> = sqlx::query_as::<_, Repository>(
"select * from repositories where owner = $1 and lower(name) = lower($2) limit 1",
)
.bind(&user_id)
.bind(user_id)
.bind(repo_name)
.fetch_optional(executor)
.await
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Repository {
cross join \
(select username from users where id = $1 limit 1) B",
)
.bind(&self.owner)
.bind(self.owner)
.fetch_one(executor)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion src/routes/admin/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) async fn dashboard(

let (latest_repo_username_option,): (String,) =
sqlx::query_as("select username from users where id = $1 limit 1")
.bind(&latest_repo.owner)
.bind(latest_repo.owner)
.fetch_one(&mut transaction)
.await?;

Expand Down
6 changes: 3 additions & 3 deletions src/routes/repository/api/create_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub(crate) async fn create(
}

let (exists,): (bool,) = sqlx::query_as("select exists(select 1 from repositories where owner = $1 and lower(name) = lower($2) limit 1)")
.bind(&user.id)
.bind(&name)
.bind(user.id)
.bind(name)
.fetch_one(&mut transaction)
.await?;

Expand All @@ -62,7 +62,7 @@ pub(crate) async fn create(
}

let repo: Repository = sqlx::query_as::<_, Repository>("insert into repositories (owner, name, description, visibility) values ($1, $2, $3, $4) returning *")
.bind(&user.id)
.bind(user.id)
.bind(name)
.bind(description)
.bind(&body.visibility)
Expand Down
6 changes: 3 additions & 3 deletions src/routes/repository/api/fork_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) async fn create_fork(
}

let (exists,): (bool,) = sqlx::query_as("select exists(select 1 from repositories where owner = $1 and lower(name) = lower($2) limit 1)")
.bind(&user.id)
.bind(user.id)
.bind(&repo.name)
.fetch_one(&mut transaction)
.await?;
Expand All @@ -88,11 +88,11 @@ pub(crate) async fn create_fork(
}

let new_repo = sqlx::query_as::<_, Repository>("insert into repositories (owner, name, description, visibility, forked_from) values ($1, $2, $3, $4, $5) returning *")
.bind(&user.id)
.bind(user.id)
.bind(&repo.name)
.bind(&repo.description)
.bind(&repo.visibility)
.bind(&repo.id)
.bind(repo.id)
.fetch_one(&mut transaction)
.await?;

Expand Down
6 changes: 3 additions & 3 deletions src/routes/repository/api/import_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ pub(crate) async fn import(
}

let (exists,): (bool,) = sqlx::query_as("select exists(select 1 from repositories where owner = $1 and lower(name) = lower($2) limit 1)")
.bind(&user.id)
.bind(&name)
.bind(user.id)
.bind(name)
.fetch_one(&mut transaction)
.await?;

Expand All @@ -78,7 +78,7 @@ pub(crate) async fn import(
}

let repo: Repository = sqlx::query_as::<_, Repository>("insert into repositories (owner, name, description, visibility) values ($1, $2, $3, $4) returning *")
.bind(&user.id)
.bind(user.id)
.bind(name)
.bind(description)
.bind(&body.visibility)
Expand Down
11 changes: 1 addition & 10 deletions src/routes/repository/blobs/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use git_repository::objs::tree::EntryMode;
use git_repository::objs::{Tree, TreeRef};
use git_repository::odb::pack::FindExt;
use git_repository::odb::Store;
use git_repository::refs::file::loose::Reference;
use git_repository::Repository as GitoxideRepository;
use gitarena_macros::route;
use magic::Cookie;
use sqlx::PgPool;
Expand Down Expand Up @@ -60,10 +58,8 @@ pub(crate) async fn view_blob(
)
.await?;
let (name, content, mode) = recursively_visit_blob_content(
&branch.reference,
tree_ref,
uri.blob.as_str(),
&gitoxide_repo,
store.clone(),
&mut blob_buffer,
)
Expand Down Expand Up @@ -150,10 +146,8 @@ pub(crate) async fn view_raw_blob(
)
.await?;
let (_, content, _) = recursively_visit_blob_content(
&branch.reference,
tree_ref,
uri.blob.as_str(),
&gitoxide_repo,
store.clone(),
&mut blob_buffer,
)
Expand All @@ -177,10 +171,8 @@ pub(crate) async fn view_raw_blob(

#[async_recursion(?Send)]
async fn recursively_visit_blob_content<'a>(
reference: &Reference,
tree_ref: TreeRef<'a>,
path: &str,
repo: &'a GitoxideRepository,
store: Arc<Store>,
buffer: &'a mut Vec<u8>,
) -> Result<(String, String, EntryMode)> {
Expand All @@ -207,8 +199,7 @@ async fn recursively_visit_blob_content<'a>(
.map(|(tree, _)| tree)?;
let mut buffer = Vec::<u8>::new();

recursively_visit_blob_content(reference, tree_ref, remaining, repo, store, &mut buffer)
.await
recursively_visit_blob_content(tree_ref, remaining, store, &mut buffer).await
}
None => {
if entry.mode != EntryMode::Blob && entry.mode != EntryMode::BlobExecutable {
Expand Down
23 changes: 6 additions & 17 deletions src/routes/repository/blobs/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use git_repository::objs::tree::EntryMode;
use git_repository::objs::{Tree, TreeRef};
use git_repository::odb::pack::FindExt;
use git_repository::odb::Store;
use git_repository::refs::file::loose::Reference;
use git_repository::{ObjectId, Repository as GitoxideRepository};
use git_repository::ObjectId;
use gitarena_macros::route;
use sqlx::PgPool;
use tera::Context;
Expand Down Expand Up @@ -61,20 +60,13 @@ pub(crate) async fn view_dir(
&mut tree_ref_buffer,
)
.await?;
let tree = recursively_visit_tree(
&branch.reference,
tree_ref,
path.as_str(),
&gitoxide_repo,
store.clone(),
&mut tree_buffer,
)
.await?;
let tree =
recursively_visit_tree(tree_ref, path.as_str(), store.clone(), &mut tree_buffer).await?;

let (issues_count,): (i64,) = sqlx::query_as(
"select count(*) from issues where repo = $1 and closed = false and confidential = false",
)
.bind(&repo.id)
.bind(repo.id)
.fetch_one(&mut transaction)
.await?;

Expand All @@ -92,8 +84,7 @@ pub(crate) async fn view_dir(

// Should be generalized so we don't have this code twice but can re-use it in repo_view and here in directory

let mut files = Vec::<RepoFile>::new();
files.reserve(tree.entries.len().min(1000));
let mut files = Vec::<RepoFile>::with_capacity(tree.entries.len().min(1000));

for entry in tree.entries.iter().take(1000) {
let name = entry.filename.to_str().unwrap_or("Invalid file name");
Expand Down Expand Up @@ -194,10 +185,8 @@ pub(crate) async fn view_dir(

#[async_recursion(?Send)]
async fn recursively_visit_tree<'a>(
reference: &Reference,
tree_ref: TreeRef<'a>,
path: &str,
repo: &'a GitoxideRepository,
store: Arc<Store>,
buffer: &'a mut Vec<u8>,
) -> Result<Tree> {
Expand All @@ -221,7 +210,7 @@ async fn recursively_visit_tree<'a>(
.map(|(tree, _)| tree)?;
let mut buffer = Vec::<u8>::new();

recursively_visit_tree(reference, tree_ref, remaining, repo, store, &mut buffer).await
recursively_visit_tree(tree_ref, remaining, store, &mut buffer).await
}
None => Ok(tree),
}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/repository/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ pub(crate) async fn commits(

let chrono_time = commit.time().try_as_chrono()?;
let chrono_date = chrono_time.date();
let chrono_time_only_date = chrono_date.and_hms(0, 0, 0);
let chrono_time_only_date = chrono_date.and_hms_opt(0, 0, 0);

commits.push(GitCommit {
oid: format!("{}", commit.id()),
message: commit.message().unwrap_or_default().to_owned(),
time: commit.time().seconds(),
date: Some(chrono_time_only_date),
date: chrono_time_only_date,
author_name: name,
author_uid: uid,
author_email: email,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/repository/git/git_receive_pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub(crate) async fn git_receive_pack(

// Let Git collect garbage to optimize repo size
let command = Command::new("git")
.args(&["gc", "--auto", "--quiet"])
.args(["gc", "--auto", "--quiet"])
.current_dir(repo_dir)
.kill_on_drop(true)
.stdout(Stdio::null())
Expand Down Expand Up @@ -219,7 +219,7 @@ pub(crate) async fn git_receive_pack(

sqlx::query("update repositories set license = $1 where id = $2")
.bind(&repo.license)
.bind(&repo.id)
.bind(repo.id)
.execute(&mut transaction)
.await?;

Expand Down
4 changes: 2 additions & 2 deletions src/routes/repository/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) async fn all_issues(
)
.as_str(),
)
.bind(&repo.id)
.bind(repo.id)
.fetch_all(&mut transaction)
.await?;

Expand All @@ -49,7 +49,7 @@ pub(crate) async fn all_issues(
for issue in issues.iter() {
let (username,): (String,) =
sqlx::query_as("select username from users where id = $1 limit 1")
.bind(&issue.author)
.bind(issue.author)
.fetch_one(&mut transaction)
.await?;

Expand Down
5 changes: 2 additions & 3 deletions src/routes/repository/repo_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn render(
let (issues_count,): (i64,) = sqlx::query_as(
"select count(*) from issues where repo = $1 and closed = false and confidential = false",
)
.bind(&repo.id)
.bind(repo.id)
.fetch_one(&mut transaction)
.await?;

Expand Down Expand Up @@ -80,8 +80,7 @@ async fn render(
let tree = repo_files_at_ref(&loose_ref, store.clone(), &gitoxide_repo, &mut buffer).await?;
let tree = Tree::from(tree);

let mut files = Vec::<RepoFile>::new();
files.reserve(tree.entries.len().min(1000));
let mut files = Vec::<RepoFile>::with_capacity(tree.entries.len().min(1000));

for entry in tree.entries.iter().take(1000) {
let name = entry.filename.to_str().unwrap_or("Invalid file name");
Expand Down
4 changes: 2 additions & 2 deletions src/routes/user/api/add_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ pub(crate) async fn put_ssh_key(
}

let key = sqlx::query_as::<_, SshKey>("insert into ssh_keys (owner, title, fingerprint, algorithm, key, expires_at) values ($1, $2, $3, $4, $5, $6) returning *")
.bind(&user.id)
.bind(user.id)
.bind(key_title)
.bind(fingerprint.as_str())
.bind(algorithm)
.bind(public_key.data().as_slice())
.bind(&body.expiration_date)
.bind(body.expiration_date)
.fetch_one(&mut transaction)
.await?;

Expand Down
4 changes: 2 additions & 2 deletions src/routes/user/avatar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ pub(crate) async fn get_avatar(
let path_str = format!("{}/default.jpg", avatars_dir);
let path = Path::new(path_str.as_str());

Ok(send_image(path, &request)
send_image(path, &request)
.await
.context("Failed to read default avatar file")?)
.context("Failed to read default avatar file")
}

#[route("/api/avatar", method = "PUT", err = "text")]
Expand Down
Loading