Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Update VCS_INFO_detect_svn for Subversion 1.7



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



Messages sorted by: Reverse Date, Date, Thread, Author