zsh-workers
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-workers@zsh.org
Subject: Re: PATCH: Update VCS_INFO_detect_svn for Subversion 1.7
Date: Wed, 09 Nov 2011 14:58:12 +0100	[thread overview]
Message-ID: <877h39z9cb.fsf@ft.bewatermyfriend.org> (raw)
In-Reply-To: <87boslzcic.fsf@ft.bewatermyfriend.org> (Frank Terbeck's message of "Wed, 09 Nov 2011 13:49:47 +0100")

Frank Terbeck wrote:
[...]
> I was kind of hoping to do this with a clever detection algorithm, which
> would work for both versions and still reveal the sandbox's root
> directory. So that we could scratch the root-retrieval from the
> `_get_data_' function altogether.

I had an idea. How about abusing evaluated globbing for this?

local -a reply
reply=( (../)#.svn(/Ne@'[ ! -d "${REPLY:h}/../.svn" ] && { [ -f "${REPLY}/format" ] || [ -f "${REPLY}/entries" ]; }'@:A) )

Say whaaat?

Yeah, let me explain: When in a subversion sandbox, then `$reply' should
contain exactly *one* entry, and that's the full name of the sandbox's
root directory. If not, the `$reply' array should be empty.

How does it work? Well, the "(../)#.svn(/N)" pattern matches all .svn
sub-directories from the current directory up to the root directory `/'.

The ":A" at the end is responsible for turning relative paths into
absolute ones.

Now the fun is happening in the e@'...'@ expression. The "..." is shell
code that's evaluated with $REPLY set to all of the matching files from
the preceding glob. One file (or directory in this case) after another.

The "[ ! -d "${REPLY:h}/../.svn" ]" checks if there's a .svn directory
in the parent directory. If that's not the case, then we found the root
of the sandbox.

And then "{ [ -f "${REPLY}/format" ] || [ -f "${REPLY}/entries" ]; }" is
just the old test to make sure the `.svn' directory is really from a
sandbox and not from something else.

(If all the above was clear anyway, sorry for the long mail.)

I think this should work nicely for 1.7 and 1.6 (and before) without
causing doubled work.

Also, I think that most - if not all - calls to
`VCS_INFO_detect_by_dir()' could be replaced by a similar globbing
expression. That might improve performance. I don't know.

I'll come up with a patch for `VCS_INFO_detect_svn' later, unless
someone finds a flaw in the above idea.

Regards, Frank


  reply	other threads:[~2011-11-09 14:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09  5:17 Akinori MUSHA
2011-11-09 12:49 ` Frank Terbeck
2011-11-09 13:58   ` Frank Terbeck [this message]
2011-11-09 15:57     ` Bart Schaefer
2011-11-09 16:07       ` Daniel Shahaf
2011-11-09 16:12       ` Jérémie Roquet
2011-11-09 16:30 ` Frank Terbeck

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=877h39z9cb.fsf@ft.bewatermyfriend.org \
    --to=ft@bewatermyfriend.org \
    --cc=zsh-workers@zsh.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 public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).