August 4, 2015

Secrets of the Local Workspace Ninja

Media & Entertainment

Maybe you’re a *nix guru but you’re stuck with the Windows computer your company provides. Or perhaps you’re a Windows guru but your current project mandates Cygwin. As one might expect, the Mac runs a third wheel over this whole picture.

Levity aside, folks working in mixed OS environments are often all too (painfully) familiar with a variety of issues sharing and working on files. I was reminded of that during a recent customer conversation about line-ending characters. Said customer was unsatisfied with the Windows approach (carriage-return followed by line-feed) and longed for the simplicity of *nix (just a simple carriage-return).

Long time users may be forgiven for immediately blurting out “Workspace!”, a term of art that has traditionally referred both to a conceptual object stored on the server and to the local directory on a client workstation. For the sake of new users, particularly those evaluating our new DVCS features, I thought I’d explain how workspaces remain useful and relevant in the DVCS era.

I’ve already written about how easy it is to get started with our DVCS features, explaining how a single “p4 init” command will create a new local repository. What I didn’t mention at the time was that part of the process is the creation of a new, local-only workspace under the hood. Most users don’t need to know or care, but it’s good to know when you need to do something special.

Coming back to the previous example, line endings are one of the things controlled by the local workspace specification. By default, initializing a new repo or cloning from a remote server will give you line endings consistent with your current platform. But you can easily customize this behavior (and a number of other aspects) simply by editing your local workspace.

How do you do this? Just execute a simple command:

p4 workspace

Whatever platform you’re on, this will invoke an editor to let you tweak the local workspace specification.[1] In the particular case of line endings, you have a variety of settings from which to choose as explained in our knowledge base. Once you’ve changed line-ending settings you must force a sync to update the local files with the new values as follows:

p4 sync -f

That’s how simple it is to change your line-ending (or other) workspace preference. There are a number of other settings you can customize for the local workspace as well, so feel free to experiment and/or consult the latest documentation. The secrets of the local workspace ninja are yours for the taking!

[1] The specific application launched depends upon the P4EDITOR variable, more information on this is available here.