Skip to content

Commit

Permalink
frame for instantiation of multi-pack-index (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 20, 2021
1 parent 0032223 commit 5e085ec
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git-pack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ pub use find_traits::{Find, FindExt};

///
pub mod index;
///
pub mod multi_index;
39 changes: 39 additions & 0 deletions git-pack/src/multi_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#![allow(missing_docs, unused)]
use filebuffer::FileBuffer;

/// A representation of an index file for multiple packs at the same time, typically stored in a file
/// named 'multi-pack-index'.
pub struct File {
data: FileBuffer,
path: std::path::PathBuf,
}

///
pub mod init {
use crate::multi_index::File;
use std::convert::TryFrom;
use std::path::Path;

mod error {
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Io(#[from] std::io::Error),
}
}
pub use error::Error;

impl File {
pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> {
Self::try_from(path.as_ref())
}
}

impl TryFrom<&Path> for File {
type Error = Error;

fn try_from(path: &Path) -> Result<Self, Self::Error> {
todo!()
}
}
}
39 changes: 39 additions & 0 deletions git-pack/tests/fixtures/make_pack_gen_repo_multi_index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -eu -o pipefail

git init -q
git config commit.gpgsign false

function write_files() {
local base_dir=${1:?directory to write them into}
local num_files=${2:?amount of files to write}
local nonce=${3:?something to make files more unique}

mkdir -p "$base_dir"
for file_id in $(seq -w "$num_files"); do
seq "$file_id" > "$base_dir/$file_id"
echo "$nonce" >> "$base_dir/$file_id"
done
}

dirs=(. a b c a/a a/b a/c a/a/a)
rounds=15

git checkout -q -b main
for round in $(seq $rounds); do
dir_index=$(( round % ${#dirs[@]} ))
num_files=$(( (round + 1) * 6 ))
write_files "${dirs[$dir_index]}" $num_files "$round"
git add .
git commit -qm "$round $num_files"
done

echo hello world > referee
git add referee
git commit -qm "to be forgotten"
git tag -m "a tag object" referrer
git reset --hard HEAD~1

# speed up all access by creating a pack
git gc --aggressive
git multi-pack-index write
1 change: 1 addition & 0 deletions git-pack/tests/pack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ mod bundle;
mod data;
mod index;
mod iter;
mod multi_index;
8 changes: 8 additions & 0 deletions git-pack/tests/pack/multi_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[test]
#[ignore]
fn access() {
let path = git_testtools::scripted_fixture_repo_read_only("make_pack_gen_repo_multi_index.sh")
.unwrap()
.join(".git/objects/pack/multi-pack-index");
let _file = git_pack::multi_index::File::at(path).unwrap();
}

0 comments on commit 5e085ec

Please sign in to comment.