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

Re: [PATCH/RFC v1 2/6] remove some memcpy() and strchr() calls inside create_directories()

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 28, 2009, 20:36 UTC
Message-ID
<7vd4e7np5i.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1233004637-15112-3-git-send-email-barvik@broadpark.no>
Kjetil Barvik <barvik@broadpark.no> writes:
> OK, maybe I instead should have tried to merge the function
> create_directories() with the safe_create_leading_directories() and
> *_const() functions?  What do pepople think?

Strictly speaking, the safe_create_leading_* functions are meant to work on paths inside $GIT_DIR and are not meant for paths inside the work tree, which is this function is about. Their semantics are different with respect to adjust_shared_perm().

Which means that you would either have two variants (one for work tree paths, and another for paths inside $GIT_DIR), or a unified function that has an argument to specify whether to run adjust_shared_perm().

HOWEVER.
That is only "strictly speaking".

A non-bare repository that is shared feels like an oximoron, but perhaps there is a valid "shared work area" workflow that may benefit from such a setup.

I see existing (mis)uses of the safe_create_leading_* in builtin-apply.c, builtin-clone.c (the one that creates the work_tree, the other one is Ok), merge-recursive.c (both call sites) that are used to touch the work tree, but all places that create regular files in the work tree do not run adjust_shared_perm() but simply honor the user's umask.

If we _were_ to support a "shared work area" workflow, having a unified "create leading directory" function that always calls adjust_shared_perm() may make sense (note that adjust_shared_perm() is a no-op in a non-shared repository). We then need to also call adjust_shared_perm() for codepaths that create regular files as well, though (e.g. write_entry() in entry.c, but there are many others).

Show 11 quoted lines
> diff --git a/entry.c b/entry.c
> index 05aa58d..c2404ea 100644
> --- a/entry.c
> +++ b/entry.c
> @@ -2,15 +2,19 @@
>  #include "blob.h"
>  #include "dir.h"
>  
> -static void create_directories(const char *path, const struct checkout *state)
> +static void
> +create_directories(int path_len, const char *path, const struct checkout *state)
Please do not split the line like this.

The existing sources are not laid out to allow "grep ^funcname(", nor are we going to reformat all the files to support such a use case.

When we pass <string, length> pair to functions, I think we pass them in the order I just wrote in all the other functions.

The micro-optimization itself makes sense to me, though.
Previous: Kjetil BarvikNext: Kjetil Barvik
Message 6 of 16 in “git checkout: more cleanups, optimisation, less lstat() calls”
  1. 0/6 git checkout: more cleanups, optimisation, less lstat() callsKjetil Barvik, Jan 26, 2009
  2. 1/6 symlinks.c: small cleanup and optimisationKjetil Barvik, Jan 26, 2009
  3. ??? Re: [PATCH/RFC v1 1/6] symlinks.c: small cleanup and optimisationJunio C Hamano, Jan 28, 2009
  4. Kjetil BarvikJan 29, 2009
  5. 2/6 remove some memcpy() and strchr() calls inside create_directories()Kjetil Barvik, Jan 26, 2009
  6. Junio C HamanoJan 28, 2009
  7. 3/6 cleanup of write_entry() in entry.cKjetil Barvik, Jan 26, 2009
  8. Junio C HamanoJan 28, 2009
  9. 4/6 use fstat() instead of lstat() when we have an opened fileKjetil Barvik, Jan 26, 2009
  10. 5/6 combine-diff.c: remove a call to fstat() inside show_patch_diff()Kjetil Barvik, Jan 26, 2009
  11. Mike RalphsonJan 27, 2009
  12. Kjetil BarvikJan 27, 2009
  13. Mike RalphsonJan 27, 2009
  14. Junio C HamanoJan 28, 2009
  15. Junio C HamanoJan 29, 2009
  16. Kjetil BarvikJan 29, 2009

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.