Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make check_ignore simple again, but with re.search and relative path. #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

natevw
Copy link

@natevw natevw commented Oct 21, 2017

This implements my proposal at #204 (comment) and is similar to how I implemented .couchappignore in putdoc with natevw/putdoc@2a5c16e

…path (instead of re.match and filename). related to couchapp#204
@iblislin
Copy link
Collaborator

diff --git a/couchapp/localdoc.py b/couchapp/localdoc.py
index 7475507..746c29a 100644
--- a/couchapp/localdoc.py
+++ b/couchapp/localdoc.py
@@ -300,10 +300,10 @@ class LocalDoc(object):
     def check_ignore(self, item):
         for pattern in self.ignores:
             match = re.search(pattern, item)
-              if match:
-                  logger.debug("ignoring %s", item)
-                  return True
-              return False
+            if match:
+                logger.debug("ignoring %s", item)
+                return True
+            return False
 
     def dir_to_fields(self, current_dir=None, depth=0, manifest=None):
         """

well, there are some false positive cases in this approach

In [2]: from couchapp.localdoc import LocalDoc                           

In [3]: l = LocalDoc('./tmp/')      

In [4]: l.ignores                   
Out[4]: []                          

In [5]: l.ignores = ['bar']         

In [6]: l.ignores                   
Out[6]: ['bar']                     

In [7]: l.check_ignore('foo/bar/baz')
Out[7]: True

In [8]: l.check_ignore('foo/bar_/baz')
Out[8]: True

In [9]: l.check_ignore('foo/_bar_/baz')
Out[9]: True

so that's why I wrote _combine_path to tokenize a path.

@iblislin
Copy link
Collaborator

I'm not a fan of this:

In [10]: l.ignores = ['att']

In [13]: l.check_ignore('foo/_attachments/baz')
Out[13]: True

@natevw
Copy link
Author

natevw commented Oct 23, 2017

Why would the regex r'bar' not match a path "foo/_bar_/baz"? AFAICT, the .couchappignore has always been for providing a regex, not plain string components.

Because it is a RegEx the author can anchor or add anything else to specify what they actually want to block. If they meant just a file named "bar" they can say ^bar$, or if they want a path component that is exactly bar but anywere they could block using \/bar\/ or if they mean just a top-level folder they could block it with ^bar\/ — it gives the author control.

@iblislin
Copy link
Collaborator

I think I'm doing the trade-off between 'flexibility' (which gives user more control) and 'ease to use' (add more builtin logic).
Basically, I want more 'ease to use', I want it more git-like.

As previous mentioned example, use may hit this pitfall quite often:

In [10]: l.ignores = ['att']

In [13]: l.check_ignore('foo/_attachments/baz')
Out[13]: True

I can understand that as developer's point of view, your proposal is easy to maintain/implement;
but my choice is doing more task for user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants