6 # GNU General Public License version 2, incorporated herein by reference. |
6 # GNU General Public License version 2, incorporated herein by reference. |
7 |
7 |
8 '''manage a stack of patches |
8 '''manage a stack of patches |
9 |
9 |
10 This extension lets you work with a stack of patches in a Mercurial |
10 This extension lets you work with a stack of patches in a Mercurial |
11 repository. It manages two stacks of patches - all known patches, and |
11 repository. It manages two stacks of patches - all known patches, and applied |
12 applied patches (subset of known patches). |
12 patches (subset of known patches). |
13 |
13 |
14 Known patches are represented as patch files in the .hg/patches |
14 Known patches are represented as patch files in the .hg/patches directory. |
15 directory. Applied patches are both patch files and changesets. |
15 Applied patches are both patch files and changesets. |
16 |
16 |
17 Common tasks (use "hg help command" for more details): |
17 Common tasks (use "hg help command" for more details): |
18 |
18 |
19 prepare repository to work with patches qinit |
19 prepare repository to work with patches qinit |
20 create new patch qnew |
20 create new patch qnew |
1679 q.qseries(repo, start=start, status='U', summary=opts.get('summary')) |
1679 q.qseries(repo, start=start, status='U', summary=opts.get('summary')) |
1680 |
1680 |
1681 def qimport(ui, repo, *filename, **opts): |
1681 def qimport(ui, repo, *filename, **opts): |
1682 """import a patch |
1682 """import a patch |
1683 |
1683 |
1684 The patch is inserted into the series after the last applied |
1684 The patch is inserted into the series after the last applied patch. If no |
1685 patch. If no patches have been applied, qimport prepends the patch |
1685 patches have been applied, qimport prepends the patch to the series. |
1686 to the series. |
1686 |
1687 |
1687 The patch will have the same name as its source file unless you give it a |
1688 The patch will have the same name as its source file unless you |
1688 new one with -n/--name. |
1689 give it a new one with -n/--name. |
1689 |
1690 |
1690 You can register an existing patch inside the patch directory with the |
1691 You can register an existing patch inside the patch directory with |
1691 -e/--existing flag. |
1692 the -e/--existing flag. |
1692 |
1693 |
1693 With -f/--force, an existing patch of the same name will be overwritten. |
1694 With -f/--force, an existing patch of the same name will be |
1694 |
1695 overwritten. |
1695 An existing changeset may be placed under mq control with -r/--rev (e.g. |
1696 |
1696 qimport --rev tip -n patch will place tip under mq control). With |
1697 An existing changeset may be placed under mq control with -r/--rev |
1697 -g/--git, patches imported with --rev will use the git diff format. See |
1698 (e.g. qimport --rev tip -n patch will place tip under mq control). |
1698 the diffs help topic for information on why this is important for |
1699 With -g/--git, patches imported with --rev will use the git diff |
1699 preserving rename/copy information and permission changes. |
1700 format. See the diffs help topic for information on why this is |
1700 |
1701 important for preserving rename/copy information and permission |
1701 To import a patch from standard input, pass - as the patch file. When |
1702 changes. |
1702 importing from standard input, a patch name must be specified using the |
1703 |
1703 --name flag. |
1704 To import a patch from standard input, pass - as the patch file. |
|
1705 When importing from standard input, a patch name must be specified |
|
1706 using the --name flag. |
|
1707 """ |
1704 """ |
1708 q = repo.mq |
1705 q = repo.mq |
1709 q.qimport(repo, filename, patchname=opts['name'], |
1706 q.qimport(repo, filename, patchname=opts['name'], |
1710 existing=opts['existing'], force=opts['force'], rev=opts['rev'], |
1707 existing=opts['existing'], force=opts['force'], rev=opts['rev'], |
1711 git=opts['git']) |
1708 git=opts['git']) |
1716 return 0 |
1713 return 0 |
1717 |
1714 |
1718 def init(ui, repo, **opts): |
1715 def init(ui, repo, **opts): |
1719 """init a new queue repository |
1716 """init a new queue repository |
1720 |
1717 |
1721 The queue repository is unversioned by default. If |
1718 The queue repository is unversioned by default. If -c/--create-repo is |
1722 -c/--create-repo is specified, qinit will create a separate nested |
1719 specified, qinit will create a separate nested repository for patches |
1723 repository for patches (qinit -c may also be run later to convert |
1720 (qinit -c may also be run later to convert an unversioned patch repository |
1724 an unversioned patch repository into a versioned one). You can use |
1721 into a versioned one). You can use qcommit to commit changes to this queue |
1725 qcommit to commit changes to this queue repository.""" |
1722 repository. |
|
1723 """ |
1726 q = repo.mq |
1724 q = repo.mq |
1727 r = q.init(repo, create=opts['create_repo']) |
1725 r = q.init(repo, create=opts['create_repo']) |
1728 q.save_dirty() |
1726 q.save_dirty() |
1729 if r: |
1727 if r: |
1730 if not os.path.exists(r.wjoin('.hgignore')): |
1728 if not os.path.exists(r.wjoin('.hgignore')): |
1742 return 0 |
1740 return 0 |
1743 |
1741 |
1744 def clone(ui, source, dest=None, **opts): |
1742 def clone(ui, source, dest=None, **opts): |
1745 '''clone main and patch repository at same time |
1743 '''clone main and patch repository at same time |
1746 |
1744 |
1747 If source is local, destination will have no patches applied. If |
1745 If source is local, destination will have no patches applied. If source is |
1748 source is remote, this command can not check if patches are |
1746 remote, this command can not check if patches are applied in source, so |
1749 applied in source, so cannot guarantee that patches are not |
1747 cannot guarantee that patches are not applied in destination. If you clone |
1750 applied in destination. If you clone remote repository, be sure |
1748 remote repository, be sure before that it has no patches applied. |
1751 before that it has no patches applied. |
1749 |
1752 |
1750 Source patch repository is looked for in <src>/.hg/patches by default. Use |
1753 Source patch repository is looked for in <src>/.hg/patches by |
1751 -p <url> to change. |
1754 default. Use -p <url> to change. |
1752 |
1755 |
1753 The patch directory must be a nested Mercurial repository, as would be |
1756 The patch directory must be a nested Mercurial repository, as |
1754 created by qinit -c. |
1757 would be created by qinit -c. |
|
1758 ''' |
1755 ''' |
1759 def patchdir(repo): |
1756 def patchdir(repo): |
1760 url = repo.url() |
1757 url = repo.url() |
1761 if url.endswith('/'): |
1758 if url.endswith('/'): |
1762 url = url[:-1] |
1759 url = url[:-1] |
1858 do('date', "%d %d" % util.makedate()) |
1855 do('date', "%d %d" % util.makedate()) |
1859 |
1856 |
1860 def new(ui, repo, patch, *args, **opts): |
1857 def new(ui, repo, patch, *args, **opts): |
1861 """create a new patch |
1858 """create a new patch |
1862 |
1859 |
1863 qnew creates a new patch on top of the currently-applied patch (if |
1860 qnew creates a new patch on top of the currently-applied patch (if any). |
1864 any). It will refuse to run if there are any outstanding changes |
1861 It will refuse to run if there are any outstanding changes unless |
1865 unless -f/--force is specified, in which case the patch will be |
1862 -f/--force is specified, in which case the patch will be initialized with |
1866 initialized with them. You may also use -I/--include, |
1863 them. You may also use -I/--include, -X/--exclude, and/or a list of files |
1867 -X/--exclude, and/or a list of files after the patch name to add |
1864 after the patch name to add only changes to matching files to the new |
1868 only changes to matching files to the new patch, leaving the rest |
1865 patch, leaving the rest as uncommitted modifications. |
1869 as uncommitted modifications. |
1866 |
1870 |
1867 -u/--user and -d/--date can be used to set the (given) user and date, |
1871 -u/--user and -d/--date can be used to set the (given) user and |
1868 respectively. -U/--currentuser and -D/--currentdate set user to current |
1872 date, respectively. -U/--currentuser and -D/--currentdate set user |
1869 user and date to current date. |
1873 to current user and date to current date. |
1870 |
1874 |
1871 -e/--edit, -m/--message or -l/--logfile set the patch header as well as |
1875 -e/--edit, -m/--message or -l/--logfile set the patch header as |
1872 the commit message. If none is specified, the header is empty and the |
1876 well as the commit message. If none is specified, the header is |
1873 commit message is '[mq]: PATCH'. |
1877 empty and the commit message is '[mq]: PATCH'. |
1874 |
1878 |
1875 Use the -g/--git option to keep the patch in the git extended diff format. |
1879 Use the -g/--git option to keep the patch in the git extended diff |
1876 Read the diffs help topic for more information on why this is important |
1880 format. Read the diffs help topic for more information on why this |
1877 for preserving permission changes and copy/rename information. |
1881 is important for preserving permission changes and copy/rename |
|
1882 information. |
|
1883 """ |
1878 """ |
1884 msg = cmdutil.logmessage(opts) |
1879 msg = cmdutil.logmessage(opts) |
1885 def getmsg(): return ui.edit(msg, ui.username()) |
1880 def getmsg(): return ui.edit(msg, ui.username()) |
1886 q = repo.mq |
1881 q = repo.mq |
1887 opts['msg'] = msg |
1882 opts['msg'] = msg |
1895 return 0 |
1890 return 0 |
1896 |
1891 |
1897 def refresh(ui, repo, *pats, **opts): |
1892 def refresh(ui, repo, *pats, **opts): |
1898 """update the current patch |
1893 """update the current patch |
1899 |
1894 |
1900 If any file patterns are provided, the refreshed patch will |
1895 If any file patterns are provided, the refreshed patch will contain only |
1901 contain only the modifications that match those patterns; the |
1896 the modifications that match those patterns; the remaining modifications |
1902 remaining modifications will remain in the working directory. |
1897 will remain in the working directory. |
1903 |
1898 |
1904 If -s/--short is specified, files currently included in the patch |
1899 If -s/--short is specified, files currently included in the patch will be |
1905 will be refreshed just like matched files and remain in the patch. |
1900 refreshed just like matched files and remain in the patch. |
1906 |
1901 |
1907 hg add/remove/copy/rename work as usual, though you might want to |
1902 hg add/remove/copy/rename work as usual, though you might want to use |
1908 use git-style patches (-g/--git or [diff] git=1) to track copies |
1903 git-style patches (-g/--git or [diff] git=1) to track copies and renames. |
1909 and renames. See the diffs help topic for more information on the |
1904 See the diffs help topic for more information on the git diff format. |
1910 git diff format. |
|
1911 """ |
1905 """ |
1912 q = repo.mq |
1906 q = repo.mq |
1913 message = cmdutil.logmessage(opts) |
1907 message = cmdutil.logmessage(opts) |
1914 if opts['edit']: |
1908 if opts['edit']: |
1915 if not q.applied: |
1909 if not q.applied: |
1926 return ret |
1920 return ret |
1927 |
1921 |
1928 def diff(ui, repo, *pats, **opts): |
1922 def diff(ui, repo, *pats, **opts): |
1929 """diff of the current patch and subsequent modifications |
1923 """diff of the current patch and subsequent modifications |
1930 |
1924 |
1931 Shows a diff which includes the current patch as well as any |
1925 Shows a diff which includes the current patch as well as any changes which |
1932 changes which have been made in the working directory since the |
1926 have been made in the working directory since the last refresh (thus |
1933 last refresh (thus showing what the current patch would become |
1927 showing what the current patch would become after a qrefresh). |
1934 after a qrefresh). |
1928 |
1935 |
1929 Use 'hg diff' if you only want to see the changes made since the last |
1936 Use 'hg diff' if you only want to see the changes made since the |
1930 qrefresh, or 'hg export qtip' if you want to see changes made by the |
1937 last qrefresh, or 'hg export qtip' if you want to see changes made |
1931 current patch without including changes made since the qrefresh. |
1938 by the current patch without including changes made since the |
|
1939 qrefresh. |
|
1940 """ |
1932 """ |
1941 repo.mq.diff(repo, pats, opts) |
1933 repo.mq.diff(repo, pats, opts) |
1942 return 0 |
1934 return 0 |
1943 |
1935 |
1944 def fold(ui, repo, *files, **opts): |
1936 def fold(ui, repo, *files, **opts): |
1945 """fold the named patches into the current patch |
1937 """fold the named patches into the current patch |
1946 |
1938 |
1947 Patches must not yet be applied. Each patch will be successively |
1939 Patches must not yet be applied. Each patch will be successively applied |
1948 applied to the current patch in the order given. If all the |
1940 to the current patch in the order given. If all the patches apply |
1949 patches apply successfully, the current patch will be refreshed |
1941 successfully, the current patch will be refreshed with the new cumulative |
1950 with the new cumulative patch, and the folded patches will be |
1942 patch, and the folded patches will be deleted. With -k/--keep, the folded |
1951 deleted. With -k/--keep, the folded patch files will not be |
1943 patch files will not be removed afterwards. |
1952 removed afterwards. |
1944 |
1953 |
1945 The header for each folded patch will be concatenated with the current |
1954 The header for each folded patch will be concatenated with the |
1946 patch header, separated by a line of '* * *'. |
1955 current patch header, separated by a line of '* * *'.""" |
1947 """ |
1956 |
1948 |
1957 q = repo.mq |
1949 q = repo.mq |
1958 |
1950 |
1959 if not files: |
1951 if not files: |
1960 raise util.Abort(_('qfold requires at least one patch name')) |
1952 raise util.Abort(_('qfold requires at least one patch name')) |
2016 return ret |
2008 return ret |
2017 |
2009 |
2018 def guard(ui, repo, *args, **opts): |
2010 def guard(ui, repo, *args, **opts): |
2019 '''set or print guards for a patch |
2011 '''set or print guards for a patch |
2020 |
2012 |
2021 Guards control whether a patch can be pushed. A patch with no |
2013 Guards control whether a patch can be pushed. A patch with no guards is |
2022 guards is always pushed. A patch with a positive guard ("+foo") is |
2014 always pushed. A patch with a positive guard ("+foo") is pushed only if |
2023 pushed only if the qselect command has activated it. A patch with |
2015 the qselect command has activated it. A patch with a negative guard |
2024 a negative guard ("-foo") is never pushed if the qselect command |
2016 ("-foo") is never pushed if the qselect command has activated it. |
2025 has activated it. |
2017 |
2026 |
2018 With no arguments, print the currently active guards. With arguments, set |
2027 With no arguments, print the currently active guards. |
2019 guards for the named patch. |
2028 With arguments, set guards for the named patch. |
|
2029 NOTE: Specifying negative guards now requires '--'. |
2020 NOTE: Specifying negative guards now requires '--'. |
2030 |
2021 |
2031 To set guards on another patch: |
2022 To set guards on another patch: |
2032 hg qguard -- other.patch +2.6.17 -stable |
2023 hg qguard -- other.patch +2.6.17 -stable |
2033 ''' |
2024 ''' |
2123 return ret |
2114 return ret |
2124 |
2115 |
2125 def pop(ui, repo, patch=None, **opts): |
2116 def pop(ui, repo, patch=None, **opts): |
2126 """pop the current patch off the stack |
2117 """pop the current patch off the stack |
2127 |
2118 |
2128 By default, pops off the top of the patch stack. If given a patch |
2119 By default, pops off the top of the patch stack. If given a patch name, |
2129 name, keeps popping off patches until the named patch is at the |
2120 keeps popping off patches until the named patch is at the top of the |
2130 top of the stack. |
2121 stack. |
2131 """ |
2122 """ |
2132 localupdate = True |
2123 localupdate = True |
2133 if opts['name']: |
2124 if opts['name']: |
2134 q = queue(ui, repo.join(""), repo.join(opts['name'])) |
2125 q = queue(ui, repo.join(""), repo.join(opts['name'])) |
2135 ui.warn(_('using patch queue: %s\n') % q.path) |
2126 ui.warn(_('using patch queue: %s\n') % q.path) |
2242 |
2233 |
2243 def strip(ui, repo, rev, **opts): |
2234 def strip(ui, repo, rev, **opts): |
2244 """strip a revision and all its descendants from the repository |
2235 """strip a revision and all its descendants from the repository |
2245 |
2236 |
2246 If one of the working directory's parent revisions is stripped, the |
2237 If one of the working directory's parent revisions is stripped, the |
2247 working directory will be updated to the parent of the stripped |
2238 working directory will be updated to the parent of the stripped revision. |
2248 revision. |
|
2249 """ |
2239 """ |
2250 backup = 'all' |
2240 backup = 'all' |
2251 if opts['backup']: |
2241 if opts['backup']: |
2252 backup = 'strip' |
2242 backup = 'strip' |
2253 elif opts['nobackup']: |
2243 elif opts['nobackup']: |
2268 return 0 |
2258 return 0 |
2269 |
2259 |
2270 def select(ui, repo, *args, **opts): |
2260 def select(ui, repo, *args, **opts): |
2271 '''set or print guarded patches to push |
2261 '''set or print guarded patches to push |
2272 |
2262 |
2273 Use the qguard command to set or print guards on patch, then use |
2263 Use the qguard command to set or print guards on patch, then use qselect |
2274 qselect to tell mq which guards to use. A patch will be pushed if |
2264 to tell mq which guards to use. A patch will be pushed if it has no guards |
2275 it has no guards or any positive guards match the currently |
2265 or any positive guards match the currently selected guard, but will not be |
2276 selected guard, but will not be pushed if any negative guards |
2266 pushed if any negative guards match the current guard. For example: |
2277 match the current guard. For example: |
|
2278 |
2267 |
2279 qguard foo.patch -stable (negative guard) |
2268 qguard foo.patch -stable (negative guard) |
2280 qguard bar.patch +stable (positive guard) |
2269 qguard bar.patch +stable (positive guard) |
2281 qselect stable |
2270 qselect stable |
2282 |
2271 |
2283 This activates the "stable" guard. mq will skip foo.patch (because |
2272 This activates the "stable" guard. mq will skip foo.patch (because it has |
2284 it has a negative match) but push bar.patch (because it has a |
2273 a negative match) but push bar.patch (because it has a positive match). |
2285 positive match). |
2274 |
2286 |
2275 With no arguments, prints the currently active guards. With one argument, |
2287 With no arguments, prints the currently active guards. |
2276 sets the active guard. |
2288 With one argument, sets the active guard. |
2277 |
2289 |
2278 Use -n/--none to deactivate guards (no other arguments needed). When no |
2290 Use -n/--none to deactivate guards (no other arguments needed). |
2279 guards are active, patches with positive guards are skipped and patches |
2291 When no guards are active, patches with positive guards are |
2280 with negative guards are pushed. |
2292 skipped and patches with negative guards are pushed. |
2281 |
2293 |
2282 qselect can change the guards on applied patches. It does not pop guarded |
2294 qselect can change the guards on applied patches. It does not pop |
2283 patches by default. Use --pop to pop back to the last applied patch that |
2295 guarded patches by default. Use --pop to pop back to the last |
2284 is not guarded. Use --reapply (which implies --pop) to push back to the |
2296 applied patch that is not guarded. Use --reapply (which implies |
2285 current patch afterwards, but skip guarded patches. |
2297 --pop) to push back to the current patch afterwards, but skip |
2286 |
2298 guarded patches. |
2287 Use -s/--series to print a list of all guards in the series file (no other |
2299 |
2288 arguments needed). Use -v for more information. |
2300 Use -s/--series to print a list of all guards in the series file |
2289 ''' |
2301 (no other arguments needed). Use -v for more information.''' |
|
2302 |
2290 |
2303 q = repo.mq |
2291 q = repo.mq |
2304 guards = q.active() |
2292 guards = q.active() |
2305 if args or opts['none']: |
2293 if args or opts['none']: |
2306 old_unapplied = q.unapplied(repo) |
2294 old_unapplied = q.unapplied(repo) |
2371 q.save_dirty() |
2359 q.save_dirty() |
2372 |
2360 |
2373 def finish(ui, repo, *revrange, **opts): |
2361 def finish(ui, repo, *revrange, **opts): |
2374 """move applied patches into repository history |
2362 """move applied patches into repository history |
2375 |
2363 |
2376 Finishes the specified revisions (corresponding to applied |
2364 Finishes the specified revisions (corresponding to applied patches) by |
2377 patches) by moving them out of mq control into regular repository |
2365 moving them out of mq control into regular repository history. |
2378 history. |
2366 |
2379 |
2367 Accepts a revision range or the -a/--applied option. If --applied is |
2380 Accepts a revision range or the -a/--applied option. If --applied |
2368 specified, all applied mq revisions are removed from mq control. |
2381 is specified, all applied mq revisions are removed from mq |
2369 Otherwise, the given revisions must be at the base of the stack of applied |
2382 control. Otherwise, the given revisions must be at the base of the |
2370 patches. |
2383 stack of applied patches. |
2371 |
2384 |
2372 This can be especially useful if your changes have been applied to an |
2385 This can be especially useful if your changes have been applied to |
2373 upstream repository, or if you are about to push your changes to upstream. |
2386 an upstream repository, or if you are about to push your changes |
|
2387 to upstream. |
|
2388 """ |
2374 """ |
2389 if not opts['applied'] and not revrange: |
2375 if not opts['applied'] and not revrange: |
2390 raise util.Abort(_('no revisions specified')) |
2376 raise util.Abort(_('no revisions specified')) |
2391 elif opts['applied']: |
2377 elif opts['applied']: |
2392 revrange = ('qbase:qtip',) + revrange |
2378 revrange = ('qbase:qtip',) + revrange |