Perforce: How do I sync the files in a specific subdirectory to a label - perforce

If I issue
p4 sync ...
it only syncs the files in my CWD and below to HEAD.
However, I am trying to sync a single directory to a label name
p4 sync #LABEL_NAME ...
and the result seems to be that the entire workspace (all files tagged with that label) is then sync'ed to that label, as though I had not added the "...".
Is this expected? And if so, how do I achieve what I want?

The #LABEL_NAME is a "revision specification", while the ... is a file pattern; what you want to do is to combine them, and specify both (the files in this directory and any sub-directories, at the revision in which they were tagged in the label).
To do that, you stick the revision specification after the file pattern, with no spaces between them:
p4 sync ...#LABEL_NAME
For more information about the things you can stick after the file pattern to refine your set of files, run:
p4 help revisions

Related

How to ignore taking revision of few files in perforce?

We have few files checked-in in perforce like **#sample.json. Such file names are not supported on Windows, so I get below exception in p4v perforce application when I take revision.
**sample.json: The filename, directory name, or volume label syntax is incorrect.
I do not want these files on my local box. How can I ignore such files in p4v ?
See the section on ASCII expansion in the doc on file specs:
https://www.perforce.com/perforce/r12.1/manuals/cmdref/o.fspecs.html
You can use this syntax to exclude files with asterisks in their names from your client view:
//depot/... //client/...
-//depot/...%2A... //client/...%2A...
If you want to actually sync these files and substitute the invalid characters you can do that too. For example:
//depot/... //client/...
//depot/...%2A%2A... //client/...WTF-WHO-PUTS-A-DOUBLE-ASTERISK-IN-A-SAMPLE-FILENAME...
will cause a file called **sample.json to be synced to your workspace as WTF-WHO-PUTS-A-DOUBLE-ASTERISK-IN-A-SAMPLE-FILENAMEsample.json.
To ignore/disregard certain files and exclude them from your client workspace, put them into your client view with a '-' in front of them.
Something like:
View:
//depot/project/... //my/client/project/...
-//depot/**/*sample.json //my/client/**/*sample.json

How to rename a file test.c to Test.c in perforce?

I have a file of name: test.c in perforce, but i want it as Test.c (capital T).
I tried rename, delete and then add but both methods are not useful! The file gets update in my machine, but when some one else accesses it, the file remains, test.c itself, not Test.c!
What can i do in this case?
And i have many files of same name inside the directory in perforce, i want to rename them all.
Ex:
dir1->test.c , dir2
dir2 ->test.c , dir3
dir3->test.c
This should become:
dir1->Test.c , dir2
dir2 ->Test.c , dir3
dir3->Test.c
If the file name appears correct when looking at the tree in P4V, but is the wrong case on the client machine, try removing the file from the workspace and then resyncing. Windows won't rename the file if it's already on disk because it's a case insensitive file system.
This is a longstanding bug with Perforce/Helix that they have consistently refused to fix for over 14 years.
The Helix knowledgebase workaround does NOT work, don't waste your time.
The closest I've found to a solution is the following:
Rename the file to an interim string that you will never use in the future and have never used before - eg add a UUID postfix
Commit this change
Copy up to the highest applicable parent stream
Merge down into ALL streams that will ever need the change and have the original erroneous name. You can filter the merge down to just the rename/move operation.
Get Latest on ALL Windows workspaces for the affected streams
Rename the file to the final case-sensitive string
Commit this change
Copy up as per step 3
Merge down as per step 4
Important: You MUST copy up and merge down while the file has the temporary name.
Perforce does not take interim changes into account when merging down or copying up - this is different to every other source control system that I'm aware of and caused much heartache.
Note: While file history across the rename is apparently preserved in the database, it appears that you can only see that the rename occurred and cannot diff or merge across the change.

Can I perforce integrate files from 2 directories into a single directory?

