##// END OF EJS Templates
Move import's working dir update code into patch.updatedir
Brendan Cully -
r2933:439fd013 default
parent child Browse files
Show More
@@ -1683,44 +1683,7 b' def import_(ui, repo, patch1, *patches, '
1683 ui.debug(_('message:\n%s\n') % message)
1683 ui.debug(_('message:\n%s\n') % message)
1684
1684
1685 files, fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root)
1685 files, fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root)
1686 removes = []
1686 files = patch.updatedir(ui, repo, files, wlock=wlock)
1687 if len(files) > 0:
1688 cfiles = files.keys()
1689 copies = []
1690 copts = {'after': False, 'force': False}
1691 cwd = repo.getcwd()
1692 if cwd:
1693 cfiles = [util.pathto(cwd, f) for f in files.keys()]
1694 for f in files:
1695 ctype, gp = files[f]
1696 if ctype == 'RENAME':
1697 copies.append((gp.oldpath, gp.path, gp.copymod))
1698 removes.append(gp.oldpath)
1699 elif ctype == 'COPY':
1700 copies.append((gp.oldpath, gp.path, gp.copymod))
1701 elif ctype == 'DELETE':
1702 removes.append(gp.path)
1703 for src, dst, after in copies:
1704 absdst = os.path.join(repo.root, dst)
1705 if not after and os.path.exists(absdst):
1706 raise util.Abort(_('patch creates existing file %s') % dst)
1707 if cwd:
1708 src, dst = [util.pathto(cwd, f) for f in (src, dst)]
1709 copts['after'] = after
1710 errs, copied = docopy(ui, repo, (src, dst), copts, wlock=wlock)
1711 if errs:
1712 raise util.Abort(errs)
1713 if removes:
1714 repo.remove(removes, True, wlock=wlock)
1715 for f in files:
1716 ctype, gp = files[f]
1717 if gp and gp.mode:
1718 x = gp.mode & 0100 != 0
1719 dst = os.path.join(repo.root, gp.path)
1720 util.set_exec(dst, x)
1721 cmdutil.addremove(repo, cfiles, wlock=wlock)
1722 files = files.keys()
1723 files.extend([r for r in removes if r not in files])
1724 repo.commit(files, message, user, date, wlock=wlock, lock=lock)
1687 repo.commit(files, message, user, date, wlock=wlock, lock=lock)
1725 finally:
1688 finally:
1726 os.unlink(tmpname)
1689 os.unlink(tmpname)
@@ -11,6 +11,28 b' from node import *'
11 demandload(globals(), "cmdutil mdiff util")
11 demandload(globals(), "cmdutil mdiff util")
12 demandload(globals(), "cStringIO email.Parser os re shutil sys tempfile")
12 demandload(globals(), "cStringIO email.Parser os re shutil sys tempfile")
13
13
14 # helper functions
15
16 def copyfile(src, dst, basedir=None):
17 if not basedir:
18 basedir = os.getcwd()
19
20 abssrc, absdst = [os.path.join(basedir, n) for n in (src, dst)]
21 if os.path.exists(absdst):
22 raise util.Abort(_("cannot create %s: destination already exists") %
23 dst)
24
25 targetdir = os.path.dirname(absdst)
26 if not os.path.isdir(targetdir):
27 os.makedirs(targetdir)
28 try:
29 shutil.copyfile(abssrc, absdst)
30 shutil.copymode(abssrc, absdst)
31 except shutil.Error, inst:
32 raise util.Abort(str(inst))
33
34 # public functions
35
14 def extract(ui, fileobj):
36 def extract(ui, fileobj):
15 '''extract patch from data read from fileobj.
37 '''extract patch from data read from fileobj.
16
38
@@ -174,21 +196,7 b' def dogitpatch(patchname, gitpatches):'
174 if not p.copymod:
196 if not p.copymod:
175 continue
197 continue
176
198
177 if os.path.exists(p.path):
199 copyfile(p.oldpath, p.path)
178 raise util.Abort(_("cannot create %s: destination already exists") %
179 p.path)
180
181 (src, dst) = [os.path.join(os.getcwd(), n)
182 for n in (p.oldpath, p.path)]
183
184 targetdir = os.path.dirname(dst)
185 if not os.path.isdir(targetdir):
186 os.makedirs(targetdir)
187 try:
188 shutil.copyfile(src, dst)
189 shutil.copymode(src, dst)
190 except shutil.Error, inst:
191 raise util.Abort(str(inst))
192
200
193 # rewrite patch hunk
201 # rewrite patch hunk
194 while pfline < p.lineno:
202 while pfline < p.lineno:
@@ -281,6 +289,45 b' def diffopts(ui, opts={}):'
281 ignoreblanklines=(opts.get('ignore_blank_lines') or
289 ignoreblanklines=(opts.get('ignore_blank_lines') or
282 ui.configbool('diff', 'ignoreblanklines', None)))
290 ui.configbool('diff', 'ignoreblanklines', None)))
283
291
292 def updatedir(ui, repo, patches, wlock=None):
293 '''Update dirstate after patch application according to metadata'''
294 if not patches:
295 return
296 copies = []
297 removes = []
298 cfiles = patches.keys()
299 copts = {'after': False, 'force': False}
300 cwd = repo.getcwd()
301 if cwd:
302 cfiles = [util.pathto(cwd, f) for f in patches.keys()]
303 for f in patches:
304 ctype, gp = patches[f]
305 if ctype == 'RENAME':
306 copies.append((gp.oldpath, gp.path, gp.copymod))
307 removes.append(gp.oldpath)
308 elif ctype == 'COPY':
309 copies.append((gp.oldpath, gp.path, gp.copymod))
310 elif ctype == 'DELETE':
311 removes.append(gp.path)
312 for src, dst, after in copies:
313 if not after:
314 copyfile(src, dst, repo.root)
315 repo.copy(src, dst, wlock=wlock)
316 if removes:
317 repo.remove(removes, True, wlock=wlock)
318 for f in patches:
319 ctype, gp = patches[f]
320 if gp and gp.mode:
321 x = gp.mode & 0100 != 0
322 dst = os.path.join(repo.root, gp.path)
323 util.set_exec(dst, x)
324 cmdutil.addremove(repo, cfiles, wlock=wlock)
325 files = patches.keys()
326 files.extend([r for r in removes if r not in files])
327 files.sort()
328
329 return files
330
284 def diff(repo, node1=None, node2=None, files=None, match=util.always,
331 def diff(repo, node1=None, node2=None, files=None, match=util.always,
285 fp=None, changes=None, opts=None):
332 fp=None, changes=None, opts=None):
286 '''print diff of changes to files between two nodes, or node and
333 '''print diff of changes to files between two nodes, or node and
General Comments 0
You need to be logged in to leave comments. Login now