Wednesday, January 22, 2014

Working with perforce streams - command line

Streams intro

Creating a stream depot

 - Command:    p4 depot <stream-depot-name>
         Ex: # p4 depot DPM
 - Change the type to stream from local
         Type:   stream

Create a new main-line stream

 - Ex: #  p4 stream -t mainline //DPM/MAIN

 - Retain the defaults

Switch your existing workspace to the new stream

 # p4 workspace -f -s -S //DPM/MAIN

Branch files from another depot location

p4 copy -v //depot/DPM/RTJC/... //DPM/MAIN/...
p4 submit -d "Creating DPM mainline"

Now the //DPM/MAIN stream is ready to use. To work on it, switch your workspace with the command 
       # p4 workspace -f -s -S //DPM/MAIN
      # p4 sync
      # p4 edit
      # p4 submit

Branching a Development stream from mainline

# p4 stream -t development -P //DPM/MAIN //DPM/DEV

Switch your workspace to work on this new stream
# p4 workspace -s -S //DPM/DEV

Populate the DEV stream by branching files from MAIN
# p4 merge -S //DPM/DEV -r
# p4 submit -d "Branching from mainline"
# p4 resolve -am
# p4 submit -c 7

Merging files from mainline

Now there are changes in mainline, which needs to be merge down to development stream.
   p4 workspace -s -S //DPM/MAIN
   p4 sync //DPM/MAIN/startbuild
   p4 edit //DPM/MAIN/startbuild
   p4 submit -d "bugfix"

 Now switch back your workspace to DEV stream
    p4 workspace -s -S //DPM/DEV

    # p4 merge -S //DPM/DEV -r
        //DPM/DEV/startbuild#1 - integrate from //DPM/MAIN/startbuild#2
    # p4 resolve
    # p4 submit -d "Merged latest changes"

Promoting changes in Dev stream to main

Now we made changes in Dev stream, which needs copy up to main.
   p4 edit //DPM/DEV/startbuild
   p4 add info.txt
   p4 submit -d "Dev changes"

Copy-up only after merging down. So lets merge down again
  # p4 merge -S //DPM/DEV -r
    All revision(s) already integrated.

Now switch back your workspace to main
  # p4 workspace -s -S //DPM/MAIN
  # p4 update     --> To synchronize the workspace with its view of the depot

Copy the content from DEV stream to Main stream
 # p4 copy -S //DPM/DEV
     //DPM/MAIN/info.txt#1 - branch/sync from //DPM/DEV/info.txt#1
     //DPM/MAIN/startbuild#2 - sync/integrate from //DPM/DEV/startbuild#3
 #p4 submit -d "New changes from Dev stream"

Stream types

1) mainline
    Sample spec:
    ----------------------------------------------------------------------
    Stream: //DPM/MAIN
    Owner:  guruss1
    Name:   MAIN
    Parent: none
    Type:   mainline
    Options:        allsubmit unlocked notoparent nofromparent
    Paths:
        share ...
    ----------------------------------------------------------------------
2) development
  
  Sample spec:
    ----------------------------------------------------------------------
   Stream: //DPM/DEV
   Owner:  guruss1
   Name:   DEV
   Parent: //DPM/MAIN
   Type:   development
   Options:        allsubmit unlocked toparent fromparent
   Paths:
        share ...
     ----------------------------------------------------------------------
3) release
 Sample Spec:
 ----------------------------------------------------------------------
  Stream: //DPM/REL-3.5
  Owner:  guruss1
  Name:   REL-3.5
  Parent: //DPM/MAIN
  Type:   release
  Options:        allsubmit unlocked toparent nofromparent
  Paths:
        share ...
 ----------------------------------------------------------------------

Creating a Release stream from mainline

#p4 stream -t release -P //DPM/MAIN //DPM/REL-3.5

Copy up or merge to release streams - Stopping the flow

Copy up or merge to release streams from parent branches are restricted by default.

# p4 merge -S //DPM/REL-3.5 -r
  Stream //DPM/REL-3.5 not configured to 'copy' or 'merge' changes in this direction.
#$ p4 copy -S //DPM/REL-3.5 -r
   Stream //DPM/REL-3.5 not configured to 'copy' or 'merge' changes in this direction.

Flushing release stream with main content

-Switch workspace to release stream
   # p4 workspace -s -S //DPM/REL-3.5 
   # p4 sync
- Forcefully copy up the content from main to release
  # p4 copy -F -S //DPM/REL-3.5 -r
- p4 submit -d "Creating REL-3.5 from main"

Stream spec options

Default options for the stream types
  main:               allsubmit unlocked notoparent nofromparent
  development:    allsubmit unlocked toparent fromparent
  release:             allsubmit unlocked toparent nofromparent

Understanding these options
 - The “fromparent” and “toparent” options toggle whether parent-to-stream and stream-toparent flow are expected at all. The presence of 'nofromparent' in release stream avoid it from accepting changes from parent.
 - “allsubmit” -> “ownersubmit”.  Only owner submit changes to that stream. Content may be pulled from an “ownersubmit” stream into other streams.
 - “locked” - it prevents other users from modifying the stream spec

Understanding stream view Paths

1) Paths:
        share ...
    It means - Share changes with other streams. These paths appear in both client views and branch views, and are mapped to the stream. These files can be synced, submitted, and integrated.
2) Isolate
    Isolate changes from other streams. These paths appear only in client views and are mapped to the stream. That means you can sync and submit the files in these paths, but you can’t integrate them. This is useful for built binaries, generated docs, and other content that you want checked in but not branched or merged.
3) Import 
   Import a path from elsewhere. These paths appear only in client views and are mapped per the parent stream’s view (the default), or to another depot location.You can sync these files, but because they’re not mapped to the stream itself, you can’t submit them. Nor can you integrate them. All they do is mirror other paths.
4) Exclude
  Exclude a path from both client views and branch views. This keeps unneeded content out of workspaces and streams entirely.