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
4 changes: 3 additions & 1 deletion docs/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ fresh bare remotes, clients, cache directories, and a temporary GPG home. Git
auto-GC, maintenance, and receive auto-GC were disabled. The bare receivers
used `receive.unpackLimit=0`; the carrier receiver also used
`attr.tree=refs/heads/git-remote-e2ee`, so it could read the committed
`e2ee/** -delta` attribute. The E2EE push and returning-client caches were
`e2ee/** -delta` attribute. (That run used an earlier layout; the current
layout, format 6, uses branch `main` and `* -delta` at the branch root, so
reproduce with `attr.tree=refs/heads/main`.) The E2EE push and returning-client caches were
isolated per round under the temporary benchmark directory. Each tiny commit
replaced one line in Godot's tracked README and was pushed and fetched before
the next. See `scripts/benchmark-git-backend.sh` for the complete harness.
Expand Down
8 changes: 4 additions & 4 deletions scripts/benchmark-comparison.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ tree_logical_bytes() {
object_snapshot() {
local root=$1
local object digest
find "$root/objects" -type f -print | LC_ALL=C sort | while IFS= read -r object; do
find "$root/packs" -type f -print | LC_ALL=C sort | while IFS= read -r object; do
if [[ $time_style == bsd ]]; then
digest=$(shasum -a 256 "$object" | awk '{print $1}')
else
Expand Down Expand Up @@ -291,7 +291,7 @@ repository_root=$(sed -n 's/^[[:space:]]*"repository_root": "\([^"]*\)",$/\1/p'
--output "$work/new-user.key.json" >/dev/null
"$git_e2ee" device-export --key "$work/new-user.key.json" \
--output "$work/new-user.public.json" >/dev/null
object_snapshot "$work/e2ee-storage" >"$work/objects-before-device-add.sha256"
object_snapshot "$work/e2ee-storage" >"$work/packs-before-device-add.sha256"
run_phase add_user e2ee device-add "$work/e2ee-storage" "$work/e2ee-new-client" \
"$git_e2ee" device-add "e2ee::dir:$work/e2ee-storage" "$work/new-user.public.json" \
--label new-user --key "$work/repository.key.json"
Expand All @@ -312,8 +312,8 @@ if (( total_readers > 2 )); then
active_reader_key=$reader_key
done
fi
object_snapshot "$work/e2ee-storage" >"$work/objects-after-device-add.sha256"
cmp "$work/objects-before-device-add.sha256" "$work/objects-after-device-add.sha256"
object_snapshot "$work/e2ee-storage" >"$work/packs-after-device-add.sha256"
cmp "$work/packs-before-device-add.sha256" "$work/packs-after-device-add.sha256"
run_phase add_user e2ee fetch-new-user "$work/e2ee-storage" \
"$work/e2ee-new-client" \
"$git_e2ee" fetch --storage "$work/e2ee-storage" \
Expand Down
4 changes: 1 addition & 3 deletions scripts/benchmark-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ final_storage_logical=$(tree_logical_bytes "$work/storage")
final_pack_logical=$(tree_logical_bytes "$work/storage/packs")
final_pack_files=$(find "$work/storage/packs" -type f | wc -l | tr -d ' ')
manifest_files=$(find "$work/storage/manifests" -type f | wc -l | tr -d ' ')
policy_files=$(find "$work/storage/policies" -type f | wc -l | tr -d ' ')
crate_sha=$(git -C "$project_root" rev-parse HEAD)
if [[ -n $(git -C "$project_root" status --porcelain=v1) ]]; then
crate_dirty=true
Expand Down Expand Up @@ -214,8 +213,7 @@ cat >"$results_dir/summary.json" <<JSON
"pack_logical_after_incremental_push_bytes": $final_pack_logical,
"pack_files_after_initial_push": $initial_pack_files,
"pack_files_after_incremental_push": $final_pack_files,
"manifest_files": $manifest_files,
"policy_files": $policy_files
"manifest_files": $manifest_files
}
JSON

Expand Down
30 changes: 22 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ fn main() -> Result<()> {
if in_repository && git_config(&format!("remote.{name}.url"), false)?.is_some() {
bail!("Git remote {name} already exists; choose another name with --name")
}
let mut created_key = None;
let key = match key {
Some(path) if path.exists() => path,
requested => {
Expand All @@ -255,18 +256,31 @@ fn main() -> Result<()> {
};
generated.write_new(&path)?;
println!("created key {} (administrator)", path.display());
created_key = Some(path.clone());
path
}
};
let target = Target {
storage,
key: std::path::absolute(key)?,
let initialized = (|| -> Result<Target> {
let target = Target {
storage,
key: std::path::absolute(key)?,
};
let pin = admin_pin_path(&target.key)?;
with_repository!(&target, |repository| {
repository.initialize(&label)?;
repository.pin_admin_state(&pin)?;
});
Ok(target)
})();
let target = match initialized {
Ok(target) => target,
Err(error) => {
if let Some(path) = created_key {
let _ = std::fs::remove_file(path);
}
return Err(error);
}
};
let pin = admin_pin_path(&target.key)?;
with_repository!(&target, |repository| {
repository.initialize(&label)?;
repository.pin_admin_state(&pin)?;
});
println!("initialized {}", target.storage);
if in_repository {
run_git(&["remote", "add", &name, &target.storage.to_string()])?;
Expand Down
14 changes: 14 additions & 0 deletions tests/cli_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ fn init_refuses_an_existing_remote_before_creating_anything() {
sandbox.git(&repo, &["push", "-q", "private", "main"]);
}

#[test]
fn failed_init_removes_the_key_it_created() {
let sandbox = Sandbox::new();
let url = format!("e2ee::dir:{}", sandbox.path().join("storage").display());

success(&sandbox.e2ee(sandbox.path(), &["init", &url]));
assert_eq!(sandbox.keys().len(), 1);

let second = sandbox.e2ee(sandbox.path(), &["init", &url]);
assert!(!second.status.success());
let keys = sandbox.keys();
assert_eq!(keys.len(), 1, "{keys:?}");
}

#[test]
fn verify_takes_a_carrier_url_outside_a_repository() {
let sandbox = Sandbox::new();
Expand Down
Loading