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

Re: [PATCH v4 4/4] add: modify already added files when --chmod is given

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Aug 12, 2017, 12:30 UTC
Message-ID
<20170812123010.GA4304@hank>
In-Reply-To
<3c61d9f6-e0fd-22a4-68e0-89fd9ce9b944@web.de>
On 08/07, René Scharfe wrote:
Show 12 quoted lines
> Am 14.09.2016 um 23:07 schrieb Thomas Gummerer:
> > When the chmod option was added to git add, it was hooked up to the diff
> > machinery, meaning that it only works when the version in the index
> > differs from the version on disk.
> > 
> > As the option was supposed to mirror the chmod option in update-index,
> > which always changes the mode in the index, regardless of the status of
> > the file, make sure the option behaves the same way in git add.
> > 
> > Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
> 
> Sorry for replying almost a year late, hopefully you're still interested.
Thanks for still replying :)
Show 44 quoted lines
> > ---
> >   builtin/add.c      | 47 ++++++++++++++++++++++++++++-------------------
> >   builtin/checkout.c |  2 +-
> >   builtin/commit.c   |  2 +-
> >   cache.h            | 10 +++++-----
> >   read-cache.c       | 14 ++++++--------
> >   t/t3700-add.sh     | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >   6 files changed, 91 insertions(+), 34 deletions(-)
> > 
> > diff --git a/builtin/add.c b/builtin/add.c
> > index b1dddb4..595a0b2 100644
> > --- a/builtin/add.c
> > +++ b/builtin/add.c
> > @@ -26,10 +26,25 @@ static int patch_interactive, add_interactive, edit_interactive;
> >   static int take_worktree_changes;
> >   
> >   struct update_callback_data {
> > -	int flags, force_mode;
> > +	int flags;
> >   	int add_errors;
> >   };
> >   
> > +static void chmod_pathspec(struct pathspec *pathspec, int force_mode)
> 
> "int force_mode" looks like a binary (or perhaps ternary) flag, but
> actually it is a character and can only have the values '-' or '+'.
> In builtin/update-index.c it's called "char flip" and we probably should
> define it like this here as well.
> 
> > +{
> > +	int i;
> > +	
> > +	for (i = 0; i < active_nr; i++) {
> > +		struct cache_entry *ce = active_cache[i];
> > +
> > +		if (pathspec && !ce_path_match(ce, pathspec, NULL))
> > +			continue;
> > +
> > +		if (chmod_cache_entry(ce, force_mode) < 0)
> > +			fprintf(stderr, "cannot chmod '%s'", ce->name);
> 
> This error message is missing a newline.  In builtin/update-index.c we
> also show the attempted change (-x or +x); perhaps we want to do that
> here as well.

Thanks for catching this, both this and the above are worth changing imo. I see Ramsay already provided a patch for this in https://public-inbox.org/git/aa004526-3e0d-66d4-287f-30abd29758fc@ramsayjones.plus.com/. Thanks Ramsay!

Show 18 quoted lines
> Currently chmod_cache_entry() can only fail if ce is not a regular
> file or it's other parameter is neither '-' nor '+'.  We rule out the
> latter already in the argument parsing code.  The former can happen if
> we add a symlink, either explicitly or because it's in a directory
> we're specified.
> 
> I wonder if we even need to report anything, or under which conditions.
> If you have a file named dir/file and a symlink named dir/symlink then
> the interesting cases are:
> 
> 	git add --chmod=.. dir/symlink
> 	git add --chmod=.. dir/file dir/symlink
> 	git add --chmod=.. dir
> 
> Warning about each case may be the most cautious thing to do, but
> documenting that --chmod has no effect on symlinks and keeping silent
> might be less annoying, especially in the last case.  What do you
> think?

I'm not sure about this. While I do agree that it could be quite annoying in the last case, it could potentially be a bit confusing to not get any warning in the first case. I don't have a strong opinion either way.

Show 21 quoted lines
> > @@ -342,13 +354,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
> >   	if (!show_only && ignore_missing)
> >   		die(_("Option --ignore-missing can only be used together with --dry-run"));
> >   
> > -	if (!chmod_arg)
> > -		force_mode = 0;
> > -	else if (!strcmp(chmod_arg, "-x"))
> > -		force_mode = 0666;
> > -	else if (!strcmp(chmod_arg, "+x"))
> > -		force_mode = 0777;
> > -	else
> > +	if (chmod_arg && ((chmod_arg[0] != '-' && chmod_arg[0] != '+') ||
> > +			  chmod_arg[1] != 'x' || chmod_arg[2]))
> >   		die(_("--chmod param '%s' must be either -x or +x"), chmod_arg);
> 
> That's the argument parsing code mentioned above.  The strcmp-based
> checks look nicer to me btw.  How about this?
> 
> 	if (chmod_arg && strcmp(chmod_arg, "-x") && strcmp(chmod_arg, "+x"))
> 
> But that's just nitpicking.

I think this looks nicer indeed, thanks! But it's probably not worth a patch for just this unless we decide to change to not warn as you mentioned above, and can fix this at the same time?

> René
Previous: René Scharfe
Message 40 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.