Skip to content

Add --asset-dir to blame-copy-royal #2065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ jobs:
libssl-dev
libstdc++6:${{ matrix.runner-arch }} # To support external 64-bit Node.js for actions.
pkgconf
python3-minimal
)
dpkg --add-architecture ${{ matrix.runner-arch }}
apt-get update
Expand Down
Binary file not shown.
35 changes: 32 additions & 3 deletions gix/tests/fixtures/make_rev_spec_parse_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@ function baseline() {
}>> baseline.git
}

function loose-obj() {
# Read content from stdin, compute header and hash, write compressed object
script=$(cat <<'EOF'
import sys
import hashlib
import zlib
import os
type = sys.argv[1]
objects_dir = sys.argv[2]
content = sys.stdin.buffer.read()
header = f"{type} {len(content)}\0".encode()
full = header + content
sha1 = hashlib.sha1(full).hexdigest()
compressed = zlib.compress(full)
bucket = f"{objects_dir}/" + sha1[:2]
filename = sha1[2:]
os.makedirs(bucket, exist_ok=True)
with open(f"{bucket}/{filename}", "wb") as f:
f.write(compressed)
print(sha1)
EOF
)
python3 -c "$script" "$@"
}

# The contents of this file is based on https://github.com/git/git/blob/8168d5e9c23ed44ae3d604f392320d66556453c9/t/t1512-rev-parse-disambiguation.sh#L38
git init --bare blob.prefix
(
Expand All @@ -31,11 +60,11 @@ git init --bare blob.bad
cd blob.bad
# Both have the prefix "bad0"
# Maybe one day we have a test to see how disambiguation reporting deals with this.
echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally
echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally
echo xyzfaowcoh | loose-obj bad objects
echo xyzhjpyvwl | loose-obj bad objects
baseline "bad0"

echo 1bbfctrkc | git hash-object -t bad -w --stdin --literally
echo 1bbfctrkc | loose-obj bad objects
baseline "e328"
baseline "e328^{object}"
)
Expand Down
4 changes: 4 additions & 0 deletions tests/it/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::{
builder::{OsStringValueParser, TypedValueParser},
Arg, Command, Error,
};
use gix::bstr::BString;

