What will this command do: p4 sync //depot/proj1/ - perforce

I am new to Perforce and want to create a automated tool to get the latest revision by itself. I have a mapping like this:
P4CLIENT: Proj_name
Worspace root direcctory: C:\...\Proj_name
Stream: Build
Now what i desire is it should get latest revision of all files from:
Build\fold1\fold2 to C:\...\Proj_name\fold1\fold2
When I just ran p4 sync command, it copied all files from Build to C:\...\Proj_name.
So please tell how to specify the folder path from where to get the latest revision. Will the command p4 sync //depot/proj1/... work for me and how does it change in my condition ?

You use the View: section of your client spec to describe which parts of the overall repository you wish to work with, and where those files should be placed on your workstation's filesystem.
In your particular case, to specify the folder path, as well as where those files should be placed, you might specify your View: as something like:
View:
//depot/Build/fold1/fold2/... //Proj_name/fold1/fold2/...
You may have considerably more complex view mappings; the view syntax is quite powerful. To learn more about view mappings, type p4 help views.
After you change your View: specification for your client, run:
p4 sync
The sync command will notice that you have changed your view mapping, and it will re-arrange the files in the root of your client on your workstation, so that they are arranged as described by your new view mapping.
If you don't wish to sync your entire client, you can specify a subset of the files which should be sync'd, by naming that subset of files using a file pattern as an argument to the sync command:
p4 sync //depot/Build/fold1/fold2/*.cpp
However, that can be quite confusing, and I recommend that, to start, you avoid using that advanced usage, and stick to performing a p4 sync with no file arguments, at least until you get more comfortable with how p4 sync is used. For one thing, when you are sync'ing different subsets of files with different file arguments, it is quite easy to get your workstation's filesystem into an un-buildable state, by getting half of the files from one changelist and half from another, which will cause you to have code that doesn't compile, etc.
So, for now:
Consider which parts of the repository you wish to work with, and where you want them to go on your workstation's filesystem
Run p4 client and describe the appropriate View: line(s) to specify those files, using the pattern-matching syntax of the View: field
Run p4 sync and Perforce will put those files on your computer as specified.

Related

In Perforce, how to get latest version of a binary file (like Excel file) safely, without overriding my local copy?

