[p4] Offline reconciliation: what files need to be added?

Jay Glanville Jay.Glanville at naturalconvergence.com
Thu Jun 14 05:38:29 PDT 2007


I have a bash script that I use.  It produces a list of files that need
to be added, have been deleted and have been modified.

It generates the "needs to be added" list by executing a 'p4 have' plus
a 'find . -type f', and then compares the results.

I can't guarantee that it will work well for you, but it does for me.
I've included it below.  (Note that the longer lines may have been
wrapped)





----- snip -----
#!/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}"/...



----- snip -----



---
Jay Dickon Glanville


> -----Original Message-----
> From: perforce-user-bounces at perforce.com 
> [mailto:perforce-user-bounces at perforce.com] On Behalf Of Marc Wensauer
> Sent: June 13, 2007 5:00 PM
> To: perforce-user at perforce.com
> Subject: [p4] Offline reconciliation: what files need to be added?
> 
> 
> This KB article provides very useful information on how to reconcile
> offline changes:
> http://kb.perforce.com/UserTasks/WorkingDisconnected
> 
> For my purposes though, I need to *query* what needs to happen before
> actually doing it.  For the most part, it's trivial to see what files
> will have to opened for delete and edit via 'p4 diff -sd' and 'p4 diff
> -se' respectively.
> 
> But how do I query my workspace for files that *would* have 
> to be added?
>  The 'find . -type f | p4 -x - add' recommendation is rather
> brute-force, and doesn't avoid actually performing the 
> operation instead
> of just telling me about it.
> 
> How might one query for this information?  A recursive 'p4 files' and
> grep for "no such file(s).", or is there something else I should
> consider?
> 
> Thanks for your advice,
> -Marc
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user
> 



More information about the perforce-user mailing list