I've imported a project into a directory and the original directory structure is:
//depot/a/b/foo.txt
//depot/a/b/bar.txt
//depot/a/b/c/baz.txt
//depot/a/b/c/boz.txt
Note that none of the files in //depot/a/b have name conflicts with files in //depot/a/b/c.
I'd now like to reorganize things such that all of those text files reside under //depot/newdir/. I attempted this by creating the following branch spec with view lines similar to the following:
//depot/a/b/... //depot/newdir/...
//depot/a/b/c/... //depot/newdir/...
This didn't work. When I integrate, the files in //depot/a/b/c clobber those in //depot/a/b. If I reverse the lines the files in //depot/a/b clobber those in //depot/a/b/c.
I've tried various wildcards (such as the following) hoping to be more specific, and can't get this to work.
//depot/a/b/%%1.txt //depot/newdir/%%1.txt
//depot/a/b/c/%%1.txt //depot/newdir/%%1.txt
Is it possible to migrate all of the files as described above to the //depot/newdir area in a single branch spec?
You should be able to use the move command here.
p4 move //depot/a/b/* //depot/newdir/*
p4 move //depot/a/b/c/* //depot/newdir/*
Those two commands will move all the files in b and c (but not any files in their subdirectories) to newdir.

p4 sync, how do you exclude files while using wildcards?

I'm trying to use p4 sync to sync a specific directory to a given changelist number using wildcards but I also want to exclude a list of files that are under that directory (in subdirectories), I tried using - (both before and after using a path with wildcards) but the file never gets excluded, this the command I'm trying:
p4 sync //Repo/Foo/... -//Repo/Foo/Bar/Foobar.txt
The file exclusion seems to only work when the files/directories you are syncing don't match the files you're trying to exclude.
In your client, you would have multiple lines:
//Repo/Foo/... //my_client/Repo/Foo/...
-//Repo/Foo/subdirectory/... //my_client/Repo/Foo/subdirectory/...
This would allow you to get everything in the Foo directory and all subdirectories except "subdirectory".
You can do this if you use a label. Create a label in your favorite editor (p4v or command line p4 label and add your two lines:
//Repo/Foo/...
-//Repo/Foo/Bar/Foobar.txt
In the revision field put "#head" (including quotes!) if you want the latest or a change list number. Give the label a name - for instance "sync_butnot_foobar"
On the command line you can now sync:
p4 sync #sync_butnot_foobar,#sync_butnot_foobar
This has a huge benefit over the modify your client spec and sync head model. If you exclude a file in your client spec, the next time you sync that file will be brought to revision 0 which probably isn't what you wanted.
In short, you can't exclude files on a sync. That can only be done within the client spec. (Well, it could be done through the protections table, but that is really a different matter I think).
But if you want to sync a specific folder and only the files in that folder, use *
p4 sync //Repo/Foo/*
will get you only the files in the Foo folder.

In Perforce P4V, how to I search for changelists with files in particular folders?

In Perforce P4V, I'd like to do a search for all changelists that have files from a particular set of folders, that all have "index" in the folder name, and also have another folder at the beginning. For instance, I want to see all changelists against any files in folders like these:
\depot\abc\def\table\index*.*
\depot\abc\ghi\table\index*.*
so basically any folders that match the pattern
\depot\abc\...\table\index*.*
But this doesn't appear to work. Any ideas? Also is there any detailed information on using perforce wildcards online? I was not able to find a whole lot. This must be something that lots of people need to do...
I use both P4V on Windows and I use the 'p4' command line client on Linux. What you're asking for actually uses two Perforce client commands:
p4 changes
p4 describe
On P4V specifically, this is done under the menu option View->Submitted Changelists (Ctrl+2). This should open a tab for searching. In the Folder/file input field, type a path expression, like this:
//depot/main/app/python/SiteControl/.../*.html
When I run this against my depot, I get a list of changelists. When I click on a changelist, it expands to a list of files. The files matching the pattern *.html are in normal font weight/color, and the non-matching files are "greyed out". Does that make sense?
Similarly, and more specific to your question/usage, you can use a wildcard to say "all files with index at the beginning of their name", as so:
//depot/main/app/python/SiteControl/.../index.*
Now just to compare, run it again but remove the "/index.*" from the path expression. Now what you'll see are all of the submitted changelists under the depot path - not just the ones that contain html files. Additionally, all files will appear in normal font weight/color.
HTH,
-aj

Resources