Streams: list / switch / merge down / copy up

- Tools -> Streams: list server streams, switch the workspace to a stream,
  merge down from parent / copy up to parent (into a pending changelist)
- Backend p4 streams, client -s -S, merge/copy -S

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Bonchellon
2026-07-08 11:56:21 +03:00
parent fdaf126c00
commit 7092c9d1dc
5 changed files with 126 additions and 1 deletions

View File

@ -1867,6 +1867,52 @@ async fn p4_latest_change(state: State<'_, AppState>, scope: String) -> Result<V
Ok(v.into_iter().next().unwrap_or(Value::Null))
}
/// List streams on the server.
#[tauri::command]
async fn p4_streams(state: State<'_, AppState>) -> Result<Vec<Value>, String> {
let conn = current(&state)?;
run_json(&conn, &["streams", "-m", "300"])
}
/// Switch the current workspace to a stream (`p4 client -s -S <stream>`), then
/// return the refreshed `p4 info`. The workspace View is rebuilt from the stream.
#[tauri::command]
async fn p4_switch_stream(state: State<'_, AppState>, stream: String) -> Result<Value, String> {
let conn = current(&state)?;
let stream = stream.trim();
if stream.is_empty() {
return Err("No stream".into());
}
run_text(&conn, &["client", "-s", "-S", stream])?;
let info = run_json(&conn, &["info"])?;
let info = info.into_iter().next().unwrap_or(Value::Null);
let root = info.get("clientRoot").and_then(|r| r.as_str()).unwrap_or("").to_string();
state.0.lock().unwrap_or_else(|e| e.into_inner()).root = root;
Ok(info)
}
/// Stream integration: direction "down" merges from the parent into the stream
/// (merge down), "up" copies the stream to its parent (copy up). Opens the work
/// into a fresh changelist; resolve (if needed) and submit as usual.
#[tauri::command]
async fn p4_stream_integ(state: State<'_, AppState>, stream: String, direction: String) -> Result<String, String> {
let conn = current(&state)?;
let stream = stream.trim();
if stream.is_empty() {
return Err("No stream".into());
}
let (verb, extra, label) = if direction == "up" {
("copy", vec!["-r"], "copy up")
} else {
("merge", vec![], "merge down")
};
let cl = create_changelist(&conn, &format!("{label} {stream}"))?;
let mut args: Vec<&str> = vec![verb, "-S", stream, "-c", &cl];
args.extend(extra);
let out = run_text(&conn, &args).unwrap_or_default();
Ok(format!("CL {cl}\n{}", out.trim()))
}
/// Get a workspace (client) spec as editable text. An unknown name returns a
/// fresh template — used to create a new workspace.
#[tauri::command]
@ -2107,6 +2153,9 @@ pub fn run() {
p4_labels,
p4_label_tag,
p4_branch_op,
p4_streams,
p4_switch_stream,
p4_stream_integ,
p4_client_spec,
p4_client_save,
uasset_thumbnail,