[p4] Querying the correct file case on a case-sensitive server

David Faison dfaison at photon.com
Wed May 24 14:34:56 PDT 2006


You're right, it's not quite as brutal as I thought - but I still think
you can speed it up probably by an order of magnitude if you actually
coded it in something like Java+P4API....
______________________________________________________________________
REM START OF [getReal.bat]
    @echo off
    setlocal    ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

    call :getDepot "%~1"
    goto end
    
:getDepot
    set depotpath=%~1

    for /f "delims=/ tokens=1,*" %%a in ("!depotpath!") do (
        set nextNode=%%a
        set restOfPath=%%b
    )
    echo "
    echo "  node=[!nextNode!]
    echo "  rest=[!restOfPath!]
    echo "
    for /f "tokens=2" %%c in ('p4 depots') do (
        if /i "%%c"=="!nextNode!" (
            set realName=//%%c
            call :getPath "!realName!" "!restOfPath!"
        )
    )
goto end

:getPath
    set realName=%~1
    set restOfPath=%~2

    for /f "delims=/ tokens=1,*" %%a in ("!restOfPath!") do (
        set nextNode=%%a
        set restOfPath=%%b
        echo "
        echo "  realName=[!realName!]
        echo "  nextNode=[!nextNode!]
        echo "      rest=[!restOfPath!]
        echo "
    )
    if "!restOfPath!"=="" (
        call :getFile "!realName!" "!nextNode!"
    ) else (
        for /f %%c in ('p4 dirs "!realName!/*"') do (
            if /i "%%c"=="!realName!/!nextNode!" (
                set realName=%%c
                echo "  real[!realName!]
                call :getPath "!realName!" "!restOfPath!" 
            ) 
        )
    )    
goto end


:getFile
    set depotpath=%~1
    set filename=%~2
    
    for /f "delims=#" %%a in ('p4 files "!depotpath!/*"') do (
        if /i "%%~nxa"=="!filename!" (
            set realName=%%~a
            goto found
        )
    )
    goto end
    :found
    echo !realname!
goto end
    
:end    

REM END OF [getReal.bat]
______________________________________________________________________


David Faison, Software Configuration Manager
Photon Research Associates, Inc.
dfaison at photon.com

-----Original Message-----
From: Jeff Grills [mailto:jgrills at drivensnow.org] 
Sent: Wednesday, May 24, 2006 1:03 AM
To: David Faison; perforce-user at perforce.com
Subject: RE: [p4] Querying the correct file case on a case-sensitive
server



I don't see why you'd necessarily have to go to the p4 API to pull this
off.
You could match the case of the //depot name against the output of "p4
depots" in a case insensitive manner, and then iteratively match each
directory name to its case by using "p4 dirs", and finally the filename
by
"p4 files".  You might need to account for multiple names that differ
only by case as the depot name, directory name, or even the file name -
that could get tricky depending upon what you want to do with the name
afterwards.

j

-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of David Faison
Sent: Tuesday, May 23, 2006 5:16 PM
To: perforce-user at perforce.com
Subject: [p4] Querying the correct file case on a case-sensitive server


You could do a script based case-insensitive search from a Windows box.
This technique is sort of brutal - and costly in a directory with a lot
of files, but it works. If performance is an issue, you'll probably have
to resort to real programming using the P4 API.

David Faison
Photon Research Associates

________________________________________________________________________
Rem start of getReal.bat        

@echo off
    setlocal    ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

    set depotpath=%~1
    set filename=%~2
    set realname=
    
    for /f "delims=#" %%a in ('p4 files "!depotpath!/*"') do (
        if /i "%%~nxa"=="!filename!" (
            set realname=%%~nxa
            goto found
        )
    )
    goto end

    :found
    echo !realname!

    :end    
rem end of getReal.bat
________________________________________________________________________


And here's an example of a second script using the one above to retrieve

the case-sensitive name.
________________________________________________________________________

@echo off
    setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

    for /f "delims=#" %%a in ('getReal.bat %~1 %~2') do set realName=%%a
    echo realname: [!realnName!]
rem end of sample.bat
________________________________________________________________________
    


-----Original Message-----
From: From: "David Genest" <david.genest at ubisoft.com>
Sent: Tue, 23 May 2006 13:20:17 -0400
Subject: [p4] Querying the correct file case on a case-sensitive server
Message: 12
Date: 
Subject: To: <perforce-user at perforce.com>
Message-ID:
	<4ABFB5DF384CA040B8AD71AD64BD6063051E3CBF at UBIMAIL1.ubisoft.org>
Content-Type: text/plain;	charset="us-ascii"

Hello, 

	Our p4 server is running on a case sensitive machine (Linux).
Our clients are in vast majority case preserving, but case-insensitive
machines (win32).

	We have automated procedures that open assets for edit, and
fetches information with the fstat command. There are some edge cases
where the file we want to query is not in the correct case.

	I was wondering if there was a function that could take as input
a wrongly cased path and get as output the correct path as stored on the
server. I would see this functionality in the p4 where command.

	For example (assume the current working directory is in
//depot):

	//depot/myGoodCaseFile.txt

	Issuing a "p4 where -serverCase mygoodcasefile.txt" would
output: 

	//depot/myGoodCaseFile.txt //myClient/myGoodCaseFile.txt
d:\workingDir\mygoodcasefile.txt

	The actual behavior of the where command just appends the
queried path to the mappings as it would be on the server, so I get:

	//depot/mygoodcasefile.txt //myClient/mygoodcasefile.txt
d:\workingDir\mygoodcasefile.txt

	I have looked around and read the docs, but I don't think there
is such a behavior. What would be the best way to get the correct case
(as stored on the server) from a wrongly cased file path?

Thanks,

David.



More information about the perforce-user mailing list