git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/4] update-index: use the same structure for chmod as add

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 12, 2016, 21:59 UTC
Message-ID
<xmqq37l4zsmo.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160912210818.26282-3-t.gummerer@gmail.com>
Thomas Gummerer <t.gummerer@gmail.com> writes:
Show 17 quoted lines
> +	char flip = force_mode == 0777 ? '+' : '-';
>  
>  	pos = cache_name_pos(path, strlen(path));
>  	if (pos < 0)
> @@ -432,17 +433,11 @@ static void chmod_path(int flip, const char *path)
>  	mode = ce->ce_mode;
>  	if (!S_ISREG(mode))
>  		goto fail;
> -	switch (flip) {
> -	case '+':
> -		ce->ce_mode |= 0111; break;
> -	case '-':
> -		ce->ce_mode &= ~0111; break;
> -	default:
> -		goto fail;
> -	}
> +	ce->ce_mode = create_ce_mode(force_mode);

create_ce_mode() is supposed to take the st_mode taken from a "struct stat", but here force_mode is 0777 or something else. The above to feed only 0777 or 0666 may happen to work with the way how create_ce_mode() is implemented now, but it is a time-bomb waiting to go off.

Instead of using force_mode that is unsigned, keep the 'flip' as argument, and do:

	if (!S_ISREG(mode))
        	goto fail;
+	if (flip == '+')
+		mode |= 0111;
+	else
+		mode &= ~0111;
	ce->ce_mode = create_ce_mode(mode);

perhaps, as you do not need and are not using the full 9 bits in force_mode anyway.

That would mean chmod_index_entry() introduced in 3/4 and its user in 4/4 need to be updated to pass '+' or '-' down the callchain, but I think that is a good change for the same reason. We do not allow you to set full 9 bits; let's not pretend as if we do so by passing just a single bit '+' or '-' around.

I think 3/4 needs to be fixed where it calls create_ce_mode() with only the 0666/0777 in chmod_index_entry() anyway, regardless of the above suggested change.

Show 20 quoted lines
> diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh
> index dfe02f4..32ac6e0 100755
> --- a/t/t2107-update-index-basic.sh
> +++ b/t/t2107-update-index-basic.sh
> @@ -80,4 +80,17 @@ test_expect_success '.lock files cleaned up' '
>  	)
>  '
>  
> +test_expect_success '--chmod=+x and chmod=-x in the same argument list' '
> +	>A &&
> +	>B &&
> +	git add A B &&
> +	git update-index --chmod=+x A --chmod=-x B &&
> +	cat >expect <<-\EOF &&
> +	100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	A
> +	100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0	B
> +	EOF
> +	git ls-files --stage A B >actual &&
> +	test_cmp expect actual
> +'

Thanks for adding this test. We may want to cross the b/c bridge in a later version bump, but until then it is good to make sure we know what the currently expected behaviour is.

Previous: Thomas GummererNext: Thomas Gummerer
Message 26 of 40 in “`make profile-install` fails in 2.9.3”
  1. Jan KeromnesSep 1, 2016
  2. Dennis KaarsemakerSep 1, 2016
  3. Thomas GummererSep 1, 2016
  4. Jeff KingSep 1, 2016
  5. Junio C HamanoSep 1, 2016
  6. Jeff KingSep 1, 2016
  7. Junio C HamanoSep 1, 2016
  8. 0/4 git add --chmod: always change the fileThomas Gummerer, Sep 4, 2016
  9. 1/4 add: document the chmod optionThomas Gummerer, Sep 4, 2016
  10. Johannes SchindelinSep 5, 2016
  11. Thomas GummererSep 5, 2016
  12. Junio C HamanoSep 7, 2016
  13. 3/4 read-cache: introduce chmod_index_entryThomas Gummerer, Sep 4, 2016
  14. 2/4 update-index: use the same structure for chmod as addThomas Gummerer, Sep 4, 2016
  15. 4/4 add: modify already added files when --chmod is givenThomas Gummerer, Sep 4, 2016
  16. 0/4 git add --chmod: always change the fileThomas Gummerer, Sep 11, 2016
  17. 1/4 add: document the chmod optionThomas Gummerer, Sep 11, 2016
  18. 2/4 update-index: use the same structure for chmod as addThomas Gummerer, Sep 11, 2016
  19. Junio C HamanoSep 11, 2016
  20. Thomas GummererSep 12, 2016
  21. 3/4 read-cache: introduce chmod_index_entryThomas Gummerer, Sep 11, 2016
  22. 4/4 add: modify already added files when --chmod is givenThomas Gummerer, Sep 11, 2016
  23. 0/4 git add --chmod: always change the fileThomas Gummerer, Sep 12, 2016
  24. 1/4 add: document the chmod optionThomas Gummerer, Sep 12, 2016
  25. 2/4 update-index: use the same structure for chmod as addThomas Gummerer, Sep 12, 2016
  26. Junio C HamanoSep 12, 2016
  27. 3/4 read-cache: introduce chmod_index_entryThomas Gummerer, Sep 12, 2016
  28. 4/4 add: modify already added files when --chmod is givenThomas Gummerer, Sep 12, 2016
  29. Junio C HamanoSep 12, 2016
  30. 0/4 git add --chmod: always change the fileThomas Gummerer, Sep 14, 2016
  31. 1/4 add: document the chmod optionThomas Gummerer, Sep 14, 2016
  32. 2/4 update-index: add test for chmod flagsThomas Gummerer, Sep 14, 2016
  33. 3/4 read-cache: introduce chmod_index_entryThomas Gummerer, Sep 14, 2016
  34. Junio C HamanoSep 14, 2016
  35. Junio C HamanoSep 14, 2016
  36. Thomas GummererSep 15, 2016
  37. 4/4 add: modify already added files when --chmod is givenThomas Gummerer, Sep 14, 2016
  38. Junio C HamanoSep 14, 2016
  39. René ScharfeAug 7, 2017
  40. Thomas GummererAug 12, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.