9 import cStringIO, email.Parser, os, errno, re |
9 import cStringIO, email.Parser, os, errno, re |
10 import tempfile, zlib |
10 import tempfile, zlib |
11 |
11 |
12 from i18n import _ |
12 from i18n import _ |
13 from node import hex, nullid, short |
13 from node import hex, nullid, short |
14 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding |
14 import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, wdutil |
15 |
15 |
16 gitre = re.compile('diff --git a/(.*) b/(.*)') |
16 gitre = re.compile('diff --git a/(.*) b/(.*)') |
17 |
17 |
18 class PatchError(Exception): |
18 class PatchError(Exception): |
19 pass |
19 pass |
1154 rejects += current_file.close() |
1154 rejects += current_file.close() |
1155 |
1155 |
1156 if rejects: |
1156 if rejects: |
1157 return -1 |
1157 return -1 |
1158 return err |
1158 return err |
|
1159 |
|
1160 def updatedir(ui, repo, patches, similarity=0): |
|
1161 '''Update dirstate after patch application according to metadata''' |
|
1162 if not patches: |
|
1163 return [] |
|
1164 copies = [] |
|
1165 removes = set() |
|
1166 cfiles = patches.keys() |
|
1167 cwd = repo.getcwd() |
|
1168 if cwd: |
|
1169 cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] |
|
1170 for f in patches: |
|
1171 gp = patches[f] |
|
1172 if not gp: |
|
1173 continue |
|
1174 if gp.op == 'RENAME': |
|
1175 copies.append((gp.oldpath, gp.path)) |
|
1176 removes.add(gp.oldpath) |
|
1177 elif gp.op == 'COPY': |
|
1178 copies.append((gp.oldpath, gp.path)) |
|
1179 elif gp.op == 'DELETE': |
|
1180 removes.add(gp.path) |
|
1181 |
|
1182 wctx = repo[None] |
|
1183 for src, dst in copies: |
|
1184 wdutil.dirstatecopy(ui, repo, wctx, src, dst, cwd=cwd) |
|
1185 if (not similarity) and removes: |
|
1186 wctx.remove(sorted(removes), True) |
|
1187 |
|
1188 for f in patches: |
|
1189 gp = patches[f] |
|
1190 if gp and gp.mode: |
|
1191 islink, isexec = gp.mode |
|
1192 dst = repo.wjoin(gp.path) |
|
1193 # patch won't create empty files |
|
1194 if gp.op == 'ADD' and not os.path.lexists(dst): |
|
1195 flags = (isexec and 'x' or '') + (islink and 'l' or '') |
|
1196 repo.wwrite(gp.path, '', flags) |
|
1197 util.setflags(dst, islink, isexec) |
|
1198 wdutil.addremove(repo, cfiles, similarity=similarity) |
|
1199 files = patches.keys() |
|
1200 files.extend([r for r in removes if r not in files]) |
|
1201 return sorted(files) |
1159 |
1202 |
1160 def _externalpatch(patcher, patchname, ui, strip, cwd, files): |
1203 def _externalpatch(patcher, patchname, ui, strip, cwd, files): |
1161 """use <patcher> to apply <patchname> to the working directory. |
1204 """use <patcher> to apply <patchname> to the working directory. |
1162 returns whether patch was applied with fuzz factor.""" |
1205 returns whether patch was applied with fuzz factor.""" |
1163 |
1206 |