#[derive(Debug, clap::Parser)]
#[clap(name = "it", about = "internal tools to help create test cases")]
Expand Down Expand Up @@ -51,6 +52,9 @@ pub enum Subcommands {
worktree_dir: PathBuf,
/// The directory into which to copy the files.
destination_dir: PathBuf,
/// The directory to place assets in.
#[clap(long)]
asset_dir: Option<BString>,
/// The file to extract the history for.
file: std::ffi::OsString,
/// Do not use `copy-royal` to obfuscate the content of blobs, but copy it verbatim.
Expand Down
34 changes: 20 additions & 14 deletions tests/it/src/commands/blame_copy_royal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(super) mod function {
dry_run: bool,
worktree_dir: &Path,
destination_dir: PathBuf,
asset_dir: Option<BString>,
file: &OsStr,
Options { verbatim }: Options,
) -> anyhow::Result<()> {
Expand Down Expand Up @@ -76,7 +77,8 @@ pub(super) mod function {
.blame_path
.expect("blame path to be present as `debug_track_path == true`");

let assets = destination_dir.join("assets");
let asset_dir = asset_dir.unwrap_or("assets".into());
let assets = destination_dir.join(asset_dir.to_os_str()?);
eprintln!("{prefix} create directory '{assets}'", assets = assets.display());

if !dry_run {
Expand Down Expand Up @@ -107,7 +109,7 @@ pub(super) mod function {
}
}

let mut blame_script = BlameScript::new(blame_infos, Options { verbatim });
let mut blame_script = BlameScript::new(blame_infos, asset_dir, Options { verbatim });
blame_script.generate()?;

let script_file = destination_dir.join("create-history.sh");
Expand All @@ -130,9 +132,9 @@ pub(super) mod function {
}

enum BlameScriptOperation {
InitRepository,
InitRepository(BString),
RemoveFile(String),
CommitFile(BString, ObjectId),
CommitFile(BString, BString, ObjectId),
CheckoutTag(ObjectId),
PrepareMerge(Vec<ObjectId>),
CreateTag(ObjectId),
Expand All @@ -141,15 +143,15 @@ pub(super) mod function {
impl Display for BlameScriptOperation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BlameScriptOperation::InitRepository => write!(
BlameScriptOperation::InitRepository(asset_dir) => write!(
f,
r"#!/bin/sh

set -e

git init
echo .gitignore >> .gitignore
echo assets/ >> .gitignore
echo {asset_dir}/ >> .gitignore
echo create-history.sh >> .gitignore

"
Expand All @@ -160,16 +162,15 @@ echo create-history.sh >> .gitignore
git rm {src}
"
),
BlameScriptOperation::CommitFile(src, commit_id) => {
BlameScriptOperation::CommitFile(asset_dir, src, commit_id) => {
writeln!(f, r"# make file {src} contain content at commit {commit_id}")?;
if let Some(pos) = src.rfind_byte(b'/') {
let dirname = src[..pos].as_bstr();
writeln!(f, "mkdir -p \"{dirname}\"")?;
}
write!(
f,
r"#
cp ./assets/{commit_id}.commit ./{src}
r"cp ./{asset_dir}/{commit_id}.commit ./{src}
git add {src}
git commit -m {commit_id}
"
Expand All @@ -194,17 +195,19 @@ git commit -m {commit_id}
blame_infos: Vec<BlamePathEntry>,
seen: BTreeSet<ObjectId>,
script: Vec<BlameScriptOperation>,
asset_dir: BString,
options: Options,
}

impl BlameScript {
fn new(blame_infos: Vec<BlamePathEntry>, options: Options) -> Self {
let script = vec![BlameScriptOperation::InitRepository];
fn new(blame_infos: Vec<BlamePathEntry>, asset_dir: BString, options: Options) -> Self {
let script = vec![BlameScriptOperation::InitRepository(asset_dir.clone())];

Self {
blame_infos,
seen: BTreeSet::default(),
script,
asset_dir,
options,
}
}
Expand Down Expand Up @@ -265,7 +268,8 @@ git commit -m {commit_id}
if let Some(delete_previous_file_operation) = delete_previous_file_operation {
self.script.push(delete_previous_file_operation);
}
self.script.push(BlameScriptOperation::CommitFile(src, commit_id));
self.script
.push(BlameScriptOperation::CommitFile(self.asset_dir.clone(), src, commit_id));
} else {
let ([first], rest) = parents.split_at(1) else {
unreachable!();
Expand All @@ -277,7 +281,8 @@ git commit -m {commit_id}
if let Some(delete_previous_file_operation) = delete_previous_file_operation {
self.script.push(delete_previous_file_operation);
}
self.script.push(BlameScriptOperation::CommitFile(src, commit_id));
self.script
.push(BlameScriptOperation::CommitFile(self.asset_dir.clone(), src, commit_id));
} else {
self.script.push(BlameScriptOperation::PrepareMerge(
rest.iter().map(|blame_path_entry| blame_path_entry.commit_id).collect(),
Expand All @@ -286,7 +291,8 @@ git commit -m {commit_id}
if let Some(delete_previous_file_operation) = delete_previous_file_operation {
self.script.push(delete_previous_file_operation);
}
self.script.push(BlameScriptOperation::CommitFile(src, commit_id));
self.script
.push(BlameScriptOperation::CommitFile(self.asset_dir.clone(), src, commit_id));
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/it/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ fn main() -> anyhow::Result<()> {
dry_run,
worktree_dir: worktree_root,
destination_dir,
asset_dir,
file,
verbatim,
} => commands::blame_copy_royal(
dry_run,
&worktree_root,
destination_dir,
asset_dir,
&file,
commands::blame_copy_royal::Options { verbatim },
),
Expand Down
Loading