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

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.

Related

What will this command do: p4 sync //depot/proj1/

I am new to Perforce and want to create a automated tool to get the latest revision by itself. I have a mapping like this:
P4CLIENT: Proj_name
Worspace root direcctory: C:\...\Proj_name
Stream: Build
Now what i desire is it should get latest revision of all files from:
Build\fold1\fold2 to C:\...\Proj_name\fold1\fold2
When I just ran p4 sync command, it copied all files from Build to C:\...\Proj_name.
So please tell how to specify the folder path from where to get the latest revision. Will the command p4 sync //depot/proj1/... work for me and how does it change in my condition ?
You use the View: section of your client spec to describe which parts of the overall repository you wish to work with, and where those files should be placed on your workstation's filesystem.
In your particular case, to specify the folder path, as well as where those files should be placed, you might specify your View: as something like:
View:
//depot/Build/fold1/fold2/... //Proj_name/fold1/fold2/...
You may have considerably more complex view mappings; the view syntax is quite powerful. To learn more about view mappings, type p4 help views.
After you change your View: specification for your client, run:
p4 sync
The sync command will notice that you have changed your view mapping, and it will re-arrange the files in the root of your client on your workstation, so that they are arranged as described by your new view mapping.
If you don't wish to sync your entire client, you can specify a subset of the files which should be sync'd, by naming that subset of files using a file pattern as an argument to the sync command:
p4 sync //depot/Build/fold1/fold2/*.cpp
However, that can be quite confusing, and I recommend that, to start, you avoid using that advanced usage, and stick to performing a p4 sync with no file arguments, at least until you get more comfortable with how p4 sync is used. For one thing, when you are sync'ing different subsets of files with different file arguments, it is quite easy to get your workstation's filesystem into an un-buildable state, by getting half of the files from one changelist and half from another, which will cause you to have code that doesn't compile, etc.
So, for now:
Consider which parts of the repository you wish to work with, and where you want them to go on your workstation's filesystem
Run p4 client and describe the appropriate View: line(s) to specify those files, using the pattern-matching syntax of the View: field
Run p4 sync and Perforce will put those files on your computer as specified.

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

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

How can you save and restore a list of checked out files in Perforce?

I have, in perforce, a sort of 'basic working set' of files that I keep checked out (and therefore writable) when working. However, every time I commit my changes, this list gets disrupted - some things committed, others reverted - and then I have to waste time tracking down and checking out all these files again.
So, is there some way to save the list of currently checked out files, and then later check out those same files again?
I primarily use P4V, but I have P4Win and command-line Perforce available. I'd strongly prefer a GUI solution, though.
I only want to save and restore the state of which files are checked out, not the contents of those files, so shelving is not the answer
I am aware of the 'Do not submit unchanged' and 'Check out after submit' options. They are not sufficient. For instance, frequently I will have files which are programmatically generated which register as 'changed' when the only thing that is different is the 'File generated on' timestamp; I need to prevent such spurious revisions from being submitted, and I have not found any practical method of searching for and managing such files that doesn't involve the 'revert if unchanged' command.
You can do:
p4 -ztag opened | grep depotFile | cut -d ' ' -f 3 > files.txt
to save a list of files already open in your client. (If you don't have Unix utilities for Windows, you could construct this list by whatever means you want, such as running p4 opened > files.txt and manually editing files.txt in an editor.)
Once you have a list of files, you can open all of them via:
p4 -x files.txt edit
This doesn't meet your preference for a GUI-based solution, but you could create .cmd scripts to perform these actions and then double-click on them (or on shortcuts to them).
The easiest solution would be to exclude those generated files via your workspace specification, e.g., "-//depot/files/ignorablefile.sh"
They can still reside in your local workspace, but the app will not attempt to update them or add them to source control.
You said that shelving's not the answer, but that's what I would go with as the easiest solution (i.e. the one that involves the least scripting and/or fewest manual steps) for the specific question you're asking:
Shelve your pending change (let's call this change 1000).
Move your open files to a new pending change (let's call this change 1001).
Submit change 1001.
Unshelve change 1000.
Sync and resolve.
Now you have the same exact files open (the unshelve opened them) but at the head revision (the sync and resolve does that).
Now, looking past what you asked for to what might make your life easier: rather than reverting the files you don't want to submit (and having some sort of scheme to get them back later, possibly via shelving as described above), what I'd do is move them to another changelist. So instead of:
Identify "unchanged" files.
Revert unchanged files.
Submit remaining files with "reopen" option.
Reopen previously reverted files (somehow).
I'd do:
Identify "unchanged" files.
Move unchanged files to another changelist N.
Submit remaining files with "reopen" option.
Move all files from changelist N back to the default changelist.
All of those except step 1 are simple one-shot commands that you can do from any client. Personally, I'd automate steps 1+2 with a script (I'm assuming it's programmatically possible to determine whether the only diff in one of these files is the timestamp) and put it into P4Win/P4V as a "custom tool".

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.

Resources