threads / patch / 28157

v2, 4 partsSupport threshold in copy/rename detection

Subject: [PATCH v2 0/4] Support threshold in copy/rename detection

## tl;dr

12 messages between Aug 18, 2011 and Aug 22, 2011. Diffs are folded; open one to read it.

replies: 11people: 3as markdown or json

Vitor Antunes· Aug 18, 2011, 22:20 UTC · lore

Second version that includes updates recommended by Pete Wyckoff. Now only "true" and "false" arguments are processed, any other argument that is no "" is passed directly.

Vitor Antunes (4):
  git-p4: Allow setting rename/copy detection threshold.
  git-p4: Add description of rename/copy detection options.
  git-p4: Add test case for rename detection.
  git-p4: Add test case for copy detection.
 contrib/fast-import/git-p4     |   18 ++++--
 contrib/fast-import/git-p4.txt |   25 ++++++++
 t/t9800-git-p4.sh              |  121 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+), 5 deletions(-)
-- 
1.7.5.4
Vitor Antunes· Aug 18, 2011, 22:20 UTC · re: Vitor Antunes · lore

[PATCH v2 1/4] git-p4: Allow setting rename/copy detection threshold.

Copy and rename detection arguments (-C and -M) allow setting a threshold value for the similarity ratio. If the similarity is below this threshold the rename or copy is ignored and the file is added as new. This patch allows setting git-p4.detectRenames and git-p4.detectCopies options to an integer value to set the respective threshold.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
 contrib/fast-import/git-p4 |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
Show changes to contrib/fast-import/git-p4 +13 −5
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 6b9de9e..cf719be 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -774,15 +774,23 @@ class P4Submit(Command, P4UserMap):
 
         if not self.detectRenames:
             # If not explicitly set check the config variable
-            self.detectRenames = gitConfig("git-p4.detectRenames").lower() == "true"
+            self.detectRenames = gitConfig("git-p4.detectRenames")
 
-        if self.detectRenames:
+        diffOpts = ""
+        if self.detectRenames.lower() == "true":
             diffOpts = "-M"
-        else:
-            diffOpts = ""
+        elif self.detectRenames != "":
+            self.detectRenames = int(self.detectRenames)
+            if self.detectRenames >= 0 and self.detectRenames <= 100:
+                diffOpts = "-M%d" % self.detectRenames
 
-        if gitConfig("git-p4.detectCopies").lower() == "true":
+        detectCopies = gitConfig("git-p4.detectCopies")
+        if detectCopies.lower() == "true":
             diffOpts += " -C"
+        elif detectCopies != "":
+            detectCopies = int(detectCopies)
+            if detectCopies >= 0 and detectCopies <= 100:
+                diffOpts += " -C%d" % detectCopies
 
         if gitConfig("git-p4.detectCopiesHarder").lower() == "true":
             diffOpts += " --find-copies-harder"
-- 
1.7.5.4
Junio C Hamano· Aug 18, 2011, 23:04 UTC · re: Vitor Antunes · lore

Re: [PATCH v2 1/4] git-p4: Allow setting rename/copy detection threshold.

Vitor Antunes <vitor.hda@gmail.com> writes:
Show 25 quoted lines
> Copy and rename detection arguments (-C and -M) allow setting a threshold value
> for the similarity ratio. If the similarity is below this threshold the rename
> or copy is ignored and the file is added as new.
> This patch allows setting git-p4.detectRenames and git-p4.detectCopies options
> to an integer value to set the respective threshold.
>
> Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
> ---
>  contrib/fast-import/git-p4 |   18 +++++++++++++-----
>  1 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
> index 6b9de9e..cf719be 100755
> --- a/contrib/fast-import/git-p4
> +++ b/contrib/fast-import/git-p4
> @@ -774,15 +774,23 @@ class P4Submit(Command, P4UserMap):
>  
>          if not self.detectRenames:
>              # If not explicitly set check the config variable
> -            self.detectRenames = gitConfig("git-p4.detectRenames").lower() == "true"
> +            self.detectRenames = gitConfig("git-p4.detectRenames")
>  
> -        if self.detectRenames:
> +        diffOpts = ""
> +        if self.detectRenames.lower() == "true":

This is not a new problem you introduced with this patch, but unless you are invoking "git config --bool" in your gitConfig() (I didn't bother to check), you will misunderstand different ways to say "Yes", e.g.

	[git-p4]
                detectRenames
                detectRenames = on
                detectRenames = yes
                detectRenames = 1

If you use --bool, you can rely on the values being either true or false, and do not have to do the .lower() thing.

Vitor Antunes· Aug 18, 2011, 23:43 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/4] git-p4: Allow setting rename/copy detection threshold.

