bzr grep should be builtin

Bug #503670 reported by Martin Pool
26
This bug affects 6 people
Affects Status Importance Assigned to Milestone
Bazaar
Won't Fix
Medium
Parth Malwankar

Bug Description

james_w wrote:

On Wed, 6 Jan 2010 09:42:04 +1100, Jonathan Lange <email address hidden> wrote:
> Interestingly, I showed the recipe for bzr-tools-grep at UDS-L, and a
> git fan in the audience sniggered about Bazaar's vaunted usability
> because,
> "bzr ls -VR --kind=file --null | xargs -0 grep -In %s"
>
> becomes
> "git grep %s"
>
> Perhaps someone would like to add the grep command to bzr-core, or a plugin.

You mean like lp:~vila/bzr/grep (confusingly a plugin under the bzr
project?)

I agree that it would be great to have it in core.

Tags: easy

Related branches

Martin Pool (mbp)
description: updated
Revision history for this message
Parth Malwankar (parthm) wrote :

I noticed that lp:~vila/bzr/grep uses xarg and grep as a subprocess.
Essentially the same as the command in comment #1. It won't work on windows.

Maybe this should be a pure python solution?

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 503670] Re: bzr grep should be builtin

On 19 February 2010 00:21, Parth Malwankar <email address hidden> wrote:
> I noticed that lp:~vila/bzr/grep uses xarg and grep as a subprocess.
> Essentially the same as the command in comment #1. It won't work on windows.
>
> Maybe this should be a pure python solution?

I think eventually it should, but in the interim depending on an
external grep command should be ok. I would expect that it's pretty
easy to remove the dependency on xargs.

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
Parth Malwankar (parthm) wrote :

I could have a look at this in case vila (or anyone else) is not planning to work on this anytime soon.

I was thinking that this could probably be developed as a plugin and in a month or so if there are no issues it could be proposed for a merge.

