Is it possible to use RCS Revision keyword for a depot path? - perforce

I've managed to use the $Revision$ RCS keyword in Perforce: when I update my file
//depot/dev_projects/main/src/include/version.h it will update my define in the file, nicely:
#define VCS_VERSION "$Revision: #4 $"
That includes the revision for the version.h file.
What I really need is to embed the revision for the folder of my project //depot/dev_projects/main/src/ to the version.h file. So if someone submits a file for example to //depot/dev_projects/main/doc/readme.txt, I would like to see #define VCS_REVISION "$Revision: #5 $" in version.h after I gets the latest revision from depot.
Is there a way to do that?

You have two cases to worry about: exiting files and new files. For existing files (and I'm going to assume you are talking about c/cpp files), you can simply 'p4 reopen' the files with the filetype 'text+k' and then submit those files:
p4 reopen -t text+k //groovy_project/src/....cpp
This would reopen all of the .cpp files in the //groovy_project/src location and make them 'text+k' (the +k means RCS keyword expansion, but I guess you know that since you have keyword expansion working).
For new files, you should use the 'p4 typemap' command. 'p4 typemap' will bring up the typemap in your editor. This form contains a mapping of files to filetypes for new files added to the depot. These are the default filetypes that new files will receive (unless a new file added explicitly uses a different filetype when the file is added). For instance, if you have
TypeMap:
text+k //groovy_project/src/....cpp
in your typemap, all new .cpp files in the //groovy_project/src folder will get the text+k filetype, allowing for keyword expansion.
Note, if you explicitly give a new file a different type than what is found in the typemap, the explicitly specified type is used. Say you had the typemap above. The command:
p4 add -t text ~/projects/groovy_project/src/newfile.cpp
this file would get added to the depot as text, and not text+k.
I hope that this information helps.
EDIT:
After reading the edits to your original question, the short answer is no, you cannot add a revision for a folder. The slightly longer answer is that Perforce doesn't really know about folders/directories. It just knows about files (and therefore the path to the file). Directories are not really individual objects in the database in a way that would make what you want work.

I think you want the $File$ keyword:
http://kb.perforce.com/article/54/using-rcs-keywords

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

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

Perforce : Revert files without losing its modification

To let you understand my problem, i must give some brief explanation about the way my client application works.
First, we create workspaces with allwrite set, this is because our programming language (PowerBuilder) does not writes directly to txt files, it writes to 'pbl' files, which are binary.
However we dont version pbl files and to be able to version each object inside a pbl we need to run some cmdcommand, which will output the classes within the pbl file to text files (one file per class), these text files is what Perforce must version.
The problem now is that the pbls are being listed as modified files (in fact they are), but we dont want them to be marked as modified.
I could put them in a ignore file, but there are some Pbls in the repository which must be synced.
I know i could specify in the ignore file to ignore Pbls except the Pbls which are in the repository, but then these specific pbls would keep showing up as modified files when i run a reconcile..
What i want is to have the PBL file exactly the way it was before running the reconcile, unopened by perforce but modified.
Its would be ok, if i could revert them without undoing its modifications...
Or if i could run a reconcilefor all the files, except the pbls.
Does anyone knows a way to do that? Thank you.
You can revert files without refreshing their content from the repository by running 'revert -k': http://perforce.com/perforce/doc.current/manuals/cmdref/p4_revert.html

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.

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.

Resources