pub struct Diff<M = Unselected> { /* private fields */ }Expand description
p4 [g-opts] diff [-doptions] [-f -t -Od] [-m max] [-soptions] [file[rev] ...]
p4 [g-opts] diff [-doptions] -As [streamname[@change]]
Diff utility for comparing workspace content to depot content. (For
comparing two depot paths, see p4 diff2.) Also for stream spec
comparison.
The M type parameter tracks the command mode at compile time. The
default Unselected state offers neither the workspace content options
nor -As; Self::force, Self::differing_only, and
Self::diff_nontext transition to the WorkspaceMode state, while
Self::stream_spec_mode transitions to the StreamSpecMode state.
Implementations§
Source§impl Diff<Unselected>
impl Diff<Unselected>
Sourcepub fn new(bin: impl Into<PathBuf>, global_opts: GlobalOpts) -> Self
pub fn new(bin: impl Into<PathBuf>, global_opts: GlobalOpts) -> Self
Creates a new p4 diff command.
bin is the path to the Perforce command-line executable.
Sourcepub fn force(self, v: bool) -> Diff<WorkspaceMode<Unselected>>
pub fn force(self, v: bool) -> Diff<WorkspaceMode<Unselected>>
§Description
-f
Force the diff (if no revision is specified, against the head
revision), even when the client file is not open for edit.
Transitions this command to the WorkspaceMode state with -f set
according to v.
Examples found in repository?
27fn main() -> std::io::Result<()> {
28 let p4 = P4Cli::default();
29
30 // Workspace mode: force a diff against head, use the unified format with
31 // whitespace-insensitive comparison, and limit output to the first 10
32 // files. `force(true)` transitions the command into `WorkspaceMode`, and
33 // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34 // `-soptions` is unavailable).
35 let mut diff = p4
36 .diff()
37 .force(true)
38 .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39 .limit(10);
40
41 let files = [OsStr::new("//depot/project/src/...")];
42 let output = diff.output_with(&files)?;
43 println!("{}", String::from_utf8_lossy(&output.stdout));
44
45 // Display mode: instead of full diffs, list only the unopened files that
46 // differ from the depot. `display_options` transitions `WorkspaceMode`
47 // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48 let mut list_changed = p4
49 .diff()
50 .force(true)
51 .display_options(DisplayOptions::UnopenedChanged);
52
53 let output = list_changed.output_with(&files)?;
54 println!("{}", String::from_utf8_lossy(&output.stdout));
55
56 // Stream-spec mode: diff a privately edited stream spec against the head
57 // version of another stream. `stream_spec_mode` transitions the command
58 // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59 let mut stream_diff = p4.diff().stream_spec_mode();
60 let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61 child.wait()?;
62
63 Ok(())
64}Sourcepub fn differing_only(self, v: bool) -> Diff<WorkspaceMode<Unselected>>
pub fn differing_only(self, v: bool) -> Diff<WorkspaceMode<Unselected>>
§Description
-Od
Limit output to only those files that differ.
Transitions this command to the WorkspaceMode state with -Od
set according to v.
Sourcepub fn diff_nontext(self, v: bool) -> Diff<WorkspaceMode<Unselected>>
pub fn diff_nontext(self, v: bool) -> Diff<WorkspaceMode<Unselected>>
§Description
-t
Diff the revisions even if the files are not of type text.
Transitions this command to the WorkspaceMode state with -t set
according to v.
Sourcepub fn stream_spec_mode(self) -> Diff<StreamSpecMode>
pub fn stream_spec_mode(self) -> Diff<StreamSpecMode>
§Description
-As
Allows two arbitrary stream specs to be diffed against each other. Can be used with a streamname, or with a streamname at a specific changelist number.
Although this option requires the user have at least the list access
to the stream path, it ignores any other entry in the protections
table, including any minus sign (-) that would otherwise block the
operation.
Transitions this command to the StreamSpecMode state. The stream
spec to compare against is passed as the argument of the spawned
command (ParameterizedSpawn::spawn_with); without one, the opened
stream spec is diffed against its have version.
Examples found in repository?
27fn main() -> std::io::Result<()> {
28 let p4 = P4Cli::default();
29
30 // Workspace mode: force a diff against head, use the unified format with
31 // whitespace-insensitive comparison, and limit output to the first 10
32 // files. `force(true)` transitions the command into `WorkspaceMode`, and
33 // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34 // `-soptions` is unavailable).
35 let mut diff = p4
36 .diff()
37 .force(true)
38 .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39 .limit(10);
40
41 let files = [OsStr::new("//depot/project/src/...")];
42 let output = diff.output_with(&files)?;
43 println!("{}", String::from_utf8_lossy(&output.stdout));
44
45 // Display mode: instead of full diffs, list only the unopened files that
46 // differ from the depot. `display_options` transitions `WorkspaceMode`
47 // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48 let mut list_changed = p4
49 .diff()
50 .force(true)
51 .display_options(DisplayOptions::UnopenedChanged);
52
53 let output = list_changed.output_with(&files)?;
54 println!("{}", String::from_utf8_lossy(&output.stdout));
55
56 // Stream-spec mode: diff a privately edited stream spec against the head
57 // version of another stream. `stream_spec_mode` transitions the command
58 // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59 let mut stream_diff = p4.diff().stream_spec_mode();
60 let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61 child.wait()?;
62
63 Ok(())
64}Source§impl<M> Diff<M>
impl<M> Diff<M>
Sourcepub fn get_diff_options(&self) -> Option<&DiffOptions>
pub fn get_diff_options(&self) -> Option<&DiffOptions>
Sourcepub fn set_diff_options(&mut self, v: impl Into<DiffOptions>) -> &mut Self
pub fn set_diff_options(&mut self, v: impl Into<DiffOptions>) -> &mut Self
Sourcepub fn diff_options(self, v: impl Into<DiffOptions>) -> Self
pub fn diff_options(self, v: impl Into<DiffOptions>) -> Self
Examples found in repository?
27fn main() -> std::io::Result<()> {
28 let p4 = P4Cli::default();
29
30 // Workspace mode: force a diff against head, use the unified format with
31 // whitespace-insensitive comparison, and limit output to the first 10
32 // files. `force(true)` transitions the command into `WorkspaceMode`, and
33 // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34 // `-soptions` is unavailable).
35 let mut diff = p4
36 .diff()
37 .force(true)
38 .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39 .limit(10);
40
41 let files = [OsStr::new("//depot/project/src/...")];
42 let output = diff.output_with(&files)?;
43 println!("{}", String::from_utf8_lossy(&output.stdout));
44
45 // Display mode: instead of full diffs, list only the unopened files that
46 // differ from the depot. `display_options` transitions `WorkspaceMode`
47 // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48 let mut list_changed = p4
49 .diff()
50 .force(true)
51 .display_options(DisplayOptions::UnopenedChanged);
52
53 let output = list_changed.output_with(&files)?;
54 println!("{}", String::from_utf8_lossy(&output.stdout));
55
56 // Stream-spec mode: diff a privately edited stream spec against the head
57 // version of another stream. `stream_spec_mode` transitions the command
58 // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59 let mut stream_diff = p4.diff().stream_spec_mode();
60 let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61 child.wait()?;
62
63 Ok(())
64}Source§impl<M: ExclusiveOption> Diff<M>
impl<M: ExclusiveOption> Diff<M>
Sourcepub fn get_global_opts(&self) -> &GlobalOpts
pub fn get_global_opts(&self) -> &GlobalOpts
Sourcepub fn set_global_opts(&mut self, v: GlobalOpts) -> &mut Self
pub fn set_global_opts(&mut self, v: GlobalOpts) -> &mut Self
Sourcepub fn global_opts(self, v: GlobalOpts) -> Self
pub fn global_opts(self, v: GlobalOpts) -> Self
Source§impl<M> Diff<WorkspaceMode<M>>
impl<M> Diff<WorkspaceMode<M>>
Sourcepub fn get_force(&self) -> bool
pub fn get_force(&self) -> bool
§Description
-f
Force the diff (if no revision is specified, against the head
revision), even when the client file is not open for edit.
Sourcepub fn set_force(&mut self, v: bool) -> &mut Self
pub fn set_force(&mut self, v: bool) -> &mut Self
§Description
-f
Force the diff (if no revision is specified, against the head
revision), even when the client file is not open for edit.
Sourcepub fn force(self, v: bool) -> Self
pub fn force(self, v: bool) -> Self
§Description
-f
Force the diff (if no revision is specified, against the head
revision), even when the client file is not open for edit.
Sourcepub fn get_differing_only(&self) -> bool
pub fn get_differing_only(&self) -> bool
Sourcepub fn set_differing_only(&mut self, v: bool) -> &mut Self
pub fn set_differing_only(&mut self, v: bool) -> &mut Self
Sourcepub fn differing_only(self, v: bool) -> Self
pub fn differing_only(self, v: bool) -> Self
Sourcepub fn get_diff_nontext(&self) -> bool
pub fn get_diff_nontext(&self) -> bool
Sourcepub fn set_diff_nontext(&mut self, v: bool) -> &mut Self
pub fn set_diff_nontext(&mut self, v: bool) -> &mut Self
Sourcepub fn diff_nontext(self, v: bool) -> Self
pub fn diff_nontext(self, v: bool) -> Self
Source§impl Diff<WorkspaceMode<Unselected>>
impl Diff<WorkspaceMode<Unselected>>
Sourcepub fn display_options(
self,
v: DisplayOptions,
) -> Diff<WorkspaceMode<WorkspaceDisplayMode>>
pub fn display_options( self, v: DisplayOptions, ) -> Diff<WorkspaceMode<WorkspaceDisplayMode>>
§Description
-soptions
Pass display options to the underlying diff routine (see Usage notes for details).
Transitions this command to the WorkspaceDisplayMode state with
the display options set; -m max is unavailable in this state.
Examples found in repository?
27fn main() -> std::io::Result<()> {
28 let p4 = P4Cli::default();
29
30 // Workspace mode: force a diff against head, use the unified format with
31 // whitespace-insensitive comparison, and limit output to the first 10
32 // files. `force(true)` transitions the command into `WorkspaceMode`, and
33 // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34 // `-soptions` is unavailable).
35 let mut diff = p4
36 .diff()
37 .force(true)
38 .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39 .limit(10);
40
41 let files = [OsStr::new("//depot/project/src/...")];
42 let output = diff.output_with(&files)?;
43 println!("{}", String::from_utf8_lossy(&output.stdout));
44
45 // Display mode: instead of full diffs, list only the unopened files that
46 // differ from the depot. `display_options` transitions `WorkspaceMode`
47 // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48 let mut list_changed = p4
49 .diff()
50 .force(true)
51 .display_options(DisplayOptions::UnopenedChanged);
52
53 let output = list_changed.output_with(&files)?;
54 println!("{}", String::from_utf8_lossy(&output.stdout));
55
56 // Stream-spec mode: diff a privately edited stream spec against the head
57 // version of another stream. `stream_spec_mode` transitions the command
58 // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59 let mut stream_diff = p4.diff().stream_spec_mode();
60 let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61 child.wait()?;
62
63 Ok(())
64}Sourcepub fn limit(self, max: u64) -> Diff<WorkspaceMode<WorkspaceRegularMode>>
pub fn limit(self, max: u64) -> Diff<WorkspaceMode<WorkspaceRegularMode>>
§Description
-m max
Limit output to diffs (or status) of only the first max files,
unless the -s option is used, in which case the -m option is
ignored.
Transitions this command to the WorkspaceRegularMode state with
the limit set to max; -soptions is unavailable in this state.
Examples found in repository?
27fn main() -> std::io::Result<()> {
28 let p4 = P4Cli::default();
29
30 // Workspace mode: force a diff against head, use the unified format with
31 // whitespace-insensitive comparison, and limit output to the first 10
32 // files. `force(true)` transitions the command into `WorkspaceMode`, and
33 // `limit(10)` further transitions it into `WorkspaceRegularMode` (where
34 // `-soptions` is unavailable).
35 let mut diff = p4
36 .diff()
37 .force(true)
38 .diff_options(DiffOptionsBuilder::unified(None).ignore_all_whitespace())
39 .limit(10);
40
41 let files = [OsStr::new("//depot/project/src/...")];
42 let output = diff.output_with(&files)?;
43 println!("{}", String::from_utf8_lossy(&output.stdout));
44
45 // Display mode: instead of full diffs, list only the unopened files that
46 // differ from the depot. `display_options` transitions `WorkspaceMode`
47 // into `WorkspaceDisplayMode`, where `-m max` is unavailable.
48 let mut list_changed = p4
49 .diff()
50 .force(true)
51 .display_options(DisplayOptions::UnopenedChanged);
52
53 let output = list_changed.output_with(&files)?;
54 println!("{}", String::from_utf8_lossy(&output.stdout));
55
56 // Stream-spec mode: diff a privately edited stream spec against the head
57 // version of another stream. `stream_spec_mode` transitions the command
58 // into `StreamSpecMode`; the stream spec is passed to `spawn_with`.
59 let mut stream_diff = p4.diff().stream_spec_mode();
60 let mut child = stream_diff.spawn_with(Some("//streams/main@head"))?;
61 child.wait()?;
62
63 Ok(())
64}Source§impl Diff<WorkspaceMode<WorkspaceDisplayMode>>
impl Diff<WorkspaceMode<WorkspaceDisplayMode>>
Sourcepub fn get_display_options(&self) -> &DisplayOptions
pub fn get_display_options(&self) -> &DisplayOptions
§Description
-soptions
Pass display options to the underlying diff routine (see Usage notes for details).
Sourcepub fn set_display_options(&mut self, v: DisplayOptions) -> &mut Self
pub fn set_display_options(&mut self, v: DisplayOptions) -> &mut Self
§Description
-soptions
Pass display options to the underlying diff routine (see Usage notes for details).
Source§impl Diff<WorkspaceMode<WorkspaceRegularMode>>
impl Diff<WorkspaceMode<WorkspaceRegularMode>>
Trait Implementations§
Source§impl ParameterizedSpawn for Diff<Unselected>
impl ParameterizedSpawn for Diff<Unselected>
Source§fn spawn_with<'a>(
&mut self,
files: Self::Input<'a>,
) -> Result<Self::Output<'a>, Self::Error>
fn spawn_with<'a>( &mut self, files: Self::Input<'a>, ) -> Result<Self::Output<'a>, Self::Error>
Spawns p4 diff for the given file arguments as a child process with
piped standard output and error streams; use the returned Child
handle to wait for it or interact with it.
type Input<'a> = &'a [&'a OsStr]
type Output<'a> = Child
type Error = Error
Source§impl<M: ExclusiveOption> ParameterizedSpawn for Diff<WorkspaceMode<M>>
impl<M: ExclusiveOption> ParameterizedSpawn for Diff<WorkspaceMode<M>>
Source§fn spawn_with<'a>(
&mut self,
files: Self::Input<'a>,
) -> Result<Self::Output<'a>, Self::Error>
fn spawn_with<'a>( &mut self, files: Self::Input<'a>, ) -> Result<Self::Output<'a>, Self::Error>
Spawns p4 diff for the given file arguments as a child process with
piped standard output and error streams; use the returned Child
handle to wait for it or interact with it.
type Input<'a> = &'a [&'a OsStr]
type Output<'a> = Child
type Error = Error
Source§impl ParameterizedSpawn for Diff<StreamSpecMode>
impl ParameterizedSpawn for Diff<StreamSpecMode>
Source§fn spawn_with<'a>(
&mut self,
stream_spec: Self::Input<'a>,
) -> Result<Self::Output<'a>, Self::Error>
fn spawn_with<'a>( &mut self, stream_spec: Self::Input<'a>, ) -> Result<Self::Output<'a>, Self::Error>
Spawns p4 diff -As as a child process with piped standard output
and error streams; use the returned Child handle to wait for it
or interact with it.
Pass Some(stream_spec) to diff against the given stream spec — a
streamname, optionally at a specific changelist number (@head
selects the head version, @change the version at a specific
change, and @=change the shelved version at a specific change) —
or None to diff the opened stream spec against its have version.
type Input<'a> = Option<&'a str>
type Output<'a> = Child
type Error = Error
Source§impl SpawnExt for Diff<StreamSpecMode>
impl SpawnExt for Diff<StreamSpecMode>
Source§fn spawn<'a>(&mut self) -> Result<Self::Output<'a>, Self::Error>
fn spawn<'a>(&mut self) -> Result<Self::Output<'a>, Self::Error>
Spawns p4 diff -As without a stream spec as a child process with
piped standard output and error streams; the opened stream spec is
diffed against its have version. Use the returned Child handle
to wait for it or interact with it.