March 26, 2012

Back-in-Time with Streams

Healthcare
Streams

Perforce streams let you capture important information about what actually goes into a codeline. Using stream paths, you can select active modules (modules that are branched and worked on), import other modules as read-only dependencies from the parent stream, and so on. (For more information on stream paths, read this post by Laura Wingerd.)

Of course, the stream paths may change over time. Let's say that originally you were importing version 1.0 of an external library, so you had a statement like this in your stream definition:

    import acme/... //depot/acme-lib/rel/1.0/...

At some point there's a 1.1 patch for this library that you want to work with, so you pull in that new version instead.

    import acme/... //depot/acme-lib/rel/1.1/...

Now let's think about how to reproduce the state of this codeline in the future. Maybe I shipped an important milestone as of changelist 100, and at that time I was using the 1.0 version of acme-lib. If I create a workspace for this stream and run p4 sync @100, I won't really have an accurate snapshot, because I'll be seeing the newer 1.1 version of acme-lib.

In other words, I need to not only sync to older versions of files. I need to use the older version of the stream definition, so that I get the 1.0 version of acme-lib.

The stream specs are versioned (in a couple of places if you use the spec depot), but using that information wasn't terribly easy until now. In the 2012.1 release, you can now include a changelist number in the stream field of a workspace definition:

    Stream: //stream/mystream@100

As a shortcut, you can also run:

p4 client -s -S //stream/mystream@100

Now when I run p4 sync in that workspace (with no arguments), I get both the file versions that existed as of changelist 100, and I'll be using the stream spec that existed as of changelist 100. That means that I'll be using the older 1.0 version of acme-lib, so I'll have an accurate reproduction of this codeline in my workspace. I can then track down bugs, run old test suites, and perform other data mining.

Being able to reference an older version of a stream in a workspace is a small but significant improvement in using Perforce streams. Try it out in our 2012.1 Beta.