Creating a remote from an already existing depo

0

Posted by Jaime | Posted in Coding, DevOps | Posted on 30-10-2016

Tags: , ,

Today, I created a remote depo, so that I can use the DVCS functionality in P4 with one of my projects.

First, I connected to my perforce server and typed:

$p4 remotes

To see all of the remotes that were on the server. Before doing this command you have to type:

$p4 login

Which thankfully, my username on the linux server is the same as my username in the Perforce server so I didn’t have to type that again.

Once I was logged in and saw that there was no remote set up for the project I wanted to use with DVCS, I typed:

$p4 remote PROJECT_CODE_NAME

This brought up NANO (I know some of you out there are rolling your eyes) and I modified the //local/… //remote/… paths to my liking. Remember, the left side represents the local depo representation on your computer and the right side of that mapping is the remote depo representation that is on your Perforce server.

Now, in another terminal, I typed:

$cd PATH_WHERE_YOU_HAVE_YOUR_DEVELOPMENT_WORK
$mkdir PROJECT_CODE_NAME
$cd PROJECT_CODE_NAME
$p4 -u jaimerios clone -p 192.168.1.10:1666 -r PROJECT_CODE_NAME

The last command then takes the files specified in the mapping and clones it to your local filesystem.

You can check that the origin server is set up by typing:

$p4 remote -o origin

Now, in my project, I had two read-only depos in my Perforce server that was for the Boost headers and the Google gtest framework libs.

For those normally import+ folders, I created a symbolic link to those folders that were already on my local filesystem:

$cd PROJECT_CODE_NAME/libs
$ln -s /Users/jaimerios/Development/Perforce/READONLY/libs/Boost ./Boost
$ln -s /Users/jaimerios/Development/Perforce/READONLY/libs/Google ./Google

And so far, everything seems to work well … except there are a few files I want p4 status to ignore, so:

$cd PROJECT_CODE_NAME
$nano .p4ignore

I added some folders and files to ignore and life is good.

So, onto happy coding 🙂

How to install Perforce DVCS

0

Posted by Jaime | Posted in Coding, Tools, Utility | Posted on 20-09-2016

Tags: , , , ,

Introduction
For 9 years now, I’ve used Perforce; before that, it was MKD, Subversion, VisualSourceSafe, CVS and a few others.

In the past year, I used Git.

One cool thing that Git has that Perforce didn’t have was being able to save your changes while not being connected to a central server.

However, Perforce recently added native DVCS to their source control tools so, checkouts and submits are now possible while offline.

Here are the steps you need to take if you want to use Perforce DVCS on your computer. Note, I’m using macOS, so my instructions are for that platform only.

Installation steps
Step 1: download Helix server at https://www.perforce.com/downloads/helix
You will need both p4d and p4 command line utilities, so head over to https://www.perforce.com/downloads/helix and download the “Helix Server” for your machine.

Step 2: Double-click the tar file to extract it
I think this step speaks for itself; on my computer I was able to double-click the tar file and everything appeared in a new folder.

Step 3: Make a folder for the binaries to live in
I created a bin folder in ~/Perforce/. I happen to have a dedicated Perforce folder in my home directory that I use for a lot of projects and the bin directory seemed to be a logical place to store the files.

From the command line you can type the following to make the folder:
mkdir -p ~/Perforce/bin

Step 4: Copy the binaries to the bin folder
Copy the p4d and p4 command line utilities to the ~/Perforce/bin folder (or whatever folder you just created)

Step 5: Add the path to the PATH environment variable
I edited my ~/.bash_login file using emacs to add the following:
export PATH=~/Perforce/bin:$PATH

Step 6: Load the Perforce bin path
Relaunch Terminal.app or open a new Terminal Window or source your .bash_login via
source ~/.bash_login

Step 7: Init your offline project
Here is how I got up and running:
cd WATEVA/PROJECT/FOLDER/
p4 init -C1 -n

The extra settings after init tell p4 what case-sensitivity is should use and whether or not to enable Unicode support. If I didn’t add those, p4 would try to find a server to copy those settings from and that won’t work for me.

Step 8: Enjoy
From here, you use the Terminal.app and p4 to perform all of your Perforce commands and enjoy the goodness that is Perforce… like the super-large-file-support-without-choking feature 😉

Aaaargh! Stop auto substituting my text!

0

Posted by Jaime | Posted in Coding, Not-so-funny | Posted on 20-03-2014

Tags: , , ,

Ugh!

I’ve been running into problems with my Jenkins scripts that would fail when attempting to run my p4 commands, because the three periods I inserted into the p4 command were automatically converted to an ellipsis by MacOSX, which is not a good thing: Three dots are automatically changed to an ellipsis

Perforce and Xcode5

3

Posted by Jaime | Posted in Tools | Posted on 06-11-2013

Tags: , , ,

In a previous post, Perforce and Xcode4, I created applescripts to work with Xcode4 and Perforce.

I updated the AppleScripts to work with Xcode5 only and added a couple of new scripts.

One, called p4_file_renamed.scpt, is used to update the renamed file Perforce when you are using Xcodes rename functionality, either directly or through the refactor functionality.

The other two scripts get the filename of the currently selected file or the full path of the file which is useful for when you want to find a file by path in P4V.

You can download the file here: xcode5_p4_applescripts

Perforce and Xcode4

12

Posted by Jaime | Posted in Coding | Posted on 14-08-2013

Tags: , , , , , ,

I created some AppleScripts that allow you to control some basic Perforce functionality in Xcode4, which was lost when Apple released the latest version of their IDE.

