How to change perforce specs from command line?
What I want to do is, I have a workspace whose clobber option is set to noclobber (default value). Now I want to change it to clobber.
I know I can do it directly from p4v, but I don't want that. I also know that if I run p4 client, it will open P4CONFIG file in text editor, where I can change noclobber to clobber and save the file and it's done, but I also don't want that.
Please tell me the specific command which directly changes noclobber to clobber without using p4v or without editing P4CONFIG.
If you're trying to avoid repeatedly opening a text editor, you can accomplish your goal with a little bit of sed, like this:
p4 client -o | \
sed 's/ noclobber/ clobber/' | \
p4 client -i
It's pretty easy to script this with Perl, Python, Ruby, or even Powershell. Here's a one-liner in Powershell:
p4 client -o | %{$_ -replace "noclobber", "clobber"} | p4 client -i
Simplest solution:
P4EDITOR='sed -i s/noclobber/clobber/' p4 client
Related
I need to change filetype to add write permission (+w) to a lot of files under a root folder. I found the following command to remove +w; somebody knows how to change it to add +w instead of remove it?
Thanks in advance
p4 -F "%type%#%depotFile%" files ... | grep -e ".*w.*#.*" | sed -e "s/\(.*\)w\(.*\)#\(.*\)/edit -t \1\2 \"\3\"/" | p4 -x - run
No need for fancy grep/sed shenanigans when you're adding a modifier, since you can specify it directly to p4 edit -t:
p4 edit -t +w ...
Note that there's a reason the writable bit isn't set by default on files under Perforce control -- it makes it really easy to lose work by forgetting to open files for edit! I usually recommend only doing this for generated files where the cost of forgetting to check them in is low relative to the minor annoyance of having to remember to open them for edit before you compile.
I need to get the local path of a depot file, for example:
input: //MyDepot/MyBranch/my file.txt
output (mac): /Volumes/p4/MyDepot/MyBranch/my file.txt
or:
output (windows): F:\p4\MyDepot\MyBranch\my file.txt
both 'p4 have' and 'p4 where' produce parse-unfriendly output, including mapping info I don't need. Is there a p4 command for that simple task?
On a non-Windows OS, Run:
p4 -ztag -F %path% where <depotFilePath>
This will give you the one-liner with only the local path.
On Windows, %path% expands to the system environment path so this only works on non-Windows systems.
The -F is a client-side option, so if you don't have it, you may need to update your p4 binary. If you don't have it, and can't update the binary, you can also just run p4 -ztag where <depotFilePath>.
You'd get back easy to parse output. The key is path to get the local path to the file.
The output will look like:
... depotFile //depot/a
... clientFile //gabe/a
... path /Users/gabe/tmp/a
Very close, Samwise. I would have made this a comment on the main answer, but not enough rep yet, sorry.
To prevent Windows from expanding the environment variable, both percents need to be carrot escaped, and that part of the expression must not be in quotes.
example: p4 -ztag -F ^%change^%,^%time^%,^%path^% changes -m 3
example from 2020/4/2: https://community.perforce.com/s/article/15148
Is it possible to use variables defined in P4CONFIG files in p4 commands? Let's say I want to define an alias for quickly seeing pending changelists in the current workspace. So something like:
p4 changes -s pending -c $P4CLIENT
I don't want to define P4CLIENT in my bashrc as I switch between different workspaces a lot. I much prefer it to come from the current P4CONFIG file. Is that possible?
This should do it:
p4 -Ztag -F %clientName% info | p4 -x - changes -s pending -c
Note that you need a relatively current p4 client to use the undoc -F flag, which is described more here: http://www.perforce.com/blog/130826/fun-formatting
You could also script something around "p4 set P4CLIENT", which is a purely client-side query and therefore a bit faster, but you'll need to manipulate the output a bit to make it suitable as an argument to "p4 changes".
After a while of working with perforce I was left with a lot of still open change lists.
To clean up I want to get rid of a subset of them.
So here is what makes this complicate:
For a subset of the changes the host of the client has changed.
Some changes contain shelved files.
Files from the change list may be deleted or moved.
When one or more of above points are true for a change list, p4v (the visual client) will not allow you to delete the change list.
So what is an effective way of deleting these change lists?
First of all, perforce refuses to work on any change lists if the host differs in their workspace. So step one is to change the host of the workspace to the current one. This can easily be done with the visual client p4v. Open the properties of a workspace, choose edit and change the host.
Then you can use the command line to get rid of the pesky change list(s):
# to delete a changelist
CLIENT="name_of_your_client"
CHANGE="number_of_the_changelist_to_delete"
p4 -c $CLIENT shelve -c $CHANGE -d //... # Delete all shelved files from it.
p4 -c $CLIENT revert -k -c $CHANGE //... # Revert all files from changelist (only metadata).
p4 -c $CLIENT change -d $CHANGE # Finally delete the changelist.
After the last command the change list will be gone forever.
Fixing the hostname can be done from the command line like this:
client_hostname="$(p4 client -o ${CLIENT} | grep "^Host" | awk '{print $2}')"
p4 client -o ${CLIENT} | sed "/^Host:/ s=${client_hostname}=${HOSTNAME}=" | p4 client -i
Had the same problem some time ago and wrote a script (p4-delete-changelist) that overcomes all of these problems (and another one - deleting p4 fixes).
Note that the script depends on another file in the repository.
p4 changes -l ... shows us the list of check-ins and the description, but it doesn't show the list of files that were modified in the check-in. Is there a way to do that in one command, without the need to create a wrapper script that combines the output of another command like p4 describe or p4 file?
In Subversion, I can do this by running svn log -v.
The 'files' command can do what you're looking for. An easy way is:
p4 files //...#=<changelist>
That example will list the files modified by that changelist, under the view specified.
You can use the "describe" command to get the description of a changelist, along with the files affected.
For example, p4 describe -s <changelist> will describe the changelist, and the "-s" will prevent it from displaying file diffs.
One liner, list all changes made to a branch, with description and list of affected files, without showing the diff. Thanks to a combination of answers. Works on windows with Unix utils
p4 changes -s submitted //depot/xxx/yyy/zzz/... | grep -o "^Change [0-9]*" | cut -f2 -d" " | p4 -x- describe -s
Output:
Change 1753385 by user#clientspec on 2019/03/08 06:29:44
Changing the world
Affected files ...
... //depot/xx/yy/zz.h#6 edit
Change 1751752 by name#clientspec on 2019/03/05 15:24:00
I made a change to a file
Affected files ...
... //depot/xx/yy/zz.h#3 integrate