From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8888 invoked by alias); 9 Nov 2011 14:11:02 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29902 Received: (qmail 17297 invoked from network); 9 Nov 2011 14:10:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at bewatermyfriend.org does not designate permitted sender hosts) From: Frank Terbeck To: zsh-workers@zsh.org Subject: Re: PATCH: Update VCS_INFO_detect_svn for Subversion 1.7 In-Reply-To: <87boslzcic.fsf@ft.bewatermyfriend.org> (Frank Terbeck's message of "Wed, 09 Nov 2011 13:49:47 +0100") References: <86sjlxoows.knu@iDaemons.org> <87boslzcic.fsf@ft.bewatermyfriend.org> User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux) Date: Wed, 09 Nov 2011 14:58:12 +0100 Message-ID: <877h39z9cb.fsf@ft.bewatermyfriend.org> MIME-Version: 1.0 Content-Type: text/plain X-Df-Sender: NDMwNDQ0 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