git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case()
@ 2018-02-08  0:41 Ben Peart
  2018-02-08  1:02 ` David Turner
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Ben Peart @ 2018-02-08  0:41 UTC (permalink / raw)
  To: git; +Cc: prohaska, gitster, tboegi, sunshine, novalis, Ben Peart

Correct the pointer arithmetic in adjust_dirname_case() so that it calls
find_dir_entry() with the correct string length.  Previously passing in
"dir1/foo" would pass a length of 6 instead of the correct 4.  This resulted in
find_dir_entry() never finding the entry and so the subsequent memcpy that would
fold the name to the version with the correct case never executed.

Add a test to validate the corrected behavior with name folding of directories.

Signed-off-by: Ben Peart <benpeart@microsoft.com>
---

Notes:
    Base Ref: v2.16.1
    Web-Diff: https://github.com/benpeart/git/commit/2944970f4e
    Checkout: git fetch https://github.com/benpeart/git adjust_dirname-v1 && git checkout 2944970f4e

 name-hash.c           |  6 +++---
 t/t0050-filesystem.sh | 12 +++++++++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/name-hash.c b/name-hash.c
index 45c98db0a0..2ddbb72647 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -696,12 +696,12 @@ void adjust_dirname_case(struct index_state *istate, char *name)
 		if (*ptr == '/') {
 			struct dir_entry *dir;
 
-			ptr++;
-			dir = find_dir_entry(istate, name, ptr - name + 1);
+			dir = find_dir_entry(istate, name, ptr - name);
 			if (dir) {
 				memcpy((void *)startPtr, dir->name + (startPtr - name), ptr - startPtr);
-				startPtr = ptr;
+				startPtr = ptr + 1;
 			}
+			ptr++;
 		}
 	}
 }
diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
index b29d749bb7..219c96594c 100755
--- a/t/t0050-filesystem.sh
+++ b/t/t0050-filesystem.sh
@@ -80,7 +80,17 @@ test_expect_success 'merge (case change)' '
 	git merge topic
 '
 
-
+test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
+	git reset --hard initial &&
+	mkdir -p dir1 &&
+	mkdir -p dir1/dir2 &&
+	touch dir1/dir2/a &&
+	touch dir1/dir2/b &&
+	git add dir1/dir2/a &&
+	git add dir1/DIR2/b &&
+	camel=$(git ls-files | grep dir2) &&
+	test $(echo "$camel" | wc -l) = 2
+'
 
 test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
 	git reset --hard initial &&

base-commit: 8279ed033f703d4115bee620dccd32a9ec94d9aa
-- 
2.15.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case()
  2018-02-08  0:41 [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case() Ben Peart
@ 2018-02-08  1:02 ` David Turner
  2018-02-08 17:21 ` Torsten Bögershausen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: David Turner @ 2018-02-08  1:02 UTC (permalink / raw)
  To: Ben Peart, git; +Cc: prohaska, gitster, tboegi, sunshine

On Wed, 2018-02-07 at 19:41 -0500, Ben Peart wrote:
> Correct the pointer arithmetic in adjust_dirname_case() so that it
> calls
> find_dir_entry() with the correct string length.  Previously passing
> in
> "dir1/foo" would pass a length of 6 instead of the correct 4.  This
> resulted in
> find_dir_entry() never finding the entry and so the subsequent memcpy
> that would
> fold the name to the version with the correct case never executed.
> 
> Add a test to validate the corrected behavior with name folding of
> directories.

Looks good to me.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case()
  2018-02-08  0:41 [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case() Ben Peart
  2018-02-08  1:02 ` David Turner