On Fri, Aug 19, 2011 at 12:04 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
> This is not a new problem you introduced with this patch, but unless you
> are invoking "git config --bool" in your gitConfig() (I didn't bother to
> check), you will misunderstand different ways to say "Yes", e.g.
>
>        [git-p4]
>                detectRenames
>                detectRenames = on
>                detectRenames = yes
>                detectRenames = 1
>
> If you use --bool, you can rely on the values being either true or false,
> and do not have to do the .lower() thing.
>

Now that I look at this carefully, Tor added the possibility to add arguments to gitConfig() exactly for that purpose. This is helpful for processing the detectCopiesHarder option I added.

For detectRenames and detectCopies it is a bit more complex. I think that if I use --bool or --bool-or-int then it is possible that certain values will fail to be processed. Let me give you some examples:

        [git-p4]
                detectRenames = true
                detectRenames = 80%
                detectRenames = 80
                detectRenames = 1%
                detectRenames = 1

It will be difficult for me to, for example, to understand if a 1 represents 1% or true. Or am I overcomplicating this? :)

Thanks,
-- 
Vitor Antunes
Pete Wyckoff· Aug 19, 2011, 11:47 UTC · re: Vitor Antunes · lore

Re: [PATCH v2 1/4] git-p4: Allow setting rename/copy detection threshold.

vitor.hda@gmail.com wrote on Fri, 19 Aug 2011 00:43 +0100:
Show 32 quoted lines
> On Fri, Aug 19, 2011 at 12:04 AM, Junio C Hamano <gitster@pobox.com> wrote:
> > This is not a new problem you introduced with this patch, but unless you
> > are invoking "git config --bool" in your gitConfig() (I didn't bother to
> > check), you will misunderstand different ways to say "Yes", e.g.
> >
> >        [git-p4]
> >                detectRenames
> >                detectRenames = on
> >                detectRenames = yes
> >                detectRenames = 1
> >
> > If you use --bool, you can rely on the values being either true or false,
> > and do not have to do the .lower() thing.
> >
> 
> Now that I look at this carefully, Tor added the possibility to add arguments to
> gitConfig() exactly for that purpose. This is helpful for processing the
> detectCopiesHarder option I added.
> 
> For detectRenames and detectCopies it is a bit more complex. I think that if I
> use --bool or --bool-or-int then it is possible that certain values will fail to
> be processed. Let me give you some examples:
> 
>         [git-p4]
>                 detectRenames = true
>                 detectRenames = 80%
>                 detectRenames = 80
>                 detectRenames = 1%
>                 detectRenames = 1
> 
> It will be difficult for me to, for example, to understand if a 1 represents 1%
> or true. Or am I overcomplicating this? :)

I think you have to decide that 1 means 1 in this case. Everything else can mean true. That may suggest that using --bool or --bool-or-int isn't possible in this case.

		-- Pete
Vitor Antunes· Aug 19, 2011, 13:51 UTC · re: Pete Wyckoff · lore

Re: [PATCH v2 1/4] git-p4: Allow setting rename/copy detection threshold.

On Fri, Aug 19, 2011 at 12:47 PM, Pete Wyckoff <pw@padd.com> wrote:
> I think you have to decide that 1 means 1 in this case.
> Everything else can mean true.  That may suggest that using
> --bool or --bool-or-int isn't possible in this case.

But doing that kind of post-processing would require me to call git-config (at least) twice: first to check if it is a number with a possible "." in the middle or "%" at the end and a second time with the --bool option. I have no problem in doing this, but I think it increases the complexity without bringing major advantages.

I will use --bool for detectCopiesHarder and will send you the new set of patches tonight, unless we decide to also start using it for detectCopies and detectRenames.

-- 
Vitor Antunes
Pete Wyckoff· Aug 20, 2011, 11:19 UTC · re: Vitor Antunes · lore

Re: [PATCH v2 1/4] git-p4: Allow setting rename/copy detection threshold.

