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

Re: [PATCH] add: add --chmod=+x / --chmod=-x options

From
Junio C Hamano <gitster@pobox.com>
Date
May 27, 2016, 18:35 UTC
Message-ID
<xmqqinxzqrhn.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<alpine.DEB.2.20.1605250923120.4449@virtualbox>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> I wonder, however, whether it would be "cleaner" to simply make this an
> OPT_STRING and perform the validation after the option parsing.
Yes, I think I touched on this in my comments in a bit more detail.
> Hmm. This change uses up 2 out of 31 available bits. I wonder whether a
> better idea would be to extend struct update_callback_data to include a
> `force_mode` field, pass a parameter of the same name to
> add_files_to_cache() and then handle that in the update_callback().

Maybe. I am not sure if it is a good idea to do lstat(2) on the calling side, though. Assuming it is, your "something like this" needs to be duplicated for the codepath that adds a new file, which is separate from the one we see below (i.e. add_files()).

Show 18 quoted lines
> Something like this:
>
>                 case DIFF_STATUS_MODIFIED:
> -               case DIFF_STATUS_TYPE_CHANGED:
> +               case DIFF_STATUS_TYPE_CHANGED: {
> +			struct stat st;
> +			if (lstat(path, &st))
> +				die_errno("unable to stat '%s'", path);
> +			if (S_ISREG(&st.st_mode) && data->force_mode)
> +				st.st_mode = data->force_mode;
> -                       if (add_file_to_index(&the_index, path, data->flags)) {
> +                       if (add_to_index(&the_index, path, &st, data->flags)) {
>                                 if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
>                                         die(_("updating files failed"));
>                                 data->add_errors++;
>                         }
>                         break;
> +		}
Previous: Johannes SchindelinNext: Junio C Hamano
Message 13 of 14 in “add: add --chmod=+x / --chmod=-x options”
  1. add: add --chmod=+x / --chmod=-x optionsEdward Thomson, May 25, 2016
  2. Junio C HamanoMay 25, 2016
  3. Johannes SchindelinMay 25, 2016
  4. Junio C HamanoMay 25, 2016
  5. Johannes SchindelinMay 25, 2016
  6. Junio C HamanoMay 25, 2016
  7. Edward ThomsonMay 27, 2016
  8. Mike HommeyMay 27, 2016
  9. Junio C HamanoMay 27, 2016
  10. Junio C HamanoMay 27, 2016
  11. Edward ThomsonMay 31, 2016
  12. Johannes SchindelinMay 25, 2016
  13. Junio C HamanoMay 27, 2016
  14. Junio C HamanoMay 25, 2016

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.