@ 2018-02-08 17:21 ` Torsten Bögershausen
  2018-02-08 17:45   ` Ben Peart
  2018-02-08 18:24   ` Junio C Hamano
  2018-02-08 18:20 ` Junio C Hamano
  2018-02-08 19:23 ` [PATCH v2] " Ben Peart
  3 siblings, 2 replies; 8+ messages in thread
From: Torsten Bögershausen @ 2018-02-08 17:21 UTC (permalink / raw)
  To: Ben Peart; +Cc: git, prohaska, gitster, sunshine, novalis

On Wed, Feb 07, 2018 at 07:41:56PM -0500, Ben Peart wrote:
[]

> diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
> index b29d749bb7..219c96594c 100755
> --- a/t/t0050-filesystem.sh
> +++ b/t/t0050-filesystem.sh
> @@ -80,7 +80,17 @@ test_expect_success 'merge (case change)' '
>  	git merge topic
>  '
>  
> -
> +test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
> +	git reset --hard initial &&
> +	mkdir -p dir1 &&
> +	mkdir -p dir1/dir2 &&
> +	touch dir1/dir2/a &&
> +	touch dir1/dir2/b &&
> +	git add dir1/dir2/a &&
> +	git add dir1/DIR2/b &&
> +	camel=$(git ls-files | grep dir2) &&
> +	test $(echo "$camel" | wc -l) = 2
> +'
>  

There is nothing wrong with with "wc -l", but:
a more new-style would probably use test_line_count() here.

My personal favorite would be to spell out what we expect and run a diff.
When it fails, we can see what fails, and the function would look
like this:


test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
	git reset --hard initial &&
	mkdir -p dir1 &&
	mkdir -p dir1/dir2 &&
	touch dir1/dir2/a &&
	touch dir1/dir2/b &&
	git add dir1/dir2/a &&
	git add dir1/DIR2/b &&
	git ls-files | grep dir2 | sort >actual &&
	cat >expected <<-\EOF &&
	dir1/dir2/a
	dir1/dir2/b
	EOF
	test_cmp expected actual
'




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case()
  2018-02-08 17:21 ` Torsten Bögershausen
@ 2018-02-08 17:45   ` Ben Peart
  2018-02-08 18:24   ` Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Ben Peart @ 2018-02-08 17:45 UTC (permalink / raw)
  To: Torsten Bögershausen, Ben Peart
  Cc: git, prohaska, gitster, sunshine, novalis



On 2/8/2018 12:21 PM, Torsten Bögershausen wrote:
> On Wed, Feb 07, 2018 at 07:41:56PM -0500, Ben Peart wrote:
> []
> 
>> diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
>> index b29d749bb7..219c96594c 100755
>> --- a/t/t0050-filesystem.sh
>> +++ b/t/t0050-filesystem.sh
>> @@ -80,7 +80,17 @@ test_expect_success 'merge (case change)' '
>>   	git merge topic
>>   '
>>   
>> -
>> +test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
>> +	git reset --hard initial &&
>> +	mkdir -p dir1 &&
>> +	mkdir -p dir1/dir2 &&
>> +	touch dir1/dir2/a &&
>> +	touch dir1/dir2/b &&
>> +	git add dir1/dir2/a &&
>> +	git add dir1/DIR2/b &&
>> +	camel=$(git ls-files | grep dir2) &&
>> +	test $(echo "$camel" | wc -l) = 2
>> +'
>>   
> 
> There is nothing wrong with with "wc -l", but:
> a more new-style would probably use test_line_count() here.
> 
> My personal favorite would be to spell out what we expect and run a diff.
> When it fails, we can see what fails, and the function would look
> like this:
> 

I agree with you completely that this is a better format and is easier 
to read.  All the new tests I've been writing follow this same pattern.

In this particular test file, I opted (for better and for worse) to 
stick with the style of all the other tests rather than 1) have this one 
test be very different than all the others or 2) rewriting all the 
existing tests in the new style.

