Skip to content

Commit

Permalink
feat: Ability to steer long running filter processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 28, 2023
1 parent f38351d commit 2376a01
Show file tree
Hide file tree
Showing 10 changed files with 1,021 additions and 210 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gix-filter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gix-object = { version = "^0.31.0", path = "../gix-object" }
gix-command = { version = "^0.2.6", path = "../gix-command" }
gix-quote = { version = "^0.4.5", path = "../gix-quote" }
gix-path = { version = "^0.8.2", path = "../gix-path" }
gix-packetline = { package = "gix-packetline-blocking", version = "^0.16.3", path = "../gix-packetline-blocking" }

encoding_rs = "0.8.32"
bstr = { version = "1.5.0", default-features = false, features = ["std"] }
Expand Down
58 changes: 57 additions & 1 deletion gix-filter/examples/ident.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bstr::io::BufReadExt;
use std::io::{stdin, stdout, Write};
use bstr::{ByteSlice, ByteVec};
use gix_filter::driver::process;
use std::io::{stdin, stdout, Read, Write};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut args = std::env::args();
Expand All @@ -11,6 +13,60 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

match sub_command.as_str() {
"process" => {
let mut srv = gix_filter::driver::process::Server::handshake(
stdin(),
stdout(),
"git-filter",
|versions| versions.contains(&2).then_some(2),
&["clean", "smudge"],
)?;

loop {
let mut request = srv.next_request()?;
let needs_failure = request
.meta
.iter()
.find_map(|(key, value)| (key == "pathname").then_some(value))
.map_or(false, |path| path.ends_with(b"fail"));
if needs_failure {
panic!("process failure requested: {:?}", request.meta);
}
match request.command.as_str() {
"clean" => {
let mut buf = Vec::new();
request.as_read().read_to_end(&mut buf)?;
request.write_status(process::Status::success())?;

let mut lines = Vec::new();
for mut line in buf.lines_with_terminator() {
if line.starts_with(b"\t") {
line = &line[1..];
}
lines.push_str(line);
}
request.as_write().write_all(&lines)?;
request.write_status(process::Status::Previous)?;
}
"smudge" => {
let mut buf = Vec::new();
request.as_read().read_to_end(&mut buf)?;
request.write_status(process::Status::success())?;

let mut lines = Vec::new();
for line in buf.lines_with_terminator() {
if !line.starts_with(b"\t") {
lines.push(b'\t');
}
lines.push_str(line);
}
request.as_write().write_all(&lines)?;
request.write_status(process::Status::Previous)?;
}
unknown => panic!("Unknown capability requested: {unknown}"),
}
}
}
"clean" => {
let mut stdin = stdin().lock();
let mut stdout = stdout().lock();
Expand Down
150 changes: 0 additions & 150 deletions gix-filter/src/driver.rs

This file was deleted.

Loading

0 comments on commit 2376a01

Please sign in to comment.