vitor.hda@gmail.com wrote on Fri, 19 Aug 2011 14:51 +0100:
Show 14 quoted lines
> On Fri, Aug 19, 2011 at 12:47 PM, Pete Wyckoff <pw@padd.com> wrote:
> > I think you have to decide that 1 means 1 in this case.
> > Everything else can mean true.  That may suggest that using
> > --bool or --bool-or-int isn't possible in this case.
> 
> But doing that kind of post-processing would require me to call
> git-config (at least) twice: first to check if it is a number with a
> possible "." in the middle or "%" at the end and a second time with
> the --bool option. I have no problem in doing this, but I think it
> increases the complexity without bringing major advantages.
> 
> I will use --bool for detectCopiesHarder and will send you the new set
> of patches tonight, unless we decide to also start using it for
> detectCopies and detectRenames.

I was imagining you would not use "--bool", and parse everything yourself. But I see your point, and letting "1" mean "-M1" as opposed to "-M" is probably okay too. I'm not particularly worked up about which way that goes.

		-- Pete
Vitor Antunes· Aug 22, 2011, 00:09 UTC · re: Pete Wyckoff · lore

Re: [PATCH v2 1/4] git-p4: Allow setting rename/copy detection threshold.

On Sat, 20 Aug 2011 07:19:56 -0400 Pete Wyckoff <pw@padd.com> wrote:

> I was imagining you would not use "--bool", and parse everything
> yourself.  But I see your point, and letting "1" mean "-M1" as
> opposed to "-M" is probably okay too.  I'm not particularly
> worked up about which way that goes.

I decided to only add --bool to detectCopiesHarder, at least for now. Will send a new set of patches shortly.

-- 
Vitor Antunes
Vitor Antunes· Aug 18, 2011, 22:20 UTC · re: Vitor Antunes · lore

[PATCH v2 2/4] git-p4: Add description of rename/copy detection options.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
 contrib/fast-import/git-p4.txt |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
Show changes to contrib/fast-import/git-p4.txt +25 −0
diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
index caa4bb3..2ffbccc 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -232,6 +232,31 @@ git-p4.skipUserNameCheck
 When submitting, git-p4 checks that the git commits are authored by the current
 p4 user, and warns if they are not. This disables the check.
 
+git-p4.detectRenames
+
+Detect renames when submitting changes to Perforce server. Will enable -M git
+argument. Can be optionally set to a number representing the threshold
+percentage value of the rename detection.
+
+  git config [--global] git-p4.detectRenames true
+  git config [--global] git-p4.detectRenames 50
+
+git-p4.detectCopies
+
+Detect copies when submitting changes to Perforce server. Will enable -C git
+argument. Can be optionally set to a number representing the threshold
+percentage value of the copy detection.
+
+  git config [--global] git-p4.detectCopies true
+  git config [--global] git-p4.detectCopies 80
+
+git-p4.detectCopiesHarder
+
+Detect copies even between files that did not change when submitting changes to
+Perforce server. Will enable --find-copies-harder git argument.
+
+  git config [--global] git-p4.detectCopies true
+
 Implementation Details...
 =========================
 
-- 
1.7.5.4
Vitor Antunes· Aug 18, 2011, 22:20 UTC · re: Vitor Antunes · lore

[PATCH v2 3/4] git-p4: Add test case for rename detection.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
 t/t9800-git-p4.sh |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
Show changes to t/t9800-git-p4.sh +50 −0
diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh
index 97ec975..d01a1cb 100755
--- a/t/t9800-git-p4.sh
+++ b/t/t9800-git-p4.sh
@@ -269,6 +269,56 @@ test_expect_success 'initial import time from top change time' '
 	test $p4time = $gittime
 '
 
