[p4] Adding a Changelist # to C++ code...?

Veronica Merryfield veronica.merryfield at shaw.ca
Thu Feb 21 17:46:06 PST 2008


Is it possible to do this with P4V? I can't see an obvious way to  
prepend the k to the file type within P4V.

Thanks

On 21-Feb-08, at 11:42 AM, Peter Prymmer wrote:

> perforce-user-bounces at perforce.com wrote on 02/21/2008 03:18:52 AM:
>
>> Does anyone know of a way to integrate the last synced version number
>> from Perforce into C++ code, such that it can be displayed on screen?
>
> One approach with perforce could exploit keywords within the files
> (example shown below).
>
> Before using this approach do note that keyword expansion by the SCM
> tool is not universally appreciated (it can lead to odd diff and merge
> problems).  You might consider confining it to one single header  
> file if
> you choose to adopt it instead of adding it to a large number of  
> files.
>
> // Demonstrate the use of perforce keywords as C++ preprocessor
> definitions in a source file.
> // Add this demo file to the depot using:
> //    p4 add -t ktext <filename>
> // after the submit the macros are modified by perforce
> // in the submitting client.  Hence within any other P4CLIENT that
> subsequently syncs
> // the file out the macros will be expanded.
>
> #include <iostream>
>
> #define ID "$Id$"
> #define DATE "$Date$"
> #define DATETIME "$DateTime$"
> #define REVISION "$Revision$"
> #define AUTHOR "$Author$"
> #define HEADER "$Header$"
> #define CHANGE "$Change$"
> #define FILE "$File$"
>
> int main() {
>    cout << "The author of this file was " << AUTHOR << endl;
>    cout << "This file can be found in the depot at " << ID << endl;
> }
>
> I hope that helps.
>
> Peter Prymmer
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user




More information about the perforce-user mailing list