Regarding the 'bzr grep' command, my understanding is that we want to search through the versioned files, not files contained in the working directory and not history (hgrep? Bug #161250). Is this correct?

hg grep searches history. I am not sure if it has something for searching versioned files.
Does anyone know how git grep behaves?

What are the important command line options that need to be supported? I am assuming it should at least have the commonly used options from unix grep.

Revision history for this message
Martin Pool (mbp) wrote :

On 20 February 2010 00:15, Parth Malwankar <email address hidden> wrote:
> I could have a look at this in case vila (or anyone else) is not
> planning to work on this anytime soon.
>
> I was thinking that this could probably be developed as a plugin and in
> a month or so if there are no issues it could be proposed for a merge.

There already is a plugin; this bug just wants it to be included in
bzr's core, or turned into a shipped plugin.

> Regarding the 'bzr grep' command, my understanding is that we want to
> search through the versioned files, not files contained in the working
> directory and not history (hgrep? Bug #161250). Is this correct?

I think at the moment it searches the versioned files. Searching
history would also be good.

>
> hg grep searches history. I am not sure if it has something for searching versioned files.
> Does anyone know how git grep behaves?
>
> What are the important command line options that need to be supported? I
> am assuming it should at least have the commonly used options from unix
> grep.

I think it would be worth getting it in even with no options, or
perhaps just --ignore-case.

--
Martin <http://launchpad.net/~mbp/>

Parth Malwankar (parthm)
Changed in bzr:
assignee: nobody → Parth Malwankar (parthm)
status: Confirmed → In Progress
Revision history for this message
Robert Collins (lifeless) wrote :

Perhaps we should just recommend this in the package dependencies? I don't think the right answer to every 'project X has it built in' is to fold it into core.

Revision history for this message
Robert Collins (lifeless) wrote :

I should expand on why I say that. git grep is a vastly different beast to the plugin we have in bzr; it can look in arbitrary revisions, in the basis tree, or the working tree.

Merging something more roughly equivalent to it would make a great deal of sense. I have the feeling though that most things that are plugins are plugins because their authors feel that they are not (appropriate|good enough) to merge to core: so we'll get disappointing results fixing 'you do not have a FOO' by taking the simple route of 'just merge to trunk'.

Revision history for this message
Parth Malwankar (parthm) wrote :

I have a similar view as Robert.

To elaborate more on my previous comment #3. IMO bzr should have a portable implementation (pure python) which searches the working tree by default and optionally searches history on all supported platforms. It may take some time for a feature of that size to mature so it can probably be created as a separate plugin and if that works well (standard grep options, history support, good performance etc.) it should probably be considered for folding into the core. The history support could possibly be done as a separate patch.

Revision history for this message
Martin Pool (mbp) wrote :

I think the most important thing is that there be a good grep command, that works against bzr tip.

Next most important is that it be easily available, either in the binary installers or packaged for unix. Having it built in is just a means to that end, and not necessarily the best means.

Perhaps this bug should be recast as: bzr-grep should have a test suite, it should pass against bzr tip, and it should then be run by babune, and it should be packaged for ubuntu.

Also, it would be cool if 'bzr grep' without the plugin installed suggested 'you should install bzr-grep'. I thought someone prototyped this...

Revision history for this message
Parth Malwankar (parthm) wrote :

bzr-search[1] certainly seems like a plugin that does a good job at searching
the content. Maybe bzr-search does what we want?

[1] https://launchpad.net/bzr-search

Revision history for this message
Martin Pool (mbp) wrote :

On 23 February 2010 13:01, Parth Malwankar <email address hidden> wrote:
> bzr-search[1] certainly seems like a plugin that does a good job at searching
> the content. Maybe bzr-search does what we want?

It searches a keyword index so it has complementary functionality.

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
Parth Malwankar (parthm) wrote :

Based on the dicussion, I have created a bzr-grep[1] plugin.
This works on windows and linux and searches versioned files in the working tree.
There is no support for views and history yet. I am still working on the tests.
Please consider this pre-alpha.

[grep]% bzr help grep
Purpose: Print lines matching PATTERN for specified files.
Usage: bzr grep PATTERN [PATH...]

Options:
  --from-root Search for pattern starting from the root of the branch.
  -R, --recursive Recurse into subdirectories.
  -h, --help Show help message.
  -q, --quiet Only display errors and warnings.
  -i, --ignore-case ignore case distinctions while matching.
  --usage Show usage message and options.
  -z, --null Write an ascii NUL (\0) separator between output lines
                     rather than a newline.
  -v, --verbose Display more information.

From: plugin "grep"
See also: plugins/grep

[1] https://code.launchpad.net/bzr-grep

Revision history for this message
Martin Pool (mbp) wrote :

I'm thinking about this a lot (see recent thread "plugins vs builtins"), and I think this actually doesn't need to be built in, just easily accessible. A packaged plugin would satisfy this. Also it may enable us to have it work on 2.1 or 2.0.

If Parth as the author strongly prefers it to be builtin, I wouldn't veto it just on the grounds that it _could_ be in a plugin. Otherwise, I suggest we close this as wontfix.

Of course he's still welcome to get code review on the code going into the plugin.

Revision history for this message
Parth Malwankar (parthm) wrote :

On Wed, Mar 3, 2010 at 12:10 PM, Martin Pool <email address hidden> wrote:
> I'm thinking about this a lot (see recent thread "plugins vs builtins"),
> and I think this actually doesn't need to be built in, just easily
> accessible.  A packaged plugin would satisfy this.  Also it may enable
> us to have it work on 2.1 or 2.0.
>

Yes. Thats certainly a big advantage of having it as a plugin.

> If Parth as the author strongly prefers it to be builtin, I wouldn't
> veto it just on the grounds that it _could_ be in a plugin.  Otherwise,
> I suggest we close this as wontfix.
>

I don't have a preference one way or another. Plugin works fine for
me. In fact I was thinking if it made sense of maintain a plugin even
if it became a builtin to make it available for 2.0/2.1.

One question though is how to we make the command easily available
to users but I suppose thats being discussed in the "plugins vs builtins"
thread.

> Of course he's still welcome to get code review on the code going into
> the plugin.
>
> --
> bzr grep should be builtin
> https://bugs.launchpad.net/bugs/503670
> You received this bug notification because you are a bug assignee.
>
> Status in Bazaar Version Control System: In Progress
>
> Bug description:
> james_w wrote:
>
> On Wed, 6 Jan 2010 09:42:04 +1100, Jonathan Lange <email address hidden> wrote:
>> Interestingly, I showed the recipe for bzr-tools-grep at UDS-L, and a
>> git fan in the audience sniggered about Bazaar's vaunted usability
>> because,
>>    "bzr ls -VR --kind=file --null | xargs -0 grep -In %s"
>>
>> becomes
>>   "git grep %s"
>>
>> Perhaps someone would like to add the grep command to bzr-core, or a plugin.
>
> You mean like lp:~vila/bzr/grep (confusingly a plugin under the bzr
> project?)
>
> I agree that it would be great to have it in core.
>
>
>
>
>

Revision history for this message
Parth Malwankar (parthm) wrote :

Based on the above discussion marking this as won't fix. lp:bzr-grep can be used for grep support.

Changed in bzr:
status: In Progress → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.