> 
> test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
> 	git reset --hard initial &&
> 	mkdir -p dir1 &&
> 	mkdir -p dir1/dir2 &&
> 	touch dir1/dir2/a &&
> 	touch dir1/dir2/b &&
> 	git add dir1/dir2/a &&
> 	git add dir1/DIR2/b &&
> 	git ls-files | grep dir2 | sort >actual &&
> 	cat >expected <<-\EOF &&
> 	dir1/dir2/a
> 	dir1/dir2/b
> 	EOF
> 	test_cmp expected actual
> '
> 
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case()
  2018-02-08  0:41 [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case() Ben Peart
  2018-02-08  1:02 ` David Turner
  2018-02-08 17:21 ` Torsten Bögershausen
@ 2018-02-08 18:20 ` Junio C Hamano
  2018-02-08 19:23 ` [PATCH v2] " Ben Peart
  3 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2018-02-08 18:20 UTC (permalink / raw)
  To: Ben Peart; +Cc: git, prohaska, tboegi, sunshine, novalis

Ben Peart <benpeart@microsoft.com> writes:

> Correct the pointer arithmetic in adjust_dirname_case() so that it calls
> find_dir_entry() with the correct string length.  Previously passing in
> "dir1/foo" would pass a length of 6 instead of the correct 4.  This resulted in
> find_dir_entry() never finding the entry and so the subsequent memcpy that would
> fold the name to the version with the correct case never executed.
>
> Add a test to validate the corrected behavior with name folding of directories.
>
> Signed-off-by: Ben Peart <benpeart@microsoft.com>
> ---

Thanks.

It appears that this codepath has been miscounting ever since it was
introduced in 41284eb0 ("name-hash: don't reuse cache_entry in
dir_entry", 2015-10-21).

> diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
> index b29d749bb7..219c96594c 100755
> --- a/t/t0050-filesystem.sh
> +++ b/t/t0050-filesystem.sh
> @@ -80,7 +80,17 @@ test_expect_success 'merge (case change)' '
> ...
> +test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
> +	git reset --hard initial &&
> +	mkdir -p dir1 &&
> +	mkdir -p dir1/dir2 &&

A single "mkdir -p dir1/dir2" should be sufficient, thanks to "-p" ;-)

> +	touch dir1/dir2/a &&
> +	touch dir1/dir2/b &&

Hmph.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case()
  2018-02-08 17:21 ` Torsten Bögershausen
  2018-02-08 17:45   ` Ben Peart
@ 2018-02-08 18:24   ` Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2018-02-08 18:24 UTC (permalink / raw)
  To: Torsten Bögershausen; +Cc: Ben Peart, git, prohaska, sunshine, novalis

Torsten Bögershausen <tboegi@web.de> writes:

> My personal favorite would be to spell out what we expect and run a diff.
> When it fails, we can see what fails, and the function would look
> like this:

I'd rather not to have the "sort" there; output from ls-files is
meant to be stable; passing it through sort would miss breakages.  I
agree that comparison between "expect" and "actual" is a good idea
nevertheless.

Speaking of styles, I'd prefer to reserve use of "touch" to cases
where resulting timestamp matters, and not "make sure it exists".

Thanks.

> test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
> 	git reset --hard initial &&
> 	mkdir -p dir1 &&
> 	mkdir -p dir1/dir2 &&
> 	touch dir1/dir2/a &&
> 	touch dir1/dir2/b &&
> 	git add dir1/dir2/a &&
> 	git add dir1/DIR2/b &&
> 	git ls-files | grep dir2 | sort >actual &&
> 	cat >expected <<-\EOF &&
> 	dir1/dir2/a
> 	dir1/dir2/b
> 	EOF
> 	test_cmp expected actual
> '

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] name-hash: properly fold directory names in adjust_dirname_case()
  2018-02-08  0:41 [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case() Ben Peart
                   ` (2 preceding siblings ...)
  2018-02-08 18:20 ` Junio C Hamano
@ 2018-02-08 19:23 ` Ben Peart
  2018-02-09  5:43   ` Torsten Bögershausen
  3 siblings, 1 reply; 8+ messages in thread
From: Ben Peart @ 2018-02-08 19:23 UTC (permalink / raw)
  To: benpeart, git; +Cc: prohaska, gitster, tboegi, sunshine, novalis

Correct the pointer arithmetic in adjust_dirname_case() so that it calls
find_dir_entry() with the correct string length.  Previously passing in
"dir1/foo" would pass a length of 6 instead of the correct 4.  This resulted in
find_dir_entry() never finding the entry and so the subsequent memcpy that would
fold the name to the version with the correct case never executed.

Add a test to validate the corrected behavior with name folding of directories.

Signed-off-by: Ben Peart <benpeart@microsoft.com>
---

Notes:
    Base Ref: v2.16.1
    Web-Diff: https://github.com/benpeart/git/commit/477da4602c
    Checkout: git fetch https://github.com/benpeart/git adjust_dirname-v2 && git checkout 477da4602c
    
    ### Interdiff (v1..v2):
    
    diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
    index 219c96594c..0e4e51b79a 100755
    --- a/t/t0050-filesystem.sh
    +++ b/t/t0050-filesystem.sh
    @@ -82,14 +82,18 @@ test_expect_success 'merge (case change)' '
    
     test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
     	git reset --hard initial &&
    -	mkdir -p dir1 &&
     	mkdir -p dir1/dir2 &&
    -	touch dir1/dir2/a &&
    -	touch dir1/dir2/b &&
    +	echo > dir1/dir2/a &&
    +	echo > dir1/dir2/b &&
     	git add dir1/dir2/a &&
     	git add dir1/DIR2/b &&
    -	camel=$(git ls-files | grep dir2) &&
    -	test $(echo "$camel" | wc -l) = 2
    +	git ls-files >actual &&
    +	cat >expected <<-\EOF &&
    +		camelcase
    +		dir1/dir2/a
    +		dir1/dir2/b
    +	EOF
    +	test_cmp expected actual
     '
    
     test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
    
    ### Patches

 name-hash.c           |  6 +++---
 t/t0050-filesystem.sh | 16 +++++++++++++++-
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/name-hash.c b/name-hash.c
index 45c98db0a0..2ddbb72647 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -696,12 +696,12 @@ void adjust_dirname_case(struct index_state *istate, char *name)
 		if (*ptr == '/') {
 			struct dir_entry *dir;
 
-			ptr++;
-			dir = find_dir_entry(istate, name, ptr - name + 1);
+			dir = find_dir_entry(istate, name, ptr - name);
 			if (dir) {
 				memcpy((void *)startPtr, dir->name + (startPtr - name), ptr - startPtr);
-				startPtr = ptr;
+				startPtr = ptr + 1;
 			}
+			ptr++;
 		}
 	}
 }
diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
index b29d749bb7..0e4e51b79a 100755
--- a/t/t0050-filesystem.sh
+++ b/t/t0050-filesystem.sh
@@ -80,7 +80,21 @@ test_expect_success 'merge (case change)' '
 	git merge topic
 '
 
-
+test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
+	git reset --hard initial &&
+	mkdir -p dir1/dir2 &&
+	echo > dir1/dir2/a &&
+	echo > dir1/dir2/b &&
+	git add dir1/dir2/a &&
+	git add dir1/DIR2/b &&
+	git ls-files >actual &&
+	cat >expected <<-\EOF &&
+		camelcase
+		dir1/dir2/a
+		dir1/dir2/b
+	EOF
+	test_cmp expected actual
+'
 
 test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' '
 	git reset --hard initial &&

base-commit: 8279ed033f703d4115bee620dccd32a9ec94d9aa
-- 
2.15.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] name-hash: properly fold directory names in adjust_dirname_case()
  2018-02-08 19:23 ` [PATCH v2] " Ben Peart
@ 2018-02-09  5:43   ` Torsten Bögershausen
  0 siblings, 0 replies; 8+ messages in thread
From: Torsten Bögershausen @ 2018-02-09  5:43 UTC (permalink / raw)
  To: Ben Peart; +Cc: git, prohaska, gitster, sunshine, novalis

On Thu, Feb 08, 2018 at 02:23:33PM -0500, Ben Peart wrote:

[]

> -
> +test_expect_success CASE_INSENSITIVE_FS 'add directory (with different case)' '
> +	git reset --hard initial &&
> +	mkdir -p dir1/dir2 &&
> +	echo > dir1/dir2/a &&
> +	echo > dir1/dir2/b &&

Thanks for working on this-
One and a half style nits:
The ">" should be close to the file name:
	echo >dir1/dir2/a &&
But then we don't even look into the file, so that the "\" produced by echo is not needed.
A simple 
	>dir1/dir2/a &&
is all that is needed.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-02-09  5:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-08  0:41 [PATCH v1] name-hash: properly fold directory names in adjust_dirname_case() Ben Peart
2018-02-08  1:02 ` David Turner
2018-02-08 17:21 ` Torsten Bögershausen
2018-02-08 17:45   ` Ben Peart
2018-02-08 18:24   ` Junio C Hamano
2018-02-08 18:20 ` Junio C Hamano
2018-02-08 19:23 ` [PATCH v2] " Ben Peart
2018-02-09  5:43   ` Torsten Bögershausen

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).