Perforce actually published a way of checking out files using the Behaviors functionality in Xcode (Xcode and P4), but I wanted a little more.

Note, these scripts are a work in progress. If you happen to make improvements, let me know so that those changes can be shared with the community.

You can download the AppleScripts here: xcode_p4_applescripts

Update
The AppleScript files are also being hosted on the public Perforce swarm forum, located here: Perforce Public Swarm Server

Update 2013-11-06
I updated the AppleScripts to work with Xcode5 only and added a couple of new scripts.

The new applescript files are referenced in post Perforce and Xcode5

Checking out a file in Perforce using Xcode’s 4 behaviors

1

Posted by Jaime | Posted in Coding | Posted on 27-07-2012

Tags: , , ,

Perforce published a knowledge base article on how to use Xcode’s built in behaviors to check out a file: Automatically checking out files for edit in Xcode 4.3

This is nifty and similar to an article I saw posted on stackoverflow by user Mark Thalman.

Update
I actually have AppleScripts that will do some of the functionality that Xcode3 had with Perforce on this posting: Perforce and Xcode4

Xcode Script Menu and P4

0

Posted by Jaime | Posted in Coding | Posted on 06-06-2011

Tags: , , ,

Here is another way that I am able to check out a file using the Xcode Script Menu and a keyboard hot key:

#!/bin/sh
# This shell script checks out the current file from Perforce
 
# Get the file's path components
FULL_FILE_PATH="%%%{PBXFilePath}%%%"
SRC_FILE=${FULL_FILE_PATH##*/}
FILE_PATH=${FULL_FILE_PATH%/*}
 
# This line brings in my settings so that Perforce knows what server I am connecting to
# This also assumes that the root of my project has a perforce.rc file
source ~/.bash_login
 
if [ -f $FULL_FILE_PATH ]
then
	cd $FILE_PATH
	/usr/local/bin/p4 edit $FILENAME
fi

The “Output:” and “Errors:” options were set to “Display in Alert”, not that this is actually applicable here, but that’s how I have it set up.

And here is what my .bash_login file looks like:

# Perforce settings                                                                                                                         
export P4CONFIG=perforce.rc
export P4PORT=mysuperawesomedomain.com:1666
export P4USER=jaimerios
export P4EDITOR=emacs
export P4PASSWD=haaaahahahaHahaHAA!

Oh, and if you want a good starter for how to work with the Script Menu scripts in Xcode, check out this site: http://www.mactech.com

Xcode 3.1 and Perforce

1

Posted by Jaime | Posted in Coding | Posted on 07-03-2009

Tags: , ,

I use Perforce and I love it! Over the years I’ve used Visual SourceSafe, CVS, SVN and I experimented with other tools, but none of them have come close to the usefulness of Perforce.

I also use Xcode for my Mac coding but when you use Xcode with Perforce, you get some wierd behaviour. Xcode get’s hung, for no reason whatsoever and although Apple seems to know this is a problem, it doesn’t seem like they are fixing this problem any time soon.

Lucky for me you can use AppleScript from within Xcode! I usually work on one project at a time, so I can create an AppleScript that checks out the frontmost project file for me and another AppleScript to check out the currently selected source code file.

When you open Xcode you’ll notice an AppleScript icon in the menubar between Window and Help, but this is not an AppleScript drop down. This is just for the General Scripts that can be invoked from Xcode. So, if you want to run a shell script from Xcode, you can use this scripts menu for doing that, but for me, I wanted to leverage AppleScript for what I want to do.

You think this is for AppleScript, but it's not.

So, to make the AppleScript menu available, you have to open the AppleScript Utility in “/Applications/AppleScript/”. Open that program and click the “Show Script menu in menu bar” checkbox.

Use this to make the Script menu available

Once you do that, you should see an AppleScript menu item by the other icons on the left side of your menubar.

Now, open the “Script Editor” program within the “/Applications/AppleScript” folder. Copy the code below, which attempts to check out the frontmost project file from Perforce:

?View Code APPLESCRIPT
-- Check out the frontmost project
tell application "Xcode"
set myProj to (active project document)
set myCmd to full path of myProj
end tell
 
set myCmd to "/usr/local/bin/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit " & myCmd & "/..."
 
do shell script myCmd

Basically, the script gets the frontmost project file, sets a variable to the full path to the project file and then I create a string with the command that I would normally invoke in Terminal.app. The changes you need to make to the command line are:

  • The -c option which tells p4 which client you are working in
  • The -p option which is the name, or ip, with TCP port to the perforce server
  • The -P option which is your password to the server and
  • The -u option which is your username

Notice that I don’t have a space between the switch and the value and that I have the full path to p4 spelled out.

Paste the code into a new script in “Script Editor” and save the script, with the name of your choice, into the “/Users/jaimerios/Library/Scripts/Applications/Xcode” folder. Once you go back to Xcode, you will see your script in the menu item.

Now the following script is almost the same thing, except for it checks out the current file that is selected in the project. Repeat the same steps for creating the project check out script for the script code below:

?View Code APPLESCRIPT
-- Check out the currently selected file
tell application "Xcode"
 
set myFile to associated file name of front window
set textDocuments to text documents
repeat with i in textDocuments
if path of i is myFile then
 
set myCmd to path of i
set myCmd to "/usr/local/bin/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit " & myCmd
do shell script myCmd
end if
end repeat
 
end tell

I hope these scripts help you out. If you have any suggestions for making these scripts better, post a comment and let me know.

Happy coding!