filelog/filelog.rs
1//! Example of the `p4 filelog` command using the builder pattern.
2//!
3//! `p4 filelog` prints detailed information about the revisions of files and
4//! requires at least one file or file pattern. Two orthogonal dimensions are
5//! tracked at compile time by the command's type parameters:
6//!
7//! - the description output: [`FileLog::full_description`](perforce_cli::cmd::filelog::FileLog::full_description)
8//! (`-l`) or [`FileLog::truncated_description`](perforce_cli::cmd::filelog::FileLog::truncated_description)
9//! (`-L`)
10//! - the content history mode: [`FileLog::content_history`](perforce_cli::cmd::filelog::FileLog::content_history)
11//! (`-h`), which unlocks [`FileLog::skip_promoted_tasks`](perforce_cli::cmd::filelog::FileLog::skip_promoted_tasks)
12//! (`-p`)
13//!
14//! Run with:
15//!
16//! ```text
17//! cargo run --example filelog
18//! ```
19
20use perforce_cli::P4Cli;
21use perforce_cli::spawn::{OutputExt1, ParameterizedSpawn};
22use std::ffi::OsStr;
23
24fn main() -> std::io::Result<()> {
25 let p4 = P4Cli::default();
26
27 // Revision history for every file under //depot/project: follow the file
28 // history across branches (`-i`), display the time as well as the date
29 // (`-t`), and list only the first 10 changes per file (`-m 10`).
30 let mut filelog = p4
31 .filelog()
32 .follow_branches(true)
33 .include_time(true)
34 .limit(10);
35
36 let files = [OsStr::new("//depot/project/...")];
37 let output = filelog.output(&files)?;
38 println!("{}", String::from_utf8_lossy(&output.stdout));
39
40 // Long output: `full_description()` transitions the command into the
41 // `FullDescription` state (`-l`), printing the full text of each
42 // changelist description. A revision range limits the listed revisions,
43 // e.g. changelists 100 through 120.
44 let mut long_log = p4.filelog().full_description();
45
46 let output = long_log.output(&["//depot/project/main.c@100,@120"])?;
47 println!("{}", String::from_utf8_lossy(&output.stdout));
48
49 // Content history: `content_history()` transitions the command into the
50 // `DisplayContentHistory` state (`-h`), which unlocks `-p` to skip the
51 // content of promoted task streams. Only revisions submitted at
52 // changelist 4321 are displayed (`-c 4321`).
53 let mut history = p4
54 .filelog()
55 .content_history()
56 .skip_promoted_tasks(true)
57 .changelist("4321");
58
59 let mut child = history.spawn_with((&files,))?;
60 child.wait()?;
61
62 Ok(())
63}