Reputation: 7890
I only understand that a workspace is an object which maps a set of file in server on user's file system.
Having used git previously, I don't understand the concept of streams yet. Is it same as branching in git? So how would you explain streams to a Git user?
Upvotes: 4
Views: 3087
Reputation: 71454
If you're already familiar with Perforce's inter-file branching system (i.e. each "branch" in Perforce is a distinct set of files in the depot), then it's easy to understand a stream as a branch that is automatically managed for you. The stream defines which depot directory the branch lives in, what the workspace view for that branch looks like, and how changes propagate to other branches. (In an unmanaged "classic" branch, these concepts exist for each branch but aren't formalized; streams provide a layer of syntactic sugar and process enforcement over all of those operations.)
If you're not at all familiar with Perforce and are coming from git
, yes, the easiest mental mapping is "stream = branch". Use p4 switch -c NEWBRANCH
instead of git checkout -b NEWBRANCH
, and p4 switch BRANCH
instead of git checkout BRANCH
.
Here's a demo (starting from scratch with a p4 init
) of creating a new stream, making a change to it, and then merging that change back to the mainline:
C:\Perforce\test4>p4 init -C1 -n
Server bob-dvcs-1592407491 saved.
C:\Perforce\test4>p4 switch -l
main *
C:\Perforce\test4>echo "here's a test file" > foo
C:\Perforce\test4>p4 add foo
//stream/main/foo#1 - opened for add
C:\Perforce\test4>p4 submit -d "my first file!"
Submitting change 1.
Locking 1 files ...
add //stream/main/foo#1
Change 1 submitted.
C:\Perforce\test4>p4 switch -c dev
dev
C:\Perforce\test4>p4 switch -l
dev *
main
C:\Perforce\test4>p4 edit foo
//stream/dev/foo#1 - opened for edit
C:\Perforce\test4>echo "a change" >> foo
C:\Perforce\test4>p4 submit -d "my first edit!"
Submitting change 3.
Locking 1 files ...
edit //stream/dev/foo#2
Change 3 submitted.
C:\Perforce\test4>p4 filelog foo
//stream/dev/foo
... #2 change 3 edit on 2020/06/17 by bob@bob-dvcs-1592407491 (text) 'my first edit!'
... ... copy into //stream/main/foo#2
... #1 change 2 branch on 2020/06/17 by bob@bob-dvcs-1592407491 (text) 'Populate //stream/dev.'
... ... branch from //stream/main/foo#1
C:\Perforce\test4>p4 switch main
C:\Perforce\test4>cat foo
"here's a test file"
C:\Perforce\test4>p4 merge --from dev
//stream/main/foo#1 - integrate from //stream/dev/foo#2
... must resolve content from //stream/dev/foo#2
C:\Perforce\test4>p4 resolve -am
c:\Perforce\test4\foo - merging //stream/dev/foo#2
Diff chunks: 0 yours + 1 theirs + 0 both + 0 conflicting
//bob-dvcs-1592407491/foo - copy from //stream/dev/foo
C:\Perforce\test4>p4 submit -d "my first merge!"
Submitting change 4.
Locking 1 files ...
integrate //stream/main/foo#2
Change 4 submitted.
C:\Perforce\test4>cat foo
"here's a test file"
"a change"
C:\Perforce\test4>p4 filelog foo
//stream/main/foo
... #2 change 4 integrate on 2020/06/17 by bob@bob-dvcs-1592407491 (text) 'my first merge!'
... ... copy from //stream/dev/foo#2
... #1 change 1 add on 2020/06/17 by bob@bob-dvcs-1592407491 (text) 'my first file!'
... ... branch into //stream/dev/foo#1
Upvotes: 2