#[deny(clippy::pedanic)]
Diff
Cargo.lock | 2 +-
Cargo.toml | 2 +-
src/main.rs | 21 ++++++++++++++-------
src/metadata.rs | 12 ++++++++----
src/util.rs | 2 ++
src/git_command_handlers/fetch.rs | 4 ++--
src/git_command_handlers/ls_refs.rs | 2 +-
src/protocol/high_level.rs | 2 +-
src/protocol/low_level.rs | 10 +++++-----
src/protocol/packet_line.rs | 2 +-
src/providers/gitlab.rs | 9 ++++++---
11 files changed, 38 insertions(+), 30 deletions(-)
@@ -510,7 +510,7 @@
]
[[package]]
name = "git-server"
name = "gitlab-cargo-shim"
version = "0.1.0"
dependencies = [
"anyhow",
@@ -1,5 +1,5 @@
[package]
name = "git-server"
name = "gitlab-cargo-shim"
version = "0.1.0"
edition = "2021"
@@ -1,3 +1,6 @@
#![deny(clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]
pub mod git_command_handlers;
pub mod metadata;
pub mod protocol;
@@ -6,6 +9,7 @@
use crate::metadata::CargoIndexCrateMetadata;
use crate::protocol::low_level::{HashOutput, PackFileEntry};
use crate::providers::Group;
use crate::util::get_crate_folder;
use crate::{
protocol::{
@@ -27,7 +31,6 @@
use thrussh_keys::key::PublicKey;
use tokio_util::{codec::Decoder, codec::Encoder as CodecEncoder};
use tracing::error;
use crate::providers::Group;
const AGENT: &str = concat!(
"agent=",
@@ -56,7 +59,7 @@
"127.0.0.1:2210",
Server {
gitlab,
metadata_cache: Arc::new(Default::default()),
metadata_cache: MetadataCache::default(),
},
)
.await?;
@@ -221,7 +224,7 @@
let meta = self
.fetch_metadata(&crate_path, &checksum, &crate_name, &version)
.fetch_metadata(crate_path, checksum, crate_name, version)
.await?;
buffer.extend_from_slice(&serde_json::to_vec(&*meta).unwrap());
@@ -229,7 +232,7 @@
}
packfile.insert(
get_crate_folder(&crate_name),
get_crate_folder(crate_name),
crate_name.to_string(),
buffer.split().freeze(),
)?;
@@ -320,7 +323,7 @@
&mut self,
&mut session,
channel,
frame.metadata,
&frame.metadata,
&commit_hash,
)?;
}
@@ -329,8 +332,8 @@
&mut self,
&mut session,
channel,
frame.metadata,
packfile_entries.clone(),
&frame.metadata,
&packfile_entries,
)?;
}
v => {
@@ -416,9 +419,7 @@
if let Some(group) = args.next().filter(|v| v.as_str() != "/") {
let user = self.user()?;
let group = group
.trim_start_matches('/')
.trim_end_matches('/');
let group = group.trim_start_matches('/').trim_end_matches('/');
match self.gitlab.clone().fetch_group(group, user).await {
Ok(v) => self.group = Some(v),
@@ -1,10 +1,13 @@
#![allow(clippy::module_name_repetitions)]
use cargo_metadata::Package;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[must_use]
pub fn transform(
metadata: cargo_metadata::Metadata,
crate_name: &str,
@@ -29,10 +32,9 @@
default_features: v.uses_default_features,
target: v.target.map(|v| v.to_string()),
kind: v.kind.to_string(),
registry: Some(
v.registry
.unwrap_or("https://github.com/rust-lang/crates.io-index.git".to_string()),
),
registry: Some(v.registry.unwrap_or_else(|| {
"https://github.com/rust-lang/crates.io-index.git".to_string()
})),
package: v.rename,
})
.collect(),
@@ -1,3 +1,4 @@
#[must_use]
pub fn format_fingerprint(fingerprint: &str) -> String {
format!("SHA256:{}", fingerprint)
}
@@ -6,6 +7,7 @@
#[must_use]
pub fn get_crate_folder(crate_name: &str) -> Vec<String> {
let mut folders = Vec::new();
@@ -13,8 +13,8 @@
handle: &mut Handler<U>,
session: &mut Session,
channel: ChannelId,
metadata: Vec<Bytes>,
packfile_entries: Vec<PackFileEntry>,
metadata: &[Bytes],
packfile_entries: &[PackFileEntry],
) -> Result<(), anyhow::Error> {
@@ -16,7 +16,7 @@
handle: &mut Handler<U>,
session: &mut Session,
channel: ChannelId,
_metadata: Vec<Bytes>,
_metadata: &[Bytes],
commit_hash: &HashOutput,
) -> Result<(), anyhow::Error> {
let commit_hash = hex::encode(&commit_hash);
@@ -75,7 +75,7 @@
Ok(())
}
pub fn commit(
@@ -11,13 +11,13 @@
pub struct PackFile {
entries: Vec<PackFileEntry>,
pub struct PackFile<'a> {
entries: &'a [PackFileEntry],
}
impl PackFile {
impl<'a> PackFile<'a> {
#[must_use]
pub fn new(entries: Vec<PackFileEntry>) -> Self {
pub fn new(entries: &'a [PackFileEntry]) -> Self {
Self { entries }
}
@@ -41,7 +41,7 @@
buf.put_u32(self.entries.len().try_into()?);
for entry in &self.entries {
for entry in self.entries {
entry.encode_to(&mut buf)?;
}
@@ -8,7 +8,7 @@
Data(&'a [u8]),
SidebandData(PackFile),
SidebandData(PackFile<'a>),
SidebandMsg(&'a [u8]),
@@ -1,3 +1,5 @@
#![allow(clippy::module_name_repetitions)]
use crate::providers::{Group, Release, User};
use async_trait::async_trait;
use futures::{stream::FuturesUnordered, StreamExt, TryStreamExt};
@@ -185,6 +187,7 @@
package_files
.into_iter()
.filter_map(|package_file| {
#[allow(clippy::case_sensitive_file_extension_comparisons)]
if package_file.file_name.ends_with(".crate") {
if package_file.file_name
== format!("{}-{}.crate", release.name, release.version)
@@ -215,7 +218,7 @@
})
.collect(),
))
}))
}));
}
}
@@ -260,8 +263,7 @@
Err(anyhow::Error::msg(
resp.message
.or(resp.error)
.map(Cow::Owned)
.unwrap_or_else(|| Cow::Borrowed("unknown error")),
.map_or_else(|| Cow::Borrowed("unknown error"), Cow::Owned)
))
}
}
@@ -294,6 +296,7 @@
}
impl GitlabCratePath {
#[must_use]
pub fn metadata_uri(&self, version: &str) -> String {
format!(
"/projects/{}/packages/generic/{}/{version}/metadata.json",