Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/commands.py @ 2859:b3d1145ed06c
Teach import to understand git diff extensions.
Vanilla patch chokes on git patches that include files that are copied
or renamed, then modified. So this code detects that case and rewrites
the patch if necessary.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Fri, 11 Aug 2006 15:50:07 -0700 |
parents | 7706fa503677 |
children | 0f08f2c042ec |
comparison
equal
deleted
inserted
replaced
2842:7706fa503677 | 2859:b3d1145ed06c |
---|---|
1823 '(---|\*\*\*)[ \t])', re.MULTILINE) | 1823 '(---|\*\*\*)[ \t])', re.MULTILINE) |
1824 | 1824 |
1825 wlock = repo.wlock() | 1825 wlock = repo.wlock() |
1826 lock = repo.lock() | 1826 lock = repo.lock() |
1827 | 1827 |
1828 wlock = repo.wlock() | |
1828 for patch in patches: | 1829 for patch in patches: |
1829 pf = os.path.join(d, patch) | 1830 pf = os.path.join(d, patch) |
1830 | 1831 |
1831 message = None | 1832 message = None |
1832 user = None | 1833 user = None |
1906 tmpfp.close() | 1907 tmpfp.close() |
1907 if not diffs_seen: | 1908 if not diffs_seen: |
1908 raise util.Abort(_('no diffs found')) | 1909 raise util.Abort(_('no diffs found')) |
1909 | 1910 |
1910 files = util.patch(strip, tmpname, ui, cwd=repo.root) | 1911 files = util.patch(strip, tmpname, ui, cwd=repo.root) |
1912 removes = [] | |
1911 if len(files) > 0: | 1913 if len(files) > 0: |
1912 cfiles = files | 1914 cfiles = files.keys() |
1915 copies = [] | |
1916 copts = {'after': False, 'force': False} | |
1913 cwd = repo.getcwd() | 1917 cwd = repo.getcwd() |
1914 if cwd: | 1918 if cwd: |
1915 cfiles = [util.pathto(cwd, f) for f in files] | 1919 cfiles = [util.pathto(cwd, f) for f in files.keys()] |
1920 for f in files: | |
1921 ctype, gp = files[f] | |
1922 if ctype == 'RENAME': | |
1923 copies.append((gp.oldpath, gp.path, gp.copymod)) | |
1924 removes.append(gp.oldpath) | |
1925 elif ctype == 'COPY': | |
1926 copies.append((gp.oldpath, gp.path, gp.copymod)) | |
1927 elif ctype == 'DELETE': | |
1928 removes.append(gp.path) | |
1929 for src, dst, after in copies: | |
1930 absdst = os.path.join(repo.root, dst) | |
1931 if not after and os.path.exists(absdst): | |
1932 raise util.Abort(_('patch creates existing file %s') % dst) | |
1933 if cwd: | |
1934 src, dst = [util.pathto(cwd, f) for f in (src, dst)] | |
1935 copts['after'] = after | |
1936 errs, copied = docopy(ui, repo, (src, dst), copts, wlock=wlock) | |
1937 if errs: | |
1938 raise util.Abort(errs) | |
1939 if removes: | |
1940 repo.remove(removes, True, wlock=wlock) | |
1941 for f in files: | |
1942 ctype, gp = files[f] | |
1943 if gp and gp.mode: | |
1944 x = gp.mode & 0100 != 0 | |
1945 dst = os.path.join(repo.root, gp.path) | |
1946 util.set_exec(dst, x) | |
1916 addremove_lock(ui, repo, cfiles, {}, wlock=wlock) | 1947 addremove_lock(ui, repo, cfiles, {}, wlock=wlock) |
1948 files = files.keys() | |
1949 files.extend([r for r in removes if r not in files]) | |
1917 repo.commit(files, message, user, date, wlock=wlock, lock=lock) | 1950 repo.commit(files, message, user, date, wlock=wlock, lock=lock) |
1918 finally: | 1951 finally: |
1919 os.unlink(tmpname) | 1952 os.unlink(tmpname) |
1920 | 1953 |
1921 def incoming(ui, repo, source="default", **opts): | 1954 def incoming(ui, repo, source="default", **opts): |