Mercurial > hg > mercurial-source
comparison mercurial/cmdutil.py @ 21998:739095270f48
log: allow patterns with -f
It's not uncommon for a user to want to run log with a pattern or directory name
on the history of their current commit. Currently we prevent that, but
I can't think of any reason to continue blocking that.
This commit removes the restriction and allows 'hg log -f <dir/pat>'
author | Durham Goode <durham@fb.com> |
---|---|
date | Tue, 22 Jul 2014 22:40:16 -0700 (2014-07-23) |
parents | be94ed4baa5d |
children | 6ce282ed801e |
comparison
equal
deleted
inserted
replaced
21997:93c3b3f55d59 | 21998:739095270f48 |
---|---|
1568 match, pats = scmutil.matchandpats(pctx, pats, opts) | 1568 match, pats = scmutil.matchandpats(pctx, pats, opts) |
1569 slowpath = match.anypats() or (match.files() and opts.get('removed')) | 1569 slowpath = match.anypats() or (match.files() and opts.get('removed')) |
1570 if not slowpath: | 1570 if not slowpath: |
1571 for f in match.files(): | 1571 for f in match.files(): |
1572 if follow and f not in pctx: | 1572 if follow and f not in pctx: |
1573 raise util.Abort(_('cannot follow file not in parent ' | 1573 # If the file exists, it may be a directory, so let it |
1574 'revision: "%s"') % f) | 1574 # take the slow path. |
1575 if os.path.exists(repo.wjoin(f)): | |
1576 slowpath = True | |
1577 continue | |
1578 else: | |
1579 raise util.Abort(_('cannot follow file not in parent ' | |
1580 'revision: "%s"') % f) | |
1575 filelog = repo.file(f) | 1581 filelog = repo.file(f) |
1576 if not filelog: | 1582 if not filelog: |
1577 # A zero count may be a directory or deleted file, so | 1583 # A zero count may be a directory or deleted file, so |
1578 # try to find matching entries on the slow path. | 1584 # try to find matching entries on the slow path. |
1579 if follow: | 1585 if follow: |
1593 slowpath = False | 1599 slowpath = False |
1594 | 1600 |
1595 if slowpath: | 1601 if slowpath: |
1596 # See walkchangerevs() slow path. | 1602 # See walkchangerevs() slow path. |
1597 # | 1603 # |
1598 if follow: | |
1599 raise util.Abort(_('can only follow copies/renames for explicit ' | |
1600 'filenames')) | |
1601 # pats/include/exclude cannot be represented as separate | 1604 # pats/include/exclude cannot be represented as separate |
1602 # revset expressions as their filtering logic applies at file | 1605 # revset expressions as their filtering logic applies at file |
1603 # level. For instance "-I a -X a" matches a revision touching | 1606 # level. For instance "-I a -X a" matches a revision touching |
1604 # "a" and "b" while "file(a) and not file(b)" does | 1607 # "a" and "b" while "file(a) and not file(b)" does |
1605 # not. Besides, filesets are evaluated against the working | 1608 # not. Besides, filesets are evaluated against the working |
1627 else: | 1630 else: |
1628 opts['_patslog'] = list(pats) | 1631 opts['_patslog'] = list(pats) |
1629 | 1632 |
1630 filematcher = None | 1633 filematcher = None |
1631 if opts.get('patch') or opts.get('stat'): | 1634 if opts.get('patch') or opts.get('stat'): |
1632 if follow and not match.always(): | 1635 # When following files, track renames via a special matcher. |
1636 # If we're forced to take the slowpath it means we're following | |
1637 # at least one pattern/directory, so don't bother with rename tracking. | |
1638 if follow and not match.always() and not slowpath: | |
1633 # _makelogfilematcher expects its files argument to be relative to | 1639 # _makelogfilematcher expects its files argument to be relative to |
1634 # the repo root, so use match.files(), not pats. | 1640 # the repo root, so use match.files(), not pats. |
1635 filematcher = _makelogfilematcher(repo, match.files(), followfirst) | 1641 filematcher = _makelogfilematcher(repo, match.files(), followfirst) |
1636 else: | 1642 else: |
1637 filematcher = lambda rev: match | 1643 filematcher = lambda rev: match |