+# Rename a file and confirm that rename is not detected in P4.
+# Rename the new file again with detectRenames option enabled and confirm that
+# this is detected in P4.
+# Rename the new file again adding an extra blank line, configure a big
+# threshold in detectRenames and confirm that rename is not detected in P4.
+# Rename the new file again adding another extra blank line, configure a small
+# threshold in detectRenames and confirm that rename is not detected in P4.
+test_expect_success 'detect renames' '
+	git init "$git" &&
+	cd "$git" &&
+	cd "$TRASH_DIRECTORY" &&
+	"$GITP4" clone --dest="$git" //depot@all &&
+	p4 files //depot/* &&
+	cd "$git" &&
+	git mv file1 file4 &&
+	git commit -a -m "Rename file1 to file4" &&
+	git diff-tree -r -M HEAD &&
+	git config git-p4.skipSubmitEditCheck true &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file4 &&
+	! p4 filelog //depot/file4 | grep -q "branch from //depot/file1" &&
+	git mv file4 file5 &&
+	git commit -a -m "Rename file4 to file5" &&
+	git diff-tree -r -M HEAD &&
+	git config git-p4.detectRenames true &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file5 &&
+	p4 filelog //depot/file5 | grep -q "branch from //depot/file4" &&
+	git mv file5 file6 &&
+	echo update >> file6 &&
+	git add file6 &&
+	git commit -a -m "Rename file5 to file6 with changes" &&
+	git diff-tree -r -M HEAD &&
+	git config git-p4.detectRenames 95 &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file6 &&
+	! p4 filelog //depot/file6 | grep -q "branch from //depot/file5" &&
+	git mv file6 file7 &&
+	echo update >> file7 &&
+	git add file7 &&
+	git commit -a -m "Rename file6 to file7 with changes" &&
+	git diff-tree -r -M HEAD &&
+	git config git-p4.detectRenames 80 &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file7 &&
+	p4 filelog //depot/file7 | grep -q "branch from //depot/file6" &&
+	cd "$TRASH_DIRECTORY" &&
+	rm -rf "$git" && mkdir "$git"
+'
+
 test_expect_success 'shutdown' '
 	pid=`pgrep -f p4d` &&
 	test -n "$pid" &&
-- 
1.7.5.4
Vitor Antunes· Aug 18, 2011, 22:20 UTC · re: Vitor Antunes · lore

[PATCH v2 4/4] git-p4: Add test case for copy detection.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
 t/t9800-git-p4.sh |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)
Show changes to t/t9800-git-p4.sh +71 −0
diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh
index d01a1cb..a4f3d66 100755
--- a/t/t9800-git-p4.sh
+++ b/t/t9800-git-p4.sh
@@ -319,6 +319,77 @@ test_expect_success 'detect renames' '
 	rm -rf "$git" && mkdir "$git"
 '
 
+# Copy a file and confirm that copy is not detected in P4.
+# Copy a file with detectCopies option enabled and confirm that copy is not
+# detected in P4.
+# Modify and copy a file with detectCopies option enabled and confirm that copy
+# is detected in P4.
+# Copy a file with detectCopies and detectCopiesHarder options enabled and
+# confirm that copy is detected in P4.
+# Modify and copy a file, configure a big threshold in detectCopies and confirm
+# that copy is not detected in P4.
+# Modify and copy a file, configure a small threshold in detectCopies and
+# confirm that copy is detected in P4.
+test_expect_success 'detect copies' '
+	git init "$git" &&
+	cd "$git" &&
+	cd "$TRASH_DIRECTORY" &&
+	"$GITP4" clone --dest="$git" //depot@all &&
+	cd "$git" &&
+	cp file2 file8 &&
+	git add file8 &&
+	git commit -a -m "Copy file2 to file8" &&
+	git diff-tree -r -C HEAD
+	git config git-p4.skipSubmitEditCheck true &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file8 &&
+	! p4 filelog //depot/file8 | grep -q "branch from //depot/file" &&
+	cp file2 file9 &&
+	git add file9 &&
+	git commit -a -m "Copy file2 to file9" &&
+	git diff-tree -r -C HEAD
+	git config git-p4.detectCopies true &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file9 &&
+	! p4 filelog //depot/file9 | grep -q "branch from //depot/file" &&
+	echo file2 >> file2 &&
+	cp file2 file10 &&
+	git add file2 file10 &&
+	git commit -a -m "Modify and copy file2 to file10" &&
+	git diff-tree -r -C HEAD
+	"$GITP4" submit &&
+	p4 filelog //depot/file10 &&
+	p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
+	cp file2 file11 &&
+	git add file11 &&
+	git commit -a -m "Copy file2 to file11" &&
+	git diff-tree -r -C --find-copies-harder HEAD
+	git config git-p4.detectCopiesHarder true &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file11 &&
+	p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
+	cp file2 file12 &&
+	echo >> file12 &&
+	git add file12 &&
+	git commit -a -m "Copy file2 to file12 with changes" &&
+	git diff-tree -r -C --find-copies-harder HEAD
+	git config git-p4.detectCopies 98 &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file12 &&
+	! p4 filelog //depot/file12 | grep -q "branch from //depot/file" &&
+	cp file2 file13 &&
+	echo >> file13 &&
+	git add file13 &&
+	git commit -a -m "Copy file2 to file13 with changes" &&
+	git diff-tree -r -C --find-copies-harder HEAD
+	git config git-p4.detectCopies 80 &&
+	"$GITP4" submit &&
+	p4 filelog //depot/file13 &&
+	p4 filelog //depot/file13 | grep -q "branch from //depot/file" &&
+	cd "$TRASH_DIRECTORY" &&
+	rm -rf "$git" && mkdir "$git"
+'
+
 test_expect_success 'shutdown' '
 	pid=`pgrep -f p4d` &&
 	test -n "$pid" &&
