Sort tree before inserting into packfile
Diff
src/main.rs | 11 ++++++++++-
src/git_command_handlers/ls_refs.rs | 2 +-
src/protocol/high_level.rs | 7 +++++++
src/protocol/low_level.rs | 1 +
4 files changed, 17 insertions(+), 4 deletions(-)
@@ -24,6 +24,7 @@
use bytes::{BufMut, Bytes, BytesMut};
use clap::Parser;
use futures::Future;
use indexmap::IndexMap;
use parking_lot::RwLock;
use std::{
borrow::Cow, collections::HashMap, fmt::Write, net::SocketAddr, net::SocketAddrV6, pin::Pin,
@@ -35,7 +36,7 @@
};
use thrussh_keys::key::PublicKey;
use tokio_util::{codec::Decoder, codec::Encoder as CodecEncoder};
use tracing::{error, info, info_span, Instrument, Span};
use tracing::{debug, error, info, info_span, Instrument, Span};
use uuid::Uuid;
const AGENT: &str = concat!(
@@ -110,6 +111,8 @@
struct Server<U: UserProvider + PackageProvider + Send + Sync + 'static> {
gitlab: Arc<U>,
metadata_cache: MetadataCache,
}
@@ -184,11 +187,11 @@
async fn fetch_releases_by_crate(
&self,
) -> anyhow::Result<HashMap<(U::CratePath, String), Vec<Release>>> {
) -> anyhow::Result<IndexMap<(U::CratePath, String), Vec<Release>>> {
let user = self.user()?;
let group = self.group()?;
let mut res = HashMap::new();
let mut res = IndexMap::new();
for (path, release) in Arc::clone(&self.gitlab)
.fetch_releases_for_group(group, user)
@@ -296,6 +299,8 @@
for release in releases {
let checksum = &release.checksum;
let version = &release.version;
debug!("Fetching metadata for {}-{}", crate_name, version);
@@ -22,7 +22,7 @@
let commit_hash = hex::encode(&commit_hash);
handle.write(PktLine::Data(
format!("{} HEAD symref-target:refs/heads/master\n", commit_hash).as_bytes(),
format!("{} HEAD symref-target:refs/heads/master", commit_hash).as_bytes(),
))?;
handle.write(PktLine::Flush)?;
handle.flush(session, channel);
@@ -132,11 +132,13 @@
tree.push(match *item {
TreeItem::Blob(hash) => LowLevelTreeItem {
kind: TreeItemKind::File,
sort_name: name.clone(),
name,
hash,
},
TreeItem::Tree(tree) => LowLevelTreeItem {
kind: TreeItemKind::Directory,
sort_name: format!("{}/", name),
name,
@@ -145,6 +147,11 @@
},
});
}
tree.sort_unstable_by(|a, b| a.sort_name.cmp(&b.sort_name));
@@ -143,6 +143,7 @@
pub kind: TreeItemKind,
pub name: String,
pub hash: HashOutput,
pub sort_name: String,
}