[p4] Writing triggers with p4.net ?

Naim Akbar naim_akbar at hotmail.com
Wed Jul 1 12:28:56 PDT 2009


That makes alot of sense. Thanks for the advice.

 

About this comment..

 

Provide one true source, but let folks map it in multiple times if need be. This should be a STOPGAP measure until such time as you (your engineers) can re-architect your projects in a more organized way.


...How can I map this multiple times. Can this be done in perforce or is this a visual studio thing?
 


Date: Wed, 1 Jul 2009 11:58:52 -0700
From: matt.janulewicz at lucasfilm.com
To: naim_akbar at hotmail.com
CC: steve at vance.com; jab at pobox.com; perforce-user at perforce.com
Subject: Re: [p4] Writing triggers with p4.net ?

Seriously, you need to tell your 'powers that be' that they are wrong, wrong, wrong, and you are teetering on the edge of a slippery slope.

The classic idea behind source control is 'one source', meaning a holy grail of code, one copy, a single point of reference. If you have 10 copies of the 'same' file and want to try to keep them up to date with each other, forget it. You say as much in your last message, so you need to follow your instincts. You know this will turn out badly!

How will people know which of the 10 they should change? Say someone randomly picks one of the 10 to edit, will your script/trigger be smart enough to know what the other nine are? Will it check that nobody else has one of those nine checked out? Will it then fail, or wait for that other checkin? Then how is *that* checkin propagated? What if the trigger fails? If you protect the nine 'other' files and tell people which one is the correct one to check out, what's to stop them from making an 11th copy and using that?

Sorry to sound so harsh, but trigger-izing this kind of thing is a bad, bad, bad idea (and like I said, I do realize that you know this.) I guarantee that this approach will end in failure, frustration and general mayhem.

Something Steve Vance said should be pursued (in my opinion):

"Are you trying to share code between projects? If so, why don't you just map the shared part of the depot into the client specs instead?"

Provide one true source, but let folks map it in multiple times if need be. This should be a STOPGAP measure until such time as you (your engineers) can re-architect your projects in a more organized way.

Also, if you are a Windows shop using VisualStudio, I've used its linking capability to great success. You can add the physical file to your 'Solution Items' folder then each project can link back to it.

On Unix systems you might even consider using filesystem links.


-Matt


Naim Akbar wrote: 


Essentialy the way we have our setup is, we have a set of core files and a set of client files (all under one branch). So we have a file which is in the core  and is present in each client (identical in each client). Now what we wanted was, if this file changes for any client, then for this change to be rippled across to all other clients. I know the structure is bad, and we should have one file for evryone, but its just the was it is at the moment, and powers to be want to leave structure as it is for the moment.



So my question is how would I, on submission of this file, ripple the change to all the other clients in an automated way?



Thanks,




