all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: locate-dominating-file calls `stat' too eagerly
Date: Mon, 29 Sep 2008 12:19:15 -0400	[thread overview]
Message-ID: <jwv1vz3djbf.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <uzllrj9x6.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 29 Sep 2008 17:36:53 +0300")

> That would work as well, but I'm not sure about the ``simpler'' part.

It's definitely a simpler change, which means it's probably safer.

> The code is already pretty convoluted, and I'm not sure why.  All it
> needs to do is (1) to find an existing parent directory of its
> argument FILE by chopping directories from the end until it finds an
> existing one, and (2) go up the tree of existing directories until it
> finds one whose owner is different.  This looks like 2 separate loops
> to me, but the code for some reason insists on doing it in a single
> loop.

I think it's mostly a historical accident, but it's also so that both
loops get the other's fixes.

> How about this:

> (defun locate-dominating-file (file regexp)
>   "Look up the directory hierarchy from FILE for a file matching REGEXP."
>   ;; If FILE does not exist, find its parent directory that does.
>   (or (file-exists-p file)
>       (while (and file (not (file-directory-p file)))
>         (setq file (file-name-directory (directory-file-name file)))))

In some corner cases, this can infloop.
That's why we do (if (equal dir (setq dir ...)) ...) test in the
main loop.
IIRC I wrote pretty much the above loop at some point and when faced
with those issues I figured it was preferable to reuse the main loop so
as to reuse all the experience it embodies.

> And btw, won't the user test cover the case of crossing ~/ as well?

In 99% of the cases, yes.

> If so, we don't need to abbreviate-file-name, which then incurs
> further overhead inside expand-file-name.

This overhead should be negligible.  Furthermore, I'm not sure whether
we'll keep the user-test since it is incompatible with some (rare)
usage patterns.


        Stefan




  reply	other threads:[~2008-09-29 16:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-29 11:54 locate-dominating-file calls `stat' too eagerly Eli Zaretskii
2008-09-29 14:06 ` Stefan Monnier
2008-09-29 14:36   ` Eli Zaretskii
2008-09-29 16:19     ` Stefan Monnier [this message]
2008-09-29 19:05       ` Eli Zaretskii
2008-09-29 20:45         ` Stefan Monnier
2008-09-30  7:14           ` Eli Zaretskii
2008-09-30 14:02             ` Stefan Monnier
2008-09-30 16:30               ` Eli Zaretskii
2008-09-30 12:52   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1vz3djbf.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.