Subject: Re: [PATCH] git-p4: Improve client path detection when branches are used

From: Junio C Hamano <[email-masked]>
Date: Sat, 18 Apr 2015 17:58:11 -0700

Vitor Antunes <[email-masked]> writes:

> This patch makes the client path detection more robust by limiting the valid
> results from p4 where. The test case is also made more complex, to guarantee
> that such client views are supported.
>
> Signed-off-by: Vitor Antunes <[email-masked]>
> ---

Was this designed to be squashed into the previous 2/2 patch?  I
do not think either 1/2 or 2/2 is in 'next' yet, and if this was
to correct mistakes in the 2/2 that was posted earlier, it would
be nicer to have a replacement patch with corrected log message.

Thanks.

>  git-p4.py                |    4 +++-
>  t/t9801-git-p4-branch.sh |   12 ++++++++++--
>  2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 262a95b..28d0d90 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -507,7 +507,9 @@ def p4Where(depotPath):
>      output = None
>      for entry in outputList:
>          if "depotFile" in entry:
> -            if entry["depotFile"].find(depotPath) >= 0:
> +            # Search for the base client side depot path, as long as it starts with the branch's P4 path.
> +            # The base path always ends with "/...".
> +            if entry["depotFile"].find(depotPath) == 0 and entry["depotFile"][-4:] == "/...":
>                  output = entry
>                  break
>          elif "data" in entry:
> diff --git a/t/t9801-git-p4-branch.sh b/t/t9801-git-p4-branch.sh
> index 4fe4e18..0aafd03 100755
> --- a/t/t9801-git-p4-branch.sh
> +++ b/t/t9801-git-p4-branch.sh
> @@ -512,23 +512,28 @@ test_expect_success 'restart p4d' '
>  #
>  # 1: //depot/branch1/base/file1
>  #    //depot/branch1/base/file2
> +#    //depot/branch1/base/dir/sub_file1
>  # 2: integrate //depot/branch1/base/... -> //depot/branch2/base/...
>  # 3: //depot/branch1/base/file3
>  # 4: //depot/branch1/base/file2 (edit)
>  # 5: integrate //depot/branch1/base/... -> //depot/branch3/base/...
>  #
> -# Note: the client view remove the "base" folder from the workspace
> +# Note: the client view removes the "base" folder from the workspace
> +#       and moves sub_file1 one level up.
>  test_expect_success 'add simple p4 branches with common base folder on each branch' '
>  	(
>  		cd "$cli" &&
>  		client_view "//depot/branch1/base/... //client/branch1/..." \
> +			    "//depot/branch1/base/dir/sub_file1 //client/branch1/sub_file1" \
>  			    "//depot/branch2/base/... //client/branch2/..." \
>  			    "//depot/branch3/base/... //client/branch3/..." &&
>  		mkdir -p branch1 &&
>  		cd branch1 &&
>  		echo file1 >file1 &&
>  		echo file2 >file2 &&
> -		p4 add file1 file2 &&
> +		mkdir dir &&
> +		echo sub_file1 >sub_file1 &&
> +		p4 add file1 file2 sub_file1 &&
>  		p4 submit -d "Create branch1" &&
>  		p4 integrate //depot/branch1/base/... //depot/branch2/base/... &&
>  		p4 submit -d "Integrate branch2 from branch1" &&
> @@ -561,16 +566,19 @@ test_expect_success 'git p4 clone simple branches with base folder on server sid
>  		test -f file1 &&
>  		test -f file2 &&
>  		test -f file3 &&
> +		test -f sub_file1 &&
>  		grep update file2 &&
>  		git reset --hard p4/depot/branch2 &&
>  		test -f file1 &&
>  		test -f file2 &&
>  		test ! -f file3 &&
> +		test -f sub_file1 &&
>  		! grep update file2 &&
>  		git reset --hard p4/depot/branch3 &&
>  		test -f file1 &&
>  		test -f file2 &&
>  		test -f file3 &&
> +		test -f sub_file1 &&
>  		grep update file2 &&
>  		cd "$cli" &&
>  		cd branch1 &&