> From: steve at vance.com
> To: naim_akbar at hotmail.com; jab at pobox.com; steve at vance.com; perforce-user at perforce.com
> Date: Wed, 1 Jul 2009 12:18:40 -0400
> Subject: RE: [p4] Writing triggers with p4.net ?
>
> What do you mean by "apply the same changes" and why do you want to do it
> for every changelist?
>
> First of all, the best way to track those changes through where they've
> been applied is with integration.
>
> Are you trying to propagate changes between branches? Are the target files
> also under constant revision or are they essentially only copies of the
> file the developer changed?
>
> Are you trying to share code between projects? If so, why don't you just
> map the shared part of the depot into the client specs instead?
>
> A better mechanism for the kind of thing you're asking is the review
> daemon. Its canonical purpose is to notify people of changes, but it can be
> used for any action whose triggering event is a new changelists.
>
> Original Message:
> -----------------
> From: Naim Akbar naim_akbar at hotmail.com
> Date: Wed, 1 Jul 2009 15:34:20 +0000
> To: jab at pobox.com, steve at vance.com, perforce-user at perforce.com
> Subject: RE: [p4] Writing triggers with p4.net ?
>
>
>
> You say triggers shouldnt 'have any side-effects except the return-code and
> error-string'.
>
>
>
> Then how would I do the following?
>
>
>
> What I wanted was, if a user submits a particular file, I would like to
> edit some client files and apply the same changes to those, in an
> automated way. So my plan was to write a trigger, check to see if developer
> is making change to this file and if he his, make this change to the client
> files. If triggers is not the way, then what do I use?
>
>
>
> CC: steve at vance.com; perforce-user at perforce.com
> From: jab at pobox.com
> To: naim_akbar at hotmail.com
> Subject: Re: [p4] Writing triggers with p4.net ?
> Date: Wed, 1 Jul 2009 08:01:14 -0700
>
> Read up on triggers using simple examples, first. You're making a couple
> of mistakes: (1) Don't try to change a file to be checked-out or labeled
> or anything like that, as part of the trigger script. (2) What is that
> triple-slash in those pathnames?
>
>
> In general, think of any trigger (there is one trigger subtype that is an
> exception to this, but "checking consistency during submits" is not one of
> those) as having NO side-effects except the return-code and error-string.
> The most a trigger should do, to assure that it doesn't confuse the server
> or you, is return that something is allowed or not allowed. (What if a
> second trigger runs on the same files for the same submit, and fails?
> Shouldn't the end-result be the same as if they had never been run, since
> the submit is failed? That is one of the two main reasons for "no side
> effects.")
>
>
> A trigger to check that files exist, or are being submitted together, etc,
> should not need to connect to Perforce except -- perhaps -- to run "p4
> describe -s 12312312" or "p4 files @=12312312" for a specific changelist.
>
>
> You return success/fail with a zero/non-zero status; error messages in the
> output are copied to the user.
>
>
> Do yourself a favor. Write the following 2-3 simple triggers, first:
> - "files whose name match //main.br/WebSite/....bak will hit a trigger
> that immediately exits with a fail-status." (This is a simple one, not
> useful for a real environment, but it will show you that triggers are
> really a two-step mechanism-- the entry in the triggers table that matches
> the filenames you want to run the trigger against (and when/why), and the
> source code. The source code for this one will be, likely, 1-3 lines.
> - "If you did not include the word 'fixed' in the change description for
> files checked into //main.br/WebSite/..., it'll fail." (Do it as a separate
> trigger, to be able to easily compare. The source code for this will
> include a single connection to Perforce and a single command that it then
> parses the output of.)
> - "If you checked in x.java but not x.class, the trigger fails; if you did,
> it succeeds. This goes both ways - x.class requires x.java." (This is the
> same as the previous one, but you need the file-list and need to match up
> filenames to subordinate files. This is where the Perl/Python/Ruby
> dictionary-lookup hash arrays are so handy, since you can just make an
> entry for each filename in the changelist and then use that
> dictionary-lookup hash array as a way to QUICKLY answer the question, "is
> this filename on the list?" as you rescan the list making sure the matches
> are included in the change.
>
>
> The above three are fairly easy, and will lead you to understand the steps
> a bit more.
>
>
> Lastly: if you have more than a small number of developer work/files in
> those Perforce databases of yours, let's say enough that your check-point
> tales more than 5-10 minutes, try to avoid adding trigger-table and
> protect-table entries on the production server until you've slept with the
> docs for a while. There's a particularly expensive way you could
> accidently configure a trigger-table or a protect-table to eat your
> performance, and you'll want to avoid that on larger servers.
>
>
> -Jeff Bowles
>
>
> (ps. I'm referring to "double-wild cards" in the protect-table and
> "different, multiple triggers with the SAME expensive prologue, run against
> the same changelist for the same event." There are workarounds for both
> cases.)
>
>
>
>
>
>
>
>
>
>
> On Jul 1, 2009, at 7:30 AM, Naim Akbar wrote:
>
> Thanks for your reply..
>
> I have tried using P4.net. I have also created a trigger on the file I am
> intrested in. If I add some exception handlers in the code, then the file
> submits ok. If I leave out exception handling then I get the message "
> Submition failed ", 'Trig validation failed: No error message". Plese see
> my trigger and the code below. I have also added a file writer class, but
> nothing gets written which makes it seem this bit of the code is not hit.
>
> What is wrong with the way I am doing it.?
> Why is there no file output...Is this part of code being hit?
> What do I have to return to indicate pass or fail ?
> How do I raise an error message?
>
>
> Here is my trigger
>
> Trig change-submit "///Misc
> Tools/PerforceClassLibrary/PerforceClassLibrary/PerforceClassLibrary/Propert
> ies/AssemblyInfo.cs" "c:\debug\ConsoleApplication1.exe %changelist%"
>
> Here is my main class
>
> class Program
> {
> static void Main(string[] args)
> {
>
> FileInfo t = new FileInfo("C:\Trigger.txt");
> StreamWriter Tex = t.CreateText();
> Tex.WriteLine(args[0]);
> Tex.WriteLine("Collin has launced another article");
> Tex.WriteLine("csharpfriends is the new url for c-sharp");
> Tex.Write(Tex.NewLine);
> Tex.Close();
>
> Perforce f;
> f = new Perforce("Naim", "MyCom");
> f.CreateConnection();
> string[] files = new string[2];
> files[0] = "///main.br/WebSite/WebUI/MINT Version.txt";
> files[1] = "///main.br/WebSite/WebUI/WebProfile.cs";
> int number = f.OpenFileForEdit(files, "This is a change to the following
> files"); //proven method that opens these two files for edit
>
> }
> }
>
> Thanks,
> Naeem
>
>
> > Date: Wed, 1 Jul 2009 07:31:43 -0400
> > From: steve at vance.com
> > To: naim_akbar at hotmail.com
> > CC: jab at pobox.com; perforce-user at perforce.com
> > Subject: Re: [p4] Writing triggers with p4.net ?
> >
> > Sure you can use .NET. You can use any language that can be run like an
> > executable. There is a COM API which I think can be called from .NET.
> > You can get that on the Perforce web site.
> >
> > As for examples, take a look at the Perforce Public Depot. Jeff Bowles
> > has excellent examples in //guest/jeff_bowles/... and many other people
> > have examples, probably some in .NET. There have been conference papers
> > on how to write triggers and scripts (see the presentations by Jeff and
> > I from 2005). Perforce and the PCTs also have a scripting class for a
> > more individual bit of guidance.
> >
> > Steve
> >
> > Naim Akbar wrote:
> > > So you cant use P4.NET to right triggers?
> > >
> > >
> > >
> > > If I was to use Perl, then where would I start. Ome sample code would
> be useful.
> > >
> > >
> > >
> > > Many thanks,
> > >
> > >
> > >
> > >
> > >
> > > Date: Tue, 30 Jun 2009 15:15:36 -0700
> > > Subject: Re: [p4] Writing triggers with p4.net ?
> > > From: jab at pobox.com
> > > To: naim_akbar at hotmail.com
> > > CC: perforce-user at perforce.com
> > >
> > > I'd use Perl, if I was at the level of asking where to start.
> > >
> > >
> > > I like Python / Ruby better, but you can quickly and easily do it.
> > >
> > >
> > > Step #1: write the trigger table entry, to fire ONLY on submits of
> files that match certain patterns. That will do the "scan" to see if the
> submit affects any part of a list of files.
> > >
> > >
> > > Step #2: Start with a trivial script that just writes its arguments to
> a debug-log somewhere and returns a SUCCESS error code. (See the docs or
> "p4 help triggers" for that.)
> > >
> > >
> > > Step #3: Change the script to look for subordinate files, using
> whatever rules you like. ("any checkin of x.java must also include
> x.reference.logs" is a good, trivial example).
> > >
> > >
> > > Step #4: Document this. Make sure the trigger(s) are backed up as part
> of your backups.
> > >
> > >
> > > Step #5: Try the ugly testing process: "what if x.reference.logs is
> submitted, as above, but not the java file?"
> > >
> > >
> > > I would not do it in a compiled language like Java or C or C++, since
> the number of steps / overhead to iterate over the programming is higher
> and because it might make other assumptions about the environment. (Java:
> classpath; C or C++: DLLs. Perl: weird CPAN libraries. And so on) So, mind
> your dependencies.
> > >
> > >
> > > -Jeff Bowles
> > > ---
> > > Jeff Bowles - jeff at vizim.com
> > >
> > >
> > >
> > > On Tue, Jun 30, 2009 at 2:17 PM, Naim Akbar <naim_akbar at hotmail.com>
> wrote:
> > >
> > >
> > > Hi there,
> > >
> > >
> > >
> > > I was just wandering whether it is possible to right perforce triggers
> with P4.Net. If so, how would I call this assembly from within the triggers
> table. If not what other scripting langauge do I use...
> > >
> > >
> > >
> > > My goal is: On a perforce submit of a file, I want to check if this
> file is in a list of particular files. If it is then I would like to submit
> a few other files. If not, then do nothing and carry on.
> > >
> > > Many thanks,
> > >
> > >
> > >
> > >
> > >
> > > _________________________________________________________________
> > > Get the best of MSN on your mobile
> > > http://clk.atdmt.com/UKM/go/147991039/direct/01/
> > > _______________________________________________
> > > perforce-user mailing list - perforce-user at perforce.com
> > > http://maillist.perforce.com/mailman/listinfo/perforce-user
> > >
> > >
> > > _________________________________________________________________
> > > Share your photos with Windows Live Photos – Free.
> > > http://clk.atdmt.com/UKM/go/134665338/direct/01/
> > > _______________________________________________
> > > perforce-user mailing list - perforce-user at perforce.com
> > > http://maillist.perforce.com/mailman/listinfo/perforce-user
> > >
> > >
> >
> > --
> > Stephen Vance
> > www.vance.com
> >
>
>
>
> Beyond Hotmail — see what else you can do with Windows Live. Find out more.
>
> _________________________________________________________________
> Get the best of MSN on your mobile
> http://clk.atdmt.com/UKM/go/147991039/direct/01/
>
> --------------------------------------------------------------------
> mail2web LIVE – Free email based on Microsoft® Exchange technology -
> http://link.mail2web.com/LIVE
>
>

_________________________________________________________________
With Windows Live, you can organise, edit, and share your photos.
http://clk.atdmt.com/UKM/go/134665338/direct/01/
_______________________________________________
perforce-user mailing list  -  perforce-user at perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user



_________________________________________________________________
Get the best of MSN on your mobile
http://clk.atdmt.com/UKM/go/147991039/direct/01/


More information about the perforce-user mailing list