git
Mercurial “git grep” equivalent extension
Thursday, May 6th, 2010 | Computer Science | Comments
As we are used to git when working on mercurial we miss a lot the “git grep” command as “hg grep” doesn’t really do the same thing. So we managed to quickly create a mercurial extension to add the hgrep command to hg which behaves a bit like git grep.
import itertools, os, os.path def hgrep(ui, repo, what, **opts): files = [] status = repo.status(clean=True) for f in itertools.chain(status[0], status[1], status[4], status[6]): files.append(os.path.join(repo.root, f)) os.system("grep %s %s" % (what, ' '.join(files))) cmdtable = {"hgrep": (hgrep, [], "[what]")}
To have the “hg hgrep” command and make it work just save it as hgrep.py in your python modules path and add it to ~/.hgrc inside the extensions section like:
[extensions] hgrep =
Then you will be able to run “hg grep what” inside a mercurial repository and it will find each file at its current state that contains what you were looking for giving you the complete absolute path to the file.
Search
Archives
- January 2012
- November 2011
- October 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- September 2010
- August 2010
- July 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- October 2008
- August 2008
Tags
3D
acr
apache
automake
autotools
benchmarks
callgrind
canvas
centos
cms
efika
elixir
functional programming
gentoo
gluster
google
labs
libacr
Linux
modsecurity
mongodb
netbook
oprofile
osx
pyhp
python
ragel
rails
redis
repoze.who
review
ruby
security
sprox
sqlalchemy
ssd
Streaming
toscawidgets
turbogears
turbogears2
twitter
valgrind
Web
webserver
windows