3316 return hash((self.linenum, self.line)) |
3316 return hash((self.linenum, self.line)) |
3317 |
3317 |
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): |
3324 matches[rev].setdefault(fn, []) |
3338 matches[rev].setdefault(fn, []) |
3325 m = matches[rev][fn] |
3339 m = matches[rev][fn] |
3355 iter = difflinestates(pstates, states) |
3369 iter = difflinestates(pstates, states) |
3356 else: |
3370 else: |
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')) |
3364 if opts.get('all'): |
3377 if opts.get('all'): |
3365 cols.append((change, 'grep.change')) |
3378 cols.append((change, 'grep.change')) |
3366 if opts.get('user'): |
3379 if opts.get('user'): |
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 ui.write(before) |
3392 for s, label in l: |
3384 ui.write(match, label='grep.match') |
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 |
3392 skip = {} |
3400 skip = {} |
3393 revfiles = {} |
3401 revfiles = {} |