1831 cmdutil.bail_if_changed(repo) |
1831 cmdutil.bail_if_changed(repo) |
1832 |
1832 |
1833 d = opts["base"] |
1833 d = opts["base"] |
1834 strip = opts["strip"] |
1834 strip = opts["strip"] |
1835 wlock = lock = None |
1835 wlock = lock = None |
|
1836 |
|
1837 def tryone(ui, hunk): |
|
1838 tmpname, message, user, date, branch, nodeid, p1, p2 = patch.extract(ui, hunk) |
|
1839 |
|
1840 if not tmpname: |
|
1841 return None |
|
1842 commitid = _('to working directory') |
|
1843 |
|
1844 try: |
|
1845 cmdline_message = cmdutil.logmessage(opts) |
|
1846 if cmdline_message: |
|
1847 # pickup the cmdline msg |
|
1848 message = cmdline_message |
|
1849 elif message: |
|
1850 # pickup the patch msg |
|
1851 message = message.strip() |
|
1852 else: |
|
1853 # launch the editor |
|
1854 message = None |
|
1855 ui.debug('message:\n%s\n' % message) |
|
1856 |
|
1857 wp = repo.parents() |
|
1858 if opts.get('exact'): |
|
1859 if not nodeid or not p1: |
|
1860 raise util.Abort(_('not a Mercurial patch')) |
|
1861 p1 = repo.lookup(p1) |
|
1862 p2 = repo.lookup(p2 or hex(nullid)) |
|
1863 |
|
1864 if p1 != wp[0].node(): |
|
1865 hg.clean(repo, p1) |
|
1866 repo.dirstate.setparents(p1, p2) |
|
1867 elif p2: |
|
1868 try: |
|
1869 p1 = repo.lookup(p1) |
|
1870 p2 = repo.lookup(p2) |
|
1871 if p1 == wp[0].node(): |
|
1872 repo.dirstate.setparents(p1, p2) |
|
1873 except error.RepoError: |
|
1874 pass |
|
1875 if opts.get('exact') or opts.get('import_branch'): |
|
1876 repo.dirstate.setbranch(branch or 'default') |
|
1877 |
|
1878 files = {} |
|
1879 try: |
|
1880 patch.patch(tmpname, ui, strip=strip, cwd=repo.root, |
|
1881 files=files, eolmode=None) |
|
1882 finally: |
|
1883 files = patch.updatedir(ui, repo, files, |
|
1884 similarity=sim / 100.0) |
|
1885 if not opts.get('no_commit'): |
|
1886 if opts.get('exact'): |
|
1887 m = None |
|
1888 else: |
|
1889 m = cmdutil.matchfiles(repo, files or []) |
|
1890 n = repo.commit(message, opts.get('user') or user, |
|
1891 opts.get('date') or date, match=m, |
|
1892 editor=cmdutil.commiteditor) |
|
1893 if opts.get('exact'): |
|
1894 if hex(n) != nodeid: |
|
1895 repo.rollback() |
|
1896 raise util.Abort(_('patch is damaged' |
|
1897 ' or loses information')) |
|
1898 # Force a dirstate write so that the next transaction |
|
1899 # backups an up-do-date file. |
|
1900 repo.dirstate.write() |
|
1901 if n: |
|
1902 commitid = short(n) |
|
1903 |
|
1904 return commitid |
|
1905 finally: |
|
1906 os.unlink(tmpname) |
|
1907 |
1836 try: |
1908 try: |
1837 wlock = repo.wlock() |
1909 wlock = repo.wlock() |
1838 lock = repo.lock() |
1910 lock = repo.lock() |
|
1911 lastcommit = None |
1839 for p in patches: |
1912 for p in patches: |
1840 pf = os.path.join(d, p) |
1913 pf = os.path.join(d, p) |
1841 |
1914 |
1842 if pf == '-': |
1915 if pf == '-': |
1843 ui.status(_("applying patch from stdin\n")) |
1916 ui.status(_("applying patch from stdin\n")) |
1844 pf = sys.stdin |
1917 pf = sys.stdin |
1845 else: |
1918 else: |
1846 ui.status(_("applying %s\n") % p) |
1919 ui.status(_("applying %s\n") % p) |
1847 pf = url.open(ui, pf) |
1920 pf = url.open(ui, pf) |
1848 data = patch.extract(ui, pf) |
1921 |
1849 tmpname, message, user, date, branch, nodeid, p1, p2 = data |
1922 haspatch = False |
1850 |
1923 for hunk in patch.split(pf): |
1851 if tmpname is None: |
1924 commitid = tryone(ui, hunk) |
|
1925 if commitid: |
|
1926 haspatch = True |
|
1927 if lastcommit: |
|
1928 ui.status(_('applied %s\n') % lastcommit) |
|
1929 lastcommit = commitid |
|
1930 |
|
1931 if not haspatch: |
1852 raise util.Abort(_('no diffs found')) |
1932 raise util.Abort(_('no diffs found')) |
1853 |
1933 |
1854 try: |
|
1855 cmdline_message = cmdutil.logmessage(opts) |
|
1856 if cmdline_message: |
|
1857 # pickup the cmdline msg |
|
1858 message = cmdline_message |
|
1859 elif message: |
|
1860 # pickup the patch msg |
|
1861 message = message.strip() |
|
1862 else: |
|
1863 # launch the editor |
|
1864 message = None |
|
1865 ui.debug('message:\n%s\n' % message) |
|
1866 |
|
1867 wp = repo.parents() |
|
1868 if opts.get('exact'): |
|
1869 if not nodeid or not p1: |
|
1870 raise util.Abort(_('not a Mercurial patch')) |
|
1871 p1 = repo.lookup(p1) |
|
1872 p2 = repo.lookup(p2 or hex(nullid)) |
|
1873 |
|
1874 if p1 != wp[0].node(): |
|
1875 hg.clean(repo, p1) |
|
1876 repo.dirstate.setparents(p1, p2) |
|
1877 elif p2: |
|
1878 try: |
|
1879 p1 = repo.lookup(p1) |
|
1880 p2 = repo.lookup(p2) |
|
1881 if p1 == wp[0].node(): |
|
1882 repo.dirstate.setparents(p1, p2) |
|
1883 except error.RepoError: |
|
1884 pass |
|
1885 if opts.get('exact') or opts.get('import_branch'): |
|
1886 repo.dirstate.setbranch(branch or 'default') |
|
1887 |
|
1888 files = {} |
|
1889 try: |
|
1890 patch.patch(tmpname, ui, strip=strip, cwd=repo.root, |
|
1891 files=files, eolmode=None) |
|
1892 finally: |
|
1893 files = patch.updatedir(ui, repo, files, |
|
1894 similarity=sim / 100.0) |
|
1895 if not opts.get('no_commit'): |
|
1896 m = cmdutil.matchfiles(repo, files or []) |
|
1897 n = repo.commit(message, opts.get('user') or user, |
|
1898 opts.get('date') or date, match=m, |
|
1899 editor=cmdutil.commiteditor) |
|
1900 if opts.get('exact'): |
|
1901 if hex(n) != nodeid: |
|
1902 repo.rollback() |
|
1903 raise util.Abort(_('patch is damaged' |
|
1904 ' or loses information')) |
|
1905 # Force a dirstate write so that the next transaction |
|
1906 # backups an up-do-date file. |
|
1907 repo.dirstate.write() |
|
1908 finally: |
|
1909 os.unlink(tmpname) |
|
1910 finally: |
1934 finally: |
1911 release(lock, wlock) |
1935 release(lock, wlock) |
1912 |
1936 |
1913 def incoming(ui, repo, source="default", **opts): |
1937 def incoming(ui, repo, source="default", **opts): |
1914 """show new changesets found in source |
1938 """show new changesets found in source |