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

Re: [PATCH] Demonstrate breakage: checkout overwrites untracked symlink with directory

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 9, 2011, 23:48 UTC
Message-ID
<7vpqr0n51f.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20110205183351.GA25717@localhost>
Clemens Buchacher <drizzd@aon.at> writes:
Show 13 quoted lines
> diff --git a/symlinks.c b/symlinks.c
> index 3cacebd..034943b 100644
> --- a/symlinks.c
> +++ b/symlinks.c
> @@ -223,7 +223,7 @@ int check_leading_path(const char *name, int len)
>         int flags;
>         int match_len = lstat_cache_matchlen(cache, name, len, &flags,
>                            FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
> -       if (flags & (FL_SYMLINK|FL_NOENT))
> +       if (flags & FL_NOENT)
>                 return 0;
>         else if (flags & FL_DIR)
>                 return -1;

This function used to be named has-symlink-or-noent-leading-path before f66caaf (do not overwrite files in leading path, 2010-10-09) and was used to check for exactly that condition. For example, verify_absent_1() used it to verify that a path A/B/C/D is not on the filesystem (e.g. in preparation for checking it out) by making sure that none of A, A/B, or A/B/C exists -- or is an untracked symlink. If one of them is a symlink leading elsewhere, even if lstat("A/B/C/D") said the path exists, A/B/C/D is not something we have in the work tree, and we decide that we can check out the path by possibly removing intermediate symbolic link and running mkdir.

Now you are changing the semantics of the function, so that we cannot clobber intermediate symbolic links when we check out a path. It may probably be a good change.

Can we rename this function to fix the naming regression introduced in f66caaf, by the way? "check_leading_path()" is a horrible name for a function that takes some parameters and returns a boolean, as the boolness of the function already says enough that it is about "check", giving the first part of the name 0-bit of information, and the remainder of the name doesn't say much either: what aspect of leading-path is the function about? Should the pathcomponents exist, should they not exist, why should the caller care?

A name that explains for what purpose the caller is expected to call it is probably the best kind of name. As long as the purpose does not change, even though the implementation and the semantics are changed later, the name can stay the same without losing its meaning. The second best kind is a name that explains what it does. The old name of this function was of this kind, until f66caaf renamed it to a meaningless name.

Perhaps can-clobber-to-checkout would be a good candidate.
Previous: Clemens BuchacherNext: Clemens Buchacher
Message 6 of 14 in “untracked symlinks are less precious than untracked files?”
  1. Johannes SixtFeb 2, 2011
  2. Junio C HamanoFeb 2, 2011
  3. Johannes SixtFeb 2, 2011
  4. Demonstrate breakage: checkout overwrites untracked symlink with directoryJohannes Sixt, Feb 5, 2011
  5. Clemens BuchacherFeb 5, 2011
  6. Junio C HamanoFeb 9, 2011
  7. Clemens BuchacherFeb 10, 2011
  8. do not overwrite untracked symlinksClemens Buchacher, Feb 20, 2011
  9. Junio C HamanoFeb 21, 2011
  10. Clemens BuchacherFeb 21, 2011
  11. Junio C HamanoFeb 22, 2011
  12. Clemens BuchacherFeb 22, 2011
  13. Junio C HamanoFeb 22, 2011
  14. Johannes SixtFeb 15, 2011

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.