问题
Q: what is the perforce equivalent for the status command of other version control tools?
E.g. git status
or hg status
or bzr status
or svn status
? (Confusingly, cvs update -nq
is the closest thing for that version control system.)
Hint: it is NOT p4 status
.
First, p4 status
does not tell you about files that are on pending changelists. You need to call p4 opened
for that, but the output format is quite different.
Second, p4 status
is not always a read-only status command. I think that the perforce version I was using at the time I originally posted this by default actually changes the state of the workspace - it actually adds local changes to a pending changelist. But I may misremember. That company used a very old version of perforce. As of the time I am updating this, using a perforce client version dated 2014/04/08, the default p4 status
behavior is read-only, but take care not to use the -A
option if you don't want to make changes to the workspace.
It looks like some combination of p4 status
and p4 opened
is needed to get the bare minimum of what the other VCSes do in a single command.
DETAIL:
Most version control systems have a command that can quickly tell you the status of a workspace. Information such as:
- what files are checked out for editing (if the VCS uses checkouts)
- which of those checked out files have been locally changed or deleted
- which files have been changed even though NOT checked out
- e.g. which files may have changes that you want to merge
- possibly which files are more recently updated in the repository than in your workspace
- e.g. changes that you may want to merge into your workspace
- what files are in the workspace but are not (yet) under version control
- e.g. which files you may want to add to the version control system
- or possibly add to your .hgignore/.gitignore/... ignore file patterns
- what files are under version control but are not in the workspace
- e.g. which files you may want to delete from your version control system
- or which files you may have accidentally deleted
Exactly what status information is provided depends on the VCS. E.g. Perforce is checkout based, but most modern version control tools are not.
But... nearly all version control tools have a single, simple, command that will tell you such status.
Except, apparently, perforce.
... I may go on to provide examples of what git/hg/bzr/svn status do in a single command, but which perforce seems to require at least two commands to provide.
回答1:
I keep saying that I dislike answering my own question, but I am going to do this here. I welcome anyone who wants to share better solutions and scripts. I would especially welcome somebody showing me that this is unnecessary, that Perforce actually does have the equivalent of svn/git/hg/bzr status
.
---+ A: git/hg/bzr/svn status
= p4 opened
+ p4 status
In perforce at least two separate commands seem to be required to approximate what other VCS tools do with a single command, to provide a quick summary of the status of the workspace wrt the depot:
p4 opened
- for a list of files that you have opened in the workspace
p4 status
- for a list of files not checked in to Perforce.
**---+ OLD: p4 reconcile -n
instead of p4 status
**
Either old versions of perforce had p4 status
act like p4 reconcile
by default making changes to workspace like adding to workspace. Or I was broken at the time I wrote this page.
New: git/hg/bzr/svn status
= p4 opened
+ p4 status
**
New: git/hg/bzr/svn status
= p4 opened
+ p4 reconcile -n
**
p4 reconcile -n
- for a list of files that are not opened wrt perforce, but to which you have made local changes.
(p4 reconcile -n
to say "make no changes.)
-n to tell reconcile to make no changes. No longer necessary - now that p4 status
is read-only by default.
OLD: p4 $P4OPTS opened p4 $P4OPTS reconcile -n | sed -e 's/ - / - RECONCILE TO MAKE: /'
---+ Suitable for an alias or quick typing
I combine these as follows:
p4 $P4OPTS opened
p4 $P4OPTS status | sed -e 's/ - / - RECONCILE TO MAKE: /'
The sed part to better differentiate the status for files that perforce already has opened from the status of files not opened under perforce. But I note that this is unsafe, when a file may have the string " - " in its name.
---+ Fancified
Because I often want the local paths, I currently use the following shell script my-p4-status
to give me something more like what I am used to from other VCSes' status command=.
The script below uses old reconcile -n
, and has not yet been updated to use status
.
#!/bin/bash
# Perforce lacks a single command to tell you the status of a workspace,
# the equivalent of hg/bzr/git status.
# Warning: "p4 status" is not actually a read-only query!!!
# "p4 status" is more like "p4 reconcile" - it actually opens files to edit, add, or delete (-e -a -d)
# p4 opened only reports on the status of files currently opened by Perforce
# It is necessary to combine "p4 opened" and "p4 reconcile -n" to get a net overview.
# TBD: convert to local file path, rather than depot path.
# (Not a simple sed-xargs-p4_fstat pipeline)
P4OPTS=''
if [ "$1" == "-ztag" ] || [ "$1" == "-verbose" ]
then
shift
P4OPTS="-ztag"
fi
case $P4OPTS in
-ztag)
p4 $P4OPTS opened
p4 $P4OPTS reconcile -n
;;
*)
echo '#### p4 opened - Perforce files already opened ###'
p4 $P4OPTS opened
echo '#### p4 reconcile -n --- local edits, not opened in Perforce. Run p4 reconcile to actually open. ###'
p4 $P4OPTS reconcile -n | sed -e 's/ - / - RECONCILE TO MAKE: /'
esac
---+ Better? Please Share!
If you have anything better, please share.
来源:https://stackoverflow.com/questions/39937962/what-is-the-p4-command-equivalent-to-something-like-git-hg-bzr-svn-status-hint