Mercurial > public > mercurial-scm > hg
diff mercurial/commands.py @ 13920:332e400764e5
grep: don't print data from binary files for matches (issue2614)
author | Md. O. Shayan <mdoshayan@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 23:13:17 +0530 |
parents | 6bc340940c18 |
children | 14d0553bd48b |
line wrap: on
line diff
--- a/mercurial/commands.py Sat Apr 09 23:53:23 2011 +0300 +++ b/mercurial/commands.py Sat Apr 09 23:13:17 2011 +0530 @@ -1871,6 +1871,10 @@ datefunc = ui.quiet and util.shortdate or util.datestr found = False filerevmatches = {} + def binary(): + flog = getfile(fn) + return util.binary(flog.read(ctx.filenode(fn))) + if opts.get('all'): iter = difflinestates(pstates, states) else: @@ -1897,9 +1901,12 @@ after = l.line[l.colend:] ui.write(sep.join(cols)) if before is not None: - ui.write(sep + before) - ui.write(match, label='grep.match') - ui.write(after) + if not opts.get('text') and binary(): + ui.write(sep + " Binary file matches") + else: + ui.write(sep + before) + ui.write(match, label='grep.match') + ui.write(after) ui.write(eol) found = True return found @@ -4567,6 +4574,7 @@ (grep, [('0', 'print0', None, _('end fields with NUL')), ('', 'all', None, _('print all revisions that match')), + ('a', 'text', None, _('treat all files as text')), ('f', 'follow', None, _('follow changeset history,' ' or file history across copies and renames')),