I use Perforce to manage a project that contains some binary files (Excel, Word and Visio diagram files).
I'd like to know the safe way to update my local version of such files from the latest version available on Perforce, without corrupting/damaging/overriding the local changes. (Local changes are made locally and not submitted to Perforce yet)
Locks don't seem to solve the problem because it helps only in concurrent submission of files.
p4 reconcile to make sure that any local changes are correctly reflected in your pending changelist(s).
p4 sync as normal. Opened files will not be overwritten by a p4 sync.
If you're following the standard Perforce workflow of always opening files for edit before you modify them (i.e. you never override the "read-only" flag on your local files), you can skip step 1 and just sync at any time without fear.
p4 resolve to handle any files that have been modified both locally and in the depot.
Note that Perforce's built-in merge logic will only handle text files, and so resolve will by default offer only a binary yours/theirs choice for binary files (at will overwrite your local changes, and ay will ignore the depot changes). If you have a merge tool that can handle your binary format, you can do:
p4 set P4MERGE=your_merge_tool
p4 resolve -t
m
to invoke your merge tool as part of the resolve process. See the documentation on the P4MERGE variable for more information how this tool will be called (you may need to wrap it in a script if it doesn't follow the base theirs yours merged calling convention): https://www.perforce.com/manuals/v17.1/cmdref/Content/CmdRef/P4MERGE.html

List changes in a directory using perforce

New to perforce (and stackoverflow). I'm trying determine what has changed in my local view: I want to list all the recent changes under a directory in my workspace.
Perforce documentation seems to suggest everything is file based. Is there not a simple solution that does not require either probing each file individually and recursively down the directory tree, or filtering and processing changelists (multiple projects are sharing the same depot in my case)?
Ideally, I'm looking for the SVN equivalent of "svn log -v" (i.e., no path specification).
I'm also looking for a command-line solution.
Take a look at p4 changes and the documentation.
There are some examples, which might already help you. Moreover there are some global options, which you can use to specify the client, port, etc.
You are probably looking for something like
p4 changes -m 5 -s submitted //depot/project/..., which return the last 5 submitted changelists under the given depot path.
To see the last N changes under a particular workspace directory, do:
p4 changes -m N path/...
Note that path/... can be a relative local path, an absolute local path, or an absolute depot path. This is true for almost any Perforce command that accepts a file argument -- if you can specify one file you can usually specify an arbitrary pattern like "foldername/...", and you can usually specify it in either local or depot syntax.

How to handle git-p4 with special workspace mapping [duplicate]

What is the proper method to do a selective import of a large Perforce repo?
The git-p4 docs mention that you can do a -//depot/main/ignore switch to filter directories. Would this be equivalent to running a git filter-branch to remove the same directories after a clone?
Additionally, it appears Perforce provides another feature called a "client" view. I have not used Perforce before, so I am a little unfamiliar with the usage model. My current understanding is that one would use p4 somehow to setup a proper client view before running git p4 clone. Does anyone have the complete details?
A Perforce clientspec determines what parts of the Perforce repository are visible (and will be synced) to the Perforce client. The clientspec also provides a mapping from Perforce repository paths to local paths.
You can prune a Perforce client by selectively including parts of the Perforce repository. For example
//depot/main/path1/... //your-perforce-client/main/path1/...
//depot/main/path2/... //your-perforce-client/main/path2/...
will include only //depot/main/path1/ and //depot/main/path2/ and not //depot/main/path3/. As you've noted, you also can explicitly exclude paths. For example
//depot/main/path1/... //your-perforce-client/main/path1/...
-//depot/main/path1/foo/... //your-perforce-client/main/path1/foo/...
will include everything in //depot/main/path1/ except files under its foo subdirectory.
Depending on how your Perforce repository is structured and depending on what you want to include (or exclude), you potentially could tell git-p4 directly which parts of the Perforce tree you want to import:
git p4 clone --destination=/path/to/new/git/tree //depot/path1 //depot/path2
If you want to use exclusions or if you want to adjust how Perforce depot paths are mapped to local paths, you will need to add the --use-client-spec option. You can configure which Perforce client should be used by creating a .p4config file in your Git tree's parent directory containing:
P4CLIENT=YOUR_PERFORCE_CLIENT_NAME
and then setting an environment variable:
P4CONFIG=.p4config
Doing this will cause p4 to look for a .p4config file in the current directory (and then progressively search parent directories) for Perforce configuration data.
The files that will be imported will be the intersection of paths included by the Perforce clientspec and by the paths explicitly provided on the git p4 clone command-line.
(As you mentioned, git-p4 clone does allow excluding paths by prefixing them with -. However, I do not recommend doing this because that means that those paths will be excluded only on the initial import. If files in that path are touched in Perforce in the future, performing git p4 rebase/git p4 sync will pick up those changed files (unless you remember to explicitly exclude them on the command-line again). Initially importing using --use-client-spec, however, will set a flag in .git/config that allows it to be honored automatically when using git p4 rebase/git p4 sync in the future.)
One caveat is that performing a selective clone will add extra complication if someday you want to include other parts of the Perforce repository. See my answer to "Extending git-p4 clientspec after initial clone" if you need to do that.

Perforce Change List too Big

In Perforce, I have created a change list that has over 200,000 files (by doing a rename on a directory). This change list is now too big to submit or revert. When I try, I get an error saying that the operation took too long.
I am now stuck with this change list that has my original directory in marked for delete state and a new directory that hasn't been submitted. Is there a way undo this change list?
You can revert the files a few at a time. As a test, you could run p4 revert //path/to/some/file and verify that it's able to revert that file.
Once you know that's working, you just need a way to automate the process.
You could script something up that starts in the root directory and runs through all directories breadth-first, running p4 revert //path/to/folder/* at each folder (I think you could also use client paths).
You can revert via the command line using the p4 tool. I do not think you can revert the files from the UI. The associated documentation shows various examples of how revert all or specific files (see the Examples section):
http://www.perforce.com/perforce/r12.1/manuals/cmdref/revert.html

p4 sync, how do you exclude files while using wildcards?

I'm trying to use p4 sync to sync a specific directory to a given changelist number using wildcards but I also want to exclude a list of files that are under that directory (in subdirectories), I tried using - (both before and after using a path with wildcards) but the file never gets excluded, this the command I'm trying:
p4 sync //Repo/Foo/... -//Repo/Foo/Bar/Foobar.txt
The file exclusion seems to only work when the files/directories you are syncing don't match the files you're trying to exclude.
In your client, you would have multiple lines:
//Repo/Foo/... //my_client/Repo/Foo/...
-//Repo/Foo/subdirectory/... //my_client/Repo/Foo/subdirectory/...
This would allow you to get everything in the Foo directory and all subdirectories except "subdirectory".
You can do this if you use a label. Create a label in your favorite editor (p4v or command line p4 label and add your two lines:
//Repo/Foo/...
-//Repo/Foo/Bar/Foobar.txt
In the revision field put "#head" (including quotes!) if you want the latest or a change list number. Give the label a name - for instance "sync_butnot_foobar"
On the command line you can now sync:
p4 sync #sync_butnot_foobar,#sync_butnot_foobar
This has a huge benefit over the modify your client spec and sync head model. If you exclude a file in your client spec, the next time you sync that file will be brought to revision 0 which probably isn't what you wanted.
In short, you can't exclude files on a sync. That can only be done within the client spec. (Well, it could be done through the protections table, but that is really a different matter I think).
But if you want to sync a specific folder and only the files in that folder, use *
p4 sync //Repo/Foo/*
will get you only the files in the Foo folder.

Resources