[p4] Finding changed files in workspace which p4 doesn't know about?

Jay Glanville Jay.Glanville at naturalconvergence.com
Fri Mar 16 08:59:06 PST 2007


> From: perforce-user-bounces at perforce.com 
> [mailto:perforce-user-bounces at perforce.com] On Behalf Of Roy Smith
> 
> We've found a few scenarios where files can change in a workspace  
> without p4 knowing about it.  For example:
> 
> 1) Somebody creates a new file and forgets to do "p4 add"
> 
> 2) Cygwin's brain-dead handling of file permissions lets you edit an  
> existing file without doing a "p4 open".
> 
> 3) Somebody deliberately (and stupidly) chmods a file so they can  
> edit it.
> 
> Is there any easy way to find all these?  Basicly, I want to answer  
> the question, "If I did an rm -rf; sync -f", would I get back 
> exactly  
> what I've got now?"


"p4 diff -se" will find the files that are 'dirty' (have been modified
without the "p4 edit" command).  "p4 diff -sd" will find the files that
have been removed without the "p4 delete" command.  There is no "find
all files that need to be 'p4 add'ed".


For my users, I wrote this script which lists all files that need to be
added, deleted or edited in order to get back to where they should be.
I've attached it below.


P4win has a 'check consistency' command that only performs a 'edit or
deleted' check.  It doesn't check for adds.

P4V has a 'reconsile offline work' which performs all three checks (add,
edit and delete).


Hope this helps.

JDG






------- p4delta -------
#!/usr/bin/bash
#
# DESCRIPTION
# -----------
# Checks for the deltas (differences) between a file tree and the
# equivalent Perforce file tree.  Identifies files that might need to be
# added, files that have been deleted, and files that have been modified
# (dirty), all without perforce's knowledge.  This script's
functionality
# is very similar to the P4Win Check Consistency functionality, with the
# exception that Check Consistency doesn't check for files that need to
be
# added.
#
# For additional information, see the wiki article p4:tools:p4delta.
#
# USAGE
# -----
# This command needs to be executed from the root directory of the tree
for
# which to check consistency.  Therefore, tree options:
# 1) add the scripts location to your PATH environment, cd to root
#    directory and execute.
# 2) cd to root directory, and then execute 'path/to/script/p4delta'
# 3) copy script to root directory, cd to same directory and execute.
#
# There are no command line parameters.
#
# IMPLEMENTATION DETAILS
# ----------------------
# For the finding of deleted and dirty files, this script uses native
# perforce functionality (p4 diff -se and -sd).
#
# For the finding of files that need to be added to perforce, this
script
# uses the following methodology to determin the uncontrolled files:
# 1) retrieve from perforce a list of all the files that p4 thinks are
on
#    the local system
# 2) retrieve from the local file system a list of all files under the
#    current directory and dump into a temp file
# 3) perform a diff between the two temp files
# 4) cleanup
#
# METADATA
# --------
# $Header: //depot/perforce_admin/general_scripts/p4delta#2 $
# $Date: 2007/01/23 $
# $Author: jglanville $

p4_have="/tmp/__p4_have_output__"
file_have="/tmp/__local_file_output__"
# the current working directory using forward slashes for dir separators
current_dir=`pwd`
# the current working directory using OS-specific directory separators
current_dir_os=${current_dir}
# deal with OS specific situations
case "`uname`" in
    CYGWIN*)
        current_dir=`cygpath -m -a ${current_dir}`
        current_dir_os=`cygpath -w -a ${current_dir}`
        ;;
esac

# get a list of files that perforce thinks are on the local system.  The
# 'p4 have' command has a format of [//depot/path#rev - /local/path].
# Therefore, use the sed to strip out the depot path and revision
number,
# plus to convert all windows back-slashes to forward slashes
p4 have ${current_dir_os}/... | sed -e "s/^.*#[0-9]* - //" -e
"s#\\\\#/#g" | sort -f > ${p4_have}

# get a list of all the files under the current file system.  The sed
# prefixes all the relative paths that find outputs with the current
# working directory
find . -type f | sed -e "s#^.#${current_dir}#" | sort -f > ${file_have}

# perform a diff of the output of the previous two commands.  Only
# interested in the entries that start with ">", which indicate files
found
# on the local system that perforce doesn't know about
echo "[not under source control]"
diff -i ${p4_have} ${file_have} | grep "^>"
#comm -2 ${p4_have} ${file_have}

# cleanup
rm  "${p4_have}" "${file_have}"

# find all files that have been modified without p4's knowledge (dirty
# files)
echo "[modified]"
p4 diff -se "${current_dir_os}"/...

# find all files that have been deleted without p4's knowledge
echo "[deleted]"
p4 diff -sd "${current_dir_os}"/...



More information about the perforce-user mailing list