Mercurial > hg
comparison mercurial/commands.py @ 38217:16f93a3b8b05
grep: enable passing wdir as a revision
When you pass wdir() to the -r flag, it catches the WdirUnsupported error
and falls back to an alternate path.
Differential Revision: https://phab.mercurial-scm.org/D3673
author | Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com> |
---|---|
date | Wed, 30 May 2018 17:37:17 +0530 |
parents | 22edd5321489 |
children | ad50f0399e1e |
comparison
equal
deleted
inserted
replaced
38216:22edd5321489 | 38217:16f93a3b8b05 |
---|---|
2511 yield ('-', a[i]) | 2511 yield ('-', a[i]) |
2512 for i in xrange(blo, bhi): | 2512 for i in xrange(blo, bhi): |
2513 yield ('+', b[i]) | 2513 yield ('+', b[i]) |
2514 | 2514 |
2515 def display(fm, fn, ctx, pstates, states): | 2515 def display(fm, fn, ctx, pstates, states): |
2516 rev = ctx.rev() | 2516 rev = scmutil.intrev(ctx) |
2517 if fm.isplain(): | 2517 if fm.isplain(): |
2518 formatuser = ui.shortuser | 2518 formatuser = ui.shortuser |
2519 else: | 2519 else: |
2520 formatuser = str | 2520 formatuser = str |
2521 if ui.quiet: | 2521 if ui.quiet: |
2524 datefmt = '%a %b %d %H:%M:%S %Y %1%2' | 2524 datefmt = '%a %b %d %H:%M:%S %Y %1%2' |
2525 found = False | 2525 found = False |
2526 @util.cachefunc | 2526 @util.cachefunc |
2527 def binary(): | 2527 def binary(): |
2528 flog = getfile(fn) | 2528 flog = getfile(fn) |
2529 return stringutil.binary(flog.read(ctx.filenode(fn))) | 2529 try: |
2530 return stringutil.binary(flog.read(ctx.filenode(fn))) | |
2531 except error.WdirUnsupported: | |
2532 return ctx[fn].isbinary() | |
2530 | 2533 |
2531 fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} | 2534 fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} |
2532 if opts.get('all'): | 2535 if opts.get('all'): |
2533 iter = difflinestates(pstates, states) | 2536 iter = difflinestates(pstates, states) |
2534 else: | 2537 else: |
2535 iter = [('', l) for l in states] | 2538 iter = [('', l) for l in states] |
2536 for change, l in iter: | 2539 for change, l in iter: |
2537 fm.startitem() | 2540 fm.startitem() |
2538 fm.data(node=fm.hexfunc(ctx.node())) | 2541 fm.data(node=fm.hexfunc(scmutil.binnode(ctx))) |
2542 | |
2539 cols = [ | 2543 cols = [ |
2540 ('filename', fn, True), | 2544 ('filename', fn, True), |
2541 ('rev', rev, True), | 2545 ('rev', rev, True), |
2542 ('linenumber', l.linenum, opts.get('line_number')), | 2546 ('linenumber', l.linenum, opts.get('line_number')), |
2543 ] | 2547 ] |
2599 flog = getfile(fn) | 2603 flog = getfile(fn) |
2600 try: | 2604 try: |
2601 fnode = ctx.filenode(fn) | 2605 fnode = ctx.filenode(fn) |
2602 except error.LookupError: | 2606 except error.LookupError: |
2603 continue | 2607 continue |
2604 | 2608 try: |
2605 copied = flog.renamed(fnode) | 2609 copied = flog.renamed(fnode) |
2610 except error.WdirUnsupported: | |
2611 copied = ctx[fn].renamed() | |
2606 copy = follow and copied and copied[0] | 2612 copy = follow and copied and copied[0] |
2607 if copy: | 2613 if copy: |
2608 copies.setdefault(rev, {})[fn] = copy | 2614 copies.setdefault(rev, {})[fn] = copy |
2609 if fn in skip: | 2615 if fn in skip: |
2610 if copy: | 2616 if copy: |
2611 skip[copy] = True | 2617 skip[copy] = True |
2612 continue | 2618 continue |
2613 files.append(fn) | 2619 files.append(fn) |
2614 | 2620 |
2615 if fn not in matches[rev]: | 2621 if fn not in matches[rev]: |
2616 grepbody(fn, rev, flog.read(fnode)) | 2622 try: |
2623 content = flog.read(fnode) | |
2624 except error.WdirUnsupported: | |
2625 content = ctx[fn].data() | |
2626 grepbody(fn, rev, content) | |
2617 | 2627 |
2618 pfn = copy or fn | 2628 pfn = copy or fn |
2619 if pfn not in matches[parent]: | 2629 if pfn not in matches[parent]: |
2620 try: | 2630 try: |
2621 fnode = pctx.filenode(pfn) | 2631 fnode = pctx.filenode(pfn) |