##// END OF EJS Templates
log: resolve --follow thoroughly in getlogrevs()...
Yuya Nishihara -
r35704:b25fa5da default
parent child Browse files
Show More
@@ -2371,6 +2371,13 b' def _makelogmatcher(repo, pats, opts):'
2371
2371
2372 return match, pats, slowpath
2372 return match, pats, slowpath
2373
2373
2374 def _fileancestors(repo, revs, match, followfirst):
2375 fctxs = []
2376 for r in revs:
2377 ctx = repo[r]
2378 fctxs.extend(ctx[f].introfilectx() for f in ctx.walk(match))
2379 return dagop.filerevancestors(fctxs, followfirst=followfirst)
2380
2374 def _makefollowlogfilematcher(repo, files, followfirst):
2381 def _makefollowlogfilematcher(repo, files, followfirst):
2375 # When displaying a revision with --patch --follow FILE, we have
2382 # When displaying a revision with --patch --follow FILE, we have
2376 # to know which file of the revision must be diffed. With
2383 # to know which file of the revision must be diffed. With
@@ -2406,14 +2413,10 b' def _makenofollowlogfilematcher(repo, pa'
2406 _opt2logrevset = {
2413 _opt2logrevset = {
2407 'no_merges': ('not merge()', None),
2414 'no_merges': ('not merge()', None),
2408 'only_merges': ('merge()', None),
2415 'only_merges': ('merge()', None),
2409 '_ancestors': ('ancestors(%r)', None),
2410 '_fancestors': ('_firstancestors(%r)', None),
2411 '_matchfiles': (None, '_matchfiles(%ps)'),
2416 '_matchfiles': (None, '_matchfiles(%ps)'),
2412 'date': ('date(%s)', None),
2417 'date': ('date(%s)', None),
2413 'branch': ('branch(%s)', '%lr'),
2418 'branch': ('branch(%s)', '%lr'),
2414 '_patslog': ('filelog(%s)', '%lr'),
2419 '_patslog': ('filelog(%s)', '%lr'),
2415 '_patsfollow': ('follow(%s)', '%lr'),
2416 '_patsfollowfirst': ('_followfirst(%s)', '%lr'),
2417 'keyword': ('keyword(%s)', '%lr'),
2420 'keyword': ('keyword(%s)', '%lr'),
2418 'prune': ('ancestors(%s)', 'not %lr'),
2421 'prune': ('ancestors(%s)', 'not %lr'),
2419 'user': ('user(%s)', '%lr'),
2422 'user': ('user(%s)', '%lr'),
@@ -2429,19 +2432,12 b' def _makelogrevset(repo, match, pats, sl'
2429 opts = dict(opts)
2432 opts = dict(opts)
2430 # follow or not follow?
2433 # follow or not follow?
2431 follow = opts.get('follow') or opts.get('follow_first')
2434 follow = opts.get('follow') or opts.get('follow_first')
2432 if opts.get('follow_first'):
2433 followfirst = 1
2434 else:
2435 followfirst = 0
2436
2435
2437 # branch and only_branch are really aliases and must be handled at
2436 # branch and only_branch are really aliases and must be handled at
2438 # the same time
2437 # the same time
2439 opts['branch'] = opts.get('branch', []) + opts.get('only_branch', [])
2438 opts['branch'] = opts.get('branch', []) + opts.get('only_branch', [])
2440 opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
2439 opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
2441
2440
2442 fpats = ('_patsfollow', '_patsfollowfirst')
2443 fnopats = ('_ancestors', '_fancestors')
2444
2445 if slowpath:
2441 if slowpath:
2446 # See walkchangerevs() slow path.
2442 # See walkchangerevs() slow path.
2447 #
2443 #
@@ -2459,19 +2455,8 b' def _makelogrevset(repo, match, pats, sl'
2459 for p in opts.get('exclude', []):
2455 for p in opts.get('exclude', []):
2460 matchargs.append('x:' + p)
2456 matchargs.append('x:' + p)
2461 opts['_matchfiles'] = matchargs
2457 opts['_matchfiles'] = matchargs
2462 if follow:
2458 elif not follow:
2463 opts[fnopats[followfirst]] = '.'
2459 opts['_patslog'] = list(pats)
2464 else:
2465 if follow:
2466 if pats:
2467 # follow() revset interprets its file argument as a
2468 # manifest entry, so use match.files(), not pats.
2469 opts[fpats[followfirst]] = list(match.files())
2470 else:
2471 op = fnopats[followfirst]
2472 opts[op] = '.'
2473 else:
2474 opts['_patslog'] = list(pats)
2475
2460
2476 filematcher = None
2461 filematcher = None
2477 if opts.get('patch') or opts.get('stat'):
2462 if opts.get('patch') or opts.get('stat'):
@@ -2482,7 +2467,7 b' def _makelogrevset(repo, match, pats, sl'
2482 # _makefollowlogfilematcher expects its files argument to be
2467 # _makefollowlogfilematcher expects its files argument to be
2483 # relative to the repo root, so use match.files(), not pats.
2468 # relative to the repo root, so use match.files(), not pats.
2484 filematcher = _makefollowlogfilematcher(repo, match.files(),
2469 filematcher = _makefollowlogfilematcher(repo, match.files(),
2485 followfirst)
2470 opts.get('follow_first'))
2486 else:
2471 else:
2487 filematcher = _makenofollowlogfilematcher(repo, pats, opts)
2472 filematcher = _makenofollowlogfilematcher(repo, pats, opts)
2488 if filematcher is None:
2473 if filematcher is None:
@@ -2511,13 +2496,14 b' def _makelogrevset(repo, match, pats, sl'
2511 return expr, filematcher
2496 return expr, filematcher
2512
2497
2513 def _logrevs(repo, opts):
2498 def _logrevs(repo, opts):
2499 """Return the initial set of revisions to be filtered or followed"""
2514 follow = opts.get('follow') or opts.get('follow_first')
2500 follow = opts.get('follow') or opts.get('follow_first')
2515 if opts.get('rev'):
2501 if opts.get('rev'):
2516 revs = scmutil.revrange(repo, opts['rev'])
2502 revs = scmutil.revrange(repo, opts['rev'])
2517 elif follow and repo.dirstate.p1() == nullid:
2503 elif follow and repo.dirstate.p1() == nullid:
2518 revs = smartset.baseset()
2504 revs = smartset.baseset()
2519 elif follow:
2505 elif follow:
2520 revs = repo.revs('reverse(:.)')
2506 revs = repo.revs('.')
2521 else:
2507 else:
2522 revs = smartset.spanset(repo)
2508 revs = smartset.spanset(repo)
2523 revs.reverse()
2509 revs.reverse()
@@ -2541,8 +2527,11 b' def getlogrevs(repo, pats, opts):'
2541 if not revs:
2527 if not revs:
2542 return smartset.baseset(), None
2528 return smartset.baseset(), None
2543 match, pats, slowpath = _makelogmatcher(repo, pats, opts)
2529 match, pats, slowpath = _makelogmatcher(repo, pats, opts)
2544 if opts.get('rev') and follow:
2530 if follow:
2545 revs = dagop.revancestors(repo, revs, followfirst=followfirst)
2531 if opts.get('rev') or slowpath or not pats:
2532 revs = dagop.revancestors(repo, revs, followfirst=followfirst)
2533 else:
2534 revs = _fileancestors(repo, revs, match, followfirst)
2546 revs.reverse()
2535 revs.reverse()
2547 expr, filematcher = _makelogrevset(repo, match, pats, slowpath, opts)
2536 expr, filematcher = _makelogrevset(repo, match, pats, slowpath, opts)
2548 if opts.get('graph') and opts.get('rev'):
2537 if opts.get('graph') and opts.get('rev'):
@@ -1724,20 +1724,14 b' Test --follow on a directory'
1724 $ hg up -q '.^'
1724 $ hg up -q '.^'
1725 $ testlog -f dir
1725 $ testlog -f dir
1726 []
1726 []
1727 (and
1727 (func
1728 (func
1728 (symbol '_matchfiles')
1729 (symbol 'ancestors')
1729 (list
1730 (symbol '.'))
1730 (string 'r:')
1731 (func
1731 (string 'd:relpath')
1732 (symbol '_matchfiles')
1732 (string 'p:dir')))
1733 (list
1734 (string 'r:')
1735 (string 'd:relpath')
1736 (string 'p:dir'))))
1737 <filteredset
1733 <filteredset
1738 <filteredset
1734 <generatorsetdesc->,
1739 <spanset- 0:4>,
1740 <generatorsetdesc+>>,
1741 <matchfiles patterns=['dir'], include=[] exclude=[], default='relpath', rev=None>>
1735 <matchfiles patterns=['dir'], include=[] exclude=[], default='relpath', rev=None>>
1742 $ hg up -q tip
1736 $ hg up -q tip
1743
1737
@@ -1752,20 +1746,14 b' Test --follow and patterns'
1752
1746
1753 $ testlog -f 'glob:*'
1747 $ testlog -f 'glob:*'
1754 []
1748 []
1755 (and
1749 (func
1756 (func
1750 (symbol '_matchfiles')
1757 (symbol 'ancestors')
1751 (list
1758 (symbol '.'))
1752 (string 'r:')
1759 (func
1753 (string 'd:relpath')
1760 (symbol '_matchfiles')
1754 (string 'p:glob:*')))
1761 (list
1762 (string 'r:')
1763 (string 'd:relpath')
1764 (string 'p:glob:*'))))
1765 <filteredset
1755 <filteredset
1766 <filteredset
1756 <generatorsetdesc->,
1767 <spanset- 0:5>,
1768 <generatorsetdesc+>>,
1769 <matchfiles patterns=['glob:*'], include=[] exclude=[], default='relpath', rev=None>>
1757 <matchfiles patterns=['glob:*'], include=[] exclude=[], default='relpath', rev=None>>
1770
1758
1771 Test --follow on a single rename
1759 Test --follow on a single rename
@@ -1773,36 +1761,24 b' Test --follow on a single rename'
1773 $ hg up -q 2
1761 $ hg up -q 2
1774 $ testlog -f a
1762 $ testlog -f a
1775 []
1763 []
1776 (func
1764 []
1777 (symbol 'follow')
1765 <generatorsetdesc->
1778 (string 'a'))
1779 <filteredset
1780 <spanset- 0:3>,
1781 <generatorsetdesc+>>
1782
1766
1783 Test --follow and multiple renames
1767 Test --follow and multiple renames
1784
1768
1785 $ hg up -q tip
1769 $ hg up -q tip
1786 $ testlog -f e
1770 $ testlog -f e
1787 []
1771 []
1788 (func
1772 []
1789 (symbol 'follow')
1773 <generatorsetdesc->
1790 (string 'e'))
1791 <filteredset
1792 <spanset- 0:5>,
1793 <generatorsetdesc+>>
1794
1774
1795 Test --follow and multiple filelog heads
1775 Test --follow and multiple filelog heads
1796
1776
1797 $ hg up -q 2
1777 $ hg up -q 2
1798 $ testlog -f g
1778 $ testlog -f g
1799 []
1779 []
1800 (func
1780 []
1801 (symbol 'follow')
1781 <generatorsetdesc->
1802 (string 'g'))
1803 <filteredset
1804 <spanset- 0:3>,
1805 <generatorsetdesc+>>
1806 $ cat log.nodes
1782 $ cat log.nodes
1807 nodetag 2
1783 nodetag 2
1808 nodetag 1
1784 nodetag 1
@@ -1810,12 +1786,8 b' Test --follow and multiple filelog heads'
1810 $ hg up -q tip
1786 $ hg up -q tip
1811 $ testlog -f g
1787 $ testlog -f g
1812 []
1788 []
1813 (func
1789 []
1814 (symbol 'follow')
1790 <generatorsetdesc->
1815 (string 'g'))
1816 <filteredset
1817 <spanset- 0:5>,
1818 <generatorsetdesc+>>
1819 $ cat log.nodes
1791 $ cat log.nodes
1820 nodetag 3
1792 nodetag 3
1821 nodetag 2
1793 nodetag 2
@@ -1825,19 +1797,8 b' Test --follow and multiple files'
1825
1797
1826 $ testlog -f g e
1798 $ testlog -f g e
1827 []
1799 []
1828 (or
1800 []
1829 (list
1801 <generatorsetdesc->
1830 (func
1831 (symbol 'follow')
1832 (string 'g'))
1833 (func
1834 (symbol 'follow')
1835 (string 'e'))))
1836 <filteredset
1837 <spanset- 0:5>,
1838 <addset
1839 <generatorsetdesc+>,
1840 <generatorsetdesc+>>>
1841 $ cat log.nodes
1802 $ cat log.nodes
1842 nodetag 4
1803 nodetag 4
1843 nodetag 3
1804 nodetag 3
@@ -1866,23 +1827,15 b' Test --follow-first'
1866 $ hg ci -m "merge 5 and 4"
1827 $ hg ci -m "merge 5 and 4"
1867 $ testlog --follow-first
1828 $ testlog --follow-first
1868 []
1829 []
1869 (func
1830 []
1870 (symbol '_firstancestors')
1831 <generatorsetdesc->
1871 (symbol '.'))
1872 <filteredset
1873 <spanset- 0:7>,
1874 <generatorsetdesc+>>
1875
1832
1876 Cannot compare with log --follow-first FILE as it never worked
1833 Cannot compare with log --follow-first FILE as it never worked
1877
1834
1878 $ hg log -G --print-revset --follow-first e
1835 $ hg log -G --print-revset --follow-first e
1879 []
1836 []
1880 (func
1837 []
1881 (symbol '_followfirst')
1838 <generatorsetdesc->
1882 (string 'e'))
1883 <filteredset
1884 <spanset- 0:7>,
1885 <generatorsetdesc+>>
1886 $ hg log -G --follow-first e --template '{rev} {desc|firstline}\n'
1839 $ hg log -G --follow-first e --template '{rev} {desc|firstline}\n'
1887 @ 6 merge 5 and 4
1840 @ 6 merge 5 and 4
1888 |\
1841 |\
@@ -1958,20 +1911,14 b' Test --removed'
1958 <matchfiles patterns=['a'], include=[] exclude=[], default='relpath', rev=None>>
1911 <matchfiles patterns=['a'], include=[] exclude=[], default='relpath', rev=None>>
1959 $ testlog --removed --follow a
1912 $ testlog --removed --follow a
1960 []
1913 []
1961 (and
1914 (func
1962 (func
1915 (symbol '_matchfiles')
1963 (symbol 'ancestors')
1916 (list
1964 (symbol '.'))
1917 (string 'r:')
1965 (func
1918 (string 'd:relpath')
1966 (symbol '_matchfiles')
1919 (string 'p:a')))
1967 (list
1968 (string 'r:')
1969 (string 'd:relpath')
1970 (string 'p:a'))))
1971 <filteredset
1920 <filteredset
1972 <filteredset
1921 <generatorsetdesc->,
1973 <spanset- 0:5>,
1974 <generatorsetdesc+>>,
1975 <matchfiles patterns=['a'], include=[] exclude=[], default='relpath', rev=None>>
1922 <matchfiles patterns=['a'], include=[] exclude=[], default='relpath', rev=None>>
1976
1923
1977 Test --patch and --stat with --follow and --follow-first
1924 Test --patch and --stat with --follow and --follow-first
@@ -2353,12 +2300,8 b' Test subdir'
2353 <spanset- 0:9>, set([1])>
2300 <spanset- 0:9>, set([1])>
2354 $ testlog -f ../b
2301 $ testlog -f ../b
2355 []
2302 []
2356 (func
2303 []
2357 (symbol 'follow')
2304 <generatorsetdesc->
2358 (string 'b'))
2359 <filteredset
2360 <spanset- 0:4>,
2361 <generatorsetdesc+>>
2362 $ cd ..
2305 $ cd ..
2363
2306
2364 Test --hidden
2307 Test --hidden
General Comments 0
You need to be logged in to leave comments. Login now