tests/test-fix.t
branchstable
changeset 48315 a44bb185f6bd
parent 48293 7a4d187479b6
child 48346 e6aecc37bfbf
equal deleted inserted replaced
48314:6f43569729d4 48315:a44bb185f6bd
  1750   hello
  1750   hello
  1751   
  1751   
  1752   r0.whole:
  1752   r0.whole:
  1753   hello
  1753   hello
  1754   
  1754   
       
  1755 
       
  1756 We should execute the fixer tools as few times as possible, because they might
       
  1757 be slow or expensive to execute. The inputs to each execution are effectively
       
  1758 the file path, file content, and line ranges. So, we should be able to re-use
       
  1759 results whenever those inputs are repeated. That saves a lot of work when
       
  1760 fixing chains of commits that all have the same file revision for a path being
       
  1761 fixed.
       
  1762 
       
  1763   $ hg init numberofinvocations
       
  1764   $ cd numberofinvocations
       
  1765 
       
  1766   $ printf "bar1" > bar.log
       
  1767   $ printf "baz1" > baz.log
       
  1768   $ printf "foo1" > foo.log
       
  1769   $ printf "qux1" > qux.log
       
  1770   $ hg commit -Aqm "commit1"
       
  1771 
       
  1772   $ printf "bar2" > bar.log
       
  1773   $ printf "baz2" > baz.log
       
  1774   $ printf "foo2" > foo.log
       
  1775   $ hg commit -Aqm "commit2"
       
  1776 
       
  1777   $ printf "bar3" > bar.log
       
  1778   $ printf "baz3" > baz.log
       
  1779   $ hg commit -Aqm "commit3"
       
  1780 
       
  1781   $ printf "bar4" > bar.log
       
  1782 
       
  1783   $ LOGFILE=$TESTTMP/log
       
  1784   $ LOGGER=$TESTTMP/log.py
       
  1785   $ cat >> $LOGGER <<EOF
       
  1786   > # Appends the input file's name to the log file.
       
  1787   > import sys
       
  1788   > with open(r'$LOGFILE', 'a') as f:
       
  1789   >     f.write(sys.argv[1] + '\n')
       
  1790   > sys.stdout.write(sys.stdin.read())
       
  1791   > EOF
       
  1792 
       
  1793   $ hg fix --working-dir -r "all()" \
       
  1794   >        --config "fix.log:command=\"$PYTHON\" \"$LOGGER\" {rootpath}" \
       
  1795   >        --config "fix.log:pattern=glob:**.log"
       
  1796 
       
  1797   $ cat $LOGFILE | sort | uniq -c
       
  1798         4 bar.log
       
  1799         4 baz.log
       
  1800         3 foo.log
       
  1801         2 qux.log
       
  1802 
       
  1803   $ cd ..
       
  1804 
       
  1805 For tools that support line ranges, it's wrong to blindly re-use fixed file
       
  1806 content for the same file revision if it appears twice with different baserevs,
       
  1807 because the line ranges could be different. Since computing line ranges is
       
  1808 ambiguous, this isn't a matter of correctness, but it affects the usability of
       
  1809 this extension. It could maybe be simpler if baserevs were computed on a
       
  1810 per-file basis to make this situation impossible to construct.
       
  1811 
       
  1812 In the following example, we construct two subgraphs with the same file
       
  1813 revisions, and fix different sub-subgraphs to get different baserevs and
       
  1814 different changed line ranges. The key precondition is that revisions 1 and 4
       
  1815 have the same file revision, and the key result is that their successors don't
       
  1816 have the same file content, because we want to fix different areas of that same
       
  1817 file revision's content.
       
  1818 
       
  1819   $ hg init differentlineranges
       
  1820   $ cd differentlineranges
       
  1821 
       
  1822   $ printf "a\nb\n" > file.changed
       
  1823   $ hg commit -Aqm "0 ab"
       
  1824   $ printf "a\nx\n" > file.changed
       
  1825   $ hg commit -Aqm "1 ax"
       
  1826   $ hg remove file.changed
       
  1827   $ hg commit -Aqm "2 removed"
       
  1828   $ hg revert file.changed -r 0
       
  1829   $ hg commit -Aqm "3 ab (reverted)"
       
  1830   $ hg revert file.changed -r 1
       
  1831   $ hg commit -Aqm "4 ax (reverted)"
       
  1832 
       
  1833   $ hg manifest --debug --template "{hash}\n" -r 0; \
       
  1834   > hg manifest --debug --template "{hash}\n" -r 3
       
  1835   418f692145676128d2fb518b027ddbac624be76e
       
  1836   418f692145676128d2fb518b027ddbac624be76e
       
  1837   $ hg manifest --debug --template "{hash}\n" -r 1; \
       
  1838   > hg manifest --debug --template "{hash}\n" -r 4
       
  1839   09b8b3ce5a507caaa282f7262679e6d04091426c
       
  1840   09b8b3ce5a507caaa282f7262679e6d04091426c
       
  1841 
       
  1842   $ hg fix --working-dir -r 1+3+4
       
  1843   3 new orphan changesets
       
  1844 
       
  1845   $ hg cat file.changed -r "successors(1)" --hidden
       
  1846   a
       
  1847   X
       
  1848   $ hg cat file.changed -r "successors(4)" --hidden
       
  1849   A
       
  1850   X
       
  1851 
       
  1852   $ cd ..