Perforce Public Knowledge Base - Updating a Sparse Branch
Reset Search
 

 

Article

Updating a Sparse Branch

« Go Back

Information

 
Problem

When working with branches, it is quite common that you will need to pull in the changes that have been made to the original code-line to keep your branch up-to-date. Normally this is done by re-integrating the entire branch, but this is not the case if you are using sparse branching; you don't want to integrate files that you have not been working on.

Solution

Assuming a code-line called "mainline" located at "//depot/mainline/..." and a sparse branch of this called "sparse_dev" located at "//depot/sparse_dev/...". Mainline contains six files, of which three are branched into "sparse_dev":

C:\>p4 files //depot/mainline/...
//depot/mainline/file0#2 - edit change 13 (text)
//depot/mainline/file1#2 - edit change 13 (text)
//depot/mainline/file2#2 - edit change 13 (text)
//depot/mainline/file3#2 - edit change 13 (text)
//depot/mainline/file4#2 - edit change 13 (text)
//depot/mainline/file5#2 - edit change 13 (text)
C:\>p4 files //depot/sparse_dev/...
//depot/sparse_dev/file0#1 - branch change 12 (text)
//depot/sparse_dev/file1#1 - branch change 12 (text)
//depot/sparse_dev/file2#1 - branch change 12 (text)

Performing an integration from the code-line to the branch would also integrate the three files that have not already been branched, which is not what we want:

C:\>p4 integrate -n //depot/mainline/... //depot/BRANCH1/...
//depot/sparse_dev/file0#1 - integrate from //depot/mainline/file0#2
//depot/sparse_dev/file1#1 - integrate from //depot/mainline/file1#2
//depot/sparse_dev/file2#1 - integrate from //depot/mainline/file2#2
//depot/sparse_dev/file3#1 - branch/sync from //depot/mainline/file3#1,#2
//depot/sparse_dev/file4#1 - branch/sync from //depot/mainline/file4#1,#2
//depot/sparse_dev/file5#1 - branch/sync from //depot/mainline/file5#1,#2

The Solution

In this case we only want to integrate files that already exist in "sparse_dev", which we can find easily with p4 files. If we create a branch specification to map the branch to the code-line, we can pass this list of files to p4 integrate by way of STDIN. For example, we would need to make a branch specification with a mapping like this:

Branch:	sparse_dev_branch

View:
	//depot/mainline/... //depot/sparse_dev/...

The standard output of p4 files is not suitable to be passed directly into p4 integrate, so we first need to strip each line of everything after the revision specifier ("#"). The easy way to do this is with the cut command.

Note: While cut was originally a Unix command, you can install it as a part of a Windows Unix subsystem (such as CygWin) or as an individual command.

Example:

C:\>p4 files //depot/sparse_dev/... | cut -f 1 -d "#"
//depot/sparse_dev/file0
//depot/sparse_dev/file1
//depot/sparse_dev/file2

Now you can pass this list of files to p4 integrate using the global "-x -" flags, which passes the command arguments from STDIN.

Example:

C:\1777>p4 files //depot/sparse_dev/... | cut -f 1 -d "#" | p4 -x - integrate -n -b sparse_dev_branch
//depot/sparse_dev/file0#1 - integrate from //depot/mainline/file0#2
//depot/sparse_dev/file1#1 - integrate from //depot/mainline/file1#2

//depot/sparse_dev/file2#1 - integrate from //depot/mainline/file2#2
Related Links

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255