[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn ls --search/pattern/glob/case-insensitive

From: Stefan Sperling <stsp_at_elego.de>
Date: Fri, 1 Sep 2017 17:55:43 +0200

On Fri, Sep 01, 2017 at 04:24:28PM +0100, Julian Foad wrote:
> And, for consistency, when matching paths with "svn log -vq --search..."
> I would expect the same (I would not expect 'dog*' to match
> lazy_dog.txt). At present the implementation does match it, because it
> treats the pattern as a substring both when searching in the log message
> and also when searching in the paths. I propose that one way to get
> consistency is if we change "svn log --search" so it treats the pattern
> as a substring in the log message but not in the paths.

Yes, that makes sense. Here's an attempt at it.

My patch is not quite correct because it does not support slashes in
the search pattern and it will not match across multiple path components.
Any suggestion how to best implement this?

$ svn log -v -r4 --search 'lazy*'
------------------------------------------------------------------------
r4 | stsp | 2017-09-01 17:42:07 +0200 (Fri, 01 Sep 2017) | 1 line
Changed paths:
   M /trunk/lazy_dog.txt

this is a log message
------------------------------------------------------------------------
$ svn log -v -r4 --search 'dog*'
------------------------------------------------------------------------

This should match but does not:
$ svn log -v -r4 --search '/trunk/*dog*'
------------------------------------------------------------------------
$

Index: subversion/svn/log-cmd.c
===================================================================
--- subversion/svn/log-cmd.c (revision 1806831)
+++ subversion/svn/log-cmd.c (working copy)
@@ -160,8 +160,10 @@ match_search_pattern(const char *search_pattern,
   if (changed_paths)
     {
       apr_hash_index_t *hi;
+ apr_pool_t *iterpool;
 
       /* Does a changed path match the search pattern? */
+ iterpool = svn_pool_create(pool);
       for (hi = apr_hash_first(pool, changed_paths);
            hi;
            hi = apr_hash_next(hi))
@@ -168,17 +170,37 @@ match_search_pattern(const char *search_pattern,
         {
           const char *path = apr_hash_this_key(hi);
           svn_log_changed_path2_t *log_item;
+ apr_array_header_t *components;
+ int i;
 
- if (match(pattern, path, buf))
- return TRUE;
+ svn_pool_clear(iterpool);
 
+ components = svn_path_decompose(path, iterpool);
+ for (i = 0; i < components->nelts; i++)
+ {
+ const char *p = APR_ARRAY_IDX(components, i, const char *);
+
+ if (match(search_pattern, p, buf))
+ return TRUE;
+ }
+
           /* Match copy-from paths, too. */
           log_item = apr_hash_this_val(hi);
           if (log_item->copyfrom_path
- && SVN_IS_VALID_REVNUM(log_item->copyfrom_rev)
- && match(pattern, log_item->copyfrom_path, buf))
- return TRUE;
+ && SVN_IS_VALID_REVNUM(log_item->copyfrom_rev))
+ {
+ components = svn_path_decompose(log_item->copyfrom_path,
+ iterpool);
+ for (i = 0; i < components->nelts; i++)
+ {
+ const char *p = APR_ARRAY_IDX(components, i, const char *);
+
+ if (match(search_pattern, p, buf))
+ return TRUE;
+ }
+ }
         }
+ svn_pool_destroy(iterpool);
     }
 
   return FALSE;
Received on 2017-09-01 17:55:52 CEST

This is an archived mail posted to the Subversion Dev mailing list.