Show More
@@ -3318,6 +3318,20 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
3318 | def __eq__(self, other): |
|
3318 | def __eq__(self, other): | |
3319 | return self.line == other.line |
|
3319 | return self.line == other.line | |
3320 |
|
3320 | |||
|
3321 | def __iter__(self): | |||
|
3322 | yield (self.line[:self.colstart], '') | |||
|
3323 | yield (self.line[self.colstart:self.colend], 'grep.match') | |||
|
3324 | rest = self.line[self.colend:] | |||
|
3325 | while rest != '': | |||
|
3326 | match = regexp.search(rest) | |||
|
3327 | if not match: | |||
|
3328 | yield (rest, '') | |||
|
3329 | break | |||
|
3330 | mstart, mend = match.span() | |||
|
3331 | yield (rest[:mstart], '') | |||
|
3332 | yield (rest[mstart:mend], 'grep.match') | |||
|
3333 | rest = rest[mend:] | |||
|
3334 | ||||
3321 | matches = {} |
|
3335 | matches = {} | |
3322 | copies = {} |
|
3336 | copies = {} | |
3323 | def grepbody(fn, rev, body): |
|
3337 | def grepbody(fn, rev, body): | |
@@ -3357,7 +3371,6 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
3357 | iter = [('', l) for l in states] |
|
3371 | iter = [('', l) for l in states] | |
3358 | for change, l in iter: |
|
3372 | for change, l in iter: | |
3359 | cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')] |
|
3373 | cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')] | |
3360 | before, match, after = None, None, None |
|
|||
3361 |
|
3374 | |||
3362 | if opts.get('line_number'): |
|
3375 | if opts.get('line_number'): | |
3363 | cols.append((str(l.linenum), 'grep.linenumber')) |
|
3376 | cols.append((str(l.linenum), 'grep.linenumber')) | |
@@ -3367,25 +3380,20 b' def grep(ui, repo, pattern, *pats, **opt' | |||||
3367 | cols.append((ui.shortuser(ctx.user()), 'grep.user')) |
|
3380 | cols.append((ui.shortuser(ctx.user()), 'grep.user')) | |
3368 | if opts.get('date'): |
|
3381 | if opts.get('date'): | |
3369 | cols.append((datefunc(ctx.date()), 'grep.date')) |
|
3382 | cols.append((datefunc(ctx.date()), 'grep.date')) | |
3370 | if not opts.get('files_with_matches'): |
|
|||
3371 | before = l.line[:l.colstart] |
|
|||
3372 | match = l.line[l.colstart:l.colend] |
|
|||
3373 | after = l.line[l.colend:] |
|
|||
3374 | for col, label in cols[:-1]: |
|
3383 | for col, label in cols[:-1]: | |
3375 | ui.write(col, label=label) |
|
3384 | ui.write(col, label=label) | |
3376 | ui.write(sep, label='grep.sep') |
|
3385 | ui.write(sep, label='grep.sep') | |
3377 | ui.write(cols[-1][0], label=cols[-1][1]) |
|
3386 | ui.write(cols[-1][0], label=cols[-1][1]) | |
3378 | if before is not None: |
|
3387 | if not opts.get('files_with_matches'): | |
3379 | ui.write(sep, label='grep.sep') |
|
3388 | ui.write(sep, label='grep.sep') | |
3380 | if not opts.get('text') and binary(): |
|
3389 | if not opts.get('text') and binary(): | |
3381 | ui.write(" Binary file matches") |
|
3390 | ui.write(" Binary file matches") | |
3382 | else: |
|
3391 | else: | |
3383 |
|
|
3392 | for s, label in l: | |
3384 |
ui.write( |
|
3393 | ui.write(s, label=label) | |
3385 | ui.write(after) |
|
|||
3386 | ui.write(eol) |
|
3394 | ui.write(eol) | |
3387 | found = True |
|
3395 | found = True | |
3388 | if before is None: |
|
3396 | if opts.get('files_with_matches'): | |
3389 | break |
|
3397 | break | |
3390 | return found |
|
3398 | return found | |
3391 |
|
3399 |
@@ -38,7 +38,7 b' simple with color' | |||||
38 | > --color=always port port |
|
38 | > --color=always port port | |
39 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc) |
|
39 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mex\x1b[0;31;1mport\x1b[0m (esc) | |
40 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc) |
|
40 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mva\x1b[0;31;1mport\x1b[0might (esc) | |
41 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/export (esc) |
|
41 | \x1b[0;35mport\x1b[0m\x1b[0;36m:\x1b[0m\x1b[0;32m4\x1b[0m\x1b[0;36m:\x1b[0mim\x1b[0;31;1mport\x1b[0m/ex\x1b[0;31;1mport\x1b[0m (esc) | |
42 |
|
42 | |||
43 | all |
|
43 | all | |
44 |
|
44 |
General Comments 0
You need to be logged in to leave comments.
Login now