-- 
1.7.5.4
Pete Wyckoff· Aug 20, 2011, 19:09 UTC · re: Vitor Antunes · lore

Re: [PATCH v2 0/4] Support threshold in copy/rename detection

vitor.hda@gmail.com wrote on Thu, 18 Aug 2011 23:20 +0100:
Show 9 quoted lines
> Second version that includes updates recommended by Pete Wyckoff.
> Now only "true" and "false" arguments are processed, any other argument
> that is no "" is passed directly.
> 
> Vitor Antunes (4):
>   git-p4: Allow setting rename/copy detection threshold.
>   git-p4: Add description of rename/copy detection options.
>   git-p4: Add test case for rename detection.
>   git-p4: Add test case for copy detection.

Here is a patch of review comments. Some of these are style and correctness fixes. Others are my annotations to understand what's going on in the test. You might take the good ones and send them to Junio.

		-- Pete
-----------------------8<--------------------
>From e8c627b08248bc17e8c4e6ca246099b0431a4bfb Mon Sep 17 00:00:00 2001
From: Pete Wyckoff <pw@padd.com>
Date: Sat, 20 Aug 2011 14:10:18 -0400
Subject: [PATCH 1/4] git-p4: copy/rename test case edits
Some review comments.  Take the ones in here you like.
Signed-off-by: Pete Wyckoff <pw@padd.com>
---
 t/t9800-git-p4.sh |   88 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 51 insertions(+), 37 deletions(-)
Show changes to t/t9800-git-p4.sh +51 −37
diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh
index 2a872bc..bbf1485 100755
--- a/t/t9800-git-p4.sh
+++ b/t/t9800-git-p4.sh
@@ -272,24 +272,22 @@ test_expect_success 'initial import time from top change time' '
 # Rename a file and confirm that rename is not detected in P4.
 # Rename the new file again with detectRenames option enabled and confirm that
 # this is detected in P4.
-# Rename the new file again adding an extra blank line, configure a big
-# threshold in detectRenames and confirm that rename is not detected in P4.
-# Rename the new file again adding another extra blank line, configure a small
+# Rename the new file again adding an extra line, configure a big
 # threshold in detectRenames and confirm that rename is not detected in P4.
+# Repeat, this time with a smaller threshold.
 test_expect_success 'detect renames' '
-	git init "$git" &&
-	cd "$git" &&
-	cd "$TRASH_DIRECTORY" &&
 	"$GITP4" clone --dest="$git" //depot@all &&
-	p4 files //depot/* &&
+	test_when_finished cleanup_git &&
 	cd "$git" &&
+	git config git-p4.skipSubmitEditCheck true &&
+
 	git mv file1 file4 &&
 	git commit -a -m "Rename file1 to file4" &&
 	git diff-tree -r -M HEAD &&
-	git config git-p4.skipSubmitEditCheck true &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file4 &&
 	! p4 filelog //depot/file4 | grep -q "branch from //depot/file1" &&
+
 	git mv file4 file5 &&
 	git commit -a -m "Rename file4 to file5" &&
 	git diff-tree -r -M HEAD &&
@@ -297,26 +295,30 @@ test_expect_success 'detect renames' '
 	"$GITP4" submit &&
 	p4 filelog //depot/file5 &&
 	p4 filelog //depot/file5 | grep -q "branch from //depot/file4" &&
+
 	git mv file5 file6 &&
-	echo update >> file6 &&
+	echo update >>file6 &&
 	git add file6 &&
 	git commit -a -m "Rename file5 to file6 with changes" &&
 	git diff-tree -r -M HEAD &&
-	git config git-p4.detectRenames 95 &&
+	level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
+	test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
+	git config git-p4.detectRenames $((level + 2)) &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file6 &&
 	! p4 filelog //depot/file6 | grep -q "branch from //depot/file5" &&
+
 	git mv file6 file7 &&
-	echo update >> file7 &&
+	echo update >>file7 &&
 	git add file7 &&
 	git commit -a -m "Rename file6 to file7 with changes" &&
 	git diff-tree -r -M HEAD &&
