Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
13919:67f20625703f | 13920:332e400764e5 |
---|---|
1869 def display(fn, ctx, pstates, states): | 1869 def display(fn, ctx, pstates, states): |
1870 rev = ctx.rev() | 1870 rev = ctx.rev() |
1871 datefunc = ui.quiet and util.shortdate or util.datestr | 1871 datefunc = ui.quiet and util.shortdate or util.datestr |
1872 found = False | 1872 found = False |
1873 filerevmatches = {} | 1873 filerevmatches = {} |
1874 def binary(): | |
1875 flog = getfile(fn) | |
1876 return util.binary(flog.read(ctx.filenode(fn))) | |
1877 | |
1874 if opts.get('all'): | 1878 if opts.get('all'): |
1875 iter = difflinestates(pstates, states) | 1879 iter = difflinestates(pstates, states) |
1876 else: | 1880 else: |
1877 iter = [('', l) for l in states] | 1881 iter = [('', l) for l in states] |
1878 for change, l in iter: | 1882 for change, l in iter: |
1895 before = l.line[:l.colstart] | 1899 before = l.line[:l.colstart] |
1896 match = l.line[l.colstart:l.colend] | 1900 match = l.line[l.colstart:l.colend] |
1897 after = l.line[l.colend:] | 1901 after = l.line[l.colend:] |
1898 ui.write(sep.join(cols)) | 1902 ui.write(sep.join(cols)) |
1899 if before is not None: | 1903 if before is not None: |
1900 ui.write(sep + before) | 1904 if not opts.get('text') and binary(): |
1901 ui.write(match, label='grep.match') | 1905 ui.write(sep + " Binary file matches") |
1902 ui.write(after) | 1906 else: |
1907 ui.write(sep + before) | |
1908 ui.write(match, label='grep.match') | |
1909 ui.write(after) | |
1903 ui.write(eol) | 1910 ui.write(eol) |
1904 found = True | 1911 found = True |
1905 return found | 1912 return found |
1906 | 1913 |
1907 skip = {} | 1914 skip = {} |
4565 _('[OPTION]... FILE...')), | 4572 _('[OPTION]... FILE...')), |
4566 "grep": | 4573 "grep": |
4567 (grep, | 4574 (grep, |
4568 [('0', 'print0', None, _('end fields with NUL')), | 4575 [('0', 'print0', None, _('end fields with NUL')), |
4569 ('', 'all', None, _('print all revisions that match')), | 4576 ('', 'all', None, _('print all revisions that match')), |
4577 ('a', 'text', None, _('treat all files as text')), | |
4570 ('f', 'follow', None, | 4578 ('f', 'follow', None, |
4571 _('follow changeset history,' | 4579 _('follow changeset history,' |
4572 ' or file history across copies and renames')), | 4580 ' or file history across copies and renames')), |
4573 ('i', 'ignore-case', None, _('ignore case when matching')), | 4581 ('i', 'ignore-case', None, _('ignore case when matching')), |
4574 ('l', 'files-with-matches', None, | 4582 ('l', 'files-with-matches', None, |