gitlabhq / grit

Grit gives you object oriented read/write access to Git repositories via Ruby. Patched for GitLab
gitlab.org
MIT License
59 stars 55 forks source link

Advanced search syntax #40

Closed GeorgeDewar closed 10 years ago

GeorgeDewar commented 10 years ago

Datacom requires the ability in GitLab to be able to perform advanced searches, for example a search for files containing "def index" and "email", but not containing "cats".

To achieve this I have modified grit to add an advanced_grep method. This supports search queries such as email "def index" -cats.

The intention is that gitlab_git and then ultimately gitlabhq can take advantage of this new method, which would supersede the original grep method. The only reason it's a separate method is to ensure that the behaviour of callers to this library are unaffected until they deliberately use the new method. However, of course we are after the community's input regarding the optimal structure for this change.

There are two areas of incompatibility with the existing grep method:

  1. This advanced_grep method requires the search input NOT to be escaped by the caller, but rather it does the shell escaping itself. This is because quote marks are now important syntactical user input.
  2. The default behaviour would no longer be an exact string match, but rather all terms appearing anywhere in a given file. An exact string match search would require quotation marks to be used.

We hope that this work is useful and that the new behaviour is desirable for most or all GitLab users.

One thing I'd say this definitely lacks (which I will wait for feedback before addressing) is testing regarding its handling of matches in binary files. I notice however that there is another pull request open which adds a test relating to this, which is helpful.

dzaporozhets commented 10 years ago

@GeorgeDewar looks good. I think we can merge this one. Thank you