-	git config git-p4.detectRenames 80 &&
+	level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
+	test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
+	git config git-p4.detectRenames $((level - 2)) &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file7 &&
-	p4 filelog //depot/file7 | grep -q "branch from //depot/file6" &&
-	cd "$TRASH_DIRECTORY" &&
-	rm -rf "$git" && mkdir "$git"
+	p4 filelog //depot/file7 | grep -q "branch from //depot/file6"
 '
 
 # Copy a file and confirm that copy is not detected in P4.
@@ -326,68 +328,80 @@ test_expect_success 'detect renames' '
 # is detected in P4.
 # Copy a file with detectCopies and detectCopiesHarder options enabled and
 # confirm that copy is detected in P4.
-# Modify and copy a file, configure a big threshold in detectCopies and confirm
-# that copy is not detected in P4.
-# Modify and copy a file, configure a small threshold in detectCopies and
+# Modify and copy a file, configure a bigger threshold in detectCopies and
+# confirm that copy is not detected in P4.
+# Modify and copy a file, configure a smaller threshold in detectCopies and
 # confirm that copy is detected in P4.
 test_expect_success 'detect copies' '
-	git init "$git" &&
-	cd "$git" &&
-	cd "$TRASH_DIRECTORY" &&
 	"$GITP4" clone --dest="$git" //depot@all &&
+	test_when_finished cleanup_git &&
 	cd "$git" &&
+	git config git-p4.skipSubmitEditCheck true &&
+
 	cp file2 file8 &&
 	git add file8 &&
 	git commit -a -m "Copy file2 to file8" &&
-	git diff-tree -r -C HEAD
-	git config git-p4.skipSubmitEditCheck true &&
+	git diff-tree -r -C HEAD &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file8 &&
-	! p4 filelog //depot/file8 | grep -q "branch from //depot/file" &&
+	! p4 filelog //depot/file8 | grep -q "branch from" &&
+
 	cp file2 file9 &&
 	git add file9 &&
 	git commit -a -m "Copy file2 to file9" &&
-	git diff-tree -r -C HEAD
+	git diff-tree -r -C HEAD &&
 	git config git-p4.detectCopies true &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file9 &&
 	! p4 filelog //depot/file9 | grep -q "branch from //depot/file" &&
-	echo file2 >> file2 &&
+
+	echo "file2" >>file2 &&
 	cp file2 file10 &&
 	git add file2 file10 &&
 	git commit -a -m "Modify and copy file2 to file10" &&
-	git diff-tree -r -C HEAD
+	git diff-tree -r -C HEAD &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file10 &&
 	p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
+
 	cp file2 file11 &&
 	git add file11 &&
 	git commit -a -m "Copy file2 to file11" &&
-	git diff-tree -r -C --find-copies-harder HEAD
+	git diff-tree -r -C --find-copies-harder HEAD &&
+	src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
+	test "$src" = file10 &&
 	git config git-p4.detectCopiesHarder true &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file11 &&
 	p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
+
 	cp file2 file12 &&
-	echo >> file12 &&
+	echo "some text" >>file12 &&
 	git add file12 &&
 	git commit -a -m "Copy file2 to file12 with changes" &&
-	git diff-tree -r -C --find-copies-harder HEAD
-	git config git-p4.detectCopies 98 &&
+	git diff-tree -r -C --find-copies-harder HEAD &&
+	level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
+	test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
+	src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
+	test "$src" = file10 &&
+	git config git-p4.detectCopies $((level + 2)) &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file12 &&
 	! p4 filelog //depot/file12 | grep -q "branch from //depot/file" &&
+
 	cp file2 file13 &&
-	echo >> file13 &&
+	echo "different text" >>file13 &&
 	git add file13 &&
 	git commit -a -m "Copy file2 to file13 with changes" &&
-	git diff-tree -r -C --find-copies-harder HEAD
-	git config git-p4.detectCopies 80 &&
+	git diff-tree -r -C --find-copies-harder HEAD &&
+	level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
+	test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
+	src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
+	test "$src" = file10 &&
+	git config git-p4.detectCopies $((level - 2)) &&
 	"$GITP4" submit &&
 	p4 filelog //depot/file13 &&
-	p4 filelog //depot/file13 | grep -q "branch from //depot/file" &&
-	cd "$TRASH_DIRECTORY" &&
-	rm -rf "$git" && mkdir "$git"
+	p4 filelog //depot/file13 | grep -q "branch from //depot/file"
 '
 
 # Create a simple branch structure in P4 depot to check if it is correctly
-- 
1.7.5.4

← back to recent threads